CombatHeroInfo.cs 9.7 KB

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