CombatHeroInfo.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Core.Language;
  4. using Core.Utility;
  5. using Excel2Json;
  6. using Fort23.UTool;
  7. using GameLogic.Combat.CombatTool;
  8. using GameLogic.Hero;
  9. using UnityEngine;
  10. using UnityEngine.Serialization;
  11. using Utility;
  12. [System.Serializable]
  13. public class CombatHeroInfo
  14. {
  15. public enum AttributeType
  16. {
  17. Hp,
  18. Att,
  19. Def,
  20. }
  21. public int modelID;
  22. public EncryptionLong hp = new EncryptionLong();
  23. public EncryptionLong defense = new EncryptionLong();
  24. public EncryptionLong attack = new EncryptionLong();
  25. /// <summary>
  26. /// 闪避 evasion
  27. /// </summary>
  28. public EncryptionInt shanbi = new EncryptionInt();
  29. /// <summary>
  30. /// 经验产出
  31. /// </defK
  32. public EncryptionLong expGain = new EncryptionLong();
  33. public EncryptionFloat attSpeed = new EncryptionFloat();
  34. public EncryptionFloat crit = new EncryptionFloat();
  35. public EncryptionFloat critDamage = new EncryptionFloat();
  36. // public EncryptionFloat dodge = new EncryptionFloat();
  37. public EncryptionInt level;
  38. public EncryptionInt star;
  39. public HeroModelConfig modelConfig;
  40. public HeroPowerUpConfig powerUpConfig;
  41. public MonsterPowerUpConfig MonsterPowerUpConfig;
  42. public HeroPromoteConfig promoteConfig;
  43. public HeroBasicEquipConfig basicEquipConfig;
  44. public long defK;
  45. /// <summary>
  46. /// 减少收到的暴击伤害
  47. /// </summary>
  48. public float reduceHitCritDamage;
  49. /// <summary>
  50. /// 减少收到的伤害
  51. /// </summary>
  52. public float reduceHitDamage;
  53. /// <summary>
  54. /// 技能暴击伤害
  55. /// </summary>
  56. public float skillCritDamage;
  57. /// <summary>
  58. /// 闪避 默认10%的几率
  59. /// </summary>
  60. public float dodge = 5;
  61. /// <summary>
  62. /// 1=英雄 2=小怪 3=精英怪 4=boss
  63. /// </summary>
  64. public int heroType;
  65. public string modelName;
  66. public float maxDis = 2;
  67. public float maxDisTo = 2 * 2;
  68. public bool isMonster;
  69. // public int[] skillId;
  70. // public List<SkillConfig> skillConfigs;
  71. /// <summary>
  72. /// 所有已解锁技能的ID
  73. /// </summary>
  74. public List<int> unLockSkills;
  75. public bool isGpu;
  76. public string heroName;
  77. public CombatHeroInfo()
  78. {
  79. }
  80. // public CombatHeroInfo(AccountFileInfo.HeroData heroData)
  81. // {
  82. // modelConfig = ConfigComponent.Instance.Get<HeroModelConfig>(heroData.heroModelId);
  83. // promoteConfig = ConfigComponent.Instance.Get<HeroPromoteConfig>(heroData.heroPromoteId);
  84. // powerConfig = ConfigComponent.Instance.Get<HeroPowerConfig>(heroData.heroPowerId);
  85. // star = promoteConfig.starGrade;
  86. // lv = powerConfig.heroLevel;
  87. // }
  88. private float rarityFactor;
  89. private float starFactor;
  90. private float factor;
  91. protected Map<AttributeType, int> _AttributeCacheValue = new Map<AttributeType, int>();
  92. /// <summary>
  93. /// 计算影响基础属性的参数
  94. /// (稀有度、星级)
  95. /// </summary>
  96. protected void CalFactor()
  97. {
  98. rarityFactor = PlayerManager.Instance.gameConstantConfig.monsterRarityAttributeFactor[modelConfig.rarity - 1]
  99. / 100f;
  100. starFactor = promoteConfig.star_Power / 100f;
  101. factor = rarityFactor * starFactor;
  102. }
  103. public void AddAttributeValueToCache(AttributeType attributeType, int value)
  104. {
  105. if (_AttributeCacheValue.TryGetValue(attributeType, out int v))
  106. {
  107. value += v;
  108. }
  109. _AttributeCacheValue[attributeType] = value;
  110. }
  111. protected void CalBasicAttribute()
  112. {
  113. _AttributeCacheValue.Clear();
  114. if (isMonster)
  115. {
  116. hp = (EncryptionLong)(modelConfig.hp * MonsterPowerUpConfig.HPFactor * factor);
  117. defense = (EncryptionLong)(modelConfig.def * MonsterPowerUpConfig.DEFFactor * factor);
  118. attack = (EncryptionLong)(modelConfig.attack * MonsterPowerUpConfig.ATKFactor * factor);
  119. shanbi = (EncryptionInt)(modelConfig.shanbi * MonsterPowerUpConfig.SHANBIFactor * factor);
  120. defK = MonsterPowerUpConfig.defK;
  121. // expGain = (EncryptionLong)(modelConfig.expGain * MonsterPowerUpConfig.EXPFactor * factor);
  122. }
  123. else
  124. {
  125. hp = (EncryptionLong)(modelConfig.hp * powerUpConfig.HPFactor * factor);
  126. defense = (EncryptionLong)(modelConfig.def * powerUpConfig.DEFFactor * factor);
  127. attack = (EncryptionLong)(modelConfig.attack * powerUpConfig.ATKFactor * factor);
  128. shanbi = (EncryptionInt)(modelConfig.shanbi * powerUpConfig.SHANBIFactor * factor);
  129. expGain = (EncryptionLong)(modelConfig.expGain * powerUpConfig.EXPFactor * factor);
  130. defK = powerUpConfig.defK;
  131. //职业装备提供的属性
  132. hp += PlayerManager.Instance.eqController.zyEqAddAttributeDic[modelConfig.profession].hp;
  133. defense += PlayerManager.Instance.eqController.zyEqAddAttributeDic[modelConfig.profession].def;
  134. attack += PlayerManager.Instance.eqController.zyEqAddAttributeDic[modelConfig.profession].atk;
  135. }
  136. CalUnLockSkill();
  137. for (_AttributeCacheValue.Begin(); _AttributeCacheValue.Next();)
  138. {
  139. switch (_AttributeCacheValue.Key)
  140. {
  141. case AttributeType.Hp:
  142. hp += CombatCalculateTool.Instance.GetVlaueRatioForLong(hp.Value, _AttributeCacheValue.Value);
  143. break;
  144. case AttributeType.Att:
  145. attack += CombatCalculateTool.Instance.GetVlaueRatioForLong(attack.Value,
  146. _AttributeCacheValue.Value);
  147. break;
  148. case AttributeType.Def:
  149. defense += CombatCalculateTool.Instance.GetVlaueRatioForLong(defense.Value,
  150. _AttributeCacheValue.Value);
  151. break;
  152. }
  153. }
  154. }
  155. public SkillConfig GetGroupSkillConfig(int idGroup)
  156. {
  157. if (unLockSkills == null)
  158. {
  159. return default;
  160. }
  161. for (int i = 0; i < unLockSkills.Count; i++)
  162. {
  163. SkillConfig skillConfig = ConfigComponent.Instance.Get<SkillConfig>(unLockSkills[i]);
  164. if (skillConfig.IDGroup == idGroup)
  165. {
  166. return skillConfig;
  167. }
  168. }
  169. return default;
  170. }
  171. protected void CalAttribute()
  172. {
  173. CalBasicAttribute();
  174. attSpeed = (EncryptionFloat)modelConfig.speed_atk;
  175. crit = (EncryptionFloat)modelConfig.crit;
  176. // skillId = modelConfig.skillID;
  177. modelName = modelConfig.model;
  178. isGpu = modelConfig.isUseGpu;
  179. maxDis = modelConfig.range_atk;
  180. maxDisTo = maxDis * maxDis;
  181. heroType = modelConfig.heroType;
  182. }
  183. /// <summary>
  184. /// 计算解锁技能
  185. /// </summary>
  186. public void CalUnLockSkill()
  187. {
  188. unLockSkills = new List<int>();
  189. for (int i = 0; i < modelConfig.skillID.Length; i++)
  190. {
  191. SkillConfig skillConfig =
  192. PlayerManager.Instance.heroController.GetHighestLevelOr1(modelConfig.skillID[i], level.Value,
  193. star.Value, true, isMonster);
  194. if (isMonster && skillConfig.ID <= 0)
  195. {
  196. skillConfig = ConfigComponent.Instance.Get<SkillConfig>(modelConfig.skillID[i] * 10 + 1);
  197. }
  198. if (skillConfig.ID > 0)
  199. {
  200. unLockSkills.Add(skillConfig.ID);
  201. AddSkillAttribute(skillConfig);
  202. }
  203. }
  204. }
  205. protected void AddSkillAttribute(SkillConfig skillConfig)
  206. {
  207. if (skillConfig.addPropertyType == null)
  208. {
  209. return;
  210. }
  211. for (int i = 0; i < skillConfig.addPropertyType.Length; i++)
  212. {
  213. int propertyType = skillConfig.addPropertyType[i];
  214. int value = skillConfig.addPropertyValue[i];
  215. switch (propertyType)
  216. {
  217. case 1:
  218. AddAttributeValueToCache(AttributeType.Hp, value);
  219. break;
  220. case 2:
  221. AddAttributeValueToCache(AttributeType.Att, value);
  222. break;
  223. case 3:
  224. AddAttributeValueToCache(AttributeType.Def, value);
  225. break;
  226. }
  227. }
  228. }
  229. protected void SetDataConfig(int modelID, int level, int star)
  230. {
  231. modelConfig = ConfigComponent.Instance.Get<HeroModelConfig>(modelID);
  232. if (isMonster)
  233. {
  234. MonsterPowerUpConfig = ConfigComponent.Instance.Get<MonsterPowerUpConfig>(level);
  235. }
  236. else
  237. {
  238. powerUpConfig = ConfigComponent.Instance.Get<HeroPowerUpConfig>(level);
  239. }
  240. promoteConfig = ConfigComponent.Instance.Get<HeroPromoteConfig>(star);
  241. this.level = (EncryptionInt)level;
  242. this.star = (EncryptionInt)star;
  243. heroName = LanguageManager.Instance.Text(modelConfig.name);
  244. }
  245. public void InitMonster(int modelID, int level, int star = 1)
  246. {
  247. isMonster = true;
  248. SetDataConfig(modelID, level, star);
  249. CalFactor();
  250. CalAttribute();
  251. // SkillData = new SkillData(this);
  252. // SkillData.InitSkills();
  253. }
  254. // public void InitMonster(int id,int level)
  255. // {
  256. // HeroModelConfig heroModelConfig = ConfigComponent.Instance.Get<HeroModelConfig>(id);
  257. // HeroPowerUpConfig heroPowerUpConfig = ConfigComponent.Instance.Get<HeroPowerUpConfig>(level);
  258. // hp = (EncryptionLong)(heroModelConfig.hp*heroPowerUpConfig.HPFactor);
  259. // defense=(EncryptionLong)(heroModelConfig.def*heroPowerUpConfig.DEFFactor);
  260. // attack=(EncryptionLong)(heroModelConfig.attack*heroPowerUpConfig.ATKFactor);
  261. // attSpeed=(EncryptionFloat)heroModelConfig.speed_atk;
  262. // crit=(EncryptionFloat)heroModelConfig.crit;
  263. // skillId = heroModelConfig.skillID;
  264. // modelName = heroModelConfig.model;
  265. // isGpu = heroModelConfig.isUseGpu;
  266. // maxDis=heroModelConfig.range_atk;
  267. // maxDisTo = maxDis * maxDis;
  268. // }
  269. public CombatHeroInfo Copy()
  270. {
  271. CombatHeroInfo combatHeroInfo = (CombatHeroInfo)MemberwiseClone();
  272. return combatHeroInfo;
  273. }
  274. }