All pastes #399650 Raw Edit

Untitled

public text v1 · immutable
·published 2007-03-18 03:48 UTC
rendered paste body
Index: src/game/Formulas.h
===================================================================
--- src/game/Formulas.h    (revision 3337)
+++ src/game/Formulas.h    (working copy)
@@ -72,19 +72,42 @@
         // then when player save, save it!!!
         inline float HonorableKillPoints( Player *killer, Player *victim )
         {
-            int total_kills  = killer->CalculateTotalKills(victim);
-            //int k_rank       = killer->CalculateHonorRank( killer->GetTotalHonor() );
-            uint32 v_rank    = victim->CalculateHonorRank( victim->GetTotalHonor() );
-            uint32 k_level   = killer->getLevel();
-            //int v_level      = victim->getLevel();
-            float diff_honor = (victim->GetTotalHonor() /(killer->GetTotalHonor()+1))+1;
-            float diff_level = (victim->getLevel()*(1.0/( killer->getLevel() )));
+            //New formulas by Zhivoi (Greetings from Russia)
+            int total_kills = killer->CalculateTotalKills(victim);
+            float f;
+            if(total_kills < 10) f = (10 - (float)total_kills)*0.1;
+            else f = 0.0;
+            
+            uint32 k_grey = 0;
+            uint32 k_level = killer->getLevel();
+            uint32 v_level = victim->getLevel();
+            
+            if(k_level <= 5)
+                 k_grey = 0;
+            else if( k_level <= 39 )
+                k_grey = k_level - 5 - k_level/10;
+            else
+                k_grey = k_level - 1 - k_level/5;
+            
+            float diff_level;
+            if((k_level - k_grey) != 0)
+                diff_level = ((float)(v_level - k_grey)) / ((float)(k_level - k_grey));
+            else return 999;    //Check, in character_kill we will see, if working incorrectly
+            
+            if(diff_level > 2.0) diff_level = 2.0;
+            if(diff_level <= 0.0) return 888; //For Debug
+            
+            int32 v_rank = (victim->GetHonorRank() - 4); //We cut all up to the first positive rank
+            if(v_rank < 0) v_rank = 0;
+            if(v_rank < 0) return 777;

-            int f = (4 - total_kills) >= 0 ? (4 - total_kills) : 0;
-            int honor_points = int(((float)(f * 0.25)*(float)((k_level+(v_rank*5+1))*(1+0.05*diff_honor)*diff_level)));
-            return (honor_points <= 400 ? honor_points : 400);
+            float honor_points = f * diff_level * (190 + v_rank*10);
+            //float honor_points = f * diff_level * (190);
+            honor_points *= ((float)k_level) / 60.0; //factor of dependence on levels of the killer
+
+            if(honor_points > 660) return 666; //For Debug
+            else return honor_points;
         }
-
     }

     namespace Combat
Index: src/game/Level0.cpp
===================================================================
--- src/game/Level0.cpp    (revision 3337)
+++ src/game/Level0.cpp    (working copy)
@@ -214,7 +214,7 @@
{
     uint32 dishonorable_kills       = m_session->GetPlayer()->GetUInt32Value(PLAYER_FIELD_LIFETIME_DISHONORABLE_KILLS);
     uint32 honorable_kills          = m_session->GetPlayer()->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS);
-    uint32 highest_rank             = (m_session->GetPlayer()->GetHonorHighestRank() < 16)? m_session->GetPlayer()->GetHonorHighestRank() : 0;
+    uint32 highest_rank             = (m_session->GetPlayer()->GetHonorHighestRank() > 4) ? m_session->GetPlayer()->GetHonorHighestRank() - 4 : 0;
     uint32 today_honorable_kills    = (uint16)m_session->GetPlayer()->GetUInt32Value(PLAYER_FIELD_SESSION_KILLS);
     uint32 today_dishonorable_kills = (uint16)(m_session->GetPlayer()->GetUInt32Value(PLAYER_FIELD_SESSION_KILLS)>>16);
     uint32 yesterday_kills          = m_session->GetPlayer()->GetUInt32Value(PLAYER_FIELD_YESTERDAY_KILLS);
