Example #1
0
 public void RemoveWeapon(WeaponHand weaponHand)
 {
     switch (weaponHand)
     {
         case WeaponHand.Left:
             // Destroy current weapon
             if (currentWeaponLeft != null)
             {
                 currentWeaponLeft.transform.parent = null;
                 Destroy(currentWeaponLeft.gameObject);
             }
             break;
         case WeaponHand.Right:
             if (currentWeaponRight != null)
             {
                 currentWeaponRight.transform.parent = null;
                 Destroy(currentWeaponRight.gameObject);
             }
             break;
         case WeaponHand.Both:
             if (currentWeaponLeft != null)
             {
                 currentWeaponLeft.transform.parent = null;
                 Destroy(currentWeaponLeft.gameObject);
             }
             if (currentWeaponRight != null)
             {
                 currentWeaponRight.transform.parent = null;
                 Destroy(currentWeaponRight.gameObject);
             }
             break;
     }
 }
    // ================================================================================
    //  public methods
    // --------------------------------------------------------------------------------

    public void SetInput(PlayerCharacter character)
    {
        _current      = character;
        _currentActor = character.GetComponent <Actor>();
        _weaponHand   = _currentActor.GetComponentInChildren <WeaponHand>();
        _crossHair.Show();
    }
Example #3
0
 // Returns clone of weapon for specified hand.
 public Weapon Clone(WeaponHand forHand)
 {
     return(new Weapon(this)
     {
         Hand = forHand
     });
 }
Example #4
0
    //Function used to change the weapon at the given slot to the new one
    public void ChangeWeaponItem(WeaponHand handSlot_, Weapon weaponToChangeTo_)
    {
        if (handSlot_ == WeaponHand.Right)
        {
            this.rightHand = weaponToChangeTo_;

            //If the slot isn't empty, this inventory becomes the item's parent
            if (weaponToChangeTo_ != null)
            {
                weaponToChangeTo_.transform.SetParent(this.transform);
            }
        }
        else if (handSlot_ == WeaponHand.Left)
        {
            this.leftHand = weaponToChangeTo_;

            //If the slot isn't empty, this inventory becomes the item's parent
            if (weaponToChangeTo_ != null)
            {
                weaponToChangeTo_.transform.SetParent(this.transform);
            }
        }

        //Updating this inventory's weight
        this.FindArmorStats();
    }
Example #5
0
    private void DropWeapon(WeaponHand type)
    {
        if (m_Weapons.ContainsKey(type))
        {
            GameObject weapon = m_Weapons[type];
            Script_Util.DetachGameObject(weapon);
            GameObject.DestroyObject(weapon);
            m_Weapons.Remove(type);
        }

        // Make Sure Remove All Children
        Transform t = LogicSystem.FindChildRecursive(this.gameObject.transform, GetBoneName(type));

        if (t != null)
        {
            int childCount = t.childCount;
            for (int index = 0; index < childCount; index++)
            {
                Transform child = t.GetChild(index);
                child.parent = null;
                GameObject.Destroy(child.gameObject);
            }
            t.DetachChildren();
        }
    }
Example #6
0
 public DamageNature(DamageNature nature)
 {
     Form       = nature.Form;
     Source     = nature.Source;
     Type       = nature.Type;
     WeaponHand = nature.WeaponHand;
     WeaponType = nature.WeaponType;
 }
Example #7
0
 public GameObject GetWeaponByHand(WeaponHand type)
 {
     if (m_Weapons.ContainsKey(type))
     {
         return(m_Weapons[type]);
     }
     return(null);
 }
    void StopAttacking(bool isLeft)
    {
        WeaponHand hand = (isLeft ? weaponHolder.LeftHand : weaponHolder.RightHand);

        hand.StopAttack();
        player.StopAttackAnims(isLeft);
        //player.StopSimpleShootAnim(isLeft);
        //player.StopSimpleMeleeAnim(isLeft);
    }
Example #9
0
    public static GameObject GetWeaponByHand(GameObject target, WeaponHand hand)
    {
        WeaponControl control = target.GetComponent <WeaponControl>();

        if (control == null)
        {
            LogicSystem.GfxLog("ShooterSkillExecutor WeaponControl Script miss!");
            return(null);
        }
        return(control.GetWeaponByHand(hand));
    }
