Files
WoW-Hybrid-gateway/tests/native_party_target_cast_test.cpp

81 lines
3.7 KiB
C++

#include "world_translation.hpp"
#include <iostream>
using namespace gateway;
// Turtle ImplicitTarget 37 spells (Prayer of Fortitude 21562 ...) need a unit; the 70334 client
// sends none. The gateway must target the selected visible player (their party gets it) or self.
namespace {
Bytes cast(uint32_t spell, uint32_t flags = 0, const Guid128& unit = {}) {
Guid128 id{}; id[0] = 9;
Bytes bytes = pack_guid(id);
le(bytes, 1, 1);
for (int i = 0; i < 3; ++i) le(bytes, 0, 4);
le(bytes, spell, 4); le(bytes, 0, 4); le(bytes, 0, 4);
le(bytes, flags, 4);
append(bytes, pack_guid(unit));
append(bytes, pack_guid(Guid128{}));
append(bytes, pack_guid(Guid128{}));
le(bytes, 0, 1); le(bytes, 0, 1);
le(bytes, 0, 4); le(bytes, 0, 4);
append(bytes, pack_guid(Guid128{}));
for (int i = 0; i < 3; ++i) le(bytes, 0, 4);
le(bytes, 0, 2);
return bytes;
}
Bytes unit_request(uint32_t spell, uint64_t legacy) {
Bytes out; le(out, spell, 4); le(out, 2, 2);
Bytes raw; le(raw, legacy, 8); append(out, pack_guid(raw));
return out;
}
Bytes no_target(uint32_t spell) { Bytes out; le(out, spell, 4); le(out, 0, 2); return out; }
void check(bool value, const char* message) { if (!value) throw Error(message); }
}
int main() {
try {
NativeWorldTranslation world;
world.realm = 70;
world.selected.guid = 4509;
world.selected.race = 6; world.selected.cls = 5; world.selected.level = 60;
world.self_created = true;
world.location = WorldLocation{1, {0, 0, 0, 0}};
constexpr uint32_t fortitude = 21562, word = 1243;
world.spells.insert(fortitude); world.spells.insert(word);
constexpr uint64_t other = 4600, npc = 0xF130000C2B001234ull;
const auto other_modern = forever_player_guid(other, world.realm);
auto& player = world.entities.actors[other];
player.kind = 4; player.modern = other_modern; player.sent = true; player.eligible = true;
Guid128 npc_modern{}; npc_modern[0] = 0x34; npc_modern[15] = 0x20;
auto& creature = world.entities.actors[npc];
creature.kind = 3; creature.modern = npc_modern; creature.sent = true; creature.eligible = true;
check(world.gameplay(0x3e0176, cast(fortitude)).body == unit_request(fortitude, world.selected.guid),
"solo Prayer of Fortitude did not target the caster");
world.gameplay(0x3f00cd, pack_guid(other_modern));
check(world.gameplay(0x3e0176, cast(fortitude)).body == unit_request(fortitude, other),
"Prayer of Fortitude did not target the selected player's party");
world.gameplay(0x3f00cd, pack_guid(npc_modern));
check(world.gameplay(0x3e0176, cast(fortitude)).body == unit_request(fortitude, world.selected.guid),
"NPC selection was sent as a party-buff unit");
world.gameplay(0x3f00cd, pack_guid(Guid128{}));
check(world.gameplay(0x3e0176, cast(fortitude)).body == unit_request(fortitude, world.selected.guid),
"cleared selection did not fall back to the caster");
// An explicit client unit is kept; spells outside the profile are untouched.
world.gameplay(0x3f00cd, pack_guid(other_modern));
check(world.gameplay(0x3e0176, cast(fortitude, 2, forever_player_guid(world.selected.guid, world.realm))).body ==
unit_request(fortitude, world.selected.guid), "explicit unit was replaced");
check(world.gameplay(0x3e0176, cast(word)).body == no_target(word),
"non-party spell received a synthesized unit");
std::cout << "party-target (ImplicitTarget 37) cast translation PASS\n";
} catch (const std::exception& e) {
std::cerr << e.what() << '\n';
return 1;
}
}