@@ -268,13 +268,17 @@

     if ( m_session->GetPlayer()->GetTeam() == ALLIANCE )
     {
-        rank_name = alliance_ranks[ m_session->GetPlayer()->CalculateHonorRank( m_session->GetPlayer()->GetTotalHonor() ) ];
+        if (m_session->GetPlayer()->CalculateHonorRank(m_session->GetPlayer()->GetTotalHonor()) > 4)
+            rank_name = alliance_ranks[ m_session->GetPlayer()->CalculateHonorRank( m_session->GetPlayer()->GetTotalHonor() ) - 4 ];
+        else rank_name = alliance_ranks[0];
         hrank_name = alliance_ranks[ highest_rank ];
     }
     else
     if ( m_session->GetPlayer()->GetTeam() == HORDE )
     {
-        rank_name = horde_ranks[ m_session->GetPlayer()->CalculateHonorRank( m_session->GetPlayer()->GetTotalHonor() ) ];
+        if (m_session->GetPlayer()->CalculateHonorRank(m_session->GetPlayer()->GetTotalHonor()) > 4)
+            rank_name = horde_ranks[ m_session->GetPlayer()->CalculateHonorRank( m_session->GetPlayer()->GetTotalHonor() ) - 4 ];
+        else rank_name = horde_ranks[0];
         hrank_name = horde_ranks[ highest_rank ];
     }
     else
@@ -282,7 +286,8 @@
         rank_name = LANG_NO_RANK;
     }

-    PSendSysMessage(LANG_RANK, rank_name.c_str(), m_session->GetPlayer()->GetName(), m_session->GetPlayer()->CalculateHonorRank( m_session->GetPlayer()->GetTotalHonor() ));
+    PSendSysMessage(LANG_RANK, rank_name.c_str(), m_session->GetPlayer()->GetName(),
+        (m_session->GetPlayer()->CalculateHonorRank( m_session->GetPlayer()->GetTotalHonor() ) > 4)?m_session->GetPlayer()->CalculateHonorRank( m_session->GetPlayer()->GetTotalHonor() ) - 4 : 0);
     PSendSysMessage(LANG_HONOR_TODAY, today_honorable_kills, today_dishonorable_kills);
     PSendSysMessage(LANG_HONOR_YESTERDAY, yesterday_kills, yesterday_honor);
     PSendSysMessage(LANG_HONOR_THIS_WEEK, this_week_kills, this_week_honor);
Index: src/game/Player.cpp
===================================================================
--- src/game/Player.cpp    (revision 3337)
+++ src/game/Player.cpp    (working copy)
@@ -4150,18 +4150,21 @@
     uint32 thisWeekKills = 0;
     uint32 lastWeekKills = 0;

-    float total_honor = 0;
-    float yesterdayHonor = 0;
-    float thisWeekHonor = 0;
-    float lastWeekHonor = 0;
+    float total_honor = 0.0;
+    float yesterdayHonor = 0.0;
+    float thisWeekHonor = 0.0;
+    float lastWeekHonor = 0.0;
+    float total_last_weekend_honor = 0.0; //Total honor (until last weekend)

+
     time( &rawtime );
     now = localtime( &rawtime );

     today = ((uint32)(now->tm_year << 16)|(uint32)(now->tm_yday));

     Yesterday     = today - 1;
-    ThisWeekBegin = today - now->tm_wday;
+    ThisWeekBegin = today - (now->tm_wday - 3);
+    if(ThisWeekBegin > today) ThisWeekBegin -= 7;
     ThisWeekEnd   = ThisWeekBegin + 7;
     LastWeekBegin = ThisWeekBegin - 7;
     LastWeekEnd   = LastWeekBegin + 7;
