XmdsVirtual_SummonUnit.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. using CommonAI;
  2. using CommonAI.Data;
  3. using CommonAI.Zone.Instance;
  4. using System;
  5. using XmdsCommon.Message;
  6. using XmdsCommon.Plugin;
  7. using XmdsCommonServer.Plugin.Scene;
  8. using XmdsCommonServer.Plugin.Units;
  9. using XmdsCommonServer.XLS;
  10. using XmdsCommonServer.XLS.Data;
  11. namespace XmdsCommonServer.Plugin
  12. {
  13. public class XmdsVirtual_SummonUnit : XmdsVirtual
  14. {
  15. public XmdsVirtual_SummonUnit(XmdsInstanceSummonUnit unit) : base(unit)
  16. {
  17. }
  18. protected override void Init(bool pointLv)
  19. {
  20. if (this.mProp.LoadDataConfig == true)
  21. {
  22. InitMonsterData2(GetCurSceneType(), mUnit.Info.TemplateID);
  23. }
  24. InitVisibleData(mUnit as XmdsInstanceSummonUnit);
  25. }
  26. protected void InitMonsterData2(string _sceneType, int templateID)
  27. {
  28. // 读一行怪物数据
  29. String ss = _sceneType;
  30. if (ss == XLSMonsterDataLoader.DUNGEONHERO || ss == XLSMonsterDataLoader.DUNGEONELITE)
  31. ss = XLSMonsterDataLoader.DUNGEONNORMAL;
  32. MonsterData ma = XmdsDataMgr.GetInstance().GetMonsterData(ss, templateID, null, false);
  33. if (ma == null)
  34. {
  35. log.Warn("初始化召唤物属性,找不到单位:" + templateID);
  36. return;
  37. }
  38. XmdsUnitProp ret = (XmdsUnitProp)mProp.ServerData.Prop;
  39. //FateType=-1
  40. if (ma.FateType == UnitFateType.Random)
  41. {
  42. ret.fateType = (UnitFateType)(this.mUnit.RandomN.Next() % (int)UnitFateType.Five + 1);
  43. }
  44. else
  45. {
  46. ret.fateType = ma.FateType;
  47. }
  48. XmdsServerScene scene = this.mUnit.Parent as XmdsServerScene;
  49. SceneType sceneType = this.mUnit.GetSceneType();
  50. int lvl_monster = ma.Level;
  51. this.mUnit.Level = lvl_monster;
  52. this.mProp.ServerData.BaseInfo.UnitLv = lvl_monster;
  53. if (ma.Fight_Type == 1)
  54. {
  55. MonsterProp prop = XmdsDataMgr.GetInstance().GetSingleMonsterProp(lvl_monster, ma.Type);
  56. initProp(prop, ma, ret);
  57. }
  58. else if (ma.Fight_Type == 2)
  59. {
  60. MonsterProp prop = XmdsDataMgr.GetInstance().GetMultipleMonsterProp(lvl_monster, ma.Type);
  61. initProp(prop, ma, ret);
  62. }
  63. else if (ma.Fight_Type == 4)
  64. {
  65. lvl_monster = ma.Level;
  66. MonsterProp prop = XmdsDataMgr.GetInstance().GetSingleMonsterProp(lvl_monster, ma.Type);
  67. initProp(prop, ma, ret);
  68. }
  69. else
  70. {
  71. OrigData oData = XmdsDataMgr.GetInstance().GetOrigData(lvl_monster);
  72. UserDefineConfig udc = XmdsDataMgr.GetInstance().GetUserDefineConfig(ma.Type);
  73. initProp2(ma, oData, udc, ret);
  74. }
  75. ret.BaseMaxHP = (int)(ret.BaseMaxHP * XmdsDataMgr.GetInstance().mMonsterDynamicLoader.Mon_Hp_Ratio);
  76. ret.BaseAttack = (int)(ret.BaseAttack * XmdsDataMgr.GetInstance().mMonsterDynamicLoader.Mon_Atk_Ratio);
  77. restoreMa2Ret(ret, ma);
  78. ret.HP = ret.BaseMaxHP;
  79. XmdsInstanceMonster unit = this.mUnit as XmdsInstanceMonster;
  80. if (unit != null)
  81. {
  82. unit.MonsterID = ma.ID;
  83. //警戒范围控制 :是否主动攻击.0否,1是.
  84. if (ma.isAttack == 0)
  85. {
  86. this.mUnit.Info.GuardRange = 0;
  87. this.mUnit.Info.GuardRangeGroup = 0;
  88. }
  89. }
  90. //edata.SenceType = GetCurSceneType();
  91. //edata.MonsterID = ma.ID;
  92. //edata.DisplayName = ma.Name;
  93. //edata.Title = ma.Title;
  94. //edata.Qcolor = (MonsterVisibleDataB2C.MonsterQcolor)ma.Qcolor;
  95. //edata.AttackType = (MonsterVisibleDataB2C.MonsterAttackType)ma.isAttack;
  96. //edata.Atype = (MonsterVisibleDataB2C.MonsterAtype)ma.Atype;
  97. //edata.MType = (MonsterVisibleDataB2C.MonsterType)ma.Type;
  98. //edata.hpPlies = (byte)ParseInt(mUnit.Info.UserTag, 1);
  99. this.mProp.ServerData.BaseInfo.name = ma.Name;
  100. this.mUnit.SetDiaplayerName(ma.Name);
  101. // 攻速初始化
  102. if (ret.AttackSpeed <= 0)
  103. {
  104. ret.AttackSpeed = GlobalData.DEFAULT_ATTACK_SPEED;
  105. }
  106. //mUnit.SetVisibleInfo(edata);
  107. //printMonsterData(ret, templateID);
  108. if (ret.MaxHP <= 0 || ret.MaxAttack <= 0 || ret.Defence <= 0)
  109. {
  110. log.Warn("召唤物属性错误:" + this.mUnit.Info.ID + ", 生命:" + ret.MaxHP +
  111. ", 攻击:" + ret.MaxAttack + ", 防御:" + ret.Defence);
  112. }
  113. }
  114. private void InitVisibleData(XmdsInstanceSummonUnit unit)
  115. {
  116. SummonUnitVisibleDataB2C data = new SummonUnitVisibleDataB2C();
  117. if (unit.SummonerUnit != null)
  118. {
  119. data.MasterObjID = unit.SummonerUnit.ID;
  120. }
  121. // 召唤的人物分身
  122. if(this.mInfo.ID == XmdsConstConfig.DEFAULT_PLAYER_TEMPLATE_ID)
  123. {
  124. data.AvatarList = this.mProp.ServerData.AvatarList;
  125. }
  126. mUnit.SetVisibleInfo(data);
  127. }
  128. public override string GetPlayerUUID()
  129. {
  130. InstanceUnit u = (mUnit as XmdsInstanceSummonUnit).SummonerUnit;
  131. if (u != null)
  132. {
  133. return ((u.Virtual) as XmdsVirtual).GetPlayerUUID();
  134. }
  135. return null;
  136. }
  137. public override int GetForceID()
  138. {
  139. InstanceUnit u = (mUnit as XmdsInstanceSummonUnit).SummonerUnit;
  140. if (u != null)
  141. {
  142. return ((u.Virtual) as XmdsVirtual).GetForceID();
  143. }
  144. return base.GetForceID();
  145. }
  146. public override string GetGuildID()
  147. {
  148. InstanceUnit u = (mUnit as XmdsInstanceSummonUnit).SummonerUnit;
  149. if (u != null)
  150. {
  151. return ((u.Virtual) as XmdsVirtual).GetGuildID();
  152. }
  153. return base.GetGuildID();
  154. }
  155. public override int GetServerID()
  156. {
  157. InstanceUnit u = (mUnit as XmdsInstanceSummonUnit).SummonerUnit;
  158. if (u != null)
  159. {
  160. return ((u.Virtual) as XmdsVirtual).GetServerID();
  161. }
  162. return base.GetServerID();
  163. }
  164. public override PKLevel GetCurPKLevel()
  165. {
  166. InstanceUnit u = (mUnit as XmdsInstanceSummonUnit).SummonerUnit;
  167. if (u != null)
  168. {
  169. return ((u.Virtual) as XmdsVirtual).GetCurPKLevel();
  170. }
  171. return base.GetCurPKLevel();
  172. }
  173. public override PKMode GetCurPKMode()
  174. {
  175. InstanceUnit u = (mUnit as XmdsInstanceSummonUnit).SummonerUnit;
  176. if (u != null)
  177. {
  178. return ((u.Virtual) as XmdsVirtual).GetCurPKMode();
  179. }
  180. return base.GetCurPKMode();
  181. }
  182. public override bool IsMember(XmdsVirtual target, PKMode mode, bool includeSelf, bool onlyForTeam = false)
  183. {
  184. if (includeSelf == true && this.mUnit == target.mUnit)
  185. {
  186. return true;
  187. }
  188. InstanceUnit u = (this.mUnit as XmdsInstanceSummonUnit).SummonerUnit;
  189. if (u != null)
  190. {
  191. XmdsVirtual zv = u.Virtual as XmdsVirtual;
  192. return zv.IsMember(target, mode, includeSelf);
  193. }
  194. return base.IsMember(target, mode, includeSelf);
  195. }
  196. public override void OnKillUnit(XmdsVirtual dead)
  197. {
  198. if (CalPKValue(dead) == true)
  199. {
  200. if (dead.IsPlayerUnit() &&
  201. dead.GetCurPKLevel() == PKLevel.White)
  202. {
  203. XmdsInstancePlayer zip = (mUnit as XmdsInstanceSummonUnit).SummonerUnit as XmdsInstancePlayer;
  204. if (zip != null)
  205. {
  206. (zip.Virtual as XmdsVirtual).OnKillUnit(dead);
  207. }
  208. }
  209. }
  210. }
  211. public override bool IsPlayerUnit()
  212. {
  213. bool ret = false;
  214. InstanceUnit u = (mUnit as XmdsInstanceSummonUnit).SummonerUnit;
  215. if (u != null && u is XmdsInstancePlayer)
  216. {
  217. ret = true;
  218. }
  219. return ret;
  220. }
  221. public override XmdsVirtual_Player GetPlayerUnit()
  222. {
  223. XmdsVirtual_Player ret = null;
  224. InstanceUnit u = (mUnit as XmdsInstanceSummonUnit).SummonerUnit;
  225. if (u != null && u is XmdsInstancePlayer)
  226. {
  227. ret = u.Virtual as XmdsVirtual_Player;
  228. }
  229. return ret;
  230. }
  231. protected override void CombatStateConnect(BattleStatus status, byte reason)
  232. {
  233. //影响主人.
  234. var v = GetPlayerUnit();
  235. if (v != null)
  236. {
  237. v.SetCombatState(status, reason);
  238. }
  239. }
  240. public override bool IsAttackable(XmdsVirtual attacker)
  241. {
  242. InstanceUnit u = (mUnit as XmdsInstanceSummonUnit).SummonerUnit;
  243. if (u != null)
  244. {
  245. return (u.Virtual as XmdsVirtual).IsAttackable(attacker);
  246. }
  247. return base.IsAttackable(attacker);
  248. }
  249. public override void OnHitOthter(XmdsVirtual target)
  250. {
  251. if (mHateSystem.ContainsID(target.mUnit.ID) == false)
  252. {
  253. mHateSystem.AddTarget(target);
  254. }
  255. var zv = GetPlayerUnit();
  256. if (zv != null)
  257. {
  258. zv.OnHitOthter(target);
  259. }
  260. }
  261. }
  262. }