Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.90 KB | None | 0 0
  1. bool Player::RewardHonor(Unit *uVictim, uint32 groupsize, float honor, bool pvptoken)
  2. {
  3.     // do not reward honor in arenas, but enable onkill spellproc
  4.     if (InArena())
  5.     {
  6.         if (!uVictim || uVictim == this || uVictim->GetTypeId() != TYPEID_PLAYER)
  7.             return false;
  8.  
  9.         if (GetBGTeam() == uVictim->ToPlayer()->GetBGTeam())
  10.             return false;
  11.  
  12.         return true;
  13.     }
  14.  
  15.     // 'Inactive' this aura prevents the player from gaining honor points and battleground tokens
  16.     if (HasAura(SPELL_AURA_PLAYER_INACTIVE))
  17.         return false;
  18.  
  19.     uint64 victim_guid = 0;
  20.     uint32 victim_rank = 0;
  21.     uint32 rank_diff = 0;
  22.     time_t now = time(NULL);
  23.  
  24.     // need call before fields update to have chance move yesterday data to appropriate fields before today data change.
  25.     UpdateHonorFields();
  26.  
  27.     // do not reward honor in arenas, but return true to enable onkill spellproc
  28.     if (InBattleGround() && GetBattleGround() && GetBattleGround()->isArena())
  29.         return true;
  30.  
  31.     if (honor <= 0)
  32.     {
  33.         if (!uVictim || uVictim == this || uVictim->HasAuraType(SPELL_AURA_NO_PVP_CREDIT))
  34.             return false;
  35.  
  36.         victim_guid = uVictim->GetGUID();
  37.  
  38.         if (uVictim->GetTypeId() == TYPEID_PLAYER)
  39.         {
  40.             Player *pVictim = uVictim->ToPlayer();
  41.  
  42.             if (GetTeam() == pVictim->GetTeam() && !sWorld.IsFFAPvPRealm())
  43.                 return false;
  44.  
  45.             float f = 1;                                    //need for total kills (?? need more info)
  46.             uint32 k_grey = 0;
  47.             uint32 k_level = getLevel();
  48.             uint32 v_level = pVictim->getLevel();
  49.  
  50.             {
  51.                 // PLAYER_CHOSEN_TITLE VALUES DESCRIPTION
  52.                 //  [0]      Just name
  53.                 //  [1..14]  Alliance honor titles and player name
  54.                 //  [15..28] Horde honor titles and player name
  55.                 //  [29..38] Other title and player name
  56.                 //  [39+]    Nothing
  57.                 uint32 victim_title = pVictim->GetUInt32Value(PLAYER_CHOSEN_TITLE);
  58.                                                             // Get Killer titles, CharTitlesEntry::bit_index
  59.                 // Ranks:
  60.                 //  title[1..14]  -> rank[5..18]
  61.                 //  title[15..28] -> rank[5..18]
  62.                 //  title[other]  -> 0
  63.                 if (victim_title == 0)
  64.                     victim_guid = 0;                        // Don't show HK: <rank> message, only log.
  65.                 else if (victim_title < 15)
  66.                     victim_rank = victim_title + 4;
  67.                 else if (victim_title < 29)
  68.                     victim_rank = victim_title - 14 + 4;
  69.                 else
  70.                     victim_guid = 0;                        // Don't show HK: <rank> message, only log.
  71.             }
  72.  
  73.             k_grey = Trinity::XP::GetGrayLevel(k_level);
  74.  
  75.             if (v_level <= k_grey)
  76.                 return false;
  77.  
  78.             float diff_level = (k_level == k_grey) ? 1 : ((float(v_level) - float(k_grey)) / (float(k_level) - float(k_grey)));
  79.  
  80.             int32 v_rank =1;                                //need more info
  81.  
  82.             honor = ((f * diff_level * (190 + v_rank*10))/6);
  83.             honor *= ((float)k_level) / 70.0f;              //factor of dependence on levels of the killer
  84.  
  85.             // count the number of playerkills in one day
  86.             ApplyModUInt32Value(PLAYER_FIELD_KILLS, 1, true);
  87.             // and those in a lifetime
  88.             ApplyModUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS, 1, true);
  89.             UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL);
  90.             UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HK_CLASS, pVictim->getClass());
  91.             UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HK_RACE, pVictim->getRace());
  92.         }
  93.         else
  94.         {
  95.             if (!uVictim->ToCreature()->isRacialLeader())
  96.                 return false;
  97.  
  98.             honor = 100;                                    // ??? need more info
  99.             victim_rank = 19;                               // HK: Leader
  100.         }
  101.     }
  102.  
  103.     if (uVictim != NULL)
  104.     {
  105.         honor *= sWorld.getRate(RATE_HONOR);
  106.  
  107.         if (groupsize > 1)
  108.             honor /= groupsize;
  109.  
  110.         // apply honor multiplier from aura (not stacking-get highest)
  111.         honor = int32(float(honor) * (float(GetMaxPositiveAuraModifier(SPELL_AURA_MOD_HONOR_GAIN_PCT))+100.0f)/100.0f);
  112.         honor *= (((float)urand(8,12))/10);                 // approx honor: 80% - 120% of real honor
  113.     }
  114.  
  115.     // honor - for show honor points in log
  116.     // victim_guid - for show victim name in log
  117.     // victim_rank [1..4]  HK: <dishonored rank>
  118.     // victim_rank [5..19] HK: <alliance\horde rank>
  119.     // victim_rank [0,20+] HK: <>
  120.     WorldPacket data(SMSG_PVP_CREDIT,4+8+4);
  121.     data << (uint32) honor;
  122.     data << (uint64) victim_guid;
  123.     data << (uint32) victim_rank;
  124.  
  125.     GetSession()->SendPacket(&data);
  126.  
  127.     // add honor points
  128.     ModifyHonorPoints(int32(honor));
  129.  
  130.     ApplyModUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, uint32(honor), true);
  131.  
  132.     if (sWorld.getConfig(CONFIG_PVP_TOKEN_ENABLE) && pvptoken)
  133.     {
  134.         if (!uVictim || uVictim == this || uVictim->HasAuraType(SPELL_AURA_NO_PVP_CREDIT))
  135.             return true;
  136.  
  137.         if (uVictim->GetTypeId() == TYPEID_PLAYER)
  138.         {
  139.             // Check if allowed to receive it in current map
  140.             uint8 MapType = sWorld.getConfig(CONFIG_PVP_TOKEN_MAP_TYPE);
  141.             if ((MapType == 1 && !InBattleGround() && !HasByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP))
  142.                 || (MapType == 2 && !HasByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP))
  143.                 || (MapType == 3 && !InBattleGround()))
  144.                 return true;
  145.  
  146.             uint32 noSpaceForCount = 0;
  147.             uint32 itemId = sWorld.getConfig(CONFIG_PVP_TOKEN_ID);
  148.             int32 count = sWorld.getConfig(CONFIG_PVP_TOKEN_COUNT);
  149.  
  150.             // check space and find places
  151.             ItemPosCountVec dest;
  152.             uint8 msg = CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount);
  153.             if (msg != EQUIP_ERR_OK)   // convert to possible store amount
  154.                 count = noSpaceForCount;
  155.  
  156.             if (count == 0 || dest.empty()) // can't add any
  157.             {
  158.                 // -- TODO: Send to mailbox if no space
  159.                 ChatHandler(this).PSendSysMessage("You don't have any space in your bags for a token.");
  160.                 return true;
  161.             }
  162.  
  163.             Item* item = StoreNewItem(dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
  164.             SendNewItem(item,count,true,false);
  165.             ChatHandler(this).PSendSysMessage("You have been awarded a token for slaying another player.");
  166.         }
  167.     }
  168.  
  169. +    if (this->GetHonorPoints() >= 1000)
  170. +    {
  171. +        uint32 noSpaceForCount = 0;
  172. +        uint32 itemId = sWorld.getConfig(CONFIG_PVP_TOKEN_ID);
  173. +        int32 count = sWorld.getConfig(CONFIG_PVP_TOKEN_COUNT);
  174. +
  175. +        // check space and find places
  176. +        ItemPosCountVec dest;
  177. +        uint8 msg = CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount);
  178. +        if (msg != EQUIP_ERR_OK)   // convert to possible store amount
  179. +            count = noSpaceForCount;
  180. +
  181. +        if (count == 0 || dest.empty()) // can't add any
  182. +        {
  183. +            // -- TODO: Send to mailbox if no space
  184. +            ChatHandler(this).PSendSysMessage("You don't have any space in your bags for a token.");
  185. +            return true;
  186. +        }
  187. +
  188. +        Item* item = StoreNewItem(dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
  189. +        SendNewItem(item,count,true,false);
  190. +        ChatHandler(this).PSendSysMessage("You have been awarded a token for slaying another player.");
  191. +        ModifyHonorPoints(-1000);
  192. +    }
  193.  
  194.     return true;
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement