using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
|
|
namespace vnxbqy.UI
|
{
|
|
public class EquipFightPower : Singleton<EquipFightPower>
|
{
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
EquipModel equipModel { get { return ModelCenter.Instance.GetModel<EquipModel>(); } }
|
EquipStarModel starModel { get { return ModelCenter.Instance.GetModel<EquipStarModel>(); } }
|
EquipTrainModel trainModel { get { return ModelCenter.Instance.GetModel<EquipTrainModel>(); } }
|
EquipStrengthModel strengthenModel { get { return ModelCenter.Instance.GetModel<EquipStrengthModel>(); } }
|
EquipGemModel gemModel { get { return ModelCenter.Instance.GetModel<EquipGemModel>(); } }
|
|
string scoreFormula;
|
string propertyFormula;
|
|
public EquipFightPower()
|
{
|
var config = FuncConfigConfig.Get("FightpowerFormula");
|
propertyFormula = config.Numerical1;
|
scoreFormula = config.Numerical2;
|
}
|
|
public int GetSpiritWeaponPower(int itemId)
|
{
|
var score = ItemLogicUtility.Instance.GetEquipScore(itemId);
|
Equation.Instance.Clear();
|
Equation.Instance.AddKeyValue("equipScoreTotal", score);
|
return Equation.Instance.Eval<int>(scoreFormula);
|
}
|
|
public int CalculatePower(int level)
|
{
|
Equation.Instance.Clear();
|
Equation.Instance.AddKeyValue("equipScoreTotal", CountEquipScore(level));
|
var power = Equation.Instance.Eval<int>(scoreFormula);
|
|
var propertyContainer = new Properties();
|
CountProperties(level, ref propertyContainer);
|
|
Equation.Instance.Clear();
|
var keys = propertyContainer.keys;
|
for (int i = 0; i < keys.Count; i++)
|
{
|
var id = keys[i];
|
var value = propertyContainer[id];
|
var config = PlayerPropertyConfig.Get(id);
|
Equation.Instance.AddKeyValue(config.Parameter, value);
|
}
|
|
var propertyPower = Equation.Instance.Eval<int>(propertyFormula);
|
power += propertyPower;
|
|
var skillIds = CountEightSuitSkills(level);
|
if (!skillIds.IsNullOrEmpty())
|
{
|
foreach (var skillId in skillIds)
|
{
|
var config = SkillConfig.Get(skillId);
|
power += config.FightPower;
|
}
|
}
|
|
return power;
|
}
|
|
private int CountEquipScore(int level)
|
{
|
var score = 0;
|
for (int i = 1; i <= 12; i++)
|
{
|
var equipPosition = new Int2(level, i);
|
var guid = equipModel.GetEquip(equipPosition);
|
if (string.IsNullOrEmpty(guid))
|
{
|
continue;
|
}
|
|
var equip = packModel.GetItemByGuid(guid);
|
if (equip == null)
|
{
|
continue;
|
}
|
|
score += equip.score;
|
}
|
|
return score;
|
}
|
|
private List<int> CountEightSuitSkills(int level)
|
{
|
var eightSuitLevel = equipModel.GetSuitLevel(level, EquipSuitType.EightSuit);
|
return CountEightSuitSkills(PlayerDatas.Instance.baseData.Job, level, eightSuitLevel);
|
}
|
|
private List<int> CountEightSuitSkills(int job, int level, int eightSuitLevel)
|
{
|
var skills = new List<int>();
|
|
List<EquipSuitConfig> eightConfigs = null;
|
if (eightSuitLevel >= 0)
|
{
|
eightConfigs = EquipSuitConfig.GetConfigs(job, level, EquipSuitType.EightSuit);
|
}
|
|
for (int i = 9; i >= 0; i--)
|
{
|
if (i % 3 != 0)
|
{
|
continue;
|
}
|
|
if (eightSuitLevel >= i)
|
{
|
var config = eightConfigs.Find(x => { return x.star == i; });
|
if (config.skillID > 0)
|
{
|
skills.Add(config.skillID);
|
}
|
}
|
}
|
|
return skills;
|
}
|
|
private void CountProperties(int level, ref Properties container)
|
{
|
CountSuitProperties(level, ref container);
|
CountStrengthenProperties(level, ref container);
|
CountStarProperties(level, ref container);
|
CountGemProperties(level, ref container);
|
CountTrainProperties(level, ref container);
|
}
|
|
private void CountSuitProperties(int level, ref Properties container)
|
{
|
var twoSuitLevel = equipModel.GetSuitLevel(level, EquipSuitType.TwoSuit);
|
var fiveSuitLevel = equipModel.GetSuitLevel(level, EquipSuitType.FiveSuit);
|
var eightSuitLevel = equipModel.GetSuitLevel(level, EquipSuitType.EightSuit);
|
|
CountSuitProperties(level, twoSuitLevel, fiveSuitLevel, eightSuitLevel, ref container);
|
}
|
|
private void CountSuitProperties(int level, int twoLevel, int fiveLevel, int eightLevel, ref Properties container)
|
{
|
List<EquipSuitConfig> twoConfigs = null;
|
if (twoLevel >= 0)
|
{
|
twoConfigs = EquipSuitConfig.GetConfigs(PlayerDatas.Instance.baseData.Job, level, EquipSuitType.TwoSuit);
|
}
|
|
List<EquipSuitConfig> fiveConfigs = null;
|
if (fiveLevel >= 0)
|
{
|
fiveConfigs = EquipSuitConfig.GetConfigs(PlayerDatas.Instance.baseData.Job, level, EquipSuitType.FiveSuit);
|
}
|
|
List<EquipSuitConfig> eightConfigs = null;
|
if (eightLevel >= 0)
|
{
|
eightConfigs = EquipSuitConfig.GetConfigs(PlayerDatas.Instance.baseData.Job, level, EquipSuitType.EightSuit);
|
}
|
|
for (int i = 9; i >= 0; i--)
|
{
|
if (i % 3 != 0)
|
{
|
continue;
|
}
|
|
if (twoLevel >= i)
|
{
|
var config = twoConfigs.Find(x => { return x.star == i; });
|
foreach (var property in config.attr)
|
{
|
container.Add(property.x, property.y);
|
}
|
}
|
|
if (fiveLevel >= i)
|
{
|
var config = fiveConfigs.Find(x => { return x.star == i; });
|
foreach (var property in config.attr)
|
{
|
container.Add(property.x, property.y);
|
}
|
}
|
|
if (eightLevel >= i)
|
{
|
var config = eightConfigs.Find(x => { return x.star == i; });
|
foreach (var property in config.attr)
|
{
|
container.Add(property.x, property.y);
|
}
|
}
|
}
|
|
}
|
|
private void CountStrengthenProperties(int level, ref Properties container)
|
{
|
for (int i = 1; i <= 12; i++)
|
{
|
var equipPosition = new Int2(level, i);
|
var equip = equipModel.GetEquip(equipPosition);
|
if (string.IsNullOrEmpty(equip))
|
{
|
continue;
|
}
|
|
var type = EquipStrengthModel.GetEquipStrengthType(i);
|
var strengthenLevel = strengthenModel.GetStrengthLevel(level, i);
|
CountStrengthenProperties(type, strengthenLevel, ref container);
|
}
|
}
|
|
private void CountStrengthenProperties(int type, int strengthenLevel, ref Properties container)
|
{
|
var config = ItemPlusConfig.GetTypeAndLevel(type, strengthenLevel);
|
var min = Mathf.Min(config.attType.Length, config.attValue.Length);
|
for (int i = 0; i < min; i++)
|
{
|
container.Add(config.attType[i], config.attValue[i]);
|
}
|
}
|
|
private void CountStarProperties(int level, ref Properties container)
|
{
|
for (int i = 1; i <= 12; i++)
|
{
|
var equipPosition = new Int2(level, i);
|
var equip = equipModel.GetEquip(equipPosition);
|
if (string.IsNullOrEmpty(equip))
|
{
|
continue;
|
}
|
|
var star = starModel.GetEquipStarLevel(equipPosition);
|
CountStarProperties(level, i, star, ref container);
|
}
|
}
|
|
private void CountStarProperties(int level, int place, int star, ref Properties container)
|
{
|
var config = EquipStarConfig.Get(level, place, star);
|
if (config == null)
|
{
|
return;
|
}
|
|
foreach (var property in config.BaseAttrInfo)
|
{
|
container.Add(property.x, property.y);
|
}
|
|
foreach (var property in config.StarAttrInfo)
|
{
|
container.Add(property.x, property.y);
|
}
|
}
|
|
private void CountGemProperties(int level, ref Properties container)
|
{
|
for (int i = 1; i <= 12; i++)
|
{
|
var equipPosition = new Int2(level, i);
|
var equip = equipModel.GetEquip(equipPosition);
|
if (string.IsNullOrEmpty(equip))
|
{
|
continue;
|
}
|
|
for (int holeIndex = 0; holeIndex < 4; holeIndex++)
|
{
|
if (!gemModel.IsEquipGemHoleOpen(equipPosition.x, equipPosition.y, holeIndex))
|
{
|
continue;
|
}
|
|
var gem = 0;
|
if (!gemModel.TryGetEquipGem(equipPosition.x, equipPosition.y, holeIndex, out gem))
|
{
|
continue;
|
}
|
|
CountGemItemProperties(gem, ref container);
|
}
|
}
|
|
}
|
|
private void CountGemItemProperties(int gem, ref Properties container)
|
{
|
var config = ItemConfig.Get(gem);
|
if (config == null)
|
{
|
return;
|
}
|
|
if (config.Effect2 > 0)
|
{
|
container.Add(config.Effect2, config.EffectValueA2);
|
}
|
|
if (config.Effect3 > 0)
|
{
|
container.Add(config.Effect3, config.EffectValueA3);
|
}
|
|
if (config.Effect4 > 0)
|
{
|
container.Add(config.Effect4, config.EffectValueA4);
|
}
|
|
if (config.Effect5 > 0)
|
{
|
container.Add(config.Effect5, config.EffectValueA5);
|
}
|
}
|
|
private void CountTrainProperties(int level, ref Properties container)
|
{
|
for (int i = 1; i <= 12; i++)
|
{
|
var equipPosition = new Int2(level, i);
|
var equip = equipModel.GetEquip(equipPosition);
|
if (string.IsNullOrEmpty(equip))
|
{
|
continue;
|
}
|
|
var trainLevel = trainModel.GetTrainLevel(equipPosition);
|
if (trainLevel <= 0)
|
{
|
continue;
|
}
|
|
var type = EquipTrainModel.GetTrainType(equipPosition.y);
|
var data = EquipWashConfig.Get(type, trainLevel);
|
if (data == null)
|
{
|
continue;
|
}
|
|
var trainedProperties = trainModel.GetTrainedProperties(equipPosition);
|
container.Add(data.config.attType1, Mathf.Min(data.config.attMax1, trainedProperties.x));
|
container.Add(data.config.attType2, Mathf.Min(data.config.attMax2, trainedProperties.y));
|
//container.Add(data.config.attType3, Mathf.Min(data.config.attMax3, trainedProperties.z));
|
}
|
|
}
|
|
public int CalculatePower(int job, int level, List<EquipInfo> equipInfos)
|
{
|
var propertyContainer = new Properties();
|
var totalScore = 0;
|
|
var stars = new List<int>();
|
foreach (var info in equipInfos)
|
{
|
totalScore += info.score;
|
stars.Add(info.starLevel);
|
|
var config = ItemConfig.Get(info.itemId);
|
var strengthenType = EquipStrengthModel.GetEquipStrengthType(config.EquipPlace);
|
CountStrengthenProperties(strengthenType, info.strengthenLevel, ref propertyContainer);
|
CountStarProperties(config.LV, config.EquipPlace, info.starLevel, ref propertyContainer);
|
|
if (!info.stones.IsNullOrEmpty())
|
{
|
foreach (var gem in info.stones)
|
{
|
CountGemItemProperties(gem, ref propertyContainer);
|
}
|
}
|
|
if (!info.trainProperties.IsNullOrEmpty())
|
{
|
foreach (var property in info.trainProperties)
|
{
|
propertyContainer.Add(property.x, property.y);
|
}
|
}
|
}
|
|
stars.Sort((int x, int y) => { return x.CompareTo(y); });
|
var twoSuitLevel = stars.Count > 1 ? stars[1] : -1;
|
var fiveSuitLevel = stars.Count > 4 ? stars[4] : -1;
|
var eightSuitLevel = stars.Count > 7 ? stars[7] : -1;
|
CountSuitProperties(level, twoSuitLevel, fiveSuitLevel, eightSuitLevel, ref propertyContainer);
|
|
Equation.Instance.Clear();
|
Equation.Instance.AddKeyValue("equipScoreTotal", totalScore);
|
var power = Equation.Instance.Eval<int>(scoreFormula);
|
|
Equation.Instance.Clear();
|
var keys = propertyContainer.keys;
|
for (int i = 0; i < keys.Count; i++)
|
{
|
var id = keys[i];
|
var value = propertyContainer[id];
|
var config = PlayerPropertyConfig.Get(id);
|
if (config != null)
|
{
|
Equation.Instance.AddKeyValue(config.Parameter, value);
|
}
|
|
}
|
|
power += Equation.Instance.Eval<int>(propertyFormula);
|
|
var skills = CountEightSuitSkills(job, level, eightSuitLevel);
|
if (!skills.IsNullOrEmpty())
|
{
|
foreach (var skill in skills)
|
{
|
var config = SkillConfig.Get(skill);
|
power += config.FightPower;
|
}
|
}
|
|
return power;
|
}
|
|
class Properties
|
{
|
Dictionary<int, int> tables = new Dictionary<int, int>();
|
|
public List<int> keys { get { return new List<int>(tables.Keys); } }
|
|
public int this[int id] { get { return tables[id]; } }
|
|
public void Add(int id, int value)
|
{
|
if (id == 7)
|
{
|
Add(67, value);
|
Add(68, value);
|
}
|
else
|
{
|
if (tables.ContainsKey(id))
|
{
|
tables[id] = tables[id] + value;
|
}
|
else
|
{
|
tables[id] = value;
|
}
|
}
|
}
|
|
public void AddRange(List<int> ids, List<int> values)
|
{
|
if (ids.IsNullOrEmpty() || values.IsNullOrEmpty())
|
{
|
return;
|
}
|
|
var count = Mathf.Min(ids.Count, values.Count);
|
for (int i = 0; i < count; i++)
|
{
|
Add(ids[i], values[i]);
|
}
|
}
|
|
}
|
|
public struct EquipInfo
|
{
|
public int itemId;
|
public int score;
|
public int strengthenLevel;
|
public int evolveLevel;
|
public int breakLevel;
|
public int starLevel;
|
public List<int> stones;
|
public List<Int2> trainProperties;
|
}
|
|
}
|
|
}
|