少年修仙传客户端代码仓库
client_Wu Xijin
2018-12-04 31efa47c430874f95f4ff5503372f0cf6ecb53ae
System/KnapSack/Logic/ItemTipsModel.cs
@@ -1692,6 +1692,8 @@
        public Dictionary<int, int> SetItemEffectDict(ItemConfig config)
        {
            Dictionary<int, int> itemEffectDict = new Dictionary<int, int>();
            if (config == null) return itemEffectDict;
            try
            {
                if (config.Effect1 != 0)
@@ -1879,6 +1881,230 @@
        #region 设置物品使用的限制条件
        #endregion
        #region 物品增加战斗力
        PlayerMountDatas mountDatas { get { return ModelCenter.Instance.GetModel<PlayerMountDatas>(); } }
        public PlayerStrengthengDatas strengthengmodel
        {
            get
            {
                return  ModelCenter.Instance.GetModel<PlayerStrengthengDatas>();
            }
        }
        public bool TryGetFightPowerByItemId(int itemId,out int fightPower)
        {
            fightPower = 0;
            ItemConfig itemConfig = Config.Instance.Get<ItemConfig>(itemId);
            if (itemConfig == null) return false;
            var attrIdlist = Config.Instance.GetAllKeys<PlayerPropertyConfig>();
            Dictionary<int, int> attrDict = new Dictionary<int, int>();
            Dictionary<int, int> itemEffectDict = SetItemEffectDict(itemConfig);
            int atk = 0;
            int hp = 0;
            int def = 0;
            foreach(var attrId in itemEffectDict.Keys)
            {
                var attrValue = itemEffectDict[attrId];
                switch ((AttrEnum)attrId)
                {
                    case AttrEnum.ATK:
                        atk += attrValue;
                        break;
                    case AttrEnum.HP:
                        hp += attrValue;
                        break;
                    case AttrEnum.DEF:
                        def += attrValue;
                        break;
                    case AttrEnum.HorseAtkPer:
                        float mountAtk = mountDatas.GetAllMountAttack();
                        atk += Mathf.RoundToInt(mountAtk * ((float)attrValue / 10000));
                        break;
                    case AttrEnum.StoneBasePer:
                        var stoneDict = GetStoneAttrDict();
                        foreach (var key in stoneDict.Keys)
                        {
                            var stoneValue = stoneDict[key];
                            switch ((AttrEnum)key)
                            {
                                case AttrEnum.ATK:
                                    atk += Mathf.RoundToInt(stoneValue *((float)attrValue / 10000));
                                    break;
                                case AttrEnum.HP:
                                    hp += Mathf.RoundToInt(stoneValue * ((float)attrValue / 10000));
                                    break;
                                case AttrEnum.DEF:
                                    def += Mathf.RoundToInt(stoneValue * ((float)attrValue / 10000));
                                    break;
                            }
                        }
                        break;
                    case AttrEnum.RealmBasePer:
                        var realmDict = GetRealmAttrDict();
                        foreach (var key in realmDict.Keys)
                        {
                            var realmValue = realmDict[key];
                            switch ((AttrEnum)key)
                            {
                                case AttrEnum.ATK:
                                    atk += Mathf.RoundToInt(realmValue * ((float)attrValue / 10000));
                                    break;
                                case AttrEnum.HP:
                                    hp += Mathf.RoundToInt(realmValue * ((float)attrValue / 10000));
                                    break;
                                case AttrEnum.DEF:
                                    def += Mathf.RoundToInt(realmValue * ((float)attrValue / 10000));
                                    break;
                            }
                        }
                        break;
                    case AttrEnum.PetSkillAtkRate:
                        break;
                    case AttrEnum.PlusBaseAtkPer:
                        var strengthDict = GetStrengthAttrDict();
                        if(strengthDict.ContainsKey((int)AttrEnum.ATK))
                        {
                            var strengthValue = strengthDict[(int)AttrEnum.ATK];
                            atk += Mathf.RoundToInt(strengthValue * ((float)attrValue / 10000));
                        }
                        break;
                    default:
                        if(attrIdlist.Contains(attrId.ToString()))
                        {
                            attrDict.Add(attrId,attrValue);
                        }
                        break;
                }
            }
            if(atk > 0)
            {
                attrDict.Add((int)AttrEnum.ATK,atk);
            }
            if(def > 0)
            {
                attrDict.Add((int)AttrEnum.DEF,def);
            }
            if(hp > 0)
            {
                attrDict.Add((int)AttrEnum.HP,hp);
            }
            fightPower = UIHelper.GetFightPower(attrDict);
            return fightPower > 0;
        }
        private Dictionary<int,int> GetStoneAttrDict()
        {
            Dictionary<int, int> attrDict = new Dictionary<int, int>();
            var stoneDict = PlayerStoneData.Instance.GetAllStone();
            foreach(var key in stoneDict.Keys)
            {
                var stoneIds = stoneDict[key];
                var itemModel = playerPack.GetItemModelByIndex(PackType.rptEquip,key);
                if (itemModel != null && stoneIds != null)
                {
                   for(int i = 0; i < stoneIds.Length; i++)
                    {
                        int stoneId = (int)stoneIds[i];
                        ItemConfig itemConfig = Config.Instance.Get<ItemConfig>(stoneId);
                        if(itemConfig != null)
                        {
                            var itemEffectDict = SetItemEffectDict(itemConfig);
                            foreach (var attrId in itemEffectDict.Keys)
                            {
                                var attrValue = itemEffectDict[attrId];
                                if (!attrDict.ContainsKey(attrId))
                                {
                                    attrDict.Add(attrId, attrValue);
                                }
                                else
                                {
                                    attrDict[attrId] += attrValue;
                                }
                            }
                        }
                    }
                }
            }
            return attrDict;
        }
        private Dictionary<int,int> GetRealmAttrDict()
        {
            Dictionary<int, int> attrDict = new Dictionary<int, int>();
            int realmLv = PlayerDatas.Instance.baseData.realmLevel;
            var realmConfig = Config.Instance.Get<RealmConfig>(realmLv);
            if(realmConfig != null)
            {
                var attrIds = realmConfig.AddAttrType;
                var attrValues = realmConfig.AddAttrNum;
                if(attrIds != null && attrValues != null
                    && attrIds.Length == attrValues.Length)
                {
                    for (int i = 0; i < attrIds.Length; i++)
                    {
                        var attrId = attrIds[i];
                        var attrValue = attrValues[i];
                        if(attrValue > 0)
                        {
                            if (!attrDict.ContainsKey(attrId))
                            {
                                attrDict.Add(attrId, attrValue);
                            }
                            else
                            {
                                attrDict[attrId] += attrValue;
                            }
                        }
                    }
                }
            }
            return attrDict;
        }
        private Dictionary<int,int> GetStrengthAttrDict()
        {
            Dictionary<int, int> attrDict = new Dictionary<int, int>();
            var strengthDict = strengthengmodel._EqInfo;
            foreach(var index in strengthDict.Keys)
            {
                var itemModel = playerPack.GetItemModelByIndex(PackType.rptEquip, index);
                if(itemModel != null)
                {
                    int lv = strengthengmodel.StrengthenTheCeiling(index);
                    int type = strengthengmodel.GameDefineIndex(index);
                    var itemPlus = ItemPlusConfig.GetItemPlusData(type, lv);
                    if (itemPlus != null)
                    {
                        int[] attrIDs = itemPlus.attrIds;
                        int[] attrValues = itemPlus.attrValues;
                        for (int i = 0; i < attrIDs.Length; i++)
                        {
                            var attrId = attrIDs[i];
                            var attrValue = attrValues[i];
                            if (attrValue > 0)
                            {
                                if (!attrDict.ContainsKey(attrId))
                                {
                                    attrDict.Add(attrId, attrValue);
                                }
                                else
                                {
                                    attrDict[attrId] += attrValue;
                                }
                            }
                        }
                    }
                }
            }
            return attrDict;
        }
        #endregion
    }
    public class ItemAttrData