From 6911a6cef61eacdd8de6b8b9df431612dffe4b89 Mon Sep 17 00:00:00 2001 From: Kitzunu <24550914+Kitzunu@users.noreply.github.com> Date: Mon, 6 Jan 2025 16:22:00 +0100 Subject: [PATCH 1/5] feat(Core/SAI): implement SMART_ACTION_DISABLE_REWARD * closes https://github.com/azerothcore/azerothcore-wotlk/issues/16359 --- src/server/game/AI/SmartScripts/SmartScript.cpp | 12 ++++++++++++ src/server/game/AI/SmartScripts/SmartScriptMgr.cpp | 7 +++++++ src/server/game/AI/SmartScripts/SmartScriptMgr.h | 9 ++++++++- src/server/game/Entities/Creature/Creature.cpp | 4 +++- src/server/game/Entities/Creature/Creature.h | 9 ++++++--- src/server/game/Entities/Player/Player.cpp | 2 +- src/server/game/Entities/Player/PlayerStorage.cpp | 2 +- src/server/game/Entities/Unit/Unit.cpp | 2 +- .../BattleForMountHyjal/instance_hyjal.cpp | 2 +- 9 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index e5d77ca4fffccf..3a42b831fd3afc 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -3282,6 +3282,18 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u sWorldState->HandleExternalEvent(static_cast(e.action.worldStateScript.eventId), e.action.worldStateScript.param); break; } + case SMART_ACTION_DISABLE_REWARD: + { + for (WorldObject* target : targets) + if (IsCreature(target)) + { + if (e.action.reward.reputation) + target->ToCreature()->SetReputationRewardDisabled(true); + if (e.action.reward.loot) + target->ToCreature()->SetLootRewardDisabled(true); + } + break; + } default: LOG_ERROR("sql.sql", "SmartScript::ProcessAction: Entry {} SourceType {}, Event {}, Unhandled Action type {}", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType()); break; diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp index ab81002eace2fd..63feea5b0ff005 100644 --- a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp +++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp @@ -860,6 +860,7 @@ bool SmartAIMgr::CheckUnusedActionParams(SmartScriptHolder const& e) case SMART_ACTION_MOVEMENT_PAUSE: return sizeof(SmartAction::move); case SMART_ACTION_MOVEMENT_RESUME: return sizeof(SmartAction::move); case SMART_ACTION_WORLD_SCRIPT: return sizeof(SmartAction::worldStateScript); + case SMART_ACTION_DISABLE_REWARD: return sizeof(SmartAction::reward); default: LOG_WARN("sql.sql", "SmartAIMgr: entryorguid {} source_type {} id {} action_type {} is using an action with no unused params specified in SmartAIMgr::CheckUnusedActionParams(), please report this.", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType()); @@ -1951,6 +1952,12 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e) AC_SAI_IS_BOOLEAN_VALID(e, e.action.timedActionList.allowOverride); break; } + case SMART_ACTION_DISABLE_REWARD: + { + AC_SAI_IS_BOOLEAN_VALID(e, e.action.reward.reputation); + AC_SAI_IS_BOOLEAN_VALID(e, e.action.reward.loot); + break; + } case SMART_ACTION_FLEE_FOR_ASSIST: case SMART_ACTION_MOVE_TO_POS: case SMART_ACTION_EVADE: diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.h b/src/server/game/AI/SmartScripts/SmartScriptMgr.h index 7ca18d2f646885..2e7c6db2c08409 100644 --- a/src/server/game/AI/SmartScripts/SmartScriptMgr.h +++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.h @@ -738,8 +738,9 @@ enum SMART_ACTION SMART_ACTION_MOVEMENT_PAUSE = 235, // timer SMART_ACTION_MOVEMENT_RESUME = 236, // timerOverride SMART_ACTION_WORLD_SCRIPT = 237, // eventId, param + SMART_ACTION_DISABLE_REWARD = 238, // reputation 0/1, loot 0/1 - SMART_ACTION_AC_END = 238, // placeholder + SMART_ACTION_AC_END = 239, // placeholder }; enum class SmartActionSummonCreatureFlags @@ -1501,6 +1502,12 @@ struct SmartAction uint32 param5; uint32 param6; } raw; + + struct + { + SAIBool reputation; + SAIBool loot; + } reward; }; }; diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 7abedcae7e02ea..4e73914d279b03 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -286,7 +286,9 @@ Creature::Creature(bool isWorldObject): Unit(isWorldObject), MovableMapObject(), m_ProhibitSchoolTime[i] = 0; m_CreatureSpellCooldowns.clear(); - DisableReputationGain = false; + + m_disableReputationReward = false; + m_disableLootReward = false; m_SightDistance = sWorld->getFloatConfig(CONFIG_SIGHT_MONSTER); m_CombatDistance = 0.0f; diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index 17f69f801e8bbc..020cfdc02d39d7 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -356,8 +356,10 @@ class Creature : public Unit, public GridObject, public MovableMapObje Unit* SelectVictim(); - void SetDisableReputationGain(bool disable) { DisableReputationGain = disable; } - [[nodiscard]] bool IsReputationGainDisabled() const { return DisableReputationGain; } + void SetReputationRewardDisabled(bool disable) { m_disableReputationReward = disable; } + [[nodiscard]] bool IsReputationRewardDisabled() const { return m_disableReputationReward; } + void SetLootRewardDisabled(bool disable) { m_disableLootReward = disable; } + [[nodiscard]] bool IsLootRewardDisabled() const { return m_disableLootReward; } [[nodiscard]] bool IsDamageEnoughForLootingAndReward() const; void LowerPlayerDamageReq(uint32 unDamage, bool damagedByPlayer = true); void ResetPlayerDamageReq(); @@ -475,7 +477,8 @@ class Creature : public Unit, public GridObject, public MovableMapObje Position m_homePosition; Position m_transportHomePosition; - bool DisableReputationGain; + bool m_disableReputationReward; + bool m_disableLootReward; CreatureTemplate const* m_creatureInfo; // in difficulty mode > 0 can different from sObjectMgr->GetCreatureTemplate(GetEntry()) CreatureData const* m_creatureData; diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index dfed1d21618d75..8d4efad95ac005 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -5982,7 +5982,7 @@ void Player::RewardReputation(Unit* victim) if (!victim || victim->IsPlayer()) return; - if (victim->ToCreature()->IsReputationGainDisabled()) + if (victim->ToCreature()->IsReputationRewardDisabled()) return; ReputationOnKillEntry const* Rep = sObjectMgr->GetReputationOnKilEntry(victim->ToCreature()->GetCreatureTemplate()->Entry); diff --git a/src/server/game/Entities/Player/PlayerStorage.cpp b/src/server/game/Entities/Player/PlayerStorage.cpp index 3e878976d2e55b..514f948cd8143d 100644 --- a/src/server/game/Entities/Player/PlayerStorage.cpp +++ b/src/server/game/Entities/Player/PlayerStorage.cpp @@ -5619,7 +5619,7 @@ bool Player::LoadFromDB(ObjectGuid playerGuid, CharacterDatabaseQueryHolder cons bool Player::isAllowedToLoot(Creature const* creature) { - if (!creature->isDead() || !creature->IsDamageEnoughForLootingAndReward()) + if (!creature->isDead() || !creature->IsDamageEnoughForLootingAndReward() || creature->IsLootRewardDisabled()) return false; if (HasPendingBind()) diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 85fe37b522987f..61379dbd384385 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -17738,7 +17738,7 @@ void Unit::Kill(Unit* killer, Unit* victim, bool durabilityLoss, WeaponAttackTyp bool isRewardAllowed = true; if (creature) { - isRewardAllowed = creature->IsDamageEnoughForLootingAndReward(); + isRewardAllowed = (creature->IsDamageEnoughForLootingAndReward() && !creature->IsLootRewardDisabled()); if (!isRewardAllowed) creature->SetLootRecipient(nullptr); } diff --git a/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/instance_hyjal.cpp b/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/instance_hyjal.cpp index c0c95f6c780bb1..2c6a3d06b9a245 100644 --- a/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/instance_hyjal.cpp +++ b/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/instance_hyjal.cpp @@ -191,7 +191,7 @@ class instance_hyjal : public InstanceMapScript if (creature->IsSummon() && _bossWave != TO_BE_DECIDED) { if (_currentWave == 0) - creature->SetDisableReputationGain(true); + creature->SetReputationRewardDisabled(true); DoUpdateWorldState(WORLD_STATE_ENEMYCOUNT, ++trash); // Update the instance wave count on new trash spawn _encounterNPCs.insert(creature->GetGUID()); // Used for despawning on wipe } From 75bdb86edcdcc5600e5f5b6260035e4fb78a41d3 Mon Sep 17 00:00:00 2001 From: Kitzunu <24550914+Kitzunu@users.noreply.github.com> Date: Mon, 6 Jan 2025 16:47:55 +0100 Subject: [PATCH 2/5] actually make sure you can disable and enable the disable --- src/server/game/AI/SmartScripts/SmartScript.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index 3a42b831fd3afc..cf317a613bdef5 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -3287,10 +3287,8 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u for (WorldObject* target : targets) if (IsCreature(target)) { - if (e.action.reward.reputation) - target->ToCreature()->SetReputationRewardDisabled(true); - if (e.action.reward.loot) - target->ToCreature()->SetLootRewardDisabled(true); + target->ToCreature()->SetReputationRewardDisabled(e.action.reward.reputation); + target->ToCreature()->SetLootRewardDisabled(e.action.reward.loot); } break; } From 3d5b75d72cf69f9be84d7b33630a7fe4319c1e88 Mon Sep 17 00:00:00 2001 From: Kitzunu <24550914+Kitzunu@users.noreply.github.com> Date: Mon, 6 Jan 2025 16:58:58 +0100 Subject: [PATCH 3/5] cast to bool --- src/server/game/AI/SmartScripts/SmartScript.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index cf317a613bdef5..2502c5c6926c82 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -3287,8 +3287,8 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u for (WorldObject* target : targets) if (IsCreature(target)) { - target->ToCreature()->SetReputationRewardDisabled(e.action.reward.reputation); - target->ToCreature()->SetLootRewardDisabled(e.action.reward.loot); + target->ToCreature()->SetReputationRewardDisabled(static_cast(e.action.reward.reputation)); + target->ToCreature()->SetLootRewardDisabled(static_cast(e.action.reward.loot)); } break; } From fbc6c8f63b77576738af6a6f84d9470c761338df Mon Sep 17 00:00:00 2001 From: Kitzunu <24550914+Kitzunu@users.noreply.github.com> Date: Wed, 8 Jan 2025 17:42:56 +0100 Subject: [PATCH 4/5] Update Creature.h --- src/server/game/Entities/Creature/Creature.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index 020cfdc02d39d7..5ece4d5be54a4f 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -356,10 +356,10 @@ class Creature : public Unit, public GridObject, public MovableMapObje Unit* SelectVictim(); - void SetReputationRewardDisabled(bool disable) { m_disableReputationReward = disable; } - [[nodiscard]] bool IsReputationRewardDisabled() const { return m_disableReputationReward; } - void SetLootRewardDisabled(bool disable) { m_disableLootReward = disable; } - [[nodiscard]] bool IsLootRewardDisabled() const { return m_disableLootReward; } + void SetReputationRewardDisabled(bool disable) { DisableReputationReward = disable; } + [[nodiscard]] bool IsReputationRewardDisabled() const { return DisableReputationReward; } + void SetLootRewardDisabled(bool disable) { DisableLootReward = disable; } + [[nodiscard]] bool IsLootRewardDisabled() const { return DisableLootReward; } [[nodiscard]] bool IsDamageEnoughForLootingAndReward() const; void LowerPlayerDamageReq(uint32 unDamage, bool damagedByPlayer = true); void ResetPlayerDamageReq(); @@ -477,8 +477,8 @@ class Creature : public Unit, public GridObject, public MovableMapObje Position m_homePosition; Position m_transportHomePosition; - bool m_disableReputationReward; - bool m_disableLootReward; + bool DisableReputationReward; + bool DisableLootReward; CreatureTemplate const* m_creatureInfo; // in difficulty mode > 0 can different from sObjectMgr->GetCreatureTemplate(GetEntry()) CreatureData const* m_creatureData; From 9dd29e862403b42f6c1a0c8d5a5d719be4fa0213 Mon Sep 17 00:00:00 2001 From: Kitzunu <24550914+Kitzunu@users.noreply.github.com> Date: Wed, 8 Jan 2025 18:26:10 +0100 Subject: [PATCH 5/5] Update Creature.cpp --- src/server/game/Entities/Creature/Creature.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 4e73914d279b03..cf197c7b232f04 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -287,8 +287,8 @@ Creature::Creature(bool isWorldObject): Unit(isWorldObject), MovableMapObject(), m_CreatureSpellCooldowns.clear(); - m_disableReputationReward = false; - m_disableLootReward = false; + DisableReputationReward = false; + DisableLootReward = false; m_SightDistance = sWorld->getFloatConfig(CONFIG_SIGHT_MONSTER); m_CombatDistance = 0.0f;