Ejemplo n.º 1
0
 /// <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
 }
Ejemplo n.º 2
0
 partial void pBeforeEquip(NPCSlots slot, ItemInst item)
 {
     if (item.IsEquipped)
     {
         pBeforeUnequip(item);
     }
 }
Ejemplo n.º 3
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public void UnequipItem(ItemInst item)
        {
            pBeforeUnequip(item);
            this.BaseInst.UnequipItem(item.BaseInst);
            pAfterUnequip(item);

            OnUnequip?.Invoke(item);
        }
Ejemplo n.º 6
0
        public void UnequipSlot(NPCSlots slot)
        {
            ItemInst item = GetEquipmentBySlot(slot);

            if (item != null)
            {
                UnequipItem(item);
            }
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        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)));
                }
            }
        }
Ejemplo n.º 10
0
        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);
            }
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        /// <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);
        }
Ejemplo n.º 16
0
        /// <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);
            }
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
 void DropItem(ItemInst item, Vec3f position, Angles angles)
 {
     item.Spawn(this.World, position, angles);
     item.BaseInst.SetNeedsClientGuide(true);
     item.Throw(Vec3f.Null);
 }
Ejemplo n.º 19
0
 partial void pAfterUnequip(ItemInst item);
Ejemplo n.º 20
0
 partial void pBeforeUnequip(ItemInst item);
Ejemplo n.º 21
0
        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)));
                }
            }
        }
Ejemplo n.º 22
0
 partial void pAfterEquip(NPCSlots slot, ItemInst item);
Ejemplo n.º 23
0
 partial void pBeforeEquip(NPCSlots slot, ItemInst item);
Ejemplo n.º 24
0
        public float GetFightRange()
        {
            ItemInst drawnWeapon = GetDrawnWeapon();

            return(this.ModelDef.Radius + (drawnWeapon == null ? ModelDef.FistRange : drawnWeapon.Definition.Range));
        }
Ejemplo n.º 25
0
        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;
            }
        }