Beispiel #1
0
 public void Handle(EquipmentChanged arg)
 {
     RefreshItem();
 }
Beispiel #2
0
        public bool TryEquip(IEquipmentHolder holder, Entity item)
        {
            if (item == null || holder == null)
            {
                return(false);
            }
            if (item == holder.Item)
            {
                holder.LastEquipStatus = "Already equipped";
                return(false);
            }
            for (int i = 0; i < holder.RequiredTypes.Length; i++)
            {
                if (!item.HasReference(holder.RequiredTypes[i]))
                {
                    holder.LastEquipStatus = "Wrong type";
                    return(false);
                }
            }
            var equipNode = item.GetNode <EquipmentNode>();

            if (equipNode == null)
            {
                holder.LastEquipStatus = "Item is bugged";
                return(false);
            }
            if (equipNode.Item == null)
            {
                holder.LastEquipStatus = "No Inventory Slot";
                return(false);
            }
            var owner = holder.Owner;

            if (owner == null)
            {
                holder.LastEquipStatus = "Holder has no owner";
                return(false);
            }
            if (holder.CompatibleSlots != null && (equipNode.Equipment == null || !holder.CompatibleSlots.Contains(equipNode.Equipment.EquipmentSlotType)))
            {
                holder.LastEquipStatus = "Wrong Slot";
                return(false);
            }
            if (equipNode.SkillRequirement != null)
            {
                var skill = owner.Get <StatsContainer>().Get <SkillStat>(equipNode.SkillRequirement.Skill);
                if (skill != null && skill.CurrentRank < equipNode.SkillRequirement.Required)
                {
                    holder.LastEquipStatus = "Skill too low";
                    return(false);
                }
            }
            if (holder.Item != null)
            {
                if (!ClearAndAddToInventory(holder, true))
                {
                    return(false);
                }
            }
            holder.Item = item;
            equipNode.Item.Inventory?.Remove(item);
            item.ParentId = owner;
            SetStats(holder, equipNode);
            equipNode.Item.SetContainer(holder.Container);
            holder.OnItemChanged?.Invoke(item);
            var msg = new EquipmentChanged(owner, holder);

            item.Post(msg);
            owner.Post(msg);
            holder.LastEquipStatus = "";
            return(true);
        }