XmdsFormula.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. using CommonAI.Zone;
  2. using CommonAI.Zone.Instance;
  3. using CommonAI.Zone.Formula;
  4. using CommonLang;
  5. using CommonLang.Concurrent;
  6. using CommonLang.IO;
  7. using CommonLang.Log;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Text;
  13. using XmdsCommon.Plugin;
  14. using XmdsCommonServer.Plugin.XmdsSkillTemplate;
  15. using XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills;
  16. using CommonAI.ZoneClient;
  17. using XmdsCommonServer.Plugin.Units;
  18. using CommonAI.Zone.ZoneEditor;
  19. using System.Xml;
  20. using CommonLang.XCSV;
  21. using XmdsCommonServer.Plugin.Scene;
  22. using XmdsCommonServer.Plugin.Quest;
  23. using XmdsCommonServer.XLS.Data;
  24. using CommonAI.data;
  25. using CommonLang.Property;
  26. using CommonAI.Data;
  27. namespace XmdsCommonServer.Plugin
  28. {
  29. /// <summary>
  30. /// FileName: XmdsFormula.cs
  31. /// Author: Alex.Yu
  32. /// Corporation:...
  33. /// Description:
  34. /// DateTime: 2015/4/22 19:31:22
  35. /// </summary>
  36. public class XmdsFormula : XmdsClientFormula
  37. {
  38. protected static Logger log = LoggerFactory.GetLogger("XmdsFormula");
  39. public XmdsFormula()
  40. {
  41. }
  42. public override void BindLogger(Logger log)
  43. {
  44. XmdsVirtual.log = log;
  45. }
  46. public override void OnEditorSaving(
  47. CommonAI.Zone.ZoneEditor.EditorTemplatesData datas,
  48. DirectoryInfo data_root,
  49. List<FileInfo> savedfiles,
  50. AtomicFloat progress_percent)
  51. {
  52. //File.WriteAllText(data_root + "\\sample_skills.csv", XmdsBattleSkill.GenSampleSkillConfig(), CUtils.UTF8);
  53. //progress_percent.GetAndSet(1f);
  54. //savedfiles.Add(new FileInfo(data_root.FullName + "\\skills.csv"));
  55. base.OnEditorSaving(datas, data_root, savedfiles, progress_percent);
  56. }
  57. public override void OnEditorPluginSaved(EditorTemplatesData datas, List<XCSVMeta> xls2csv, List<FileInfo> savedfiles, AtomicFloat progress_percent)
  58. {
  59. base.OnEditorPluginSaved(datas, xls2csv, savedfiles, progress_percent);
  60. }
  61. // public override void OnEditorPluginSaved(EditorTemplatesData datas, List<XmlDocument> xls2csv, DirectoryInfo xls_dir, List<FileInfo> savedfiles, AtomicFloat progress_percent)
  62. // {
  63. // base.OnEditorPluginSaved(datas, xls2csv, xls_dir, savedfiles, progress_percent);
  64. // }
  65. public override void InitPluginsData(CommonAI.Zone.ZoneEditor.EditorTemplates data_root)
  66. {
  67. BindLogger(LoggerFactory.GetLogger("XmdsCommonWin32"));
  68. //数值配置初始化.
  69. new XmdsGameConfig();
  70. //技能数值公式管理.
  71. //XmdsSkillDataMgr.Init(data_root.DataRoot);
  72. //加载怪物能力配置表.
  73. string sheetBasePath = data_root.DataRoot + "/data_config/";
  74. XmdsDataMgr.GetInstance().LoadMonsterData(sheetBasePath + "Monster.xlsx");
  75. XmdsDataMgr.GetInstance().LoadMonsterDynamicData(sheetBasePath + "MonsterDynamicProp.xlsx");
  76. //技能配置.
  77. XmdsDataMgr.GetInstance().LoadSkillCfgData(sheetBasePath + "SkillData.xlsx");
  78. //NPC配置.
  79. XmdsDataMgr.GetInstance().LoadNPCData(sheetBasePath + "NPCData.xlsx");
  80. //斩妖暴击配置.
  81. XmdsDataMgr.GetInstance().LoadZhanYaoData(sheetBasePath + "BUFF.xlsx");
  82. //随机怪物技能
  83. XmdsDataMgr.GetInstance().LoadMonsterSkillInfo(sheetBasePath + "BattleServerConfig.xlsx");
  84. //读取战斗服配置
  85. XmdsDataMgr.GetInstance().LoadBSConfig(sheetBasePath + "BattleServerConfig.xlsx");
  86. //buff配置数据
  87. //技能配置.
  88. XmdsDataMgr.GetInstance().LoadBuffCfgData(sheetBasePath + "BuffData.xlsx");
  89. //随机名字库
  90. XmdsDataMgr.GetInstance().LoadRandomNameData(sheetBasePath + "RandomName.xlsx");
  91. XmdsDataMgr.GetInstance().LoadMountainKingData(sheetBasePath + "MountainKingConfig.xlsx");
  92. //反射初始化XmdsSkill并读取配置表数据.
  93. XmdsBattleSkill.Init(data_root.Templates);
  94. //反射初始化场景扩展.
  95. XmdsSceneFactory.Init();
  96. //反射任务脚本
  97. QuestScriptManager.Init();
  98. base.InitPluginsData(data_root);
  99. this.InitRelationModule();
  100. }
  101. //加载技能配置.
  102. //private void LoadSkillConfig(string path)
  103. //{
  104. // string skillcfgpath = Resource.FormatPath(path);
  105. // string text = Resource.LoadAllText(skillcfgpath);
  106. // if ( text != null )
  107. // {
  108. // XmdsBattleSkill.LoadSkillConfig(text);
  109. // }
  110. // else
  111. // {
  112. // throw new Exception("无法加载技能配置文件 :" + skillcfgpath);
  113. // }
  114. //}
  115. public override int OnHit(InstanceUnit attacker, AttackSource source, InstanceUnit targget)
  116. {
  117. XmdsVirtual src_prop = attacker.Virtual as XmdsVirtual;
  118. XmdsVirtual dst_prop = targget.Virtual as XmdsVirtual;
  119. return dst_prop.OnHit(src_prop as XmdsVirtual, source);
  120. }
  121. public override void OnUnitDead(InstanceUnit targget, InstanceUnit killer)
  122. {
  123. XmdsVirtual src_prop = targget.Virtual as XmdsVirtual;
  124. if(killer == null)
  125. {
  126. src_prop.OnUnitDead(null);
  127. }
  128. else
  129. {
  130. XmdsVirtual dst_prop = killer.Virtual as XmdsVirtual;
  131. src_prop.OnUnitDead(dst_prop);
  132. dst_prop.OnKillUnit(src_prop);
  133. }
  134. }
  135. public override void OnUnitRemoved(InstanceUnit unit)
  136. {
  137. XmdsVirtual prop = unit.Virtual as XmdsVirtual;
  138. prop.OnUnitRemoved();
  139. }
  140. public override void OnTriggerStart(InstanceUnit unit, InstanceUnit.TriggerState trigger, InstanceUnit target)
  141. {
  142. XmdsVirtual src_prop = unit.Virtual as XmdsVirtual;
  143. XmdsVirtual dst_prop = target.Virtual as XmdsVirtual;
  144. (dst_prop).OnTriggerStart(trigger, dst_prop);
  145. }
  146. public override void OnUnitHandleNetMessage(InstanceUnit unit, ObjectAction action)
  147. {
  148. XmdsVirtual unit_prop = unit.Virtual as XmdsVirtual;
  149. (unit_prop).OnHandleNetMessage(action);
  150. }
  151. public override void OnBuffBegin(InstanceUnit unit, InstanceUnit.BuffState buff, InstanceUnit sender)
  152. {
  153. XmdsVirtual unit_prop = unit.Virtual as XmdsVirtual;
  154. XmdsVirtual sender_prop = sender.Virtual as XmdsVirtual;
  155. (unit_prop).OnBuffBegin(buff, sender_prop);
  156. }
  157. public override void OnBuffUpdate(InstanceUnit unit, InstanceUnit.BuffState buff, int time)
  158. {
  159. XmdsVirtual unit_prop = unit.Virtual as XmdsVirtual;
  160. (unit_prop).OnBuffUpdate(buff, time);
  161. }
  162. public override void OnBuffEnd(InstanceUnit unit, InstanceUnit.BuffState buff, string result, bool replace)
  163. {
  164. XmdsVirtual unit_prop = unit.Virtual as XmdsVirtual;
  165. (unit_prop).OnBuffEnd(buff, result, replace);
  166. }
  167. public override bool TryLaunchSkill(InstanceUnit unit, InstanceUnit.SkillState skill, ref InstanceUnit.LaunchSkillParam param)
  168. {
  169. XmdsVirtual unit_prop = unit.Virtual as XmdsVirtual;
  170. return (unit_prop).TryLaunchSkill(skill, ref param);
  171. }
  172. public override bool TriggerPetSkill(InstanceUnit unit, InstanceUnit.SkillState skill, ref InstanceUnit.LaunchSkillParam param)
  173. {
  174. XmdsVirtual unit_prop = unit.Virtual as XmdsVirtual;
  175. if((unit_prop).DispatchTriggerPetSkillEvent(ref skill, ref param))
  176. {
  177. skill.StartCD();
  178. }
  179. return true;
  180. }
  181. public override bool TryLaunchSpell(InstanceUnit launcher, LaunchSpell launch, ref SpellTemplate spell, out JSGCreateSpellData createData, ref float startX, ref float startY)
  182. {
  183. XmdsVirtual unit_prop = launcher.Virtual as XmdsVirtual;
  184. return (unit_prop).TryLaunchSpell(launch, ref spell, out createData, ref startX, ref startY);
  185. }
  186. public override bool TryAddBuff(InstanceUnit unit, InstanceUnit sender, ref BuffTemplate buff, out object tag)
  187. {
  188. XmdsVirtual owner_prop = unit.Virtual as XmdsVirtual;
  189. XmdsVirtual sender_prop = sender.Virtual as XmdsVirtual;
  190. return (sender_prop).TrySendBuff(ref buff, owner_prop, out tag);
  191. }
  192. public override void SendAddBuffEvent(InstanceUnit unit, InstanceUnit sender, BuffTemplate buff)
  193. {
  194. XmdsVirtual owner_prop = unit.Virtual as XmdsVirtual;
  195. XmdsVirtual sender_prop = sender.Virtual as XmdsVirtual;
  196. sender_prop.SendAddBuffEvent(owner_prop, buff);
  197. }
  198. public override bool TrySummonUnit(InstanceUnit owner, SummonUnit summon, ref UnitInfo summonUnit, ref string name)
  199. {
  200. return true;
  201. }
  202. public override void OnUpdateTriggerSkill(InstanceUnit unit, int intervalMS, bool slowRefresh)
  203. {
  204. XmdsVirtual unit_prop = unit.Virtual as XmdsVirtual;
  205. if ( unit_prop == null )
  206. {
  207. //throw new Exception("Xmds virtual is null : " + unit.Info);
  208. Console.WriteLine("Xmds virtual is null : " + unit.Info);
  209. }
  210. else
  211. {
  212. unit_prop.OnUpdateTriggerSkill(intervalMS, slowRefresh);
  213. }
  214. }
  215. // 有关联性功能加载
  216. private void InitRelationModule()
  217. {
  218. // 事件脚本功能扩展
  219. XmdsBattleSkill.loadExtendFuntionEvent();
  220. }
  221. }
  222. }