diff --git a/server/gameserver/mapinstance.cc b/server/gameserver/mapinstance.cc index 1b21375..929227c 100644 --- a/server/gameserver/mapinstance.cc +++ b/server/gameserver/mapinstance.cc @@ -70,6 +70,7 @@ void MapInstance::AttachRoom(Room* room, RoomInitInfo& init_info) init_info.map_meta = map_meta_; init_info.grid_service = grid_service_; init_info.map_service = map_service_; + init_info.map_instance = this; init_info.mini_room_spawn_points = &mini_room_spawn_points_; init_info.normal_room_spawn_points = &normal_room_spawn_points_; init_info.room_monster_spawn_points = &room_monster_spawn_points_; diff --git a/server/gameserver/mapinstance.h b/server/gameserver/mapinstance.h index 2891ff3..2225e9d 100644 --- a/server/gameserver/mapinstance.h +++ b/server/gameserver/mapinstance.h @@ -23,7 +23,7 @@ class MapInstance void AttachRoom(Room* room, RoomInitInfo& init_info); MetaData::Map* GetMapMeta() { return map_meta_; } - + Entity* GetEntityByUniId(int uniid); private: void CreateThings(); void CreateTerrain(); @@ -34,7 +34,6 @@ class MapInstance bool no_grid_service = false, int collider_param1 = 0, int collider_param2 = 0); - Entity* GetEntityByUniId(int uniid); int AllocUniid(); private: diff --git a/server/gameserver/obstacle.cc b/server/gameserver/obstacle.cc index 0a1511c..bb9cbb5 100644 --- a/server/gameserver/obstacle.cc +++ b/server/gameserver/obstacle.cc @@ -615,6 +615,17 @@ bool Obstacle::DoInteraction(Human* sender) }); return true; } + switch (meta->i->thing_type()) { + case kObstacleHideHouse: + { + DoHideHouseInteraction(sender); + } + break; + default: + { + } + break; + } return false; } @@ -622,3 +633,57 @@ void Obstacle::OnCollisionTrigger(Creature* c) { } + +void Obstacle::DoHideHouseInteraction(Human* sender) +{ + auto p = GetInteractionData(sender); + if (p) { + sender->SetPos(std::get<1>(*p)); + ClearObstacleBuff(sender); + } else { + sender->SetPos(GetPos()); + AddObstacleBuff(sender); + ObstacleData* p = sender->room->GetPermanentObstacleData(GetUniId()); + if (!a8::HasBitFlag(p->flags, kHealth)) { + p->health = health_; + a8::SetBitFlag(p->flags, kHealth); + } + if (!p->interaction_humans) { + p->interaction_humans = new std::map>(); + } + (*p->interaction_humans)[sender->GetUniId()] = std::make_tuple + (sender->room->GetFrameNo(), sender->GetPos()); + } +} + +std::tuple* Obstacle::GetInteractionData(Human* sender) +{ + if (IsPermanent()) { + ObstacleData* p = sender->room->GetPermanentObstacleData(GetUniId()); + if (!a8::HasBitFlag(p->flags, kHealth)) { + p->health = health_; + a8::SetBitFlag(p->flags, kHealth); + } + if (!p->interaction_humans) { + return nullptr; + } + auto itr = p->interaction_humans->find(sender->GetUniId()); + return itr != p->interaction_humans->end() ? &itr->second : nullptr; + } else { + return nullptr; + } +} + +void Obstacle::AddObstacleBuff(Creature* c) +{ + for (int buff_id : meta->buff_list) { + c->TryAddBuff(c, buff_id); + } +} + +void Obstacle::ClearObstacleBuff(Creature* c) +{ + for (int buff_id : meta->buff_list) { + c->RemoveBuffById(buff_id); + } +} diff --git a/server/gameserver/obstacle.h b/server/gameserver/obstacle.h index 493fa87..0baf34b 100644 --- a/server/gameserver/obstacle.h +++ b/server/gameserver/obstacle.h @@ -69,6 +69,10 @@ class Obstacle : public Entity protected: Obstacle(); + void DoHideHouseInteraction(Human* sender); + std::tuple* GetInteractionData(Human* sender); + void AddObstacleBuff(Creature* c); + void ClearObstacleBuff(Creature* c); protected: CircleCollider* self_collider_ = nullptr; diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 4f1d481..385b779 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -62,6 +62,7 @@ void Room::InitData(RoomInitInfo& init_info) map_tpl_name_ = init_info.map_tpl_name; grid_service = init_info.grid_service; map_service = init_info.map_service; + map_instance = init_info.map_instance; map_meta_ = init_info.map_meta; mini_room_spawn_points_ = init_info.mini_room_spawn_points; normal_room_spawn_points_ = init_info.normal_room_spawn_points; @@ -203,6 +204,9 @@ Player* Room::GetPlayerByUniId(int uniid) Entity* Room::GetEntityByUniId(int uniid) { + if (uniid < FIXED_OBJECT_MAXID) { + return map_instance->GetEntityByUniId(uniid); + } auto itr = uniid_hash_.find(uniid); return itr != uniid_hash_.end() ? itr->second : nullptr; } diff --git a/server/gameserver/room.h b/server/gameserver/room.h index 37106e5..071ba0f 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -48,6 +48,7 @@ public: a8::TimerAttacher timer_attacher; GridService* grid_service = nullptr; MapService* map_service = nullptr; + MapInstance* map_instance = nullptr; bool debug_trace = false; bool added_to_over_room = false; a8::Vec2 last_player_jump_pos; diff --git a/server/gameserver/roomobstacle.cc b/server/gameserver/roomobstacle.cc index bac37d6..c95a01e 100644 --- a/server/gameserver/roomobstacle.cc +++ b/server/gameserver/roomobstacle.cc @@ -511,50 +511,6 @@ bool RoomObstacle::DoInteraction(Human* sender) if (Obstacle::DoInteraction(sender)) { return true; } - switch (meta->i->thing_type()) { - case kObstacleHideHouse: - { - DoHideHouseInteraction(sender); - } - break; - default: - { - } - break; - } return true; } -void RoomObstacle::DoHideHouseInteraction(Human* sender) -{ - auto p = GetInteractionData(sender); - if (p) { - sender->SetPos(std::get<1>(*p)); - ClearObstacleBuff(sender); - } else { - sender->SetPos(GetPos()); - AddObstacleBuff(sender); - interaction_humans_[sender->GetUniId()] = std::make_tuple - (room->GetFrameNo(), sender->GetPos()); - } -} - -std::tuple* RoomObstacle::GetInteractionData(Human* sender) -{ - auto itr = interaction_humans_.find(sender->GetUniId()); - return itr != interaction_humans_.end() ? &itr->second : nullptr; -} - -void RoomObstacle::AddObstacleBuff(Creature* c) -{ - for (int buff_id : meta->buff_list) { - c->TryAddBuff(c, buff_id); - } -} - -void RoomObstacle::ClearObstacleBuff(Creature* c) -{ - for (int buff_id : meta->buff_list) { - c->RemoveBuffById(buff_id); - } -} diff --git a/server/gameserver/roomobstacle.h b/server/gameserver/roomobstacle.h index f51f213..e4ca658 100644 --- a/server/gameserver/roomobstacle.h +++ b/server/gameserver/roomobstacle.h @@ -36,18 +36,11 @@ private: void ActiveHideHouse(); void ActiveGully(); - void DoHideHouseInteraction(Human* sender); - - std::tuple* GetInteractionData(Human* sender); - void AddObstacleBuff(Creature* c); - void ClearObstacleBuff(Creature* c); - protected: bool temp_through_ = false; std::set* grid_list_ = nullptr; int explosion_times_ = 0; bool detached_ = false; - std::map> interaction_humans_; RoomObstacle(); diff --git a/server/gameserver/types.h b/server/gameserver/types.h index 0afb07f..8f5f7b8 100755 --- a/server/gameserver/types.h +++ b/server/gameserver/types.h @@ -151,6 +151,7 @@ struct ObstacleData int door_open_times = 0; DoorState_e door_state = DoorStateClose; + std::map>* interaction_humans = nullptr; }; struct KillInfo @@ -178,6 +179,7 @@ struct ObjectSyncFlags class GridService; class MapService; +class MapInstance; class Building; struct RoomInitInfo { @@ -196,6 +198,7 @@ struct RoomInitInfo std::string map_tpl_name; GridService* grid_service = nullptr; MapService* map_service = nullptr; + MapInstance* map_instance = nullptr; const std::vector* mini_room_spawn_points = nullptr; const std::vector* normal_room_spawn_points = nullptr; const std::vector* room_monster_spawn_points = nullptr;