Skip to content

Commit 297aa0d

Browse files
committed
Merge branch 'development'
2 parents f644f92 + 9e864a8 commit 297aa0d

File tree

5 files changed

+60
-4
lines changed

5 files changed

+60
-4
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ All notable changes to this project will be documented in this file.
33

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

6+
## 8193.34.8
7+
https://github.com/nwn-dotnet/Anvil/compare/v8193.34.7...v8193.34.8
8+
9+
### Deprecated
10+
- `NwObject.Destroy(float delay)` - Use the non-delay overload instead, with the `SchedulerService`.
11+
12+
### Fixed
13+
- Fixed `NwEncounter.Destroy()` not destroying the encounter object.
14+
- Fixed `PlaceableEvents.OnPhysicalAttacked` event always returning no data.
15+
616
## 8193.34.7
717
https://github.com/nwn-dotnet/Anvil/compare/v8193.34.6...v8193.34.7
818

NWN.Anvil.Tests/src/main/API/Object/NwEncounterTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,29 @@ public void CreateEncounterIsCreated(string encounterResRef)
3232
createdTestObjects.Add(encounter);
3333
}
3434

35+
[Test(Description = "Creating a encounter and destroying it destroys the encounter.")]
36+
[TestCase(StandardResRef.Encounter.x2_beholder001)]
37+
[TestCase(StandardResRef.Encounter.x2_golem001)]
38+
[TestCase(StandardResRef.Encounter.nw_dragonweak)]
39+
[TestCase(StandardResRef.Encounter.x2_lich001)]
40+
[TestCase(StandardResRef.Encounter.x2_mindflay001)]
41+
[TestCase(StandardResRef.Encounter.nw_mummies)]
42+
[TestCase(StandardResRef.Encounter.x2_slaad001)]
43+
[TestCase(StandardResRef.Encounter.x2_undead001)]
44+
[TestCase(StandardResRef.Encounter.nw_undeadhigh)]
45+
[TestCase(StandardResRef.Encounter.x2_beholder001)]
46+
public void DestroyEncounterIsDestroyed(string encounterResRef)
47+
{
48+
Location startLocation = NwModule.Instance.StartingLocation;
49+
NwEncounter encounter = NwEncounter.Create(encounterResRef, startLocation);
50+
51+
Assert.That(encounter, Is.Not.Null, $"Encounter {encounterResRef} was null after creation.");
52+
Assert.That(encounter.IsValid, Is.True, $"Encounter {encounterResRef} was invalid after creation.");
53+
54+
encounter.Destroy();
55+
Assert.That(encounter.IsValid, Is.False, $"Encounter {encounterResRef} was still valid after deletion.");
56+
}
57+
3558
[TearDown]
3659
public void CleanupTestObjects()
3760
{

NWN.Anvil/src/main/API/Events/Game/PlaceableEvents/PlaceableEvents.OnPhysicalAttacked.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,27 @@ public static partial class PlaceableEvents
1515
[GameEvent(EventScriptType.PlaceableOnMeleeAttacked)]
1616
public sealed class OnPhysicalAttacked : IEvent
1717
{
18+
public OnPhysicalAttacked()
19+
{
20+
Placeable = NWScript.OBJECT_SELF.ToNwObject<NwPlaceable>();
21+
Attacker = NWScript.GetLastAttacker(Placeable).ToNwObject<NwCreature>();
22+
AttackType = (SpecialAttack)NWScript.GetLastAttackType(Attacker);
23+
}
24+
1825
/// <summary>
1926
/// Gets the <see cref="NwCreature"/> that attacked the <see cref="NwPlaceable"/>.
2027
/// </summary>
21-
public NwCreature Attacker { get; } = NWScript.GetLastAttacker().ToNwObject<NwCreature>();
28+
public NwCreature Attacker { get; }
2229

2330
/// <summary>
2431
/// Gets the <see cref="SpecialAttack"/> used to damage <see cref="NwPlaceable"/>.
2532
/// </summary>
26-
public SpecialAttack AttackType { get; } = (SpecialAttack)NWScript.GetLastAttackType();
33+
public SpecialAttack AttackType { get; }
2734

2835
/// <summary>
2936
/// Gets the <see cref="NwPlaceable"/> that was physically attacked.
3037
/// </summary>
31-
public NwPlaceable Placeable { get; } = NWScript.OBJECT_SELF.ToNwObject<NwPlaceable>();
38+
public NwPlaceable Placeable { get; }
3239

3340
NwObject IEvent.Context => Placeable;
3441

NWN.Anvil/src/main/API/Object/NwEncounter.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,13 @@ public override byte[] Serialize()
251251
});
252252
}
253253

254+
public override void Destroy()
255+
{
256+
RemoveFromArea();
257+
CNWSEncounter encounter = CNWSEncounter.FromPointer(Encounter.Pointer, true);
258+
encounter.Dispose();
259+
}
260+
254261
internal override void RemoveFromArea()
255262
{
256263
Encounter.RemoveFromArea();

NWN.Anvil/src/main/API/Object/NwGameObject.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,20 @@ public void ApplyEffect(EffectDuration durationType, Effect effect, TimeSpan dur
250250
/// Destroys this object (irrevocably).
251251
/// </summary>
252252
/// <param name="delay">Time in seconds until this object should be destroyed.</param>
253-
public void Destroy(float delay = 0.0f)
253+
[Obsolete("Use the non-delay overload instead, in combination with the scheduler service or async/await.")]
254+
public void Destroy(float delay)
254255
{
255256
NWScript.DestroyObject(this, delay);
256257
}
257258

259+
/// <summary>
260+
/// Destroys this object (irrevocably).
261+
/// </summary>
262+
public virtual void Destroy()
263+
{
264+
NWScript.DestroyObject(this);
265+
}
266+
258267
/// <summary>
259268
/// Returns the distance to the target.<br/>
260269
/// If you only need to compare the distance, you can compare the squared distance using <see cref="DistanceSquared"/> to avoid a costly sqrt operation.

0 commit comments

Comments
 (0)