|
| 1 | +#include "Playerbots.h" |
| 2 | +#include "TrialOfTheChampionActions.h" |
| 3 | +#include "TrialOfTheChampionStrategy.h" |
| 4 | +#include "strategy/values/NearestNpcsValue.h" |
| 5 | +#include "ObjectAccessor.h" |
| 6 | +#include "Timer.h" |
| 7 | +#include "Vehicle.h" |
| 8 | +#include "GenericSpellActions.h" |
| 9 | +#include "GenericActions.h" |
| 10 | +#include <fstream> |
| 11 | + |
| 12 | + |
| 13 | +bool ToCLanceAction::Execute(Event event) |
| 14 | +{ |
| 15 | + // If already has lance equipped, do nothing |
| 16 | + if (bot->HasItemOrGemWithIdEquipped(ITEM_LANCE, 1)) |
| 17 | + return false; |
| 18 | + |
| 19 | + // Store current mainhand item |
| 20 | + Item* oldWeapon = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); |
| 21 | + |
| 22 | + // Search inventory for the lance item |
| 23 | + Item* lanceItem = nullptr; |
| 24 | + |
| 25 | + // Check main inventory |
| 26 | + for (uint8 slot = INVENTORY_SLOT_ITEM_START; slot < INVENTORY_SLOT_ITEM_END; slot++) |
| 27 | + { |
| 28 | + Item* item = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, slot); |
| 29 | + if (item && item->GetEntry() == ITEM_LANCE) |
| 30 | + { |
| 31 | + lanceItem = item; |
| 32 | + break; |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + // Check bags if not found in main inventory |
| 37 | + if (!lanceItem) |
| 38 | + { |
| 39 | + for (uint8 bag = INVENTORY_SLOT_BAG_START; bag < INVENTORY_SLOT_BAG_END; bag++) |
| 40 | + { |
| 41 | + Bag* pBag = bot->GetBagByPos(bag); |
| 42 | + if (pBag) |
| 43 | + { |
| 44 | + for (uint8 slot = 0; slot < pBag->GetBagSize(); slot++) |
| 45 | + { |
| 46 | + Item* item = bot->GetItemByPos(bag, slot); |
| 47 | + if (item && item->GetEntry() == ITEM_LANCE) |
| 48 | + { |
| 49 | + lanceItem = item; |
| 50 | + break; |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + if (lanceItem) |
| 55 | + break; |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + // If we found the lance, equip it |
| 60 | + if (lanceItem) |
| 61 | + { |
| 62 | + // Store the lance's current position |
| 63 | + uint8 srcBag = lanceItem->GetBagSlot(); |
| 64 | + uint8 srcSlot = lanceItem->GetSlot(); |
| 65 | + |
| 66 | + // First unequip current weapon if it exists |
| 67 | + if (oldWeapon) |
| 68 | + { |
| 69 | + bot->SwapItem(oldWeapon->GetPos(), lanceItem->GetPos()); |
| 70 | + } |
| 71 | + else |
| 72 | + { |
| 73 | + bot->EquipItem(EQUIPMENT_SLOT_MAINHAND, lanceItem, true); |
| 74 | + } |
| 75 | + return true; |
| 76 | + } |
| 77 | + |
| 78 | + if (bot->HasItemCount(ITEM_LANCE, 1)) |
| 79 | + return false; |
| 80 | + |
| 81 | + GameObject* lanceRack = bot->FindNearestGameObject(OBJECT_LANCE_RACK, 100.0f); |
| 82 | + if (!lanceRack) |
| 83 | + return false; |
| 84 | + |
| 85 | + if (!lanceRack->IsWithinDistInMap(bot, INTERACTION_DISTANCE)) |
| 86 | + return MoveTo(lanceRack, INTERACTION_DISTANCE); |
| 87 | + |
| 88 | + botAI->RemoveShapeshift(); |
| 89 | + bot->GetMotionMaster()->Clear(); |
| 90 | + bot->StopMoving(); |
| 91 | + lanceRack->Use(bot); |
| 92 | + |
| 93 | + return false; |
| 94 | +} |
| 95 | + |
| 96 | +bool ToCUELanceAction::Execute(Event event) |
| 97 | +{ |
| 98 | + if (!bot->HasItemOrGemWithIdEquipped(ITEM_LANCE, 1)) |
| 99 | + return false; |
| 100 | + |
| 101 | + // Call EquipUpgradeAction |
| 102 | + EquipUpgradeAction equipUpgradeAction(botAI); |
| 103 | + if (!equipUpgradeAction.Execute(event)) |
| 104 | + return false; |
| 105 | + |
| 106 | + return false; |
| 107 | +} |
| 108 | + |
| 109 | +bool ToCMountedAction::Execute(Event event) |
| 110 | +{ |
| 111 | + Unit* vehicleBase = bot->GetVehicleBase(); |
| 112 | + Vehicle* vehicle = bot->GetVehicle(); |
| 113 | + if (!vehicleBase || !vehicle) |
| 114 | + return false; |
| 115 | + |
| 116 | + GuidVector attackers = AI_VALUE(GuidVector, "possible targets no los"); |
| 117 | + |
| 118 | + Unit* target = nullptr; |
| 119 | + for (auto i = attackers.begin(); i != attackers.end(); ++i) |
| 120 | + { |
| 121 | + Unit* unit = botAI->GetUnit(*i); |
| 122 | + if (!unit) |
| 123 | + continue; |
| 124 | + for (uint32 entry : availableTargets) |
| 125 | + { |
| 126 | + if (unit->GetEntry() == entry) |
| 127 | + { |
| 128 | + target = unit; |
| 129 | + break; |
| 130 | + } |
| 131 | + } |
| 132 | + if (target) |
| 133 | + break; |
| 134 | + } |
| 135 | + |
| 136 | + Aura* defendBot = botAI->GetAura("defend", bot, false, true); |
| 137 | + if (!defendBot || defendBot->GetStackAmount() < 3) |
| 138 | + { |
| 139 | + uint32 spellId = AI_VALUE2(uint32, "vehicle spell id", "Defend"); |
| 140 | + if (botAI->CanCastVehicleSpell(spellId, target) && botAI->CastVehicleSpell(spellId, target)) |
| 141 | + { |
| 142 | + vehicleBase->AddSpellCooldown(spellId, 0, 1000); |
| 143 | + return true; |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + if (!target) |
| 148 | + return false; |
| 149 | + |
| 150 | + if (target->GetDistance2d(bot) > 5.0f) |
| 151 | + { |
| 152 | + uint32 spellId = AI_VALUE2(uint32, "vehicle spell id", "Charge"); |
| 153 | + if (botAI->CanCastVehicleSpell(spellId, target) && botAI->CastVehicleSpell(spellId, target)) |
| 154 | + { |
| 155 | + vehicleBase->AddSpellCooldown(spellId, 0, 1000); |
| 156 | + return true; |
| 157 | + } |
| 158 | + } |
| 159 | + |
| 160 | + Aura* defendTarget = botAI->GetAura("defend", target, false, false); |
| 161 | + if (!defendTarget) |
| 162 | + {} |
| 163 | + else |
| 164 | + { |
| 165 | + uint32 spellId = AI_VALUE2(uint32, "vehicle spell id", "Shield-Breaker"); |
| 166 | + if (botAI->CanCastVehicleSpell(spellId, target) && botAI->CastVehicleSpell(spellId, target)) |
| 167 | + { |
| 168 | + vehicleBase->AddSpellCooldown(spellId, 0, 1000); |
| 169 | + return true; |
| 170 | + } |
| 171 | + } |
| 172 | + |
| 173 | + uint32 spellId = AI_VALUE2(uint32, "vehicle spell id", "Thrust"); |
| 174 | + if (botAI->CanCastVehicleSpell(spellId, target) && botAI->CastVehicleSpell(spellId, target)) |
| 175 | + { |
| 176 | + vehicleBase->AddSpellCooldown(spellId, 0, 1000); |
| 177 | + return true; |
| 178 | + } |
| 179 | + |
| 180 | + return false; |
| 181 | +} |
| 182 | + |
| 183 | +bool ToCMountAction::Execute(Event event) |
| 184 | +{ |
| 185 | + // do not switch vehicles yet |
| 186 | + if (bot->GetVehicle()) |
| 187 | + return false; |
| 188 | + |
| 189 | + Unit* vehicleToEnter = nullptr; |
| 190 | + GuidVector npcs = AI_VALUE(GuidVector, "nearest vehicles"); |
| 191 | + for (GuidVector::iterator i = npcs.begin(); i != npcs.end(); i++) |
| 192 | + { |
| 193 | + Unit* vehicleBase = botAI->GetUnit(*i); |
| 194 | + if (!vehicleBase) |
| 195 | + continue; |
| 196 | + |
| 197 | + if (vehicleBase->HasUnitFlag(UNIT_FLAG_NOT_SELECTABLE)) |
| 198 | + continue; |
| 199 | + |
| 200 | + if (!vehicleBase->IsFriendlyTo(bot)) |
| 201 | + continue; |
| 202 | + |
| 203 | + if (!vehicleBase->GetVehicleKit() || !vehicleBase->GetVehicleKit()->GetAvailableSeatCount()) |
| 204 | + continue; |
| 205 | + |
| 206 | + uint32 entry = vehicleBase->GetEntry(); |
| 207 | + if (entry != NPC_ARGENT_BATTLEWORG && entry != NPC_ARGENT_WARHORSE) |
| 208 | + continue; |
| 209 | + |
| 210 | + if (!vehicleToEnter || bot->GetExactDist(vehicleToEnter) > bot->GetExactDist(vehicleBase)) |
| 211 | + vehicleToEnter = vehicleBase; |
| 212 | + } |
| 213 | + |
| 214 | + if (!vehicleToEnter) |
| 215 | + return false; |
| 216 | + |
| 217 | + if (EnterVehicle(vehicleToEnter, true)) |
| 218 | + return true; |
| 219 | + |
| 220 | + return false; |
| 221 | +} |
| 222 | + |
| 223 | +bool ToCMountAction::EnterVehicle(Unit* vehicleBase, bool moveIfFar) |
| 224 | +{ |
| 225 | + float dist = bot->GetDistance(vehicleBase); |
| 226 | + |
| 227 | + if (dist > INTERACTION_DISTANCE && !moveIfFar) |
| 228 | + return false; |
| 229 | + |
| 230 | + if (dist > INTERACTION_DISTANCE) |
| 231 | + return MoveTo(vehicleBase); |
| 232 | + |
| 233 | + botAI->RemoveShapeshift(); |
| 234 | + |
| 235 | + bot->GetMotionMaster()->Clear(); |
| 236 | + bot->StopMoving(); |
| 237 | + vehicleBase->HandleSpellClick(bot); |
| 238 | + |
| 239 | + if (!bot->IsOnVehicle(vehicleBase)) |
| 240 | + return false; |
| 241 | + |
| 242 | + // dismount because bots can enter vehicle on mount |
| 243 | + WorldPacket emptyPacket; |
| 244 | + bot->GetSession()->HandleCancelMountAuraOpcode(emptyPacket); |
| 245 | + return true; |
| 246 | +} |
| 247 | + |
| 248 | +bool ToCEadricAction::Execute(Event event) |
| 249 | +{ |
| 250 | + Unit* boss = AI_VALUE2(Unit*, "find target", "eadric the pure"); |
| 251 | + if (!boss) |
| 252 | + return false; |
| 253 | + |
| 254 | + // If Eadric is casting Radiance, face the opposite direction |
| 255 | + if (boss->HasUnitState(UNIT_STATE_CASTING) && boss->FindCurrentSpellBySpellId(SPELL_RADIANCE)) |
| 256 | + { |
| 257 | + // Calculate the opposite direction |
| 258 | + float angle = bot->GetAngle(boss); |
| 259 | + float newAngle = Position::NormalizeOrientation(angle + M_PI); // Add 180 degrees (PI radians) |
| 260 | + |
| 261 | + // Set the bot's orientation to face away from Eadric |
| 262 | + bot->SetFacingTo(newAngle); |
| 263 | + return true; |
| 264 | + } |
| 265 | + |
| 266 | + return false; |
| 267 | +} |
0 commit comments