This commit is contained in:
aozhiwei 2023-03-30 12:06:11 +08:00
parent 4c7db9a16f
commit b9c01688c3
2 changed files with 16 additions and 20 deletions

View File

@ -1701,14 +1701,6 @@ void Creature::SlaveOnRemove(Entity* slave)
switch (slave->GetEntityType()) { switch (slave->GetEntityType()) {
case ET_Hero: case ET_Hero:
{ {
#if 0
for (auto itr = slave_heros_.begin(); itr != slave_heros_.end(); ++itr) {
if ((Entity*)std::get<1>(*itr) == slave) {
slave_heros_.erase(itr);
break;
}
}
#endif
} }
break; break;
case ET_Obstacle: case ET_Obstacle:
@ -1732,21 +1724,25 @@ void Creature::SlaveOnRemove(Entity* slave)
void Creature::RemoveSurplusHero(int hero_id, int num) void Creature::RemoveSurplusHero(int hero_id, int num)
{ {
#if 0 auto itr = slave_heros_.find(hero_id);
if (slave_heros_.size() >= num && num > 0) { if (itr != slave_heros_.end()) {
std::vector<Hero*> matched_heros; int exists_num = 0;
for (auto& itr : slave_heros_) { {
if (std::get<0>(itr) == buff_id && list_head* pos = nullptr;
std::get<1>(itr)->meta->id() == id) { list_head* next = nullptr;
matched_heros.push_back(std::get<1>(itr)); list_head* head = &itr->second;
list_for_each_safe(pos, next, head) {
++exists_num;
} }
} }
while (matched_heros.size() > num) { while (exists_num > num) {
matched_heros[0]->Destory(); Hero* hero = list_first_entry(&itr->second,
matched_heros.erase(matched_heros.begin()); Hero,
entry);
list_del_init(&hero->entry);
--exists_num;
} }
} }
#endif
} }
void Creature::RemoveSurplusObstacle(int buff_id, int id, int num) void Creature::RemoveSurplusObstacle(int buff_id, int id, int num)

View File

@ -221,7 +221,7 @@ void Hero::DetachFromMaster()
} }
detached_ = true; detached_ = true;
} }
if (list_empty(&entry)) { if (!list_empty(&entry)) {
list_del_init(&entry); list_del_init(&entry);
} }
} }