ZoneServiceICE.cs 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715
  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(value1 == 0 && value2 == 0 && value3 == 0 && value4 == 0 && value5 == 0 && value6 == 0)
  503. {
  504. XmdsVirtual virtualUnit = (player.BindingActor.Virtual as XmdsVirtual);
  505. BattleFunction.GetInstance().TriggrBattleFunction(eventId, virtualUnit, virtualUnit);
  506. }
  507. else
  508. {
  509. BattleFunction.GetInstance().TriggrBattleFunction(eventId, (player.BindingActor.Virtual as XmdsVirtual), value1, value2, value3, value4, value5, value6);
  510. }
  511. }
  512. catch(Exception e)
  513. {
  514. log.Warn("r2b_notify_triggrBattleFunction catch: " + playerId + ", " + eventId + ", 参数:" + value1 + ", " + value2
  515. + ", " + value3 + ", " + value4 + ", " + value5 + ", " + value6 + ", e: " + e);
  516. }
  517. });
  518. }
  519. }
  520. /// <summary>
  521. /// 种怪
  522. /// </summary>
  523. /// <param name="instanceId"></param>
  524. /// <param name="data"></param>
  525. public void r2b_notify_addUnits(string instanceId, string propertyData, Action<int> cb, Action<Exception> err)
  526. {
  527. int unitId = 0;
  528. dynamic data = Json.Decode(propertyData);
  529. var zoneNode = getZoneNode(instanceId);
  530. if (zoneNode != null)
  531. {
  532. zoneNode.Node.QueueTaskAsync((zone) =>
  533. {
  534. int count = 0;
  535. foreach (var u in data)
  536. {
  537. int templateId = u.id;
  538. int gsFlag = u["gsFlag"];
  539. int hp = 0;
  540. int maxHP = 0;
  541. float birthDirection = (float)u["birthDirection"];
  542. int level = u["level"];
  543. string flagName = u["flag"];
  544. string name = u["name"];
  545. //指定追击玩家id(必须是无限追击怪才会联动生效)
  546. string attackPlayerId = u["attackPlayer"];
  547. //创建护卫怪,主人ObjectId(主人脱战或者死亡消失)
  548. int masterId = u.masterID;
  549. bool autoGuard = false;
  550. if (u["autoGuard"] != null)
  551. {
  552. autoGuard = u["autoGuard"];
  553. }
  554. //同一个场景内是否只能拥有唯一一个unit
  555. bool unique = false;
  556. if (u["unique"] != null)
  557. {
  558. unique = u["unique"];
  559. }
  560. if (u["hp"] != null && u["maxHP"] != null)
  561. {
  562. hp = u["hp"];
  563. maxHP = u["maxHP"];
  564. }
  565. float x = 0;
  566. float y = 0;
  567. if (flagName != null)
  568. {
  569. var p = zone.getFlag(flagName);
  570. if(p == null)
  571. {
  572. log.Error("r2b_notify_addUnits 路点错误,怪物:" + templateId + ", 路点:" + flagName);
  573. cb(0);
  574. return;
  575. }
  576. else if (p is ZoneRegion)
  577. {
  578. // Region随机取一个坐标
  579. var v2 = (p as ZoneRegion).getRandomPos(zone.RandomN);
  580. x = v2.X;
  581. y = v2.Y;
  582. }
  583. else
  584. {
  585. x = p.X;
  586. y = p.Y;
  587. }
  588. }
  589. else
  590. {
  591. //根据坐标
  592. x = u.x;
  593. y = u.y;
  594. }
  595. int force = u.force;
  596. var unitInfo = zone.Templates.getUnit(templateId);
  597. if (unitInfo != null)
  598. {
  599. string uuid = u["uuid"];
  600. if (string.IsNullOrEmpty(uuid))
  601. {
  602. if (unitInfo.UType == CommonAI.Zone.UnitInfo.UnitType.TYPE_PLAYER)
  603. {
  604. uuid = unitInfo.Name + CUtils.CurrentTimeMS.ToString() + count.ToString();
  605. }
  606. else
  607. {
  608. uuid = "";
  609. }
  610. }
  611. if (unique)
  612. {
  613. InstanceUnit targetUnit = zone.getUnitByTemplateID(templateId);
  614. if (targetUnit != null)
  615. {
  616. log.Info("AddUnits is already exist, id:" + templateId + "," + x + "," + y);
  617. continue;
  618. }
  619. }
  620. var ret = zone.AddUnit(unitInfo, uuid, force, level, x, y, birthDirection, null, name, gsFlag, level > 0);
  621. if(ret == null)
  622. {
  623. log.Warn("单位添加失败:" + unitInfo.TemplateID + ", " + zone.Data.ID);
  624. continue;
  625. }
  626. if (flagName != null)
  627. {
  628. ret.SetAttribute("RefreshMonsterTag", flagName);
  629. }
  630. if (ret is InstancePlayer && autoGuard)
  631. {
  632. var act = new CommonAI.Zone.UnitGuardAction(ret.ID, autoGuard);
  633. zone.pushAction(act);
  634. }
  635. if (ret.Virtual is XmdsVirtual_Monster)
  636. {
  637. var monster = ret.Virtual as XmdsVirtual_Monster;
  638. if (u["shareType"] != null)
  639. {
  640. monster.IsShare = true;
  641. }
  642. //血量数据设置
  643. if(hp > 0)
  644. {
  645. // 最大血量小于设置血量,需要调整下
  646. if(monster.mUnit.MaxHP < hp)
  647. {
  648. monster.mUnit.SetMaxHP(hp);
  649. }
  650. monster.mUnit.CurrentHP = hp;
  651. }
  652. if (!JSGModule.IsEmpty(attackPlayerId))
  653. {
  654. ret.BindAttackPlayer(attackPlayerId);
  655. }
  656. if(masterId > 0)
  657. {
  658. ret.BindMasterId(masterId);
  659. }
  660. }
  661. unitId = (int)ret.ID;
  662. }
  663. count = count + 1;
  664. }
  665. if(count <= 1)
  666. {
  667. cb(unitId);
  668. }
  669. else
  670. {
  671. cb(0);
  672. }
  673. });
  674. }
  675. else
  676. {
  677. log.Warn("场景不存在加入单位:" + instanceId + ", " + propertyData);
  678. cb(-1);
  679. }
  680. }
  681. /// <summary>
  682. /// 玩家基本信息同步
  683. /// </summary>
  684. /// <param name="instanceId"></param>
  685. /// <returns>副本实例id</returns>
  686. public void r2b_notify_refreshPlayerPetFollowModeChange(string playerId, int model)
  687. {
  688. var player = getPlayer(playerId);
  689. if (player != null)
  690. {
  691. PetFollowModeChangeEventR2B r2b = new PetFollowModeChangeEventR2B();
  692. r2b.mode = (XmdsPetConifg.XmdsPetFollowMode)model;
  693. player.ReceiveMsgR2B(r2b);
  694. }
  695. }
  696. // TODO playerReady
  697. public void r2b_notify_playerReady(string playerId)
  698. {
  699. var player = getPlayer(playerId);
  700. if (player != null)
  701. {
  702. player.Node.OnPlayerReadyR2B(player);
  703. }
  704. }
  705. public void r2b_request_addUnit(string instanceId, int unitTemplateID, string data, Action<int> cb, Action<Exception> err)
  706. {
  707. dynamic input = Json.Decode(data);
  708. string name = (string)input.name;
  709. byte force = (byte)input.force;
  710. String flag = input.flag; //刷新点
  711. float x = (float)input.x;
  712. float y = (float)input.y;
  713. float direction = (float)input.direction;
  714. int lifeEndTime = (int)input.lifeEndTime;
  715. int lifeTime = (int)input.lifeTime;
  716. bool showLifeTime = (bool)input.showLifeTime;
  717. byte maxPickPlayers = (byte)input.maxPickPlayers;
  718. short maxPickTimes = (short)input.maxPickTimes;
  719. short gotInterval = (short)input.gotInterval;
  720. float offset = (float)input.offsetValue;
  721. String playerId = input.playerId;
  722. var node = getZoneNode(instanceId);
  723. if (node != null)
  724. {
  725. node.Node.QueueTaskAsync((zone) =>
  726. {
  727. //如果玩家id不为空,就是用改玩家的坐标
  728. if(playerId != null && playerId.Length > 0)
  729. {
  730. var player = zone.getPlayerByUUID(playerId);
  731. if(player != null)
  732. {
  733. x = player.X;
  734. y = player.Y;
  735. }
  736. }
  737. var temp = zone.Templates.getItem(unitTemplateID);
  738. if (temp != null)
  739. {
  740. //如果设置了路点,优先使用路点的x,y
  741. if (flag != null)
  742. {
  743. var p = zone.getFlag(flag);
  744. if(p == null)
  745. {
  746. log.Error("创建单位出现错误flag:" + unitTemplateID + ", " + flag);
  747. cb(-1);
  748. return;
  749. }
  750. if (p is ZoneRegion)
  751. {
  752. // Region随机取一个坐标
  753. var v2 = (p as ZoneRegion).getRandomPos(zone.RandomN);
  754. x = v2.X;
  755. y = v2.Y;
  756. }
  757. else
  758. {
  759. x = p.X;
  760. y = p.Y;
  761. }
  762. }
  763. if (lifeTime > 0)
  764. {
  765. temp.LifeTimeMS = lifeTime * 1000;
  766. }
  767. temp.LifeEndTime = lifeEndTime;
  768. temp.showLifeTime = showLifeTime;
  769. if(maxPickPlayers != 0)
  770. {
  771. temp.maxPickPlayers = maxPickPlayers;
  772. }
  773. if(maxPickTimes != 0)
  774. {
  775. temp.maxPickTimes = maxPickTimes;
  776. }
  777. if(gotInterval != -1)
  778. {
  779. temp.UseCoolDownTimeMS = gotInterval;
  780. }
  781. if(offset == 0)
  782. {
  783. InstanceItem unit_data = zone.AddItem(temp, name, x, y, direction, force, name, null);
  784. if (unit_data != null)
  785. {
  786. cb((int)unit_data.ID);
  787. }
  788. }
  789. else
  790. {
  791. //特殊写法,仰慕道具
  792. for(int i = 0; i < 4; i++)
  793. {
  794. float tempX = x + mXChange[i] * offset;
  795. float tempY = y + mYChange[i] * offset;
  796. InstanceItem unit_data = zone.AddItem(temp, name, tempX, tempY, direction, force, name, null);
  797. }
  798. cb(0);
  799. }
  800. }
  801. else
  802. {
  803. cb(0);
  804. }
  805. });
  806. }
  807. else
  808. {
  809. cb(-1);
  810. }
  811. }
  812. public void r2b_request_removeUnit(string instanceId, int unitId)
  813. {
  814. var node = getZoneNode(instanceId);
  815. if (node != null)
  816. {
  817. node.Node.QueueTaskAsync((zone) =>
  818. {
  819. zone.RemoveUnitByID((uint)unitId);
  820. });
  821. }
  822. }
  823. public void r2b_request_removePointUnit(string instanceId, int unitObjectId)
  824. {
  825. var node = getZoneNode(instanceId);
  826. if (node != null)
  827. {
  828. node.Node.QueueTaskAsync((zone) =>
  829. {
  830. zone.RemoveObjectByID((uint)unitObjectId);
  831. });
  832. }
  833. }
  834. public void r2b_request_removeItem(string instanceId, int itemId)
  835. {
  836. var node = getZoneNode(instanceId);
  837. if (node != null)
  838. {
  839. node.Node.QueueTaskAsync((zone) =>
  840. {
  841. zone.RemoveItemByID((uint)itemId);
  842. });
  843. }
  844. }
  845. #endregion
  846. //----------------------------------------------------------------------------------------------
  847. #region _获取静态数据_
  848. /// <summary>
  849. /// 【静态数据】获取副本传送点
  850. /// </summary>
  851. /// <param name="instanceId"></param>
  852. /// <returns>副本实例id</returns>
  853. public void r2b_get_static_getBornPlace(string instanceId, int areaId, string pointId, Action<dynamic> cb, Action<Exception> err)
  854. {
  855. var node = getZoneNode(instanceId);
  856. if (node != null)
  857. {
  858. cb(node.r2b_get_getBornPlace(areaId, pointId));
  859. }
  860. else
  861. {
  862. err(new InstanceNotExistException(instanceId));
  863. }
  864. }
  865. /// <summary>
  866. /// 【静态数据】获取副本静态模版数据
  867. /// </summary>
  868. /// <param name="instanceId"></param>
  869. /// <returns>副本实例id</returns>
  870. public void r2b_get_static_getZoneStaticData(string instanceId, Action<EdgeSceneData> cb, Action<Exception> err)
  871. {
  872. var node = getZoneNode(instanceId);
  873. if (node != null)
  874. {
  875. var data = new EdgeSceneData(node.Node.SceneData);
  876. cb(data);
  877. }
  878. else
  879. {
  880. err(new InstanceNotExistException(instanceId));
  881. }
  882. }
  883. ///
  884. public void r2b_notify_setTeamData(string playerId, dynamic data)
  885. {
  886. var player = getPlayer(playerId);
  887. if (player != null)
  888. {
  889. TeamDataEventR2B r2b = new TeamDataEventR2B();
  890. r2b.LeaderId = data.leaderId;
  891. r2b.TeamMembers = new List<TeamMemberEventR2B>();
  892. foreach (dynamic obj in data.members)
  893. {
  894. TeamMemberEventR2B mbr = new TeamMemberEventR2B();
  895. mbr.followLeader = (int)obj.followLeader;
  896. mbr.uuid = obj.uuid;
  897. r2b.TeamMembers.Add(mbr);
  898. }
  899. player.ReceiveMsgR2B(r2b);
  900. }
  901. }
  902. #endregion
  903. //----------------------------------------------------------------------------------------------
  904. #region _获取动态数据_
  905. /// <summary>
  906. /// 获取地图上所有enable的区域
  907. /// </summary>
  908. /// <param name="instanceId"></param>
  909. /// <returns></returns>
  910. public void r2b_get_getZoneRegions(string instanceId, Action<List<EdgeRegionData>> cb, Action<Exception> err)
  911. {
  912. var node = getZoneNode(instanceId);
  913. if (node != null)
  914. {
  915. node.Node.QueueTaskAsync((zone) =>
  916. {
  917. try
  918. {
  919. List<RegionData> regions = zone.Data.Regions;
  920. List<EdgeRegionData> edgeRegions = new List<EdgeRegionData>();
  921. foreach (RegionData rd in regions)
  922. {
  923. var flag = zone.getFlag(rd.Name);
  924. if (flag != null && flag.Enable)
  925. {
  926. EdgeRegionData eRd = new EdgeRegionData(rd);
  927. eRd.Enable = true;
  928. edgeRegions.Add(eRd);
  929. }
  930. }
  931. cb(edgeRegions);
  932. }
  933. catch (Exception e)
  934. {
  935. err(e);
  936. }
  937. });
  938. }
  939. else
  940. {
  941. err(new InstanceNotExistException(instanceId));
  942. }
  943. }
  944. /// <summary>
  945. /// 获取地图上所有enable的区域
  946. /// </summary>
  947. /// <param name="playerId"></param>
  948. /// <returns></returns>
  949. public void r2b_get_canUseItem(string playerId, Action<bool> cb, Action<Exception> err)
  950. {
  951. XmdsPlayer player = getPlayer(playerId);
  952. if (player != null)
  953. {
  954. //player.Node.QueueTaskAsync(() =>
  955. //{
  956. // try
  957. // {
  958. XmdsVirtual zv = (XmdsVirtual)player.BindingActor.Virtual;
  959. cb(zv.CanUseItem());
  960. // }
  961. // catch (Exception e)
  962. // {
  963. // err(e);
  964. // }
  965. //});
  966. }
  967. else
  968. {
  969. err(new PlayerNotExistException(playerId));
  970. }
  971. }
  972. /// <summary>
  973. /// 获取该地图的所有unit
  974. /// </summary>
  975. /// <param name="instanceId"></param>
  976. /// <returns></returns>
  977. public void r2b_get_getAllUnitInfo(string instanceId, Action<List<UnitInfo>> cb, Action<Exception> err)
  978. {
  979. var node = getZoneNode(instanceId);
  980. if (node != null)
  981. {
  982. node.Node.QueueTaskAsync((zone) =>
  983. {
  984. var units = new List<InstanceUnit>();
  985. zone.GetAllUnits(units);
  986. List<UnitInfo> ret = new List<UnitInfo>();
  987. foreach (InstanceUnit unit in units)
  988. {
  989. CommonAI.ZoneClient.SyncUnitInfo syncInfo = unit.GenSyncUnitInfo();
  990. UnitInfo info = new UnitInfo();
  991. info.type = unit.GetType().Name;
  992. info.ObjectId = syncInfo.ObjectID;
  993. info.force = syncInfo.Force;
  994. info.templateId = syncInfo.TemplateID;
  995. info.playerId = syncInfo.PlayerUUID;
  996. info.x = syncInfo.x;
  997. info.y = syncInfo.y;
  998. ret.Add(info);
  999. }
  1000. cb(ret);
  1001. });
  1002. }
  1003. else
  1004. {
  1005. err(new InstanceNotExistException(instanceId));
  1006. }
  1007. }
  1008. /// <summary>
  1009. /// 获取该地图的所有npc
  1010. /// </summary>
  1011. /// <param name="instanceId"></param>
  1012. /// <returns></returns>
  1013. public void r2b_get_getAllNpcInfo(string instanceId, Action<List<UnitInfo>> cb, Action<Exception> err)
  1014. {
  1015. try
  1016. {
  1017. var node = getZoneNode(instanceId);
  1018. if (node != null)
  1019. {
  1020. //node.Node.QueueTaskAsync((zone) =>
  1021. //{
  1022. List<InstanceUnit> units = new List<InstanceUnit>();
  1023. node.Node.Zone.GetAllUnits(units);
  1024. List<UnitInfo> ret = new List<UnitInfo>();
  1025. foreach (InstanceUnit unit in units)
  1026. {
  1027. if (unit.Info.UType == CommonAI.Zone.UnitInfo.UnitType.TYPE_NPC)
  1028. {
  1029. CommonAI.ZoneClient.SyncUnitInfo syncInfo = unit.GenSyncUnitInfo();
  1030. UnitInfo info = new UnitInfo();
  1031. UnitData data = (UnitData)unit.GetAttribute("UnitData");
  1032. string[] attributes = data == null ? null : data.Attributes;
  1033. //string[] attributes = unit.Info.Attributes;
  1034. if (attributes != null && attributes.Length > 0)
  1035. {
  1036. info.unitType = attributes[0];
  1037. }
  1038. else
  1039. {
  1040. info.unitType = "";
  1041. }
  1042. info.name = unit.Name;
  1043. info.type = unit.GetType().Name;
  1044. info.ObjectId = syncInfo.ObjectID;
  1045. info.force = syncInfo.Force;
  1046. info.templateId = syncInfo.TemplateID;
  1047. info.playerId = syncInfo.PlayerUUID;
  1048. info.x = syncInfo.x;
  1049. info.y = syncInfo.y;
  1050. ret.Add(info);
  1051. }
  1052. }
  1053. cb(ret);
  1054. return;
  1055. //});
  1056. }
  1057. }
  1058. catch(Exception e)
  1059. {
  1060. log.Warn("r2b_get_getAllNpcInfo catch: " + instanceId + ", " + e);
  1061. }
  1062. cb(new List<UnitInfo>());
  1063. }
  1064. /// <summary>
  1065. /// 获取所有玩家UUID信息
  1066. /// </summary>
  1067. public void r2b_get_getAllPlayerUUID(Action<dynamic> cb, Action<Exception> err)
  1068. {
  1069. GetAllPlayers((e2, ret) =>
  1070. {
  1071. if (e2 != null)
  1072. {
  1073. err(e2);
  1074. }
  1075. else
  1076. {
  1077. dynamic json = new { list = ret };
  1078. cb(json);
  1079. }
  1080. });
  1081. }
  1082. /// <summary>
  1083. /// 玩家基本信息同步
  1084. /// </summary>
  1085. /// <param name="PlayerId"></param>
  1086. /// <returns>副本实例id</returns>
  1087. public void r2b_get_getPlayerData(string playerId, bool changeArea, Action<dynamic> cb, Action<Exception> err)
  1088. {
  1089. XmdsPlayer player = getPlayer(playerId);
  1090. if (player != null && player.BindingActor != null)
  1091. {
  1092. //player.Node.QueueTaskAsync(() =>
  1093. //{
  1094. // try
  1095. // {
  1096. InstancePlayer p = player.BindingActor;
  1097. XmdsUnitProperties prop = p.Properties as XmdsUnitProperties;
  1098. PKInfo pkInfo = prop.ServerData.UnitPKInfo;
  1099. ArrayList skillList = new ArrayList();
  1100. XmdsVirtual zv = (XmdsVirtual)p.Virtual;
  1101. if (changeArea)
  1102. {
  1103. XmdsCommonServer.Plugin.XmdsVirtual.XmdsSkillStatusData skillData = zv.GetSkillStatusData();
  1104. foreach (KeyValuePair<int, long> kvp in skillData.SkillTimestampMSMap)
  1105. {
  1106. int skillId = kvp.Key;
  1107. long skillTime = kvp.Value;
  1108. skillList.Add(new { skillId = skillId, skillTime = skillTime });
  1109. }
  1110. }
  1111. dynamic ret = new
  1112. {
  1113. x = p.X,
  1114. y = p.Y,
  1115. direction = p.Direction,
  1116. hp = p.get_current_hp(),
  1117. mp = p.get_current_mp(),
  1118. pkMode = (int)pkInfo.CurPKMode,
  1119. pkValue = pkInfo.CurPKValue,
  1120. pkLevel = (int)pkInfo.CurPKLevel,
  1121. skillData = skillList,
  1122. combatState = zv.CombatState
  1123. };
  1124. cb(ret);
  1125. // }
  1126. // catch (Exception e)
  1127. // {
  1128. // err(e);
  1129. // }
  1130. //});
  1131. }
  1132. else
  1133. {
  1134. //err(new PlayerNotExistException(playerId));
  1135. cb(null);
  1136. }
  1137. }
  1138. /// <summary>
  1139. /// 玩家宠物基本信息同步
  1140. /// </summary>
  1141. /// <param name="PlayerId"></param>
  1142. /// <returns>副本实例id</returns>
  1143. public void r2b_get_getPlayerPetData(string playerId, Action<dynamic> cb, Action<Exception> err)
  1144. {
  1145. try
  1146. {
  1147. do
  1148. {
  1149. if (string.IsNullOrEmpty(playerId))
  1150. {
  1151. log.Error("那个sx传过来一个空玩家信息:");
  1152. break; ;
  1153. }
  1154. XmdsPlayer player = getPlayer(playerId);
  1155. if (player != null && player.BindingActor != null)
  1156. {
  1157. XmdsVirtual_Player zv = (XmdsVirtual_Player)player.BindingActor.Virtual;
  1158. if(zv == null)
  1159. {
  1160. break;
  1161. }
  1162. XmdsVirtual_Pet petData = zv.GetPet();
  1163. if (petData == null)
  1164. {
  1165. log.Warn("找不到玩家对应宠物信息:" + playerId);
  1166. break; ;
  1167. }
  1168. dynamic ret = new
  1169. {
  1170. hp = petData.mUnit.CurrentHP,
  1171. mp = petData.mUnit.CurrentMP,
  1172. };
  1173. cb(ret);
  1174. return;
  1175. }
  1176. } while (false);
  1177. }
  1178. catch(Exception e)
  1179. {
  1180. log.Error("r2b_get_getPlayerPetData : " + playerId + ", " + e);
  1181. }
  1182. dynamic retFinal = new
  1183. {
  1184. hp = -1,
  1185. mp = -1,
  1186. };
  1187. cb(retFinal);
  1188. }
  1189. /// <summary>
  1190. /// 玩家基本信息同步
  1191. /// </summary>
  1192. /// <param name="PlayerId"></param>
  1193. /// <returns>副本实例id</returns>
  1194. public void r2b_get_getPlayerSkillCDTime(string playerId, Action<ArrayList> cb, Action<Exception> err)
  1195. {
  1196. XmdsPlayer player = getPlayer(playerId);
  1197. if (player != null)
  1198. {
  1199. //player.Node.QueueTaskAsync(() =>
  1200. //{
  1201. try
  1202. {
  1203. ArrayList skillList = new ArrayList();
  1204. global::XmdsCommonServer.Plugin.XmdsVirtual zv = (global::XmdsCommonServer.Plugin.XmdsVirtual)player.BindingActor.Virtual;
  1205. global::XmdsCommonServer.Plugin.XmdsVirtual.XmdsSkillStatusData skillData = zv.GetSkillStatusData();
  1206. foreach (KeyValuePair<int, long> kvp in skillData.SkillTimestampMSMap)
  1207. {
  1208. int skillId = kvp.Key;
  1209. long skillTime = kvp.Value;
  1210. skillList.Add(new { skillId = skillId, skillTime = skillTime });
  1211. }
  1212. cb(skillList);
  1213. }
  1214. catch (Exception e)
  1215. {
  1216. err(e);
  1217. }
  1218. //});
  1219. }
  1220. else
  1221. {
  1222. err(new PlayerNotExistException(playerId));
  1223. }
  1224. }
  1225. public void r2b_get_CanTalkWithNpc(string playerId, uint npcId, Action<dynamic> cb, Action<Exception> err)
  1226. {
  1227. XmdsPlayer player = getPlayer(playerId);
  1228. if (player != null)
  1229. {
  1230. //player.Node.QueueTaskAsync(() =>
  1231. //{
  1232. InstancePlayer src = player.BindingActor;
  1233. InstanceUnit dst = null;
  1234. if (src != null && (dst = src.Parent.getUnit(npcId)) != null)
  1235. {
  1236. dynamic ret = new
  1237. {
  1238. templateId = dst.Info.TemplateID,
  1239. canTalk = CMath.intersectRound(
  1240. src.X, src.Y, src.BodyBlockSize + 5,
  1241. dst.X, dst.Y, dst.BodyBlockSize),
  1242. };
  1243. cb(ret);
  1244. return;
  1245. }
  1246. //});
  1247. }
  1248. cb(new
  1249. {
  1250. templateId = 0,
  1251. canTalk = false,
  1252. });
  1253. }
  1254. /// <summary>
  1255. /// 玩家基本信息同步
  1256. /// </summary>
  1257. /// <param name="PlayerId"></param>
  1258. /// <returns>副本实例id</returns>
  1259. public void r2b_get_getPlayerPKInfoData(string playerId, Action<dynamic> cb, Action<Exception> err)
  1260. {
  1261. XmdsPlayer player = getPlayer(playerId);
  1262. if (player != null)
  1263. {
  1264. //player.Node.QueueTaskAsync(() =>
  1265. //{
  1266. //try
  1267. //{
  1268. XmdsUnitProperties prop = player.BindingActor.Properties as XmdsUnitProperties;
  1269. PKInfo pkInfo = prop.ServerData.UnitPKInfo;
  1270. dynamic ret = new
  1271. {
  1272. pkMode = (int)pkInfo.CurPKMode,
  1273. pkValue = pkInfo.CurPKValue,
  1274. pkLevel = (int)pkInfo.CurPKLevel
  1275. };
  1276. cb(ret);
  1277. //}
  1278. //catch (Exception e)
  1279. //{
  1280. // err(e);
  1281. //}
  1282. //});
  1283. }
  1284. else
  1285. {
  1286. err(new PlayerNotExistException(playerId));
  1287. }
  1288. }
  1289. public void r2b_request_autoBattle(string instanceId, string playerId, bool enable)
  1290. {
  1291. var node = getZoneNode(instanceId);
  1292. if (node != null)
  1293. {
  1294. node.Node.QueueTaskAsync((zone) =>
  1295. {
  1296. InstanceUnit u = zone.getPlayerByUUID(playerId.ToString());
  1297. if (u != null)
  1298. {
  1299. UnitGuardAction guard = new UnitGuardAction();
  1300. guard.guard = enable;
  1301. guard.object_id = u.ID;
  1302. guard.forceNotify = true;
  1303. u.Parent.pushAction(guard);
  1304. log.Debug("--------autoBattle from gs: playerId=" + playerId + " area=" + node.Node.Name + " instanceId=" + instanceId);
  1305. }
  1306. else
  1307. {
  1308. log.Error("r2b_request_autoBattle PlayerNotExistException: playerId =" + playerId + " area=" + node.Node.Name);
  1309. }
  1310. });
  1311. }
  1312. }
  1313. public void r2b_request_getPlayerStatistic(string instanceId, string playerId, int flag, Action<dynamic> cb, Action<Exception> err)
  1314. {
  1315. try
  1316. {
  1317. var node = getZoneNode(instanceId);
  1318. var player = getPlayer(playerId);
  1319. if (player != null && node != null)
  1320. {
  1321. if (flag == 0)
  1322. {
  1323. node.Node.ForEachPlayers((client) =>
  1324. {
  1325. var insPlayer = client.Actor;
  1326. if (insPlayer != null)
  1327. {
  1328. insPlayer.Statistic.Reset();
  1329. }
  1330. });
  1331. cb(null);
  1332. return;
  1333. }
  1334. else
  1335. {
  1336. dynamic statistic = new Dictionary<string, dynamic>();
  1337. node.Node.ForEachPlayers((client) =>
  1338. {
  1339. var insPlayer = client.Actor;
  1340. if (insPlayer != null)
  1341. {
  1342. statistic[insPlayer.PlayerUUID] = new
  1343. {
  1344. totalDamage = insPlayer.Statistic.TotalDamage,
  1345. totalHealing = insPlayer.Statistic.TotalHealing,
  1346. //killPlayerCount = insPlayer.Statistic.KillPlayerCount,
  1347. //killUnitCount = insPlayer.Statistic.KillUnitCount,
  1348. //deadCount = insPlayer.Statistic.DeadCount,
  1349. SelfDamage = insPlayer.Statistic.SelfDamage
  1350. };
  1351. }
  1352. });
  1353. cb(statistic);
  1354. return;
  1355. }
  1356. }
  1357. }
  1358. catch(Exception e)
  1359. {
  1360. log.Error("r2b_request_getPlayerStatistic catch: " + playerId + ", " + instanceId + ", " + flag + ", " + e);
  1361. }
  1362. string notifyMsg = "r2b_request_getPlayerStatistic error: " + playerId + ", " + instanceId + ", " + flag;
  1363. log.Error(notifyMsg);
  1364. cb(notifyMsg);
  1365. }
  1366. public void r2b_request_getInstanceStatistic(string instanceId, Action<dynamic> cb, Action<Exception> err)
  1367. {
  1368. var node = getZoneNode(instanceId);
  1369. if (node != null)
  1370. {
  1371. dynamic statistic = new Dictionary<string, dynamic>();
  1372. node.Node.ForEachPlayers((client) =>
  1373. {
  1374. var insPlayer = client.Actor;
  1375. if (insPlayer != null)
  1376. {
  1377. statistic[insPlayer.PlayerUUID] = new
  1378. {
  1379. totalDamage = insPlayer.Statistic.TotalDamage,
  1380. totalHealing = insPlayer.Statistic.TotalHealing,
  1381. killPlayerCount = insPlayer.Statistic.KillPlayerCount,
  1382. killUnitCount = insPlayer.Statistic.KillUnitCount,
  1383. deadCount = insPlayer.Statistic.DeadCount
  1384. };
  1385. }
  1386. });
  1387. cb(statistic);
  1388. }
  1389. else
  1390. {
  1391. log.Error("r2b_request_getInstanceStatistic: InstanceNotExistException: instanceId =" + instanceId);
  1392. cb(null);
  1393. return;
  1394. }
  1395. }
  1396. /// <summary>
  1397. /// 玩家更换技能
  1398. /// </summary>
  1399. /// <param name="instanceId"></param>
  1400. /// <returns>副本实例id</returns>
  1401. ///
  1402. public void r2b_notify_playerChangeSkill(string playerId, int oldSkillID, int newSkillID, dynamic data)
  1403. {
  1404. var player = getPlayer(playerId);
  1405. if (player != null)
  1406. {
  1407. XmdsInstancePlayer instancePlayer = player.getInstancePlayer() as XmdsInstancePlayer;
  1408. if (instancePlayer == null)
  1409. {
  1410. return;
  1411. }
  1412. SkillLevelData levelData = null;
  1413. if (data != null)
  1414. {
  1415. levelData = new SkillLevelData();
  1416. levelData.SkillLevel = data.level;
  1417. levelData.TalentSkillLevel1 = data.talentLevel[0];
  1418. levelData.TalentSkillLevel2 = data.talentLevel[1];
  1419. levelData.TalentSkillLevel3 = data.talentLevel[2];
  1420. levelData.skillType = (XmdsSkillType)data.skillType;
  1421. }
  1422. instancePlayer.PlayerChangeSkill(oldSkillID, newSkillID, levelData);
  1423. //player.get
  1424. //XmdsUnitSkillInfo skillData = XmdsPlayerUtil.instance()
  1425. }
  1426. }
  1427. /// <summary>
  1428. /// 玩家基本信息同步
  1429. /// </summary>
  1430. /// <param name="playerId"></param>
  1431. /// <returns></returns>
  1432. public bool r2b_notify_transferToPointPos(string instanceId, string playerId, string refreshPoint, bool setDirction, float direction)
  1433. {
  1434. var node = getZoneNode(instanceId);
  1435. if (node == null)
  1436. {
  1437. return false;
  1438. }
  1439. var player = getPlayer(playerId);
  1440. if (player == null)
  1441. {
  1442. return false;
  1443. }
  1444. InstanceFlag flag = node.Node.Zone.getFlag(refreshPoint);
  1445. if (flag == null)
  1446. {
  1447. return false;
  1448. }
  1449. if (flag is ZoneWayPoint)
  1450. {
  1451. // Region随机取一个坐标
  1452. var v2 = (flag as ZoneWayPoint).getRandomPos(node.Node.Zone.RandomN);
  1453. player.getInstancePlayer().transport(v2.X, v2.Y, setDirction, direction);
  1454. return true;
  1455. }
  1456. return false;
  1457. }
  1458. /// <summary>
  1459. /// 更改玩家状态
  1460. /// </summary>
  1461. /// <param name="playerId"></param>
  1462. /// <returns></returns>
  1463. public void r2b_notify_changePlayerStatus(string instanceId, string playerId, byte status, int time)
  1464. {
  1465. if(status != (byte)UnitActionStatus.DaZuo && status != (byte)UnitActionStatus.ClearYaoQi
  1466. && status != (byte)UnitActionStatus.Idle && status != (byte)UnitActionStatus.CrossRobbery
  1467. && status != (byte)UnitActionStatus.DaZuoRecoveryAttr)
  1468. {
  1469. return;
  1470. }
  1471. var node = getZoneNode(instanceId);
  1472. if (node == null)
  1473. {
  1474. return ;
  1475. }
  1476. var player = getPlayer(playerId);
  1477. if (player == null)
  1478. {
  1479. return ;
  1480. }
  1481. var instancePlayer = player.getInstancePlayer();
  1482. if(instancePlayer == null)
  1483. {
  1484. return;
  1485. }
  1486. //if(status == (byte)UnitActionStatus.ChuanGongA)
  1487. //{
  1488. // instancePlayer.changeState(new StateChuanGongA(instancePlayer), false);
  1489. //}
  1490. //else if(status == (byte)UnitActionStatus.ChuanGongB)
  1491. //{
  1492. // instancePlayer.changeState(new StateChuanGongB(instancePlayer), false);
  1493. //}
  1494. //else
  1495. if(status == (byte)UnitActionStatus.DaZuo)
  1496. {
  1497. instancePlayer.Virtual.TakeOffMount();
  1498. instancePlayer.changeState(new StateDaZuo(instancePlayer, time), false);
  1499. }
  1500. else if (status == (byte) UnitActionStatus.DaZuoRecoveryAttr)
  1501. {
  1502. //非战斗状态,才能打坐回血
  1503. if (instancePlayer.Virtual.GetBattleStatus() <= BattleStatus.ReadyBattle && (instancePlayer.CurrentActionStatus != UnitActionStatus.DaZuoRecoveryAttr) && (instancePlayer.CurrentActionStatus != UnitActionStatus.Move) )
  1504. {
  1505. instancePlayer.Virtual.TakeOffMount();
  1506. instancePlayer.changeState(new StateDaZuoRecoveryAttr(instancePlayer, time), false);
  1507. }
  1508. }
  1509. else if(status == (byte)UnitActionStatus.ClearYaoQi)
  1510. {
  1511. instancePlayer.Virtual.TakeOffMount();
  1512. instancePlayer.changeState(new StateClearYaoQi(instancePlayer), false);
  1513. }
  1514. else if (status == (byte)UnitActionStatus.Idle)
  1515. {
  1516. if(instancePlayer.CurrentActionStatus == UnitActionStatus.DaZuo || instancePlayer.CurrentActionStatus == UnitActionStatus.ChuanGongA
  1517. || instancePlayer.CurrentActionStatus == UnitActionStatus.ChuanGongB || instancePlayer.CurrentActionStatus == UnitActionStatus.DaZuoRecoveryAttr)
  1518. {
  1519. instancePlayer.CurrentState.MarkRemove();
  1520. }
  1521. }
  1522. else if(status == (byte)UnitActionStatus.CrossRobbery)
  1523. {
  1524. instancePlayer.Virtual.TakeOffMount();
  1525. instancePlayer.changeState(new StateDuJie(instancePlayer), false);
  1526. }
  1527. }
  1528. /// <summary>
  1529. /// 更改玩家状态
  1530. /// </summary>
  1531. /// <param name="playerId"></param>
  1532. /// <returns></returns>
  1533. public void r2b_notify_playerChuanGong(string instanceId, string playerIdA, string playerIdB)
  1534. {
  1535. var node = getZoneNode(instanceId);
  1536. if (node == null)
  1537. {
  1538. return;
  1539. }
  1540. var playerA = getPlayer(playerIdA);
  1541. var playerB = getPlayer(playerIdB);
  1542. if (playerA == null || playerB == null)
  1543. {
  1544. return;
  1545. }
  1546. var instancePlayerA = playerA.getInstancePlayer();
  1547. var instancePlayerB = playerB.getInstancePlayer();
  1548. if (instancePlayerA == null || instancePlayerB == null)
  1549. {
  1550. return;
  1551. }
  1552. instancePlayerA.Virtual.TakeOffMount();
  1553. instancePlayerB.Virtual.TakeOffMount();
  1554. instancePlayerA.changeState(new StateChuanGongA(instancePlayerA), false);
  1555. instancePlayerB.changeState(new StateChuanGongB(instancePlayerB), false);
  1556. //接受传功者,pos和方向设置
  1557. instancePlayerB.faceTo(instancePlayerA.Direction);
  1558. float xAdd = (float)(2 * Math.Cos(instancePlayerA.Direction)); //角Dir的对边
  1559. float yAdd = (float)(2 * Math.Sin(instancePlayerA.Direction)); //Dir的邻边
  1560. instancePlayerB.setPos(instancePlayerA.X + xAdd, instancePlayerA.Y + yAdd);
  1561. }
  1562. /** 通知山大王延时刷新 */
  1563. public void r2b_notifyMountainKingRefresh(string instanceId, string data)
  1564. {
  1565. var node = getZoneNode(instanceId);
  1566. if (node == null)
  1567. {
  1568. return;
  1569. }
  1570. List<KingRefreshData> refreshList = new List<KingRefreshData>();
  1571. dynamic propertyData = Json.Decode(data);
  1572. foreach(var temp in propertyData)
  1573. {
  1574. refreshList.Add(new KingRefreshData(temp.monsterId, temp.nextRefreshTime));
  1575. }
  1576. if(refreshList.Count > 0)
  1577. {
  1578. JSGMountainKingModule.OnMonsterRefreshNotify(node.GetBindGameSrvId(), refreshList);
  1579. }
  1580. }
  1581. #endregion
  1582. //----------------------------------------------------------------------------------------------
  1583. }
  1584. }