Pets benefit from owner's haste rating

Yo guys, i’m trying to fix the issue of DK’s gargoyles not benefiting from the owner’s haste. i think i’m on the right way but i need a little help /emoticons/default_tongue.png

First at all, since i’m a newb on trinity i said to myself “kay, first i need an code example of how a pet get a rating benefit from his owner” so i searched for the resilence benefit code /emoticons/default_biggrin.png

having already read, i tried to do something similar, and that’s what i did:

[SPOILER]
/emoticons/default_biggrin.png

  •    if (Unit* owner = GetOwner())
    
  •        if (owner->GetTypeId() == TYPEID_PLAYER)
    
  •            return ((Player*)owner)->GetRatingBonusValue(cr);
    
  • }

  • return 0.0f;

+}

uint32 Unit::GetCombatRatingDamageReduction(CombatRating cr, float rate, float cap, uint32 damage) const

{

 float percent = std::min(GetCombatRatingReduction(cr) * rate, cap);

[CODE]diff -r d7a5acaa4c45 src/server/game/Entities/Unit/Unit.cpp

— a/src/server/game/Entities/Unit/Unit.cpp Thu Apr 28 18:49:05 2011 -0300

+++ b/src/server/game/Entities/Unit/Unit.cpp Mon May 02 21:15:58 2011 -0300

@@ -16437,6 +16441,21 @@

 return 0.0f;

}

+float Unit::GetCombatRatingBonusFromOwner(CombatRating cr) const

+{

  • if (GetTypeId() == TYPEID_PLAYER)

  •    return ((Player const*)this)->GetRatingBonusValue(cr);
    
  • else if (((Creature const*)this)->isPet())

  • {

  •    // Gargoyle Should get 100% benefit from owner haste [/CODE][/SPOILER]
    

/emoticons/default_biggrin.png

  •   float GetHasteBonusMelee() const {return GetCombatRatingBonusFromOwner(CR_HASTE_MELEE); }
    
  •   float GetHasteBonusRanged() const {return GetCombatRatingBonusFromOwner(CR_HASTE_RANGED); }
    
  •   float GetHasteBonusSpell() const {return GetCombatRatingBonusFromOwner(CR_HASTE_SPELL); }
    
    
       // player or player's pet resilience (-1%)
    
       float GetMeleeCritChanceReduction() const { return GetCombatRatingReduction(CR_CRIT_TAKEN_MELEE); }
    

@@ -2084,6 +2088,7 @@

     bool HandleAuraRaidProcFromCharge(AuraEffect* triggeredByAura);


     // player or player's pet
  •   float GetCombatRatingBonusFromOwner(CombatRating cr) const;
    
       float GetCombatRatingReduction(CombatRating cr) const;
    
       uint32 GetCombatRatingDamageReduction(CombatRating cr, float rate, float cap, uint32 damage) const;
    

[CODE]diff -r d7a5acaa4c45 src/server/game/Entities/Unit/Unit.h

— a/src/server/game/Entities/Unit/Unit.h Thu Apr 28 18:49:05 2011 -0300

+++ b/src/server/game/Entities/Unit/Unit.h Mon May 02 21:15:58 2011 -0300

@@ -1300,6 +1300,10 @@

     void CalculateSpellDamageTaken(SpellNonMeleeDamage *damageInfo, int32 damage, SpellEntry const *spellInfo, WeaponAttackType attackType = BASE_ATTACK, bool crit = false);

     void DealSpellDamage(SpellNonMeleeDamage *damageInfo, bool durabilityLoss);
  •   // Hehe, Haste bonus from player [/CODE]
    

Sounds like i’m in the right way, but there’s still something missing, because the gargoyle isn’t getting any benefit from the owners haste even after that /emoticons/default_tongue.png

Srry for the bad english.

Use brackets in all code, better to use brackets everywhere then skipping it, after that you add some debug lines that write something on the screen, using sLog (or what it’s called on trinitycore) anyways you are close, the base idea is correct and i cba to clone tc2 and check it out myself /emoticons/default_tongue.png

Soooo, yeah, this is all fun guys but, any other idea on the code i posted above? /emoticons/default_ohmy.png

I did some more research and found this old rev the devs used to update the resilience to 3.3 standarts, i’ve checked it to see if i didn’t forgot to code the haste benefit on SpellAuraEffects or somewhere else but that i got was a headache >.>

Maybe something like this:


if (GetTpeID() == TYPEID_PLAYER)

{

	return ToPlayer()->GetRatingBonusValue(cr);

}

else

{

	if (GetTypeID() == TYPEID_UNIT && isPet())

	{

		if (GetCharmerOrOwner()->GetTypeId() == TYPEID_PLAYER)

		{

			return GetCharmerOrOwner()->ToPlayer()->GetRatingBonusValue(cr);

		}

	}

}


sLog->outStaticDebug("GetCombatRatingBonusFromOwner() returned 0.0")

return 0.0f;

Since they added ToPlayer(), ToPet(), ToPrettyMuchAnything(), you don’t need to do all the casting

like: ((Player const*)this)->GetRatingBonusValue(cr)

Maybe you’re not getting a bonus though because the bonus doesn’t exist? Have you debugged to see

if the haste bonus is being applied correctly to the Player before trying to give it to the pet?

Fuck da police!

Seriously, stop flaming.

  • Removed some posts.

my post wasnt flaming /emoticons/default_sad.png

Since they added ToPlayer(), ToPet(), ToPrettyMuchAnything(), you don’t need to do all the casting

like: ((Player const*)this)->GetRatingBonusValue(cr)

Maybe you’re not getting a bonus though because the bonus doesn’t exist? Have you debugged to see

if the haste bonus is being applied correctly to the Player before trying to give it to the pet?

[/SPOILER]
What do you mean by “debug” in this case? i have a debug solution here that i use when the server crash by any reason, but i dont know how to use it to see “all that is happening in the core” (i think people call it “create a core dump file”) and if the haste bonus is being correctly applied to the player/pet

Thank you alot, this brings piece to the topic again /emoticons/default_smile.png

Kay, did a little more research and found out that the function i’ve made is not being called at all /emoticons/default_ohmy.png, i put two sLogs on the function but none of them showed up in the core log.

/emoticons/default_biggrin.png

    if (Unit* owner = GetOwner())

	{

        if (owner->GetTypeId() == TYPEID_PLAYER)

		{

            return ((Player*)owner)->GetRatingBonusValue(cr);

			sLog->outStaticDebug("GetCombatRatingBonusFromOwner() returned positive value");

		}

	}

}

sLog->outStaticDebug("GetCombatRatingBonusFromOwner() returned 0.0");

return 0.0f;

}