@@ -4180,7 +4183,7 @@
             if(fields[0].GetUInt32() == HONORABLE_KILL)
             {
                 lifetime_honorableKills++;
-                //total_honor += fields[1].GetFloat();
+                total_honor += fields[1].GetFloat();

                 if( date == today)
                 {
@@ -4205,14 +4208,17 @@
                 //All honor points until last week
                 if( date < LastWeekEnd )
                 {
-                    total_honor += fields[1].GetFloat();
+                    total_last_weekend_honor += fields[1].GetFloat();
                 }

             }
             else if(fields[0].GetUInt32() == DISHONORABLE_KILL)
             {
                 lifetime_dishonorableKills++;
-                //total_honor -= fields[1].GetFloat();
+                total_honor -= fields[1].GetFloat();
+                
+                if(total_honor < -2500.0) total_honor = -2500.0;
+                if(total_honor > 64999.0) total_honor = 64999.0;

                 if( date == today)
                 {
@@ -4222,7 +4228,8 @@
                 //All honor points until last week
                 if( date < LastWeekEnd )
                 {
-                    total_honor -= fields[1].GetFloat();
+                    total_last_weekend_honor -= fields[1].GetFloat();
+                    if(total_last_weekend_honor < -2500.0) total_last_weekend_honor = -2500.0;
                 }
             }
         }
@@ -4231,14 +4238,15 @@
         delete result;
     }

-    //Store Total Honor points...
+    //Store Total Honor points...
     SetTotalHonor(total_honor);
+    SetWeekEndHonor(total_last_weekend_honor);

     //RIGHEST RANK
     //If the new rank is highest then the old one, then m_highest_rank is updated
-    if( CalculateHonorRank(total_honor) > GetHonorHighestRank() )
+    if( CalculateHonorRank(total_last_weekend_honor) > GetHonorHighestRank() )
     {
-        SetHonorHighestRank( CalculateHonorRank(total_honor) );
+        SetHonorHighestRank( CalculateHonorRank(total_last_weekend_honor) );
     }

     //RATING
@@ -4247,16 +4255,28 @@
     //STANDING
     SetHonorLastWeekStanding( MaNGOS::Honor::CalculeStanding(this) );

-    //TODO Fix next rank bar... it is not working fine! For while it be set with the total honor points...
     //NEXT RANK BAR
     //PLAYER_FIELD_HONOR_BAR
-    SetUInt32Value(PLAYER_FIELD_BYTES2, (uint32)( (total_honor < 0) ? 0: total_honor) );
+//    SetUInt32Value(PLAYER_FIELD_BYTES2, (uint32)( (total_honor < 0) ? 0: total_honor) );

-    //RANK (Patent)
-    if( CalculateHonorRank(total_honor) )
-        SetUInt32Value(PLAYER_BYTES_3, (( CalculateHonorRank(total_honor) << 24) + 0x04000000) + (m_drunk & 0xFFFE) + getGender());
-    else
-        SetUInt32Value(PLAYER_BYTES_3, (m_drunk & 0xFFFE) + getGender());
+    if( total_honor <= 0.00 )
+    {
+        SetUInt32Value(PLAYER_FIELD_BYTES2, 0 );
+    }
+    else
+    {
+        float honor_bar;
+        if( total_honor <= 2000 )
+            honor_bar = total_honor * 0.1275;
+        else if( total_honor <= 5000 )
+            honor_bar = (total_honor-2000) * 0.085;
+        else
+            honor_bar = ( (uint32)total_honor % 5000) * 0.051;
+        
+        SetUInt32Value(PLAYER_FIELD_BYTES2, (uint32)honor_bar );
+    }
+    //RANK
+        SetUInt32Value(PLAYER_BYTES_3, (CalculateHonorRank(total_last_weekend_honor) << 24) + (m_drunk & 0xFFFE) + getGender());

     //TODAY
     SetUInt32Value(PLAYER_FIELD_SESSION_KILLS, (today_dishonorableKills << 16) + today_honorableKills );
@@ -4272,7 +4292,6 @@
     SetUInt32Value(PLAYER_FIELD_LAST_WEEK_RANK, GetHonorLastWeekStanding());

     //LIFE TIME
-    SetUInt32Value(PLAYER_FIELD_SESSION_KILLS, (lifetime_dishonorableKills << 16) + lifetime_honorableKills );
     SetUInt32Value(PLAYER_FIELD_LIFETIME_DISHONORABLE_KILLS, lifetime_dishonorableKills);
     SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS, lifetime_honorableKills);
     //TODO: Into what field we need to set it? Fix it!
@@ -4281,19 +4300,21 @@

uint32 Player::GetHonorRank() const
{
-    return CalculateHonorRank(m_total_honor_points);
+    return CalculateHonorRank(m_honor_points_lastweek);
}

