Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 97 additions & 3 deletions scripts/test-playerbot-gameplay.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ param(
[switch]$GoalArbitration,
[switch]$OracleDeparture,
[switch]$StaminaProjection,
[switch]$HuntRegionPlanning,
[switch]$HuntRegionPlanning,
[switch]$CombatReadiness,
[switch]$Focused,
[switch]$SkipBuild,
[switch]$KeepStack
Expand Down Expand Up @@ -495,7 +496,7 @@ function Assert-HealingResupplyEvents {
$_.reason -eq "transaction_delta_mismatch" -or $_.reason -eq "shop_transaction_delta_mismatch"
})
if ($missingSupply.Count -ne 1 -or $flaskSales.Count -ne 1 -or $purchases.Count -lt 1 -or $heals.Count -lt 1) {
throw "The bot did not refill and consume potions after the missing-supply healing outcome."
throw "The bot did not refill and consume potions after the missing-supply healing outcome: missing=$($missingSupply.Count), flaskSales=$($flaskSales.Count), purchases=$($purchases.Count), heals=$($heals.Count)."
}
if ($serviceResumed.Count -lt 1) {
throw "The bot did not resume service after healing with newly purchased potions."
Expand Down Expand Up @@ -866,6 +867,47 @@ function Assert-HuntRegionPlanningEvents {
}
}

function Assert-CombatReadinessEvents {
param([string]$Logs, [string]$Mode)

$events = @(ConvertFrom-PlayerbotLogs -Logs $Logs)
$readiness = @($events | Where-Object {
$_.event -eq "combat_readiness" -and $_.vocation_id -eq 4 -and $_.requirements.Count -eq 5
})
if ($readiness.Count -lt 1) {
throw "Combat readiness emitted no complete Knight requirement evidence for $Mode."
}
$latest = $readiness[-1]
if ($Mode -eq "missing_weapon") {
$terminal = @($events | Where-Object {
$_.event -eq "terminal" -and $_.reason -eq "combat_readiness_missing_legal_melee_weapon"
})
$hunts = @($events | Where-Object { $_.action -eq "hunt_cycle" -or $_.reason -eq "visible_monster" })
if ($terminal.Count -ne 1 -or $hunts.Count -ne 0 -or $latest.terminal_reason -ne "missing_legal_melee_weapon") {
throw "Missing weapon did not produce the terminal no-naked-hunt state."
}
return
}
$ready = @($readiness | Where-Object { $_.result -eq "ready" -and @($_.requirements | Where-Object { -not $_.ready }).Count -eq 0 })
if ($ready.Count -lt 1) {
throw "Combat readiness did not reach a fully evidenced ready state for $Mode."
}
if ($Mode -eq "upgrade") {
$equip = @($events | Where-Object { $_.event -eq "action_result" -and $_.action -eq "equip_readiness" -and $_.result -eq "success" -and $_.item_id -eq 2384 })
if ($equip.Count -ne 1) { throw "Carried legal weapon was not equipped and verified." }
}
if ($Mode -eq "supplies") {
$service = @($events | Where-Object { $_.event -eq "combat_readiness" -and $_.selected_recovery -eq "service" })
$potions = @($events | Where-Object { $_.action -eq "buy_potions" -and $_.result -eq "success" })
$food = @($events | Where-Object { $_.action -eq "buy_meat" -and $_.result -eq "success" })
if ($service.Count -lt 1 -or $potions.Count -lt 1 -or $food.Count -lt 1) { throw "Missing supplies did not select and complete service recovery." }
}
if ($Mode -eq "retention") {
$depositedUnknown = @($events | Where-Object { $_.action -eq "deposit" -and $_.item_id -eq 2050 })
if ($depositedUnknown.Count -ne 0) { throw "Depot policy deposited an unknown retained item." }
}
}

function Assert-GoalArbitrationInterruptEvents {
param([string]$Logs)

Expand Down Expand Up @@ -978,7 +1020,7 @@ if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
}

$focusedScenarioRequested = $FullNavigation -or $CorpseLoot -or $DeathTelemetry -or $Healing -or $ValueLoot -or
$PickupProgression -or $GoalArbitration -or $OracleDeparture -or $StaminaProjection -or $HuntRegionPlanning
$PickupProgression -or $GoalArbitration -or $OracleDeparture -or $StaminaProjection -or $HuntRegionPlanning -or $CombatReadiness
if ($Focused -and -not $focusedScenarioRequested) {
throw "-Focused requires at least one focused scenario switch."
}
Expand Down Expand Up @@ -1138,6 +1180,58 @@ try {
}
}

