XmdsVirtual_SummonUnit.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. //等级转仙阶
  54. this.mProp.ServerData.BaseInfo.StateLv = (byte)(Math.Max(0, (lvl_monster - 70) / 10));
  55. if (ma.Fight_Type == 1)
  56. {
  57. MonsterProp prop = XmdsDataMgr.GetInstance().GetSingleMonsterProp(lvl_monster, ma.Type);
  58. initProp(prop, ma, ret);
  59. }
  60. else if (ma.Fight_Type == 2)
  61. {
  62. MonsterProp prop = XmdsDataMgr.GetInstance().GetMultipleMonsterProp(lvl_monster, ma.Type);
  63. initProp(prop, ma, ret);
  64. }
  65. else if (ma.Fight_Type == 4)
  66. {
  67. lvl_monster = ma.Level;
  68. MonsterProp prop = XmdsDataMgr.GetInstance().GetSingleMonsterProp(lvl_monster, ma.Type);
  69. initProp(prop, ma, ret);
  70. }
  71. else
  72. {
  73. OrigData oData = XmdsDataMgr.GetInstance().GetOrigData(lvl_monster);
  74. UserDefineConfig udc = XmdsDataMgr.GetInstance().GetUserDefineConfig(ma.Type);
  75. initProp2(ma, oData, udc, ret);
  76. }
  77. ret.BaseMaxHP = (int)(ret.BaseMaxHP * XmdsDataMgr.GetInstance().mMonsterDynamicLoader.Mon_Hp_Ratio);
  78. ret.BaseAttack = (int)(ret.BaseAttack * XmdsDataMgr.GetInstance().mMonsterDynamicLoader.Mon_Atk_Ratio);
  79. restoreMa2Ret(ret, ma);
  80. ret.HP = ret.BaseMaxHP;
  81. XmdsInstanceMonster unit = this.mUnit as XmdsInstanceMonster;
  82. if (unit != null)
  83. {
  84. unit.MonsterID = ma.ID;
  85. //警戒范围控制 :是否主动攻击.0否,1是.
  86. if (ma.isAttack == 0)
  87. {
  88. this.mUnit.Info.GuardRange = 0;
  89. this.mUnit.Info.GuardRangeGroup = 0;
  90. }
  91. }
  92. //edata.SenceType = GetCurSceneType();
  93. //edata.MonsterID = ma.ID;
  94. //edata.DisplayName = ma.Name;
  95. //edata.Title = ma.Title;
  96. //edata.Qcolor = (MonsterVisibleDataB2C.MonsterQcolor)ma.Qcolor;
  97. //edata.AttackType = (MonsterVisibleDataB2C.MonsterAttackType)ma.isAttack;
  98. //edata.Atype = (MonsterVisibleDataB2C.MonsterAtype)ma.Atype;
  99. //edata.MType = (MonsterVisibleDataB2C.MonsterType)ma.Type;
  100. //edata.hpPlies = (byte)ParseInt(mUnit.Info.UserTag, 1);
  101. this.mProp.ServerData.BaseInfo.name = ma.Name;
  102. this.mUnit.SetDiaplayerName(ma.Name);
  103. // 攻速初始化
  104. if (ret.AttackSpeed <= 0)
  105. {
  106. ret.AttackSpeed = GlobalData.DEFAULT_ATTACK_SPEED;
  107. }
  108. //mUnit.SetVisibleInfo(edata);
  109. //printMonsterData(ret, templateID);
  110. if (ret.MaxHP <= 0 || ret.MaxAttack <= 0 || ret.Defence <= 0)
  111. {
  112. log.Warn("召唤物属性错误:" + this.mUnit.Info.ID + ", 生命:" + ret.MaxHP +
  113. ", 攻击:" + ret.MaxAttack + ", 防御:" + ret.Defence);
  114. }
  115. }
  116. private void InitVisibleData(XmdsInstanceSummonUnit unit)
  117. {
  118. SummonUnitVisibleDataB2C data = new SummonUnitVisibleDataB2C();
  119. if (unit.SummonerUnit != null)
  120. {
  121. data.MasterObjID = unit.SummonerUnit.ID;
  122. }
  123. // 召唤的人物分身
  124. if(this.mInfo.ID == XmdsConstConfig.DEFAULT_PLAYER_TEMPLATE_ID)
  125. {
  126. data.AvatarList = this.mProp.ServerData.AvatarList;
  127. }
  128. mUnit.SetVisibleInfo(data);
  129. }
  130. public override string GetPlayerUUID()
  131. {
  132. InstanceUnit u = (mUnit as XmdsInstanceSummonUnit).SummonerUnit;
  133. if (u != null)
  134. {
  135. return ((u.Virtual) as XmdsVirtual).GetPlayerUUID();
  136. }
  137. return null;
  138. }
  139. public override int GetForceID()
  140. {
  141. InstanceUnit u = (mUnit as XmdsInstanceSummonUnit).SummonerUnit;
  142. if (u != null)
  143. {
  144. return ((u.Virtual) as XmdsVirtual).GetForceID();
  145. }
  146. return base.GetForceID();
  147. }
  148. public override string GetGuildID()
  149. {
  150. InstanceUnit u = (mUnit as XmdsInstanceSummonUnit).SummonerUnit;
  151. if (u != null)
  152. {
  153. return ((u.Virtual) as XmdsVirtual).GetGuildID();
  154. }
  155. return base.GetGuildID();
  156. }
  157. public override int GetServerID()
  158. {
  159. InstanceUnit u = (mUnit as XmdsInstanceSummonUnit).SummonerUnit;
  160. if (u != null)
  161. {
  162. return ((u.Virtual) as XmdsVirtual).GetServerID();
  163. }
  164. return base.GetServerID();
  165. }
  166. public override PKLevel GetCurPKLevel()
  167. {
  168. InstanceUnit u = (mUnit as XmdsInstanceSummonUnit).SummonerUnit;
  169. if (u != null)
  170. {
  171. return ((u.Virtual) as XmdsVirtual).GetCurPKLevel();
  172. }
  173. return base.GetCurPKLevel();
  174. }
  175. public override PKMode GetCurPKMode()
  176. {
  177. InstanceUnit u = (mUnit as XmdsInstanceSummonUnit).SummonerUnit;
  178. if (u != null)
  179. {
  180. return ((u.Virtual) as XmdsVirtual).GetCurPKMode();
  181. }
  182. return base.GetCurPKMode();
  183. }
  184. public override bool IsMember(XmdsVirtual target, PKMode mode, bool includeSelf, bool onlyForTeam = false)
  185. {
  186. if (includeSelf == true && this.mUnit == target.mUnit)
  187. {
  188. return true;
  189. }
  190. InstanceUnit u = (this.mUnit as XmdsInstanceSummonUnit).SummonerUnit;
  191. if (u != null)
  192. {
  193. XmdsVirtual zv = u.Virtual as XmdsVirtual;
  194. return zv.IsMember(target, mode, includeSelf);
  195. }
  196. return base.IsMember(target, mode, includeSelf);
  197. }
  198. public override void OnKillUnit(XmdsVirtual dead)
  199. {
  200. if (CalPKValue(dead) == true)
  201. {
  202. if (dead.IsPlayerUnit() &&
  203. dead.GetCurPKLevel() == PKLevel.White)
  204. {
  205. XmdsInstancePlayer zip = (mUnit as XmdsInstanceSummonUnit).SummonerUnit as XmdsInstancePlayer;
  206. if (zip != null)
  207. {
  208. (zip.Virtual as XmdsVirtual).OnKillUnit(dead);
  209. }
  210. }
  211. }
  212. }
  213. public override bool IsPlayerUnit()
  214. {
  215. bool ret = false;
  216. InstanceUnit u = (mUnit as XmdsInstanceSummonUnit).SummonerUnit;
  217. if (u != null && u is XmdsInstancePlayer)
  218. {
  219. ret = true;
  220. }
  221. return ret;
  222. }
  223. public override XmdsVirtual_Player GetPlayerUnit()
  224. {
  225. XmdsVirtual_Player ret = null;
  226. InstanceUnit u = (mUnit as XmdsInstanceSummonUnit).SummonerUnit;
  227. if (u != null && u is XmdsInstancePlayer)
  228. {
  229. ret = u.Virtual as XmdsVirtual_Player;
  230. }
  231. return ret;
  232. }
  233. protected override void CombatStateConnect(BattleStatus status, byte reason)
  234. {
  235. //影响主人.
  236. var v = GetPlayerUnit();
  237. if (v != null)
  238. {
  239. v.SetCombatState(status, reason);
  240. }
  241. }
  242. public override bool IsAttackable(XmdsVirtual attacker)
  243. {
  244. InstanceUnit u = (mUnit as XmdsInstanceSummonUnit).SummonerUnit;
  245. if (u != null)
  246. {
  247. return (u.Virtual as XmdsVirtual).IsAttackable(attacker);
  248. }
  249. return base.IsAttackable(attacker);
  250. }
  251. public override void OnHitOthter(XmdsVirtual target)
  252. {
  253. if (mHateSystem.ContainsID(target.mUnit.ID) == false)
  254. {
  255. mHateSystem.AddTarget(target);
  256. }
  257. var zv = GetPlayerUnit();
  258. if (zv != null)
  259. {
  260. zv.OnHitOthter(target);
  261. }
  262. }
  263. }
  264. }