Esempio n. 1
0
bool Player::UpdateStats(Stats stat)
{
    if(stat > STAT_SPIRIT)
        return false;

    // value = ((base_value * base_pct) + total_value) * total_pct
    float value  = GetTotalStatValue(stat);

    SetStat(stat, int32(value));

    //DK ghoul benefit from owner strength
	if(stat == STAT_STAMINA || stat == STAT_INTELLECT || stat == STAT_STRENGTH)
    {
        Pet *pet = GetPet();
        if(pet)
		{
            pet->UpdateStats(stat);
			if (getClass() == CLASS_DEATH_KNIGHT && pet->getPetType() == SUMMON_PET)
            {
                pet->RemoveAllAuras();
                pet->CastPetAuras(true);
			}
		}
	}

    switch(stat)
    {
        case STAT_STRENGTH:
            UpdateShieldBlockValue();
            break;
        case STAT_AGILITY:
            UpdateArmor();
            UpdateAllCritPercentages();
            UpdateDodgePercentage();
            break;
        case STAT_STAMINA:   UpdateMaxHealth(); break;
        case STAT_INTELLECT:
            UpdateMaxPower(POWER_MANA);
            UpdateAllSpellCritChances();
            UpdateArmor();                                  //SPELL_AURA_MOD_RESISTANCE_OF_INTELLECT_PERCENT, only armor currently
            break;

        case STAT_SPIRIT:
            break;

        default:
            break;
    }
    // Need update (exist AP from stat auras)
    UpdateAttackPowerAndDamage();
    UpdateAttackPowerAndDamage(true);

    UpdateSpellDamageAndHealingBonus();
    UpdateManaRegen();

    // Update ratings in exist SPELL_AURA_MOD_RATING_FROM_STAT and only depends from stat
    uint32 mask = 0;
    AuraList const& modRatingFromStat = GetAurasByType(SPELL_AURA_MOD_RATING_FROM_STAT);
    for(AuraList::const_iterator i = modRatingFromStat.begin();i != modRatingFromStat.end(); ++i)
        if (Stats((*i)->GetMiscBValue()) == stat)
            mask |= (*i)->GetMiscValue();
    if (mask)
    {
        for (uint32 rating = 0; rating < MAX_COMBAT_RATING; ++rating)
            if (mask & (1 << rating))
                ApplyRatingMod(CombatRating(rating), 0, true);
    }
    return true;
}
Esempio n. 2
0
void WorldSession::HandleLoadPetFromDBSecondCallback(LoadPetFromDBQueryHolder* holder)
{
	if (!GetPlayer())
        return;

	Player* owner = GetPlayer();
	Pet* pet = owner->GetPet();
	if (!pet)
		return;

	pet->_LoadAuras(holder->GetPreparedResult(PET_LOAD_QUERY_LOADAURAS), holder->GetDiffTime());
	bool current = holder->GetCurrent();
	uint32 summon_spell_id = pet->GetUInt32Value(UNIT_CREATED_BY_SPELL);
    SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(summon_spell_id); // CANT BE NULL
    bool is_temporary_summoned = spellInfo && spellInfo->GetDuration() > 0;

    // load action bar, if data broken will fill later by default spells.
    if (!is_temporary_summoned)
    {
        pet->_LoadSpells(holder->GetPreparedResult(PET_LOAD_QUERY_LOADSPELLS));
        pet->InitTalentForLevel();                               // re-init to check talent count
        pet->_LoadSpellCooldowns(holder->GetPreparedResult(PET_LOAD_QUERY_LOADSPELLCOOLDOWN));
        pet->LearnPetPassives();
        pet->InitLevelupSpellsForLevel();
        pet->CastPetAuras(current);

		pet->GetCharmInfo()->LoadPetActionBar(holder->GetActionBar()); // action bar stored in already read string
    }

    pet->CleanupActionBar();                                     // remove unknown spells from action bar after load
    owner->PetSpellInitialize();
    owner->SendTalentsInfoData(true);
    if (owner->GetGroup())
        owner->SetGroupUpdateFlag(GROUP_UPDATE_PET);

    //set last used pet number (for use in BG's)
    if (owner->GetTypeId() == TYPEID_PLAYER && pet->isControlled() && !pet->isTemporarySummoned() && (pet->getPetType() == SUMMON_PET || pet->getPetType() == HUNTER_PET))
	{
        owner->ToPlayer()->SetLastPetNumber(holder->GetPetNumber());
		owner->SetLastPetSpell(pet->GetUInt32Value(UNIT_CREATED_BY_SPELL));
	}

    if (pet->getPetType() == SUMMON_PET && !current)              //all (?) summon pets come with full health when called, but not when they are current
	{
        pet->SetPower(POWER_MANA, pet->GetMaxPower(POWER_MANA));
		pet->SetHealth(pet->GetMaxHealth());
	}
    else
    {
        if (!holder->GetSavedHealth() && pet->getPetType() == HUNTER_PET && pet->GetAsynchLoadType() != PET_LOAD_SUMMON_DEAD_PET)
            pet->setDeathState(JUST_DIED);
        else
        {
            pet->SetHealth(holder->GetSavedHealth() > pet->GetMaxHealth() ? pet->GetMaxHealth() : holder->GetSavedHealth());
            pet->SetPower(POWER_MANA, holder->GetSavedMana() > pet->GetMaxPower(POWER_MANA) ? pet->GetMaxPower(POWER_MANA) : holder->GetSavedMana());
        }
    }

	pet->SetLoading(false);
	owner->SetTemporaryUnsummonedPetNumber(0); // clear this only if pet is loaded successfuly

	// current
	if (current && owner->IsPetNeedBeTemporaryUnsummoned())
	{
        owner->UnsummonPetTemporaryIfAny();
		return;
	}

	pet->HandleAsynchLoadSucceed();
	return;
}