Example #1
0
void Pet::UpdateArmor()
{
    float value = 0.0f;
    float bonus_armor = 0.0f;
    UnitMods unitMod = UNIT_MOD_ARMOR;

    Unit *owner = GetOwner();
    // chained, use original owner instead
    if (owner && owner->GetTypeId() == TYPEID_UNIT && ((Creature*)owner)->GetEntry() == GetEntry())
        if (Unit *creator = GetCreator())
            owner = creator;

    // hunter and warlock and shaman pets gain 35% of owner's armor value
    if (owner && (getPetType() == HUNTER_PET || (getPetType() == SUMMON_PET 
        && (owner->getClass() == CLASS_WARLOCK || owner->getClass() == CLASS_SHAMAN))))
        bonus_armor = 0.35f * float(owner->GetArmor());

    value  = GetModifierValue(unitMod, BASE_VALUE);
    value *= GetModifierValue(unitMod, BASE_PCT);
    value += GetStat(STAT_AGILITY);
    value += GetModifierValue(unitMod, TOTAL_VALUE) + bonus_armor;
    value *= GetModifierValue(unitMod, TOTAL_PCT);

    SetArmor(int32(value));
}
Example #2
0
void Pet::UpdateArmor()
{
    float bonus_armor = 0.0f;
    UnitMods unitMod = UNIT_MOD_ARMOR;

    Unit* owner = GetOwner();
    // hunter and warlock pets gain 35% of owner's armor value
    if (owner && (getPetType() == HUNTER_PET || (getPetType() == SUMMON_PET && owner->getClass() == CLASS_WARLOCK)))
        bonus_armor = 0.35f * float(owner->GetArmor());

    float value = GetModifierValue(unitMod, BASE_VALUE);
    value *= GetModifierValue(unitMod, BASE_PCT);
    value += GetStat(STAT_AGILITY) * 2.0f;
    value += GetModifierValue(unitMod, TOTAL_VALUE) + bonus_armor;
    value *= GetModifierValue(unitMod, TOTAL_PCT);

    SetArmor(int32(value));
}
// is Resource heavy, do not spam or use heavily in loop
Unit *PlayerbotClassAI::FindMainTankInRaid(Player *gPlayer)
{
    // check if original main tank is still alive. No point regetting main
    // tank b/c chances are slim that it will not get reset in the middle of a fight.
    // But if main tank dies, try to find next best canidate
    if (mainTank!=NULL && mainTank->isAlive()) {
        return mainTank;
    }

    if (!gPlayer) return NULL;
    Group *pGroup = gPlayer->GetGroup();
    if (!pGroup) return NULL;
    uint64 pLeaderGuid = pGroup->GetLeaderGUID();

    Unit *pPlayer = NULL;

    // Check if set in raid
    if (pGroup->isRaidGroup())
    {
        QueryResult result = CharacterDatabase.PQuery("SELECT memberGuid FROM group_member WHERE memberFlags='%u' AND guid = '%u'",MEMBER_FLAG_MAINTANK, pGroup->GetGUID());
        if(result)
        {
            uint64 pGuid = MAKE_NEW_GUID(result->Fetch()->GetInt32(),0,HIGHGUID_PLAYER);
            pPlayer = sObjectMgr->GetPlayer(pGuid);
            if (pPlayer && pGroup->IsMember(pGuid) && pPlayer->isAlive()){
                mainTank = pPlayer;
                return pPlayer;
            }
        }
    }


    // if could not find tank try assuming
    // Assume the one with highest health is the main tank
    uint32 maxhpfound=0;
    std::list<Unit*> unitList;
    gPlayer->GetRaidMember(unitList,30);
    if (!unitList.empty()){
      for (std::list<Unit*>::iterator itr = unitList.begin() ; itr!=unitList.end();++itr) {
        //Player *tPlayer = GetPlayerBot()->GetObjPlayer((*itr)->GetGUID());
        Unit *tPlayer = sObjectMgr->GetPlayer((*itr)->GetGUID());
        if (tPlayer == NULL) continue;
        if (tPlayer->isDead()) continue;
        if (GetPlayerBot()->GetAreaId() != tPlayer->GetAreaId()) continue;
        //if(tPlayer->GetGUID() == GetPlayerBot()->GetGUID()) continue;
        if (GetPlayerBot()->GetDistance(tPlayer) > 50) continue;
        if (tPlayer->GetMaxHealth() > maxhpfound) { maxhpfound = tPlayer->GetMaxHealth(); pPlayer=tPlayer; }
        // Also check pets
        if ( (tPlayer->getClass() == (uint8) CLASS_HUNTER || tPlayer->getClass() == (uint8) CLASS_WARLOCK) && IS_PET_GUID(tPlayer->GetPetGUID()) )
        {
            Pet* tpet = ObjectAccessor::GetPet(*tPlayer, tPlayer->GetPetGUID());
            if (!tpet || !tpet->IsInWorld() || !tpet->isDead()) continue;
            if (tpet->GetArmor() > tPlayer->GetArmor()) //Probably a tanking capable pet..
            {
                if (tpet->GetMaxHealth() > maxhpfound) { maxhpfound = tpet->GetMaxHealth(); pPlayer=tpet; }
                else if (tPlayer->GetGUID() == pPlayer->GetGUID()) {pPlayer = tpet;} //set pet as tank instead of owner
            }
        }
      }
    }

    mainTank = pPlayer;
    return pPlayer;
}
 void UpdateThreat()
 {
     ThreatList const& tList = m_creature->getThreatManager().getThreatList();
     ThreatList::const_iterator itr;
     bool empty = true;
     for(itr = tList.begin(); itr!=tList.end(); ++itr)
     {
         Unit* pUnit = Unit::GetUnit((*m_creature), (*itr)->getUnitGuid());
         if (pUnit && m_creature->getThreatManager().getThreat(pUnit))
         {
             if(pUnit->GetTypeId()==TYPEID_PLAYER)
             {
                 float threat = CalculateThreat(m_creature->GetDistance2d(pUnit), (float)pUnit->GetArmor(), pUnit->GetHealth());
                 m_creature->getThreatManager().modifyThreatPercent(pUnit, -100);
                 m_creature->AddThreat(pUnit, 1000000.0f * threat);
                 empty = false;
             }
         }
     }
 }