Core/Cleanup: refactor honor and arena rating modifying methods:
* simplify wierd logic; * add const modifiers to several getter methods. (Idea based on commit [11187] by zergtmn for Mangos)
This commit is contained in:
@@ -2490,9 +2490,9 @@ bool ChatHandler::HandleResetHonorCommand (const char * args)
|
||||
if (!extractPlayerTarget((char*)args,&target))
|
||||
return false;
|
||||
|
||||
target->SetHonorPoints(0);
|
||||
target->SetUInt32Value(PLAYER_FIELD_KILLS, 0);
|
||||
target->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS, 0);
|
||||
target->SetHonorPoints(0);
|
||||
target->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, 0);
|
||||
target->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION, 0);
|
||||
target->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL);
|
||||
|
||||
@@ -7213,30 +7213,38 @@ bool Player::RewardHonor(Unit *uVictim, uint32 groupsize, int32 honor, bool pvpt
|
||||
return true;
|
||||
}
|
||||
|
||||
void Player::SetHonorPoints(uint32 value)
|
||||
{
|
||||
if (value > sWorld->getIntConfig(CONFIG_MAX_HONOR_POINTS))
|
||||
value = sWorld->getIntConfig(CONFIG_MAX_HONOR_POINTS);
|
||||
SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY, value);
|
||||
if (value)
|
||||
AddKnownCurrency(ITEM_HONOR_POINTS_ID);
|
||||
}
|
||||
|
||||
void Player::SetArenaPoints(uint32 value)
|
||||
{
|
||||
if (value > sWorld->getIntConfig(CONFIG_MAX_ARENA_POINTS))
|
||||
value = sWorld->getIntConfig(CONFIG_MAX_ARENA_POINTS);
|
||||
SetUInt32Value(PLAYER_FIELD_ARENA_CURRENCY, value);
|
||||
if (value)
|
||||
AddKnownCurrency(ITEM_ARENA_POINTS_ID);
|
||||
}
|
||||
|
||||
void Player::ModifyHonorPoints(int32 value)
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
if (GetHonorPoints() > sWorld->getIntConfig(CONFIG_MAX_HONOR_POINTS))
|
||||
SetHonorPoints(sWorld->getIntConfig(CONFIG_MAX_HONOR_POINTS) + value);
|
||||
else
|
||||
SetHonorPoints(GetHonorPoints() > uint32(-value) ? GetHonorPoints() + value : 0);
|
||||
}
|
||||
else
|
||||
SetHonorPoints(GetHonorPoints() < sWorld->getIntConfig(CONFIG_MAX_HONOR_POINTS) - value ? GetHonorPoints() + value : sWorld->getIntConfig(CONFIG_MAX_HONOR_POINTS));
|
||||
int32 newValue = int32(GetHonorPoints()) + value;
|
||||
if (newValue < 0)
|
||||
newValue = 0;
|
||||
SetHonorPoints(uint32(newValue));
|
||||
}
|
||||
|
||||
void Player::ModifyArenaPoints(int32 value)
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
if (GetArenaPoints() > sWorld->getIntConfig(CONFIG_MAX_ARENA_POINTS))
|
||||
SetArenaPoints(sWorld->getIntConfig(CONFIG_MAX_ARENA_POINTS) + value);
|
||||
else
|
||||
SetArenaPoints(GetArenaPoints() > uint32(-value) ? GetArenaPoints() + value : 0);
|
||||
}
|
||||
else
|
||||
SetArenaPoints(GetArenaPoints() < sWorld->getIntConfig(CONFIG_MAX_ARENA_POINTS) - value ? GetArenaPoints() + value : sWorld->getIntConfig(CONFIG_MAX_ARENA_POINTS));
|
||||
int32 newValue = int32(GetArenaPoints()) + value;
|
||||
if (newValue < 0)
|
||||
newValue = 0;
|
||||
SetArenaPoints(uint32(newValue));
|
||||
}
|
||||
|
||||
uint32 Player::GetGuildIdFromDB(uint64 guid)
|
||||
@@ -16547,11 +16555,7 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder)
|
||||
_LoadArenaTeamInfo(holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOADARENAINFO));
|
||||
_LoadArenaStatsInfo(holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOADARENASTATS));
|
||||
|
||||
uint32 arena_currency = fields[39].GetUInt32();
|
||||
if (arena_currency > sWorld->getIntConfig(CONFIG_MAX_ARENA_POINTS))
|
||||
arena_currency = sWorld->getIntConfig(CONFIG_MAX_ARENA_POINTS);
|
||||
|
||||
SetArenaPoints(arena_currency);
|
||||
SetArenaPoints(fields[39].GetUInt32());
|
||||
|
||||
// check arena teams integrity
|
||||
for (uint32 arena_slot = 0; arena_slot < MAX_ARENA_SLOT; ++arena_slot)
|
||||
@@ -20388,7 +20392,7 @@ bool Player::BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32
|
||||
return crItem->maxcount != 0;
|
||||
}
|
||||
|
||||
uint32 Player::GetMaxPersonalArenaRatingRequirement(uint32 minarenaslot)
|
||||
uint32 Player::GetMaxPersonalArenaRatingRequirement(uint32 minarenaslot) const
|
||||
{
|
||||
// returns the maximal personal arena rating that can be used to purchase items requiring this condition
|
||||
// the personal rating of the arena team must match the required limit as well
|
||||
|
||||
@@ -1782,12 +1782,12 @@ class Player : public Unit, public GridObject<Player>
|
||||
{
|
||||
SetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (slot * ARENA_TEAM_END) + type, value);
|
||||
}
|
||||
uint32 GetArenaTeamId(uint8 slot) { return GetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (slot * ARENA_TEAM_END) + ARENA_TEAM_ID); }
|
||||
uint32 GetArenaPersonalRating(uint8 slot) { return GetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (slot * ARENA_TEAM_END) + ARENA_TEAM_PERSONAL_RATING); }
|
||||
static uint32 GetArenaTeamIdFromDB(uint64 guid, uint8 slot);
|
||||
static void LeaveAllArenaTeams(uint64 guid);
|
||||
uint32 GetArenaTeamId(uint8 slot) const { return GetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (slot * ARENA_TEAM_END) + ARENA_TEAM_ID); }
|
||||
uint32 GetArenaPersonalRating(uint8 slot) const { return GetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (slot * ARENA_TEAM_END) + ARENA_TEAM_PERSONAL_RATING); }
|
||||
void SetArenaTeamIdInvited(uint32 ArenaTeamId) { m_ArenaTeamIdInvited = ArenaTeamId; }
|
||||
uint32 GetArenaTeamIdInvited() { return m_ArenaTeamIdInvited; }
|
||||
static void LeaveAllArenaTeams(uint64 guid);
|
||||
|
||||
Difficulty GetDifficulty(bool isRaid) const { return isRaid ? m_raidDifficulty : m_dungeonDifficulty; }
|
||||
Difficulty GetDungeonDifficulty() const { return m_dungeonDifficulty; }
|
||||
@@ -1992,23 +1992,13 @@ class Player : public Unit, public GridObject<Player>
|
||||
/*********************************************************/
|
||||
void UpdateHonorFields();
|
||||
bool RewardHonor(Unit *pVictim, uint32 groupsize, int32 honor = -1, bool pvptoken = false);
|
||||
uint32 GetHonorPoints() { return GetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY); }
|
||||
uint32 GetArenaPoints() { return GetUInt32Value(PLAYER_FIELD_ARENA_CURRENCY); }
|
||||
uint32 GetHonorPoints() const { return GetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY); }
|
||||
uint32 GetArenaPoints() const { return GetUInt32Value(PLAYER_FIELD_ARENA_CURRENCY); }
|
||||
void ModifyHonorPoints(int32 value);
|
||||
void ModifyArenaPoints(int32 value);
|
||||
uint32 GetMaxPersonalArenaRatingRequirement(uint32 minarenaslot);
|
||||
void SetHonorPoints(uint32 value)
|
||||
{
|
||||
SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY, value);
|
||||
if (value)
|
||||
AddKnownCurrency(ITEM_HONOR_POINTS_ID); // Arena Points
|
||||
}
|
||||
void SetArenaPoints(uint32 value)
|
||||
{
|
||||
SetUInt32Value(PLAYER_FIELD_ARENA_CURRENCY, value);
|
||||
if (value)
|
||||
AddKnownCurrency(ITEM_ARENA_POINTS_ID); // Arena Points
|
||||
}
|
||||
uint32 GetMaxPersonalArenaRatingRequirement(uint32 minarenaslot) const;
|
||||
void SetHonorPoints(uint32 value);
|
||||
void SetArenaPoints(uint32 value);
|
||||
|
||||
//End of PvP System
|
||||
|
||||
|
||||
Reference in New Issue
Block a user