This commit is contained in:
aozhiwei 2024-07-31 11:34:41 +08:00
parent 5d3889cb15
commit 6525b795f5

View File

@ -1,5 +1,7 @@
#include "precompile.h"
#include <random>
#include <a8/mutable_xobject.h>
#include <f8/app.h>
@ -226,23 +228,45 @@ void BoxDrop::AllocBoxToRoom()
if (alloc_box_num_ <= 0) {
return;
}
std::vector<Entity*> all_list;
std::vector<Creature*> hero_list;
std::vector<Obstacle*> box_list;
room_->TraverseEntityList
(
[this, &hero_list, &box_list] (Entity* e) -> bool
[this, &all_list, &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);
all_list.push_back(e);
}
} else if (e->IsRoomObstacle()) {
RoomObstacle* ob = (RoomObstacle*)e;
if (ob->meta->HasDrop()) {
box_list.push_back(ob);
all_list.push_back(e);
}
}
return true;
});
std::shuffle(all_list.begin(),
all_list.end(),
std::default_random_engine(a8::XGetTickCount()));
std::shuffle(hero_list.begin(),
hero_list.end(),
std::default_random_engine(a8::XGetTickCount()));
std::shuffle(box_list.begin(),
box_list.end(),
std::default_random_engine(a8::XGetTickCount()));
#ifdef MYDEBUG
f8::UdpLog::Instance()->Info
("AllocBoxToRoom room_uuid:%s all:%d hero:%d box:%d",
{
room_->GetRoomUuid(),
all_list.size(),
hero_list.size(),
box_list.size()
});
#endif
}