Role.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5. using UnityEngine.UI;
  6. using UnityEngine.AI;
  7. using Cinemachine;
  8. using BehaviorDesigner.Runtime;
  9. using UnityGameFramework.Runtime;
  10. using Chronos;
  11. using AdonGameKit;
  12. using Adon.Game.BO;
  13. /// <summary>
  14. /// 角色类
  15. /// </summary>
  16. public class Role : RoleBase
  17. {
  18. /// <summary>
  19. /// 动画控制器
  20. /// </summary>
  21. public Animator mAnimator = null;
  22. public Animator mBattleCameraAnim = null;
  23. public int cameraState = 0;
  24. public bool cameraLock = false;
  25. public string playerUID = "";
  26. /// <summary>
  27. /// 攻击中
  28. /// </summary>
  29. public bool attacking = false;
  30. /// <summary>
  31. /// 行为树
  32. /// </summary>
  33. public BehaviorTree mBehaviorTree = null;
  34. /// <summary>
  35. /// 寻路插件(配合行为树插件使用)
  36. /// </summary>
  37. public NavMeshAgent mNavMeshAgent = null;
  38. /// <summary>
  39. /// 寻路插件(配合行为树插件使用)
  40. /// </summary>
  41. public CharacterController mCharacterController = null;
  42. /// <summary>
  43. /// 动作帧事件
  44. /// </summary>
  45. public AnimationSkillEvent mSkillEvent = null;
  46. /// <summary>
  47. /// 阵营
  48. /// </summary>
  49. public E_Camp Camp = E_Camp.None;
  50. /// <summary>
  51. /// 移动方向
  52. /// </summary>
  53. private Vector3 mMoveDir = Vector3.zero;
  54. /// <summary>
  55. /// 蒙皮SkinnedMeshRenderer
  56. /// </summary>
  57. private SkinnedMeshRenderer[] mSkinnedMeshRenderers = null;
  58. /// <summary>
  59. /// 开火点
  60. /// </summary>
  61. public FirePos[] mFirePoss = null;
  62. /// <summary>
  63. /// 打击点
  64. /// </summary>
  65. public HitPos mHitPos = null;
  66. /// <summary>
  67. /// 是否是队长
  68. /// </summary>
  69. public bool IsTeamLeader = false;
  70. /// <summary>
  71. /// 是否是英雄
  72. /// </summary>
  73. public bool IsHero = false;
  74. /// <summary>
  75. /// 角色类型
  76. /// </summary>
  77. public RoleType roleType;
  78. /// <summary>
  79. /// 是否是最后一个点
  80. /// </summary>
  81. public bool IsEndPoint = false;
  82. /// <summary>
  83. /// 出生区域
  84. /// </summary>
  85. public int mLiveArea = -1;
  86. /// <summary>
  87. /// 是否无敌
  88. /// </summary>
  89. public bool mInvincible = false;
  90. /// <summary>
  91. /// 出生坐标
  92. /// </summary>
  93. public Vector3 mLivePos;
  94. public List<int> dropId = null;
  95. /// <summary>
  96. /// 活动范围
  97. /// </summary>
  98. public float mRadius = 0;
  99. /// <summary>
  100. /// 资源名称
  101. /// </summary>
  102. public string mResName = "";
  103. /// <summary>
  104. /// 能量更新计时器
  105. /// </summary>
  106. private float addSPTime = 0;
  107. private Dictionary<string, GameObject> _buffEffctList;
  108. public YLBattle.SpawnPoint.BubbleType bubType;
  109. public string bubStr;
  110. public bool bubEnable = false;
  111. public int spawnerID = 0;
  112. private GameObject mTipArrowObj = null;
  113. private List<GameObject> mCreateTipArrows = new List<GameObject>();
  114. /// <summary>
  115. /// 碰撞
  116. /// </summary>
  117. public CapsuleCollider mCollider = null;
  118. /// <summary>
  119. ///
  120. /// 是否是镜像
  121. /// </summary>
  122. public bool isMirror = false;
  123. /// <summary>
  124. /// 时钟组件
  125. /// </summary>
  126. public Timeline time
  127. {
  128. get
  129. {
  130. return GetComponent<Timeline>();
  131. }
  132. }
  133. /// <summary>
  134. /// 初始化
  135. /// </summary>
  136. /// <param name="date">数据</param>
  137. /// <param name="camp">阵营</param>
  138. /// <param name="_isMirror">是否是镜像</param>
  139. public void Init(YLBattleUnit date, E_Camp camp = E_Camp.Red, bool _isMirror = false)
  140. {
  141. base.Init(date);
  142. selfTransform = transform;
  143. Camp = camp;
  144. if (Camp == E_Camp.Red)
  145. {
  146. gameObject.layer = LayerMask.NameToLayer("Enemy");
  147. this.transform.Find("MiniMapFlagEnemy").gameObject.SetActive(false);
  148. }
  149. else
  150. {
  151. gameObject.layer = LayerMask.NameToLayer("Player");
  152. this.transform.Find("MiniMapFlagSelf").gameObject.SetActive(false);
  153. }
  154. isMirror = _isMirror;
  155. mBehaviorTree = transform.GetComponent<BehaviorTree>();
  156. mNavMeshAgent = transform.GetComponent<NavMeshAgent>();
  157. mCollider = transform.GetComponent<CapsuleCollider>();
  158. mCharacterController = transform.GetComponent<CharacterController>();
  159. mSkillEvent = transform.GetComponentInChildren<AnimationSkillEvent>();
  160. mAnimator = mSkillEvent.transform.GetComponent<Animator>();
  161. Transform btCA = this.transform.Find("CMStateDrivenCamera");
  162. if (btCA)
  163. {
  164. mBattleCameraAnim = btCA.GetComponent<Animator>();
  165. }
  166. mSkinnedMeshRenderers = transform.GetComponentsInChildren<SkinnedMeshRenderer>();
  167. mFirePoss = transform.GetComponentsInChildren<FirePos>(true);
  168. mHitPos = transform.GetComponentInChildren<HitPos>(true);
  169. this._buffEffctList = new Dictionary<string, GameObject>();
  170. ////// 显示攻击特效
  171. ////mSkillEvent.mSlowTimeStart = OnSlowTimeStart;
  172. ////mSkillEvent.mSlowTimeEnd = OnSlowTimeEnd;
  173. // 英雄
  174. if (date.mIsHero)
  175. {
  176. //GameObject cm = this.gameObject.transform.Find("CMStateDrivenCamera").gameObject;
  177. //if (cm)
  178. //{
  179. // cm.SetActive(false);
  180. //}
  181. // 武器换装
  182. if (this.mData.mHeroVo.equips.ContainsKey("weapon") && this.mData.mHeroVo.equips["weapon"].EquipMo() != null)
  183. {
  184. string weaponName = this.mData.mHeroVo.equips["weapon"].EquipMo().res;
  185. WeaponPos[] weapons = this.transform.GetComponentsInChildren<WeaponPos>(true);
  186. foreach (var item in weapons)
  187. {
  188. if (String.Equals(item.gameObject.name, weaponName, StringComparison.CurrentCultureIgnoreCase))///按刘海的要求,改动一下,刘海要求从typeid适配武器模型,改为从res来适配武器模型。
  189. // if (item.gameObject.name == weaponName)
  190. {
  191. item.gameObject.SetActive(true);
  192. }
  193. else
  194. {
  195. item.gameObject.SetActive(false);
  196. }
  197. }
  198. }
  199. }
  200. }
  201. public void Update()
  202. {
  203. }
  204. /// <summary>
  205. /// 设置移动速度
  206. /// </summary>
  207. /// <param name="speed"></param>
  208. public void SetMoveSpeed(float speed)
  209. {
  210. if (mBehaviorTree)
  211. {
  212. mBehaviorTree.SetVariableValue("moveSpeed", speed);
  213. }
  214. }
  215. public void RefreshYanLing(int pos, HeroGameVo_Yanling yanlingVO)
  216. {
  217. if (yanlingVO != null)
  218. {
  219. // 骨骼挂载点 挂载言灵装饰预制体
  220. Transform tsfmHero = transform;
  221. Transform tsfmPoint;
  222. YanLingBonePoint[] points = tsfmHero.GetComponentsInChildren<YanLingBonePoint>(true);
  223. foreach (var item in points)
  224. {
  225. if (item._bonePointType != (YanLingBonePoint.BonePoint)pos)
  226. {
  227. continue;
  228. }
  229. if (yanlingVO.itemuid == 0)
  230. {
  231. // item.gameObject.SetActive(false);
  232. return;
  233. }
  234. item.gameObject.SetActive(true);
  235. int childCount = item.transform.childCount;
  236. if (childCount > 0)
  237. {
  238. var children = new List<GameObject>();
  239. for (int i = 0; i < childCount; ++i)
  240. {
  241. var child = item.transform.GetChild(i).gameObject;
  242. children.Add(child);
  243. }
  244. for (int i = 0; i < childCount; ++i)
  245. {
  246. var child = children[i];
  247. #if UNITY_EDITOR
  248. UnityEngine.Object.DestroyImmediate(child);
  249. #else
  250. UnityEngine. Object.Destroy(child);
  251. #endif
  252. }
  253. }
  254. string ylRes = yanlingVO.Mo().GetYanlingExt().res;
  255. ResourceHelper.Instance.LoadAssetBundle(ylRes, (bundle) =>
  256. {
  257. if (bundle != null)
  258. {
  259. GameObject obj = (GameObject)Instantiate(bundle.LoadAsset(ylRes), item.transform);
  260. if (obj)
  261. {
  262. obj.transform.parent = item.transform;
  263. obj.transform.localPosition = Vector3.zero;
  264. }
  265. }
  266. });
  267. }
  268. }
  269. }
  270. public void NetMoveSC(float x, float y, float z)
  271. {
  272. this.transform.position.Set(x, y, z);
  273. }
  274. public static GameObject FindHideChildGameObject(GameObject parent, string childName)
  275. {
  276. if (parent.name == childName)
  277. {
  278. return parent;
  279. }
  280. if (parent.transform.childCount < 1)
  281. {
  282. return null;
  283. }
  284. GameObject obj = null;
  285. for (int i = 0; i < parent.transform.childCount; i++)
  286. {
  287. GameObject go = parent.transform.GetChild(i).gameObject;
  288. obj = FindHideChildGameObject(go, childName);
  289. if (obj != null)
  290. {
  291. break;
  292. }
  293. }
  294. return obj;
  295. }
  296. /////// <summary>
  297. /////// 技能发射事件
  298. /////// </summary>
  299. ////private void OnSlowTimeStart()
  300. ////{
  301. //// RPGPlayerController.Instance.OnSlowTimeStart(this);
  302. ////}
  303. /////// <summary>
  304. /////// 技能发射事件
  305. /////// </summary>
  306. ////private void OnSlowTimeEnd()
  307. ////{
  308. //// RPGPlayerController.Instance.OnSlowTimeEnd(this);
  309. ////}
  310. /// <summary>
  311. /// 播放动画
  312. /// </summary>
  313. /// <param name="aniName">动作名称</param>
  314. /// <param name="crossTime">淡入时间</param>
  315. public void PlayAnimation(string aniName, float crossTime = 0)
  316. {
  317. if (mAnimator == null)
  318. {
  319. return;
  320. }
  321. if (crossTime < 0.01f)
  322. {
  323. mAnimator.Play(aniName, 0, 0);
  324. }
  325. else
  326. {
  327. mAnimator.CrossFade(aniName, crossTime);
  328. }
  329. }
  330. /// <summary>
  331. /// 某段动画是否播放完成
  332. /// </summary>
  333. /// <param name="aniName">动画名称</param>
  334. /// <param name="playProgress">播放的进度(大于1.0f表示播放完成)</param>
  335. /// <returns>状态</returns>
  336. public bool IsPlayAnimationOver(string aniName, float playProgress = 1.0f)
  337. {
  338. if (mAnimator == null)
  339. {
  340. return true;
  341. }
  342. // 获取动画层 0 指Base Layer.
  343. AnimatorStateInfo stateinfo = mAnimator.GetCurrentAnimatorStateInfo(0);
  344. if (stateinfo.IsName(aniName))
  345. {
  346. if (stateinfo.loop)
  347. {
  348. return false;
  349. }
  350. else
  351. {
  352. if (stateinfo.normalizedTime >= playProgress)
  353. {
  354. return true;
  355. }
  356. else
  357. {
  358. return false;
  359. }
  360. }
  361. }
  362. return true;
  363. }
  364. ///// <summary>
  365. ///// 获取动画时长
  366. ///// </summary>
  367. ///// <param name="clip">片段名称</param>
  368. ///// <returns></returns>
  369. //public float GetAnimationClipLength(string clip)
  370. //{
  371. // if (null == mAnimator || string.IsNullOrEmpty(clip) || null == mAnimator.runtimeAnimatorController)
  372. // {
  373. // return 0;
  374. // }
  375. // RuntimeAnimatorController ac = mAnimator.runtimeAnimatorController;
  376. // AnimationClip[] tAnimationClips = ac.animationClips;
  377. // if (null == tAnimationClips || tAnimationClips.Length <= 0)
  378. // {
  379. // return 0;
  380. // }
  381. // AnimationClip tAnimationClip;
  382. // for (int i = 0; i < tAnimationClips.Length; i++)
  383. // {
  384. // tAnimationClip = tAnimationClips[i];
  385. // if (null != tAnimationClip && tAnimationClip.name == clip)
  386. // {
  387. // return tAnimationClip.length;
  388. // }
  389. // }
  390. // return 0;
  391. //}
  392. /// <summary>
  393. /// 颜色抖动
  394. /// </summary>
  395. public void ShakeColor(bool heroShake = false)
  396. {
  397. // 英雄不变色
  398. if (heroShake == false && mData.mIsHero)
  399. {
  400. return;
  401. }
  402. BeAttackFlash flash = gameObject.GetComponent<BeAttackFlash>();
  403. if (flash == null)
  404. {
  405. flash = gameObject.AddComponent<BeAttackFlash>();
  406. }
  407. flash.Flash();
  408. }
  409. /// <summary>
  410. /// 旋转
  411. /// </summary>
  412. /// <param name="dir"></param>
  413. public void SetRotation(Vector3 dir)
  414. {
  415. Quaternion quaDir = Quaternion.LookRotation(dir, Vector3.up);
  416. Vector3 angle = quaDir.eulerAngles;
  417. angle.x = 0;
  418. quaDir.eulerAngles = angle;
  419. // 方向不同才需转向
  420. if (quaDir != selfTransform.rotation)
  421. {
  422. StartCoroutine(IE_Rotationing(quaDir));
  423. }
  424. }
  425. /// <summary>
  426. /// 协同旋转
  427. /// </summary>
  428. /// <param name="dir">方向</param>
  429. /// <returns>迭代器</returns>
  430. private IEnumerator IE_Rotationing(Quaternion quaDir)
  431. {
  432. float val = 0;
  433. while (val < 1.0f)
  434. {
  435. val += Time.deltaTime * 5;
  436. selfTransform.rotation = Quaternion.Lerp(selfTransform.rotation, quaDir, val);
  437. yield return null;
  438. }
  439. }
  440. private bool bTip = false;
  441. /// <summary>
  442. /// 更新血条
  443. /// </summary>
  444. /// <param name="val"></param>
  445. public void UpdateHP(float val, bool isCrit = false)
  446. {
  447. //HpbarManager.Instance.CreateHpTip(this, (int)val, isCrit);
  448. if (!(val > 0 || val < 0))
  449. {
  450. return;
  451. }
  452. // 队长
  453. if (IsTeamLeader)
  454. {
  455. GameDateManager.Instance.PlayerBehitCount++;
  456. BattleCanvas.Instance.ShowPlayerHP(mData.HP_Final, mData.MaxHP_Final);
  457. //HpbarManager.Instance.UpdateHpbar(this, mData.HP_Final / (float)mData.MaxHP_Final, (int)val);
  458. if (mData.HP_Final / (float)mData.MaxHP_Final < 0.3f)
  459. {
  460. ConvertEffect.Instance.PlayEffect(ConvertEffect.convertEffectType.Dying, null);
  461. }
  462. else
  463. {
  464. ConvertEffect.Instance.PlayEffect(ConvertEffect.convertEffectType.Default, null);
  465. }
  466. //BattleCanvas.Instance.ShowPlayerPower(mData.MP_Final, mData.MaxMP_Final);
  467. }
  468. // 队员
  469. else if (mData.mIsHero && IsTeamLeader == false)
  470. {
  471. GameDateManager.Instance.PlayerBehitCount++;
  472. HpbarManager.Instance.UpdateHpbar(this, mData.HP_Final / (float)mData.MaxHP_Final, (int)val);
  473. }
  474. // 怪物
  475. else if (mData.mIsHero == false)
  476. {
  477. GameDateManager.Instance.PlayerComboCount++;
  478. if (BattleCanvas.Instance)
  479. {
  480. BattleCanvas.Instance.UpdateComboNumber();
  481. }
  482. if (isDie)
  483. {
  484. this.mBehaviorTree.SendEvent("DieEvent");
  485. }
  486. // 更新已经锁定的目标血条
  487. if (HeroPlayerController.Instance.m_Hero.TargetRole == this)
  488. {
  489. if (isDie)
  490. {
  491. BattleCanvas.Instance.HideLockMonsterHP();
  492. }
  493. else
  494. {
  495. BattleCanvas.Instance.ShowLockMonsterHP(this);
  496. }
  497. }
  498. HpbarManager.Instance.UpdateHpbar(this, mData.HP_Final / (float)mData.MaxHP_Final, (int)val);
  499. }
  500. if (val > 0)
  501. {
  502. ResourceHelper.Instance.LoadAssetBundle("zhandou_jiaxue_tishi", (AssetBundle bundle) =>
  503. {
  504. if (null != bundle)
  505. {
  506. GameObject jiaxue = Instantiate(bundle.LoadAsset<GameObject>("zhandou_jiaxue_tishi"));
  507. jiaxue.transform.parent = this.transform;
  508. jiaxue.transform.localPosition = Vector3.zero;
  509. CmptAutoDestory cmpt = jiaxue.AddComponent<CmptAutoDestory>();
  510. cmpt.LiveTime = 2.0f;
  511. }
  512. });
  513. }
  514. // 收到伤害颜色渐变
  515. //if (val < 0)
  516. //{
  517. // ShakeColor();
  518. //}
  519. }
  520. /// <summary>
  521. /// 0 自己 1 父节点
  522. /// </summary>
  523. /// <param name="addType"></param>
  524. /// <param name="effectObj"></param>
  525. /// <param name="castType"></param>
  526. /// <param name="skillPos"></param>
  527. public void AddEffect(int addType, Transform effectObj, X2Battle.EBulletCastPoint castType, BattleDefine.Skill_LaunchPos skillPos = BattleDefine.Skill_LaunchPos.Chest)
  528. {
  529. Transform node = null;
  530. if (castType == X2Battle.EBulletCastPoint.ECAST_POINT_DEFLUAT)
  531. {
  532. switch (skillPos)
  533. {
  534. case BattleDefine.Skill_LaunchPos.Chest:
  535. if (mData.mIsHero)
  536. {
  537. node = mAnimator.transform.Find("Effect_000/Hit");
  538. }
  539. else
  540. {
  541. node = mAnimator.transform.Find("Effect_000/Hit");
  542. }
  543. break;
  544. case BattleDefine.Skill_LaunchPos.Head:
  545. node = mAnimator.transform.Find("Effect_000/Top");
  546. break;
  547. case BattleDefine.Skill_LaunchPos.Hand:
  548. node = mAnimator.transform.Find("Effect_000/Hit");
  549. break;
  550. case BattleDefine.Skill_LaunchPos.Foot:
  551. node = mAnimator.transform.Find("Effect_000/Foot");
  552. break;
  553. }
  554. }
  555. else
  556. {
  557. node = X2Battle.X2BattleManager.Instance.mBulletModel.GetPosBySkillType(this, castType);
  558. }
  559. if (node != null)
  560. {
  561. effectObj.position = node.position;
  562. effectObj.rotation = node.rotation;
  563. if (addType == 0)
  564. {
  565. effectObj.SetParent(mAnimator.transform.parent);
  566. }
  567. else if (addType == 1)
  568. {
  569. effectObj.SetParent(mAnimator.transform.parent.parent);
  570. }
  571. }
  572. }
  573. public Transform GetPointTrans(BattleDefine.Skill_LaunchPos pointType)
  574. {
  575. Transform node = null;
  576. switch (pointType)
  577. {
  578. case BattleDefine.Skill_LaunchPos.Chest:
  579. if (mData.mIsHero)
  580. {
  581. node = mAnimator.transform.Find("Effect_000/Hit");
  582. }
  583. else
  584. {
  585. node = mAnimator.transform.Find("Effect_000/Hit");
  586. }
  587. break;
  588. case BattleDefine.Skill_LaunchPos.Head:
  589. node = mAnimator.transform.Find("Effect_000/Top");
  590. break;
  591. case BattleDefine.Skill_LaunchPos.Hand:
  592. node = mAnimator.transform.Find("Effect_000/Hit");
  593. break;
  594. case BattleDefine.Skill_LaunchPos.Foot:
  595. node = mAnimator.transform.Find("Effect_000/Foot");
  596. break;
  597. }
  598. return node;
  599. }
  600. public float GetPropertyBase(YLBattle.EBattleProperty perperty)
  601. {
  602. return 0;
  603. }
  604. public void AdditionBuffEffect(YLBattle.Buff buff)
  605. {
  606. return;
  607. if (this._buffEffctList.ContainsKey(buff.tid.ToString()))
  608. {
  609. return;
  610. }
  611. string buffPathName = "Battle/buff_" + buff.adapter.Res();
  612. UnityEngine.Object buffObj = Resources.Load(buffPathName);
  613. if (buffObj)
  614. {
  615. Transform newBuffObj = (GameObject.Instantiate(buffObj) as GameObject).transform;
  616. newBuffObj.name = buffPathName;
  617. this._buffEffctList.Add(buff.tid.ToString(), newBuffObj.gameObject);
  618. sm_buff buffMo = sm_buff.GetMoByID(int.Parse(buff.tid));
  619. AddEffect(0, newBuffObj, X2Battle.EBulletCastPoint.ECAST_POINT_DEFLUAT, (BattleDefine.Skill_LaunchPos)buffMo.bullet_attack_poi);
  620. }
  621. }
  622. public void RemoveBuffEffect(YLBattle.Buff buff)
  623. {
  624. return;
  625. if (this._buffEffctList.ContainsKey(buff.tid.ToString()))
  626. {
  627. GameObject.Destroy(this._buffEffctList[buff.tid.ToString()]);
  628. this._buffEffctList.Remove(buff.tid.ToString());
  629. }
  630. }
  631. /// <summary>
  632. /// 执行一次Buff 属性修改
  633. /// </summary>
  634. /// <param name="buff"></param>
  635. /// <param name="property"></param>
  636. /// <param name="value"></param>
  637. public void ModifyProperty(YLBattle.Buff buff, YLBattle.EBattleProperty property, int value)
  638. {
  639. this.SetPropertyFinal(buff, property, value);
  640. }
  641. /// <summary>
  642. /// 执行一次Buff 属性修改
  643. /// </summary>
  644. /// <param name="buff"></param>
  645. /// <param name="property"></param>
  646. /// <param name="value"></param>
  647. public void ModifyProperty(YLBattle.Buff buff, YLBattle.EBattleProperty property, float value)
  648. {
  649. this.SetPropertyFinal(buff, property, value);
  650. }
  651. public float GetBattleProperty(YLBattle.EBattleProperty property)
  652. {
  653. return (float)this.GetPropertyFinal(property);
  654. }
  655. public int GetBuffEffectProperty(YLBattle.EBuffEffect property)
  656. {
  657. return 0;
  658. }
  659. public string ID()
  660. {
  661. return this.mData.UID.ToString();
  662. }
  663. public float GetProperty(YLBattle.EBattleProperty property)
  664. {
  665. float value = 0;
  666. switch (property)
  667. {
  668. case YLBattle.EBattleProperty.YANLI:
  669. value = mData.YAN;
  670. break;
  671. case YLBattle.EBattleProperty.KANGBAOLI:
  672. value = mData.KBL;
  673. break;
  674. case YLBattle.EBattleProperty.ATTACK:
  675. value = mData.ATK;
  676. break;
  677. case YLBattle.EBattleProperty.ATTACKSPEED:
  678. value = mData.ASP;
  679. break;
  680. case YLBattle.EBattleProperty.MOVESPEED:
  681. value = mData.MSP;
  682. break;
  683. case YLBattle.EBattleProperty.COOLTIME:
  684. value = mData.CLT;
  685. break;
  686. case YLBattle.EBattleProperty.ATKRANGE:
  687. value = mData.ARG;
  688. break;
  689. case YLBattle.EBattleProperty.ALARMRANGE:
  690. value = mData.ORG;
  691. break;
  692. case YLBattle.EBattleProperty.CRITICALPROB:
  693. value = mData.CRT;
  694. break;
  695. // 暴击伤害 默认2倍 不做基础属性存储
  696. case YLBattle.EBattleProperty.CRITICALDAMAGE:
  697. value = 2;
  698. break;
  699. case YLBattle.EBattleProperty.DEFENSE:
  700. value = mData.DEF;
  701. break;
  702. case YLBattle.EBattleProperty.HEIGHT:
  703. value = 2;
  704. break;
  705. case YLBattle.EBattleProperty.HP:
  706. value = mData.HP;
  707. break;
  708. case YLBattle.EBattleProperty.HPMAX:
  709. value = mData.MaxHP;
  710. break;
  711. case YLBattle.EBattleProperty.LEVEL:
  712. value = mData.LV;
  713. break;
  714. case YLBattle.EBattleProperty.MAGICFORCE:
  715. value = mData.MDF;
  716. break;
  717. case YLBattle.EBattleProperty.MAGICSTRENGTH:
  718. value = mData.ADM;
  719. break;
  720. case YLBattle.EBattleProperty.NMAXPOWER:
  721. value = 10;
  722. break;
  723. case YLBattle.EBattleProperty.NPOWER:
  724. value = 100;
  725. break;
  726. case YLBattle.EBattleProperty.POSX:
  727. value = this.transform.position.x;
  728. break;
  729. case YLBattle.EBattleProperty.POSY:
  730. value = this.transform.position.z;
  731. break;
  732. }
  733. return value;
  734. }
  735. public float GetPropertyFinal(YLBattle.EBattleProperty property)
  736. {
  737. float value = 0;
  738. switch (property)
  739. {
  740. case YLBattle.EBattleProperty.YANLI:
  741. value = mData.YAN_Final;
  742. break;
  743. case YLBattle.EBattleProperty.KANGBAOLI:
  744. value = mData.KBL_Final;
  745. break;
  746. case YLBattle.EBattleProperty.ATTACK:
  747. value = mData.ATK_Final;
  748. break;
  749. case YLBattle.EBattleProperty.ATTACKSPEED:
  750. value = mData.ASP_Final;
  751. break;
  752. case YLBattle.EBattleProperty.MOVESPEED:
  753. value = mData.MSP_Final;
  754. break;
  755. case YLBattle.EBattleProperty.COOLTIME:
  756. value = mData.CLT_Final;
  757. break;
  758. case YLBattle.EBattleProperty.ATKRANGE:
  759. value = mData.ARG_Final;
  760. break;
  761. case YLBattle.EBattleProperty.ALARMRANGE:
  762. value = mData.ORG_Final;
  763. break;
  764. case YLBattle.EBattleProperty.CRITICALPROB:
  765. value = mData.CRT_Final;
  766. break;
  767. case YLBattle.EBattleProperty.CRITICALDAMAGE:
  768. value = mData.CRD_Final;
  769. break;
  770. case YLBattle.EBattleProperty.DEFENSE:
  771. value = mData.DEF_Final;
  772. break;
  773. case YLBattle.EBattleProperty.HEIGHT:
  774. value = 2;
  775. break;
  776. case YLBattle.EBattleProperty.HP:
  777. value = mData.HP_Final;
  778. break;
  779. case YLBattle.EBattleProperty.HPMAX:
  780. value = mData.MaxHP_Final;
  781. break;
  782. case YLBattle.EBattleProperty.LEVEL:
  783. value = mData.LV;
  784. break;
  785. case YLBattle.EBattleProperty.MAGICFORCE:
  786. value = mData.MDF_Final;
  787. break;
  788. case YLBattle.EBattleProperty.MAGICSTRENGTH:
  789. value = mData.ADM_Final;
  790. break;
  791. case YLBattle.EBattleProperty.NMAXPOWER:
  792. value = mData.MaxMP_Final;
  793. break;
  794. case YLBattle.EBattleProperty.NPOWER:
  795. value = mData.MP_Final;
  796. break;
  797. case YLBattle.EBattleProperty.POSX:
  798. value = this.transform.position.x;
  799. break;
  800. case YLBattle.EBattleProperty.POSY:
  801. value = this.transform.position.z;
  802. break;
  803. }
  804. return value;
  805. }
  806. public void SetPropertyFinal(YLBattle.Buff buff, YLBattle.EBattleProperty property, float value)
  807. {
  808. switch (property)
  809. {
  810. case YLBattle.EBattleProperty.YANLI:
  811. mData.YAN_Final = (int)value;
  812. break;
  813. case YLBattle.EBattleProperty.KANGBAOLI:
  814. mData.KBL_Final = value;
  815. break;
  816. case YLBattle.EBattleProperty.ATTACK:
  817. mData.ATK_Final = (int)value;
  818. break;
  819. case YLBattle.EBattleProperty.ATTACKSPEED:
  820. mData.ASP_Final = value;
  821. // mAnimator.speed = mData.ASP_Final;
  822. break;
  823. case YLBattle.EBattleProperty.MOVESPEED:
  824. mData.MSP_Final = value;
  825. // SetMoveSpeed(mData.MSP_Final);
  826. break;
  827. case YLBattle.EBattleProperty.COOLTIME:
  828. mData.CLT_Final = value;
  829. break;
  830. case YLBattle.EBattleProperty.ATKRANGE:
  831. mData.ARG_Final = value;
  832. break;
  833. case YLBattle.EBattleProperty.ALARMRANGE:
  834. mData.ORG_Final = value;
  835. break;
  836. case YLBattle.EBattleProperty.CRITICALPROB:
  837. mData.CRT_Final = value;
  838. break;
  839. case YLBattle.EBattleProperty.CRITICALDAMAGE:
  840. mData.CRD_Final = value;
  841. break;
  842. case YLBattle.EBattleProperty.DEFENSE:
  843. mData.DEF_Final = (int)value;
  844. break;
  845. case YLBattle.EBattleProperty.HEIGHT:
  846. value = 2;
  847. break;
  848. case YLBattle.EBattleProperty.HP:
  849. mData.HP_Final = (int)value;
  850. break;
  851. case YLBattle.EBattleProperty.HPMAX:
  852. mData.MaxHP_Final = (int)value;
  853. break;
  854. case YLBattle.EBattleProperty.LEVEL:
  855. break;
  856. case YLBattle.EBattleProperty.MAGICFORCE:
  857. mData.MDF_Final = (int)value;
  858. break;
  859. case YLBattle.EBattleProperty.MAGICSTRENGTH:
  860. mData.ADM_Final = (int)value;
  861. break;
  862. case YLBattle.EBattleProperty.NMAXPOWER:
  863. mData.MaxMP_Final = (int)value;
  864. break;
  865. case YLBattle.EBattleProperty.NPOWER:
  866. mData.SetMP((int)value, true);
  867. break;
  868. case YLBattle.EBattleProperty.POSX:
  869. break;
  870. case YLBattle.EBattleProperty.POSY:
  871. break;
  872. }
  873. }
  874. public bool GetPropertyBuff(YLBattle.EBuffEffect eff)
  875. {
  876. int value = 0;
  877. switch (eff)
  878. {
  879. case YLBattle.EBuffEffect.EBUFF_EFFECT_Shield:
  880. value = this.mData.BUFF_SHI;
  881. break;
  882. case YLBattle.EBuffEffect.EBUFF_EFFECT_Silent:
  883. value = this.mData.BUFF_SIL;
  884. break;
  885. case YLBattle.EBuffEffect.EBUFF_EFFECT_Static:
  886. value = this.mData.BUFF_STA;
  887. break;
  888. case YLBattle.EBuffEffect.EBUFF_EFFECT_Stun:
  889. value = this.mData.BUFF_STU;
  890. break;
  891. case YLBattle.EBuffEffect.EBUFF_EFFECT_BUR:
  892. value = this.mData.BUFF_BUR;
  893. break;
  894. case YLBattle.EBuffEffect.EBUFF_EFFECT_ICE:
  895. value = this.mData.BUFF_ICE;
  896. break;
  897. case YLBattle.EBuffEffect.EBUFF_EFFECT_DIM:
  898. value = this.mData.BUFF_DIM;
  899. break;
  900. }
  901. return value > 0 ? true : false;
  902. }
  903. public void AddPropertyBuff(YLBattle.Buff buff, YLBattle.EBuffEffect eff)
  904. {
  905. sm_buff nowbuff = GameConfigData.Ins.GetbuffMo(int.Parse(buff.tid));
  906. // 创建战报
  907. Role cRole = buff.caster;
  908. Role tRole = buff.target;
  909. WarReport.WarReportInfo info = new WarReport.WarReportInfo();
  910. WarReport.WarReportUnit ownerUnit = new WarReport.WarReportUnit();
  911. WarReport.WarReportUnit targetUnit = new WarReport.WarReportUnit();
  912. ownerUnit.InitData(cRole);
  913. targetUnit.InitData(tRole);
  914. info.UnitDataOwner.Add(ownerUnit);
  915. info.UnitDataTarget.Add(targetUnit);
  916. switch (eff)
  917. {
  918. case YLBattle.EBuffEffect.EBUFF_EFFECT_Shield:
  919. targetUnit.OriginData.BUFF_SHI = this.mData.BUFF_SHI;
  920. this.mData.BUFF_SHI += 1;
  921. targetUnit.NowData.BUFF_SHI = this.mData.BUFF_SHI;
  922. targetUnit.DiffData.BUFF_SHI = 1;
  923. break;
  924. case YLBattle.EBuffEffect.EBUFF_EFFECT_Silent:
  925. targetUnit.OriginData.BUFF_SIL = this.mData.BUFF_SIL;
  926. this.mData.BUFF_SIL += 1;
  927. targetUnit.NowData.BUFF_SIL = this.mData.BUFF_SIL;
  928. targetUnit.DiffData.BUFF_SIL = 1;
  929. this.BuffStopAttack();
  930. break;
  931. case YLBattle.EBuffEffect.EBUFF_EFFECT_Static:
  932. targetUnit.OriginData.BUFF_STA = this.mData.BUFF_STA;
  933. this.mData.BUFF_STA += 1;
  934. targetUnit.NowData.BUFF_STA = this.mData.BUFF_STA;
  935. targetUnit.DiffData.BUFF_STA = 1;
  936. this.BuffStopAnimation();
  937. this.BuffStopMove();
  938. this.BuffStopAttack();
  939. break;
  940. case YLBattle.EBuffEffect.EBUFF_EFFECT_Stun:
  941. targetUnit.OriginData.BUFF_SHI = this.mData.BUFF_STU;
  942. this.mData.BUFF_STU += 1;
  943. targetUnit.NowData.BUFF_SHI = this.mData.BUFF_SHI;
  944. targetUnit.DiffData.BUFF_SHI = 1;
  945. this.BuffStopMove();
  946. this.BuffStopAttack();
  947. break;
  948. }
  949. //EventComponent eventCmpt = GameEntry.GetComponent<EventComponent>();
  950. //eventCmpt.FireNow(this, new BattleEventReport(WarReport.EReportType.DeBuffAttach, info));
  951. }
  952. public void RemovePropertyBuff(YLBattle.Buff buff, YLBattle.EBuffEffect eff)
  953. {
  954. sm_buff nowbuff = GameConfigData.Ins.GetbuffMo(int.Parse(buff.tid));
  955. // 创建战报
  956. Role cRole = buff.caster;
  957. Role tRole = buff.target;
  958. WarReport.WarReportInfo info = new WarReport.WarReportInfo();
  959. WarReport.WarReportUnit ownerUnit = new WarReport.WarReportUnit();
  960. WarReport.WarReportUnit targetUnit = new WarReport.WarReportUnit();
  961. ownerUnit.InitData(cRole);
  962. targetUnit.InitData(tRole);
  963. info.UnitDataOwner.Add(ownerUnit);
  964. info.UnitDataTarget.Add(targetUnit);
  965. switch (eff)
  966. {
  967. case YLBattle.EBuffEffect.EBUFF_EFFECT_Shield:
  968. this.mData.BUFF_SHI -= 1;
  969. targetUnit.NowData.BUFF_SHI = this.mData.BUFF_SHI;
  970. break;
  971. case YLBattle.EBuffEffect.EBUFF_EFFECT_Silent:
  972. this.mData.BUFF_SIL -= 1;
  973. //if (this.mData.SIL_Final <= 0)
  974. //{
  975. // if (this.mData.STU_Final <= 0 && this.mData.STA_Final <= 0)
  976. // {
  977. // this.BuffPlayAttack();
  978. // }
  979. //}
  980. targetUnit.NowData.BUFF_SIL = this.mData.BUFF_SIL;
  981. break;
  982. case YLBattle.EBuffEffect.EBUFF_EFFECT_Static:
  983. this.mData.BUFF_STA -= 1;
  984. //if (this.mData.STA_Final <= 0)
  985. //{
  986. // if (this.mData.SIL_Final <= 0 && this.mData.STU_Final <= 0)
  987. // {
  988. // this.BuffPlayAnimation();
  989. // this.BuffPlayAttack();
  990. // this.BuffPlayMove();
  991. // }
  992. // else if (this.mData.SIL_Final <= 0)
  993. // {
  994. // this.BuffPlayAnimation();
  995. // }
  996. // else if (this.mData.STU_Final <= 0)
  997. // {
  998. // this.BuffPlayAnimation();
  999. // this.BuffPlayMove();
  1000. // }
  1001. //}
  1002. targetUnit.NowData.BUFF_STA = this.mData.BUFF_STA;
  1003. break;
  1004. case YLBattle.EBuffEffect.EBUFF_EFFECT_Stun:
  1005. this.mData.BUFF_STU -= 1;
  1006. //if (this.mData.STU_Final <= 0)
  1007. //{
  1008. // if (this.mData.SIL_Final <= 0 && this.mData.STA_Final <= 0)
  1009. // {
  1010. // this.BuffPlayAttack();
  1011. // this.BuffPlayMove();
  1012. // }
  1013. // else if (this.mData.STA_Final <= 0)
  1014. // {
  1015. // this.BuffPlayMove();
  1016. // }
  1017. //}
  1018. targetUnit.NowData.BUFF_STU = this.mData.BUFF_STU;
  1019. break;
  1020. }
  1021. //EventComponent eventCmpt = GameEntry.GetComponent<EventComponent>();
  1022. //eventCmpt.FireNow(this, new BattleEventReport(WarReport.EReportType.DeBuffCancel, info));
  1023. }
  1024. public int GetLastBuff(string tid, int iid)
  1025. {
  1026. return int.Parse(tid) * 100 + iid;
  1027. }
  1028. public bool IsDead()
  1029. {
  1030. return this.isDie;
  1031. }
  1032. public void BuffStopMove()
  1033. {
  1034. buffCanMove = false;
  1035. }
  1036. public void BuffPlayMove()
  1037. {
  1038. buffCanMove = true;
  1039. }
  1040. public void BuffStopAnimation()
  1041. {
  1042. mAnimator.speed = 0;
  1043. }
  1044. public void BuffPlayAnimation()
  1045. {
  1046. mAnimator.speed = 1;
  1047. }
  1048. public void BuffStopAttack()
  1049. {
  1050. buffCanAttack = false;
  1051. }
  1052. public void BuffPlayAttack()
  1053. {
  1054. buffCanAttack = true;
  1055. }
  1056. public void OnTriggerEnter(Collider other)
  1057. {
  1058. }
  1059. }