From 52144aacad48e78e8c66a8de230b408e30eda6a5 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 7 Apr 2021 14:15:32 +0800 Subject: [PATCH] 1 --- server/gameserver/constant.h | 5 +++ server/gameserver/creature.cc | 53 ++++++++++++++++--------------- server/gameserver/roomobstacle.cc | 32 +++++++++++++++++++ server/gameserver/roomobstacle.h | 1 + 4 files changed, 66 insertions(+), 25 deletions(-) diff --git a/server/gameserver/constant.h b/server/gameserver/constant.h index 665406ba..ce60a475 100755 --- a/server/gameserver/constant.h +++ b/server/gameserver/constant.h @@ -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"; diff --git a/server/gameserver/creature.cc b/server/gameserver/creature.cc index 14704a4c..8ac161eb 100644 --- a/server/gameserver/creature.cc +++ b/server/gameserver/creature.cc @@ -1319,32 +1319,35 @@ RoomObstacle* Creature::SummonObstacle(int id, const a8::Vec2& pos) RoomObstacle* obstacle = room->CreateObstacle(id, pos.x, pos.y); if (obstacle) { obstacle->master.Attach(this); - room->xtimer.AddRepeatTimerAndAttach - ( - SERVER_FRAME_RATE, - a8::XParams() - .SetSender(obstacle), - [] (const a8::XParams& param) - { - RoomObstacle* obstacle = (RoomObstacle*)param.sender.GetUserData(); - obstacle->ActiveTimerFunc(); - }, - &obstacle->xtimer_attacher.timer_list_ - ); - - room->xtimer.AddRepeatTimerAndAttach - ( - SERVER_FRAME_RATE, - a8::XParams() - .SetSender(obstacle), - [] (const a8::XParams& param) - { - RoomObstacle* obstacle = (RoomObstacle*)param.sender.GetUserData(); - obstacle->UpdateTimerFunc(); - }, - &obstacle->xtimer_attacher.timer_list_ - ); + if (obstacle->meta->i->thing_type() == kObstacleSelfExplosion) { + obstacle->Active(); + } else { + room->xtimer.AddRepeatTimerAndAttach + ( + SERVER_FRAME_RATE, + a8::XParams() + .SetSender(obstacle), + [] (const a8::XParams& param) + { + RoomObstacle* obstacle = (RoomObstacle*)param.sender.GetUserData(); + obstacle->ActiveTimerFunc(); + }, + &obstacle->xtimer_attacher.timer_list_ + ); + room->xtimer.AddRepeatTimerAndAttach + ( + SERVER_FRAME_RATE, + a8::XParams() + .SetSender(obstacle), + [] (const a8::XParams& param) + { + RoomObstacle* obstacle = (RoomObstacle*)param.sender.GetUserData(); + obstacle->UpdateTimerFunc(); + }, + &obstacle->xtimer_attacher.timer_list_ + ); + } } else { abort(); } diff --git a/server/gameserver/roomobstacle.cc b/server/gameserver/roomobstacle.cc index 03246ec6..c340da74 100644 --- a/server/gameserver/roomobstacle.cc +++ b/server/gameserver/roomobstacle.cc @@ -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_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; + } +} diff --git a/server/gameserver/roomobstacle.h b/server/gameserver/roomobstacle.h index 26d1ca11..53e3a558 100644 --- a/server/gameserver/roomobstacle.h +++ b/server/gameserver/roomobstacle.h @@ -20,6 +20,7 @@ class RoomObstacle : public Obstacle virtual bool CanThroughable(Human* hum) override; void ActiveTimerFunc(); void UpdateTimerFunc(); + void Active(); private: void Explosion();