This commit is contained in:
aozhiwei 2020-07-29 17:32:43 +08:00
commit 18de7c6deb
13 changed files with 124 additions and 60 deletions

View File

@ -17,8 +17,17 @@ void AIComponent::SetAiLevel(int ai_level)
ai_level_ = ai_level;
}
void AIComponent::SetAiMode(int ai_mode)
{
ai_mode_ = ai_mode;
}
int AIComponent::GetAiLevel()
{
return ai_level_;
}
int AIComponent::GetAiMode()
{
return ai_mode_;
}

View File

@ -9,10 +9,14 @@ class AIComponent
virtual ~AIComponent();
virtual void Update(int delta_time);
virtual float GetAttackRate() { return 0;};
virtual void Reset() {};
void SetAiLevel(int ai_level);
void SetAiMode(int ai_mode);
int GetAiLevel();
int GetAiMode();
private:
int ai_level_ = 0;
int ai_mode_ = 0;
};

View File

@ -410,7 +410,7 @@ void AndroidNewAI::UpdateNewAI()
return;
}
if (!ai_meta && GetAiLevel() != 0) {
ai_meta = MetaMgr::Instance()->GetAI(GetAiLevel());
ai_meta = MetaMgr::Instance()->GetAI(GetAiLevel(), 0);
if (!ai_meta) {
abort();
}

View File

@ -3,14 +3,12 @@
#include "android.h"
#include "metamgr.h"
#include "android.ai.h"
#include "zombie.ai.h"
#include "zombiemode.ai.h"
#include "room.h"
#include "app.h"
Android::Android():Human()
{
ai = new ZombieAI;
ai->owner = this;
#if 0
++PerfMonitor::Instance()->entity_num[ET_Android];
#endif
@ -18,8 +16,9 @@ Android::Android():Human()
Android::~Android()
{
delete ai;
ai = nullptr;
if (ai) {
A8_SAFE_DELETE(ai);
}
#if 0
--PerfMonitor::Instance()->entity_num[ET_Android];
#endif
@ -27,6 +26,15 @@ Android::~Android()
void Android::Initialize()
{
if (room->GetRoomMode() == kZombieMode) {
ai = new ZombieModeAI;
ai->owner = this;
ai->SetAiLevel(8);
ai->SetAiMode(kHumanAiMode);
} else {
ai = new AndroidNewAI;
ai->owner = this;
}
Human::Initialize();
RandSkin();
GiveEquip();

View File

@ -131,6 +131,7 @@ enum BuffEffectType_e
kBET_Pull = 12, //拉人(主动方)
kBET_Terminator = 13, //终结者模式
kBET_PlayShotAni = 14, //播放射击动画
kBET_Vertigo = 15, //眩晕
kBET_End
};
@ -303,6 +304,13 @@ enum RaceType_e
kZombieRace = 2
};
enum AIMode_e
{
kChiJiAiMode = 0,
kHumanAiMode = 1,
kZombieAiMode = 2
};
const char* const PROJ_NAME_FMT = "game%d_gameserver";
const char* const PROJ_ROOT_FMT = "/data/logs/%s";
@ -357,3 +365,5 @@ const int HUMAN_RACE_META_START_ID = 5001;
const int ZOMBIE_RACE_META_START_ID = 6001;
const int TERMINATOR_BUFF_ID = 1033;
const int TURN_OVER_SKILL_ID = 41001;

View File

@ -22,6 +22,7 @@
#include "player.h"
#include "buff.h"
#include "roomobstacle.h"
#include "aicomponent.h"
#include "framework/cpp/utils.h"
#include "framework/cpp/httpclientpool.h"
@ -1924,6 +1925,15 @@ void Human::ChangeToRace(RaceType_e race, int level)
race != kZombieRace) {
abort();
}
if (race_ != race && IsAndroid()) {
Android* android = (Android*)this;
android->ai->Reset();
if (race == kHumanRace) {
android->ai->SetAiMode(kHumanAiMode);
} else if (race == kZombieRace) {
android->ai->SetAiMode(kZombieAiMode);
}
}
race_ = race;
level_ = level;
if (race_ == kHumanRace) {

View File

@ -602,12 +602,7 @@ private:
MetaData::AI& item = a8::FastAppend(ai_list);
item.i = &meta;
item.Init();
ai_hash[meta.ai_level()] = &item;
}
for (int i = 1; i <= MAX_AI_LEVEL; ++i) {
if (ai_hash.find(i) == ai_hash.end()) {
abort();
}
ai_hash[a8::MakeInt64(meta.ai_level(), meta.ai_mode())] = &item;
}
}
@ -836,8 +831,8 @@ MetaData::Robot* MetaMgr::RandRobot(std::set<int>& refreshed_robot_set)
}
}
MetaData::AI* MetaMgr::GetAI(int ai_level)
MetaData::AI* MetaMgr::GetAI(int ai_level, int ai_mode)
{
auto itr = loader_->ai_hash.find(ai_level);
auto itr = loader_->ai_hash.find(a8::MakeInt64(ai_level, ai_mode));
return itr != loader_->ai_hash.end() ? itr->second : nullptr;
}

