/// <summary> /// Applies extra damage from a poisoned attack. /// </summary> /// <param name="srcIoid">the source of the damage</param> /// <param name="isSpellDamage">flag indicating whether the damage is from a spell</param> private void ApplyPoisonDamage(int srcIoid, bool isSpellDamage) { if (Interactive.Instance.HasIO(srcIoid)) { BaseInteractiveObject poisonWeaponIO = null; BaseInteractiveObject sourceIO = Interactive.Instance.GetIO( srcIoid); if (sourceIO.HasIOFlag(IoGlobals.IO_01_PC)) { IOPcData player = sourceIO.PcData; if (player.GetEquippedItem(EquipmentGlobals.EQUIP_SLOT_WEAPON) > 0 && Interactive.Instance.HasIO(player.GetEquippedItem(EquipmentGlobals.EQUIP_SLOT_WEAPON))) { poisonWeaponIO = Interactive.Instance.GetIO(player.GetEquippedItem(EquipmentGlobals.EQUIP_SLOT_WEAPON)); if (poisonWeaponIO != null && (poisonWeaponIO.PoisonLevel == 0 || poisonWeaponIO.PoisonCharges == 0) || isSpellDamage) { poisonWeaponIO = null; } } } else { 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 - apply poison damage // reduce poison level on attacking weapon if (poisonWeaponIO.PoisonCharges > 0) { poisonWeaponIO.PoisonCharges--; } } sourceIO = null; poisonWeaponIO = null; } }
private float ProcessDamage(float dmg, int srcIoid) { float damagesdone = Math.Min(dmg, Life); AdjustLife(-dmg); if (Life <= 0f) { // IONpcData is dead // base life should be 0 if (Interactive.Instance.HasIO(srcIoid)) { int xp = Xpvalue; BaseInteractiveObject srcIO = Interactive.Instance.GetIO(srcIoid); ForceDeath(srcIO); if (srcIO.HasIOFlag(IoGlobals.IO_01_PC)) { AwardXpForNpcDeath(xp, srcIO); } } else { ForceDeath(null); } } return(damagesdone); }
/// <summary> /// Removes all the player's equipment. /// </summary> public void UnEquipAll() { int i = ProjectConstants.Instance.GetMaxEquipped() - 1; for (; i >= 0; i--) { if (equippedItems[i] >= 0) { if (!Interactive.Instance.HasIO(equippedItems[i])) { throw new RPGException(ErrorMessage.INVALID_DATA_TYPE, "Equipped unregistered item in slot " + i); } BaseInteractiveObject itemIO = Interactive.Instance.GetIO(equippedItems[i]); if (!itemIO.HasIOFlag(IoGlobals.IO_02_ITEM)) { throw new RPGException(ErrorMessage.INVALID_DATA_TYPE, "Equipped item without IO_02_ITEM in slot " + i); } if (itemIO.ItemData == null) { throw new RPGException(ErrorMessage.INVALID_DATA_TYPE, "Equipped item with null item data in slot " + i); } itemIO.ItemData.UnEquip(GetIo(), false); } } ComputeFullStats(); }
/// <summary> /// Gets the total percentage modifier for a specific element type from the equipment the player is wielding. /// </summary> /// <param name="elementType">the type of element</param> /// <param name="trueval">the true value being modified</param> /// <returns>float</returns> public float ApplyEquipmentPercentModifiers(int elementType, float trueval) { float toadd = 0; int i = ProjectConstants.Instance.GetMaxEquipped() - 1; for (; 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 * trueval * MathGlobals.DIV100); }
/** * Replaces an item in all inventories. * @param oldItemIO the old item being replaced * @param newItemIO the new item * @ if an error occurs */ public void ReplaceInAllInventories(BaseInteractiveObject oldItemIO, BaseInteractiveObject newItemIO) { if (oldItemIO != null && !oldItemIO.HasIOFlag(IoGlobals.IO_15_MOVABLE) && newItemIO != null && !newItemIO.HasIOFlag(IoGlobals.IO_15_MOVABLE)) { int oldIORefId = Interactive.Instance.GetInterNum(oldItemIO); int newIORefId = Interactive.Instance.GetInterNum(newItemIO); int i = Interactive.Instance.GetMaxIORefId(); for (; i >= 0; i--) { if (i == oldIORefId || i == newIORefId || !Interactive.Instance.HasIO(i)) { continue; } BaseInteractiveObject invOwner = (BaseInteractiveObject)Interactive.Instance.GetIO(i); if (invOwner.Inventory != null) { InventoryData inv = invOwner.Inventory; for (int j = inv.Slots.Length - 1; j >= 0; j--) { if (inv.Slots[j].Io.Equals(oldItemIO)) { inv.Slots[j].Io = newItemIO; } } } } } }
/// <summary> /// Unequips the item from the targeted <see cref="BaseInteractiveObject"/>. /// </summary> /// <param name="target">the targeted <see cref="BaseInteractiveObject"/></param> /// <param name="isDestroyed">if true the item is destroyed afterwards</param> public virtual void UnEquip(BaseInteractiveObject target, bool isDestroyed) { if (target != null) { if (target.HasIOFlag(IoGlobals.IO_01_PC)) { int i = ProjectConstants.Instance.GetMaxEquipped() - 1; for (; i >= 0; i--) { IOPcData player = target.PcData; int itemRefId = player.GetEquippedItem(i); if (itemRefId >= 0 && Interactive.Instance.HasIO(itemRefId) && Interactive.Instance.GetIO( itemRefId).Equals(io)) { // EERIE_LINKEDOBJ_UnLinkObjectFromObject( // target->obj, tounequip->obj); player.ReleaseEquipment(itemRefId); // target->bbox1.x = 9999; // target->bbox2.x = -9999; if (!isDestroyed) { // if (DRAGINTER == null) { // ARX_SOUND_PlayInterface(SND_INVSTD); // Set_DragInter(tounequip); // } else if (!target.Inventory.CanBePutInInventory(io)) { target.Inventory.PutInFrontOfPlayer(io, true); } } // send event from this item to target to unequip Script.Instance.EventSender = io; Script.Instance.SendIOScriptEvent(target, ScriptConsts.SM_007_EQUIPOUT, null, null); // send event from target to this item to unequip Script.Instance.EventSender = target; Script.Instance.SendIOScriptEvent(io, ScriptConsts.SM_007_EQUIPOUT, null, null); } } if (io.HasTypeFlag(EquipmentGlobals.OBJECT_TYPE_HELMET) || io.HasTypeFlag(EquipmentGlobals.OBJECT_TYPE_ARMOR) || io.HasTypeFlag(EquipmentGlobals.OBJECT_TYPE_LEGGINGS)) { target.PcData.RecreatePlayerMesh(); } } } }
/** * Action when a player attempts to identify an item. * @param playerIO the player's <see cref="BaseInteractiveObject"/> * @param itemIO the itme's <see cref="BaseInteractiveObject"/> * @ if an error occurs */ public void IdentifyIO(BaseInteractiveObject playerIO, BaseInteractiveObject itemIO) { if (playerIO != null && playerIO.HasIOFlag(IoGlobals.IO_01_PC) && playerIO.PcData != null && itemIO != null && itemIO.HasIOFlag(IoGlobals.IO_02_ITEM) && itemIO.ItemData != null && itemIO.ItemData.Equipitem != null) { if (playerIO.PcData.CanIdentifyEquipment(itemIO.ItemData.Equipitem)) { Script.Instance.SendIOScriptEvent(itemIO, ScriptConsts.SM_069_IDENTIFY, null, ""); } } }
protected void UnequipItemInSlot(IOCharacter player, int slot) { // UnityEngine.Debug.Log("UnequipItemInSlot"); if (player.GetEquippedItem(slot) >= 0) { int slotioid = player.GetEquippedItem(slot); UnityEngine.Debug.Log("slot io " + slotioid); if (Interactive.Instance.HasIO(slotioid)) { BaseInteractiveObject equipIO = Interactive.Instance.GetIO(slotioid); if (equipIO.HasIOFlag(IoGlobals.IO_02_ITEM) && equipIO.ItemData != null) { equipIO.ItemData.UnEquip(player.GetIo(), false); } } } }
/// <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> /// Damages an IONpcData. /// </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> public virtual float DamageNPC(float dmg, int srcIoid, bool isSpellDamage) { //UnityEngine.Debug.Log("IONpcData.DamageNpc(" + dmg + "," + srcIoid + "," + isSpellDamage); float damagesdone = 0f; if (io.Show > 0 && !io.HasIOFlag(IoGlobals.IO_08_INVULNERABILITY)) { if (Life <= 0f) { DamageNonLivingNPC(dmg, srcIoid, isSpellDamage); } else { // send OUCH event SendOuchEvent(dmg, srcIoid); // TODO - remove Confusion spell when hit if (dmg >= 0f) { ApplyPoisonDamage(srcIoid, isSpellDamage); int accepted = ScriptConsts.ACCEPT; // if BaseInteractiveObject has a script, send HIT event if (io.Script != null) { accepted = SendHitEvent(dmg, srcIoid, isSpellDamage); } // if HIT event doesn't handle damage, handle it here if (accepted == ScriptConsts.ACCEPT) { damagesdone = ProcessDamage(dmg, srcIoid); } } } } return(damagesdone); }
/// <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; } }
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); }