| 469 | } |
| 470 | |
| 471 | void EntityList::MobProcess() |
| 472 | { |
| 473 | bool mob_dead; |
| 474 | |
| 475 | auto it = mob_list.begin(); |
| 476 | while (it != mob_list.end()) { |
| 477 | uint16 id = it->first; |
| 478 | Mob *mob = it->second; |
| 479 | |
| 480 | size_t sz = mob_list.size(); |
| 481 | |
| 482 | static int old_client_count = 0; |
| 483 | static Timer *mob_settle_timer = new Timer(); |
| 484 | |
| 485 | if (zone->IsIdleWhenEmpty()) { |
| 486 | if ( |
| 487 | numclients == 0 && |
| 488 | old_client_count > 0 && |
| 489 | zone->GetSecondsBeforeIdle() > 0 |
| 490 | ) { |
| 491 | LogInfo( |
| 492 | "Zone will go into an idle state after [{}] second{}.", |
| 493 | zone->GetSecondsBeforeIdle(), |
| 494 | zone->GetSecondsBeforeIdle() != 1 ? "s" : "" |
| 495 | ); |
| 496 | mob_settle_timer->Start(zone->GetSecondsBeforeIdle() * 1000); |
| 497 | } |
| 498 | |
| 499 | if (numclients == 0 && mob_settle_timer->Check()) { |
| 500 | LogInfo( |
| 501 | "Zone has gone idle after [{}] second{}.", |
| 502 | zone->GetSecondsBeforeIdle(), |
| 503 | zone->GetSecondsBeforeIdle() != 1 ? "s" : "" |
| 504 | ); |
| 505 | |
| 506 | CheckToClearTraderAndBuyerTables(); |
| 507 | |
| 508 | mob_settle_timer->Disable(); |
| 509 | } |
| 510 | |
| 511 | // Disable settle timer if someone zones into empty zone |
| 512 | if (numclients > 0 || mob_settle_timer->Check()) { |
| 513 | if (mob_settle_timer->Enabled()) { |
| 514 | LogInfo("Zone is no longer scheduled to go idle."); |
| 515 | mob_settle_timer->Disable(); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | old_client_count = numclients; |
| 520 | |
| 521 | Spawn2* s2 = mob->CastToNPC()->respawn2; |
| 522 | |
| 523 | // Perform normal mob processing if any of these are true: |
| 524 | // -- zone is not empty |
| 525 | // -- the entity's spawn2 point is marked as path_while_zone_idle |
| 526 | // -- the zone is newly empty and we're allowing mobs to settle |
| 527 | if ( |
| 528 | numclients > 0 || zone->quest_idle_override || |