CombatHeroInfo.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. public EncryptionFloat attSpeed = new EncryptionFloat();
  26. public EncryptionFloat crit = new EncryptionFloat();
  27. public EncryptionFloat critDamage = new EncryptionFloat();
  28. // public EncryptionFloat dodge = new EncryptionFloat();
  29. public EncryptionInt level;
  30. public HeroModelConfig modelConfig;
  31. public HeroPowerUpConfig powerUpConfig;
  32. public MonsterPowerUpConfig MonsterPowerUpConfig;
  33. public HeroPromoteConfig promoteConfig;
  34. public HeroBasicEquipConfig basicEquipConfig;
  35. public long defK;
  36. /// <summary>
  37. /// 闪避 默认10%的几率
  38. /// </summary>
  39. public float dodge = 5;
  40. /// <summary>
  41. /// 1=英雄 2=小怪 3=精英怪 4=boss
  42. /// </summary>
  43. public int heroType;
  44. public string modelName;
  45. public float maxDis = 2;
  46. public float maxDisTo = 2 * 2;
  47. public bool isMonster;
  48. // public int[] skillId;
  49. // public List<SkillConfig> skillConfigs;
  50. /// <summary>
  51. /// 所有已解锁技能的ID
  52. /// </summary>
  53. public List<int> unLockSkills;
  54. public bool isGpu;
  55. public string heroName;
  56. public List<int> MagicWeaponID;
  57. public CombatHeroInfo()
  58. {
  59. }
  60. private float rarityFactor;
  61. private float starFactor;
  62. private float factor;
  63. protected Map<AttributeType, int> _AttributeCacheValue = new Map<AttributeType, int>();
  64. /// <summary>
  65. /// 计算影响基础属性的参数
  66. /// (稀有度、星级)
  67. /// </summary>
  68. protected void CalFactor()
  69. {
  70. rarityFactor = PlayerManager.Instance.gameConstantConfig.monsterRarityAttributeFactor[modelConfig.rarity - 1]
  71. / 100f;
  72. starFactor = promoteConfig.star_Power / 100f;
  73. factor = rarityFactor * starFactor;
  74. }
  75. public void AddAttributeValueToCache(AttributeType attributeType, int value)
  76. {
  77. if (_AttributeCacheValue.TryGetValue(attributeType, out int v))
  78. {
  79. value += v;
  80. }
  81. _AttributeCacheValue[attributeType] = value;
  82. }
  83. protected void CalBasicAttribute()
  84. {
  85. _AttributeCacheValue.Clear();
  86. if (isMonster)
  87. {
  88. hp = (EncryptionLong)(modelConfig.hp * MonsterPowerUpConfig.HPFactor * factor);
  89. defense = (EncryptionLong)(modelConfig.def * MonsterPowerUpConfig.DEFFactor * factor);
  90. attack = (EncryptionLong)(modelConfig.attack * MonsterPowerUpConfig.ATKFactor * factor);
  91. defK = MonsterPowerUpConfig.defK;
  92. // expGain = (EncryptionLong)(modelConfig.expGain * MonsterPowerUpConfig.EXPFactor * factor);
  93. }
  94. else
  95. {
  96. hp = (EncryptionLong)(modelConfig.hp * powerUpConfig.HPFactor * factor);
  97. defense = (EncryptionLong)(modelConfig.def * powerUpConfig.DEFFactor * factor);
  98. attack = (EncryptionLong)(modelConfig.attack * powerUpConfig.ATKFactor * factor);
  99. defK = powerUpConfig.defK;
  100. //职业装备提供的属性
  101. hp += PlayerManager.Instance.eqController.zyEqAddAttributeDic[modelConfig.profession].hp;
  102. defense += PlayerManager.Instance.eqController.zyEqAddAttributeDic[modelConfig.profession].def;
  103. attack += PlayerManager.Instance.eqController.zyEqAddAttributeDic[modelConfig.profession].atk;
  104. }
  105. CalUnLockSkill();
  106. for (_AttributeCacheValue.Begin(); _AttributeCacheValue.Next();)
  107. {
  108. switch (_AttributeCacheValue.Key)
  109. {
  110. case AttributeType.Hp:
  111. hp += CombatCalculateTool.Instance.GetVlaueRatioForLong(hp.Value, _AttributeCacheValue.Value);
  112. break;
  113. case AttributeType.Att:
  114. attack += CombatCalculateTool.Instance.GetVlaueRatioForLong(attack.Value,
  115. _AttributeCacheValue.Value);
  116. break;
  117. case AttributeType.Def:
  118. defense += CombatCalculateTool.Instance.GetVlaueRatioForLong(defense.Value,
  119. _AttributeCacheValue.Value);
  120. break;
  121. }
  122. }
  123. }
  124. public SkillConfig GetGroupSkillConfig(int idGroup)
  125. {
  126. if (unLockSkills == null)
  127. {
  128. return default;
  129. }
  130. for (int i = 0; i < unLockSkills.Count; i++)
  131. {
  132. SkillConfig skillConfig = ConfigComponent.Instance.Get<SkillConfig>(unLockSkills[i]);
  133. if (skillConfig.IDGroup == idGroup)
  134. {
  135. return skillConfig;
  136. }
  137. }
  138. return default;
  139. }
  140. protected void CalAttribute()
  141. {
  142. CalBasicAttribute();
  143. attSpeed = (EncryptionFloat)modelConfig.speed_atk;
  144. crit = (EncryptionFloat)modelConfig.crit;
  145. // skillId = modelConfig.skillID;
  146. modelName = modelConfig.model;
  147. isGpu = modelConfig.isUseGpu;
  148. maxDis = modelConfig.range_atk;
  149. maxDisTo = maxDis * maxDis;
  150. heroType = modelConfig.heroType;
  151. }
  152. /// <summary>
  153. /// 计算解锁技能
  154. /// </summary>
  155. public void CalUnLockSkill()
  156. {
  157. unLockSkills = new List<int>();
  158. }
  159. protected void AddSkillAttribute(SkillConfig skillConfig)
  160. {
  161. if (skillConfig.addPropertyType == null)
  162. {
  163. return;
  164. }
  165. for (int i = 0; i < skillConfig.addPropertyType.Length; i++)
  166. {
  167. int propertyType = skillConfig.addPropertyType[i];
  168. int value = skillConfig.addPropertyValue[i];
  169. switch (propertyType)
  170. {
  171. case 1:
  172. AddAttributeValueToCache(AttributeType.Hp, value);
  173. break;
  174. case 2:
  175. AddAttributeValueToCache(AttributeType.Att, value);
  176. break;
  177. case 3:
  178. AddAttributeValueToCache(AttributeType.Def, value);
  179. break;
  180. }
  181. }
  182. }
  183. protected void SetDataConfig(int modelID, int level, int star)
  184. {
  185. modelConfig = ConfigComponent.Instance.Get<HeroModelConfig>(modelID);
  186. if (isMonster)
  187. {
  188. MonsterPowerUpConfig = ConfigComponent.Instance.Get<MonsterPowerUpConfig>(level);
  189. }
  190. else
  191. {
  192. powerUpConfig = ConfigComponent.Instance.Get<HeroPowerUpConfig>(level);
  193. }
  194. promoteConfig = ConfigComponent.Instance.Get<HeroPromoteConfig>(star);
  195. this.level = (EncryptionInt)level;
  196. heroName = LanguageManager.Instance.Text(modelConfig.name);
  197. }
  198. public void InitMonster(int modelID, int level, int star = 1)
  199. {
  200. isMonster = true;
  201. SetDataConfig(modelID, level, star);
  202. CalFactor();
  203. CalAttribute();
  204. }
  205. public CombatHeroInfo Copy()
  206. {
  207. CombatHeroInfo combatHeroInfo = (CombatHeroInfo)MemberwiseClone();
  208. return combatHeroInfo;
  209. }
  210. }