CombatHeroInfo.cs 8.6 KB

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