Add batch pickup command mt_pickup (AVA2 do_pickup_all)
/mt_pickup 1 MASK picks up every own or ownerless ground item within the original pickup distance whose category matches the 8-bit mask, nearest first, capped at 48. Each item goes through the original PickupItem, so distance, stacking, inventory space, ItemLog GET and quest triggers are unchanged; only the first failure INFO line is resent. 500 ms throttle, MTPU1 done/error replies, MTF1 cap mask 127 -> 255. Live tested on the channel-5 test core (isolated binary) with the macOS native client. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
a1c6917e1f
commit
3b7e158ba6
@@ -521,6 +521,7 @@ class CHARACTER : public CEntity, public CFSM, public CHorseRider
|
||||
DWORD m_portSwitchbotLastCommand = 0; // PORT: switchbot command throttle.
|
||||
bool m_portQuietInfo = false; // PORT: switchbot rolls hold back per-roll INFO lines...
|
||||
std::string m_portLastInfo; // ...keeping the last one to report a rejected roll.
|
||||
DWORD m_portPickupLastCommand = 0; // PORT: batch pickup throttle.
|
||||
|
||||
LPCHARACTER FindCharacterInView(const char * name, bool bFindPCOnly);
|
||||
void UpdatePacket();
|
||||
|
||||
@@ -11,6 +11,7 @@ ACMD(do_server_bonuses);
|
||||
ACMD(do_port_biolog);
|
||||
ACMD(do_port_features);
|
||||
ACMD(do_port_switchbot);
|
||||
ACMD(do_port_pickup);
|
||||
ACMD(do_user_horse_ride);
|
||||
ACMD(do_user_horse_back);
|
||||
ACMD(do_user_horse_feed);
|
||||
@@ -287,6 +288,7 @@ struct command_info cmd_info[] =
|
||||
{ "autohunt_pull", do_autohunt_pull, 0, POS_STANDING, GM_PLAYER },
|
||||
{ "mt_features", do_port_features, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "mt_switchbot", do_port_switchbot, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "mt_pickup", do_port_pickup, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "bio", do_port_biolog, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "biolog", do_port_biolog, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "server_bonuses", do_server_bonuses, 0, POS_DEAD, GM_PLAYER },
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include "port_calendar_runtime.h"
|
||||
#include "port_features.h"
|
||||
#include "port_switchbot.h"
|
||||
#include "port_pickup.h"
|
||||
|
||||
extern int g_server_id;
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ ACMD(do_port_features) {
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTF1 error %u rate",request);return;
|
||||
}
|
||||
ch->m_portFeatureLastQuery=get_dword_time();
|
||||
if(kind=="cap" && args.size()==3) {ch->ChatPacket(CHAT_TYPE_COMMAND,"MTF1 cap %u 1 127 %lld",request,(long long)get_global_time());return;}
|
||||
if(kind=="cap" && args.size()==3) {ch->ChatPacket(CHAT_TYPE_COMMAND,"MTF1 cap %u 1 255 %lld",request,(long long)get_global_time());return;}
|
||||
if(kind=="dungeons" && args.size()==3) {PortDungeonQuery(ch,request);return;}
|
||||
if(kind=="stats" && args.size()==3) {
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTF1 begin %u stats 0 0 %u 0 %lld",request,unsigned(sizeof(kPortStats)/sizeof(kPortStats[0])),(long long)get_global_time());
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
#ifndef METIN2_PORT_PICKUP_H
|
||||
#define METIN2_PORT_PICKUP_H
|
||||
// PORT: AVA2-style batch pickup (do_pickup_all). One command picks up every ground item this character
|
||||
// owns within the original pickup distance, filtered by category. Each item goes through the original
|
||||
// CHARACTER::PickupItem, so distance, stacking, inventory space, ItemLog GET and quest triggers are unchanged.
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
static const unsigned kPortPickupMaxItems=48;
|
||||
static const DWORD kPortPickupGapMs=500;
|
||||
enum EPortPickupCategory {
|
||||
PORT_PICKUP_YANG=1,PORT_PICKUP_WEAPON=2,PORT_PICKUP_ARMOR=4,PORT_PICKUP_BOOK=8,
|
||||
PORT_PICKUP_STONE=16,PORT_PICKUP_MATERIAL=32,PORT_PICKUP_COSTUME=64,PORT_PICKUP_OTHER=128,PORT_PICKUP_ALL=255
|
||||
};
|
||||
|
||||
static unsigned PortPickupCategory(LPITEM item) {
|
||||
switch(item->GetType()) {
|
||||
case ITEM_ELK:return PORT_PICKUP_YANG;
|
||||
case ITEM_WEAPON:return PORT_PICKUP_WEAPON;
|
||||
case ITEM_ARMOR:return PORT_PICKUP_ARMOR;
|
||||
case ITEM_SKILLBOOK:return PORT_PICKUP_BOOK;
|
||||
case ITEM_METIN:return PORT_PICKUP_STONE;
|
||||
case ITEM_MATERIAL:return PORT_PICKUP_MATERIAL;
|
||||
case ITEM_COSTUME:return PORT_PICKUP_COSTUME;
|
||||
default:return PORT_PICKUP_OTHER;
|
||||
}
|
||||
}
|
||||
|
||||
// Own (or ownerless) items only, like AVA2: PickupItem's party branch would hand someone else's loot to us.
|
||||
struct FPortPickupCollect {
|
||||
LPCHARACTER ch;unsigned mask;std::vector<std::pair<int,DWORD> > found;
|
||||
FPortPickupCollect(LPCHARACTER c,unsigned m):ch(c),mask(m){}
|
||||
void operator()(LPENTITY ent) {
|
||||
if(!ent->IsType(ENTITY_ITEM))return;
|
||||
LPITEM item=(LPITEM)ent;
|
||||
if(!item->GetSectree() || !item->DistanceValid(ch) || !item->IsOwnership(ch) || !(PortPickupCategory(item)&mask))return;
|
||||
found.push_back(std::make_pair(DISTANCE_APPROX(item->GetX()-ch->GetX(),item->GetY()-ch->GetY()),item->GetVID()));
|
||||
}
|
||||
};
|
||||
|
||||
ACMD(do_port_pickup) {
|
||||
if(!ch || !ch->IsPC() || !ch->GetDesc())return;
|
||||
std::istringstream input(argument);std::vector<std::string> args;std::string token;
|
||||
while(input>>token){if(token.size()>10 || args.size()>=3)return;args.push_back(token);}
|
||||
if(args.empty() || args[0]!="1")return;
|
||||
if(ch->m_portPickupLastCommand && get_dword_time()-ch->m_portPickupLastCommand<kPortPickupGapMs) {
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTPU1 error rate");return;
|
||||
}
|
||||
ch->m_portPickupLastCommand=get_dword_time();
|
||||
unsigned mask=0;
|
||||
if(args.size()!=2 || args[1].empty() || args[1].size()>3 || args[1].find_first_not_of("0123456789")!=std::string::npos ||
|
||||
(mask=unsigned(atoi(args[1].c_str())))<1 || mask>PORT_PICKUP_ALL) {
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTPU1 error invalid");return;
|
||||
}
|
||||
if(ch->IsDead() || ch->IsStun() || ch->IsObserverMode() || ch->IsWarping() || !ch->GetSectree()) {
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTPU1 error busy");return;
|
||||
}
|
||||
FPortPickupCollect collect(ch,mask);
|
||||
ch->GetSectree()->ForEachAround(collect);
|
||||
std::sort(collect.found.begin(),collect.found.end());
|
||||
if(collect.found.size()>kPortPickupMaxItems)collect.found.resize(kPortPickupMaxItems);
|
||||
// Successful pickups keep their own INFO line; a failure (usually a full inventory) is reported once.
|
||||
unsigned picked=0,failed=0;std::string failure;
|
||||
for(const auto& entry:collect.found) {
|
||||
ch->m_portQuietInfo=true;ch->m_portLastInfo.clear();
|
||||
const bool ok=ch->PickupItem(entry.second);
|
||||
ch->m_portQuietInfo=false;
|
||||
if(ok) {++picked;if(!ch->m_portLastInfo.empty())ch->ChatPacket(CHAT_TYPE_INFO,"%s",ch->m_portLastInfo.c_str());}
|
||||
else {++failed;if(failure.empty())failure=ch->m_portLastInfo;}
|
||||
}
|
||||
if(!failure.empty())ch->ChatPacket(CHAT_TYPE_INFO,"%s",failure.c_str());
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTPU1 done %u %u %u",unsigned(collect.found.size()),picked,failed);
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user