HoS_PRC8/_mod/_module/nss/unit_inv_h.nss
Jaysyn904 04165202c0 Initial upload
Initial upload
2024-11-25 19:36:07 -05:00

101 lines
3.7 KiB
Plaintext

///////////////////////////////////////////////////////////////////
// unit_inv_h - Handles reequipping of items
// By Deva Bryson Winblood. 04/28/2005
///////////////////////////////////////////////////////////////////
///////////////////////////
// PROTOTYPES
///////////////////////////
// FILE: unit_inv_h FUNCTION: EquipItem()
// This function will attempt to get the NPC to equip the
// specified item.
void EquipItem(object oNPC,object oItem);
// FILE: unit_inv_h FUNCTION: ReturnBelongings()
// This function will return the belongings to the NPC
void ReturnBelongings(object oNPC,object oSource);
///////////////////////////
// FUNCTIONS
///////////////////////////
int fnReturnSlotType(object oItem)
{ // PURPOSE: Return the slot type this item uses when equipped
int nRet=-1;
int nBT=GetBaseItemType(oItem);
if (nBT==BASE_ITEM_AMULET) nRet=INVENTORY_SLOT_NECK;
else if (nBT==BASE_ITEM_ARMOR) nRet=INVENTORY_SLOT_CHEST;
else if (nBT==BASE_ITEM_ARROW) nRet=INVENTORY_SLOT_ARROWS;
else if (nBT==BASE_ITEM_BELT) nRet=INVENTORY_SLOT_BELT;
else if (nBT==BASE_ITEM_BOLT) nRet=INVENTORY_SLOT_BOLTS;
else if (nBT==BASE_ITEM_BOOTS) nRet=INVENTORY_SLOT_BOOTS;
else if (nBT==BASE_ITEM_BULLET) nRet=INVENTORY_SLOT_BULLETS;
else if (nBT==BASE_ITEM_CLOAK) nRet=INVENTORY_SLOT_CLOAK;
else if (nBT==BASE_ITEM_HELMET) nRet=INVENTORY_SLOT_HEAD;
else if (nBT==BASE_ITEM_LARGESHIELD) nRet=INVENTORY_SLOT_LEFTHAND;
else if (nBT==BASE_ITEM_RING) nRet=INVENTORY_SLOT_RIGHTRING;
else if (nBT==BASE_ITEM_SMALLSHIELD) nRet=INVENTORY_SLOT_LEFTHAND;
else if (nBT==BASE_ITEM_TORCH) nRet=INVENTORY_SLOT_LEFTHAND;
else if (nBT==BASE_ITEM_TOWERSHIELD) nRet=INVENTORY_SLOT_LEFTHAND;
else { nRet=INVENTORY_SLOT_RIGHTHAND; }
return nRet;
} // fnReturnSlotType()
void EquipItem(object oNPC,object oItem)
{
int nSlot=fnReturnSlotType(oItem);
object oCurrent=GetItemInSlot(nSlot,oNPC);
if (nSlot==INVENTORY_SLOT_LEFTHAND&&oCurrent==OBJECT_INVALID)
{ // equip
AssignCommand(oNPC,ActionEquipItem(oItem,nSlot));
} // equip
else if (nSlot==INVENTORY_SLOT_RIGHTHAND&&oCurrent==OBJECT_INVALID)
{ // equip
AssignCommand(oNPC,ActionEquipItem(oItem,nSlot));
} // equip
else if (nSlot==INVENTORY_SLOT_RIGHTHAND&&oCurrent!=OBJECT_INVALID)
{ // equip - check left hand and dual wielding options
oCurrent=GetItemInSlot(INVENTORY_SLOT_LEFTHAND,oNPC);
if (GetHasFeat(FEAT_AMBIDEXTERITY,oNPC)||GetHasFeat(FEAT_TWO_WEAPON_FIGHTING,oNPC))
{ // can dual wield
if (oCurrent==OBJECT_INVALID)
{ // equip
AssignCommand(oNPC,ActionEquipItem(oItem,INVENTORY_SLOT_LEFTHAND));
} // equip
} // can dual wield
} // equip - check left hand and dual wielding options
else if (nSlot==INVENTORY_SLOT_RIGHTRING&&oCurrent==OBJECT_INVALID)
{ // equip ring
AssignCommand(oNPC,ActionEquipItem(oItem,nSlot));
} // equip ring
else if (nSlot==INVENTORY_SLOT_RIGHTRING&&oCurrent!=OBJECT_INVALID)
{ // equip ring - try other hand
oCurrent=GetItemInSlot(INVENTORY_SLOT_LEFTRING,oNPC);
if (oCurrent==OBJECT_INVALID)
{ // equip
AssignCommand(oNPC,ActionEquipItem(oItem,INVENTORY_SLOT_LEFTRING));
} // equip
} // equip ring - try other hand
else if (oCurrent==OBJECT_INVALID)
{ // try slot
AssignCommand(oNPC,ActionEquipItem(oItem,nSlot));
} // try slot
} // EquipItem()
void ReturnBelongings(object oNPC,object oSource)
{
object oItem=GetFirstItemInInventory(oSource);
int nSS;
while(oItem!=OBJECT_INVALID)
{ // copy over items
nSS=GetItemStackSize(oItem);
CreateItemOnObject(GetResRef(oItem),oNPC,nSS);
DelayCommand(0.5,DestroyObject(oItem));
oItem=GetNextItemInInventory(oSource);
} // copy over items
} // ReturnBelongings()
//void main(){}