Skip to content

Commit

Permalink
xrGame/Inventory.cpp: fix using of eatable items for NPC
Browse files Browse the repository at this point in the history
  • Loading branch information
ChugunovRoman committed Dec 15, 2024
1 parent bc91f16 commit c2bf09e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/xrGame/Inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ bool CInventory::Eat(PIItem pIItem)
if (pItemToEat->object().H_Parent()->ID() != entity_alive->ID())
return false;

if (g_enhancend_anims && pSettings->line_exist(pIItem->m_section_id, "hud"))
if (g_enhancend_anims && m_pOwner->object_id() == 0 && pSettings->line_exist(pIItem->m_section_id, "hud"))
{
if (CCustomDetector* detector = smart_cast<CCustomDetector*>(Actor()->inventory().ItemFromSlot(DETECTOR_SLOT)))
{
Expand Down
32 changes: 26 additions & 6 deletions src/xrGame/eatable_item_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,28 @@ void CEatableItemObject::OnStateSwitch(u32 S, u32 oldState)
{
case eShowing:
{
g_player_hud[0]->attach_item(this);
m_sounds.PlaySound("useAnmSound", Fvector().set(0, 0, 0), this, true, false);
PlayHUDMotion("anm_use", "anim_use", FALSE, this, GetState());
PlayCamAnim("cam_anm_use");
SetPending(true);
if (Parent)
{
CInventoryOwner* m_pOwner = Parent->cast_inventory_owner();
if (m_pOwner && m_pOwner->object_id() == 0)
{
g_player_hud[0]->attach_item(this);
m_sounds.PlaySound("useAnmSound", Fvector().set(0, 0, 0), this, true, false);
PlayHUDMotion("anm_use", "anim_use", FALSE, this, GetState());
PlayCamAnim("cam_anm_use");
SetPending(true);
}
else
{
UseBy();
SwitchState(eHiding);
}
}
else
{
UseBy();
SwitchState(eHiding);
}
}
break;
case eHiding:
Expand Down Expand Up @@ -284,8 +301,11 @@ void CEatableItemObject::RemoveItemIfNecessaryOrMoveToRuck()
}
void CEatableItemObject::RestoreSlot()
{
if (!Parent)
return;

CInventoryOwner* m_pOwner = Parent->cast_inventory_owner();
if (!m_pOwner)
if (!m_pOwner || m_pOwner->object_id() != 0)
return;

m_pOwner->inventory().SetActiveSlot(prev_slot);
Expand Down

0 comments on commit c2bf09e

Please sign in to comment.