Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class VmNpcInventoryExternalDomain
[Inject] private readonly NpcInventoryService _npcInventoryService;
[Inject] private readonly ProjectileService _projectileService;
[Inject] private readonly GameStateService _gameStateService;
[Inject] private readonly VmCacheService _vmCacheService;

private readonly VmExternalSupport _support;

Expand Down Expand Up @@ -94,15 +95,29 @@ public int Npc_HasReadiedWeapon(NpcInstance npc)
public void CreateInvItem(NpcInstance npc, int itemId)
{
_npcInventoryService.ExtCreateInvItems(npc, itemId, 1);
SetScriptItem(itemId);
_support.LogInstantExternal(nameof(CreateInvItem), npc, itemId);
}

public void CreateInvItems(NpcInstance npc, int itemId, int amount)
{
_npcInventoryService.ExtCreateInvItems(npc, itemId, amount);
SetScriptItem(itemId);
_support.LogInstantExternal(nameof(CreateInvItem), npc, itemId, amount);
}

/// <summary>
/// Like the engine, the created item becomes the scripts' 'item': G2's B_GiveInvItems prints item.name right
/// after CreateInvItems ("Torch - received"). Without it the name was empty and ZenKit logged
/// 'Accessing member "C_ITEM.NAME" without an instance set'.
/// </summary>
private void SetScriptItem(int itemId)
{
var item = _vmCacheService.TryGetItemData(itemId);
if (item != null)
_gameStateService.GothicVm.GlobalItem = item;
}

public void Npc_RemoveInvItem(NpcInstance npc, int itemId)
{
_npcInventoryService.ExtRemoveInvItems(npc, itemId, 1);
Expand Down