diff --git a/server/gameserver/incubator.cc b/server/gameserver/incubator.cc index ef8526a..1261692 100644 --- a/server/gameserver/incubator.cc +++ b/server/gameserver/incubator.cc @@ -7,7 +7,18 @@ void Incubator::Init() { - + xtimer_attacher_.xtimer = &room->xtimer; + room->xtimer.AddRepeatTimerAndAttach + ( + SERVER_FRAME_RATE * (2 + rand() % 3), + a8::XParams() + .SetSender(this), + [] (const a8::XParams& param) + { + Incubator* incubator = (Incubator*)param.sender.GetUserData(); + incubator->AutoAllocAndroid(); + }, + &xtimer_attacher_.timer_list_); } void Incubator::UnInit() @@ -134,3 +145,42 @@ bool Incubator::CanSet(Human* hum, Human* exclude_hum) }); return can_set; } + +void Incubator::AutoAllocAndroid() +{ + switch (room->GetGasData().gas_mode) { + case GasWaiting: + case GasMoving: + { + if (!hold_humans_.empty()){ + Human* hum = hold_humans_[0]; + if (room->GetGasData().gas_mode == GasWaiting && + hold_humans_.size() > 1 && + ((rand() % 100) > 30)) { + Human* killer = nullptr; + if (hold_humans_.size() == 2) { + killer = hold_humans_[1]; + } else { + killer = hold_humans_[1 + (rand() % (hold_humans_.size() - 1))]; + } + hum->BeKill(killer->GetEntityUniId(), + killer->name, + killer->GetCurrWeapon()->weapon_id); + } else if (room->GetGasData().gas_count > 1) { + hum->BeKill(VP_SafeArea, + TEXT("battle_server_killer_gas", "毒圈"), + VW_SafeArea); + } else { + return; + } + hold_humans_.erase(hold_humans_.begin()); + room->xtimer.ModifyTimer(room->xtimer.GetRunningTimer(), SERVER_FRAME_RATE * (3 + rand() % 5)); + } + } + break; + default: + { + } + break; + } +} diff --git a/server/gameserver/incubator.h b/server/gameserver/incubator.h index 165cf58..47a293b 100644 --- a/server/gameserver/incubator.h +++ b/server/gameserver/incubator.h @@ -1,5 +1,7 @@ #pragma once +#include + class Human; class Room; class Incubator @@ -14,7 +16,9 @@ class Incubator private: bool CanSet(Human* hum, Human* exclude_hum); + void AutoAllocAndroid(); private: std::vector hold_humans_; + a8::XTimerAttacher xtimer_attacher_; }; diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 95fe20c..0d29afd 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -3722,6 +3722,7 @@ void Room::ForwardGasRing(int n) } gas_data_.rad_old = gas_data_.old_area_meta->i->rad(); gas_data_.rad_new = gas_data_.new_area_meta->i->rad(); + gas_data_.gas_count++; --n; } } diff --git a/server/gameserver/types.h b/server/gameserver/types.h index e639071..fbff66c 100755 --- a/server/gameserver/types.h +++ b/server/gameserver/types.h @@ -29,6 +29,7 @@ struct GasData MetaData::SafeArea* old_area_meta = nullptr; MetaData::SafeArea* new_area_meta = nullptr; bool is_last_gas = false; + int gas_count = 0; }; struct Weapon