Skip to content

Commit

Permalink
[s2477] Creature: Add CharmedSpellList shorthand during charm
Browse files Browse the repository at this point in the history
Common and confirmed on reference
  • Loading branch information
killerwife committed Apr 6, 2024
1 parent fc48782 commit b788607
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 8 deletions.
3 changes: 2 additions & 1 deletion sql/base/mangos.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ DROP TABLE IF EXISTS `db_version`;
CREATE TABLE `db_version` (
`version` varchar(120) DEFAULT NULL,
`creature_ai_version` varchar(120) DEFAULT NULL,
`required_s2476_01_mangos_spell_template_ap` bit(1) DEFAULT NULL
`required_s2477_01_mangos_charmed_spell_list` bit(1) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='Used DB version notes';

--
Expand Down Expand Up @@ -1394,6 +1394,7 @@ CREATE TABLE `creature_template` (
`InteractionPauseTimer` INT(10) NOT NULL DEFAULT -1,
`CorpseDecay` INT UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Time before corpse despawns',
`SpellList` INT NOT NULL DEFAULT '0' COMMENT 'creature_spell_list_entry',
`CharmedSpellList` INT NOT NULL DEFAULT '0' COMMENT 'creature_spell_list_entry during charm',
`StringId1` INT(11) UNSIGNED NOT NULL DEFAULT '0',
`StringId2` INT(11) UNSIGNED NOT NULL DEFAULT '0',
`AIName` char(64) NOT NULL DEFAULT '',
Expand Down
5 changes: 5 additions & 0 deletions sql/updates/mangos/s2477_01_mangos_charmed_spell_list.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE db_version CHANGE COLUMN required_s2476_01_mangos_spell_template_ap required_s2477_01_mangos_charmed_spell_list bit;

ALTER TABLE `creature_template` ADD COLUMN `CharmedSpellList` INT NOT NULL DEFAULT '0' COMMENT 'creature_spell_list_entry during charm' AFTER `SpellList`;


10 changes: 10 additions & 0 deletions src/game/Entities/Creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2346,6 +2346,16 @@ void Creature::UpdateSpell(int32 index, int32 newSpellId)

void Creature::SetSpellList(uint32 spellSet)
{
if (spellSet == 0)
{
m_spellList.Disabled = true;
m_spellList.Spells.clear();

if (AI())
AI()->SpellListChanged();
return;
}

// Try difficulty dependent version before falling back to base entry
auto spellList = GetMap()->GetMapDataContainer().GetCreatureSpellList(spellSet);
if (!spellList)
Expand Down
1 change: 1 addition & 0 deletions src/game/Entities/Creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ struct CreatureInfo
uint32 InteractionPauseTimer;
uint32 CorpseDelay;
uint32 SpellList;
uint32 CharmedSpellList;
uint32 StringID1;
uint32 StringID2;
char const* AIName;
Expand Down
19 changes: 15 additions & 4 deletions src/game/Entities/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11625,6 +11625,8 @@ Unit* Unit::TakePossessOf(SpellEntry const* spellEntry, SummonPropertiesEntry co
if (player)
{
// Initialize pet bar
if (uint32 charmedSpellList = possessed->GetCreatureInfo()->CharmedSpellList)
possessed->SetSpellList(charmedSpellList);
charmInfo->InitPossessCreateSpells();
player->PossessSpellInitialize();

Expand Down Expand Up @@ -11692,6 +11694,9 @@ bool Unit::TakePossessOf(Unit* possessed)
charmInfo->SetCharmState("PossessedAI");
possessedCreature->SetWalk(IsWalking(), true);
getHostileRefManager().deleteReference(possessedCreature);

if (uint32 charmedSpellList = possessedCreature->GetCreatureInfo()->CharmedSpellList)
possessedCreature->SetSpellList(charmedSpellList);
}
else if (possessed->GetTypeId() == TYPEID_PLAYER)
{
Expand Down Expand Up @@ -11797,7 +11802,7 @@ bool Unit::TakeCharmOf(Unit* charmed, uint32 spellId, bool advertised /*= true*/

Position combatStartPosition;

if (charmed->GetTypeId() == TYPEID_PLAYER)
if (charmed->IsPlayer())
{
Player* charmedPlayer = static_cast<Player*>(charmed);
if (charmerPlayer && charmerPlayer->IsInDuelWith(charmedPlayer))
Expand All @@ -11821,7 +11826,7 @@ bool Unit::TakeCharmOf(Unit* charmed, uint32 spellId, bool advertised /*= true*/

charmedPlayer->SendForcedObjectUpdate();
}
else if (charmed->GetTypeId() == TYPEID_UNIT)
else if (charmed->IsCreature())
{
Creature* charmedCreature = static_cast<Creature*>(charmed);

Expand All @@ -11838,6 +11843,9 @@ bool Unit::TakeCharmOf(Unit* charmed, uint32 spellId, bool advertised /*= true*/

charmedCreature->SetFactionTemporary(GetFaction(), TEMPFACTION_NONE);

if (uint32 charmedSpellList = charmedCreature->GetCreatureInfo()->CharmedSpellList)
charmedCreature->SetSpellList(charmedSpellList);

if (isPossessCharm)
charmInfo->InitPossessCreateSpells();
else
Expand Down Expand Up @@ -12020,7 +12028,7 @@ void Unit::Uncharm(Unit* charmed, uint32 spellId)
// TODO: maybe should be done on HomeMovementGenerator::MovementExpires
charmed->GetCombatManager().SetEvadeState(EVADE_NONE);

if (charmed->GetTypeId() == TYPEID_UNIT)
if (charmed->IsCreature())
{
// now we have to clean threat list to be able to restore normal creature behavior
Creature* charmedCreature = static_cast<Creature*>(charmed);
Expand Down Expand Up @@ -12052,9 +12060,12 @@ void Unit::Uncharm(Unit* charmed, uint32 spellId)
charmed->DeleteCharmInfo();
}

if (charmedCreature->GetCreatureInfo()->CharmedSpellList)
charmedCreature->SetSpellList(charmedCreature->GetCreatureInfo()->SpellList);

charmed->SetTarget(charmed->GetVictim());
}
else if (charmed->GetTypeId() == TYPEID_PLAYER)
else if (charmed->IsPlayer())
{
charmed->AttackStop(true, true);

Expand Down
4 changes: 2 additions & 2 deletions src/game/Server/SQLStorages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

#include "Server/SQLStorages.h"

const char CreatureInfosrcfmt[] = "isssiiiiiiiifiiiiliiiiiiiiiffiiiiiiiiffffffiiiiffffiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiss";
const char CreatureInfodstfmt[] = "isssiiiiiiiifiiiiliiiiiiiiiffiiiiiiiiffffffiiiiffffiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiisi";
const char CreatureInfosrcfmt[] = "isssiiiiiiiifiiiiliiiiiiiiiffiiiiiiiiffffffiiiiffffiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiss";
const char CreatureInfodstfmt[] = "isssiiiiiiiifiiiiliiiiiiiiiffiiiiiiiiffffffiiiiffffiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiisi";
const char CreatureDataAddonInfofmt[] = "iibbiis";
const char CreatureConditionalSpawnSrcFmt[] = "iiix";
const char CreatureConditionalSpawnDstFmt[] = "iii";
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
#define REVISION_DB_REALMD "required_s2474_01_realmd_joindate_datetime"
#define REVISION_DB_LOGS "required_s2433_01_logs_anticheat"
#define REVISION_DB_CHARACTERS "required_s2473_01_characters_item_instance_text_id_fix"
#define REVISION_DB_MANGOS "required_s2476_01_mangos_spell_template_ap"
#define REVISION_DB_MANGOS "required_s2477_01_mangos_charmed_spell_list"
#endif // __REVISION_SQL_H__

0 comments on commit b788607

Please sign in to comment.