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