XmdsBattleHelper.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. 
  2. using CommonAI.Zone.Helper;
  3. using CommonAI.Zone.Instance;
  4. using CommonLang;
  5. using CommonLang.Log;
  6. using System;
  7. using XmdsCommon.Plugin;
  8. using XmdsCommonServer.Plugin.Units;
  9. using XmdsCommonServer.Plugin.XmdsSkillTemplate.DamageCalculator;
  10. using CommonAI.Zone;
  11. using XmdsCommonServer.XLS.Data;
  12. namespace XmdsCommonServer.Plugin
  13. {
  14. public class XmdsBattleHelper
  15. {
  16. protected static Logger log = LoggerFactory.GetLogger("XmdsBattleSkill");
  17. private static int GetPercentValue(float src, float percent)
  18. {
  19. return CUtils.CastInt(src * percent);
  20. }
  21. #region 获得召唤单位宿主的XmdsVirtual.
  22. public static XmdsVirtual GetSummonMaster(XmdsVirtual summonunit)
  23. {
  24. XmdsVirtual ret = null;
  25. ISummonedUnit u = summonunit.mUnit as ISummonedUnit;
  26. if (u != null && u.SummonerUnit != null && u.SummonerUnit.IsActive)
  27. {
  28. ret = XmdsZoneServerFactory.ToVirtual(u.SummonerUnit);
  29. }
  30. return ret;
  31. }
  32. #endregion
  33. #region 获得一定范围内离单位最近的目标.
  34. public static InstanceUnit GetNearestFirstTarget(
  35. InstanceUnit unit, float x, float y, int range,
  36. CommonAI.Zone.SkillTemplate.CastTarget exceptTarget,
  37. AttackReason reason,
  38. InstanceUnit ingore = null)
  39. {
  40. InstanceUnit ret = null;
  41. using (var list = ListObjectPool<InstanceUnit>.AllocAutoRelease())
  42. {
  43. unit.Parent.getObjectsRoundRange<InstanceUnit>(
  44. (obj, dx, dy, dr) =>
  45. {
  46. var u = obj as InstanceUnit;
  47. if (u != ingore && u.Parent.IsAttackable(unit, u, exceptTarget, reason, unit.Info))
  48. {
  49. return CMath.includeRoundPoint(dx, dy, dr, u.X, u.Y);
  50. }
  51. return false;
  52. },
  53. x,
  54. y,
  55. range,
  56. list,
  57. unit.AoiStatus);
  58. if (list.Count > 0)
  59. {
  60. list.Sort(new ObjectSorterNearest<InstanceUnit>(x, y));
  61. ret = list[0];
  62. }
  63. }
  64. return ret;
  65. }
  66. /// <summary>
  67. /// 获得一定范围内离单位最近的单位列表.
  68. /// </summary>
  69. /// <param name="unit"></param>
  70. /// <param name="x"></param>
  71. /// <param name="y"></param>
  72. /// <param name="range"></param>
  73. /// <param name="exceptTarget"></param>
  74. /// <param name="reason"></param>
  75. /// <param name="do_action"></param>
  76. public static void ForEachRangedAttackableTargets(
  77. InstanceUnit unit, float x, float y, int range,
  78. CommonAI.Zone.SkillTemplate.CastTarget exceptTarget,
  79. AttackReason reason,
  80. Action<InstanceUnit> do_action)
  81. {
  82. unit.Parent.ForEachNearObjects(x, y, range, (InstanceZoneObject o, ref bool cancel) =>
  83. {
  84. if (o is InstanceUnit)
  85. {
  86. var u = o as InstanceUnit;
  87. if (u.Parent.IsAttackable(unit, u, exceptTarget, reason, unit.Info))
  88. {
  89. if (CMath.includeRoundPoint(x, y, range, u.X, u.Y))
  90. {
  91. do_action(u);
  92. }
  93. }
  94. }
  95. });
  96. }
  97. #endregion
  98. public static bool BuffIsStealthAbility(XmdsBuffProperties.XmdsBuffAbility ability)
  99. {
  100. bool ret = false;
  101. if (ability == XmdsBuffProperties.XmdsBuffAbility.Stealth)
  102. {
  103. ret = true;
  104. }
  105. return ret;
  106. }
  107. public static int GetTargetFormulaValue(int lv, int[] formula, int skill)
  108. {
  109. int ret = 0;
  110. int v = lv - 1;
  111. if (v < 0 || formula.Length == 0)
  112. {
  113. LogError(string.Format("GetTargetFormulaValue Error:skill id = {0} lv = {1}", skill, lv));
  114. }
  115. else if (v >= formula.Length)
  116. {
  117. ret = formula[formula.Length - 1];
  118. }
  119. else
  120. {
  121. ret = formula[v];
  122. }
  123. return ret;
  124. }
  125. public static void LogError(string text)
  126. {
  127. log.Error(text);
  128. }
  129. public static void LogWarn(string text)
  130. {
  131. log.Warn(text);
  132. }
  133. #region 是否为友军判断.
  134. /*
  135. /// <summary>
  136. /// 是否为友军,根据单位PK模式不同结果不同.
  137. /// </summary>
  138. /// <param name="src"></param>
  139. /// <param name="target"></param>
  140. /// <param name="exceptTarget"></param>
  141. /// <returns></returns>
  142. public static bool IsAllies(InstanceUnit src, InstanceUnit target, SkillTemplate.CastTarget exceptTarget)
  143. {
  144. bool ret = false;
  145. var srcVirtual = src.Virtual as XmdsVirtual;
  146. var targetVirtual = target.Virtual as XmdsVirtual;
  147. //获得当前PK模式.
  148. PKInfo.PKMode mode = srcVirtual.GetCurPKMode();
  149. ret = IsAllies(srcVirtual, targetVirtual, exceptTarget, mode);
  150. return ret;
  151. }
  152. private static bool IsAllies(XmdsVirtual src, XmdsVirtual target, SkillTemplate.CastTarget expectTarget, PKInfo.PKMode mode)
  153. {
  154. bool includeSelf = false;
  155. bool ret = false;
  156. InstanceUnit u = target.mUnit;
  157. InstanceUnit temp = null;
  158. if (expectTarget == SkillTemplate.CastTarget.AlliesIncludeSelf) { includeSelf = true; }
  159. if (u is XmdsInstanceMonster)
  160. {
  161. ret = IsMember(src, temp, mode, includeSelf);
  162. }
  163. else if (u is XmdsInstancePlayer)
  164. {
  165. ret = IsMember(src, temp, mode, includeSelf);
  166. }
  167. else if (u is XmdsInstanceSummonUnit)
  168. {
  169. temp = (u as XmdsInstanceSummonUnit).SummonerUnit;
  170. //召唤物的主人是自己.
  171. ret = IsMember(src, temp, mode, includeSelf);
  172. }
  173. else if (u is InstancePet)
  174. {
  175. temp = (u as InstancePet).Master;
  176. ret = IsMember(src, temp, mode, includeSelf);
  177. }
  178. return ret;
  179. }
  180. private static bool IsMember(XmdsVirtual src, InstanceUnit target, PKInfo.PKMode mode, bool includeSelf)
  181. {
  182. bool ret = false;
  183. XmdsVirtual zv = null;
  184. if (src.mUnit == target)
  185. {
  186. if (includeSelf) { return true; }
  187. else { return false; }
  188. }
  189. switch (mode)
  190. {
  191. case PKInfo.PKMode.Peace://和平模式使用默认出生的force.
  192. ret = src.mUnit.Force == src.mUnit.Force ? true : false;
  193. break;
  194. case PKInfo.PKMode.Camp://阵营模式使用Camp.
  195. zv = (target.Virtual) as XmdsVirtual;
  196. ret = src.IsCampMember(zv.GetCampID());
  197. //非同势力时,还需判断是否为队友.
  198. if (ret == false && target is XmdsInstancePlayer)
  199. {
  200. ret = src.IsTeamMember((target as XmdsInstancePlayer).PlayerUUID);
  201. }
  202. break;
  203. case PKInfo.PKMode.Guild:
  204. ret = src.IsGuildMember((target as XmdsInstancePlayer).PlayerUUID);
  205. //非公会成员时还需判断单位是否为为队友.
  206. if (ret == false)
  207. {
  208. ret = src.IsTeamMember((target as XmdsInstancePlayer).PlayerUUID);
  209. }
  210. break;
  211. case PKInfo.PKMode.Justice:
  212. zv = (target.Virtual) as XmdsVirtual;
  213. //非红名玩家才算友军.
  214. ret = zv.GetCurPKLevel() == PKLevel.White ? true : false;
  215. //非红名时还需判断单位是否为为队友.
  216. if (ret == false)
  217. {
  218. ret = src.IsTeamMember((target as XmdsInstancePlayer).PlayerUUID);
  219. }
  220. break;
  221. case PKInfo.PKMode.Server:
  222. zv = (target.Virtual) as XmdsVirtual;
  223. if (zv != null) { ret = src.IsServerMember(zv.GetServerID()); }
  224. //非友军时还需判断单位是否为为队友.
  225. if (ret == false)
  226. {
  227. ret = src.IsTeamMember((target as XmdsInstancePlayer).PlayerUUID);
  228. }
  229. break;
  230. case PKInfo.PKMode.Team:
  231. case PKInfo.PKMode.All:
  232. ret = src.IsTeamMember((target as XmdsInstancePlayer).PlayerUUID);
  233. break;
  234. }
  235. return ret;
  236. }
  237. */
  238. #endregion
  239. }
  240. }