InstanceZone.API.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using CommonLang;
  5. using CommonAI.Zone.Helper;
  6. namespace CommonAI.Zone.Instance
  7. {
  8. /// <summary>
  9. /// 代理用类
  10. /// </summary>
  11. partial class InstanceZone
  12. {
  13. private InstanceUnit mLastAddedUnit;
  14. private InstanceUnit mLastActivatedUnit;
  15. private InstanceUnit mLastRebirthUnit;
  16. private InstanceUnit mLastHittedUnit;
  17. private InstanceUnit mLastAttackUnit;
  18. private InstanceUnit mLastKilledUnit;
  19. private InstanceItem mLastCreatedInstanceItem;
  20. private InstanceItem mLastUnitGotInstanceItem;
  21. private ItemTemplate mLastUnitGotItem;
  22. private ItemTemplate mLastUnitLostItem;
  23. private ItemTemplate mLastUnitUseItem;
  24. private BuffTemplate mLastUnitGotBuff;
  25. private InstanceUnit mLastPickingItemUnit;
  26. private InstanceItem mLastPickingItem;
  27. private InstanceUnit mLastPickableUnit;
  28. private InstanceUnit mLastLaunchSkillUnit;
  29. private SkillTemplate mLastLaunchSkill;
  30. private SpellTemplate mLastLaunchSpell;
  31. private ZoneServer.SendMessageR2B mLastRecvMessageR2B;
  32. private ZoneServer.SendMessageB2R mLastSentMessageB2R;
  33. //当前场景类型
  34. protected CommonAI.Data.SceneType mSceneType;
  35. public InstanceUnit LastAddedUnit
  36. {
  37. get { return mLastAddedUnit; }
  38. private set { if (value != null) mLastAddedUnit = value; }
  39. }
  40. public InstanceUnit LastActivatedUnit
  41. {
  42. get { return mLastActivatedUnit; }
  43. private set { if (value != null) mLastActivatedUnit = value; }
  44. }
  45. public InstanceUnit LastRebirthUnit
  46. {
  47. get { return mLastRebirthUnit; }
  48. private set { if (value != null) mLastRebirthUnit = value; }
  49. }
  50. public InstanceUnit LastHittedUnit
  51. {
  52. get { return mLastHittedUnit; }
  53. private set { if (value != null) mLastHittedUnit = value; }
  54. }
  55. public InstanceUnit LastAttackUnit
  56. {
  57. get { return mLastAttackUnit; }
  58. private set { if (value != null) mLastAttackUnit = value; }
  59. }
  60. public InstanceUnit LastKilledUnit
  61. {
  62. get { return mLastKilledUnit; }
  63. private set { if (value != null) mLastKilledUnit = value; }
  64. }
  65. public InstanceItem LastCreatedInstanceItem
  66. {
  67. get { return mLastCreatedInstanceItem; }
  68. private set { if (value != null) mLastCreatedInstanceItem = value; }
  69. }
  70. public InstanceItem LastUnitGotInstanceItem
  71. {
  72. get { return mLastUnitGotInstanceItem; }
  73. private set { if (value != null) mLastUnitGotInstanceItem = value; }
  74. }
  75. public ItemTemplate LastUnitGotInventoryItem
  76. {
  77. get { return mLastUnitGotItem; }
  78. private set { if (value != null) mLastUnitGotItem = value; }
  79. }
  80. public ItemTemplate LastUnitLostInventoryItem
  81. {
  82. get { return mLastUnitLostItem; }
  83. private set { if (value != null) mLastUnitLostItem = value; }
  84. }
  85. public ItemTemplate LastUnitUseItem
  86. {
  87. get { return mLastUnitUseItem; }
  88. private set { if (value != null) mLastUnitUseItem = value; }
  89. }
  90. public BuffTemplate LastUnitGotBuff
  91. {
  92. get { return mLastUnitGotBuff; }
  93. private set { if (value != null) mLastUnitGotBuff = value; }
  94. }
  95. public InstanceUnit LastPickingItemUnit
  96. {
  97. get { return mLastPickingItemUnit; }
  98. private set { if (value != null) mLastPickingItemUnit = value; }
  99. }
  100. public InstanceItem LastPickingItem
  101. {
  102. get { return mLastPickingItem; }
  103. private set { if (value != null) mLastPickingItem = value; }
  104. }
  105. public InstanceUnit LastPickableUnit
  106. {
  107. get { return mLastPickableUnit; }
  108. private set { if (value != null) mLastPickableUnit = value; }
  109. }
  110. public InstanceUnit LastLaunchSkillUnit
  111. {
  112. get { return mLastLaunchSkillUnit; }
  113. private set { if (value != null) mLastLaunchSkillUnit = value; }
  114. }
  115. public SkillTemplate LastLaunchSkill
  116. {
  117. get { return mLastLaunchSkill; }
  118. private set { if (value != null) mLastLaunchSkill = value; }
  119. }
  120. public SpellTemplate LastLaunchSpell
  121. {
  122. get { return mLastLaunchSpell; }
  123. private set { if (value != null) mLastLaunchSpell = value; }
  124. }
  125. public ZoneServer.SendMessageR2B LastRecvMessageR2B
  126. {
  127. get { return mLastRecvMessageR2B; }
  128. private set { if (value != null) mLastRecvMessageR2B = value; }
  129. }
  130. public ZoneServer.SendMessageB2R LastSentMessageB2R
  131. {
  132. get { return mLastSentMessageB2R; }
  133. private set { if (value != null) mLastSentMessageB2R = value; }
  134. }
  135. private void beginEventsRecord()
  136. {
  137. // mLastAddedUnit = null;
  138. // mLastActivatedUnit = null;
  139. // mLastRebirthUnit = null;
  140. // mLastHittedUnit = null;
  141. // mLastAttackUnit = null;
  142. // mLastKilledUnit = null;
  143. //
  144. // mLastCreatedInstanceItem = null;
  145. // mLastUnitGotInstanceItem = null;
  146. //
  147. // mLastUnitGotItem = null;
  148. // mLastUnitLostItem = null;
  149. // mLastUnitUseItem = null;
  150. // mLastUnitGotBuff = null;
  151. //
  152. // mLastPickingItemUnit = null;
  153. // mLastPickingItem = null;
  154. // mLastPickableUnit = null;
  155. //
  156. // mLastLaunchSkillUnit = null;
  157. // mLastLaunchSkill = null;
  158. // mLastLaunchSpell = null;
  159. //
  160. // mLastRecvMessageR2B = null;
  161. // mLastSentMessageB2R = null;
  162. }
  163. private HashMap<int, int> mForceTotalDead = new HashMap<int, int>();
  164. public int GetTotalForceDead(byte force)
  165. {
  166. int ret = 0;
  167. mForceTotalDead.TryGetValue(force, out ret);
  168. return ret;
  169. }
  170. private void statisticForceDead(InstanceUnit unit)
  171. {
  172. int ret = 0;
  173. mForceTotalDead.TryGetValue(unit.Force, out ret);
  174. ret += 1;
  175. mForceTotalDead[unit.Force] = ret;
  176. }
  177. #region LUA_API
  178. public int get_total_width()
  179. {
  180. return TotalWidth;
  181. }
  182. public int get_total_height()
  183. {
  184. return TotalHeight;
  185. }
  186. public int get_grid_cell_w()
  187. {
  188. return GridCellW;
  189. }
  190. public int get_grid_cell_h()
  191. {
  192. return GridCellH;
  193. }
  194. public int get_x_count()
  195. {
  196. return XCount;
  197. }
  198. public int get_y_count()
  199. {
  200. return YCount;
  201. }
  202. public ulong get_tick()
  203. {
  204. return Tick;
  205. }
  206. public long get_pass_time_ms()
  207. {
  208. return PassTimeMS;
  209. }
  210. public Random get_random()
  211. {
  212. return RandomN;
  213. }
  214. public bool is_attribute(string key)
  215. {
  216. return IsAttribute(key);
  217. }
  218. public void set_attribute(string key, object value)
  219. {
  220. SetAttribute(key, value);
  221. }
  222. public object get_attribute(string key)
  223. {
  224. return GetAttribute(key);
  225. }
  226. public InstanceUnit get_edit_unit(string name)
  227. {
  228. return GetEditUnit(name);
  229. }
  230. public InstanceFlag get_edit_flag(string name)
  231. {
  232. return GetEditFlag(name);
  233. }
  234. //public TimeTaskMS add_time_task_ms(int interval, int delay, int repeat, TickHandler handler)
  235. //{
  236. // return AddTimeTask(interval, delay, repeat, handler);
  237. //}
  238. //public TimeTaskMS add_time_delay_ms(int delay, TickHandler handler)
  239. //{
  240. // return AddTimeDelayMS(delay, handler);
  241. //}
  242. //public TimeTaskMS add_time_periodic_ms(int interval, TickHandler handler)
  243. //{
  244. // return AddTimePeriodicMS(interval, handler);
  245. //}
  246. public void do_client_script(string filename)
  247. {
  248. DoClientScript(filename);
  249. }
  250. public bool send_script_command(string reason)
  251. {
  252. return SendScriptCommand(reason);
  253. }
  254. public bool send_game_over(int force, string reason)
  255. {
  256. return GameOver(force, reason);
  257. }
  258. public InstanceUnit add_unit(int templateID, string name, byte force, int level, float x, float y, float direction)
  259. {
  260. return AddUnit(templateID, name, force, level, x, y, direction, false);
  261. }
  262. public InstanceItem add_item(int templateID, string name, byte force, float x, float y)
  263. {
  264. ItemTemplate info = Templates.getItem(templateID);
  265. if (info != null)
  266. {
  267. return AddItem(info, name, x, y, CMath.RandomAngle(RandomN), force, name, null,0);
  268. }
  269. return null;
  270. }
  271. public InstanceUnit GetEditUnit(string name)
  272. {
  273. return getUnitByName(name);
  274. }
  275. public InstanceFlag GetEditFlag(string name)
  276. {
  277. return getFlag(name);
  278. }
  279. public void DoClientScript(string filename)
  280. {
  281. DoScriptEvent evt = new DoScriptEvent(filename);
  282. queueEvent(evt);
  283. }
  284. public bool SendScriptCommand(string reason)
  285. {
  286. queueEvent(new ScriptCommandEvent(reason));
  287. return true;
  288. }
  289. public bool GameOver(int force, string reason)
  290. {
  291. queueEvent(new GameOverEvent(force, reason));
  292. return true;
  293. }
  294. [Obsolete]
  295. public List<InstanceUnit> GetAllUnits()
  296. {
  297. return new List<InstanceUnit>(this.AllUnits);
  298. }
  299. public void GetAllUnits(List<InstanceUnit> ret)
  300. {
  301. ret.AddRange(this.AllUnits);
  302. }
  303. public int GetAllUnitsCount()
  304. {
  305. return this.AllUnitsCount;
  306. }
  307. [Obsolete]
  308. public List<InstanceUnit> GetForceUnits(byte force)
  309. {
  310. List<InstanceUnit> ret = new List<InstanceUnit>(this.AllUnitsCount);
  311. foreach (InstanceUnit u in this.AllUnits)
  312. {
  313. if (u.Force == force)
  314. {
  315. ret.Add(u);
  316. }
  317. }
  318. return ret;
  319. }
  320. public void GetForceUnits(byte force, List<InstanceUnit> ret)
  321. {
  322. foreach (InstanceUnit u in this.AllUnits)
  323. {
  324. if (u.Force == force)
  325. {
  326. ret.Add(u);
  327. }
  328. }
  329. }
  330. public int GetForceUnitsCount(byte force)
  331. {
  332. int Count = 0;
  333. foreach (InstanceUnit u in this.AllUnits)
  334. {
  335. if (u.Force == force)
  336. {
  337. Count++;
  338. }
  339. }
  340. return Count;
  341. }
  342. public CommonAI.Data.SceneType SceneType
  343. {
  344. get { return mSceneType; }
  345. }
  346. #endregion
  347. }
  348. }