157 lines
3.3 KiB
C#
157 lines
3.3 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2020-09-02
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "Stat_IdleAction" company="Kimch"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
namespace G
|
|||
|
{
|
|||
|
|
|||
|
public class Stat_AtkAction : Stat_BaseAction
|
|||
|
{
|
|||
|
private bool m_isEnd;
|
|||
|
|
|||
|
private NormalAtkBase m_normalAtk;
|
|||
|
|
|||
|
private float m_time;
|
|||
|
|
|||
|
public Stat_AtkAction(Stat_StateManager statMgr)
|
|||
|
: base(statMgr)
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
public override bool Enter(Dictionary<string, object> param, bool clearDelegates = false)
|
|||
|
{
|
|||
|
m_isEnd = false;
|
|||
|
if (m_char.IsPlayer())
|
|||
|
{
|
|||
|
//DailyTaskDataManager.instance.killOnceCount = 0;
|
|||
|
}
|
|||
|
bool flag = base.Enter(param, clearDelegates);
|
|||
|
m_normalAtk = m_char.gameObject.GetComponent<NormalAtkBase>();
|
|||
|
if ((bool)m_normalAtk)
|
|||
|
{
|
|||
|
if (param != null && param.ContainsKey("normal_atk_idx"))
|
|||
|
{
|
|||
|
m_normalAtk.myStep = (int)param["normal_atk_idx"];
|
|||
|
}
|
|||
|
DoAtk();
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public override bool Exit()
|
|||
|
{
|
|||
|
ExitDelegate();
|
|||
|
if (m_exitDelegate != null && m_exitDelegate != new StatDelegate(ExitDelegate))
|
|||
|
{
|
|||
|
return m_exitDelegate();
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public override bool ExitDelegate()
|
|||
|
{
|
|||
|
if (m_char.IsPlayer())
|
|||
|
{
|
|||
|
//DailyTaskDataManager.instance.RecordKillOnce();
|
|||
|
}
|
|||
|
CancelAtk();
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public override bool CanTransition(enStat stat)
|
|||
|
{
|
|||
|
if (stat == enStat.STAT_ACTION_ATK && !m_isEnd)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
switch (stat)
|
|||
|
{
|
|||
|
case enStat.STAT_ACTION_DEAD:
|
|||
|
return true;
|
|||
|
case enStat.STAT_ACTION_MOVE:
|
|||
|
{
|
|||
|
if (m_char.target == null)
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
var component = m_char.target.gameObject.GetComponent<EntityCha>();
|
|||
|
Vector3 lhs = component.position - m_char.position;
|
|||
|
lhs.y = 0f;
|
|||
|
lhs.Normalize();
|
|||
|
float magnitude = lhs.magnitude;
|
|||
|
Vector3 curDir = m_char.forward;
|
|||
|
if (!(curDir != Vector3.zero))
|
|||
|
{
|
|||
|
break;
|
|||
|
}
|
|||
|
float num = Vector3.Dot(lhs, curDir);
|
|||
|
if (magnitude > 0.2f)
|
|||
|
{
|
|||
|
if (num < 0.5f)
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
if (num < -0.2f)
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
private void DoAtk()
|
|||
|
{
|
|||
|
if (m_normalAtk && m_char.target)
|
|||
|
{
|
|||
|
var component = m_char.target.gameObject.GetComponent<EntityCha>();
|
|||
|
m_time = m_normalAtk.DoAtk(component);
|
|||
|
if (m_time > 0f)
|
|||
|
{
|
|||
|
SetTimers();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void CancelAtk()
|
|||
|
{
|
|||
|
if ((bool)m_normalAtk)
|
|||
|
{
|
|||
|
m_normalAtk.CancelAtk();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void SetTimers()
|
|||
|
{
|
|||
|
m_statMgr.AddTimer(m_time, AnimationEnd_CB);
|
|||
|
}
|
|||
|
|
|||
|
private bool AnimationEnd_CB(object[] param)
|
|||
|
{
|
|||
|
m_isEnd = true;
|
|||
|
if ((bool)m_normalAtk)
|
|||
|
{
|
|||
|
m_normalAtk.CancelAtk();
|
|||
|
}
|
|||
|
if (m_char.normalAtkEnableMove)
|
|||
|
{
|
|||
|
Dictionary<string, object> dictionary = new Dictionary<string, object>();
|
|||
|
dictionary.Add("speed", 5.3f);
|
|||
|
return SetCurActionState(enStat.STAT_ACTION_ATK_MOVE, dictionary);
|
|||
|
}
|
|||
|
return SetCurActionState(enStat.STAT_ACTION_IDLE);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|