Example #10
0
    private void HoldWeapon(WeaponHand type, SkillWeaponInfo info)
    {
        GameObject newWeapon = CreateNewWeapon(info);

        if (newWeapon != null)
        {
#if SHOOTER_LOG
            Debug.Log("HoldWeapon:" + newWeapon.name);
#endif
            m_Weapons.Add(info.HoldType, newWeapon);
            Script_Util.AttachGameObject(this.gameObject, newWeapon, GetBoneName(info.HoldType));
        }
    }
Example #11
0
    private string GetBoneName(WeaponHand type)
    {
        switch (type)
        {
        case WeaponHand.LeftHand: {
            return(BoneLeftHand);
        }

        case WeaponHand.RightHand: {
            return(BoneRightHand);
        }
        }
        return("");
    }
Example #12
0
    public void AttachToCharacter(PlayerCharacter character)
    {
        _currentActor = character.GetComponent <Actor>();
        _weaponHand   = character.GetComponentInChildren <WeaponHand>();
        currentWeapons.Clear();
        index = 0;

        foreach (var weapon in startWeapons)
        {
            currentWeapons.Add(weapon);
        }

        _weaponHand.SetWeapon(current);
        inventoryDisplay.SetWeapon(current);
        inventoryDisplay.Show();
    }
    void Attack(bool isLeft)
    {
        WeaponHand hand = (isLeft ? weaponHolder.LeftHand : weaponHolder.RightHand);

        if (hand.AttachedWeapon != null)
        {
            player.PlayAttackAnim(hand.AttachedWeapon.Type, isLeft);

            /*
             * switch(hand.AttachedWeapon.Type)
             * {
             * case WeaponType.ONE_HAND_PROJ: player.PlaySimpleShootAnim(isLeft); break;
             * case WeaponType.ONE_HAND_MELEE: player.PlaySimpleMeleeAnim(isLeft); break;
             * case WeaponType.ONE_HAND_STAB: player.PlayAttackAnim(isLeft); break;
             * }*/
        }

        hand.AttackWithWeapon();
    }
Example #14
0
    public void UnequipWeapon(WeaponHand handToRemove_)
    {
        switch (handToRemove_)
        {
        case WeaponHand.Right:
            //Making sure there's an equipped weapon and empty slot to put the weapon
            if (this.rightHand != null && this.CheckForEmptySlot() > 0)
            {
                //Moves the current right hand weapon to the inventory and nulls the hand slot
                this.AddItemToInventory(this.rightHand.GetComponent <Item>());

                //If this character is holding a 2-handed weapon, the left hand is freed as well
                if (this.rightHand.size == Weapon.WeaponSize.TwoHands)
                {
                    this.leftHand = null;
                }

                this.rightHand = null;
            }
            break;

        case WeaponHand.Left:
            //Making sure there's an equipped weapon and empty slot to put the weapon
            if (this.leftHand != null && this.CheckForEmptySlot() > 0)
            {
                //Moves the current left hand weapon to the inventory and nulls the hand slot
                this.AddItemToInventory(this.leftHand.GetComponent <Item>());
                this.leftHand = null;
            }
            break;

        case WeaponHand.Both:
            //Calls this function twice, but with the other hands
            this.UnequipWeapon(WeaponHand.Right);
            this.UnequipWeapon(WeaponHand.Left);
            break;
        }

        //Finding the new inventory weight
        this.FindArmorStats();
    }
Example #15
0
 public SkillWeaponInfo(string param)
 {
     string[] result = Script_Util.SplitParam(param, 6);
     if (result != null)
     {
         Id             = Convert.ToInt32(result[0]);
         WeaponName     = result[1];
         Operate        = (WeaponCmd)Convert.ToInt32(result[2]);
         HoldType       = (WeaponHand)Convert.ToInt32(result[3]);
         IsCurWeapon    = Convert.ToBoolean(result[4]);
         IsCurSubWeapon = Convert.ToBoolean(result[5]);
         if (result.Length > 6)
         {
             SpriteName = result[6];
         }
     }
     else
     {
         IsValid = false;
     }
 }
Example #16
0
    private void AimWeapon()
    {
        Vector3    mousePosition = GetMousePosition();
        WeaponHand weaponHand    = GetUsedWeaponHand(mousePosition);

        if (weaponHand.IsMelee())
        {
            return;
        }

        if (weaponHand != currentWeaponHand)
        {
            if (currentIdleCoroutine != null)
            {
                StopCoroutine(currentIdleCoroutine);
            }
            currentIdleCoroutine = MoveToIdlePosition(GetIdleWeaponHand(mousePosition));
        }

        MovementUtils.Instance.RotateTowards(weaponHand.GetHand(), mousePosition);
        currentWeaponHand = weaponHand;
    }
Example #17
0
    public bool ChangeWeapon(WeaponGroup.WeaponType weaponType, int index, WeaponHand weaponHand)
    {
        // Remove weapon first
        RemoveWeapon(weaponHand);

        Transform weaponPrefab;
        if (WeaponGroup.Instance.GetWeapon(index, prof, out weaponPrefab, weaponType))
        {
            Transform w;
            switch (weaponHand)
            {
                case WeaponHand.Left:
                    w = Instantiate(weaponPrefab, weaponHandLeft.position, weaponHandLeft.rotation) as Transform;
                    currentWeaponLeft = w;
                    w.parent = weaponHandLeft;
                    break;
                case WeaponHand.Right:
                    w = Instantiate(weaponPrefab, weaponHandRight.position, weaponHandRight.rotation) as Transform;
                    currentWeaponRight = w;
                    w.parent = weaponHandRight;
                    break;
                case WeaponHand.Both:
                    w = Instantiate(weaponPrefab, weaponHandLeft.position, weaponHandLeft.rotation) as Transform;
                    currentWeaponLeft = w;
                    w.parent = weaponHandLeft;

                    w = Instantiate(weaponPrefab, weaponHandRight.position, weaponHandRight.rotation) as Transform;
                    currentWeaponRight = w;
                    w.parent = weaponHandRight;
                    break;
            }
            // Weapon equipped
            return true;
        }
        else
        {
            return false;
        }
    }
Example #18
0
 // Returns clone of weapon for specified hand.
 public Weapon Clone(WeaponHand forHand)
 {
     return new Weapon(this) { Hand = forHand };
 }
Example #19
0
            public Weapon(WeaponHand hand, Item item)
            {
                Hand = hand;

                if (item != null)
                {
                    Item = item;

                    // Get weapon type (damage nature).
                    if (item.Keywords == null) // Quiver or shield.
                    {
                        if (item.BaseType.Contains("Quiver"))
                            Nature = new DamageNature() { WeaponType = WeaponType.Quiver };
                        else
                            if (item.BaseType.Contains("Shield") || item.BaseType.Contains("Buckler") || item.BaseType == "Spiked Bundle")
                                Nature = new DamageNature() { WeaponType = WeaponType.Shield };
                            else
                                throw new Exception("Unknown weapon type: " + item.BaseType);
                    }
                    else // Regular weapon.
                        foreach (string keyword in item.Keywords)
                            if (Types.ContainsKey(keyword))
                            {
                                Nature = new DamageNature() { WeaponType = Types[keyword] };
                                break;
                            }

                    // If weapon is melee, it defaults to melee form. If it's ranged then projectile.
                    if (Nature.Is(WeaponType.Melee))
                        Nature.Form = DamageForm.Melee;
                    else
                        if (Nature.Is(WeaponType.Ranged))
                            Nature.Form = DamageForm.Projectile;

                    // Copy attributes and create damage dealt.
                    foreach (var attr in item.Attributes)
                    {
                        Attributes.Add(attr);

                        Damage damage = Damage.Create(Nature, attr);
                        if (damage != null && damage.Type == DamageType.Physical) // Create only physical damage from item properties.
                            Deals.Add(damage);
                    }

                    // Copy local and non-local mods and collect added non-physical damage.
                    foreach (var mod in item.Mods)
                    {
                        if (mod.isLocal)
                        {
                            Damage.Added added = Damage.Added.Create(Nature.Source, mod);
                            if (added != null && added.Type != DamageType.Physical)
                                Added.Add(added);
                        }

                        Attributes.Add(mod);
                    }
                }
                else // No item.
                    if (hand == WeaponHand.Main) // Only Main Hand can be Unarmed.
                    {
                        Nature = new DamageNature() { WeaponType = WeaponType.Unarmed };

                        // Implicit Unarmed attributes.
                        Attributes.Add("Attacks per Second: #", new List<float>() { UnarmedAttacksPerSecond });

                        // Unarmed damage.
                        Damage damage = Damage.Create(Nature);
                        Deals.Add(damage);
                    }
            }
Example #20
0
                private static bool IsPoisonApplied(WeaponHand checkWeaponHand)
                {
                    List<string> weaponEnchants = Lua.GetReturnValues("return GetWeaponEnchantInfo()", "stuff.lua");

                    if (weaponEnchants != null)
                    {
                        bool result;
                        switch (checkWeaponHand)
                        {
                            case WeaponHand.MainHand:
                                result = weaponEnchants[0] == string.Empty || weaponEnchants[0] == "nil";
                                return !result;

                            case WeaponHand.OffHand:
                                result = weaponEnchants[3] == string.Empty || weaponEnchants[3] == "nil";
                                return !result;
                        }
                    }

                    return false;
                }
Example #21
0
        public Weapon(WeaponHand hand, Item item)
        {
            Hand = hand;

            if (item != null)
            {
                Item = item;

                // Get weapon type (damage nature).
                if (item.ItemGroup != ItemGroup.OneHandedWeapon && item.ItemGroup != ItemGroup.TwoHandedWeapon)
                // Quiver or shield.
                {
                    if (item.BaseType.Name.Contains("Quiver"))
                    {
                        Nature = new DamageNature()
                        {
                            WeaponType = WeaponType.Quiver
                        }
                    }
                    ;
                    else if (item.BaseType.Name.Contains("Shield") || item.BaseType.Name.Contains("Buckler") ||
                             item.BaseType.Name == "Spiked Bundle")
                    {
                        Nature = new DamageNature()
                        {
                            WeaponType = WeaponType.Shield
                        }
                    }
                    ;
                    else
                    {
                        throw new Exception("Unknown weapon type: " + item.BaseType);
                    }
                }
                else // Regular weapon.
                {
                    WeaponType weaponType;
                    if (!Enum.TryParse(item.ItemType.ToString(), out weaponType))
                    {
                        if (item.ItemType == ItemType.ThrustingOneHandedSword)
                        {
                            weaponType = WeaponType.OneHandedSword;
                        }
                        else if (item.ItemType == ItemType.Sceptre)
                        {
                            weaponType = WeaponType.OneHandedMace;
                        }
                        else
                        {
                            throw new Exception("Unknown weapon type: " + item.BaseType);
                        }
                    }
                    Nature = new DamageNature {
                        WeaponType = weaponType
                    };
                }

                // If weapon is melee, it defaults to melee form. If it's ranged then projectile.
                if (Nature.Is(WeaponType.Melee))
                {
                    Nature.Form = DamageForm.Melee;
                }
                else
                if (Nature.Is(WeaponType.Ranged))
                {
                    Nature.Form = DamageForm.Projectile;
                }

                // Copy attributes and create damage dealt.
                foreach (var prop in item.Properties)
                {
                    Attributes.Add(prop);

                    Damage damage = Damage.Create(Nature, prop.Attribute, prop.Value);
                    if (damage != null && damage.Type == DamageType.Physical) // Create only physical damage from item properties.
                    {
                        Deals.Add(damage);
                    }
                }

                // Copy local and non-local mods and collect added non-physical damage.
                foreach (var mod in item.Mods)
                {
                    if (mod.IsLocal)
                    {
                        Damage.Added added = Damage.Added.Create(Nature.Source, mod);
                        if (added != null && added.Type != DamageType.Physical)
                        {
                            Added.Add(added);
                        }
                    }

                    Attributes.Add(mod);
                }
            }
            else // No item.
            if (hand == WeaponHand.Main)     // Only Main Hand can be Unarmed.
            {
                Nature = new DamageNature()
                {
                    WeaponType = WeaponType.Unarmed
                };

                // Implicit Unarmed attributes.
                Attributes.Add("Attacks per Second: #", new List <float>()
                {
                    UnarmedAttacksPerSecond
                });

                // Unarmed damage.
                Damage damage = Damage.Create(Nature);
                Deals.Add(damage);
            }
        }
Example #22
0
 public bool Is(WeaponHand weaponHand)
 {
     return((WeaponHand & weaponHand) != 0);
 }
Example #23
0
        // Merges attributes of specified gem.
        public void Merge(Gem gem)
        {
            // Take properties from parameter if they are not specified here.
            if (!ExcludeFormSpecified && gem.ExcludeFormSpecified)
            {
                ExcludeForm = gem.ExcludeForm;
            }
            if (!ExcludeFormSupportSpecified && gem.ExcludeFormSupportSpecified)
            {
                ExcludeFormSupport = gem.ExcludeFormSupport;
            }
            if (!ExcludeSourceSpecified && gem.ExcludeSourceSpecified)
            {
                ExcludeSource = gem.ExcludeSource;
            }
            if (!HitsPerAttackSpecified && gem.HitsPerAttackSpecified)
            {
                HitsPerAttack = gem.HitsPerAttack;
            }
            if (!IncludeFormSpecified && gem.IncludeFormSpecified)
            {
                IncludeForm = gem.IncludeForm;
            }
            if (!RequiresEquippedShieldSpecified && gem.RequiresEquippedShieldSpecified)
            {
                RequiresEquippedShield = gem.RequiresEquippedShield;
            }
            if (!RequiredHandSpecified && gem.RequiredHandSpecified)
            {
                RequiredHand = gem.RequiredHand;
            }
            if (!RequiredWeaponSpecified && gem.RequiredWeaponSpecified)
            {
                RequiredWeapon = gem.RequiredWeapon;
            }
            if (!StrikesWithBothWeaponsSpecified && gem.StrikesWithBothWeaponsSpecified)
            {
                StrikesWithBothWeapons = gem.StrikesWithBothWeapons;
            }
            if (!UnarmedSpecified && gem.UnarmedSpecified)
            {
                Unarmed = gem.Unarmed;
            }

            if (gem.Attributes != null)
            {
                if (Attributes == null)
                {
                    Attributes = new List <GemAttribute>();
                }

                foreach (GemAttribute attr in gem.Attributes)
                {
                    attr.Optimize();
                    // Find existing attribute to merge with.
                    GemAttribute with = Attributes.Find(a => a.Name == attr.Name);
                    if (with == null)
                    {
                        Attributes.Add(attr);
                    }
                    else
                    {
                        if (!with.NoUpdate)
                        {
                            // Sort values by priority so less specific values won't overwrite more specific ones.
                            attr.Values.Sort(new ValuePriorityComparer {
                                Reversed = true
                            });

                            foreach (Value value in attr.Values)
                            {
                                with.Merge(value);
                            }

                            with.CleanUp();
                        }
                    }
                }

                // Sort gem attribute values logically.
                Comparer <Value> comparer = new ValueLogicalComparer();
                foreach (GemAttribute attr in Attributes)
                {
                    attr.Values.Sort(comparer);
                }
            }
        }
Example #24
0
            public Weapon(WeaponHand hand, Item item)
            {
                Hand = hand;

                if (item != null)
                {
                    Item = item;

                    // Get weapon type (damage nature).
                    if (item.ItemGroup != ItemGroup.OneHandedWeapon && item.ItemGroup != ItemGroup.TwoHandedWeapon)
                        // Quiver or shield.
                    {
                        if (item.BaseType.Name.Contains("Quiver"))
                            Nature = new DamageNature() {WeaponType = WeaponType.Quiver};
                        else if (item.BaseType.Name.Contains("Shield") || item.BaseType.Name.Contains("Buckler") ||
                                 item.BaseType.Name == "Spiked Bundle")
                            Nature = new DamageNature() {WeaponType = WeaponType.Shield};
                        else
                            throw new Exception("Unknown weapon type: " + item.BaseType);
                    }
                    else // Regular weapon.
                    {
                        WeaponType weaponType;
                        if (!Enum.TryParse(item.ItemType.ToString(), out weaponType))
                        {
                            if (item.ItemType == ItemType.ThrustingOneHandedSword)
                                weaponType = WeaponType.OneHandedSword;
                            else if (item.ItemType == ItemType.Sceptre)
                                weaponType = WeaponType.OneHandedMace;
                            else
                                throw new Exception("Unknown weapon type: " + item.BaseType);
                        }
                        Nature = new DamageNature {WeaponType = weaponType};
                    }

                    // If weapon is melee, it defaults to melee form. If it's ranged then projectile.
                    if (Nature.Is(WeaponType.Melee))
                        Nature.Form = DamageForm.Melee;
                    else
                        if (Nature.Is(WeaponType.Ranged))
                            Nature.Form = DamageForm.Projectile;

                    // Copy attributes and create damage dealt.
                    foreach (var prop in item.Properties)
                    {
                        Attributes.Add(prop);

                        Damage damage = Damage.Create(Nature, prop.Attribute, prop.Value);
                        if (damage != null && damage.Type == DamageType.Physical) // Create only physical damage from item properties.
                            Deals.Add(damage);
                    }

                    // Copy local and non-local mods and collect added non-physical damage.
                    foreach (var mod in item.Mods)
                    {
                        if (mod.IsLocal)
                        {
                            Damage.Added added = Damage.Added.Create(Nature.Source, mod);
                            if (added != null && added.Type != DamageType.Physical)
                                Added.Add(added);
                        }

                        Attributes.Add(mod);
                    }
                }
                else // No item.
                    if (hand == WeaponHand.Main) // Only Main Hand can be Unarmed.
                    {
                        Nature = new DamageNature() { WeaponType = WeaponType.Unarmed };

                        // Implicit Unarmed attributes.
                        Attributes.Add("Attacks per Second: #", new List<float>() { UnarmedAttacksPerSecond });

                        // Unarmed damage.
                        Damage damage = Damage.Create(Nature);
                        Deals.Add(damage);
                    }
            }
Example #25
0
 // Returns true if weapon is in specified hand, false otherwise.
 public bool Is(WeaponHand hand)
 {
     return hand == WeaponHand.Any || (Hand & hand) != 0;
 }
Example #26
0
            public DamageNature(DamageNature nature, string str)
            {
                Form = nature.Form;
                Source = nature.Source;
                Type = nature.Type;
                WeaponHand = nature.WeaponHand;
                WeaponType = nature.WeaponType;

                string[] words = str.Split(' ');
                foreach (string word in words)
                {
                    if (Forms.ContainsKey(word)) Form |= Forms[word];
                    if (Types.ContainsKey(word)) Type = Types[word];
                    if (Weapon.Types.ContainsKey(word)) WeaponType = Weapon.Types[word];
                    if (Sources.ContainsKey(word)) Source = Sources[word];
                }
            }
Example #27
0
 // Returns true if weapon is in specified hand, false otherwise.
 public bool Is(WeaponHand hand)
 {
     return(hand == WeaponHand.Any || (Hand & hand) != 0);
 }
Example #28
0
 public DamageNature(DamageNature nature)
 {
     Form = nature.Form;
     Source = nature.Source;
     Type = nature.Type;
     WeaponHand = nature.WeaponHand;
     WeaponType = nature.WeaponType;
 }
Example #29
0
 void Start()
 {
     left  = new WeaponHand(transform.Find("leftHandWeapon"), true);
     right = new WeaponHand(transform.Find("rightHandWeapon"), false);
     EquipWeapon(origWeapon);
 }
Example #30
0
 public bool Is(WeaponHand weaponHand)
 {
     return (WeaponHand & weaponHand) != 0;
 }
Example #31
0
    private Coroutine MoveToIdlePosition(WeaponHand weaponHand)
    {
        Vector3 idlePosition = weaponHand.GetDefaultHandPointGlobal();

        return(MovementUtils.Instance.RotateTowards(weaponHand.GetHand(), weaponHand.GetDefaultHandPointGlobal(), 1f));
    }