From 5d3889cb15ae363778416da5be0f19197b2d8879 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 31 Jul 2024 11:24:57 +0800 Subject: [PATCH] 1 --- server/gameserver/boxdrop.cc | 31 ++++++++++++++++++++++++++++++- server/gameserver/boxdrop.h | 2 ++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/server/gameserver/boxdrop.cc b/server/gameserver/boxdrop.cc index 2feb809a..791afc99 100644 --- a/server/gameserver/boxdrop.cc +++ b/server/gameserver/boxdrop.cc @@ -8,12 +8,14 @@ #include "boxdrop.h" #include "room.h" #include "hero.h" -#include "obstacle.h" +#include "roomobstacle.h" #include "httpproxy.h" #include "jsondatamgr.h" #include "player.h" #include "mt/MapMode.h" +#include "mt/Hero.h" +#include "mt/MapThing.h" const int BOX_ID = 150001; @@ -209,6 +211,7 @@ void BoxDrop::OnAllocOk(int box_num) } alloced_ = true; alloc_box_num_ = box_num; + AllocBoxToRoom(); } void BoxDrop::OnAllocFail() @@ -217,3 +220,29 @@ void BoxDrop::OnAllocFail() room_->xtimer.Delete(get_box_num_timer_); } } + +void BoxDrop::AllocBoxToRoom() +{ + if (alloc_box_num_ <= 0) { + return; + } + std::vector hero_list; + std::vector box_list; + room_->TraverseEntityList + ( + [this, &hero_list, &box_list] (Entity* e) -> bool + { + if (e->IsCreature(room_) && ((Creature*)e)->IsHero()) { + Hero* hero = (Hero*)e; + if (hero->meta->HasDrop()) { + hero_list.push_back(hero); + } + } else if (e->IsRoomObstacle()) { + RoomObstacle* ob = (RoomObstacle*)e; + if (ob->meta->HasDrop()) { + box_list.push_back(ob); + } + } + return true; + }); +} diff --git a/server/gameserver/boxdrop.h b/server/gameserver/boxdrop.h index 8bb2e2bf..91707367 100644 --- a/server/gameserver/boxdrop.h +++ b/server/gameserver/boxdrop.h @@ -24,6 +24,7 @@ class BoxDrop : public std::enable_shared_from_this bool FillAccountIdSessionId(std::string account_id, std::string session_id); void OnAllocOk(int box_num); void OnAllocFail(); + void AllocBoxToRoom(); private: Room* room_ = nullptr; @@ -32,4 +33,5 @@ class BoxDrop : public std::enable_shared_from_this int alloc_box_num_ = 0; bool alloced_ = false; bool returned_ = false; + std::map drop_hash_; };