This commit is contained in:
aozhiwei 2021-04-13 20:26:32 +08:00
parent 3013b24550
commit 8b76a1cd57
3 changed files with 45 additions and 4 deletions

View File

@ -170,6 +170,7 @@ enum BuffEffectType_e
kBET_InIce = 58, //在冰里
kBET_BatchAddBuff = 60, //批量添加buff
kBET_BeRecycle = 61, //待回收
kBET_Trace = 62, //追踪玩家
kBET_End
};
@ -470,4 +471,5 @@ const int kInGrassBuffId = 7006;
const int kInWaterBuffId = 7007;
const int kInIceBuffId = 7008;
const int kBeRecycleBuffId = 7009;
const int kTraceBuffId = 7011;
const float DEFAULT_FLY_DISTANCE = 5.0f;

View File

@ -4,6 +4,9 @@
#include "room.h"
#include "human.h"
const int ALLOC_BASE_LENGTH = 500;
const int ALLOC_RAND_LENGTH = 100;
void Incubator::Init()
{
@ -16,8 +19,23 @@ void Incubator::UnInit()
void Incubator::AllocAndroid(Human* target, int num)
{
if (num > 0) {
int try_count = 0;
a8::Vec2 dir = a8::Vec2::UP;
while (num > 0 && try_count < 20 && !hold_humans_.empty()) {
dir.Rotate(a8::RandAngle());
int rand_len = rand() % ALLOC_RAND_LENGTH;
Human* hum = hold_humans_[0];
a8::Vec2 old_pos = hum->GetPos();
hum->SetPos(target->GetPos() + dir + ALLOC_BASE_LENGTH + rand_len);
if (!hum->CollisonDetection() && CanSet(hum, target)) {
hum->SetPos(old_pos);
} else {
room->EnableHuman(hum);
hum->MustBeAddBuff(hum, kTraceBuffId);
hold_humans_.erase(hold_humans_.begin());
--num;
}
++try_count;
}
}
@ -48,7 +66,27 @@ void Incubator::RecycleAndroid(Human* hum)
}
if (distance > 1450) {
hum->RemoveBuffByEffectId(kBET_BeRecycle);
hold_humans_.insert(hum);
hold_humans_.push_back(hum);
return;
}
}
bool Incubator::CanSet(Human* hum, Human* exclude_hum)
{
Human* target = hum;
bool can_set = true;
room->TouchAlivePlayers
(
a8::XParams(),
[target, exclude_hum, &can_set] (Human* hum, a8::XParams& param) -> bool
{
if (hum != exclude_hum) {
if (target->GetPos().ManhattanDistance(hum->GetPos()) < 100) {
can_set = false;
return false;
}
}
return true;
});
return can_set;
}

View File

@ -13,7 +13,8 @@ class Incubator
void RecycleAndroid(Human* hum);
private:
bool CanSet(Human* hum, Human* exclude_hum);
private:
std::set<Human*> hold_humans_;
std::vector<Human*> hold_humans_;
};