[CODE]float Unit::GetCombatRatingBonusFromOwner(CombatRating cr) const

{

if (GetTypeId() == TYPEID_PLAYER)

{

    return ((Player const*)this)->GetRatingBonusValue(cr);

}

else if (((Creature const*)this)->isPet() || isSummon() || isGuardian())

{

    // Gargoyle Should get 100% benefit from owner haste [/CODE]

So i guess since the function is defined here, i must make a call for it inside the function that control/update the pets stats? (maybe somewhere in statsystem.cpp ou pet.cpp?)

There is a function in the Pet class that sets the pet’s stats, I don’t remember the name at the moment

but you’d probably want to stick a call to your function in there.

Also, by “debug” I was referring to:

  1. Compile a DEBUG build of the core

  2. Set a breakpoint on your function in Visual Studio

  3. Start the core

  4. In Visual Studio choose “Debug->Attach To Process”, pick the worldserver.exe

If you do this while the core is loading, when you log a character in that has a pet, if your function

is called the breakpoint will halt the core so you can step through and see what’s happening.

Just make sure you copy the *.pdb files with the debug build since they contain the symbols that VS

needs to make sense of everything.

Did what you said, and the debug caught nothing about the function i’ve made, i also “double checked” if i was doing everything right by seting breakpoints in other functions, and the debug caught them >.>

looks like i must implement a new Guardian function on statsystem.cpp calling the GetRatngBonusFromOwner for this to work >.>

Indeed, sounds like nothing’s calling your function.

You might want to look at putting a call to your function in Statsystem.cpp at the end

of Guardian::UpdateStats() since this gets called from Player::UpdateStats() so you’d

be sure to get modified pet stats everytime the player’s stats change.

Where exactly in Pet::UpdateStats() you should call it is up to you. Putting it at the

end will allow the Pet’s base stats to change first and then your function modifies it

further.