Skip to content

Commit

Permalink
[10327] Implement reputation rates and aura effects for Spell::Effect…
Browse files Browse the repository at this point in the history
…Reputation().

Also apply rates after percentage aura modifiers, so auras always
give expected percentage of final value independant of "hidden" rates.
  • Loading branch information
Lynx3d committed Aug 7, 2010
1 parent 1bf6931 commit 92d2121
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 24 deletions.
65 changes: 44 additions & 21 deletions src/game/Player.cpp
Expand Up @@ -6251,35 +6251,58 @@ ReputationRank Player::GetReputationRank(uint32 faction) const
}

//Calculate total reputation percent player gain with quest/creature level
int32 Player::CalculateReputationGain(uint32 creatureOrQuestLevel, int32 rep, int32 faction, bool for_quest, bool noQuestBonus)
int32 Player::CalculateReputationGain(ReputationSource source, int32 rep, int32 faction, uint32 creatureOrQuestLevel, bool noAuraBonus)
{
float percent = 100.0f;

// Get the generic rate first
if (const RepRewardRate *repData = sObjectMgr.GetRepRewardRate(faction))
{
float repRate = for_quest ? repData->quest_rate : repData->creature_rate;
percent *= repRate;
float repMod = noAuraBonus ? 0.0f : (float)GetTotalAuraModifier(SPELL_AURA_MOD_REPUTATION_GAIN);

// for custom, a rate of 0.0 will totally disable reputation gain for this faction/type
if (repRate <= 0.0f)
percent = repRate;
}
// faction specific auras only seem to apply to kills
if (source == REPUTATION_SOURCE_KILL)
repMod += GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_FACTION_REPUTATION_GAIN, faction);

percent += rep > 0 ? repMod : -repMod;

float rate = for_quest ? sWorld.getConfig(CONFIG_FLOAT_RATE_REPUTATION_LOWLEVEL_QUEST) : sWorld.getConfig(CONFIG_FLOAT_RATE_REPUTATION_LOWLEVEL_KILL);
float rate = 1.0f;
switch (source)
{
case REPUTATION_SOURCE_KILL:
rate = sWorld.getConfig(CONFIG_FLOAT_RATE_REPUTATION_LOWLEVEL_KILL);
break;
case REPUTATION_SOURCE_QUEST:
rate = sWorld.getConfig(CONFIG_FLOAT_RATE_REPUTATION_LOWLEVEL_QUEST);
break;
}

if (rate != 1.0f && creatureOrQuestLevel <= MaNGOS::XP::GetGrayLevel(getLevel()))
percent *= rate;

float repMod = noQuestBonus ? 0.0f : (float)GetTotalAuraModifier(SPELL_AURA_MOD_REPUTATION_GAIN);
if (percent <= 0.0f)
return 0;

if (!for_quest)
repMod += GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_FACTION_REPUTATION_GAIN, faction);
// Multiply result with the faction specific rate
if (const RepRewardRate *repData = sObjectMgr.GetRepRewardRate(faction))
{
float repRate = 0.0f;
switch (source)
{
case REPUTATION_SOURCE_KILL:
repRate = repData->creature_rate;
break;
case REPUTATION_SOURCE_QUEST:
repRate = repData->quest_rate;
break;
case REPUTATION_SOURCE_SPELL:
repRate = repData->spell_rate;
break;
}

percent += rep > 0 ? repMod : -repMod;
// for custom, a rate of 0.0 will totally disable reputation gain for this faction/type
if (repRate <= 0.0f)
return 0;

if (percent <= 0.0f)
return 0;
percent *= repRate;
}

return int32(sWorld.getConfig(CONFIG_FLOAT_RATE_REPUTATION_GAIN)*rep*percent/100.0f);
}
Expand All @@ -6298,7 +6321,7 @@ void Player::RewardReputation(Unit *pVictim, float rate)

