XmdsZoneServerFactory.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. using CommonAI.Zone;
  2. using CommonAI.Zone.Helper;
  3. using CommonAI.Zone.Instance;
  4. using XmdsCommon.Plugin;
  5. using XmdsCommonServer.Plugin.Units;
  6. using XmdsCommonServer.Plugin.Scene;
  7. using CommonAI.Zone.ZoneEditor;
  8. using XmdsCommonServer.Plugin.Quest;
  9. using CommonLang;
  10. using CommonAI.ZoneClient;
  11. using CommonAI.RTS.Manhattan;
  12. using XmdsCommon.ZoneClient;
  13. using CommonAI.Data;
  14. namespace XmdsCommonServer.Plugin
  15. {
  16. /// <summary>
  17. /// FileName: XmdsZoneFactory.cs
  18. /// Author: Alex.Yu
  19. /// Corporation:...
  20. /// Description:
  21. /// DateTime: 2015/1/26 16:15:25
  22. /// </summary>
  23. public class XmdsZoneServerFactory : XmdsZoneFactory
  24. {
  25. private XmdsFormula mFormula = new XmdsFormula();
  26. public override CommonAI.Zone.Formula.IFormula Formula
  27. {
  28. get { return mFormula; }
  29. }
  30. public XmdsZoneServerFactory()
  31. {
  32. }
  33. public override EditorScene CreateEditorScene(TemplateManager templates, InstanceZoneListener listener, SceneData data, GSCreateAreaData createData, string bindGameSrvId)
  34. {
  35. return XmdsSceneFactory.CreateScene(templates, listener, data, createData, bindGameSrvId);
  36. }
  37. public override CommonAI.Zone.Helper.IQuestAdapter CreateQuestAdapter(CommonAI.Zone.Instance.InstanceZone zone)
  38. {
  39. return new XmdsQuestAdapter(zone as XmdsServerScene);
  40. }
  41. public override CommonAI.Zone.Formula.IVirtualUnit CreateUnitVirtual(InstanceUnit owner)
  42. {
  43. XmdsVirtual ret = null;
  44. if (owner is XmdsInstanceMonster)
  45. {
  46. ret = new XmdsVirtual_Monster(owner as XmdsInstanceMonster);
  47. }
  48. else if (owner is XmdsInstancePlayer)
  49. {
  50. ret = new XmdsVirtual_Player(owner as XmdsInstancePlayer);
  51. }
  52. else if (owner is XmdsInstanceNPC)
  53. {
  54. ret = new XmdsVirtual_NPC(owner as XmdsInstanceNPC);
  55. }
  56. else if (owner is XmdsInstanceSummonUnit)
  57. {
  58. ret = new XmdsVirtual_SummonUnit(owner as XmdsInstanceSummonUnit);
  59. }
  60. else if (owner is XmdsInstancePet)
  61. {
  62. ret = new XmdsVirtual_Pet(owner as XmdsInstancePet);
  63. }
  64. else
  65. {
  66. ret = new XmdsVirtual(owner);
  67. }
  68. return ret;
  69. }
  70. public override InstanceUnit CreateUnit(InstanceZone zone, UnitInfo info, string name, int force, int alliesForce, int level)
  71. {
  72. XmdsUnitProperties unit_prop = info.Properties as XmdsUnitProperties;
  73. switch (info.UType)
  74. {
  75. case UnitInfo.UnitType.TYPE_NEUTRALITY:
  76. case UnitInfo.UnitType.TYPE_NPC:
  77. return new XmdsInstanceNPC(zone, info, name, force, level);
  78. case UnitInfo.UnitType.TYPE_SUMMON:
  79. return new XmdsInstanceSummonUnit(zone, info, name, force, level);
  80. case UnitInfo.UnitType.TYPE_MONSTER:
  81. return new XmdsInstanceMonster(zone, info, name, force, level);
  82. case UnitInfo.UnitType.TYPE_PLAYER:
  83. return new XmdsInstancePlayer(zone, info, name, force, alliesForce, level);
  84. case UnitInfo.UnitType.TYPE_PET:
  85. return new XmdsInstancePet(zone, info, name, force, level);
  86. }
  87. return base.CreateUnit(zone, info, name, force, alliesForce, level);
  88. }
  89. public override InstanceItem CreateItem(
  90. InstanceZone zone,
  91. ItemTemplate item,
  92. string name,
  93. int force,
  94. InstanceUnit creater,
  95. string disPlayName,
  96. int from)
  97. {
  98. return new XmdsDropableInstanceItem(zone, item, name, force, creater, disPlayName);
  99. }
  100. public override HateSystem CreateHateSystem(InstanceUnit owner)
  101. {
  102. return ((owner.Virtual as XmdsVirtual)).GetHateSystem();
  103. }
  104. public static XmdsVirtual ToVirtual(InstanceUnit unit)
  105. {
  106. return (unit.Virtual as XmdsVirtual);
  107. }
  108. //---------------------------------------------------------------------------------------------
  109. #region Client
  110. public static bool ClientSaveMemory
  111. {
  112. get { return s_save_memory; }
  113. set
  114. {
  115. s_save_memory = value;
  116. lock (s_maps)
  117. {
  118. if (value == false)
  119. {
  120. s_maps.Clear();
  121. }
  122. }
  123. }
  124. }
  125. private static HashMap<int, BotMapInfo> s_maps = new HashMap<int, BotMapInfo>();
  126. private static bool s_save_memory = true;
  127. public override ZoneLayer CreateClientZoneLayer(EditorTemplates templates, ILayerClient listener)
  128. {
  129. return new BotZoneLayer(templates, listener);
  130. }
  131. class BotZoneLayer : HZZoneLayer
  132. {
  133. public BotZoneLayer(EditorTemplates dataroot, ILayerClient client)
  134. : base(dataroot, client)
  135. {
  136. }
  137. protected override void InitTerrain(ClientEnterScene msg, out ZoneManhattanMap terrain_data, out AstarManhattan path_finder, out ManhattanMapAreaGenerator area_gen)
  138. {
  139. if (ClientSaveMemory)
  140. {
  141. BotMapInfo minfo = null;
  142. lock (s_maps)
  143. {
  144. minfo = s_maps.Get(this.Data.ID);
  145. if (minfo == null)
  146. {
  147. minfo = new BotMapInfo(base.TerrainSrc.Clone() as ZoneInfo, base.Templates);
  148. s_maps.Add(this.Data.ID, minfo);
  149. }
  150. }
  151. terrain_data = minfo.terrain_data;
  152. path_finder = minfo.path_finder;
  153. area_gen = minfo.area_gen;
  154. //Data.Terrain = null;
  155. this.IsShareTerrain = true;
  156. this.IsIgnoreTerrainTouch = true;
  157. }
  158. else
  159. {
  160. base.InitTerrain(msg, out terrain_data, out path_finder, out area_gen);
  161. }
  162. }
  163. protected override void DisposeTerrain()
  164. {
  165. if (ClientSaveMemory)
  166. {
  167. }
  168. else
  169. {
  170. base.DisposeTerrain();
  171. }
  172. }
  173. }
  174. class BotMapInfo
  175. {
  176. public readonly BotLayerManhattanMap terrain_data;
  177. public readonly AstarManhattan path_finder;
  178. public readonly ManhattanMapAreaGenerator area_gen;
  179. public BotMapInfo(ZoneInfo data, TemplateManager templates)
  180. {
  181. this.terrain_data = new BotLayerManhattanMap(templates, data);
  182. this.path_finder = new AstarManhattan(data.TemplateID, terrain_data, true, 0);
  183. this.area_gen = new ManhattanMapAreaGenerator(terrain_data.Data);
  184. }
  185. }
  186. class BotLayerManhattanMap : ZoneManhattanMap
  187. {
  188. public BotLayerManhattanMap(TemplateManager templates, ZoneInfo info)
  189. : base(info, templates.TerrainDefinition)
  190. {
  191. }
  192. public override bool SetValue(int bx, int by, int value)
  193. {
  194. return false;
  195. }
  196. }
  197. #endregion
  198. }
  199. }