-//What is Player's rank... private, scout...
+//What is Player's rank
uint32 Player::CalculateHonorRank(float honor_points) const
{
-    int rank = 0;
-
-    if(honor_points <=    0.00) rank = 0; else
-        if(honor_points <  2000.00) rank = 1;
+    uint32 rank = 0;
+    if        (honor_points <= -2000.0) rank = 1;    // Pariah (-4)
+    else if    (honor_points <= -1000.0) rank = 2;    // Outlaw (-3)
+    else if    (honor_points <= -500.0) rank = 3;    // Exiled (-2)
+    else if    (honor_points < 0.0) rank = 4;        // Dishonored (-1)
+    else if    (honor_points == 0.0) rank = 0;        // No rank (0)
+    else if    (honor_points <= 2000.0) rank = 5;    // First rank
     else
-        rank = ( (int)(honor_points / 5000) + 1);
-
+            rank = ((int)(honor_points / 5000) + 6);
     return rank;
}

@@ -4301,9 +4322,16 @@
int Player::CalculateTotalKills(Player *pVictim) const
{
     int total_kills = 0;
-
-    QueryResult *result = sDatabase.PQuery("SELECT count(*) as cnt FROM `character_kill` WHERE `guid` = '%u' AND `creature_template` = '%u'", GetGUIDLow(), pVictim->GetEntry());
-
+    
+    //Change GetEntry to GetGUIDLow for Victim & Added Today kills (from wowwiki)
+    time_t rawtime;
+    struct tm * now;
+    uint32 today = 0;
+    time( &rawtime );
+    now = localtime( &rawtime );
+    today = ((uint32)(now->tm_year << 16)|(uint32)(now->tm_yday));
+    //QueryResult *result = sDatabase.PQuery("SELECT `honor` FROM `character_kill` WHERE `guid` = '%u' AND `creature_template` = '%u' AND `date` = '%u'", GetGUIDLow(), pVictim->GetGUIDLow(), (uint32)today);
+    QueryResult *result = sDatabase.PQuery("SELECT count(*) as cnt FROM `character_kill` WHERE `guid` = '%u' AND `creature_template` = '%u' AND `date` = '%u'", GetGUIDLow(), pVictim->GetGUIDLow(), (uint32)today);
     if(result)
     {
         Field *fields = result->Fetch();
@@ -4314,7 +4342,7 @@
}

//How much honor Player gains/loses killing uVictim
-void Player::CalculateHonor(Unit *uVictim)
+void Player::CalculateHonor(Unit *uVictim, float honor_mn)
{
     float parcial_honor_points = 0;
     int kill_type = 0;
@@ -4328,10 +4356,27 @@
     if( uVictim->GetTypeId() == TYPEID_UNIT )
     {
         Creature *cVictim = (Creature *)uVictim;
-        if( cVictim->isCivilian() )
+        int32 pl_grey = 0;
+        int32 pl_level = getLevel();
+        if( pl_level <= 5 )
+            pl_grey = 0;
+        else if( pl_level <= 39 )
+            pl_grey = pl_level - 5 - pl_level/10;
+        else
+            pl_grey = pl_level - 1 - pl_level/5;
+        if((cVictim->isCivilian()) && (cVictim->getLevel() < pl_grey))
         {
             parcial_honor_points = MaNGOS::Honor::DishonorableKillPoints( getLevel() );
             kill_type = DISHONORABLE_KILL;
+///*******************************************ADDED For "Flying away DK"
+            WorldPacket data;
+            data.Initialize(SMSG_PVP_CREDIT);
+            data << (uint32) 0; // honor points    
+            data << (uint64) cVictim->GetGUID(); // guid civilian victim
+            //uint32 v_rank  = cVictim->GetHonorRank();
+            //data << (uint32) (v_rank);
+            this->GetSession()->SendPacket(&data);
+///*******************************************END
             savekill = true;
         }
     }
@@ -4341,15 +4386,34 @@
         Player *pVictim = (Player *)uVictim;

         if( GetTeam() == pVictim->GetTeam() ) return;
-
-        if( getLevel() < (pVictim->getLevel()+5) )
+        //Gray Level
+        int32 pl_grey = 0;
+        int32 pl_level = getLevel();
+        if( pl_level <= 5 )
+                 pl_grey = 0;
+            else if( pl_level <= 39 )
+                pl_grey = pl_level - 5 - pl_level/10;
+            else
+                pl_grey = pl_level - 1 - pl_level/5;
+        if( pVictim->getLevel() > pl_grey )
         {
             parcial_honor_points = MaNGOS::Honor::HonorableKillPoints( this, pVictim );
+            parcial_honor_points *= honor_mn;
             kill_type = HONORABLE_KILL;
+///*******************************************ADDED For "Flying away rank"
+            WorldPacket data;
+            data.Initialize(SMSG_PVP_CREDIT);
+            data << (uint32) parcial_honor_points; // honor points    
+            // If guid=0, in combatlog: You have been awarded %u honor points.
+            // If guid != 0, in combatlog - player_name dies, honorable kill Rank: rank_name (Estimated Honor Points: %u)
+            data << (uint64) pVictim->GetGUID(); // guid victim
+            uint32 v_rank  = pVictim->GetHonorRank();
+            data << (uint32) (v_rank);
+            this->GetSession()->SendPacket(&data);
+///*******************************************END
             savekill = true;
         }
     }
-
     if (savekill)
     {
         time_t rawtime;
@@ -4359,8 +4423,8 @@
         now = localtime( &rawtime );
         today = ((uint32)(now->tm_year << 16)|(uint32)(now->tm_yday));

-        sDatabase.PExecute("INSERT INTO `character_kill` (`guid`,`creature_template`,`honor`,`date`,`type`) VALUES (%u, %u, %f, %u, %u)", (uint32)GetGUIDLow(), (uint32)uVictim->GetEntry(), (float)parcial_honor_points, (uint32)today, (uint8)kill_type);
-
+        // Change GetEntry to GetGUIDLow for Victim
+        sDatabase.PExecute("INSERT INTO `character_kill` (`guid`,`creature_template`,`honor`,`date`,`type`) VALUES (%u, %u, %f, %u, %u)", (uint32)GetGUIDLow(), (uint32)uVictim->GetGUIDLow(), (float)parcial_honor_points, (uint32)today, (uint8)kill_type);
         UpdateHonor();
     }
}
@@ -6998,7 +7062,7 @@
         }
         if( pProto->RequiredSpell != 0 && !HasSpell( pProto->RequiredSpell ) )
             return false;
