From f4098cb2dba03bf9a7cea96bb5988ec02118d09f Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 10 Jun 2020 16:38:22 +0800 Subject: [PATCH] add AdjustPosInnnerMap function --- server/gameserver/room.cc | 32 ++++++++++++++++++++++++++++++++ server/gameserver/room.h | 1 + 2 files changed, 33 insertions(+) diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 8c8aed8..5b51820 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -569,6 +569,38 @@ bool Room::OverBorder(const a8::Vec2 pos, float radius) return false; } +void Room::AdjustPosInnerMap(a8::Vec2& pos, float radius) +{ + //检查x轴 + { + int left_x = pos.x - radius; + if (left_x < 0.001f) { + pos.x = radius + 10; + } + int right_x = pos.x + radius; + if (right_x > map_meta_->i->map_width()) { + pos.x = map_meta_->i->map_width() - radius - 10; + } + } + //检查y轴 + { + int up_y = pos.y + radius; + if (up_y > map_meta_->i->map_height()) { + pos.y = map_meta_->i->map_height() - radius - 10; + } + int down_y = pos.y - radius; + if (down_y < 0.001f) { + pos.y = radius + 10; + } + } + if (OverBorder(pos, radius)) { + pos = a8::Vec2(1800, 1800); +#ifdef DEBUG + abort(); +#endif + } +} + Human* Room::GetWatchWarTarget(Human* hum) { if (hum->team_members) { diff --git a/server/gameserver/room.h b/server/gameserver/room.h index 6b7d59c..65de0e9 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -120,6 +120,7 @@ public: Player* GetOneAlivePlayer(); void GetAlivePlayers(std::vector& humans, size_t num); int GetCanShuaNum(int shua_num); + void AdjustPosInnerMap(a8::Vec2& pos, float radius); private: int AllocUniid();