// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2020-09-02
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
//
//
// ***********************************************************************
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 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();
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();
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();
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 dictionary = new Dictionary();
dictionary.Add("speed", 5.3f);
return SetCurActionState(enStat.STAT_ACTION_ATK_MOVE, dictionary);
}
return SetCurActionState(enStat.STAT_ACTION_IDLE);
}
}
}