View File

@ -47,7 +47,7 @@ class MetaMgr : public a8::Singleton<MetaMgr>
int GetKillPointParam1(int kill_num);
int GetKillPointParam2(int kill_num);
MetaData::Robot* RandRobot(std::set<int>& refreshed_robot_set);
MetaData::AI* GetAI(int ai_level);
MetaData::AI* GetAI(int ai_level, int ai_mode);
int gas_inactive_time = 10;
int newbie_gas_inactive_time = 5;

View File

@ -127,6 +127,9 @@ void Player::UpdateMove()
SetLastCollisionDoor(nullptr);
return;
}
if (HasBuffEffect(kBET_Vertigo)) {
return;
}
if (HasBuffEffect(kBET_Camouflage)) {
RemoveBuffByEffectId(kBET_Camouflage);
}
@ -163,6 +166,9 @@ void Player::UpdateShot()
series_shot_frames = 0;
return;
}
if (HasBuffEffect(kBET_Vertigo)) {
return;
}
if (shot_start) {
shot_start = false;
Shot();
@ -317,6 +323,9 @@ void Player::UpdateGetDown()
void Player::UpdateUseSkill()
{
if (HasBuffEffect(kBET_Vertigo)) {
return;
}
DoSkill();
}
@ -552,7 +561,10 @@ void Player::LootInteraction(Loot* entity)
weapon->ammo = 0;
weapon->meta = item_meta;
weapon->Recalc();
AutoLoadingBullet();
if (room->GetRoomMode() == kZombieMode && HasBuffEffect(kBET_Car)) {
} else {
AutoLoadingBullet();
}
need_sync_active_player = true;
SyncAroundPlayers(__FILE__, __LINE__, __func__);
}

View File

