Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
jhett12321 committed Sep 2, 2022
2 parents 6947349 + 168bac7 commit 2874b42
Show file tree
Hide file tree
Showing 115 changed files with 1,341 additions and 607 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NWN_VERSION=8193.34
NWNX_VERSION=5ade7de
NWNX_VERSION=8faa9d4
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## 8193.34.16
https://github.com/nwn-dotnet/Anvil/compare/v8193.34.15...v8193.34.16

### Added
- Events: Added `OnDebugPlayVisualEffect`, `OnDebugRunScript`, `OnDebugRunScriptChunk` events.
- NwGameObject: Added `AnimationState`.
- Effect: Added `Effect.VisualEffect(VisualEffectTableEntry, bool, float, Vector3, Vector3)` overload.

### Package Updates
- NWN.Core 8193.34.6 -> 8193.34.7
- LightInject 6.4.1 -> 6.5.1
- NLog 5.0.1 -> 5.0.4
- NWNX 5ade7de -> 8faa9d4

### Changed
- SchedulerService: Use `PriorityQueue` to improve main server loop performance.

## 8193.34.15
https://github.com/nwn-dotnet/Anvil/compare/v8193.34.14...v8193.34.15

Expand Down
2 changes: 1 addition & 1 deletion NWN.Anvil.TestRunner/NWN.Anvil.TestRunner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.2.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.0" />
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion NWN.Anvil.Tests/NWN.Anvil.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

<ItemGroup>
<PackageReference Include="NWN.Native" Version="8193.34.4" PrivateAssets="compile" />
<PackageReference Include="NWN.Core" Version="8193.34.6" PrivateAssets="compile" />
<PackageReference Include="NWN.Core" Version="8193.34.7" PrivateAssets="compile" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,36 @@ public async Task RepeatingScheduleCancelAfterRunPreventsSubsequentRuns(int dela
await NwTask.WaitUntil(() => executionCount > 0);
Assert.That(executionCount, Is.EqualTo(1));
}

