game2005/server/gameserver/posiongas_mitask.cc
aozhiwei 1dec9d2c26 1
2021-04-06 14:35:36 +08:00

78 lines
1.9 KiB
C++

#include "precompile.h"
#include "posiongas_mitask.h"
#include "room.h"
#include "player.h"
#include "metadata.h"
void PosionGasMiTask::Initialzie()
{
sender.Get()->room->grid_service->GetAllCellsByXy
(
sender.Get()->room,
bomb_pos.x,
bomb_pos.y,
grid_list
);
}
void PosionGasMiTask::Active()
{
room->xtimer.AddRepeatTimerAndAttach
(SERVER_FRAME_RATE / 2,
a8::XParams()
.SetSender(this),
[] (const a8::XParams& param)
{
PosionGasMiTask* task = (PosionGasMiTask*)param.sender.GetUserData();
task->Check();
},
&timer_attacher.timer_list_);
room->xtimer.AddDeadLineTimerAndAttach
(SERVER_FRAME_RATE * meta->i->time(),
a8::XParams()
.SetSender(this),
[] (const a8::XParams& param)
{
},
&timer_attacher.timer_list_,
[] (const a8::XParams& param)
{
PosionGasMiTask* task = (PosionGasMiTask*)param.sender.GetUserData();
task->Done();
delete task;
}
);
}
void PosionGasMiTask::Check()
{
if (sender.Get()) {
std::set<Creature*> objects;
sender.Get()->room->grid_service->TouchCreatures
(
sender.Get()->room->GetRoomIdx(),
grid_list,
[this, &objects] (Creature* c, bool& stop)
{
if (sender.Get()->IsProperTarget(c)) {
if (bomb_pos.Distance(c->GetPos()) < meta->i->explosion_range()) {
objects.insert(c);
}
}
}
);
for (Creature* target : objects) {
if (!target->GetBuffById(meta->i->buffid())) {
target->MustBeAddBuff(sender.Get(), meta->i->buffid());
}
}
}
}
void PosionGasMiTask::Done()
{
}