From b9cdccc885e18b1ef9479896651dc61c99fc5a6d Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 17 Mar 2021 13:33:54 +0800 Subject: [PATCH] 1 --- server/gameserver/hero.ai.cc | 98 ++++++++++++++++++++---------------- server/gameserver/hero.cc | 15 ++++++ server/gameserver/hero.h | 9 ++++ 3 files changed, 79 insertions(+), 43 deletions(-) diff --git a/server/gameserver/hero.ai.cc b/server/gameserver/hero.ai.cc index 0396ea91..118ca964 100644 --- a/server/gameserver/hero.ai.cc +++ b/server/gameserver/hero.ai.cc @@ -37,14 +37,16 @@ HeroAI::~HeroAI() void HeroAI::Update(int delta_time) { - Human* hum = (Human*)owner; + Hero* hero = (Hero*)owner; + #if 0 if (hum->poisoning) { hum->poisoning_time += delta_time; } if (hum->poisoning) { hum->UpdatePoisoning(); } - if (hum->dead) { + #endif + if (hero->dead) { return; } UpdateAI(); @@ -61,10 +63,7 @@ float HeroAI::GetAttackRate() void HeroAI::UpdateAI() { - Human* hum = (Human*)owner; - if (a8::HasBitFlag(hum->status, HS_Disable)) { - return; - } + Hero* hero = (Hero*)owner; if (!ai_meta && GetAiLevel() != 0) { ai_meta = MetaMgr::Instance()->GetAI(GetAiLevel(), 0); if (!ai_meta) { @@ -72,7 +71,7 @@ void HeroAI::UpdateAI() } } ++node_.exec_frame_num; - hum->shot_hold = false; + hero->shot_hold = false; switch (node_.main_state) { case HSE_Idle: { @@ -112,20 +111,20 @@ void HeroAI::UpdateAI() void HeroAI::UpdateIdle() { - Human* hum = (Human*)owner; - if (hum->room->GetFrameNo() > node_.frameno + node_.param1) { + Hero* hero = (Hero*)owner; + if (hero->room->GetFrameNo() > node_.frameno + node_.param1) { ChangeToStateAI(HSE_Thinking); } } void HeroAI::UpdateThinking() { - Human* hum = (Human*)owner; - if (hum->room->GetGasData().gas_mode == GasInactive || - hum->room->IsWaitingStart() || - hum->HasBuffEffect(kBET_Jump) || - a8::HasBitFlag(hum->status, HS_DisableAttack)) { - if (hum->room->IsWaitingStart()) { + Hero* hero = (Hero*)owner; + if (hero->room->GetGasData().gas_mode == GasInactive || + hero->room->IsWaitingStart() || + hero->HasBuffEffect(kBET_Jump) + ) { + if (hero->room->IsWaitingStart()) { ChangeToStateAI(HSE_Idle); } else { ChangeToStateAI(HSE_RandomWalk); @@ -136,7 +135,7 @@ void HeroAI::UpdateThinking() node_.target = target; ChangeToStateAI(HSE_Attack); } else { - if (hum->room->GetFrameNo() >= node_.next_random_move_frameno) { + if (hero->room->GetFrameNo() >= node_.next_random_move_frameno) { if ((rand() % 7) < 4) { ChangeToStateAI(HSE_Idle); } else { @@ -144,7 +143,7 @@ void HeroAI::UpdateThinking() } } else { ChangeToStateAI(HSE_Idle); - node_.param1 = node_.next_random_move_frameno - hum->room->GetFrameNo(); + node_.param1 = node_.next_random_move_frameno - hero->room->GetFrameNo(); } } } @@ -152,7 +151,7 @@ void HeroAI::UpdateThinking() void HeroAI::UpdateAttack() { - Human* myself = (Human*)owner; + Hero* myself = (Hero*)owner; if (!node_.target || node_.target->dead) { ChangeToStateAI(HSE_Thinking); return; @@ -210,18 +209,17 @@ void HeroAI::UpdateAttack() void HeroAI::UpdateRandomWalk() { - Human* hum = (Human*)owner; - if (hum->room->GetFrameNo() > node_.frameno + node_.param1) { + Hero* hero = (Hero*)owner; + if (hero->room->GetFrameNo() > node_.frameno + node_.param1) { ChangeToStateAI(HSE_Thinking); } } void HeroAI::UpdatePursuit() { - Human* myself = (Human*)owner; + Hero* myself = (Hero*)owner; float distance = myself->GetPos().Distance(node_.target->GetPos()); if (!myself->HasBuffEffect(kBET_Jump) && - !a8::HasBitFlag(myself->status, HS_DisableAttack) && distance < GetAttackRange()) { ChangeToStateAI(HSE_Attack); } else { @@ -233,15 +231,18 @@ void HeroAI::UpdatePursuit() void HeroAI::DoMoveAI() { - Human* hum = (Human*)owner; - if (std::abs(hum->move_dir.x) > FLT_EPSILON || - std::abs(hum->move_dir.y) > FLT_EPSILON) { + Hero* hero = (Hero*)owner; + if (std::abs(hero->move_dir.x) > FLT_EPSILON || + std::abs(hero->move_dir.y) > FLT_EPSILON) { + #if 0 hum->on_move_collision = [this] () { ChangeToStateAI(HSE_RandomWalk); return false; }; - int speed = std::max(1, (int)hum->GetSpeed()) * 1; + #endif + int speed = std::max(1, (int)hero->GetSpeed()) * 1; + #if 0 hum->_UpdateMove(speed); hum->on_move_collision = nullptr; if (node_.nearest_human) { @@ -252,12 +253,13 @@ void HeroAI::DoMoveAI() GetTarget(); } } + #endif } } void HeroAI::ChangeToStateAI(HeroState_e to_state) { - Human* hum = (Human*)owner; + Hero* hero = (Hero*)owner; switch (to_state) { case HSE_Idle: { @@ -266,9 +268,9 @@ void HeroAI::ChangeToStateAI(HeroState_e to_state) node_.start_shot_frameno = 0; node_.shot_times = 0; moving_ = false; - if (hum->room->GetGasData().gas_mode == GasInactive || - hum->room->IsWaitingStart() || - hum->HasBuffEffect(kBET_Jump)) { + if (hero->room->GetGasData().gas_mode == GasInactive || + hero->room->IsWaitingStart() || + hero->HasBuffEffect(kBET_Jump)) { node_.param1 = rand() % (3 * SERVER_FRAME_RATE); } else { node_.param1 = rand() % (2 * SERVER_FRAME_RATE); @@ -304,12 +306,14 @@ void HeroAI::ChangeToStateAI(HeroState_e to_state) #endif node_.start_shot_frameno = 0; node_.shot_times = 0; - node_.next_random_move_frameno = hum->room->GetFrameNo() + + node_.next_random_move_frameno = hero->room->GetFrameNo() + SERVER_FRAME_RATE * ai_meta->GetMoveIdleTime(); - hum->move_dir = a8::Vec2(1.0f, 0); - hum->move_dir.Rotate(a8::RandAngle()); - hum->move_dir.Normalize(); - hum->attack_dir = hum->move_dir; + hero->move_dir = a8::Vec2(1.0f, 0); + hero->move_dir.Rotate(a8::RandAngle()); + hero->move_dir.Normalize(); + #if 0 + hero->attack_dir = hero->move_dir; + #endif if (node_.param1 <= 1) { moving_ = false; } @@ -319,15 +323,17 @@ void HeroAI::ChangeToStateAI(HeroState_e to_state) { moving_ = true; if (node_.target) { - hum->move_dir = node_.target->GetPos() - hum->GetPos(); - hum->move_dir.Normalize(); - hum->attack_dir = hum->move_dir; + hero->move_dir = node_.target->GetPos() - hero->GetPos(); + hero->move_dir.Normalize(); + #if 0 + hero->attack_dir = hero->move_dir; + #endif } } break; } node_.main_state = to_state; - node_.frameno = hum->room->GetFrameNo(); + node_.frameno = hero->room->GetFrameNo(); node_.exec_frame_num = 0; } @@ -336,7 +342,7 @@ Human* HeroAI::GetTarget() if (GetAiLevel() <= 1) { return nullptr; } - Human* myself = (Human*)owner; + Hero* myself = (Hero*)owner; if (myself->room->GetGasData().gas_mode == GasInactive) { return nullptr; } @@ -378,17 +384,19 @@ Human* HeroAI::GetTarget() float HeroAI::GetAttackRange() { float attack_range = 0; - Human* myself = (Human*)owner; + Hero* myself = (Hero*)owner; + #if 0 if (myself->curr_weapon && myself->curr_weapon->meta) { attack_range = myself->curr_weapon->meta->i->range(); } + #endif attack_range = std::min(ai_meta->i->attack_range(), (int)attack_range); return attack_range; } void HeroAI::DoShotAI() { - Human* myself = (Human*)owner; + Hero* myself = (Hero*)owner; if (!node_.target) { return; } @@ -414,7 +422,9 @@ void HeroAI::DoShotAI() } a8::Vec2 old_attack_dir = myself->attack_dir; myself->attack_dir = shot_dir; + #if 0 myself->Shot(shot_dir, shot_ok); + #endif myself->attack_dir = old_attack_dir; if (shot_ok) { if (node_.shot_times <= 0) { @@ -428,10 +438,12 @@ void HeroAI::DoShotAI() int HeroAI::GetAttackTimes() { - Human* myself = (Human*)owner; + Hero* myself = (Hero*)owner; + #if 0 if (myself->curr_weapon) { return std::min(ai_meta->i->attack_times(), myself->curr_weapon->GetClipVolume()); } else { return ai_meta->i->attack_times(); } + #endif } diff --git a/server/gameserver/hero.cc b/server/gameserver/hero.cc index f32eb3f1..da0d7cd4 100644 --- a/server/gameserver/hero.cc +++ b/server/gameserver/hero.cc @@ -47,3 +47,18 @@ void Hero::Update(int delta_time) { ++updated_times_; } + +bool Hero::HasBuffEffect(int buff_effect_id) +{ + return false; +} + +Buff* Hero::GetBuffByEffectId(int effect_id) +{ + return nullptr; +} + +float Hero::GetSpeed() +{ + return 0; +} diff --git a/server/gameserver/hero.h b/server/gameserver/hero.h index 3bef213a..962dc440 100644 --- a/server/gameserver/hero.h +++ b/server/gameserver/hero.h @@ -11,11 +11,16 @@ namespace MetaData class Human; class Room; +class Buff; class Hero : public MoveableEntity { public: Entity* master = nullptr; MetaData::Player* meta = nullptr; + bool dead = false; + bool shot_hold = false; + int team_id = 0; + a8::Vec2 attack_dir; Hero(); virtual ~Hero() override; @@ -24,6 +29,10 @@ class Hero : public MoveableEntity virtual void FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data) override; virtual void Update(int delta_time) override; + bool HasBuffEffect(int buff_effect_id); + Buff* GetBuffByEffectId(int effect_id); + float GetSpeed(); + private: bool later_removed_ = false;