ZoneServiceICE.cs 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687
  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() + ", " +
  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.Error("找不到玩家对应宠物信息:" + 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 playerId, Action<int> cb, Action<Exception> err)
  1314. {
  1315. var player = getPlayer(playerId);
  1316. if (player != null)
  1317. {
  1318. //player.Node.QueueTaskAsync(() =>
  1319. //{
  1320. InstancePlayer insPlayer = player.BindingActor;
  1321. dynamic ret = new
  1322. {
  1323. totalDamage = insPlayer.Statistic.TotalDamage,
  1324. totalHealing = insPlayer.Statistic.TotalHealing,
  1325. killPlayerCount = insPlayer.Statistic.KillPlayerCount,
  1326. killUnitCount = insPlayer.Statistic.KillUnitCount,
  1327. deadCount = insPlayer.Statistic.DeadCount
  1328. };
  1329. cb(ret);
  1330. //});
  1331. }
  1332. else
  1333. {
  1334. log.Error("r2b_request_getPlayerStatistic: PlayerNotExistException: playerId =" + playerId);
  1335. cb(0);
  1336. return;
  1337. }
  1338. }
  1339. public void r2b_request_getInstanceStatistic(string instanceId, Action<dynamic> cb, Action<Exception> err)
  1340. {
  1341. var node = getZoneNode(instanceId);
  1342. if (node != null)
  1343. {
  1344. dynamic statistic = new Dictionary<string, dynamic>();
  1345. node.Node.ForEachPlayers((client) =>
  1346. {
  1347. var insPlayer = client.Actor;
  1348. if (insPlayer != null)
  1349. {
  1350. statistic[insPlayer.PlayerUUID] = new
  1351. {
  1352. totalDamage = insPlayer.Statistic.TotalDamage,
  1353. totalHealing = insPlayer.Statistic.TotalHealing,
  1354. killPlayerCount = insPlayer.Statistic.KillPlayerCount,
  1355. killUnitCount = insPlayer.Statistic.KillUnitCount,
  1356. deadCount = insPlayer.Statistic.DeadCount
  1357. };
  1358. }
  1359. });
  1360. cb(statistic);
  1361. }
  1362. else
  1363. {
  1364. log.Error("r2b_request_getInstanceStatistic: InstanceNotExistException: instanceId =" + instanceId);
  1365. cb(null);
  1366. return;
  1367. }
  1368. }
  1369. /// <summary>
  1370. /// 玩家更换技能
  1371. /// </summary>
  1372. /// <param name="instanceId"></param>
  1373. /// <returns>副本实例id</returns>
  1374. ///
  1375. public void r2b_notify_playerChangeSkill(string playerId, int oldSkillID, int newSkillID, dynamic data)
  1376. {
  1377. var player = getPlayer(playerId);
  1378. if (player != null)
  1379. {
  1380. XmdsInstancePlayer instancePlayer = player.getInstancePlayer() as XmdsInstancePlayer;
  1381. if (instancePlayer == null)
  1382. {
  1383. return;
  1384. }
  1385. SkillLevelData levelData = null;
  1386. if (data != null)
  1387. {
  1388. levelData = new SkillLevelData();
  1389. levelData.SkillLevel = data.level;
  1390. levelData.TalentSkillLevel1 = data.talentLevel[0];
  1391. levelData.TalentSkillLevel2 = data.talentLevel[1];
  1392. levelData.TalentSkillLevel3 = data.talentLevel[2];
  1393. levelData.skillType = (XmdsSkillType)data.skillType;
  1394. }
  1395. instancePlayer.PlayerChangeSkill(oldSkillID, newSkillID, levelData);
  1396. //player.get
  1397. //XmdsUnitSkillInfo skillData = XmdsPlayerUtil.instance()
  1398. }
  1399. }
  1400. /// <summary>
  1401. /// 玩家基本信息同步
  1402. /// </summary>
  1403. /// <param name="playerId"></param>
  1404. /// <returns></returns>
  1405. public bool r2b_notify_transferToPointPos(string instanceId, string playerId, string refreshPoint, bool setDirction, float direction)
  1406. {
  1407. var node = getZoneNode(instanceId);
  1408. if (node == null)
  1409. {
  1410. return false;
  1411. }
  1412. var player = getPlayer(playerId);
  1413. if (player == null)
  1414. {
  1415. return false;
  1416. }
  1417. InstanceFlag flag = node.Node.Zone.getFlag(refreshPoint);
  1418. if (flag == null)
  1419. {
  1420. return false;
  1421. }
  1422. if (flag is ZoneWayPoint)
  1423. {
  1424. // Region随机取一个坐标
  1425. var v2 = (flag as ZoneWayPoint).getRandomPos(node.Node.Zone.RandomN);
  1426. player.getInstancePlayer().transport(v2.X, v2.Y, setDirction, direction);
  1427. return true;
  1428. }
  1429. return false;
  1430. }
  1431. /// <summary>
  1432. /// 更改玩家状态
  1433. /// </summary>
  1434. /// <param name="playerId"></param>
  1435. /// <returns></returns>
  1436. public void r2b_notify_changePlayerStatus(string instanceId, string playerId, byte status, int time)
  1437. {
  1438. if(status != (byte)UnitActionStatus.DaZuo && status != (byte)UnitActionStatus.ClearYaoQi
  1439. && status != (byte)UnitActionStatus.Idle && status != (byte)UnitActionStatus.CrossRobbery
  1440. && status != (byte)UnitActionStatus.DaZuoRecoveryAttr)
  1441. {
  1442. return;
  1443. }
  1444. var node = getZoneNode(instanceId);
  1445. if (node == null)
  1446. {
  1447. return ;
  1448. }
  1449. var player = getPlayer(playerId);
  1450. if (player == null)
  1451. {
  1452. return ;
  1453. }
  1454. var instancePlayer = player.getInstancePlayer();
  1455. if(instancePlayer == null)
  1456. {
  1457. return;
  1458. }
  1459. //if(status == (byte)UnitActionStatus.ChuanGongA)
  1460. //{
  1461. // instancePlayer.changeState(new StateChuanGongA(instancePlayer), false);
  1462. //}
  1463. //else if(status == (byte)UnitActionStatus.ChuanGongB)
  1464. //{
  1465. // instancePlayer.changeState(new StateChuanGongB(instancePlayer), false);
  1466. //}
  1467. //else
  1468. if(status == (byte)UnitActionStatus.DaZuo)
  1469. {
  1470. instancePlayer.Virtual.TakeOffMount();
  1471. instancePlayer.changeState(new StateDaZuo(instancePlayer, time), false);
  1472. }
  1473. else if (status == (byte) UnitActionStatus.DaZuoRecoveryAttr)
  1474. {
  1475. //非战斗状态,才能打坐回血
  1476. if (instancePlayer.Virtual.GetBattleStatus() <= BattleStatus.ReadyBattle && (instancePlayer.CurrentActionStatus != UnitActionStatus.DaZuoRecoveryAttr) && (instancePlayer.CurrentActionStatus != UnitActionStatus.Move) )
  1477. {
  1478. instancePlayer.Virtual.TakeOffMount();
  1479. instancePlayer.changeState(new StateDaZuoRecoveryAttr(instancePlayer, time), false);
  1480. }
  1481. }
  1482. else if(status == (byte)UnitActionStatus.ClearYaoQi)
  1483. {
  1484. instancePlayer.Virtual.TakeOffMount();
  1485. instancePlayer.changeState(new StateClearYaoQi(instancePlayer), false);
  1486. }
  1487. else if (status == (byte)UnitActionStatus.Idle)
  1488. {
  1489. if(instancePlayer.CurrentActionStatus == UnitActionStatus.DaZuo || instancePlayer.CurrentActionStatus == UnitActionStatus.ChuanGongA
  1490. || instancePlayer.CurrentActionStatus == UnitActionStatus.ChuanGongB || instancePlayer.CurrentActionStatus == UnitActionStatus.DaZuoRecoveryAttr)
  1491. {
  1492. instancePlayer.CurrentState.MarkRemove();
  1493. }
  1494. }
  1495. else if(status == (byte)UnitActionStatus.CrossRobbery)
  1496. {
  1497. instancePlayer.Virtual.TakeOffMount();
  1498. instancePlayer.changeState(new StateDuJie(instancePlayer), false);
  1499. }
  1500. }
  1501. /// <summary>
  1502. /// 更改玩家状态
  1503. /// </summary>
  1504. /// <param name="playerId"></param>
  1505. /// <returns></returns>
  1506. public void r2b_notify_playerChuanGong(string instanceId, string playerIdA, string playerIdB)
  1507. {
  1508. var node = getZoneNode(instanceId);
  1509. if (node == null)
  1510. {
  1511. return;
  1512. }
  1513. var playerA = getPlayer(playerIdA);
  1514. var playerB = getPlayer(playerIdB);
  1515. if (playerA == null || playerB == null)
  1516. {
  1517. return;
  1518. }
  1519. var instancePlayerA = playerA.getInstancePlayer();
  1520. var instancePlayerB = playerB.getInstancePlayer();
  1521. if (instancePlayerA == null || instancePlayerB == null)
  1522. {
  1523. return;
  1524. }
  1525. instancePlayerA.Virtual.TakeOffMount();
  1526. instancePlayerB.Virtual.TakeOffMount();
  1527. instancePlayerA.changeState(new StateChuanGongA(instancePlayerA), false);
  1528. instancePlayerB.changeState(new StateChuanGongB(instancePlayerB), false);
  1529. //接受传功者,pos和方向设置
  1530. instancePlayerB.faceTo(instancePlayerA.Direction);
  1531. float xAdd = (float)(2 * Math.Cos(instancePlayerA.Direction)); //角Dir的对边
  1532. float yAdd = (float)(2 * Math.Sin(instancePlayerA.Direction)); //Dir的邻边
  1533. instancePlayerB.setPos(instancePlayerA.X + xAdd, instancePlayerA.Y + yAdd);
  1534. }
  1535. /** 通知山大王延时刷新 */
  1536. public void r2b_notifyMountainKingRefresh(string instanceId, string data)
  1537. {
  1538. var node = getZoneNode(instanceId);
  1539. if (node == null)
  1540. {
  1541. return;
  1542. }
  1543. List<KingRefreshData> refreshList = new List<KingRefreshData>();
  1544. dynamic propertyData = Json.Decode(data);
  1545. foreach(var temp in propertyData)
  1546. {
  1547. refreshList.Add(new KingRefreshData(temp.monsterId, temp.nextRefreshTime));
  1548. }
  1549. if(refreshList.Count > 0)
  1550. {
  1551. JSGMountainKingModule.OnMonsterRefreshNotify(node.GetBindGameSrvId(), refreshList);
  1552. }
  1553. }
  1554. #endregion
  1555. //----------------------------------------------------------------------------------------------
  1556. }
  1557. }