// *********************************************************************** // Assembly : Game // Author : Kimch // Created : 2020-09-02 // Description : // Last Modified By : // Last Modified On : // *********************************************************************** // // // *********************************************************************** using UnityEngine; namespace G { partial class EntityPlayer { private const float STOP_MOVE_THRESHOLD = 0.01F; private const float START_MOVE_THRESHOLD = 0.03F; private bool _keydown; private bool _saveTouchPosition; private Vector3 _currTouchPosistion; private Vector3 _prevTouchPosistion; private bool _skillDown; private float _lastAttackTime; private float _lastMoveTime; public bool anyKey { get { return Input.anyKey; } } public bool anyKeyDown { get { return Input.anyKeyDown; } } public Vector3 mousePosition { get { return Input.mousePosition; } } public Vector3 joystick { get { var dir = UI_Ingame.Instance.joystickDirection; return new Vector3(dir.x, 0f, dir.y); } } public void OnSPBtnClick() { if (sp < 100) return; SpCharge(-100); SpSkill(); } public void OnSkillBtnClick(Cha_Moves.MovesInfo buffInfo) { if (_isPlaying && moveState < MoveState.Generalstate100) { CancelAtk(); _pressDelay = 1f; _skillDown = scriptMoves.CastSkill(buffInfo); } _skillDown = true; } public void OnAttackBtnClick() { if (_isPlaying && moveState <= MoveState.state10_Atk_T && moveState >= MoveState.state0_Idle) { if (Time.time - _lastAttackTime > 0.2f) { _lastAttackTime = Time.time; if (targetEnemy) { AttackOn(targetEnemy.position); } else if (_targetProp) { AttackOn(_targetProp.position); } else { AttackOn(this.transform.TransformPoint(Vector3.forward), false); } } } //else if (chamovestat == MoveState.state212) //{ // Attack_spear(targetenemy.transform.position); //} //else if (chamovestat == MoveState.state203) //{ // Attack_arrow(targetenemy.transform.position); //} //else if (grabstart && !general) //{ // targetenemy.gameObject.SendMessage("Grabed"); // grabstart = false; //} } /// /// /// public void OnDodgeBtnClick() { Dodge(); } private bool _autoAttackTarget; /// /// 自动攻击 /// public bool autoAttack { get { return _autoAttackTarget; } set { _autoAttackTarget = value; } } private bool _autoCastSkill; /// /// 自动释放技能 /// public bool autoCastSkill { get { return _autoCastSkill; } set { _autoCastSkill = value; } } public bool autoStudySkill { get { #if !UNITY_WEBGL && UNITY_EDITOR if (KGMOptions.Instance.自动挂机) return true; #endif return _autoCastSkill; } } /// /// /// public bool autoSelectAdventure { get { return _autoCastSkill; } } public void AutoSelectTarget(Transform target) { targetEnemy = target; } Transform _targetProp; public void AutoSelectProp(Transform target) { _targetProp = target; } public void AutoAttackTarget(Transform target) { if (!_isPlaying || anyKey) return; float sqrDistance = -1f; if (moveState == MoveState.state222_wheelwind) { sqrDistance = 0.04f; } else if (moveState >= MoveState.state0_Idle && moveState <= MoveState.state10_Atk_T) { sqrDistance = _weaponAttackRange * _weaponAttackRange; } else { return; } if (GameLevel.Instance.autoTrackEnemy) { var vector = target.position - this.position; vector.y = 0f; if (vector.sqrMagnitude > sqrDistance) { _direction = vector.normalized; _directionFactor = 6.5f; return; } } if (Time.time - _lastAttackTime < 0.25f || moveState == MoveState.state222_wheelwind || (moveState == MoveState.state10_Atk_T && stateTime < 0.08f)) return; attackEnemy = target; _lastAttackTime = Time.time; AttackOn(target.position); } public void AutoCastSkill() { if (_isPlaying && isLife && targetEnemy) { scriptMoves.AutoCastSkill(); } } public void AutoFindPortal() { if (!_isPlaying || anyKey || Time.time - _lastMoveTime < 1f) return; float sqrDistance = -1f; Vector3 targetPos; if (EntityPortal.Instance) { sqrDistance = 0.01f; targetPos = EntityPortal.Instance.position; } else if (EntityGiftBox.Instance && EntityGiftBox.Instance.canOpen) { sqrDistance = 0.008f; targetPos = EntityGiftBox.Instance.position; } else { return; } var vector = targetPos - this.position; vector.y = 0f; if (vector.sqrMagnitude > sqrDistance) { _direction = vector.normalized; _directionFactor = 6.5f; return; } } //Vector3 _prevPoint; private void UpdateInput() { if (this.anyKeyDown) { //处理技能 _saveTouchPosition = false; //_prevPoint = Input.mousePosition; _pressDelay = 0f; _keydown = true; } else if (this.anyKey) { //Vector3 dir = Input.mousePosition - _prevPoint;// this.joystick; //dir.z = dir.y; //dir.y = 0; //_prevPoint = Input.mousePosition; //Debug.Log("press " + dir + " " + joystick); Vector3 dir = this.joystick; if (!_skillDown && dir != Vector3.zero) { dir *= 0.2f; _currTouchPosistion = dir + this.transform.position;// casthit.point; if (!_saveTouchPosition) { _prevTouchPosistion = _currTouchPosistion; _saveTouchPosition = true; } //var tempdir = currentTouchPos - mytransform.position; //tempdir.y = 0f; var dirMag = dir.magnitude; dir /= dirMag; var m_hold = STOP_MOVE_THRESHOLD; //if (attackHold > 0.2f) // m_hold = 0.06f; //双击 if (dirMag < m_hold) { _direction = Vector3.zero; //if (rideon) //{ // script_horse.RunStart(false); // if (clone_ride != null) // { // clone_ride.speed = 0.1f; // } //} } else if (dirMag > START_MOVE_THRESHOLD) { _direction = dir; _directionFactor = 6.5f; _lastMoveTime = Time.time; } } else { } if (moveState < MoveState.state19_dash) { _pressDelay += Time.deltaTime; //if (_pressDelay > 0.3f) //{ // Exstart(); //} // else // //无双技能 // //if (superModeBtn && superMode != 0) // if (_pressDelay < 0.1f && !general && !grabstart && (/*sp >= 50f ||*/ superMode != 0) && Vector3.Distance(prevPoint, currentTouchPos) > 0.2f) // { // Wushuan(); // } } } else { if (_keydown) { _saveTouchPosition = false; _keydown = false; _skillDown = false; ResetPower(); //GlobalNotifier.PostNotification(GlobalDefine.EVENT_HOLD_STATE, 0F); //transform.Find("xuli_fx").gameObject.SetActive(false); //transform.Find("xuli2_fx").gameObject.SetActive(false); //if (attackHold > 0.6f) //{ // attackHold = 0f; // //script_skill.skillatk = maxAtk * 2f; // //script_skill.LaunchSkill(0); // return; //} //attackHold = 0f; //if (moveState < MoveState.attackState11 && moveState >= MoveState.state0) //{ // //if (Time.time - _lastTime < 0.1f) // //var dir = JoystickPlayerExample.Instance.variableJoystick.Direction; // //if (!Input.anyKey) // { // //if (_pressDelay > 0.5f) // //{ // // script_skill.LaunchSkill(0); // //} // //else // //{ // if (_targetEnemy) // { // AttackOn(_targetEnemy.position, false); // _targetEnemy = null; // } // else // { // AttackOn(transform.position + transform.forward, false); // } // //} // _attackTime = Time.time; // //AttackOn(_targetEnemy.position); // _myCollider.enabled = false; // } //} } } } } }