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
1 change: 1 addition & 0 deletions server/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ set(tfs_SRC
${CMAKE_CURRENT_LIST_DIR}/playerbotlootsession.cpp
${CMAKE_CURRENT_LIST_DIR}/playerbotlootworkflow.cpp
${CMAKE_CURRENT_LIST_DIR}/playerbotprogression.cpp
${CMAKE_CURRENT_LIST_DIR}/playerbotprogressionplanners.cpp
${CMAKE_CURRENT_LIST_DIR}/playerbotprogressionruntime.cpp
${CMAKE_CURRENT_LIST_DIR}/playerbotprogressionsession.cpp
${CMAKE_CURRENT_LIST_DIR}/playerbotrecoverysession.cpp
Expand Down
8 changes: 4 additions & 4 deletions server/src/playerbotcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ void PlayerBotController::start(const Position& position, bool recovered, uint32
refreshItemValues();
const bool startInHunt = !recovered && fixtureDriver.startInHunt();
Player* controlledPlayer = g_game.getPlayerByID(playerId);
const bool departureComplete = controlledPlayer && hasCompletedRookgaardDeparture(*controlledPlayer);
const bool departureRequired = controlledPlayer && requiresRookgaardDeparture(*controlledPlayer);
const bool departureComplete = controlledPlayer && departurePlanner.hasCompleted(departureSnapshot(*controlledPlayer));
const bool departureRequired = controlledPlayer && departurePlanner.required(departureSnapshot(*controlledPlayer));
const bool useGoalSelector = controlledPlayer && !startInHunt &&
(departureRequired || (!recovered && fixtureDriver.progressionEnabled()));
if (!fixtureDriver.magicTrainingScenario() && !fixtureDriver.deferInitialization() && useGoalSelector &&
Expand Down Expand Up @@ -453,7 +453,7 @@ void PlayerBotController::navigate()
}
emitFixtureEvents(fixtureDriver.runMagicTraining(*player), currentPosition);
const bool useGoalSelector = !fixtureDriver.startInHunt() &&
(requiresRookgaardDeparture(*player) || fixtureDriver.progressionEnabled());
(departurePlanner.required(departureSnapshot(*player)) || fixtureDriver.progressionEnabled());
if (useGoalSelector) {
if (!selectTopLevelGoal(*player, currentPosition, "startup")) {
return;
Expand Down Expand Up @@ -490,7 +490,7 @@ void PlayerBotController::navigate()
}
const bool waitingForRecovery = cyclePhase == CyclePhase::Service && survivalRuntime.needsHealing(survivalSnapshot(*player));
if (!accessingReward && !progressionSession.active(PlayerBotProgressionProcedure::OracleDeparture) &&
requiresRookgaardDeparture(*player) && !waitingForRecovery) {
departurePlanner.required(departureSnapshot(*player)) && !waitingForRecovery) {
if (selectTopLevelGoal(*player, currentPosition, "level_eight_interrupt")) {
schedule(SCHEDULER_MINTICKS);
}
Expand Down
78 changes: 8 additions & 70 deletions server/src/playerbotcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "playerbotlootworkflow.h"
#include "playerbotnavigationruntime.h"
#include "playerbotprogressionruntime.h"
#include "playerbotprogressionplanners.h"
#include "playerbotsurvivalruntime.h"
#include "playerbottestpolicy.h"
#include "playerbotfixturedriver.h"
Expand Down Expand Up @@ -181,45 +182,8 @@ class PlayerBotController : public std::enable_shared_from_this<PlayerBotControl
using EquipmentHuntSummary = PlayerBotEquipmentHuntSummary;
using EquipmentOfferEvaluation = PlayerBotEquipmentOfferEvaluation;

struct RewardItemInspection {
uint16_t itemId;
uint32_t count;
uint32_t depth;
uint16_t rootOrdinal;
std::vector<uint16_t> path;
std::vector<std::string> classes;
uint32_t worth = 0;
uint32_t sellValue = 0;
};

struct RewardInspection {
std::vector<RewardItemInspection> items;
std::vector<std::string> rootSignatures;
std::vector<std::string> nonStackableRootSignatures;
std::map<uint16_t, uint32_t> stackableRootCounts;
std::optional<EquipmentUpgrade> bestUpgrade;
std::optional<EquipmentOfferEvaluation> bestEquipment;
std::string equipmentRejection;
uint16_t bestItemId = 0;
uint16_t bestRootOrdinal = 0;
std::vector<uint16_t> bestItemPath;
std::string bestRootSignature;
uint16_t primaryKnownItemId = 0;
uint16_t primaryKnownRootOrdinal = 0;
std::string primaryKnownRootSignature;
uint32_t primaryKnownItemUtility = 0;
uint32_t itemCount = 0;
uint32_t containerCount = 0;
uint32_t unknownCount = 0;
uint32_t equipmentUpgradeCount = 0;
uint32_t currencyValue = 0;
uint32_t sellValue = 0;
uint32_t potionCount = 0;
uint32_t foodCount = 0;
uint32_t ropeCount = 0;
uint32_t shovelCount = 0;
int32_t knownUtility = 0;
};
using RewardItemInspection = PlayerBotRewardItemInspection;
using RewardInspection = PlayerBotRewardInspection;

using ServiceNpc = PlayerBotEconomyProvider;

Expand Down Expand Up @@ -313,37 +277,8 @@ class PlayerBotController : public std::enable_shared_from_this<PlayerBotControl
void processEquipmentPurchase(Player* player, const Position& position);
void finishEquipmentPurchase(Player* player, const Position& position, const char* result, const char* reason);

std::string rewardItemSignature(const Item& item) const;

void inspectRewardItem(Player& player, const Item& item, uint16_t rootOrdinal,
std::vector<uint16_t>& path, const std::string& rootSignature,
const EquipmentLoadout& currentLoadout,
const PlayerBotCombatProfile& currentProfile,
const EquipmentHuntSummary& currentHunts, bool currentReady,
uint32_t additionalWeight,
std::map<std::pair<uint16_t, uint32_t>, EquipmentOfferEvaluation>& equipmentEvaluations,
size_t& simulatedItems, RewardInspection& inspection) const;

RewardInspection inspectRewardBundle(Player& player, const Container& contents,
const EquipmentLoadout& currentLoadout,
const PlayerBotCombatProfile& currentProfile,
const EquipmentHuntSummary& currentHunts, bool currentReady,
uint32_t additionalWeight,
std::map<std::pair<uint16_t, uint32_t>, EquipmentOfferEvaluation>& equipmentEvaluations,
size_t& simulatedItems) const;
RewardInspection inspectKnownReward(Player& player, const Item& item,
const EquipmentLoadout& currentLoadout,
const PlayerBotCombatProfile& currentProfile,
const EquipmentHuntSummary& currentHunts, bool currentReady,
uint32_t additionalWeight,
std::map<std::pair<uint16_t, uint32_t>, EquipmentOfferEvaluation>& equipmentEvaluations,
size_t& simulatedItems) const;
void finalizeRewardInspection(Player& player, RewardInspection& inspection) const;

std::string rewardInspectionItemsJson(const RewardInspection& inspection) const;

int32_t estimatedPickupUtility(const PlayerBotRewardPlan& reward) const;

Container* playerBackpack(Player& player) const;

uint32_t matchingRewardRootCount(Player& player, const std::string& signature) const;
Expand Down Expand Up @@ -373,8 +308,7 @@ class PlayerBotController : public std::enable_shared_from_this<PlayerBotControl
bool findPickupReward(Player& player, const Position& position, PlayerBotRewardPlan& reward,
std::deque<PlayerBotNavigationStep>& rewardSteps);

bool hasCompletedRookgaardDeparture(const Player& player) const;
bool requiresRookgaardDeparture(const Player& player) const;
PlayerBotDeparturePlannerSnapshot departureSnapshot(const Player& player) const;

bool findOracleDeparture(Player& player, const Position& position, PlayerBotOracleDeparturePlan& plan,
std::deque<PlayerBotNavigationStep>& departureSteps);
Expand Down Expand Up @@ -548,6 +482,10 @@ class PlayerBotController : public std::enable_shared_from_this<PlayerBotControl
}};
CyclePhase cyclePhase = CyclePhase::ReturnToDepot;
PlayerBotProgressionRuntime progressionRuntime;
PlayerBotRewardPlanner rewardPlanner;
PlayerBotEquipmentProviderPlanner equipmentProviderPlanner;
PlayerBotSpellTrainingPlanner spellTrainingPlanner;
PlayerBotDeparturePlanner departurePlanner;
// These references keep the game-adapter code narrow while the runtime owns
// all progression state. New procedure logic must use progressionRuntime.
const PlayerBotProgressionSession& progressionSession = progressionRuntime.session();
Expand Down
21 changes: 9 additions & 12 deletions server/src/playerbotdeparture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@
// Rookgaard Oracle discovery, dialogue, and departure verification.
using namespace playerbot;

bool PlayerBotController::hasCompletedRookgaardDeparture(const Player& player) const
PlayerBotDeparturePlannerSnapshot PlayerBotController::departureSnapshot(const Player& player) const
{
return player.getVocation()->getId() != 0 && player.getTown() && player.getTown()->getID() != rookgaardTownId;
}

bool PlayerBotController::requiresRookgaardDeparture(const Player& player) const
{
return player.getVocation()->getId() == 0 && player.getLevel() >= oracleMinimumLevel;
return {player.getLevel(), player.getVocation()->getId(), player.getTown() ? player.getTown()->getID() : 0,
oracleMinimumLevel, oracleMaximumLevel, rookgaardTownId, {}};
}

bool PlayerBotController::findOracleDeparture(Player& player, const Position& position, PlayerBotOracleDeparturePlan& plan,
std::deque<PlayerBotNavigationStep>& departureSteps)
{
PlayerBotDeparturePlannerSnapshot snapshot = departureSnapshot(player);
Npc* oracle = nullptr;
for (const auto& entry : g_game.getNpcs()) {
Npc* npc = entry.second;
Expand Down Expand Up @@ -77,11 +74,11 @@ bool PlayerBotController::findOracleDeparture(Player& player, const Position& po
if (!planned) {
continue;
}
plan.npcId = oracle->getID();
plan.npcPosition = oracle->getPosition();
plan.approachPosition = candidate;
plan.travelSteps = static_cast<uint32_t>(steps.size());
plan.expandedNodes = expandedNodes;
snapshot.providers.push_back({oracle->getID(), oracle->getPosition(),
{true, false, candidate, static_cast<uint32_t>(steps.size()), expandedNodes}});
const std::optional<PlayerBotOracleDeparturePlan> selected = departurePlanner.select(snapshot);
if (!selected) return false;
plan = *selected;
departureSteps = std::move(steps);
return true;
}
Expand Down
8 changes: 8 additions & 0 deletions server/src/playerbotequipment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ std::optional<PlayerBotController::EquipmentOfferEvaluation> PlayerBotController
std::map<uint32_t, std::optional<std::pair<Position, uint32_t>>> providerRoutes;
std::set<uint32_t> providerRouteNodeLimits;
std::optional<EquipmentOfferEvaluation> selected;
std::vector<PlayerBotEquipmentProviderOfferSnapshot> plannerOffers;
uint32_t feasibleCandidates = 0;
size_t simulatedItems = 0;
bool providerRouteBudgetExhausted = false;
Expand Down Expand Up @@ -217,6 +218,8 @@ std::optional<PlayerBotController::EquipmentOfferEvaluation> PlayerBotController
if (evaluation.carried) {
evaluation.travelSteps = 0;
emitEquipmentOffer(player, evaluation, currentProfile, currentHunts, reserve, position, "feasible", "carried_upgrade");
plannerOffers.push_back({evaluation, Item::items[offer.itemId].weight, freeBackpackSlots, backpack != nullptr,
false, {true, false, Position(), 0, 0}});
++feasibleCandidates;
if (!selected || PlayerBotEquipmentPolicy::prefers(evaluation, *selected)) {
selected = evaluation;
Expand All @@ -242,12 +245,17 @@ std::optional<PlayerBotController::EquipmentOfferEvaluation> PlayerBotController
evaluation.approachPosition = route->first;
evaluation.travelSteps = route->second;
emitEquipmentOffer(player, evaluation, currentProfile, currentHunts, reserve, position, "feasible", nullptr);
plannerOffers.push_back({evaluation, Item::items[offer.itemId].weight, freeBackpackSlots, backpack != nullptr,
false, {true, false, route->first, route->second, 0}});
++feasibleCandidates;
if (!selected || PlayerBotEquipmentPolicy::prefers(evaluation, *selected)) {
selected = evaluation;
}
}
}
const PlayerBotEquipmentProviderDecision plannerDecision = equipmentProviderPlanner.select({true, reserve, totalMoney,
reserve != std::numeric_limits<uint64_t>::max(), player.getFreeCapacity(), std::move(plannerOffers)});
selected = plannerDecision.selected;
std::ostringstream fields;
fields << "\"result\":" << jsonString(selected ? (selected->carried ? "would_equip" : "would_buy") : "no_decision")
<< ",\"feasible_candidates\":" << feasibleCandidates
Expand Down
Loading