Exemple #1
0
        public bool IsCurrentlyEquipped(Item_Equipment equipment)
        {
            foreach (var a in equippedAttachmentDic)
            {
                if (a.Value == equipment)
                {
                    return(true);
                }
            }

            foreach (var a in equippedArmorDic)
            {
                if (a.Value == equipment)
                {
                    return(true);
                }
            }

            if (equipment is Item_Weapon)
            {
                var weapon = equipment as Item_Weapon;
                if (EquippedWeapon == weapon)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #2
0
        private void OnWeaponEquipped(Item_Equipment oldWeapon, Item_Equipment newWeapon)
        {
            if (newWeapon is Item_Weapon == false)
            {
                return;
            }

            Unit.UnitAnimator.Params.Is2H = (newWeapon as Item_Weapon).WeaponType == WeaponType.TwoHand;
        }
Exemple #3
0
        private void OnEquippedWeapon(Item_Equipment oldWeapon, Item_Equipment newWeapon)
        {
            if (newWeapon is Item_Weapon == false)
            {
                return;
            }

            if ((newWeapon as Item_Weapon).WeaponType == WeaponType.TwoHand)
            {
                currentCombatAnimDataContainer = combatAnimDataContainer2H;
            }
            else
            {
                currentCombatAnimDataContainer = combatAnimDataContainer;
            }
        }
Exemple #4
0
 private void OnEquipped(Item_Equipment oldEquipment, Item_Equipment newEquipment)
 {
     Debug.Log($"Old : {oldEquipment?.ItemName} | New : {newEquipment.ItemName}");
     UpdateValue();
 }
Exemple #5
0
 private void OnUnequipped(Item_Equipment equipment)
 {
     Debug.Log($"Old : {equipment.ItemName}");
     UpdateValue();
 }
Exemple #6
0
        public void UnequipModularPart(Item_ModularBodyPart modularBodyPart)
        {
            // ===============================================================================================
            // Get default part
            // ===============================================================================================
            var modularMetadata = ResourcesLoader.Instance.LoadModularBodyMetadata();
            var defaults        = modularMetadata.objs
                                  .Where(x => x.Gender == modularBodyPart.Gender &&
                                         x.IsDefault == true);

            Item_ModularBodyPart_Metadata?defaultPart = null;
            Item_Armor      armor      = null;
            Item_Attachment attachment = null;

            if (modularBodyPart is Item_Armor)
            {
                armor       = modularBodyPart as Item_Armor;
                defaultPart = defaults.FirstOrDefault(x => x.ArmorType == armor.Type);
            }
            else
            {
                attachment  = modularBodyPart as Item_Attachment;
                defaultPart = defaults.FirstOrDefault(x => x.AttachmentType == attachment.Type);
            }

            if (defaultPart == null || defaultPart.HasValue == false)
            {
                string type = armor == null?armor.Type.ToString() : attachment.Type.ToString();

                Debug.Log($"Faile to unequip. Default part was not found!! ItemType : {modularBodyPart.ItemType} | Type : {type}");
                return;
            }

            // ===============================================================================================
            // Split the path to the Transform part
            // ===============================================================================================
            var splitCurrentEquippedPart = modularBodyPart.PartLocation.Split('/').ToList();
            var splitDefaultPart         = string.IsNullOrEmpty(defaultPart.Value.PartLocation) ?
                                           null : defaultPart.Value.PartLocation.Split('/').ToList();

            splitCurrentEquippedPart.RemoveAt(0);
            splitDefaultPart?.RemoveAt(0);

            // ===============================================================================================
            // Get the equip part by searching it through child
            // ===============================================================================================
            var portraitPart = portraitTransform;
            var ownerPart    = UnitTransform;

            var defaultPortaitPart = portraitTransform;
            var defaultOwnerPart   = ownerPart;

            while (splitCurrentEquippedPart.Count > 0)
            {
                portraitPart = GetChildTransformWithName(portraitPart, splitCurrentEquippedPart[0]);
                ownerPart    = GetChildTransformWithName(ownerPart, splitCurrentEquippedPart[0]);
                splitCurrentEquippedPart.RemoveAt(0);

                if (splitDefaultPart != null)
                {
                    defaultPortaitPart = GetChildTransformWithName(defaultPortaitPart, splitDefaultPart[0]);
                    defaultOwnerPart   = GetChildTransformWithName(defaultOwnerPart, splitDefaultPart[0]);

                    splitDefaultPart.RemoveAt(0);
                }
            }

            // ===============================================================================================
            // Finally, activate the equip
            // ===============================================================================================
            ownerPart.gameObject.SetActive(false);
            portraitPart?.gameObject.SetActive(false);
            if (splitDefaultPart != null)
            {
                defaultPortaitPart?.gameObject.SetActive(true);
                defaultOwnerPart.gameObject.SetActive(true);
            }

            // ===============================================================================================
            // Register equip item to dictionary
            // ===============================================================================================
            Item_Equipment oldEquipment = null;

            if (modularBodyPart is Item_Attachment)
            {
                var itemAttachment = modularBodyPart as Item_Attachment;
                oldEquipment = itemAttachment;
                equippedAttachmentDic[itemAttachment.Type] = null;
            }
            else if (modularBodyPart is Item_Armor)
            {
                var itemArmor = modularBodyPart as Item_Armor;
                oldEquipment = itemArmor;
                equippedArmorDic[itemArmor.Type] = null;
            }

            // ===============================================================================================
            // Fire on unequipped event
            // ===============================================================================================
            OnUnequippedEvent.Invoke(oldEquipment);
        }
Exemple #7
0
        public void EquipModularPart(Item_ModularBodyPart modularPart)
        {
            // ===============================================================================================
            // Split the path to the Transform part
            // ===============================================================================================
            var split = modularPart.PartLocation.Split('/').ToList();

            split.RemoveAt(0);

            // ===============================================================================================
            // Get the equip part by searching it through child
            // ===============================================================================================
            var portraitPart = portraitTransform;
            var ownerPart    = UnitTransform;

            while (split.Count > 0)
            {
                portraitPart = GetChildTransformWithName(portraitPart, split[0]);
                ownerPart    = GetChildTransformWithName(ownerPart, split[0]);
                split.RemoveAt(0);
            }

            // ===============================================================================================
            // Deactivate all parts with same type as the equip item
            // ===============================================================================================
            var portaitPartParent = portraitPart?.parent;
            var ownerPartParent   = ownerPart.parent;

            for (int i = 0; i < ownerPartParent.childCount; i++)
            {
                if (ownerPartParent.GetChild(i) == ownerPart)
                {
                    continue;
                }

                portaitPartParent?.GetChild(i).gameObject.SetActive(false);
                ownerPartParent.GetChild(i).gameObject.SetActive(false);
            }

            // ===============================================================================================
            // Finally, activate the equip
            // ===============================================================================================
            ownerPart.gameObject.SetActive(true);
            portraitPart?.gameObject.SetActive(true);

            // ===============================================================================================
            // Register equip item to dictionary
            // ===============================================================================================
            Item_Equipment oldEquipment = null;

            if (modularPart is Item_Armor)
            {
                var itemArmor = modularPart as Item_Armor;
                oldEquipment = equippedArmorDic[itemArmor.Type];
                equippedArmorDic[itemArmor.Type] = itemArmor;
            }
            else if (modularPart is Item_Attachment)
            {
                var itemAttachment = modularPart as Item_Attachment;
                oldEquipment = equippedAttachmentDic[itemAttachment.Type];
                equippedAttachmentDic[itemAttachment.Type] = itemAttachment;
            }

            // ===============================================================================================
            // Fire on equipped event (left hand is old, right hand is new)
            // ===============================================================================================
            OnEquippedEvent.Invoke(oldEquipment, modularPart);
        }