-        if( GetHonorRank() < pProto->RequiredHonorRank )
+        if( GetHonorHighestRank() < pProto->RequiredHonorRank ) //Change to Highest Rank ( Old GetHonorRank() )
             return false;
         if( getLevel() < pProto->RequiredLevel )
             return false;
@@ -7030,7 +7094,7 @@
         }
         if( pProto->RequiredSpell != 0 && !HasSpell( pProto->RequiredSpell ) )
             return EQUIP_ERR_NO_REQUIRED_PROFICIENCY;
-        if( GetHonorRank() < pProto->RequiredHonorRank )
+        if( GetHonorHighestRank() < pProto->RequiredHonorRank ) //Change to Highest Rank ( Old GetHonorRank() )
             return EQUIP_ITEM_RANK_NOT_ENOUGH;
         /*if( GetReputation() < pProto->RequiredReputation )
         return EQUIP_ITEM_REPUTATION_NOT_ENOUGH;
Index: src/game/Player.h
===================================================================
--- src/game/Player.h    (revision 3337)
+++ src/game/Player.h    (working copy)
@@ -1079,13 +1079,17 @@
         /***                  HONOR SYSTEM                     ***/
         /*********************************************************/
         void UpdateHonor();
-        void CalculateHonor(Unit *pVictim);
+//        void CalculateHonor(Unit *pVictim); //Changed for GroupHonor
+        void CalculateHonor(Unit *pVictim, float); //Changed for GroupHonor
         uint32 CalculateHonorRank(float honor) const;
         uint32 GetHonorRank() const;
         int  CalculateTotalKills(Player *pVictim) const;
         //Acessors of total honor points
         void SetTotalHonor(float total_honor_points) { m_total_honor_points = total_honor_points; };
         float GetTotalHonor(void) const { return m_total_honor_points; };
+        void SetWeekEndHonor(float total_week_honor_points) { m_honor_points_lastweek = total_week_honor_points; };
+        float GetWeekEndHonor(void) const { return m_honor_points_lastweek; };
+
         //Acessors of righest rank
         uint32 GetHonorHighestRank() const { return m_highest_rank; }
         void SetHonorHighestRank(uint32 hr) { m_highest_rank = hr; }
