// *********************************************************************** // Assembly : Game // Author : Kimch // Created : 2021-01-09 // Description : // Last Modified By : // Last Modified On : // *********************************************************************** // // // *********************************************************************** using System.Collections; using System.Collections.Generic; using UnityEngine; namespace G { /// /// /// public enum MoveState { none = -1, state0_Idle = 0, state1_Walk = 1, state2_Run = 2, state3_Dash = 3, state5_Change = 5, state10_Atk_T = 10, attackState11 = 11, state12 = 12, state13 = 13, state17 = 17, state19_dash = 19, state50 = 50, state53_dodge = 53, Generalstate100 = 100, state101 = 101, state102 = 102, state103 = 103, state104 = 104, state110_SkillCast = 110, state111_Skill = 111, grabState112 = 112, grabState113 = 113, grabState114 = 114, state151 = 151, state180 = 180, state181 = 181, state182 = 182, state184 = 184, state185 = 185, state192 = 192, state200_eagle = 200, state203 = 203, state212 = 212, state214 = 214, state222_wheelwind = 222, state300 = 300, deadState500 = 500, } /// /// /// partial class EntityPlayer { #region Event /// /// attack_style /// public event System.Action OnAttack; public event System.Action OnDodge; public event System.Action OnHurt; public event System.Action OnKill; #endregion #region Field /// /// /// public bool rideon { get; set; } private Vector3 _chaPosition; private Quaternion _chaRotation; /// /// /// private Vector3 _direction; /// /// /// private float _directionFactor = 7f; /// /// 进入传送门 /// private bool _enterPortal; /// /// 进入地图 /// private bool _enterMap; /// /// /// private float _pressDelay; private float _commendDelay; /// /// /// private float _fogDelay = 0.15f; /// /// /// private float _longdash; private int _superMode; /// /// 状态 /// private bool _exStart; private bool _grabStart; private bool _grabing; private bool _peting; private bool _skilling; /// /// /// private bool _isPlaying; /// /// 换人 /// private bool _changeCha; private bool _showHelper; #endregion #region Property private float _comboTime; /// /// 连击时间 /// public float comboTime { get { return _comboTime; } set { value = value < 0f ? 0f : value; if (_comboTime != value) { _comboTime = value; if (_comboTime <= 0f) { } } } } private Vector3Int _damage; /// /// /// public int damage { get { if (_damage.z != _damage.y) { _damage.z = _damage.y; } return _damage.x; } private set { _damage.x = value; _damage.y++; } } /// /// 击飞 /// public bool attackRising { get; set; } public int critDamage { get; private set; } #endregion public void OnAttacked(Vector3 dir, int attackStyle) { _direction = dir; OnAttack?.Invoke(attackStyle); } /// /// 受到伤害 /// /// public virtual void Damaged(Vector3 damageVec, int hit) { if (this.invincible || moveState > MoveState.state50) { return; } int damage = (int)damageVec.y; damageVec.y = 0f; //闪避 if (moveState >= 0 && GlobalUtils.RndHundred < sourceTotalEvasionRate) { Evade(damageVec); } else { moveState = MoveState.none; var realDamage = Mathf.Max(1, damage - sourceTotalDefence); if (block > GlobalUtils.RndHundred) { //格档 realDamage /= 2; } script_ui.Damaged(realDamage); GameCamera.Instance.ZoomIn(5, 22, 0.2f); curHp -= realDamage; this.mass = 2f; comboTime = 0f; //int hitRate = Random.Range(0, 100); int hitRate = hit; if (curHp <= 0) { if (scriptMoves.avoidDeath) { curHp = (int)(maxHp * 0.3f); Invincibility(1f); scriptEffect.PlayEffect("pt_avoid_death"); } else { curHp = 0; Died(); } } else if (hitRate > resist) { BehitDown(damageVec); } else { Invincibility(0.2f); //AddForce(damageVec * 20f); scriptEffect.Flash(); OnHurt?.Invoke(realDamage); //script_splash.SplashOn(true, 0f, 0f); //return; } UpdateHpBar(); } //CancelAtk(); ResetPower(); } /// /// /// public void Exstart() { if (!isGeneral) { CancelAtk(); scriptSound.PlaySound(scriptSound.sndSkillYells[0]); _exStart = true; PlayAnimation(Hash_AttackEx2); if (_direction != Vector3.zero) { transform.forward = _direction; } _commendDelay = 0f; _showHelper = false; script_ui.PowerCharge(); } } /// /// /// public void Eximpact() { _scriptSwingEx2.SwingOn(0f, 2, 2, 20, 1, 0); PlayAnimation(Hash_AttackEx2_Impact); _exStart = false; scriptSound.PlayBoom(); AddForwardForce(30f); //_keydown = false; _prevTouchPosistion = _currTouchPosistion; } /// /// /// public void SpSkill(short mode = 1) { if (moveState >= MoveState.state19_dash) { return; } _superMode = mode; //if (superMode != 0) { scriptSound.PlayYell(2); scriptSound.PlaySkillStart(); moveState = MoveState.state53_dodge; Vector3 vector = Vector3.Normalize(_currTouchPosistion - _prevTouchPosistion); if (vector != Vector3.zero) { transform.rotation = Quaternion.LookRotation(vector); } if (_superMode == 0) { //AddForce(vector * 300f); PlayAnimation(Hash_Grab_Start); _grabStart = true; if (targetEnemy) { targetEnemy.gameObject.SendMessage("Grabed"); } } else if (_superMode == 1) { this.mass = 6f; this.drag = 15f; //StopAnim(); _skilling = true; Time.timeScale = 0.1f; _superMode = 2; //SetTrigger(Hash_AttackEx3); //myanimation["attackex3"].speed = 1.35f; PlayAnimation(Hash_AttackEx3); //AnimationState animationState = PlayAnimQueued("attackex3_impact"); //animationState.speed = 0.25f; Invincibility(1f); script_ui.SuperModeOn(); ef_swordExtreme.position = transform.position + Vector3.up * 0.1f; ef_swordExtreme.gameObject.SetActive(true); transform.forward = vector; } CancelAtk(); _pressDelay = 1f; } } /// /// 闪开技能 /// public virtual void Dodge() { if (moveState >= MoveState.state0_Idle && moveState < MoveState.state19_dash && !isGeneral && !_grabStart /*&& sp >= 20f*/) { //躲避技能 if (_direction != Vector3.zero) //direction = mytransform.forward; transform.rotation = Quaternion.LookRotation(_direction); _directionFactor = 0f; this.mass = 2f; //Spcharge((0f - weaponweight) * 2f); //Spcharge(-20F); CancelAtk(); scriptSound.PlaySoundDodge(); //PlayInAttackLayer(Hash_Atk_4); //script_thrust.SwingOn(0.28f - _atkSpeed, 4, 1, 20, 1, 100); //_myRigidbody.AddForce(attackVector * 30f); if (scriptMoves.dodgeType == 1) { PlayAnimation(Hash_Dodge2); script_thrust2.SwingOn(0, 4, 1, 20, 1, 100); } else { PlayAnimation(Hash_Dodge); } //SetTrigger(Hash_Dodge); moveState = MoveState.state53_dodge; //_hitCollider.enabled = false; Physics.IgnoreLayerCollision(GameLayer.AllyLayer, GameLayer.UnitLayer); AddForwardForce(300f /*220f*/); _pressDelay = 0.2f; // //script_skill.LaunchSkill(0); Invincibility(0.1f); //mycollider.enabled = false; //mycollider.enabled = true; //CancelAtk(); //pressdelay = 1f; OnDodge?.Invoke(scriptMoves.dodgeType); } } private int _deathReborn = 0; private int _deathRebornRate = 0; private int _deathRebornHpRate = 0; private int _deathInvinc = 0; private int _deathInvincRate = 0; private int _deathInvincSecond = 0; /// /// /// public virtual void Died() { if (_deathReborn > 0) { _deathReborn--; if (GlobalUtils.RndHundred < _deathRebornRate) { Reborn(_deathRebornHpRate); return; } } if (_deathInvinc > 0) { _deathInvinc--; if (GlobalUtils.RndHundred < _deathInvincRate) { curHp = 1; Invincibility(_deathInvincSecond); return; } } isLife = false; //moveState = MoveState.deadState500; Invincibility(10f); Time.timeScale = 0.2f; scriptSound.PlaySoundOneShot(scriptSound.sndDied); SetInteger(Hash_State, 1); this.deathCount += 1; GlobalVar.DeathCount++; GameLevel.Instance.OnPlayerDead(); StartCoroutine(DiedCO()); } private System.Collections.IEnumerator DiedCO() { yield return new WaitForSecondsRealtime(1f); Time.timeScale = 1f; script_ui.GameOver(); } /// /// 复活 /// public void Reborn(int hpRate = 100) { isLife = true; _isPlaying = true; //moveState = 0; Time.timeScale = 1f; curHp = maxHp * hpRate / 100; sp = maxSp; UpdateHpBar(); //script_ui.StatUpdate_sp(sp); if (isGeneral) { SpCharge(100f); script_ui.CallGeneral(1); } else { SetInteger(Hash_State, 0); } Invincibility(3f); scriptSkill.BoomOn(0, true); } /// /// /// public void Fly() { scriptSound.PlaySkillStart(); _peting = true; _currentPet = 1; StopAnimation(); PlayAnimation("jump_changeweapon"); //AnimationState animationState = PlayAnimQueued("jump_changeweapon_i"); //animationState.speed = GetAnimSpeed("jump_changeweapon"); //animationState = PlayAnimQueued("eagle_start"); //animationState.speed = GetAnimSpeed("eagle_start"); //animationState = PlayAnimQueued("eagle"); //animationState.speed = GetAnimSpeed("eagle"); //animationState.wrapMode = WrapMode.Loop; _moveSpeed = 0.3f; if (!noeagle) { //pet_eagle.gameObject.SetActive(true); //script_eagle.SkillOn(); } AttackUp(_attackEagle / 100, 0); } /// /// /// public void RideHorse() { _peting = true; StopAnimation(); PlayAnimation("ride_s"); //AnimationState animationState = PlayAnimQueued("ride1"); //animationState.speed = 0f; _moveSpeed = 0.8f; } /// /// /// public void SkillStart() { _skilling = true; scriptSound.PlaySkillStart(); scriptSound.PlaySoundOneShot(scriptSound.sndSkillYells[1]); } /// /// /// /// /// public void Grab(int kind, Vector3 monpos) { Debug.Log($"Grab {kind}"); //kind = 0; float delay = 0f; _grabing = true; GameCamera.Instance.LookTarget(this.transform, 0, 0f); StopAnimation(); //Spcharge(-50f); script_ui.ComboPlus(0.1f); moveState = MoveState.grabState112; Vector3 lhs = monpos - transform.position; if (lhs != Vector3.zero) { transform.forward = new Vector3(lhs.x, 0f, lhs.z); } SwingStart(); switch (kind) { case 0: delay = 1.6f; PlayAnimation(Hash_Grab10); break; case 1: delay = 1.6f; PlayAnimation(Hash_Grab11); break; case 2: delay = 2f; PlayAnimation(Hash_Grab12); break; case 3: delay = 1.6f; PlayAnimation(Hash_Grab20); break; case 4: delay = 1.6f; PlayAnimation(Hash_Grab21); break; case 5: delay = 3f; PlayAnimation(Hash_Grab22); break; case 6: delay = 1.2f; PlayAnimation(Hash_Grab30); break; } GameCamera.Instance.ZoomIn(5, 13, delay); } /// /// /// /// /// public void Grabfinish(Vector3 monpos, Vector3 lookat) { monpos.y = 0f; transform.position = Vector3.Lerp(this.transform.position, monpos, Time.deltaTime * 15f); transform.forward = -new Vector3(lookat.x, 0f, lookat.z); } /// /// 进入传送门 /// /// public void EnterPortal(Vector3 pos) { transform.forward = targetPos - this.transform.position; _isPlaying = false; _enterPortal = true; targetPos = pos; } public void ChangeFinish(bool _generalin, bool _jumpatk) { _changeCha = false; moveState = MoveState.state5_Change; if (_generalin) { StopAnimation(); if (_jumpatk) { //SetAnimSpeed(ATK_1T, 0.24f); //PlayAnim(ATK_1T); } else { //PlayAnim(IDLE); } scriptWeapon.GeneralWeaponOn(general_kind + 1, general_weapon); //GetComponent().Costume(general_kind + 17); if (general_kind == 1) { transform.localScale = Vector3.one * 1.4f; } else if (general_kind == 3) { transform.localScale = Vector3.one * 1.1f; } } } /// /// /// public void KillEnemy() { SpCharge(5f); int killHpRecover = GetCurrentValue(CombatAttributeId.KillHpRecover); int killHpRecoverPercent = GetCurrentValue(CombatAttributeId.KillHpRecoverPercent); if (killHpRecover > 0 || killHpRecoverPercent > 0) Heal(killHpRecover, killHpRecoverPercent); OnKill?.Invoke(1); } private bool UpdateNotPlaying() { if (!_isPlaying) { if (_enterPortal) { _chaPosition = Vector3.MoveTowards(_chaPosition, targetPos, Time.deltaTime); _direction = targetPos - _chaPosition; if (_direction.sqrMagnitude < 0.0001f) { _enterPortal = false; _chaPosition = Vector3.zero; transform.forward = Vector3.forward; targetPos = Vector3.forward * 0.01f; StopControl(); SetModelVisible(false); HideHpBar(); GameLevel.Instance.NextStage(); } } else if (_enterMap) { var baseStateIfno = _animator.GetCurrentAnimatorStateInfo(BASE_LAYER); if (baseStateIfno.shortNameHash != Hash_Change_In) { _enterMap = false; PlayAnimation(Hash_Land_Change_Weapon); //scriptWeapon.ReturnBlade(); targetPos = Vector3.zero; //_isPlaying = true; //script_spawn.RegenStart(); script_ui.ResetTime(); //if (extremeStageHeal) //{ // Heal(10, true); //} HpRecoverStage(); scriptEffect.PlayEffect("ef_enter", 1f, 0.7f); ShowHpBar(); SetShadowVisible(true); SetDirectorVisible(true); UpdateHpBar(); StartControl(); } } return true; } return false; } private bool UpdateAttackState() { var currStateInfo = _animator.GetCurrentAnimatorStateInfo(BASE_LAYER); var currStateHash = currStateInfo.shortNameHash; var currTagHash = currStateInfo.tagHash; if (currTagHash == Hash_Dodge) { moveState = MoveState.state53_dodge; comboTime = 0f; } else if (currStateHash == Hash_Blocked) { moveState = MoveState.none; comboTime = 0f; } else if (currStateHash == Hash_Evade) { moveState = MoveState.none; comboTime = 0f; } else if (currStateHash == Hash_Behitdown) { moveState = MoveState.none; } else if (currTagHash == Hash_Atk) { if (currStateHash == Hash_Atk_1) { _commendDelay = 0f; moveState = MoveState.attackState11; comboTime = 1f; } else if (currStateHash == Hash_Atk_2) { moveState = MoveState.state13; comboTime = 1f; } else if (currStateHash == Hash_Atk_3) { comboTime = 1f; moveState = MoveState.attackState11; _fogDelay = 0f; } else if (currStateHash == Hash_Atk_4) { if (_weaponKind == (int)WeaponKind.blade) { if (_fogDelay >= 0.15f) { scriptEffect.FogOn(1); _fogDelay = float.MinValue; } else { _fogDelay += Time.deltaTime; } } comboTime = 1f; _moveSpeed = _moveSpeedOrigin; moveState = MoveState.state12; _commendDelay = 0f; _showHelper = false; } else if (currStateHash == Hash_Atk_5) { moveState = MoveState.state13; } else if (currStateHash == Hash_Attack_Dash) { _chaPosition += transform.forward * Time.deltaTime * 0.5f; _commendDelay = 0f; moveState = MoveState.state19_dash; comboTime = 1f; } else if (currStateHash == Hash_Attack_Rise) { moveState = MoveState.state102; scriptSound.PlaySound(scriptSound.sndRiseAttack); scriptEffect.pt_rising.Rotate(Vector3.up * Time.deltaTime * 2000f); } else if (currStateHash == Hash_AttackEx2) { _pressDelay = 1f; moveState = MoveState.state19_dash; _commendDelay = 0f; _showHelper = false; } else if (currStateHash == Hash_AttackEx2_Impact) { if (!isGeneral) { _commendDelay += Time.deltaTime; if (!_showHelper && _commendDelay > 0.3f) { //guide_circle.gameObject.SetActive(true); _showHelper = true; } //if (Input.anyKeyDown) //{ // if (commendDelay < 0.7f && commendDelay > 0.5f) // { // script_weapon.SwitchWepon(0, 8, 0.6f, 1f); // PlayInAttackLayer(Hash_AttackEx1); // //PlayAnim("attackex1"); // //impact = PlayAnimQueued("attackex1_impact"); // //impact.speed = 0.25f; // script_audio.PlayOneShot(snd_skillstart); // commendDelay = 1f; // } // else // { // commendDelay = 1f; // } //} _pressDelay = 1f; } if (/*moveState != MoveState.none &&*/ moveState != MoveState.state102) { scriptSound.PlayBoom(); //script_skill.skillatk = maxAtk * 2f; //script_skill.LaunchSkill(0); script_thump.SplashOn(true, 0.1f, 0f); moveState = MoveState.state102; } //else //{ // moveState = MoveState.none; //} } else if (currStateHash == Hash_AttackEx1) { if (_fogDelay >= 0.15f) { scriptEffect.FogOn(0); _fogDelay = 0f; } else { _fogDelay += Time.deltaTime; } _chaPosition += _direction * 0.5f * Time.deltaTime; if (_direction != Vector3.zero) { transform.forward = _direction; } moveState = MoveState.state101; _commendDelay = 0f; _showHelper = false; } else if (currStateHash == Hash_AttackEx1_Impact) { _fogDelay = 0.15f; _commendDelay += Time.deltaTime; if (!_showHelper && _commendDelay > 0.3f) { scriptEffect.guide_circle.gameObject.SetActive(true); _showHelper = true; } if (Input.anyKeyDown) { if (_commendDelay < 0.7f && _commendDelay > 0.5f) { GameCamera.Instance.Topview(); scriptEffect.pt_rising.position = transform.position; scriptEffect.pt_rising.gameObject.SetActive(true); PlayAnimation("rise_attack"); scriptWeapon.SwitchWepon(1, 8, 1.4f, 1f); scriptSound.PlaySkillStart(); _commendDelay = 1f; } else { _commendDelay = 1f; } } if (moveState != MoveState.state102) { GameCamera.Instance.Topview(); scriptEffect.ef_riseattack.position = transform.position; scriptEffect.ef_riseattack.gameObject.SetActive(true); scriptSound.PlayBoom(); } moveState = MoveState.state102; } else if (currStateHash == Hash_Jump_Attack_AIR) { moveState = MoveState.state104; } else if (currStateHash == Hash_Jump_Attack_Impact) { scriptSound.PlayBoom(); script_thump.SplashOn(true, 0.1f, 0f); } } //else if (baseStateHash == Hash_Atk_1T || baseStateHash == Hash_Atk_2T || baseStateHash == Hash_Atk_3T || baseStateHash == Hash_Atk_4T) else if (currTagHash == Hash_Atk_T) { //进入后摇 moveState = MoveState.state10_Atk_T; } else if (currStateHash == Hash_Idle) { Physics.IgnoreLayerCollision(GameLayer.AllyLayer, GameLayer.UnitLayer, false); //_hitCollider.enabled = true; if (_moveSpeed > 0f) { if (moveState == MoveState.state2_Run) { if (_longdash < dashTimer) { _longdash += Time.deltaTime; } else { scriptEffect.ef_blur.gameObject.SetActive(true); if (!noeagle) { //pet_eagle.gameObject.SetActive(true); } moveState = MoveState.state3_Dash; } } //else if (moveState == MoveState.dodgestate53) //{ // _myCollider.enabled = false; // moveState = MoveState.dodgestate53; // comboTime = 0f; //} else if (moveState != MoveState.state3_Dash) { _peting = false; _skilling = false; _grabStart = false; this.mass = 2f; this.drag = 10f; _longdash = 0f; moveState = MoveState.state2_Run; } //else //{ // moveState = MoveState.state0_Idle; // _myCollider.enabled = true; // //Spcharge(-Time.deltaTime * 10f); //} } else { moveState = MoveState.state0_Idle; } } return true; } private bool UpdateSkillState() { if (_skilling) { var skillLayer = _animator.GetCurrentAnimatorStateInfo(BASE_LAYER); var currStateHash = skillLayer.shortNameHash; var currTagHash = skillLayer.tagHash; if (currTagHash == Hash_Skill) { if (currStateHash == Hash_WheelWind) { _moveSpeed = 0.5f; moveState = MoveState.state222_wheelwind; comboTime = 0f; } else { moveState = MoveState.state111_Skill; comboTime = 0f; _skilling = false; } } else if (currTagHash == Hash_Cast) { if (currStateHash == Hash_Cast2) { moveState = MoveState.state110_SkillCast; comboTime = 0f; } else { if (_direction != Vector3.zero) { transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(_direction), Time.unscaledDeltaTime * 10f); } moveState = MoveState.state110_SkillCast; comboTime = 0f; } } else if (currStateHash == Hash_Wing_I) { if (moveState != MoveState.grabState112) { scriptSkill.DelaySkill(19); moveState = MoveState.grabState112; scriptSound.PlayBoom(); } comboTime = 0f; _skilling = false; } else if (currStateHash == Hash_Wing) { if (_fogDelay >= 0.1f) { scriptEffect.FogOn(2); _fogDelay = 0f; } else { _fogDelay += Time.deltaTime; } moveState = MoveState.state111_Skill; comboTime = 0f; transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.identity, Time.deltaTime * 3f); } else if (currStateHash == Hash_Jump_Attack_AIR) { _chaPosition += _direction * Time.deltaTime * 0.6f; moveState = MoveState.state151; comboTime = 0f; } else if (currStateHash == Hash_Jump_Attack_Impact) { if (moveState != MoveState.grabState112) { scriptSkill.DelaySkill(2); moveState = MoveState.grabState112; scriptSound.PlayBoom(); } comboTime = 0f; _skilling = false; } else if (currStateHash == Hash_AttackEx3) { _chaPosition += _direction * 0.03f * Time.deltaTime; if (_direction != Vector3.zero) { transform.forward = _direction; } moveState = MoveState.state103; } else if (currStateHash == Hash_AttackEx3_Impact) { if (_fogDelay >= 0.1f) { scriptEffect.FogOn(0); _fogDelay = 0f; } if (moveState != MoveState.state102) { scriptSound.PlayBoom(); if (_superMode == 2) { _superMode = 0; scriptEffect.ef_linehit.position = transform.position + Vector3.up * 0.02f; scriptEffect.ef_linehit.right = -transform.forward; scriptEffect.ef_linehit.gameObject.SetActive(true); Time.timeScale = 1f; AddForwardForce(1000f); } else { AddForwardForce(380f); } } moveState = MoveState.state102; } else { //if (moveState == MoveState.state102) _skilling = false; } return true; } return false; } private bool UpdateGrabState() { if (_grabing) { var currStateInfo = _animator.GetCurrentAnimatorStateInfo(BASE_LAYER); var currStateHash = currStateInfo.shortNameHash; var currTagHash = currStateInfo.tagHash; if (currTagHash == Hash_Grab_Finish2) { if (currStateHash == Hash_Grab10_Finish2 || currStateHash == Hash_Grab20_Finish2 || currStateHash == Hash_Grab22_Finish2 || currStateHash == Hash_Grab30_Finish2) { if (moveState != MoveState.grabState114) { //script_cam.ResetCam(); //script_txtef.TxtEfOn(0); //Heal((int)(_chaMaxHp * grabheal_factor)); script_splash.SplashOn(true, 0.07f, 0f); ef_rotfog.position = transform.position; script_rotfog.RotfogOn(4f, 5f, 80, 8, 2f); GameCamera.Instance.Reset(); scriptEffect.OneHitKillText(); } moveState = MoveState.grabState114; comboTime = 0f; } else if (currStateHash == Hash_Grab11_Finish2 || currStateHash == Hash_Grab12_Finish2 || currStateHash == Hash_Grab21_Finish2) { if (moveState != MoveState.grabState114) { //Heal((int)(_chaMaxHp * 0.1f)); script_splash.SplashOn(true, 0.07f, 0f); ef_rotfog.position = transform.position; script_rotfog.RotfogOn(4f, 5f, 80, 8, 2f); GameCamera.Instance.Reset(); scriptEffect.OneHitKillText(); } moveState = MoveState.grabState114; } } else if (currTagHash == Hash_Grab_Finish) //else if (currStateInfo.IsName("grab10_finish") || currStateInfo.IsName("grab11_finish") || currStateInfo.IsName("grab12_finish") || currStateInfo.IsName("grab20_finish") || currStateInfo.IsName("grab21_finish") || currStateInfo.IsName("grab22_finish") || currStateInfo.IsName("grab30_finish")) { moveState = MoveState.grabState113; comboTime = 0f; } else if (currTagHash == Hash_Grab) //else if ( currStateInfo.IsName("grab10") || currStateInfo.IsName("grab11") || currStateInfo.IsName("grab12") || currStateInfo.IsName("grab20") || currStateInfo.IsName("grab21") || currStateInfo.IsName("grab22") || currStateInfo.IsName("grab30")) { moveState = MoveState.grabState112; comboTime = 0f; } else { _grabing = false; } return true; } return false; } private bool UpdatePetState() { if (_peting) { var stateInfo = _animator.GetCurrentAnimatorStateInfo(BASE_LAYER); if (stateInfo.IsName("land_changeweapon")) { if (moveState != MoveState.state182) { //scriptWeapon.ReturnBlade(); moveState = MoveState.state182; _peting = false; } } else if (stateInfo.IsName("jump_changeweapon")) { moveState = MoveState.state180; } else if (stateInfo.IsName("jump_changeweapon_i")) { if (moveState != MoveState.state181) { //scriptWeapon.SwitchWepon(_currentPet, 3, 0f, 0f); } moveState = MoveState.state181; } else if (stateInfo.IsName("eagle_shoot")) { moveState = MoveState.state192; _chaPosition[1] = 0.02f * Mathf.Sin(Time.time * 8f) + 0.02f; } else if (stateInfo.IsName("eagle_start")) { moveState = MoveState.state200_eagle; _chaPosition[1] = 0.02f * Mathf.Sin(Time.time * 8f) + 0.02f; } else if (stateInfo.IsName("eagle")) { if (moveState != MoveState.state203) { _moveSpeed = 0.3f; moveState = MoveState.state203; } _chaPosition[1] = 0.02f * Mathf.Sin(Time.time * 8f) + 0.02f; } else if (stateInfo.IsName("eagle_finish") || stateInfo.IsName("horse_finish")) { moveState = MoveState.state184; } else if (stateInfo.IsName("horse_chacry")) { if (moveState != MoveState.state185) { rideon = true; script_horse.RideandCry(); moveState = MoveState.state185; } } else if (stateInfo.IsName("ride_s") || stateInfo.IsName("horse_start")) { moveState = MoveState.state184; _direction = Vector3.zero; _chaPosition = Vector3.Lerp(transform.position, pet_horse.position, Time.deltaTime * 5f); transform.rotation = Quaternion.Slerp(transform.rotation, pet_horse.rotation, Time.deltaTime * 5f); } else if (stateInfo.IsName("attack_ride1") || stateInfo.IsName("attack_ride2")) { moveState = MoveState.state214; comboTime = 1f; } else if (stateInfo.IsName("ride1") && moveState != MoveState.state212) { moveState = MoveState.state212; } return true; } return false; } private void UpdateState() { _chaPosition = transform.position; UpdateInvincibility(); if (!UpdateNotPlaying()) { UpdateInput(); } if (!isLife) { moveState = MoveState.deadState500; _direction = Vector3.zero; comboTime = 0f; return; } if (_changeCha) { if (false/*!myanimation.isPlaying ||*/ /*IsPlayingAnim(ATK_1T)*/) { #pragma warning disable CS0162 // 检测到无法访问的代码 _changeCha = false; #pragma warning restore CS0162 // 检测到无法访问的代码 moveState = MoveState.state5_Change; } } //pet move state > 180 else if (UpdatePetState()) { } //技能状态 if (UpdateSkillState()) { } else if (UpdateGrabState()) { } else { UpdateAttackState(); } //普通战斗可以被拖走 if (moveState <= MoveState.attackState11 || moveState > MoveState.state200_eagle) { comboTime -= Time.deltaTime; if (_direction == Vector3.zero || moveState == MoveState.none) { _longdash = 0f; _moveSpeed = 0f; _directionFactor = 0f; SetFloat(Hash_Speed_Move, 0f); } else { _chaRotation = Quaternion.LookRotation(_direction); if (_directionFactor > 5f) { _directionFactor -= 10f * Time.deltaTime; _moveSpeed = _moveSpeedOrigin; SetFloat(Hash_Speed_Move, _moveSpeed); _chaPosition += _direction * (_moveSpeed * Time.deltaTime); } //else if (_speedFactor > 0.2f) //{ // _speedFactor -= 10f * Time.deltaTime; // SetFloat(Hash_Speed_Move, _speedFactor / 7.5f + 0.2f); // _moveSpeed = _speedFactor / 12f; //} else { _moveSpeed = 0f; _directionFactor = 0f; SetFloat(Hash_Speed_Move, 0f); _direction = Vector3.zero; } } this.transform.rotation = this._chaRotation;// Quaternion.Lerp(mytransform.rotation, rotate, Time.deltaTime * 8f * rotationSpeed); } this.transform.position = this._chaPosition; } private void Update() { if (entityView.initSuccess) UpdateState(); } float _stateTime; MoveState _moveState; /// /// 角色状态 /// public MoveState moveState { get { return _moveState; } set { if (_moveState != value) { _stateTime = Time.time; } _moveState = value; } } public float stateTime => Time.time - _stateTime; public bool IsAttackState() { var stateInfo = _animator.GetCurrentAnimatorStateInfo(BASE_LAYER); return stateInfo.tagHash == Hash_Atk; } public bool IsAttackTState() { var stateInfo = _animator.GetCurrentAnimatorStateInfo(BASE_LAYER); return stateInfo.tagHash == Hash_Atk_T; } /// /// 闪避 /// public void Evade(Vector3 damageVector) { moveState = MoveState.none; scriptEffect.EvadeText(); Invincibility(0.5f); if (damageVector != Vector3.zero) { this.transform.rotation = Quaternion.LookRotation(damageVector); } AddForce(damageVector * 140f); // PlayAnimation(Hash_Evade); if (IsMainPlayer()) GameCamera.Instance.ZoomIn(5, 22, 0.2f); } /// /// 被格档 /// /// public void Blocked(Vector3 enemyPos) { if (moveState >= 0) { moveState = MoveState.none; var _direction = Vector3.Normalize(enemyPos - transform.position); transform.rotation = Quaternion.LookRotation(_direction); if (_guardBreak > GlobalUtils.RndHundred) { scriptSound.PlaySoundOneShot(scriptSound.sndBlockBreak); scriptEffect.ef_blockbreak.gameObject.SetActive(true); scriptEffect.ef_blockbreak.position = enemyPos + Vector3.up * 0.05f; scriptEffect.ef_block.rotation = transform.rotation; AddForce(_direction * -10f); } else { scriptSound.PlaySound(scriptSound.sndBlock); scriptEffect.ef_block.gameObject.SetActive(true); scriptEffect.ef_block.position = transform.position; scriptEffect.ef_block.rotation = transform.rotation; CancelAtk(); scriptEffect.BlockedText(); PlayAnimation(Hash_Blocked); AddForce(_direction * -80f); } } } /// /// 击倒 /// /// public void BehitDown(Vector3 damageVector) { PlayAnimation(Hash_Behitdown); Invincibility(2f); AddForce(damageVector * 180f); } /// /// /// /// public bool CanSelectAsTarget() { return moveState < MoveState.state110_SkillCast; } } }