aozhiwei 377a3b5cbc 1
2021-08-06 07:56:49 +00:00

74 lines
1.5 KiB
C++

#pragma once
#include <a8/vec2.h>
#include "aicomponent.h"
#include "weakptr.h"
enum HeroState_e : int
{
HSE_Idle,
HSE_Thinking,
HSE_Attack,
HSE_RandomWalk,
HSE_Pursuit,
HSE_FollowMaster,
HSE_SweepMine
};
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;
a8::Vec2 target_pos;
RoomObstacleWeakPtr target_obstacle;
long long last_collision_times = 0;
};
class HeroAI : public AIComponent
{
public:
HeroAI();
virtual ~HeroAI() override;
virtual void Update(int delta_time) override;
float GetAttackRate();
void ForceRandomWalk(int time, int idle_time);
protected:
void UpdateAI();
void UpdateIdle();
void UpdateThinking();
void UpdateAttack();
void UpdateRandomWalk();
void UpdatePursuit();
void UpdateFollowMaster();
void UpdateSweepMine();
void DoMoveAI();
void ChangeToStateAI(HeroState_e to_state);
void DoShotAI();
Creature* GetTarget();
RoomObstacle* FindObstacleTarget();
float GetAttackRange();
float GetShotRange();
int GetAttackTimes();
protected:
HeroAINode* node_ = nullptr;
bool moving_ = false;
};