/** * Determines if an item is in inventory. * @param io the item * @return <tt>true</tt> if the item is in inventory; <tt>false</tt> * otherwise */ public bool IsInPlayerInventory(BaseInteractiveObject io) { bool f = false; for (int i = Slots.Length - 1; i >= 0; i--) { BaseInteractiveObject ioo = (BaseInteractiveObject)Slots[i].Io; if (ioo != null && ioo.Equals(io)) { f = true; break; } } return(f); }
/// <summary> /// Determines if the player has an item equipped. /// </summary> /// <param name="itemIO">the item</param> /// <returns><tt>true</tt> if the player has the item equipped; <tt>false</tt> otherwise</returns> public bool IsPlayerEquip(BaseInteractiveObject itemIO) { bool isEquipped = false; int i = ProjectConstants.Instance.GetMaxEquipped() - 1; for (; i >= 0; i--) { if (this.GetEquippedItem(i) >= 0 && Interactive.Instance.HasIO(GetEquippedItem(i))) { BaseInteractiveObject toequip = Interactive.Instance.GetIO(GetEquippedItem(i)); if (toequip.Equals(itemIO)) { isEquipped = true; break; } } } return(isEquipped); }
/// <summary> /// Forces the IONpcData to die. /// </summary> /// <param name="killerIO">the BaseInteractiveObject that killed the IONpcData</param> public void ForceDeath(BaseInteractiveObject killerIO) { if (io.Mainevent == null || (io.Mainevent != null && !string.Equals(io.Mainevent, "DEAD", StringComparison.OrdinalIgnoreCase))) { BaseInteractiveObject oldSender = Script.Instance.EventSender; Script.Instance.EventSender = killerIO; // TODO - reset drag BaseInteractiveObject // if (io == DRAGINTER) // Set_DragInter(NULL); // TODO - reset flying over (with mouse) BaseInteractiveObject // if (io == FlyingOverIO) // FlyingOverIO = NULL; // TODO - reset camera 1 when pointing to BaseInteractiveObject // if ((MasterCamera.exist & 1) && (MasterCamera.io == io)) // MasterCamera.exist = 0; // TODO - reset camera 2 when pointing to BaseInteractiveObject // if ((MasterCamera.exist & 2) && (MasterCamera.want_io == io)) // MasterCamera.exist = 0; // TODO - kill dynamic lighting for BaseInteractiveObject // if (ValidDynLight(io->dynlight)) // DynLight[io->dynlight].exist = 0; // io->dynlight = -1; // if (ValidDynLight(io->halo.dynlight)) // DynLight[io->halo.dynlight].exist = 0; // io->halo.dynlight = -1; // reset all behaviors ResetBehavior(); // TODO - kill speeches // ARX_SPEECH_ReleaseIOSpeech(io); // Kill all Timers... Script.Instance.TimerClearByIO(io); if (io.Mainevent == null || (io.Mainevent != null && !string.Equals(io.Mainevent, "DEAD", StringComparison.OrdinalIgnoreCase))) { Script.Instance.NotifyIOEvent(io, ScriptConsts.SM_017_DIE, ""); } if (Interactive.Instance.HasIO(io)) { io.Mainevent = "DEAD"; // TODO - kill animations // if (EEDistance3D(&io_dead->pos, &ACTIVECAM->pos) > 3200) { // io_dead->animlayer[0].ctime = 9999999; // io_dead->lastanimtime = 0; // } // set killer String killer = ""; WeaponInHand = -1; Interactive.Instance.DestroyDynamicInfo(io); // set killer name if (killerIO != null && killerIO.HasIOFlag(IoGlobals.IO_01_PC)) { killer = "PLAYER"; } else if (killerIO != null && killerIO.HasIOFlag(IoGlobals.IO_03_NPC)) { killer = killerIO.NpcData.Name; } int i = Interactive.Instance.GetMaxIORefId(); for (; i >= 0; i--) { if (!Interactive.Instance.HasIO(i)) { continue; } BaseInteractiveObject ioo = Interactive.Instance.GetIO(i); if (ioo == null) { continue; } if (ioo.Equals(io)) { continue; } if (ioo.HasIOFlag(IoGlobals.IO_03_NPC)) { if (Interactive.Instance.HasIO(ioo.Targetinfo)) { if (Interactive.Instance.GetIO(ioo.Targetinfo).Equals(io)) { Script.Instance.EventSender = io; Script.Instance.StackSendIOScriptEvent(ioo, 0, new object[] { "killer", killer }, "onTargetDeath"); ioo.Targetinfo = IoGlobals.TARGET_NONE; ioo.NpcData.Reachedtarget = false; } } // TODO - handle pathfinding target cleanup // if (ValidIONum(ioo->_npcdata->pathfind.truetarget)) { // if (inter.iobj[ioo->_npcdata->pathfind.truetarget] == // io_dead) { // EVENT_SENDER = io_dead; // Stack_SendIOScriptEvent(inter.iobj[i], 0, killer, // "TARGET_DEATH"); // ioo->_npcdata->pathfind.truetarget = TARGET_NONE; // ioo->_npcdata->reachedtarget = 0; // } // } } } // TODO - kill animations // IO_UnlinkAllLinkedObjects(io_dead); // io_dead->animlayer[1].cur_anim = NULL; // io_dead->animlayer[2].cur_anim = NULL; // io_dead->animlayer[3].cur_anim = NULL; // reduce life to 0 AdjustLife(-99999); if (Weapon != null) { BaseInteractiveObject wpnIO = Weapon; if (Interactive.Instance.HasIO(wpnIO)) { wpnIO.Show = IoGlobals.SHOW_FLAG_IN_SCENE; wpnIO.AddIOFlag(IoGlobals.IO_07_NO_COLLISIONS); // TODO - reset positioning and velocity // ioo->pos.x = // ioo->obj->vertexlist3[ioo->obj->origin].v.x; // ioo->pos.y = // ioo->obj->vertexlist3[ioo->obj->origin].v.y; // ioo->pos.z = // ioo->obj->vertexlist3[ioo->obj->origin].v.z; // ioo->velocity.x = 0.f; // ioo->velocity.y = 13.f; // ioo->velocity.z = 0.f; // ioo->stopped = 0; } } } Script.Instance.EventSender = oldSender; } }
/// <summary> /// Equips the item on a target BaseInteractiveObject. /// </summary> /// <param name="target">the target <see cref="BaseInteractiveObject"/></param> public virtual void Equip(BaseInteractiveObject target) { if (Io == null) { throw new RPGException(ErrorMessage.INTERNAL_ERROR, "Cannot equip item with no BaseInteractiveObject data"); } if (target != null) { if (target.HasIOFlag(IoGlobals.IO_01_PC) || target.HasIOFlag(IoGlobals.IO_03_NPC)) { IOCharacter charData; if (target.HasIOFlag(IoGlobals.IO_01_PC)) { charData = target.PcData; } else { charData = target.NpcData; } int validid = -1; int i = Interactive.Instance.GetMaxIORefId(); for (; i >= 0; i--) { if (Interactive.Instance.HasIO(i) && Interactive.Instance.GetIO(i) != null && io.Equals(Interactive.Instance.GetIO(i))) { validid = i; break; } } if (validid >= 0) { Interactive.Instance.RemoveFromAllInventories(io); io.Show = IoGlobals.SHOW_FLAG_ON_PLAYER; // on player // handle drag // if (toequip == DRAGINTER) // Set_DragInter(NULL); if (io.HasTypeFlag(EquipmentGlobals.OBJECT_TYPE_WEAPON)) { EquipWeapon(charData); } else if (io.HasTypeFlag(EquipmentGlobals.OBJECT_TYPE_SHIELD)) { EquipShield(charData); } else if (io.HasTypeFlag(EquipmentGlobals.OBJECT_TYPE_RING)) { EquipRing(charData); } else if (io.HasTypeFlag(EquipmentGlobals.OBJECT_TYPE_ARMOR)) { // unequip old armor UnequipItemInSlot(charData, EquipmentGlobals.EQUIP_SLOT_TORSO); // equip new armor charData.SetEquippedItem(EquipmentGlobals.EQUIP_SLOT_TORSO, validid); } else if (io.HasTypeFlag(EquipmentGlobals.OBJECT_TYPE_LEGGINGS)) { // unequip old leggings UnequipItemInSlot(charData, EquipmentGlobals.EQUIP_SLOT_LEGGINGS); // equip new leggings charData.SetEquippedItem(EquipmentGlobals.EQUIP_SLOT_LEGGINGS, validid); } else if (io.HasTypeFlag(EquipmentGlobals.OBJECT_TYPE_HELMET)) { // unequip old helmet UnequipItemInSlot(charData, EquipmentGlobals.EQUIP_SLOT_HELMET); // equip new helmet charData.SetEquippedItem(EquipmentGlobals.EQUIP_SLOT_HELMET, validid); } if (io.HasTypeFlag(EquipmentGlobals.OBJECT_TYPE_HELMET) || io.HasTypeFlag(EquipmentGlobals.OBJECT_TYPE_ARMOR) || io.HasTypeFlag(EquipmentGlobals.OBJECT_TYPE_LEGGINGS)) { charData.RecreatePlayerMesh(); } charData.ComputeFullStats(); } } } }
/// <summary> /// Determines if an item can be put in inventory. /// </summary> /// <param name="itemIO">the item</param> /// <returns>true if the item can be put in inventory; false otherwise</returns> public bool CanBePutInInventory(BaseInteractiveObject itemIO) { bool can = false; if (itemIO != null && !itemIO.HasIOFlag(IoGlobals.IO_15_MOVABLE)) { if (itemIO.HasIOFlag(IoGlobals.IO_10_GOLD) && Io.HasIOFlag(IoGlobals.IO_01_PC)) { Io.PcData.AdjustGold(itemIO.ItemData.Price); if (itemIO.ScriptLoaded) { Interactive.Instance.RemoveFromAllInventories(itemIO); Interactive.Instance.ReleaseIO(itemIO); } else { itemIO.Show = IoGlobals.SHOW_FLAG_KILLED; itemIO.RemoveGameFlag(IoGlobals.GFLAG_ISINTREATZONE); } can = true; } if (!can) { // first try to stack for (int i = Slots.Length - 1; i >= 0; i--) { BaseInteractiveObject slotIO = (BaseInteractiveObject)Slots[i].Io; if (slotIO != null && slotIO.ItemData.StackSize > 1 && Interactive.Instance.IsSameObject(itemIO, slotIO)) { // found a matching item - try to stack int slotCount = slotIO.ItemData.Count; int itemCount = itemIO.ItemData.Count; int slotMaxStack = slotIO.ItemData.StackSize; if (slotCount < slotMaxStack) { // there's room to stack more - stack it slotIO.ItemData.AdjustCount(itemCount); // check to see if too many are stacked slotCount = slotIO.ItemData.Count; if (slotCount > slotMaxStack) { // remove excess from stack // and put it back into item io itemIO.ItemData.Count = slotCount - slotMaxStack; slotIO.ItemData.Count = slotMaxStack; } else { // no excess. remove count from item io itemIO.ItemData.Count = 0; } // was item count set to 0? release the BaseInteractiveObject if (itemIO.ItemData.Count == 0) { if (itemIO.ScriptLoaded) { int inner = Interactive.Instance.GetMaxIORefId(); for (; inner >= 0; inner--) { if (Interactive.Instance.HasIO(inner)) { BaseInteractiveObject innerIO = Interactive.Instance.GetIO(inner); if (innerIO.Equals(itemIO)) { Interactive.Instance.ReleaseIO(innerIO); innerIO = null; } } } } else { itemIO.Show = IoGlobals.SHOW_FLAG_KILLED; } } // declare item in inventory DeclareInInventory(Io, slotIO); can = true; break; } } } } // cant stack the item? find an empty slot if (!can) { // find an empty slot for the item for (int i = 0, li = Slots.Length; i < li; i++) { // got an empty slot - add it if (Slots[i].Io == null) { Slots[i].Io = itemIO; Slots[i].Show = true; DeclareInInventory(Io, itemIO); can = true; break; } } } } return(can); }