StrategyMgr.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. public struct ValType
  5. {
  6. public int id;
  7. public int val;
  8. public ValType(int id, int val)
  9. {
  10. this.id = id;
  11. this.val = val;
  12. }
  13. }
  14. public struct FValType
  15. {
  16. public int id;
  17. public float val;
  18. public FValType(int id, float val)
  19. {
  20. this.id = id;
  21. this.val = val;
  22. }
  23. }
  24. public enum eNatureAntiType
  25. {
  26. Damage = 1, //伤害加成
  27. Crit = 2, //暴击加成
  28. Hit = 3, //命中加成
  29. }
  30. public enum EnNatureType
  31. {
  32. en_None = 1,
  33. en_Water, //水
  34. en_Land, //地
  35. en_Fire, //火
  36. en_Wind, //风
  37. en_Holy, //圣
  38. en_Dark, //暗
  39. en_Pray, //念
  40. }
  41. public enum EnAttr_NatureType
  42. {
  43. Attr_Nature_None_Damage_Percent = 71, //对无属性目标伤害加成/减免百分比
  44. Attr_Nature_Water_Damage_Percent = 72, //对水属性目标的伤害加成/减免百分比
  45. Attr_Nature_Ground_Damage_Percent = 73, //对地属性目标的伤害加成/减免百分比
  46. Attr_Nature_Fire_Damage_Percent = 74, //对火属性目标的伤害加成/减免百分比
  47. Attr_Nature_Wind_Damage_Percent = 75, //对风属性目标的伤害加成/减免百分比
  48. Attr_Nature_Saint_Damage_Percent = 76, //对圣属性目标的伤害加成/减免百分比
  49. Attr_Nature_Dark_Damage_Percent = 77, //对暗属性目标的伤害加成/减免百分比
  50. Attr_Nature_Read_Damage_Percent = 78, //对念属性目标的伤害加成/减免百分比
  51. Attr_Nature_None_AntiDamage_Percent = 81, //抗无属性伤害加成/减免百分比
  52. Attr_Nature_Water_AntiDamage_Percent = 82, //抗水属性伤害加成/减免百分比
  53. Attr_Nature_Ground_AntiDamage_Percent = 83, //抗地属性伤害加成/减免百分比
  54. Attr_Nature_Fire_AntiDamage_Percent = 84, //抗火属性伤害加成/减免百分比
  55. Attr_Nature_Wind_AntiDamage_Percent = 85, //抗风属性伤害加成/减免百分比
  56. Attr_Nature_Saint_AntiDamage_Percent = 86, //抗圣属性伤害加成/减免百分比
  57. Attr_Nature_Dark_AntiDamage_Percent = 87, //抗暗属性伤害加成/减免百分比
  58. Attr_Nature_Read_AntiDamage_Percent = 88, //抗念属性伤害加成/减免百分比
  59. }
  60. public class StrategyMgr : Singleton<StrategyMgr>
  61. {
  62. Dictionary<int, Dictionary<EnNatureType, int>> mAnitNatureCfg = new Dictionary<int, Dictionary<EnNatureType, int>>();
  63. Dictionary<int, Dictionary<EnAttr_NatureType, int>> mAddNatureCfg = new Dictionary<int, Dictionary<EnAttr_NatureType, int>>();
  64. NPack.MersenneTwister rand = null;
  65. public override void Init()
  66. {
  67. base.Init();
  68. rand = new NPack.MersenneTwister(100);
  69. ReadAntiNatureCfg();
  70. }
  71. public override void UnInit()
  72. {
  73. base.UnInit();
  74. }
  75. void ReadAntiNatureCfg()
  76. {
  77. mAnitNatureCfg.Clear();
  78. mAddNatureCfg.Clear();
  79. Dictionary<string, Dictionary<string, string>> table = ConfigMgr.Instance.getTable(Config.NatureCfgName);
  80. if (table != null)
  81. {
  82. foreach (var cfg in table)
  83. {
  84. if (cfg.Key.ToLower() == "id" || cfg.Key.ToLower() == "int") continue;
  85. int natureId = 0;
  86. int.TryParse(cfg.Key, out natureId);
  87. if (natureId < 1) continue;
  88. Dictionary<string, string> dic = cfg.Value;
  89. if (dic != null)
  90. {
  91. if (dic.ContainsKey("AntiNature"))
  92. {
  93. string[] temp = StringUtil.split(dic["AntiNature"], ';');
  94. Dictionary<EnNatureType, int> DicantiVals = new Dictionary<EnNatureType, int>();
  95. for (int i=0;i< temp.Length;i++)
  96. {
  97. string[] ArrayValue = StringUtil.split(temp[i], ':');
  98. if(ArrayValue.Length==2)
  99. {
  100. EnNatureType enType = (EnNatureType)int.Parse(ArrayValue[0]);
  101. int Val = int.Parse(ArrayValue[1]);
  102. DicantiVals.Add(enType, Val);
  103. }
  104. }
  105. mAnitNatureCfg.Add(natureId, DicantiVals);
  106. }
  107. if(dic.ContainsKey("NatureAttribute"))
  108. {
  109. string[] temp = StringUtil.split(dic["NatureAttribute"], ';');
  110. Dictionary<EnAttr_NatureType, int> DicantiVals = new Dictionary<EnAttr_NatureType, int>();
  111. if(null != temp)
  112. for (int i = 0; i < temp.Length; i++)
  113. {
  114. string[] ArrayValue = StringUtil.split(temp[i], ':');
  115. if (ArrayValue.Length == 2)
  116. {
  117. EnAttr_NatureType nArrtiId = (EnAttr_NatureType)int.Parse(ArrayValue[0]);
  118. int nVal = int.Parse(ArrayValue[1]);
  119. DicantiVals.Add(nArrtiId, nVal);
  120. }
  121. }
  122. mAddNatureCfg.Add(natureId, DicantiVals);
  123. }
  124. }
  125. }
  126. }
  127. }
  128. //附加属性
  129. public void GetAddAntiAttr(int nNatureId, EnAttr_NatureType enNatureType, out SFloat AntiRatio)
  130. {
  131. AntiRatio = 0;
  132. if (nNatureId < 0) return;
  133. int nOutRatio = 0;
  134. Dictionary<EnAttr_NatureType, int> valList;
  135. if (mAddNatureCfg.TryGetValue(nNatureId, out valList))
  136. {
  137. valList.TryGetValue(enNatureType, out nOutRatio);
  138. AntiRatio = SFloat.Convert( nOutRatio * 0.0001f);
  139. }
  140. }
  141. //系数获取
  142. public void GetAntiVals(int nNatureId, EnNatureType enNatureType, out SFloat AntiRatio)
  143. {
  144. AntiRatio = 0.0f;
  145. if (nNatureId < 0) return;
  146. int nOutRatio = 0;
  147. Dictionary<EnNatureType, int> valList;
  148. if (mAnitNatureCfg.TryGetValue(nNatureId, out valList))
  149. {
  150. valList.TryGetValue(enNatureType, out nOutRatio);
  151. AntiRatio = SFloat.Convert(nOutRatio * 0.0001f);
  152. }
  153. }
  154. //总值加成获取
  155. public void GetAllAntiVals(Fighter caster, Fighter target, out SFloat fAddValue)
  156. {
  157. fAddValue = 0;
  158. SFloat[] ArrayAddAttr = new SFloat[8] { 0, 0, 0, 0, 0, 0, 0, 0 };
  159. SFloat[] ArrayAntiAttr = new SFloat[8] { 0, 0, 0, 0, 0, 0, 0, 0 };
  160. int nIndex = 0;
  161. int nFuncOffset = 42;//效果偏移枚举
  162. int nAntiTypeOffset = 10;//加成抵抗偏移
  163. for (int i= (int)EnAttr_NatureType.Attr_Nature_None_Damage_Percent; i <= (int)EnAttr_NatureType.Attr_Nature_Read_Damage_Percent; i++)
  164. {
  165. GetAddAntiAttr(caster.NatureId, (EnAttr_NatureType)i, out ArrayAddAttr[nIndex]);//加成
  166. GetAddAntiAttr(target.NatureId, (EnAttr_NatureType)(i+10), out ArrayAntiAttr[nIndex]);//抵抗
  167. //加入角色属性 fun 枚举
  168. /*
  169. Nature_None_Change_Value = 113,
  170. Nature_Water_Change_Value = 114,
  171. Nature_Ground_Change_Value = 115,
  172. Nature_Fire_Change_Value = 116,
  173. Nature_Wind_Change_Value = 117,
  174. Nature_Saint_Change_Value = 118,
  175. Nature_Dark_Change_Value = 119,
  176. Nature_Read_Change_Value = 120,
  177. AntiNature_None_Change_Value = 121,
  178. AntiNature_Water_Change_Value = 122,
  179. AntiNature_Ground_Change_Value = 123,
  180. AntiNature_Fire_Change_Value = 124,
  181. AntiNature_Wind_Change_Value = 125,
  182. AntiNature_Saint_Change_Value = 126,
  183. AntiNature_Dark_Change_Value = 127,
  184. AntiNature_Read_Change_Value = 128,
  185. */
  186. ArrayAddAttr[nIndex] += caster.Actor.GetAdditionalAttrPercent(i) + caster.GetBuffFunctionValue((Buff_Function_Type)(i + nFuncOffset));//加成
  187. ArrayAntiAttr[nIndex] += target.Actor.GetAdditionalAttrPercent(i + nAntiTypeOffset) + target.GetBuffFunctionValue((Buff_Function_Type)(i + nAntiTypeOffset + nFuncOffset));//抵抗
  188. ArrayAntiAttr[nIndex] = Mathf.Max(ArrayAntiAttr[nIndex], 0.0f);//抵抗最小为0
  189. nIndex += 1;
  190. }
  191. for (int i= (int)EnNatureType.en_None; i <= (int)EnNatureType.en_Pray; i++)
  192. {
  193. SFloat AntiRatio = 0;
  194. GetAntiVals(target.NatureId, (EnNatureType)i, out AntiRatio);
  195. fAddValue += Mathf.Min(Mathf.Max((ArrayAddAttr[i-1] - ArrayAntiAttr[i-1]) * AntiRatio, 0.0f), 0.3f);
  196. }
  197. fAddValue = Mathf.Min(fAddValue, 1.0f);
  198. }
  199. }