/// <summary> /// Instantly puts the item in the hand and activates fight mode /// </summary> private void DrawWeapon(ItemInst item) { if (item.ItemType == ItemTypes.WepBow) { EquipItem(NPCSlots.LeftHand, item); var ammo = GetAmmo(); if (ammo != null) { EquipItem(NPCSlots.RightHand, ammo); } } else if (item.ItemType == ItemTypes.WepXBow) { EquipItem(NPCSlots.RightHand, item); var ammo = GetAmmo(); if (ammo != null) { EquipItem(NPCSlots.LeftHand, ammo); } } else { EquipItem(NPCSlots.RightHand, item); // put weapon into hand var melee2 = GetEquipmentBySlot(NPCSlots.OneHanded2); if (melee2 != null) { EquipItem(NPCSlots.LeftHand, melee2); } } SetFightMode(true); // look angry }
public void UnequipItem(ItemInst item) { BaseInst.UnequipItem(item.BaseInst); OnUnequip?.Invoke(item); }
public void UnequipSlot(NPCSlots slot) { ItemInst item = GetEquipmentBySlot(slot); if (item != null) { UnequipItem(item); } }
public void EquipItem(NPCSlots slot, ItemInst item) { if (item.BaseInst.Slot == (int)slot) { return; } BaseInst.EquipItem((int)slot, item.BaseInst); OnEquip?.Invoke(item); }
public void DoUndrawWeapon(ItemInst item) { NPCCatalog.DrawWeaponAnis catalog; switch (item.ItemType) { default: case ItemTypes.Wep1H: catalog = AniCatalog.Draw1H; break; case ItemTypes.Wep2H: catalog = AniCatalog.Draw2H; break; case ItemTypes.WepBow: catalog = AniCatalog.DrawBow; break; case ItemTypes.WepXBow: catalog = AniCatalog.DrawXBow; break; case ItemTypes.Rune: case ItemTypes.Scroll: catalog = AniCatalog.DrawMagic; break; } if (GetDrawnWeapon() == null) { } else { ScriptAniJob job = Movement == NPCMovement.Stand && !Environment.InAir ? catalog.Undraw : catalog.UndrawWhileRunning; if (job == null || !ModelInst.TryGetAniFromJob(job, out ScriptAni ani)) // no animation { UndrawWeapon(item); } else { if (!ani.TryGetSpecialFrame(SpecialFrame.Draw, out float drawFrame)) { drawFrame = 0; } ModelInst.StartAniJob(job, new FrameActionPair(drawFrame, () => UndrawWeapon(item))); } } }
private void ChugPotion(ItemInst item) { if (item == null) { return; } int hp = HP + 50; SetHealth(hp > HPMax ? HPMax : hp); if (item.IsEquipped) { UnequipItem(item); } item.SetAmount(item.Amount - 1); }
public void DoTakeItem(ItemInst item) { ScriptAniJob job = AniCatalog?.ItemHandling.TakeItem; if (job != null && ModelInst.TryGetAniFromJob(job, out ScriptAni ani)) { if (!ani.TryGetSpecialFrame(SpecialFrame.ItemHandle, out float frame)) { frame = float.MaxValue; } var pair = new FrameActionPair(frame, () => TakeItem(item)); ModelInst.StartAniJob(job, 0.8f, 0, pair); return; } TakeItem(item); }
public void DoDropItem(ItemInst item, int amount, Vec3f position, Angles angles) { item = item.Split(amount); ScriptAniJob job = AniCatalog?.ItemHandling.DropItem; if (job != null && ModelInst.TryGetAniFromJob(job, out ScriptAni ani)) { if (!ani.TryGetSpecialFrame(SpecialFrame.ItemHandle, out float frame)) { frame = float.MaxValue; } var pair = new FrameActionPair(frame, () => DropItem(item, position, angles)); ModelInst.StartAniJob(job, 0.8f, 0, pair); return; } DropItem(item, position, angles); }
/// <summary> /// Instantly puts the item back and deactivates fight mode /// </summary> private void UndrawWeapon(ItemInst item) { switch (item.ItemType) { case ItemTypes.Wep1H: EquipItem(NPCSlots.OneHanded1, item); var other1H = GetLeftHand(); if (other1H != null && other1H.ItemType == ItemTypes.Wep1H) { EquipItem(NPCSlots.OneHanded2, other1H); } break; case ItemTypes.Wep2H: EquipItem(NPCSlots.TwoHanded, item); break; case ItemTypes.WepBow: EquipItem(NPCSlots.Ranged, item); var ammo = GetRightHand(); if (ammo != null && ammo.ItemType == ItemTypes.AmmoBow) { EquipItem(NPCSlots.Ammo, ammo); } break; case ItemTypes.WepXBow: EquipItem(NPCSlots.Ranged, item); ammo = GetLeftHand(); if (ammo != null && ammo.ItemType == ItemTypes.AmmoXBow) { EquipItem(NPCSlots.Ammo, ammo); } break; } SetFightMode(false); }
private void TakeItem(ItemInst item) { if (item != null && item.IsSpawned) { // remove item in world item.Despawn(); bool add = true; // stack items of the same kind Inventory.ForEachItemPredicate(invItem => { if (invItem.Definition == item.Definition) { invItem.SetAmount(invItem.Amount + item.Amount); add = false; return(false); } return(true); }); if (add) { Inventory.AddItem(item); // check if this is ammo we need ItemInst rangedWep = GetEquipmentBySlot(NPCSlots.Ranged); if (rangedWep != null && GetEquipmentBySlot(NPCSlots.Ammo) == null && (item.ItemType == ItemTypes.AmmoBow && rangedWep.ItemType == ItemTypes.WepBow || item.ItemType == ItemTypes.AmmoXBow && rangedWep.ItemType == ItemTypes.WepXBow)) { EquipItem(NPCSlots.Ammo, item); } } } }
public void UseItem(ItemInst item) { if (item.ItemType != ItemTypes.Drinkable) { return; } ScriptAniJob job = AniCatalog?.ItemHandling.DrinkPotion; if (job != null && ModelInst.TryGetAniFromJob(job, out ScriptAni ani)) { if (!ani.TryGetSpecialFrame(SpecialFrame.ItemHandle, out float frame)) { frame = float.MaxValue; } EquipItem(NPCSlots.RightHand, item); var pair = new FrameActionPair(frame, () => ChugPotion(item)); ModelInst.StartAniJob(job, pair); return; } ChugPotion(item); }
public void DoDrawWeapon(ItemInst item) { NPCCatalog.DrawWeaponAnis catalog; switch (item.ItemType) { default: case ItemTypes.Wep1H: catalog = AniCatalog.Draw1H; break; case ItemTypes.Wep2H: catalog = AniCatalog.Draw2H; break; case ItemTypes.WepBow: catalog = AniCatalog.DrawBow; break; case ItemTypes.WepXBow: catalog = AniCatalog.DrawXBow; break; case ItemTypes.Rune: case ItemTypes.Scroll: catalog = AniCatalog.DrawMagic; break; } if (IsInFightMode || GetDrawnWeapon() != null) { /*if (this.DrawnWeapon != null) * { * ItemInst weapon = this.DrawnWeapon; * catalog = GetDrawWeaponCatalog(weapon.ItemType); * // weapon draw while running or when standing * if (this.Movement == NPCMovement.Forward || this.Movement == NPCMovement.Left || this.Movement == NPCMovement.Right) * { * this.ModelInst.StartAniJob(catalog.UndrawWhileRunning, 0.1f, () => * { * this.UnequipItem(weapon); // take weapon from hand * this.EquipItem(weapon); // place weapon into parking slot * }); * } * else * { * this.ModelInst.StartAniJob(catalog.Undraw, 0.1f, () => * { * this.UnequipItem(weapon); // take weapon from hand * this.EquipItem(weapon); // place weapon into parking slot * }); * } * } * this.SetFightMode(false);*/ } else { ScriptAniJob job = Movement == NPCMovement.Stand && !Environment.InAir ? catalog.Draw : catalog.DrawWhileRunning; if (job == null || !ModelInst.TryGetAniFromJob(job, out ScriptAni ani)) // no animation { DrawWeapon(item); } else { if (!ani.TryGetSpecialFrame(SpecialFrame.Draw, out float drawFrame)) { drawFrame = 0; } ModelInst.StartAniJob(job, new FrameActionPair(drawFrame, () => DrawWeapon(item))); } } }
private void DropItem(ItemInst item, Vec3f position, Angles angles) { item.Spawn(World, position, angles); item.BaseInst.SetNeedsClientGuide(true); item.Throw(Vec3f.Null); }
public float GetFightRange() { ItemInst drawnWeapon = GetDrawnWeapon(); return(ModelDef.Radius + (drawnWeapon?.Definition.Range ?? ModelDef.FistRange)); }