Expand auto-hunt pursuit ranges and show server bonus effects
This commit is contained in:
@@ -3,9 +3,38 @@
|
||||
#include "group_select.h"
|
||||
#else
|
||||
#include "sectree_manager.h"
|
||||
#include "autohunt_pull_range.h"
|
||||
#include "autohunt_group_select.h"
|
||||
#endif
|
||||
|
||||
// PORT: only mobs pulled by this command receive a temporary extended pursuit leash.
|
||||
struct AutoHuntPullLease {
|
||||
LPCHARACTER mob;
|
||||
DWORD ownerPID;
|
||||
int radius;
|
||||
int expires;
|
||||
};
|
||||
static std::map<DWORD, AutoHuntPullLease> s_autoHuntPullLeases;
|
||||
int AutoHuntPullLeash(LPCHARACTER mob, LPCHARACTER victim) {
|
||||
std::map<DWORD, AutoHuntPullLease>::iterator it = s_autoHuntPullLeases.find((DWORD)mob->GetVID());
|
||||
if (it == s_autoHuntPullLeases.end()) return 4000;
|
||||
const AutoHuntPullLease& lease = it->second;
|
||||
if (lease.mob != mob || !victim || !victim->IsPC() || victim->IsDead() ||
|
||||
victim->GetPlayerID() != lease.ownerPID || mob->GetMapIndex() != victim->GetMapIndex() ||
|
||||
get_global_time() >= lease.expires) {
|
||||
s_autoHuntPullLeases.erase(it);
|
||||
return 4000;
|
||||
}
|
||||
return std::max(4000, lease.radius + 1);
|
||||
}
|
||||
static void AutoHuntPullPrune(DWORD cancelPID = 0) {
|
||||
for (std::map<DWORD, AutoHuntPullLease>::iterator it = s_autoHuntPullLeases.begin(); it != s_autoHuntPullLeases.end();) {
|
||||
if (it->second.expires <= get_global_time() || (cancelPID && it->second.ownerPID == cancelPID))
|
||||
s_autoHuntPullLeases.erase(it++);
|
||||
else ++it;
|
||||
}
|
||||
}
|
||||
|
||||
struct AutoHuntPullCollector {
|
||||
LPCHARACTER owner;
|
||||
int radius;
|
||||
@@ -35,8 +64,11 @@ ACMD(do_autohunt_pull) {
|
||||
unsigned int request = 0;
|
||||
char extra = 0;
|
||||
if (sscanf(argument, "%d %d %d %u %c", &groups, &radius, &bosses, &request, &extra) != 4 ||
|
||||
(groups != 3 && groups != 10 && groups != 20) || radius < 500 || radius > 5000 ||
|
||||
(groups != 0 && groups != 3 && groups != 10 && groups != 20) || radius < 500 || radius > 15000 ||
|
||||
(bosses != 0 && bosses != 1)) return;
|
||||
if (!ch->IsPC()) return;
|
||||
AutoHuntPullPrune(groups == 0 ? ch->GetPlayerID() : 0);
|
||||
if (groups == 0) return;
|
||||
const int now = get_global_time();
|
||||
if (!ch->IsPC() || ch->IsDead() || ch->IsStun() || !ch->CanHandleItem() || !ch->GetSectree() ||
|
||||
(ch->GetSectree()->GetAttribute(ch->GetX(), ch->GetY()) & ATTR_BANPK) ||
|
||||
@@ -47,13 +79,23 @@ ACMD(do_autohunt_pull) {
|
||||
// Server-side cooldown survives reconnects and switching auto hunt on/off.
|
||||
ch->SetQuestFlag("autohunt.next_pull", now + 10);
|
||||
AutoHuntPullCollector collector(ch, radius, bosses != 0);
|
||||
ch->GetSectree()->ForEachAround(collector);
|
||||
// ForEachAround only covers nine cells: visit every cell intersecting the requested radius.
|
||||
LPSECTREE_MAP map = SECTREE_MANAGER::instance().GetMap(ch->GetMapIndex());
|
||||
if (map) map->for_each_in_rect(std::max(0, int(ch->GetX()) - radius),
|
||||
std::max(0, int(ch->GetY()) - radius), ch->GetX() + radius, ch->GetY() + radius, collector);
|
||||
const mt_autohunt::Selection selected = mt_autohunt::SelectGroups(collector.candidates, groups);
|
||||
for (size_t i = 0; i < selected.mobs.size(); ++i) {
|
||||
LPCHARACTER mob = CHARACTER_MANAGER::instance().Find(selected.mobs[i]);
|
||||
if (!mob) continue;
|
||||
if (mob->IsDead() || (mob->GetVictim() && mob->GetVictim() != ch)) continue;
|
||||
AutoHuntPullLease lease = {mob, ch->GetPlayerID(), radius, now + 180};
|
||||
s_autoHuntPullLeases[(DWORD)mob->GetVID()] = lease;
|
||||
if (!mob->GetVictim()) mob->BeginFight(ch);
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND, "AutoHuntGather %u mob %u", request, selected.mobs[i]);
|
||||
}
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND, "AutoHuntGather %u done %d", request, selected.groups);
|
||||
}
|
||||
|
||||
#ifndef MT_AUTOHUNT_SERVER_TEST
|
||||
#include "server_bonuses.h"
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user