@ -26,6 +26,8 @@
#include "entityfactory.h"
#include "perfmonitor.h"
#include "framework/cpp/utils.h"
const size_t NORMAL_ROOM_MAX_PLAYER_NUM = 40;
const size_t MINI_ROOM_MAX_PLAYER_NUM = 20;
@ -1983,7 +1985,11 @@ long long Room::GetGasInactiveTime()
{
if (room_mode_ == kZombieMode) {
#if DEBUG
return 5;
if (f8::IsTestEnv()) {
return MetaMgr::Instance()->zbmode_gas_inactive_time + 10000;
} else {
return 5;
}
#else
return MetaMgr::Instance()->zbmode_gas_inactive_time;
#endif
@ -2655,8 +2661,8 @@ void Room::AddPlayerPostProc(Player* hum)
RandRemoveAndroid();
}
if (GetRoomMode() == kZombieMode) {
#if 0
hum->ChangeToRace(kZombieRace, 1);
#if 1
hum->ChangeToRace(kZombieRace, 2);
#else
hum->ChangeToRace(kHumanRace, 1);
#endif

View File

@ -2,7 +2,7 @@
#include <float.h>
#include "zombie.ai.h"
#include "zombiemode.ai.h"
#include "android.h"
#include "room.h"
#include "metamgr.h"
@ -39,31 +39,17 @@ public:
MetaData::AI* ai_meta = nullptr;
};
/*
nn目标ai可切换/()
ai级别
1: ()
2:
3:
4: ()
5:
6:
7:
8:
*/
ZombieAI::ZombieAI()
ZombieModeAI::ZombieModeAI()
{
node_ = new ZombieAINode();
}
ZombieAI::~ZombieAI()
ZombieModeAI::~ZombieModeAI()
{
A8_SAFE_DELETE(node_);
}
void ZombieAI::Update(int delta_time)
void ZombieModeAI::Update(int delta_time)
{
Human* hum = (Human*)owner;
if (hum->poisoning) {
@ -75,13 +61,17 @@ void ZombieAI::Update(int delta_time)
if (hum->dead) {
return;
}
if (hum->room->GetGasData().gas_mode == GasInactive) {
return;
}
UpdateAI();
}
float ZombieAI::GetAttackRate()
void ZombieModeAI::Reset()
{
ChangeToState(ZSE_Idle);
node_->param1 = 2;
node_->ai_meta = nullptr;
}
float ZombieModeAI::GetAttackRate()
{
if (!node_->ai_meta) {
return 1;
@ -90,14 +80,14 @@ float ZombieAI::GetAttackRate()
}
}
void ZombieAI::UpdateAI()
void ZombieModeAI::UpdateAI()
{
Human* hum = (Human*)owner;
if (a8::HasBitFlag(hum->status, HS_Disable)) {
return;
}
if (!node_->ai_meta && GetAiLevel() != 0) {
node_->ai_meta = MetaMgr::Instance()->GetAI(GetAiLevel());
node_->ai_meta = MetaMgr::Instance()->GetAI(GetAiLevel(), GetAiMode());
if (!node_->ai_meta) {
abort();
}
@ -145,7 +135,7 @@ void ZombieAI::UpdateAI()
}
}
void ZombieAI::UpdateIdle()
void ZombieModeAI::UpdateIdle()
{
Human* hum = (Human*)owner;
if (hum->room->GetFrameNo() > node_->frameno + node_->param1) {
@ -153,7 +143,7 @@ void ZombieAI::UpdateIdle()
}
}
void ZombieAI::UpdateThinking()
void ZombieModeAI::UpdateThinking()
{
Human* hum = (Human*)owner;
if (hum->room->GetGasData().gas_mode == GasInactive ||
@ -183,9 +173,12 @@ void ZombieAI::UpdateThinking()
}
}
void ZombieAI::UpdateAttack()
void ZombieModeAI::UpdateAttack()
{
Human* myself = (Human*)owner;
if (myself->HasBuffEffect(kBET_Vertigo)) {
return;
}
if (!node_->target || node_->target->dead) {
ChangeToState(ZSE_Thinking);
return;
@ -196,7 +189,11 @@ void ZombieAI::UpdateAttack()
}
float distance = myself->GetPos().Distance(node_->target->GetPos());
if (distance > GetAttackRange()) {
if (node_->ai_meta->i->pursuit_radius() <= 0) {
if (myself->CanUseSkill() &&
myself->CurrentSkillMeta()->i->skill_id() != TURN_OVER_SKILL_ID &&
distance < myself->CurrentSkillMeta()->i->skill_distance()) {
DoSkill();
} else if (node_->ai_meta->i->pursuit_radius() <= 0) {
//站桩
ChangeToState(ZSE_Thinking);
} else {
@ -245,7 +242,7 @@ void ZombieAI::UpdateAttack()
}
}
void ZombieAI::UpdateRandomWalk()
void ZombieModeAI::UpdateRandomWalk()
{
Human* hum = (Human*)owner;
if (hum->room->GetFrameNo() > node_->frameno + node_->param1) {
@ -253,7 +250,7 @@ void ZombieAI::UpdateRandomWalk()
}
}
void ZombieAI::UpdatePursuit()
void ZombieModeAI::UpdatePursuit()
{
Human* myself = (Human*)owner;
float distance = myself->GetPos().Distance(node_->target->GetPos());
@ -266,9 +263,12 @@ void ZombieAI::UpdatePursuit()
}
}
void ZombieAI::DoMove()
void ZombieModeAI::DoMove()
{
Human* hum = (Human*)owner;
if (hum->HasBuffEffect(kBET_Vertigo)) {
return;
}
if (std::abs(hum->move_dir.x) > FLT_EPSILON ||
std::abs(hum->move_dir.y) > FLT_EPSILON) {
hum->on_move_collision =
@ -290,7 +290,7 @@ void ZombieAI::DoMove()
}
}
void ZombieAI::ChangeToState(ZombieState_e to_state)
void ZombieModeAI::ChangeToState(ZombieState_e to_state)
{
Human* hum = (Human*)owner;
switch (to_state) {
@ -361,7 +361,7 @@ void ZombieAI::ChangeToState(ZombieState_e to_state)
node_->exec_frame_num = 0;
}
Human* ZombieAI::GetTarget()
Human* ZombieModeAI::GetTarget()
{
if (GetAiLevel() <= 1) {
return nullptr;
@ -401,8 +401,7 @@ Human* ZombieAI::GetTarget()
node_->nearest_human = target;
node_->last_check_nearest_human_frameno = myself->room->GetFrameNo();
float distance = myself->GetPos().Distance(target->GetPos());
#if 1
#else
#if 0
if (distance > GetAttackRange()) {
target = nullptr;
}
@ -411,7 +410,7 @@ Human* ZombieAI::GetTarget()
return target;
}
float ZombieAI::GetAttackRange()
float ZombieModeAI::GetAttackRange()
{
float attack_range = 0;
Human* myself = (Human*)owner;
@ -424,7 +423,7 @@ float ZombieAI::GetAttackRange()
return attack_range;
}
void ZombieAI::DoShot()
void ZombieModeAI::DoShot()
{
Human* myself = (Human*)owner;
if (!node_->target) {
@ -464,7 +463,15 @@ void ZombieAI::DoShot()
}
}
int ZombieAI::GetAttackTimes()
void ZombieModeAI::DoSkill()
{
Human* myself = (Human*)owner;
myself->skill_target_id = node_->target->GetEntityUniId();
myself->skill_target_pos = node_->target->GetPos();
myself->DoSkill();
}
int ZombieModeAI::GetAttackTimes()
{
Human* myself = (Human*)owner;
if (myself->curr_weapon) {

View File

@ -13,13 +13,14 @@ enum ZombieState_e
class Human;
class ZombieAINode;
class ZombieAI : public AIComponent
class ZombieModeAI : public AIComponent
{
public:
ZombieAI();
virtual ~ZombieAI() override;
ZombieModeAI();
virtual ~ZombieModeAI() override;
virtual void Update(int delta_time) override;
virtual void Reset() override;
float GetAttackRate();
private:
@ -32,6 +33,7 @@ private:
void DoMove();
void ChangeToState(ZombieState_e to_state);
void DoShot();
void DoSkill();
Human* GetTarget();
float GetAttackRange();

View File

@ -263,6 +263,7 @@ message AI
optional string random_move_time = 9;
optional int32 attack_range = 10;
optional float attack_rate = 11;
optional int32 ai_mode = 12;
}
//end