if(Rep->repfaction1 && (!Rep->team_dependent || GetTeam()==ALLIANCE))
{
int32 donerep1 = CalculateReputationGain(pVictim->getLevel(), Rep->repvalue1, Rep->repfaction1, false);
int32 donerep1 = CalculateReputationGain(REPUTATION_SOURCE_KILL, Rep->repvalue1, Rep->repfaction1, pVictim->getLevel());
donerep1 = int32(donerep1*rate);
FactionEntry const *factionEntry1 = sFactionStore.LookupEntry(Rep->repfaction1);
uint32 current_reputation_rank1 = GetReputationMgr().GetRank(factionEntry1);
Expand All @@ -6316,7 +6339,7 @@ void Player::RewardReputation(Unit *pVictim, float rate)

if(Rep->repfaction2 && (!Rep->team_dependent || GetTeam()==HORDE))
{
int32 donerep2 = CalculateReputationGain(pVictim->getLevel(), Rep->repvalue2, Rep->repfaction2, false);
int32 donerep2 = CalculateReputationGain(REPUTATION_SOURCE_KILL, Rep->repvalue2, Rep->repfaction2, pVictim->getLevel());
donerep2 = int32(donerep2*rate);
FactionEntry const *factionEntry2 = sFactionStore.LookupEntry(Rep->repfaction2);
uint32 current_reputation_rank2 = GetReputationMgr().GetRank(factionEntry2);
Expand Down Expand Up @@ -6345,7 +6368,7 @@ void Player::RewardReputation(Quest const *pQuest)
// No diplomacy mod are applied to the final value (flat). Note the formula (finalValue = DBvalue/100)
if (pQuest->RewRepValue[i])
{
int32 rep = CalculateReputationGain(GetQuestLevelForPlayer(pQuest), pQuest->RewRepValue[i]/100, pQuest->RewRepFaction[i], true, true);
int32 rep = CalculateReputationGain(REPUTATION_SOURCE_QUEST, pQuest->RewRepValue[i]/100, pQuest->RewRepFaction[i], GetQuestLevelForPlayer(pQuest), true);

if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(pQuest->RewRepFaction[i]))
GetReputationMgr().ModifyReputation(factionEntry, rep);
Expand All @@ -6362,7 +6385,7 @@ void Player::RewardReputation(Quest const *pQuest)
if (!repPoints)
continue;

repPoints = CalculateReputationGain(GetQuestLevelForPlayer(pQuest), repPoints, pQuest->RewRepFaction[i], true);
repPoints = CalculateReputationGain(REPUTATION_SOURCE_QUEST, repPoints, pQuest->RewRepFaction[i], GetQuestLevelForPlayer(pQuest));

if (const FactionEntry* factionEntry = sFactionStore.LookupEntry(pQuest->RewRepFaction[i]))
GetReputationMgr().ModifyReputation(factionEntry, repPoints);
Expand Down
9 changes: 8 additions & 1 deletion src/game/Player.h
Expand Up @@ -928,6 +928,13 @@ enum PlayerDelayedOperations
DELAYED_END
};

enum ReputationSource
{
REPUTATION_SOURCE_KILL,
REPUTATION_SOURCE_QUEST,
REPUTATION_SOURCE_SPELL
};

// Player summoning auto-decline time (in secs)
#define MAX_PLAYER_SUMMON_DELAY (2*MINUTE)
#define MAX_MONEY_AMOUNT (0x7FFFFFFF-1)
Expand Down Expand Up @@ -1993,6 +2000,7 @@ class MANGOS_DLL_SPEC Player : public Unit
ReputationRank GetReputationRank(uint32 faction_id) const;
void RewardReputation(Unit *pVictim, float rate);
void RewardReputation(Quest const *pQuest);
int32 CalculateReputationGain(ReputationSource source, int32 rep, int32 faction, uint32 creatureOrQuestLevel = 0, bool noAuraBonus = false);

void UpdateSkillsForLevel();
void UpdateSkillsToMaxSkillsForLevel(); // for .levelup
Expand Down Expand Up @@ -2617,7 +2625,6 @@ class MANGOS_DLL_SPEC Player : public Unit
Item* _StoreItem( uint16 pos, Item *pItem, uint32 count, bool clone, bool update );

void UpdateKnownCurrencies(uint32 itemId, bool apply);
int32 CalculateReputationGain(uint32 creatureOrQuestLevel, int32 rep, int32 faction, bool for_quest, bool noQuestBonus = false);
void AdjustQuestReqItemCount( Quest const* pQuest, QuestStatusData& questStatusData );

void SetCanDelayTeleport(bool setting) { m_bCanDelayTeleport = setting; }
Expand Down
3 changes: 2 additions & 1 deletion src/game/SpellEffects.cpp
Expand Up @@ -7143,14 +7143,15 @@ void Spell::EffectReputation(SpellEffectIndex eff_idx)
Player *_player = (Player*)unitTarget;

int32 rep_change = m_currentBasePoints[eff_idx];

uint32 faction_id = m_spellInfo->EffectMiscValue[eff_idx];

FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction_id);

if(!factionEntry)
return;

rep_change = _player->CalculateReputationGain(REPUTATION_SOURCE_SPELL, rep_change, faction_id);

_player->GetReputationMgr().ModifyReputation(factionEntry, rep_change);
}

Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "10326"
#define REVISION_NR "10327"
#endif // __REVISION_NR_H__

0 comments on commit 92d2121

Please sign in to comment.