581 lines
15 KiB
C#
581 lines
15 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2021-01-09
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "EntityPlayer" company="Kunpo"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace G
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public partial class EntityPlayer : EntityCha
|
|
{
|
|
#region Field
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public Vector3 targetPos = Vector3.zero;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
private Transform _targetEnemy;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
private Transform _attackEnemy;
|
|
|
|
private float _restrictArea = 100f;
|
|
|
|
#endregion
|
|
|
|
#region Property
|
|
|
|
/// <summary>
|
|
/// 攻击组件
|
|
/// </summary>
|
|
public Cha_Attack scriptAttack
|
|
{
|
|
get;
|
|
protected set;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 武器组件
|
|
/// </summary>
|
|
public Cha_Weapon scriptWeapon
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 技能组件
|
|
/// </summary>
|
|
public Cha_Skill scriptSkill
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
/// <summary>
|
|
/// buff组件
|
|
/// </summary>
|
|
public Cha_Buff scriptBuff
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 武学组件
|
|
/// </summary>
|
|
public Cha_Moves scriptMoves
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 特效
|
|
/// </summary>
|
|
public Cha_Effect scriptEffect
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public Cha_Auto scriptAuto
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 目标敌人
|
|
/// </summary>
|
|
public Transform targetEnemy
|
|
{
|
|
get => _targetEnemy;
|
|
set => _targetEnemy = value;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public Transform attackEnemy
|
|
{
|
|
get => _attackEnemy;
|
|
set => _attackEnemy = value;
|
|
}
|
|
|
|
public UI_Ingame script_ui
|
|
{
|
|
get { return UI_Ingame.Instance; }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
public override void OnEnterScene()
|
|
{
|
|
|
|
}
|
|
|
|
public bool EnterScene(Vector3 point)
|
|
{
|
|
if (!entityView.initSuccess)
|
|
return false;
|
|
|
|
targetPos = point;
|
|
|
|
//if (_infinityMode)
|
|
//{
|
|
//noeagle = true;
|
|
//Object.Destroy(pet_eagle.gameObject);
|
|
Invincibility(1f);
|
|
|
|
//scriptEffect.PlayEffect("ef_enter", 1f, 0.7f);
|
|
SetModelVisible(true);
|
|
SetDirectorVisible(false);
|
|
SetShadowVisible(false);
|
|
//ShowHpBar();
|
|
//ShowShadow();
|
|
|
|
_enterMap = true;
|
|
_chaPosition = Vector3.zero;
|
|
|
|
transform.forward = Vector3.forward;
|
|
targetPos = Vector3.forward * 0.01f;
|
|
|
|
PlayAnimation(Hash_Change_In);
|
|
//}
|
|
//else
|
|
//{
|
|
//transform.rotation = Quaternion.Euler(0f, 40f, 0f);
|
|
//_peting = true;
|
|
//PetSkillFinish(0);
|
|
//_isPlaying = true;
|
|
//}
|
|
|
|
//UpdateHpBar();
|
|
|
|
scriptAuto.StartAuto();
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void StartControl()
|
|
{
|
|
_isPlaying = true;
|
|
//scriptWeapon.ShowBlade();
|
|
PlayAnimation(Hash_Land_Change_Weapon);
|
|
//scriptWeapon.SwitchWepon(-1, 0, 0.2f, 0f);
|
|
scriptWeapon.ReturnBlade();
|
|
if (!noeagle)
|
|
{
|
|
//pet_eagle.gameObject.SetActive(true);
|
|
}
|
|
|
|
ResetInvincibility();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void StopControl()
|
|
{
|
|
_isPlaying = false;
|
|
_direction = Vector3.zero;
|
|
if (rideon)
|
|
{
|
|
//script_horse.RunStart(false);
|
|
//clone_ride.speed = 0.1f;
|
|
}
|
|
moveState = MoveState.state300;
|
|
//scriptWeapon.HideBlade();
|
|
scriptWeapon.SwitchWepon(-1, 0, 0.2f, 0f);
|
|
|
|
Invincibility(10f);
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="finditem"></param>
|
|
public void FindItem(Transform finditem)
|
|
{
|
|
int rate = GlobalUtils.RndHundred;
|
|
if (rate < _autoFindRate && !noeagle)
|
|
{
|
|
pet_eagle.gameObject.SetActive(true);
|
|
script_eagle.GetItem(finditem);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="pos"></param>
|
|
/// <param name="run"></param>
|
|
/// <param name="ride"></param>
|
|
public void WalkToward(Vector3 pos, bool run, bool ride)
|
|
{
|
|
//StopAnim();
|
|
_isPlaying = false;
|
|
if (!run)
|
|
{
|
|
scriptWeapon.SwitchWepon(3, 3, 0f, 1f);
|
|
//myanimation["walk_free"].speed = 0.45f;
|
|
//PlayAnim("walk_free");
|
|
}
|
|
else
|
|
{
|
|
//script_weapon.SetStoryBlade();
|
|
//script_weapon.ReturnBlade();
|
|
moveState = MoveState.state2_Run;
|
|
_moveSpeed = _moveSpeedOrigin;
|
|
//PlayAnim("run");
|
|
}
|
|
targetPos = pos;
|
|
_direction = targetPos - transform.position;
|
|
}
|
|
|
|
public void StepOn()
|
|
{
|
|
if (moveState <= MoveState.state10_Atk_T)
|
|
{
|
|
scriptSound.PlaySound(scriptSound.sndFootstep);
|
|
}
|
|
}
|
|
|
|
public void SetRestrictArea(float area)
|
|
{
|
|
_restrictArea = area;
|
|
}
|
|
|
|
protected override void OnViewInitCompleted()
|
|
{
|
|
SetModel(entityView.gameObject);
|
|
SetRigidbody(GetComponent<Rigidbody>());
|
|
|
|
CreateHpBar();
|
|
|
|
InitEffect();
|
|
|
|
InitValue();
|
|
|
|
comboTime = 1f;
|
|
scriptSkill.SetRHand(scriptWeapon.main_hand);
|
|
|
|
_colliderDodge = new Vector3(0f, 0.05f, 0.05f);
|
|
_colliderFly = new Vector3(0f, 0.05f, 0.32f);
|
|
_colliderHorse = new Vector3(0f, 0.05f, 0.22f);
|
|
|
|
RndAtk(-1);
|
|
|
|
ef_swordExtreme.GetComponent<Sword_Extreme>().SetPower(attackOrigin);
|
|
|
|
//script_horse.Rideing(infinitymode);
|
|
//InitWeapon();
|
|
//script_skill.SetBaseDamage(_skillboost);
|
|
|
|
isLife = true;
|
|
//_isPlaying = false;
|
|
|
|
SetModelVisible(false);
|
|
UpdateHpBar();
|
|
}
|
|
|
|
public override void InitComponent()
|
|
{
|
|
base.InitComponent();
|
|
scriptAttack = GetComponent<Cha_Attack>();
|
|
scriptWeapon = GetComponent<Cha_Weapon>();
|
|
|
|
scriptSkill = GetComponent<Cha_Skill>();
|
|
scriptBuff = GetComponent<Cha_Buff>();
|
|
scriptMoves = GetComponent<Cha_Moves>();
|
|
scriptEffect = GetComponent<Cha_Effect>();
|
|
|
|
scriptAuto = GetComponent<Cha_Auto>();
|
|
}
|
|
|
|
public override void SetModel(GameObject model)
|
|
{
|
|
base.SetModel(model);
|
|
if (scriptWeapon)
|
|
scriptWeapon.SetModel(model);
|
|
}
|
|
|
|
public override void SetModelVisible(bool visible)
|
|
{
|
|
if (_model)
|
|
_model.transform.localPosition = new Vector3(0f, visible ? 0f : -100f, 0f);
|
|
}
|
|
|
|
public override void SetShadowVisible(bool visible)
|
|
{
|
|
transform.Find("shadow").gameObject.SetActive(visible);
|
|
}
|
|
|
|
public override void CreateHpBar()
|
|
{
|
|
if (!_blood)
|
|
{
|
|
_blood = BoardManager.Instance.CreateBloodBoard("BloodBoard");
|
|
_blood.SetTarget(this.transform, Vector3.up * 0.18f);
|
|
_blood.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public override void UpdateHpBar()
|
|
{
|
|
if (_blood)
|
|
{
|
|
_blood.SetHpValue(curHp, maxHp);
|
|
script_ui.StatUpdate_hp(curHp, maxHp);
|
|
}
|
|
}
|
|
|
|
public void SetDirectorVisible(bool visible)
|
|
{
|
|
transform.Find("direction").gameObject.SetActive(visible);
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="targetPos"></param>
|
|
/// <param name="real">真实目标</param>
|
|
public void AttackOn(Vector3 targetPos, bool real = true)
|
|
{
|
|
if (scriptAttack)
|
|
scriptAttack.DoAttack(targetPos);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取消攻击
|
|
/// </summary>
|
|
public void CancelAtk()
|
|
{
|
|
if (scriptAttack)
|
|
scriptAttack.CancelAttack();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void SwingStart()
|
|
{
|
|
//if (attackStyle >= 0 && attackStyle < 3)
|
|
// scriptSound.PlaySoundOneShot(snd_blades[attackStyle]);
|
|
scriptSound.PlaySoundOneShot(scriptSound.sndSwing);
|
|
}
|
|
|
|
public void SetSearchNearCollider(bool b)
|
|
{
|
|
//m_searchNearCollider.enabled = b;
|
|
}
|
|
|
|
public virtual void IgnoreAtkCollision(Collider otherCollision)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// 无敌
|
|
/// </summary>
|
|
private bool _isInvincibility;
|
|
private float _delayInvincibility;
|
|
private float _targetInvincibility;
|
|
|
|
public override bool invincible
|
|
{
|
|
get { return _isInvincibility; }
|
|
set
|
|
{
|
|
_isInvincibility = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 无敌
|
|
/// </summary>
|
|
/// <param name="t"></param>
|
|
public void Invincibility(float t)
|
|
{
|
|
_isInvincibility = true;
|
|
_targetInvincibility = t;
|
|
}
|
|
|
|
public void Invincibility(float t, bool withFx)
|
|
{
|
|
if (isLife && withFx)
|
|
{
|
|
scriptEffect.ef_super.gameObject.SetActive(true);
|
|
}
|
|
_isInvincibility = true;
|
|
_targetInvincibility = t;
|
|
|
|
//hitrate = 200;
|
|
}
|
|
|
|
public void ResetInvincibility()
|
|
{
|
|
_isInvincibility = false;
|
|
_targetInvincibility = 0f;
|
|
}
|
|
|
|
protected bool UpdateInvincibility()
|
|
{
|
|
if (_isInvincibility)
|
|
{
|
|
if (_delayInvincibility < _targetInvincibility)
|
|
{
|
|
_delayInvincibility += Time.deltaTime;
|
|
}
|
|
else
|
|
{
|
|
//hitrate = hitrateOrigin;
|
|
scriptEffect.ef_super.gameObject.SetActive(false);
|
|
|
|
_isInvincibility = false;
|
|
_delayInvincibility = 0f;
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 增加buff
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
public void AddMovesByBuff(int id)
|
|
{
|
|
var buffItem = ItemProxy.Instance.GetStaticItem<ItemBuff>(id);
|
|
if (buffItem != null)
|
|
{
|
|
scriptMoves.AddMovesByBuff(id, false);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 增加武学
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="doubleValue"></param>
|
|
public void AddMoves(int id, bool doubleValue)
|
|
{
|
|
scriptMoves.AddMoves(id, doubleValue);
|
|
//scriptMoves.AddMoves(movesItem.targetId, movesItem.targetType | movesItem.trigger, movesItem.targetArgs, doubleValue);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获得武学全局参数
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public void ApplyGlobalMovesArgs(int id, int[] skillArgs)
|
|
{
|
|
BookProxy.Instance.GetGlobalMovesArgs(id, skillArgs);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Unity
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
if (pet_eagle)
|
|
script_eagle = pet_eagle.GetComponent<Pet_eagle>();
|
|
if (pet_horse)
|
|
script_horse = pet_horse.GetComponent<Pet_horse>();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
this.Init(null);
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
//if (other.gameObject.layer == GameLayer.UnitLayer)
|
|
//{
|
|
// if (_grabStart && !isGeneral)
|
|
// {
|
|
// other.gameObject.SendMessage("Grabed");
|
|
// _grabStart = false;
|
|
// }
|
|
//}
|
|
return;
|
|
//if (!_isPlaying)
|
|
// return;
|
|
//if (Time.time - _attackTime < 0.2f)
|
|
// return;
|
|
//if (other.gameObject.layer == GameLayer.UnitLayer)
|
|
//{
|
|
// if (!_targetEnemy)
|
|
// _targetEnemy = other.transform;
|
|
|
|
// //if (autoAttack)
|
|
// //{
|
|
// // OnAttackBtnClick();
|
|
// //}
|
|
|
|
// //return;
|
|
// //Debug.Log("chamovestat" + chamovestat);
|
|
// if (moveState < MoveState.state10 && moveState >= MoveState.state0)
|
|
// {
|
|
// //if (Time.time - _lastTime < 0.1f)
|
|
// //var dir = JoystickPlayerExample.Instance.variableJoystick.Direction;
|
|
// if (!Input.anyKey)
|
|
// {
|
|
// //_lastTime = Time.time;
|
|
|
|
// _targetEnemy = other.transform;
|
|
// AttackOn(_targetEnemy.position);
|
|
// _myCollider.enabled = false;
|
|
// }
|
|
// }
|
|
// else if (moveState == MoveState.state212)
|
|
// {
|
|
// Attack_spear(other.transform.position);
|
|
// }
|
|
// else if (moveState == MoveState.state203)
|
|
// {
|
|
// Attack_arrow(other.transform.position);
|
|
// }
|
|
// else if (_grabStart && !isGeneral)
|
|
// {
|
|
// other.gameObject.SendMessage("Grabed");
|
|
// _grabStart = false;
|
|
// }
|
|
//}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|