This commit is contained in:
aozhiwei 2021-04-16 15:18:33 +08:00
parent 09862e8c44
commit b6abae1922
8 changed files with 142 additions and 26 deletions

View File

@ -75,6 +75,11 @@ void Bullet::OnHit(std::set<Entity*>& objects)
#if 0
sender->stats.damage_amount_out += finaly_dmg;
#endif
#ifdef DEBUG
if (App::Instance()->HasFlag(1) && hum->IsPlayer()) {
continue;
}
#endif
hum->DecHP(finaly_dmg, sender.Get()->GetEntityUniId(), sender.Get()->GetName(), gun_meta->i->id());
#ifdef DEBUG
sender.Get()->SendDebugMsg(a8::Format("bullet weapon_id:%d atk:%f",

View File

@ -6,6 +6,7 @@
#include "typeconvert.h"
#include "metamgr.h"
#include "car.h"
#include "app.h"
cs::SMUpdate* FrameMaker::MakeUpdateMsg(Human* hum)
{
@ -31,6 +32,16 @@ cs::SMUpdate* FrameMaker::MakeUpdateMsg(Human* hum)
if (hum->IsPlayer()) {
itr->FillMFObjectFull(room, (Human*)hum, msg->add_full_objects());
}
#ifdef DEBUG
if (App::Instance()->HasFlag(2) && itr->GetEntityType() == ET_Player) {
room->BroadcastDebugMsg(a8::Format("投放 %d pos:%d,%d 出现",
{
itr->GetEntityUniId(),
itr->GetPos().x,
itr->GetPos().y,
}));
}
#endif
}
for (auto& itr : hum->part_objects) {
Entity* entity = itr;
@ -52,9 +63,25 @@ cs::SMUpdate* FrameMaker::MakeUpdateMsg(Human* hum)
}
for (auto& itr : hum->del_objects) {
msg->add_del_objids(itr);
#ifdef DEBUG
if (App::Instance()->HasFlag(2)) {
room->BroadcastDebugMsg(a8::Format("投放 删除对象%d",
{
itr
}));
}
#endif
}
for (auto& itr : hum->out_objects) {
msg->add_out_objids(itr);
#ifdef DEBUG
if (App::Instance()->HasFlag(2)) {
room->BroadcastDebugMsg(a8::Format("投放 移除视野对象%d",
{
itr
}));
}
#endif
}
for (size_t idx : hum->shots_) {
if (idx < room->frame_event.shots_.size()) {

View File

@ -945,7 +945,9 @@ void Human::DecHP(float dec_hp, int killer_id, const std::string& killer_name, i
SyncAroundPlayers(__FILE__, __LINE__, __func__);
if (GetNearbyTeammateNum(MetaMgr::Instance()->refresh_ai_downed_nearby_range) <
MetaMgr::Instance()->refresh_ai_downed_nearby_teammate_num) {
#if 0
room->GetIncubator()->AllocAndroid(this, 1 + rand() % 2);
#endif
}
} else {
BeKill(killer_id, killer_name, weapon_id);
@ -981,6 +983,11 @@ int Human::GetPartObjectsCount()
return part_objects.size();
}
bool Human::InNewObjects(Entity* target)
{
return new_objects.find(target) != new_objects.end();
}
bool Human::InPartObjects(Entity* target)
{
return part_objects.find(target) != part_objects.end();
@ -2747,7 +2754,9 @@ void Human::DropItems(Obstacle* obstacle)
behavior.curr_destory_box_times++;
behavior.total_destory_box_times++;
if (behavior.curr_destory_box_times >= MetaMgr::Instance()->refresh_ai_destory_box_times) {
#if 0
room->GetIncubator()->AllocAndroid(this, 1 + rand() % 2);
#endif
}
}
#ifdef DEBUG
@ -3246,6 +3255,27 @@ void Human::OnLand()
//着陆
RemoveBuffByEffectId(kBET_Jump);
RemoveBuffByEffectId(kBET_ThroughWall);
if (IsAndroid() && team_uuid.empty()) {
MustBeAddBuff(this, kBeRecycleBuffId);
}
if (IsPlayer()) {
refresh_view_timer_ = room->xtimer.AddRepeatTimerAndAttach
(
SERVER_FRAME_RATE * MetaMgr::Instance()->refresh_view_time,
a8::XParams()
.SetSender(this),
[] (const a8::XParams& param)
{
Human* hum = (Human*)param.sender.GetUserData();
hum->UpdateViewObjects();
},
&xtimer_attacher.timer_list_,
[] (const a8::XParams& param)
{
Human* hum = (Human*)param.sender.GetUserData();
hum->refresh_view_timer_ = nullptr;
});
}
if (IsCollisionInMapService()) {
a8::Vec2 old_pos = GetPos();
std::vector<a8::Vec2> dirs;
@ -3266,27 +3296,6 @@ void Human::OnLand()
}
SetPos(old_pos);
}
if (IsAndroid() && team_uuid.empty()) {
MustBeAddBuff(this, kBeRecycleBuffId);
}
if (IsPlayer()) {
refresh_view_timer_ = room->xtimer.AddRepeatTimerAndAttach
(
SERVER_FRAME_RATE * 8,
a8::XParams()
.SetSender(this),
[] (const a8::XParams& param)
{
Human* hum = (Human*)param.sender.GetUserData();
hum->UpdateViewObjects();
},
&xtimer_attacher.timer_list_,
[] (const a8::XParams& param)
{
Human* hum = (Human*)param.sender.GetUserData();
hum->refresh_view_timer_ = nullptr;
});
}
}
void Human::NextReload(int prev_weapon_id, int prev_weapon_idx)
@ -3463,8 +3472,8 @@ void Human::UpdateViewObjects()
if (view_objects_.size() >= 2) {
std::vector<Human*> deleted_humans;
for (Human* hum : view_objects_) {
if (hum->dead || hum->GetPos().ManhattanDistance(GetPos()) >
MetaMgr::Instance()->view_objects_out_distance) {
if (hum->dead ||
hum->GetPos().ManhattanDistance(GetPos()) > MetaMgr::Instance()->view_objects_out_distance) {
deleted_humans.push_back(hum);
}
}
@ -3492,7 +3501,9 @@ void Human::UpdateViewObjects()
if (view_objects_.size() < 2) {
room->GetIncubator()->AllocAndroid(this, 1 + rand() % 2);
if (refresh_view_timer_) {
room->xtimer.ModifyTimer(refresh_view_timer_, SERVER_FRAME_RATE * (8 + (rand() % 3)));
room->xtimer.ModifyTimer(refresh_view_timer_,
SERVER_FRAME_RATE * (MetaMgr::Instance()->refresh_view_time + (rand() % 3))
);
}
}
}

View File

@ -164,6 +164,7 @@ class Human : public Creature
void AddToNewObjects(Entity* entity);
void AddToPartObjects(Entity* entity);
void RemovePartObjects(Entity* entity);
bool InNewObjects(Entity* target);
bool InPartObjects(Entity* target);
int GetPartObjectsCount();
void RemoveObjects(Entity* entity);

View File

@ -17,6 +17,10 @@ void Incubator::UnInit()
void Incubator::AllocAndroid(Human* target, int num)
{
if (room->xtimer.GetRunningTimer() == nullptr) {
abort();
}
num = 1;
int try_count = 0;
a8::Vec2 dir = a8::Vec2::UP;
while (num > 0 && try_count < 20 && !hold_humans_.empty()) {
@ -24,17 +28,41 @@ void Incubator::AllocAndroid(Human* target, int num)
int rand_len = rand() % MetaMgr::Instance()->incubator_rand_length;
Human* hum = hold_humans_[0];
a8::Vec2 old_pos = hum->GetPos();
hum->SetPos(target->GetPos() + dir + MetaMgr::Instance()->incubator_base_length + rand_len);
if (!hum->CollisonDetection() && CanSet(hum, target)) {
hum->SetPos(target->GetPos() + dir * (MetaMgr::Instance()->incubator_base_length + rand_len));
if (hum->CollisonDetection() || !CanSet(hum, target)) {
hum->SetPos(old_pos);
} else {
room->EnableHuman(hum);
#ifdef DEBUG
if (!target->InNewObjects(hum)) {
abort();
}
if (hum->dead) {
abort();
}
#endif
hum->MustBeAddBuff(hum, kTraceBuffId);
hold_humans_.erase(hold_humans_.begin());
--num;
#ifdef DEBUG
room->BroadcastDebugMsg(a8::Format("投放机器人 %d:%s pos:%d,%d pos1:%d,%d %d num:%d",
{hum->GetEntityUniId(),
hum->name,
hum->GetPos().x,
hum->GetPos().y,
target->GetPos().x,
target->GetPos().y,
hum->GetPos().Distance(target->GetPos()),
hold_humans_.size()}));
#endif
}
++try_count;
}
#ifdef DEBUG
if (num > 0) {
room->BroadcastDebugMsg(a8::Format("投放机器人 分配失败 %d", {hold_humans_.size()}));
}
#endif
}
void Incubator::RecycleAndroid(Human* hum)
@ -55,22 +83,43 @@ void Incubator::RecycleAndroid(Human* hum)
return true;
});
if (hum->dead) {
#ifdef DEBUG
room->BroadcastDebugMsg(a8::Format("回收机器人 %d:%s 角色已死亡",
{hum->GetEntityUniId(),
hum->name}));
#endif
hum->RemoveBuffByEffectId(kBET_BeRecycle);
return;
}
if (distance < 450) {
#ifdef DEBUG
room->BroadcastDebugMsg(a8::Format("回收机器人 %d:%s 距离太近",
{hum->GetEntityUniId(),
hum->name}));
#endif
hum->RemoveBuffByEffectId(kBET_BeRecycle);
return;
}
if (distance > 1450) {
hum->RemoveBuffByEffectId(kBET_BeRecycle);
hold_humans_.push_back(hum);
room->DisableHuman(hum);
#ifdef DEBUG
room->BroadcastDebugMsg(a8::Format("回收机器人 %d:%s:%d 添加到回收列表",
{hum->GetEntityUniId(),
hum->name,
hold_humans_.size()
}));
#endif
return;
}
}
bool Incubator::CanSet(Human* hum, Human* exclude_hum)
{
#if 1
return true;
#endif
Human* target = hum;
bool can_set = true;
room->TouchAlivePlayers

View File

@ -241,6 +241,15 @@ public:
METAMGR_READ(refresh_ai_destory_box_times, 5);
METAMGR_READ(refresh_ai_downed_nearby_teammate_num, 1);
METAMGR_READ(refresh_ai_downed_nearby_range, 580);
METAMGR_READ(view_objects_out_distance, 580);
METAMGR_READ(view_objects_in_distance, 580);
METAMGR_READ(incubator_base_length, 80);
METAMGR_READ(incubator_rand_length, 10);
METAMGR_READ(incubator_canset_distance, 100);
METAMGR_READ(refresh_view_time, 4);
{
METAMGR_READ_STR(level0room_spec_things, "");
std::vector<std::string> tmpstrings;

View File

@ -151,6 +151,8 @@ class MetaMgr : public a8::Singleton<MetaMgr>
int incubator_rand_length = 100;
int incubator_canset_distance = 100;
int refresh_view_time = 8;
#if 0
int refresh_robot_min_num = 0;
int refresh_robot_max_num = 0;

View File

@ -2311,13 +2311,23 @@ void Room::EnableHuman(Human* target)
target->GetEntityUniId()
});
#endif
#if 0
target->OnEnable();
AddToMoveableHash(target);
if (!target->real_dead) {
AddToAliveHumanHash(target);
}
#else
if (a8::HasBitFlag(target->status, HS_Disable)) {
target->OnEnable();
AddToMoveableHash(target);
if (!target->real_dead) {
AddToAliveHumanHash(target);
}
} else {
abort();
}
#endif
#ifdef DEBUG
CheckPartObjects();
#endif
@ -2325,9 +2335,11 @@ void Room::EnableHuman(Human* target)
void Room::DisableHuman(Human* target)
{
#if 0
if (!RuningInTimer()) {
abort();
}
#endif
#ifdef DEBUG
CheckPartObjects();
a8::UdpLog::Instance()->Debug("disablehuman %d %d",