81 lines
2.1 KiB
C++
81 lines
2.1 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);
|
|
}
|
|
}
|
|
}
|
|
);
|
|
a8::Vec2 old_buff_vec2_param1 = sender.Get()->buff_vec2_param1;
|
|
sender.Get()->buff_vec2_param1 = sender.Get()->GetPos();
|
|
for (Creature* target : objects) {
|
|
if (!target->GetBuffById(meta->i->buffid())) {
|
|
target->MustBeAddBuff(sender.Get(), meta->i->buffid());
|
|
}
|
|
}
|
|
sender.Get()->buff_vec2_param1 = old_buff_vec2_param1;
|
|
}
|
|
}
|
|
|
|
void PosionGasMiTask::Done()
|
|
{
|
|
}
|