From d3d6e91a1a840493ba096facb11fb34601e6c8e2 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 10 Mar 2021 15:12:28 +0800 Subject: [PATCH] 1 --- server/gameserver/human.cc | 24 +++++++++++++++++ server/gameserver/human.h | 2 ++ server/gameserver/room.h | 2 +- server/gameserver/roomobstacle.cc | 43 +++++++++++++++++++++++++++++-- server/gameserver/roomobstacle.h | 8 +++++- 5 files changed, 75 insertions(+), 4 deletions(-) diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index c345cb4..6755a6d 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -19,6 +19,7 @@ #include "gamelog.h" #include "typeconvert.h" #include "obstacle.h" +#include "roomobstacle.h" #include "player.h" #include "buff.h" #include "roomobstacle.h" @@ -2154,6 +2155,29 @@ bool Human::IsEnemy(Human* hum) } } +RoomObstacle* Human::SummonObstacle(int equip_id, const a8::Vec2& pos) +{ + RoomObstacle* obstacle = room->CreateObstacle(equip_id, pos.x, pos.y); + if (obstacle) { + obstacle->master = 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_ + ); + } else { + abort(); + } + return obstacle; +} + void Human::_InternalUpdateMove(float speed) { float nx = move_dir.x * speed; diff --git a/server/gameserver/human.h b/server/gameserver/human.h index f80bfd6..66edeca 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -32,6 +32,7 @@ struct xtimer_list; class CircleCollider; class AabbCollider; class Obstacle; +class RoomObstacle; class Loot; class Buff; class Human : public MoveableEntity @@ -302,6 +303,7 @@ class Human : public MoveableEntity HumanCar& GetCar() { return car_; } void DeadDrop(); bool IsEnemy(Human* hum); + RoomObstacle* SummonObstacle(int equip_id, const a8::Vec2& pos); protected: void _InternalUpdateMove(float speed); diff --git a/server/gameserver/room.h b/server/gameserver/room.h index e11b75b..60e30fb 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -152,6 +152,7 @@ public: void OnZombieAppear(Human* hum); int GetAliveCountByRace(RaceType_e race); int GetOnlinePlayerNum(); + RoomObstacle* CreateObstacle(int id, float x, float y); private: int AllocUniid(); @@ -171,7 +172,6 @@ private: void AdjustAirDropPos(MetaData::MapThing* thing_meta, a8::Vec2& box_pos); void ShuaPlane(); int NewTeam(); - RoomObstacle* CreateObstacle(int id, float x, float y); RoomObstacle* InternalCreateObstacle(int id, float x, float y, std::function on_precreate); void AddObjectLater(RoomEntity* entity); diff --git a/server/gameserver/roomobstacle.cc b/server/gameserver/roomobstacle.cc index b0df082..dc29aa1 100644 --- a/server/gameserver/roomobstacle.cc +++ b/server/gameserver/roomobstacle.cc @@ -31,6 +31,9 @@ RoomObstacle::~RoomObstacle() #endif room->map_service->RemoveCollider(collider); } + if (!grid_list_) { + A8_SAFE_DELETE(grid_list_); + } } void RoomObstacle::Initialize() @@ -83,7 +86,43 @@ void RoomObstacle::RecalcSelfCollider() } } -bool RoomObstacle::CanThroughable(Human* num) +bool RoomObstacle::CanThroughable(Human* hum) { - return true; + if (master) { + return master->team_id == hum->team_id && temp_through_; + } else { + return temp_through_; + } +} + +void RoomObstacle::ActiveTimerFunc() +{ + if (!master) { + room->xtimer.DeleteTimer(room->xtimer.GetRunningTimer()); + return; + } + if (!grid_list_) { + grid_list_ = new std::set(); + room->grid_service->GetAllCellsByXy(room, GetPos().x, GetPos().y, *grid_list_); + } + bool has_hum = false; + room->grid_service->TouchAllLayerHumanList + (room->GetRoomIdx(), + *grid_list_, + [this, &has_hum] (Human* hum, bool& stop) + { + bool old_temp_through = temp_through_; + temp_through_ = false; + if (master->team_id == hum->team_id) { + if (TestCollision(room, hum)) { + has_hum = true; + stop = true; + } + } + temp_through_ = old_temp_through; + } + ); + if (!has_hum) { + room->xtimer.DeleteTimer(room->xtimer.GetRunningTimer()); + } } diff --git a/server/gameserver/roomobstacle.h b/server/gameserver/roomobstacle.h index 96a4df8..698899d 100644 --- a/server/gameserver/roomobstacle.h +++ b/server/gameserver/roomobstacle.h @@ -1,5 +1,6 @@ #pragma once +#include "gridservice.h" #include "obstacle.h" class RoomObstacle : public Obstacle @@ -9,14 +10,19 @@ class RoomObstacle : public Obstacle a8::XTimerAttacher xtimer_attacher; bool is_treasure_box = false; bool is_terminator_airdrop_box = false; + class Human* master = nullptr; virtual ~RoomObstacle() override; virtual void Initialize() override; virtual void RecalcSelfCollider() override; virtual bool IsTerminatorAirDropBox(Room* room) override { return is_terminator_airdrop_box; } - virtual bool CanThroughable(Human* num) override; + virtual bool CanThroughable(Human* hum) override; + void ActiveTimerFunc(); protected: + bool temp_through_ = false; + std::set* grid_list_ = nullptr; + RoomObstacle(); friend class EntityFactory;