BaseHero.cs 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690
  1. using Adon.Game.Data;
  2. using Adon.Game.Data.StructData;
  3. using Adon.Game.BO;
  4. using Adon.Game.Helper;
  5. using Chronos;
  6. using Cinemachine;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using UnityEngine;
  10. using UnityEngine.Playables;
  11. using WarReport;
  12. using BehaviorDesigner.Runtime;
  13. using X2Battle;
  14. namespace AdonGameKit
  15. {
  16. /// <summary>
  17. /// 英雄基础类
  18. /// </summary>
  19. public class BaseHero : BaseCharacterAdon
  20. {
  21. #region readonly
  22. /// <summary>
  23. /// 前速度字符
  24. /// </summary>
  25. readonly int m_HashForwardSpeed = Animator.StringToHash("ForwardSpeed");
  26. /// <summary>
  27. /// 近战攻击字符
  28. /// </summary>
  29. readonly int m_HashMeleeAttack = Animator.StringToHash("MeleeAttack");
  30. /// <summary>
  31. /// 冲刺攻击字符
  32. /// </summary>
  33. readonly int m_HashDashAttack = Animator.StringToHash("DashAttack");
  34. /// <summary>
  35. /// 后退闪避字符
  36. /// </summary>
  37. readonly int m_HashDodge = Animator.StringToHash("Dodge");
  38. /// <summary>
  39. /// 前冲闪避字符
  40. /// </summary>
  41. readonly int m_HashRush = Animator.StringToHash("Rush");
  42. /// <summary>
  43. /// 技能字符
  44. /// </summary>
  45. readonly int m_HashSkill = Animator.StringToHash("Skill");
  46. readonly int m_HashIdle = Animator.StringToHash("Idle");
  47. #endregion
  48. GameObject _targetMonster;
  49. /// <summary>
  50. /// 目标怪
  51. /// </summary>
  52. public GameObject m_targetMonster;
  53. /// <summary>
  54. /// 技能碰撞器
  55. /// </summary>
  56. public Collider m_SkillCol;
  57. /// <summary>
  58. /// 是否僵直中
  59. /// </summary>
  60. private bool isStiff;
  61. /// <summary>
  62. /// 根时钟
  63. /// </summary>
  64. private Clock m_clockRoot;
  65. /// <summary>
  66. /// 玩家时钟
  67. /// </summary>
  68. public Clock m_clockPlayer;
  69. /// <summary>
  70. /// 敌人时钟
  71. /// </summary>
  72. private Clock m_clockEnemy;
  73. /// <summary>
  74. /// 僵直时间
  75. /// </summary>
  76. private float stiffTime;
  77. /// <summary>
  78. /// 是否被击
  79. /// </summary>
  80. private bool isAttacked;
  81. /// <summary>
  82. /// 是否治疗
  83. /// </summary>
  84. private bool isCuring;
  85. /// <summary>
  86. /// 损伤材质闪光强度
  87. /// </summary>
  88. private float m_damageFlashScale;
  89. /// <summary>
  90. /// 损伤材质闪光强度
  91. /// </summary>
  92. private float m_CuringFlashScale;
  93. /// <summary>
  94. /// 是否看向目标
  95. /// </summary>
  96. private bool isHeadlook;
  97. private bool isExtermeTimeZone;//是否进入极限闪避时区
  98. private float m_ExtermeZoneTimer;//极限闪避时区计时
  99. private bool isExtermeDodge;//是否进入极限闪避
  100. private float m_ExtermeDodgeTimer;//极限闪避计时
  101. /// <summary>
  102. /// 镜头效果组件
  103. /// </summary>
  104. public PlayableDirector m_PlayableDirector;
  105. public HeroBlur m_HeroBlur;//残影组件
  106. /// <summary>
  107. /// 检测的攻击范围
  108. /// </summary>
  109. public float m_AutoAttackRange = 18;
  110. /// <summary>
  111. /// 近战攻击视野
  112. /// </summary>
  113. public float m_AttackSight = 3;
  114. /// <summary>
  115. /// 攻击角度
  116. /// </summary>
  117. public float m_AttackAngle = 160;
  118. //private GameObject m_targetMonster;
  119. /// <summary>
  120. /// 推力方向
  121. /// </summary>
  122. public Vector3 m_ForceDirection;
  123. /// <summary>
  124. /// 是否切换角色
  125. /// </summary>
  126. private bool IsSwitchRoles;
  127. /// <summary>
  128. /// 无敌
  129. /// </summary>
  130. private bool isGod;
  131. /// <summary>
  132. /// 无敌时间
  133. /// </summary>
  134. private float m_GodTime;
  135. private float detectTime;
  136. private bool isStun;
  137. /// <summary>
  138. /// 网络同步间隔
  139. /// </summary>
  140. public float netUpdateTime = 0.1f;
  141. public float curUpdateTime = 0;
  142. /// <summary>
  143. /// 言灵挂件
  144. /// </summary>
  145. public Dictionary<string, BaseYLPartAdon> m_YLParts = new Dictionary<string, BaseYLPartAdon>();
  146. Dictionary<int, int> buffnum = new Dictionary<int, int>();//buff计数
  147. protected static readonly int hashHit = Animator.StringToHash("Hit");//打击
  148. protected static readonly int hashHitAngle = Animator.StringToHash("HitAngle");//受击方向
  149. protected static readonly int hashHitDown = Animator.StringToHash("HitDown");//击倒
  150. protected static readonly int hashDie = Animator.StringToHash("Die");//死亡
  151. protected static readonly int hashDieDown = Animator.StringToHash("DieDown");//击飞死亡
  152. protected static readonly int hashStun = Animator.StringToHash("Stun");//眩晕
  153. protected static readonly int hashWin = Animator.StringToHash("Win");//胜利
  154. private Transform attackRangeTran = null;
  155. /// <summary>
  156. /// 时间器刚体
  157. /// </summary>
  158. private RigidbodyTimeline3D m_Rigidbody
  159. {
  160. get { return time.rigidbody; }
  161. }
  162. /// <summary>
  163. /// 时间寻路组件
  164. /// </summary>
  165. public NavMeshAgentTimeline m_navMeshAgent
  166. {
  167. get { return time.navMeshAgent; }
  168. }
  169. /// <summary>
  170. /// 头部言灵
  171. /// </summary>
  172. BaseYLPartAdon _Head_YL;
  173. BaseYLPartAdon _Shoulder_YL;
  174. BaseYLPartAdon _Foot_YL;
  175. /// <summary>
  176. /// 头部言灵
  177. /// </summary>
  178. public BaseYLPartAdon m_Head_YL
  179. {
  180. get
  181. {
  182. if (_Head_YL == null)
  183. {
  184. Transform head_YL = X2BattleManager.Instance.mBulletModel.GetCmptRootByType(this, YanLingBonePoint.BonePoint.head);
  185. ///获取言灵脚本
  186. _Head_YL = head_YL.GetComponent<BaseYLPartAdon>();
  187. _Head_YL.m_Hero = this;
  188. }
  189. return _Head_YL;
  190. }
  191. }
  192. /// <summary>
  193. /// 肩部言灵
  194. /// </summary>
  195. public BaseYLPartAdon m_Shoulder_YL
  196. {
  197. get
  198. {
  199. if (_Shoulder_YL == null)
  200. {
  201. Transform Shoulder_YL = X2BattleManager.Instance.mBulletModel.GetCmptRootByType(this, YanLingBonePoint.BonePoint.shoulder);
  202. ///获取言灵脚本
  203. _Shoulder_YL = Shoulder_YL.GetComponent<BaseYLPartAdon>();
  204. _Shoulder_YL.m_Hero = this;
  205. }
  206. return _Shoulder_YL;
  207. }
  208. }
  209. /// <summary>
  210. /// 脚部言灵
  211. /// </summary>
  212. public BaseYLPartAdon m_Foot_YL
  213. {
  214. get
  215. {
  216. if (_Foot_YL == null)
  217. {
  218. Transform foot_YL = X2BattleManager.Instance.mBulletModel.GetCmptRootByType(this, YanLingBonePoint.BonePoint.foot);
  219. ///获取言灵脚本
  220. _Foot_YL = foot_YL.GetComponent<BaseYLPartAdon>();
  221. _Foot_YL.m_Hero = this;
  222. }
  223. return _Foot_YL;
  224. }
  225. }
  226. protected override void Awake()
  227. {
  228. base.Awake();
  229. m_CameraManagerAdon = gameObject.AddComponent<CameraManagerAdon>();//添加相机管理
  230. m_CameraManagerAdon.m_Hero = this.transform;
  231. m_HeroBlur = gameObject.AddComponent<HeroBlur>();//添加残影脚本
  232. m_HeroBlur.enabled = false;
  233. m_fbx.gameObject.GetComponent<FBXEvent>().SetOwner(this.gameObject);
  234. mCM_ThirdPerson = transform.Find("CMStateDrivenCamera/CM_ThirdPerson").GetComponent<CinemachineFreeLook>();
  235. attackRangeTran = transform.Find("AttackRange");
  236. m_CameraManagerAdon.m_Timeline_CM_Respawn.gameObject.SetActive(false);
  237. }
  238. void Start()
  239. {
  240. m_clockRoot = Timekeeper.instance.Clock("Root");
  241. m_clockPlayer = Timekeeper.instance.Clock("Player");
  242. m_clockEnemy = Timekeeper.instance.Clock("Enemy");
  243. //m_fbx.gameObject.SetActive(true);
  244. ////开始场景漫游相机
  245. //CameraManager.Instance.PlaySceneTour();
  246. }
  247. private void OnEnable()
  248. {
  249. if (IsSwitchRoles)
  250. {
  251. BattleCanvas.Instance.userYanlingSkill = BattleUseYanlingSkill;//注册言灵技委托。
  252. BattleCanvas.Instance.cancelyanlingSkill = BattleCancelyanlingSkill;//注册言灵技委托。
  253. m_fbx.gameObject.SetActive(true);
  254. m_CameraManagerAdon.SwitchToCM_TopDown();
  255. SetAnimatorStatusIdle();
  256. }
  257. else
  258. {
  259. //m_fbx.gameObject.SetActive(false);
  260. Invoke("showFBX", 0.5f);//延迟显示角色
  261. }
  262. }
  263. void Update()
  264. {
  265. if (m_bStopTime)//时间暂停
  266. {
  267. if (m_stopTime <= Time.realtimeSinceStartup - lastUpdateTime)
  268. {
  269. Time.timeScale = 1;
  270. m_bStopTime = false;
  271. }
  272. }
  273. if (isGod)
  274. {
  275. //m_CapsuleCollider.enabled = false;
  276. if (m_GodTime <= 0)
  277. {
  278. m_GodTime = 0;
  279. isGod = false;
  280. //m_CapsuleCollider.enabled = true; ;
  281. }
  282. m_GodTime -= time.deltaTime;
  283. }
  284. ///检测可锁定的攻击目标
  285. detectTime += time.deltaTime;
  286. if (detectTime >= 0.1f)
  287. {
  288. detectTime = 0;
  289. PlayerHelperAdon.GetNearEnemyDistance(this, m_AutoAttackRange, out _targetMonster);
  290. if (_targetMonster == null)
  291. {
  292. if (m_targetMonster != null)
  293. {
  294. m_targetMonster.GetComponent<BaseMonsterAdon>().ReleaseLock();
  295. m_targetMonster = null;
  296. }
  297. return;
  298. }
  299. if (m_targetMonster != _targetMonster)
  300. {
  301. if (m_targetMonster != null)
  302. {
  303. m_targetMonster.GetComponent<BaseMonsterAdon>().ReleaseLock();
  304. ReleaseTarget();
  305. }
  306. if (_targetMonster != null)
  307. {
  308. _targetMonster.GetComponent<BaseMonsterAdon>().Lock();
  309. }
  310. m_targetMonster = _targetMonster;
  311. TargetRole = _targetMonster.GetComponent<BaseMonsterAdon>();
  312. }
  313. // BOSS 通过服务器刷新血量
  314. if (GameDateManager.Instance.GateVO != null && int.Parse(GameDateManager.Instance.GateVO.Mo.battleType) != (int)BattleDefine.EBattleSceneType.EBattleType_WorldBoss)
  315. {
  316. BattleCanvas.Instance.ShowLockMonsterHP(TargetRole);
  317. }
  318. }
  319. //残影测试
  320. if (Input.GetKeyDown(KeyCode.Q))
  321. {
  322. m_HeroBlur.enabled = false;
  323. m_HeroBlur.enabled = true;
  324. }
  325. // 网络同步
  326. curUpdateTime += Time.deltaTime;
  327. if (curUpdateTime > netUpdateTime)
  328. {
  329. curUpdateTime = curUpdateTime - netUpdateTime;
  330. }
  331. else
  332. {
  333. return;
  334. }
  335. //if (this.mData.UID == HeroPlayerController.Instance.m_Hero.mData.UID)
  336. if (GameDateManager.Instance.isMultiRoom && playerUID == UserProxy.Instance.player.uid)
  337. {
  338. float x = this.transform.position.x;
  339. float y = this.transform.position.y;
  340. float z = this.transform.position.z;
  341. MultiBattleProxy.Instance.SendPostion(x, y, z);
  342. }
  343. }
  344. void showFBX()
  345. {
  346. m_fbx.gameObject.SetActive(true);
  347. m_CameraManagerAdon.m_Timeline_CM_Respawn.gameObject.SetActive(true);
  348. //CameraManager.Instance.StopSceneTour();//停止场景漫游
  349. //判断是否为角色切换,如果是角色切换则不播放出生动作和出生特写镜头
  350. if (IsSwitchRoles)
  351. {
  352. m_CameraManagerAdon.SwitchToCM_TopDown();
  353. SetAnimatorStatusIdle();
  354. }
  355. else
  356. {
  357. m_CameraManagerAdon.m_Timeline_CM_Respawn.gameObject.SetActive(true);
  358. }
  359. }
  360. /// <summary>
  361. /// 设置是否切换角色
  362. /// </summary>
  363. /// <param name="isSwitchRoles"></param>
  364. public void SetIsSwitchRoles(bool isSwitchRoles)
  365. {
  366. IsSwitchRoles = isSwitchRoles;
  367. m_fbx.gameObject.SetActive(true);
  368. if (IsSwitchRoles)
  369. {
  370. BattleCanvas.Instance.userYanlingSkill = BattleUseYanlingSkill;//注册言灵技委托。
  371. BattleCanvas.Instance.cancelyanlingSkill = BattleCancelyanlingSkill;//注册言灵技委托。
  372. }
  373. }
  374. void FixedUpdate()
  375. {
  376. if (isStiff)//僵直
  377. {
  378. if (stiffTime > 0)
  379. {
  380. stiffTime -= Time.deltaTime;
  381. }
  382. else
  383. {
  384. stiffTime = 0;
  385. m_clockRoot.localTimeScale = 1;
  386. //m_clockPlayer.localTimeScale = 1;
  387. //m_clockEnemy.localTimeScale = 1;
  388. //m_Hero.m_Animator.speed = 1;
  389. isStiff = false;
  390. }
  391. }
  392. //受击闪光效果
  393. if (isAttacked)
  394. {
  395. m_damageFlashScale -= time.deltaTime * 10;
  396. if (m_damageFlashScale <= 0)
  397. {
  398. m_damageFlash.gameObject.SetActive(false);
  399. m_damageFlashScale = 0;
  400. isAttacked = false;
  401. }
  402. for (int l = 0; l < m_damageFlashMaterial.Length; l++)
  403. {
  404. m_damageFlashMaterial[l].SetFloat("_Scale", m_damageFlashScale);
  405. }
  406. }
  407. //治愈闪光效果
  408. if (isCuring)
  409. {
  410. m_CuringFlashScale -= time.deltaTime * 2;
  411. if (m_CuringFlashScale <= 0)
  412. {
  413. m_CuringFlashs.gameObject.SetActive(false);
  414. m_CuringFlashScale = 0;
  415. isCuring = false;
  416. }
  417. for (int l = 0; l < m_CuringFlashMaterial.Length; l++)
  418. {
  419. m_CuringFlashMaterial[l].SetFloat("_Scale", m_CuringFlashScale);
  420. }
  421. }
  422. //看向目标
  423. if (m_PerfectLookAtAdon != null)
  424. {
  425. if (isHeadlook == true)//如果看向目标
  426. {
  427. m_PerfectLookAtAdon.m_Weight += 0.03f;//权重增加
  428. }
  429. else
  430. {
  431. m_PerfectLookAtAdon.m_Weight -= 0.03f;//权重递减
  432. }
  433. if (m_PerfectLookAtAdon.m_Weight > 1)
  434. {
  435. m_PerfectLookAtAdon.m_Weight = 1;//限制权重不能大于1
  436. }
  437. else if (m_PerfectLookAtAdon.m_Weight < 0)
  438. {
  439. m_PerfectLookAtAdon.m_Weight = 0;//限制权重不能小于0
  440. }
  441. }
  442. if (isExtermeTimeZone)//进入极限闪避时区
  443. {
  444. m_ExtermeZoneTimer -= Time.deltaTime;//递减极限闪避时区
  445. if (m_ExtermeZoneTimer <= 0)
  446. {
  447. m_ExtermeZoneTimer = 0;
  448. isExtermeTimeZone = false;
  449. }
  450. }
  451. if (isExtermeDodge)//成功极限闪避
  452. {
  453. m_ExtermeDodgeTimer -= Time.deltaTime;//递减极限闪避时区
  454. if (m_ExtermeDodgeTimer <= 0)
  455. {
  456. m_ExtermeDodgeTimer = 0;
  457. isExtermeDodge = false;
  458. FreedExterme();
  459. }
  460. }
  461. }
  462. #region ============================================ MSG ======================================================
  463. /// <summary>
  464. /// 攻击消息
  465. /// </summary>
  466. /// <param name="baseData"></param>
  467. public void OnMsg_Attack(Attack_MsgData data)
  468. {
  469. SetAnimatorStatusAttack(data);
  470. }
  471. public void SetAnimatorStatusAttack(Attack_MsgData data)
  472. {
  473. m_Rigidbody.velocity = Vector3.zero;//刚体推力设置为0
  474. m_Animator.SetBool(m_HashMeleeAttack, true);//触发近战攻击动作
  475. data.dir.Normalize();
  476. transform.rotation = Quaternion.LookRotation(data.dir);//看向方向
  477. if (m_targetMonster)
  478. {
  479. LockingTarget();//锁定目标
  480. }
  481. // 网络同步
  482. if (GameDateManager.Instance.isMultiRoom && playerUID == UserProxy.Instance.player.uid)
  483. {
  484. string msgData = CommonManager.Serialize<Attack_MsgData>(data);
  485. MultiBattleProxy.Instance.SendStatus("SetBool", msgData);
  486. }
  487. }
  488. /// <summary>
  489. /// 冲刺攻击
  490. /// </summary>
  491. /// <param name="b"></param>
  492. public void SetAnimatorStatusDash(Rush_MsgData data)
  493. {
  494. m_Rigidbody.velocity = Vector3.zero;//刚体推力设置为0
  495. data.dir.Normalize();
  496. transform.localRotation = Quaternion.LookRotation(data.dir);//看向方向
  497. if (m_targetMonster)
  498. {
  499. LockingTarget();//锁定目标
  500. }
  501. m_Animator.SetTrigger(m_HashDashAttack);//触发冲刺攻击动作
  502. }
  503. /// <summary>
  504. /// 闪避后退
  505. /// </summary>
  506. /// <param name="b"></param>
  507. public void SetAnimatorStatusDodge()
  508. {
  509. bDodge = true;
  510. m_Animator.SetTrigger(m_HashDodge);
  511. // 网络同步
  512. if (GameDateManager.Instance.isMultiRoom && playerUID == UserProxy.Instance.player.uid)
  513. {
  514. MultiBattleProxy.Instance.SendStatus("Dodge", m_HashDodge.ToString());
  515. }
  516. }
  517. /// <summary>
  518. /// 闪避前进
  519. /// </summary>
  520. /// <param name="b"></param>
  521. public void SetAnimatorStatusRush()
  522. {
  523. bDodge = true;
  524. m_Animator.SetTrigger(m_HashRush);
  525. // 网络同步
  526. if (GameDateManager.Instance.isMultiRoom && playerUID == UserProxy.Instance.player.uid)
  527. {
  528. MultiBattleProxy.Instance.SendStatus("Rush", m_HashDodge.ToString());
  529. }
  530. }
  531. /// <summary>
  532. /// 施放必杀
  533. /// </summary>
  534. public void SetAnimatorStatusSkill()
  535. {
  536. // m_Animator.SetTrigger(m_HashSkill);
  537. // 释放必杀 放入场景
  538. GameObject bishaEffObj = m_Animator.transform.Find("Effect_000/Attacks/skill/skill_101005").gameObject;
  539. GameObject newEffObj = (GameObject)Instantiate(bishaEffObj, bishaEffObj.transform.parent);
  540. newEffObj.SetActive(true);
  541. newEffObj.transform.parent = null;
  542. FBXEvent fe = newEffObj.GetComponent<FBXEvent>();
  543. fe.SetOwner(this.gameObject);
  544. // 网络同步
  545. if (GameDateManager.Instance.isMultiRoom && playerUID == UserProxy.Instance.player.uid)
  546. {
  547. MultiBattleProxy.Instance.SendStatus("Skill", m_HashSkill.ToString());
  548. }
  549. }
  550. /// <summary>
  551. /// 等待
  552. /// </summary>
  553. public void SetAnimatorStatusIdle()
  554. {
  555. m_Animator.SetTrigger(m_HashIdle);
  556. // 网络同步
  557. if (GameDateManager.Instance.isMultiRoom && playerUID == UserProxy.Instance.player.uid)
  558. {
  559. MultiBattleProxy.Instance.SendStatus("Idle", m_HashIdle.ToString());
  560. }
  561. }
  562. /// <summary>
  563. /// 冲刺攻击消息
  564. /// </summary>
  565. /// <param name="data"></param>
  566. public void OnMsg_DashAttack(Rush_MsgData data)
  567. {
  568. SetAnimatorStatusDash(data);
  569. // 网络同步
  570. if (GameDateManager.Instance.isMultiRoom && playerUID == UserProxy.Instance.player.uid)
  571. {
  572. string msgData = CommonManager.Serialize<Rush_MsgData>(data);
  573. MultiBattleProxy.Instance.SendStatus("DashAttack", m_HashDashAttack.ToString());
  574. }
  575. }
  576. /// <summary>
  577. /// 闪避消息
  578. /// </summary>
  579. /// <param name="data"></param>
  580. public void OnMsg_Dodge(Dodge_MsgData data)
  581. {
  582. isGod = true;
  583. m_GodTime = 0.5f;
  584. ////if (m_CurState != eState.Idle)
  585. {
  586. SetAnimatorStatusRush();//触发前冲闪避
  587. }
  588. ////else
  589. ////{
  590. //// SetAnimatorStatusDodge();//触发后退闪避动作
  591. ////}
  592. data.dir.Normalize();
  593. //if (isExtermeTimeZone)//极限闪避
  594. //{
  595. // SetExtermeDodgeTimer(10);
  596. //}
  597. }
  598. public void OnMsg_Bisha(Dodge_MsgData data)
  599. {
  600. SetAnimatorStatusSkill();
  601. }
  602. /// <summary>
  603. /// 技能消息
  604. /// </summary>
  605. /// <param name="data"></param>
  606. public void OnMsg_Skill(Skill_MsgData data)
  607. {
  608. m_Rigidbody.velocity = Vector3.zero;//刚体推力设置为0
  609. SetAnimatorStatusSkill();
  610. data.dir.Normalize();
  611. transform.rotation = Quaternion.LookRotation(data.dir);//看向方向
  612. if (m_targetMonster)
  613. {
  614. LockingTarget();//锁定目标
  615. }
  616. m_CurState = eState.Skill;
  617. }
  618. /// <summary>
  619. /// 受击消息接收
  620. /// </summary>
  621. /// <param name="baseData"></param>
  622. public override void OnMsg_Attacked(Attacked_MsgData data)
  623. {
  624. Debug.Log("英雄受击消息");
  625. //m_targetMonster = data.sender;
  626. m_ForceDirection = data.forceDirection;
  627. //计算怪角度偏移
  628. float HitAngle = PlayerHelperAdon.Angle_360(transform.forward, m_ForceDirection);
  629. HpbarManager.Instance.CreateHpTip(this, data.dmg, data.isCR, data.weakness);//血条及数字显示
  630. if (data.resultHp <= 0)//死亡
  631. {
  632. if (data.attackedEffType == EnumDefine.AttackedEffT.DWN)//击倒击飞
  633. {
  634. SetCameraShake(transform.position, 2f, 0.1f, 0.3f);//震屏
  635. m_Animator.SetTrigger(hashDieDown);//播放击飞死亡动作
  636. //转向玩家
  637. transform.LookAt(data.sender.transform);
  638. }
  639. else
  640. {
  641. m_Animator.SetTrigger(hashDie);//播放死亡动作
  642. SetCameraShake(transform.position, 0.8f, 0.1f, 0.2f);//震屏
  643. }
  644. // 英雄死亡
  645. HeroDie();
  646. }
  647. else
  648. {
  649. if (data.dmg < 0)
  650. {
  651. if (data.attackedEffType == EnumDefine.AttackedEffT.DWN)//击倒击飞
  652. {
  653. SetCameraShake(transform.position, 2f, 0.1f, 0.3f);//震屏
  654. m_Animator.SetTrigger(hashHitDown);//播放击倒动作
  655. transform.LookAt(data.sender.transform);
  656. }
  657. else if (data.attackedEffType == EnumDefine.AttackedEffT.NOR)
  658. {
  659. SetCameraShake(transform.position, 0.8f, 0.1f, 0.2f);//震屏
  660. }
  661. else
  662. {
  663. m_Animator.SetTrigger(hashHit);//播放受击动作
  664. m_Animator.SetFloat(hashHitAngle, HitAngle);//根据受击方向播受击动作
  665. SetCameraShake(transform.position, 0.8f, 0.1f, 0.2f);//震屏
  666. }
  667. }
  668. }
  669. //实例化克隆被击光效
  670. if (data.AttackedEff != null)
  671. {
  672. GameObject effobj = Instantiate(data.AttackedEff);
  673. if (!effobj.GetComponent<DestroyObjectDelayed>()) effobj.gameObject.AddComponent<DestroyObjectDelayed>();//添加延迟销毁脚本
  674. effobj.transform.position = m_HitObj.position;
  675. if (m_targetMonster != null)
  676. {
  677. effobj.transform.rotation = m_targetMonster.transform.rotation;
  678. }
  679. effobj.SetActive(true);
  680. }
  681. if (data.SkillId == "711002" || data.SkillId == "708003" || data.dmg > 0)
  682. {
  683. //m_damageFlash.gameObject.SetActive(true);//受击高亮材质显示
  684. //m_damageFlashScale = 5;
  685. //for (int l = 0; l < m_damageFlashMaterial.Length; l++)
  686. //{
  687. // m_damageFlashMaterial[l].SetFloat("_Scale", m_damageFlashScale);
  688. //}
  689. m_freezeFlashs.gameObject.SetActive(true);
  690. //m_freezeFlashPower = 5;
  691. for (int l = 0; l < m_freezeFlashMaterial.Length; l++)
  692. {
  693. m_freezeFlashMaterial[l].SetFloat("_Power", 0.6f);
  694. }
  695. }
  696. else
  697. {
  698. m_damageFlash.gameObject.SetActive(true);//受击高亮材质显示
  699. m_damageFlashScale = 5;
  700. for (int l = 0; l < m_damageFlashMaterial.Length; l++)
  701. {
  702. m_damageFlashMaterial[l].SetFloat("_Scale", m_damageFlashScale);
  703. }
  704. }
  705. isAttacked = true;
  706. isGod = true;
  707. m_GodTime = 0.5f;
  708. }
  709. /// <summary>
  710. /// 英雄死亡
  711. /// </summary>
  712. private void HeroDie()
  713. {
  714. // 延迟删除角色
  715. RoleManager.Instance.DeleteRole(this, 2.0f);
  716. GameDateManager.Instance.PlayerDeathNumber++;
  717. HeroPlayerController.Instance.m_Hero.TargetRole = null;
  718. // 队长死亡
  719. if (IsTeamLeader)
  720. {
  721. GameDateManager.Instance.PlayerDeathNumber++;
  722. // 切换下一位队长
  723. RoleManager.Instance.NextTeamLeader(transform.position, (suc) =>
  724. {
  725. if (suc == false)
  726. {
  727. if (YLBattle.GameBattleManager.Instance().battleType == BattleDefine.EBattleSceneType.EBattleType_Arena)
  728. {
  729. RoleManager.Instance.ChallengeResult(false);
  730. }
  731. else
  732. {
  733. // 切换队长失败,游戏结束
  734. PanelHelper.Instance.ShowPanel("YL_BattleFailWindow", null, null);
  735. }
  736. }
  737. });
  738. }
  739. }
  740. /// <summary>
  741. /// 治愈消息接收
  742. /// </summary>
  743. /// <param name="baseData"></param>
  744. public void OnMsg_Curing(Attacked_MsgData data)
  745. {
  746. Debug.Log("英雄治愈消息");
  747. //m_targetMonster = data.sender;
  748. m_ForceDirection = data.forceDirection;
  749. //计算怪角度偏移
  750. float HitAngle = PlayerHelperAdon.Angle_360(transform.forward, m_ForceDirection);
  751. HpbarManager.Instance.CreateHpTip(this, data.dmg, data.isCR, data.weakness);//血条及数字显示
  752. //实例化克隆被击光效
  753. if (data.AttackedEff != null)
  754. {
  755. GameObject effobj = Instantiate(data.AttackedEff);
  756. if (!effobj.GetComponent<DestroyObjectDelayed>()) effobj.gameObject.AddComponent<DestroyObjectDelayed>();//添加延迟销毁脚本
  757. effobj.transform.position = m_HitObj.position;
  758. effobj.transform.rotation = this.transform.rotation;
  759. effobj.SetActive(true);
  760. }
  761. m_CuringFlashs.gameObject.SetActive(true);//治愈高亮材质显示
  762. m_CuringFlashScale = 5;
  763. for (int l = 0; l < m_CuringFlashMaterial.Length; l++)
  764. {
  765. m_CuringFlashMaterial[l].SetFloat("_Scale", m_CuringFlashScale);
  766. }
  767. isCuring = true;
  768. }
  769. ///// <summary>
  770. ///// 战士普通打击
  771. ///// </summary>
  772. ///// <param name="attackIdx"></param>
  773. ///// <param name="enemy"></param>
  774. //public void OnMsgAttackHit(WarReportInfo report)
  775. //{
  776. // WarReportUnit enemyData = report.UnitDataTarget[0];
  777. // BaseMonsterAdon enemy = RoleManager.Instance.GetRole(enemyData.UnitId) as BaseMonsterAdon;
  778. // //m_targetMonster = enemy.gameObject;
  779. // //僵直一下
  780. // //m_clockRoot.localTimeScale = 0.01f;
  781. // //特效时钟暂停
  782. // stiffTime += 0.05f;
  783. // if (stiffTime > 0.3f)
  784. // {
  785. // stiffTime = 0.3f;
  786. // }
  787. // isStiff = true;
  788. // Attacked_MsgData data = new Attacked_MsgData();//受击消息数据
  789. // data.sender = this.gameObject;
  790. // Vector3 force = enemy.transform.position - transform.position;//推力方向
  791. // force.Normalize();
  792. // if (m_CurAttackIdx == 5)
  793. // {
  794. // data.attackedEffType = EnumDefine.AttackedEffT.DWN;
  795. // data.forceDirection = force;//推力方向
  796. // //发送震屏
  797. // //SetCameraShake(transform.position, 2, 0.1f, 0.3f);
  798. // }
  799. // else if (m_CurAttackIdx == 0)
  800. // {
  801. // data.attackedEffType = EnumDefine.AttackedEffT.SLD;
  802. // data.forceDirection = force;//推力方向
  803. // //发送震屏
  804. // //SetCameraShake(transform.position, 2f, 0.1f, 0.3f);
  805. // }
  806. // else
  807. // {
  808. // data.attackedEffType = EnumDefine.AttackedEffT.SLD;
  809. // data.forceDirection = force;//推力方向
  810. // //发送震屏
  811. // //SetCameraShake(transform.position, 0.8f, 0.1f, 0.2f);
  812. // }
  813. // //计算怪剩余血量
  814. // data.resultHp = enemyData.NowData.HP_Final;
  815. // data.dmg = enemyData.DiffData.HP_Final;
  816. // data.isCR = enemyData.NowData.IS_CRT;//是否暴击
  817. // data.AttackedEff = m_FxManagerAdon.m_AttackedEff[m_CurAttackIdx].gameObject;//被击特效
  818. // enemy.OnMsg_Attacked(data);
  819. // if (data.resultHp <= 0)//目标死亡
  820. // {
  821. // //释放目标
  822. // ReleaseTarget();
  823. // }
  824. //}
  825. ///// <summary>
  826. ///// 言灵技能打击
  827. ///// </summary>
  828. ///// <param name="attackIdx"></param>
  829. ///// <param name="enemy"></param>
  830. //public void OnMsgYanlingSkill(WarReportInfo report)
  831. //{
  832. // //string OwnerId;//发送者id
  833. // //string TargetId;//目标者id
  834. // //string SkillId;//技能id
  835. // //int resultHP;//剩余血量
  836. // //int dmg;//单次伤害值
  837. // //bool isCR;//是否暴击
  838. // //bool isBuff;//是否为buff
  839. // //int buffType;//buff类型
  840. // //bool isDOG;//是否闪避
  841. // WarReportUnit enemyData = report.UnitDataTarget[0];
  842. // BaseMonsterAdon enemy = RoleManager.Instance.GetRole(enemyData.UnitId) as BaseMonsterAdon;
  843. // Attacked_MsgData data = new Attacked_MsgData();//受击消息数据
  844. // data.sender = this.gameObject;
  845. // Vector3 force = enemy.transform.position - transform.position;//推力方向
  846. // force.Normalize();
  847. // //判断技能id
  848. // if (m_CurAttackIdx == 5)
  849. // {
  850. // data.attackedEffType = EnumDefine.AttackedEffT.DWN;
  851. // data.forceDirection = force;//推力方向
  852. // //发送震屏
  853. // //SetCameraShake(transform.position, 2, 0.1f, 0.3f);
  854. // }
  855. // else if (m_CurAttackIdx == 0)
  856. // {
  857. // data.attackedEffType = EnumDefine.AttackedEffT.SLD;
  858. // data.forceDirection = force;//推力方向
  859. // //发送震屏
  860. // //SetCameraShake(transform.position, 2f, 0.1f, 0.3f);
  861. // }
  862. // else
  863. // {
  864. // data.attackedEffType = EnumDefine.AttackedEffT.SLD;
  865. // data.forceDirection = force;//推力方向
  866. // //发送震屏
  867. // //SetCameraShake(transform.position, 0.8f, 0.1f, 0.2f);
  868. // }
  869. // //计算怪剩余血量
  870. // data.resultHp = enemyData.NowData.HP_Final;
  871. // data.dmg = enemyData.DiffData.HP_Final;
  872. // data.isCR = enemyData.NowData.IS_CRT;//是否暴击
  873. // data.AttackedEff = m_FxManagerAdon.m_AttackedEff[m_CurAttackIdx].gameObject;//被击特效
  874. // enemy.OnMsg_Attacked(data);
  875. // if (data.resultHp <= 0)//目标死亡
  876. // {
  877. // //释放目标
  878. // ReleaseTarget();
  879. // }
  880. //}
  881. ///// <summary>
  882. ///// Debuff打击发动
  883. ///// </summary>
  884. ///// <param name="attackIdx"></param>
  885. ///// <param name="enemy"></param>
  886. //public void OnMsgDebuff(WarReportInfo report)
  887. //{
  888. // Attacked_MsgData data = new Attacked_MsgData();//受击消息数据
  889. // data.buffType = report.BuffDataInfo.mo.buffType;
  890. // data.valueMove = report.BuffDataInfo.mo.moveSpeed;
  891. // data.dmg = (int)report.BuffDataInfo.mo.damage;
  892. // data.sender = this.gameObject;
  893. // ///根据触发的技能id获取触发的言灵挂件
  894. // ///获取挂件技能的被动技
  895. // //data.AttackedEff = m_FxManagerAdon.m_AttackedEff[m_CurAttackIdx].gameObject;//被击特效
  896. // WarReportUnit enemyData = report.UnitDataTarget[0];
  897. // BaseMonsterAdon enemy = RoleManager.Instance.GetRole(enemyData.UnitId) as BaseMonsterAdon;
  898. // enemy.OnMsgDebuff(data);
  899. // if (data.resultHp <= 0)//目标死亡
  900. // {
  901. // //释放目标
  902. // ReleaseTarget();
  903. // }
  904. //}
  905. public Attacked_MsgData m_Attacked_MsgData;
  906. public BaseCharacterAdon m_Enemy;
  907. //----------------------新战报方法
  908. /// <summary>
  909. /// 新战士普通打击
  910. /// </summary>
  911. /// <param name="attackIdx"></param>
  912. /// <param name="enemy"></param>
  913. public void OnMsgAttackHitNew(ReportDataAdon report)
  914. {
  915. m_Enemy = null;
  916. if (report.targetUnitType == EBattleUnitType.Hero)
  917. {
  918. m_Enemy = RoleManager.Instance.GetRole(report.TargetId) as BaseHero;
  919. }
  920. else
  921. {
  922. m_Enemy = RoleManager.Instance.GetRole(report.TargetId) as BaseMonsterAdon;
  923. }
  924. //BaseMonsterAdon enemy = RoleManager.Instance.GetRole(report.TargetId) as BaseMonsterAdon;
  925. m_Attacked_MsgData = new Attacked_MsgData();//受击消息数据
  926. m_Attacked_MsgData.sender = this.gameObject;
  927. Vector3 force = m_Enemy.transform.position - transform.position;//推力方向
  928. m_Attacked_MsgData.HitAngle = 180;
  929. force.Normalize();
  930. if (m_CurAttackIdx == 5)
  931. {
  932. m_Attacked_MsgData.attackedEffType = EnumDefine.AttackedEffT.DWN;
  933. m_Attacked_MsgData.forceDirection = force;//推力方向
  934. }
  935. else if (m_CurAttackIdx == 0)//冲刺攻击
  936. {
  937. m_Attacked_MsgData.attackedEffType = EnumDefine.AttackedEffT.SLD;
  938. m_Attacked_MsgData.forceDirection = force;//推力方向
  939. }
  940. else
  941. {
  942. m_Attacked_MsgData.attackedEffType = EnumDefine.AttackedEffT.SLD;
  943. m_Attacked_MsgData.forceDirection = force;//推力方向
  944. //发送震屏
  945. //SetCameraShake(transform.position, 0.8f, 0.1f, 0.2f);
  946. }
  947. //计算怪剩余血量
  948. m_Attacked_MsgData.resultHp = report.resultHP;
  949. m_Attacked_MsgData.dmg = report.dmg;
  950. m_Attacked_MsgData.isCR = report.isCR;//是否暴击
  951. m_Attacked_MsgData.weakness = report.weakness;
  952. m_Attacked_MsgData.AttackedEff = m_FxManagerAdon.m_AttackedEff[m_CurAttackIdx].gameObject;//被击特效
  953. if (m_Attacked_MsgData.resultHp <= 0)//目标死亡
  954. {
  955. //释放目标
  956. ReleaseTarget();
  957. }
  958. OnMsgAttackHitNewExpand(report);
  959. m_Enemy.OnMsg_Attacked(m_Attacked_MsgData);
  960. }
  961. /// <summary>
  962. /// 新战士普通打击拓展
  963. /// </summary>
  964. /// <param name="report"></param>
  965. public virtual void OnMsgAttackHitNewExpand(ReportDataAdon report)
  966. {
  967. }
  968. float m_stopTime;
  969. bool m_bStopTime;
  970. float lastUpdateTime;
  971. public void HITStop(float stopTime)
  972. {
  973. m_stopTime = stopTime;
  974. m_bStopTime = true;
  975. lastUpdateTime = Time.realtimeSinceStartup;
  976. Time.timeScale = 0;
  977. }
  978. /// <summary>
  979. /// 言灵技能打击
  980. /// </summary>
  981. /// <param name="attackIdx"></param>
  982. /// <param name="enemy"></param>
  983. public void OnMsgYanlingSkillNew(ReportDataAdon report)
  984. {
  985. Debug.Log("新言灵技战报触发");
  986. Role target = RoleManager.Instance.GetRole(report.TargetId);
  987. Attacked_MsgData data = new Attacked_MsgData();//受击消息数据
  988. data.sender = this.gameObject;
  989. Vector3 force = target.transform.position - transform.position;//推力方向
  990. force.Normalize();
  991. data.resultHp = report.resultHP;
  992. data.dmg = report.dmg;
  993. data.isCR = report.isCR;//是否暴击
  994. data.weakness = report.weakness;
  995. //获取言灵挂件被击特效
  996. //BaseYLPartAdon YLPart = report.YLPart.GetComponent<BaseYLPartAdon>();
  997. //data.AttackedEff = YLPart.m_FxManagerAdon.m_AttackedEff[m_CurAttackIdx].gameObject;//被击特效
  998. data.SkillId = report.SkillId;
  999. //判断技能id
  1000. if (data.SkillId == "6010201" || data.SkillId == "6010301")
  1001. {
  1002. data.attackedEffType = EnumDefine.AttackedEffT.STF;
  1003. data.forceDirection = Vector3.zero;//推力方向
  1004. }
  1005. else if (data.SkillId == "6010302")//星云吸力
  1006. {
  1007. data.attackedEffType = EnumDefine.AttackedEffT.INHALE;
  1008. data.forceDirection = Vector3.zero;//推力方向
  1009. }
  1010. else
  1011. {
  1012. data.attackedEffType = EnumDefine.AttackedEffT.SLD;
  1013. data.forceDirection = force;//推力方向
  1014. }
  1015. if (data.resultHp <= 0)//目标死亡
  1016. {
  1017. //释放目标
  1018. ReleaseTarget();
  1019. }
  1020. if (report.targetUnitType == EBattleUnitType.Hero)
  1021. {
  1022. BaseHero hero = target as BaseHero;
  1023. hero.OnMsg_Curing(data);//治愈
  1024. }
  1025. else
  1026. {
  1027. BaseMonsterAdon enemy = target as BaseMonsterAdon;
  1028. enemy.OnMsg_Attacked(data);
  1029. }
  1030. }
  1031. /// <summary>
  1032. /// Debuff打击发动
  1033. /// </summary>
  1034. /// <param name="attackIdx"></param>
  1035. /// <param name="enemy"></param>
  1036. public void FireMsgDebuffNew(ReportDataAdon report)
  1037. {
  1038. Debug.Log("新Debuff战报触发");
  1039. Attacked_MsgData data = new Attacked_MsgData();//受击消息数据
  1040. data.buffType = report.buffType;
  1041. //data.valueMove = report.BuffDataInfo.mo.moveSpeed;
  1042. data.dmg = report.dmg;
  1043. data.resultHp = report.resultHP;
  1044. data.sender = this.gameObject;
  1045. data.buffResStr = report.buffData.mo.res;
  1046. data.buffPoi = report.buffData.mo.bullet_attack_poi;
  1047. ///根据触发的技能id获取触发的言灵挂件
  1048. ///获取挂件技能的被动光效
  1049. //获取挂件技能的死亡光效
  1050. //BaseYLPartAdon part = GetYLPart(report.SkillId);
  1051. //if(part != null)
  1052. //{
  1053. // data.AttackedEff = part.GetAttackedEff().gameObject;
  1054. // data.DieEff = part.GetDieEff().gameObject;
  1055. //}
  1056. BaseMonsterAdon enemy = RoleManager.Instance.GetRole(report.TargetId) as BaseMonsterAdon;
  1057. if (enemy != null)
  1058. {
  1059. enemy.OnMsgDebuff(data);
  1060. }
  1061. BaseHero play = RoleManager.Instance.GetRole(report.TargetId) as BaseHero;
  1062. if (play != null)
  1063. {
  1064. play.OnMsgDebuff(data);
  1065. }
  1066. if (data.resultHp <= 0)//目标死亡
  1067. {
  1068. //释放目标
  1069. ReleaseTarget();
  1070. //根据技能id获取挂件
  1071. //获取挂件的死亡特效
  1072. //赋值死亡特效
  1073. }
  1074. }
  1075. /// <summary>
  1076. /// 执行debuff
  1077. /// </summary>
  1078. /// <param name="report"></param>
  1079. public void OnMsgDebuff(Attacked_MsgData data)
  1080. {
  1081. int damage;
  1082. //debuff计数
  1083. if (buffnum.ContainsKey(data.buffType))
  1084. {
  1085. int num = buffnum[data.buffType];
  1086. num++;
  1087. buffnum[data.buffType] = num;
  1088. }
  1089. else
  1090. {
  1091. buffnum[data.buffType] = 1;
  1092. }
  1093. //1眩晕 2静止 3护盾 4沉默 5麻痹 6灼烧 7冰冻 8黯
  1094. switch (data.buffType)
  1095. {
  1096. case 1:
  1097. //眩晕,播放眩晕动作,显示眩晕光效,禁用玩家控制
  1098. m_FxManagerAdon.m_DizzEff.gameObject.SetActive(true);
  1099. HeroPlayerController.Instance.SetInputBlocked(true);//禁用控制
  1100. HeroPlayerController.Instance.SetAutoMoveDirection(Vector2.zero);
  1101. isStun = true;
  1102. m_Animator.SetBool(hashStun, true);
  1103. break;
  1104. case 5:
  1105. damage = data.dmg;
  1106. ///执行debuff
  1107. ///麻痹
  1108. SetLocalClockTimeScale(0.1f);
  1109. HpbarManager.Instance.CreateHpTip(this, -damage, false, 1.0f);//血条及数字显示
  1110. break;
  1111. case 6:
  1112. damage = data.dmg;
  1113. ///灼烧
  1114. HpbarManager.Instance.CreateHpTip(this, -damage, false, 1.0f);//血条及数字显示
  1115. break;
  1116. case 7:
  1117. damage = data.dmg;
  1118. ///执行debuff
  1119. ///缓速
  1120. ///冻结效果
  1121. SetLocalClockTimeScale(0.3f);
  1122. //开启冻结网格材质
  1123. m_freezeFlashs.gameObject.SetActive(true);
  1124. //m_freezeFlashPower = 5;
  1125. for (int l = 0; l < m_freezeFlashMaterial.Length; l++)
  1126. {
  1127. m_freezeFlashMaterial[l].SetFloat("_Power", 0.6f);
  1128. }
  1129. HpbarManager.Instance.CreateHpTip(this, -damage, false, 1.0f);//血条及数字显示
  1130. break;
  1131. case 8:
  1132. damage = data.dmg;
  1133. ///中毒
  1134. HpbarManager.Instance.CreateHpTip(this, -damage, false, 1.0f);//血条及数字显示
  1135. break;
  1136. }
  1137. if (data.resultHp <= 0)//死亡
  1138. {
  1139. m_Animator.SetTrigger(hashDie);
  1140. // 英雄死亡
  1141. HeroDie();
  1142. }
  1143. }
  1144. /// <summary>
  1145. /// 关闭debuff
  1146. /// </summary>
  1147. /// <param name="report"></param>
  1148. public void OffMsgDebuff(ReportDataAdon reportData)
  1149. {
  1150. //debuff计数减
  1151. if (buffnum.ContainsKey(reportData.buffType))
  1152. {
  1153. int num = buffnum[reportData.buffType];
  1154. num--;
  1155. buffnum[reportData.buffType] = num;
  1156. if (buffnum[reportData.buffType] > 0) return;
  1157. }
  1158. //1眩晕 2静止 3护盾 4沉默 5麻痹 6灼烧 7冰冻 8黯
  1159. switch (reportData.buffType)
  1160. {
  1161. case 1:
  1162. //眩晕,播放眩晕动作,显示眩晕光效,禁用玩家控制
  1163. m_FxManagerAdon.m_DizzEff.gameObject.SetActive(false);
  1164. HeroPlayerController.Instance.SetInputBlocked(false);//禁用控制
  1165. isStun = false;
  1166. m_Animator.SetBool(hashStun, false);
  1167. break;
  1168. case 5:
  1169. SetLocalClockTimeScale(1);
  1170. break;
  1171. case 7:
  1172. SetLocalClockTimeScale(1);
  1173. for (int l = 0; l < m_freezeFlashMaterial.Length; l++)
  1174. {
  1175. m_freezeFlashMaterial[l].SetFloat("_Power", 2.5f);
  1176. }
  1177. m_freezeFlashs.gameObject.SetActive(false);
  1178. break;
  1179. }
  1180. }
  1181. #endregion
  1182. //#endregion
  1183. /// <summary>
  1184. /// 锁定目标
  1185. /// </summary>
  1186. void LockingTarget()
  1187. {
  1188. if (m_targetMonster)
  1189. {
  1190. BaseMonsterAdon targetM = m_targetMonster.GetComponent<BaseMonsterAdon>();
  1191. if (targetM == null || targetM.m_HitObj == null)
  1192. {
  1193. return;
  1194. }
  1195. //Debug.Log("锁定目标");
  1196. if (m_targetMonster.GetComponent<BaseMonsterAdon>().m_CurState == eState.Die) return;
  1197. //m_CameraManagerAdon.SetLockTarget(targetMonster);//相机添加锁定目标
  1198. GameObject lookTarget = targetM.m_HitObj.gameObject;
  1199. m_PerfectLookAtAdon.m_TargetObject = lookTarget;//甚至看向对目标对象
  1200. isHeadlook = true;
  1201. }
  1202. }
  1203. void ReleaseTarget()
  1204. {
  1205. //m_CameraManagerAdon.ReleaseTarget();//相机释放锁定目标
  1206. m_PerfectLookAtAdon.m_TargetObject = null;
  1207. isHeadlook = false;
  1208. //ObjectManagerAdon.RemoveMonster(targetMonster.GetComponent<BaseCharacterAdon>().Name, targetMonster);
  1209. //m_targetMonster = null;
  1210. }
  1211. /// <summary>
  1212. /// 设置可极限闪避时区
  1213. /// </summary>
  1214. /// <param name="_time">可极限闪避的倒计时</param>
  1215. public void SetExtermeTimeZone(float _time)
  1216. {
  1217. m_ExtermeZoneTimer = _time;
  1218. isExtermeTimeZone = true;
  1219. }
  1220. /// <summary>
  1221. /// 设置极限闪避计时
  1222. /// </summary>
  1223. /// <param name="_time">可极限闪避的倒计时</param>
  1224. public void SetExtermeDodgeTimer(float _time)
  1225. {
  1226. m_ExtermeDodgeTimer = _time;
  1227. isExtermeDodge = true;
  1228. //全部慢放
  1229. m_clockEnemy.localTimeScale = 0.1f;
  1230. m_clockPlayer.localTimeScale = 0.1f;
  1231. m_CameraManagerAdon.PlyeExterme();
  1232. }
  1233. /// <summary>
  1234. /// 释放极限闪避效果
  1235. /// </summary>
  1236. private void FreedExterme()
  1237. {
  1238. m_clockEnemy.localTimeScale = 1;
  1239. m_CameraManagerAdon.StopExterme();
  1240. }
  1241. /// <summary>
  1242. /// 设置无敌免伤
  1243. /// </summary>
  1244. /// <param name="godTime">免伤时间</param>
  1245. public void SetGod(float godTime)
  1246. {
  1247. isGod = true;
  1248. m_GodTime = godTime;
  1249. }
  1250. /// <summary>
  1251. /// 发动言灵技
  1252. /// </summary>
  1253. /// <param name="num"></param>
  1254. public void BattleUseYanlingSkill(string id, X2Battle.EBulletCastPoint point)
  1255. {
  1256. if (isStun == true) return;
  1257. ///播放言灵挂件攻击动作
  1258. if (point == EBulletCastPoint.ECAST_POINT_HEAD)
  1259. {
  1260. m_Head_YL.m_CurUseSkill = id;
  1261. m_Head_YL.OnFire();
  1262. _Head_YL.M_YLType = point;
  1263. m_YLParts[id] = m_Head_YL;
  1264. }
  1265. else if (point == EBulletCastPoint.ECAST_POINT_SHOULDER)
  1266. {
  1267. m_Shoulder_YL.m_CurUseSkill = id;
  1268. m_Shoulder_YL.OnFire();
  1269. m_Shoulder_YL.M_YLType = point;
  1270. m_YLParts[id] = m_Shoulder_YL;
  1271. }
  1272. else if (point == EBulletCastPoint.ECAST_POINT_FOOT)
  1273. {
  1274. m_Foot_YL.m_CurUseSkill = id;
  1275. m_Foot_YL.OnFire();
  1276. m_Foot_YL.M_YLType = point;
  1277. m_YLParts[id] = m_Foot_YL;
  1278. }
  1279. LockingTarget();
  1280. }
  1281. /// <summary>
  1282. /// 取消言灵技
  1283. /// </summary>
  1284. /// <param name="num"></param>
  1285. public void BattleCancelyanlingSkill(string id, X2Battle.EBulletCastPoint point)
  1286. {
  1287. Debug.Log(id);
  1288. ///播放言灵挂件攻击动作
  1289. if (point == EBulletCastPoint.ECAST_POINT_HEAD)
  1290. {
  1291. //m_Head_YL.m_CurUseSkill = "";
  1292. m_Head_YL.OffFire();
  1293. }
  1294. else if (point == EBulletCastPoint.ECAST_POINT_SHOULDER)
  1295. {
  1296. //m_Shoulder_YL.m_CurUseSkill = "";
  1297. m_Shoulder_YL.OffFire();
  1298. //m_Foot_YL.OnFire();//测试
  1299. }
  1300. else if (point == EBulletCastPoint.ECAST_POINT_FOOT)
  1301. {
  1302. //m_Foot_YL.m_CurUseSkill = "";
  1303. m_Foot_YL.OffFire();
  1304. }
  1305. //LockingTarget();
  1306. }
  1307. /// <summary>
  1308. /// 获取言灵部件
  1309. /// </summary>
  1310. /// <param name="skillId"></param>
  1311. /// <returns></returns>
  1312. public BaseYLPartAdon GetYLPart(string skillId)
  1313. {
  1314. if (m_YLParts.Count > 0 && m_YLParts.ContainsKey(skillId))
  1315. {
  1316. return m_YLParts[skillId];
  1317. }
  1318. return null;
  1319. }
  1320. /// <summary>
  1321. /// 播放胜利
  1322. /// </summary>
  1323. public void PlayWinning()
  1324. {
  1325. m_Animator.SetTrigger(hashWin);
  1326. m_CameraManagerAdon.SwitchToCM_Win();
  1327. m_CurState = eState.Win;
  1328. }
  1329. /// <summary>
  1330. /// 是否可伤害
  1331. /// </summary>
  1332. /// <returns></returns>
  1333. public bool IsHurt()
  1334. {
  1335. if (isGod || m_CurState == eState.Die || m_CurState == eState.Win)
  1336. {
  1337. return false;
  1338. }
  1339. return true;
  1340. }
  1341. float attackNum = 1;
  1342. bool bDodge = false;
  1343. //---------------------------FBXEvent------------------------------------
  1344. /// <summary>
  1345. /// 攻击移动开始
  1346. /// </summary>
  1347. public void OnAttackMoveStart(float num)
  1348. {
  1349. attackNum = num;
  1350. //更改为寻路方式冲刺
  1351. if (m_CurState == eState.DashAttack)
  1352. {
  1353. m_navMeshAgent.component.destination = m_targetMonster.transform.position;
  1354. m_navMeshAgent.component.speed = 10;
  1355. }
  1356. else
  1357. {
  1358. //HeroPlayerController.Instance.moveController.SetMoveOff();//关闭控制器移动
  1359. // 闪避
  1360. if (bDodge)
  1361. {
  1362. bDodge = false;
  1363. // 推力
  1364. Vector3 velocity = transform.forward * attackNum;
  1365. m_Rigidbody.velocity = velocity;
  1366. }
  1367. }
  1368. }
  1369. /// <summary>
  1370. /// 显示攻击范围
  1371. /// </summary>
  1372. public void ShowAttackRange()
  1373. {
  1374. // 推力
  1375. if (m_CurState != eState.Skill && m_Rigidbody.velocity.magnitude == 0)
  1376. {
  1377. Vector3 velocity = transform.forward.normalized * attackNum;
  1378. m_Rigidbody.velocity = velocity;
  1379. }
  1380. if (attackRangeTran)
  1381. {
  1382. //attackRangeTran.localScale = Vector3.one * (m_WeaponCol as SphereCollider).radius * 2;
  1383. attackRangeTran.localScale = Vector3.one * 5;
  1384. attackRangeTran.gameObject.SetActive(true);
  1385. if (IsInvoking("HideAttackRange"))
  1386. {
  1387. CancelInvoke("HideAttackRange");
  1388. }
  1389. Invoke("HideAttackRange", 1.0f);
  1390. }
  1391. }
  1392. /// <summary>
  1393. /// 隐藏攻击范围
  1394. /// </summary>
  1395. public void HideAttackRange()
  1396. {
  1397. CancelInvoke("ShowAttackRange");
  1398. if (attackRangeTran)
  1399. {
  1400. attackRangeTran.gameObject.SetActive(false);
  1401. }
  1402. }
  1403. /// <summary>
  1404. /// 击飞移动开始
  1405. /// </summary>
  1406. public void OnDownMoveStart(float num)
  1407. {
  1408. //HeroPlayerController.Instance.moveController.SetMoveOff();//关闭控制器移动
  1409. Vector3 velocity = m_ForceDirection * num;
  1410. m_Rigidbody.velocity = velocity;
  1411. }
  1412. /// <summary>
  1413. /// 击飞移动结束
  1414. /// </summary>
  1415. public void OnDownMoveEnd()
  1416. {
  1417. HeroPlayerController.Instance.moveController.SetMoveOn();//开启控制器移动
  1418. m_Rigidbody.velocity = Vector3.zero;
  1419. }
  1420. public void OnAttackMoveEnd()
  1421. {
  1422. HeroPlayerController.Instance.moveController.SetMoveOn();//开启控制器移动
  1423. m_Rigidbody.velocity = Vector3.zero;
  1424. m_navMeshAgent.component.ResetPath();
  1425. m_navMeshAgent.component.speed = 5;
  1426. }
  1427. /// <summary>
  1428. /// 普通攻击触发
  1429. /// </summary>
  1430. /// <param name="skillId">技能id</param>
  1431. /// <param name="attackId">子连击id</param>
  1432. public virtual void OnAttackOn(string attackId)
  1433. {
  1434. // 检测是否有怪物
  1435. Collider[] colliders = Physics.OverlapSphere(transform.position, 2.5f, 1 << LayerMask.NameToLayer("Enemy"));
  1436. bool showAttackRange = true;
  1437. for (int i = 0; i < colliders.Length; i++)
  1438. {
  1439. // 筛选符合攻击范围的玩家
  1440. Vector3 v3Dir = colliders[i].transform.position - transform.position;
  1441. v3Dir.Normalize();
  1442. float angle = Vector3.Angle(transform.forward, v3Dir);
  1443. if (angle <= 70)
  1444. {
  1445. showAttackRange = false;
  1446. break;
  1447. }
  1448. }
  1449. if (showAttackRange)
  1450. {
  1451. ShowAttackRange();
  1452. }
  1453. List<string> list = new List<string>(attackId.Split(','));
  1454. m_SkillId = int.Parse(list[0]);
  1455. if (list.Count > 1)
  1456. {
  1457. m_CurAttackIdx = int.Parse(list[1]);
  1458. }
  1459. else
  1460. {
  1461. m_CurAttackIdx = 1;
  1462. }
  1463. if (m_SkillId == 1)
  1464. {
  1465. m_WeaponCol.transform.localEulerAngles = Vector3.zero;
  1466. m_WeaponCol.enabled = true;
  1467. }
  1468. else if (m_SkillId == 2)
  1469. {
  1470. m_SkillCol.transform.localEulerAngles = Vector3.zero;
  1471. m_SkillCol.enabled = true;
  1472. }
  1473. }
  1474. /// <summary>
  1475. /// 普通攻击结束
  1476. /// </summary>
  1477. public void OnAttackOff()
  1478. {
  1479. if (m_WeaponCol) m_WeaponCol.enabled = false;//关闭武器碰撞
  1480. if (m_SkillCol) m_SkillCol.enabled = false;//关闭技能碰撞
  1481. }
  1482. /// <summary>
  1483. /// 受击移动开始
  1484. /// </summary>
  1485. public void OnHitMoveStart(float force)
  1486. {
  1487. Vector3 velocity = m_ForceDirection * force;
  1488. m_Rigidbody.velocity = velocity;
  1489. }
  1490. /// <summary>
  1491. /// 受击移动结束
  1492. /// </summary>
  1493. public void OnHitMoveEnd()
  1494. {
  1495. m_Rigidbody.velocity = Vector3.zero;
  1496. }
  1497. /// <summary>
  1498. /// 释放残影
  1499. /// </summary>
  1500. public void OnHeroBlur()
  1501. {
  1502. m_HeroBlur.enabled = false;
  1503. m_HeroBlur.enabled = true;
  1504. }
  1505. /// <summary>
  1506. /// 武器技能触发事件
  1507. /// </summary>
  1508. /// <param name="collision"></param>
  1509. void OnTriggerEnter(Collider collision)
  1510. {
  1511. if (collision.gameObject.layer == LayerMask.NameToLayer("Obstacle"))//层
  1512. {
  1513. Debug.Log("碰撞陷阱");
  1514. m_CapsuleCollider.isTrigger = false;
  1515. }
  1516. }
  1517. #if UNITY_EDITOR
  1518. /// <summary>
  1519. /// 绘制打击配置
  1520. /// </summary>
  1521. private void OnDrawGizmosSelected()
  1522. {
  1523. Vector3 forward = transform.forward;
  1524. UnityEditor.Handles.color = new Color(1.0f, 0.0f, 0.0f, 0.1f);
  1525. Vector3 rotatedForward = Quaternion.Euler(0, -m_AttackAngle * 0.5f, 0) * transform.forward;
  1526. UnityEditor.Handles.DrawSolidArc(transform.position, Vector3.up, rotatedForward, m_AttackAngle, m_AttackSight);
  1527. UnityEditor.Handles.color = new Color(0.0f, 1.0f, 0.0f, 0.1f);
  1528. UnityEditor.Handles.DrawSolidArc(transform.position, transform.up, forward, 360, m_AutoAttackRange);
  1529. }
  1530. #endif
  1531. }
  1532. }