Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Core/SAI): implement SMART_ACTION_DISABLE_REWARD #21105

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/server/game/AI/SmartScripts/SmartScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/server/game/AI/SmartScripts/SmartScriptMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion src/server/game/AI/SmartScripts/SmartScriptMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1501,6 +1502,12 @@ struct SmartAction
uint32 param5;
uint32 param6;
} raw;

struct
{
SAIBool reputation;
SAIBool loot;
} reward;
};
};

Expand Down
4 changes: 3 additions & 1 deletion src/server/game/Entities/Creature/Creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions src/server/game/Entities/Creature/Creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,10 @@ class Creature : public Unit, public GridObject<Creature>, public MovableMapObje

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();
Expand Down Expand Up @@ -475,7 +477,8 @@ class Creature : public Unit, public GridObject<Creature>, public MovableMapObje
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;
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Player/PlayerStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Unit/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17748,7 +17748,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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading