113 lines
7.3 KiB
C++
113 lines
7.3 KiB
C++
// 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);
|
|
}
|