if ($CombatReadiness) {
Invoke-Scenario -Name "combat_readiness_ready" -DefaultTimeoutSeconds 60 -Body {
Invoke-Compose down --volumes --remove-orphans
$env:PLAYERBOT_GAMEPLAY_MODE = "readiness_ready"
Invoke-Compose up --detach
Wait-ForLog -Pattern 'PLAYERBOT_GAMEPLAY_TEST READINESS_READY_PASS' | Out-Null
$readyLogs = Wait-ForLog -Pattern '"event":"combat_readiness".*"result":"ready"'
Assert-CombatReadinessEvents -Logs $readyLogs -Mode "ready"
$restartLineCount = @((Get-ServerLogs) -split "`r?`n").Count
Invoke-Compose stop server
Invoke-Compose up --detach server
$restartLogs = ""
for ($attempt = 0; $attempt -lt 30; $attempt++) {
Start-Sleep -Seconds 1
$restartLogs = ((Get-ServerLogs) -split "`r?`n" | Select-Object -Skip $restartLineCount) -join "`n"
if ($restartLogs -match '"event":"combat_readiness".*"vocation_id":4') { break }
}
Assert-CombatReadinessEvents -Logs $restartLogs -Mode "ready"
}
Invoke-Scenario -Name "combat_readiness_upgrade" -DefaultTimeoutSeconds 60 -Body {
Invoke-Compose down --volumes --remove-orphans
$env:PLAYERBOT_GAMEPLAY_MODE = "readiness_upgrade"
Invoke-Compose up --detach
Wait-ForLog -Pattern 'PLAYERBOT_GAMEPLAY_TEST READINESS_UPGRADE_PASS' | Out-Null
Assert-CombatReadinessEvents -Logs (Get-ServerLogs) -Mode "upgrade"
}
Invoke-Scenario -Name "combat_readiness_missing_weapon" -DefaultTimeoutSeconds 45 -Body {
Invoke-Compose down --volumes --remove-orphans
$env:PLAYERBOT_GAMEPLAY_MODE = "readiness_missing_weapon"
Invoke-Compose up --detach
Wait-ForLog -Pattern 'PLAYERBOT_GAMEPLAY_TEST READINESS_MISSING_WEAPON_START' | Out-Null
$missingWeaponLogs = Wait-ForLog -Pattern '"reason":"combat_readiness_missing_legal_melee_weapon"'
Assert-CombatReadinessEvents -Logs $missingWeaponLogs -Mode "missing_weapon"
}
Invoke-Scenario -Name "combat_readiness_supplies" -DefaultTimeoutSeconds 120 -Body {
Invoke-Compose down --volumes --remove-orphans
$env:PLAYERBOT_GAMEPLAY_MODE = "readiness_supplies"
Invoke-Compose up --detach
Wait-ForLog -Pattern 'PLAYERBOT_GAMEPLAY_TEST READINESS_SUPPLIES_PASS' | Out-Null
$supplyLogs = Wait-ForLog -Pattern '"event":"combat_readiness".*"result":"ready"'
Assert-CombatReadinessEvents -Logs $supplyLogs -Mode "supplies"
}
Invoke-Scenario -Name "combat_readiness_retention" -DefaultTimeoutSeconds 120 -Body {
Invoke-Compose down --volumes --remove-orphans
$env:PLAYERBOT_GAMEPLAY_MODE = "readiness_retention"
Invoke-Compose up --detach
Wait-ForLog -Pattern 'PLAYERBOT_GAMEPLAY_TEST READINESS_RETENTION_PASS' | Out-Null
$retentionLogs = Wait-ForLog -Pattern '"event":"combat_readiness".*"result":"ready"'
Assert-CombatReadinessEvents -Logs $retentionLogs -Mode "retention"
}
}

