This commit is contained in:
aozhiwei 2021-04-07 14:15:32 +08:00
parent 45c68e188c
commit 52144aacad
4 changed files with 66 additions and 25 deletions

View File

@ -375,6 +375,11 @@ enum PostBuffAction_e
kRemoveBuffByEffectAction = 2
};
enum ObstacleType_e
{
kObstacleSelfExplosion = 1,
};
const char* const PROJ_NAME_FMT = "game%d_gameserver";
const char* const PROJ_ROOT_FMT = "/data/logs/%s";

View File

@ -1319,6 +1319,9 @@ RoomObstacle* Creature::SummonObstacle(int id, const a8::Vec2& pos)
RoomObstacle* obstacle = room->CreateObstacle(id, pos.x, pos.y);
if (obstacle) {
obstacle->master.Attach(this);
if (obstacle->meta->i->thing_type() == kObstacleSelfExplosion) {
obstacle->Active();
} else {
room->xtimer.AddRepeatTimerAndAttach
(
SERVER_FRAME_RATE,
@ -1344,7 +1347,7 @@ RoomObstacle* Creature::SummonObstacle(int id, const a8::Vec2& pos)
},
&obstacle->xtimer_attacher.timer_list_
);
}
} else {
abort();
}

View File

@ -97,6 +97,10 @@ bool RoomObstacle::CanThroughable(Human* hum)
void RoomObstacle::ActiveTimerFunc()
{
if (meta->i->thing_type() == kObstacleSelfExplosion) {
room->xtimer.DeleteTimer(room->xtimer.GetRunningTimer());
return;
}
if (!master.Get()) {
room->xtimer.DeleteTimer(room->xtimer.GetRunningTimer());
return;
@ -131,6 +135,10 @@ void RoomObstacle::ActiveTimerFunc()
void RoomObstacle::UpdateTimerFunc()
{
if (meta->i->thing_type() == kObstacleSelfExplosion) {
room->xtimer.DeleteTimer(room->xtimer.GetRunningTimer());
return;
}
if (grid_list_ && master.Get() && !IsDead(room)) {
std::set<Human*> human_list;
room->grid_service->TouchAllLayerHumanList
@ -255,3 +263,27 @@ void RoomObstacle::Explosion()
self_collider_->rad = old_rad;
}
}
void RoomObstacle::Active()
{
switch (meta->i->thing_type()) {
case kObstacleSelfExplosion:
{
room->xtimer.AddDeadLineTimerAndAttach
(
meta->i->time() / FRAME_RATE_MS,
a8::XParams()
.SetSender(this),
[] (const a8::XParams& param)
{
RoomObstacle* obstacle = (RoomObstacle*)param.sender.GetUserData();
obstacle->Explosion();
},
&xtimer_attacher.timer_list_
);
}
break;
default:
break;
}
}

View File

@ -20,6 +20,7 @@ class RoomObstacle : public Obstacle
virtual bool CanThroughable(Human* hum) override;
void ActiveTimerFunc();
void UpdateTimerFunc();
void Active();
private:
void Explosion();