Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool Player::RewardHonor(Unit *uVictim, uint32 groupsize, float honor, bool pvptoken)
- {
- // do not reward honor in arenas, but enable onkill spellproc
- if (InArena())
- {
- if (!uVictim || uVictim == this || uVictim->GetTypeId() != TYPEID_PLAYER)
- return false;
- if (GetBGTeam() == uVictim->ToPlayer()->GetBGTeam())
- return false;
- return true;
- }
- // 'Inactive' this aura prevents the player from gaining honor points and battleground tokens
- if (HasAura(SPELL_AURA_PLAYER_INACTIVE))
- return false;
- uint64 victim_guid = 0;
- uint32 victim_rank = 0;
- uint32 rank_diff = 0;
- time_t now = time(NULL);
- // need call before fields update to have chance move yesterday data to appropriate fields before today data change.
- UpdateHonorFields();
- // do not reward honor in arenas, but return true to enable onkill spellproc
- if (InBattleGround() && GetBattleGround() && GetBattleGround()->isArena())
- return true;
- if (honor <= 0)
- {
- if (!uVictim || uVictim == this || uVictim->HasAuraType(SPELL_AURA_NO_PVP_CREDIT))
- return false;
- victim_guid = uVictim->GetGUID();
- if (uVictim->GetTypeId() == TYPEID_PLAYER)
- {
- Player *pVictim = uVictim->ToPlayer();
- if (GetTeam() == pVictim->GetTeam() && !sWorld.IsFFAPvPRealm())
- return false;
- float f = 1; //need for total kills (?? need more info)
- uint32 k_grey = 0;
- uint32 k_level = getLevel();
- uint32 v_level = pVictim->getLevel();
- {
- // PLAYER_CHOSEN_TITLE VALUES DESCRIPTION
- // [0] Just name
- // [1..14] Alliance honor titles and player name
- // [15..28] Horde honor titles and player name
- // [29..38] Other title and player name
- // [39+] Nothing
- uint32 victim_title = pVictim->GetUInt32Value(PLAYER_CHOSEN_TITLE);
- // Get Killer titles, CharTitlesEntry::bit_index
- // Ranks:
- // title[1..14] -> rank[5..18]
- // title[15..28] -> rank[5..18]
- // title[other] -> 0
- if (victim_title == 0)
- victim_guid = 0; // Don't show HK: <rank> message, only log.
- else if (victim_title < 15)
- victim_rank = victim_title + 4;
- else if (victim_title < 29)
- victim_rank = victim_title - 14 + 4;
- else
- victim_guid = 0; // Don't show HK: <rank> message, only log.
- }
- k_grey = Trinity::XP::GetGrayLevel(k_level);
- if (v_level <= k_grey)
- return false;
- float diff_level = (k_level == k_grey) ? 1 : ((float(v_level) - float(k_grey)) / (float(k_level) - float(k_grey)));
- int32 v_rank =1; //need more info
- honor = ((f * diff_level * (190 + v_rank*10))/6);
- honor *= ((float)k_level) / 70.0f; //factor of dependence on levels of the killer
- // count the number of playerkills in one day
- ApplyModUInt32Value(PLAYER_FIELD_KILLS, 1, true);
- // and those in a lifetime
- ApplyModUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS, 1, true);
- UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL);
- UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HK_CLASS, pVictim->getClass());
- UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HK_RACE, pVictim->getRace());
- }
- else
- {
- if (!uVictim->ToCreature()->isRacialLeader())
- return false;
- honor = 100; // ??? need more info
- victim_rank = 19; // HK: Leader
- }
- }
- if (uVictim != NULL)
- {
- honor *= sWorld.getRate(RATE_HONOR);
- if (groupsize > 1)
- honor /= groupsize;
- // apply honor multiplier from aura (not stacking-get highest)
- honor = int32(float(honor) * (float(GetMaxPositiveAuraModifier(SPELL_AURA_MOD_HONOR_GAIN_PCT))+100.0f)/100.0f);
- honor *= (((float)urand(8,12))/10); // approx honor: 80% - 120% of real honor
- }
- // honor - for show honor points in log
- // victim_guid - for show victim name in log
- // victim_rank [1..4] HK: <dishonored rank>
- // victim_rank [5..19] HK: <alliance\horde rank>
- // victim_rank [0,20+] HK: <>
- WorldPacket data(SMSG_PVP_CREDIT,4+8+4);
- data << (uint32) honor;
- data << (uint64) victim_guid;
- data << (uint32) victim_rank;
- GetSession()->SendPacket(&data);
- // add honor points
- ModifyHonorPoints(int32(honor));
- ApplyModUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, uint32(honor), true);
- if (sWorld.getConfig(CONFIG_PVP_TOKEN_ENABLE) && pvptoken)
- {
- if (!uVictim || uVictim == this || uVictim->HasAuraType(SPELL_AURA_NO_PVP_CREDIT))
- return true;
- if (uVictim->GetTypeId() == TYPEID_PLAYER)
- {
- // Check if allowed to receive it in current map
- uint8 MapType = sWorld.getConfig(CONFIG_PVP_TOKEN_MAP_TYPE);
- if ((MapType == 1 && !InBattleGround() && !HasByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP))
- || (MapType == 2 && !HasByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP))
- || (MapType == 3 && !InBattleGround()))
- return true;
- uint32 noSpaceForCount = 0;
- uint32 itemId = sWorld.getConfig(CONFIG_PVP_TOKEN_ID);
- int32 count = sWorld.getConfig(CONFIG_PVP_TOKEN_COUNT);
- // check space and find places
- ItemPosCountVec dest;
- uint8 msg = CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount);
- if (msg != EQUIP_ERR_OK) // convert to possible store amount
- count = noSpaceForCount;
- if (count == 0 || dest.empty()) // can't add any
- {
- // -- TODO: Send to mailbox if no space
- ChatHandler(this).PSendSysMessage("You don't have any space in your bags for a token.");
- return true;
- }
- Item* item = StoreNewItem(dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
- SendNewItem(item,count,true,false);
- ChatHandler(this).PSendSysMessage("You have been awarded a token for slaying another player.");
- }
- }
- + if (this->GetHonorPoints() >= 1000)
- + {
- + uint32 noSpaceForCount = 0;
- + uint32 itemId = sWorld.getConfig(CONFIG_PVP_TOKEN_ID);
- + int32 count = sWorld.getConfig(CONFIG_PVP_TOKEN_COUNT);
- +
- + // check space and find places
- + ItemPosCountVec dest;
- + uint8 msg = CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount);
- + if (msg != EQUIP_ERR_OK) // convert to possible store amount
- + count = noSpaceForCount;
- +
- + if (count == 0 || dest.empty()) // can't add any
- + {
- + // -- TODO: Send to mailbox if no space
- + ChatHandler(this).PSendSysMessage("You don't have any space in your bags for a token.");
- + return true;
- + }
- +
- + Item* item = StoreNewItem(dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
- + SendNewItem(item,count,true,false);
- + ChatHandler(this).PSendSysMessage("You have been awarded a token for slaying another player.");
- + ModifyHonorPoints(-1000);
- + }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement