public RuntimeWeapon WeaponToRuntimeWeapon(Weapon weapon, bool isLeftHand = false)
        {
            //Debug.Log("Converting to runtime weapon: " + weapon.item_id);
            GameObject go = new GameObject();

            go.transform.parent = referencesParent.transform;
            RuntimeWeapon inst = go.AddComponent <RuntimeWeapon>();

            go.name = weapon.item_id;

            inst.Instance = new Weapon();
            StaticFunctions.DeepCopyWeapon(weapon, inst.Instance);

            inst.weaponStats = new WeaponStats();
            WeaponStats weaponStats = ResourcesManager.Instance.GetWeaponStats(weapon.item_id);

            if (weaponStats == null)
            {
                Debug.Log("Couldn't find weaponStats");
            }
            StaticFunctions.DeepCopyWeaponStats(weaponStats, inst.weaponStats);

            //Create weapon 3D model to scene
            inst.weaponModel = Instantiate(weapon.weaponModelPrefab) as GameObject;

            //If the weapon is used by left hand, assign left hand as weapon's parents and vice versa
            Transform parent = states.animator.GetBoneTransform((isLeftHand) ? HumanBodyBones.LeftHand : HumanBodyBones.RightHand);

            inst.weaponModel.transform.parent = parent;

            //Reset the transform properties of the weapon
            inst.weaponModel.transform.localPosition =
                (isLeftHand) ?
                inst.Instance.left_model_pos : inst.Instance.right_model_pos;

            inst.weaponModel.transform.localEulerAngles =
                (isLeftHand) ?
                inst.Instance.left_model_eulerRot : inst.Instance.right_model_eulerRot;

            inst.weaponModel.transform.localScale = (isLeftHand) ?
                                                    inst.Instance.left_model_scale : inst.Instance.right_model_scale;;

            inst.weaponHook = inst.weaponModel.GetComponentInChildren <WeaponHook>();
            if (inst.weaponHook == null)
            {
                Debug.Log("Missing component 'WeaponHook' on weapon: " + weapon.item_id);
            }

            inst.weaponHook.InitDamageColliders(states);

            inst.weaponModel.SetActive(false);

            return(inst);
        }
        public void EquipInventory()
        {
            //Runtime Weapons

            if (right_Index > rightHand_Indexes.Count - 1)
            {
                right_Index = 0;
            }
            rightHandWeapon = rightHand_Indexes[right_Index];

            if (left_Index > leftHand_Indexes.Count - 1)
            {
                left_Index = 0;
            }
            leftHandWeapon = leftHand_Indexes[left_Index];

            //RightHand Weapons
            EquipWeapon(rightHandWeapon, false);

            //LeftHand weapons
            EquipWeapon(leftHandWeapon, true);
            //hasLeftHandWeapon = true;

            //Consumables
            if (consumable_Index > consumable_Indexes.Count - 1)
            {
                consumable_Index = 0;
            }

            EquipConsumable(consumable_Indexes[consumable_Index]);


            //Spells
            if (runtime_Spells.Count > 0)
            {
                if (spell_Index > runtime_Spells.Count)
                {
                    spell_Index = 0;
                }

                EquipSpell(runtime_Spells[spell_Index]);
            }
            else
            {
                quickSlotManager.ClearSlot(QSlotType.spell);
            }
        }
        public void EquipWeapon(RuntimeWeapon weapon, bool isLeft = false)
        {
            if (isLeft)
            {
                if (leftHandWeapon != null)
                {
                    leftHandWeapon.weaponModel.SetActive(false);
                }

                leftHandWeapon = weapon;
            }
            else
            {
                if (rightHandWeapon != null)
                {
                    rightHandWeapon.weaponModel.SetActive(false);
                }

                rightHandWeapon = weapon;
            }

            string targetIdle = weapon.Instance.oh_idle;

            targetIdle += (isLeft) ? StaticStrings._leftPrefix : StaticStrings._rightPrefix;
            states.animator.SetBool(StaticStrings.animParam_Mirror, isLeft);
            states.animator.Play(StaticStrings.animState_ChangeWeapon);
            //Debug.Log("TargetIdle: " + targetIdle);
            states.animator.Play(targetIdle);

            Item i = ResourcesManager.Instance.GetItem(weapon.Instance.item_id, Itemtype.Weapon);

            quickSlotManager.UpdateSlot(
                (isLeft) ?
                QSlotType.leftHand : QSlotType.rightHand, i.itemIcon);

            weapon.weaponModel.SetActive(true);
        }
        public void LoadInventory(bool updateActions = false)
        {
            SessionManager sessionManger = SessionManager.Instance;

            unarmedRunTimeWeapon           = WeaponToRuntimeWeapon(ResourcesManager.Instance.GetWeapon(unarmedId), false);
            unarmedRunTimeWeapon.isUnarmed = true;

            //3 --> number of equipment slots in inventory
            for (int i = 0; i < 3; i++)
            {
                runtime_Right_Weapons.Add(unarmedRunTimeWeapon);
                runtime_Left_Weapons.Add(unarmedRunTimeWeapon);
            }

            //There are 10 slots for consumables in inventory
            for (int i = 0; i < 10; i++)
            {
                runtime_Consumables.Add(emptyItem);
            }

            for (int i = 0; i < rightHandWeapons.Count; i++)
            {
                if (rightHandWeapons[i] == -1)
                {
                    runtime_Right_Weapons[i] = unarmedRunTimeWeapon;
                }
                else
                {
                    ItemInventoryInstance invInstance = sessionManger.GetWeaponItem(rightHandWeapons[i]);
                    RuntimeWeapon         weapon      = WeaponToRuntimeWeapon(ResourcesManager.Instance.GetWeapon(invInstance.itemId));
                    runtime_Right_Weapons[i] = weapon;
                }
            }

            for (int i = 0; i < leftHandWeapons.Count; i++)
            {
                if (leftHandWeapons[i] == -1)
                {
                    runtime_Left_Weapons[i] = unarmedRunTimeWeapon;
                }
                else
                {
                    ItemInventoryInstance invInstance = sessionManger.GetWeaponItem(leftHandWeapons[i]);
                    RuntimeWeapon         weapon      = WeaponToRuntimeWeapon(ResourcesManager.Instance.GetWeapon(invInstance.itemId), true);
                    runtime_Left_Weapons[i] = weapon;
                }
            }

            for (int i = 0; i < spellItems.Count; i++)
            {
                SpellToRuntimeSpell(ResourcesManager.Instance.GetSpell(spellItems[i]));
            }

            emptyItem         = ConsumableToRunTime(ResourcesManager.Instance.GetConsumable("empty"));
            emptyItem.isEmpty = true;
            //Consumables
            for (int i = 0; i < consumableItems.Count; i++)
            {
                if (consumableItems[i] == -1)
                {
                    runtime_Consumables[i] = emptyItem;
                }
                else
                {
                    ItemInventoryInstance invInstance       = sessionManger.GetConsumableItem(consumableItems[i]);
                    RuntimeConsumableItem runtimeConsumable = ConsumableToRunTime(ResourcesManager.Instance.GetConsumable(invInstance.itemId));
                    runtime_Consumables[i] = runtimeConsumable;
                }
            }

            InitAllDamageColliders(states);
            CloseAllDamageColliders();

            MakeIndexesList();
            EquipInventory();

            if (updateActions)
            {
                states.actionManager.UpdateActionsOneHanded();
            }
        }
        public void ClearReferences()
        {
            if (runtime_Right_Weapons != null)
            {
                //Clear right hand weapons
                for (int i = 0; i < runtime_Right_Weapons.Count; i++)
                {
                    Destroy(runtime_Right_Weapons[i].weaponModel);
                }

                runtime_Right_Weapons.Clear();
            }

            if (runtime_Left_Weapons != null)
            {
                //Clear left hand weapons
                for (int i = 0; i < runtime_Left_Weapons.Count; i++)
                {
                    Destroy(runtime_Left_Weapons[i].weaponModel);
                }

                runtime_Left_Weapons.Clear();
            }

            leftHandWeapon  = null;
            rightHandWeapon = null;

            if (runtime_Consumables != null)
            {
                //Clear consumables
                for (int i = 0; i < runtime_Consumables.Count; i++)
                {
                    if (runtime_Consumables[i] != null)
                    {
                        if (runtime_Consumables[i].consumableModel)
                        {
                            Destroy(runtime_Consumables[i].consumableModel);
                        }
                    }
                }

                runtime_Consumables.Clear();
            }

            if (runtime_Spells != null)
            {
                for (int i = 0; i < runtime_Spells.Count; i++)
                {
                    if (runtime_Spells[i].currentParticle)
                    {
                        Destroy(runtime_Spells[i].currentParticle);
                    }
                }

                runtime_Spells.Clear();
            }

            if (referencesParent)
            {
                Destroy(referencesParent);
            }
            referencesParent = new GameObject("Run Time References");
        }