InstanceUnit.cs 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896
  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.AddHP(-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. #endregion
  1720. //-----------------------------------------------------------------------------------------------------//
  1721. //-----------------------------------------------------------------------------------------------------//
  1722. }
  1723. }