/// <summary> /// Instantly puts the item in the hand and activates fight mode /// </summary> void DrawWeapon(ItemInst item) { if (item.ItemType == ItemTypes.WepBow) { this.EquipItem(NPCSlots.LeftHand, item); var ammo = GetAmmo(); if (ammo != null) { this.EquipItem(NPCSlots.RightHand, ammo); } } else if (item.ItemType == ItemTypes.WepXBow) { this.EquipItem(NPCSlots.RightHand, item); var ammo = GetAmmo(); if (ammo != null) { this.EquipItem(NPCSlots.LeftHand, ammo); } } else { this.EquipItem(NPCSlots.RightHand, item); // put weapon into hand var melee2 = GetEquipmentBySlot(NPCSlots.OneHanded2); if (melee2 != null) { this.EquipItem(NPCSlots.LeftHand, melee2); } } this.SetFightMode(true); // look angry }
partial void pBeforeEquip(NPCSlots slot, ItemInst item) { if (item.IsEquipped) { pBeforeUnequip(item); } }
void TakeItem(ItemInst item) { if (item != null && item.IsSpawned) { // remove item in world item.Despawn(); bool add = true; // stack items of the same kind this.Inventory.ForEachItemPredicate(invItem => { if (invItem.Definition == item.Definition) { invItem.SetAmount(invItem.Amount + item.Amount); add = false; return(false); } return(true); }); if (add) { this.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); } } } }
static bool doDrawItemSound = true; //improveme void PlayDrawItemSound(ItemInst item, bool undraw) { if (!doDrawItemSound) { return; } SoundDefinition sound; switch (item.Definition.Material) { case ItemMaterials.Metal: sound = undraw ? sfx_UndrawMetal : sfx_DrawMetal; break; case ItemMaterials.Wood: sound = undraw ? sfx_UndrawWood : sfx_DrawWood; break; default: sound = sfx_DrawGeneric; break; } SoundHandler.PlaySound3D(sound, this.BaseInst); }
public void UnequipItem(ItemInst item) { pBeforeUnequip(item); this.BaseInst.UnequipItem(item.BaseInst); pAfterUnequip(item); OnUnequip?.Invoke(item); }
public void UnequipSlot(NPCSlots slot) { ItemInst item = GetEquipmentBySlot(slot); if (item != null) { UnequipItem(item); } }
partial void pAfterEquip(NPCSlots slot, ItemInst item) { if (!this.IsSpawned) { return; } oCNpc gNpc = this.BaseInst.gVob; oCItem gItem = item.BaseInst.gVob; Gothic.Types.zString node; bool undraw = true; bool ininv = true; switch (slot) { case NPCSlots.OneHanded1: node = oCNpc.NPCNodes.Sword; break; case NPCSlots.TwoHanded: node = oCNpc.NPCNodes.Longsword; break; case NPCSlots.Ranged: node = item.ItemType == ItemTypes.WepBow ? oCNpc.NPCNodes.Bow : oCNpc.NPCNodes.Crossbow; break; case NPCSlots.Armor: node = oCNpc.NPCNodes.Torso; gItem.VisualChange.Set(item.Definition.VisualChange); break; case NPCSlots.RightHand: node = oCNpc.NPCNodes.RightHand; undraw = false; break; case NPCSlots.LeftHand: node = oCNpc.NPCNodes.LeftHand; undraw = false; break; default: return; } if (item.ModelDef.Visual.EndsWith(".ZEN")) { ininv = false; } gItem.Material = (int)item.Material; gNpc.PutInSlot(node, gItem, ininv); PlayDrawItemSound(item, undraw); }
public void EquipItem(NPCSlots slot, ItemInst item) { if (item.BaseInst.Slot == (int)slot) { return; } pBeforeEquip(slot, item); this.BaseInst.EquipItem((int)slot, item.BaseInst); pAfterEquip(slot, item); 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 (this.GetDrawnWeapon() == null) { } else { ScriptAniJob job = (this.Movement == NPCMovement.Stand && !this.Environment.InAir) ? catalog.Undraw : catalog.UndrawWhileRunning; if (job == null || !this.ModelInst.TryGetAniFromJob(job, out ScriptAni ani)) // no animation { UndrawWeapon(item); } else { if (!ani.TryGetSpecialFrame(SpecialFrame.Draw, out float drawFrame)) { drawFrame = 0; } this.ModelInst.StartAniJob(job, new Animations.FrameActionPair(drawFrame, () => UndrawWeapon(item))); } } }
partial void pOnEndPos() { if (DoHitDetection(BaseInst.LastPosition, Destination)) { return; } ItemInst item = this.Item; if (item != null) { item.Spawn(this.World, this.Destination, this.GetAngles()); this.World.DespawnList_PItems.AddVob(item); } }
void ChugPotion(ItemInst item) { if (item == null) { return; } int hp = this.HP + 50; this.SetHealth(hp > HPMax ? HPMax : hp); if (item.IsEquipped) { this.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 Animations.FrameActionPair(frame, () => this.TakeItem(item)); this.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 Animations.FrameActionPair(frame, () => this.DropItem(item, position, angles)); this.ModelInst.StartAniJob(job, 0.8f, 0, pair); return; } DropItem(item, position, angles); }
partial void pBeforeUnequip(ItemInst item) { if (!this.IsSpawned) { return; } oCNpc gNpc = this.BaseInst.gVob; oCItem gItem = item.BaseInst.gVob; Gothic.Types.zString node; switch ((NPCSlots)item.BaseInst.Slot) { case NPCSlots.OneHanded1: node = oCNpc.NPCNodes.Sword; break; case NPCSlots.TwoHanded: node = oCNpc.NPCNodes.Longsword; break; case NPCSlots.Ranged: node = item.ItemType == ItemTypes.WepBow ? oCNpc.NPCNodes.Bow : oCNpc.NPCNodes.Crossbow; break; case NPCSlots.Armor: node = oCNpc.NPCNodes.Torso; break; case NPCSlots.RightHand: node = oCNpc.NPCNodes.RightHand; break; case NPCSlots.LeftHand: node = oCNpc.NPCNodes.LeftHand; break; default: return; } gNpc.RemoveFromSlot(node, false, true); }
/// <summary> /// Instantly puts the item back and deactivates fight mode /// </summary> 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; } this.SetFightMode(false); }
/// <summary> /// Creates a new item from the old item with the given amount and reduces the old item's amount. /// </summary> /// <param name="amount"></param> /// <returns></returns> public ItemInst Split(int amount) { if (amount <= 0 || this.Amount <= 0) { return(null); } int newAmount = this.Amount - amount; if (newAmount > 0) { this.SetAmount(newAmount); // split item ItemInst newItem = new ItemInst(this.Definition); newItem.SetAmount(amount); return(newItem); } else { this.Remove(); return(this); } }
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; } this.EquipItem(NPCSlots.RightHand, item); var pair = new Animations.FrameActionPair(frame, () => ChugPotion(item)); ModelInst.StartAniJob(job, pair); return; } ChugPotion(item); }
void DropItem(ItemInst item, Vec3f position, Angles angles) { item.Spawn(this.World, position, angles); item.BaseInst.SetNeedsClientGuide(true); item.Throw(Vec3f.Null); }
partial void pAfterUnequip(ItemInst item);
partial void pBeforeUnequip(ItemInst 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 (this.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 = (this.Movement == NPCMovement.Stand && !this.Environment.InAir) ? catalog.Draw : catalog.DrawWhileRunning; if (job == null || !this.ModelInst.TryGetAniFromJob(job, out ScriptAni ani)) // no animation { DrawWeapon(item); } else { if (!ani.TryGetSpecialFrame(SpecialFrame.Draw, out float drawFrame)) { drawFrame = 0; } this.ModelInst.StartAniJob(job, new Animations.FrameActionPair(drawFrame, () => DrawWeapon(item))); } } }
partial void pAfterEquip(NPCSlots slot, ItemInst item);
partial void pBeforeEquip(NPCSlots slot, ItemInst item);
public float GetFightRange() { ItemInst drawnWeapon = GetDrawnWeapon(); return(this.ModelDef.Radius + (drawnWeapon == null ? ModelDef.FistRange : drawnWeapon.Definition.Range)); }
void UpdateFightStance() { int fmode; if (this.BaseInst.IsInFightMode) { ItemInst wep = GetDrawnWeapon(); if (wep == null) { fmode = 1; // fists } else { if (wep.ItemType == ItemTypes.Wep1H) { fmode = 3; } else if (wep.ItemType == ItemTypes.Wep2H) { fmode = 4; } else if (wep.ItemType == ItemTypes.WepBow) { fmode = 5; } else if (wep.ItemType == ItemTypes.WepXBow) { fmode = 6; } else { fmode = 0; } } } else { fmode = 0; } if (this.fmode != fmode) { var gNpc = this.BaseInst.gVob; var ai = gNpc.HumanAI; // check before changing animations, cause gothic only checks the current animation set bool running = ai.IsRunning(); bool standing = ai.IsStanding(); // set fight mode & animations in gothic gNpc.FMode = fmode; ai.SetFightAnis(fmode); ai.SetWalkMode(0); // override active animations from the old animation set var gModel = BaseInst.gModel; if (running) { gModel.StartAni(ai._s_walkl, 0); } else if (standing) { gModel.StartAni(ai._s_walk, 0); } // sets focus and camera modes if (this == ScriptClient.Client.Character) { gNpc.SetWeaponMode(fmode); if (fmode == 0) { oCNpcFocus.SetFocusMode(0); } } this.fmode = fmode; } }