aozhiwei 418d98deea 1
2021-03-30 14:05:06 +08:00

68 lines
1.3 KiB
C++

#pragma once
#include "aicomponent.h"
#include "weakptr.h"
namespace MetaData
{
class AI;
}
enum HeroState_e
{
HSE_Idle = 0,
HSE_Thinking = 1,
HSE_Attack = 2,
HSE_RandomWalk = 3,
HSE_Pursuit = 4
};
class Human;
class HeroAINode
{
public:
HeroState_e main_state = HSE_Idle;
long long frameno = 0;
long long exec_frame_num = 0;
long long start_shot_frameno = 0;
long long next_random_move_frameno = 0;
int shot_times = 0;
int total_shot_times = 0;
int next_total_shot_times = 0;
long long param1 = 0;
CreatureWeakPtr target;
CreatureWeakPtr nearest_human;
long long last_check_nearest_human_frameno = 0;
a8::Vec2 shot_dir;
};
class HeroAI : public AIComponent
{
public:
virtual ~HeroAI() override;
virtual void Update(int delta_time) override;
float GetAttackRate();
private:
void UpdateAI();
void UpdateIdle();
void UpdateThinking();
void UpdateAttack();
void UpdateRandomWalk();
void UpdatePursuit();
void DoMoveAI();
void ChangeToStateAI(HeroState_e to_state);
void DoShotAI();
Human* GetTarget();
float GetAttackRange();
int GetAttackTimes();
private:
MetaData::AI* ai_meta = nullptr;
HeroAINode node_;
bool moving_ = false;
};