@@ -1338,6 +1342,9 @@
         std::deque<uint32> m_TaxiDestinations;

         float m_total_honor_points;
+        //Added by Zhivoi
+        float m_honor_points_lastweek; //For calculate rang
+
         float m_rating;
         uint32 m_highest_rank;
         int32 m_standing;
Index: src/game/Unit.cpp
===================================================================
--- src/game/Unit.cpp    (revision 3337)
+++ src/game/Unit.cpp    (working copy)
@@ -416,13 +416,13 @@
         if(player)
         {
             float honordiff = player->GetTotalHonor();
-            player->CalculateHonor(pVictim);
             honordiff -= player->GetTotalHonor();

             player->CalculateReputation(pVictim);

             if(!PvP)
             {
+                player->CalculateHonor(pVictim,1.0); //Civilian
                 DEBUG_LOG("DealDamageIsPvE");
                 uint32 xp = MaNGOS::XP::Gain(player, pVictim);

@@ -463,6 +463,64 @@
                 if(xp || honordiff < 0)
                     ProcDamageAndSpell(pVictim,PROC_FLAG_KILL_XP_GIVER,PROC_FLAG_NONE);
             } // if (!PvP)
+            ///// HONOR PARTY
+            else
+            {
+                Group *pGroup = player->groupInfo.group;
+                if(pGroup)
+                {
+                    uint32 party_level = 0; //party level
+                    uint32 party_grey = 0;    //party grey level
+                    int32 party_membcount = pGroup->GetMembersCount(); //Members
+
+                    for (uint32 i = 0; i < pGroup->GetMembersCount(); i++)
+                    {
+                        Player *pGroupGuy = objmgr.GetPlayer(pGroup->GetMemberGUID(i));
+                        if(    (!pGroupGuy) ||    //Player
+                            (pVictim->GetDistanceSq(pGroupGuy) > sWorld.getConfig(CONFIG_GROUP_XP_DISTANCE)) || //Distance
+                            (!pGroupGuy->isAlive()) )    //Died
+                        {
+                            party_membcount-=1;
+                            continue;
+                        }
+                        //We take only alive players, which beside
+                        if(i+1) //check =)
+                            party_level=(uint32)((float)((party_level*i)+pGroupGuy->getLevel()))/((float)(i+1));
+                        else pGroupGuy->CalculateHonor(pVictim,10.0);    //FOR DEBUG
+                    }
+
+                    if( party_level <= 10 )
+                        party_grey = 0;
+                    else party_grey = party_level * 0.9;
+                    
+                    for (uint32 i = 0; i < pGroup->GetMembersCount(); i++)
+                    {
+                        Player *pGroupGuy = objmgr.GetPlayer(pGroup->GetMemberGUID(i));
+                        if(!pGroupGuy) //No Player
+                        {
+                            continue;
+                        }
+                        if(pVictim->GetDistanceSq(pGroupGuy) > sWorld.getConfig(CONFIG_GROUP_XP_DISTANCE)) //Distance too greater
+                        {
+                            continue;
+                        }
+                        if(!pGroupGuy->isAlive()) //Player has died
+                        {
+                            continue;
+                        }
+                        //if all cheks passed - give honor for this player
+                        if(pGroupGuy->getLevel() > party_grey)
+                        {
+                            if(party_membcount<1) party_membcount=1;
+                            pGroupGuy->CalculateHonor(pVictim,(float)(1.0/((float)party_membcount)));
+                        }
+                    }
+                }
+                else //No Group
+                {
+                    player->CalculateHonor(pVictim,1.0);
+                }
+            }
         }
         else // if (player)
         {
Index: src/game/WorldSession.cpp
===================================================================
--- src/game/WorldSession.cpp    (revision 3337)
+++ src/game/WorldSession.cpp    (working copy)
@@ -185,7 +185,7 @@
             }
             // give honor to all attackers from set
             for(std::set<Player*>::const_iterator itr = aset.begin(); itr != aset.end(); ++itr)
-                (*itr)->CalculateHonor(_player);
+                (*itr)->CalculateHonor(_player,1.0);
         }

         ///- Reset the online field in the account table