if ($OracleDeparture) {
Invoke-Scenario -Name "oracle_departure" -DefaultTimeoutSeconds 180 -Body {
Invoke-Compose down --volumes --remove-orphans
Expand Down
32 changes: 26 additions & 6 deletions server/schema/insertPlayerbots.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ INSERT INTO `accounts` (`name`, `password`, `type`, `premium_ends_at`, `email`,
VALUES ('bot-one', SHA1('bot-one'), 1, 0, '', 0)
ON DUPLICATE KEY UPDATE `id` = `id`;

-- These local-development defaults start normal Rookgaard progression. Focused
-- gameplay fixtures add any stronger equipment their scenario requires.
-- This idempotent kit remains valid through the deterministic Rookgaard-to-Knight
-- transition. Focused gameplay fixtures add any stronger equipment they need.

CREATE TABLE IF NOT EXISTS `player_bots` (
`player_id` int NOT NULL,
Expand Down Expand Up @@ -60,10 +60,10 @@ SET @bot_next_sid = (
);

INSERT INTO `player_items` (`player_id`, `pid`, `sid`, `itemtype`, `count`, `attributes`)
SELECT @bot_player_id, `loadout`.`pid`, @bot_next_sid + `loadout`.`offset`, `loadout`.`itemtype`, 1, ''
SELECT @bot_player_id, `loadout`.`pid`, @bot_next_sid + `loadout`.`offset`, `loadout`.`itemtype`, `loadout`.`count`, ''
FROM (
SELECT 4 AS `pid`, 1 AS `offset`, 2650 AS `itemtype`
UNION ALL SELECT 6, 2, 2382
SELECT 4 AS `pid`, 1 AS `offset`, 2650 AS `itemtype`, 1 AS `count`
UNION ALL SELECT 6, 2, 2382, 1
) AS `loadout`
WHERE NOT EXISTS (
SELECT 1 FROM `player_items`
Expand All @@ -83,9 +83,29 @@ FROM (
WHERE @bot_backpack_sid IS NOT NULL
AND NOT EXISTS (
SELECT 1 FROM `player_items`
WHERE `player_id` = @bot_player_id AND `itemtype` = `tools`.`itemtype`
WHERE `player_id` = @bot_player_id AND `itemtype` = `tools`.`itemtype`
);

SET @bot_next_sid = (
SELECT COALESCE(MAX(`sid`), 100) FROM `player_items` WHERE `player_id` = @bot_player_id
);

INSERT INTO `player_items` (`player_id`, `pid`, `sid`, `itemtype`, `count`, `attributes`)
SELECT @bot_player_id, @bot_backpack_sid, @bot_next_sid + `supplies`.`offset`, `supplies`.`itemtype`, `supplies`.`count`, ''
FROM (
SELECT 1 AS `offset`, 8704 AS `itemtype`, 1 AS `count`
UNION ALL SELECT 2, 8704, 1
UNION ALL SELECT 3, 8704, 1
UNION ALL SELECT 4, 8704, 1
UNION ALL SELECT 5, 8704, 1
UNION ALL SELECT 6, 2666, 1
) AS `supplies`
WHERE @bot_backpack_sid IS NOT NULL
AND NOT EXISTS (
SELECT 1 FROM `player_items`
WHERE `player_id` = @bot_player_id AND `itemtype` = `supplies`.`itemtype`
);

-- Seed the initial purse once; later provisioning runs preserve spent money.
SET @bot_next_sid = (
SELECT COALESCE(MAX(`sid`), 100) FROM `player_items` WHERE `player_id` = @bot_player_id
Expand Down
3 changes: 3 additions & 0 deletions server/src/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "itemloader.h"
#include "position.h"

#include <set>

enum SlotPositionBits : uint32_t {
SLOTP_WHEREEVER = 0xFFFFFFFF,
SLOTP_HEAD = 1 << 0,
Expand Down Expand Up @@ -311,6 +313,7 @@ class ItemType
std::string description;
std::string runeSpellName;
std::string vocationString;
std::set<uint16_t> vocationIds;

std::unique_ptr<Abilities> abilities;
std::unique_ptr<ConditionDamage> conditionDamage;
Expand Down
4 changes: 4 additions & 0 deletions server/src/luascript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16309,6 +16309,10 @@ int LuaScriptInterface::luaWeaponRegister(lua_State* L)
it.vocationString = weapon->getVocationString();
it.minReqLevel = weapon->getReqLevel();
it.minReqMagicLevel = weapon->getReqMagLv();
it.vocationIds.clear();
for (const auto& vocation : weapon->vocWeaponMap) {
it.vocationIds.insert(vocation.first);
}
}

weapon->configureWeapon(it);
Expand Down
28 changes: 28 additions & 0 deletions server/src/movement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ bool MoveEvents::registerEvent(Event_ptr event, const pugi::xml_node& node)
it.minReqLevel = moveEvent->getReqLevel();
it.minReqMagicLevel = moveEvent->getReqMagLv();
it.vocationString = moveEvent->getVocationString();
it.vocationIds.clear();
for (const auto& vocation : moveEvent->getVocEquipMap()) {
it.vocationIds.insert(vocation.first);
}
}
addEvent(std::move(*moveEvent), id, itemIdMap);
}
Expand All @@ -146,6 +150,10 @@ bool MoveEvents::registerEvent(Event_ptr event, const pugi::xml_node& node)
it.minReqLevel = moveEvent->getReqLevel();
it.minReqMagicLevel = moveEvent->getReqMagLv();
it.vocationString = moveEvent->getVocationString();
it.vocationIds.clear();
for (const auto& vocation : moveEvent->getVocEquipMap()) {
it.vocationIds.insert(vocation.first);
}

while (++id <= endId) {
addEvent(*moveEvent, id, itemIdMap);
Expand All @@ -155,6 +163,10 @@ bool MoveEvents::registerEvent(Event_ptr event, const pugi::xml_node& node)
tit.minReqLevel = moveEvent->getReqLevel();
tit.minReqMagicLevel = moveEvent->getReqMagLv();
tit.vocationString = moveEvent->getVocationString();
tit.vocationIds.clear();
for (const auto& vocation : moveEvent->getVocEquipMap()) {
tit.vocationIds.insert(vocation.first);
}
}
} else {
while (++id <= endId) {
Expand Down Expand Up @@ -231,6 +243,10 @@ bool MoveEvents::registerLuaFunction(MoveEvent* event)
it.minReqLevel = moveEvent->getReqLevel();
it.minReqMagicLevel = moveEvent->getReqMagLv();
it.vocationString = moveEvent->getVocationString();
it.vocationIds.clear();
for (const auto& vocation : moveEvent->getVocEquipMap()) {
it.vocationIds.insert(vocation.first);
}
}
} else {
uint32_t iterId = 0;
Expand All @@ -241,6 +257,10 @@ bool MoveEvents::registerLuaFunction(MoveEvent* event)
it.minReqLevel = moveEvent->getReqLevel();
it.minReqMagicLevel = moveEvent->getReqMagLv();
it.vocationString = moveEvent->getVocationString();
it.vocationIds.clear();
for (const auto& vocation : moveEvent->getVocEquipMap()) {
it.vocationIds.insert(vocation.first);
}
}
addEvent(*moveEvent, moveEvent->getItemIdRange().at(iterId), itemIdMap);
}
Expand Down Expand Up @@ -281,6 +301,10 @@ bool MoveEvents::registerLuaEvent(MoveEvent* event)
it.minReqLevel = moveEvent->getReqLevel();
it.minReqMagicLevel = moveEvent->getReqMagLv();
it.vocationString = moveEvent->getVocationString();
it.vocationIds.clear();
for (const auto& vocation : moveEvent->getVocEquipMap()) {
it.vocationIds.insert(vocation.first);
}
}
} else {
auto v = moveEvent->getItemIdRange();
Expand All @@ -291,6 +315,10 @@ bool MoveEvents::registerLuaEvent(MoveEvent* event)
it.minReqLevel = moveEvent->getReqLevel();
it.minReqMagicLevel = moveEvent->getReqMagLv();
it.vocationString = moveEvent->getVocationString();
it.vocationIds.clear();
for (const auto& vocation : moveEvent->getVocEquipMap()) {
it.vocationIds.insert(vocation.first);
}
}
addEvent(*moveEvent, *i, itemIdMap);
}
Expand Down
10 changes: 10 additions & 0 deletions server/src/playerbotcombat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,9 @@ void PlayerBotController::startHunt(Player* player, const Position& position, co
stop("controlled_player_not_found", position);
return;
}
if (!ensureCombatReady(player, position, reason)) {
return;
}
activeGoal = TopLevelGoal::Hunt;
setCyclePhase(CyclePhase::Hunt, position, reason);
huntRouteIndex = 0;
Expand All @@ -761,6 +764,13 @@ void PlayerBotController::startHunt(Player* player, const Position& position, co

void PlayerBotController::processTraversal(Player* player, const Position& currentPosition)
{
if (readinessEquipmentPending) {
processReadinessEquipment(player, currentPosition);
return;
}
if (cyclePhase == CyclePhase::Hunt && !ensureCombatReady(player, currentPosition, "readiness_continuous_check")) {
return;
}
if (cyclePhase != CyclePhase::Hunt || progressionObjective == ProgressionObjective::OracleDeparture) {
if (defensiveTargetId != 0) {
processDefensiveCombat(player, currentPosition);
Expand Down
9 changes: 7 additions & 2 deletions server/src/playerbotcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ const PlayerBotTestPolicy& playerbot::testPolicyFromEnvironment()
std::strcmp(gameplayMode, "healing") == 0 || std::strcmp(gameplayMode, "healing_resupply") == 0 ||
std::strcmp(gameplayMode, "value") == 0 || std::strcmp(gameplayMode, "departure_interrupt") == 0 ||
std::strcmp(gameplayMode, "stamina_bonus") == 0 || std::strcmp(gameplayMode, "stamina_boundary") == 0 ||
std::strcmp(gameplayMode, "stamina_normal") == 0 || std::strcmp(gameplayMode, "hunt_planning") == 0);
std::strcmp(gameplayMode, "stamina_normal") == 0 || std::strcmp(gameplayMode, "hunt_planning") == 0 ||
std::strcmp(gameplayMode, "readiness_ready") == 0 || std::strcmp(gameplayMode, "readiness_upgrade") == 0 ||
std::strcmp(gameplayMode, "readiness_missing_weapon") == 0 || std::strcmp(gameplayMode, "readiness_supplies") == 0 ||
std::strcmp(gameplayMode, "readiness_retention") == 0);
const bool fixedFixtureRoute = gameplayMode && std::strcmp(gameplayMode, "stamina_bonus") != 0 &&
std::strcmp(gameplayMode, "stamina_boundary") != 0 &&
std::strcmp(gameplayMode, "stamina_normal") != 0 &&
Expand Down Expand Up @@ -219,7 +222,9 @@ uint32_t PlayerBotController::protectedItemReserve(uint16_t itemId) const
uint32_t PlayerBotController::getSaleItemCount(const Player& player, uint16_t itemId) const
{
const ItemType& type = Item::items[itemId];
if ((type.isContainer() && type.corpseType == RACE_NONE) || type.isFluidContainer() || type.isSplash()) {
if ((type.isContainer() && type.corpseType == RACE_NONE) || type.isFluidContainer() || type.isSplash() ||
type.weaponType != WEAPON_NONE || type.armor > 0 || type.defense > 0 ||
(type.slotPosition & (SLOTP_HEAD | SLOTP_ARMOR | SLOTP_LEGS | SLOTP_FEET)) != 0) {
return 0;
}
Item* backpackItem = player.getInventoryItem(CONST_SLOT_BACKPACK);
Expand Down
16 changes: 16 additions & 0 deletions server/src/playerbotcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,18 @@ class PlayerBotController : public std::enable_shared_from_this<PlayerBotControl
bool canEatCheese(const Player& player) const;

bool needsHealing(const Player& player) const;
bool requiresKnightCombatReadiness(const Player& player) const;
bool isLegalEquipmentItem(const Player& player, const Item& item) const;
bool isKnightMeleeWeapon(const Player& player, const Item& item) const;
bool isCombatEquipment(const Item& item) const;
bool isProtectedInventoryItem(const Item& item) const;
bool isCombatReady(const Player& player, std::string& recovery, std::string& terminalReason) const;
void emitCombatReadiness(const Player& player, const Position& position, const char* result,
const std::string& recovery, const std::string& terminalReason) const;
bool findCarriedEquipmentUpgrade(Player& player, Item*& item, EquipmentUpgrade& upgrade) const;
bool beginReadinessEquipment(Player* player, const Position& position, const char* reason);
void processReadinessEquipment(Player* player, const Position& position);
bool ensureCombatReady(Player* player, const Position& position, const char* reason);

void logHealResult(const char* result, const char* reason, int32_t healthAfter,
uint32_t potionCountAfter, const Position& position);
Expand Down Expand Up @@ -678,6 +690,10 @@ class PlayerBotController : public std::enable_shared_from_this<PlayerBotControl
std::map<uint16_t, std::string> rewardInspectionFingerprints;
uint16_t pendingEquipmentItemId = 0;
uint32_t pendingEquipmentItemCount = 0;
uint16_t pendingReadinessItemId = 0;
slots_t pendingReadinessSlot = CONST_SLOT_WHEREEVER;
uint32_t pendingReadinessAttempts = 0;
bool readinessEquipmentPending = false;
std::vector<ServiceNpc> serviceShops;
std::vector<ServiceNpc> serviceBankers;
uint32_t serviceTargetId = 0;
Expand Down
5 changes: 2 additions & 3 deletions server/src/playerbotloot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@ uint8_t PlayerBotController::backpackDestinationIndex(const Container& backpack,
bool PlayerBotController::isReplaceableCargo(const Item& item) const
{
const ItemType& type = Item::items[item.getID()];
const Container* container = item.getContainer();
return (!container || (type.corpseType != RACE_NONE && container->empty())) && item.getWorth() == 0 && protectedItemReserve(item.getID()) == 0 &&
itemUnitValue(item.getID()) != 0 && item.getBaseWeight() != 0;
return !isProtectedInventoryItem(item) && type.corpseType == RACE_NONE && itemUnitValue(item.getID()) != 0 &&
item.getBaseWeight() != 0;
}

bool PlayerBotController::chooseCargoReplacement(const Container& backpack, const Item& incoming, uint32_t freeCapacity,
Expand Down
Loading