Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
jhett12321 committed Apr 18, 2023
2 parents bdde90b + 65dedbb commit 4322170
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 11 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ 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.28
https://github.com/nwn-dotnet/Anvil/compare/v8193.34.27...v8193.34.28

### Fixed
- NwCreature: Fixed an issue where GetAssociates would return an empty list for certain associate types.
- VirtualMachine: Fix an issue where the context object would be incorrectly flagged as invalid.
- Creature.OnDeath: Support Area/Module as the killer of the creature.
- EventService: More reliable handling of game events.

## 8193.34.27
https://github.com/nwn-dotnet/Anvil/compare/v8193.34.26...v8193.34.27

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public sealed class OnDeath : IEvent
/// <summary>
/// Gets the <see cref="NwGameObject"/> that killed <see cref="NwCreature"/>.
/// </summary>
public NwGameObject Killer { get; } = NWScript.GetLastKiller().ToNwObject<NwGameObject>()!;
public NwObject? Killer { get; } = NWScript.GetLastKiller().ToNwObject();

NwObject IEvent.Context => KilledCreature;
}
Expand Down
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 @@ -44,7 +44,7 @@ ScriptHandleResult IScriptDispatcher.ExecuteScript(string? scriptName, uint oidS
return ScriptHandleResult.NotHandled;
}

EventScriptType eventScriptType = (EventScriptType)NWScript.GetCurrentlyRunningEvent();
EventScriptType eventScriptType = (EventScriptType)NWScript.GetCurrentlyRunningEvent(false.ToInt());
if (eventScriptType == EventScriptType.None)
{
return ScriptHandleResult.NotHandled;
Expand Down
2 changes: 1 addition & 1 deletion NWN.Anvil/src/main/API/Objects/NwCreature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2548,7 +2548,7 @@ private List<NwCreature> GetAssociates(AssociateType associateType)
List<NwCreature> associates = new List<NwCreature>();
int type = (int)associateType;

for (int i = 0;; i++)
for (int i = 1;; i++)
{
NwCreature? associate = NWScript.GetAssociate(type, this, i).ToNwObject<NwCreature>();
if (associate == null || associates.Contains(associate))
Expand Down
2 changes: 1 addition & 1 deletion NWN.Anvil/src/main/API/Scripts/CallInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public CallInfo(string scriptName, NwObject? objSelf)
{
ScriptName = scriptName;
ObjectSelf = objSelf;
ScriptType = (EventScriptType)NWScript.GetCurrentlyRunningEvent();
ScriptType = (EventScriptType)NWScript.GetCurrentlyRunningEvent(false.ToInt());
}

/// <summary>
Expand Down
17 changes: 11 additions & 6 deletions NWN.Anvil/src/main/API/Utils/VirtualMachine.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Anvil.Internal;
using Anvil.Services;
using NLog;
using NWN.Core;
Expand Down Expand Up @@ -89,9 +90,9 @@ public void Execute(string scriptName, params (string ParamName, string ParamVal
Execute(scriptName, null, scriptParams);
}

public void ExecuteInScriptContext(System.Action action, uint objectId = NwObject.Invalid, int scriptEventId = 0, bool valid = false)
public void ExecuteInScriptContext(System.Action action, uint objectId = NwObject.Invalid, int scriptEventId = 0)
{
int spBefore = PushScriptContext(objectId, scriptEventId, valid);
int spBefore = PushScriptContext(objectId, scriptEventId);
try
{
action();
Expand All @@ -106,9 +107,9 @@ public void ExecuteInScriptContext(System.Action action, uint objectId = NwObjec
}
}

public T ExecuteInScriptContext<T>(System.Func<T> action, uint objectId = NwObject.Invalid, int scriptEventId = 0, bool valid = false)
public T ExecuteInScriptContext<T>(System.Func<T> action, uint objectId = NwObject.Invalid, int scriptEventId = 0)
{
int spBefore = PushScriptContext(objectId, scriptEventId, valid);
int spBefore = PushScriptContext(objectId, scriptEventId);

try
{
Expand Down Expand Up @@ -181,9 +182,10 @@ private int PopScriptContext()
return virtualMachine.m_cRunTimeStack.GetStackPointer();
}

private int PushScriptContext(uint oid, int scriptEventId, bool valid)
private int PushScriptContext(uint oid, int scriptEventId)
{
CNWVirtualMachineCommands cmd = CNWVirtualMachineCommands.FromPointer(virtualMachine.m_pCmdImplementer.Pointer);
bool valid = LowLevel.ServerExoApp.GetGameObject(oid) != null;

if (virtualMachine.m_nRecursionLevel++ == -1)
{
Expand All @@ -196,7 +198,10 @@ private int PushScriptContext(uint oid, int scriptEventId, bool valid)
virtualMachine.m_oidObjectRunScript[virtualMachine.m_nRecursionLevel] = oid;
virtualMachine.m_bValidObjectRunScript[virtualMachine.m_nRecursionLevel] = valid.ToInt();

virtualMachine.m_pVirtualMachineScript[virtualMachine.m_nRecursionLevel].m_nScriptEventID = scriptEventId;
CVirtualMachineScript script = virtualMachine.m_pVirtualMachineScript[virtualMachine.m_nRecursionLevel];
script.m_nScriptEventID = scriptEventId;

virtualMachine.m_pVirtualMachineScript[virtualMachine.m_nRecursionLevel] = script;
cmd.m_oidObjectRunScript = virtualMachine.m_oidObjectRunScript[virtualMachine.m_nRecursionLevel];
cmd.m_bValidObjectRunScript = virtualMachine.m_bValidObjectRunScript[virtualMachine.m_nRecursionLevel];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Anvil.Services
{
public enum ScriptHandleResult
{
NotHandled = -1,
NotHandled = ~0,
Handled = 0,
False = 0,
True = 1,
Expand Down

0 comments on commit 4322170

Please sign in to comment.