Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4d36c6f702 | |||
| ed017ab51a | |||
| 444b2b9d80 | |||
| 7c092e8a72 |
+2
-1
@@ -124,4 +124,5 @@ __pycache__/
|
||||
# !modules/yourmodule
|
||||
#
|
||||
# ==================
|
||||
.claude
|
||||
.claude
|
||||
!modules/AccountBound
|
||||
|
||||
+13
-2
@@ -145,7 +145,7 @@ import_mythicplus_sql() {
|
||||
WHEN EXISTS (SELECT 1 FROM creature_template WHERE entry = 900001)
|
||||
AND EXISTS (SELECT 1 FROM item_template WHERE entry = 900100)
|
||||
AND EXISTS (SELECT 1 FROM gameobject_template WHERE entry = 900000)
|
||||
AND EXISTS (SELECT 1 FROM creature WHERE id = 900001)
|
||||
AND EXISTS (SELECT 1 FROM creature WHERE id1 = 900001)
|
||||
AND EXISTS (SELECT 1 FROM gameobject WHERE id = 900000)
|
||||
THEN 1
|
||||
ELSE 0
|
||||
@@ -156,7 +156,7 @@ import_mythicplus_sql() {
|
||||
log "repairing MythicPlus world bootstrap entries"
|
||||
mysql_exec "acore_world" "
|
||||
DELETE FROM creature WHERE id = 900001;
|
||||
DELETE FROM gameobject WHERE id = 900000;
|
||||
DELETE FROM gameobject WHERE id1 = 900000;
|
||||
DELETE FROM creature_template_locale WHERE entry = 900001;
|
||||
DELETE FROM item_template_locale WHERE ID = 900100;
|
||||
DELETE FROM creature_template_model WHERE CreatureID = 900001;
|
||||
@@ -279,6 +279,16 @@ import_playerbots_ru_sql() {
|
||||
import_sql_file "acore_characters" "$names_sql_file"
|
||||
}
|
||||
|
||||
import_transmog_sql() {
|
||||
log "Started importing Transmogrification SQL files"
|
||||
|
||||
local account_transmog_sql="$ROOT_DIR/sql/Transmogrification/auth.sql"
|
||||
local character_transmog_sql="$ROOT_DIR/sql/Transmogrification/char.sql"
|
||||
|
||||
maybe_import_table "acore_auth" "account_transmog" "$account_transmog_sql"
|
||||
maybe_import_table "acore_characters" "character_transmog" "$character_transmog_sql"
|
||||
}
|
||||
|
||||
configure_server_motd() {
|
||||
log "configuring MoonWell login message"
|
||||
mysql_exec "acore_auth" "
|
||||
@@ -362,6 +372,7 @@ import_aoe_loot_sql
|
||||
import_playerbots_ru_sql
|
||||
import_encounter_journal_sql
|
||||
import_store_sql
|
||||
import_transmog_sql
|
||||
configure_server_motd
|
||||
|
||||
log "custom SQL bootstrap completed"
|
||||
|
||||
@@ -0,0 +1,838 @@
|
||||
-- ╔════════════════════════════════════════════════════════════════════════╗
|
||||
-- ║ Transmog System Eluna Script by DanielTheDeveloper ║
|
||||
-- ╚════════════════════════════════════════════════════════════════════════╝
|
||||
--
|
||||
-- ╔══════════════════════════╗
|
||||
-- ╔══════════════════════║ Transmog System Settings ║══════════════════════╗
|
||||
-- ║ ╚══════════════════════════╝ ║
|
||||
-- ║ Automatically adds transmog appearances to the players account-wide ║
|
||||
-- ║ transmog collection when they equip an item for the first time. ║
|
||||
-- ║ ║
|
||||
-- ║ It is recommended to leave this option enabled. ║
|
||||
-- ╟────────────────────────────────────────────────────────────────────────╢
|
||||
local ADD_NEWLY_EQUIPPED_ITEMS_TO_THE_TRANSMOG_LIST = true --║
|
||||
-- ╟────────────────────────────────────────────────────────────────────────╢
|
||||
-- ║ ║
|
||||
-- ║ Automatically adds transmog appearances to the players account-wide ║
|
||||
-- ║ transmog collection when they loot an item for the first time. ║
|
||||
-- ║ ║
|
||||
-- ║ It is recommended to leave this option disabled as it creates the ║
|
||||
-- ║ potential for a more healthy transmog economy to exist inside the ║
|
||||
-- ║ auction house. ║
|
||||
-- ╟────────────────────────────────────────────────────────────────────────╢
|
||||
local ADD_NEWLY_LOOTED_ITEMS_TO_THE_TRANSMOG_LIST = false --║
|
||||
-- ╟────────────────────────────────────────────────────────────────────────╢
|
||||
-- ║ ║
|
||||
-- ║ Automatically adds all applicable quest reward items as transmog ║
|
||||
-- ║ appearances to the players account-wide transmog collection when ║
|
||||
-- ║ completing a quest, regardless of which quest reward the player ║
|
||||
-- ║ actually decided to select. ║
|
||||
-- ║ ║
|
||||
-- ║ It is recommended to leave this option enabled as it eliminates the ║
|
||||
-- ║ dilemma of deciding between a potential transmog appearance or gear ║
|
||||
-- ║ that is useful for the character. ║
|
||||
-- ╟────────────────────────────────────────────────────────────────────────╢
|
||||
local ADD_QUEST_REWARD_ITEMS_TO_THE_TRANSMOG_LIST = true --║
|
||||
-- ╟────────────────────────────────────────────────────────────────────────╢
|
||||
-- ║ ║
|
||||
-- ║ Restricts armor transmog appearances to items made up of the same ║
|
||||
-- ║ material. As an example, with this option enabled, cloth chest pieces ║
|
||||
-- ║ can only be transmogrified to appear as other cloth chest pieces. ║
|
||||
-- ║ When this option is disabled, cloth chest pieces can be ║
|
||||
-- ║ transmogrified to appear as a cloth, leather, mail, or plate chest ║
|
||||
-- ║ piece. ║
|
||||
-- ║ ║
|
||||
-- ║ It is recommended to leave this option enabled as it leaves the ║
|
||||
-- ║ class fantasy intact. ║
|
||||
-- ╟────────────────────────────────────────────────────────────────────────╢
|
||||
local RESTRICT_ARMOR_TRANSMOG_TO_SIMILAR_MATERIALS = true --║
|
||||
-- ╟────────────────────────────────────────────────────────────────────────╢
|
||||
-- ║ ║
|
||||
-- ║ Restricts weapon transmog appearances to the same weapon. As an ║
|
||||
-- ║ example, with this option enabled, two-handed swords can only be ║
|
||||
-- ║ transmogrified to appear as other two-handed swords. When this option ║
|
||||
-- ║ is disabled, two-handed swords can be transmogrified to appear as a ║
|
||||
-- ║ one-handed sword, staff, polearm, fishing pole, etc. ║
|
||||
-- ║ ║
|
||||
-- ║ It is recommended to leave this option enabled as it leaves the ║
|
||||
-- ║ class fantasy intact. ║
|
||||
-- ╟────────────────────────────────────────────────────────────────────────╢
|
||||
local RESTRICT_WEAPON_TRANSMOG_TO_SIMILAR_WEAPONS = true --║
|
||||
-- ╚════════════════════════════════════════════════════════════════════════╝
|
||||
|
||||
local AIO = AIO or require("AIO")
|
||||
local TransmogrificationHandler = AIO.AddHandlers("TransmogrificationServer", {})
|
||||
|
||||
local SLOTS = 6
|
||||
local CALC = 281
|
||||
local PLAYER_VISIBLE_ITEM_1_ENTRYID = 283 -- Head
|
||||
local PLAYER_VISIBLE_ITEM_3_ENTRYID = 287 -- Shoulder
|
||||
local PLAYER_VISIBLE_ITEM_4_ENTRYID = 289 -- Shirt
|
||||
local PLAYER_VISIBLE_ITEM_5_ENTRYID = 291 -- Chest
|
||||
local PLAYER_VISIBLE_ITEM_6_ENTRYID = 293 -- Waist
|
||||
local PLAYER_VISIBLE_ITEM_7_ENTRYID = 295 -- Legs
|
||||
local PLAYER_VISIBLE_ITEM_8_ENTRYID = 297 -- Feet
|
||||
local PLAYER_VISIBLE_ITEM_9_ENTRYID = 299 -- Wrist
|
||||
local PLAYER_VISIBLE_ITEM_10_ENTRYID = 301 -- Hands
|
||||
local PLAYER_VISIBLE_ITEM_15_ENTRYID = 311 -- Back
|
||||
local PLAYER_VISIBLE_ITEM_16_ENTRYID = 313 -- Main
|
||||
local PLAYER_VISIBLE_ITEM_17_ENTRYID = 315 -- Off
|
||||
local PLAYER_VISIBLE_ITEM_18_ENTRYID = 317 -- Ranged
|
||||
local PLAYER_VISIBLE_ITEM_19_ENTRYID = 319 -- Tabard
|
||||
local UNUSABLE_INVENTORY_TYPES = {[2] = true, [11] = true, [12] = true, [18] = true, [24] = true, [27] = true, [28] = true}
|
||||
|
||||
-- TODO: Add further language support.
|
||||
local localeMessages = {
|
||||
LOOT_ITEM_LOCALE = {
|
||||
[0] = " has been added to your appearance collection.", -- enUS/enGB
|
||||
[3] = " wurde deiner Transmog-Sammlung hinzugefügt.", -- deDE
|
||||
}
|
||||
}
|
||||
|
||||
local function GetLocalizedMessage(messageID, locale, ...)
|
||||
local message = localeMessages[messageID][locale] or localeMessages[messageID][0]
|
||||
if select("#", ...) > 0 then
|
||||
return string.format(message, ...)
|
||||
end
|
||||
return message
|
||||
end
|
||||
|
||||
function Transmog_CalculateSlot(slot)
|
||||
if (slot == 0) then
|
||||
slot = 1
|
||||
elseif (slot >= 2) then
|
||||
slot = slot + 1
|
||||
end
|
||||
return CALC + (slot * 2);
|
||||
end
|
||||
|
||||
function Transmog_CalculateSlotReverse(slot)
|
||||
local reverseSlot = (slot - CALC) / 2
|
||||
if (reverseSlot == 1) then
|
||||
return 0;
|
||||
end
|
||||
return reverseSlot;
|
||||
end
|
||||
|
||||
function Transmog_OnCharacterCreate(event, player)
|
||||
local playerGUID = player:GetGUIDLow()
|
||||
CharDBQuery("INSERT IGNORE INTO `character_transmog` (`player_guid`, `slot`, `item`, `real_item`) VALUES (" .. playerGUID .. ", '" .. PLAYER_VISIBLE_ITEM_1_ENTRYID .. "', NULL, '');") -- Head
|
||||
CharDBQuery("INSERT IGNORE INTO `character_transmog` (`player_guid`, `slot`, `item`, `real_item`) VALUES (" .. playerGUID .. ", '" .. PLAYER_VISIBLE_ITEM_3_ENTRYID .. "', NULL, '');") -- Shoulder
|
||||
CharDBQuery("INSERT IGNORE INTO `character_transmog` (`player_guid`, `slot`, `item`, `real_item`) VALUES (" .. playerGUID .. ", '" .. PLAYER_VISIBLE_ITEM_4_ENTRYID .. "', NULL, '');") -- Shirt
|
||||
CharDBQuery("INSERT IGNORE INTO `character_transmog` (`player_guid`, `slot`, `item`, `real_item`) VALUES (" .. playerGUID .. ", '" .. PLAYER_VISIBLE_ITEM_5_ENTRYID .. "', NULL, '');") -- Chest
|
||||
CharDBQuery("INSERT IGNORE INTO `character_transmog` (`player_guid`, `slot`, `item`, `real_item`) VALUES (" .. playerGUID .. ", '" .. PLAYER_VISIBLE_ITEM_6_ENTRYID .. "', NULL, '');") -- Waist
|
||||
CharDBQuery("INSERT IGNORE INTO `character_transmog` (`player_guid`, `slot`, `item`, `real_item`) VALUES (" .. playerGUID .. ", '" .. PLAYER_VISIBLE_ITEM_7_ENTRYID .. "', NULL, '');") -- Legs
|
||||
CharDBQuery("INSERT IGNORE INTO `character_transmog` (`player_guid`, `slot`, `item`, `real_item`) VALUES (" .. playerGUID .. ", '" .. PLAYER_VISIBLE_ITEM_8_ENTRYID .. "', NULL, '');") -- Feet
|
||||
CharDBQuery("INSERT IGNORE INTO `character_transmog` (`player_guid`, `slot`, `item`, `real_item`) VALUES (" .. playerGUID .. ", '" .. PLAYER_VISIBLE_ITEM_9_ENTRYID .. "', NULL, '');") -- Wrist
|
||||
CharDBQuery("INSERT IGNORE INTO `character_transmog` (`player_guid`, `slot`, `item`, `real_item`) VALUES (" .. playerGUID .. ", '" .. PLAYER_VISIBLE_ITEM_10_ENTRYID .. "', NULL, '');") -- Hands
|
||||
CharDBQuery("INSERT IGNORE INTO `character_transmog` (`player_guid`, `slot`, `item`, `real_item`) VALUES (" .. playerGUID .. ", '" .. PLAYER_VISIBLE_ITEM_15_ENTRYID .. "', NULL, '');") -- Back
|
||||
CharDBQuery("INSERT IGNORE INTO `character_transmog` (`player_guid`, `slot`, `item`, `real_item`) VALUES (" .. playerGUID .. ", '" .. PLAYER_VISIBLE_ITEM_16_ENTRYID .. "', NULL, '');") -- Main
|
||||
CharDBQuery("INSERT IGNORE INTO `character_transmog` (`player_guid`, `slot`, `item`, `real_item`) VALUES (" .. playerGUID .. ", '" .. PLAYER_VISIBLE_ITEM_17_ENTRYID .. "', NULL, '');") -- Off
|
||||
CharDBQuery("INSERT IGNORE INTO `character_transmog` (`player_guid`, `slot`, `item`, `real_item`) VALUES (" .. playerGUID .. ", '" .. PLAYER_VISIBLE_ITEM_18_ENTRYID .. "', NULL, '');") -- Ranged
|
||||
CharDBQuery("INSERT IGNORE INTO `character_transmog` (`player_guid`, `slot`, `item`, `real_item`) VALUES (" .. playerGUID .. ", '" .. PLAYER_VISIBLE_ITEM_19_ENTRYID .. "', NULL, '');") -- Tabard
|
||||
end
|
||||
|
||||
function Transmog_OnCharacterDelete(event, guid)
|
||||
CharDBQuery("DELETE FROM character_transmog WHERE player_guid = " .. guid .. "")
|
||||
end
|
||||
|
||||
function Transmog_OnCharacterLogin(event, player)
|
||||
local playerGUID = player:GetGUIDLow()
|
||||
local playerExistsQuery = CharDBQuery("SELECT COUNT(*) FROM character_transmog WHERE player_guid = " .. playerGUID .. ";")
|
||||
local playerExists = playerExistsQuery:GetUInt32(0) > 0
|
||||
if not playerExists then
|
||||
Transmog_OnCharacterCreate(event, player)
|
||||
end
|
||||
end
|
||||
|
||||
function TransmogrificationHandler.LootItemLocale(player, item, count, locale)
|
||||
local accountGUID = player:GetAccountId()
|
||||
local itemID
|
||||
local itemTemplate
|
||||
|
||||
if type(item) == "number" then
|
||||
itemID = item
|
||||
itemTemplate = GetItemTemplate(itemID)
|
||||
else
|
||||
itemTemplate = item:GetItemTemplate()
|
||||
itemID = itemTemplate:GetItemId()
|
||||
end
|
||||
|
||||
local inventoryType = itemTemplate:GetInventoryType()
|
||||
local inventorySubType = itemTemplate:GetSubClass()
|
||||
local class = itemTemplate:GetClass()
|
||||
|
||||
if (class == 2 or class == 4) and not UNUSABLE_INVENTORY_TYPES[inventoryType] then
|
||||
local countQuery = AuthDBQuery("SELECT COUNT(*) FROM account_transmog WHERE account_id = " .. accountGUID .. " AND unlocked_item_id = " .. itemID .. ";")
|
||||
local count = countQuery:GetUInt32(0)
|
||||
local isNewTransmog = (count == 0)
|
||||
|
||||
local displayID = itemTemplate:GetDisplayId()
|
||||
|
||||
local displayExistsQuery = AuthDBQuery("SELECT COUNT(*) FROM account_transmog WHERE account_id = " .. accountGUID .. " AND display_id = " .. displayID .. ";")
|
||||
local displayExists = displayExistsQuery:GetUInt32(0) > 0
|
||||
|
||||
if isNewTransmog and not displayExists then
|
||||
local itemName = itemTemplate:GetName()
|
||||
local locItemName = itemTemplate:GetName(locale)
|
||||
local itemQuality = itemTemplate:GetQuality()
|
||||
|
||||
itemName = itemName:gsub("'", "''")
|
||||
AuthDBQuery("INSERT IGNORE INTO `account_transmog` (`account_id`, `unlocked_item_id`, `inventory_type`, `inventory_subtype`,`display_id`, `item_name`) VALUES (" .. accountGUID .. ", " .. itemID .. ", " .. inventoryType .. ", " .. inventorySubType .. ", " .. displayID .. ", '" .. itemName .. "');")
|
||||
|
||||
if locItemName == nil then
|
||||
locItemName = itemTemplate:GetName(0)
|
||||
end
|
||||
|
||||
local qualityColors = {
|
||||
[0] = "|cff9d9d9d", -- Poor
|
||||
[1] = "|cffffffff", -- Common
|
||||
[2] = "|cff1eff00", -- Uncommon
|
||||
[3] = "|cff0070dd", -- Rare
|
||||
[4] = "|cffa335ee", -- Epic
|
||||
[5] = "|cffff8000", -- Legendary
|
||||
[6] = "|cffe6cc80" -- Heirloom
|
||||
}
|
||||
|
||||
local colorCode = qualityColors[itemQuality] or "|cffffffff" -- Default to white if quality not found
|
||||
|
||||
local itemLink = "|Hitem:" .. itemID .. ":0:0:0:0:0:0:0:0|h" .. colorCode .. "[" .. locItemName .. "]|r|h|r"
|
||||
player:SendBroadcastMessage(itemLink .. GetLocalizedMessage("LOOT_ITEM_LOCALE", locale))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function GetDisplaySlotForEquipmentSlot(equipSlot)
|
||||
local slotMapping = {
|
||||
[0] = PLAYER_VISIBLE_ITEM_1_ENTRYID, -- Head
|
||||
[2] = PLAYER_VISIBLE_ITEM_3_ENTRYID, -- Shoulders
|
||||
[3] = PLAYER_VISIBLE_ITEM_4_ENTRYID, -- Shirt
|
||||
[4] = PLAYER_VISIBLE_ITEM_5_ENTRYID, -- Chest
|
||||
[5] = PLAYER_VISIBLE_ITEM_6_ENTRYID, -- Waist
|
||||
[6] = PLAYER_VISIBLE_ITEM_7_ENTRYID, -- Legs
|
||||
[7] = PLAYER_VISIBLE_ITEM_8_ENTRYID, -- Feet
|
||||
[8] = PLAYER_VISIBLE_ITEM_9_ENTRYID, -- Wrists
|
||||
[9] = PLAYER_VISIBLE_ITEM_10_ENTRYID, -- Hands
|
||||
[14] = PLAYER_VISIBLE_ITEM_15_ENTRYID, -- Back
|
||||
[15] = PLAYER_VISIBLE_ITEM_16_ENTRYID, -- Main Hand
|
||||
[16] = PLAYER_VISIBLE_ITEM_17_ENTRYID, -- Off Hand
|
||||
[17] = PLAYER_VISIBLE_ITEM_18_ENTRYID, -- Ranged
|
||||
[18] = PLAYER_VISIBLE_ITEM_19_ENTRYID -- Tabard
|
||||
}
|
||||
|
||||
return slotMapping[equipSlot]
|
||||
end
|
||||
|
||||
function Transmog_OnEquipItem(event, player, item, bag, slot)
|
||||
local itemID = item:GetItemTemplate():GetItemId()
|
||||
local locale = player:GetDbLocaleIndex()
|
||||
|
||||
if ADD_NEWLY_EQUIPPED_ITEMS_TO_THE_TRANSMOG_LIST then
|
||||
TransmogrificationHandler.LootItemLocale(player, itemID, 1, locale)
|
||||
end
|
||||
|
||||
local class = item:GetItemTemplate():GetClass()
|
||||
local inventoryType = item:GetItemTemplate():GetInventoryType()
|
||||
|
||||
if (class == 2 or class == 4) and not UNUSABLE_INVENTORY_TYPES[inventoryType] then
|
||||
local playerGUID = player:GetGUIDLow()
|
||||
local displaySlot = GetDisplaySlotForEquipmentSlot(slot)
|
||||
|
||||
if displaySlot then
|
||||
CharDBQuery("UPDATE character_transmog SET real_item = " .. itemID .. " WHERE player_guid = " .. playerGUID .. " AND slot = " .. displaySlot)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Transmog_OnLootItem(event, player, item, count)
|
||||
local locale = player:GetDbLocaleIndex()
|
||||
TransmogrificationHandler.LootItemLocale(player, item, 1, locale)
|
||||
end
|
||||
|
||||
function Transmog_OnQuestComplete(event, player, quest)
|
||||
local questID = quest:GetId()
|
||||
local locale = player:GetDbLocaleIndex()
|
||||
|
||||
local questRewardsQuery = WorldDBQuery("SELECT RewardItem1, RewardItem2, RewardItem3, RewardItem4, RewardChoiceItemID1, RewardChoiceItemID2, RewardChoiceItemID3, RewardChoiceItemID4, RewardChoiceItemID5, RewardChoiceItemID6 FROM quest_template WHERE ID = " .. questID .. ";")
|
||||
|
||||
if not questRewardsQuery then
|
||||
return
|
||||
end
|
||||
|
||||
for i = 0, 9 do
|
||||
local itemID = questRewardsQuery:GetUInt32(i)
|
||||
if itemID and itemID > 0 then
|
||||
TransmogrificationHandler.LootItemLocale(player, itemID, 1, locale)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function GetEquipmentSlot(displaySlot)
|
||||
-- Map from display/visual slots to actual equipment slots
|
||||
local slotMapping = {
|
||||
[PLAYER_VISIBLE_ITEM_1_ENTRYID] = 0, -- Head (0 in equipment slot system)
|
||||
[PLAYER_VISIBLE_ITEM_3_ENTRYID] = 2, -- Shoulders
|
||||
[PLAYER_VISIBLE_ITEM_4_ENTRYID] = 3, -- Shirt
|
||||
[PLAYER_VISIBLE_ITEM_5_ENTRYID] = 4, -- Chest
|
||||
[PLAYER_VISIBLE_ITEM_6_ENTRYID] = 5, -- Waist
|
||||
[PLAYER_VISIBLE_ITEM_7_ENTRYID] = 6, -- Legs
|
||||
[PLAYER_VISIBLE_ITEM_8_ENTRYID] = 7, -- Feet
|
||||
[PLAYER_VISIBLE_ITEM_9_ENTRYID] = 8, -- Wrists
|
||||
[PLAYER_VISIBLE_ITEM_10_ENTRYID] = 9, -- Hands
|
||||
[PLAYER_VISIBLE_ITEM_15_ENTRYID] = 14, -- Back/Cloak
|
||||
[PLAYER_VISIBLE_ITEM_16_ENTRYID] = 15, -- Main Hand
|
||||
[PLAYER_VISIBLE_ITEM_17_ENTRYID] = 16, -- Off Hand
|
||||
[PLAYER_VISIBLE_ITEM_18_ENTRYID] = 17, -- Ranged
|
||||
[PLAYER_VISIBLE_ITEM_19_ENTRYID] = 18, -- Tabard
|
||||
}
|
||||
|
||||
return slotMapping[displaySlot] or Transmog_CalculateSlotReverse(displaySlot)
|
||||
end
|
||||
|
||||
-- TODO: add lua/c++ function for unequip!!
|
||||
function TransmogrificationHandler.OnUnequipItem(player)
|
||||
local playerGUID = player:GetGUIDLow()
|
||||
|
||||
-- Check all slots to see if any items were unequipped
|
||||
local slots = {
|
||||
PLAYER_VISIBLE_ITEM_1_ENTRYID, -- Head
|
||||
PLAYER_VISIBLE_ITEM_3_ENTRYID, -- Shoulder
|
||||
PLAYER_VISIBLE_ITEM_4_ENTRYID, -- Shirt
|
||||
PLAYER_VISIBLE_ITEM_5_ENTRYID, -- Chest
|
||||
PLAYER_VISIBLE_ITEM_6_ENTRYID, -- Waist
|
||||
PLAYER_VISIBLE_ITEM_7_ENTRYID, -- Legs
|
||||
PLAYER_VISIBLE_ITEM_8_ENTRYID, -- Feet
|
||||
PLAYER_VISIBLE_ITEM_9_ENTRYID, -- Wrist
|
||||
PLAYER_VISIBLE_ITEM_10_ENTRYID, -- Hands
|
||||
PLAYER_VISIBLE_ITEM_15_ENTRYID, -- Back
|
||||
PLAYER_VISIBLE_ITEM_16_ENTRYID, -- Main
|
||||
PLAYER_VISIBLE_ITEM_17_ENTRYID, -- Off
|
||||
PLAYER_VISIBLE_ITEM_18_ENTRYID, -- Ranged
|
||||
PLAYER_VISIBLE_ITEM_19_ENTRYID -- Tabard
|
||||
}
|
||||
|
||||
for _, slot in ipairs(slots) do
|
||||
-- Get the corresponding equipment slot
|
||||
local equipmentSlot = GetEquipmentSlot(slot)
|
||||
|
||||
-- Check if this slot has an item equipped
|
||||
local currentItem = player:GetEquippedItemBySlot(equipmentSlot)
|
||||
|
||||
-- If the slot is empty but we have a transmog value, we need to clear it
|
||||
if not currentItem then
|
||||
local transmogQuery = CharDBQuery("SELECT item FROM character_transmog WHERE player_guid = "..playerGUID.." AND slot = "..slot..";")
|
||||
|
||||
if transmogQuery and transmogQuery:GetUInt32(0) and transmogQuery:GetUInt32(0) > 0 then
|
||||
-- Clear the transmog by setting both item and real_item to NULL
|
||||
CharDBQuery("UPDATE character_transmog SET item = NULL, real_item = NULL WHERE player_guid = "..playerGUID.." AND slot = "..slot..";")
|
||||
player:SetUInt32Value(tonumber(slot), 0)
|
||||
|
||||
-- Inform the client to update the display for this slot
|
||||
AIO.Handle(player, "TransmogrificationServer", "ClearSlotTransmogrification", slot)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Transmog_Load(player)
|
||||
local playerGUID = player:GetGUIDLow()
|
||||
|
||||
local transmogs = CharDBQuery("SELECT item, slot FROM character_transmog WHERE player_guid = "..playerGUID..";")
|
||||
if (transmogs == nil) then
|
||||
return;
|
||||
end
|
||||
|
||||
for i = 1, transmogs:GetRowCount(), 1 do
|
||||
local currentRow = transmogs:GetRow()
|
||||
local slot = currentRow["slot"]
|
||||
local item = currentRow["item"]
|
||||
if (item ~= nil and item ~= '') then
|
||||
player:SetUInt32Value(tonumber(slot), item)
|
||||
end
|
||||
transmogs:NextRow()
|
||||
end
|
||||
end
|
||||
|
||||
function Transmog_OnLogin(event, player)
|
||||
-- Apply transmog on login
|
||||
-- Transmog_Load(player)
|
||||
--local item = player:GetEquippedItemBySlot(4)
|
||||
--print(item:GetName())
|
||||
end
|
||||
|
||||
function TransmogrificationHandler.LoadPlayer(player)
|
||||
Transmog_Load(player)
|
||||
player:SetUInt32Value(147, 1) -- use unit padding
|
||||
end
|
||||
|
||||
function TransmogrificationHandler.EquipTransmogItem(player, item, slot)
|
||||
local playerGUID = player:GetGUIDLow()
|
||||
|
||||
if item == nil and item ~= 0 then
|
||||
local oldItem = CharDBQuery("SELECT real_item FROM character_transmog WHERE player_guid = "..playerGUID.." AND slot = "..slot..";")
|
||||
local oldItemID = oldItem:GetUInt32(0)
|
||||
if oldItemID == nil or oldItemID == 0 then
|
||||
CharDBQuery("INSERT INTO character_transmog (`player_guid`, `slot`, `item`) VALUES ("..playerGUID..", '"..slot.."', NULL) ON DUPLICATE KEY UPDATE item = VALUES(item);")
|
||||
player:SetUInt32Value(tonumber(slot), 0)
|
||||
return
|
||||
end
|
||||
|
||||
CharDBQuery("INSERT INTO character_transmog (`player_guid`, `slot`, `item`, `real_item`) VALUES ("..playerGUID..", '"..slot.."', NULL, "..oldItemID..") ON DUPLICATE KEY UPDATE item = VALUES(item), real_item = VALUES(real_item);")
|
||||
player:SetUInt32Value(tonumber(slot), oldItemID)
|
||||
return
|
||||
end
|
||||
|
||||
local oldItem = CharDBQuery("SELECT real_item FROM character_transmog WHERE player_guid = "..playerGUID.." AND slot = "..slot..";")
|
||||
local oldItemID = oldItem:GetUInt32(0)
|
||||
if oldItemID == nil or oldItemID == 0 then
|
||||
CharDBQuery("INSERT INTO character_transmog (`player_guid`, `slot`, `item`) VALUES ("..playerGUID..", '"..slot.."', "..item..") ON DUPLICATE KEY UPDATE item = VALUES(item);")
|
||||
else
|
||||
CharDBQuery("INSERT INTO character_transmog (`player_guid`, `slot`, `item`, `real_item`) VALUES ("..playerGUID..", '"..slot.."', "..item..", "..oldItemID..") ON DUPLICATE KEY UPDATE item = VALUES(item), real_item = VALUES(real_item);")
|
||||
end
|
||||
player:SetUInt32Value(tonumber(slot), item)
|
||||
end
|
||||
|
||||
function TransmogrificationHandler.EquipAllTransmogItems(player, transmogPreview)
|
||||
if (transmogPreview == {}) then
|
||||
return;
|
||||
end
|
||||
|
||||
local playerGUID = player:GetGUIDLow()
|
||||
|
||||
for slot, item in ipairs(transmogPreview) do
|
||||
player:SetUInt32Value(tonumber(slot), item)
|
||||
CharDBQuery("INSERT INTO character_transmog (`player_guid`, `slot`, `item`) VALUES ("..playerGUID..", '"..slot.."', "..item..") ON DUPLICATE KEY UPDATE item = VALUES(item);")
|
||||
end
|
||||
end
|
||||
|
||||
function TransmogrificationHandler.UnequipTransmogItem(player, slot)
|
||||
local playerGUID = player:GetGUIDLow()
|
||||
|
||||
-- Get the corresponding equipment slot using our mapping function
|
||||
local equipmentSlot = GetEquipmentSlot(slot)
|
||||
|
||||
-- Check if there's an actual item equipped in this slot
|
||||
local currentItem = player:GetEquippedItemBySlot(equipmentSlot)
|
||||
|
||||
-- If no item is currently equipped, we should set the visual to 0
|
||||
if not currentItem then
|
||||
CharDBQuery("UPDATE character_transmog SET item = NULL, real_item = NULL WHERE player_guid = "..playerGUID.." AND slot = "..slot..";")
|
||||
player:SetUInt32Value(tonumber(slot), 0)
|
||||
return
|
||||
end
|
||||
|
||||
-- Otherwise, handle normally but ensure we're setting to the real item or 0
|
||||
local oldItem = CharDBQuery("SELECT real_item FROM character_transmog WHERE player_guid = "..playerGUID.." AND slot = "..slot..";")
|
||||
|
||||
-- If no record or null real_item, set to the actual item's appearance
|
||||
if not oldItem or not oldItem:GetUInt32(0) or oldItem:GetUInt32(0) == 0 then
|
||||
-- Here we set item to NULL (not 0) to indicate no transmog is applied
|
||||
CharDBQuery("UPDATE character_transmog SET item = NULL WHERE player_guid = "..playerGUID.." AND slot = "..slot..";")
|
||||
|
||||
-- Get the current equipped item's ID to display
|
||||
local realItemID = currentItem:GetItemTemplate():GetItemId()
|
||||
player:SetUInt32Value(tonumber(slot), realItemID)
|
||||
return
|
||||
end
|
||||
|
||||
-- If we have a real_item value, restore that appearance
|
||||
local oldItemID = oldItem:GetUInt32(0)
|
||||
CharDBQuery("UPDATE character_transmog SET item = NULL WHERE player_guid = "..playerGUID.." AND slot = "..slot..";")
|
||||
player:SetUInt32Value(tonumber(slot), oldItemID)
|
||||
end
|
||||
|
||||
function TransmogrificationHandler.displayTransmog(player, spellid)
|
||||
AIO.Handle(player, "TransmogrificationServer", "TransmogrificationFrame")
|
||||
return false
|
||||
end
|
||||
|
||||
function TransmogrificationHandler.Print(player, ...)
|
||||
print(...)
|
||||
end
|
||||
|
||||
function TransmogrificationHandler.SetTransmogItemIDs(player)
|
||||
local playerGUID = player:GetGUIDLow()
|
||||
|
||||
local transmogs = CharDBQuery('SELECT item, real_item, slot FROM character_transmog WHERE player_guid = '..playerGUID..';') -- AND slot NOT IN ("313", "315", "317")
|
||||
if (transmogs == nil) then
|
||||
return;
|
||||
end
|
||||
|
||||
for i = 1, transmogs:GetRowCount(), 1 do
|
||||
local currentRow = transmogs:GetRow()
|
||||
local item = currentRow["item"]
|
||||
local slot = currentRow["slot"]
|
||||
local real_item = currentRow["real_item"]
|
||||
local validSlotItem = player:GetUInt32Value(tonumber(slot))
|
||||
if (validSlotItem == 0) then
|
||||
CharDBQuery("INSERT INTO character_transmog (`player_guid`, `slot`, `item`, `real_item`) VALUES ("..playerGUID..", '"..slot.."', 0, "..real_item..") ON DUPLICATE KEY UPDATE item = VALUES(item), real_item = VALUES(real_item);")
|
||||
end
|
||||
if (not item or item == 0 and real_item ~= nil and real_item ~= 0 and (validSlotItem ~= 0 or not validSlotItem)) then
|
||||
AIO.Handle(player, "TransmogrificationServer", "SetTransmogItemIDClient", slot, 0, real_item)
|
||||
else
|
||||
AIO.Handle(player, "TransmogrificationServer", "SetTransmogItemIDClient", slot, item, real_item)
|
||||
end
|
||||
transmogs:NextRow()
|
||||
end
|
||||
end
|
||||
|
||||
function TransmogrificationHandler.SetCurrentSlotItemIDs(player, slot, page)
|
||||
local accountGUID = player:GetAccountId()
|
||||
|
||||
-- Define inventory type mapping
|
||||
local inventoryTypesMapping = {
|
||||
[PLAYER_VISIBLE_ITEM_1_ENTRYID] = "= 1",
|
||||
[PLAYER_VISIBLE_ITEM_3_ENTRYID] = "= 3",
|
||||
[PLAYER_VISIBLE_ITEM_4_ENTRYID] = "= 4",
|
||||
[PLAYER_VISIBLE_ITEM_5_ENTRYID] = "IN (5, 20)",
|
||||
[PLAYER_VISIBLE_ITEM_6_ENTRYID] = "= 6",
|
||||
[PLAYER_VISIBLE_ITEM_7_ENTRYID] = "= 7",
|
||||
[PLAYER_VISIBLE_ITEM_8_ENTRYID] = "= 8",
|
||||
[PLAYER_VISIBLE_ITEM_9_ENTRYID] = "= 9",
|
||||
[PLAYER_VISIBLE_ITEM_10_ENTRYID] = "= 10",
|
||||
[PLAYER_VISIBLE_ITEM_15_ENTRYID] = "= 16",
|
||||
[PLAYER_VISIBLE_ITEM_16_ENTRYID] = "IN (13, 17, 21)",
|
||||
[PLAYER_VISIBLE_ITEM_17_ENTRYID] = "IN (13, 17, 22, 23, 14)",
|
||||
[PLAYER_VISIBLE_ITEM_18_ENTRYID] = "IN (15, 25, 26)",
|
||||
[PLAYER_VISIBLE_ITEM_19_ENTRYID] = "= 19"
|
||||
}
|
||||
|
||||
-- Get the inventory type for the given slot
|
||||
local inventoryTypes = inventoryTypesMapping[slot]
|
||||
if not inventoryTypes then
|
||||
return -- Slot not valid, exit early
|
||||
end
|
||||
|
||||
local equipmentSlot = nil
|
||||
|
||||
if slot == PLAYER_VISIBLE_ITEM_3_ENTRYID then
|
||||
equipmentSlot = 2 -- Shoulder
|
||||
elseif slot == PLAYER_VISIBLE_ITEM_4_ENTRYID then
|
||||
equipmentSlot = 3 -- Shirt
|
||||
elseif slot == PLAYER_VISIBLE_ITEM_5_ENTRYID then
|
||||
equipmentSlot = 4 -- Chest
|
||||
elseif slot == PLAYER_VISIBLE_ITEM_6_ENTRYID then
|
||||
equipmentSlot = 5 -- Waist
|
||||
elseif slot == PLAYER_VISIBLE_ITEM_10_ENTRYID then
|
||||
equipmentSlot = 9 -- Hands
|
||||
elseif slot == PLAYER_VISIBLE_ITEM_15_ENTRYID then
|
||||
equipmentSlot = 14 -- Back
|
||||
elseif slot == PLAYER_VISIBLE_ITEM_16_ENTRYID then
|
||||
equipmentSlot = 15 -- Main
|
||||
elseif slot == PLAYER_VISIBLE_ITEM_17_ENTRYID then
|
||||
equipmentSlot = 16 -- Off
|
||||
elseif slot == PLAYER_VISIBLE_ITEM_18_ENTRYID then
|
||||
equipmentSlot = 17 -- Ranged
|
||||
else
|
||||
equipmentSlot = Transmog_CalculateSlotReverse(slot)
|
||||
end
|
||||
|
||||
local currentItem = player:GetEquippedItemBySlot(equipmentSlot)
|
||||
local equippedItemType = nil
|
||||
local equippedItemSubType = nil
|
||||
|
||||
if currentItem then
|
||||
equippedItemType = currentItem:GetClass()
|
||||
equippedItemSubType = currentItem:GetSubClass()
|
||||
end
|
||||
|
||||
-- Calculate page offset for pagination
|
||||
local pageOffset = (page > 1) and (SLOTS * (page - 1)) or 0
|
||||
|
||||
local queryConditions = "account_id = " .. accountGUID .. " AND inventory_type " .. inventoryTypes
|
||||
|
||||
if equippedItemSubType then
|
||||
if (RESTRICT_ARMOR_TRANSMOG_TO_SIMILAR_MATERIALS and equippedItemType == 4) then
|
||||
if slot == PLAYER_VISIBLE_ITEM_5_ENTRYID then -- Special check for chestpiece/robes.
|
||||
queryConditions = queryConditions .. " AND inventory_subtype = " .. equippedItemSubType
|
||||
else
|
||||
queryConditions = queryConditions .. " AND inventory_subtype = " .. equippedItemSubType
|
||||
end
|
||||
elseif (RESTRICT_WEAPON_TRANSMOG_TO_SIMILAR_WEAPONS and equippedItemType == 2) then
|
||||
queryConditions = queryConditions .. " AND inventory_subtype = " .. equippedItemSubType
|
||||
end
|
||||
end
|
||||
|
||||
-- Query to count matching transmogs
|
||||
local countQuery = string.format(
|
||||
"SELECT COUNT(unlocked_item_id) FROM account_transmog WHERE %s",
|
||||
queryConditions
|
||||
)
|
||||
local countResult = AuthDBQuery(countQuery)
|
||||
if not countResult then
|
||||
AIO.Handle(player, "TransmogrificationServer", "InitTab", {}, page, false)
|
||||
return
|
||||
end
|
||||
|
||||
-- Get the total number of transmogs
|
||||
local totalTransmogs = countResult:GetUInt32(0)
|
||||
local hasMorePages = (totalTransmogs > SLOTS * page)
|
||||
|
||||
-- Query to retrieve transmogs for the current page
|
||||
local transmogQuery = string.format(
|
||||
"SELECT unlocked_item_id FROM account_transmog WHERE %s LIMIT %d OFFSET %d;",
|
||||
queryConditions, SLOTS, pageOffset
|
||||
)
|
||||
local transmogs = AuthDBQuery(transmogQuery)
|
||||
if not transmogs then
|
||||
AIO.Handle(player, "TransmogrificationServer", "InitTab", {}, page, false)
|
||||
return
|
||||
end
|
||||
|
||||
-- Collect the unlocked item IDs
|
||||
local currentSlotItemIDs = {}
|
||||
for i = 1, transmogs:GetRowCount() do
|
||||
local currentRow = transmogs:GetRow()
|
||||
local item = currentRow["unlocked_item_id"]
|
||||
table.insert(currentSlotItemIDs, item)
|
||||
transmogs:NextRow()
|
||||
end
|
||||
|
||||
-- Return the result to the player
|
||||
AIO.Handle(player, "TransmogrificationServer", "InitTab", currentSlotItemIDs, page, hasMorePages)
|
||||
end
|
||||
|
||||
function TransmogrificationHandler.SetSearchCurrentSlotItemIDs(player, slot, page, search)
|
||||
-- Ensure search is not empty or nil
|
||||
if ( search == nil or serach == '' ) then
|
||||
return;
|
||||
end
|
||||
|
||||
-- Escape special characters in search string
|
||||
search = search:gsub("[%'`&\"]", "%%")
|
||||
|
||||
-- Define slot-to-inventory type mapping
|
||||
local inventoryTypesMapping = {
|
||||
[PLAYER_VISIBLE_ITEM_1_ENTRYID] = "= 1",
|
||||
[PLAYER_VISIBLE_ITEM_3_ENTRYID] = "= 3",
|
||||
[PLAYER_VISIBLE_ITEM_4_ENTRYID] = "= 4",
|
||||
[PLAYER_VISIBLE_ITEM_5_ENTRYID] = "IN (5, 20)",
|
||||
[PLAYER_VISIBLE_ITEM_6_ENTRYID] = "= 6",
|
||||
[PLAYER_VISIBLE_ITEM_7_ENTRYID] = "= 7",
|
||||
[PLAYER_VISIBLE_ITEM_8_ENTRYID] = "= 8",
|
||||
[PLAYER_VISIBLE_ITEM_9_ENTRYID] = "= 9",
|
||||
[PLAYER_VISIBLE_ITEM_10_ENTRYID] = "= 10",
|
||||
[PLAYER_VISIBLE_ITEM_15_ENTRYID] = "= 16",
|
||||
[PLAYER_VISIBLE_ITEM_16_ENTRYID] = "IN (13, 17, 21)",
|
||||
[PLAYER_VISIBLE_ITEM_17_ENTRYID] = "IN (13, 17, 22, 23, 14)",
|
||||
[PLAYER_VISIBLE_ITEM_18_ENTRYID] = "IN (15, 25, 26)",
|
||||
[PLAYER_VISIBLE_ITEM_19_ENTRYID] = "= 19"
|
||||
}
|
||||
|
||||
-- Get inventory type for the given slot
|
||||
local inventoryTypes = inventoryTypesMapping[slot]
|
||||
if not inventoryTypes then
|
||||
return -- Slot not valid
|
||||
end
|
||||
|
||||
local equipmentSlot = nil
|
||||
|
||||
if slot == PLAYER_VISIBLE_ITEM_3_ENTRYID then
|
||||
equipmentSlot = 2 -- Shoulder
|
||||
elseif slot == PLAYER_VISIBLE_ITEM_4_ENTRYID then
|
||||
equipmentSlot = 3 -- Shirt
|
||||
elseif slot == PLAYER_VISIBLE_ITEM_5_ENTRYID then
|
||||
equipmentSlot = 4 -- Chest
|
||||
elseif slot == PLAYER_VISIBLE_ITEM_6_ENTRYID then
|
||||
equipmentSlot = 5 -- Waist
|
||||
elseif slot == PLAYER_VISIBLE_ITEM_10_ENTRYID then
|
||||
equipmentSlot = 9 -- Hands
|
||||
elseif slot == PLAYER_VISIBLE_ITEM_15_ENTRYID then
|
||||
equipmentSlot = 14 -- Back
|
||||
elseif slot == PLAYER_VISIBLE_ITEM_16_ENTRYID then
|
||||
equipmentSlot = 15 -- Main
|
||||
elseif slot == PLAYER_VISIBLE_ITEM_17_ENTRYID then
|
||||
equipmentSlot = 16 -- Off
|
||||
elseif slot == PLAYER_VISIBLE_ITEM_18_ENTRYID then
|
||||
equipmentSlot = 17 -- Ranged
|
||||
else
|
||||
equipmentSlot = Transmog_CalculateSlotReverse(slot)
|
||||
end
|
||||
|
||||
local currentItem = player:GetEquippedItemBySlot(equipmentSlot)
|
||||
local equippedItemType = nil
|
||||
local equippedItemSubType = nil
|
||||
|
||||
if currentItem then
|
||||
equippedItemType = currentItem:GetClass()
|
||||
equippedItemSubType = currentItem:GetSubClass()
|
||||
end
|
||||
|
||||
-- Calculate page offset
|
||||
local pageOffset = (page > 1) and (SLOTS * (page - 1)) or 0
|
||||
|
||||
local queryConditions = "account_id = " .. player:GetAccountId() .. " AND inventory_type " .. inventoryTypes .. " AND (display_id LIKE '%" .. search .. "%' OR item_name LIKE '%" .. search .. "%')"
|
||||
|
||||
if equippedItemSubType then
|
||||
if (RESTRICT_ARMOR_TRANSMOG_TO_SIMILAR_MATERIALS and equippedItemType == 4) then
|
||||
if slot == PLAYER_VISIBLE_ITEM_5_ENTRYID then -- Special check for chestpiece/robes.
|
||||
queryConditions = queryConditions .. " AND inventory_subtype = " .. equippedItemSubType
|
||||
else
|
||||
queryConditions = queryConditions .. " AND inventory_subtype = " .. equippedItemSubType
|
||||
end
|
||||
elseif (RESTRICT_WEAPON_TRANSMOG_TO_SIMILAR_WEAPONS and equippedItemType == 2) then
|
||||
queryConditions = queryConditions .. " AND inventory_subtype = " .. equippedItemSubType
|
||||
end
|
||||
end
|
||||
|
||||
-- Query to count matching transmogs
|
||||
local countQuery = string.format(
|
||||
"SELECT COUNT(unlocked_item_id) FROM account_transmog WHERE %s;",
|
||||
queryConditions
|
||||
)
|
||||
local countResult = AuthDBQuery(countQuery)
|
||||
if not countResult then
|
||||
AIO.Handle(player, "TransmogrificationServer", "InitTab", {}, page, false)
|
||||
return
|
||||
end
|
||||
|
||||
local totalTransmogs = countResult:GetUInt32(0)
|
||||
local hasMorePages = (totalTransmogs > SLOTS * page)
|
||||
|
||||
-- Query to get transmogs
|
||||
local transmogQuery = string.format(
|
||||
"SELECT unlocked_item_id FROM account_transmog WHERE %s LIMIT %d OFFSET %d;",
|
||||
queryConditions, SLOTS, pageOffset
|
||||
)
|
||||
local transmogs = AuthDBQuery(transmogQuery)
|
||||
if not transmogs then
|
||||
AIO.Handle(player, "TransmogrificationServer", "InitTab", {}, page, false)
|
||||
return
|
||||
end
|
||||
|
||||
-- Collect the unlocked item IDs
|
||||
local currentSlotItemIDs = {}
|
||||
for i = 1, transmogs:GetRowCount() do
|
||||
local currentRow = transmogs:GetRow()
|
||||
local item = currentRow["unlocked_item_id"]
|
||||
table.insert(currentSlotItemIDs, item)
|
||||
transmogs:NextRow()
|
||||
end
|
||||
|
||||
-- Return the result
|
||||
AIO.Handle(player, "TransmogrificationServer", "InitTab", currentSlotItemIDs, page, hasMorePages)
|
||||
end
|
||||
|
||||
function TransmogrificationHandler.SetEquipmentTransmogInfo(player, slot, currentSlotTooltip)
|
||||
local playerGUID = player:GetGUIDLow()
|
||||
|
||||
local transmog = CharDBQuery("SELECT COUNT(item) FROM character_transmog WHERE player_guid = "..playerGUID.." AND slot = '"..slot.."';")
|
||||
if (transmog == nil) then
|
||||
return;
|
||||
end
|
||||
|
||||
if (transmog:GetUInt32(0) ~= 0) then
|
||||
AIO.Handle(player, "TransmogrificationServer", "SetEquipmentTransmogInfoClient", currentSlotTooltip)
|
||||
end
|
||||
end
|
||||
|
||||
function TransmogrificationHandler.GetItemsWithSameAppearance(player, itemID)
|
||||
-- Query the server for the display ID of the new item
|
||||
local displayIDQuery = "SELECT displayid FROM item_template WHERE entry = " .. itemID .. ";"
|
||||
local displayIDResult = WorldDBQuery(displayIDQuery)
|
||||
|
||||
if not displayIDResult then
|
||||
return
|
||||
end
|
||||
|
||||
local displayID = displayIDResult:GetUInt32(0)
|
||||
|
||||
-- Find all items with the same display ID
|
||||
local matchingItemsQuery = "SELECT entry FROM item_template WHERE displayid = " .. displayID .. ";"
|
||||
local matchingItemsResult = WorldDBQuery(matchingItemsQuery)
|
||||
|
||||
if not matchingItemsResult then
|
||||
return
|
||||
end
|
||||
|
||||
-- Collect the matching item IDs into a table
|
||||
local matchingItems = {}
|
||||
for i = 1, matchingItemsResult:GetRowCount() do
|
||||
local currentRow = matchingItemsResult:GetRow()
|
||||
local matchingItemID = currentRow["entry"]
|
||||
table.insert(matchingItems, matchingItemID)
|
||||
matchingItemsResult:NextRow()
|
||||
end
|
||||
|
||||
-- Send the matching transmogs to the client
|
||||
AIO.Handle(player, "TransmogrificationServer", "ReceiveMatchingAppearances", itemID, matchingItems)
|
||||
end
|
||||
|
||||
function TransmogrificationHandler.SendCollectedTransmogItemIDs(player)
|
||||
local accountGUID = player:GetAccountId()
|
||||
|
||||
-- Query to retrieve collected transmog display IDs
|
||||
local collectedDisplayIDsQuery = "SELECT DISTINCT display_id FROM account_transmog WHERE account_id = " .. accountGUID .. ";"
|
||||
local displayIDsResult = AuthDBQuery(collectedDisplayIDsQuery)
|
||||
|
||||
if not displayIDsResult then
|
||||
AIO.Handle(player, "TransmogrificationServer", "ReceiveCollectedAppearances", {}, 0)
|
||||
return
|
||||
end
|
||||
|
||||
-- Count the unique appearances.
|
||||
local uniqueAppearancesCount = displayIDsResult:GetRowCount()
|
||||
|
||||
-- Collect the display IDs into a table
|
||||
local collectedDisplayIDs = {}
|
||||
for i = 1, displayIDsResult:GetRowCount() do
|
||||
local currentRow = displayIDsResult:GetRow()
|
||||
local displayID = currentRow["display_id"]
|
||||
table.insert(collectedDisplayIDs, displayID)
|
||||
displayIDsResult:NextRow()
|
||||
end
|
||||
|
||||
local collectedAppearances = {}
|
||||
|
||||
-- For each display ID, find all items that share the appearance
|
||||
for _, displayID in ipairs(collectedDisplayIDs) do
|
||||
local itemsWithDisplayQuery = "SELECT entry FROM item_template WHERE displayid = " .. displayID .. ";"
|
||||
local itemsResult = WorldDBQuery(itemsWithDisplayQuery)
|
||||
|
||||
if itemsResult then
|
||||
for j = 1, itemsResult:GetRowCount() do
|
||||
local itemRow = itemsResult:GetRow()
|
||||
local itemID = itemRow["entry"]
|
||||
table.insert(collectedAppearances, itemID)
|
||||
itemsResult:NextRow()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Send the collected transmogs to the client
|
||||
AIO.Handle(player, "TransmogrificationServer", "ReceiveCollectedAppearances", collectedAppearances, uniqueAppearancesCount)
|
||||
end
|
||||
|
||||
RegisterPlayerEvent(1, Transmog_OnCharacterCreate)
|
||||
RegisterPlayerEvent(2, Transmog_OnCharacterDelete)
|
||||
RegisterPlayerEvent(3, Transmog_OnCharacterLogin)
|
||||
|
||||
RegisterPlayerEvent(29, Transmog_OnEquipItem)
|
||||
|
||||
RegisterPlayerEvent(30, function(event, player, bag, slot)
|
||||
if bag == 255 then
|
||||
TransmogrificationHandler.OnUnequipItem(player)
|
||||
end
|
||||
end)
|
||||
|
||||
if ADD_NEWLY_LOOTED_ITEMS_TO_THE_TRANSMOG_LIST then
|
||||
RegisterPlayerEvent(32, Transmog_OnLootItem)
|
||||
RegisterPlayerEvent(51, Transmog_OnLootItem)
|
||||
RegisterPlayerEvent(52, Transmog_OnLootItem)
|
||||
RegisterPlayerEvent(53, Transmog_OnLootItem)
|
||||
RegisterPlayerEvent(56, Transmog_OnLootItem)
|
||||
end
|
||||
|
||||
if ADD_QUEST_REWARD_ITEMS_TO_THE_TRANSMOG_LIST then
|
||||
RegisterPlayerEvent(54, Transmog_OnQuestComplete)
|
||||
end
|
||||
|
||||
RegisterPlayerEvent(42, function(event, player, command)
|
||||
if command:lower() == "transmog sync" then
|
||||
TransmogrificationHandler.SendCollectedTransmogItemIDs(player)
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end)
|
||||
|
||||
print("[Eluna] Transmog System loaded successfully.")
|
||||
@@ -0,0 +1,6 @@
|
||||
* text=auto
|
||||
*.cpp text eol=lf
|
||||
*.h text eol=lf
|
||||
*.md text eol=lf
|
||||
*.dist text eol=lf
|
||||
*.patch text eol=lf
|
||||
@@ -0,0 +1,15 @@
|
||||
# Build and editor artifacts
|
||||
.vs/
|
||||
.vscode/
|
||||
build/
|
||||
cmake-build-*/
|
||||
*.user
|
||||
*.suo
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
*.obj
|
||||
*.pdb
|
||||
*.log
|
||||
|
||||
# Active server config
|
||||
conf/AccountBound.conf
|
||||
@@ -0,0 +1,27 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to AccountBound are documented in this file.
|
||||
|
||||
## 1.1.0 - 2026-06-06
|
||||
|
||||
- Changed account sharing to silent database-only synchronization.
|
||||
- Removed live `learnSpell()` calls for mounts and companion pets.
|
||||
- Removed live replay of achievements, titles, reputations and friend lists.
|
||||
- Added `SyncOnCreate` support to every shared category.
|
||||
- Enabled startup friend backfill by default.
|
||||
- Removed the optional achievement live-sync core patch.
|
||||
|
||||
## 1.0.0 - 2026-06-06
|
||||
|
||||
- Initial public release.
|
||||
- Added account-wide achievements.
|
||||
- Added account-wide mounts with riding, class and faction checks.
|
||||
- Added account-wide vanity companion pets.
|
||||
- Added account-wide titles.
|
||||
- Added monotonic account-wide reputation sharing.
|
||||
- Added account-wide profession ranks, progress and recipes.
|
||||
- Added configurable support for all 11 primary professions.
|
||||
- Added account-wide friend lists and notes.
|
||||
- Added per-category switches, filters and startup backfill.
|
||||
- Added compatibility with stock AzerothCore and mod-playerbots.
|
||||
- Added optional instant achievement import patch.
|
||||
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
@@ -0,0 +1,482 @@
|
||||
# AccountBound
|
||||
|
||||
AccountBound is an AzerothCore module for WotLK 3.3.5a that shares selected
|
||||
collections and progression systems between eligible characters on the same
|
||||
game account.
|
||||
|
||||
It combines achievements, mounts, companion pets, titles, reputations,
|
||||
professions and friends into one module with one configuration file. Every
|
||||
category can be enabled, disabled and filtered independently.
|
||||
|
||||
## Features
|
||||
|
||||
- Account-wide achievements with faction conversion support.
|
||||
- Account-wide mounts with riding, class and faction requirement checks.
|
||||
- Account-wide vanity companion pets.
|
||||
- Account-wide titles with faction conversion support.
|
||||
- Account-wide reputations that only copy higher standings.
|
||||
- Account-wide profession ranks, skill progress and recipes.
|
||||
- Configurable primary-profession limit up to all 11 WotLK professions.
|
||||
- Account-wide friend lists and friend notes.
|
||||
- Per-category startup backfill for existing realms.
|
||||
- Silent SQL synchronization without learned-spell or collection spam.
|
||||
- Character creation seeding before the character's first login.
|
||||
- Per-category ID allow lists and block lists.
|
||||
- One master switch and one module configuration file.
|
||||
- Uses AzerothCore's existing character tables.
|
||||
- No custom SQL tables are required.
|
||||
|
||||
## Compatibility
|
||||
|
||||
- AzerothCore WotLK 3.3.5a
|
||||
- AzerothCore `master`
|
||||
- `mod-playerbots/azerothcore-wotlk`
|
||||
- Built as a normal source module under `modules/`
|
||||
- Tested with a Release worldserver build on Windows
|
||||
|
||||
The module uses hooks currently available in AzerothCore. Stock AzerothCore
|
||||
does not require a core patch.
|
||||
|
||||
## Silent Database Synchronization
|
||||
|
||||
AccountBound writes shared data directly to AzerothCore's existing character
|
||||
tables. It does not call `learnSpell()` or replay achievements, titles,
|
||||
reputation gains or friend notifications during login.
|
||||
|
||||
The synchronization lifecycle is:
|
||||
|
||||
1. `StartupBackfill` migrates characters that already exist before players can
|
||||
log in.
|
||||
2. `SyncOnCreate` seeds a new character after its initial database save and
|
||||
before its first login.
|
||||
3. Normal gameplay hooks persist newly earned data to the other characters on
|
||||
the account.
|
||||
4. The target character loads the already-persisted rows during its next normal
|
||||
login.
|
||||
|
||||
This prevents login spam. If a requirement changes while a character is
|
||||
already online, such as gaining a higher riding rank, the newly eligible rows
|
||||
are stored immediately and become visible after one relog.
|
||||
|
||||
## Installation
|
||||
|
||||
Clone the repository into the AzerothCore modules directory:
|
||||
|
||||
```bash
|
||||
cd azerothcore-wotlk/modules
|
||||
git clone https://github.com/AlsoNotMehh/AccountBound.git
|
||||
```
|
||||
|
||||
Re-run CMake and rebuild `worldserver`.
|
||||
|
||||
Copy:
|
||||
|
||||
```text
|
||||
modules/AccountBound/conf/AccountBound.conf.dist
|
||||
```
|
||||
|
||||
to:
|
||||
|
||||
```text
|
||||
configs/modules/AccountBound.conf
|
||||
```
|
||||
|
||||
Restart `worldserver`.
|
||||
|
||||
The startup log should contain:
|
||||
|
||||
```text
|
||||
Using modules configuration:
|
||||
> AccountBound.conf
|
||||
```
|
||||
|
||||
## Quick Config
|
||||
|
||||
The master switch controls the entire module:
|
||||
|
||||
```ini
|
||||
AccountBound.Enable = 1
|
||||
```
|
||||
|
||||
Each system has an independent switch:
|
||||
|
||||
```ini
|
||||
AccountBound.Achievements.Enable = 1
|
||||
AccountBound.Mounts.Enable = 1
|
||||
AccountBound.Pets.Enable = 1
|
||||
AccountBound.Titles.Enable = 1
|
||||
AccountBound.Reputations.Enable = 1
|
||||
AccountBound.Professions.Enable = 1
|
||||
AccountBound.Friends.Enable = 1
|
||||
```
|
||||
|
||||
Set any category to `0` to keep it character-specific.
|
||||
|
||||
## Shared Data
|
||||
|
||||
| Category | Shared data |
|
||||
| --- | --- |
|
||||
| Achievements | Completed achievements and completion date |
|
||||
| Mounts | Learned mount spells |
|
||||
| Pets | Vanity companion and minipet spells |
|
||||
| Titles | Known character titles |
|
||||
| Reputations | Highest eligible standing and reputation flags |
|
||||
| Professions | Ranks, current/max skill and learned recipes |
|
||||
| Friends | Friend list entries and notes |
|
||||
|
||||
The module intentionally does not share quests, inventory, gold, currencies,
|
||||
honor, arena rating, instance lockouts, cooldowns, talents, glyphs, action bars,
|
||||
mail, auctions or hunter stable pets.
|
||||
|
||||
Those systems contain character-specific progression, ownership or class data
|
||||
and should not be merged automatically.
|
||||
|
||||
## ID Filters
|
||||
|
||||
Achievements, mounts, pets, titles and reputations support:
|
||||
|
||||
```ini
|
||||
AccountBound.CATEGORY.AllowList = all
|
||||
AccountBound.CATEGORY.BlockList = ""
|
||||
```
|
||||
|
||||
Replace `CATEGORY` with:
|
||||
|
||||
```text
|
||||
Achievements
|
||||
Mounts
|
||||
Pets
|
||||
Titles
|
||||
Reputations
|
||||
```
|
||||
|
||||
`AllowList = all` permits every valid entry.
|
||||
|
||||
`AllowList = none` permits no entries.
|
||||
|
||||
A comma-separated allow list shares only those IDs:
|
||||
|
||||
```ini
|
||||
AccountBound.Mounts.AllowList = 458,470,6648
|
||||
```
|
||||
|
||||
The block list always wins:
|
||||
|
||||
```ini
|
||||
AccountBound.Mounts.AllowList = all
|
||||
AccountBound.Mounts.BlockList = 48778,54729
|
||||
```
|
||||
|
||||
Converted Horde or Alliance equivalents must also pass the configured filter.
|
||||
|
||||
## Achievements
|
||||
|
||||
Recommended defaults:
|
||||
|
||||
```ini
|
||||
AccountBound.Achievements.Enable = 1
|
||||
AccountBound.Achievements.SyncOnCreate = 1
|
||||
AccountBound.Achievements.SyncRealmFirst = 0
|
||||
AccountBound.Achievements.SyncHidden = 0
|
||||
AccountBound.Achievements.ConvertFactionSpecific = 1
|
||||
```
|
||||
|
||||
Realm First achievements are excluded by default because they represent a
|
||||
specific character or realm race.
|
||||
|
||||
Faction-specific achievements are converted with AzerothCore's faction-change
|
||||
mapping when `ConvertFactionSpecific = 1`.
|
||||
|
||||
Achievements are inserted into `character_achievement`. They are never replayed
|
||||
through the live achievement reward path, so the module does not resend
|
||||
announcements, mail, items or title notifications.
|
||||
|
||||
## Mounts
|
||||
|
||||
Recommended defaults:
|
||||
|
||||
```ini
|
||||
AccountBound.Mounts.Enable = 1
|
||||
AccountBound.Mounts.SyncOnCreate = 1
|
||||
AccountBound.Mounts.RespectFactionRestrictions = 1
|
||||
AccountBound.Mounts.ConvertFactionSpecific = 1
|
||||
AccountBound.Mounts.RequireRiding = 1
|
||||
AccountBound.Mounts.RequireClass = 1
|
||||
```
|
||||
|
||||
The module discovers mount spells from spell data and item templates.
|
||||
|
||||
It can enforce:
|
||||
|
||||
- Riding skill requirements.
|
||||
- Class restrictions for class mounts.
|
||||
- Horde and Alliance restrictions.
|
||||
- Same-faction restrictions for class mounts.
|
||||
|
||||
Invalid shared mount rows can be cleaned at startup:
|
||||
|
||||
```ini
|
||||
AccountBound.Mounts.CleanupInvalid = 1
|
||||
```
|
||||
|
||||
## Companion Pets
|
||||
|
||||
The pets category shares vanity companions only:
|
||||
|
||||
```ini
|
||||
AccountBound.Pets.SyncOnCreate = 1
|
||||
AccountBound.Pets.IncludeCompanionSkillLine = 1
|
||||
AccountBound.Pets.IncludeMinipetSummons = 1
|
||||
```
|
||||
|
||||
It detects WotLK companion skill-line spells and custom summons using
|
||||
`SUMMON_TYPE_MINIPET`.
|
||||
|
||||
Hunter stable pets, permanent combat pets and pet talent data are not shared.
|
||||
|
||||
## Titles
|
||||
|
||||
Recommended defaults:
|
||||
|
||||
```ini
|
||||
AccountBound.Titles.Enable = 1
|
||||
AccountBound.Titles.SyncOnCreate = 1
|
||||
AccountBound.Titles.SyncOnSave = 1
|
||||
AccountBound.Titles.SyncRealmFirst = 0
|
||||
AccountBound.Titles.ConvertFactionSpecific = 1
|
||||
```
|
||||
|
||||
Realm First reward titles are excluded by default. Faction-specific titles are
|
||||
converted using AzerothCore's faction-change title mappings.
|
||||
|
||||
## Reputations
|
||||
|
||||
Recommended public-realm defaults:
|
||||
|
||||
```ini
|
||||
AccountBound.Reputations.Enable = 1
|
||||
AccountBound.Reputations.SyncOnCreate = 1
|
||||
AccountBound.Reputations.SyncOnChange = 1
|
||||
AccountBound.Reputations.SameFactionOnly = 1
|
||||
AccountBound.Reputations.ConvertFactionSpecific = 1
|
||||
```
|
||||
|
||||
Reputation sync is monotonic: it copies a standing only when it improves the
|
||||
target character. It never lowers another character's standing.
|
||||
|
||||
Base reputation differences for race and class are respected. Cross-faction
|
||||
sharing can convert supported faction pairs.
|
||||
|
||||
## Professions
|
||||
|
||||
The default configuration allows all 11 WotLK primary professions:
|
||||
|
||||
```ini
|
||||
AccountBound.Professions.MaxPrimaryProfessions = 11
|
||||
AccountBound.Professions.Primary.AllowList = all
|
||||
AccountBound.Professions.Primary.BlockList = ""
|
||||
```
|
||||
|
||||
Accepted English profession names:
|
||||
|
||||
```text
|
||||
alchemy, blacksmithing, enchanting, engineering, herbalism,
|
||||
inscription, jewelcrafting, leatherworking, mining, skinning, tailoring
|
||||
```
|
||||
|
||||
Accepted Spanish aliases:
|
||||
|
||||
```text
|
||||
alquimia, herreria, encantamiento, ingenieria, herboristeria,
|
||||
inscripcion, joyeria, peleteria, mineria, desuello, sastreria
|
||||
```
|
||||
|
||||
Skill IDs are also accepted:
|
||||
|
||||
```text
|
||||
171,164,333,202,182,773,755,165,186,393,197
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```ini
|
||||
AccountBound.Professions.Primary.AllowList = alchemy, enchanting, tailoring
|
||||
AccountBound.Professions.MaxPrimaryProfessions = 3
|
||||
```
|
||||
|
||||
Strict allow-list enforcement is disabled by default:
|
||||
|
||||
```ini
|
||||
AccountBound.Professions.Primary.EnforceAllowedList = 0
|
||||
```
|
||||
|
||||
Warning: enabling it can remove blocked professions from existing characters.
|
||||
|
||||
Account-wide profession settings:
|
||||
|
||||
```ini
|
||||
AccountBound.Professions.SyncOnCreate = 1
|
||||
AccountBound.Professions.SyncSkillProgress = 1
|
||||
AccountBound.Professions.SyncProfessionRanks = 1
|
||||
AccountBound.Professions.SyncRecipes = 1
|
||||
AccountBound.Professions.SyncSkillGrantedSpells = 1
|
||||
AccountBound.Professions.IncludeSecondaryProfessions = 1
|
||||
AccountBound.Professions.RequireRecipeSkill = 1
|
||||
```
|
||||
|
||||
Custom recipe spells can be explicitly allowed or blocked:
|
||||
|
||||
```ini
|
||||
AccountBound.Professions.SpellAllowList = 900001,900002
|
||||
AccountBound.Professions.SpellBlockList = 20219,20222
|
||||
```
|
||||
|
||||
## Friends
|
||||
|
||||
The friends category mirrors the normal character friend list across every
|
||||
character on an account:
|
||||
|
||||
```ini
|
||||
AccountBound.Friends.SyncOnCreate = 1
|
||||
AccountBound.Friends.SyncOnlineChanges = 1
|
||||
AccountBound.Friends.SyncIntervalSeconds = 3
|
||||
```
|
||||
|
||||
Friend notes are shared. Characters belonging to the same account are removed
|
||||
from the friend list to avoid self-friend entries.
|
||||
|
||||
Cross-faction friends are allowed by default:
|
||||
|
||||
```ini
|
||||
AccountBound.Friends.SameFactionOnly = 0
|
||||
```
|
||||
|
||||
## Startup Backfill
|
||||
|
||||
Every progression category has a `StartupBackfill` setting.
|
||||
|
||||
Example:
|
||||
|
||||
```ini
|
||||
AccountBound.Achievements.StartupBackfill = 1
|
||||
AccountBound.Mounts.StartupBackfill = 1
|
||||
AccountBound.Pets.StartupBackfill = 1
|
||||
AccountBound.Titles.StartupBackfill = 1
|
||||
AccountBound.Reputations.StartupBackfill = 1
|
||||
AccountBound.Professions.StartupBackfill = 1
|
||||
AccountBound.Friends.StartupBackfill = 1
|
||||
```
|
||||
|
||||
For an existing realm:
|
||||
|
||||
1. Back up the characters database.
|
||||
2. Enable the categories you want.
|
||||
3. Enable their startup backfill options.
|
||||
4. Start `worldserver` once.
|
||||
5. Wait for every AccountBound startup message.
|
||||
6. Stop `worldserver`.
|
||||
7. Set the startup backfill options back to `0`.
|
||||
8. Start the server normally.
|
||||
|
||||
Backfill uses idempotent inserts or monotonic updates, but it can touch many
|
||||
rows on a large realm.
|
||||
|
||||
Version 1.1 replaces the old `SyncOnLogin` options with `SyncOnCreate`.
|
||||
Existing custom configuration files should be updated to use the new keys.
|
||||
|
||||
## Safe Public-Realm Defaults
|
||||
|
||||
```ini
|
||||
AccountBound.Enable = 1
|
||||
|
||||
AccountBound.Achievements.SyncRealmFirst = 0
|
||||
AccountBound.Achievements.SyncHidden = 0
|
||||
|
||||
AccountBound.Mounts.RespectFactionRestrictions = 1
|
||||
AccountBound.Mounts.RequireRiding = 1
|
||||
AccountBound.Mounts.RequireClass = 1
|
||||
|
||||
AccountBound.Titles.SyncRealmFirst = 0
|
||||
|
||||
AccountBound.Reputations.SameFactionOnly = 1
|
||||
AccountBound.Reputations.SyncUnpairedCrossFaction = 0
|
||||
|
||||
AccountBound.Professions.Primary.EnforceAllowedList = 0
|
||||
AccountBound.Professions.RequireRecipeSkill = 1
|
||||
|
||||
AccountBound.Friends.StartupBackfill = 1
|
||||
```
|
||||
|
||||
After the initial migration, keep every broad `StartupBackfill` option disabled.
|
||||
|
||||
## Database Tables Used
|
||||
|
||||
The module uses normal AzerothCore tables:
|
||||
|
||||
```text
|
||||
characters
|
||||
character_achievement
|
||||
character_spell
|
||||
character_skills
|
||||
character_reputation
|
||||
character_social
|
||||
```
|
||||
|
||||
No custom tables or SQL installation files are required.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If the module is not loaded:
|
||||
|
||||
- Confirm the folder is `modules/AccountBound`.
|
||||
- Re-run CMake after adding the module.
|
||||
- Rebuild `worldserver`.
|
||||
- Confirm `configs/modules/AccountBound.conf` exists.
|
||||
- Confirm `AccountBound.Enable = 1`.
|
||||
|
||||
If a mount is not shared:
|
||||
|
||||
- Confirm the spell passes `AllowList` and `BlockList`.
|
||||
- Check riding, class and faction requirements.
|
||||
- Check `RequireRiding`, `RequireClass` and `RespectFactionRestrictions`.
|
||||
|
||||
If a profession recipe is not shared:
|
||||
|
||||
- Confirm the profession is allowed.
|
||||
- Confirm `SyncRecipes = 1`.
|
||||
- Confirm the target has sufficient skill when `RequireRecipeSkill = 1`.
|
||||
- Add custom recipes to `SpellAllowList`.
|
||||
|
||||
If data was inserted while the target character was already online:
|
||||
|
||||
- Relog once so AzerothCore reloads the updated character tables.
|
||||
|
||||
If startup takes longer than normal:
|
||||
|
||||
- Disable broad `StartupBackfill` options after the initial migration.
|
||||
|
||||
## Files
|
||||
|
||||
```text
|
||||
AccountBound/
|
||||
conf/
|
||||
AccountBound.conf.dist
|
||||
src/
|
||||
AccountBound.h
|
||||
Achievements.cpp
|
||||
Friends.cpp
|
||||
Mounts.cpp
|
||||
Pets.cpp
|
||||
Professions.cpp
|
||||
Reputations.cpp
|
||||
Titles.cpp
|
||||
loader.cpp
|
||||
CHANGELOG.md
|
||||
LICENSE
|
||||
README.md
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
AccountBound is distributed under GPL-2.0 to match the AzerothCore core
|
||||
license.
|
||||
@@ -0,0 +1,111 @@
|
||||
#
|
||||
# AccountBound
|
||||
# One configurable account-wide module for AzerothCore WotLK.
|
||||
#
|
||||
|
||||
# Master switch for every category below.
|
||||
AccountBound.Enable = 1
|
||||
|
||||
#
|
||||
# Achievements
|
||||
#
|
||||
AccountBound.Achievements.Enable = 0
|
||||
AccountBound.Achievements.StartupBackfill = 1
|
||||
AccountBound.Achievements.SameFactionOnly = 1
|
||||
AccountBound.Achievements.SyncOnCreate = 1
|
||||
AccountBound.Achievements.SyncRealmFirst = 0
|
||||
AccountBound.Achievements.SyncHidden = 0
|
||||
AccountBound.Achievements.ConvertFactionSpecific = 1
|
||||
AccountBound.Achievements.SyncUnpairedFactionSpecific = 0
|
||||
AccountBound.Achievements.AllowList = all
|
||||
AccountBound.Achievements.BlockList = ""
|
||||
|
||||
#
|
||||
# Mounts
|
||||
#
|
||||
AccountBound.Mounts.Enable = 1
|
||||
AccountBound.Mounts.StartupBackfill = 1
|
||||
AccountBound.Mounts.SyncOnCreate = 1
|
||||
AccountBound.Mounts.RespectFactionRestrictions = 1
|
||||
AccountBound.Mounts.ConvertFactionSpecific = 1
|
||||
AccountBound.Mounts.RequireRiding = 1
|
||||
AccountBound.Mounts.SyncClassMounts = 1
|
||||
AccountBound.Mounts.RequireClass = 1
|
||||
AccountBound.Mounts.ClassMountsSameFactionOnly = 1
|
||||
AccountBound.Mounts.CleanupInvalid = 1
|
||||
AccountBound.Mounts.BackfillOnRidingSkillChange = 1
|
||||
AccountBound.Mounts.AllowList = all
|
||||
AccountBound.Mounts.BlockList = ""
|
||||
|
||||
#
|
||||
# Companion pets
|
||||
# This intentionally shares vanity companions, not hunter stable pets.
|
||||
#
|
||||
AccountBound.Pets.Enable = 1
|
||||
AccountBound.Pets.StartupBackfill = 1
|
||||
AccountBound.Pets.SyncOnCreate = 1
|
||||
AccountBound.Pets.SameFactionOnly = 0
|
||||
AccountBound.Pets.IncludeCompanionSkillLine = 1
|
||||
AccountBound.Pets.IncludeMinipetSummons = 1
|
||||
AccountBound.Pets.AllowList = all
|
||||
AccountBound.Pets.BlockList = ""
|
||||
|
||||
#
|
||||
# Titles
|
||||
#
|
||||
AccountBound.Titles.Enable = 0
|
||||
AccountBound.Titles.StartupBackfill = 1
|
||||
AccountBound.Titles.SyncOnCreate = 1
|
||||
AccountBound.Titles.SyncOnSave = 1
|
||||
AccountBound.Titles.SyncRealmFirst = 0
|
||||
AccountBound.Titles.ConvertFactionSpecific = 1
|
||||
AccountBound.Titles.AllowList = all
|
||||
AccountBound.Titles.BlockList = ""
|
||||
|
||||
#
|
||||
# Reputations
|
||||
# Values only move upward. Faction-specific equivalents are converted.
|
||||
#
|
||||
AccountBound.Reputations.Enable = 0
|
||||
AccountBound.Reputations.StartupBackfill = 1
|
||||
AccountBound.Reputations.SyncOnCreate = 1
|
||||
AccountBound.Reputations.SyncOnChange = 1
|
||||
AccountBound.Reputations.SameFactionOnly = 1
|
||||
AccountBound.Reputations.ConvertFactionSpecific = 1
|
||||
AccountBound.Reputations.SyncUnpairedCrossFaction = 0
|
||||
AccountBound.Reputations.AllowList = all
|
||||
AccountBound.Reputations.BlockList = ""
|
||||
|
||||
#
|
||||
# Professions
|
||||
# Supports English/Spanish names or skill IDs in the primary lists.
|
||||
#
|
||||
AccountBound.Professions.Enable = 0
|
||||
AccountBound.Professions.MaxPrimaryProfessions = 11
|
||||
AccountBound.Professions.Primary.AllowList = all
|
||||
AccountBound.Professions.Primary.BlockList = ""
|
||||
AccountBound.Professions.Primary.CountOnlyAllowed = 1
|
||||
AccountBound.Professions.Primary.EnforceAllowedList = 0
|
||||
AccountBound.Professions.MaxSkillValue = 450
|
||||
AccountBound.Professions.StartupBackfill = 1
|
||||
AccountBound.Professions.SyncOnCreate = 1
|
||||
AccountBound.Professions.SyncOnLearn = 1
|
||||
AccountBound.Professions.IncludeSecondaryProfessions = 1
|
||||
AccountBound.Professions.SyncSkillProgress = 1
|
||||
AccountBound.Professions.SyncProfessionRanks = 1
|
||||
AccountBound.Professions.SyncRecipes = 1
|
||||
AccountBound.Professions.SyncSkillGrantedSpells = 1
|
||||
AccountBound.Professions.RequireRecipeSkill = 1
|
||||
AccountBound.Professions.SpellAllowList = ""
|
||||
AccountBound.Professions.SpellBlockList = ""
|
||||
|
||||
#
|
||||
# Friends
|
||||
# Mirrors the normal friend list and notes across characters on the account.
|
||||
#
|
||||
AccountBound.Friends.Enable = 1
|
||||
AccountBound.Friends.SyncOnCreate = 1
|
||||
AccountBound.Friends.SyncOnlineChanges = 1
|
||||
AccountBound.Friends.SameFactionOnly = 0
|
||||
AccountBound.Friends.SyncIntervalSeconds = 3
|
||||
AccountBound.Friends.StartupBackfill = 1
|
||||
@@ -0,0 +1,94 @@
|
||||
#ifndef ACCOUNT_BOUND_H
|
||||
#define ACCOUNT_BOUND_H
|
||||
|
||||
#include "Config.h"
|
||||
#include "Log.h"
|
||||
|
||||
#include <charconv>
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace AccountBound
|
||||
{
|
||||
struct IdFilter
|
||||
{
|
||||
bool AllowAll = true;
|
||||
std::unordered_set<uint32> Allowed;
|
||||
std::unordered_set<uint32> Blocked;
|
||||
|
||||
bool Allows(uint32 id) const
|
||||
{
|
||||
return id && !Blocked.contains(id) && (AllowAll || Allowed.contains(id));
|
||||
}
|
||||
};
|
||||
|
||||
inline std::string Trim(std::string_view value)
|
||||
{
|
||||
std::size_t first = 0;
|
||||
while (first < value.size() && std::isspace(static_cast<unsigned char>(value[first])))
|
||||
++first;
|
||||
|
||||
std::size_t last = value.size();
|
||||
while (last > first && std::isspace(static_cast<unsigned char>(value[last - 1])))
|
||||
--last;
|
||||
|
||||
return std::string(value.substr(first, last - first));
|
||||
}
|
||||
|
||||
inline void ParseIds(std::string const& raw, std::unordered_set<uint32>& destination)
|
||||
{
|
||||
std::size_t start = 0;
|
||||
while (start <= raw.size())
|
||||
{
|
||||
std::size_t end = raw.find(',', start);
|
||||
if (end == std::string::npos)
|
||||
end = raw.size();
|
||||
|
||||
std::string token = Trim(std::string_view(raw).substr(start, end - start));
|
||||
if (!token.empty())
|
||||
{
|
||||
uint32 id = 0;
|
||||
auto const [ptr, error] = std::from_chars(token.data(), token.data() + token.size(), id);
|
||||
if (error == std::errc() && ptr == token.data() + token.size() && id)
|
||||
destination.insert(id);
|
||||
else
|
||||
LOG_WARN("module.accountbound", "AccountBound: ignored invalid ID '{}' in an AllowList or BlockList.", token);
|
||||
}
|
||||
|
||||
if (end == raw.size())
|
||||
break;
|
||||
|
||||
start = end + 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool IsCategoryEnabled(std::string_view category, bool defaultValue = true)
|
||||
{
|
||||
if (!sConfigMgr->GetOption<bool>("AccountBound.Enable", true))
|
||||
return false;
|
||||
|
||||
return sConfigMgr->GetOption<bool>(
|
||||
"AccountBound." + std::string(category) + ".Enable", defaultValue);
|
||||
}
|
||||
|
||||
inline IdFilter LoadIdFilter(std::string_view category)
|
||||
{
|
||||
IdFilter filter;
|
||||
std::string const prefix = "AccountBound." + std::string(category);
|
||||
std::string const allowList = Trim(sConfigMgr->GetOption<std::string>(prefix + ".AllowList", "all"));
|
||||
|
||||
if (!allowList.empty() && allowList != "all" && allowList != "ALL" && allowList != "*")
|
||||
{
|
||||
filter.AllowAll = false;
|
||||
if (allowList != "none" && allowList != "NONE")
|
||||
ParseIds(allowList, filter.Allowed);
|
||||
}
|
||||
|
||||
ParseIds(sConfigMgr->GetOption<std::string>(prefix + ".BlockList", ""), filter.Blocked);
|
||||
return filter;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,378 @@
|
||||
/*
|
||||
* Account-bound achievements for AzerothCore.
|
||||
*/
|
||||
|
||||
#include "AccountBound.h"
|
||||
#include "Config.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "DBCEnums.h"
|
||||
#include "DBCStores.h"
|
||||
#include "GameTime.h"
|
||||
#include "Log.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "Player.h"
|
||||
#include "PlayerScript.h"
|
||||
#include "StringFormat.h"
|
||||
#include "WorldScript.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct ModuleConfig
|
||||
{
|
||||
bool Enabled = true;
|
||||
bool StartupBackfill = true;
|
||||
bool SameFactionOnly = false;
|
||||
bool SyncOnCreate = true;
|
||||
bool SyncRealmFirst = false;
|
||||
bool SyncHidden = false;
|
||||
bool ConvertFactionSpecific = true;
|
||||
bool SyncUnpairedFactionSpecific = false;
|
||||
AccountBound::IdFilter Filter;
|
||||
};
|
||||
|
||||
struct CharacterInfo
|
||||
{
|
||||
uint32 Guid = 0;
|
||||
uint32 AccountId = 0;
|
||||
uint8 Race = 0;
|
||||
};
|
||||
|
||||
ModuleConfig Config;
|
||||
|
||||
bool CanShareBetweenRaces(uint8 sourceRace, uint8 targetRace)
|
||||
{
|
||||
return !Config.SameFactionOnly || Player::TeamIdForRace(sourceRace) == Player::TeamIdForRace(targetRace);
|
||||
}
|
||||
|
||||
bool IsRealmFirstAchievement(AchievementEntry const* achievement)
|
||||
{
|
||||
return achievement && (achievement->flags & (ACHIEVEMENT_FLAG_REALM_FIRST_REACH | ACHIEVEMENT_FLAG_REALM_FIRST_KILL));
|
||||
}
|
||||
|
||||
bool IsAchievementAllowed(AchievementEntry const* achievement)
|
||||
{
|
||||
if (!achievement || (achievement->flags & ACHIEVEMENT_FLAG_COUNTER))
|
||||
return false;
|
||||
|
||||
if (!Config.Filter.Allows(achievement->ID))
|
||||
return false;
|
||||
|
||||
if (!Config.SyncRealmFirst && IsRealmFirstAchievement(achievement))
|
||||
return false;
|
||||
|
||||
if (!Config.SyncHidden && (achievement->flags & ACHIEVEMENT_FLAG_HIDDEN))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32 GetFactionAchievementForTeam(uint32 achievementId, TeamId targetTeam)
|
||||
{
|
||||
AchievementEntry const* achievement = sAchievementStore.LookupEntry(achievementId);
|
||||
if (!IsAchievementAllowed(achievement))
|
||||
return 0;
|
||||
|
||||
if (achievement->requiredFaction == ACHIEVEMENT_FACTION_ANY)
|
||||
return achievementId;
|
||||
|
||||
if (achievement->requiredFaction == ACHIEVEMENT_FACTION_ALLIANCE && targetTeam == TEAM_ALLIANCE)
|
||||
return achievementId;
|
||||
|
||||
if (achievement->requiredFaction == ACHIEVEMENT_FACTION_HORDE && targetTeam == TEAM_HORDE)
|
||||
return achievementId;
|
||||
|
||||
if (!Config.ConvertFactionSpecific)
|
||||
return Config.SyncUnpairedFactionSpecific ? achievementId : 0;
|
||||
|
||||
for (auto const& [allianceAchievement, hordeAchievement] : sObjectMgr->FactionChangeAchievements)
|
||||
{
|
||||
uint32 mappedAchievement = 0;
|
||||
|
||||
if (achievementId == allianceAchievement && targetTeam == TEAM_HORDE)
|
||||
mappedAchievement = hordeAchievement;
|
||||
else if (achievementId == hordeAchievement && targetTeam == TEAM_ALLIANCE)
|
||||
mappedAchievement = allianceAchievement;
|
||||
|
||||
if (!mappedAchievement)
|
||||
continue;
|
||||
|
||||
AchievementEntry const* mappedEntry = sAchievementStore.LookupEntry(mappedAchievement);
|
||||
return IsAchievementAllowed(mappedEntry) ? mappedAchievement : 0;
|
||||
}
|
||||
|
||||
return Config.SyncUnpairedFactionSpecific ? achievementId : 0;
|
||||
}
|
||||
|
||||
uint32 GetAchievementForRace(uint32 achievementId, uint8 race)
|
||||
{
|
||||
return GetFactionAchievementForTeam(achievementId, Player::TeamIdForRace(race));
|
||||
}
|
||||
|
||||
void AppendOrCommit(CharacterDatabaseTransaction& trans, std::string_view sql)
|
||||
{
|
||||
if (!trans)
|
||||
trans = CharacterDatabase.BeginTransaction();
|
||||
|
||||
trans->Append(sql);
|
||||
|
||||
if (trans->GetSize() >= 1000)
|
||||
{
|
||||
CharacterDatabase.DirectCommitTransaction(trans);
|
||||
trans = CharacterDatabase.BeginTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
void CommitIfNeeded(CharacterDatabaseTransaction& trans)
|
||||
{
|
||||
if (trans && trans->GetSize())
|
||||
CharacterDatabase.DirectCommitTransaction(trans);
|
||||
}
|
||||
|
||||
void InsertAchievementForCharacter(CharacterDatabaseTransaction& trans, uint32 targetGuid, uint32 achievementId, uint32 date)
|
||||
{
|
||||
AppendOrCommit(trans, Acore::StringFormat(
|
||||
"INSERT IGNORE INTO character_achievement (guid, achievement, date) VALUES ({}, {}, {})",
|
||||
targetGuid, achievementId, date));
|
||||
}
|
||||
|
||||
std::vector<CharacterInfo> LoadAccountCharacters(uint32 accountId)
|
||||
{
|
||||
std::vector<CharacterInfo> characters;
|
||||
QueryResult result = CharacterDatabase.Query(
|
||||
"SELECT guid, account, race FROM characters WHERE account = {}", accountId);
|
||||
|
||||
if (!result)
|
||||
return characters;
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
characters.push_back({
|
||||
fields[0].Get<uint32>(),
|
||||
fields[1].Get<uint32>(),
|
||||
fields[2].Get<uint8>()
|
||||
});
|
||||
} while (result->NextRow());
|
||||
|
||||
return characters;
|
||||
}
|
||||
|
||||
void SyncAchievementToAccount(Player* player, uint32 achievementId, uint32 date)
|
||||
{
|
||||
if (!Config.Enabled || !player)
|
||||
return;
|
||||
|
||||
uint8 const sourceRace = player->getRace(true);
|
||||
std::vector<CharacterInfo> characters = LoadAccountCharacters(player->GetSession()->GetAccountId());
|
||||
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
uint32 synced = 0;
|
||||
|
||||
for (CharacterInfo const& target : characters)
|
||||
{
|
||||
if (target.Guid == player->GetGUID().GetCounter() || !CanShareBetweenRaces(sourceRace, target.Race))
|
||||
continue;
|
||||
|
||||
uint32 const targetAchievementId = GetAchievementForRace(achievementId, target.Race);
|
||||
if (!targetAchievementId)
|
||||
continue;
|
||||
|
||||
InsertAchievementForCharacter(trans, target.Guid, targetAchievementId, date);
|
||||
++synced;
|
||||
}
|
||||
|
||||
CommitIfNeeded(trans);
|
||||
|
||||
if (synced)
|
||||
LOG_DEBUG("module.accountboundachievements",
|
||||
"AccountBoundAchievements: synced achievement {} from player {} to {} account character(s).",
|
||||
achievementId, player->GetGUID().GetCounter(), synced);
|
||||
}
|
||||
|
||||
void BackfillAchievementsForCharacter(Player* player)
|
||||
{
|
||||
if (!Config.Enabled || !player)
|
||||
return;
|
||||
|
||||
uint32 const accountId = player->GetSession()->GetAccountId();
|
||||
uint32 const targetGuid = player->GetGUID().GetCounter();
|
||||
uint8 const targetRace = player->getRace(true);
|
||||
QueryResult result = CharacterDatabase.Query(
|
||||
"SELECT ca.achievement, MIN(ca.date), c.race "
|
||||
"FROM character_achievement ca "
|
||||
"INNER JOIN characters c ON c.guid = ca.guid "
|
||||
"WHERE c.account = {} AND c.guid <> {} "
|
||||
"GROUP BY ca.achievement, c.race "
|
||||
"ORDER BY MIN(ca.date)",
|
||||
accountId, targetGuid);
|
||||
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
uint32 inserted = 0;
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
uint32 const achievementId = fields[0].Get<uint32>();
|
||||
uint32 const date = fields[1].Get<uint32>();
|
||||
uint8 const sourceRace = fields[2].Get<uint8>();
|
||||
|
||||
if (!CanShareBetweenRaces(sourceRace, targetRace))
|
||||
continue;
|
||||
|
||||
uint32 const targetAchievementId = GetAchievementForRace(achievementId, targetRace);
|
||||
if (!targetAchievementId)
|
||||
continue;
|
||||
|
||||
InsertAchievementForCharacter(trans, targetGuid, targetAchievementId, date);
|
||||
++inserted;
|
||||
} while (result->NextRow());
|
||||
|
||||
CommitIfNeeded(trans);
|
||||
|
||||
if (inserted)
|
||||
LOG_INFO("module.accountboundachievements",
|
||||
"AccountBoundAchievements: seeded {} achievement row(s) for new character {}.",
|
||||
inserted, targetGuid);
|
||||
}
|
||||
|
||||
void BackfillAllAchievements()
|
||||
{
|
||||
if (!Config.Enabled || !Config.StartupBackfill)
|
||||
return;
|
||||
|
||||
QueryResult charactersResult = CharacterDatabase.Query(
|
||||
"SELECT guid, account, race FROM characters WHERE account <> 0");
|
||||
|
||||
if (!charactersResult)
|
||||
return;
|
||||
|
||||
std::unordered_map<uint32, std::vector<CharacterInfo>> charactersByAccount;
|
||||
do
|
||||
{
|
||||
Field* fields = charactersResult->Fetch();
|
||||
CharacterInfo character = {
|
||||
fields[0].Get<uint32>(),
|
||||
fields[1].Get<uint32>(),
|
||||
fields[2].Get<uint8>()
|
||||
};
|
||||
charactersByAccount[character.AccountId].push_back(character);
|
||||
} while (charactersResult->NextRow());
|
||||
|
||||
QueryResult achievementsResult = CharacterDatabase.Query(
|
||||
"SELECT c.account, c.race, ca.achievement, MIN(ca.date) "
|
||||
"FROM character_achievement ca "
|
||||
"INNER JOIN characters c ON c.guid = ca.guid "
|
||||
"WHERE c.account <> 0 "
|
||||
"GROUP BY c.account, c.race, ca.achievement "
|
||||
"ORDER BY MIN(ca.date)");
|
||||
|
||||
if (!achievementsResult)
|
||||
return;
|
||||
|
||||
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
uint64 inserted = 0;
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = achievementsResult->Fetch();
|
||||
uint32 const accountId = fields[0].Get<uint32>();
|
||||
uint8 const sourceRace = fields[1].Get<uint8>();
|
||||
uint32 const achievementId = fields[2].Get<uint32>();
|
||||
uint32 const date = fields[3].Get<uint32>();
|
||||
auto accountItr = charactersByAccount.find(accountId);
|
||||
|
||||
if (accountItr == charactersByAccount.end())
|
||||
continue;
|
||||
|
||||
for (CharacterInfo const& target : accountItr->second)
|
||||
{
|
||||
if (!CanShareBetweenRaces(sourceRace, target.Race))
|
||||
continue;
|
||||
|
||||
uint32 const targetAchievementId = GetAchievementForRace(achievementId, target.Race);
|
||||
if (!targetAchievementId)
|
||||
continue;
|
||||
|
||||
InsertAchievementForCharacter(trans, target.Guid, targetAchievementId, date);
|
||||
++inserted;
|
||||
}
|
||||
} while (achievementsResult->NextRow());
|
||||
|
||||
CommitIfNeeded(trans);
|
||||
LOG_INFO("module.accountboundachievements",
|
||||
"AccountBoundAchievements: startup backfill queued {} achievement row(s).", inserted);
|
||||
}
|
||||
|
||||
void LoadModuleConfig()
|
||||
{
|
||||
Config.Enabled = AccountBound::IsCategoryEnabled("Achievements");
|
||||
Config.StartupBackfill = sConfigMgr->GetOption<bool>("AccountBound.Achievements.StartupBackfill", true);
|
||||
Config.SameFactionOnly = sConfigMgr->GetOption<bool>("AccountBound.Achievements.SameFactionOnly", false);
|
||||
Config.SyncOnCreate = sConfigMgr->GetOption<bool>("AccountBound.Achievements.SyncOnCreate", true);
|
||||
Config.SyncRealmFirst = sConfigMgr->GetOption<bool>("AccountBound.Achievements.SyncRealmFirst", false);
|
||||
Config.SyncHidden = sConfigMgr->GetOption<bool>("AccountBound.Achievements.SyncHidden", false);
|
||||
Config.ConvertFactionSpecific = sConfigMgr->GetOption<bool>("AccountBound.Achievements.ConvertFactionSpecific", true);
|
||||
Config.SyncUnpairedFactionSpecific = sConfigMgr->GetOption<bool>("AccountBound.Achievements.SyncUnpairedFactionSpecific", false);
|
||||
Config.Filter = AccountBound::LoadIdFilter("Achievements");
|
||||
}
|
||||
}
|
||||
|
||||
class AccountBoundAchievementsWorldScript : public WorldScript
|
||||
{
|
||||
public:
|
||||
AccountBoundAchievementsWorldScript() : WorldScript("AccountBoundAchievementsWorldScript", {
|
||||
WORLDHOOK_ON_AFTER_CONFIG_LOAD,
|
||||
WORLDHOOK_ON_STARTUP
|
||||
}) { }
|
||||
|
||||
void OnAfterConfigLoad(bool reload) override
|
||||
{
|
||||
LoadModuleConfig();
|
||||
LOG_INFO("module.accountboundachievements",
|
||||
"AccountBoundAchievements: {}. CreateSync={}, StartupBackfill={}, SameFactionOnly={}, RealmFirst={}.",
|
||||
Config.Enabled ? (reload ? "configuration reloaded" : "configuration loaded") : "disabled",
|
||||
Config.Enabled && Config.SyncOnCreate ? "on" : "off",
|
||||
Config.Enabled && Config.StartupBackfill ? "on" : "off",
|
||||
Config.Enabled && Config.SameFactionOnly ? "on" : "off",
|
||||
Config.Enabled && Config.SyncRealmFirst ? "on" : "off");
|
||||
}
|
||||
|
||||
void OnStartup() override
|
||||
{
|
||||
BackfillAllAchievements();
|
||||
}
|
||||
};
|
||||
|
||||
class AccountBoundAchievementsPlayerScript : public PlayerScript
|
||||
{
|
||||
public:
|
||||
AccountBoundAchievementsPlayerScript() : PlayerScript("AccountBoundAchievementsPlayerScript", {
|
||||
PLAYERHOOK_ON_CREATE,
|
||||
PLAYERHOOK_ON_ACHI_COMPLETE
|
||||
}) { }
|
||||
|
||||
void OnPlayerCreate(Player* player) override
|
||||
{
|
||||
if (Config.SyncOnCreate)
|
||||
BackfillAchievementsForCharacter(player);
|
||||
}
|
||||
|
||||
void OnPlayerAchievementComplete(Player* player, AchievementEntry const* achievement) override
|
||||
{
|
||||
if (achievement)
|
||||
SyncAchievementToAccount(player, achievement->ID, uint32(GameTime::GetGameTime().count()));
|
||||
}
|
||||
};
|
||||
|
||||
void AddAccountBoundAchievementsScripts()
|
||||
{
|
||||
new AccountBoundAchievementsWorldScript();
|
||||
new AccountBoundAchievementsPlayerScript();
|
||||
}
|
||||
@@ -0,0 +1,526 @@
|
||||
/*
|
||||
* AccountWideFriends module for AzerothCore.
|
||||
*/
|
||||
|
||||
#include "AccountBound.h"
|
||||
#include "Config.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "Log.h"
|
||||
#include "Player.h"
|
||||
#include "PlayerScript.h"
|
||||
#include "SocialMgr.h"
|
||||
#include "WorldScript.h"
|
||||
#include "WorldSession.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr uint32 FriendFlag = SOCIAL_FLAG_FRIEND;
|
||||
constexpr uint32 WithoutFriendFlagMask = 0xFE;
|
||||
|
||||
struct ModuleConfig
|
||||
{
|
||||
bool Enabled = true;
|
||||
bool SyncOnCreate = true;
|
||||
bool SyncOnlineChanges = true;
|
||||
bool StartupBackfill = true;
|
||||
bool SameFactionOnly = false;
|
||||
uint32 SyncIntervalMs = 3000;
|
||||
};
|
||||
|
||||
struct CharacterInfo
|
||||
{
|
||||
uint32 Guid = 0;
|
||||
uint8 Race = 0;
|
||||
};
|
||||
|
||||
using FriendMap = std::unordered_map<uint32, std::string>;
|
||||
|
||||
ModuleConfig Config;
|
||||
std::unordered_map<uint32, uint32> UpdateTimersByCharacter;
|
||||
std::unordered_map<uint32, FriendMap> CachedFriendsByCharacter;
|
||||
|
||||
bool IsEnabled()
|
||||
{
|
||||
return Config.Enabled;
|
||||
}
|
||||
|
||||
std::string EscapeSqlString(std::string text)
|
||||
{
|
||||
CharacterDatabase.EscapeString(text);
|
||||
return text;
|
||||
}
|
||||
|
||||
bool CanShareBetweenRaces(uint8 ownerRace, uint8 friendRace)
|
||||
{
|
||||
return !Config.SameFactionOnly || Player::TeamIdForRace(ownerRace) == Player::TeamIdForRace(friendRace);
|
||||
}
|
||||
|
||||
std::vector<CharacterInfo> LoadAccountCharacterInfos(uint32 accountId)
|
||||
{
|
||||
std::vector<CharacterInfo> characters;
|
||||
|
||||
QueryResult result = CharacterDatabase.Query(
|
||||
"SELECT guid, race FROM characters WHERE account = {}", accountId);
|
||||
|
||||
if (!result)
|
||||
return characters;
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
characters.push_back({ fields[0].Get<uint32>(), fields[1].Get<uint8>() });
|
||||
} while (result->NextRow());
|
||||
|
||||
return characters;
|
||||
}
|
||||
|
||||
std::vector<uint32> LoadAccountCharacters(uint32 accountId)
|
||||
{
|
||||
std::vector<uint32> characterGuids;
|
||||
|
||||
for (CharacterInfo const& character : LoadAccountCharacterInfos(accountId))
|
||||
characterGuids.push_back(character.Guid);
|
||||
|
||||
return characterGuids;
|
||||
}
|
||||
|
||||
std::unordered_set<uint32> MakeGuidSet(std::vector<uint32> const& guids)
|
||||
{
|
||||
return { guids.begin(), guids.end() };
|
||||
}
|
||||
|
||||
std::unordered_set<uint32> MakeGuidSet(std::vector<CharacterInfo> const& characters)
|
||||
{
|
||||
std::unordered_set<uint32> guids;
|
||||
|
||||
for (CharacterInfo const& character : characters)
|
||||
guids.insert(character.Guid);
|
||||
|
||||
return guids;
|
||||
}
|
||||
|
||||
uint8 LoadCharacterRace(uint32 characterGuid)
|
||||
{
|
||||
QueryResult result = CharacterDatabase.Query(
|
||||
"SELECT race FROM characters WHERE guid = {}", characterGuid);
|
||||
|
||||
if (!result)
|
||||
return 0;
|
||||
|
||||
return result->Fetch()[0].Get<uint8>();
|
||||
}
|
||||
|
||||
bool CanCharacterShareWithFriend(CharacterInfo const& owner, uint32 friendGuid)
|
||||
{
|
||||
uint8 const friendRace = LoadCharacterRace(friendGuid);
|
||||
return friendRace && CanShareBetweenRaces(owner.Race, friendRace);
|
||||
}
|
||||
|
||||
void RemoveFriendFromCharacter(uint32 ownerGuid, uint32 friendGuid)
|
||||
{
|
||||
CharacterDatabase.DirectExecute(
|
||||
"UPDATE character_social SET flags = flags & {} "
|
||||
"WHERE guid = {} AND friend = {} AND (flags & {}) <> 0",
|
||||
WithoutFriendFlagMask, ownerGuid, friendGuid, FriendFlag);
|
||||
|
||||
CharacterDatabase.DirectExecute(
|
||||
"DELETE FROM character_social WHERE guid = {} AND friend = {} AND flags = 0",
|
||||
ownerGuid, friendGuid);
|
||||
}
|
||||
|
||||
FriendMap LoadCharacterFriends(uint32 characterGuid)
|
||||
{
|
||||
FriendMap friends;
|
||||
|
||||
QueryResult result = CharacterDatabase.Query(
|
||||
"SELECT social.friend, COALESCE(social.note, ''), owner.race, friend_char.race "
|
||||
"FROM character_social social "
|
||||
"INNER JOIN characters owner ON owner.guid = social.guid "
|
||||
"INNER JOIN characters friend_char ON friend_char.guid = social.friend "
|
||||
"WHERE social.guid = {} AND owner.account <> friend_char.account AND (social.flags & {}) <> 0",
|
||||
characterGuid, FriendFlag);
|
||||
|
||||
if (!result)
|
||||
return friends;
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
uint32 const friendGuid = fields[0].Get<uint32>();
|
||||
uint8 const ownerRace = fields[2].Get<uint8>();
|
||||
uint8 const friendRace = fields[3].Get<uint8>();
|
||||
|
||||
if (friendGuid && friendGuid != characterGuid && CanShareBetweenRaces(ownerRace, friendRace))
|
||||
friends[friendGuid] = fields[1].Get<std::string>();
|
||||
} while (result->NextRow());
|
||||
|
||||
return friends;
|
||||
}
|
||||
|
||||
FriendMap LoadAccountFriendUnion(uint32 accountId)
|
||||
{
|
||||
FriendMap friends;
|
||||
std::vector<uint32> accountCharacters = LoadAccountCharacters(accountId);
|
||||
std::unordered_set<uint32> ownCharacters = MakeGuidSet(accountCharacters);
|
||||
|
||||
QueryResult result = CharacterDatabase.Query(
|
||||
"SELECT social.friend, COALESCE(social.note, '') "
|
||||
"FROM character_social social "
|
||||
"INNER JOIN characters owner ON owner.guid = social.guid "
|
||||
"WHERE owner.account = {} AND (social.flags & {}) <> 0 "
|
||||
"ORDER BY social.note <> '' DESC",
|
||||
accountId, FriendFlag);
|
||||
|
||||
if (!result)
|
||||
return friends;
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
uint32 const friendGuid = fields[0].Get<uint32>();
|
||||
|
||||
if (!friendGuid || ownCharacters.contains(friendGuid))
|
||||
continue;
|
||||
|
||||
std::string const note = fields[1].Get<std::string>();
|
||||
auto [itr, inserted] = friends.emplace(friendGuid, note);
|
||||
|
||||
if (!inserted && itr->second.empty() && !note.empty())
|
||||
itr->second = note;
|
||||
} while (result->NextRow());
|
||||
|
||||
return friends;
|
||||
}
|
||||
|
||||
void InsertOrUpdateFriendForCharacter(uint32 ownerGuid, uint32 friendGuid, std::string const& note, bool forceNote)
|
||||
{
|
||||
if (!ownerGuid || !friendGuid || ownerGuid == friendGuid)
|
||||
return;
|
||||
|
||||
std::string safeNote = note.substr(0, 48);
|
||||
safeNote = EscapeSqlString(safeNote);
|
||||
|
||||
if (forceNote)
|
||||
{
|
||||
CharacterDatabase.DirectExecute(
|
||||
"INSERT INTO character_social (guid, friend, flags, note) VALUES ({}, {}, {}, '{}') "
|
||||
"ON DUPLICATE KEY UPDATE flags = flags | {}, note = '{}'",
|
||||
ownerGuid, friendGuid, FriendFlag, safeNote, FriendFlag, safeNote);
|
||||
return;
|
||||
}
|
||||
|
||||
CharacterDatabase.DirectExecute(
|
||||
"INSERT INTO character_social (guid, friend, flags, note) VALUES ({}, {}, {}, '{}') "
|
||||
"ON DUPLICATE KEY UPDATE flags = flags | {}, note = IF(VALUES(note) <> '', VALUES(note), note)",
|
||||
ownerGuid, friendGuid, FriendFlag, safeNote, FriendFlag);
|
||||
}
|
||||
|
||||
uint32 SyncFriendToCharacters(
|
||||
std::vector<CharacterInfo> const& accountCharacters,
|
||||
std::unordered_set<uint32> const& ownCharacters,
|
||||
uint32 friendGuid,
|
||||
std::string const& note,
|
||||
bool forceNote)
|
||||
{
|
||||
if (!friendGuid || ownCharacters.contains(friendGuid))
|
||||
return 0;
|
||||
|
||||
uint32 synced = 0;
|
||||
|
||||
for (CharacterInfo const& owner : accountCharacters)
|
||||
{
|
||||
if (owner.Guid == friendGuid || !CanCharacterShareWithFriend(owner, friendGuid))
|
||||
continue;
|
||||
|
||||
InsertOrUpdateFriendForCharacter(owner.Guid, friendGuid, note, forceNote);
|
||||
++synced;
|
||||
}
|
||||
|
||||
return synced;
|
||||
}
|
||||
|
||||
uint32 SyncFriendToAccount(uint32 accountId, uint32 friendGuid, std::string const& note, bool forceNote = false)
|
||||
{
|
||||
std::vector<CharacterInfo> accountCharacters = LoadAccountCharacterInfos(accountId);
|
||||
std::unordered_set<uint32> ownCharacters = MakeGuidSet(accountCharacters);
|
||||
|
||||
return SyncFriendToCharacters(accountCharacters, ownCharacters, friendGuid, note, forceNote);
|
||||
}
|
||||
|
||||
void RemoveInvalidFactionFriends(uint32 accountId)
|
||||
{
|
||||
if (!Config.SameFactionOnly || !accountId)
|
||||
return;
|
||||
|
||||
QueryResult result = CharacterDatabase.Query(
|
||||
"SELECT social.guid, social.friend, owner.race, friend_char.race "
|
||||
"FROM character_social social "
|
||||
"INNER JOIN characters owner ON owner.guid = social.guid "
|
||||
"INNER JOIN characters friend_char ON friend_char.guid = social.friend "
|
||||
"WHERE owner.account = {} AND owner.account <> friend_char.account AND (social.flags & {}) <> 0",
|
||||
accountId, FriendFlag);
|
||||
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
uint32 const ownerGuid = fields[0].Get<uint32>();
|
||||
uint32 const friendGuid = fields[1].Get<uint32>();
|
||||
uint8 const ownerRace = fields[2].Get<uint8>();
|
||||
uint8 const friendRace = fields[3].Get<uint8>();
|
||||
|
||||
if (!CanShareBetweenRaces(ownerRace, friendRace))
|
||||
RemoveFriendFromCharacter(ownerGuid, friendGuid);
|
||||
} while (result->NextRow());
|
||||
}
|
||||
|
||||
void RemoveOwnAccountFriends(uint32 accountId)
|
||||
{
|
||||
if (!accountId)
|
||||
return;
|
||||
|
||||
CharacterDatabase.DirectExecute(
|
||||
"UPDATE character_social social "
|
||||
"INNER JOIN characters owner ON owner.guid = social.guid "
|
||||
"INNER JOIN characters friend_char ON friend_char.guid = social.friend "
|
||||
"SET social.flags = social.flags & {} "
|
||||
"WHERE owner.account = {} AND friend_char.account = {} AND (social.flags & {}) <> 0",
|
||||
WithoutFriendFlagMask, accountId, accountId, FriendFlag);
|
||||
|
||||
CharacterDatabase.DirectExecute(
|
||||
"DELETE social FROM character_social social "
|
||||
"INNER JOIN characters owner ON owner.guid = social.guid "
|
||||
"INNER JOIN characters friend_char ON friend_char.guid = social.friend "
|
||||
"WHERE owner.account = {} AND friend_char.account = {} AND social.flags = 0",
|
||||
accountId, accountId);
|
||||
}
|
||||
|
||||
uint32 SyncAccountFriends(uint32 accountId)
|
||||
{
|
||||
RemoveOwnAccountFriends(accountId);
|
||||
RemoveInvalidFactionFriends(accountId);
|
||||
|
||||
std::vector<CharacterInfo> accountCharacters = LoadAccountCharacterInfos(accountId);
|
||||
|
||||
if (accountCharacters.empty())
|
||||
return 0;
|
||||
|
||||
std::unordered_set<uint32> ownCharacters = MakeGuidSet(accountCharacters);
|
||||
FriendMap accountFriends = LoadAccountFriendUnion(accountId);
|
||||
uint32 synced = 0;
|
||||
|
||||
for (auto const& [friendGuid, note] : accountFriends)
|
||||
synced += SyncFriendToCharacters(accountCharacters, ownCharacters, friendGuid, note, false);
|
||||
|
||||
return synced;
|
||||
}
|
||||
|
||||
void RemoveFriendFromAccount(uint32 accountId, uint32 friendGuid)
|
||||
{
|
||||
if (!accountId || !friendGuid)
|
||||
return;
|
||||
|
||||
CharacterDatabase.DirectExecute(
|
||||
"UPDATE character_social social "
|
||||
"INNER JOIN characters owner ON owner.guid = social.guid "
|
||||
"SET social.flags = social.flags & {} "
|
||||
"WHERE owner.account = {} AND social.friend = {} AND (social.flags & {}) <> 0",
|
||||
WithoutFriendFlagMask, accountId, friendGuid, FriendFlag);
|
||||
|
||||
CharacterDatabase.DirectExecute(
|
||||
"DELETE social FROM character_social social "
|
||||
"INNER JOIN characters owner ON owner.guid = social.guid "
|
||||
"WHERE owner.account = {} AND social.friend = {} AND social.flags = 0",
|
||||
accountId, friendGuid);
|
||||
}
|
||||
|
||||
void CacheCharacterFriends(uint32 characterGuid)
|
||||
{
|
||||
CachedFriendsByCharacter[characterGuid] = LoadCharacterFriends(characterGuid);
|
||||
}
|
||||
|
||||
void DetectAndSyncOnlineChanges(Player* player)
|
||||
{
|
||||
if (!player || !player->GetSession())
|
||||
return;
|
||||
|
||||
uint32 const accountId = player->GetSession()->GetAccountId();
|
||||
uint32 const characterGuid = player->GetGUID().GetCounter();
|
||||
RemoveOwnAccountFriends(accountId);
|
||||
RemoveInvalidFactionFriends(accountId);
|
||||
FriendMap currentFriends = LoadCharacterFriends(characterGuid);
|
||||
|
||||
auto cacheItr = CachedFriendsByCharacter.find(characterGuid);
|
||||
if (cacheItr == CachedFriendsByCharacter.end())
|
||||
{
|
||||
CachedFriendsByCharacter[characterGuid] = std::move(currentFriends);
|
||||
return;
|
||||
}
|
||||
|
||||
FriendMap const& cachedFriends = cacheItr->second;
|
||||
bool changed = false;
|
||||
|
||||
for (auto const& [friendGuid, note] : currentFriends)
|
||||
{
|
||||
auto cachedFriend = cachedFriends.find(friendGuid);
|
||||
|
||||
if (cachedFriend == cachedFriends.end())
|
||||
{
|
||||
SyncFriendToAccount(accountId, friendGuid, note);
|
||||
changed = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cachedFriend->second != note)
|
||||
{
|
||||
SyncFriendToAccount(accountId, friendGuid, note, true);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto const& cachedFriendEntry : cachedFriends)
|
||||
{
|
||||
uint32 const friendGuid = cachedFriendEntry.first;
|
||||
|
||||
if (!currentFriends.contains(friendGuid))
|
||||
{
|
||||
RemoveFriendFromAccount(accountId, friendGuid);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed)
|
||||
LOG_DEBUG("module.accountwidefriends", "AccountWideFriends: synced friend changes for account {} from character {}.", accountId, characterGuid);
|
||||
|
||||
CacheCharacterFriends(characterGuid);
|
||||
}
|
||||
|
||||
void BackfillAllAccounts()
|
||||
{
|
||||
QueryResult result = CharacterDatabase.Query(
|
||||
"SELECT DISTINCT account FROM characters WHERE account <> 0");
|
||||
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
uint32 accountCount = 0;
|
||||
uint32 syncCount = 0;
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
uint32 const accountId = fields[0].Get<uint32>();
|
||||
|
||||
syncCount += SyncAccountFriends(accountId);
|
||||
++accountCount;
|
||||
} while (result->NextRow());
|
||||
|
||||
LOG_INFO("module.accountwidefriends", "AccountWideFriends: startup backfill checked {} account(s) and queued {} friend row sync operation(s).", accountCount, syncCount);
|
||||
}
|
||||
|
||||
void LoadModuleConfig()
|
||||
{
|
||||
Config.Enabled = AccountBound::IsCategoryEnabled("Friends");
|
||||
Config.SyncOnCreate = sConfigMgr->GetOption<bool>("AccountBound.Friends.SyncOnCreate", true);
|
||||
Config.SyncOnlineChanges = sConfigMgr->GetOption<bool>("AccountBound.Friends.SyncOnlineChanges", true);
|
||||
Config.StartupBackfill = sConfigMgr->GetOption<bool>("AccountBound.Friends.StartupBackfill", true);
|
||||
Config.SameFactionOnly = sConfigMgr->GetOption<bool>("AccountBound.Friends.SameFactionOnly", false);
|
||||
Config.SyncIntervalMs = std::max<uint32>(
|
||||
1000,
|
||||
sConfigMgr->GetOption<uint32>("AccountBound.Friends.SyncIntervalSeconds", 3) * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
class AccountWideFriendsWorldScript : public WorldScript
|
||||
{
|
||||
public:
|
||||
AccountWideFriendsWorldScript() : WorldScript("AccountWideFriendsWorldScript", {
|
||||
WORLDHOOK_ON_AFTER_CONFIG_LOAD,
|
||||
WORLDHOOK_ON_STARTUP
|
||||
}) { }
|
||||
|
||||
void OnAfterConfigLoad(bool reload) override
|
||||
{
|
||||
LoadModuleConfig();
|
||||
|
||||
LOG_INFO("module.accountwidefriends", "AccountWideFriends: {}. Enabled={}, CreateSync={}, OnlineSync={}, SameFactionOnly={}, IntervalMs={}, StartupBackfill={}.",
|
||||
reload ? "configuration reloaded" : "configuration loaded",
|
||||
Config.Enabled ? "on" : "off",
|
||||
Config.Enabled && Config.SyncOnCreate ? "on" : "off",
|
||||
Config.Enabled && Config.SyncOnlineChanges ? "on" : "off",
|
||||
Config.Enabled && Config.SameFactionOnly ? "on" : "off",
|
||||
Config.SyncIntervalMs,
|
||||
Config.Enabled && Config.StartupBackfill ? "on" : "off");
|
||||
}
|
||||
|
||||
void OnStartup() override
|
||||
{
|
||||
if (IsEnabled() && Config.StartupBackfill)
|
||||
BackfillAllAccounts();
|
||||
}
|
||||
};
|
||||
|
||||
class AccountWideFriendsPlayerScript : public PlayerScript
|
||||
{
|
||||
public:
|
||||
AccountWideFriendsPlayerScript() : PlayerScript("AccountWideFriendsPlayerScript", {
|
||||
PLAYERHOOK_ON_LOGIN,
|
||||
PLAYERHOOK_ON_CREATE,
|
||||
PLAYERHOOK_ON_LOGOUT,
|
||||
PLAYERHOOK_ON_UPDATE
|
||||
}) { }
|
||||
|
||||
void OnPlayerLogin(Player* player) override
|
||||
{
|
||||
if (!IsEnabled() || !player || !player->GetSession())
|
||||
return;
|
||||
|
||||
CacheCharacterFriends(player->GetGUID().GetCounter());
|
||||
}
|
||||
|
||||
void OnPlayerCreate(Player* player) override
|
||||
{
|
||||
if (IsEnabled() && Config.SyncOnCreate && player && player->GetSession())
|
||||
SyncAccountFriends(player->GetSession()->GetAccountId());
|
||||
}
|
||||
|
||||
void OnPlayerLogout(Player* player) override
|
||||
{
|
||||
if (!player)
|
||||
return;
|
||||
|
||||
uint32 const characterGuid = player->GetGUID().GetCounter();
|
||||
UpdateTimersByCharacter.erase(characterGuid);
|
||||
CachedFriendsByCharacter.erase(characterGuid);
|
||||
}
|
||||
|
||||
void OnPlayerUpdate(Player* player, uint32 diff) override
|
||||
{
|
||||
if (!IsEnabled() || !Config.SyncOnlineChanges || !player)
|
||||
return;
|
||||
|
||||
uint32 const characterGuid = player->GetGUID().GetCounter();
|
||||
uint32& timer = UpdateTimersByCharacter[characterGuid];
|
||||
timer = std::min<uint32>(Config.SyncIntervalMs, timer + diff);
|
||||
|
||||
if (timer < Config.SyncIntervalMs)
|
||||
return;
|
||||
|
||||
timer = 0;
|
||||
DetectAndSyncOnlineChanges(player);
|
||||
}
|
||||
};
|
||||
|
||||
void AddAccountWideFriendsScripts()
|
||||
{
|
||||
new AccountWideFriendsWorldScript();
|
||||
new AccountWideFriendsPlayerScript();
|
||||
}
|
||||
@@ -0,0 +1,692 @@
|
||||
/*
|
||||
* Account-bound mounts for AzerothCore.
|
||||
*/
|
||||
|
||||
#include "AccountBound.h"
|
||||
#include "Config.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "DBCEnums.h"
|
||||
#include "ItemTemplate.h"
|
||||
#include "Log.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "Player.h"
|
||||
#include "PlayerScript.h"
|
||||
#include "RaceMgr.h"
|
||||
#include "SpellAuraDefines.h"
|
||||
#include "SpellInfo.h"
|
||||
#include "SpellMgr.h"
|
||||
#include "StringFormat.h"
|
||||
#include "WorldScript.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct ModuleConfig
|
||||
{
|
||||
bool Enabled = true;
|
||||
bool StartupBackfill = true;
|
||||
bool SyncOnCreate = true;
|
||||
bool ConvertFactionSpecific = false;
|
||||
bool RespectFactionRestrictions = true;
|
||||
bool RequireRiding = true;
|
||||
bool SyncClassMounts = true;
|
||||
bool RequireClass = true;
|
||||
bool ClassMountsSameFactionOnly = true;
|
||||
bool CleanupInvalid = true;
|
||||
bool BackfillOnRidingSkillChange = true;
|
||||
AccountBound::IdFilter Filter;
|
||||
};
|
||||
|
||||
struct CharacterInfo
|
||||
{
|
||||
uint32 Guid = 0;
|
||||
uint32 AccountId = 0;
|
||||
uint8 Race = 0;
|
||||
uint8 Class = 0;
|
||||
uint16 RidingSkill = 0;
|
||||
};
|
||||
|
||||
struct MountSpellRequirements
|
||||
{
|
||||
uint16 RequiredRidingRank = 1;
|
||||
uint32 ClassMask = 0;
|
||||
};
|
||||
|
||||
ModuleConfig Config;
|
||||
std::unordered_map<uint32, TeamId> MountSpellFactionMap;
|
||||
std::unordered_map<uint32, MountSpellRequirements> MountSpellRequirementsMap;
|
||||
|
||||
bool IsMountSpell(uint32 spellId)
|
||||
{
|
||||
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
|
||||
return spellInfo && spellInfo->HasAura(SPELL_AURA_MOUNTED);
|
||||
}
|
||||
|
||||
uint32 GetClassMaskForClass(uint8 classId)
|
||||
{
|
||||
if (!classId || classId >= MAX_CLASSES)
|
||||
return 0;
|
||||
|
||||
return 1u << (classId - 1);
|
||||
}
|
||||
|
||||
uint32 NormalizeClassMask(uint32 classMask)
|
||||
{
|
||||
classMask &= CLASSMASK_ALL_PLAYABLE;
|
||||
return classMask && classMask != CLASSMASK_ALL_PLAYABLE ? classMask : 0;
|
||||
}
|
||||
|
||||
uint16 GetRidingRankFromRequiredSpell(uint32 spellId)
|
||||
{
|
||||
switch (spellId)
|
||||
{
|
||||
case 33388: return 75; // Apprentice Riding
|
||||
case 33391: return 150; // Journeyman Riding
|
||||
case 34090: return 225; // Expert Riding
|
||||
case 34091: return 300; // Artisan Riding
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
MountSpellRequirements& GetMountSpellRequirements(uint32 spellId)
|
||||
{
|
||||
return MountSpellRequirementsMap.try_emplace(spellId).first->second;
|
||||
}
|
||||
|
||||
void SetMountRidingRequirement(uint32 spellId, uint16 requiredRidingRank)
|
||||
{
|
||||
if (!IsMountSpell(spellId) || !requiredRidingRank)
|
||||
return;
|
||||
|
||||
MountSpellRequirements& requirements = GetMountSpellRequirements(spellId);
|
||||
requirements.RequiredRidingRank = std::max(requirements.RequiredRidingRank, requiredRidingRank);
|
||||
}
|
||||
|
||||
void SetMountClassRestriction(uint32 spellId, uint32 classMask)
|
||||
{
|
||||
classMask = NormalizeClassMask(classMask);
|
||||
if (!IsMountSpell(spellId) || !classMask)
|
||||
return;
|
||||
|
||||
GetMountSpellRequirements(spellId).ClassMask |= classMask;
|
||||
}
|
||||
|
||||
void ApplyClassMountFallbacks()
|
||||
{
|
||||
uint32 const paladinMask = GetClassMaskForClass(CLASS_PALADIN);
|
||||
uint32 const warlockMask = GetClassMaskForClass(CLASS_WARLOCK);
|
||||
uint32 const deathKnightMask = GetClassMaskForClass(CLASS_DEATH_KNIGHT);
|
||||
uint32 const druidMask = GetClassMaskForClass(CLASS_DRUID);
|
||||
|
||||
for (uint32 spellId : { 13819u, 23214u, 34767u, 34769u, 66906u })
|
||||
SetMountClassRestriction(spellId, paladinMask);
|
||||
|
||||
for (uint32 spellId : { 5784u, 23161u })
|
||||
SetMountClassRestriction(spellId, warlockMask);
|
||||
|
||||
for (uint32 spellId : { 48778u, 54729u })
|
||||
SetMountClassRestriction(spellId, deathKnightMask);
|
||||
|
||||
for (uint32 spellId : { 33943u, 40120u, 40121u })
|
||||
SetMountClassRestriction(spellId, druidMask);
|
||||
}
|
||||
|
||||
TeamId GetAllowedMountTeamForRaceMask(uint32 allowableRace)
|
||||
{
|
||||
uint32 const playableRaceMask = sRaceMgr->GetPlayableRaceMask();
|
||||
uint32 const allowedRaceMask = allowableRace ? (allowableRace & playableRaceMask) : playableRaceMask;
|
||||
|
||||
if (!allowedRaceMask)
|
||||
return TEAM_NEUTRAL;
|
||||
|
||||
bool const hasAllianceRace = (allowedRaceMask & sRaceMgr->GetAllianceRaceMask()) != 0;
|
||||
bool const hasHordeRace = (allowedRaceMask & sRaceMgr->GetHordeRaceMask()) != 0;
|
||||
|
||||
if (hasAllianceRace && !hasHordeRace)
|
||||
return TEAM_ALLIANCE;
|
||||
|
||||
if (hasHordeRace && !hasAllianceRace)
|
||||
return TEAM_HORDE;
|
||||
|
||||
return TEAM_NEUTRAL;
|
||||
}
|
||||
|
||||
void SetMountSpellFaction(uint32 spellId, TeamId teamId, bool force = false)
|
||||
{
|
||||
if (!IsMountSpell(spellId))
|
||||
return;
|
||||
|
||||
auto itr = MountSpellFactionMap.find(spellId);
|
||||
if (itr == MountSpellFactionMap.end())
|
||||
{
|
||||
MountSpellFactionMap.emplace(spellId, teamId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (force)
|
||||
{
|
||||
itr->second = teamId;
|
||||
return;
|
||||
}
|
||||
|
||||
if (teamId == TEAM_NEUTRAL)
|
||||
{
|
||||
itr->second = TEAM_NEUTRAL;
|
||||
return;
|
||||
}
|
||||
|
||||
if (itr->second == TEAM_NEUTRAL)
|
||||
{
|
||||
itr->second = teamId;
|
||||
return;
|
||||
}
|
||||
|
||||
if (itr->second != teamId)
|
||||
itr->second = TEAM_NEUTRAL;
|
||||
}
|
||||
|
||||
void BuildMountCache()
|
||||
{
|
||||
MountSpellFactionMap.clear();
|
||||
MountSpellRequirementsMap.clear();
|
||||
|
||||
for (uint32 spellId = 1; spellId < sSpellMgr->GetSpellInfoStoreSize(); ++spellId)
|
||||
{
|
||||
if (!IsMountSpell(spellId))
|
||||
continue;
|
||||
|
||||
MountSpellFactionMap.emplace(spellId, TEAM_NEUTRAL);
|
||||
MountSpellRequirementsMap.emplace(spellId, MountSpellRequirements{});
|
||||
|
||||
SkillLineAbilityMapBounds bounds = sSpellMgr->GetSkillLineAbilityMapBounds(spellId);
|
||||
for (SkillLineAbilityMap::const_iterator itr = bounds.first; itr != bounds.second; ++itr)
|
||||
{
|
||||
SkillLineAbilityEntry const* skillLineAbility = itr->second;
|
||||
if (!skillLineAbility)
|
||||
continue;
|
||||
|
||||
SetMountClassRestriction(spellId, skillLineAbility->ClassMask);
|
||||
|
||||
if (skillLineAbility->SkillLine == SKILL_RIDING)
|
||||
SetMountRidingRequirement(spellId, uint16(skillLineAbility->MinSkillLineRank));
|
||||
}
|
||||
}
|
||||
|
||||
if (ItemTemplateContainer const* itemTemplates = sObjectMgr->GetItemTemplateStore())
|
||||
{
|
||||
for (auto const& itemTemplatePair : *itemTemplates)
|
||||
{
|
||||
ItemTemplate const& itemTemplate = itemTemplatePair.second;
|
||||
if (itemTemplate.Class != ITEM_CLASS_MISC || itemTemplate.SubClass != ITEM_SUBCLASS_JUNK_MOUNT)
|
||||
continue;
|
||||
|
||||
TeamId const itemTeam = GetAllowedMountTeamForRaceMask(itemTemplate.AllowableRace);
|
||||
|
||||
for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i)
|
||||
{
|
||||
int32 const itemSpellId = itemTemplate.Spells[i].SpellId;
|
||||
if (itemSpellId <= 0 || !IsMountSpell(uint32(itemSpellId)))
|
||||
continue;
|
||||
|
||||
SetMountSpellFaction(uint32(itemSpellId), itemTeam);
|
||||
SetMountClassRestriction(uint32(itemSpellId), itemTemplate.AllowableClass);
|
||||
|
||||
if (itemTemplate.RequiredSkill == SKILL_RIDING)
|
||||
SetMountRidingRequirement(uint32(itemSpellId), uint16(itemTemplate.RequiredSkillRank));
|
||||
|
||||
SetMountRidingRequirement(uint32(itemSpellId), GetRidingRankFromRequiredSpell(itemTemplate.RequiredSpell));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto const& [allianceSpell, hordeSpell] : sObjectMgr->FactionChangeSpells)
|
||||
{
|
||||
if (!IsMountSpell(allianceSpell) || !IsMountSpell(hordeSpell))
|
||||
continue;
|
||||
|
||||
SetMountSpellFaction(allianceSpell, TEAM_ALLIANCE, true);
|
||||
SetMountSpellFaction(hordeSpell, TEAM_HORDE, true);
|
||||
}
|
||||
|
||||
ApplyClassMountFallbacks();
|
||||
LOG_INFO("module.accountboundmounts",
|
||||
"AccountBoundMounts: cached {} faction rule(s) and {} requirement rule(s).",
|
||||
MountSpellFactionMap.size(), MountSpellRequirementsMap.size());
|
||||
}
|
||||
|
||||
TeamId GetMountSpellFaction(uint32 spellId)
|
||||
{
|
||||
auto itr = MountSpellFactionMap.find(spellId);
|
||||
return itr != MountSpellFactionMap.end() ? itr->second : TEAM_NEUTRAL;
|
||||
}
|
||||
|
||||
uint32 GetFactionConvertedMountSpell(uint32 spellId, TeamId targetTeam)
|
||||
{
|
||||
for (auto const& [allianceSpell, hordeSpell] : sObjectMgr->FactionChangeSpells)
|
||||
{
|
||||
if (!IsMountSpell(allianceSpell) || !IsMountSpell(hordeSpell))
|
||||
continue;
|
||||
|
||||
if (spellId == allianceSpell && targetTeam == TEAM_HORDE)
|
||||
return hordeSpell;
|
||||
|
||||
if (spellId == hordeSpell && targetTeam == TEAM_ALLIANCE)
|
||||
return allianceSpell;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool IsMountSpellAllowedForTeam(uint32 spellId, TeamId targetTeam)
|
||||
{
|
||||
if (!Config.RespectFactionRestrictions)
|
||||
return true;
|
||||
|
||||
TeamId const mountTeam = GetMountSpellFaction(spellId);
|
||||
return mountTeam == TEAM_NEUTRAL || mountTeam == targetTeam;
|
||||
}
|
||||
|
||||
uint32 GetMountSpellForRace(uint32 spellId, uint8 race)
|
||||
{
|
||||
if (!Config.Filter.Allows(spellId) || !IsMountSpell(spellId))
|
||||
return 0;
|
||||
|
||||
TeamId const targetTeam = Player::TeamIdForRace(race);
|
||||
if (IsMountSpellAllowedForTeam(spellId, targetTeam))
|
||||
return spellId;
|
||||
|
||||
if (!Config.ConvertFactionSpecific)
|
||||
return 0;
|
||||
|
||||
uint32 const convertedSpellId = GetFactionConvertedMountSpell(spellId, targetTeam);
|
||||
return Config.Filter.Allows(convertedSpellId) &&
|
||||
IsMountSpellAllowedForTeam(convertedSpellId, targetTeam) ? convertedSpellId : 0;
|
||||
}
|
||||
|
||||
bool IsClassRestrictedMount(uint32 spellId)
|
||||
{
|
||||
return GetMountSpellRequirements(spellId).ClassMask != 0;
|
||||
}
|
||||
|
||||
bool ShouldAccountSyncMount(uint32 spellId)
|
||||
{
|
||||
return Config.Filter.Allows(spellId) && IsMountSpell(spellId) &&
|
||||
(Config.SyncClassMounts || !IsClassRestrictedMount(spellId));
|
||||
}
|
||||
|
||||
bool CanShareClassMountFromRace(uint32 spellId, uint8 sourceRace, uint8 targetRace)
|
||||
{
|
||||
if (!Config.ClassMountsSameFactionOnly || !sourceRace || !IsClassRestrictedMount(spellId))
|
||||
return true;
|
||||
|
||||
return Player::TeamIdForRace(sourceRace) == Player::TeamIdForRace(targetRace);
|
||||
}
|
||||
|
||||
bool CanCharacterReceiveMount(uint32 spellId, uint8 classId, uint16 ridingSkill, uint8 sourceRace = 0, uint8 targetRace = 0)
|
||||
{
|
||||
MountSpellRequirements const& requirements = GetMountSpellRequirements(spellId);
|
||||
|
||||
if (Config.RequireRiding && ridingSkill < requirements.RequiredRidingRank)
|
||||
return false;
|
||||
|
||||
if (Config.RequireClass && requirements.ClassMask && !(requirements.ClassMask & GetClassMaskForClass(classId)))
|
||||
return false;
|
||||
|
||||
return !targetRace || CanShareClassMountFromRace(spellId, sourceRace, targetRace);
|
||||
}
|
||||
|
||||
bool CanCharacterReceiveMount(uint32 spellId, CharacterInfo const& character, uint8 sourceRace = 0)
|
||||
{
|
||||
return CanCharacterReceiveMount(spellId, character.Class, character.RidingSkill, sourceRace, character.Race);
|
||||
}
|
||||
|
||||
bool CanPlayerReceiveMount(uint32 spellId, Player* player, uint8 sourceRace = 0)
|
||||
{
|
||||
return player && CanCharacterReceiveMount(
|
||||
spellId, player->getClass(), player->GetSkillValue(SKILL_RIDING), sourceRace, player->getRace(true));
|
||||
}
|
||||
|
||||
void AppendOrCommit(CharacterDatabaseTransaction& trans, std::string_view sql)
|
||||
{
|
||||
if (!trans)
|
||||
trans = CharacterDatabase.BeginTransaction();
|
||||
|
||||
trans->Append(sql);
|
||||
|
||||
if (trans->GetSize() >= 1000)
|
||||
{
|
||||
CharacterDatabase.DirectCommitTransaction(trans);
|
||||
trans = CharacterDatabase.BeginTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
void CommitIfNeeded(CharacterDatabaseTransaction& trans)
|
||||
{
|
||||
if (trans && trans->GetSize())
|
||||
CharacterDatabase.DirectCommitTransaction(trans);
|
||||
}
|
||||
|
||||
void InsertMountForCharacter(CharacterDatabaseTransaction& trans, uint32 targetGuid, uint32 spellId)
|
||||
{
|
||||
AppendOrCommit(trans, Acore::StringFormat(
|
||||
"INSERT IGNORE INTO character_spell (guid, spell, specMask) VALUES ({}, {}, {})",
|
||||
targetGuid, spellId, uint32(SPEC_MASK_ALL)));
|
||||
}
|
||||
|
||||
void DeleteMountForCharacter(CharacterDatabaseTransaction& trans, uint32 targetGuid, uint32 spellId)
|
||||
{
|
||||
AppendOrCommit(trans, Acore::StringFormat(
|
||||
"DELETE FROM character_spell WHERE guid = {} AND spell = {}",
|
||||
targetGuid, spellId));
|
||||
}
|
||||
|
||||
std::vector<CharacterInfo> LoadAccountCharacters(uint32 accountId)
|
||||
{
|
||||
std::vector<CharacterInfo> characters;
|
||||
QueryResult result = CharacterDatabase.Query(
|
||||
"SELECT c.guid, c.account, c.race, c.`class`, COALESCE(cs.value, 0) "
|
||||
"FROM characters c "
|
||||
"LEFT JOIN character_skills cs ON cs.guid = c.guid AND cs.skill = {} "
|
||||
"WHERE c.account = {}",
|
||||
uint32(SKILL_RIDING), accountId);
|
||||
|
||||
if (!result)
|
||||
return characters;
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
characters.push_back({
|
||||
fields[0].Get<uint32>(),
|
||||
fields[1].Get<uint32>(),
|
||||
fields[2].Get<uint8>(),
|
||||
fields[3].Get<uint8>(),
|
||||
fields[4].Get<uint16>()
|
||||
});
|
||||
} while (result->NextRow());
|
||||
|
||||
return characters;
|
||||
}
|
||||
|
||||
void SyncMountToAccount(Player* player, uint32 spellId)
|
||||
{
|
||||
if (!Config.Enabled || !player || !ShouldAccountSyncMount(spellId))
|
||||
return;
|
||||
|
||||
uint8 const sourceRace = player->getRace(true);
|
||||
std::vector<CharacterInfo> characters = LoadAccountCharacters(player->GetSession()->GetAccountId());
|
||||
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
uint32 synced = 0;
|
||||
|
||||
for (CharacterInfo const& target : characters)
|
||||
{
|
||||
if (target.Guid == player->GetGUID().GetCounter())
|
||||
continue;
|
||||
|
||||
uint32 const targetSpellId = GetMountSpellForRace(spellId, target.Race);
|
||||
if (!targetSpellId || !CanCharacterReceiveMount(targetSpellId, target, sourceRace))
|
||||
continue;
|
||||
|
||||
InsertMountForCharacter(trans, target.Guid, targetSpellId);
|
||||
++synced;
|
||||
}
|
||||
|
||||
CommitIfNeeded(trans);
|
||||
|
||||
if (synced)
|
||||
LOG_DEBUG("module.accountboundmounts",
|
||||
"AccountBoundMounts: synced mount spell {} from player {} to {} account character(s).",
|
||||
spellId, player->GetGUID().GetCounter(), synced);
|
||||
}
|
||||
|
||||
void BackfillMountsForCharacter(Player* player)
|
||||
{
|
||||
if (!Config.Enabled || !player)
|
||||
return;
|
||||
|
||||
uint32 const accountId = player->GetSession()->GetAccountId();
|
||||
uint32 const targetGuid = player->GetGUID().GetCounter();
|
||||
uint8 const targetRace = player->getRace(true);
|
||||
QueryResult result = CharacterDatabase.Query(
|
||||
"SELECT DISTINCT cs.spell, c.race "
|
||||
"FROM character_spell cs "
|
||||
"INNER JOIN characters c ON c.guid = cs.guid "
|
||||
"WHERE c.account = {} AND c.guid <> {}",
|
||||
accountId, targetGuid);
|
||||
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
uint32 inserted = 0;
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
uint32 const spellId = fields[0].Get<uint32>();
|
||||
uint8 const sourceRace = fields[1].Get<uint8>();
|
||||
|
||||
if (!ShouldAccountSyncMount(spellId))
|
||||
continue;
|
||||
|
||||
uint32 const targetSpellId = GetMountSpellForRace(spellId, targetRace);
|
||||
if (!targetSpellId || !CanPlayerReceiveMount(targetSpellId, player, sourceRace))
|
||||
continue;
|
||||
|
||||
InsertMountForCharacter(trans, targetGuid, targetSpellId);
|
||||
++inserted;
|
||||
} while (result->NextRow());
|
||||
|
||||
CommitIfNeeded(trans);
|
||||
|
||||
if (inserted)
|
||||
LOG_INFO("module.accountboundmounts",
|
||||
"AccountBoundMounts: seeded {} mount spell row(s) for character {}.",
|
||||
inserted, targetGuid);
|
||||
}
|
||||
|
||||
void BackfillAllMounts()
|
||||
{
|
||||
if (!Config.Enabled || !Config.StartupBackfill)
|
||||
return;
|
||||
|
||||
QueryResult charactersResult = CharacterDatabase.Query(
|
||||
"SELECT c.guid, c.account, c.race, c.`class`, COALESCE(cs.value, 0) "
|
||||
"FROM characters c "
|
||||
"LEFT JOIN character_skills cs ON cs.guid = c.guid AND cs.skill = {} "
|
||||
"WHERE c.account <> 0",
|
||||
uint32(SKILL_RIDING));
|
||||
|
||||
if (!charactersResult)
|
||||
return;
|
||||
|
||||
std::unordered_map<uint32, std::vector<CharacterInfo>> charactersByAccount;
|
||||
do
|
||||
{
|
||||
Field* fields = charactersResult->Fetch();
|
||||
CharacterInfo character = {
|
||||
fields[0].Get<uint32>(),
|
||||
fields[1].Get<uint32>(),
|
||||
fields[2].Get<uint8>(),
|
||||
fields[3].Get<uint8>(),
|
||||
fields[4].Get<uint16>()
|
||||
};
|
||||
charactersByAccount[character.AccountId].push_back(character);
|
||||
} while (charactersResult->NextRow());
|
||||
|
||||
QueryResult spellsResult = CharacterDatabase.Query(
|
||||
"SELECT DISTINCT c.account, c.race, cs.spell "
|
||||
"FROM character_spell cs "
|
||||
"INNER JOIN characters c ON c.guid = cs.guid "
|
||||
"WHERE c.account <> 0");
|
||||
|
||||
if (!spellsResult)
|
||||
return;
|
||||
|
||||
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
uint64 inserted = 0;
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = spellsResult->Fetch();
|
||||
uint32 const accountId = fields[0].Get<uint32>();
|
||||
uint8 const sourceRace = fields[1].Get<uint8>();
|
||||
uint32 const spellId = fields[2].Get<uint32>();
|
||||
|
||||
if (!ShouldAccountSyncMount(spellId))
|
||||
continue;
|
||||
|
||||
auto accountItr = charactersByAccount.find(accountId);
|
||||
if (accountItr == charactersByAccount.end())
|
||||
continue;
|
||||
|
||||
for (CharacterInfo const& target : accountItr->second)
|
||||
{
|
||||
uint32 const targetSpellId = GetMountSpellForRace(spellId, target.Race);
|
||||
if (!targetSpellId || !CanCharacterReceiveMount(targetSpellId, target, sourceRace))
|
||||
continue;
|
||||
|
||||
InsertMountForCharacter(trans, target.Guid, targetSpellId);
|
||||
++inserted;
|
||||
}
|
||||
} while (spellsResult->NextRow());
|
||||
|
||||
CommitIfNeeded(trans);
|
||||
LOG_INFO("module.accountboundmounts",
|
||||
"AccountBoundMounts: startup backfill queued {} mount spell row(s).", inserted);
|
||||
}
|
||||
|
||||
void CleanupInvalidMounts()
|
||||
{
|
||||
if (!Config.Enabled || !Config.CleanupInvalid)
|
||||
return;
|
||||
|
||||
QueryResult result = CharacterDatabase.Query(
|
||||
"SELECT c.guid, c.race, c.`class`, COALESCE(sk.value, 0), cs.spell "
|
||||
"FROM character_spell cs "
|
||||
"INNER JOIN characters c ON c.guid = cs.guid "
|
||||
"LEFT JOIN character_skills sk ON sk.guid = c.guid AND sk.skill = {}",
|
||||
uint32(SKILL_RIDING));
|
||||
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
uint64 removed = 0;
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
CharacterInfo character = {
|
||||
fields[0].Get<uint32>(),
|
||||
0,
|
||||
fields[1].Get<uint8>(),
|
||||
fields[2].Get<uint8>(),
|
||||
fields[3].Get<uint16>()
|
||||
};
|
||||
uint32 const spellId = fields[4].Get<uint32>();
|
||||
|
||||
if (!ShouldAccountSyncMount(spellId))
|
||||
continue;
|
||||
|
||||
uint32 const allowedSpellId = GetMountSpellForRace(spellId, character.Race);
|
||||
if (allowedSpellId == spellId && CanCharacterReceiveMount(spellId, character))
|
||||
continue;
|
||||
|
||||
DeleteMountForCharacter(trans, character.Guid, spellId);
|
||||
++removed;
|
||||
} while (result->NextRow());
|
||||
|
||||
CommitIfNeeded(trans);
|
||||
|
||||
if (removed)
|
||||
LOG_INFO("module.accountboundmounts",
|
||||
"AccountBoundMounts: removed {} invalid mount spell row(s).", removed);
|
||||
}
|
||||
|
||||
void LoadModuleConfig()
|
||||
{
|
||||
Config.Enabled = AccountBound::IsCategoryEnabled("Mounts");
|
||||
Config.StartupBackfill = sConfigMgr->GetOption<bool>("AccountBound.Mounts.StartupBackfill", true);
|
||||
Config.SyncOnCreate = sConfigMgr->GetOption<bool>("AccountBound.Mounts.SyncOnCreate", true);
|
||||
Config.ConvertFactionSpecific = sConfigMgr->GetOption<bool>("AccountBound.Mounts.ConvertFactionSpecific", true);
|
||||
Config.RespectFactionRestrictions = sConfigMgr->GetOption<bool>("AccountBound.Mounts.RespectFactionRestrictions", true);
|
||||
Config.RequireRiding = sConfigMgr->GetOption<bool>("AccountBound.Mounts.RequireRiding", true);
|
||||
Config.SyncClassMounts = sConfigMgr->GetOption<bool>("AccountBound.Mounts.SyncClassMounts", true);
|
||||
Config.RequireClass = sConfigMgr->GetOption<bool>("AccountBound.Mounts.RequireClass", true);
|
||||
Config.ClassMountsSameFactionOnly = sConfigMgr->GetOption<bool>("AccountBound.Mounts.ClassMountsSameFactionOnly", true);
|
||||
Config.CleanupInvalid = sConfigMgr->GetOption<bool>("AccountBound.Mounts.CleanupInvalid", true);
|
||||
Config.BackfillOnRidingSkillChange = sConfigMgr->GetOption<bool>("AccountBound.Mounts.BackfillOnRidingSkillChange", true);
|
||||
Config.Filter = AccountBound::LoadIdFilter("Mounts");
|
||||
}
|
||||
}
|
||||
|
||||
class AccountBoundMountsWorldScript : public WorldScript
|
||||
{
|
||||
public:
|
||||
AccountBoundMountsWorldScript() : WorldScript("AccountBoundMountsWorldScript", {
|
||||
WORLDHOOK_ON_AFTER_CONFIG_LOAD,
|
||||
WORLDHOOK_ON_STARTUP
|
||||
}) { }
|
||||
|
||||
void OnAfterConfigLoad(bool reload) override
|
||||
{
|
||||
LoadModuleConfig();
|
||||
LOG_INFO("module.accountboundmounts",
|
||||
"AccountBoundMounts: {}. CreateSync={}, StartupBackfill={}, RequireRiding={}, RequireClass={}.",
|
||||
Config.Enabled ? (reload ? "configuration reloaded" : "configuration loaded") : "disabled",
|
||||
Config.Enabled && Config.SyncOnCreate ? "on" : "off",
|
||||
Config.Enabled && Config.StartupBackfill ? "on" : "off",
|
||||
Config.Enabled && Config.RequireRiding ? "on" : "off",
|
||||
Config.Enabled && Config.RequireClass ? "on" : "off");
|
||||
}
|
||||
|
||||
void OnStartup() override
|
||||
{
|
||||
if (!Config.Enabled)
|
||||
return;
|
||||
|
||||
BuildMountCache();
|
||||
CleanupInvalidMounts();
|
||||
BackfillAllMounts();
|
||||
}
|
||||
};
|
||||
|
||||
class AccountBoundMountsPlayerScript : public PlayerScript
|
||||
{
|
||||
public:
|
||||
AccountBoundMountsPlayerScript() : PlayerScript("AccountBoundMountsPlayerScript", {
|
||||
PLAYERHOOK_ON_CREATE,
|
||||
PLAYERHOOK_ON_LEARN_SPELL,
|
||||
PLAYERHOOK_ON_SET_SKILL
|
||||
}) { }
|
||||
|
||||
void OnPlayerCreate(Player* player) override
|
||||
{
|
||||
if (Config.SyncOnCreate)
|
||||
BackfillMountsForCharacter(player);
|
||||
}
|
||||
|
||||
void OnPlayerLearnSpell(Player* player, uint32 spellId) override
|
||||
{
|
||||
SyncMountToAccount(player, spellId);
|
||||
}
|
||||
|
||||
void OnPlayerSetSkill(Player* player, uint32 skillId, uint32 value, uint32 /*max*/, uint32 /*step*/, uint32 newValue) override
|
||||
{
|
||||
if (!Config.Enabled || !Config.BackfillOnRidingSkillChange || skillId != SKILL_RIDING || newValue <= value)
|
||||
return;
|
||||
|
||||
BackfillMountsForCharacter(player);
|
||||
}
|
||||
};
|
||||
|
||||
void AddAccountBoundMountsScripts()
|
||||
{
|
||||
new AccountBoundMountsWorldScript();
|
||||
new AccountBoundMountsPlayerScript();
|
||||
}
|
||||
@@ -0,0 +1,348 @@
|
||||
/*
|
||||
* Account-bound companion pets for AzerothCore.
|
||||
*/
|
||||
|
||||
#include "AccountBound.h"
|
||||
#include "Config.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "DBCStores.h"
|
||||
#include "Log.h"
|
||||
#include "Player.h"
|
||||
#include "PlayerScript.h"
|
||||
#include "SpellInfo.h"
|
||||
#include "SpellMgr.h"
|
||||
#include "StringFormat.h"
|
||||
#include "WorldScript.h"
|
||||
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct ModuleConfig
|
||||
{
|
||||
bool Enabled = true;
|
||||
bool StartupBackfill = true;
|
||||
bool SyncOnCreate = true;
|
||||
bool SameFactionOnly = false;
|
||||
bool IncludeCompanionSkillLine = true;
|
||||
bool IncludeMinipetSummons = true;
|
||||
AccountBound::IdFilter Filter;
|
||||
};
|
||||
|
||||
struct CharacterInfo
|
||||
{
|
||||
uint32 Guid = 0;
|
||||
uint8 Race = 0;
|
||||
};
|
||||
|
||||
ModuleConfig Config;
|
||||
std::unordered_set<uint32> CompanionSpells;
|
||||
|
||||
bool HasCompanionSkillLine(uint32 spellId)
|
||||
{
|
||||
SkillLineAbilityMapBounds bounds = sSpellMgr->GetSkillLineAbilityMapBounds(spellId);
|
||||
for (SkillLineAbilityMap::const_iterator itr = bounds.first; itr != bounds.second; ++itr)
|
||||
if (itr->second && itr->second->SkillLine == SKILL_COMPANIONS)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsMinipetSummon(SpellInfo const* spellInfo)
|
||||
{
|
||||
if (!spellInfo)
|
||||
return false;
|
||||
|
||||
for (uint8 effectIndex = 0; effectIndex < MAX_SPELL_EFFECTS; ++effectIndex)
|
||||
{
|
||||
SpellEffectInfo const& effect = spellInfo->Effects[effectIndex];
|
||||
if (effect.Effect != SPELL_EFFECT_SUMMON || effect.MiscValue <= 0)
|
||||
continue;
|
||||
|
||||
SummonPropertiesEntry const* properties = sSummonPropertiesStore.LookupEntry(effect.MiscValueB);
|
||||
if (properties && properties->Type == SUMMON_TYPE_MINIPET)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsCompanionSpell(uint32 spellId)
|
||||
{
|
||||
return Config.Filter.Allows(spellId) && CompanionSpells.find(spellId) != CompanionSpells.end();
|
||||
}
|
||||
|
||||
void BuildCompanionCache()
|
||||
{
|
||||
CompanionSpells.clear();
|
||||
|
||||
for (uint32 spellId = 1; spellId < sSpellMgr->GetSpellInfoStoreSize(); ++spellId)
|
||||
{
|
||||
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
|
||||
if (!spellInfo)
|
||||
continue;
|
||||
|
||||
bool const companionSkill = Config.IncludeCompanionSkillLine && HasCompanionSkillLine(spellId);
|
||||
bool const minipetSummon = Config.IncludeMinipetSummons && IsMinipetSummon(spellInfo);
|
||||
if (companionSkill || minipetSummon)
|
||||
CompanionSpells.insert(spellId);
|
||||
}
|
||||
|
||||
LOG_INFO("module.accountboundpets",
|
||||
"AccountBoundPets: cached {} companion pet spell(s).", CompanionSpells.size());
|
||||
}
|
||||
|
||||
bool CanShareBetweenRaces(uint8 sourceRace, uint8 targetRace)
|
||||
{
|
||||
return !Config.SameFactionOnly || Player::TeamIdForRace(sourceRace) == Player::TeamIdForRace(targetRace);
|
||||
}
|
||||
|
||||
void AppendOrCommit(CharacterDatabaseTransaction& trans, std::string_view sql)
|
||||
{
|
||||
if (!trans)
|
||||
trans = CharacterDatabase.BeginTransaction();
|
||||
|
||||
trans->Append(sql);
|
||||
|
||||
if (trans->GetSize() >= 1000)
|
||||
{
|
||||
CharacterDatabase.DirectCommitTransaction(trans);
|
||||
trans = CharacterDatabase.BeginTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
void CommitIfNeeded(CharacterDatabaseTransaction& trans)
|
||||
{
|
||||
if (trans && trans->GetSize())
|
||||
CharacterDatabase.DirectCommitTransaction(trans);
|
||||
}
|
||||
|
||||
void InsertCompanionForCharacter(CharacterDatabaseTransaction& trans, uint32 targetGuid, uint32 spellId)
|
||||
{
|
||||
AppendOrCommit(trans, Acore::StringFormat(
|
||||
"INSERT IGNORE INTO character_spell (guid, spell, specMask) VALUES ({}, {}, {})",
|
||||
targetGuid, spellId, uint32(SPEC_MASK_ALL)));
|
||||
}
|
||||
|
||||
std::vector<CharacterInfo> LoadAccountCharacters(uint32 accountId)
|
||||
{
|
||||
std::vector<CharacterInfo> characters;
|
||||
QueryResult result = CharacterDatabase.Query(
|
||||
"SELECT guid, race FROM characters WHERE account = {}", accountId);
|
||||
|
||||
if (!result)
|
||||
return characters;
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
characters.push_back({
|
||||
fields[0].Get<uint32>(),
|
||||
fields[1].Get<uint8>()
|
||||
});
|
||||
} while (result->NextRow());
|
||||
|
||||
return characters;
|
||||
}
|
||||
|
||||
void SyncCompanionToAccount(Player* player, uint32 spellId)
|
||||
{
|
||||
if (!Config.Enabled || !player || !IsCompanionSpell(spellId))
|
||||
return;
|
||||
|
||||
uint32 const sourceGuid = player->GetGUID().GetCounter();
|
||||
uint8 const sourceRace = player->getRace(true);
|
||||
std::vector<CharacterInfo> characters = LoadAccountCharacters(player->GetSession()->GetAccountId());
|
||||
CharacterDatabaseTransaction trans;
|
||||
uint32 synced = 0;
|
||||
|
||||
for (CharacterInfo const& target : characters)
|
||||
{
|
||||
if (target.Guid == sourceGuid || !CanShareBetweenRaces(sourceRace, target.Race))
|
||||
continue;
|
||||
|
||||
InsertCompanionForCharacter(trans, target.Guid, spellId);
|
||||
++synced;
|
||||
}
|
||||
|
||||
CommitIfNeeded(trans);
|
||||
|
||||
if (synced)
|
||||
LOG_DEBUG("module.accountboundpets",
|
||||
"AccountBoundPets: synced companion spell {} from player {} to {} account character(s).",
|
||||
spellId, sourceGuid, synced);
|
||||
}
|
||||
|
||||
void SeedCompanionsForCharacter(Player* player)
|
||||
{
|
||||
if (!Config.Enabled || !player)
|
||||
return;
|
||||
|
||||
uint32 const accountId = player->GetSession()->GetAccountId();
|
||||
uint32 const targetGuid = player->GetGUID().GetCounter();
|
||||
uint8 const targetRace = player->getRace(true);
|
||||
QueryResult result = CharacterDatabase.Query(
|
||||
"SELECT DISTINCT cs.spell, c.race "
|
||||
"FROM character_spell cs "
|
||||
"INNER JOIN characters c ON c.guid = cs.guid "
|
||||
"WHERE c.account = {} AND c.guid <> {}",
|
||||
accountId, targetGuid);
|
||||
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
CharacterDatabaseTransaction trans;
|
||||
uint32 inserted = 0;
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
uint32 const spellId = fields[0].Get<uint32>();
|
||||
uint8 const sourceRace = fields[1].Get<uint8>();
|
||||
|
||||
if (!IsCompanionSpell(spellId) || !CanShareBetweenRaces(sourceRace, targetRace))
|
||||
continue;
|
||||
|
||||
InsertCompanionForCharacter(trans, targetGuid, spellId);
|
||||
++inserted;
|
||||
} while (result->NextRow());
|
||||
|
||||
CommitIfNeeded(trans);
|
||||
|
||||
if (inserted)
|
||||
LOG_INFO("module.accountboundpets",
|
||||
"AccountBoundPets: seeded {} companion spell row(s) for character {}.",
|
||||
inserted, targetGuid);
|
||||
}
|
||||
|
||||
void BackfillAllCompanions()
|
||||
{
|
||||
if (!Config.Enabled || !Config.StartupBackfill)
|
||||
return;
|
||||
|
||||
QueryResult charactersResult = CharacterDatabase.Query(
|
||||
"SELECT guid, account, race FROM characters WHERE account <> 0");
|
||||
|
||||
if (!charactersResult)
|
||||
return;
|
||||
|
||||
std::unordered_map<uint32, std::vector<CharacterInfo>> charactersByAccount;
|
||||
do
|
||||
{
|
||||
Field* fields = charactersResult->Fetch();
|
||||
charactersByAccount[fields[1].Get<uint32>()].push_back({
|
||||
fields[0].Get<uint32>(),
|
||||
fields[2].Get<uint8>()
|
||||
});
|
||||
} while (charactersResult->NextRow());
|
||||
|
||||
QueryResult spellsResult = CharacterDatabase.Query(
|
||||
"SELECT DISTINCT c.account, c.race, cs.spell "
|
||||
"FROM character_spell cs "
|
||||
"INNER JOIN characters c ON c.guid = cs.guid "
|
||||
"WHERE c.account <> 0");
|
||||
|
||||
if (!spellsResult)
|
||||
return;
|
||||
|
||||
CharacterDatabaseTransaction trans;
|
||||
uint64 queued = 0;
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = spellsResult->Fetch();
|
||||
uint32 const accountId = fields[0].Get<uint32>();
|
||||
uint8 const sourceRace = fields[1].Get<uint8>();
|
||||
uint32 const spellId = fields[2].Get<uint32>();
|
||||
|
||||
if (!IsCompanionSpell(spellId))
|
||||
continue;
|
||||
|
||||
auto accountItr = charactersByAccount.find(accountId);
|
||||
if (accountItr == charactersByAccount.end())
|
||||
continue;
|
||||
|
||||
for (CharacterInfo const& target : accountItr->second)
|
||||
{
|
||||
if (!CanShareBetweenRaces(sourceRace, target.Race))
|
||||
continue;
|
||||
|
||||
InsertCompanionForCharacter(trans, target.Guid, spellId);
|
||||
++queued;
|
||||
}
|
||||
} while (spellsResult->NextRow());
|
||||
|
||||
CommitIfNeeded(trans);
|
||||
LOG_INFO("module.accountboundpets",
|
||||
"AccountBoundPets: startup backfill queued {} companion spell row(s).", queued);
|
||||
}
|
||||
|
||||
void LoadModuleConfig()
|
||||
{
|
||||
Config.Enabled = AccountBound::IsCategoryEnabled("Pets");
|
||||
Config.StartupBackfill = sConfigMgr->GetOption<bool>("AccountBound.Pets.StartupBackfill", true);
|
||||
Config.SyncOnCreate = sConfigMgr->GetOption<bool>("AccountBound.Pets.SyncOnCreate", true);
|
||||
Config.SameFactionOnly = sConfigMgr->GetOption<bool>("AccountBound.Pets.SameFactionOnly", false);
|
||||
Config.IncludeCompanionSkillLine = sConfigMgr->GetOption<bool>("AccountBound.Pets.IncludeCompanionSkillLine", true);
|
||||
Config.IncludeMinipetSummons = sConfigMgr->GetOption<bool>("AccountBound.Pets.IncludeMinipetSummons", true);
|
||||
Config.Filter = AccountBound::LoadIdFilter("Pets");
|
||||
}
|
||||
}
|
||||
|
||||
class AccountBoundPetsWorldScript : public WorldScript
|
||||
{
|
||||
public:
|
||||
AccountBoundPetsWorldScript() : WorldScript("AccountBoundPetsWorldScript", {
|
||||
WORLDHOOK_ON_AFTER_CONFIG_LOAD,
|
||||
WORLDHOOK_ON_STARTUP
|
||||
}) { }
|
||||
|
||||
void OnAfterConfigLoad(bool reload) override
|
||||
{
|
||||
LoadModuleConfig();
|
||||
LOG_INFO("module.accountboundpets",
|
||||
"AccountBoundPets: {}. StartupBackfill={}, CreateSync={}, SameFactionOnly={}.",
|
||||
Config.Enabled ? (reload ? "configuration reloaded" : "configuration loaded") : "disabled",
|
||||
Config.Enabled && Config.StartupBackfill ? "on" : "off",
|
||||
Config.Enabled && Config.SyncOnCreate ? "on" : "off",
|
||||
Config.Enabled && Config.SameFactionOnly ? "on" : "off");
|
||||
}
|
||||
|
||||
void OnStartup() override
|
||||
{
|
||||
if (!Config.Enabled)
|
||||
return;
|
||||
|
||||
BuildCompanionCache();
|
||||
BackfillAllCompanions();
|
||||
}
|
||||
};
|
||||
|
||||
class AccountBoundPetsPlayerScript : public PlayerScript
|
||||
{
|
||||
public:
|
||||
AccountBoundPetsPlayerScript() : PlayerScript("AccountBoundPetsPlayerScript", {
|
||||
PLAYERHOOK_ON_CREATE,
|
||||
PLAYERHOOK_ON_LEARN_SPELL
|
||||
}) { }
|
||||
|
||||
void OnPlayerCreate(Player* player) override
|
||||
{
|
||||
if (Config.SyncOnCreate)
|
||||
SeedCompanionsForCharacter(player);
|
||||
}
|
||||
|
||||
void OnPlayerLearnSpell(Player* player, uint32 spellId) override
|
||||
{
|
||||
SyncCompanionToAccount(player, spellId);
|
||||
}
|
||||
};
|
||||
|
||||
void AddAccountBoundPetsScripts()
|
||||
{
|
||||
new AccountBoundPetsWorldScript();
|
||||
new AccountBoundPetsPlayerScript();
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,419 @@
|
||||
/*
|
||||
* Account-bound reputations for AzerothCore.
|
||||
*/
|
||||
|
||||
#include "AccountBound.h"
|
||||
#include "Config.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "DBCStores.h"
|
||||
#include "Log.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "Player.h"
|
||||
#include "PlayerScript.h"
|
||||
#include "ReputationMgr.h"
|
||||
#include "StringFormat.h"
|
||||
#include "WorldScript.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct ModuleConfig
|
||||
{
|
||||
bool Enabled = true;
|
||||
bool StartupBackfill = true;
|
||||
bool SyncOnCreate = true;
|
||||
bool SyncOnChange = true;
|
||||
bool SameFactionOnly = true;
|
||||
bool ConvertFactionSpecific = true;
|
||||
bool SyncUnpairedCrossFaction = false;
|
||||
AccountBound::IdFilter Filter;
|
||||
};
|
||||
|
||||
struct ReputationInfo
|
||||
{
|
||||
int32 Standing = 0;
|
||||
uint16 Flags = 0;
|
||||
};
|
||||
|
||||
struct CharacterInfo
|
||||
{
|
||||
uint32 Guid = 0;
|
||||
uint32 AccountId = 0;
|
||||
uint8 Race = 0;
|
||||
uint8 Class = 0;
|
||||
std::unordered_map<uint32, ReputationInfo> Reputations;
|
||||
};
|
||||
|
||||
ModuleConfig Config;
|
||||
|
||||
void AppendOrCommit(CharacterDatabaseTransaction& trans, std::string_view sql)
|
||||
{
|
||||
if (!trans)
|
||||
trans = CharacterDatabase.BeginTransaction();
|
||||
|
||||
trans->Append(sql);
|
||||
|
||||
if (trans->GetSize() >= 1000)
|
||||
{
|
||||
CharacterDatabase.DirectCommitTransaction(trans);
|
||||
trans = CharacterDatabase.BeginTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
void CommitIfNeeded(CharacterDatabaseTransaction& trans)
|
||||
{
|
||||
if (trans && trans->GetSize())
|
||||
CharacterDatabase.DirectCommitTransaction(trans);
|
||||
}
|
||||
|
||||
bool CanShareBetweenRaces(uint8 sourceRace, uint8 targetRace)
|
||||
{
|
||||
return !Config.SameFactionOnly || Player::TeamIdForRace(sourceRace) == Player::TeamIdForRace(targetRace);
|
||||
}
|
||||
|
||||
uint32 GetFactionForTarget(uint32 factionId, uint8 sourceRace, uint8 targetRace)
|
||||
{
|
||||
if (!Config.Filter.Allows(factionId))
|
||||
return 0;
|
||||
|
||||
TeamId const sourceTeam = Player::TeamIdForRace(sourceRace);
|
||||
TeamId const targetTeam = Player::TeamIdForRace(targetRace);
|
||||
|
||||
if (sourceTeam == targetTeam)
|
||||
return factionId;
|
||||
|
||||
if (Config.SameFactionOnly)
|
||||
return 0;
|
||||
|
||||
if (Config.ConvertFactionSpecific)
|
||||
{
|
||||
for (auto const& [allianceFaction, hordeFaction] : sObjectMgr->FactionChangeReputation)
|
||||
{
|
||||
if (sourceTeam == TEAM_ALLIANCE && factionId == allianceFaction)
|
||||
return Config.Filter.Allows(targetTeam == TEAM_HORDE ? hordeFaction : allianceFaction) ?
|
||||
(targetTeam == TEAM_HORDE ? hordeFaction : allianceFaction) : 0;
|
||||
|
||||
if (sourceTeam == TEAM_HORDE && factionId == hordeFaction)
|
||||
return Config.Filter.Allows(targetTeam == TEAM_ALLIANCE ? allianceFaction : hordeFaction) ?
|
||||
(targetTeam == TEAM_ALLIANCE ? allianceFaction : hordeFaction) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
return Config.SyncUnpairedCrossFaction ? factionId : 0;
|
||||
}
|
||||
|
||||
int32 GetAbsoluteStanding(CharacterInfo const& character, uint32 factionId, ReputationInfo const& reputation)
|
||||
{
|
||||
FactionEntry const* faction = sFactionStore.LookupEntry(factionId);
|
||||
if (!faction || !faction->CanHaveReputation())
|
||||
return ReputationMgr::Reputation_Bottom;
|
||||
|
||||
int32 const base = sObjectMgr->GetBaseReputationOf(faction, character.Race, character.Class);
|
||||
return std::clamp(base + reputation.Standing, ReputationMgr::Reputation_Bottom, ReputationMgr::Reputation_Cap);
|
||||
}
|
||||
|
||||
int32 GetStoredStanding(CharacterInfo const& character, uint32 factionId, int32 absoluteStanding)
|
||||
{
|
||||
FactionEntry const* faction = sFactionStore.LookupEntry(factionId);
|
||||
if (!faction)
|
||||
return 0;
|
||||
|
||||
int32 const base = sObjectMgr->GetBaseReputationOf(faction, character.Race, character.Class);
|
||||
return std::clamp(absoluteStanding, ReputationMgr::Reputation_Bottom, ReputationMgr::Reputation_Cap) - base;
|
||||
}
|
||||
|
||||
std::vector<CharacterInfo> LoadCharacters(uint32 accountId = 0)
|
||||
{
|
||||
std::vector<CharacterInfo> characters;
|
||||
std::unordered_map<uint32, std::size_t> characterIndexes;
|
||||
QueryResult result;
|
||||
|
||||
if (accountId)
|
||||
{
|
||||
result = CharacterDatabase.Query(
|
||||
"SELECT c.guid, c.account, c.race, c.class, cr.faction, cr.standing, cr.flags "
|
||||
"FROM characters c "
|
||||
"LEFT JOIN character_reputation cr ON cr.guid = c.guid "
|
||||
"WHERE c.account = {} "
|
||||
"ORDER BY c.guid",
|
||||
accountId);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = CharacterDatabase.Query(
|
||||
"SELECT c.guid, c.account, c.race, c.class, cr.faction, cr.standing, cr.flags "
|
||||
"FROM characters c "
|
||||
"LEFT JOIN character_reputation cr ON cr.guid = c.guid "
|
||||
"WHERE c.account <> 0 "
|
||||
"ORDER BY c.account, c.guid");
|
||||
}
|
||||
|
||||
if (!result)
|
||||
return characters;
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
uint32 const guid = fields[0].Get<uint32>();
|
||||
auto [itr, inserted] = characterIndexes.try_emplace(guid, characters.size());
|
||||
|
||||
if (inserted)
|
||||
{
|
||||
characters.push_back({
|
||||
guid,
|
||||
fields[1].Get<uint32>(),
|
||||
fields[2].Get<uint8>(),
|
||||
fields[3].Get<uint8>(),
|
||||
{}
|
||||
});
|
||||
}
|
||||
|
||||
if (!fields[4].IsNull())
|
||||
{
|
||||
characters[itr->second].Reputations[fields[4].Get<uint32>()] = {
|
||||
fields[5].Get<int32>(),
|
||||
fields[6].Get<uint16>()
|
||||
};
|
||||
}
|
||||
} while (result->NextRow());
|
||||
|
||||
return characters;
|
||||
}
|
||||
|
||||
void PersistReputation(
|
||||
CharacterDatabaseTransaction& trans,
|
||||
CharacterInfo const& target,
|
||||
uint32 factionId,
|
||||
int32 absoluteStanding,
|
||||
uint16 flags)
|
||||
{
|
||||
int32 const storedStanding = GetStoredStanding(target, factionId, absoluteStanding);
|
||||
AppendOrCommit(trans, Acore::StringFormat(
|
||||
"INSERT INTO character_reputation (guid, faction, standing, flags) "
|
||||
"VALUES ({}, {}, {}, {}) "
|
||||
"ON DUPLICATE KEY UPDATE standing = VALUES(standing), flags = flags | VALUES(flags)",
|
||||
target.Guid, factionId, storedStanding, flags));
|
||||
}
|
||||
|
||||
bool ApplyReputation(
|
||||
CharacterDatabaseTransaction& trans,
|
||||
CharacterInfo& target,
|
||||
uint32 factionId,
|
||||
int32 absoluteStanding,
|
||||
uint16 flags)
|
||||
{
|
||||
FactionEntry const* faction = sFactionStore.LookupEntry(factionId);
|
||||
if (!faction || !faction->CanHaveReputation())
|
||||
return false;
|
||||
|
||||
int32 currentStanding = sObjectMgr->GetBaseReputationOf(faction, target.Race, target.Class);
|
||||
auto currentItr = target.Reputations.find(factionId);
|
||||
if (currentItr != target.Reputations.end())
|
||||
currentStanding = GetAbsoluteStanding(target, factionId, currentItr->second);
|
||||
|
||||
absoluteStanding = std::clamp(absoluteStanding, ReputationMgr::Reputation_Bottom, ReputationMgr::Reputation_Cap);
|
||||
if (absoluteStanding <= currentStanding)
|
||||
return false;
|
||||
|
||||
uint16 const mergedFlags = currentItr == target.Reputations.end() ? flags : uint16(currentItr->second.Flags | flags);
|
||||
PersistReputation(trans, target, factionId, absoluteStanding, mergedFlags);
|
||||
target.Reputations[factionId] = { GetStoredStanding(target, factionId, absoluteStanding), mergedFlags };
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32 MergeReputations(CharacterInfo const& source, CharacterInfo& target, CharacterDatabaseTransaction& trans)
|
||||
{
|
||||
if (source.Guid == target.Guid || !CanShareBetweenRaces(source.Race, target.Race))
|
||||
return 0;
|
||||
|
||||
uint32 updated = 0;
|
||||
for (auto const& [sourceFactionId, sourceReputation] : source.Reputations)
|
||||
{
|
||||
uint32 const targetFactionId = GetFactionForTarget(sourceFactionId, source.Race, target.Race);
|
||||
if (!targetFactionId)
|
||||
continue;
|
||||
|
||||
int32 const absoluteStanding = GetAbsoluteStanding(source, sourceFactionId, sourceReputation);
|
||||
if (ApplyReputation(trans, target, targetFactionId, absoluteStanding, sourceReputation.Flags))
|
||||
++updated;
|
||||
}
|
||||
|
||||
return updated;
|
||||
}
|
||||
|
||||
void BackfillReputationsForCharacter(Player* player)
|
||||
{
|
||||
if (!Config.Enabled || !player)
|
||||
return;
|
||||
|
||||
std::vector<CharacterInfo> characters = LoadCharacters(player->GetSession()->GetAccountId());
|
||||
auto targetItr = std::find_if(characters.begin(), characters.end(), [player](CharacterInfo const& character)
|
||||
{
|
||||
return character.Guid == player->GetGUID().GetCounter();
|
||||
});
|
||||
|
||||
if (targetItr == characters.end())
|
||||
return;
|
||||
|
||||
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
uint32 updated = 0;
|
||||
for (CharacterInfo const& source : characters)
|
||||
updated += MergeReputations(source, *targetItr, trans);
|
||||
|
||||
CommitIfNeeded(trans);
|
||||
|
||||
if (updated)
|
||||
LOG_INFO("module.accountboundreputations",
|
||||
"AccountBoundReputations: seeded {} improved reputation(s) for character {}.",
|
||||
updated, targetItr->Guid);
|
||||
}
|
||||
|
||||
void SyncReputationToAccount(Player* player, uint32 factionId, int32 absoluteStanding)
|
||||
{
|
||||
if (!Config.Enabled || !Config.SyncOnChange || !player)
|
||||
return;
|
||||
|
||||
FactionEntry const* sourceFaction = sFactionStore.LookupEntry(factionId);
|
||||
if (!sourceFaction || !sourceFaction->CanHaveReputation())
|
||||
return;
|
||||
|
||||
std::vector<CharacterInfo> characters = LoadCharacters(player->GetSession()->GetAccountId());
|
||||
auto sourceItr = std::find_if(characters.begin(), characters.end(), [player](CharacterInfo const& character)
|
||||
{
|
||||
return character.Guid == player->GetGUID().GetCounter();
|
||||
});
|
||||
|
||||
if (sourceItr == characters.end())
|
||||
return;
|
||||
|
||||
uint16 flags = 0;
|
||||
if (FactionState const* state = player->GetReputationMgr().GetState(sourceFaction))
|
||||
flags = state->Flags;
|
||||
|
||||
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
uint32 updated = 0;
|
||||
|
||||
for (CharacterInfo& target : characters)
|
||||
{
|
||||
if (target.Guid == sourceItr->Guid || !CanShareBetweenRaces(sourceItr->Race, target.Race))
|
||||
continue;
|
||||
|
||||
uint32 const targetFactionId = GetFactionForTarget(factionId, sourceItr->Race, target.Race);
|
||||
if (targetFactionId && ApplyReputation(trans, target, targetFactionId, absoluteStanding, flags))
|
||||
++updated;
|
||||
}
|
||||
|
||||
CommitIfNeeded(trans);
|
||||
|
||||
if (updated)
|
||||
LOG_DEBUG("module.accountboundreputations",
|
||||
"AccountBoundReputations: propagated faction {} from character {} to {} account character(s).",
|
||||
factionId, sourceItr->Guid, updated);
|
||||
}
|
||||
|
||||
void BackfillAllReputations()
|
||||
{
|
||||
if (!Config.Enabled || !Config.StartupBackfill)
|
||||
return;
|
||||
|
||||
std::vector<CharacterInfo> characters = LoadCharacters();
|
||||
std::unordered_map<uint32, std::vector<std::size_t>> charactersByAccount;
|
||||
|
||||
for (std::size_t index = 0; index < characters.size(); ++index)
|
||||
charactersByAccount[characters[index].AccountId].push_back(index);
|
||||
|
||||
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
uint64 updated = 0;
|
||||
|
||||
for (auto const& [accountId, indexes] : charactersByAccount)
|
||||
{
|
||||
(void)accountId;
|
||||
std::vector<CharacterInfo> const snapshot = [&]()
|
||||
{
|
||||
std::vector<CharacterInfo> result;
|
||||
result.reserve(indexes.size());
|
||||
for (std::size_t index : indexes)
|
||||
result.push_back(characters[index]);
|
||||
return result;
|
||||
}();
|
||||
|
||||
for (std::size_t targetIndex : indexes)
|
||||
for (CharacterInfo const& source : snapshot)
|
||||
updated += MergeReputations(source, characters[targetIndex], trans);
|
||||
}
|
||||
|
||||
CommitIfNeeded(trans);
|
||||
LOG_INFO("module.accountboundreputations",
|
||||
"AccountBoundReputations: startup backfill queued {} improved reputation row(s).", updated);
|
||||
}
|
||||
|
||||
void LoadModuleConfig()
|
||||
{
|
||||
Config.Enabled = AccountBound::IsCategoryEnabled("Reputations");
|
||||
Config.StartupBackfill = sConfigMgr->GetOption<bool>("AccountBound.Reputations.StartupBackfill", true);
|
||||
Config.SyncOnCreate = sConfigMgr->GetOption<bool>("AccountBound.Reputations.SyncOnCreate", true);
|
||||
Config.SyncOnChange = sConfigMgr->GetOption<bool>("AccountBound.Reputations.SyncOnChange", true);
|
||||
Config.SameFactionOnly = sConfigMgr->GetOption<bool>("AccountBound.Reputations.SameFactionOnly", true);
|
||||
Config.ConvertFactionSpecific = sConfigMgr->GetOption<bool>("AccountBound.Reputations.ConvertFactionSpecific", true);
|
||||
Config.SyncUnpairedCrossFaction = sConfigMgr->GetOption<bool>("AccountBound.Reputations.SyncUnpairedCrossFaction", false);
|
||||
Config.Filter = AccountBound::LoadIdFilter("Reputations");
|
||||
}
|
||||
}
|
||||
|
||||
class AccountBoundReputationsWorldScript : public WorldScript
|
||||
{
|
||||
public:
|
||||
AccountBoundReputationsWorldScript() : WorldScript("AccountBoundReputationsWorldScript", {
|
||||
WORLDHOOK_ON_AFTER_CONFIG_LOAD,
|
||||
WORLDHOOK_ON_STARTUP
|
||||
}) { }
|
||||
|
||||
void OnAfterConfigLoad(bool reload) override
|
||||
{
|
||||
LoadModuleConfig();
|
||||
LOG_INFO("module.accountboundreputations",
|
||||
"AccountBoundReputations: {}. CreateSync={}, ChangeSync={}, StartupBackfill={}, SameFactionOnly={}.",
|
||||
Config.Enabled ? (reload ? "configuration reloaded" : "configuration loaded") : "disabled",
|
||||
Config.Enabled && Config.SyncOnCreate ? "on" : "off",
|
||||
Config.Enabled && Config.SyncOnChange ? "on" : "off",
|
||||
Config.Enabled && Config.StartupBackfill ? "on" : "off",
|
||||
Config.Enabled && Config.SameFactionOnly ? "on" : "off");
|
||||
}
|
||||
|
||||
void OnStartup() override
|
||||
{
|
||||
BackfillAllReputations();
|
||||
}
|
||||
};
|
||||
|
||||
class AccountBoundReputationsPlayerScript : public PlayerScript
|
||||
{
|
||||
public:
|
||||
AccountBoundReputationsPlayerScript() : PlayerScript("AccountBoundReputationsPlayerScript", {
|
||||
PLAYERHOOK_ON_CREATE,
|
||||
PLAYERHOOK_ON_REPUTATION_CHANGE
|
||||
}) { }
|
||||
|
||||
void OnPlayerCreate(Player* player) override
|
||||
{
|
||||
if (Config.SyncOnCreate)
|
||||
BackfillReputationsForCharacter(player);
|
||||
}
|
||||
|
||||
bool OnPlayerReputationChange(Player* player, uint32 factionId, int32& standing, bool /*incremental*/) override
|
||||
{
|
||||
SyncReputationToAccount(player, factionId, standing);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void AddAccountBoundReputationsScripts()
|
||||
{
|
||||
new AccountBoundReputationsWorldScript();
|
||||
new AccountBoundReputationsPlayerScript();
|
||||
}
|
||||
@@ -0,0 +1,466 @@
|
||||
/*
|
||||
* Account-bound character titles for AzerothCore.
|
||||
*/
|
||||
|
||||
#include "AchievementMgr.h"
|
||||
#include "AccountBound.h"
|
||||
#include "Config.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "DBCStores.h"
|
||||
#include "Log.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "Player.h"
|
||||
#include "PlayerScript.h"
|
||||
#include "StringFormat.h"
|
||||
#include "WorldScript.h"
|
||||
|
||||
#include <array>
|
||||
#include <sstream>
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
using KnownTitlesMask = std::array<uint32, KNOWN_TITLES_SIZE * 2>;
|
||||
|
||||
struct ModuleConfig
|
||||
{
|
||||
bool Enabled = true;
|
||||
bool StartupBackfill = true;
|
||||
bool SyncOnCreate = true;
|
||||
bool SyncOnSave = true;
|
||||
bool SyncRealmFirst = false;
|
||||
bool ConvertFactionSpecific = true;
|
||||
AccountBound::IdFilter Filter;
|
||||
};
|
||||
|
||||
ModuleConfig Config;
|
||||
std::unordered_map<uint32, uint32> TitleIdByBitIndex;
|
||||
std::unordered_set<uint32> RealmFirstTitleIds;
|
||||
std::unordered_map<uint32, KnownTitlesMask> LastKnownTitlesByCharacter;
|
||||
|
||||
bool IsRealmFirstAchievement(AchievementEntry const* achievement)
|
||||
{
|
||||
return achievement && (achievement->flags & (ACHIEVEMENT_FLAG_REALM_FIRST_REACH | ACHIEVEMENT_FLAG_REALM_FIRST_KILL));
|
||||
}
|
||||
|
||||
bool IsTitleAllowed(uint32 titleId)
|
||||
{
|
||||
return Config.Filter.Allows(titleId) &&
|
||||
(Config.SyncRealmFirst || !RealmFirstTitleIds.contains(titleId));
|
||||
}
|
||||
|
||||
void BuildTitleCache()
|
||||
{
|
||||
TitleIdByBitIndex.clear();
|
||||
RealmFirstTitleIds =
|
||||
{
|
||||
// Restored beta/datamined Realm First titles used by RealmFirstTitles.
|
||||
85, 86, 87, 89, 90, 91, 92, 93, 94, 95,
|
||||
96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
|
||||
106, 107, 108, 109, 110, 111, 112, 113, 114, 115,
|
||||
116, 117, 118, 119, 123, 156
|
||||
};
|
||||
|
||||
for (uint32 titleId = 0; titleId < sCharTitlesStore.GetNumRows(); ++titleId)
|
||||
if (CharTitlesEntry const* title = sCharTitlesStore.LookupEntry(titleId))
|
||||
TitleIdByBitIndex.try_emplace(title->bit_index, titleId);
|
||||
|
||||
for (uint32 achievementId = 0; achievementId < sAchievementStore.GetNumRows(); ++achievementId)
|
||||
{
|
||||
AchievementEntry const* achievement = sAchievementStore.LookupEntry(achievementId);
|
||||
if (!IsRealmFirstAchievement(achievement))
|
||||
continue;
|
||||
|
||||
if (AchievementReward const* reward = sAchievementMgr->GetAchievementReward(achievement))
|
||||
for (uint32 titleId : reward->titleId)
|
||||
if (titleId)
|
||||
RealmFirstTitleIds.insert(titleId);
|
||||
}
|
||||
|
||||
LOG_INFO("module.accountboundtitles",
|
||||
"AccountBoundTitles: cached {} title bit mapping(s) and {} Realm First exclusion(s).",
|
||||
TitleIdByBitIndex.size(), RealmFirstTitleIds.size());
|
||||
}
|
||||
|
||||
KnownTitlesMask ParseKnownTitles(std::string const& text)
|
||||
{
|
||||
KnownTitlesMask titles = {};
|
||||
std::stringstream stream(text);
|
||||
|
||||
for (uint32& value : titles)
|
||||
stream >> value;
|
||||
|
||||
return titles;
|
||||
}
|
||||
|
||||
KnownTitlesMask GetPlayerKnownTitles(Player const* player)
|
||||
{
|
||||
KnownTitlesMask titles = {};
|
||||
if (!player)
|
||||
return titles;
|
||||
|
||||
for (uint32 index = 0; index < titles.size(); ++index)
|
||||
titles[index] = player->GetUInt32Value(PLAYER__FIELD_KNOWN_TITLES + index);
|
||||
|
||||
return titles;
|
||||
}
|
||||
|
||||
std::string KnownTitlesToString(KnownTitlesMask const& titles)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
|
||||
for (uint32 index = 0; index < titles.size(); ++index)
|
||||
{
|
||||
if (index)
|
||||
stream << ' ';
|
||||
|
||||
stream << titles[index];
|
||||
}
|
||||
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
bool HasKnownTitle(KnownTitlesMask const& titles, uint32 bitIndex)
|
||||
{
|
||||
if (bitIndex >= titles.size() * 32)
|
||||
return false;
|
||||
|
||||
return (titles[bitIndex / 32] & (1u << (bitIndex % 32))) != 0;
|
||||
}
|
||||
|
||||
bool AddKnownTitle(KnownTitlesMask& titles, uint32 bitIndex)
|
||||
{
|
||||
if (bitIndex >= titles.size() * 32)
|
||||
return false;
|
||||
|
||||
uint32& mask = titles[bitIndex / 32];
|
||||
uint32 const flag = 1u << (bitIndex % 32);
|
||||
|
||||
if (mask & flag)
|
||||
return false;
|
||||
|
||||
mask |= flag;
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32 GetTitleForRace(uint32 titleId, uint8 sourceRace, uint8 targetRace)
|
||||
{
|
||||
if (!IsTitleAllowed(titleId))
|
||||
return 0;
|
||||
|
||||
TeamId const sourceTeam = Player::TeamIdForRace(sourceRace);
|
||||
TeamId const targetTeam = Player::TeamIdForRace(targetRace);
|
||||
|
||||
if (sourceTeam == targetTeam)
|
||||
return titleId;
|
||||
|
||||
for (auto const& [allianceTitle, hordeTitle] : sObjectMgr->FactionChangeTitles)
|
||||
{
|
||||
if (titleId == allianceTitle)
|
||||
return Config.ConvertFactionSpecific && targetTeam == TEAM_HORDE &&
|
||||
IsTitleAllowed(hordeTitle) ? hordeTitle : 0;
|
||||
|
||||
if (titleId == hordeTitle)
|
||||
return Config.ConvertFactionSpecific && targetTeam == TEAM_ALLIANCE &&
|
||||
IsTitleAllowed(allianceTitle) ? allianceTitle : 0;
|
||||
}
|
||||
|
||||
return titleId;
|
||||
}
|
||||
|
||||
uint32 MergeTitlesForRace(KnownTitlesMask const& sourceTitles, uint8 sourceRace, uint8 targetRace, KnownTitlesMask& targetTitles)
|
||||
{
|
||||
uint32 added = 0;
|
||||
|
||||
for (uint32 sourceBitIndex = 0; sourceBitIndex < sourceTitles.size() * 32; ++sourceBitIndex)
|
||||
{
|
||||
if (!HasKnownTitle(sourceTitles, sourceBitIndex))
|
||||
continue;
|
||||
|
||||
auto titleItr = TitleIdByBitIndex.find(sourceBitIndex);
|
||||
if (titleItr == TitleIdByBitIndex.end())
|
||||
continue;
|
||||
|
||||
uint32 const targetTitleId = GetTitleForRace(titleItr->second, sourceRace, targetRace);
|
||||
CharTitlesEntry const* targetTitle = sCharTitlesStore.LookupEntry(targetTitleId);
|
||||
|
||||
if (targetTitle && AddKnownTitle(targetTitles, targetTitle->bit_index))
|
||||
++added;
|
||||
}
|
||||
|
||||
return added;
|
||||
}
|
||||
|
||||
void AppendOrCommit(CharacterDatabaseTransaction& trans, std::string_view sql)
|
||||
{
|
||||
if (!trans)
|
||||
trans = CharacterDatabase.BeginTransaction();
|
||||
|
||||
trans->Append(sql);
|
||||
|
||||
if (trans->GetSize() >= 1000)
|
||||
{
|
||||
CharacterDatabase.DirectCommitTransaction(trans);
|
||||
trans = CharacterDatabase.BeginTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
void CommitIfNeeded(CharacterDatabaseTransaction& trans)
|
||||
{
|
||||
if (trans && trans->GetSize())
|
||||
CharacterDatabase.DirectCommitTransaction(trans);
|
||||
}
|
||||
|
||||
void UpdateTitlesForCharacter(CharacterDatabaseTransaction& trans, uint32 targetGuid, KnownTitlesMask const& titles)
|
||||
{
|
||||
AppendOrCommit(trans, Acore::StringFormat(
|
||||
"UPDATE characters SET knownTitles = '{}' WHERE guid = {}",
|
||||
KnownTitlesToString(titles), targetGuid));
|
||||
}
|
||||
|
||||
void BackfillTitlesForCharacter(Player* player)
|
||||
{
|
||||
if (!Config.Enabled || !player)
|
||||
return;
|
||||
|
||||
uint32 const accountId = player->GetSession()->GetAccountId();
|
||||
uint32 const targetGuid = player->GetGUID().GetCounter();
|
||||
uint8 const targetRace = player->getRace(true);
|
||||
KnownTitlesMask targetTitles = {};
|
||||
uint32 added = 0;
|
||||
QueryResult targetResult = CharacterDatabase.Query(
|
||||
"SELECT COALESCE(knownTitles, '') FROM characters WHERE guid = {}", targetGuid);
|
||||
|
||||
if (targetResult)
|
||||
targetTitles = ParseKnownTitles(targetResult->Fetch()[0].Get<std::string>());
|
||||
|
||||
QueryResult result = CharacterDatabase.Query(
|
||||
"SELECT guid, race, COALESCE(knownTitles, '') "
|
||||
"FROM characters WHERE account = {} AND guid <> {}",
|
||||
accountId, targetGuid);
|
||||
|
||||
if (result)
|
||||
{
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
uint8 const sourceRace = fields[1].Get<uint8>();
|
||||
KnownTitlesMask const sourceTitles = ParseKnownTitles(fields[2].Get<std::string>());
|
||||
added += MergeTitlesForRace(sourceTitles, sourceRace, targetRace, targetTitles);
|
||||
} while (result->NextRow());
|
||||
}
|
||||
|
||||
if (added)
|
||||
{
|
||||
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
UpdateTitlesForCharacter(trans, targetGuid, targetTitles);
|
||||
CommitIfNeeded(trans);
|
||||
|
||||
LOG_INFO("module.accountboundtitles",
|
||||
"AccountBoundTitles: seeded {} account title(s) for character {}.",
|
||||
added, targetGuid);
|
||||
}
|
||||
}
|
||||
|
||||
void SyncTitlesFromPlayerToAccount(Player* player)
|
||||
{
|
||||
if (!Config.Enabled || !Config.SyncOnSave || !player)
|
||||
return;
|
||||
|
||||
uint32 const sourceGuid = player->GetGUID().GetCounter();
|
||||
uint8 const sourceRace = player->getRace(true);
|
||||
KnownTitlesMask const sourceTitles = GetPlayerKnownTitles(player);
|
||||
auto snapshotItr = LastKnownTitlesByCharacter.find(sourceGuid);
|
||||
|
||||
if (snapshotItr != LastKnownTitlesByCharacter.end() && snapshotItr->second == sourceTitles)
|
||||
return;
|
||||
|
||||
QueryResult result = CharacterDatabase.Query(
|
||||
"SELECT guid, race, COALESCE(knownTitles, '') "
|
||||
"FROM characters WHERE account = {} AND guid <> {}",
|
||||
player->GetSession()->GetAccountId(), sourceGuid);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
LastKnownTitlesByCharacter[sourceGuid] = sourceTitles;
|
||||
return;
|
||||
}
|
||||
|
||||
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
uint32 updatedCharacters = 0;
|
||||
uint32 addedTitles = 0;
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
uint32 const targetGuid = fields[0].Get<uint32>();
|
||||
uint8 const targetRace = fields[1].Get<uint8>();
|
||||
KnownTitlesMask targetTitles = ParseKnownTitles(fields[2].Get<std::string>());
|
||||
uint32 const added = MergeTitlesForRace(sourceTitles, sourceRace, targetRace, targetTitles);
|
||||
|
||||
if (!added)
|
||||
continue;
|
||||
|
||||
UpdateTitlesForCharacter(trans, targetGuid, targetTitles);
|
||||
|
||||
++updatedCharacters;
|
||||
addedTitles += added;
|
||||
} while (result->NextRow());
|
||||
|
||||
CommitIfNeeded(trans);
|
||||
LastKnownTitlesByCharacter[sourceGuid] = sourceTitles;
|
||||
|
||||
if (updatedCharacters)
|
||||
LOG_INFO("module.accountboundtitles",
|
||||
"AccountBoundTitles: propagated {} title(s) from character {} to {} account character(s).",
|
||||
addedTitles, sourceGuid, updatedCharacters);
|
||||
}
|
||||
|
||||
void BackfillAllTitles()
|
||||
{
|
||||
if (!Config.Enabled || !Config.StartupBackfill)
|
||||
return;
|
||||
|
||||
struct TitleCharacterInfo
|
||||
{
|
||||
uint32 Guid;
|
||||
uint8 Race;
|
||||
KnownTitlesMask Titles;
|
||||
};
|
||||
|
||||
QueryResult result = CharacterDatabase.Query(
|
||||
"SELECT guid, account, race, COALESCE(knownTitles, '') "
|
||||
"FROM characters WHERE account <> 0");
|
||||
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
std::unordered_map<uint32, std::vector<TitleCharacterInfo>> charactersByAccount;
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
charactersByAccount[fields[1].Get<uint32>()].push_back({
|
||||
fields[0].Get<uint32>(),
|
||||
fields[2].Get<uint8>(),
|
||||
ParseKnownTitles(fields[3].Get<std::string>())
|
||||
});
|
||||
} while (result->NextRow());
|
||||
|
||||
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
uint32 updatedCharacters = 0;
|
||||
uint32 addedTitles = 0;
|
||||
|
||||
for (auto const& [accountId, characters] : charactersByAccount)
|
||||
{
|
||||
(void)accountId;
|
||||
|
||||
for (TitleCharacterInfo const& target : characters)
|
||||
{
|
||||
KnownTitlesMask mergedTitles = target.Titles;
|
||||
uint32 added = 0;
|
||||
|
||||
for (TitleCharacterInfo const& source : characters)
|
||||
{
|
||||
if (source.Guid != target.Guid)
|
||||
added += MergeTitlesForRace(source.Titles, source.Race, target.Race, mergedTitles);
|
||||
}
|
||||
|
||||
if (!added)
|
||||
continue;
|
||||
|
||||
UpdateTitlesForCharacter(trans, target.Guid, mergedTitles);
|
||||
++updatedCharacters;
|
||||
addedTitles += added;
|
||||
}
|
||||
}
|
||||
|
||||
CommitIfNeeded(trans);
|
||||
LOG_INFO("module.accountboundtitles",
|
||||
"AccountBoundTitles: startup backfill added {} title(s) to {} character(s).",
|
||||
addedTitles, updatedCharacters);
|
||||
}
|
||||
|
||||
void LoadModuleConfig()
|
||||
{
|
||||
Config.Enabled = AccountBound::IsCategoryEnabled("Titles");
|
||||
Config.StartupBackfill = sConfigMgr->GetOption<bool>("AccountBound.Titles.StartupBackfill", true);
|
||||
Config.SyncOnCreate = sConfigMgr->GetOption<bool>("AccountBound.Titles.SyncOnCreate", true);
|
||||
Config.SyncOnSave = sConfigMgr->GetOption<bool>("AccountBound.Titles.SyncOnSave", true);
|
||||
Config.SyncRealmFirst = sConfigMgr->GetOption<bool>("AccountBound.Titles.SyncRealmFirst", false);
|
||||
Config.ConvertFactionSpecific = sConfigMgr->GetOption<bool>("AccountBound.Titles.ConvertFactionSpecific", true);
|
||||
Config.Filter = AccountBound::LoadIdFilter("Titles");
|
||||
}
|
||||
}
|
||||
|
||||
class AccountBoundTitlesWorldScript : public WorldScript
|
||||
{
|
||||
public:
|
||||
AccountBoundTitlesWorldScript() : WorldScript("AccountBoundTitlesWorldScript", {
|
||||
WORLDHOOK_ON_AFTER_CONFIG_LOAD,
|
||||
WORLDHOOK_ON_STARTUP
|
||||
}) { }
|
||||
|
||||
void OnAfterConfigLoad(bool reload) override
|
||||
{
|
||||
LoadModuleConfig();
|
||||
LOG_INFO("module.accountboundtitles",
|
||||
"AccountBoundTitles: {}. CreateSync={}, SaveSync={}, StartupBackfill={}, RealmFirst={}.",
|
||||
Config.Enabled ? (reload ? "configuration reloaded" : "configuration loaded") : "disabled",
|
||||
Config.Enabled && Config.SyncOnCreate ? "on" : "off",
|
||||
Config.Enabled && Config.SyncOnSave ? "on" : "off",
|
||||
Config.Enabled && Config.StartupBackfill ? "on" : "off",
|
||||
Config.Enabled && Config.SyncRealmFirst ? "on" : "off");
|
||||
}
|
||||
|
||||
void OnStartup() override
|
||||
{
|
||||
if (!Config.Enabled)
|
||||
return;
|
||||
|
||||
BuildTitleCache();
|
||||
BackfillAllTitles();
|
||||
}
|
||||
};
|
||||
|
||||
class AccountBoundTitlesPlayerScript : public PlayerScript
|
||||
{
|
||||
public:
|
||||
AccountBoundTitlesPlayerScript() : PlayerScript("AccountBoundTitlesPlayerScript", {
|
||||
PLAYERHOOK_ON_LOAD_FROM_DB,
|
||||
PLAYERHOOK_ON_LOGOUT,
|
||||
PLAYERHOOK_ON_CREATE,
|
||||
PLAYERHOOK_ON_SAVE
|
||||
}) { }
|
||||
|
||||
void OnPlayerLoadFromDB(Player* player) override
|
||||
{
|
||||
if (player)
|
||||
LastKnownTitlesByCharacter[player->GetGUID().GetCounter()] = GetPlayerKnownTitles(player);
|
||||
}
|
||||
|
||||
void OnPlayerCreate(Player* player) override
|
||||
{
|
||||
if (Config.SyncOnCreate)
|
||||
BackfillTitlesForCharacter(player);
|
||||
}
|
||||
|
||||
void OnPlayerSave(Player* player) override
|
||||
{
|
||||
SyncTitlesFromPlayerToAccount(player);
|
||||
}
|
||||
|
||||
void OnPlayerLogout(Player* player) override
|
||||
{
|
||||
if (player)
|
||||
LastKnownTitlesByCharacter.erase(player->GetGUID().GetCounter());
|
||||
}
|
||||
};
|
||||
|
||||
void AddAccountBoundTitlesScripts()
|
||||
{
|
||||
new AccountBoundTitlesWorldScript();
|
||||
new AccountBoundTitlesPlayerScript();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
void AddAccountBoundAchievementsScripts();
|
||||
void AddAccountBoundMountsScripts();
|
||||
void AddAccountBoundPetsScripts();
|
||||
void AddAccountBoundProfessionsScripts();
|
||||
void AddAccountBoundReputationsScripts();
|
||||
void AddAccountBoundTitlesScripts();
|
||||
void AddAccountWideFriendsScripts();
|
||||
|
||||
void AddAccountBoundScripts()
|
||||
{
|
||||
AddAccountBoundAchievementsScripts();
|
||||
AddAccountBoundMountsScripts();
|
||||
AddAccountBoundPetsScripts();
|
||||
AddAccountBoundProfessionsScripts();
|
||||
AddAccountBoundReputationsScripts();
|
||||
AddAccountBoundTitlesScripts();
|
||||
AddAccountWideFriendsScripts();
|
||||
}
|
||||
@@ -472,6 +472,84 @@ DynamicQuestXP.Level_70_plus = ${ACORE_DYNAMIC_QUEST_XP_LEVEL_70_PLUS}
|
||||
EOF
|
||||
}
|
||||
|
||||
write_account_bound_conf() {
|
||||
write_file "$MODULES_ETC_DIR/AccountBound.conf.dist" <<EOF
|
||||
# Managed by ./setup-modules.sh
|
||||
AccountBound.Achievements.Enable = 0
|
||||
AccountBound.Achievements.StartupBackfill = 1
|
||||
AccountBound.Achievements.SameFactionOnly = 1
|
||||
AccountBound.Achievements.SyncOnCreate = 1
|
||||
AccountBound.Achievements.SyncRealmFirst = 0
|
||||
AccountBound.Achievements.SyncHidden = 0
|
||||
AccountBound.Achievements.ConvertFactionSpecific = 1
|
||||
AccountBound.Achievements.SyncUnpairedFactionSpecific = 0
|
||||
AccountBound.Achievements.AllowList = all
|
||||
AccountBound.Achievements.BlockList = ""
|
||||
AccountBound.Mounts.Enable = 1
|
||||
AccountBound.Mounts.StartupBackfill = 1
|
||||
AccountBound.Mounts.SyncOnCreate = 1
|
||||
AccountBound.Mounts.RespectFactionRestrictions = 1
|
||||
AccountBound.Mounts.ConvertFactionSpecific = 1
|
||||
AccountBound.Mounts.RequireRiding = 1
|
||||
AccountBound.Mounts.SyncClassMounts = 1
|
||||
AccountBound.Mounts.RequireClass = 1
|
||||
AccountBound.Mounts.ClassMountsSameFactionOnly = 1
|
||||
AccountBound.Mounts.CleanupInvalid = 1
|
||||
AccountBound.Mounts.BackfillOnRidingSkillChange = 1
|
||||
AccountBound.Mounts.AllowList = all
|
||||
AccountBound.Mounts.BlockList = ""
|
||||
AccountBound.Pets.Enable = 1
|
||||
AccountBound.Pets.StartupBackfill = 1
|
||||
AccountBound.Pets.SyncOnCreate = 1
|
||||
AccountBound.Pets.SameFactionOnly = 0
|
||||
AccountBound.Pets.IncludeCompanionSkillLine = 1
|
||||
AccountBound.Pets.IncludeMinipetSummons = 1
|
||||
AccountBound.Pets.AllowList = all
|
||||
AccountBound.Pets.BlockList = ""
|
||||
AccountBound.Titles.Enable = 0
|
||||
AccountBound.Titles.StartupBackfill = 1
|
||||
AccountBound.Titles.SyncOnCreate = 1
|
||||
AccountBound.Titles.SyncOnSave = 1
|
||||
AccountBound.Titles.SyncRealmFirst = 0
|
||||
AccountBound.Titles.ConvertFactionSpecific = 1
|
||||
AccountBound.Titles.AllowList = all
|
||||
AccountBound.Titles.BlockList = ""
|
||||
AccountBound.Reputations.Enable = 0
|
||||
AccountBound.Reputations.StartupBackfill = 1
|
||||
AccountBound.Reputations.SyncOnCreate = 1
|
||||
AccountBound.Reputations.SyncOnChange = 1
|
||||
AccountBound.Reputations.SameFactionOnly = 1
|
||||
AccountBound.Reputations.ConvertFactionSpecific = 1
|
||||
AccountBound.Reputations.SyncUnpairedCrossFaction = 0
|
||||
AccountBound.Reputations.AllowList = all
|
||||
AccountBound.Reputations.BlockList = ""
|
||||
AccountBound.Professions.Enable = 0
|
||||
AccountBound.Professions.MaxPrimaryProfessions = 11
|
||||
AccountBound.Professions.Primary.AllowList = all
|
||||
AccountBound.Professions.Primary.BlockList = ""
|
||||
AccountBound.Professions.Primary.CountOnlyAllowed = 1
|
||||
AccountBound.Professions.Primary.EnforceAllowedList = 0
|
||||
AccountBound.Professions.MaxSkillValue = 450
|
||||
AccountBound.Professions.StartupBackfill = 1
|
||||
AccountBound.Professions.SyncOnCreate = 1
|
||||
AccountBound.Professions.SyncOnLearn = 1
|
||||
AccountBound.Professions.IncludeSecondaryProfessions = 1
|
||||
AccountBound.Professions.SyncSkillProgress = 1
|
||||
AccountBound.Professions.SyncProfessionRanks = 1
|
||||
AccountBound.Professions.SyncRecipes = 1
|
||||
AccountBound.Professions.SyncSkillGrantedSpells = 1
|
||||
AccountBound.Professions.RequireRecipeSkill = 1
|
||||
AccountBound.Professions.SpellAllowList = ""
|
||||
AccountBound.Professions.SpellBlockList = ""
|
||||
AccountBound.Friends.Enable = 1
|
||||
AccountBound.Friends.SyncOnCreate = 1
|
||||
AccountBound.Friends.SyncOnlineChanges = 1
|
||||
AccountBound.Friends.SameFactionOnly = 0
|
||||
AccountBound.Friends.SyncIntervalSeconds = 3
|
||||
AccountBound.Friends.StartupBackfill = 1
|
||||
EOF
|
||||
}
|
||||
|
||||
write_aoe_loot_conf() {
|
||||
write_file "$MODULES_ETC_DIR/mod_aoe_loot.conf.dist" <<EOF
|
||||
# Managed by ./setup-modules.sh
|
||||
@@ -729,6 +807,7 @@ main() {
|
||||
write_gamemodes_conf
|
||||
write_playerbots_conf
|
||||
write_playerbots_ai_conf
|
||||
write_account_bound_conf
|
||||
if (( SKIP_SQL )); then
|
||||
log "local module SQL imports skipped"
|
||||
else
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
-- --------------------------------------------------------
|
||||
-- Host: 192.168.0.167
|
||||
-- Server-Version: 8.3.0 - MySQL Community Server - GPL
|
||||
-- Server-Betriebssystem: Linux
|
||||
-- HeidiSQL Version: 12.8.0.6908
|
||||
-- --------------------------------------------------------
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET NAMES utf8 */;
|
||||
/*!50503 SET NAMES utf8mb4 */;
|
||||
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
|
||||
/*!40103 SET TIME_ZONE='+00:00' */;
|
||||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
|
||||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
||||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
||||
|
||||
-- Exportiere Struktur von Tabelle acore_auth.account_transmog
|
||||
CREATE TABLE IF NOT EXISTS `account_transmog` (
|
||||
`account_id` int unsigned NOT NULL,
|
||||
`unlocked_item_id` int unsigned NOT NULL,
|
||||
`inventory_type` int unsigned DEFAULT NULL,
|
||||
`inventory_subtype` int unsigned DEFAULT NULL,
|
||||
`display_id` int unsigned NOT NULL,
|
||||
`item_name` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL,
|
||||
UNIQUE KEY `account_item_id` (`account_id`,`unlocked_item_id`) USING BTREE,
|
||||
UNIQUE KEY `account_display_id` (`account_id`,`display_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
|
||||
-- Daten-Export vom Benutzer nicht ausgewählt
|
||||
|
||||
/*!40103 SET TIME_ZONE=IFNULL(@OLD_TIME_ZONE, 'system') */;
|
||||
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
|
||||
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
/*!40111 SET SQL_NOTES=IFNULL(@OLD_SQL_NOTES, 1) */;
|
||||
@@ -0,0 +1,33 @@
|
||||
-- --------------------------------------------------------
|
||||
-- Host: 192.168.0.167
|
||||
-- Server-Version: 8.3.0 - MySQL Community Server - GPL
|
||||
-- Server-Betriebssystem: Linux
|
||||
-- HeidiSQL Version: 12.8.0.6908
|
||||
-- --------------------------------------------------------
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET NAMES utf8 */;
|
||||
/*!50503 SET NAMES utf8mb4 */;
|
||||
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
|
||||
/*!40103 SET TIME_ZONE='+00:00' */;
|
||||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
|
||||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
||||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
||||
|
||||
-- Exportiere Struktur von Tabelle acore_characters.character_transmog
|
||||
CREATE TABLE IF NOT EXISTS `character_transmog` (
|
||||
`player_guid` int unsigned DEFAULT NULL,
|
||||
`slot` varchar(3) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
|
||||
`item` int unsigned DEFAULT NULL,
|
||||
`real_item` int unsigned DEFAULT NULL,
|
||||
UNIQUE KEY `player_and_slot` (`player_guid`,`slot`) USING BTREE,
|
||||
KEY `player_and_slot_key` (`player_guid`,`slot`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
|
||||
-- Daten-Export vom Benutzer nicht ausgewählt
|
||||
|
||||
/*!40103 SET TIME_ZONE=IFNULL(@OLD_TIME_ZONE, 'system') */;
|
||||
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
|
||||
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
/*!40111 SET SQL_NOTES=IFNULL(@OLD_SQL_NOTES, 1) */;
|
||||
Reference in New Issue
Block a user