ZoneServiceICE.cs 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724
  1. using CommonAI;
  2. using CommonAI.data;
  3. using CommonAI.Data;
  4. using CommonAI.Zone;
  5. using CommonAI.Zone.Helper;
  6. using CommonAI.Zone.Instance;
  7. using CommonAI.Zone.ZoneEditor;
  8. using CommonAI.ZoneServer.JSGModule;
  9. using CommonLang;
  10. using CommonLang.Log;
  11. using CommonLang.Property;
  12. using Pomelo;
  13. using System;
  14. using System.Collections;
  15. using System.Collections.Generic;
  16. using System.Data;
  17. using System.Threading;
  18. using System.Web.Helpers;
  19. using XmdsCommon.EditorData;
  20. using XmdsCommon.Message;
  21. using XmdsCommon.Plugin;
  22. using XmdsCommonServer.Message;
  23. using XmdsCommonServer.Plugin;
  24. using XmdsCommonServer.Plugin.Units;
  25. using XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills;
  26. using XmdsCommonSkill.Plugin;
  27. using XmdsCommonSkill.Plugin.FunctionEvent;
  28. using XmdsServerNode.Node;
  29. using XmdsServerNode.Node.Interface;
  30. using XmdsServerNode.Node.R2bNotify;
  31. using static CommonAI.Zone.Instance.InstanceUnit;
  32. using static JSGMountainKingModule;
  33. namespace XmdsServerEdgeJS.Zone
  34. {
  35. public class ZoneServiceICE : ZoneService
  36. {
  37. private static readonly short [] mXChange = { 0, 0, -1, 1 };
  38. private static readonly short [] mYChange = { 1, -1, 0, 0 };
  39. public static ZoneServiceICE InstanceICE { get; private set; }
  40. public ZoneServiceICE() { InstanceICE = this; }
  41. //----------------------------------------------------------------------------------------------
  42. #region _游戏服单向通知战斗服_
  43. /// <summary>
  44. /// 无差别通知战斗服
  45. /// </summary>
  46. /// <param name="instanceId"></param>
  47. /// <param name="name"></param>
  48. /// <param name="param"></param>
  49. /// <returns></returns>
  50. public void r2b_notify_notifyBattleServer(string instanceId, string name, dynamic param)
  51. {
  52. R2BNotifyMessage msg = R2bNotifyManager.GetR2bNotifyMessage(name);
  53. if (msg != null)
  54. {
  55. CommonAIServer.ServerUtils.DynamicToObject(param, msg);
  56. base.notifyBattleServer(instanceId, msg);
  57. }
  58. }
  59. /// <summary>
  60. /// 玩家基本信息同步
  61. /// </summary>
  62. /// <param name="instanceId"></param>
  63. /// <returns>副本实例id</returns>
  64. public void r2b_notify_refreshPlayerBasicData(string playerId, dynamic basic)
  65. {
  66. var player = getPlayer(playerId);
  67. if (player != null)
  68. {
  69. XmdsUnitBaseInfo baseData = XmdsPlayerUtil.instance().createXmdsUnitBaseInfo(basic);
  70. XmdsUnitBaseInfoEventB2C b2c = new XmdsUnitBaseInfoEventB2C(baseData);
  71. player.ReceiveMsgR2B(b2c);
  72. }
  73. }
  74. /// <summary>
  75. /// 玩家基本信息同步
  76. /// </summary>
  77. /// <param name="instanceId"></param>
  78. /// <returns>副本实例id</returns>
  79. public void r2b_notify_refreshPlayerPropertyChange(string playerId, int changeType, int valueType, int value, int duration, long timestamp)
  80. {
  81. var player = getPlayer(playerId);
  82. if (player != null)
  83. {
  84. PropertyChangeEventR2B r2b = new PropertyChangeEventR2B();
  85. r2b.ChangeType = (PropertyChangeEventR2B.PropertyChangeType)changeType;
  86. r2b.ChangeValueType = (PropertyChangeEventR2B.ValueType)valueType;
  87. r2b.ChangeValue = value;
  88. r2b.Duration = duration;
  89. //r2b.TimestampMS = timestamp;
  90. //药剂时间直接用本机的时间
  91. r2b.TimestampMS = TimeUtil.GetTimestampMS() + r2b.Duration;
  92. //Console.Write("timestamp:" + timestamp);
  93. //TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1).ToUniversalTime();
  94. //Console.Write("timestamp cs:" + ts.TotalMilliseconds);
  95. player.ReceiveMsgR2B(r2b);
  96. }
  97. }
  98. /// <summary>
  99. /// 玩家基本信息同步
  100. /// </summary>
  101. /// <param name="instanceId"></param>
  102. /// <returns>副本实例id</returns>
  103. public void r2b_notify_refreshPlayerPetBaseInfoChange(string playerId, dynamic propertyData)
  104. {
  105. var player = getPlayer(playerId);
  106. if (player != null)
  107. {
  108. PetBaseInfoChangeEventR2B r2b = new PetBaseInfoChangeEventR2B();
  109. r2b.BaseInfo = XmdsPlayerUtil.instance().createPetBaseData(propertyData);
  110. player.ReceiveMsgR2B(r2b);
  111. }
  112. }
  113. //public void r2b_request_addUnit(string instanceId, int unitTemplateID, string data, Action<int> cb, Action<Exception> err)
  114. /// <summary>
  115. /// 玩家基本信息同步
  116. /// </summary>
  117. /// <param name="instanceId"></param>
  118. /// <returns>副本实例id</returns>
  119. public void r2b_notify_refreshPlayerPetDataChange(string playerId, int type, PetDataChangeEventR2B r2b, Action<int> cb, Action<Exception> err)
  120. {
  121. int petHP = 0;
  122. var player = getPlayer(playerId);
  123. if (player != null)
  124. {
  125. player.ReceiveMsgR2B(r2b);
  126. // 获取该玩家宠物血量
  127. if (player.BindingObject != null && player.BindingObject.BindingActor != null)
  128. {
  129. XmdsVirtual_Player zv = (XmdsVirtual_Player)player.BindingObject.BindingActor.Virtual;
  130. if(zv != null && zv.GetPet() != null)
  131. {
  132. petHP = zv.GetPet().mUnit.CurrentHP;
  133. }
  134. }
  135. }
  136. cb(petHP);
  137. }
  138. /// <summary>
  139. /// 宠物技能信息同步
  140. /// </summary>
  141. /// <param name="playerId"></param>
  142. /// <param name="type"></param>
  143. /// <param name="propertyData"></param>
  144. /// <returns></returns>
  145. public void r2b_notify_refreshPlayerPetSkillChange(string playerId, int type, dynamic propertyData)
  146. {
  147. var player = getPlayer(playerId);
  148. if (player != null)
  149. {
  150. PetSkillChangeEventR2B r2b = new PetSkillChangeEventR2B();
  151. List<GameSkill> UnitSkills = new List<GameSkill>();
  152. foreach (dynamic obj in propertyData)
  153. {
  154. GameSkill skill = new GameSkill();
  155. skill.SkillID = (int)obj.id;
  156. skill.SkillLevel = (int)obj.level;
  157. skill.SkillType = (XmdsSkillType)obj.type;
  158. skill.TalentSkillLevel1 = (int)obj.talentLevel[0];
  159. skill.TalentSkillLevel2 = (int)obj.talentLevel[1];
  160. skill.TalentSkillLevel3 = (int)obj.talentLevel[2];
  161. UnitSkills.Add(skill);
  162. }
  163. r2b.OperateID = (PlayerSkillChangeEventR2B.SkillOperate)type;
  164. r2b.SkillList = UnitSkills;
  165. player.ReceiveMsgR2B(r2b);
  166. }
  167. }
  168. /// <summary>
  169. /// 玩家基本信息同步
  170. /// </summary>
  171. /// <param name="playerId"></param>
  172. /// <returns></returns>
  173. public void r2b_notify_refreshPlayerPetPropertyChange(string playerId, dynamic propertyData)
  174. {
  175. var player = getPlayer(playerId);
  176. if (player != null)
  177. {
  178. PetPropertyChangeEventR2B r2b = new PetPropertyChangeEventR2B();
  179. PropertyChangeEventR2B order = new PropertyChangeEventR2B();
  180. order.ChangeType = (PropertyChangeEventR2B.PropertyChangeType)propertyData.changeType;
  181. order.ChangeValue = (int)propertyData.value;
  182. order.ChangeValueType = (PropertyChangeEventR2B.ValueType)propertyData.valueType;
  183. order.Duration = (int)propertyData.duration;
  184. order.TimestampMS = (long)propertyData.timestamp;
  185. r2b.Order = order;
  186. player.ReceiveMsgR2B(r2b);
  187. }
  188. }
  189. /// <summary>
  190. /// 玩家基本信息同步
  191. /// </summary>
  192. /// <param name="instanceId"></param>
  193. /// <returns>副本实例id</returns>
  194. public void r2b_notify_refreshPlayerPKMode(string playerId, bool isLook, dynamic model, Action<int> cb, Action<Exception> err)
  195. {
  196. int resCode = 0;
  197. var player = getPlayer(playerId);
  198. if (player != null)
  199. {
  200. /*player.BindingActor.Virtual.IsInPVE() || */
  201. if(isLook)
  202. {
  203. resCode = (player.BindingActor.IsActive && player.BindingActor.Virtual.IsInPVP()) ? 1 : 0;
  204. if (resCode == 1)
  205. {
  206. XmdsVirtual playerVirtual = player.BindingActor.Virtual as XmdsVirtual;
  207. log.Warn("PVP状态下传送1:" + playerVirtual.mUnit.PlayerUUID + ", 场景ID: " + playerVirtual.mUnit.Parent.GetSceneID() + ", hateInfo:" +
  208. playerVirtual.GetHateSystem().GetHatePlayerInfo() + ", 触发PVP玩家:" + playerVirtual.mPvpTriggerPlayerId);
  209. }
  210. }
  211. else
  212. {
  213. PlayerPKModeChangeEventR2B r2b = new PlayerPKModeChangeEventR2B();
  214. r2b.CurPKMode = (PKMode)model;
  215. player.ReceiveMsgR2B(r2b);
  216. }
  217. }
  218. cb(resCode);
  219. }
  220. /// <summary>
  221. /// 玩家基本信息同步
  222. /// </summary>
  223. /// <param name="instanceId"></param>
  224. /// <returns>副本实例id</returns>
  225. public void r2b_notify_refreshPlayerPKValue(string playerId, int value)
  226. {
  227. var player = getPlayer(playerId);
  228. if (player != null)
  229. {
  230. PlayerPKValueChangeEventR2B r2b = new PlayerPKValueChangeEventR2B();
  231. r2b.ChangeValue = value;
  232. player.ReceiveMsgR2B(r2b);
  233. }
  234. }
  235. /// <summary>
  236. /// 玩家基本信息同步
  237. /// </summary>
  238. /// <param name="instanceId"></param>
  239. /// <returns>副本实例id</returns>
  240. public void r2b_notify_refreshPlayerPKLevel(string playerId, dynamic level)
  241. {
  242. var player = getPlayer(playerId);
  243. if (player != null)
  244. {
  245. PlayerPKLevelChangeEventR2B r2b = new PlayerPKLevelChangeEventR2B();
  246. r2b.CurPKLv = (PKLevel)level;
  247. player.ReceiveMsgR2B(r2b);
  248. }
  249. }
  250. /// <summary>
  251. /// 玩家队伍信息同步
  252. /// </summary>
  253. /// <param name="instanceId"></param>
  254. /// <returns>副本实例id</returns>
  255. public void r2b_notify_refreshPlayerTeamData(string playerId, List<string> uuidList)
  256. {
  257. var player = getPlayer(playerId);
  258. if (player != null)
  259. {
  260. TeamInfoEventR2B r2b = new TeamInfoEventR2B();
  261. r2b.UUIDList = uuidList;
  262. player.Node.OnPlayerReviveTeamInfoEventR2B(player, r2b);
  263. }
  264. }
  265. /// <summary>
  266. /// 玩家背包剩余格子数量信息同步
  267. /// </summary>
  268. /// <param name="instanceId"></param>
  269. /// <returns>副本实例id</returns>
  270. public void r2b_notify_refreshPlayerRemainBagCountData(string playerId, int remainCount)
  271. {
  272. var player = getPlayer(playerId);
  273. if (player != null)
  274. {
  275. SyncPlayerInventorySizeEventR2B r2b = new SyncPlayerInventorySizeEventR2B();
  276. r2b.Size = remainCount;
  277. player.ReceiveMsgR2B(r2b);
  278. }
  279. }
  280. /// <summary>
  281. /// 玩家队伍背包剩余格子数量信息同步
  282. /// </summary>
  283. /// <param name="instanceId"></param>
  284. /// <returns>副本实例id</returns>
  285. public void r2b_notify_refreshPlayerRemainTeamBagCountData(string playerId, int remainCount)
  286. {
  287. var player = getPlayer(playerId);
  288. if (player != null)
  289. {
  290. TeamInventorySizeChangeEventR2B r2b = new TeamInventorySizeChangeEventR2B();
  291. r2b.size = remainCount;
  292. player.ReceiveMsgR2B(r2b);
  293. }
  294. }
  295. /// <summary>
  296. /// 玩家战斗信息同步
  297. /// </summary>
  298. /// <param name="instanceId"></param>
  299. /// <returns>副本实例id</returns>
  300. public void r2b_notify_refreshPlayerBattleEffect(string playerId, dynamic effects)
  301. {
  302. var player = getPlayer(playerId);
  303. if (player != null)
  304. {
  305. XmdsUnitProp effectData = XmdsPlayerUtil.instance().createXmdsUnitProp(effects, playerId);
  306. XmdsUnitPropEventB2C b2c = new XmdsUnitPropEventB2C(effectData);
  307. player.ReceiveMsgR2B(b2c);
  308. }
  309. }
  310. /// <summary>
  311. /// 添加玩家属性
  312. /// </summary>
  313. /// <param name="instanceId"></param>
  314. /// <returns>副本实例id</returns>
  315. public void r2b_notify_addPlayerAtt(List<string> notifyPlayerIds, string playerId, string key, int value)
  316. {
  317. var player = getPlayer(playerId);
  318. if (player != null)
  319. {
  320. List<IPlayer> notifyPlayers = new List<IPlayer>();
  321. foreach (string notifyPlayerId in notifyPlayerIds)
  322. {
  323. XmdsPlayer notifyPlayer = getPlayer(notifyPlayerId);
  324. if (notifyPlayer != null)
  325. {
  326. notifyPlayers.Add(notifyPlayer);
  327. }
  328. }
  329. if (key.Equals("hp"))
  330. {
  331. player.Node.OnPlayerAddHPByItem(notifyPlayers, player, value);
  332. }
  333. }
  334. }
  335. /// <summary>
  336. /// 玩家技能信息同步
  337. /// </summary>
  338. /// <param name="instanceId"></param>
  339. /// <returns>副本实例id</returns>
  340. public void r2b_notify_refreshPlayerSkill(string playerId, int operateID, dynamic skills)
  341. {
  342. var player = getPlayer(playerId);
  343. if (player != null)
  344. {
  345. //XmdsUnitSkillInfo skillData = XmdsPlayerUtil.instance().createXmdsUnitSkillInfo(skills);
  346. PlayerSkillChangeEventR2B r2b = new PlayerSkillChangeEventR2B();
  347. List<GameSkill> UnitSkills = new List<GameSkill>();
  348. foreach (dynamic obj in skills)
  349. {
  350. GameSkill skill = new GameSkill();
  351. skill.SkillID = (int)obj.id;
  352. skill.SkillLevel = (int)obj.level;
  353. skill.SkillType = (XmdsSkillType)obj.type;
  354. skill.TalentSkillLevel1 = (int)obj.talentLevel[0];
  355. skill.TalentSkillLevel2 = (int)obj.talentLevel[1];
  356. skill.TalentSkillLevel3 = (int)obj.talentLevel[2];
  357. skill.SkillTimestampMS = (long)obj.skillTime;
  358. skill.SkillCDDecreasePercent = (int)obj.cdTime;
  359. UnitSkills.Add(skill);
  360. }
  361. r2b.OperateID = (PlayerSkillChangeEventR2B.SkillOperate)operateID;
  362. r2b.SkillList = UnitSkills;
  363. player.ReceiveMsgR2B(r2b);
  364. }
  365. }
  366. /// <summary>
  367. /// 玩家时装信息同步
  368. /// </summary>
  369. /// <param name="instanceId"></param>
  370. /// <returns>副本实例id</returns>
  371. public void r2b_notify_refreshPlayerAvatar(string playerId, dynamic avatars)
  372. {
  373. var player = getPlayer(playerId);
  374. if (player != null)
  375. {
  376. List<XmdsAvatarInfo> avatarList = XmdsPlayerUtil.instance().createXmdsAvatarInfoList(avatars);
  377. PlayAvatarEventB2C b2c = new PlayAvatarEventB2C(avatarList);
  378. player.ReceiveMsgR2B(b2c);
  379. }
  380. }
  381. /// <summary>
  382. /// 协助角色复活
  383. /// </summary>
  384. /// <param name="playerId"></param>
  385. /// <param name="x"></param>
  386. /// <param name="y"></param>
  387. /// <param name="items"></param>
  388. /// <returns>副本实例id</returns>
  389. public void r2b_notify_helpRevivePlayer(string playerId, string revivePlayerId, int time)
  390. {
  391. var player = getPlayer(playerId);
  392. var revivePlayer = getPlayer(revivePlayerId);
  393. if (player != null && revivePlayer != null)
  394. {
  395. player.Node.OnHelpPlayerRebirth(player, revivePlayer, time);
  396. }
  397. }
  398. /// <summary>
  399. /// 角色复活
  400. /// </summary>
  401. /// <param name="playerId"></param>
  402. /// <param name="x"></param>
  403. /// <param name="y"></param>
  404. /// <param name="items"></param>
  405. /// <returns>副本实例id</returns>
  406. public void r2b_notify_revivePlayer(string playerId, int type, int qty, string itemType, int hp, int mp)
  407. {
  408. var player = getPlayer(playerId);
  409. if (player != null)
  410. {
  411. ConsumeItemEventB2R b2r = new ConsumeItemEventB2R();
  412. b2r.playerId = playerId;
  413. b2r.Qty = qty;
  414. b2r.Type = itemType;
  415. PlayerRebirthEventR2B b2c = new PlayerRebirthEventR2B((byte)type, b2r);
  416. b2c.HP = hp;
  417. b2c.MP = mp;
  418. player.ReceiveMsgR2B(b2c);
  419. }
  420. }
  421. /// <summary>
  422. /// 角色复活
  423. /// </summary>
  424. /// <param name="playerId"></param>
  425. /// <param name="x"></param>
  426. /// <param name="y"></param>
  427. /// <param name="items"></param>
  428. /// <returns>副本实例id</returns>
  429. public void r2b_notify_refreshSummonMount(string playerId, int time, bool IsSummonMount)
  430. {
  431. var player = getPlayer(playerId);
  432. if (player != null)
  433. {
  434. PlayerSummonMountEventR2B b2c = new PlayerSummonMountEventR2B();
  435. b2c.TimeMS = time;
  436. b2c.IsSummonMount = IsSummonMount;
  437. player.ReceiveMsgR2B(b2c);
  438. }
  439. }
  440. /// <summary>
  441. /// 怪物死亡掉落
  442. /// </summary>
  443. /// <param name="PlayerId"></param>
  444. /// <param name="x"></param>
  445. /// <param name="y"></param>
  446. /// <param name="items"></param>
  447. /// <returns>副本实例id</returns>
  448. public void r2b_notify_onMonsterDiedDrops(string instanceId, float x, float y, dynamic items)
  449. {
  450. //TODO 要计算道具的位置
  451. var zone = getZoneNode(instanceId);
  452. if (zone != null)
  453. {
  454. zone.Node.AddDropItem(x, y, items);
  455. }
  456. }
  457. /// <summary>
  458. /// 提示客户端获得道具
  459. /// </summary>
  460. /// <param name="PlayerId"></param>
  461. /// <param name="itemIcon"></param>
  462. /// <param name="quality"></param>
  463. /// <param name="num"></param>
  464. /// <returns></returns>
  465. public void r2b_notify_onFinishPickItem(string playerId, string itemIcon, int quality, int num, int objectId, String instanceId)
  466. {
  467. //TODO 要计算道具的位置
  468. var player = getPlayer(playerId);
  469. if (player != null)
  470. {
  471. player.Node.FinishPickItem(player, itemIcon, quality, num);
  472. }
  473. //if(objectId > 0)
  474. //{
  475. // var node = getZoneNode(instanceId);
  476. // if (node != null)
  477. // {
  478. // node.Node.QueueTaskAsync((zone) =>
  479. // {
  480. // zone.RemoveObjectByID((uint)objectId);
  481. // });
  482. // }
  483. //}
  484. }
  485. /// <summary>
  486. ///
  487. /// </summary>
  488. /// <param name="playerId"></param>
  489. /// <param name="eventId"></param>
  490. /// <param name="data"></param>
  491. /// <param name="cb"></param>
  492. /// <param name="err"></param>
  493. public void r2b_notify_triggrBattleFunction(string playerId, int eventId, int value1, int value2, int value3, int value4, int value5, int value6)
  494. {
  495. XmdsPlayer player = getPlayer(playerId);
  496. if (player != null)
  497. {
  498. player.Node.QueueTaskAsync(() =>
  499. {
  500. try
  501. {
  502. if(eventId <= 0)
  503. {
  504. log.Warn("r2b_notify_triggrBattleFunction 错误事件id:" + playerId + ", " + eventId);
  505. return;
  506. }
  507. if(value1 == 0 && value2 == 0 && value3 == 0 && value4 == 0 && value5 == 0 && value6 == 0)
  508. {
  509. XmdsVirtual virtualUnit = (player.BindingActor.Virtual as XmdsVirtual);
  510. BattleFunction.GetInstance().TriggrBattleFunction(eventId, virtualUnit, virtualUnit);
  511. }
  512. else
  513. {
  514. BattleFunction.GetInstance().TriggrBattleFunction(eventId, (player.BindingActor.Virtual as XmdsVirtual), value1, value2, value3, value4, value5, value6);
  515. }
  516. }
  517. catch(Exception e)
  518. {
  519. log.Warn("r2b_notify_triggrBattleFunction catch: " + playerId + ", " + eventId + ", 参数:" + value1 + ", " + value2
  520. + ", " + value3 + ", " + value4 + ", " + value5 + ", " + value6 + ", e: " + e);
  521. }
  522. });
  523. }
  524. else
  525. {
  526. log.Warn("r2b_notify_triggrBattleFunction player not exists:" + playerId + ", " + eventId);
  527. }
  528. }
  529. /// <summary>
  530. /// 种怪
  531. /// </summary>
  532. /// <param name="instanceId"></param>
  533. /// <param name="data"></param>
  534. public void r2b_notify_addUnits(string instanceId, string propertyData, Action<int> cb, Action<Exception> err)
  535. {
  536. int unitId = 0;
  537. dynamic data = Json.Decode(propertyData);
  538. var zoneNode = getZoneNode(instanceId);
  539. if (zoneNode != null)
  540. {
  541. zoneNode.Node.QueueTaskAsync((zone) =>
  542. {
  543. int count = 0;
  544. foreach (var u in data)
  545. {
  546. int templateId = u.id;
  547. int gsFlag = u["gsFlag"];
  548. int hp = 0;
  549. int maxHP = 0;
  550. float birthDirection = (float)u["birthDirection"];
  551. int level = u["level"];
  552. string flagName = u["flag"];
  553. string name = u["name"];
  554. //指定追击玩家id(必须是无限追击怪才会联动生效)
  555. string attackPlayerId = u["attackPlayer"];
  556. //创建护卫怪,主人ObjectId(主人脱战或者死亡消失)
  557. int masterId = u.masterID;
  558. bool autoGuard = false;
  559. if (u["autoGuard"] != null)
  560. {
  561. autoGuard = u["autoGuard"];
  562. }
  563. //同一个场景内是否只能拥有唯一一个unit
  564. bool unique = false;
  565. if (u["unique"] != null)
  566. {
  567. unique = u["unique"];
  568. }
  569. if (u["hp"] != null && u["maxHP"] != null)
  570. {
  571. hp = u["hp"];
  572. maxHP = u["maxHP"];
  573. }
  574. float x = 0;
  575. float y = 0;
  576. if (flagName != null)
  577. {
  578. var p = zone.getFlag(flagName);
  579. if(p == null)
  580. {
  581. log.Error("r2b_notify_addUnits 路点错误,怪物:" + templateId + ", 路点:" + flagName);
  582. cb(0);
  583. return;
  584. }
  585. else if (p is ZoneRegion)
  586. {
  587. // Region随机取一个坐标
  588. var v2 = (p as ZoneRegion).getRandomPos(zone.RandomN);
  589. x = v2.X;
  590. y = v2.Y;
  591. }
  592. else
  593. {
  594. x = p.X;
  595. y = p.Y;
  596. }
  597. }
  598. else
  599. {
  600. //根据坐标
  601. x = u.x;
  602. y = u.y;
  603. }
  604. int force = u.force;
  605. var unitInfo = zone.Templates.getUnit(templateId);
  606. if (unitInfo != null)
  607. {
  608. string uuid = u["uuid"];
  609. if (string.IsNullOrEmpty(uuid))
  610. {
  611. if (unitInfo.UType == CommonAI.Zone.UnitInfo.UnitType.TYPE_PLAYER)
  612. {
  613. uuid = unitInfo.Name + CUtils.CurrentTimeMS.ToString() + count.ToString();
  614. }
  615. else
  616. {
  617. uuid = "";
  618. }
  619. }
  620. if (unique)
  621. {
  622. InstanceUnit targetUnit = zone.getUnitByTemplateID(templateId);
  623. if (targetUnit != null)
  624. {
  625. log.Info("AddUnits is already exist, id:" + templateId + "," + x + "," + y);
  626. continue;
  627. }
  628. }
  629. var ret = zone.AddUnit(unitInfo, uuid, force, level, x, y, birthDirection, null, name, gsFlag, level > 0);
  630. if(ret == null)
  631. {
  632. log.Warn("单位添加失败:" + unitInfo.TemplateID + ", " + zone.Data.ID);
  633. continue;
  634. }
  635. if (flagName != null)
  636. {
  637. ret.SetAttribute("RefreshMonsterTag", flagName);
  638. }
  639. if (ret is InstancePlayer && autoGuard)
  640. {
  641. var act = new CommonAI.Zone.UnitGuardAction(ret.ID, autoGuard);
  642. zone.pushAction(act);
  643. }
  644. if (ret.Virtual is XmdsVirtual_Monster)
  645. {
  646. var monster = ret.Virtual as XmdsVirtual_Monster;
  647. if (u["shareType"] != null)
  648. {
  649. monster.IsShare = true;
  650. }
  651. //血量数据设置
  652. if(hp > 0)
  653. {
  654. // 最大血量小于设置血量,需要调整下
  655. if(monster.mUnit.MaxHP < hp)
  656. {
  657. monster.mUnit.SetMaxHP(hp);
  658. }
  659. monster.mUnit.CurrentHP = hp;
  660. }
  661. if (!JSGModule.IsEmpty(attackPlayerId))
  662. {
  663. ret.BindAttackPlayer(attackPlayerId);
  664. }
  665. if(masterId > 0)
  666. {
  667. ret.BindMasterId(masterId);
  668. }
  669. }
  670. unitId = (int)ret.ID;
  671. }
  672. count = count + 1;
  673. }
  674. if(count <= 1)
  675. {
  676. cb(unitId);
  677. }
  678. else
  679. {
  680. cb(0);
  681. }
  682. });
  683. }
  684. else
  685. {
  686. log.Warn("场景不存在加入单位:" + instanceId + ", " + propertyData);
  687. cb(-1);
  688. }
  689. }
  690. /// <summary>
  691. /// 玩家基本信息同步
  692. /// </summary>
  693. /// <param name="instanceId"></param>
  694. /// <returns>副本实例id</returns>
  695. public void r2b_notify_refreshPlayerPetFollowModeChange(string playerId, int model)
  696. {
  697. var player = getPlayer(playerId);
  698. if (player != null)
  699. {
  700. PetFollowModeChangeEventR2B r2b = new PetFollowModeChangeEventR2B();
  701. r2b.mode = (XmdsPetConifg.XmdsPetFollowMode)model;
  702. player.ReceiveMsgR2B(r2b);
  703. }
  704. }
  705. // TODO playerReady
  706. public void r2b_notify_playerReady(string playerId)
  707. {
  708. var player = getPlayer(playerId);
  709. if (player != null)
  710. {
  711. player.Node.OnPlayerReadyR2B(player);
  712. }
  713. }
  714. public void r2b_request_addUnit(string instanceId, int unitTemplateID, string data, Action<int> cb, Action<Exception> err)
  715. {
  716. dynamic input = Json.Decode(data);
  717. string name = (string)input.name;
  718. byte force = (byte)input.force;
  719. String flag = input.flag; //刷新点
  720. float x = (float)input.x;
  721. float y = (float)input.y;
  722. float direction = (float)input.direction;
  723. int lifeEndTime = (int)input.lifeEndTime;
  724. int lifeTime = (int)input.lifeTime;
  725. bool showLifeTime = (bool)input.showLifeTime;
  726. byte maxPickPlayers = (byte)input.maxPickPlayers;
  727. short maxPickTimes = (short)input.maxPickTimes;
  728. short gotInterval = (short)input.gotInterval;
  729. float offset = (float)input.offsetValue;
  730. String playerId = input.playerId;
  731. var node = getZoneNode(instanceId);
  732. if (node != null)
  733. {
  734. node.Node.QueueTaskAsync((zone) =>
  735. {
  736. //如果玩家id不为空,就是用改玩家的坐标
  737. if(playerId != null && playerId.Length > 0)
  738. {
  739. var player = zone.getPlayerByUUID(playerId);
  740. if(player != null)
  741. {
  742. x = player.X;
  743. y = player.Y;
  744. }
  745. }
  746. var temp = zone.Templates.getItem(unitTemplateID);
  747. if (temp != null)
  748. {
  749. //如果设置了路点,优先使用路点的x,y
  750. if (flag != null)
  751. {
  752. var p = zone.getFlag(flag);
  753. if(p == null)
  754. {
  755. log.Error("创建单位出现错误flag:" + unitTemplateID + ", " + flag);
  756. cb(-1);
  757. return;
  758. }
  759. if (p is ZoneRegion)
  760. {
  761. // Region随机取一个坐标
  762. var v2 = (p as ZoneRegion).getRandomPos(zone.RandomN);
  763. x = v2.X;
  764. y = v2.Y;
  765. }
  766. else
  767. {
  768. x = p.X;
  769. y = p.Y;
  770. }
  771. }
  772. if (lifeTime > 0)
  773. {
  774. temp.LifeTimeMS = lifeTime * 1000;
  775. }
  776. temp.LifeEndTime = lifeEndTime;
  777. temp.showLifeTime = showLifeTime;
  778. if(maxPickPlayers != 0)
  779. {
  780. temp.maxPickPlayers = maxPickPlayers;
  781. }
  782. if(maxPickTimes != 0)
  783. {
  784. temp.maxPickTimes = maxPickTimes;
  785. }
  786. if(gotInterval != -1)
  787. {
  788. temp.UseCoolDownTimeMS = gotInterval;
  789. }
  790. if(offset == 0)
  791. {
  792. InstanceItem unit_data = zone.AddItem(temp, name, x, y, direction, force, name, null);
  793. if (unit_data != null)
  794. {
  795. cb((int)unit_data.ID);
  796. }
  797. }
  798. else
  799. {
  800. //特殊写法,仰慕道具
  801. for(int i = 0; i < 4; i++)
  802. {
  803. float tempX = x + mXChange[i] * offset;
  804. float tempY = y + mYChange[i] * offset;
  805. InstanceItem unit_data = zone.AddItem(temp, name, tempX, tempY, direction, force, name, null);
  806. }
  807. cb(0);
  808. }
  809. }
  810. else
  811. {
  812. cb(0);
  813. }
  814. });
  815. }
  816. else
  817. {
  818. cb(-1);
  819. }
  820. }
  821. public void r2b_request_removeUnit(string instanceId, int unitId)
  822. {
  823. var node = getZoneNode(instanceId);
  824. if (node != null)
  825. {
  826. node.Node.QueueTaskAsync((zone) =>
  827. {
  828. zone.RemoveUnitByID((uint)unitId);
  829. });
  830. }
  831. }
  832. public void r2b_request_removePointUnit(string instanceId, int unitObjectId)
  833. {
  834. var node = getZoneNode(instanceId);
  835. if (node != null)
  836. {
  837. node.Node.QueueTaskAsync((zone) =>
  838. {
  839. zone.RemoveObjectByID((uint)unitObjectId);
  840. });
  841. }
  842. }
  843. public void r2b_request_removeItem(string instanceId, int itemId)
  844. {
  845. var node = getZoneNode(instanceId);
  846. if (node != null)
  847. {
  848. node.Node.QueueTaskAsync((zone) =>
  849. {
  850. zone.RemoveItemByID((uint)itemId);
  851. });
  852. }
  853. }
  854. #endregion
  855. //----------------------------------------------------------------------------------------------
  856. #region _获取静态数据_
  857. /// <summary>
  858. /// 【静态数据】获取副本传送点
  859. /// </summary>
  860. /// <param name="instanceId"></param>
  861. /// <returns>副本实例id</returns>
  862. public void r2b_get_static_getBornPlace(string instanceId, int areaId, string pointId, Action<dynamic> cb, Action<Exception> err)
  863. {
  864. var node = getZoneNode(instanceId);
  865. if (node != null)
  866. {
  867. cb(node.r2b_get_getBornPlace(areaId, pointId));
  868. }
  869. else
  870. {
  871. err(new InstanceNotExistException(instanceId));
  872. }
  873. }
  874. /// <summary>
  875. /// 【静态数据】获取副本静态模版数据
  876. /// </summary>
  877. /// <param name="instanceId"></param>
  878. /// <returns>副本实例id</returns>
  879. public void r2b_get_static_getZoneStaticData(string instanceId, Action<EdgeSceneData> cb, Action<Exception> err)
  880. {
  881. var node = getZoneNode(instanceId);
  882. if (node != null)
  883. {
  884. var data = new EdgeSceneData(node.Node.SceneData);
  885. cb(data);
  886. }
  887. else
  888. {
  889. err(new InstanceNotExistException(instanceId));
  890. }
  891. }
  892. ///
  893. public void r2b_notify_setTeamData(string playerId, dynamic data)
  894. {
  895. var player = getPlayer(playerId);
  896. if (player != null)
  897. {
  898. TeamDataEventR2B r2b = new TeamDataEventR2B();
  899. r2b.LeaderId = data.leaderId;
  900. r2b.TeamMembers = new List<TeamMemberEventR2B>();
  901. foreach (dynamic obj in data.members)
  902. {
  903. TeamMemberEventR2B mbr = new TeamMemberEventR2B();
  904. mbr.followLeader = (int)obj.followLeader;
  905. mbr.uuid = obj.uuid;
  906. r2b.TeamMembers.Add(mbr);
  907. }
  908. player.ReceiveMsgR2B(r2b);
  909. }
  910. }
  911. #endregion
  912. //----------------------------------------------------------------------------------------------
  913. #region _获取动态数据_
  914. /// <summary>
  915. /// 获取地图上所有enable的区域
  916. /// </summary>
  917. /// <param name="instanceId"></param>
  918. /// <returns></returns>
  919. public void r2b_get_getZoneRegions(string instanceId, Action<List<EdgeRegionData>> cb, Action<Exception> err)
  920. {
  921. var node = getZoneNode(instanceId);
  922. if (node != null)
  923. {
  924. node.Node.QueueTaskAsync((zone) =>
  925. {
  926. try
  927. {
  928. List<RegionData> regions = zone.Data.Regions;
  929. List<EdgeRegionData> edgeRegions = new List<EdgeRegionData>();
  930. foreach (RegionData rd in regions)
  931. {
  932. var flag = zone.getFlag(rd.Name);
  933. if (flag != null && flag.Enable)
  934. {
  935. EdgeRegionData eRd = new EdgeRegionData(rd);
  936. eRd.Enable = true;
  937. edgeRegions.Add(eRd);
  938. }
  939. }
  940. cb(edgeRegions);
  941. }
  942. catch (Exception e)
  943. {
  944. err(e);
  945. }
  946. });
  947. }
  948. else
  949. {
  950. err(new InstanceNotExistException(instanceId));
  951. }
  952. }
  953. /// <summary>
  954. /// 获取地图上所有enable的区域
  955. /// </summary>
  956. /// <param name="playerId"></param>
  957. /// <returns></returns>
  958. public void r2b_get_canUseItem(string playerId, Action<bool> cb, Action<Exception> err)
  959. {
  960. XmdsPlayer player = getPlayer(playerId);
  961. if (player != null)
  962. {
  963. //player.Node.QueueTaskAsync(() =>
  964. //{
  965. // try
  966. // {
  967. XmdsVirtual zv = (XmdsVirtual)player.BindingActor.Virtual;
  968. cb(zv.CanUseItem());
  969. // }
  970. // catch (Exception e)
  971. // {
  972. // err(e);
  973. // }
  974. //});
  975. }
  976. else
  977. {
  978. err(new PlayerNotExistException(playerId));
  979. }
  980. }
  981. /// <summary>
  982. /// 获取该地图的所有unit
  983. /// </summary>
  984. /// <param name="instanceId"></param>
  985. /// <returns></returns>
  986. public void r2b_get_getAllUnitInfo(string instanceId, Action<List<UnitInfo>> cb, Action<Exception> err)
  987. {
  988. var node = getZoneNode(instanceId);
  989. if (node != null)
  990. {
  991. node.Node.QueueTaskAsync((zone) =>
  992. {
  993. var units = new List<InstanceUnit>();
  994. zone.GetAllUnits(units);
  995. List<UnitInfo> ret = new List<UnitInfo>();
  996. foreach (InstanceUnit unit in units)
  997. {
  998. CommonAI.ZoneClient.SyncUnitInfo syncInfo = unit.GenSyncUnitInfo();
  999. UnitInfo info = new UnitInfo();
  1000. info.type = unit.GetType().Name;
  1001. info.ObjectId = syncInfo.ObjectID;
  1002. info.force = syncInfo.Force;
  1003. info.templateId = syncInfo.TemplateID;
  1004. info.playerId = syncInfo.PlayerUUID;
  1005. info.x = syncInfo.x;
  1006. info.y = syncInfo.y;
  1007. ret.Add(info);
  1008. }
  1009. cb(ret);
  1010. });
  1011. }
  1012. else
  1013. {
  1014. err(new InstanceNotExistException(instanceId));
  1015. }
  1016. }
  1017. /// <summary>
  1018. /// 获取该地图的所有npc
  1019. /// </summary>
  1020. /// <param name="instanceId"></param>
  1021. /// <returns></returns>
  1022. public void r2b_get_getAllNpcInfo(string instanceId, Action<List<UnitInfo>> cb, Action<Exception> err)
  1023. {
  1024. try
  1025. {
  1026. var node = getZoneNode(instanceId);
  1027. if (node != null)
  1028. {
  1029. //node.Node.QueueTaskAsync((zone) =>
  1030. //{
  1031. List<InstanceUnit> units = new List<InstanceUnit>();
  1032. node.Node.Zone.GetAllUnits(units);
  1033. List<UnitInfo> ret = new List<UnitInfo>();
  1034. foreach (InstanceUnit unit in units)
  1035. {
  1036. if (unit.Info.UType == CommonAI.Zone.UnitInfo.UnitType.TYPE_NPC)
  1037. {
  1038. CommonAI.ZoneClient.SyncUnitInfo syncInfo = unit.GenSyncUnitInfo();
  1039. UnitInfo info = new UnitInfo();
  1040. UnitData data = (UnitData)unit.GetAttribute("UnitData");
  1041. string[] attributes = data == null ? null : data.Attributes;
  1042. //string[] attributes = unit.Info.Attributes;
  1043. if (attributes != null && attributes.Length > 0)
  1044. {
  1045. info.unitType = attributes[0];
  1046. }
  1047. else
  1048. {
  1049. info.unitType = "";
  1050. }
  1051. info.name = unit.Name;
  1052. info.type = unit.GetType().Name;
  1053. info.ObjectId = syncInfo.ObjectID;
  1054. info.force = syncInfo.Force;
  1055. info.templateId = syncInfo.TemplateID;
  1056. info.playerId = syncInfo.PlayerUUID;
  1057. info.x = syncInfo.x;
  1058. info.y = syncInfo.y;
  1059. ret.Add(info);
  1060. }
  1061. }
  1062. cb(ret);
  1063. return;
  1064. //});
  1065. }
  1066. }
  1067. catch(Exception e)
  1068. {
  1069. log.Warn("r2b_get_getAllNpcInfo catch: " + instanceId + ", " + e);
  1070. }
  1071. cb(new List<UnitInfo>());
  1072. }
  1073. /// <summary>
  1074. /// 获取所有玩家UUID信息
  1075. /// </summary>
  1076. public void r2b_get_getAllPlayerUUID(Action<dynamic> cb, Action<Exception> err)
  1077. {
  1078. GetAllPlayers((e2, ret) =>
  1079. {
  1080. if (e2 != null)
  1081. {
  1082. err(e2);
  1083. }
  1084. else
  1085. {
  1086. dynamic json = new { list = ret };
  1087. cb(json);
  1088. }
  1089. });
  1090. }
  1091. /// <summary>
  1092. /// 玩家基本信息同步
  1093. /// </summary>
  1094. /// <param name="PlayerId"></param>
  1095. /// <returns>副本实例id</returns>
  1096. public void r2b_get_getPlayerData(string playerId, bool changeArea, Action<dynamic> cb, Action<Exception> err)
  1097. {
  1098. XmdsPlayer player = getPlayer(playerId);
  1099. if (player != null && player.BindingActor != null)
  1100. {
  1101. //player.Node.QueueTaskAsync(() =>
  1102. //{
  1103. // try
  1104. // {
  1105. InstancePlayer p = player.BindingActor;
  1106. XmdsUnitProperties prop = p.Properties as XmdsUnitProperties;
  1107. PKInfo pkInfo = prop.ServerData.UnitPKInfo;
  1108. ArrayList skillList = new ArrayList();
  1109. XmdsVirtual zv = (XmdsVirtual)p.Virtual;
  1110. if (changeArea)
  1111. {
  1112. XmdsCommonServer.Plugin.XmdsVirtual.XmdsSkillStatusData skillData = zv.GetSkillStatusData();
  1113. foreach (KeyValuePair<int, long> kvp in skillData.SkillTimestampMSMap)
  1114. {
  1115. int skillId = kvp.Key;
  1116. long skillTime = kvp.Value;
  1117. skillList.Add(new { skillId = skillId, skillTime = skillTime });
  1118. }
  1119. }
  1120. dynamic ret = new
  1121. {
  1122. x = p.X,
  1123. y = p.Y,
  1124. direction = p.Direction,
  1125. hp = p.get_current_hp(),
  1126. mp = p.get_current_mp(),
  1127. pkMode = (int)pkInfo.CurPKMode,
  1128. pkValue = pkInfo.CurPKValue,
  1129. pkLevel = (int)pkInfo.CurPKLevel,
  1130. skillData = skillList,
  1131. combatState = zv.CombatState
  1132. };
  1133. cb(ret);
  1134. // }
  1135. // catch (Exception e)
  1136. // {
  1137. // err(e);
  1138. // }
  1139. //});
  1140. }
  1141. else
  1142. {
  1143. //err(new PlayerNotExistException(playerId));
  1144. cb(null);
  1145. }
  1146. }
  1147. /// <summary>
  1148. /// 玩家宠物基本信息同步
  1149. /// </summary>
  1150. /// <param name="PlayerId"></param>
  1151. /// <returns>副本实例id</returns>
  1152. public void r2b_get_getPlayerPetData(string playerId, Action<dynamic> cb, Action<Exception> err)
  1153. {
  1154. try
  1155. {
  1156. do
  1157. {
  1158. if (string.IsNullOrEmpty(playerId))
  1159. {
  1160. log.Error("那个sx传过来一个空玩家信息:");
  1161. break; ;
  1162. }
  1163. XmdsPlayer player = getPlayer(playerId);
  1164. if (player != null && player.BindingActor != null)
  1165. {
  1166. XmdsVirtual_Player zv = (XmdsVirtual_Player)player.BindingActor.Virtual;
  1167. if(zv == null)
  1168. {
  1169. break;
  1170. }
  1171. XmdsVirtual_Pet petData = zv.GetPet();
  1172. if (petData == null)
  1173. {
  1174. log.Warn("找不到玩家对应宠物信息:" + playerId);
  1175. break; ;
  1176. }
  1177. dynamic ret = new
  1178. {
  1179. hp = petData.mUnit.CurrentHP,
  1180. mp = petData.mUnit.CurrentMP,
  1181. };
  1182. cb(ret);
  1183. return;
  1184. }
  1185. } while (false);
  1186. }
  1187. catch(Exception e)
  1188. {
  1189. log.Error("r2b_get_getPlayerPetData : " + playerId + ", " + e);
  1190. }
  1191. dynamic retFinal = new
  1192. {
  1193. hp = -1,
  1194. mp = -1,
  1195. };
  1196. cb(retFinal);
  1197. }
  1198. /// <summary>
  1199. /// 玩家基本信息同步
  1200. /// </summary>
  1201. /// <param name="PlayerId"></param>
  1202. /// <returns>副本实例id</returns>
  1203. public void r2b_get_getPlayerSkillCDTime(string playerId, Action<ArrayList> cb, Action<Exception> err)
  1204. {
  1205. XmdsPlayer player = getPlayer(playerId);
  1206. if (player != null)
  1207. {
  1208. //player.Node.QueueTaskAsync(() =>
  1209. //{
  1210. try
  1211. {
  1212. ArrayList skillList = new ArrayList();
  1213. global::XmdsCommonServer.Plugin.XmdsVirtual zv = (global::XmdsCommonServer.Plugin.XmdsVirtual)player.BindingActor.Virtual;
  1214. global::XmdsCommonServer.Plugin.XmdsVirtual.XmdsSkillStatusData skillData = zv.GetSkillStatusData();
  1215. foreach (KeyValuePair<int, long> kvp in skillData.SkillTimestampMSMap)
  1216. {
  1217. int skillId = kvp.Key;
  1218. long skillTime = kvp.Value;
  1219. skillList.Add(new { skillId = skillId, skillTime = skillTime });
  1220. }
  1221. cb(skillList);
  1222. }
  1223. catch (Exception e)
  1224. {
  1225. err(e);
  1226. }
  1227. //});
  1228. }
  1229. else
  1230. {
  1231. err(new PlayerNotExistException(playerId));
  1232. }
  1233. }
  1234. public void r2b_get_CanTalkWithNpc(string playerId, uint npcId, Action<dynamic> cb, Action<Exception> err)
  1235. {
  1236. XmdsPlayer player = getPlayer(playerId);
  1237. if (player != null)
  1238. {
  1239. //player.Node.QueueTaskAsync(() =>
  1240. //{
  1241. InstancePlayer src = player.BindingActor;
  1242. InstanceUnit dst = null;
  1243. if (src != null && (dst = src.Parent.getUnit(npcId)) != null)
  1244. {
  1245. dynamic ret = new
  1246. {
  1247. templateId = dst.Info.TemplateID,
  1248. canTalk = CMath.intersectRound(
  1249. src.X, src.Y, src.BodyBlockSize + 5,
  1250. dst.X, dst.Y, dst.BodyBlockSize),
  1251. };
  1252. cb(ret);
  1253. return;
  1254. }
  1255. //});
  1256. }
  1257. cb(new
  1258. {
  1259. templateId = 0,
  1260. canTalk = false,
  1261. });
  1262. }
  1263. /// <summary>
  1264. /// 玩家基本信息同步
  1265. /// </summary>
  1266. /// <param name="PlayerId"></param>
  1267. /// <returns>副本实例id</returns>
  1268. public void r2b_get_getPlayerPKInfoData(string playerId, Action<dynamic> cb, Action<Exception> err)
  1269. {
  1270. XmdsPlayer player = getPlayer(playerId);
  1271. if (player != null)
  1272. {
  1273. //player.Node.QueueTaskAsync(() =>
  1274. //{
  1275. //try
  1276. //{
  1277. XmdsUnitProperties prop = player.BindingActor.Properties as XmdsUnitProperties;
  1278. PKInfo pkInfo = prop.ServerData.UnitPKInfo;
  1279. dynamic ret = new
  1280. {
  1281. pkMode = (int)pkInfo.CurPKMode,
  1282. pkValue = pkInfo.CurPKValue,
  1283. pkLevel = (int)pkInfo.CurPKLevel
  1284. };
  1285. cb(ret);
  1286. //}
  1287. //catch (Exception e)
  1288. //{
  1289. // err(e);
  1290. //}
  1291. //});
  1292. }
  1293. else
  1294. {
  1295. err(new PlayerNotExistException(playerId));
  1296. }
  1297. }
  1298. public void r2b_request_autoBattle(string instanceId, string playerId, bool enable)
  1299. {
  1300. var node = getZoneNode(instanceId);
  1301. if (node != null)
  1302. {
  1303. node.Node.QueueTaskAsync((zone) =>
  1304. {
  1305. InstanceUnit u = zone.getPlayerByUUID(playerId.ToString());
  1306. if (u != null)
  1307. {
  1308. UnitGuardAction guard = new UnitGuardAction();
  1309. guard.guard = enable;
  1310. guard.object_id = u.ID;
  1311. guard.forceNotify = true;
  1312. u.Parent.pushAction(guard);
  1313. log.Debug("--------autoBattle from gs: playerId=" + playerId + " area=" + node.Node.Name + " instanceId=" + instanceId);
  1314. }
  1315. else
  1316. {
  1317. log.Error("r2b_request_autoBattle PlayerNotExistException: playerId =" + playerId + " area=" + node.Node.Name);
  1318. }
  1319. });
  1320. }
  1321. }
  1322. public void r2b_request_getPlayerStatistic(string instanceId, string playerId, int flag, Action<dynamic> cb, Action<Exception> err)
  1323. {
  1324. try
  1325. {
  1326. var node = getZoneNode(instanceId);
  1327. var player = getPlayer(playerId);
  1328. if (player != null && node != null)
  1329. {
  1330. if (flag == 0)
  1331. {
  1332. node.Node.ForEachPlayers((client) =>
  1333. {
  1334. var insPlayer = client.Actor;
  1335. if (insPlayer != null)
  1336. {
  1337. insPlayer.Statistic.Reset();
  1338. }
  1339. });
  1340. cb(null);
  1341. return;
  1342. }
  1343. else
  1344. {
  1345. dynamic statistic = new Dictionary<string, dynamic>();
  1346. node.Node.ForEachPlayers((client) =>
  1347. {
  1348. var insPlayer = client.Actor;
  1349. if (insPlayer != null)
  1350. {
  1351. statistic[insPlayer.PlayerUUID] = new
  1352. {
  1353. totalDamage = insPlayer.Statistic.TotalDamage,
  1354. totalHealing = insPlayer.Statistic.TotalHealing,
  1355. //killPlayerCount = insPlayer.Statistic.KillPlayerCount,
  1356. //killUnitCount = insPlayer.Statistic.KillUnitCount,
  1357. //deadCount = insPlayer.Statistic.DeadCount,
  1358. SelfDamage = insPlayer.Statistic.SelfDamage
  1359. };
  1360. }
  1361. });
  1362. cb(statistic);
  1363. return;
  1364. }
  1365. }
  1366. }
  1367. catch(Exception e)
  1368. {
  1369. log.Error("r2b_request_getPlayerStatistic catch: " + playerId + ", " + instanceId + ", " + flag + ", " + e);
  1370. }
  1371. string notifyMsg = "r2b_request_getPlayerStatistic error: " + playerId + ", " + instanceId + ", " + flag;
  1372. log.Error(notifyMsg);
  1373. cb(notifyMsg);
  1374. }
  1375. public void r2b_request_getInstanceStatistic(string instanceId, Action<dynamic> cb, Action<Exception> err)
  1376. {
  1377. var node = getZoneNode(instanceId);
  1378. if (node != null)
  1379. {
  1380. dynamic statistic = new Dictionary<string, dynamic>();
  1381. node.Node.ForEachPlayers((client) =>
  1382. {
  1383. var insPlayer = client.Actor;
  1384. if (insPlayer != null)
  1385. {
  1386. statistic[insPlayer.PlayerUUID] = new
  1387. {
  1388. totalDamage = insPlayer.Statistic.TotalDamage,
  1389. totalHealing = insPlayer.Statistic.TotalHealing,
  1390. killPlayerCount = insPlayer.Statistic.KillPlayerCount,
  1391. killUnitCount = insPlayer.Statistic.KillUnitCount,
  1392. deadCount = insPlayer.Statistic.DeadCount
  1393. };
  1394. }
  1395. });
  1396. cb(statistic);
  1397. }
  1398. else
  1399. {
  1400. log.Error("r2b_request_getInstanceStatistic: InstanceNotExistException: instanceId =" + instanceId);
  1401. cb(null);
  1402. return;
  1403. }
  1404. }
  1405. /// <summary>
  1406. /// 玩家更换技能
  1407. /// </summary>
  1408. /// <param name="instanceId"></param>
  1409. /// <returns>副本实例id</returns>
  1410. ///
  1411. public void r2b_notify_playerChangeSkill(string playerId, int oldSkillID, int newSkillID, dynamic data)
  1412. {
  1413. var player = getPlayer(playerId);
  1414. if (player != null)
  1415. {
  1416. XmdsInstancePlayer instancePlayer = player.getInstancePlayer() as XmdsInstancePlayer;
  1417. if (instancePlayer == null)
  1418. {
  1419. return;
  1420. }
  1421. SkillLevelData levelData = null;
  1422. if (data != null)
  1423. {
  1424. levelData = new SkillLevelData();
  1425. levelData.SkillLevel = data.level;
  1426. levelData.TalentSkillLevel1 = data.talentLevel[0];
  1427. levelData.TalentSkillLevel2 = data.talentLevel[1];
  1428. levelData.TalentSkillLevel3 = data.talentLevel[2];
  1429. levelData.skillType = (XmdsSkillType)data.skillType;
  1430. }
  1431. instancePlayer.PlayerChangeSkill(oldSkillID, newSkillID, levelData);
  1432. //player.get
  1433. //XmdsUnitSkillInfo skillData = XmdsPlayerUtil.instance()
  1434. }
  1435. }
  1436. /// <summary>
  1437. /// 玩家基本信息同步
  1438. /// </summary>
  1439. /// <param name="playerId"></param>
  1440. /// <returns></returns>
  1441. public bool r2b_notify_transferToPointPos(string instanceId, string playerId, string refreshPoint, bool setDirction, float direction)
  1442. {
  1443. var node = getZoneNode(instanceId);
  1444. if (node == null)
  1445. {
  1446. return false;
  1447. }
  1448. var player = getPlayer(playerId);
  1449. if (player == null)
  1450. {
  1451. return false;
  1452. }
  1453. InstanceFlag flag = node.Node.Zone.getFlag(refreshPoint);
  1454. if (flag == null)
  1455. {
  1456. return false;
  1457. }
  1458. if (flag is ZoneWayPoint)
  1459. {
  1460. // Region随机取一个坐标
  1461. var v2 = (flag as ZoneWayPoint).getRandomPos(node.Node.Zone.RandomN);
  1462. player.getInstancePlayer().transport(v2.X, v2.Y, setDirction, direction);
  1463. return true;
  1464. }
  1465. return false;
  1466. }
  1467. /// <summary>
  1468. /// 更改玩家状态
  1469. /// </summary>
  1470. /// <param name="playerId"></param>
  1471. /// <returns></returns>
  1472. public void r2b_notify_changePlayerStatus(string instanceId, string playerId, byte status, int time)
  1473. {
  1474. if(status != (byte)UnitActionStatus.DaZuo && status != (byte)UnitActionStatus.ClearYaoQi
  1475. && status != (byte)UnitActionStatus.Idle && status != (byte)UnitActionStatus.CrossRobbery
  1476. && status != (byte)UnitActionStatus.DaZuoRecoveryAttr)
  1477. {
  1478. return;
  1479. }
  1480. var node = getZoneNode(instanceId);
  1481. if (node == null)
  1482. {
  1483. return ;
  1484. }
  1485. var player = getPlayer(playerId);
  1486. if (player == null)
  1487. {
  1488. return ;
  1489. }
  1490. var instancePlayer = player.getInstancePlayer();
  1491. if(instancePlayer == null)
  1492. {
  1493. return;
  1494. }
  1495. //if(status == (byte)UnitActionStatus.ChuanGongA)
  1496. //{
  1497. // instancePlayer.changeState(new StateChuanGongA(instancePlayer), false);
  1498. //}
  1499. //else if(status == (byte)UnitActionStatus.ChuanGongB)
  1500. //{
  1501. // instancePlayer.changeState(new StateChuanGongB(instancePlayer), false);
  1502. //}
  1503. //else
  1504. if(status == (byte)UnitActionStatus.DaZuo)
  1505. {
  1506. instancePlayer.Virtual.TakeOffMount();
  1507. instancePlayer.changeState(new StateDaZuo(instancePlayer, time), false);
  1508. }
  1509. else if (status == (byte) UnitActionStatus.DaZuoRecoveryAttr)
  1510. {
  1511. //非战斗状态,才能打坐回血
  1512. if (instancePlayer.Virtual.GetBattleStatus() <= BattleStatus.ReadyBattle && (instancePlayer.CurrentActionStatus != UnitActionStatus.DaZuoRecoveryAttr) && (instancePlayer.CurrentActionStatus != UnitActionStatus.Move) )
  1513. {
  1514. instancePlayer.Virtual.TakeOffMount();
  1515. instancePlayer.changeState(new StateDaZuoRecoveryAttr(instancePlayer, time), false);
  1516. }
  1517. }
  1518. else if(status == (byte)UnitActionStatus.ClearYaoQi)
  1519. {
  1520. instancePlayer.Virtual.TakeOffMount();
  1521. instancePlayer.changeState(new StateClearYaoQi(instancePlayer), false);
  1522. }
  1523. else if (status == (byte)UnitActionStatus.Idle)
  1524. {
  1525. if(instancePlayer.CurrentActionStatus == UnitActionStatus.DaZuo || instancePlayer.CurrentActionStatus == UnitActionStatus.ChuanGongA
  1526. || instancePlayer.CurrentActionStatus == UnitActionStatus.ChuanGongB || instancePlayer.CurrentActionStatus == UnitActionStatus.DaZuoRecoveryAttr)
  1527. {
  1528. instancePlayer.CurrentState.MarkRemove();
  1529. }
  1530. }
  1531. else if(status == (byte)UnitActionStatus.CrossRobbery)
  1532. {
  1533. instancePlayer.Virtual.TakeOffMount();
  1534. instancePlayer.changeState(new StateDuJie(instancePlayer), false);
  1535. }
  1536. }
  1537. /// <summary>
  1538. /// 更改玩家状态
  1539. /// </summary>
  1540. /// <param name="playerId"></param>
  1541. /// <returns></returns>
  1542. public void r2b_notify_playerChuanGong(string instanceId, string playerIdA, string playerIdB)
  1543. {
  1544. var node = getZoneNode(instanceId);
  1545. if (node == null)
  1546. {
  1547. return;
  1548. }
  1549. var playerA = getPlayer(playerIdA);
  1550. var playerB = getPlayer(playerIdB);
  1551. if (playerA == null || playerB == null)
  1552. {
  1553. return;
  1554. }
  1555. var instancePlayerA = playerA.getInstancePlayer();
  1556. var instancePlayerB = playerB.getInstancePlayer();
  1557. if (instancePlayerA == null || instancePlayerB == null)
  1558. {
  1559. return;
  1560. }
  1561. instancePlayerA.Virtual.TakeOffMount();
  1562. instancePlayerB.Virtual.TakeOffMount();
  1563. instancePlayerA.changeState(new StateChuanGongA(instancePlayerA), false);
  1564. instancePlayerB.changeState(new StateChuanGongB(instancePlayerB), false);
  1565. //接受传功者,pos和方向设置
  1566. instancePlayerB.faceTo(instancePlayerA.Direction);
  1567. float xAdd = (float)(2 * Math.Cos(instancePlayerA.Direction)); //角Dir的对边
  1568. float yAdd = (float)(2 * Math.Sin(instancePlayerA.Direction)); //Dir的邻边
  1569. instancePlayerB.setPos(instancePlayerA.X + xAdd, instancePlayerA.Y + yAdd);
  1570. }
  1571. /** 通知山大王延时刷新 */
  1572. public void r2b_notifyMountainKingRefresh(string instanceId, string data)
  1573. {
  1574. var node = getZoneNode(instanceId);
  1575. if (node == null)
  1576. {
  1577. return;
  1578. }
  1579. List<KingRefreshData> refreshList = new List<KingRefreshData>();
  1580. dynamic propertyData = Json.Decode(data);
  1581. foreach(var temp in propertyData)
  1582. {
  1583. refreshList.Add(new KingRefreshData(temp.monsterId, temp.nextRefreshTime));
  1584. }
  1585. if(refreshList.Count > 0)
  1586. {
  1587. JSGMountainKingModule.OnMonsterRefreshNotify(node.GetBindGameSrvId(), refreshList);
  1588. }
  1589. }
  1590. #endregion
  1591. //----------------------------------------------------------------------------------------------
  1592. }
  1593. }