XmdsVirtual_Monster.cs 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  1. using CommonAI.Zone.Instance;
  2. using System;
  3. using XmdsCommon.Message;
  4. using XmdsCommon.Plugin;
  5. using XmdsCommonServer.Plugin.Units;
  6. using XmdsCommonServer.XLS.Data;
  7. using CommonAI.Zone.Formula;
  8. using XmdsCommonServer.Plugin.XmdsSkillTemplate.DamageCalculator;
  9. using CommonAI.Zone;
  10. using System.Collections.Generic;
  11. using CommonLang;
  12. using XmdsCommonServer.Plugin.Scene;
  13. using static CommonAI.XmdsConstConfig;
  14. using XmdsCommonServer.XLS;
  15. using CommonLang.Log;
  16. using static XmdsCommonServer.XLS.XLSRandomMonsterSkillLoader;
  17. using static XmdsCommon.Plugin.GameSkill;
  18. using CommonAI.Zone.Helper;
  19. using CommonAI.Data;
  20. using XmdsCommon.JSGModule.Interface;
  21. namespace XmdsCommonServer.Plugin
  22. {
  23. public class XmdsVirtual_Monster : XmdsVirtual
  24. {
  25. private static Logger logger = LoggerFactory.GetLogger("MonsterData");
  26. /// <summary>
  27. /// 个性语言.
  28. /// </summary>
  29. protected string[] mDialogWords = null;//"(#‵′)凸|测试".
  30. /// <summary>
  31. /// 个性语言概率.
  32. /// </summary>
  33. protected int mDialogWordRate = 100;
  34. /// <summary>
  35. /// 死亡个性语言.
  36. /// </summary>
  37. protected string[] mDeadDialogWords = null;//"(#‵′)凸|测试".
  38. /// <summary>
  39. /// 死亡个性语言概率.
  40. /// </summary>
  41. protected int mDeadDialogWordRate = 100;
  42. /// <summary>
  43. /// 是否为BOSS.(是否受控制技能影响).
  44. /// </summary>
  45. private bool mIsBoss = false;
  46. /// <summary>
  47. /// 怪物类型
  48. /// </summary>
  49. private byte mMonsterType = 0;
  50. private bool mIsLvRepress = false;
  51. /// <summary>
  52. /// 怪物特殊能力列表.
  53. /// </summary>
  54. private List<int> mAbilityList = null;
  55. /// <summary>
  56. /// BOSS遭受攻击伤害信息.
  57. /// </summary>
  58. private HashMap<string, PlayerDamageInfo> mSufferDamageInfo = null;
  59. /// <summary>
  60. /// 是否为共享怪
  61. /// </summary>
  62. private bool mIsShare = false;
  63. //随机技能类型
  64. private byte skillType = 0;
  65. //绑定攻击者
  66. private InstanceUnit mBindAttakPlayer;
  67. /// <summary>
  68. /// 滚回去的提速buffid
  69. /// </summary>
  70. private int backSpeedBuffId = 0;
  71. public bool IsShare
  72. {
  73. get { return mIsShare; }
  74. set { mIsShare = value;}
  75. }
  76. public XmdsVirtual_Monster(InstanceUnit unit) : base(unit)
  77. {
  78. mHateSystem.SetFindHeirs(true);
  79. }
  80. public override string GetPlayerUUID()
  81. {
  82. return mUnit.ID.ToString();
  83. }
  84. public override PKLevel GetCurPKLevel()
  85. {
  86. return base.GetCurPKLevel();
  87. }
  88. //解析字符串里的数字
  89. //特点之一就是不报错,字符串随便传
  90. //特点之二就是字母数学混杂时,取最前面的数字串
  91. //dft,取值失败时的返回
  92. public static int ParseInt(string str, int dft = 0)
  93. {
  94. if (string.IsNullOrEmpty(str))
  95. {
  96. return dft;
  97. }
  98. System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(str, @"(\d+)");
  99. if (m.Groups.Count >= 2)
  100. {
  101. try
  102. {
  103. return System.Convert.ToInt32(m.Groups[1].Value);
  104. }
  105. catch (System.Exception)
  106. {
  107. return dft;
  108. }
  109. }
  110. return dft;
  111. }
  112. protected override void Init(bool pointLv)
  113. {
  114. if (this.mProp.LoadDataConfig == true)
  115. {
  116. //InitMonsterData(GetCurSceneType(), mUnit.Info.TemplateID, mUnit.Level, this.mUnit.RandomN);
  117. InitMonsterData2(GetCurSceneType(), mUnit.Info.TemplateID, pointLv);
  118. }
  119. else
  120. {
  121. MonsterVisibleDataB2C edata = new MonsterVisibleDataB2C();
  122. edata.SenceType = GetCurSceneType();
  123. edata.MonsterID = mUnit.Info.TemplateID;
  124. edata.DisplayName = mUnit.Name;
  125. edata.AttackType = MonsterVisibleDataB2C.MonsterAttackType.Passive;
  126. edata.Atype = MonsterVisibleDataB2C.MonsterAtype.Monster;
  127. edata.MType = MonsterVisibleDataB2C.MonsterType.MType0;
  128. edata.Qcolor = MonsterVisibleDataB2C.MonsterQcolor.Q0;
  129. edata.hpPlies = (byte)ParseInt(mUnit.Info.UserTag, 1);
  130. mUnit.SetVisibleInfo(edata);
  131. }
  132. //随机名字
  133. if(this.mUnit.Info.IsRandomName)
  134. {
  135. string randomName = XmdsDataMgr.GetInstance().GetRanomName();
  136. mUnit.SetDiaplayerName(randomName);
  137. }
  138. mHateSystem.OnHandleTargetAddEvent += MHateSystem_OnHandleTargetAddEvent;
  139. }
  140. private void MHateSystem_OnHandleTargetAddEvent(CommonAI.Zone.Helper.HateSystem.HateInfo target)
  141. {
  142. if (target.Unit != null)
  143. {
  144. if ((target.Unit.Virtual as XmdsVirtual).IsPlayerUnit())
  145. {
  146. SetCombatState(BattleStatus.PVP);
  147. }
  148. else
  149. {
  150. SetCombatState(BattleStatus.PVE);
  151. }
  152. }
  153. }
  154. public override void SetCombatState(BattleStatus value, byte reason = 0, string pvpTriggerID = "")
  155. {
  156. //怪物强制为PVE状态.
  157. if (value == BattleStatus.PVP)
  158. {
  159. value = BattleStatus.PVE;
  160. }
  161. base.SetCombatState(value, reason);
  162. }
  163. protected override void OnCombatStateChange(BattleStatus status)
  164. {
  165. base.OnCombatStateChange(status);
  166. //单位脱战条件必须是非无限追击怪物.
  167. if (status == BattleStatus.None && this.mUnit.Info.GuardRangeLimit != 0)
  168. {
  169. (mUnit as CommonAI.Zone.Instance.InstanceGuard).backToOrgin();
  170. //changeRunSpeed4back();
  171. CleanDamageInfo();
  172. }
  173. if (status != BattleStatus.None)//进入战斗时触发个性化语句.
  174. {
  175. RandomDialogWords();
  176. }
  177. }
  178. /// <summary>
  179. /// 怪物回去要提你麻痹的速
  180. /// </summary>
  181. public void changeRunSpeed4back()
  182. {
  183. if(backSpeedBuffId > 0)
  184. {
  185. RemovePropChangeOperation(backSpeedBuffId);
  186. }
  187. XmdsVirtual.PropChangeOperation pco = this.CreatePropChangeOpertation(null);
  188. pco.Type = XmdsVirtual.UnitAttributeType.MoveSpeed;
  189. pco.Value = 5000;
  190. pco.OpType = XmdsVirtual.PropChangeOperation.OperateType.Percent;
  191. backSpeedBuffId = AddPropChangeOperation(pco);
  192. }
  193. public void onBack2PositionEnd()
  194. {
  195. RemovePropChangeOperation(backSpeedBuffId);
  196. }
  197. public override void OnUnitDead(XmdsVirtual killer)
  198. {
  199. //怪物死亡时,需要计算组队分享人员名单.
  200. var u = mHateSystem.GetHeirs();
  201. if (u != null)
  202. {
  203. mHateSystem.CalAtkAssistantList(mIsShare);
  204. CheckKillGroup((u.Virtual as XmdsVirtual));
  205. }
  206. base.OnUnitDead(killer);
  207. RandomDeadDialogWords();
  208. }
  209. public override int OnHit(XmdsVirtual attacker, AttackSource source)
  210. {
  211. //怪物回程状态不能被攻击.
  212. if (this.mUnit.CurrentState is InstanceUnit.StateBackToPosition)
  213. {
  214. source.OutIsDamage = false;
  215. source.OutClientState = (int)UnitHitEventState.Immunity;
  216. return 0;
  217. }
  218. OnBossHit(attacker, ref source);
  219. int ret = base.OnHit(attacker, source);
  220. if (ret > 0)
  221. {
  222. OnDamageInfoCheck(attacker, ref source, ret);
  223. }
  224. return ret;
  225. }
  226. public override void SyncHeirsInfo(string name, int hpPercent, CommonAI.Data.XmdsUnitPro protype)
  227. {
  228. if (string.IsNullOrEmpty(name))
  229. {
  230. (this.mUnit.VisibleInfo as MonsterVisibleDataB2C).UnitHeirInfo = null;
  231. SendMonsterHeirInfoChangeEventB2C(null);
  232. }
  233. else {
  234. MonsterVisibleDataB2C.HeirInfo info = new MonsterVisibleDataB2C.HeirInfo();
  235. info.Name = name;
  236. info.hpPercent = hpPercent;
  237. info.ProType = protype;
  238. SendMonsterHeirInfoChangeEventB2C(info);
  239. (this.mUnit.VisibleInfo as MonsterVisibleDataB2C).UnitHeirInfo = info;
  240. }
  241. }
  242. private void SendMonsterHeirInfoChangeEventB2C(MonsterVisibleDataB2C.HeirInfo info)
  243. {
  244. MonsterHeirInfoChangeEventB2C evt = new MonsterHeirInfoChangeEventB2C();
  245. evt.UnitHeirInfo = info;
  246. this.mUnit.queueEvent(evt);
  247. }
  248. //怪物判断是否为队友时,直接用force.
  249. public override bool IsTeamMember(InstanceUnit unit)
  250. {
  251. return IsAllies(unit.Virtual as XmdsVirtual);
  252. }
  253. protected override bool JudgeChangeCombatStateChange(BattleStatus status, byte reason)
  254. {
  255. //普通情况下,召唤物未出战斗状态,主人也处于战斗状态.
  256. if (status == BattleStatus.None && reason == 0)
  257. {
  258. if (mSummonList != null && mSummonList.Count > 0)
  259. {
  260. for (int i = 0; i < mSummonList.Count; i++)
  261. {
  262. if (mSummonList[i].CombatState != BattleStatus.None)
  263. {
  264. return false;
  265. }
  266. }
  267. }
  268. }
  269. return base.JudgeChangeCombatStateChange(status, reason);
  270. }
  271. protected override void CombatStateConnect(BattleStatus status, byte reason)
  272. {
  273. if (mSummonList != null && mSummonList.Count > 0)
  274. {
  275. for (int i = 0; i < mSummonList.Count; i++)
  276. {
  277. mSummonList[i].SetCombatState(status, reason);
  278. }
  279. }
  280. }
  281. protected override void Dispose()
  282. {
  283. UnInitBossAbilities();
  284. CleanSummonList();
  285. DisposeDamageInfo();
  286. base.Dispose();
  287. }
  288. public override int GetVirtualTemplateID()
  289. {
  290. MonsterVisibleDataB2C data = (this.mUnit.VisibleInfo as MonsterVisibleDataB2C);
  291. if (data != null)
  292. {
  293. return data.MonsterID;
  294. }
  295. else
  296. {
  297. return base.GetVirtualTemplateID();
  298. }
  299. }
  300. public void DoUnitStateReset()
  301. {
  302. //野外无效.
  303. //if (this.mUnit.GetSceneType() == CommonAI.Data.SceneType.Dungeon ||
  304. // this.mUnit.GetSceneType() == CommonAI.Data.SceneType.GuildDungeon)
  305. //{
  306. // if ((this.mUnit.CurrentState is InstanceUnit.StateFollowAndAttack) || (this.mUnit.CurrentState is InstanceUnit.StateSkill))
  307. // {
  308. // if (CombatState != BattleStatus.None)
  309. // {
  310. // SetCombatState(BattleStatus.None, COMBATSTATE_CHANGE_REASON_DORESET);
  311. // CleanDamageInfo();
  312. // //如果是BOSS直接重新生成单位.
  313. // if (mIsBoss)
  314. // {
  315. // RemoveSelfAndCreate();
  316. // //var pos = (this.mUnit as XmdsInstanceMonster).GetOrginPosition();
  317. // //this.mUnit.setPos(pos.x, pos.y);
  318. // //Reset();
  319. // }
  320. // else
  321. // {
  322. // Reset();
  323. // }
  324. // }
  325. // }
  326. //}
  327. }
  328. private void RemoveSelfAndCreate()
  329. {
  330. var pos = (this.mUnit as XmdsInstanceMonster).GetOrginPosition();
  331. float x = 0;
  332. float y = 0;
  333. if (pos != null)
  334. {
  335. x = pos.X;
  336. y = pos.Y;
  337. }
  338. else
  339. {
  340. x = this.mUnit.X;
  341. y = this.mUnit.Y;
  342. }
  343. var u = this.mUnit.Parent.AddUnit(this.mUnit.Info.ID,
  344. this.mUnit.Name,
  345. this.mUnit.Force,
  346. this.mProp.ServerData.BaseInfo.UnitLv,
  347. x,
  348. y,
  349. this.mUnit.Direction, false);
  350. if (u != null)
  351. {
  352. u.UnitTag = this.mUnit.UnitTag;
  353. }
  354. this.mUnit.removeFromParent();
  355. }
  356. protected override void InitSkillInfo(XmdsUnitData data)
  357. {
  358. this.checkSkillData(data);
  359. //初始化随机技能
  360. if (this.skillType > 0)
  361. {
  362. ////如果配置了技能类型,就清除boss被动
  363. //if (mAbilityList != null)
  364. //{
  365. // mAbilityList.Clear();
  366. //}
  367. randomMonsterSkillInfo(this.mUnit.Info.ID, this.skillType);
  368. }
  369. //如果是boss
  370. if(this.IsBoss())
  371. {
  372. this.mProp.ServerData.Skills.UnitSkills.Add(new GameSkill(XmdsComSrvData.BOSS_CARD_SKILLID, XmdsSkillType.active, false));
  373. }
  374. mFinishSkillInit = true;
  375. mSkillHelper.InitSkill(data.Skills, this);
  376. if (mAbilityList != null)
  377. {
  378. InitAbilityList(mAbilityList);
  379. }
  380. }
  381. #region 共享相关计算.
  382. private void CheckKillGroup(XmdsVirtual killer)
  383. {
  384. if (killer == null) { return; }
  385. XmdsVirtual_Player ret = killer.GetPlayerUnit();
  386. if (ret == null) { return; }
  387. List<string> lt = ret.TeamList as List<string>;
  388. //拿到队友列表.
  389. if (lt != null && lt.Count > 0)
  390. {
  391. this.mHateSystem.ClearSharedList();
  392. string uuid = null;
  393. //找到当前场景队友.
  394. for (int i = 0; i < lt.Count; i++)
  395. {
  396. uuid = lt[i];
  397. var unit = this.mUnit.Parent.getPlayerByUUID(uuid);
  398. if (unit != null)
  399. {
  400. float dist = CMath.getDistance(this.mUnit.X, this.mUnit.Y, unit.X, unit.Y);
  401. //单位在范围内.
  402. if (dist <= XmdsConfig.Instance.SHARED_AWARD_MAX_RANGE)
  403. {
  404. this.mHateSystem.AddSharedList(uuid);
  405. }
  406. }
  407. }
  408. }
  409. }
  410. #endregion
  411. #region SummonUnit.
  412. private List<XmdsVirtual> mSummonList = new List<XmdsVirtual>();
  413. public void AddSummonUnitList(XmdsVirtual unit)
  414. {
  415. mSummonList.Add(unit);
  416. unit.mUnit.OnDead += MUnit_OnDead;
  417. }
  418. private void MUnit_OnDead(CommonAI.Zone.Instance.InstanceUnit unit, CommonAI.Zone.Instance.InstanceUnit attacker)
  419. {
  420. XmdsVirtual v = unit.Virtual as XmdsVirtual;
  421. if (v != null && mSummonList != null)
  422. {
  423. unit.OnDead -= MUnit_OnDead;
  424. mSummonList.Remove(v);
  425. }
  426. }
  427. public int GetSummonUnitListCount()
  428. {
  429. return mSummonList.Count;
  430. }
  431. public XmdsVirtual GetFirstTimesupSummonUnit()
  432. {
  433. if (mSummonList.Count > 0)
  434. {
  435. return mSummonList[0];
  436. }
  437. return null;
  438. }
  439. public List<XmdsVirtual> GetSummonUnits()
  440. {
  441. return mSummonList;
  442. }
  443. public void CleanSummonList()
  444. {
  445. if (mSummonList != null && mSummonList.Count > 0)
  446. {
  447. for (int i = 0; i < mSummonList.Count; i++)
  448. {
  449. mSummonList[i].mUnit.OnDead -= MUnit_OnDead;
  450. mSummonList[i].mUnit.kill(null, false);
  451. }
  452. mSummonList.Clear();
  453. }
  454. }
  455. #endregion
  456. #region 单位能力读取加载.
  457. protected void InitMonsterData2(string _sceneType, int templateID, bool pointLv)
  458. {
  459. // 读一行怪物数据
  460. String ss = _sceneType;
  461. if (ss == XLSMonsterDataLoader.DUNGEONHERO || ss == XLSMonsterDataLoader.DUNGEONELITE)
  462. ss = XLSMonsterDataLoader.DUNGEONNORMAL;
  463. MonsterData ma = XmdsDataMgr.GetInstance().GetMonsterData(ss, templateID, null, false);
  464. //赋值特殊属性同步给客户端.
  465. MonsterVisibleDataB2C edata = new MonsterVisibleDataB2C();
  466. if (ma == null)
  467. {
  468. edata.MonsterID = templateID;
  469. edata.DisplayName = string.Format("Cfg Err id={0}", templateID);
  470. edata.AttackType = MonsterVisibleDataB2C.MonsterAttackType.Passive;
  471. edata.Atype = MonsterVisibleDataB2C.MonsterAtype.Monster;
  472. edata.MType = MonsterVisibleDataB2C.MonsterType.MType0;
  473. edata.Qcolor = MonsterVisibleDataB2C.MonsterQcolor.Q0;
  474. edata.hpPlies = (byte)ParseInt(mUnit.Info.UserTag, 1);
  475. mUnit.SetVisibleInfo(edata);
  476. return;
  477. }
  478. XmdsUnitProp ret = (XmdsUnitProp)mProp.ServerData.Prop;
  479. //FateType=-1
  480. if (ma.FateType == UnitFateType.Random)
  481. {
  482. ret.fateType = (UnitFateType)(this.mUnit.RandomN.Next() % (int)UnitFateType.Five + 1);
  483. }
  484. else
  485. {
  486. ret.fateType = ma.FateType;
  487. }
  488. XmdsServerScene scene = this.mUnit.Parent as XmdsServerScene;
  489. SceneType sceneType = this.mUnit.GetSceneType();
  490. int lvl_monster = pointLv ? this.mUnit.Level : ma.Level;
  491. this.skillType = (byte)ma.SkillType;
  492. int floor = 1;
  493. TowerMonsterRatio tmr = null;
  494. if (sceneType == SceneType.HaoYueJing || sceneType == SceneType.PickLotus)//monster level based on xlsconfig
  495. {
  496. //计算当前地图玩家等级:取平均等级
  497. IEnumerable<InstancePlayer> players = scene.AllPlayers;
  498. int level = 0;
  499. foreach (InstancePlayer player in players)
  500. {
  501. level += player.Level;
  502. }
  503. if (scene.AllPlayersCount == 0)
  504. {
  505. // 可能玩家已经都离开场景了,但是地图还在刷新怪物,为了不报错,将怪物等级默认设置为1
  506. lvl_monster = 1;
  507. }
  508. else
  509. {
  510. level = level / scene.AllPlayersCount;
  511. // 执行:怪物等级+=玩家等级
  512. lvl_monster += level;
  513. }
  514. }
  515. else if (sceneType == SceneType.GoblinTower)
  516. {
  517. floor = (int)scene.Data.MonsterAddPropPercentWithFloor;
  518. const int MAX_FLOOR = 80;//GoblinTower max floor
  519. if (floor < 1)
  520. floor = 1;
  521. if (floor > MAX_FLOOR)
  522. floor = MAX_FLOOR;
  523. tmr = XmdsDataMgr.GetInstance().GetTowerMonsterRatio(floor);
  524. lvl_monster = tmr.TowMon_Lv;
  525. }
  526. else if (sceneType == SceneType.AbyssDungeon)
  527. {
  528. floor = (int)scene.Data.MonsterAddPropPercentWithFloor;
  529. const int MAX_FLOOR = 80;//GoblinTower max floor
  530. if (floor < 1)
  531. floor = 1;
  532. if (floor > MAX_FLOOR)
  533. floor = MAX_FLOOR;
  534. tmr = XmdsDataMgr.GetInstance().GetAbyssMonsterRatio(floor);
  535. lvl_monster = tmr.TowMon_Lv;
  536. }
  537. else if (sceneType == SceneType.SourceDungeon)//资源副本怪物等级根据玩家等级上下浮动
  538. {
  539. //lvl_monster += (int)scene.Data.DefaultUnitLevel;
  540. }
  541. else if (sceneType == SceneType.GuildBoss || sceneType == SceneType.SHI_MEN_POS)//仙盟Boss
  542. {
  543. if (scene.Data.DefaultUnitLevel > 1)
  544. {
  545. lvl_monster = (int)scene.Data.DefaultUnitLevel;
  546. }
  547. }
  548. this.mUnit.Level = lvl_monster;
  549. this.mProp.ServerData.BaseInfo.UnitLv = lvl_monster;
  550. //等级转仙阶
  551. this.mProp.ServerData.BaseInfo.StateLv = (byte)(Math.Max(0, (lvl_monster - 70) / 10));
  552. if (ma.Fight_Type == 1)
  553. {
  554. MonsterProp prop = XmdsDataMgr.GetInstance().GetSingleMonsterProp(lvl_monster, ma.Type);
  555. initProp(prop, ma, ret);
  556. }
  557. else if (ma.Fight_Type == 2)
  558. {
  559. MonsterProp prop = XmdsDataMgr.GetInstance().GetMultipleMonsterProp(lvl_monster, ma.Type);
  560. initProp(prop, ma, ret);
  561. }
  562. else if (ma.Fight_Type == 4)
  563. {
  564. lvl_monster = ma.Level;
  565. MonsterProp prop = XmdsDataMgr.GetInstance().GetSingleMonsterProp(lvl_monster, ma.Type);
  566. initProp(prop, ma, ret);
  567. }
  568. else
  569. {
  570. OrigData oData = XmdsDataMgr.GetInstance().GetOrigData(lvl_monster);
  571. UserDefineConfig udc = XmdsDataMgr.GetInstance().GetUserDefineConfig(ma.Type);
  572. initProp2(ma, oData, udc, ret);
  573. }
  574. ret.BaseMaxHP = (int)(ret.BaseMaxHP * XmdsDataMgr.GetInstance().mMonsterDynamicLoader.Mon_Hp_Ratio);
  575. ret.BaseAttack = (int)(ret.BaseAttack * XmdsDataMgr.GetInstance().mMonsterDynamicLoader.Mon_Atk_Ratio);
  576. restoreMa2Ret(ret, ma);
  577. //镇妖塔层数加成
  578. if (sceneType == SceneType.GoblinTower && tmr != null)
  579. {
  580. dynamicCalcBy(ret,
  581. tmr.TowMon_Hp_Ratio,
  582. tmr.TowMon_Atk_Ratio,
  583. tmr.TowMon_Def_Ratio,
  584. tmr.TowMon_Crit_Ratio,
  585. tmr.TowMon_CritDamage_Ratio,
  586. tmr.TowMon_IgnoreDef_Ratio);
  587. }
  588. else if (sceneType == SceneType.AbyssDungeon && tmr != null)
  589. {
  590. float extRate = 1.0F;// (float)Math.Max(1.0f, scene.Data.MonsterAddPropPercentWithFloor);
  591. if (scene.Data.isTeam)
  592. {
  593. AbyssMutilAddition abyssAddition = XmdsDataMgr.GetInstance().GetAbyssMutilAddition();
  594. tmr.TowMon_Atk_Ratio *= abyssAddition.AttackAddition;
  595. tmr.TowMon_Def_Ratio *= abyssAddition.DefenceAddition;
  596. tmr.TowMon_Hp_Ratio *= abyssAddition.HPAddition;
  597. }
  598. dynamicCalcBy(ret,
  599. tmr.TowMon_Hp_Ratio * extRate,
  600. tmr.TowMon_Atk_Ratio * extRate,
  601. tmr.TowMon_Def_Ratio * extRate,
  602. tmr.TowMon_Crit_Ratio * extRate,
  603. tmr.TowMon_CritDamage_Ratio * extRate,
  604. tmr.TowMon_IgnoreDef_Ratio * extRate);
  605. }
  606. if (sceneType == SceneType.GuildBoss)
  607. {
  608. GuildBossRatio gbr = XmdsDataMgr.GetInstance().GetGuildBossRatio(lvl_monster);
  609. if (gbr != null)
  610. {
  611. dynamicCalcBy(ret,
  612. gbr.GBoss_Hp_Ratio,
  613. gbr.GBoss_Atk_Ratio,
  614. gbr.GBoss_Def_Ratio,
  615. gbr.GBoss_Crit_Ratio,
  616. gbr.GBoss_CritDamage_Ratio,
  617. gbr.GBoss_IgnoreDef_Ratio);
  618. }
  619. }
  620. if (_sceneType == XLSMonsterDataLoader.DUNGEONELITE)
  621. {
  622. ma = XmdsDataMgr.GetInstance().GetMonsterData(_sceneType, templateID, null, true);
  623. DungeonMonsterRatio dmr = XmdsDataMgr.GetInstance().mMonsterDynamicLoader.GetDungeonMonsterRatio(ma.Type);
  624. dynamicCalcBy(ret,
  625. dmr.Normal_Hp_Ratio,
  626. dmr.Normal_Atk_Ratio,
  627. dmr.Normal_Def_Ratio,
  628. dmr.Normal_DM_Ratio,
  629. dmr.Normal_DM_Ratio,
  630. dmr.Normal_DM_Ratio);
  631. restoreMa2Ret(ret, ma);
  632. }
  633. if (_sceneType == XLSMonsterDataLoader.DUNGEONHERO)
  634. {
  635. ma = XmdsDataMgr.GetInstance().GetMonsterData(_sceneType, templateID, null, true);
  636. DungeonMonsterRatio dmr = XmdsDataMgr.GetInstance().mMonsterDynamicLoader.GetDungeonMonsterRatio(ma.Type);
  637. dynamicCalcBy(ret,
  638. dmr.Hard_Hp_Ratio,
  639. dmr.Hard_Atk_Ratio,
  640. dmr.Hard_Def_Ratio,
  641. dmr.Hard_DM_Ratio,
  642. dmr.Hard_DM_Ratio,
  643. dmr.Hard_DM_Ratio);
  644. restoreMa2Ret(ret, ma);
  645. }
  646. ret.HP = ret.BaseMaxHP;
  647. XmdsInstanceMonster unit = this.mUnit as XmdsInstanceMonster;
  648. if (unit != null)
  649. {
  650. unit.MonsterID = ma.ID;
  651. //警戒范围控制 :是否主动攻击.0否,1是.
  652. if (ma.isAttack == 0)
  653. {
  654. this.mUnit.Info.GuardRange = 0;
  655. this.mUnit.Info.GuardRangeGroup = 0;
  656. }
  657. }
  658. edata.SenceType = GetCurSceneType();
  659. edata.MonsterID = ma.ID;
  660. edata.DisplayName = ma.Name;
  661. edata.Title = ma.Title;
  662. edata.Qcolor = (MonsterVisibleDataB2C.MonsterQcolor)ma.Qcolor;
  663. edata.AttackType = (MonsterVisibleDataB2C.MonsterAttackType)ma.isAttack;
  664. edata.Atype = (MonsterVisibleDataB2C.MonsterAtype)ma.Atype;
  665. edata.MType = (MonsterVisibleDataB2C.MonsterType)ma.Type;
  666. edata.hpPlies = (byte)ParseInt(mUnit.Info.UserTag, 1);
  667. this.mProp.ServerData.BaseInfo.name = ma.Name;
  668. //设置个性语言.
  669. if (!string.IsNullOrEmpty(ma.DialogWords))
  670. {
  671. mDialogWords = ma.DialogWords.Split('|');
  672. mDialogWordRate = ma.DialogChance;
  673. }
  674. //设置死亡个性语言.
  675. if (!string.IsNullOrEmpty(ma.DeadDialogWords))
  676. {
  677. mDeadDialogWords = ma.DeadDialogWords.Split('|');
  678. mDeadDialogWordRate = ma.DeadDialogChance;
  679. }
  680. mIsShare = ma.ShareType == 1;
  681. this.mMonsterType = ma.Type;
  682. this.mIsLvRepress = (ma.LvRepress == 1) && (this.mMonsterType == (byte)MonsterVisibleDataB2C.MonsterType.MType6);
  683. //是否为boss.
  684. if (ma.Type >= (byte)MonsterVisibleDataB2C.MonsterType.MType4)
  685. {
  686. InitBossAbilities();
  687. }
  688. //BOSS特殊能力.
  689. if (ma.AbilityList != null && mProp != null)
  690. {
  691. //之后会初始化特殊能力技能.
  692. mAbilityList = new List<int>(ma.AbilityList);
  693. }
  694. // 攻速初始化
  695. if (ret.AttackSpeed <= 0)
  696. {
  697. ret.AttackSpeed = GlobalData.DEFAULT_ATTACK_SPEED;
  698. }
  699. //定力值
  700. ret.ShieldValue = ma.MPValue;
  701. mUnit.SetVisibleInfo(edata);
  702. //printMonsterData(ret, templateID);
  703. if (ret.MaxHP <= 0 || ret.MaxAttack <= 0 || ret.Defence <= 0)
  704. {
  705. log.Error("怪物属性错误:" + this.mUnit.Parent.GetSceneID() + ", " + this.mUnit.Info.ID + ", 生命:" + ret.MaxHP +
  706. ", 攻击:" + ret.MaxAttack + ", 防御:" + ret.Defence);
  707. }
  708. else if(this.IsBoss() || ret.MaxHP > 500000 || ret.MaxAttack > 10000)
  709. {
  710. log.Debug("怪属性:" + this.mUnit.Parent.GetSceneID() + ", ID: " + templateID + ", " + this.mUnit.Parent.UUID + ", UID: " + this.mUnit.ID + ", 等级: " + lvl_monster
  711. + ", FT:" + ma.Fight_Type + ",(攻-" + ret.BaseAttack + ", 防-" + ret.BaseDefence + ", 血-" + ret.BaseMaxHP + ", 爆-" + ret.CritRate
  712. + ", 爆伤-" + ret.CritDamage + ", 穿透-" + ret.IgnoreDefensePer + ")");
  713. }
  714. }
  715. private void randomMonsterSkillInfo(int monsterId, int skillType)
  716. {
  717. MonsterSkills skillInfo = XmdsDataMgr.GetInstance().GetMonsterSkillInfo(monsterId);
  718. if (skillInfo == null)
  719. {
  720. // 指定的怪物概率读不到,就去读默认的技能概率
  721. skillInfo = XmdsDataMgr.GetInstance().GetMonsterSkillInfo();
  722. if(skillInfo == null)
  723. {
  724. return;
  725. }
  726. }
  727. if(this.mProp.ServerData.Skills == null)
  728. {
  729. this.mProp.ServerData.Skills = new XmdsUnitSkillInfo();
  730. }
  731. //else
  732. //{
  733. // this.mProp.ServerData.Skills.UnitSkills.Clear();
  734. //}
  735. if ((skillType & (int)MonsterRandomSkillType.OnlyActive) > 0)
  736. {
  737. //随机找一个技能
  738. if (this.mUnit.RandomN.Next(10000) < skillInfo.Skill1Probability)
  739. {
  740. XmdsSkillData activeSkill = XmdsDataMgr.GetInstance().GetBossRandomActiveSkill(this.mUnit.RandomN);
  741. //初始化主动技能
  742. if (activeSkill != null)
  743. {
  744. this.mProp.ServerData.Skills.UnitSkills.Add(new GameSkill(activeSkill.SkillID, XmdsSkillType.active));
  745. //log.Info("怪物:" + monsterId + ", 随机主动技能: " + activeSkill.SkillID);
  746. }
  747. }
  748. }
  749. if ((skillType & (int)MonsterRandomSkillType.OnlyPassive) > 0)
  750. {
  751. int[] nArray = { skillInfo.Skill2Probability, skillInfo.Skill3Probability, skillInfo.Skill4Probability };
  752. XmdsSkillData[] passiveSkills = new XmdsSkillData[3];
  753. int passiveIndex = 0;
  754. for (int i = 0; i < nArray.Length; i++)
  755. {
  756. if (nArray[i] > 0 && this.mUnit.RandomN.Next(10000) < nArray[i] && (passiveSkills[passiveIndex] =
  757. XmdsDataMgr.GetInstance().GetBossRandomPassiveSkill(this.mUnit.RandomN, passiveSkills)) != null)
  758. {
  759. passiveIndex++;
  760. }
  761. }
  762. //初始化被动技能
  763. for (int i = 0; i < passiveIndex; i++)
  764. {
  765. this.mProp.ServerData.Skills.UnitSkills.Add(new GameSkill(passiveSkills[i].SkillID, XmdsSkillType.passive));
  766. //log.Info("怪物:" + monsterId + ", 随机被动技能: " + passiveSkills[i].SkillID);
  767. }
  768. }
  769. }
  770. /// <summary>
  771. /// 随机发送个性语句.
  772. /// </summary>
  773. protected void RandomDialogWords()
  774. {
  775. if (mDialogWords != null && mDialogWords.Length > 0 && mDialogWordRate > 0)
  776. {
  777. int v = this.mUnit.RandomN.Next(0, 100);
  778. //随机触发概率.
  779. if (v <= mDialogWordRate)
  780. {
  781. //随机语句.
  782. v = this.mUnit.RandomN.Next(0, mDialogWords.Length);
  783. SendBubbleTipsEventB2C(mDialogWords[v]);
  784. }
  785. }
  786. }
  787. /// <summary>
  788. /// 随机发送死亡个性语句.
  789. /// </summary>
  790. protected void RandomDeadDialogWords()
  791. {
  792. if (mDeadDialogWords != null && mDeadDialogWords.Length > 0 && mDeadDialogWordRate > 0)
  793. {
  794. int v = this.mUnit.RandomN.Next(0, 100);
  795. //随机触发概率.
  796. if (v <= mDeadDialogWordRate)
  797. {
  798. //随机语句.
  799. v = this.mUnit.RandomN.Next(0, mDeadDialogWords.Length);
  800. SendBubbleTipsEventB2C(mDeadDialogWords[v]);
  801. }
  802. }
  803. }
  804. /// <summary>
  805. /// 初始化单位特殊能力(AI+技能).
  806. /// </summary>
  807. /// <param name="list"></param>
  808. private void InitAbilityList(List<int> list)
  809. {
  810. GameSkill gs = null;
  811. List<GameSkill> mlist = new List<GameSkill>();
  812. for (int i = 0; i < list.Count; i++)
  813. {
  814. gs = new GameSkill();
  815. gs.SkillID = list[i];
  816. gs.SkillType = XmdsSkillType.passive;
  817. mlist.Add(gs);
  818. }
  819. this.SkillHelper.AddSkill(mlist);
  820. }
  821. public override InstanceUnit GetAtkTarget(InstanceUnit target)
  822. {
  823. if(mBindAttakPlayer != null)
  824. {
  825. if (mBindAttakPlayer.IsActive)
  826. {
  827. return mBindAttakPlayer;
  828. }
  829. // 绑定目标不存在,自杀
  830. this.mUnit.kill();
  831. }
  832. else
  833. {
  834. string bindAttackPlayerId = this.mUnit.GetAttackPlayer();
  835. if (bindAttackPlayerId != null)
  836. {
  837. mBindAttakPlayer = this.mUnit.Parent.getPlayerByUUID(bindAttackPlayerId);
  838. if(mBindAttakPlayer == null)
  839. {
  840. log.Warn("GetAtkTarget有攻击目标玩家找不到:" + this.mUnit.Info.ID + ", " + mBindAttakPlayer);
  841. this.mUnit.BindAttackPlayer(null);
  842. this.mUnit.kill();
  843. }
  844. else
  845. {
  846. return mBindAttakPlayer;
  847. }
  848. }
  849. }
  850. return base.GetAtkTarget(target);
  851. }
  852. #endregion
  853. #region BOSS能力.
  854. private void InitBossAbilities()
  855. {
  856. mIsBoss = true;
  857. GameSkill gs = new GameSkill();
  858. gs.SkillID = 0;
  859. this.RegistTryAddBuffEvent(OnTryAddBuffEvent, gs);
  860. }
  861. private void UnInitBossAbilities()
  862. {
  863. if (mIsBoss)
  864. {
  865. }
  866. }
  867. private bool OnTryAddBuffEvent(ref BuffTemplate buff, XmdsVirtual attacker, XmdsVirtual hitter, GameSkill skill)
  868. {
  869. //检索所有能力,如果为控制类,则不生效.
  870. if (!buff.forceAdd && buff.IsHarmful && XmdsInstanceUtils.IsControlBuff_Monster(buff))
  871. {
  872. return false;
  873. }
  874. return true;
  875. }
  876. private void OnBossHit(XmdsVirtual attacker, ref AttackSource source)
  877. {
  878. if (mIsBoss)
  879. {
  880. if (source.OutIsDamage == true && this.mUnit.CurrentState is InstanceUnit.StateSkill)
  881. {
  882. this.mUnit.SetStunTimeMS(0);
  883. }
  884. source.OutIsDamage = false;
  885. }
  886. }
  887. private void OnDamageInfoCheck(XmdsVirtual attacker, ref AttackSource source, int damage)
  888. {
  889. if (mIsBoss)
  890. {
  891. var player = attacker.GetPlayerUnit();
  892. AddDamageInfo(player, damage);
  893. }
  894. }
  895. private void AddDamageInfo(XmdsVirtual_Player attacker, int damage)
  896. {
  897. //保证伤害有效性.
  898. if (attacker == null || attacker.mUnit.IsActive == false)
  899. {
  900. return;
  901. }
  902. if (mSufferDamageInfo == null)
  903. {
  904. mSufferDamageInfo = new HashMap<string, PlayerDamageInfo>();
  905. }
  906. PlayerDamageInfo info = null;
  907. string uuid = attacker.GetPlayerUUID();
  908. if (string.IsNullOrEmpty(uuid) == false)
  909. {
  910. if (mSufferDamageInfo.TryGetValue(uuid, out info))
  911. {
  912. info.Damage += damage;
  913. info.PlayerInfo = attacker.mProp.ServerData.BaseInfo;
  914. }
  915. else
  916. {
  917. info = new PlayerDamageInfo();
  918. info.Damage += damage;
  919. info.PlayerInfo = attacker.mProp.ServerData.BaseInfo;
  920. info.PlayerUUID = uuid;
  921. mSufferDamageInfo.Add(uuid, info);
  922. }
  923. }
  924. }
  925. private void CleanDamageInfo()
  926. {
  927. if (mSufferDamageInfo != null)
  928. {
  929. mSufferDamageInfo.Clear();
  930. }
  931. }
  932. private void DisposeDamageInfo()
  933. {
  934. CleanDamageInfo();
  935. }
  936. /// <summary>
  937. /// 获取怪物单位伤害排名表.
  938. /// </summary>
  939. /// <returns></returns>
  940. public HashMap<string, PlayerDamageInfo> GetSufferDamage()
  941. {
  942. return mSufferDamageInfo;
  943. }
  944. public override int GetMaType()
  945. {
  946. return this.mMonsterType;
  947. }
  948. public override bool IsLvRepress()
  949. {
  950. return this.mIsLvRepress;
  951. }
  952. public override bool IsBoss()
  953. {
  954. return this.mIsBoss;
  955. }
  956. #endregion
  957. }
  958. }