/// <summary> /// Determines if a summoned BaseInteractiveObject's summoner is a IOPcData. /// </summary> /// <param name="io">the <see cref="BaseInteractiveObject"/></param> /// <returns>true if the summoner is a player; false otherwise</returns> private bool SummonerIsPlayer(BaseInteractiveObject io) { bool isPlayer = false; if (io != null) { int summonerId = io.Summoner; if (Interactive.Instance.HasIO(summonerId)) { BaseInteractiveObject summoner = Interactive.Instance.GetIO(summonerId); if (summoner.HasIOFlag(IoGlobals.IO_01_PC)) { isPlayer = true; } summoner = null; } } return(isPlayer); }
/// <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); }
public override bool Equals(System.Object obj) { bool equals = false; if (this == obj) { equals = true; } else if (obj != null && obj is BaseInteractiveObject) { BaseInteractiveObject other = (BaseInteractiveObject)obj; if (this.dmgFlags == other.dmgFlags && this.gameFlags == other.gameFlags && this.ioFlags == other.ioFlags && this.numberOfSpellsOn == other.numberOfSpellsOn && this.RefId == other.RefId) { equals = true; } } return(equals); }
/// <summary> /// Gets the total modifier for a specific element type from the equipment the player is wielding. /// </summary> /// <param name="elementType">the type of element</param> /// <returns>float</returns> public float ApplyEquipmentModifiers(int elementType) { float toadd = 0; for (int i = ProjectConstants.Instance.GetMaxEquipped() - 1; i >= 0; i--) { if (equippedItems[i] >= 0 && Interactive.Instance.HasIO(equippedItems[i])) { BaseInteractiveObject toequip = Interactive.Instance.GetIO(equippedItems[i]); if (toequip.HasIOFlag(IoGlobals.IO_02_ITEM) && toequip.ItemData != null && toequip.ItemData.Equipitem != null) { EquipmentItemModifier element = toequip.ItemData.Equipitem.GetElementModifier(elementType); if (!element.Percent) { toadd += element.Value; } } } } return(toadd); }
/// <summary> /// Sends the IONpcData BaseInteractiveObject a 'Hit' event. /// </summary> /// <param name="dmg">the amount of damage</param> /// <param name="srcIoid">the source of the damage</param> /// <param name="isSpellDamage">flag indicating whether the damage is from a spell</param> /// <returns></returns> private int SendHitEvent(float dmg, int srcIoid, bool isSpellDamage) { //UnityEngine.Debug.Log("IONpcData.SendHitEvent"); if (Interactive.Instance.HasIO(srcIoid)) { Script.Instance.EventSender = Interactive.Instance.GetIO(srcIoid); } else { Script.Instance.EventSender = null; } Object[] p; if (Script.Instance.EventSender != null && Script.Instance.EventSender.HasIOFlag(IoGlobals.IO_01_PC)) { BaseInteractiveObject plrIO = Script.Instance.EventSender; if (isSpellDamage) { p = new Object[] { "SPELL_DMG", dmg }; } else { int wpnId = plrIO.PcData.GetEquippedItem(EquipmentGlobals.EQUIP_SLOT_WEAPON); BaseInteractiveObject wpnIO = Interactive.Instance.GetIO(wpnId); int wpnType = EquipmentGlobals.WEAPON_BARE; if (wpnIO != null) { wpnType = wpnIO.ItemData.GetWeaponType(); } switch (wpnType) { case EquipmentGlobals.WEAPON_BARE: p = new Object[] { "BARE_DMG", dmg }; break; case EquipmentGlobals.WEAPON_DAGGER: p = new Object[] { "DAGGER_DMG", dmg }; break; case EquipmentGlobals.WEAPON_1H: p = new Object[] { "1H_DMG", dmg }; break; case EquipmentGlobals.WEAPON_2H: p = new Object[] { "2H_DMG", dmg }; break; case EquipmentGlobals.WEAPON_BOW: p = new Object[] { "ARROW_DMG", dmg }; break; default: p = new Object[] { "DMG", dmg }; break; } wpnIO = null; } plrIO = null; } else { p = new Object[] { "DMG", dmg }; } // if player summoned object causing damage, // change event sender to player if (SummonerIsPlayer(Script.Instance.EventSender)) { BaseInteractiveObject summonerIO = Interactive.Instance.GetIO(Script.Instance.EventSender.Summoner); Script.Instance.EventSender = summonerIO; summonerIO = null; p = new Object[] { "SUMMONED_DMG", dmg }; } else { p = new Object[] { "SUMMONED_OUCH", 0f, "OUCH", io.DamageSum }; } return(Script.Instance.SendIOScriptEvent(io, ScriptConsts.SM_016_HIT, p, null)); }
/// <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; } }
protected abstract void AwardXpForNpcDeath(int xp, BaseInteractiveObject killerIO);
public void GetTargetPos(BaseInteractiveObject io, long smoothing) { if (io == null) { return; } if (io.HasIOFlag(IoGlobals.IO_03_NPC)) { if (io.NpcData.HasBehavior(MobBehaviour.BEHAVIOUR_NONE)) { /* * io.Target.setX(io.getPosition().getX()); * io.Target.setY(io.getPosition().getY()); * io.Target.setZ(0); */ return; } if (io.NpcData.HasBehavior(MobBehaviour.BEHAVIOUR_GO_HOME)) { /* * if (io.NpcData.getPathfinding().getListPosition() < io * .NpcData.getPathfinding().getListnb()) * { * long pos = io.NpcData.getPathfinding().getListItem( * io.NpcData.getPathfinding().getListPosition()); * // io.Target.setX(ACTIVEBKG->anchors[pos].pos.x; * // io.Target.setY(ACTIVEBKG->anchors[pos].pos.y; * // io.Target.setZ(ACTIVEBKG->anchors[pos].pos.z; * return; * } * io.Target.setX(io.getInitPosition().getX()); * io.Target.setY(io.getInitPosition().getY()); * io.Target.setZ(0); */ return; } /* * if (io.HasIOFlag(IoGlobals.IO_03_NPC) * && io.NpcData.getPathfinding().getListnb() != -1 * && io.NpcData.getPathfinding().hasList() * && !io.NpcData.HasBehavior(Behaviour.BEHAVIOUR_FRIENDLY)) * { * // Targeting Anchors ! * if (io.NpcData.getPathfinding().getListPosition() < io * .NpcData.getPathfinding().getListnb()) * { * long pos = io.NpcData.getPathfinding().getListItem( * io.NpcData.getPathfinding().getListPosition()); * // io.Target.setX(ACTIVEBKG->anchors[pos].pos.x; * // io.Target.setY(ACTIVEBKG->anchors[pos].pos.y; * // io.Target.setZ(ACTIVEBKG->anchors[pos].pos.z; * } * else if (Interactive.Instance.HasIO( * io.NpcData.getPathfinding().getTruetarget())) * { * BaseInteractiveObject ioo = (BaseInteractiveObject)Interactive.Instance.GetIO( * io.NpcData.getPathfinding() * .getTruetarget()); * io.Target.setX(ioo.getPosition().getX()); * io.Target.setY(ioo.getPosition().getY()); * io.Target.setZ(0); * } * return; * } */ } if (io.Targetinfo == ScriptConsts.TARGET_PATH) { // if (io->usepath == NULL) // { // io->target.x = io->pos.x; // io->target.y = io->pos.y; // io->target.z = io->pos.z; // return; // } // ARX_USE_PATH * aup = (ARX_USE_PATH *)io->usepath; // aup->_curtime += smoothing + 100; // EERIE_3D tp; // long wp = ARX_PATHS_Interpolate(aup, &tp); // if (wp < 0) // { // if (io->ioflags & IO_CAMERA) // io->_camdata->cam.lastinfovalid = FALSE; // } // else // { // io->target.x = tp.x; // io->target.y = tp.y; // io->target.z = tp.z; // } // return; } if (io.Targetinfo == ScriptConsts.TARGET_NONE) { /* * io.Target.setX(io.getPosition().getX()); * io.Target.setY(io.getPosition().getY()); * io.Target.setZ(0); */ return; } if (io.Targetinfo == ScriptConsts.TARGET_PLAYER || io.Targetinfo == -1) { /* * BaseInteractiveObject player = (BaseInteractiveObject)Interactive.Instance.GetIO(ProjectConstants.Instance.GetPlayer()); * io.Target.setX(player.getPosition().getX()); * io.Target.setY(player.getPosition().getY()); * io.Target.setZ(0); * player = null; */ return; } else { if (Interactive.Instance.HasIO(io.Targetinfo)) { /* * BaseInteractiveObject tio = (BaseInteractiveObject)Interactive.Instance.GetIO(io.Targetinfo); * Vector2 pos = new Vector2(); * if (Interactive.Instance.GetItemWorldPosition(tio, pos)) * { * io.Target.setX(pos.getX()); * io.Target.setY(pos.getY()); * io.Target.setZ(0); * return; * } * io.Target.setX(tio.getPosition().getX()); * io.Target.setY(tio.getPosition().getY()); * io.Target.setZ(0); */ return; } } /* * io.Target.setX(io.getPosition().getX()); * io.Target.setY(io.getPosition().getY()); * io.Target.setZ(0); */ }
/** * Equips a ring on a character. * @param charData the character data * @ if an error occurs */ private void EquipRing(IOCharacter charData) { // check left and right finger // to see if it can be equipped bool canEquip = true; int ioid = charData.GetEquippedItem(EquipmentGlobals.EQUIP_SLOT_RING_LEFT); if (Interactive.Instance.HasIO(ioid)) { BaseInteractiveObject oldRing = Interactive.Instance.GetIO(ioid); if (oldRing.ItemData.RingType == RingType) { // already wearing that type // of ring on left finger canEquip = false; } } if (canEquip) { ioid = charData.GetEquippedItem(EquipmentGlobals.EQUIP_SLOT_RING_RIGHT); if (Interactive.Instance.HasIO(ioid)) { BaseInteractiveObject oldRing = Interactive.Instance.GetIO(ioid); if (oldRing.ItemData.RingType == RingType) { // already wearing that type // of ring on right finger canEquip = false; } } } if (canEquip) { int equipSlot = -1; if (charData.GetEquippedItem( EquipmentGlobals.EQUIP_SLOT_RING_LEFT) < 0) { equipSlot = EquipmentGlobals.EQUIP_SLOT_RING_LEFT; } if (charData.GetEquippedItem( EquipmentGlobals.EQUIP_SLOT_RING_RIGHT) < 0) { equipSlot = EquipmentGlobals.EQUIP_SLOT_RING_RIGHT; } if (equipSlot == -1) { if (!charData.GetIo().Inventory.LeftRing) { ioid = charData.GetEquippedItem(EquipmentGlobals.EQUIP_SLOT_RING_RIGHT); if (Interactive.Instance.HasIO(ioid)) { BaseInteractiveObject oldIO = Interactive.Instance.GetIO(ioid); if (oldIO.HasIOFlag(IoGlobals.IO_02_ITEM)) { UnequipItemInSlot(charData, EquipmentGlobals.EQUIP_SLOT_RING_RIGHT); } } equipSlot = EquipmentGlobals.EQUIP_SLOT_RING_RIGHT; } else { ioid = charData.GetEquippedItem(EquipmentGlobals.EQUIP_SLOT_RING_LEFT); if (Interactive.Instance.HasIO(ioid)) { BaseInteractiveObject oldIO = Interactive.Instance.GetIO(ioid); if (oldIO.HasIOFlag(IoGlobals.IO_02_ITEM)) { UnequipItemInSlot(charData, EquipmentGlobals.EQUIP_SLOT_RING_LEFT); } } equipSlot = EquipmentGlobals.EQUIP_SLOT_RING_LEFT; } charData.GetIo().Inventory.LeftRing = !charData.GetIo().Inventory.LeftRing; } charData.SetEquippedItem(equipSlot, io.RefId); } }
/// <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> /// Damages the player. /// </summary> /// <param name="dmg">the damage amount</param> /// <param name="type">the type of damage</param> /// <param name="source">the source reference id of the damage (if attacked, should be the attacker)</param> /// <returns>the total damage done</returns> public virtual float DamagePlayer(float dmg, long type, int source) { Debug.Log("DamagePlayer(" + dmg); float damagesdone = 0f; ComputeFullStats(); if (!io.HasIOFlag(IoGlobals.PLAYERFLAGS_INVULNERABILITY) && Life > 0) { if (dmg > Life) { damagesdone = Life; } else { damagesdone = dmg; } io.DamageSum += dmg; // TODO - add timer for ouch // if (ARXTime > inter.iobj[0]->ouch_time + 500) { BaseInteractiveObject oes = Script.Instance.EventSender; if (Interactive.Instance.HasIO(source)) { Script.Instance.EventSender = Interactive.Instance.GetIO(source); } else { Script.Instance.EventSender = null; } Script.Instance.SendIOScriptEvent(io, ScriptConsts.SM_045_OUCH, new object[] { "OUCH", io.DamageSum, "SUMMONED_OUCH", 0f }, null); Script.Instance.EventSender = oes; io.DamageSum = 0; // } if (dmg > 0f) { if (Interactive.Instance.HasIO(source)) { BaseInteractiveObject poisonWeaponIO = null; BaseInteractiveObject sourceIO = Interactive.Instance.GetIO(source); if (sourceIO.HasIOFlag(IoGlobals.IO_03_NPC)) { poisonWeaponIO = sourceIO.NpcData.Weapon; if (poisonWeaponIO != null && (poisonWeaponIO.PoisonLevel == 0 || poisonWeaponIO.PoisonCharges == 0)) { poisonWeaponIO = null; } } if (poisonWeaponIO == null) { poisonWeaponIO = sourceIO; } if (poisonWeaponIO != null && poisonWeaponIO.PoisonLevel > 0 && poisonWeaponIO.PoisonCharges > 0) { // TODO - handle poisoning if (poisonWeaponIO.PoisonCharges > 0) { poisonWeaponIO.PoisonCharges--; } } } bool alive; if (Life > 0) { alive = true; } else { alive = false; } AdjustLife(-dmg); if (Life <= 0f) { AdjustLife(-Life); if (alive) { // TODO - what is this? // REFUSE_GAME_RETURN = true; BecomesDead(); // TODO - play fire sounds // if (type & DAMAGE_TYPE_FIRE // || type & DAMAGE_TYPE_FAKEFIRE) { // ARX_SOUND_PlayInterface(SND_PLAYER_DEATH_BY_FIRE); // } Script.Instance.SendIOScriptEvent(io, ScriptConsts.SM_017_DIE, null, null); int i = Interactive.Instance.GetMaxIORefId(); for (; i >= 0; i--) { if (!Interactive.Instance.HasIO(i)) { continue; } BaseInteractiveObject ioo = Interactive.Instance.GetIO(i); // tell all IOs not to target player anymore if (ioo != null && ioo.HasIOFlag(IoGlobals.IO_03_NPC)) { if (ioo.Targetinfo == io.RefId || ioo.Targetinfo == IoGlobals.TARGET_PLAYER) { Script.Instance.EventSender = io; String killer = ""; if (source == io.RefId) { killer = "PLAYER"; } else if (source <= -1) { killer = "NONE"; } else if (Interactive.Instance.HasIO(source)) { BaseInteractiveObject sourceIO = Interactive.Instance.GetIO(source); if (sourceIO.HasIOFlag(IoGlobals.IO_03_NPC)) { killer = sourceIO.NpcData.Name; } } Script.Instance.SendIOScriptEvent(ioo, 0, new System.Object[] { "tmp_int1", source }, "TargetDeath"); } } } } } } } return(damagesdone); }
/// <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); }
/** * Puts an item in front of the player. * @param itemIO the item * @param doNotApplyPhysics if <tt>true</tt>, do not apply physics */ public abstract void PutInFrontOfPlayer(BaseInteractiveObject itemIO, bool doNotApplyPhysics);