mxwow modules

This commit is contained in:
mikx
2025-03-24 23:53:45 -04:00
parent 93073b0be2
commit e87efbaf6e
99 changed files with 4909 additions and 814 deletions

View File

@@ -26,5 +26,5 @@ bool CanLootValue::Calculate()
{
LootObject loot = AI_VALUE(LootObject, "loot target");
return !loot.IsEmpty() && loot.GetWorldObject(bot) && loot.IsLootPossible(bot) &&
sServerFacade->IsDistanceLessOrEqualThan(AI_VALUE2(float, "distance", "loot target"), INTERACTION_DISTANCE);
sServerFacade->IsDistanceLessOrEqualThan(AI_VALUE2(float, "distance", "loot target"), INTERACTION_DISTANCE - 2);
}

View File

@@ -5,6 +5,7 @@
#include "GrindTargetValue.h"
#include "NewRpgInfo.h"
#include "Playerbots.h"
#include "ReputationMgr.h"
#include "SharedDefines.h"
@@ -52,7 +53,7 @@ Unit* GrindTargetValue::FindTargetForGrinding(uint32 assistCount)
float distance = 0;
Unit* result = nullptr;
// std::unordered_map<uint32, bool> needForQuestMap;
std::unordered_map<uint32, bool> needForQuestMap;
for (ObjectGuid const guid : targets)
{
@@ -99,19 +100,6 @@ Unit* GrindTargetValue::FindTargetForGrinding(uint32 assistCount)
if (!bot->InBattleground() && (int)unit->GetLevel() - (int)bot->GetLevel() > 4 && !unit->GetGUID().IsPlayer())
continue;
// if (needForQuestMap.find(unit->GetEntry()) == needForQuestMap.end())
// needForQuestMap[unit->GetEntry()] = needForQuest(unit);
// if (!needForQuestMap[unit->GetEntry()])
// {
// Creature* creature = dynamic_cast<Creature*>(unit);
// if ((urand(0, 100) < 60 || (context->GetValue<TravelTarget*>("travel target")->Get()->isWorking() &&
// context->GetValue<TravelTarget*>("travel target")->Get()->getDestination()->getName() != "GrindTravelDestination")))
// {
// continue;
// }
// }
if (Creature* creature = unit->ToCreature())
if (CreatureTemplate const* CreatureTemplate = creature->GetCreatureTemplate())
if (CreatureTemplate->rank > CREATURE_ELITE_NORMAL && !AI_VALUE(bool, "can fight elite"))
@@ -122,6 +110,26 @@ Unit* GrindTargetValue::FindTargetForGrinding(uint32 assistCount)
continue;
}
bool inactiveGrindStatus = botAI->rpgInfo.status == RPG_GO_GRIND ||
botAI->rpgInfo.status == RPG_NEAR_NPC ||
botAI->rpgInfo.status == RPG_REST ||
botAI->rpgInfo.status == RPG_GO_INNKEEPER ||
botAI->rpgInfo.status == RPG_DO_QUEST;
bool notHostile = !bot->IsHostileTo(unit); /*|| (unit->ToCreature() && unit->ToCreature()->IsCivilian());*/
float aggroRange = 30.0f;
if (unit->ToCreature())
aggroRange = std::min(30.0f, unit->ToCreature()->GetAggroRange(bot) + 10.0f);
bool outOfAggro = unit->ToCreature() && bot->GetDistance(unit) > aggroRange;
if (inactiveGrindStatus && (outOfAggro || notHostile))
{
if (needForQuestMap.find(unit->GetEntry()) == needForQuestMap.end())
needForQuestMap[unit->GetEntry()] = needForQuest(unit);
if (!needForQuestMap[unit->GetEntry()])
continue;
}
if (group)
{
Group::MemberSlotList const& groupSlot = group->GetMemberSlots();
@@ -155,8 +163,6 @@ Unit* GrindTargetValue::FindTargetForGrinding(uint32 assistCount)
bool GrindTargetValue::needForQuest(Unit* target)
{
bool justCheck = (bot->GetGUID() == target->GetGUID());
QuestStatusMap& questMap = bot->getQuestStatusMap();
for (auto& quest : questMap)
{
@@ -170,16 +176,9 @@ bool GrindTargetValue::needForQuest(Unit* target)
QuestStatus status = bot->GetQuestStatus(questId);
if ((status == QUEST_STATUS_COMPLETE && !bot->GetQuestRewardStatus(questId)))
if (status == QUEST_STATUS_INCOMPLETE)
{
if (!justCheck && !target->hasInvolvedQuest(questId))
continue;
return true;
}
else if (status == QUEST_STATUS_INCOMPLETE)
{
QuestStatusData* questStatus = sTravelMgr->getQuestStatus(bot, questId);
const QuestStatusData* questStatus = &bot->getQuestStatusMap()[questId];
if (questTemplate->GetQuestLevel() > bot->GetLevel() + 5)
continue;
@@ -193,33 +192,18 @@ bool GrindTargetValue::needForQuest(Unit* target)
int required = questTemplate->RequiredNpcOrGoCount[j];
int available = questStatus->CreatureOrGOCount[j];
if (required && available < required && (target->GetEntry() == entry || justCheck))
if (required && available < required && target->GetEntry() == entry)
return true;
}
if (justCheck)
{
int32 itemId = questTemplate->RequiredItemId[j];
if (itemId && itemId > 0)
{
uint32 required = questTemplate->RequiredItemCount[j];
uint32 available = questStatus->ItemCount[j];
if (required && available < required)
return true;
}
}
}
if (!justCheck)
if (CreatureTemplate const* data = sObjectMgr->GetCreatureTemplate(target->GetEntry()))
{
if (CreatureTemplate const* data = sObjectMgr->GetCreatureTemplate(target->GetEntry()))
if (uint32 lootId = data->lootid)
{
if (uint32 lootId = data->lootid)
if (LootTemplates_Creature.HaveQuestLootForPlayer(lootId, bot))
{
if (LootTemplates_Creature.HaveQuestLootForPlayer(lootId, bot))
return true;
return true;
}
}
}

View File

@@ -71,6 +71,9 @@ Item* ItemForSpellValue::Calculate()
if (!strcmpi(spellInfo->SpellName[0], "disenchant"))
return nullptr;
if (!strcmpi(spellInfo->SpellName[0], "pick lock"))
return nullptr;
for (uint8 slot = EQUIPMENT_SLOT_START; slot < EQUIPMENT_SLOT_END; slot++)
{
itemForSpell = GetItemFitsToSpellRequirements(slot, spellInfo);

View File

@@ -17,6 +17,7 @@ class Unit;
enum class MovementPriority
{
MOVEMENT_IDLE,
MOVEMENT_WANDER,
MOVEMENT_NORMAL,
MOVEMENT_COMBAT,
MOVEMENT_FORCED

View File

@@ -12,24 +12,6 @@
#include "SharedDefines.h"
#include "SpellMgr.h"
class AnyGameObjectInObjectRangeCheck
{
public:
AnyGameObjectInObjectRangeCheck(WorldObject const* obj, float range) : i_obj(obj), i_range(range) {}
WorldObject const& GetFocusObject() const { return *i_obj; }
bool operator()(GameObject* u)
{
if (u && i_obj->IsWithinDistInMap(u, i_range) && u->isSpawned() && u->GetGOInfo())
return true;
return false;
}
private:
WorldObject const* i_obj;
float i_range;
};
GuidVector NearestGameObjects::Calculate()
{
std::list<GameObject*> targets;

View File

@@ -8,15 +8,34 @@
#include "PlayerbotAIConfig.h"
#include "Value.h"
#include "GameObject.h"
class PlayerbotAI;
class AnyGameObjectInObjectRangeCheck
{
public:
AnyGameObjectInObjectRangeCheck(WorldObject const* obj, float range) : i_obj(obj), i_range(range) {}
WorldObject const& GetFocusObject() const { return *i_obj; }
bool operator()(GameObject* u)
{
if (u && i_obj->IsWithinDistInMap(u, i_range) && u->isSpawned() && u->GetGOInfo())
return true;
return false;
}
private:
WorldObject const* i_obj;
float i_range;
};
class NearestGameObjects : public ObjectGuidListCalculatedValue
{
public:
NearestGameObjects(PlayerbotAI* botAI, float range = sPlayerbotAIConfig->sightDistance, bool ignoreLos = false,
std::string const name = "nearest game objects")
: ObjectGuidListCalculatedValue(botAI, name, 2 * 1000), range(range), ignoreLos(ignoreLos)
: ObjectGuidListCalculatedValue(botAI, name, 1 * 1000), range(range), ignoreLos(ignoreLos)
{
}

View File

@@ -63,3 +63,25 @@ bool PositionValue::Load(std::string const text)
}
WorldPosition CurrentPositionValue::Calculate() { return WorldPosition(bot); }
PositionInfo SinglePositionValue::Calculate()
{
PositionMap& posMap = AI_VALUE(PositionMap&, "position");
return posMap[getQualifier()];
}
void SinglePositionValue::Set(PositionInfo value)
{
PositionMap& posMap = AI_VALUE(PositionMap&, "position");
PositionInfo pos = posMap[getQualifier()];
pos = value;
posMap[getQualifier()] = pos;
}
void SinglePositionValue::Reset()
{
PositionMap& posMap = AI_VALUE(PositionMap&, "position");
PositionInfo pos = posMap[getQualifier()];
pos.Reset();
posMap[getQualifier()] = pos;
}

View File

@@ -6,6 +6,7 @@
#ifndef _PLAYERBOT_POSITIONVALUE_H
#define _PLAYERBOT_POSITIONVALUE_H
#include "NamedObjectContext.h"
#include "TravelMgr.h"
#include "Value.h"
@@ -15,6 +16,10 @@ class PositionInfo
{
public:
PositionInfo() : valueSet(false), x(0), y(0), z(0), mapId(0) {}
PositionInfo(float x, float y, float z, uint32 mapId, bool valueSet = true)
: valueSet(valueSet), x(x), y(y), z(z), mapId(mapId)
{
}
PositionInfo(PositionInfo const& other)
: valueSet(other.valueSet), x(other.x), y(other.y), z(other.z), mapId(other.mapId)
{
@@ -72,4 +77,13 @@ public:
WorldPosition Calculate() override;
};
class SinglePositionValue : public CalculatedValue<PositionInfo>, public Qualified
{
public:
SinglePositionValue(PlayerbotAI* ai, std::string name = "pos") : CalculatedValue(ai, name), Qualified() {};
virtual PositionInfo Calculate() override;
virtual void Set(PositionInfo value) override;
virtual void Reset() override;
};
#endif

View File

@@ -8,8 +8,11 @@
#include "CellImpl.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "ObjectGuid.h"
#include "Playerbots.h"
#include "ServerFacade.h"
#include "SharedDefines.h"
#include "NearestGameObjects.h"
std::vector<uint32> PossibleRpgTargetsValue::allowedNpcFlags;
@@ -78,3 +81,125 @@ bool PossibleRpgTargetsValue::AcceptUnit(Unit* unit)
return false;
}
std::vector<uint32> PossibleNewRpgTargetsValue::allowedNpcFlags;
PossibleNewRpgTargetsValue::PossibleNewRpgTargetsValue(PlayerbotAI* botAI, float range)
: NearestUnitsValue(botAI, "possible new rpg targets", range, true)
{
if (allowedNpcFlags.empty())
{
allowedNpcFlags.push_back(UNIT_NPC_FLAG_INNKEEPER);
allowedNpcFlags.push_back(UNIT_NPC_FLAG_GOSSIP);
allowedNpcFlags.push_back(UNIT_NPC_FLAG_QUESTGIVER);
allowedNpcFlags.push_back(UNIT_NPC_FLAG_FLIGHTMASTER);
allowedNpcFlags.push_back(UNIT_NPC_FLAG_BANKER);
allowedNpcFlags.push_back(UNIT_NPC_FLAG_GUILD_BANKER);
allowedNpcFlags.push_back(UNIT_NPC_FLAG_TRAINER_CLASS);
allowedNpcFlags.push_back(UNIT_NPC_FLAG_TRAINER_PROFESSION);
allowedNpcFlags.push_back(UNIT_NPC_FLAG_VENDOR_AMMO);
allowedNpcFlags.push_back(UNIT_NPC_FLAG_VENDOR_FOOD);
allowedNpcFlags.push_back(UNIT_NPC_FLAG_VENDOR_POISON);
allowedNpcFlags.push_back(UNIT_NPC_FLAG_VENDOR_REAGENT);
allowedNpcFlags.push_back(UNIT_NPC_FLAG_AUCTIONEER);
allowedNpcFlags.push_back(UNIT_NPC_FLAG_STABLEMASTER);
allowedNpcFlags.push_back(UNIT_NPC_FLAG_PETITIONER);
allowedNpcFlags.push_back(UNIT_NPC_FLAG_TABARDDESIGNER);
allowedNpcFlags.push_back(UNIT_NPC_FLAG_BATTLEMASTER);
allowedNpcFlags.push_back(UNIT_NPC_FLAG_TRAINER);
allowedNpcFlags.push_back(UNIT_NPC_FLAG_VENDOR);
allowedNpcFlags.push_back(UNIT_NPC_FLAG_REPAIR);
}
}
GuidVector PossibleNewRpgTargetsValue::Calculate()
{
std::list<Unit*> targets;
FindUnits(targets);
GuidVector results;
std::vector<std::pair<ObjectGuid, float>> guidDistancePairs;
for (Unit* unit : targets)
{
if (AcceptUnit(unit) && (ignoreLos || bot->IsWithinLOSInMap(unit)))
guidDistancePairs.push_back({unit->GetGUID(), bot->GetExactDist(unit)});
}
// Override to sort by distance
std::sort(guidDistancePairs.begin(), guidDistancePairs.end(), [](const auto& a, const auto& b) {
return a.second < b.second;
});
for (const auto& pair : guidDistancePairs) {
results.push_back(pair.first);
}
return results;
}
void PossibleNewRpgTargetsValue::FindUnits(std::list<Unit*>& targets)
{
Acore::AnyUnitInObjectRangeCheck u_check(bot, range);
Acore::UnitListSearcher<Acore::AnyUnitInObjectRangeCheck> searcher(bot, targets, u_check);
Cell::VisitAllObjects(bot, searcher, range);
}
bool PossibleNewRpgTargetsValue::AcceptUnit(Unit* unit)
{
if (unit->IsHostileTo(bot) || unit->GetTypeId() == TYPEID_PLAYER)
return false;
if (unit->HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITHEALER))
return false;
for (uint32 npcFlag : allowedNpcFlags)
{
if (unit->HasFlag(UNIT_NPC_FLAGS, npcFlag))
return true;
}
return false;
}
std::vector<GameobjectTypes> PossibleNewRpgGameObjectsValue::allowedGOFlags;
GuidVector PossibleNewRpgGameObjectsValue::Calculate()
{
std::list<GameObject*> targets;
AnyGameObjectInObjectRangeCheck u_check(bot, range);
Acore::GameObjectListSearcher<AnyGameObjectInObjectRangeCheck> searcher(bot, targets, u_check);
Cell::VisitAllObjects(bot, searcher, range);
std::vector<std::pair<ObjectGuid, float>> guidDistancePairs;
for (GameObject* go : targets)
{
bool flagCheck = false;
for (uint32 goFlag : allowedGOFlags)
{
if (go->GetGoType() == goFlag)
{
flagCheck = true;
break;
}
}
if (!flagCheck)
continue;
if (!ignoreLos && !bot->IsWithinLOSInMap(go))
continue;
guidDistancePairs.push_back({go->GetGUID(), bot->GetExactDist(go)});
}
GuidVector results;
// Sort by distance
std::sort(guidDistancePairs.begin(), guidDistancePairs.end(), [](const auto& a, const auto& b) {
return a.second < b.second;
});
for (const auto& pair : guidDistancePairs) {
results.push_back(pair.first);
}
return results;
}

View File

@@ -6,8 +6,10 @@
#ifndef _PLAYERBOT_POSSIBLERPGTARGETSVALUE_H
#define _PLAYERBOT_POSSIBLERPGTARGETSVALUE_H
#include "NearestGameObjects.h"
#include "NearestUnitsValue.h"
#include "PlayerbotAIConfig.h"
#include "SharedDefines.h"
class PlayerbotAI;
@@ -23,4 +25,36 @@ protected:
bool AcceptUnit(Unit* unit) override;
};
class PossibleNewRpgTargetsValue : public NearestUnitsValue
{
public:
PossibleNewRpgTargetsValue(PlayerbotAI* botAI, float range = 150.0f);
static std::vector<uint32> allowedNpcFlags;
GuidVector Calculate() override;
protected:
void FindUnits(std::list<Unit*>& targets) override;
bool AcceptUnit(Unit* unit) override;
};
class PossibleNewRpgGameObjectsValue : public ObjectGuidListCalculatedValue
{
public:
PossibleNewRpgGameObjectsValue(PlayerbotAI* botAI, float range = 150.0f, bool ignoreLos = true)
: ObjectGuidListCalculatedValue(botAI, "possible new rpg game objects"), range(range), ignoreLos(ignoreLos)
{
if (allowedGOFlags.empty())
{
allowedGOFlags.push_back(GAMEOBJECT_TYPE_QUESTGIVER);
}
}
static std::vector<GameobjectTypes> allowedGOFlags;
GuidVector Calculate() override;
private:
float range;
bool ignoreLos;
};
#endif

View File

@@ -118,6 +118,8 @@ public:
creators["prioritized targets"] = &ValueContext::prioritized_targets;
creators["all targets"] = &ValueContext::all_targets;
creators["possible rpg targets"] = &ValueContext::possible_rpg_targets;
creators["possible new rpg targets"] = &ValueContext::possible_new_rpg_targets;
creators["possible new rpg game objects"] = &ValueContext::possible_new_rpg_game_objects;
creators["nearest adds"] = &ValueContext::nearest_adds;
creators["nearest corpses"] = &ValueContext::nearest_corpses;
creators["log level"] = &ValueContext::log_level;
@@ -192,6 +194,7 @@ public:
creators["rti cc"] = &ValueContext::rti_cc;
creators["rti"] = &ValueContext::rti;
creators["position"] = &ValueContext::position;
creators["pos"] = &ValueContext::pos;
creators["current position"] = &ValueContext::current_position;
creators["threat"] = &ValueContext::threat;
@@ -340,6 +343,7 @@ private:
static UntypedValue* attackers(PlayerbotAI* botAI) { return new AttackersValue(botAI); }
static UntypedValue* position(PlayerbotAI* botAI) { return new PositionValue(botAI); }
static UntypedValue* pos(PlayerbotAI* ai) { return new SinglePositionValue(ai); }
static UntypedValue* current_position(PlayerbotAI* botAI) { return new CurrentPositionValue(botAI); }
static UntypedValue* rti(PlayerbotAI* botAI) { return new RtiValue(botAI); }
static UntypedValue* rti_cc(PlayerbotAI* botAI) { return new RtiCcValue(botAI); }
@@ -406,6 +410,8 @@ private:
static UntypedValue* nearest_enemy_players(PlayerbotAI* botAI) { return new NearestEnemyPlayersValue(botAI); }
static UntypedValue* nearest_corpses(PlayerbotAI* botAI) { return new NearestCorpsesValue(botAI); }
static UntypedValue* possible_rpg_targets(PlayerbotAI* botAI) { return new PossibleRpgTargetsValue(botAI); }
static UntypedValue* possible_new_rpg_targets(PlayerbotAI* botAI) { return new PossibleNewRpgTargetsValue(botAI); }
static UntypedValue* possible_new_rpg_game_objects(PlayerbotAI* botAI) { return new PossibleNewRpgGameObjectsValue(botAI); }
static UntypedValue* possible_targets(PlayerbotAI* botAI) { return new PossibleTargetsValue(botAI); }
static UntypedValue* possible_triggers(PlayerbotAI* botAI) { return new PossibleTriggersValue(botAI); }
static UntypedValue* possible_targets_no_los(PlayerbotAI* botAI)