ZoneServiceICE.cs 59 KB

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