XmdsVirtual.cs 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489
  1. using CommonAI.Zone;
  2. using CommonAI.Zone.Helper;
  3. using CommonAI.Zone.Instance;
  4. using CommonAI.Zone.Formula;
  5. using CommonLang;
  6. using CommonLang.Log;
  7. using System.Collections.Generic;
  8. using XmdsCommon.Message;
  9. using XmdsCommon.Plugin;
  10. using XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills;
  11. using CommonAI.Zone.ZoneEditor;
  12. using System.Diagnostics;
  13. using XmdsCommonServer.Plugin.Units;
  14. using XmdsCommonServer.Plugin.XmdsSkillTemplate.DamageCalculator;
  15. using XmdsCommonServer.XLS.Data;
  16. using System;
  17. using XmdsCommonServer.Plugin.Scene;
  18. using CommonLang.Vector;
  19. using CommonLang.Concurrent;
  20. using CommonAI.Data;
  21. using static CommonAI.Zone.Instance.InstanceUnit;
  22. using CommonAI.data;
  23. using XmdsCommonServer.Plugin.Base;
  24. using XmdsCommonSkill.Plugin.CardSkill;
  25. using CommonAI.ZoneServer.JSGModule;
  26. using XmdsCommonServer.Plugin.JSGXmdsModule;
  27. namespace XmdsCommonServer.Plugin
  28. {
  29. /// <summary>
  30. /// FileName: XmdsVirtualUnit.cs
  31. /// </summary>
  32. public partial class XmdsVirtual : XmdsCommon.Plugin.VirtualUnitBase
  33. {
  34. private static AtomicInteger s_alloc_object_count = new AtomicInteger(0);
  35. /// <summary>
  36. /// 分配实例数量
  37. /// </summary>
  38. public static int AllocCount { get { return s_alloc_object_count.Value; } }
  39. #region Log.
  40. public static Logger log = LoggerFactory.GetLogger("XVirtual");
  41. public static void FormatLog(string txt, params object[] args)
  42. {
  43. //if (args != null) { log.Debug(string.Format(txt, args)); }
  44. //else { log.Debug(txt); }
  45. }
  46. public static void FormatLog(uint level, string txt, params object[] args)
  47. {
  48. if (args != null)
  49. {
  50. switch (level)
  51. {
  52. case LoggerLevel.ERROR:
  53. log.Error(string.Format(txt, args));
  54. break;
  55. case LoggerLevel.WARNNING:
  56. log.Warn(string.Format(txt, args));
  57. break;
  58. case LoggerLevel.INFO:
  59. log.Info(string.Format(txt, args));
  60. break;
  61. default:
  62. //log.Debug(string.Format(txt, args));
  63. break;
  64. }
  65. }
  66. else
  67. {
  68. switch (level)
  69. {
  70. case LoggerLevel.ERROR:
  71. log.Error(txt);
  72. break;
  73. case LoggerLevel.WARNNING:
  74. log.Warn(txt);
  75. break;
  76. case LoggerLevel.INFO:
  77. log.Info(txt);
  78. break;
  79. default:
  80. //log.Debug(txt);
  81. break;
  82. }
  83. }
  84. }
  85. #endregion
  86. #region 战斗状态恢复配置.
  87. //血量恢复时间和系数,目前战中和非战中恢复速度一致.
  88. //HP回复频率.
  89. public static readonly int Coefficient_HPRebornTime = 5000;
  90. //战斗中HP回复系数.
  91. public static readonly float Coefficient_CombatHPReborn = 1f;
  92. #endregion
  93. readonly public UnitInfo mInfo;
  94. readonly public InstanceUnit mUnit;
  95. readonly public XmdsUnitProperties mProp;
  96. readonly public XmdsHateSystem mHateSystem;
  97. //是否完成初始化技能.
  98. protected bool mFinishSkillInit = false;
  99. public XmdsUnitProp MirrorProp;
  100. //脱战计时器.
  101. private TimeExpire<int> mOutOfCombatTime = null;
  102. //血量回复计时器.
  103. private TimeInterval<int> mHPRebornTimer = null;
  104. //定力值回复计时器.
  105. private TimeInterval<int> mMPRebornTimer = null;
  106. //出生点坐标.
  107. protected float mBirthPosX;
  108. protected float mBirthPosY;
  109. //坐骑状态.
  110. private bool mIsMounted = false;
  111. //是否在战斗状态.
  112. private BattleStatus mInCombatState = BattleStatus.None;
  113. //游戏服场景配置.
  114. public XmdsServerSceneData ServerSceneData = null;
  115. //隐身时队友是否可见.
  116. protected bool mTeamMemberVisible = true;
  117. public virtual bool TeamMemberVisible { get { return mTeamMemberVisible; } set { mTeamMemberVisible = value; } }
  118. //是否无敌.
  119. public bool IsInvincible { get; set; }
  120. //虚无状态无视技能.
  121. public bool NothingnessIgnoreSkill { get; set; }
  122. //虚无状态无视Buff效果.
  123. public bool NothingnessIgnoreBuff { get; set; }
  124. //虚无状态无视所有效果.
  125. public bool NothingnessIgnoreAll { get; set; }
  126. //恢复MP状态,不可打断
  127. public int mRecoverMPLeftTimes;
  128. //PVP触发的玩家id
  129. public string mPvpTriggerPlayerId;
  130. //战斗状态变更通知.
  131. public delegate void OnCombatChangeEvent(BattleStatus status);
  132. public event OnCombatChangeEvent OnHandleCombatChangeEvent
  133. {
  134. add { event_OnHandleCombatChangeEvent += value; }
  135. remove { event_OnHandleCombatChangeEvent -= value; }
  136. }
  137. protected event OnCombatChangeEvent event_OnHandleCombatChangeEvent;
  138. #region 属性变更.
  139. //操作指令申请计数.
  140. private int mPropChangeOperationCount = 0;
  141. //操作指令合集.
  142. private HashMap<int, PropChangeOperation> mPropChangeMap = new HashMap<int, PropChangeOperation>();
  143. protected PlayerBattlePropChangeEventB2C mBattlePropChangeEvt = null;
  144. private int mVirtualInventorySize = 0;
  145. #endregion
  146. #region 战斗状态变更原因.
  147. public const byte COMBATSTATE_CHANGE_REASON_DORESET = 1;
  148. #endregion
  149. public XmdsVirtual(InstanceUnit unit)
  150. {
  151. s_alloc_object_count++;
  152. mUnit = unit;
  153. mInfo = unit.Info;
  154. mProp = unit.Info.Properties as XmdsUnitProperties;
  155. mHateSystem = new XmdsHateSystem(this);
  156. }
  157. ~XmdsVirtual() { s_alloc_object_count--; }
  158. public void OnInit(InstanceUnit unit, bool pointLv)
  159. {
  160. UnitInfo info = unit.Info;
  161. FormatLog("- 初始化单位 : {0} - {0} ", unit.ID, unit.Name);
  162. Stopwatch sw = Stopwatch.StartNew();
  163. try
  164. {
  165. //出生点坐标.
  166. mBirthPosX = mUnit.X;
  167. mBirthPosY = mUnit.Y;
  168. //背包格子数.
  169. mVirtualInventorySize = mProp.ServerData.Prop.CurInventorySize;
  170. //非玩家,速度配置0
  171. if (mInfo.UType != UnitInfo.UnitType.TYPE_PLAYER && mProp.ServerData.Prop.MoveSpeed == 0)
  172. {
  173. mProp.ServerData.Prop.MoveSpeed = mInfo.MoveSpeedSEC;
  174. }
  175. //当前场景类型.
  176. InitSceneInfo();
  177. //子类初始化.
  178. Init(pointLv);
  179. //基础信息初始化.
  180. InitBaseData(mProp.ServerData.Prop);
  181. //坐骑信息记录.
  182. CheckMountStatus(mProp.ServerData.AvatarList);
  183. if (this.mCardModule == null)
  184. {
  185. this.CreateCreateCardModule();
  186. }
  187. //初始化技能信息.
  188. InitSkillInfo(mProp.ServerData);
  189. //脱战计时器初始化.
  190. InitOutOfCombatTime();
  191. //初始化HP恢复计时器.
  192. InitRebornTimer();
  193. //(最后执行)同步给客户度信息.
  194. SyncClientData();
  195. //施放技能监听.
  196. mUnit.OnLaunchSkill += OnLaunchSkillHandler;
  197. //技能新增监听.
  198. mUnit.OnSkillAdded += OnSkillAddHandler;
  199. //技能移除监听.
  200. mUnit.OnSkillRemoved += OnSkillRemoveHandler;
  201. //技能变更监听.
  202. mUnit.OnStateChanged += OnStateChangedHandler;
  203. //物品时候时触发.
  204. mUnit.OnUseItem += MUnit_OnUseItem;
  205. mUnit.OnSkillHitTarget += OnSkillHitTargetHandler;
  206. }
  207. catch(Exception e)
  208. {
  209. log.Error("单位初始化异常:" + unit.Info.ID + ", " + e);
  210. }
  211. finally
  212. {
  213. sw.Stop();
  214. if (sw.ElapsedMilliseconds > 10)
  215. {
  216. FormatLog("XmdsVirtual create overload , stopwatch time {0} > 10ms", sw.ElapsedMilliseconds);
  217. }
  218. }
  219. }
  220. private void MUnit_OnUseItem(InstanceUnit obj, ItemTemplate item, InstanceUnit item_creater)
  221. {
  222. BattleFunction battleFuntion = BattleFunction.GetInstance();
  223. if (item != null && battleFuntion != null)
  224. {
  225. int id = (item.Properties as XmdsItemProperties).TriggerFunctionID;
  226. if (id != 0)
  227. {
  228. battleFuntion.TriggrBattleFunction(id, this, this);
  229. }
  230. }
  231. }
  232. public void OnDispose(InstanceUnit owner)
  233. {
  234. if(this.mUnit != null)
  235. {
  236. //施放技能监听.
  237. mUnit.OnLaunchSkill -= OnLaunchSkillHandler;
  238. //技能新增监听.
  239. mUnit.OnSkillAdded -= OnSkillAddHandler;
  240. //技能移除监听.
  241. mUnit.OnSkillRemoved -= OnSkillRemoveHandler;
  242. //技能变更监听.
  243. mUnit.OnStateChanged -= OnStateChangedHandler;
  244. //物品时候时触发.
  245. mUnit.OnUseItem -= MUnit_OnUseItem;
  246. mUnit.OnSkillHitTarget -= OnSkillHitTargetHandler;
  247. }
  248. Dispose();
  249. }
  250. /// <summary>
  251. /// 供子类重铸.
  252. /// </summary>
  253. protected virtual void Init(bool pointLv) { }
  254. public bool IsFinishSkillInit()
  255. {
  256. return mFinishSkillInit;
  257. }
  258. #region 常用API.
  259. protected virtual void SyncClientData()
  260. {
  261. //推属性变更计算.
  262. UnitPropRefresh();
  263. //第一次将全部属性推给客户端.
  264. SyncBattlePropsFields(PlayerBattlePropChangeEventB2C.MASK_ALL);
  265. }
  266. public int GetUnitLv()
  267. {
  268. if (this.mProp.ServerData.BaseInfo.UnitLv == 0)
  269. {
  270. return 1;
  271. }
  272. return this.mProp.ServerData.BaseInfo.UnitLv;
  273. }
  274. public int GetStateLv()
  275. {
  276. return this.mProp.ServerData.BaseInfo.StateLv;
  277. }
  278. // 神器id
  279. public int GetArtifactIndex()
  280. {
  281. return ((XmdsUnitProp)mProp.ServerData.Prop).ArtifactIndex;
  282. }
  283. //获得神器克制id
  284. public bool IsArtifactRestrain(UnitFateType fateType)
  285. {
  286. return ((int)fateType-1) == (((XmdsUnitProp)mProp.ServerData.Prop).ArtifactIndex + 1) % 5;
  287. }
  288. //是否有神器
  289. public bool IsHasArtifact()
  290. {
  291. return ((XmdsUnitProp)mProp.ServerData.Prop).ArtifactIndex != (int)ArtifactType.None;
  292. }
  293. //神器背饰id
  294. public int GetArtifactDefenceIndex()
  295. {
  296. return ((XmdsUnitProp)mProp.ServerData.Prop).ArtifactDefenceIndex;
  297. }
  298. protected void InitBaseInfo(XmdsUnitBaseInfo baseInfo)
  299. {
  300. //同步等级信息.
  301. mProp.ServerData.BaseInfo = baseInfo;
  302. this.mUnit.Level = mProp.ServerData.BaseInfo.UnitLv;
  303. }
  304. public HateSystem GetHateSystem()
  305. {
  306. return mHateSystem;
  307. }
  308. /// <summary>
  309. /// 获得攻击目标.
  310. /// </summary>
  311. /// <returns></returns>
  312. public virtual InstanceUnit GetAtkTarget(InstanceUnit target)
  313. {
  314. var unit_prop = target.Virtual as XmdsVirtual;
  315. return DispatchGetAtkUnitEvent(unit_prop).mUnit;
  316. }
  317. /// <summary>
  318. /// 物品触发单位加血效果.
  319. /// </summary>
  320. /// <param name="hp"></param>
  321. public int AddHPByItem(int hp)
  322. {
  323. int v = hp;
  324. this.mUnit.ReduceHP(-v, null, null, false, null);
  325. return v;
  326. }
  327. /// <summary>
  328. /// 女武神能量变更.
  329. /// </summary>
  330. /// <param name="value"></param>
  331. public void AddEnergyByItem(int value)
  332. {
  333. }
  334. /// <summary>
  335. /// 通知单位接收跳字事件.
  336. /// </summary>
  337. /// <param name="objID"></param>
  338. /// <param name="value"></param>
  339. public void SendHPChangeMessage(uint objID, int value)
  340. {
  341. BattleHintNumberB2C evt = new BattleHintNumberB2C();
  342. evt.Value = -value;
  343. evt.State = (byte)UnitHitEventState.Normal;
  344. evt.TargetObjID = this.mUnit.ID;
  345. this.mUnit.queueEvent(evt);
  346. }
  347. /// <summary>
  348. /// 通知单位接收能量变更跳字事件.
  349. /// </summary>
  350. /// <param name="objID"></param>
  351. /// <param name="value"></param>
  352. public void SendMPChangeMessage(uint objID, int value)
  353. {
  354. BattleHintNumberB2C evt = new BattleHintNumberB2C();
  355. evt.Value = -value;
  356. evt.State = (byte)UnitHitEventState.MP;
  357. evt.TargetObjID = this.mUnit.ID;
  358. this.mUnit.queueEvent(evt);
  359. }
  360. public void SendBattleHintNumberB2C(int Value, UnitHitEventState type, uint targetId = 0)
  361. {
  362. BattleHintNumberB2C evt = new BattleHintNumberB2C();
  363. evt.Value = Value;
  364. evt.State = (byte)type;
  365. evt.TargetObjID = targetId == 0 ? this.mUnit.ID : targetId;
  366. this.mUnit.queueEvent(evt);
  367. }
  368. /// <summary>
  369. /// 加血.
  370. /// </summary>
  371. /// <param name="hp">血量</param>
  372. /// <param name="sender">加血者</param>
  373. /// <param name="sendMsg">是否发送协议</param>
  374. public void AddHP(int hp, InstanceUnit sender = null, bool sendMsg = true, DamageSource dmgSrc = DamageSource.Def)
  375. {
  376. this.mUnit.ReduceHP(-hp, sender, null, sendMsg, null, false, dmgSrc);
  377. }
  378. public void AddHP(int hp, InstanceUnit sender, DamageSource dmgSrc)
  379. {
  380. this.mUnit.ReduceHP(-hp, sender, null, true, null, false, dmgSrc);
  381. }
  382. /// <summary>
  383. /// 加能量.
  384. /// </summary>
  385. /// <param name="mp"></param>
  386. /// <param name="sendMsg">是否发送协议</param>
  387. public void AddMP(int mp, InstanceUnit sender, bool sendMsg = true, bool force = false, AttackSource source = null)
  388. {
  389. this.mUnit.AddMP(mp, sender, force, false, source);
  390. }
  391. public void AddMP(int mp, InstanceUnit sender, AttackSource source)
  392. {
  393. this.mUnit.AddMP(mp, sender, true, false, source);
  394. }
  395. public bool IsCanReduceMP(bool force)
  396. {
  397. return force || mRecoverMPLeftTimes <= 0;
  398. }
  399. /// <summary>
  400. /// 获得角色原始属性.
  401. /// </summary>
  402. /// <returns></returns>
  403. public XmdsUnitProp GetOriginProp()
  404. {
  405. return mProp.ServerData.Prop;
  406. }
  407. /// <summary>
  408. /// 判断一定概率是否触发概率单位为万分比:填写1000表示百分之10.
  409. /// </summary>
  410. /// <param name="percent"></param>
  411. /// <returns></returns>
  412. public bool RandomPercent(int percent)
  413. {
  414. return XmdsDamageCalculator.IsInRandomRange(percent,
  415. this.mUnit.RandomN, (int)XmdsDamageCalculator.PERER);
  416. }
  417. protected virtual void Dispose()
  418. {
  419. DestorySkill();
  420. mOutOfCombatTime = null;
  421. mHPRebornTimer = null;
  422. mMPRebornTimer = null;
  423. OnHealEventHandle = null;
  424. event_OnCombatStateChangeHandle = null;
  425. event_OnHandleCombatChangeEvent = null;
  426. mBattlePropChangeEvt = null;
  427. // if(this.mCardModule != null)
  428. // {
  429. // this.mCardModule.Dispose();
  430. // }
  431. ClearRegistEvent();
  432. mHateSystem.Dispose();
  433. }
  434. /// <summary>
  435. /// 是否在异常状态内.
  436. /// </summary>
  437. /// <returns></returns>
  438. public bool IsInDebuffStatus()
  439. {
  440. bool ret = false;
  441. if (this.mUnit.IsStun || this.mUnit.IsSilent)
  442. {
  443. ret = true;
  444. }
  445. //取当前所有BUFF,判断如果有隐身BUFF立即解除该BUFF.
  446. using (var buffList = ListObjectPool<InstanceUnit.BuffState>.AllocAutoRelease())
  447. {
  448. this.mUnit.GetAllBuffStatus(buffList);
  449. if (buffList != null && buffList.Count > 0)
  450. {
  451. for (int i = 0; i < buffList.Count; i++)
  452. {
  453. if (XmdsInstanceUtils.IsControlBuff(buffList[i].Data))
  454. {
  455. return true;
  456. }
  457. }
  458. }
  459. }
  460. return ret;
  461. }
  462. //移除控制buff
  463. public void RemoveControlBuff()
  464. {
  465. //取当前所有BUFF,判断如果有隐身BUFF立即解除该BUFF.
  466. using (var buffList = ListObjectPool<InstanceUnit.BuffState>.AllocAutoRelease())
  467. {
  468. //InstanceUnit.BuffState bfs = null;
  469. //XmdsBuffProperties prop = null;
  470. //BuffTemplate bt = null;
  471. this.mUnit.GetAllBuffStatus(buffList);
  472. if (buffList == null || buffList.Count <= 0)
  473. {
  474. return;
  475. }
  476. for (int i = 0; i < buffList.Count; i++)
  477. {
  478. if (XmdsInstanceUtils.IsControlBuff(buffList[i].Data))
  479. {
  480. this.mUnit.removeBuff(buffList[i].Data.ID);
  481. }
  482. }
  483. }
  484. }
  485. protected bool IsBusy()
  486. {
  487. bool ret = false;
  488. if (this.mUnit.CurrentState != null &&
  489. (this.mUnit.CurrentState is InstanceUnit.StateSkill))// ||
  490. //(this.mUnit.CurrentState is InstanceUnit.StatePickObject))
  491. {
  492. ret = true;
  493. }
  494. return ret;
  495. }
  496. /// <summary>
  497. /// 向战斗服发送提示信息.
  498. /// </summary>
  499. /// <param name="msg"></param>
  500. public void SendMsgToClient(string msg)
  501. {
  502. if (msg != null)
  503. {
  504. ShowTipsEventB2C evt = new ShowTipsEventB2C();
  505. evt.Msg = msg;
  506. this.mUnit.queueEvent(evt);
  507. }
  508. }
  509. //单独给玩家发送消息,非广播
  510. public void SendMsgToPlayer(ObjectEvent evt, bool force = false)
  511. {
  512. this.mUnit.queueEvent(evt, force);
  513. }
  514. /// <summary>
  515. /// 获取当前可用背包格子数量.
  516. /// </summary>
  517. /// <returns></returns>
  518. public int GetInventorySize()
  519. {
  520. if (mProp != null)
  521. {
  522. return mProp.ServerData.Prop.CurInventorySize;
  523. }
  524. return 0;
  525. }
  526. public void SetInventorySize(int size)
  527. {
  528. if (mProp != null)
  529. {
  530. mProp.ServerData.Prop.CurInventorySize = size;
  531. VirtualInventorySize = size;
  532. }
  533. }
  534. public int VirtualInventorySize
  535. {
  536. get { return mVirtualInventorySize; }
  537. set { mVirtualInventorySize = value; }
  538. }
  539. /// <summary>
  540. /// 组队背包格子数.
  541. /// </summary>
  542. /// <returns></returns>
  543. public int GetTeamInventorySize()
  544. {
  545. if (mProp != null)
  546. {
  547. return mProp.ServerData.Prop.CurTeamInventorySize;
  548. }
  549. return 0;
  550. }
  551. public bool ContainBuff(bool isDebuff)
  552. {
  553. using (var buffList = ListObjectPool<InstanceUnit.BuffState>.AllocAutoRelease())
  554. {
  555. InstanceUnit.BuffState bfs = null;
  556. XmdsBuffProperties prop = null;
  557. BuffTemplate bt = null;
  558. this.mUnit.GetAllBuffStatus(buffList);
  559. if (buffList != null && buffList.Count > 0)
  560. {
  561. for (int i = 0; i < buffList.Count; i++)
  562. {
  563. bfs = buffList[i];
  564. bt = bfs.Data;
  565. prop = bt.Properties as XmdsBuffProperties;
  566. if (prop.Dispelled == false) { continue; }
  567. if (bt.IsHarmful == isDebuff)
  568. {
  569. return true;
  570. }
  571. }
  572. }
  573. }
  574. return false;
  575. }
  576. /// <summary>
  577. /// 记录同步可视数据.
  578. /// 战斗服数据大致分为两块,一部分用作战斗计算使用,另一部分用作同步客户端表现相关信息,
  579. /// 当表现信息变更时,需要将数据同步给syncInfo,底层每次调用时时直接拿syncInfo来推送.
  580. /// </summary>
  581. protected void SyncPlayerVisibleData()
  582. {
  583. if (this.mUnit.VisibleInfo is PlayerVisibleDataB2C)
  584. {
  585. PlayerVisibleDataB2C pvd = this.mUnit.VisibleInfo as PlayerVisibleDataB2C;
  586. pvd.AvatarList = this.mProp.ServerData.AvatarList;
  587. pvd.BaseInfo = this.mProp.ServerData.BaseInfo;
  588. pvd.UnitPKInfo = this.mProp.ServerData.UnitPKInfo;
  589. pvd.UnitSceneInfo = this.mProp.ServerData.UnitSceneInfo;
  590. }
  591. }
  592. /// <summary>
  593. /// 当前场景信息初始化记录.
  594. /// </summary>
  595. protected virtual void InitSceneInfo()
  596. {
  597. EditorScene es = mUnit.Parent as EditorScene;
  598. XmdsSceneProperties zp = es.Data.Properties as XmdsSceneProperties;
  599. ServerSceneData = zp.ServerSceneData;
  600. }
  601. protected bool CalPKValue(XmdsVirtual target)
  602. {
  603. //特殊规则,跨服场景,击杀非本服玩家.
  604. if (this.mUnit.GetSceneType() >= CommonAI.Data.SceneType.CROSS_SERVER_NEW)
  605. {
  606. XmdsVirtual_Player r = target.GetPlayerUnit();
  607. if (r != null && this.GetServerID() != r.GetServerID())
  608. {
  609. return false;
  610. }
  611. }
  612. return ServerSceneData.CalPKValue;
  613. }
  614. public virtual PKMode GetCurPKMode()
  615. {
  616. if (mProp.ServerData.UnitPKInfo != null)
  617. {
  618. return mProp.ServerData.UnitPKInfo.CurPKMode;
  619. }
  620. return PKMode.Peace;
  621. }
  622. /// <summary>
  623. /// 获得当前PK等级(判断是否为红名).
  624. /// </summary>
  625. /// <returns></returns>
  626. public virtual PKLevel GetCurPKLevel()
  627. {
  628. PKLevel ret = PKLevel.White;
  629. if (mProp != null && mProp.ServerData.UnitPKInfo != null)
  630. {
  631. ret = mProp.ServerData.UnitPKInfo.CurPKLevel;
  632. }
  633. return ret;
  634. }
  635. /// <summary>
  636. /// 服ID.
  637. /// </summary>
  638. /// <returns></returns>
  639. public virtual int GetServerID()
  640. {
  641. int ret = 0;
  642. if (this.mProp.ServerData != null && this.mProp.ServerData.BaseInfo != null)
  643. {
  644. ret = this.mProp.ServerData.BaseInfo.ServerID;
  645. }
  646. return ret;
  647. }
  648. /// <summary>
  649. /// 获得公会ID.
  650. /// </summary>
  651. /// <returns></returns>
  652. public virtual string GetGuildID()
  653. {
  654. string ret = null;
  655. if (this.mProp.ServerData != null && this.mProp.ServerData.BaseInfo != null)
  656. {
  657. ret = this.mProp.ServerData.BaseInfo.GuildID;
  658. }
  659. return ret;
  660. }
  661. /// <summary>
  662. /// 获得阵营ID
  663. /// </summary>
  664. /// <returns></returns>
  665. public virtual int GetForceID()
  666. {
  667. return this.mUnit.Force;
  668. }
  669. /// <summary>
  670. /// 获得单位ID(玩家返回UUID).
  671. /// </summary>
  672. /// <returns></returns>
  673. public virtual string GetPlayerUUID()
  674. {
  675. return mUnit.ID.ToString();
  676. }
  677. /// <summary>
  678. /// 重置功能,血量、buff、状态、技能全部变为初始状态.
  679. /// </summary>
  680. public void Reset()
  681. {
  682. //脱战.
  683. SetCombatState(BattleStatus.None, 1);
  684. //BUFF.
  685. this.mUnit.clearBuffs();
  686. //技能CD.
  687. this.mUnit.ClearAllSkillCD();
  688. //坐骑状态.
  689. this.TakeOffMount();
  690. //回血重置.
  691. if (mHPRebornTimer != null)
  692. {
  693. mHPRebornTimer.Reset();
  694. }
  695. if(mMPRebornTimer != null)
  696. {
  697. mMPRebornTimer.Reset();
  698. }
  699. this.mUnit.startRebirth();
  700. this.mUnit.CurrentHP = this.mUnit.MaxHP;
  701. this.mUnit.CurrentMP = this.mUnit.MaxMP;
  702. }
  703. /// <summary>
  704. /// 获取当前强度类型
  705. /// </summary>
  706. /// <returns></returns>
  707. public string GetCurSceneType()
  708. {
  709. return ServerSceneData.SceneHard;
  710. }
  711. /// <summary>
  712. /// 获取当前场景类型
  713. /// </summary>
  714. /// <returns></returns>
  715. public CommonAI.XmdsConstConfig.AreaType CurAreaType()
  716. {
  717. return ServerSceneData.CurAreaType;
  718. }
  719. protected virtual void OnHeal(XmdsVirtual attcker, int value, ref AtkResult result)
  720. {
  721. if (OnHealEventHandle != null)
  722. {
  723. OnHealEventHandle.Invoke(attcker, this, value, ref result);
  724. }
  725. }
  726. public void SendBattleFloatTipsEventB2C(BattleFloatTipsEventB2C evt)
  727. {
  728. if (evt != null)
  729. {
  730. this.mUnit.queueEvent(evt);
  731. }
  732. }
  733. public void SendBubbleTipsEventB2C(string msg)
  734. {
  735. if (!string.IsNullOrEmpty(msg))
  736. {
  737. var evt = new BubbleTipsEventB2C();
  738. evt.Msg = msg;
  739. this.mUnit.queueEvent(evt);
  740. }
  741. }
  742. /// <summary>
  743. /// 能否使用物品.
  744. /// </summary>
  745. /// <returns></returns>
  746. public bool CanUseItem()
  747. {
  748. bool ret = true;
  749. ret = (!this.mUnit.IsSilent);
  750. return ret;
  751. }
  752. /// <summary>
  753. /// 同步归属权信息.
  754. /// </summary>
  755. /// <param name="name"></param>
  756. /// <param name="protype"></param>
  757. public virtual void SyncHeirsInfo(string name, int hpPercent, CommonAI.Data.XmdsUnitPro protype)
  758. {
  759. }
  760. /// <summary>
  761. /// 是否可被攻击.
  762. /// </summary>
  763. public virtual bool IsAttackable(XmdsVirtual attacker)
  764. {
  765. return true;
  766. }
  767. public virtual int GetVirtualTemplateID()
  768. {
  769. return mInfo.TemplateID;
  770. }
  771. /// <summary>
  772. /// 治愈效果,满血、满蓝.
  773. /// </summary>
  774. public virtual void DoCure()
  775. {
  776. this.AddHP(this.mUnit.MaxHP, null, false);
  777. this.AddMP(this.mUnit.MaxMP, null, false, true);
  778. }
  779. public bool SkillAutoLaunchTest(InstanceUnit.SkillState ss)
  780. {
  781. bool ret = false;
  782. UnitSkill us = XmdsBattleSkill.GetUnitSkill(ss.Data.ID); ;
  783. if (us != null)
  784. {
  785. ret = us.SkillAutoLaunchTest(ss, this);
  786. }
  787. return ret;
  788. }
  789. #endregion
  790. #region 基础事件.
  791. /// <summary>
  792. /// 角色本身的初始化.
  793. /// </summary>
  794. /// <param name="unit"></param>
  795. private void Unit_OnActivated(InstanceUnit unit)
  796. {
  797. mUnit.OnActivated -= Unit_OnActivated;
  798. }
  799. //主动移除技能.
  800. public GameSkill RemoveSkill(int skillID)
  801. {
  802. GameSkill skillData = this.SkillHelper.GetGameSkill(skillID);
  803. if (skillData == null)
  804. {
  805. return null;
  806. }
  807. if (skillData.SkillType == XmdsSkillType.passive || skillData.SkillType == XmdsSkillType.petGivePassive)
  808. {
  809. this.SkillHelper.RemovePassiveSkill(skillID);
  810. return null;
  811. }
  812. else
  813. {
  814. SkillState skillState = this.mUnit.getSkillState(skillID);
  815. this.SkillHelper.RemoveActiveSkill(skillID);
  816. return skillData;
  817. }
  818. }
  819. #endregion
  820. #region 安全区域
  821. private bool mIsInSafeArea = false;
  822. /// <summary>
  823. /// 是否在安全区域
  824. /// </summary>
  825. public bool IsInSafeArea(){ return mIsInSafeArea; }
  826. //跟新战斗区域状态
  827. private void UpdateAreaState(int intervalMS)
  828. {
  829. //var sa = mUnit.Parent.GetArea(mUnit.X, mUnit.Y);
  830. var sa = mUnit.CurrentArea;
  831. if (sa != null && sa.CurrentMapNodeValue == XmdsMapBlock.BLOCK_VALUE_SAFE)
  832. {
  833. this.mIsInSafeArea = true;
  834. }
  835. else
  836. {
  837. this.mIsInSafeArea = false;
  838. }
  839. }
  840. public void OnPlayerKillMonster(InstanceUnit monster)
  841. {
  842. try
  843. {
  844. XmdsInstancePlayer player = this.mUnit as XmdsInstancePlayer;
  845. List<XmdsInstancePlayer> members = player.TeamVirtual == null ? null : player.TeamVirtual.GetTeamMembers();
  846. log.Info("--------OnPlayerKillMonster print start:" + mUnit.PlayerUUID + ", 场景ID" + mUnit.Parent.GetSceneID() + ", 怪ID:"
  847. + monster.Info.ID + ", 队伍人数:" + (members == null ? -1 : members.Count));
  848. if(members == null)
  849. {
  850. JSGXmdsHackerModule.OnPlayerKillMonster(player, monster);
  851. }
  852. else
  853. {
  854. //foreach(XmdsInstancePlayer member in members)
  855. {
  856. JSGXmdsHackerModule.OnPlayerKillMonster(player, monster);
  857. }
  858. }
  859. }
  860. catch (Exception e)
  861. {
  862. log.Warn("XMDSS OnPlayerKillMonster catch:", e);
  863. }
  864. }
  865. #endregion
  866. #region 战斗状态.
  867. /// <summary>
  868. /// 是否在战斗状态.
  869. /// </summary>
  870. public BattleStatus CombatState
  871. {
  872. get { return mInCombatState; }
  873. }
  874. public virtual void SetCombatState(BattleStatus value, byte reason = 0, String pvpTriggerPlayerId = "")
  875. {
  876. // 只有在空闲状态才允许设置技能展示状态
  877. if (value == BattleStatus.ReadyBattle && mInCombatState != BattleStatus.None)
  878. {
  879. return;
  880. }
  881. if (value != BattleStatus.None && mOutOfCombatTime != null)
  882. {
  883. mOutOfCombatTime.Reset();
  884. }
  885. if (mInCombatState != value)
  886. {
  887. if (value == BattleStatus.None)
  888. {
  889. if (JudgeChangeCombatStateChange(value, reason))
  890. {
  891. mInCombatState = value;
  892. CombatStateConnect(value, reason);
  893. OnCombatStateChange(mInCombatState);
  894. //单位脱战了
  895. this.mUnit.Parent.cb_unitOutBattleCallBack(this.mUnit);
  896. }
  897. }
  898. else if (value > mInCombatState)//战斗状态等级不同.
  899. {
  900. if (JudgeChangeCombatStateChange(value, reason))
  901. {
  902. mInCombatState = value;
  903. CombatStateConnect(value, reason);
  904. OnCombatStateChange(mInCombatState);
  905. }
  906. }
  907. }
  908. if(mInCombatState == BattleStatus.PVP)
  909. {
  910. this.mPvpTriggerPlayerId = pvpTriggerPlayerId;
  911. }
  912. }
  913. public bool IsInPVP()
  914. {
  915. return mInCombatState == BattleStatus.PVP ? true : false;
  916. }
  917. public bool IsInPVE()
  918. {
  919. return mInCombatState == BattleStatus.PVE ? true : false;
  920. }
  921. public BattleStatus GetBattleStatus()
  922. {
  923. return mInCombatState;
  924. }
  925. //坐骑状态变更.
  926. public bool IsMounted
  927. {
  928. set { mIsMounted = value; }
  929. get { return mIsMounted; }
  930. }
  931. private void CheckMountStatus(List<XmdsAvatarInfo> list)
  932. {
  933. if (list != null)
  934. {
  935. for (int i = 0; i < list.Count; i++)
  936. {
  937. if (list[i].PartTag == XmdsAvatarInfo.XmdsAvatar.Ride_Equipment)
  938. {
  939. if (!string.IsNullOrEmpty(list[i].FileName))
  940. {
  941. //有坐骑信息.
  942. IsMounted = true;
  943. break;
  944. }
  945. }
  946. }
  947. }
  948. }
  949. //状态改变时候触发.
  950. protected virtual void OnCombatStateChange(BattleStatus status)
  951. {
  952. //脱战时,清空仇恨列表.
  953. if (status == BattleStatus.None && this.mUnit.IsDead() == false)
  954. {
  955. mHateSystem.Clear();
  956. if (event_OnCombatStateChangeHandle != null)
  957. {
  958. event_OnCombatStateChangeHandle.Invoke(this, false);
  959. }
  960. FormatLog("{0}脱离战斗", mInfo.Name);
  961. }
  962. //状态变更时,需要同步告知客户端做响应表现.
  963. if (status != BattleStatus.None)
  964. {
  965. FormatLog("{0}进入战斗", mInfo.Name);
  966. }
  967. SyncUnitCombatState(status);
  968. if (event_OnHandleCombatChangeEvent != null)
  969. {
  970. event_OnHandleCombatChangeEvent.Invoke(status);
  971. }
  972. var scene = (mUnit.Parent as XmdsServerScene);
  973. scene.callback_OnCombatStateChange(this.mUnit, status);
  974. }
  975. protected virtual bool JudgeChangeCombatStateChange(BattleStatus status, byte reason)
  976. {
  977. bool ret = true;
  978. //默认为0,特殊情况不为0.
  979. if (reason != 0)
  980. {
  981. ret = true;
  982. }
  983. else
  984. {
  985. if (status == BattleStatus.None)
  986. {
  987. //表示单位一旦开始追击不会退出战斗状态.
  988. if (this.mUnit.Info.GuardRangeLimit == 0)
  989. {
  990. return false;
  991. }
  992. }
  993. }
  994. return ret;
  995. }
  996. protected virtual void ChangeCombatStateFromAtk(XmdsVirtual target)
  997. {
  998. var s = (this.IsPlayerUnit() && target.IsPlayerUnit()) ? BattleStatus.PVP : BattleStatus.PVE;
  999. SetCombatState(s, 0, target.mUnit.PlayerUUID);
  1000. }
  1001. protected virtual void CombatStateConnect(BattleStatus status, byte reason)
  1002. {
  1003. }
  1004. public virtual void OnHitOthter(XmdsVirtual target)
  1005. {
  1006. }
  1007. private void SyncUnitCombatState(BattleStatus status)
  1008. {
  1009. //改走通用字段.
  1010. //mUnit.queueEvent(new CombatStateChangeEvent(mUnit.ID, status));
  1011. //Dummy_0用来同步战斗状态.
  1012. mUnit.Dummy_0 = (byte)status;
  1013. }
  1014. //脱战计时器.
  1015. private void InitOutOfCombatTime()
  1016. {
  1017. if (mProp.IsUseCombatTimeCount == true)
  1018. {
  1019. if (this.mUnit.IsMonster)
  1020. {
  1021. mOutOfCombatTime = new TimeExpire<int>(XmdsConfig.Instance.OUTOF_BATTLE_MONSTER);
  1022. }
  1023. else
  1024. {
  1025. mOutOfCombatTime = new TimeExpire<int>(XmdsConfig.Instance.OUTOF_BATTLE_PLAYER);
  1026. }
  1027. }
  1028. }
  1029. //更新脱战计时.
  1030. private void UpdateOutOfCombatTime(int time)
  1031. {
  1032. if (mInCombatState != BattleStatus.None && mOutOfCombatTime != null && mOutOfCombatTime.Update(time))
  1033. {
  1034. SetCombatState(BattleStatus.None);
  1035. }
  1036. }
  1037. #endregion
  1038. #region 基础信息.
  1039. protected void InitBaseData(XmdsUnitProp data)
  1040. {
  1041. //复制原始单位数据.
  1042. MirrorProp = (XmdsUnitProp)data.Clone();
  1043. this.mUnit.SetMaxHP(data.MaxHP, true);
  1044. if (data.HP >= 0)
  1045. {
  1046. this.mUnit.CurrentHP = data.HP;
  1047. }
  1048. this.mUnit.MaxMP = data.ShieldValue;
  1049. this.mUnit.CurrentMP = data.ShieldValue;
  1050. SycSkillCdReduce();
  1051. SycControledTimeReduce();
  1052. SycMoveSpeed();
  1053. SycAttackSpeed();
  1054. }
  1055. public void SycMoveSpeed()
  1056. {
  1057. this.mUnit.SetMoveSpeed(this.MirrorProp.MoveSpeed);
  1058. }
  1059. private void SycAttackSpeed()
  1060. {
  1061. this.mUnit.SetAttackSpeed(this.MirrorProp.AttackSpeed);
  1062. }
  1063. private void SycMaxHP()
  1064. {
  1065. mUnit.SetMaxHP(this.MirrorProp.MaxHP, true);
  1066. }
  1067. private void SycSkillCdReduce()
  1068. {
  1069. mUnit.SetSkillCdReduce(this.MirrorProp.SkillCD);
  1070. }
  1071. private void SycControledTimeReduce()
  1072. {
  1073. mUnit.SetControledTimeReduce(this.MirrorProp.CtrlTimeReduce);
  1074. }
  1075. #endregion
  1076. #region 血量回复.
  1077. private void InitRebornTimer()
  1078. {
  1079. if (mHPRebornTimer == null)
  1080. {
  1081. mHPRebornTimer = new TimeInterval<int>(Coefficient_HPRebornTime);
  1082. mHPRebornTimer.FirstTimeEnable = false;
  1083. }
  1084. if(mMPRebornTimer == null)
  1085. {
  1086. mMPRebornTimer = new TimeInterval< int > (GlobalData.SHIELD_RECOVER_INTERVAL);
  1087. mMPRebornTimer.FirstTimeEnable = false;
  1088. }
  1089. }
  1090. private void UpdateHPReborn(int intervalMS)
  1091. {
  1092. try
  1093. {
  1094. if (MirrorProp.HPReborn > 0 && this.mUnit.CurrentHP < this.mUnit.MaxHP && mHPRebornTimer != null && !this.mUnit.IsDead())
  1095. {
  1096. if (mHPRebornTimer.Update(intervalMS))
  1097. {
  1098. if (mInCombatState != BattleStatus.None)
  1099. {
  1100. int v = CUtils.CastInt(MirrorProp.MaxHPReborn * Coefficient_CombatHPReborn);
  1101. this.mUnit.AddHP(v, null);
  1102. }
  1103. else
  1104. {
  1105. this.mUnit.AddHP(MirrorProp.MaxHPReborn, null);
  1106. }
  1107. }
  1108. }
  1109. }
  1110. catch(Exception e)
  1111. {
  1112. log.Error("UpdateHPReborn catch : " + this.mUnit.Info.ID + ", IsActive: " + this.mUnit.IsActive +
  1113. ", " + (mMPRebornTimer == null ? "timer null" : "OK") + ", " + e);
  1114. }
  1115. }
  1116. private void UpdateMPReborn(int intervalMS)
  1117. {
  1118. try
  1119. {
  1120. if(this.mRecoverMPLeftTimes > 0 && mMPRebornTimer != null && mMPRebornTimer.Update(intervalMS))
  1121. {
  1122. int addMP = 0;
  1123. if(--this.mRecoverMPLeftTimes == 0)
  1124. {
  1125. addMP = this.mUnit.MaxMP - this.mUnit.CurrentMP;
  1126. }
  1127. else
  1128. {
  1129. addMP = this.mUnit.MaxMP / GlobalData.SHIELD_RECOVER_TIME;
  1130. }
  1131. this.AddMP(addMP, null);
  1132. }
  1133. }
  1134. catch (Exception e)
  1135. {
  1136. log.Error("UpdateMPReborn catch : " + this.mUnit.Info.ID + ", IsActive: " + this.mUnit.IsActive +
  1137. ", " + (mMPRebornTimer == null ? "timer null" : "OK") + ", " + e);
  1138. }
  1139. }
  1140. public void StartRecoverMP(bool reset = false)
  1141. {
  1142. if (reset)
  1143. {
  1144. this.mRecoverMPLeftTimes = 0;
  1145. }
  1146. else
  1147. {
  1148. this.mRecoverMPLeftTimes = GlobalData.SHIELD_RECOVER_TIME;
  1149. }
  1150. }
  1151. #endregion
  1152. #region Formula调用.
  1153. public void OnUnitRemoved() { }
  1154. public virtual int OnHit(XmdsVirtual attacker, AttackSource source)
  1155. {
  1156. AtkResult result = new AtkResult();
  1157. //无敌直接免疫打击效果.
  1158. if ((this.IsInvincible == true) && source.FromExpectTarget == SkillTemplate.CastTarget.Enemy)
  1159. {
  1160. attacker.OnHitOthter(this);
  1161. //无敌时仇恨减为1.
  1162. attacker.mHateSystem.SetHateInfo(this.mUnit.ID, 1);
  1163. //攻击者进度战斗状态.
  1164. attacker.ChangeCombatStateFromAtk(this);
  1165. mHateSystem.OnHitted(attacker, this, 0, ref result);
  1166. source.OutIsDamage = false;
  1167. source.OutClientState = (int)UnitHitEventState.Immunity;
  1168. return 0;
  1169. }
  1170. #region 特殊状态判断.
  1171. if (this.NothingnessIgnoreBuff)
  1172. {
  1173. if (source.FromBuffState != null)
  1174. {
  1175. return 0;
  1176. }
  1177. }
  1178. if (this.NothingnessIgnoreSkill)
  1179. {
  1180. if (source.FromSkillState != null || source.FromSpellUnit != null)
  1181. {
  1182. return 0;
  1183. }
  1184. }
  1185. if (this.NothingnessIgnoreAll)
  1186. {
  1187. return 0;
  1188. }
  1189. #endregion
  1190. int damage = this.On_hit_unit_vs_unit(attacker, this, source, ref result);
  1191. if (damage < 0)
  1192. {
  1193. OnHeal(attacker, -damage, ref result);
  1194. //加血.
  1195. if (attacker.CombatState != BattleStatus.None) { SetCombatState(attacker.CombatState); }
  1196. }
  1197. else if(this.mUnit.ID != attacker.mUnit.ID)//自己对自己作用的不算
  1198. {
  1199. if (damage == 0 && source.OutClientState != (int)UnitHitEventState.Dodge)//增益、负面效果.
  1200. {
  1201. if (source.FromExpectTarget == SkillTemplate.CastTarget.Enemy)//负面效果.
  1202. {
  1203. attacker.OnHitOthter(this);
  1204. //攻击者进度战斗状态.
  1205. attacker.ChangeCombatStateFromAtk(this);
  1206. mHateSystem.OnHitted(attacker, this, damage, ref result);
  1207. var v = (this.IsPlayerUnit() && attacker.IsPlayerUnit()) ? BattleStatus.PVP : BattleStatus.PVE;
  1208. //单位被攻击,且从PVE状态转为PVP状态,
  1209. if (v == BattleStatus.PVP && CombatState != BattleStatus.PVP)
  1210. {
  1211. UnderAttackCheck(attacker);
  1212. }
  1213. SetCombatState(v, 0, attacker.mUnit.PlayerUUID);
  1214. //坐骑状态下检查受击影响.
  1215. MountOnHitCheck(attacker);
  1216. //判断异常状态(击倒击飞).
  1217. {
  1218. MountOnHit(source);
  1219. }
  1220. }
  1221. else //增益效果.
  1222. {
  1223. if (this != attacker)
  1224. {
  1225. //施术者或受攻击者双方互相影响.
  1226. if (this.CombatState != BattleStatus.None)
  1227. {
  1228. attacker.SetCombatState(this.CombatState);
  1229. }
  1230. if (attacker.CombatState != BattleStatus.None)
  1231. {
  1232. SetCombatState(attacker.CombatState);
  1233. }
  1234. }
  1235. }
  1236. }
  1237. else
  1238. {
  1239. attacker.OnHitOthter(this);
  1240. //致命一击时候死亡状态不设置.
  1241. // if (this.mUnit.CurrentHP - damage > 0)
  1242. {
  1243. var s = (this.IsPlayerUnit() && attacker.IsPlayerUnit()) ? BattleStatus.PVP : BattleStatus.PVE;
  1244. //单位被攻击,且从PVE状态转为PVP状态,
  1245. if (s == BattleStatus.PVP && CombatState != BattleStatus.PVP)
  1246. {
  1247. UnderAttackCheck(attacker);
  1248. }
  1249. SetCombatState(s, 0, attacker.mUnit.PlayerUUID);
  1250. }
  1251. //攻击者进度战斗状态.
  1252. attacker.ChangeCombatStateFromAtk(this);
  1253. //仇恨值计算.
  1254. attacker.DispatchCalThreatValueEvent(this, source, ref result);
  1255. mHateSystem.OnHitted(attacker, this, damage, ref result);
  1256. //坐骑状态下检查受击影响.
  1257. MountOnHitCheck(attacker);
  1258. //判断异常状态(击倒击飞).
  1259. {
  1260. MountOnHit(source);
  1261. }
  1262. //扣除定力
  1263. if (this.mUnit.MaxMP > 0 && result.breakShieldValue > 0)
  1264. {
  1265. this.AddMP(-result.breakShieldValue, attacker.mUnit, source);
  1266. }
  1267. }
  1268. }
  1269. //if (damage == 0)
  1270. //{
  1271. // source.OutIsDamage = false;
  1272. //}
  1273. return damage;
  1274. }
  1275. public virtual void OnUnitDead(XmdsVirtual killer)
  1276. {
  1277. //坐骑状态设置为false.
  1278. TakeOffMount();
  1279. //脱战.
  1280. SetCombatState(BattleStatus.None, 1);
  1281. if (mHateSystem != null)
  1282. {
  1283. mHateSystem.Clear();
  1284. }
  1285. }
  1286. public virtual void OnKillUnit(XmdsVirtual dead)
  1287. {
  1288. }
  1289. /// <summary>
  1290. /// 是否属于玩家.
  1291. /// </summary>
  1292. /// <returns></returns>
  1293. public virtual bool IsPlayerUnit()
  1294. {
  1295. return false;
  1296. }
  1297. /// <summary>
  1298. /// 获取对应玩家单位.
  1299. /// </summary>
  1300. /// <returns></returns>
  1301. public virtual XmdsVirtual_Player GetPlayerUnit()
  1302. {
  1303. return null;
  1304. }
  1305. public void OnHandleNetMessage(ObjectAction action)
  1306. {
  1307. }
  1308. public void OnTriggerStart(InstanceUnit.TriggerState trigger, XmdsVirtual target)
  1309. {
  1310. }
  1311. public virtual void OnUpdateTriggerSkill(int intervalMS, bool slowRefresh)
  1312. {
  1313. // 区域刷新 //
  1314. UpdateAreaState(intervalMS);
  1315. //同步战斗属性协议.
  1316. UpdateBattlePropsChangeEvt();
  1317. //慢刷新,不必要每一帧都刷新
  1318. if (slowRefresh)
  1319. {
  1320. int slowInterval = intervalMS * GlobalData.ZONE_UPDATE_SLOW;
  1321. //计算是否脱战.
  1322. UpdateOutOfCombatTime(slowInterval);
  1323. //HP回复.
  1324. UpdateHPReborn(slowInterval);
  1325. UpdateMPReborn(slowInterval);
  1326. //仇恨系统刷新.
  1327. UpdateHateSystem(slowInterval);
  1328. }
  1329. //技能刷新.
  1330. UpdateSkillHelper(intervalMS, slowRefresh);
  1331. // if (this.mCardModule != null)
  1332. // {
  1333. // this.mCardModule.Update(intervalMS, slowRefresh);
  1334. // }
  1335. }
  1336. public void OnBuffBegin(InstanceUnit.BuffState state, XmdsVirtual sender)
  1337. {
  1338. BuffTemplate template = state.Data;
  1339. XmdsBuffProperties prop = template.Properties as XmdsBuffProperties;
  1340. List<XmdsBuffVirtual> list = null;
  1341. if (state.Tag != null)
  1342. {
  1343. list = state.Tag as List<XmdsBuffVirtual>;
  1344. }
  1345. //异常BUFF对坐骑状态有影响.
  1346. MountOnBuffBegin(template);
  1347. if (list != null)
  1348. {
  1349. for (int i = 0; i < list.Count; i++)
  1350. {
  1351. UnitBuff ub = list[i] as UnitBuff;
  1352. ub.BuffBegin(this, sender, state);
  1353. }
  1354. }
  1355. DispatchBuffEvent(state, BuffEventType.Begin, null);
  1356. }
  1357. public void OnBuffUpdate(InstanceUnit.BuffState state, int time)
  1358. {
  1359. BuffTemplate template = state.Data;
  1360. List<XmdsBuffVirtual> list = null;
  1361. if (state.Tag != null)
  1362. {
  1363. list = state.Tag as List<XmdsBuffVirtual>;
  1364. }
  1365. if (list != null && list.Count != 0)
  1366. {
  1367. int count = 0;
  1368. for (int i = 0; i < list.Count; i++)
  1369. {
  1370. UnitBuff ub = list[i] as UnitBuff;
  1371. ub.BuffUpdate(this, state);
  1372. if (ub.IsInvaild())
  1373. {
  1374. count++;
  1375. }
  1376. }
  1377. if (count == list.Count)//当前BUFF所有能力都已失效,主动移出该BUFF.
  1378. {
  1379. this.mUnit.removeBuff(template.ID);
  1380. }
  1381. }
  1382. }
  1383. public void OnBuffEnd(InstanceUnit.BuffState state, string result, bool replace)
  1384. {
  1385. BuffTemplate template = state.Data;
  1386. XmdsBuffProperties prop = template.Properties as XmdsBuffProperties;
  1387. List<XmdsBuffVirtual> list = null;
  1388. if (state.Tag != null)
  1389. {
  1390. list = state.Tag as List<XmdsBuffVirtual>;
  1391. }
  1392. if (list != null)
  1393. {
  1394. for (int i = 0; i < list.Count; i++)
  1395. {
  1396. UnitBuff ub = list[i] as UnitBuff;
  1397. ub.BuffEnd(this, state, replace);
  1398. }
  1399. }
  1400. DispatchBuffEvent(state, BuffEventType.End, result);
  1401. }
  1402. #endregion
  1403. #region 属性能力重算.
  1404. /// <summary>
  1405. /// 刷新属性.
  1406. /// </summary>
  1407. protected void UnitPropRefresh(XmdsUnitProp prop = null)
  1408. {
  1409. if (prop == null)
  1410. {
  1411. XmdsUnitProp zup = GetOriginProp();
  1412. this.MirrorProp = zup.Clone() as XmdsUnitProp;
  1413. }
  1414. else
  1415. {
  1416. this.MirrorProp = prop;
  1417. }
  1418. foreach (KeyValuePair<int, PropChangeOperation> kvp in mPropChangeMap)
  1419. {
  1420. ChangeProp(kvp.Value);
  1421. }
  1422. int srcHP = this.MirrorProp.MaxHP;
  1423. // 更新虚拟属性,只影响数值,不计入显示和战力计算(也不在面板上显示)
  1424. if(this.mProp.ServerData.PropExt != null && this.mUnit.IsPlayer)
  1425. {
  1426. this.MirrorProp.AddTo(this.mProp.ServerData.PropExt);
  1427. }
  1428. SycMaxHP();
  1429. SycSkillCdReduce();
  1430. SycControledTimeReduce();
  1431. SycMoveSpeed();
  1432. SycAttackSpeed();
  1433. //隐藏属性导致玩家血量变了,同步最大血量ext
  1434. if(this.MirrorProp.MaxHP != srcHP)
  1435. {
  1436. SyncBattlePropsFields(UnitAttributeType.SetMaxHP);
  1437. }
  1438. }
  1439. private void ChangeProp(PropChangeOperation opt)
  1440. {
  1441. XmdsUnitProp zup = GetOriginProp();
  1442. switch (opt.Type)
  1443. {
  1444. case UnitAttributeType.Defence:
  1445. if (opt.OpType == PropChangeOperation.OperateType.Percent)
  1446. {
  1447. this.MirrorProp.DefencePer += opt.Value;
  1448. }
  1449. else
  1450. {
  1451. this.MirrorProp.BaseDefence += opt.Value;
  1452. }
  1453. //攻击异常日志
  1454. JSGXmdsHackerModule.PrintAttrErrorInfo(this, opt.Type, this.MirrorProp.Defence, this.GetOriginProp().Defence);
  1455. break;
  1456. case UnitAttributeType.CritRate:
  1457. this.MirrorProp.CritRate += opt.Value;
  1458. break;
  1459. case UnitAttributeType.MaxHP:
  1460. if (opt.OpType == PropChangeOperation.OperateType.Percent)
  1461. {
  1462. this.MirrorProp.HPPer += opt.Value;
  1463. }
  1464. else
  1465. {
  1466. this.MirrorProp.BaseMaxHP += opt.Value;
  1467. }
  1468. mUnit.SetMaxHP(this.MirrorProp.MaxHP, true);
  1469. //攻击异常日志
  1470. JSGXmdsHackerModule.PrintAttrErrorInfo(this, opt.Type, this.MirrorProp.MaxHP, this.GetOriginProp().MaxHP);
  1471. break;
  1472. case UnitAttributeType.Attack:
  1473. if (opt.OpType == PropChangeOperation.OperateType.Percent)
  1474. {
  1475. this.MirrorProp.AttackPer += opt.Value;
  1476. }
  1477. else
  1478. {
  1479. this.MirrorProp.BaseAttack += opt.Value;
  1480. }
  1481. //攻击异常日志
  1482. if (this.MirrorProp.MaxAttack > this.GetOriginProp().MaxAttack * 3)
  1483. {
  1484. JSGXmdsHackerModule.PrintAttrErrorInfo(this, opt.Type, this.MirrorProp.MaxAttack, this.GetOriginProp().MaxAttack);
  1485. }
  1486. break;
  1487. case UnitAttributeType.HealedEffect:
  1488. this.MirrorProp.HealedEffect += opt.Value;
  1489. break;
  1490. case UnitAttributeType.HealEffect:
  1491. this.MirrorProp.HealEffect += opt.Value;
  1492. break;
  1493. case UnitAttributeType.PlayerDamageReduce:
  1494. this.MirrorProp.PlayerDamageReduce += opt.Value;
  1495. // 免伤异常日志
  1496. JSGXmdsHackerModule.PrintAttrErrorInfo(this, opt.Type, this.MirrorProp.PlayerDamageReduce, opt.Value);
  1497. break;
  1498. case UnitAttributeType.MoveSpeed:
  1499. this.MirrorProp.MoveSpeed += GetOpValueFloat(zup.MoveSpeed, opt.Value, opt.OpType);
  1500. this.MirrorProp.VelocityAddition += opt.Value;
  1501. break;
  1502. case UnitAttributeType.PickupRange:
  1503. this.MirrorProp.pickupRange += GetOpValue(zup.pickupRange, opt.Value, opt.OpType);
  1504. break;
  1505. case UnitAttributeType.AttackSpeed:
  1506. this.MirrorProp.AttackSpeed += GetOpValue(zup.AttackSpeed, opt.Value, opt.OpType);
  1507. break;
  1508. case UnitAttributeType.SkillLanuchSpeed:
  1509. this.MirrorProp.SkillCD += GetOpValue(zup.SkillCD, opt.Value, opt.OpType);
  1510. break;
  1511. case UnitAttributeType.ControlTimeReduce:
  1512. this.MirrorProp.CtrlTimeReduce += opt.Value;
  1513. break;
  1514. case UnitAttributeType.SkillDamage:
  1515. this.MirrorProp.SkillDamageAdd += opt.Value;
  1516. break;
  1517. case UnitAttributeType.IngoreDefence:
  1518. if (opt.OpType == PropChangeOperation.OperateType.Percent)
  1519. {
  1520. this.MirrorProp.IgnoreDefensePer += opt.Value;
  1521. }
  1522. else
  1523. {
  1524. this.MirrorProp.BaseIgnoreDefense += opt.Value;
  1525. }
  1526. break;
  1527. case UnitAttributeType.SkillLeech:
  1528. this.MirrorProp.ActiveAtkLeech += opt.Value;
  1529. break;
  1530. case UnitAttributeType.CritDamage:
  1531. this.MirrorProp.CritDamage += opt.Value;
  1532. break;
  1533. case UnitAttributeType.PlayerDamageAdd:
  1534. this.MirrorProp.PlayerDamageAdd += opt.Value;
  1535. // 伤害增加异常日志
  1536. JSGXmdsHackerModule.PrintAttrErrorInfo(this, opt.Type, this.MirrorProp.PlayerDamageAdd, opt.Value);
  1537. break;
  1538. case UnitAttributeType.MonsterDamageAdd:
  1539. this.MirrorProp.monsterDamageAdd += opt.Value;
  1540. break;
  1541. case UnitAttributeType.MonsterDamageReduce:
  1542. this.MirrorProp.monsterDamageReduce += opt.Value;
  1543. break;
  1544. case UnitAttributeType.AllDmgAdd:
  1545. this.MirrorProp.AllDmgAdd += opt.Value;
  1546. // 伤害增加异常日志
  1547. JSGXmdsHackerModule.PrintAttrErrorInfo(this, opt.Type, this.MirrorProp.AllDmgAdd, opt.Value);
  1548. break;
  1549. case UnitAttributeType.AllDmgReduce:
  1550. this.MirrorProp.AllDmgReduce += opt.Value;
  1551. // 伤害增加异常日志
  1552. JSGXmdsHackerModule.PrintAttrErrorInfo(this, opt.Type, this.MirrorProp.AllDmgReduce, opt.Value);
  1553. break;
  1554. case UnitAttributeType.SetMaxHP:
  1555. this.MirrorProp.BaseMaxHP = opt.Value;
  1556. break;
  1557. case UnitAttributeType.CritRate_NormalAtk:
  1558. this.MirrorProp.NormalAtkCriteRate += opt.Value;
  1559. break;
  1560. case UnitAttributeType.HPRecover:
  1561. if (opt.OpType == PropChangeOperation.OperateType.Percent)
  1562. {
  1563. this.MirrorProp.HPRecoverPer += opt.Value;
  1564. }
  1565. else
  1566. {
  1567. this.MirrorProp.HPReborn += opt.Value;
  1568. }
  1569. break;
  1570. case UnitAttributeType.EAttack_Gold:
  1571. this.MirrorProp.ArtifactAttack[(int)ArtifactType.Gold] += opt.Value;
  1572. break;
  1573. case UnitAttributeType.EAttack_Wood:
  1574. this.MirrorProp.ArtifactAttack[(int)ArtifactType.Wood] += opt.Value;
  1575. break;
  1576. case UnitAttributeType.EAttack_Water:
  1577. this.MirrorProp.ArtifactAttack[(int)ArtifactType.Water] += opt.Value;
  1578. break;
  1579. case UnitAttributeType.EAttack_Fire:
  1580. this.MirrorProp.ArtifactAttack[(int)ArtifactType.Fire] += opt.Value;
  1581. break;
  1582. case UnitAttributeType.EAttack_Soil:
  1583. this.MirrorProp.ArtifactAttack[(int)ArtifactType.Soil] += opt.Value;
  1584. break;
  1585. case UnitAttributeType.EDefence_Gold:
  1586. this.MirrorProp.ArtifactDefense[(int)ArtifactType.Gold] += opt.Value;
  1587. break;
  1588. case UnitAttributeType.EDefence_Wood:
  1589. this.MirrorProp.ArtifactDefense[(int)ArtifactType.Wood] += opt.Value;
  1590. break;
  1591. case UnitAttributeType.EDefence_Water:
  1592. this.MirrorProp.ArtifactDefense[(int)ArtifactType.Water] += opt.Value;
  1593. break;
  1594. case UnitAttributeType.EDefence_Fire:
  1595. this.MirrorProp.ArtifactDefense[(int)ArtifactType.Fire] += opt.Value;
  1596. break;
  1597. case UnitAttributeType.EDefence_Soil:
  1598. this.MirrorProp.ArtifactDefense[(int)ArtifactType.Soil] += opt.Value;
  1599. break;
  1600. case UnitAttributeType.ToBoss_CriteRate:
  1601. this.MirrorProp.ToBossCritRate += opt.Value;
  1602. break;
  1603. case UnitAttributeType.ToBoss_CriteDamage:
  1604. this.MirrorProp.ToBossCritDamage += opt.Value;
  1605. break;
  1606. case UnitAttributeType.MonsterRestraint_1:
  1607. this.MirrorProp.MonsterRestraint[(int)UnitFateType.One - 1] += opt.Value;
  1608. break;
  1609. case UnitAttributeType.MonsterRestraint_2:
  1610. this.MirrorProp.MonsterRestraint[(int)UnitFateType.Two - 1] += opt.Value;
  1611. break;
  1612. case UnitAttributeType.MonsterRestraint_3:
  1613. this.MirrorProp.MonsterRestraint[(int)UnitFateType.Three - 1] += opt.Value;
  1614. break;
  1615. case UnitAttributeType.MonsterRestraint_4:
  1616. this.MirrorProp.MonsterRestraint[(int)UnitFateType.Four - 1] += opt.Value;
  1617. break;
  1618. case UnitAttributeType.MonsterRestraint_5:
  1619. this.MirrorProp.MonsterRestraint[(int)UnitFateType.Five - 1] += opt.Value;
  1620. break;
  1621. default:
  1622. break;
  1623. }
  1624. }
  1625. private int GetOpValue(float UnitProp, float changeValue, PropChangeOperation.OperateType type)
  1626. {
  1627. float ret = 0;
  1628. if (type == PropChangeOperation.OperateType.Percent)
  1629. {
  1630. ret = UnitProp * (changeValue / XmdsDamageCalculator.PERER);
  1631. }
  1632. else
  1633. {
  1634. ret = changeValue;
  1635. }
  1636. return CUtils.CastInt(ret);
  1637. }
  1638. private float GetOpValueFloat(float UnitProp, float changeValue, PropChangeOperation.OperateType type)
  1639. {
  1640. float ret = 0;
  1641. if (type == PropChangeOperation.OperateType.Percent)
  1642. {
  1643. ret = UnitProp * (changeValue / XmdsDamageCalculator.PERER);
  1644. }
  1645. else
  1646. {
  1647. ret = changeValue;
  1648. }
  1649. return ret;
  1650. }
  1651. public PropChangeOperation CreatePropChangeOpertation(UnitBuff buff)
  1652. {
  1653. return new PropChangeOperation(buff == null ? 0 : buff.GetBindBuffID());
  1654. }
  1655. /** 被动改变数值 */
  1656. public void ChangeMaxHP(int addValues)
  1657. {
  1658. mProp.ServerData.Prop.BaseMaxHP += addValues;
  1659. mUnit.SetMaxHP(this.MirrorProp.MaxHP, true);
  1660. }
  1661. /** 被动改变攻击,除非死亡,否则不清除属性 */
  1662. public void ChangeAttack(int addValues)
  1663. {
  1664. mProp.ServerData.Prop.BaseAttack += addValues;
  1665. UnitPropRefresh();
  1666. }
  1667. /** 被动改变防御,除非死亡,否则不清除属性 */
  1668. public void ChangeDefence(int addValues)
  1669. {
  1670. mProp.ServerData.Prop.BaseDefence += addValues;
  1671. UnitPropRefresh();
  1672. }
  1673. /** 被动改变攻速,除非死亡,否则不清除属性 */
  1674. public void ChangeAtkSpeed(int addValues)
  1675. {
  1676. mProp.ServerData.Prop.AttackSpeed += addValues;
  1677. UnitPropRefresh();
  1678. }
  1679. /** 被动改变暴击伤害,除非死亡,否则不清除属性 */
  1680. public void ChangeCriteDamage(int addValues)
  1681. {
  1682. mProp.ServerData.Prop.CritDamage += addValues;
  1683. UnitPropRefresh();
  1684. }
  1685. /** 被动改变暴击率,除非死亡,否则不清除属性 */
  1686. public void ChangeCriteRate(int addValues)
  1687. {
  1688. mProp.ServerData.Prop.CritRate += addValues;
  1689. UnitPropRefresh();
  1690. }
  1691. /// <summary>
  1692. /// 插入一条属性变更操作指令,返回id用来删除.
  1693. /// </summary>
  1694. /// <returns></returns>
  1695. public int AddPropChangeOperation(PropChangeOperation opt)
  1696. {
  1697. int ret = 0;
  1698. mPropChangeOperationCount++;
  1699. ret = mPropChangeOperationCount;
  1700. mPropChangeMap.Add(ret, opt);
  1701. //立刻生效计算.
  1702. UnitPropRefresh();
  1703. SyncBattlePropsFields(opt.Type);
  1704. return ret;
  1705. }
  1706. public bool UpdatePropChangeOperation(int OpID, PropChangeOperation opt)
  1707. {
  1708. if (mPropChangeMap.ContainsKey(OpID))
  1709. {
  1710. mPropChangeMap[OpID] = opt;
  1711. //立刻生效计算.
  1712. UnitPropRefresh();
  1713. SyncBattlePropsFields(opt.Type);
  1714. return true;
  1715. }
  1716. return false;
  1717. }
  1718. /// <summary>
  1719. ///删除属性变更操作指令.
  1720. /// </summary>
  1721. public void RemovePropChangeOperation(int id)
  1722. {
  1723. PropChangeOperation opt;
  1724. if (mPropChangeMap != null && mPropChangeMap.TryGetValue(id, out opt))
  1725. {
  1726. mPropChangeMap.Remove(id);
  1727. SyncBattlePropsFields(opt.Type);
  1728. UnitPropRefresh();
  1729. }
  1730. else
  1731. {
  1732. FormatLog("RemovePropChangeOperation Error");
  1733. }
  1734. }
  1735. public HashMap<int, PropChangeOperation> GetChangePropMap()
  1736. {
  1737. return this.mPropChangeMap;
  1738. }
  1739. /// <summary>
  1740. /// 操作指令.
  1741. /// </summary>
  1742. public class PropChangeOperation
  1743. {
  1744. /// <summary>
  1745. /// 操作属性.
  1746. /// </summary>
  1747. public UnitAttributeType Type;
  1748. /// <summary>
  1749. /// 操作值.
  1750. /// </summary>
  1751. public int Value;
  1752. /// <summary>
  1753. /// 操作类型.
  1754. /// </summary>
  1755. public OperateType OpType;
  1756. //唯一标识key
  1757. private int mBindBuffID;
  1758. /// <summary>
  1759. /// 操作类型:值加减,百分比,
  1760. /// </summary>
  1761. public enum OperateType : byte
  1762. {
  1763. Value,
  1764. Percent,
  1765. }
  1766. public PropChangeOperation(int buffID)
  1767. {
  1768. this.mBindBuffID = buffID;
  1769. }
  1770. public int GetBindBuffID()
  1771. {
  1772. return this.mBindBuffID;
  1773. }
  1774. public override string ToString()
  1775. {
  1776. return "[" + this.mBindBuffID + ", " + this.Type + ", " + this.Value + ", " + this.OpType + "]";
  1777. }
  1778. }
  1779. /// <summary>
  1780. /// 操作标识.
  1781. /// </summary>
  1782. public enum UnitAttributeType : Byte
  1783. {
  1784. None, //无.
  1785. MoveSpeed, //速度.
  1786. Defence, //防御.
  1787. Attack, //最大攻击
  1788. /**attention, 这里存在坑,之前增伤,减伤被改成玩家后,后来有需要所有的增伤,减伤,有新加了一个奇怪的东西。 容易混淆*/
  1789. PlayerDamageAdd, // 伤害加成(玩家之间)
  1790. PlayerDamageReduce, // 伤害减免(被改成玩家之间)
  1791. MonsterDamageAdd, // 怪物(妖兽)伤害增加
  1792. MonsterDamageReduce, // 怪物(妖兽)免伤
  1793. AllDmgReduce, // 所有伤害减免
  1794. AllDmgAdd, // 单位增伤,IncAllDamage改成玩家之间导致新增一个奇怪所有增伤属性
  1795. HealEffect, //治疗效果.
  1796. HealedEffect, //受治疗效果.
  1797. MaxHP, //生命上限.
  1798. CritRate, //暴击率
  1799. PickupRange, //拾取距离
  1800. AttackSpeed, //攻速, 普攻冷却缩减
  1801. SkillLanuchSpeed, //技能冷却缩减
  1802. ControlTimeReduce, //控制时间改变,韧性
  1803. SkillDamage, //技能伤害
  1804. IngoreDefence, //无视防御
  1805. SkillLeech, //技能吸血
  1806. CritDamage, //暴击伤害
  1807. SetMaxHP, //设置最大血量
  1808. CritRate_NormalAtk, //普攻暴击率(为实现技能效果加的)
  1809. HPRecover, //生命恢复效果
  1810. EAttack_Gold,
  1811. EAttack_Wood,
  1812. EAttack_Water,
  1813. EAttack_Fire,
  1814. EAttack_Soil,
  1815. EDefence_Gold,
  1816. EDefence_Wood,
  1817. EDefence_Water,
  1818. EDefence_Fire,
  1819. EDefence_Soil,
  1820. ToBoss_CriteRate,
  1821. ToBoss_CriteDamage,
  1822. MonsterRestraint_1, // 命格克制
  1823. MonsterRestraint_2,
  1824. MonsterRestraint_3,
  1825. MonsterRestraint_4,
  1826. MonsterRestraint_5,
  1827. }
  1828. // 数值上限
  1829. public class GamePropLimit
  1830. {
  1831. public const int AttackSpeed_Down = -5000; // 攻速下限
  1832. public const int AttackSpeed_Up = 25000; // 攻速上限
  1833. public const int MoveSpeed = 4000; // 移速
  1834. public const int SkillLaunchSpeed = 5000; // 冷却缩减
  1835. public const int DamageRemit = 5000; // 伤害减免
  1836. public const int CtrlTimeReduce = 5000; // 韧性
  1837. public const int SkillDamageAdd = 5000; // 技能伤害增幅
  1838. public const int HealthAddition = 5000; // 治疗增幅
  1839. public const int CtrlAddition = 5000; // 控制增幅
  1840. }
  1841. /// <summary>
  1842. /// 同步客户端.
  1843. /// </summary>
  1844. private void UpdateBattlePropsChangeEvt()
  1845. {
  1846. if (mBattlePropChangeEvt != null)
  1847. {
  1848. GenBattlePropsFields(mBattlePropChangeEvt);
  1849. SendBattlePropsChangeEvt(mBattlePropChangeEvt);
  1850. mBattlePropChangeEvt = null;
  1851. }
  1852. }
  1853. private ulong GetBattlePropFieldsMask(UnitAttributeType type)
  1854. {
  1855. ulong mask = 0;
  1856. switch (type)
  1857. {
  1858. case UnitAttributeType.MaxHP:
  1859. mask = PlayerBattlePropChangeEventB2C.MASK_MAX_HP;
  1860. break;
  1861. case UnitAttributeType.MoveSpeed:
  1862. mask = PlayerBattlePropChangeEventB2C.MASK_MOVE_SPEED | PlayerBattlePropChangeEventB2C.MASK_MOVE_SPEED_ADDITION;
  1863. break;
  1864. case UnitAttributeType.Attack:
  1865. mask = PlayerBattlePropChangeEventB2C.MASK_ATTACK;
  1866. break;
  1867. case UnitAttributeType.IngoreDefence:
  1868. mask = PlayerBattlePropChangeEventB2C.MASK_IGNORE_DEFENSE_PER;
  1869. break;
  1870. case UnitAttributeType.Defence:
  1871. mask = PlayerBattlePropChangeEventB2C.MASK_DEF;
  1872. break;
  1873. case UnitAttributeType.CritRate:
  1874. mask = PlayerBattlePropChangeEventB2C.MASK_CRIT_RATE;
  1875. break;
  1876. case UnitAttributeType.CritDamage:
  1877. mask = PlayerBattlePropChangeEventB2C.MASK_CRIT_DAMAGE;
  1878. break;
  1879. case UnitAttributeType.PlayerDamageReduce:
  1880. mask = PlayerBattlePropChangeEventB2C.MASK_ALL_DAMAGE_REDUCE;
  1881. break;
  1882. case UnitAttributeType.HealEffect:
  1883. mask = PlayerBattlePropChangeEventB2C.MASK_HEALEFFECT;
  1884. break;
  1885. case UnitAttributeType.HealedEffect:
  1886. mask = PlayerBattlePropChangeEventB2C.MASK_HEALEDEFFECT;
  1887. break;
  1888. case UnitAttributeType.AttackSpeed:
  1889. mask = PlayerBattlePropChangeEventB2C.MASK_ATTACK_SPEED;
  1890. break;
  1891. case UnitAttributeType.SkillLanuchSpeed:
  1892. mask = PlayerBattlePropChangeEventB2C.MASK_SKILL_CD;
  1893. break;
  1894. case UnitAttributeType.ControlTimeReduce:
  1895. mask = PlayerBattlePropChangeEventB2C.MASK_CTRLTIME_REDUCE;
  1896. break;
  1897. case UnitAttributeType.SkillDamage:
  1898. mask = PlayerBattlePropChangeEventB2C.MASK_SKILLDAMAGE;
  1899. break;
  1900. case UnitAttributeType.PlayerDamageAdd:
  1901. mask = PlayerBattlePropChangeEventB2C.MASK_INCALLDAMAGE;
  1902. break;
  1903. case UnitAttributeType.SetMaxHP:
  1904. mask = PlayerBattlePropChangeEventB2C.MASK_MAX_HP_EXT;
  1905. break;
  1906. case UnitAttributeType.SkillLeech:
  1907. mask = PlayerBattlePropChangeEventB2C.MASK_ACTIVE_ATK_LEECH;
  1908. break;
  1909. case UnitAttributeType.HPRecover:
  1910. mask = PlayerBattlePropChangeEventB2C.MASK_HP_REBORN;
  1911. break;
  1912. case UnitAttributeType.EAttack_Gold:
  1913. mask = PlayerBattlePropChangeEventB2C.MASK_GOLD_ATTACK;
  1914. break;
  1915. case UnitAttributeType.EAttack_Wood:
  1916. mask = PlayerBattlePropChangeEventB2C.MASK_WOOD_ATTACK;
  1917. break;
  1918. case UnitAttributeType.EAttack_Water:
  1919. mask = PlayerBattlePropChangeEventB2C.MASK_WATER_ATTACK;
  1920. break;
  1921. case UnitAttributeType.EAttack_Fire:
  1922. mask = PlayerBattlePropChangeEventB2C.MASK_FIRE_ATTACK;
  1923. break;
  1924. case UnitAttributeType.EAttack_Soil:
  1925. mask = PlayerBattlePropChangeEventB2C.MASK_SOIL_ATTACK;
  1926. break;
  1927. case UnitAttributeType.EDefence_Gold:
  1928. mask = PlayerBattlePropChangeEventB2C.MASK_GOLD_DEFENSE;
  1929. break;
  1930. case UnitAttributeType.EDefence_Wood:
  1931. mask = PlayerBattlePropChangeEventB2C.MASK_WOOD_DEFENSE;
  1932. break;
  1933. case UnitAttributeType.EDefence_Water:
  1934. mask = PlayerBattlePropChangeEventB2C.MASK_WATER_DEFENSE;
  1935. break;
  1936. case UnitAttributeType.EDefence_Fire:
  1937. mask = PlayerBattlePropChangeEventB2C.MASK_FIRE_DEFENSE;
  1938. break;
  1939. case UnitAttributeType.EDefence_Soil:
  1940. mask = PlayerBattlePropChangeEventB2C.MASK_SOIL_DEFENSE;
  1941. break;
  1942. case UnitAttributeType.ToBoss_CriteRate:
  1943. mask = PlayerBattlePropChangeEventB2C.MASK_TOBOSS_CRIT_RATE;
  1944. break;
  1945. case UnitAttributeType.ToBoss_CriteDamage:
  1946. mask = PlayerBattlePropChangeEventB2C.MASK_TOBOSS_CRIT_DAMAGE;
  1947. break;
  1948. case UnitAttributeType.MonsterRestraint_1:
  1949. mask = PlayerBattlePropChangeEventB2C.MASK_MONSTER_RESTRAINT_1;
  1950. break;
  1951. case UnitAttributeType.MonsterRestraint_2:
  1952. mask = PlayerBattlePropChangeEventB2C.MASK_MONSTER_RESTRAINT_2;
  1953. break;
  1954. case UnitAttributeType.MonsterRestraint_3:
  1955. mask = PlayerBattlePropChangeEventB2C.MASK_MONSTER_RESTRAINT_3;
  1956. break;
  1957. case UnitAttributeType.MonsterRestraint_4:
  1958. mask = PlayerBattlePropChangeEventB2C.MASK_MONSTER_RESTRAINT_4;
  1959. break;
  1960. case UnitAttributeType.MonsterRestraint_5:
  1961. mask = PlayerBattlePropChangeEventB2C.MASK_MONSTER_RESTRAINT_5;
  1962. break;
  1963. //case UnitAttributeType.
  1964. //mask = PlayerBattlePropChangeEventB2C.MASK_BREAK_SHIELD;
  1965. //break;
  1966. default:
  1967. break;
  1968. }
  1969. return mask;
  1970. }
  1971. private void SyncBattlePropsFields(UnitAttributeType type)
  1972. {
  1973. ulong mask = GetBattlePropFieldsMask(type);
  1974. SyncBattlePropsFields(mask);
  1975. }
  1976. public virtual void SyncBattlePropsFields(ulong mask)
  1977. {
  1978. //该功能实现转移至player.
  1979. //donothing.
  1980. }
  1981. private void GenBattlePropsFields(PlayerBattlePropChangeEventB2C evt)
  1982. {
  1983. XmdsUnitProp UseProp = this.MirrorProp; //this.GetOriginProp();
  1984. evt.MaxHP = UseProp.MaxHP;
  1985. evt.MoveSpeed = UseProp.MoveSpeed;
  1986. evt.HPReborn = UseProp.HPReborn;
  1987. //同步Attribute
  1988. evt.HPPer = UseProp.HPPer;
  1989. evt.Attack = UseProp.MaxAttack;
  1990. evt.AttackPer = UseProp.AttackPer;
  1991. evt.Def = UseProp.Defence;
  1992. evt.DefPer = UseProp.DefencePer;
  1993. evt.IgnoreDefensePer = UseProp.IgnoreDefensePer;
  1994. evt.CritRate = UseProp.CritRate;
  1995. evt.ResCritRate = UseProp.ResCritRate;
  1996. evt.CritDamage = UseProp.CritDamage;
  1997. evt.IncAllDamage = UseProp.PlayerDamageAdd;
  1998. evt.AllDamageReduce = UseProp.PlayerDamageReduce;
  1999. evt.CtrlTimeReduce = UseProp.CtrlTimeReduce;
  2000. evt.SkillCD = UseProp.SkillCD;
  2001. evt.HealEffect = UseProp.HealEffect;
  2002. evt.HealedEffect = UseProp.HealedEffect;
  2003. evt.SkillDamage = UseProp.SkillDamageAdd;
  2004. evt.AttackSpeed = UseProp.AttackSpeed;
  2005. evt.ControlUp = UseProp.ControlUp;
  2006. evt.GoldAttack = UseProp.ArtifactAttack[(int)ArtifactType.Gold];
  2007. evt.WoodAttack = UseProp.ArtifactAttack[(int)ArtifactType.Wood];
  2008. evt.WaterAttack = UseProp.ArtifactAttack[(int)ArtifactType.Water];
  2009. evt.FireAttack = UseProp.ArtifactAttack[(int)ArtifactType.Fire];
  2010. evt.SoilAttack = UseProp.ArtifactAttack[(int)ArtifactType.Soil];
  2011. evt.GoldDefense = UseProp.ArtifactDefense[(int)ArtifactType.Gold];
  2012. evt.WoodDefense = UseProp.ArtifactDefense[(int)ArtifactType.Wood];
  2013. evt.WaterDefense = UseProp.ArtifactDefense[(int)ArtifactType.Water];
  2014. evt.FireDefense = UseProp.ArtifactDefense[(int)ArtifactType.Fire];
  2015. evt.SoilDefense = UseProp.ArtifactDefense[(int)ArtifactType.Soil];
  2016. evt.ToBossCritRate = UseProp.ToBossCritRate;
  2017. evt.ToBossCritDamage = UseProp.ToBossCritDamage;
  2018. evt.GoldRestraint = UseProp.ArtifactRestraint[(int)ArtifactType.Gold];
  2019. evt.WoodRestraint = UseProp.ArtifactRestraint[(int)ArtifactType.Wood];
  2020. evt.WaterRestraint = UseProp.ArtifactRestraint[(int)ArtifactType.Water];
  2021. evt.FireRestraint = UseProp.ArtifactRestraint[(int)ArtifactType.Fire];
  2022. evt.SoilRestraint = UseProp.ArtifactRestraint[(int)ArtifactType.Soil];
  2023. evt.GoldResist = UseProp.ArtifactResist[(int)ArtifactType.Gold];
  2024. evt.WoodResist = UseProp.ArtifactResist[(int)ArtifactType.Wood];
  2025. evt.WaterResist = UseProp.ArtifactResist[(int)ArtifactType.Water];
  2026. evt.FireResist = UseProp.ArtifactResist[(int)ArtifactType.Fire];
  2027. evt.SoilResist = UseProp.ArtifactResist[(int)ArtifactType.Soil];
  2028. evt.PvpKillValue = UseProp.KillValuePer;
  2029. evt.YaoQiLevel = UseProp.YaoQiLevel;
  2030. evt.NormalAtkLeech = UseProp.NormalAtkLeech;
  2031. evt.ActiveAtkLeech = UseProp.ActiveAtkLeech;
  2032. evt.ArtifactMainPer = UseProp.ArtifactMainPer;
  2033. evt.FieldBossDamageAdd = UseProp.monsterDamageAdd;
  2034. evt.MaxHPExt = this.MirrorProp.MaxHP;
  2035. evt.DungeonMonsterDamageAdd = UseProp.monsterDamageReduce;
  2036. evt.MoveSpeedAddition = UseProp.VelocityAddition;
  2037. for(int i = 0; i < (int)UnitFateType.Five; i++)
  2038. {
  2039. evt.MonsterRestraint[i] = UseProp.MonsterRestraint[i];
  2040. }
  2041. //// 猎妖属性
  2042. evt.monsterAtk = UseProp.monsterAtk;
  2043. evt.monsterDef = UseProp.monsterDef;
  2044. evt.monsterAtkPer = UseProp.monsterAtkPer;
  2045. evt.monsterDefPer = UseProp.monsterDefPer;
  2046. }
  2047. private void UpdateHateSystem(int intervalMS)
  2048. {
  2049. if (mHateSystem != null)
  2050. {
  2051. //定期去除仇恨对象.
  2052. mHateSystem.Update(intervalMS);
  2053. }
  2054. }
  2055. private void SendBattlePropsChangeEvt(PlayerBattlePropChangeEventB2C evt)
  2056. {
  2057. this.mUnit.queueEvent(evt);
  2058. }
  2059. private void UnderAttackCheck(XmdsVirtual attacker)
  2060. {
  2061. //单位被攻击,且从PVE状态转为PVP状态,
  2062. if (this is XmdsVirtual_Player)
  2063. {
  2064. var atk = attacker.GetPlayerUnit();
  2065. if (atk != null)
  2066. {
  2067. UnderAttackNotifyB2C evt = new UnderAttackNotifyB2C();
  2068. evt.AttackerID = atk.mUnit.ID;
  2069. evt.AttackerInfo = atk.mProp.ServerData.BaseInfo;
  2070. this.mUnit.queueEvent(evt);
  2071. }
  2072. }
  2073. }
  2074. public bool IsAllies(CommonAI.Zone.Formula.IVirtualUnit target, bool includeSelf = true, bool onlyForTeam = false)
  2075. {
  2076. XmdsVirtual unit = target as XmdsVirtual;
  2077. if (unit == null)
  2078. {
  2079. return false;
  2080. }
  2081. return IsMember(unit, this.GetCurPKMode(), includeSelf, onlyForTeam);
  2082. }
  2083. public virtual int GetMaType() { return -1; }
  2084. public virtual bool IsLvRepress() { return false; }
  2085. public virtual bool IsBoss() { return false; }
  2086. public virtual void doEvent(JSGCustomOpType value) {}
  2087. public virtual uint GetMasterID() { return 0; }
  2088. public virtual InstanceUnit GetMasterUnit() { return null; }
  2089. public virtual InstanceUnit GetPetUnit()
  2090. {
  2091. return null;
  2092. }
  2093. /// <summary>
  2094. /// 下坐骑.
  2095. /// </summary>
  2096. public virtual void TakeOffMount()
  2097. {
  2098. if (mIsMounted == true)
  2099. {
  2100. SyncMountStatus(false);
  2101. }
  2102. }
  2103. public int GetHealedEffect()
  2104. {
  2105. return this.MirrorProp.HealedEffect;
  2106. }
  2107. public int GetHealEffect()
  2108. {
  2109. return this.MirrorProp.HealEffect;
  2110. }
  2111. /** 获得单位职业 */
  2112. public XmdsUnitPro GetUnitPro()
  2113. {
  2114. return this.mProp.ServerData.BaseInfo.ProType;
  2115. }
  2116. //性别: 0-男,1-女
  2117. public int GetUnitSex()
  2118. {
  2119. return this.mProp.ServerData.BaseInfo.sex;
  2120. }
  2121. /** 获得宠物天赋加成 */
  2122. public virtual int GetPetTalentAddition(UnitFateType type)
  2123. {
  2124. return ((XmdsUnitProp)mProp.ServerData.Prop).fateValue;
  2125. }
  2126. public UnitFateType GetUnitFateType()
  2127. {
  2128. return ((XmdsUnitProp)mProp.ServerData.Prop).fateType;
  2129. }
  2130. #endregion
  2131. }
  2132. }