// ***********************************************************************
// 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 partial class EntityPlayer : EntityCha
{
#region Field
///
///
///
public Vector3 targetPos = Vector3.zero;
///
///
///
private Transform _targetEnemy;
///
///
///
private Transform _attackEnemy;
private float _restrictArea = 100f;
#endregion
#region Property
///
/// 攻击组件
///
public Cha_Attack scriptAttack
{
get;
protected set;
}
///
/// 武器组件
///
public Cha_Weapon scriptWeapon
{
get;
private set;
}
///
/// 技能组件
///
public Cha_Skill scriptSkill
{
get;
private set;
}
///
/// buff组件
///
public Cha_Buff scriptBuff
{
get;
private set;
}
///
/// 武学组件
///
public Cha_Moves scriptMoves
{
get;
private set;
}
///
/// 特效
///
public Cha_Effect scriptEffect
{
get;
private set;
}
///
///
///
public Cha_Auto scriptAuto
{
get;
private set;
}
///
/// 目标敌人
///
public Transform targetEnemy
{
get => _targetEnemy;
set => _targetEnemy = value;
}
///
///
///
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;
}
///
///
///
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();
}
///
///
///
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);
}
///
///
///
///
public void FindItem(Transform finditem)
{
int rate = GlobalUtils.RndHundred;
if (rate < _autoFindRate && !noeagle)
{
pet_eagle.gameObject.SetActive(true);
script_eagle.GetItem(finditem);
}
}
///
///
///
///
///
///
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());
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().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();
scriptWeapon = GetComponent();
scriptSkill = GetComponent();
scriptBuff = GetComponent();
scriptMoves = GetComponent();
scriptEffect = GetComponent();
scriptAuto = GetComponent();
}
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);
}
}
///
///
///
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);
}
///
///
///
///
/// 真实目标
public void AttackOn(Vector3 targetPos, bool real = true)
{
if (scriptAttack)
scriptAttack.DoAttack(targetPos);
}
///
/// 取消攻击
///
public void CancelAtk()
{
if (scriptAttack)
scriptAttack.CancelAttack();
}
///
///
///
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)
{
}
///
/// 无敌
///
private bool _isInvincibility;
private float _delayInvincibility;
private float _targetInvincibility;
public override bool invincible
{
get { return _isInvincibility; }
set
{
_isInvincibility = value;
}
}
///
/// 无敌
///
///
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;
}
///
/// 增加buff
///
///
public void AddMovesByBuff(int id)
{
var buffItem = ItemProxy.Instance.GetStaticItem(id);
if (buffItem != null)
{
scriptMoves.AddMovesByBuff(id, false);
}
}
///
/// 增加武学
///
///
///
public void AddMoves(int id, bool doubleValue)
{
scriptMoves.AddMoves(id, doubleValue);
//scriptMoves.AddMoves(movesItem.targetId, movesItem.targetType | movesItem.trigger, movesItem.targetArgs, doubleValue);
}
///
/// 获得武学全局参数
///
///
///
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();
if (pet_horse)
script_horse = pet_horse.GetComponent();
}
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
}
}