XmdsFormula.cs 9.5 KB

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