CombatHeroInfo.cs 10 KB

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