feat(Core/SAI): implement SMART_ACTION_DISABLE_REWARD (#21105)

This commit is contained in:
Kitzunu 2025-02-01 22:49:41 +01:00 committed by GitHub
parent 47c5ff904f
commit 17412174be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 35 additions and 9 deletions

View File

@ -3282,6 +3282,16 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
sWorldState->HandleExternalEvent(static_cast<WorldStateEvent>(e.action.worldStateScript.eventId), e.action.worldStateScript.param);
break;
}
case SMART_ACTION_DISABLE_REWARD:
{
for (WorldObject* target : targets)
if (IsCreature(target))
{
target->ToCreature()->SetReputationRewardDisabled(static_cast<bool>(e.action.reward.reputation));
target->ToCreature()->SetLootRewardDisabled(static_cast<bool>(e.action.reward.loot));
}
break;
}
default:
LOG_ERROR("sql.sql", "SmartScript::ProcessAction: Entry {} SourceType {}, Event {}, Unhandled Action type {}", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType());
break;

View File

@ -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());
@ -1894,6 +1895,9 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
return IsSAIBoolValid(e, e.action.setHealthRegen.regenHealth);
case SMART_ACTION_CALL_TIMED_ACTIONLIST:
return IsSAIBoolValid(e, e.action.timedActionList.allowOverride);
case SMART_ACTION_DISABLE_REWARD:
return IsSAIBoolValid(e, e.action.reward.reputation) &&
IsSAIBoolValid(e, e.action.reward.loot);
case SMART_ACTION_FLEE_FOR_ASSIST:
case SMART_ACTION_MOVE_TO_POS:
case SMART_ACTION_EVADE:

View File

@ -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;
};
};

View File

@ -286,7 +286,9 @@ Creature::Creature(bool isWorldObject): Unit(isWorldObject), MovableMapObject(),
m_ProhibitSchoolTime[i] = 0;
m_CreatureSpellCooldowns.clear();
DisableReputationGain = false;
DisableReputationReward = false;
DisableLootReward = false;
m_SightDistance = sWorld->getFloatConfig(CONFIG_SIGHT_MONSTER);
m_CombatDistance = 0.0f;

View File

@ -359,8 +359,10 @@ public:
Unit* SelectVictim();
void SetDisableReputationGain(bool disable) { DisableReputationGain = disable; }
[[nodiscard]] bool IsReputationGainDisabled() const { return DisableReputationGain; }
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();
@ -478,7 +480,8 @@ protected:
Position m_homePosition;
Position m_transportHomePosition;
bool DisableReputationGain;
bool DisableReputationReward;
bool DisableLootReward;
CreatureTemplate const* m_creatureInfo; // in difficulty mode > 0 can different from sObjectMgr->GetCreatureTemplate(GetEntry())
CreatureData const* m_creatureData;

View File

@ -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);

View File

@ -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())

View File

@ -17781,7 +17781,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);
}

View File

@ -191,7 +191,7 @@ public:
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
}