[Test(Description = "Scheduling multiple tasks correctly schedules all tasks and runs them after the expected delay.")]
[Timeout(10000)]
[TestCase(200, 500, 1000)]
[TestCase(500, 200, 1000)]
[TestCase(1000, 500, 100)]
public async Task ScheduleMultipleTasksRunsAtExpectedTime(int delay1Ms, int delay2Ms, int delay3Ms)
{
TimeSpan delay1 = TimeSpan.FromMilliseconds(delay1Ms);
TimeSpan delay2 = TimeSpan.FromMilliseconds(delay2Ms);
TimeSpan delay3 = TimeSpan.FromMilliseconds(delay3Ms);

Stopwatch stopwatch = Stopwatch.StartNew();
int executedCount = 0;

void ScheduleAndAssert(TimeSpan delay)
{
SchedulerService.Schedule(() =>
{
Assert.That(stopwatch.Elapsed, Is.EqualTo(delay).Within(100).Milliseconds, "Delay was not within the margin of error.");
executedCount++;
}, delay);
}

ScheduleAndAssert(delay1);
ScheduleAndAssert(delay2);
ScheduleAndAssert(delay3);

await NwTask.WaitUntil(() => executedCount == 3);
Assert.That(executedCount, Is.EqualTo(3));
}
}
}
6 changes: 3 additions & 3 deletions NWN.Anvil/NWN.Anvil.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="LightInject" Version="6.4.1" />
<PackageReference Include="LightInject" Version="6.5.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NLog" Version="5.0.1" />
<PackageReference Include="NLog" Version="5.0.4" />
<PackageReference Include="Paket.Core" Version="7.1.5" PrivateAssets="all" />
<PackageReference Include="NWN.Core" Version="8193.34.6" PrivateAssets="compile" />
<PackageReference Include="NWN.Core" Version="8193.34.7" PrivateAssets="compile" />
<PackageReference Include="NWN.Native" Version="8193.34.4" PrivateAssets="compile" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions NWN.Anvil/NWN.Anvil.csproj.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=src_005Cmain_005Capi_005Cevents_005Cgame_005Cstoreevents/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=src_005Cmain_005Capi_005Cevents_005Cgame_005Ctriggerevents/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=src_005Cmain_005Capi_005Cevents_005Cnative_005Ccreatureevents/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=src_005Cmain_005Capi_005Cevents_005Cnative_005Cdebugevents/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=src_005Cmain_005Capi_005Cevents_005Cnative_005Cmapevents/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=src_005Cmain_005Capi_005Cevents_005Cnative_005Cskillevents/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=src_005Cmain_005Capi_005Cextensions/@EntryIndexedValue">True</s:Boolean>
Expand Down
120 changes: 120 additions & 0 deletions NWN.Anvil/src/main/API/Constants/AnimationState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
namespace Anvil.API
{
public enum AnimationState
{
Pause = NWN.Native.API.Animation.Pause,
Ready = NWN.Native.API.Animation.Ready,
Walking = NWN.Native.API.Animation.Walking,
WalkingBackwards = NWN.Native.API.Animation.WalkingBackwards,
Running = NWN.Native.API.Animation.Running,
KnockdownFront = NWN.Native.API.Animation.KnockdownFront,
DeadFront = NWN.Native.API.Animation.DeadFront,
KnockdownButt = NWN.Native.API.Animation.KnockdownButt,
DeadButt = NWN.Native.API.Animation.DeadButt,
Attack = NWN.Native.API.Animation.Attack,
Throw = NWN.Native.API.Animation.Throw,
Dodge = NWN.Native.API.Animation.Dodge,
Parry = NWN.Native.API.Animation.Parry,
Shield = NWN.Native.API.Animation.Shield,
Damage = NWN.Native.API.Animation.Damage,
Conjure1 = NWN.Native.API.Animation.Conjure1,
Conjure2 = NWN.Native.API.Animation.Conjure2,
Cast1 = NWN.Native.API.Animation.Cast1,
Cast2 = NWN.Native.API.Animation.Cast2,
Cast3 = NWN.Native.API.Animation.Cast3,
Cast4 = NWN.Native.API.Animation.Cast4,
Open = NWN.Native.API.Animation.Open,
Closed = NWN.Native.API.Animation.Closed,
Spasm = NWN.Native.API.Animation.Spasm,
CombatStepFront = NWN.Native.API.Animation.CombatStepFront,
CombatStepBack = NWN.Native.API.Animation.CombatStepBack,
CombatStepLeft = NWN.Native.API.Animation.CombatStepLeft,
CombatStepRight = NWN.Native.API.Animation.CombatStepRight,
Taunt = NWN.Native.API.Animation.Taunt,
OverlayGreeting = NWN.Native.API.Animation.OverlayGreeting,
OverlayListen = NWN.Native.API.Animation.OverlayListen,
Meditate = NWN.Native.API.Animation.Meditate,
Worship = NWN.Native.API.Animation.Worship,
OverlaySalute = NWN.Native.API.Animation.OverlaySalute,
Bow = NWN.Native.API.Animation.Bow,
Sitting = NWN.Native.API.Animation.Sitting,
Steal = NWN.Native.API.Animation.Steal,
OverlayTalkNormal = NWN.Native.API.Animation.OverlayTalkNormal,
OverlayTalkPleading = NWN.Native.API.Animation.OverlayTalkPleading,
OverlayTalkForceful = NWN.Native.API.Animation.OverlayTalkForceful,
OverlayTalkLaugh = NWN.Native.API.Animation.OverlayTalkLaugh,
CombatStepDummy = NWN.Native.API.Animation.CombatStepDummy,
AttackDummy = NWN.Native.API.Animation.AttackDummy,
VictoryFighter = NWN.Native.API.Animation.VictoryFighter,
VictoryMage = NWN.Native.API.Animation.VictoryMage,
VictoryThief = NWN.Native.API.Animation.VictoryThief,
SitCrossLegs = NWN.Native.API.Animation.SitCrossLegs,
LookFar = NWN.Native.API.Animation.LookFar,
CombatStepDummyFbs = NWN.Native.API.Animation.CombatStepDummyFB,
Opened1 = NWN.Native.API.Animation.Opened1,
Opened2 = NWN.Native.API.Animation.Opened2,
Pause2 = NWN.Native.API.Animation.Pause2,
HeadTurnLeft = NWN.Native.API.Animation.HeadTurnLeft,
HeadTurnRight = NWN.Native.API.Animation.HeadTurnRight,
PauseScratchHead = NWN.Native.API.Animation.PauseScratchHead,
PauseBored = NWN.Native.API.Animation.PauseBored,
PauseTired = NWN.Native.API.Animation.PauseTired,
PauseDrunk = NWN.Native.API.Animation.PauseDrunk,
GetLow = NWN.Native.API.Animation.GetLow,
GetMid = NWN.Native.API.Animation.GetMid,
Cast5 = NWN.Native.API.Animation.Cast5,
Flown = NWN.Native.API.Animation.Flown,
Arrived = NWN.Native.API.Animation.Arrived,
OverlayDrink = NWN.Native.API.Animation.OverlayDrink,
OverlayRead = NWN.Native.API.Animation.OverlayRead,
Destroyed = NWN.Native.API.Animation.Destroyed,
PlaceableActivated = NWN.Native.API.Animation.PlaceableActivated,
PlaceableDeactivated = NWN.Native.API.Animation.PlaceableDeactivated,
PlaceableOpened = NWN.Native.API.Animation.PlaceableOpened,
PlaceableClosed = NWN.Native.API.Animation.PlaceableClosed,
DamageStab = NWN.Native.API.Animation.DamageStab,
WalkingLeft = NWN.Native.API.Animation.WalkingLeft,
WalkingRight = NWN.Native.API.Animation.WalkingRight,
TurnOnSpotRight = NWN.Native.API.Animation.TurnOnSpotRight,
TurnOnSpotLeft = NWN.Native.API.Animation.TurnOnSpotLeft,
CombatTurnRight = NWN.Native.API.Animation.CombatTurnRight,
CombatTurnLeft = NWN.Native.API.Animation.CombatTurnLeft,
WalkingForwardLeft = NWN.Native.API.Animation.WalkingForwardLeft,
WalkingForwardRight = NWN.Native.API.Animation.WalkingForwardRight,
RunningForwardLeft = NWN.Native.API.Animation.RunningForwardLeft,
RunningForwardRight = NWN.Native.API.Animation.RunningForwardRight,
DialogNoAnim = NWN.Native.API.Animation.DialogNoAnim,
FakeAttack = NWN.Native.API.Animation.FakeAttack,
FakeDodgeSide = NWN.Native.API.Animation.FakeDodgeSide,
FakeDodgeDuck = NWN.Native.API.Animation.FakeDodgeDuck,
Whirlwind = NWN.Native.API.Animation.Whirlwind,
SpasmLooping = NWN.Native.API.Animation.SpasmLooping,
Flown2 = NWN.Native.API.Animation.Flown2,
Arrived2 = NWN.Native.API.Animation.Arrived2,
CastCreature = NWN.Native.API.Animation.CastCreature,
Custom1 = NWN.Native.API.Animation.Custom1,
Custom2 = NWN.Native.API.Animation.Custom2,
DamageLeft = NWN.Native.API.Animation.DamageLeft,
DamageRight = NWN.Native.API.Animation.DamageRight,
Custom3 = NWN.Native.API.Animation.Custom3,
Custom4 = NWN.Native.API.Animation.Custom4,
Custom5 = NWN.Native.API.Animation.Custom5,
Custom6 = NWN.Native.API.Animation.Custom6,
Custom7 = NWN.Native.API.Animation.Custom7,
Custom8 = NWN.Native.API.Animation.Custom8,
Custom9 = NWN.Native.API.Animation.Custom9,
Custom10 = NWN.Native.API.Animation.Custom10,
Custom11 = NWN.Native.API.Animation.Custom11,
Custom12 = NWN.Native.API.Animation.Custom12,
Custom13 = NWN.Native.API.Animation.Custom13,
Custom14 = NWN.Native.API.Animation.Custom14,
Custom15 = NWN.Native.API.Animation.Custom15,
Custom16 = NWN.Native.API.Animation.Custom16,
Custom17 = NWN.Native.API.Animation.Custom17,
Custom18 = NWN.Native.API.Animation.Custom18,
Custom19 = NWN.Native.API.Animation.Custom19,
Custom20 = NWN.Native.API.Animation.Custom20,
Mount1 = NWN.Native.API.Animation.Mount1,
Dismount1 = NWN.Native.API.Animation.Dismount1,
}
}
5 changes: 5 additions & 0 deletions NWN.Anvil/src/main/API/EngineStructure/Effect.Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -648,5 +648,10 @@ public static Effect VisualEffect(VfxType visualEffectId, bool missEffect = fals
{
return NWScript.EffectVisualEffect((int)visualEffectId, missEffect.ToInt(), fScale, vTranslate, vRotate)!;
}

public static Effect VisualEffect(VisualEffectTableEntry visualEffect, bool missEffect = false, float fScale = 1.0f, System.Numerics.Vector3 vTranslate = default, System.Numerics.Vector3 vRotate = default)
{
return NWScript.EffectVisualEffect(visualEffect.RowIndex, missEffect.ToInt(), fScale, vTranslate, vRotate)!;
}
}
}
2 changes: 1 addition & 1 deletion NWN.Anvil/src/main/API/Events/Game/GameEventFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ScriptHandleResult IScriptDispatcher.ExecuteScript(string? scriptName, uint oidS
NWScript.ExecuteScript(scriptName, oidSelf);
}

