XmdsSummonBase.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using CommonAI.Data;
  2. using CommonAI.Zone;
  3. using CommonLang;
  4. using CommonLang.Geometry;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using XmdsCommonServer.Plugin;
  11. using XmdsCommonServer.Plugin.Units;
  12. using XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills;
  13. using XmdsCommonServer.XLS.Data;
  14. using static XmdsCommonServer.XLS.Data.XmdsSkillData;
  15. namespace XmdsCommonSkill.Plugin.Skills
  16. {
  17. /**
  18. * 召唤类boss机制:按照数量,时间,半径召唤小怪
  19. */
  20. public class XmdsSummonBase
  21. {
  22. protected XmdsSkillValue mSummonNums; // 单次数量,最大数量
  23. protected XmdsSkillValue mSummonLiftTime; // 召唤物ID, 生命时间
  24. protected int mSummonRange_Min; // 召唤半径
  25. protected int mSummonRange_Chg; // 召唤半径
  26. protected SummonType mSummonType = SummonType.guard;
  27. /// <summary>
  28. /// 召唤单位
  29. /// </summary>
  30. public void SummonUnit(XmdsVirtual master)
  31. {
  32. XmdsVirtual_Monster masterMonster = master as XmdsVirtual_Monster;
  33. //剩余可召唤数量
  34. int leftSummonCount = mSummonNums.GetValue(1, 2) - masterMonster.GetSummonUnitListCount();
  35. leftSummonCount = Math.Min(leftSummonCount, mSummonNums.GetValue(1, 1));
  36. if (leftSummonCount <= 0) { return; }
  37. UnitInfo info = XmdsBattleSkill.GetUnitInfo(mSummonLiftTime.GetValue(1, 1));
  38. for (int i = 0; i < leftSummonCount; i++)
  39. {
  40. this.ProcessSummonUnit(master, info, mSummonLiftTime.GetValue(1, 2));
  41. }
  42. }
  43. protected bool ProcessSummonUnit(XmdsVirtual master, UnitInfo info, int liftTime)
  44. {
  45. AddUnitEvent aue = null;
  46. //控制生命周期.
  47. info.LifeTimeMS = liftTime;
  48. Vector2 randomPos = this.RandomSummonPos(master);
  49. var unit = master.mUnit.Parent.AddUnit(
  50. info, "", master.mUnit.Force, master.GetUnitLv(), randomPos.X, randomPos.Y,
  51. master.mUnit.Direction, out aue, master.mUnit);
  52. //var monsterUnit = unit as XmdsInstanceMonster;
  53. //if (monsterUnit == null)
  54. //{
  55. // //log.Warn("添加召唤物失败:" + info.ID + ", " + this.SkillID);
  56. // return false;
  57. //}
  58. //if(this.mSummonType == SummonType.guard)
  59. //{
  60. // monsterUnit.guard();
  61. //}
  62. //else if(this.mSummonType == SummonType.guardMaster)
  63. //{
  64. // monsterUnit.guardUnit(master.mUnit);
  65. //}
  66. //else if (this.mSummonType == SummonType.attack)
  67. //{
  68. // //unit.followAndAttack(master.mUnit);
  69. //}
  70. XmdsVirtual_Monster materMonster = master as XmdsVirtual_Monster;
  71. materMonster.AddSummonUnitList(unit.Virtual as XmdsVirtual);
  72. return true;
  73. }
  74. // 默认直接按照半径来随机
  75. //protected Vector2 RandomSummonPos(XmdsVirtual master)
  76. //{
  77. // Vector2 randomPos = new Vector2();
  78. // int addX = master.mUnit.RandomN.Next() % 2 == 0 ? 1 : -1;
  79. // int addY = master.mUnit.RandomN.Next() % 2 == 0 ? 1 : -1;
  80. // float chgX = mSummonRange.GetValue(1) + (float)(master.mUnit.RandomN.NextDouble() * mSummonRange.GetValue(2));
  81. // float chgY = mSummonRange.GetValue(1) + (float)(master.mUnit.RandomN.NextDouble() * mSummonRange.GetValue(2));
  82. // randomPos.X = master.mUnit.X + chgX * addX;
  83. // randomPos.Y = master.mUnit.Y + chgY * addX;
  84. // return randomPos;
  85. //}
  86. //protected Vector2 RandomSummonPos(XmdsVirtual master)
  87. //{
  88. // Vector2 randomPos = new Vector2();
  89. // var pos = master.mUnit.Parent.PathFinder.FindNearRandomMoveableNode(
  90. // master.mUnit.RandomN, master.mUnit.X, master.mUnit.Y, mSummonRange_Min, true);
  91. // if (mSummonRange_Chg > 0)
  92. // {
  93. // randomPos.X = pos.PosX + (pos.PosX > master.mUnit.X ? 1 : -1) * mSummonRange_Chg;
  94. // randomPos.Y = pos.PosY + (pos.PosY > master.mUnit.Y ? 1 : -1) * mSummonRange_Chg;
  95. // }
  96. // System.Console.WriteLine("RandomSummonPos: " + randomPos.X + ", " + randomPos.Y);
  97. // return randomPos;
  98. //}
  99. protected Vector2 RandomSummonPos(XmdsVirtual master)
  100. {
  101. Vector2 randomPos = new Vector2();
  102. var pos = master.mUnit.Parent.PathFinder.FindNearRandomMoveableNode(
  103. master.mUnit.RandomN, master.mUnit.X, master.mUnit.Y, mSummonRange_Min, mSummonRange_Min + mSummonRange_Chg, true);
  104. randomPos.X = pos.PosX;
  105. randomPos.Y = pos.PosY;
  106. //System.Console.WriteLine("RandomSummonPos: " + randomPos.X + ", " + randomPos.Y);
  107. return randomPos;
  108. }
  109. public int GetSummonID()
  110. {
  111. return this.mSummonLiftTime.GetValue(1, 1);
  112. }
  113. public void InitConfig(SummonType summonType, XmdsSkillValue value1, XmdsSkillValue value2, XmdsSkillValue value3)
  114. {
  115. this.mSummonType = summonType;
  116. this.mSummonNums = value1;
  117. this.mSummonLiftTime = value2;
  118. this.mSummonRange_Min = value3.GetValue(1, 1);
  119. this.mSummonRange_Chg = Math.Max(0, value3.GetValue(1, 2) - mSummonRange_Min);
  120. }
  121. }
  122. }