From 1500453f5951093c5d1ed9bc2be0358ba88d3ad8 Mon Sep 17 00:00:00 2001 From: acidmanifesto Date: Fri, 3 Dec 2021 22:33:21 +0100 Subject: [PATCH] feat(Core\Player): Added createplayerinfo_cast_spell support cast spell for some class spells (#9448) --- .../rev_1638401383244389098.sql | 14 ++++ src/server/game/Entities/Player/Player.h | 1 + src/server/game/Globals/ObjectMgr.cpp | 57 ++++++++++++++++ src/server/game/Handlers/CharacterHandler.cpp | 9 +++ .../scripts/World/character_creation.cpp | 67 ------------------- .../scripts/World/world_script_loader.cpp | 2 - 6 files changed, 81 insertions(+), 69 deletions(-) create mode 100644 data/sql/updates/pending_db_world/rev_1638401383244389098.sql delete mode 100644 src/server/scripts/World/character_creation.cpp diff --git a/data/sql/updates/pending_db_world/rev_1638401383244389098.sql b/data/sql/updates/pending_db_world/rev_1638401383244389098.sql new file mode 100644 index 000000000..bb42fb735 --- /dev/null +++ b/data/sql/updates/pending_db_world/rev_1638401383244389098.sql @@ -0,0 +1,14 @@ +INSERT INTO `version_db_world` (`sql_rev`) VALUES ('1638401383244389098'); + +DROP TABLE IF EXISTS `playercreateinfo_cast_spell`; +CREATE TABLE IF NOT EXISTS `playercreateinfo_cast_spell` ( + `raceMask` INT UNSIGNED NOT NULL DEFAULT '0', + `classMask` INT UNSIGNED NOT NULL DEFAULT '0', + `spell` MEDIUMINT UNSIGNED NOT NULL DEFAULT '0', + `note` VARCHAR(255) DEFAULT NULL +) ENGINE=MYISAM DEFAULT CHARSET=utf8mb4; + +DELETE FROM `playercreateinfo_cast_spell` WHERE `spell` IN (48266, 2457); +INSERT INTO `playercreateinfo_cast_spell` (`racemask`, `classmask`, `spell`, `note`) VALUES +(0, 32, 48266, 'Death Knight - Blood Presence'), +(0, 1, 2457, 'Warrior - Battle Stance'); diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index f8de207b4..34c5faa1a 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -339,6 +339,7 @@ struct PlayerInfo uint16 displayId_f{0}; PlayerCreateInfoItems item; PlayerCreateInfoSpells customSpells; + PlayerCreateInfoSpells castSpells; PlayerCreateInfoActions action; PlayerCreateInfoSkills skills; diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index a3581964b..865877fa1 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -3607,6 +3607,63 @@ void ObjectMgr::LoadPlayerInfo() } } + // Load playercreate cast spell + LOG_INFO("server.loading", "Loading Player Create Cast Spell Data..."); + { + uint32 oldMSTime = getMSTime(); + + QueryResult result = WorldDatabase.PQuery("SELECT raceMask, classMask, spell FROM playercreateinfo_cast_spell"); + + if (!result) + { + LOG_ERROR("server.loading", ">> Loaded 0 player create cast spells. DB table `playercreateinfo_cast_spell` is empty."); + } + else + { + uint32 count = 0; + + do + { + Field* fields = result->Fetch(); + uint32 raceMask = fields[0].GetUInt32(); + uint32 classMask = fields[1].GetUInt32(); + uint32 spellId = fields[2].GetUInt32(); + + if (raceMask != 0 && !(raceMask & RACEMASK_ALL_PLAYABLE)) + { + LOG_ERROR("sql.sql", "Wrong race mask %u in `playercreateinfo_cast_spell` table, ignoring.", raceMask); + continue; + } + + if (classMask != 0 && !(classMask & CLASSMASK_ALL_PLAYABLE)) + { + LOG_ERROR("sql.sql", "Wrong class mask %u in `playercreateinfo_cast_spell` table, ignoring.", classMask); + continue; + } + + for (uint32 raceIndex = RACE_HUMAN; raceIndex < MAX_RACES; ++raceIndex) + { + if (raceMask == 0 || ((1 << (raceIndex - 1)) & raceMask)) + { + for (uint32 classIndex = CLASS_WARRIOR; classIndex < MAX_CLASSES; ++classIndex) + { + if (classMask == 0 || ((1 << (classIndex - 1)) & classMask)) + { + if (PlayerInfo* info = _playerInfo[raceIndex][classIndex]) + { + info->castSpells.push_back(spellId); + ++count; + } + } + } + } + } + } while (result->NextRow()); + + LOG_INFO("server.loading", ">> Loaded %u player create cast spells in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + } + } + // Load playercreate actions LOG_INFO("server.loading", "Loading Player Create Action Data..."); { diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp index 4925dc6f0..d092c3aea 100644 --- a/src/server/game/Handlers/CharacterHandler.cpp +++ b/src/server/game/Handlers/CharacterHandler.cpp @@ -982,13 +982,22 @@ void WorldSession::HandlePlayerLoginFromDB(LoginQueryHolder const& holder) bool firstLogin = pCurrChar->HasAtLoginFlag(AT_LOGIN_FIRST); if (firstLogin) { + pCurrChar->RemoveAtLoginFlag(AT_LOGIN_FIRST); + PlayerInfo const* info = sObjectMgr->GetPlayerInfo(pCurrChar->getRace(), pCurrChar->getClass()); + for (uint32 spellId : info->castSpells) + { + pCurrChar->CastSpell(pCurrChar, spellId, true); + } + // start with every map explored if (sWorld->getBoolConfig(CONFIG_START_ALL_EXPLORED)) { for (uint8 i = 0; i < PLAYER_EXPLORED_ZONES_SIZE; i++) + { pCurrChar->SetFlag(PLAYER_EXPLORED_ZONES_1 + i, 0xFFFFFFFF); + } } // Reputations if "StartAllReputation" is enabled, -- TODO: Fix this in a better way diff --git a/src/server/scripts/World/character_creation.cpp b/src/server/scripts/World/character_creation.cpp deleted file mode 100644 index f0dd1b60d..000000000 --- a/src/server/scripts/World/character_creation.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by the - * Free Software Foundation; either version 3 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 Affero General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#include "Player.h" -#include "ScriptMgr.h" - -enum Creationabilities -{ - WARRIOR_CREATION_BATTLE_STANCE = 2457, // Battle Stance - DEATH_KNIGHT_CREATION_BLOOD_PRESENCE = 48266, // Blood Presence -}; - -// Instead of adding a hacky way into Player::Create, we use existing hooks to cast these spells on first character login -class CharacterCreationProcedures : public PlayerScript -{ -public: - CharacterCreationProcedures() : PlayerScript("CharacterCreationProcedures") - { - } - - void OnFirstLogin(Player* player) override - { - switch (player->getClass()) - { - // Only two classes posses an aura on creation; - case CLASS_WARRIOR: - player->CastSpell(player, WARRIOR_CREATION_BATTLE_STANCE, true); - return; - case CLASS_DEATH_KNIGHT: - player->CastSpell(player, DEATH_KNIGHT_CREATION_BLOOD_PRESENCE, true); - return; - // We include, but do not change the other classes - case CLASS_NONE: - case CLASS_PALADIN: - case CLASS_HUNTER: - case CLASS_ROGUE: - case CLASS_PRIEST: - case CLASS_SHAMAN: - case CLASS_MAGE: - case CLASS_WARLOCK: - // case CLASS_UNK: // Does not exist! - case CLASS_DRUID: - default: - // Can be modified based on personal needs; - return; - } - } -}; - -void AddSC_character_creation() -{ - new CharacterCreationProcedures(); -} diff --git a/src/server/scripts/World/world_script_loader.cpp b/src/server/scripts/World/world_script_loader.cpp index e5be6e0aa..e5006a218 100644 --- a/src/server/scripts/World/world_script_loader.cpp +++ b/src/server/scripts/World/world_script_loader.cpp @@ -28,7 +28,6 @@ void AddSC_npcs_special(); void AddSC_npc_taxi(); void AddSC_achievement_scripts(); void AddSC_chat_log(); // location: scripts\World\chat_log.cpp -void AddSC_character_creation(); void AddSC_action_ip_logger(); // location: scripts\World\action_ip_logger.cpp void AddSC_player_scripts(); void AddSC_npc_stave_of_ancients(); @@ -49,7 +48,6 @@ void AddWorldScripts() AddSC_npc_taxi(); AddSC_achievement_scripts(); AddSC_chat_log(); // location: scripts\World\chat_log.cpp - AddSC_character_creation(); AddSC_action_ip_logger(); // location: scripts\World\action_ip_logger.cpp AddSC_player_scripts(); AddSC_npc_stave_of_ancients();