InstanceUnit.cs 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using CommonAI.RTS;
  5. using CommonLang.Vector;
  6. using CommonAI.Zone;
  7. using CommonAI.Zone.Instance;
  8. using CommonAI.RTS.Manhattan;
  9. using CommonLang;
  10. using CommonLang.Log;
  11. using CommonAI.Zone.Formula;
  12. using CommonAI.ZoneClient;
  13. using CommonAI.Zone.Helper;
  14. using CommonLang.Property;
  15. using CommonAI.Zone.Attributes;
  16. using CommonAI.Zone.EventTrigger;
  17. using CommonAI.Zone.Instance.Helper;
  18. using CommonAI.Data;
  19. using static CommonAI.Zone.UnitInfo;
  20. using CommonAI.data;
  21. namespace CommonAI.Zone.Instance
  22. {
  23. abstract public partial class InstanceUnit : InstanceZoneObject
  24. {
  25. private readonly UnitInfo mInfo;
  26. private readonly DropItemGenerator mDropItems;
  27. /// <summary>
  28. /// 统计信息
  29. /// </summary>
  30. public IUnitStatistic Statistic { get; private set; }
  31. //最后一次受伤时间
  32. public long mLastDamageTime;
  33. //最后一次攻击事件
  34. public long mLastHitOtherTime;
  35. //上一次处理死亡回调时间
  36. public long mProcessDeadCallbackTime;
  37. private IFormula mFormula = TemplateManager.Factory.Formula;
  38. private IVirtualUnit mUnitVirtual;
  39. private readonly string mName;
  40. private int mForce = 0;
  41. private int mAlliesForce = 0; // 服务器对战情况下,有盟友服务器
  42. private int mLevel = 0;
  43. private int mMoney = 0;
  44. private readonly bool mIsAttackRangeIncludeBodySize;
  45. // 当前HP
  46. private readonly RangeValue __mCurrentHP;
  47. // 当前MP
  48. private readonly RangeValue __mCurrentMP;
  49. // 当前移动速度加成
  50. private float __mCurrentMoveSpeedSEC = 0;
  51. // 攻速
  52. private int __mCurrentAttackSpeed = 10000;
  53. // 当前技能速度加成
  54. private float __mSkillActionSpeedRate = 0;
  55. // 当前快速施法速度
  56. private float mFastCastRate = 0;
  57. /// <summary>
  58. /// 当前单位是否地图阻挡
  59. /// </summary>
  60. private bool mIntersectMap = false;
  61. /// <summary>
  62. /// 当前单位是否单位阻挡
  63. /// </summary>
  64. private bool mIntersectObj = false;
  65. // 当前技能cd减少
  66. private float __mCurrentSkillCdReduce;
  67. // 控制减速,韧性
  68. private float __mCurrentControledTimeReduce;
  69. // 控制增幅
  70. private float __mControledTimeAdd;
  71. /// 单位最后死亡时间
  72. private long mDeadTime = 0;
  73. //游戏服标记字段,怪物死亡的时候,回传给游戏服
  74. public int gameServerFlag = 0;
  75. //回血
  76. public int recoverHP = 0;
  77. //随从最后一次瞬移时间
  78. public long petTeleportTime = 0;
  79. //最后一次返回召回随从操作频繁时间
  80. public long lastTeleportTime = 0;
  81. //绑定攻击玩家
  82. private string mBindAttackPlayerId;
  83. //主人id
  84. private long mRemoveSelfTime;
  85. private InstanceUnit mBindMaster;
  86. /// <summary>
  87. /// 自动恢复计数器
  88. /// </summary>
  89. private TimeInterval<int> mRecoveryTime = null;
  90. public InstanceUnit(InstanceZone zone, UnitInfo uinfo, string name, int force, int level, bool is_static_block = false, int alliesForce = 0)
  91. : base(zone, is_static_block)
  92. {
  93. this.mInfo = (UnitInfo)uinfo.Clone();
  94. this.mName = string.IsNullOrEmpty(name) ? "" : name;
  95. this.mIsAttackRangeIncludeBodySize = zone.Templates.CFG.OBJECT_ATTACK_RANGE_INCLUDE_BODYSIZE;
  96. this.mForce = force;
  97. this.mAlliesForce = alliesForce;
  98. this.mLevel = level;
  99. this.mIntersectMap = true;
  100. this.mIntersectObj = !Templates.CFG.OBJECT_NONE_TOUCH && (mInfo.BodySize > 0);
  101. this.mSyncInfo = new SyncUnitInfo(zone.IsHalfSync);
  102. this.mSyncInfo.Name = mName;
  103. this.mSyncInfo.TemplateID = mInfo.ID;
  104. this.__mCurrentHP = new RangeValue(mInfo.HealthPoint, 0, mInfo.HealthPoint);
  105. this.__mCurrentMP = new RangeValue(mInfo.ManaPoint, 0, mInfo.ManaPoint);
  106. this.__mCurrentMoveSpeedSEC = mInfo.MoveSpeedSEC;
  107. this.mDropItems = new DropItemGenerator(uinfo.DropItemsSet);
  108. this.mTriggerHelper = new UnitTriggerHelper(this);
  109. if (mInfo.IdleRecover && mInfo.RecoveryIntervalMS > 0)
  110. {
  111. this.mRecoveryTime = new TimeInterval<int>(mInfo.RecoveryIntervalMS);
  112. this.recoverHP = Info.HealthRecoveryPoint;
  113. }
  114. this.InitTimeLines();
  115. this.InitBagSlots();
  116. this.InitSkills(mInfo.BaseSkillID, mInfo.Skills.ToArray());
  117. this.Statistic = this.CreateUnitStatistic();
  118. this.mUnitVirtual = TemplateManager.Factory.CreateUnitVirtual(this);
  119. }
  120. public override bool IsNeedProcessDead()
  121. {
  122. return this.mProcessDeadTime == 0;
  123. }
  124. protected override void Disposing()
  125. {
  126. //if(this.IsMonster && (this.mProcessDeadTime == 0 || this.CurrentHP > 0 || this.mProcessDeadTime == 0))
  127. //{
  128. // log.Info("单位Disposing:" + this.Parent.UUID + ", " + this.Parent.GetSceneID() + ", " + this.ID + ", " + this.CurrentHP + "," +
  129. // this.IsMonster + ", " + mProcessDeadTime);
  130. //}
  131. if (mUnitVirtual != null)
  132. {
  133. mUnitVirtual.OnDispose(this);
  134. }
  135. base.Disposing();
  136. this.clearBindEvents();
  137. this.clearSkills();
  138. this.clearBuffs();
  139. this.clearItemSlots();
  140. this.clearTriggers();
  141. }
  142. protected override void onAdded(bool pointLv)
  143. {
  144. if (this.mUnitVirtual != null)
  145. {
  146. this.mUnitVirtual.OnInit(this, pointLv);
  147. if (this.mRecoveryTime != null && this.Info.UType == UnitType.TYPE_MONSTER)
  148. {
  149. this.recoverHP = Info.HealthRecoveryPoint == 0 ? (int)(this.MaxHP * 0.005f) : Info.HealthRecoveryPoint;
  150. }
  151. }
  152. this.mSyncInfo.ObjectID = base.ID;
  153. this.mSyncInfo.IsTouchObj = this.mIntersectObj;
  154. this.mSyncInfo.IsTouchMap = this.mIntersectMap;
  155. this.mSyncInfo.IsStaticBlockable = this.IsStaticBlockable;
  156. this.mSyncInfo.fateType = (byte)this.Virtual.GetUnitFateType();
  157. if (mInfo.SpawnTimeMS > 0)
  158. {
  159. this.SetInvincibleTimeMS(mInfo.SpawnTimeMS);
  160. }
  161. if (this.mInfo.InventoryList != null)
  162. {
  163. foreach (InventoryItem item in mInfo.InventoryList)
  164. {
  165. ItemTemplate temp = Templates.getItem(item.ItemTemplateID);
  166. if (temp != null)
  167. {
  168. AddItemToEmptyInventory(temp, item.Count);
  169. }
  170. }
  171. }
  172. if (mInfo.Events != null)
  173. {
  174. foreach (int evt_id in mInfo.Events)
  175. {
  176. this.BindUnitEvent(evt_id);
  177. }
  178. }
  179. if (mOnAdded != null)
  180. {
  181. mOnAdded.Invoke(this);
  182. }
  183. }
  184. protected override void onRemoved()
  185. {
  186. if (mOnRemoved != null)
  187. {
  188. mOnRemoved.Invoke(this);
  189. }
  190. foreach (UnitEventTriggerCollection uc in mBindEvents.Values)
  191. {
  192. uc.Dispose();
  193. }
  194. mBindEvents.Clear();
  195. if (Info.RemovedEffect != null)
  196. {
  197. Parent.queueEvent(new AddEffectEvent(this.ID, X, Y, Direction, Info.RemovedEffect));
  198. }
  199. }
  200. public void BindAttackPlayer(string playerId)
  201. {
  202. this.mBindAttackPlayerId = playerId;
  203. }
  204. public string GetAttackPlayer()
  205. {
  206. return this.mBindAttackPlayerId;
  207. }
  208. public void BindMasterId(int masterId)
  209. {
  210. InstanceUnit master = this.Parent.getUnitByID(masterId);
  211. if(master == null)
  212. {
  213. log.Error("BindMasterId找不到单位:" + this.Parent.GetSceneID() + ", " + masterId);
  214. return;
  215. }
  216. if(this.mBindMaster != null)
  217. {
  218. log.Error("BindMasterId重复:" + this.Info.ID + ", " + master.PlayerUUID);
  219. return;
  220. }
  221. this.mBindMaster = master;
  222. }
  223. //--------------------------------------------------------------------------
  224. /// <summary>
  225. /// 扩展功能绑定接口
  226. /// </summary>
  227. public IVirtualUnit Virtual { get { return mUnitVirtual; } }
  228. /// <summary>
  229. /// 扩展数据
  230. /// </summary>
  231. public virtual IUnitProperties Properties { get { return mInfo.Properties; } }
  232. //--------------------------------------------------------------------------
  233. //--------------------------------------------------------------------------
  234. public UnitInfo Info { get { return mInfo; } }
  235. public string Name { get { return mName; } }
  236. public string Alias { get { return mSyncInfo.Alias; } set { if (value != null) { mSyncInfo.Alias = value; } } }
  237. public int Force { get { return mForce; } protected set { mForce = value; } }
  238. public int AlliesForce { get { return mAlliesForce; } protected set { mAlliesForce = value; } }
  239. public float MoveSpeedSEC { get { return __mCurrentMoveSpeedSEC; } }
  240. public float SkillCdReduce { get { return __mCurrentSkillCdReduce; } }
  241. public float ControledTimeReduce { get { return __mCurrentControledTimeReduce; } }
  242. public float ControledTimeAdd { get { return __mControledTimeAdd; } }
  243. public float FastCastRate { get { return mFastCastRate; } }
  244. public override float BodyBlockSize { get { return mInfo.BodySize; } }
  245. public override float BodyHitSize { get { return mInfo.BodyHitSize; } }
  246. public override float BodyHeight { get { return mInfo.BodyHeight; } }
  247. public override float Weight { get { return mInfo.Weight; } }
  248. public override bool IntersectMap { get { return mIntersectMap; } }
  249. public override bool IntersectObj { get { return mIntersectObj && IsVisible; } }
  250. public override bool Moveable { get { return mInfo.IsMoveable; } }
  251. public override bool ClientVisible { get { return true; } }
  252. public override bool SyncPos { get { return true; } }
  253. public override bool IsDead (){ return __mCurrentHP.Value <= 0; }
  254. public int DeadCount { get { return Statistic.DeadCount; } }
  255. public long LastDeadTimeMS { get { return mDeadTime; } }
  256. public bool CanWhiplashDeadBody { get { return Templates.CFG.UNIT_CAN_WHIPLASH_BODY && (LastDeadTimeMS + mInfo.DeadTimeMS > Parent.PassTimeMS); } }
  257. /// <summary>
  258. /// 是否为玩家
  259. /// </summary>
  260. virtual public bool IsPlayer { get { return false; } }
  261. virtual public bool IsMonster { get { return false; } }
  262. virtual public bool IsPet { get { return false; } }
  263. virtual public void OnUnitDead() {}
  264. /// <summary>
  265. /// 是否中立
  266. /// </summary>
  267. virtual public bool IsNature { get { return false; } }
  268. /// <summary>
  269. /// 此单位是否能被攻击并且活着
  270. /// </summary>
  271. virtual public bool IsActive { get { return (base.Enable) && (__mCurrentHP.Value > 0) /*&& !IsInvincible && IsVisible*/; } }
  272. /// <summary>
  273. /// 此单位是否可以被打到,包括鞭尸
  274. /// </summary>
  275. virtual public bool IsAttackable { get { return (base.Enable) /*&& !IsInvincible && IsVisible*/; } }
  276. /// <summary>
  277. /// 此单位是否无技能
  278. /// </summary>
  279. public bool IsNoneSkill { get { return mSkillStatus.Count == 0; } }
  280. /// <summary>
  281. /// 技能可产生位移,或者多段由服务器决定
  282. /// </summary>
  283. virtual public bool IsSkillControllableByServer { get { return true; } }
  284. /// <summary>
  285. /// 单位是否可控
  286. /// </summary>
  287. virtual public bool IsControllable { get { return IsActive && !IsStun && CurrentActionStatus != UnitActionStatus.Damage; } }
  288. /// <summary>
  289. /// 用于显示的,单位横向数据
  290. /// </summary>
  291. public ZoneClient.IUnitVisibleData VisibleInfo { get { return mSyncInfo.VisibleInfo; } }
  292. //-----------------------------------------------------------------------------------------------------//
  293. protected virtual IUnitStatistic CreateUnitStatistic()
  294. {
  295. return new UnitStatistic(this);
  296. }
  297. //-----------------------------------------------------------------------------------------------------//
  298. #region __StateMachine__
  299. private bool is_init = false;
  300. private State current_state = null;
  301. private State next_state;
  302. private Queue<State> next_state_queue = new Queue<State>();
  303. /// <summary>
  304. /// 当前状态机
  305. /// </summary>
  306. public State CurrentState { get { return current_state; } }
  307. //状态机额外数据
  308. public long chuangongTime = 0;
  309. /// <summary>
  310. /// 下一个状态
  311. /// </summary>
  312. protected State NextState { get { return next_state; } }
  313. /// <summary>
  314. /// 死亡状态可能的状态机,一般配合<see cref="IsDead"/>使用
  315. /// </summary>
  316. public bool IsStateDead
  317. {
  318. get
  319. {
  320. if ((current_state is StateDead) ||
  321. (current_state is StateDamage) ||
  322. (current_state is StateDeadFuck) ||
  323. (current_state is StateDeadFuckFuck) ||
  324. (current_state is StateRebirth) ||
  325. (next_state is StateDead) ||
  326. (next_state is StateDamage) ||
  327. (next_state is StateDeadFuck) ||
  328. (next_state is StateDeadFuckFuck) ||
  329. (next_state is StateRebirth))
  330. {
  331. return true;
  332. }
  333. return false;
  334. }
  335. }
  336. public void queueState(State s)
  337. {
  338. next_state_queue.Enqueue(s);
  339. }
  340. public bool TryEnqueueIdleState()
  341. {
  342. if (next_state_queue.Count > 0)
  343. {
  344. return false;
  345. }
  346. next_state_queue.Enqueue(new StateIdle(this));
  347. return true;
  348. }
  349. public void queueCurrentState(State s)
  350. {
  351. if (current_state != null)
  352. {
  353. if (!changeState(s))
  354. {
  355. State.StateStopHandler onstop = new State.StateStopHandler((obj, st) =>
  356. {
  357. changeState(s);
  358. });
  359. current_state.AddStopOnce(onstop);
  360. }
  361. }
  362. else
  363. {
  364. changeState(s);
  365. }
  366. }
  367. public bool changeState(State s, bool force = false)
  368. {
  369. if (s == current_state)
  370. {
  371. return true;
  372. }
  373. if (s == next_state)
  374. {
  375. return true;
  376. }
  377. if (s.unit != this)
  378. {
  379. throw new Exception("State is not Owner unit : " + s);
  380. }
  381. if (current_state == null || current_state.onBlock(s) || force)
  382. {
  383. if (next_state == null || next_state.onBlock(s) || force)
  384. {
  385. if (next_state != null)
  386. {
  387. next_state.stop();
  388. }
  389. onNewStateBeginChange(current_state, ref s);
  390. next_state = s;
  391. return true;
  392. }
  393. }
  394. return false;
  395. }
  396. private void updateState()
  397. {
  398. //绑定主人类怪物,脱战或者主人移除自杀
  399. if(mRemoveSelfTime == 0)
  400. {
  401. if (this.mBindMaster != null && (!this.mBindMaster.IsActive || this.mBindMaster.Virtual.GetBattleStatus() <= BattleStatus.ReadyBattle))
  402. {
  403. //添加移除逻辑
  404. mRemoveSelfTime = CommonLang.CUtils.localTimeMS + 3000;
  405. }
  406. }
  407. else if(mRemoveSelfTime < CommonLang.CUtils.localTimeMS)
  408. {
  409. this.kill(null, false);
  410. }
  411. if (IsDead() && (!IsStateDead))
  412. {
  413. changeState(new StateDead(this, this, false), true);
  414. Parent.cb_unitDeadCallBack(this, this);
  415. queueEvent(new UnitDeadEvent(ID, this.ID, false, mInfo.RebirthTimeMS));
  416. }
  417. else if (next_state == null && next_state_queue.Count > 0)
  418. {
  419. // 尝试从队列中取一个状态机,有机会就执行 //
  420. while (next_state_queue.Count > 0)
  421. {
  422. State queued_state = next_state_queue.Peek();
  423. if (changeState(queued_state))
  424. {
  425. next_state_queue.Dequeue();
  426. }
  427. else { break; }
  428. }
  429. }
  430. if (next_state != null && next_state != current_state)
  431. {
  432. State old_state = current_state;
  433. if (old_state != null)
  434. {
  435. old_state.stop();
  436. }
  437. this.current_state = next_state;
  438. this.next_state = null;
  439. this.current_state.start();
  440. this.onStateChanged(old_state, current_state);
  441. if (mOnStateChanged != null)
  442. {
  443. mOnStateChanged.Invoke(this, old_state, current_state);
  444. }
  445. }
  446. if (current_state != null)
  447. {
  448. current_state.update();
  449. }
  450. UpdateTimeLines(Parent.UpdateIntervalMS);
  451. }
  452. #endregion
  453. protected virtual void onUpdateRecover()
  454. {
  455. //自动恢复
  456. if (this.recoverHP > 0 && mRecoveryTime != null && this.CurrentHP < this.MaxHP && CurrentActionStatus != UnitActionStatus.Damage
  457. && this.Virtual.GetBattleStatus() == BattleStatus.None && !IsDead())
  458. {
  459. if (mRecoveryTime.Update(Parent.UpdateIntervalMS))
  460. {
  461. AddHP(this.recoverHP, null);
  462. //AddMP(Info.ManaRecoveryPoint);
  463. }
  464. }
  465. }
  466. override protected void onUpdate(bool slowRefresh)
  467. {
  468. if (!is_init)
  469. {
  470. is_init = true;
  471. onInit();
  472. }
  473. if (!IsPaused)
  474. {
  475. updatePhysical();
  476. updateState();
  477. onUpdateRecover();
  478. updateSkills();
  479. updateBuffs();
  480. updateTriggers(slowRefresh);
  481. updateItems();
  482. if (mOnUpdate != null)
  483. {
  484. mOnUpdate.Invoke(this);
  485. }
  486. }
  487. updateSyncFields();
  488. updateSyncSkillActives();
  489. }
  490. internal void doAction(ObjectAction act)
  491. {
  492. this.onAction(act);
  493. if (mOnHandleObjectAction != null)
  494. {
  495. mOnHandleObjectAction.Invoke(this, act);
  496. }
  497. }
  498. private void doRebirth(int max_hp, int max_mp)
  499. {
  500. next_state_queue.Clear();
  501. if (this.Moveable)
  502. {
  503. this.mIntersectObj = !Templates.CFG.OBJECT_NONE_TOUCH && (mInfo.BodySize > 0);
  504. }
  505. else
  506. {
  507. this.mIntersectObj = (mInfo.BodySize > 0);
  508. }
  509. if (max_hp == 0) max_hp = this.MaxHP;
  510. if (max_mp == 0) max_mp = this.MaxMP;
  511. if (max_hp != 0) this.__mCurrentHP.SetValue(max_hp);
  512. if (max_mp != 0) this.__mCurrentMP.SetValue(max_mp);
  513. syncFields(UnitFieldChangedEvent.MASK_HP | UnitFieldChangedEvent.MASK_MP);
  514. Parent.cb_unitRebirthCallBack(this);
  515. queueEvent(new UnitRebirthEvent(ID));
  516. }
  517. public void updateContinueKills()
  518. {
  519. if (this.Statistic.continueKills < short.MaxValue)
  520. {
  521. ++this.Statistic.continueKills;
  522. }
  523. UnitContinueKillValue temp = new UnitContinueKillValue(this.ID, this.Statistic.continueKills);
  524. queueEvent(temp);
  525. }
  526. public void resetContinueKills()
  527. {
  528. this.Statistic.continueKills = 0;
  529. }
  530. private void doActivated()
  531. {
  532. next_state_queue.Clear();
  533. if (this.Moveable)
  534. {
  535. this.mIntersectObj = !Templates.CFG.OBJECT_NONE_TOUCH && (mInfo.BodySize > 0);
  536. }
  537. else
  538. {
  539. this.mIntersectObj = (mInfo.BodySize > 0);
  540. }
  541. this.addTriggers(mInfo.Triggers);
  542. Parent.cb_unitActivatedCallBack(this);
  543. }
  544. internal void doDead(InstanceUnit killer)
  545. {
  546. if(killer != null)
  547. {
  548. this.Statistic.LogDead(killer.Statistic);
  549. }
  550. this.mIntersectObj = false;
  551. this.clearBuffs();
  552. //吴永辉:5v5人物死亡后会重置技能CD 无论在哪个地图死亡都不能重置 你可能要指给黄鱼 bugid=2748
  553. //this.ClearAllSkillCD();
  554. this.resetAI();
  555. }
  556. //------------------------------------------------------------------------------------------------------//
  557. internal void callback_onActivated(InstanceZone zone)
  558. {
  559. if (this.mOnActivated != null)
  560. this.mOnActivated.Invoke(this);
  561. }
  562. internal void callback_onAttack(InstanceZone zone, InstanceUnit target, int reduceHP, AttackSource source)
  563. {
  564. if (this.mOnAttack != null)
  565. this.mOnAttack(this, target, reduceHP, source);
  566. }
  567. internal void callback_onDamage(InstanceZone zone, InstanceUnit attacker, int reduceHP, AttackSource source)
  568. {
  569. if (this.mOnDamage != null)
  570. this.mOnDamage.Invoke(this, attacker, reduceHP, source);
  571. }
  572. public long mProcessDeadTime = 0;
  573. internal void callback_onDead(InstanceZone zone, InstanceUnit attacker)
  574. {
  575. this.mProcessDeadTime = CommonLang.TimeUtil.GetTimestampMS();
  576. this.OnUnitDead();
  577. if (this.mOnDead != null)
  578. this.mOnDead.Invoke(this, attacker);
  579. }
  580. internal void callback_onRebirth(InstanceZone zone)
  581. {
  582. if (this.mOnRebirth != null)
  583. this.mOnRebirth.Invoke(this);
  584. }
  585. internal void callback_onGotInstanceItem(InstanceZone zone, InstanceItem item)
  586. {
  587. if (this.mOnGotInstanceItem != null)
  588. this.mOnGotInstanceItem.Invoke(this, item);
  589. }
  590. internal void callback_onGotInventoryItem(InstanceZone zone, ItemTemplate item)
  591. {
  592. if (this.mOnGotInventoryItem != null)
  593. this.mOnGotInventoryItem.Invoke(this, item);
  594. }
  595. internal void callback_onLostInventoryItem(InstanceZone zone, ItemTemplate item)
  596. {
  597. if (this.mOnLostInventoryItem != null)
  598. this.mOnLostInventoryItem.Invoke(this, item);
  599. }
  600. internal void callback_onUseItem(InstanceZone zone, ItemTemplate item, InstanceUnit item_creater)
  601. {
  602. if (this.mOnUseItem != null)
  603. this.mOnUseItem.Invoke(this, item, item_creater);
  604. }
  605. internal void callback_onGotBuff(InstanceZone zone, InstanceUnit.BuffState buff)
  606. {
  607. if (this.mOnGotBuff != null)
  608. this.mOnGotBuff.Invoke(this, buff);
  609. }
  610. internal void callback_onLostBuff(InstanceZone zone, InstanceUnit.BuffState buff)
  611. {
  612. if (this.mOnLostBuff != null)
  613. this.mOnLostBuff.Invoke(this, buff);
  614. }
  615. //-----------------------------------------------------------------------------------------------------//
  616. private void onInit()
  617. {
  618. syncFields(UnitFieldChangedEvent.MASK_ALL);
  619. if (mInfo.SpawnTimeMS > 0)
  620. {
  621. changeState(new StateSpawn(this, mInfo.SpawnTimeMS));
  622. }
  623. else
  624. {
  625. changeState(new StateIdle(this));
  626. doActivated();
  627. }
  628. }
  629. #region _Overrideable_
  630. /// <summary>
  631. /// 收到协议
  632. /// </summary>
  633. /// <param name="act"></param>
  634. virtual protected void onAction(ObjectAction act) { }
  635. /// <summary>
  636. /// 新的状态将要切换时回调
  637. /// </summary>
  638. virtual protected void onNewStateBeginChange(State old_state, ref State new_state) { }
  639. /// <summary>
  640. /// 状态已切换时回调
  641. /// </summary>
  642. /// <param name="old_state"></param>
  643. /// <param name="state"></param>
  644. virtual protected void onStateChanged(State old_state, State state) { }
  645. // 被攻击时回调
  646. virtual protected void onDamaged(InstanceUnit attacker, AttackSource source, int reduceHP) { }
  647. virtual protected void onDead(InstanceUnit killer) { }
  648. #endregion
  649. /// <summary>
  650. /// 单位被攻击核心函数,里面处理受击状态,死亡状态
  651. /// </summary>
  652. /// <param name="attacker"></param>
  653. /// <param name="source"></param>
  654. virtual protected internal void doHitAttack(InstanceUnit attacker, AttackSource source)
  655. {
  656. if (IsDead())
  657. {
  658. //死亡后鞭尸//
  659. if (Moveable && CanWhiplashDeadBody)
  660. {
  661. source.Begin(this);
  662. changeState(new StateDamage(this, source, attacker));
  663. }
  664. doHitAttackEndEffect(attacker, source);
  665. return;
  666. }
  667. else
  668. {
  669. if (current_state is StateDamage)
  670. {
  671. StateDamage state_damage = current_state as StateDamage;
  672. if (state_damage.IsDamageProtect)
  673. {
  674. return;
  675. }
  676. }
  677. // TODO HP //
  678. source.Begin(this);
  679. int reduceHP = mFormula.OnHit(attacker, source, this);
  680. // 统计 //
  681. this.Statistic.LogDamage(attacker.Statistic, reduceHP);
  682. reduceHP = this.AddHP(-reduceHP, attacker, !source.OutSendEvent, source);
  683. AttackProp attack = source.Attack;
  684. // Post Event //
  685. if (source.OutSendEvent)
  686. {
  687. UnitHitEvent evt = new UnitHitEvent(ID);
  688. evt.senderId = attacker.ID;
  689. evt.senderMasterId = attacker.Virtual.GetMasterID();
  690. evt.hitMasterId = this.Virtual.GetMasterID();
  691. evt.hp = reduceHP;
  692. evt.isDead = IsDead();
  693. evt.isCritical = source.Attack.MaskMustCritical;
  694. evt.effect = source.OutHitEffect;
  695. evt.SourceAttack = source.Attack;
  696. evt.client_state = source.OutClientState;
  697. if(source != null && attacker != null && source.FromSkillType == XmdsSkillType.cardSkill && this.IsMonster && attacker.IsMonster)
  698. {
  699. evt.InViewForceSend = true;
  700. }
  701. queueEvent(evt);
  702. }
  703. if (reduceHP > 0)
  704. {
  705. source.HasHitted = true;
  706. onDamaged(attacker, source, reduceHP);
  707. Parent.cb_unitDamageCallBack(this, attacker, reduceHP, source);
  708. if (IsDead())
  709. {
  710. doDeadProcess(attacker, source);
  711. return;
  712. }
  713. }
  714. // 非免控,才会有受击
  715. if (!this.IsIgnoreControl && source.OutIsDamage && Moveable)
  716. {
  717. changeState(new StateDamage(this, source, attacker));
  718. }
  719. doHitAttackEndEffect(attacker, source);
  720. return;
  721. }
  722. }
  723. /** 执行死亡处理逻辑 */
  724. private void doDeadProcess(InstanceUnit attacker, AttackSource source)
  725. {
  726. if (this.IsMonster)
  727. {
  728. if (this.mProcessDeadCallbackTime + 1000 > CommonLang.CUtils.localTimeMS)
  729. {
  730. log.Info("cb_unitDeadCallBack 跳过:" + this.mProcessDeadCallbackTime + ", " + this.Info.ID + ", " + this.ID);
  731. return;
  732. }
  733. if(this.Virtual.GetMaType() >= 4 && this.Level > 80)
  734. {
  735. log.Info("boss死亡:" + this.mProcessDeadCallbackTime + ", 单位id=" + this.Info.ID + ", 场景Id=" +
  736. this.Parent.GetSceneID() + ", " + this.mZone.UUID + ", " + (attacker == null ? "null" : attacker.PlayerUUID));
  737. }
  738. }
  739. mDeadTime = Parent.PassTimeMS;
  740. onDead(attacker);
  741. Parent.cb_unitDeadCallBack(this, attacker);
  742. queueEvent(new UnitDeadEvent(ID, attacker.ID, source.OutIsCrush, mInfo.RebirthTimeMS));
  743. // 被击碎,秒杀 //
  744. if (source.OutIsCrush)
  745. {
  746. Parent.queueEvent(new AddEffectEvent(this.ID, X, Y, Direction, source.Attack.CrushEffect));
  747. changeState(new StateDead(this, attacker, true));
  748. }
  749. else
  750. {
  751. if (!Moveable)
  752. {
  753. changeState(new StateDead(this, attacker));
  754. }
  755. else if (source.OutHasKnockDown || source.OutHasFly)
  756. {
  757. if (!changeState(new StateDamage(this, source, attacker)))
  758. {
  759. changeState(new StateDead(this, attacker));
  760. }
  761. }
  762. else
  763. {
  764. changeState(new StateDead(this, attacker));
  765. }
  766. }
  767. doHitAttackEndEffect(attacker, source);
  768. }
  769. /// <summary>
  770. /// 死亡后自爆或者触发法术
  771. /// </summary>
  772. /// <param name="attacker"></param>
  773. /// <param name="source"></param>
  774. private void doHitAttackEndEffect(InstanceUnit attacker, AttackSource source)
  775. {
  776. if (source.Attack.Buff != null)
  777. {
  778. AddBuff(source.Attack.Buff, attacker);
  779. }
  780. if (source.Attack.Spell != null)
  781. {
  782. Parent.attackLaunchSpell(source.FromSkillType, attacker, this, source);
  783. }
  784. }
  785. // 单位获取道具
  786. protected virtual bool tryGotItem(InstanceItem item, out bool removeItem)
  787. {
  788. if (!Parent.IsVisibleAOI(this, item))
  789. {
  790. removeItem = false;
  791. return false;
  792. }
  793. if (item.Info.DropMoneyMin > 0 && item.Info.DropMoneyMax > 0)
  794. {
  795. int min = Math.Min(item.Info.DropMoneyMin, item.Info.DropMoneyMax);
  796. int max = Math.Max(item.Info.DropMoneyMin, item.Info.DropMoneyMax);
  797. int money = RandomN.Next(min, max + 1);
  798. this.CurrentMoney += money;
  799. removeItem = item.Info.RemoveOnFinishPick;
  800. return true;
  801. }
  802. if (item.Info.GotOnUse)
  803. {
  804. // 获取后立即使用 //
  805. if (UseItem(item.Info, item.ItemCreater))
  806. {
  807. removeItem = item.Info.RemoveOnFinishPick;
  808. return true;
  809. }
  810. }
  811. else
  812. {
  813. // 获取后进背包 //
  814. if (AddItemToEmptyInventory(item.Info) > 0)
  815. {
  816. removeItem = item.Info.RemoveOnFinishPick;
  817. return true;
  818. }
  819. }
  820. removeItem = false;
  821. return false;
  822. }
  823. internal bool doGotInstanceItem(InstanceItem item, out bool removeItem, out int pickTimes)
  824. {
  825. pickTimes = 0;
  826. var ret = tryGotItem(item, out removeItem);
  827. if (ret)
  828. {
  829. pickTimes = Parent.cb_unitGotInstanceItemCallBack(this, item);
  830. if (item.Info.GotEffect != null)
  831. {
  832. queueEvent(new UnitEffectEvent(ID, item.Info.GotEffect));
  833. }
  834. }
  835. return ret;
  836. }
  837. internal void doGotInventoryItem(InventorySlot slot, ItemTemplate item, int index, int count)
  838. {
  839. mFormula.OnGotInventoryItem(this, item);
  840. queueEvent(new UnitSyncInventoryItemEvent(ID, item.ID, index, slot.Count));
  841. Parent.cb_unitGotInventoryItemCallBack(this, item, count);
  842. // 添加装备Buff //
  843. if (item.EquipBuffs != null)
  844. {
  845. foreach (LaunchBuff buff in item.EquipBuffs)
  846. {
  847. AddBuff(buff, this, true);
  848. }
  849. }
  850. }
  851. internal void doLostInventoryItem(InventorySlot slot, ItemTemplate item, int index, int count)
  852. {
  853. mFormula.OnLostInventoryItem(this, item);
  854. queueEvent(new UnitSyncInventoryItemEvent(ID, item.ID, index, slot.Count));
  855. Parent.cb_unitLostInventoryItemCallBack(this, item, count);
  856. // 移除装备Buff //
  857. if (item.EquipBuffs != null)
  858. {
  859. foreach (LaunchBuff buff in item.EquipBuffs)
  860. {
  861. removeBuff(buff.BuffID);
  862. }
  863. }
  864. }
  865. // 单位获取道具
  866. internal void doGotBuff(InstanceUnit.BuffState buff)
  867. {
  868. Parent.cb_unitGotBuffCallBack(this, buff);
  869. }
  870. internal void doLostBuff(InstanceUnit.BuffState buff)
  871. {
  872. Parent.cb_unitLostBuffCallBack(this, buff);
  873. }
  874. public bool UseItem(int itemTemplateID, InstanceUnit item_creater = null)
  875. {
  876. ItemTemplate item = Templates.getItem(itemTemplateID);
  877. if (item != null)
  878. {
  879. return UseItem(item, item_creater);
  880. }
  881. return false;
  882. }
  883. public bool UseItem(ItemTemplate item, InstanceUnit item_creater = null)
  884. {
  885. if (item_creater == null)
  886. {
  887. item_creater = this;
  888. }
  889. if (tryUseItem(item, item_creater))
  890. {
  891. beginUseItem(item);
  892. // 如果关键帧绑定特效
  893. if (item.UseEffect != null)
  894. {
  895. queueEvent(new UnitEffectEvent(ID, item.UseEffect));
  896. }
  897. // 如果关键帧绑定释放法术
  898. if (item.UseSpell != null)
  899. {
  900. Parent.unitLaunchSpell(XmdsSkillType.none, item_creater, item.UseSpell, X, Y);
  901. }
  902. if (item.UseSummon != null)
  903. {
  904. Parent.unitSummonUnit(item_creater, item.UseSummon);
  905. }
  906. // 如果关键帧绑定自己释放BUFF
  907. if (item.UseBuffs != null)
  908. {
  909. foreach (LaunchBuff buff in item.UseBuffs)
  910. {
  911. this.AddBuff(buff, item_creater);
  912. }
  913. }
  914. mFormula.OnUseItem(this, item, item_creater);
  915. queueEvent(new UnitUseItemEvent(ID, item.ID));
  916. Parent.cb_unitUseItemCallBack(this, item, item_creater);
  917. Statistic.LogUseItem(item);
  918. return true;
  919. }
  920. return false;
  921. }
  922. //-----------------------------------------------------------------------------------------------------//
  923. /// <summary>
  924. /// 有伤害源的扣血
  925. /// </summary>
  926. /// <param name="hp"></param>
  927. /// <param name="attacker"></param>
  928. /// <param name="sendHit"></param>
  929. /// <param name="hitMessage"></param>
  930. public int ReduceHP(int hp, InstanceUnit attacker, bool sendHit = true, UnitHitEvent hitMessage = null,
  931. bool IngoreHealEffect = false, DamageSource dmgSrc = DamageSource.Def)
  932. {
  933. //1.目标无敌,不扣血
  934. if (IsDead() || hp == 0 || ( hp > 0 && this.IsInvincible))
  935. {
  936. return 0;
  937. }
  938. if (attacker != null)
  939. {
  940. if (hp < 0 && !IngoreHealEffect)
  941. {
  942. int healedEffect = this.Virtual.GetHealedEffect();
  943. int healEffect = (attacker.Virtual.GetUnitPro() == XmdsUnitPro.Priest) ? attacker.Virtual.GetHealEffect() : 0;
  944. if (healedEffect != 0 || healEffect != 0)
  945. {
  946. hp = CUtils.CastInt(hp * (1 + healEffect * 0.0001) * (1 + healedEffect * 0.0001));
  947. }
  948. }
  949. this.Statistic.LogDamage(attacker.Statistic, hp);
  950. }
  951. //2. 针对有发送者的伤害来源
  952. if(attacker != null)
  953. {
  954. if (hp < 0)
  955. {
  956. //2.1 传递加血事件
  957. int finalHP = hp;
  958. attacker.Virtual.DispatchAddOtherHPEvent(-hp, this, out finalHP);
  959. hp = -finalHP;
  960. //2.2 道灵对宠物加血,需要有个系数
  961. if(attacker.IsPlayer && this.IsPet && attacker.Virtual.GetUnitPro() == XmdsUnitPro.Priest)
  962. {
  963. hp = (int)(hp * XmdsConstConfig.PET_HEALD_RATIO);
  964. }
  965. }
  966. else if(this.IsPlayer)
  967. {
  968. //2.2 如果为玩家,伤害来源存在且为怪物,宠物可以分担伤害
  969. InstanceUnit petUnit = this.Virtual.GetPetUnit();
  970. if(petUnit != null)
  971. {
  972. int petShareDmg = Math.Max(1, (int)(hp * XmdsConstConfig.PET_SHARE_MASTERDMG_RATIO));
  973. hp = Math.Max(1, hp - petShareDmg);
  974. petUnit.PetShareDamage(petShareDmg, this);
  975. }
  976. }
  977. }
  978. this.DoAddHP(-hp);
  979. if (attacker != null && sendHit)
  980. {
  981. if (hitMessage == null)
  982. {
  983. hitMessage = new UnitHitEvent();
  984. }
  985. hitMessage.object_id = this.ID;
  986. hitMessage.senderId = attacker == null ? 0 : attacker.ID;
  987. hitMessage.senderMasterId = attacker == null ? 0 : attacker.Virtual.GetMasterID();
  988. hitMessage.hitMasterId = this.Virtual.GetMasterID();
  989. hitMessage.hp = hp;
  990. hitMessage.isSpecialHit = dmgSrc != DamageSource.Def;
  991. hitMessage.dmgSrc = dmgSrc;
  992. hitMessage.isDead = IsDead();
  993. queueEvent(hitMessage);
  994. }
  995. //if (IsDead())
  996. //{
  997. // changeState(new StateDead(this, attacker, false));
  998. // Parent.cb_unitDeadCallBack(this, attacker);
  999. // queueEvent(new UnitDeadEvent(ID, attacker == null ? 0 : attacker.ID, false, mInfo.RebirthTimeMS));
  1000. //}
  1001. return hp;
  1002. }
  1003. public void AddMP(int mp, InstanceUnit sender, bool sendMsg = true, bool force = false, AttackSource source = null)
  1004. {
  1005. if(mp == 0 || this.MaxMP <= 0)
  1006. {
  1007. return;
  1008. }
  1009. //传递扣定力事件
  1010. if (mp < 0 && sender != null)
  1011. {
  1012. int finalHP = mp;
  1013. sender.Virtual.DispatchAddMPEvent(mp, this, out finalHP, source);
  1014. mp = finalHP;
  1015. }
  1016. this.DoAddMP(mp, force);
  1017. }
  1018. public void removeFromParent()
  1019. {
  1020. Parent.RemoveObjectByID(ID);
  1021. }
  1022. public void kill(InstanceUnit killer = null, bool sendHit = true, UnitHitEvent hitMessage = null)
  1023. {
  1024. ReduceHP(this.CurrentHP, killer, sendHit, hitMessage, true);
  1025. }
  1026. virtual protected void onResetAI()
  1027. {
  1028. this.doSomething();
  1029. }
  1030. public void resetAI()
  1031. {
  1032. next_state_queue.Clear();
  1033. onResetAI();
  1034. }
  1035. public override void faceTo(float d)
  1036. {
  1037. if (Info.IsTurnable) { base.faceTo(d); }
  1038. }
  1039. public override void faceTo(float x, float y)
  1040. {
  1041. if (Info.IsTurnable) { base.faceTo(x, y); }
  1042. }
  1043. /// <summary>
  1044. /// 瞬移
  1045. /// </summary>
  1046. /// <param name="x"></param>
  1047. /// <param name="y"></param>
  1048. public void transport(float x, float y, bool setDirction = false, float direction = 0)
  1049. {
  1050. this.SetActionStatus(UnitActionStatus.Transport);
  1051. this.changeState(new StateTransport(this), true);
  1052. setPos(x, y);
  1053. if (setDirction)
  1054. {
  1055. this.faceTo(direction);
  1056. }
  1057. SendForceSync();
  1058. if (mOnRegionTransport != null)
  1059. {
  1060. mOnRegionTransport.Invoke();
  1061. }
  1062. }
  1063. //-----------------------------------------------------------------------------------------------------//
  1064. public virtual void doSomething()
  1065. {
  1066. startIdle();
  1067. }
  1068. /// <summary>
  1069. /// 单位待机
  1070. /// </summary>
  1071. public bool startIdle(bool force = false)
  1072. {
  1073. if (current_state is StateIdle)
  1074. {
  1075. }
  1076. else
  1077. {
  1078. return changeState(new StateIdle(this), force);
  1079. }
  1080. return false;
  1081. }
  1082. /// <summary>
  1083. /// 直接复活
  1084. /// </summary>
  1085. public bool startRebirth(int max_hp = 0, int max_mp = 0)
  1086. {
  1087. if (IsDead())
  1088. {
  1089. this.DeadHide = false;
  1090. return changeState(new StateRebirth(this, max_hp, max_mp));
  1091. }
  1092. return false;
  1093. }
  1094. /// <summary>
  1095. /// 单位移动
  1096. /// </summary>
  1097. /// <param name="x"></param>
  1098. /// <param name="y"></param>
  1099. public bool startMoveTo(float x, float y)
  1100. {
  1101. return changeState(new StateMove(this, x, y));
  1102. }
  1103. /// <summary>
  1104. /// 调整射击位置
  1105. /// </summary>
  1106. /// <param name="expect_skill"></param>
  1107. /// <param name="target"></param>
  1108. /// <param name="onEndAction"></param>
  1109. public bool startAdjustLaunchSkill(SkillTemplate expect_skill, InstanceUnit target, Predicate<StateMove> onEndAction)
  1110. {
  1111. if (expect_skill.AttackKeepRange > 0 && expect_skill.AttackRange > expect_skill.AttackKeepRange)
  1112. {
  1113. float keep_range = GetSkillAttackRange(expect_skill.AttackKeepRange) + target.BodyBlockSize;
  1114. float distance = MathVector.getDistance(this.X, this.Y, target.X, target.Y);
  1115. if (distance < keep_range)
  1116. {
  1117. var half = (expect_skill.AttackRange - expect_skill.AttackKeepRange) / 2;
  1118. var md = (keep_range - distance) + (float)(RandomN.NextDouble() * half);
  1119. var target_pos = new Vector2(this.X, this.Y);
  1120. var rd = (CMath.PI_DIV_2 / 4);
  1121. var target_direction = this.Direction + CMath.PI_F - (rd / 2 + (float)(RandomN.NextDouble() * rd));
  1122. MathVector.movePolar(target_pos, target_direction, md);
  1123. if (!Parent.TryTouchMap(this, target_pos.X, target_pos.Y))
  1124. {
  1125. var back_pos = new Vector2(this.X, this.Y);
  1126. MathVector.movePolar(back_pos, target_direction, this.BodyBlockSize);
  1127. if (!Parent.TryTouchMap(this, back_pos.X, back_pos.Y))
  1128. {
  1129. var move = new StateMove(this, target_pos.X, target_pos.Y);
  1130. move.MinStepCheckCount = 0;
  1131. move.StopOnTouchMap = true;
  1132. move.EndMoveAction = onEndAction;
  1133. return this.changeState(move);
  1134. }
  1135. }
  1136. }
  1137. }
  1138. return false;
  1139. }
  1140. /// <summary>
  1141. /// 单位移动
  1142. /// </summary>
  1143. /// <param name="obj"></param>
  1144. public bool startFollowTo(InstanceZoneObject obj)
  1145. {
  1146. return changeState(new StateFollowObject(this, obj));
  1147. }
  1148. /// <summary>
  1149. /// 单位逃跑
  1150. /// </summary>
  1151. /// <param name="timeMS"></param>
  1152. /// <param name="distance"></param>
  1153. public bool startEscape(int timeMS, float distance = 0)
  1154. {
  1155. return changeState(new StateEscape(this, timeMS, distance));
  1156. }
  1157. /// <summary>
  1158. /// 和自身交互(搓炉石)
  1159. /// </summary>
  1160. /// <param name="timeMS"></param>
  1161. /// <param name="done"></param>
  1162. /// <param name="status"></param>
  1163. public StatePickObject startPickProgressSelf(int timeMS, StatePickObject.OnPickDone done, string status = null)
  1164. {
  1165. StatePickObject picking = new StatePickObject(this, this, timeMS, status, done);
  1166. changeState(picking);
  1167. return picking;
  1168. }
  1169. /// <summary>
  1170. /// 和目标交互
  1171. /// </summary>
  1172. /// <param name="item"></param>
  1173. /// <param name="timeMS"></param>
  1174. /// <param name="done"></param>
  1175. /// <param name="status"></param>
  1176. /// <returns></returns>
  1177. public StatePickObject startPickProgressObject(InstanceZoneObject item, int timeMS, StatePickObject.OnPickDone done, string status = null)
  1178. {
  1179. StatePickObject picking = new StatePickObject(this, item, timeMS, status, done);
  1180. changeState(picking);
  1181. return picking;
  1182. }
  1183. //-----------------------------------------------------------------------------------------------------------------
  1184. #region _SKILL_
  1185. //-----------------------------------------------------------------------------------------------------------------
  1186. public float GetSkillAttackRange(SkillTemplate skill)
  1187. {
  1188. return mIsAttackRangeIncludeBodySize ? BodyBlockSize + skill.AttackRange : skill.AttackRange;
  1189. }
  1190. public float GetSkillAttackRange(float range)
  1191. {
  1192. return (mIsAttackRangeIncludeBodySize ? BodyBlockSize + range : range);
  1193. }
  1194. /// <summary>
  1195. /// 判断当前目标在攻击范围内
  1196. /// </summary>
  1197. /// <param name="skill"></param>
  1198. /// <param name="unit"></param>
  1199. /// <returns></returns>
  1200. public bool IsTargetInSkillRange(SkillTemplate skill, InstanceUnit unit)
  1201. {
  1202. float rg = GetSkillAttackRange(skill);
  1203. float dr = skill.AttackAngle / 2;
  1204. if (Collider.Object_HitBody_TouchFan(unit, X, Y, rg, Direction - dr, Direction + dr))
  1205. {
  1206. return true;
  1207. }
  1208. return false;
  1209. }
  1210. [Obsolete]
  1211. public List<InstanceUnit> getSkillAttackableTargets(SkillTemplate skill, AttackReason reason)
  1212. {
  1213. float rg = GetSkillAttackRange(skill);
  1214. List<InstanceUnit> list = Parent.getObjectsRoundRange<InstanceUnit>(Collider.Object_HitBody_TouchRound, X, Y, rg , this.AoiStatus);
  1215. Parent.getAttackableUnits(this, list, skill.ExpectTarget, reason, skill);
  1216. return list;
  1217. }
  1218. public void getSkillAttackableTargets(SkillTemplate skill, List<InstanceUnit> list, AttackReason reason)
  1219. {
  1220. float rg = GetSkillAttackRange(skill);
  1221. Parent.getObjectsRoundRange<InstanceUnit>(Collider.Object_HitBody_TouchRound, X, Y, rg, list, this.AoiStatus);
  1222. Parent.getAttackableUnits(this, list, skill.ExpectTarget, reason, skill);
  1223. }
  1224. /// <summary>
  1225. /// 获得可用的技能
  1226. /// </summary>
  1227. /// <param name="expect"></param>
  1228. /// <returns></returns>
  1229. public SkillState getAvailableSkill(SkillTemplate.CastTarget expect)
  1230. {
  1231. for (int si = mAllSkills.Count - 1; si >= 0; --si)
  1232. {
  1233. SkillTemplate st = mAllSkills[si];
  1234. if (st.ExpectTarget == expect)
  1235. {
  1236. SkillState sst = mSkillStatus.Get(st.GetID());
  1237. if (sst.IsActive && sst.IsDone)
  1238. {
  1239. return sst;
  1240. }
  1241. }
  1242. }
  1243. return null;
  1244. }
  1245. /** 获取当前可自动释放的技能 */
  1246. public SkillState getAvailableAutoLaunchSkill(SkillTemplate.CastTarget expect)
  1247. {
  1248. for (int si = mAllSkills.Count - 1; si >= 0; --si)
  1249. {
  1250. SkillTemplate st = mAllSkills[si];
  1251. if (st.ExpectTarget == expect)
  1252. {
  1253. SkillState sst = mSkillStatus.Get(st.GetID());
  1254. if (sst.IsActive && sst.IsDone && sst.LaunchSkill.AutoLaunch && sst.CanAutoLaunch())
  1255. {
  1256. return sst;
  1257. }
  1258. }
  1259. }
  1260. return null;
  1261. }
  1262. /// <summary>
  1263. /// 获取当前最适合攻击的目标
  1264. /// </summary>
  1265. /// <param name="skill"></param>
  1266. /// <param name="reason"></param>
  1267. /// <param name="directionChange"></param>
  1268. /// <returns></returns>
  1269. public InstanceUnit getSkillAttackableFirstTarget(SkillTemplate skill, AttackReason reason, ref bool directionChange)
  1270. {
  1271. using (var list = ListObjectPool<InstanceUnit>.AllocAutoRelease())
  1272. {
  1273. getSkillAttackableTargets(skill, list, reason);
  1274. if (list.Count > 0)
  1275. {
  1276. float rg = GetSkillAttackRange(skill);
  1277. // 检测攻击范围内的单位 //
  1278. float dr = skill.AttackAngle / 2;
  1279. for (int i = 0; i < list.Count; i++)
  1280. {
  1281. InstanceUnit u = list[i];
  1282. if (Collider.Object_HitBody_TouchFan(u, X, Y, rg, Direction - dr, Direction + dr))
  1283. {
  1284. directionChange = false;
  1285. return u;
  1286. }
  1287. }
  1288. // 优先当前朝向的目标 //
  1289. dr = CMath.PI_DIV_2;
  1290. directionChange = true;
  1291. for (int i = 0; i < list.Count; i++)
  1292. {
  1293. InstanceUnit u = list[i];
  1294. if (Collider.Object_HitBody_TouchFan(u, X, Y, rg, Direction - dr, Direction + dr))
  1295. {
  1296. return u;
  1297. }
  1298. }
  1299. // 最后选取最近的目标 //
  1300. InstanceUnit min = null;
  1301. float min_len = float.MaxValue;
  1302. for (int i = 0; i < list.Count; i++)
  1303. {
  1304. InstanceUnit u = list[i];
  1305. float len = MathVector.getDistanceSquare(u.X, u.Y, X, Y);
  1306. if (min_len > len)
  1307. {
  1308. min_len = len;
  1309. min = u;
  1310. }
  1311. }
  1312. return min;
  1313. }
  1314. }
  1315. return null;
  1316. }
  1317. public struct LaunchSkillParam
  1318. {
  1319. public uint TargetUnitID;
  1320. public Vector2 SpellTargetPos;
  1321. public bool AutoFocusNearTarget;
  1322. public bool LaunchSetDirection; // 释放时是否重新设置方向
  1323. public float direction;
  1324. public bool IsAutoLaunch; // 是否自动战斗时释放
  1325. public bool IsInGuard; // 是否是自动战斗
  1326. public LaunchSkillParam(uint targetUnitID = 0, Vector2 target_pos = null, bool autoFocusNearTarget = false,
  1327. bool LaunchSetDirection = false, float direction = 0, bool IsAutoLaunch = false, bool IsInGuard = false)
  1328. {
  1329. this.TargetUnitID = targetUnitID;
  1330. this.SpellTargetPos = target_pos;
  1331. this.AutoFocusNearTarget = autoFocusNearTarget;
  1332. this.LaunchSetDirection = LaunchSetDirection;
  1333. this.direction = direction;
  1334. this.IsAutoLaunch = IsAutoLaunch;
  1335. this.IsInGuard = IsInGuard;
  1336. }
  1337. }
  1338. public StateSkill launchSkill(SkillState ss, LaunchSkillParam param)
  1339. {
  1340. if (ss == null) return null;
  1341. StateSkill current = CurrentState as StateSkill;
  1342. if (current != null && current.SkillData.IsManuallyCancelable)
  1343. {
  1344. //如果当前技能为手动取消//
  1345. if (current.Skill.ID == ss.ID)
  1346. {
  1347. //判断停止当前技能//
  1348. if (current.IsCancelableBySkill)
  1349. {
  1350. current.block();
  1351. }
  1352. }
  1353. //手动取消技能禁止其他技能打断//
  1354. return null;
  1355. }
  1356. if (ss.TryLaunch() && mFormula.TryLaunchSkill(this, ss, ref param))
  1357. {
  1358. if(param.IsAutoLaunch && !ss.CanAutoLaunch())
  1359. {
  1360. return null;
  1361. }
  1362. //沉默不能释放其他技能//
  1363. if (IsSilent && ss != mDefaultSkill)
  1364. {
  1365. return null;
  1366. }
  1367. // 自动战斗下,释放技能要在范围内
  1368. InstanceUnit target = null;
  1369. if (ss.Data.AttackMustBeInRange)
  1370. {
  1371. target = Parent.getUnit(param.TargetUnitID);
  1372. if (!ss.checkTargetRange(target))
  1373. {
  1374. return null;
  1375. }
  1376. }
  1377. //是否在合理的攻击范围内
  1378. if(param.IsInGuard && !ss.checkTargetInAttackRange(target, param))
  1379. {
  1380. return null;
  1381. }
  1382. if (ss.GetSkillType() == XmdsSkillType.petGiveAcitve)
  1383. {
  1384. mFormula.TriggerPetSkill(this, ss, ref param);
  1385. return null;
  1386. }
  1387. StateSkill state = new StateSkill(this, ss, param, ss.ActionSpeed, (st) =>
  1388. {
  1389. overLaunchSkill(ss, st);
  1390. if (mOnLaunchSkill != null)
  1391. {
  1392. mOnLaunchSkill.Invoke(this, ss);
  1393. }
  1394. });
  1395. if (state.tryLaunch())
  1396. {
  1397. this.Virtual.SetCombatState(BattleStatus.ReadyBattle);
  1398. Parent.cb_unitLaunchSkill(this, ss);
  1399. if (changeState(state))
  1400. {
  1401. //释放成功
  1402. if (param.LaunchSetDirection)
  1403. {
  1404. //Console.WriteLine("launchSkill - 设置方向: " + param.direction + ", " + this.ID);
  1405. //this.faceTo(param.direction);
  1406. //this.SendForceSync();
  1407. }
  1408. return state;
  1409. }
  1410. }
  1411. }
  1412. return null;
  1413. }
  1414. protected virtual void overLaunchSkill(SkillState ss, StateSkill state)
  1415. {
  1416. this.AddHP(-ss.Data.CostHP, null);
  1417. this.AddMP(-ss.Data.CostMP, null);
  1418. }
  1419. /// <summary>
  1420. /// 单位释放技能
  1421. /// </summary>
  1422. public StateSkill launchSkill(int skillID, LaunchSkillParam param)
  1423. {
  1424. SkillState skill = getSkillState(skillID);
  1425. return launchSkill(skill, param);
  1426. }
  1427. /// <summary>
  1428. /// 释放随机技能,一般用于AI
  1429. /// </summary>
  1430. /// <param name="expectTarget"></param>
  1431. /// <param name="param"></param>
  1432. /// <returns></returns>
  1433. public virtual StateSkill launchRandomSkill(SkillTemplate.CastTarget expectTarget, LaunchSkillParam param)
  1434. {
  1435. StateSkill current = CurrentState as StateSkill;
  1436. if (current != null && !current.IsCancelableBySkill)
  1437. {
  1438. return null;
  1439. }
  1440. int rand = RandomN.Next(0, mAllSkills.Count);
  1441. for (int si = mAllSkills.Count - 1; si >= 0; --si)
  1442. {
  1443. SkillTemplate st = mAllSkills[CMath.cycNum(rand, si, mAllSkills.Count)];
  1444. if (st.ExpectTarget == expectTarget)
  1445. {
  1446. SkillState sst = mSkillStatus.Get(st.GetID());
  1447. if (sst.LaunchSkill.AutoLaunch && sst.TryLaunch())
  1448. {
  1449. StateSkill state = launchSkill(sst, param);
  1450. if (state != null)
  1451. {
  1452. return state;
  1453. }
  1454. }
  1455. }
  1456. }
  1457. return null;
  1458. }
  1459. public virtual StateSkill launchRandomSkillForAll(LaunchSkillParam param)
  1460. {
  1461. StateSkill current = CurrentState as StateSkill;
  1462. if (current != null && !current.IsCancelableBySkill)
  1463. {
  1464. return null;
  1465. }
  1466. int rand = RandomN.Next(0, mAllSkills.Count);
  1467. for (int si = mAllSkills.Count - 1; si >= 0; --si)
  1468. {
  1469. SkillTemplate st = mAllSkills[CMath.cycNum(rand, si, mAllSkills.Count)];
  1470. SkillState sst = mSkillStatus.Get(st.GetID());
  1471. if (sst.LaunchSkill.AutoLaunch && sst.TryLaunch())
  1472. {
  1473. StateSkill state = launchSkill(sst, param);
  1474. if (state != null)
  1475. {
  1476. return state;
  1477. }
  1478. }
  1479. }
  1480. return null;
  1481. }
  1482. /// <summary>
  1483. /// 尝试取消当前技能,打出连击
  1484. /// </summary>
  1485. /// <param name="target"></param>
  1486. /// <param name="autoFocusNearTarget"></param>
  1487. /// <returns></returns>
  1488. public virtual bool tryLaunchRandomSkillAndCancelCurrentSkill(InstanceUnit target, bool autoFocusNearTarget = false)
  1489. {
  1490. StateSkill current = CurrentState as StateSkill;
  1491. if (current != null && !current.IsChanting && current.IsCancelableBySkill)
  1492. {
  1493. LaunchSkillParam param = new LaunchSkillParam(target.ID, null, autoFocusNearTarget);
  1494. //优先多段攻击//
  1495. if (current.SkillData.IsSingleAction)
  1496. {
  1497. if (IsTargetInSkillRange(current.SkillData, target))
  1498. {
  1499. StateSkill st = launchSkill(current.SkillData.ID, param);
  1500. if (st != null)
  1501. {
  1502. return true;
  1503. }
  1504. }
  1505. }
  1506. //随机其他技能//
  1507. int rand = RandomN.Next(0, mAllSkills.Count);
  1508. for (int si = mAllSkills.Count - 1; si >= 0; --si)
  1509. {
  1510. SkillTemplate st = mAllSkills[CMath.cycNum(rand, si, mAllSkills.Count)];
  1511. if (Parent.IsAttackable(this, target, st.ExpectTarget, AttackReason.Attack, st))
  1512. {
  1513. SkillState sst = mSkillStatus.Get(st.GetID());
  1514. if (sst.LaunchSkill.AutoLaunch && IsTargetInSkillRange(st, target))
  1515. {
  1516. StateSkill state = launchSkill(sst, param);
  1517. if (state != null)
  1518. {
  1519. return true;
  1520. }
  1521. }
  1522. }
  1523. }
  1524. }
  1525. return false;
  1526. }
  1527. /// <summary>
  1528. /// 尝试在范围内找到目标释放技能,并进入StateFollowAndAttack,自己走过去打。
  1529. /// </summary>
  1530. /// <param name="range"></param>
  1531. /// <param name="skill_auto_launchable"></param>
  1532. /// <returns></returns>
  1533. public virtual bool tryFollowAndLaunchRandomSkillToTargetInRange(float range, bool skill_auto_launchable = false)
  1534. {
  1535. if (!IsNoneSkill)
  1536. {
  1537. SkillState[] skills = mSkillStatus.SkillsArray;
  1538. CUtils.RandomArray(RandomN, skills);
  1539. using (var list = ListObjectPool<InstanceUnit>.AllocAutoRelease())
  1540. {
  1541. //随机找个目标施法//
  1542. Parent.getObjectsRoundRange<InstanceUnit>(Collider.Object_Pos_IncludeInRound, X, Y, Info.GuardRange, list , this.AoiStatus);
  1543. DoAndRemoveCollection.UpdateAndRemove<InstanceUnit>(list, (InstanceUnit u) =>
  1544. {
  1545. return !u.IsActive;
  1546. });
  1547. if (list.Count == 0) { return false; }
  1548. CUtils.RandomList(Parent.RandomN, list);
  1549. foreach (SkillState skill in skills)
  1550. {
  1551. if ((!skill_auto_launchable || skill.LaunchSkill.AutoLaunch) && skill.TryLaunch())
  1552. {
  1553. for (int i = 0; i < list.Count; i++)
  1554. {
  1555. InstanceUnit u = list[i];
  1556. if (Parent.IsAttackable(this, u, skill.Data.ExpectTarget, AttackReason.Attack, skill.Data))
  1557. {
  1558. //检测是否有可释放技能//
  1559. changeState(new StateFollowAndAttack(this, u, skill.Data.ExpectTarget));
  1560. return true;
  1561. }
  1562. }
  1563. }
  1564. }
  1565. }
  1566. }
  1567. return false;
  1568. }
  1569. #endregion
  1570. //-----------------------------------------------------------------------------------------------------------------
  1571. internal void deadDropItems(int force)
  1572. {
  1573. foreach (KeyValuePair<ItemTemplate, DropItem> e in mDropItems.Drop(Parent, Parent.RandomN))
  1574. {
  1575. float x;
  1576. float y;
  1577. CMath.RandomPosInRound(RandomN, X, Y, e.Value.DropPosRange, out x, out y);
  1578. Parent.AddItem(e.Key, e.Key.Name, x, y, CMath.RandomAngle(RandomN), force, e.Key.Name, this);
  1579. }
  1580. }
  1581. protected bool tryPickObject(InstanceUnit unit)
  1582. {
  1583. if (!Parent.IsVisibleAOI(this, unit))
  1584. {
  1585. return false;
  1586. }
  1587. bool ret = true;
  1588. if (mOnTryPickUnit != null)
  1589. {
  1590. foreach (TryPickUnitHandler trypick in mOnTryPickUnit.GetInvocationList())
  1591. {
  1592. if (!trypick.Invoke(this, unit))
  1593. {
  1594. ret = false;
  1595. }
  1596. }
  1597. }
  1598. return ret;
  1599. }
  1600. public void PickUnit(InstanceUnit pickable)
  1601. {
  1602. if (tryPickObject(pickable))
  1603. {
  1604. Parent.cb_unitPickUnitCallBack(this, pickable);
  1605. if (mOnPickUnit != null)
  1606. {
  1607. mOnPickUnit.Invoke(this, pickable);
  1608. }
  1609. }
  1610. }
  1611. public CommonAI.Data.SceneType GetSceneType()
  1612. {
  1613. return mZone.SceneType;
  1614. }
  1615. //-----------------------------------------------------------------------------------------------------//
  1616. #region Environment
  1617. //-----------------------------------------------------------------------------------------------------//
  1618. private HashMap<string, EnvironmentVar> EnvironmentVarMap = new HashMap<string, EnvironmentVar>();
  1619. public void SetEnvironmentVar(string key, object value, bool syncToClient = false)
  1620. {
  1621. if (!string.IsNullOrEmpty(key))
  1622. {
  1623. EnvironmentVar var = EnvironmentVarMap.Get(key);
  1624. if (var != null)
  1625. {
  1626. if (EnvironmentVar.ALWAYS_SYNC_ENVIRONMENT_VAR || (var.SyncToClient && var.Value != value))
  1627. {
  1628. queueEvent(new PlayerSyncEnvironmentVarEvent(ID, key, value));
  1629. }
  1630. var.Value = value;
  1631. }
  1632. else
  1633. {
  1634. var = new EnvironmentVar(key, syncToClient, value);
  1635. EnvironmentVarMap.Add(key, var);
  1636. if (EnvironmentVar.ALWAYS_SYNC_ENVIRONMENT_VAR || var.SyncToClient)
  1637. {
  1638. queueEvent(new PlayerSyncEnvironmentVarEvent(ID, key, value));
  1639. }
  1640. }
  1641. }
  1642. }
  1643. public T GetEnvironmentVarAs<T>(string key)
  1644. {
  1645. if (!string.IsNullOrEmpty(key))
  1646. {
  1647. EnvironmentVar var = EnvironmentVarMap.Get(key);
  1648. if (var != null)
  1649. {
  1650. try
  1651. {
  1652. return (T)var.Value;
  1653. }
  1654. catch (Exception err)
  1655. {
  1656. log.Warn("GetEnvironmentVarAs : " + key + ", catch: " + err);
  1657. }
  1658. }
  1659. }
  1660. return default(T);
  1661. }
  1662. public int ListEnvironmentVars(List<EnvironmentVar> list)
  1663. {
  1664. list.AddRange(EnvironmentVarMap.Values);
  1665. return EnvironmentVarMap.Count;
  1666. }
  1667. public List<EnvironmentVar> ListEnvironmentVars()
  1668. {
  1669. return new List<EnvironmentVar>(EnvironmentVarMap.Values);
  1670. }
  1671. public ClientStruct.ZoneEnvironmentVar[] GetCurrentUnitVars()
  1672. {
  1673. ClientStruct.ZoneEnvironmentVar[] ret = new ClientStruct.ZoneEnvironmentVar[EnvironmentVarMap.Count];
  1674. int i = 0;
  1675. try
  1676. {
  1677. foreach (EnvironmentVar var in EnvironmentVarMap.Values)
  1678. {
  1679. ret[i].Key = var.Key;
  1680. ret[i].Value = var.Value;
  1681. ret[i].SyncToClient = var.SyncToClient;
  1682. i++;
  1683. }
  1684. }
  1685. catch(Exception e)
  1686. {
  1687. log.Warn("GetCurrentUnitVars catch: " + ret.Length + ", " + EnvironmentVarMap.Count + ", " + i + ", e: " + e);
  1688. }
  1689. return ret;
  1690. }
  1691. #endregion
  1692. //-----------------------------------------------------------------------------------------------------//
  1693. //-----------------------------------------------------------------------------------------------------//
  1694. #region SceneEvents
  1695. //-----------------------------------------------------------------------------------------------------//
  1696. private HashMap<int, UnitEventTriggerCollection> mBindEvents = new HashMap<int, UnitEventTriggerCollection>();
  1697. public void BindUnitEvent(int unit_event_id)
  1698. {
  1699. if (!mBindEvents.ContainsKey(unit_event_id))
  1700. {
  1701. UnitEventTemplate uet = Templates.getUnitEvent(unit_event_id);
  1702. if (uet != null)
  1703. {
  1704. uet = uet.Clone() as UnitEventTemplate;
  1705. UnitEventTriggerCollection bind_event = new UnitEventTriggerCollection(this);
  1706. bind_event.Bind(uet.Events);
  1707. mBindEvents.Add(unit_event_id, bind_event);
  1708. }
  1709. }
  1710. }
  1711. protected virtual void clearBindEvents()
  1712. {
  1713. foreach (var evt in mBindEvents.Values)
  1714. {
  1715. evt.Dispose();
  1716. }
  1717. mBindEvents.Clear();
  1718. }
  1719. /** 计算并获得伤害 */
  1720. public virtual void PetShareDamage(int baseDmgValue, InstanceUnit sender)
  1721. {
  1722. }
  1723. #endregion
  1724. //-----------------------------------------------------------------------------------------------------//
  1725. //-----------------------------------------------------------------------------------------------------//
  1726. }
  1727. }