EventService.Value.ProcessEvent(value.Invoke());
EventService.Value.ProcessEvent(EventCallbackType.Before, value.Invoke());
return ScriptHandleResult.Handled;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed class OnAssociateAdd : IEvent

NwObject IEvent.Context => Owner;

internal sealed unsafe class Factory : HookEventFactory
public sealed unsafe class Factory : HookEventFactory
{
private static FunctionHook<AddAssociateHook> Hook { get; set; } = null!;

Expand All @@ -32,14 +32,15 @@ protected override IDisposable[] RequestHooks()
[UnmanagedCallersOnly]
private static void OnAddAssociate(void* pCreature, uint oidAssociate, ushort associateType)
{
ProcessEvent(new OnAssociateAdd
OnAssociateAdd eventData = ProcessEvent(EventCallbackType.Before, new OnAssociateAdd
{
Owner = CNWSCreature.FromPointer(pCreature).ToNwObject<NwCreature>()!,
Associate = oidAssociate.ToNwObject<NwCreature>()!,
AssociateType = (AssociateType)associateType,
});

Hook.CallOriginal(pCreature, oidAssociate, associateType);
ProcessEvent(EventCallbackType.After, eventData);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public sealed class OnAssociateRemove : IEvent

NwObject IEvent.Context => Owner;

internal sealed unsafe class Factory : HookEventFactory
public sealed unsafe class Factory : HookEventFactory
{
private static FunctionHook<RemoveAssociateHook> Hook { get; set; } = null!;

Expand All @@ -29,13 +29,14 @@ protected override IDisposable[] RequestHooks()
[UnmanagedCallersOnly]
private static void OnRemoveAssociate(void* pCreature, uint oidAssociate)
{
ProcessEvent(new OnAssociateRemove
OnAssociateRemove eventData = ProcessEvent(EventCallbackType.Before, new OnAssociateRemove
{
Owner = CNWSCreature.FromPointer(pCreature).ToNwObject<NwCreature>()!,
Associate = oidAssociate.ToNwObject<NwCreature>()!,
});

Hook.CallOriginal(pCreature, oidAssociate);
ProcessEvent(EventCallbackType.After, eventData);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public sealed class OnFamiliarPossess : IEvent

NwObject IEvent.Context => Owner;

internal sealed unsafe class Factory : HookEventFactory
public sealed unsafe class Factory : HookEventFactory
{
private static FunctionHook<PossessFamiliarHook> Hook { get; set; } = null!;

Expand All @@ -31,13 +31,14 @@ private static void OnPossessFamiliar(void* pCreature)
{
CNWSCreature creature = CNWSCreature.FromPointer(pCreature);

ProcessEvent(new OnFamiliarPossess
OnFamiliarPossess eventData = ProcessEvent(EventCallbackType.Before, new OnFamiliarPossess
{
Owner = creature.ToNwObject<NwCreature>()!,
Familiar = creature.GetAssociateId((ushort)AssociateType.Familiar).ToNwObject<NwCreature>()!,
});

Hook.CallOriginal(pCreature);
ProcessEvent(EventCallbackType.After, eventData);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public sealed class OnFamiliarUnpossess : IEvent

NwObject IEvent.Context => Owner;

internal sealed unsafe class Factory : HookEventFactory
public sealed unsafe class Factory : HookEventFactory
{
private static FunctionHook<UnpossessFamiliarHook> Hook { get; set; } = null!;

Expand All @@ -31,13 +31,14 @@ private static void OnUnpossessFamiliar(void* pCreature)
{
CNWSCreature creature = CNWSCreature.FromPointer(pCreature);

ProcessEvent(new OnFamiliarUnpossess
OnFamiliarUnpossess eventData = ProcessEvent(EventCallbackType.Before, new OnFamiliarUnpossess
{
Owner = creature.ToNwObject<NwCreature>()!,
Familiar = creature.GetAssociateId((ushort)AssociateType.Familiar).ToNwObject<NwCreature>()!,
});

Hook.CallOriginal(pCreature);
ProcessEvent(EventCallbackType.After, eventData);
}
}
}
Expand Down
Loading

0 comments on commit 2874b42

Please sign in to comment.