ZoneServiceICE.cs 61 KB

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