Improve auto-hunt navigation, recovery and mounted skill casting
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
#ifdef NDEBUG
|
||||
#undef NDEBUG
|
||||
#endif
|
||||
#include "../../src/port/UserInterface/AutoHuntNavigation.h"
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
using namespace AutoHuntNavigation;
|
||||
int main() {
|
||||
auto free=[](Point) { return true; };
|
||||
auto direct=FindPath({0,0},{1000,0},100,free);
|
||||
assert(direct.size()==1 && direct.back().x==1000);
|
||||
// A solid wall must be bypassed through its opening, with every returned segment traversable.
|
||||
auto wall=[](Point p) { return !(p.x>=400 && p.x<=600 && p.y>-500 && p.y<500); };
|
||||
auto detour=FindPath({0,0},{1000,0},100,wall);
|
||||
assert(detour.size()>1);
|
||||
Point prev{0,0}; bool turned=false;
|
||||
for (auto p:detour) { assert(Segment(prev,p,wall)); turned |= std::abs(p.y)>=500; prev=p; }
|
||||
assert(turned && Distance(prev,{1000,0})<=100);
|
||||
auto sealed=[](Point p) { return p.x<400 || p.x>600; };
|
||||
assert(FindPath({0,0},{1000,0},100,sealed).empty());
|
||||
// A nearby target across a thin wall is not reachable merely because it is in attack range.
|
||||
auto thin=[](Point p) { return p.x<30 || p.x>70; };
|
||||
assert(FindPath({0,0},{100,0},150,thin).empty());
|
||||
// Corner cutting cannot pass between touching wall cells.
|
||||
auto diagonal=[](Point p) {
|
||||
return (p.x<50 && p.y<50) || (p.x>=50 && p.y>=50);
|
||||
};
|
||||
assert(FindPath({0,0},{200,200},0,diagonal).empty());
|
||||
assert(FindPath({0,0},{1000,0},100,wall,1).empty());
|
||||
assert(FindPath({0,0},{1000,0},100,[](Point){return false;}).empty());
|
||||
assert(FindPath({0,0},{std::numeric_limits<float>::quiet_NaN(),0},100,free).empty());
|
||||
// Start/finish and negative map-relative coordinates retain their exact positions.
|
||||
auto negative=FindPath({-23,-47},{-1023,-47},0,free);
|
||||
assert(negative.size()==1 && negative.back().x==-1023 && negative.back().y==-47);
|
||||
std::puts("autohunt navigation: direct, detour, sealed, thin wall, corners, budget, unloaded and coordinates passed");
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
// PORT: actual Python UI/bindings and player frame loop, with actor changes simulating server acknowledgments.
|
||||
if (server && CPythonPlayer::Instance().NEW_GetMainActorPtr()) {
|
||||
auto& player=CPythonPlayer::Instance();
|
||||
auto* actor=player.NEW_GetMainActorPtr();
|
||||
const auto saved=player.AutoHunt_GetConfig();
|
||||
const int savedHP=player.GetStatus(POINT_HP), savedMaxHP=player.GetStatus(POINT_MAX_HP);
|
||||
const int savedSP=player.GetStatus(POINT_SP), savedMaxSP=player.GetStatus(POINT_MAX_SP);
|
||||
TPixelPosition position; actor->NEW_GetPixelPosition(&position);
|
||||
auto config=saved; config.iGatherCount=0; config.iPickup=0; config.iHPPercent=0; config.iSPPercent=0;
|
||||
config.bAttackStone=false; config.bAttackBoss=false; config.bAutoRevive=false; config.bDismountSkill=true;
|
||||
config.vecSkillIndices.clear();
|
||||
player.AutoHunt_SetConfig(config);
|
||||
player.SetStatus(POINT_HP,1000); player.SetStatus(POINT_MAX_HP,1000);
|
||||
player.SetStatus(POINT_SP,1000); player.SetStatus(POINT_MAX_SP,1000);
|
||||
const int previousIndex=player.GetSkillIndex(9), previousLevel=player.GetSkillLevel(9), previousGrade=player.GetSkillGrade(9);
|
||||
player.SetSkill(9,19); player.SetSkillLevel_(19,0,1);
|
||||
CHECK(py("import player, mt_autohunt\n"
|
||||
"player.AutoHuntSetSkills([19,19,0,9999])\n"
|
||||
"assert player.AutoHuntGetSkills()[0] == (19,)\n"
|
||||
"assert 19 in player.AutoHuntGetSkills()[1]\n"
|
||||
"mt_autohunt.g_dialog.Open()\n"
|
||||
"assert 19 in mt_autohunt.g_dialog.skillIDs\n"
|
||||
"assert mt_autohunt.g_dialog.selectedSkills == set([19])\n"
|
||||
"assert mt_autohunt.g_dialog.GetHeight() <= 565\n"
|
||||
"player.AutoHuntSetConfig(3500,0,0,0,0,0,0,0,0,1)\n"
|
||||
"assert player.AutoHuntGetSkills()[0] == (19,)\n"
|
||||
"mt_autohunt.g_dialog.Close()"));
|
||||
// Saving unrelated settings/toggling a shortcut cannot change selected skill IDs.
|
||||
DWORD shortcutType=0,shortcutPosition=0;
|
||||
const DWORD globalShortcut=player.LocalQuickSlotIndexToGlobalQuickSlotIndex(0);
|
||||
player.GetGlobalQuickSlotData(globalShortcut,&shortcutType,&shortcutPosition);
|
||||
player.AddQuickSlot(globalShortcut,SLOT_TYPE_SKILL,9);
|
||||
player.DeleteQuickSlot(globalShortcut);
|
||||
CHECK(player.AutoHunt_GetConfig().vecSkillIndices==std::vector<DWORD>{19});
|
||||
player.AddQuickSlot(globalShortcut,char(shortcutType),WORD(shortcutPosition));
|
||||
CHECK(player.AutoHunt_GetConfig().vecSkillIndices==std::vector<DWORD>{19});
|
||||
// Recreate just the main actor, as the real server's mount status insert does. No game phase reset.
|
||||
auto acknowledgeMount=[&](DWORD mount) {
|
||||
auto* old=player.NEW_GetMainActorPtr(); TPixelPosition here; old->NEW_GetPixelPosition(&here);
|
||||
CInstanceBase::SCreateData data={};
|
||||
data.m_bType=6; data.m_dwRace=0; data.m_dwVID=FakeLoginServer::kMainVID;
|
||||
data.m_dwMovSpd=100; data.m_dwAtkSpd=100; data.m_dwWeapon=19;
|
||||
data.m_lPosX=LONG(here.x); data.m_lPosY=LONG(here.y); data.m_stName=FakeLoginServer::kCharacterName;
|
||||
data.m_isMain=true; data.m_dwMountVnum=mount;
|
||||
CPythonCharacterManager::Instance().DeleteInstance(data.m_dwVID);
|
||||
auto* fresh=CPythonCharacterManager::Instance().CreateInstance(data);
|
||||
player.SetMainCharacterIndex(data.m_dwVID);
|
||||
return fresh;
|
||||
};
|
||||
auto rideCount=[&] {
|
||||
int count=0; for (const auto& event:server->Events()) if (event=="game2:chat 0 /ride") ++count;
|
||||
return count;
|
||||
};
|
||||
TPixelPosition combatPosition;
|
||||
CPythonCharacterManager::Instance().GetInstancePtr(FakeLoginServer::kMobVID)->NEW_GetPixelPosition(&combatPosition);
|
||||
combatPosition.x+=1000;
|
||||
actor->NEW_Stop(); actor->NEW_SetPixelPosition(combatPosition);
|
||||
actor=acknowledgeMount(20103);
|
||||
CHECK(actor && actor->IsMountingHorse() && !actor->IsInSafe());
|
||||
config=player.AutoHunt_GetConfig(); config.bDismountSkill=false; player.AutoHunt_SetConfig(config);
|
||||
const int disabledRideCount=rideCount();
|
||||
player.AutoHunt_SetEnabled(true); pump_frames(12);
|
||||
CHECK(player.AutoHunt_GetMountState()==0 && rideCount()==disabledRideCount && actor->IsMountingHorse());
|
||||
player.AutoHunt_SetEnabled(false);
|
||||
config.bDismountSkill=true; player.AutoHunt_SetConfig(config);
|
||||
player.AutoHunt_SetEnabled(true);
|
||||
CHECK(pump_until(3,[&] { return player.AutoHunt_GetMountState()==1 && rideCount()==disabledRideCount+1; }));
|
||||
player.SetAttackKeyState(true); player.SetAttackKeyState(false);
|
||||
CHECK(player.AutoHunt_GetState()==CPythonPlayer::AUTO_HUNT_PAUSED && player.AutoHunt_GetMountState()==0);
|
||||
player.AutoHunt_SetEnabled(false); pump_frames(12);
|
||||
CHECK(rideCount()==disabledRideCount+1); // canceled cycle cannot send its eventual remount
|
||||
const int beforeRide=rideCount();
|
||||
player.AutoHunt_SetEnabled(true);
|
||||
CHECK(pump_until(3,[&] { return rideCount()==beforeRide+1 && player.AutoHunt_GetMountState()==1; }));
|
||||
CHECK(!player.IsSkillCoolTime(9)); // no cast before the dismount acknowledgment
|
||||
actor=acknowledgeMount(0);
|
||||
CHECK(actor && !actor->IsMountingHorse());
|
||||
CHECK(pump_until(4,[&] { return player.IsSkillCoolTime(9); }));
|
||||
CHECK(pump_until(5,[&] { return rideCount()==beforeRide+2 && player.AutoHunt_GetMountState()==3; }));
|
||||
actor=acknowledgeMount(20103);
|
||||
CHECK(pump_until(2,[&] { return player.AutoHunt_GetMountState()==0; }));
|
||||
CHECK(actor && actor->IsMountingHorse());
|
||||
player.AutoHunt_SetEnabled(false);
|
||||
actor=acknowledgeMount(0);
|
||||
player.AutoHunt_SetSkills({});
|
||||
// Default remains stop-on-death. Opt-in waits for a real alive actor and recovery HP.
|
||||
player.AutoHunt_SetEnabled(true); actor->Die(); player.NotifyDeadMainCharacter();
|
||||
CHECK(!player.AutoHunt_IsEnabled() && player.AutoHunt_GetStopReason()==CPythonPlayer::AUTO_HUNT_STOP_DEAD);
|
||||
actor->Revive(); actor->NEW_Stop();
|
||||
config=player.AutoHunt_GetConfig(); config.bAutoRevive=true; player.AutoHunt_SetConfig(config);
|
||||
player.AutoHunt_SetEnabled(true); actor->Die(); player.SetStatus(POINT_HP,0); player.NotifyDeadMainCharacter();
|
||||
CHECK(player.AutoHunt_IsEnabled() && player.AutoHunt_GetState()==CPythonPlayer::AUTO_HUNT_REVIVE);
|
||||
CHECK(pump_until(12,[&] { return server->Has("game2:chat 0 /restart_here"); }));
|
||||
CHECK(player.AutoHunt_GetState()==CPythonPlayer::AUTO_HUNT_REVIVE); // command alone cannot revive locally
|
||||
actor->Revive(); player.SetStatus(POINT_HP,100);
|
||||
CHECK(pump_until(2,[&] { return player.AutoHunt_GetState()==CPythonPlayer::AUTO_HUNT_RECOVER; }));
|
||||
pump_frames(330); // > 5 seconds even at custom 60 Hz; low HP must still prevent combat
|
||||
CHECK(player.AutoHunt_GetState()==CPythonPlayer::AUTO_HUNT_RECOVER);
|
||||
player.SetStatus(POINT_HP,700);
|
||||
CHECK(pump_until(7,[&] { return player.AutoHunt_GetState()!=CPythonPlayer::AUTO_HUNT_RECOVER; }));
|
||||
CHECK(player.AutoHunt_IsEnabled());
|
||||
player.AutoHunt_SetEnabled(false);
|
||||
// A stopped recovery cannot emit later revival or riding commands.
|
||||
CHECK(player.AutoHunt_GetMountState()==0);
|
||||
player.SetSkillLevel_(19,0,0); player.SetSkill(9,previousIndex);
|
||||
if (previousIndex) player.SetSkillLevel_(previousIndex,previousGrade,previousLevel);
|
||||
player.AutoHunt_SetConfig(saved);
|
||||
player.SetStatus(POINT_HP,savedHP); player.SetStatus(POINT_MAX_HP,savedMaxHP);
|
||||
player.SetStatus(POINT_SP,savedSP); player.SetStatus(POINT_MAX_SP,savedMaxSP);
|
||||
actor->NEW_Stop(); actor->NEW_SetPixelPosition(position);
|
||||
pump_frames(30);
|
||||
}
|
||||
@@ -393,9 +393,10 @@ int main(int argc, char** argv)
|
||||
});
|
||||
CHECK(loading && !failed());
|
||||
CHECK(py_true(loaded));
|
||||
// The map is available during loading. A fast server may have already switched the
|
||||
// network phase to Game before the loading window closes on the next script frame.
|
||||
CHECK(!PythonBoot::CurrentMapName().empty());
|
||||
// CG_CLIENT_VERSION is sent before introLoading's background-load steps. Wait for those
|
||||
// script frames rather than racing the server thread's receipt of the version packet.
|
||||
CHECK(pump_until(live ? 10 : 5, [&] { return failed() || !PythonBoot::CurrentMapName().empty(); }) &&
|
||||
!PythonBoot::CurrentMapName().empty());
|
||||
|
||||
// 6. introLoading's update steps end in net.StartGame(); the next CPythonNetworkStream::Process calls
|
||||
// networkModule's SetGamePhase, which builds game.GameWindow (interfaceModule.MakeInterface) and
|
||||
@@ -745,6 +746,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
}
|
||||
#include "autohunt_pull_checks.inc"
|
||||
#include "autohunt_recovery_checks.inc"
|
||||
// 9. (批次 4-b) Combat: a left click on the stray dog reaches CPythonPlayer::__OnClickActor, which targets it
|
||||
// (CG_TARGET → GC_TARGET, uitarget shows the HP board) and walks into range to attack. Each attack frame's
|
||||
// hit (CPythonPlayerEventHandler::OnHit) sends CG_ATTACK; the fake server answers GC_DAMAGE_INFO + GC_TARGET,
|
||||
|
||||
Reference in New Issue
Block a user