refactor(Core/ServerMail): Refactor to Dedicated Manager Class with Multi-Item & Condition Support (#21590)

1. Core Cleanup
    - Move all ServerMail logic from `ObjectMgr` into a new dedicated `ServerMailMgr` class
    - Move faction logic for money from SendServerMail into the script
2. Separation of items into a new table
    - Create a new `mail_server_template_items` table
    - Allows to send multiple items in one mail
    - Separate items per faction Alliance/Horde
3. Separation of conditions into a new table
    - Create a new `mail_server_template_conditions` table
    - Allows to use multiple conditions for one mail
    - Available condition types
        - Minimum playtime (playerLevel >= condition)
        - Minimum playtime (playerPlayTime >= condition)
        - Rewarded quest
        - Earned achievement
        - Earned reputation (playerReputation >= conditionState)
        - Faction
        - Race
        - Class
4. Updated ServerMail loading
    - Move item and condition loading to their own functions
        - LoadMailServerTemplateItems()
        - LoadMailServerTemplateConditions()
5. Reworked eligibility check
    - Player needs to pass all conditions to be eligible for the mail
    - All players are automatically eligible if no conditions exist for a server mail template.
6. Updated foreign keys
    - For table `mail_server_character`, `mail_server_template_conditions`, `mail_server_template_items` foreign key with on delete cascade is added for automatic removal of entries if mail_server_template.id is deleted.
7. Database changes
    - See the PR
This commit is contained in:
Kitzunu
2025-03-09 09:18:01 +01:00
committed by GitHub
parent 061044b710
commit 231096132c
9 changed files with 666 additions and 155 deletions

View File

@@ -0,0 +1,65 @@
--
DROP TABLE IF EXISTS `mail_server_template_items`;
CREATE TABLE `mail_server_template_items` (
`id` INT UNSIGNED AUTO_INCREMENT,
`templateID` INT UNSIGNED NOT NULL,
`faction` ENUM('Alliance', 'Horde') NOT NULL,
`item` INT UNSIGNED NOT NULL,
`itemCount` INT UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `fk_mail_template`
FOREIGN KEY (`templateID`) REFERENCES `mail_server_template`(`id`)
ON DELETE CASCADE
) ENGINE=InnoDB COLLATE='utf8mb4_unicode_ci';
DELETE FROM `mail_server_template_items` WHERE `faction` = 'Alliance';
INSERT INTO `mail_server_template_items` (`templateID`, `faction`, `item`, `itemCount`)
SELECT `id`, 'Alliance', `itemA`, `itemCountA` FROM `mail_server_template` WHERE `itemA` > 0;
DELETE FROM `mail_server_template_items` WHERE `faction` = 'Horde';
INSERT INTO `mail_server_template_items` (`templateID`, `faction`, `item`, `itemCount`)
SELECT `id`, 'Horde', `itemH`, `itemCountH` FROM `mail_server_template` WHERE `itemH` > 0;
ALTER TABLE `mail_server_template`
DROP COLUMN `itemA`,
DROP COLUMN `itemCountA`,
DROP COLUMN `itemH`,
DROP COLUMN `itemCountH`;
-- mail_server_template_conditions
DROP TABLE IF EXISTS `mail_server_template_conditions`;
CREATE TABLE `mail_server_template_conditions` (
`id` INT UNSIGNED AUTO_INCREMENT,
`templateID` INT UNSIGNED NOT NULL,
`conditionType` ENUM('Level', 'PlayTime', 'Quest', 'Achievement', 'Reputation', 'Faction', 'Race', 'Class') NOT NULL,
`conditionValue` INT UNSIGNED NOT NULL,
`conditionState` INT UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
CONSTRAINT `fk_mail_template_conditions`
FOREIGN KEY (`templateID`) REFERENCES `mail_server_template`(`id`)
ON DELETE CASCADE
) ENGINE=InnoDB COLLATE='utf8mb4_unicode_ci';
DELETE FROM `mail_server_template_conditions` WHERE `conditionType` = 'Level';
INSERT INTO `mail_server_template_conditions` (`templateID`, `conditionType`, `conditionValue`)
SELECT `id`, 'Level', `reqLevel` FROM `mail_server_template` WHERE `reqLevel` > 0;
DELETE FROM `mail_server_template_conditions` WHERE `conditionType` = 'PlayTime';
INSERT INTO `mail_server_template_conditions` (`templateID`, `conditionType`, `conditionValue`)
SELECT `id`, 'PlayTime', `reqPlayTime` FROM `mail_server_template` WHERE `reqPlayTime` > 0;
ALTER TABLE `mail_server_template`
DROP COLUMN `reqLevel`,
DROP COLUMN `reqPlayTime`;
-- mail_server_character
-- Make sure we dont have invalid instances in mail_server_character.mailId before we add the foregin key to avoid SQL errors
DELETE FROM `mail_server_character` WHERE `mailId` NOT IN (SELECT `id` FROM `mail_server_template`);
-- Add foreign key for mail_server_character.mailId
ALTER TABLE `mail_server_character`
DROP PRIMARY KEY,
ADD PRIMARY KEY (`guid`, `mailId`),
ADD CONSTRAINT `fk_mail_server_character`
FOREIGN KEY (`mailId`) REFERENCES `mail_server_template`(`id`)
ON DELETE CASCADE;