Example #1
0
void TotemSummon::Load(CreatureProto* proto, Unit* owner, LocationVector & position, uint32 spellid, int32 summonslot)
{
	Summon::Load(proto, owner, position, spellid, summonslot);

	TotemDisplayIdEntry* totemdisplay = TotemDisplayIdStorage.LookupEntry(creature_info->Male_DisplayID);
	uint32 displayID = 0;

	if(totemdisplay != NULL)
	{
		switch(owner->getRace())
		{
			case RACE_DRAENEI:
				displayID = totemdisplay->DraeneiId;
				break;

			case RACE_TROLL:
				displayID = totemdisplay->TrollId;
				break;

			case RACE_ORC:
				displayID = totemdisplay->OrcId;
				break;
		}
	}

	if(displayID == 0)
		displayID = creature_info->Male_DisplayID;

	// Set up the creature.
	SetMaxPower(POWER_TYPE_FOCUS, owner->getLevel() * 30);
	SetPower(POWER_TYPE_FOCUS, owner->getLevel() * 30);
	setLevel(owner->getLevel());
	setRace(0);
	setClass(1);
	setGender(2);
	SetPowerType(1);
	SetBaseAttackTime(MELEE, 2000);
	SetBaseAttackTime(OFFHAND, 2000);
	SetBoundingRadius(1.0f);
	SetCombatReach(1.0f);
	SetDisplayId(displayID);
	SetNativeDisplayId(creature_info->Male_DisplayID);
	SetCastSpeedMod(1.0f);
	SetUInt32Value(OBJECT_FIELD_DYNAMIC_FLAGS, 0);

	InheritSMMods(owner);

	for(uint8 school = 0; school < SCHOOL_COUNT; school++)
	{
		ModDamageDone[ school ] = owner->GetDamageDoneMod(school);
		HealDoneMod[ school ] = owner->HealDoneMod[ school ];
	}

	m_aiInterface->Init(this, AITYPE_TOTEM, MOVEMENTTYPE_NONE, owner);
	DisableAI();
}
Example #2
0
void GuardianSummon::Load(CreatureProto* proto, Unit* owner, LocationVector & position, uint32 spellid, int32 summonslot)
{
	Summon::Load(proto, owner, position, spellid, summonslot);

	SetPowerType(POWER_TYPE_MANA);
	SetMaxPower(POWER_TYPE_MANA, GetMaxPower(POWER_TYPE_MANA) + 28 + 10 * getLevel());
	SetPower(POWER_TYPE_MANA, GetPower(POWER_TYPE_MANA) + 28 + 10 * getLevel());
	setLevel(owner->getLevel());
	SetMaxHealth(GetMaxHealth() + 28 + 30 * getLevel());
	SetHealth(GetMaxHealth());
	SetType(CREATURE_TYPE_GUARDIAN);

	m_aiInterface->Init(this, AITYPE_PET , MOVEMENTTYPE_NONE, owner);
	m_aiInterface->SetUnitToFollow(owner);
	m_aiInterface->SetFollowDistance(3.0f);

	m_noRespawn = true;
}
Example #3
0
void Pet::LoadFromDB(Player* owner, PlayerPet * pi)
{
    m_Owner = owner;
    m_OwnerGuid = m_Owner->GetGUID();
    mPi = pi;

    Create(pi->name.c_str(), owner->GetMapId(), owner->GetPositionX() + 2 , owner->GetPositionY() +2, owner->GetPositionZ(), owner->GetOrientation());

    LoadValues(mPi->fields.c_str());
    m_PetNumber = mPi->number;
    m_PetXP = mPi->xp;
    Summon = mPi->summon;
    SetPowerType(POWER_TYPE_FOCUS);
    SetIsPet(true);

    // Setup actionbar
    uint32 pos = 0;
    string::size_type sp = mPi->actionbar.find(",");
    string::size_type lp = 0;
    while(sp != string::npos)
    {
        uint32 spell = atol(mPi->actionbar.substr(lp, sp).c_str());
        ActionBar[pos] = spell;
        ++pos;

        lp = sp+1;
        sp = mPi->actionbar.find(",", lp);
    }

    SetIsPet(true);
    InitializeMe(false);
    bExpires = false;   
    if(pi->autocastspell)
    {
        AI_Spell * sp = GetAISpellForSpellId(pi->autocastspell);
        if(sp)
            m_aiInterface->SetDefaultSpell(sp);
    }
}
Example #4
0
void Pet::CreateAsSummon(uint32 entry, CreatureInfo *ci, Creature* created_from_creature, Unit* owner, SpellEntry* created_by_spell, uint32 type, uint32 expiretime)
{
	if(ci == NULL)
		return;
	SetIsPet(true);

	m_OwnerGuid = owner->GetGUID();
	m_Owner = TO_PLAYER(owner);
	m_OwnerGuid = m_Owner->GetGUID();
	creature_info = ci;
	myFamily = dbcCreatureFamily.LookupEntry(creature_info->Family);
	//m_name = objmgr.GetCreatureFamilyName(myFamily->ID);
	if( myFamily->name == NULL )
		m_name = "Pet";
	else
		m_name.assign( myFamily->name );

	// Create ourself
	Create(m_name.c_str(), owner->GetMapId(), owner->GetPositionX(), owner->GetPositionY(), owner->GetPositionZ(), owner->GetOrientation());
	SetUInt32Value(OBJECT_FIELD_ENTRY, entry);
	SetFloatValue(UNIT_MOD_CAST_SPEED, 1.0f);	// better set this one

	// Fields common to both lock summons and pets
	uint32 level = (m_Owner->GetUInt32Value( UNIT_FIELD_LEVEL ) - 5);
	if( type & 0x2 && created_from_creature != NULL && created_from_creature->getLevel() > level)
	{
		level = created_from_creature->getLevel();
	}

	SetUInt32Value(UNIT_FIELD_LEVEL, level);
	SetUInt32Value(UNIT_FIELD_DISPLAYID,  ci->Male_DisplayID);
	SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID, ci->Male_DisplayID);
	SetSummonedByGUID(owner->GetGUID());
	SetCreatedByGUID(owner->GetGUID());

	if(type & 0x1 && created_by_spell != NULL)
		SetUInt64Value(UNIT_CREATED_BY_SPELL, created_by_spell->Id);

	if(type & 0x1 || created_from_creature == NULL)
	{
		Summon = true;
		SetUInt32Value(UNIT_FIELD_BYTES_0, 2048 | (0 << 24));
		SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
		SetUInt32Value(UNIT_FIELD_BASEATTACKTIME, 2000);
		SetUInt32Value(UNIT_FIELD_RANGEDATTACKTIME, 2000);
		SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, 0.5f);
		SetFloatValue(UNIT_FIELD_COMBATREACH, 0.75f);
		SetUInt32Value(UNIT_FIELD_BYTES_2, (0x01 | (0x2 << 24)));
		SetUInt32Value(UNIT_FIELD_PETNUMBER, GetUIdFromGUID());
		SetPowerType(POWER_TYPE_MANA);
		if(entry == WATER_ELEMENTAL)
			m_name = "Water Elemental";
		else if( entry == 19668)
			m_name = "Shadowfiend";
		else
			m_name = sWorld.GenerateName();
	}
	else
	{
		SetUInt32Value(UNIT_FIELD_BYTES_0, 2048 | (0 << 24));
		SetUInt32Value(UNIT_FIELD_BASEATTACKTIME, 2000);
		SetUInt32Value(UNIT_FIELD_RANGEDATTACKTIME, 2000); // Supalosa: 2.00 normalized attack speed

		// hacks D: allow correct creation of hunter pets via gm command
		if(created_from_creature == this)
		{
			SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, 0.5f);
			SetFloatValue(UNIT_FIELD_COMBATREACH, 0.75f);
		}
		else
		{
			SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, created_from_creature->GetFloatValue(UNIT_FIELD_BOUNDINGRADIUS));
			SetFloatValue(UNIT_FIELD_COMBATREACH, created_from_creature->GetFloatValue(UNIT_FIELD_COMBATREACH));
		}

		// These need to be checked.
		SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED | UNIT_FLAG_COMBAT); // why combat ??
		SetHappiness(PET_HAPPINESS_UPDATE_VALUE >> 1); // happiness
		SetUInt32Value(UNIT_FIELD_MAXPOWER5, 1000000);
		SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, 0);
		SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, GetNextLevelXP(getLevel()));
		SetUInt32Value(UNIT_FIELD_BYTES_1, 0);

		// Focus
		SetUInt32Value(UNIT_FIELD_POWER3, 100);
		SetUInt32Value(UNIT_FIELD_MAXPOWER3, 100);

		// 0x3 -> Enable pet rename.
		SetUInt32Value(UNIT_FIELD_BYTES_2, 1 | (0x3 << 16));

		// Change the power type to FOCUS
		SetPowerType(POWER_TYPE_FOCUS);

		// create our spells
		SetDefaultSpells();

		InitTalentsForLevel(true);
	}

	// Apply stats.
	ApplyStatsForLevel();

	BaseDamage[0]=GetFloatValue(UNIT_FIELD_MINDAMAGE);
	BaseDamage[1]=GetFloatValue(UNIT_FIELD_MAXDAMAGE);
	BaseOffhandDamage[0]=GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE);
	BaseOffhandDamage[1]=GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE);
	BaseRangedDamage[0]=GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE);
	BaseRangedDamage[1]=GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE);

	SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, owner->GetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE));
	m_PartySpellsUpdateTimer = 0;

	m_PetNumber = TO_PLAYER(owner)->GeneratePetNumber();
	SetUInt32Value(UNIT_FIELD_PETNUMBER, GetUIdFromGUID());

	m_ExpireTime = expiretime;
	bExpires = m_ExpireTime > 0 ? true : false;

	if(!bExpires)
	{
		// Create PlayerPet struct (Rest done by UpdatePetInfo)
		PlayerPet *pp = new PlayerPet;
		pp->number = m_PetNumber;
		pp->stablestate = STABLE_STATE_ACTIVE;
		TO_PLAYER(owner)->AddPlayerPet(pp, pp->number);
	}

	//maybe we should use speed from the template we created the creature ?
	m_base_runSpeed = m_runSpeed = owner->m_base_runSpeed; //should we be able to keep up with master ?
	m_base_walkSpeed = m_walkSpeed = owner->m_base_walkSpeed; //should we be able to keep up with master ?

	InitializeMe(true);
}
Example #5
0
bool Creature::Load(CreatureSpawn *spawn, uint32 mode, MapInfo *info)
{
	m_spawn = spawn;
	proto = CreatureProtoStorage.LookupEntry(spawn->entry);
	if(!proto)
		return false;
	creature_info = CreatureNameStorage.LookupEntry(spawn->entry);
	if(!creature_info)
		return false;
	
	spawnid = spawn->id;

	m_walkSpeed = m_base_walkSpeed = proto->walk_speed; //set speeds
	m_runSpeed = m_base_runSpeed = proto->run_speed; //set speeds
	m_flySpeed = proto->fly_speed;

	//Set fields
	SetUInt32Value(OBJECT_FIELD_ENTRY,proto->Id);
	SetFloatValue(OBJECT_FIELD_SCALE_X,proto->Scale);
	
	//SetUInt32Value(UNIT_FIELD_HEALTH, (mode ? long2int32(proto->Health * 1.5)  : proto->Health));
	//SetUInt32Value(UNIT_FIELD_BASE_HEALTH, (mode ? long2int32(proto->Health * 1.5)  : proto->Health));
	//SetUInt32Value(UNIT_FIELD_MAXHEALTH, (mode ? long2int32(proto->Health * 1.5)  : proto->Health));
	uint32 health = proto->MinHealth + RandomUInt(proto->MaxHealth - proto->MinHealth);
	if(mode)
		health = long2int32(double(health) * 1.5);
	SetUInt32Value(UNIT_FIELD_HEALTH, health);
	SetUInt32Value(UNIT_FIELD_MAXHEALTH, health);
	SetUInt32Value(UNIT_FIELD_BASE_HEALTH, health);

	SetUInt32Value(UNIT_FIELD_POWER1,proto->Mana);
	SetUInt32Value(UNIT_FIELD_MAXPOWER1,proto->Mana);
	SetUInt32Value(UNIT_FIELD_BASE_MANA,proto->Mana);
	
	// Whee, thank you blizz, I love patch 2.2! Later on, we can randomize male/female mobs! xD
	// Determine gender (for voices)
	//if(spawn->displayid != creature_info->Male_DisplayID)
	//	setGender(1);   // Female
	
	uint32 model;
	uint32 gender = creature_info->GenerateModelId(&model);
	setGender(gender);

	SetUInt32Value(UNIT_FIELD_DISPLAYID,model);
	SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID,model);
	SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID,proto->MountedDisplayID);

    //SetUInt32Value(UNIT_FIELD_LEVEL, (mode ? proto->Level + (info ? info->lvl_mod_a : 0) : proto->Level));
	SetUInt32Value(UNIT_FIELD_LEVEL, proto->MinLevel + (RandomUInt(proto->MaxLevel - proto->MinLevel)));
	if(mode && info)
		ModUnsigned32Value(UNIT_FIELD_LEVEL, info->lvl_mod_a);

	for(uint32 i = 0; i < 7; ++i)
		SetUInt32Value(UNIT_FIELD_RESISTANCES+i,proto->Resistances[i]);

	SetUInt32Value(UNIT_FIELD_BASEATTACKTIME,proto->AttackTime);
	SetFloatValue(UNIT_FIELD_MINDAMAGE, (mode ? proto->MinDamage * 1.5f  : proto->MinDamage));
	SetFloatValue(UNIT_FIELD_MAXDAMAGE, (mode ? proto->MaxDamage * 1.5f  : proto->MaxDamage));

	SetUInt32Value(UNIT_FIELD_RANGEDATTACKTIME,proto->RangedAttackTime);
	SetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE,proto->RangedMinDamage);
	SetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE,proto->RangedMaxDamage);

	SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, proto->Item1SlotDisplay);
	SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, proto->Item2SlotDisplay);
	SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, proto->Item3SlotDisplay);
	SetUInt32Value(UNIT_VIRTUAL_ITEM_INFO, proto->Item1Info1);
	SetUInt32Value(UNIT_VIRTUAL_ITEM_INFO_01, proto->Item1Info2);
	SetUInt32Value(UNIT_VIRTUAL_ITEM_INFO_02, proto->Item2Info1);
	SetUInt32Value(UNIT_VIRTUAL_ITEM_INFO_03, proto->Item2Info2);
	SetUInt32Value(UNIT_VIRTUAL_ITEM_INFO_04, proto->Item3Info1);
	SetUInt32Value(UNIT_VIRTUAL_ITEM_INFO_05, proto->Item3Info2);

	SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, spawn->factionid);
	SetUInt32Value(UNIT_FIELD_FLAGS, spawn->flags);
	SetUInt32Value(UNIT_NPC_EMOTESTATE, spawn->emote_state);
	SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, proto->BoundingRadius);
	SetFloatValue(UNIT_FIELD_COMBATREACH, proto->CombatReach);
	original_emotestate = spawn->emote_state;
	// set position
	m_position.ChangeCoords( spawn->x, spawn->y, spawn->z, spawn->o );
	m_spawnLocation.ChangeCoords(spawn->x, spawn->y, spawn->z, spawn->o);
	m_aiInterface->setMoveType(spawn->movetype);	
	m_aiInterface->m_waypoints = objmgr.GetWayPointMap(spawn->id);

	m_faction = dbcFactionTemplate.LookupEntry(spawn->factionid);
	if(m_faction)
	{
		m_factionDBC = dbcFaction.LookupEntry(m_faction->Faction);
		// not a neutral creature
		if(!(m_factionDBC->RepListId == -1 && m_faction->HostileMask == 0 && m_faction->FriendlyMask == 0))
		{
			GetAIInterface()->m_canCallForHelp = true;
		}
	}


//SETUP NPC FLAGS
	SetUInt32Value(UNIT_NPC_FLAGS,proto->NPCFLags);

	if ( HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_VENDOR ) )
		m_SellItems = objmgr.GetVendorList(GetEntry());

	if ( HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_QUESTGIVER ) )
		_LoadQuests();

	if ( HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_TAXIVENDOR) )
		m_TaxiNode = sTaxiMgr.GetNearestTaxiNode( m_position.x, m_position.y, m_position.z, GetMapId() );

	if ( HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_TRAINER) || HasFlag(UNIT_NPC_FLAGS,UNIT_NPC_FLAG_TRAINER_PROF))
		mTrainer = objmgr.GetTrainer(GetEntry());

	if ( HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_AUCTIONEER ) )
		auctionHouse = sAuctionMgr.GetAuctionHouse(GetEntry());

//NPC FLAGS
	 m_aiInterface->m_waypoints=objmgr.GetWayPointMap(spawn->id);

	//load resistances
	for(uint32 x=0;x<7;x++)
		BaseResistance[x]=GetUInt32Value(UNIT_FIELD_RESISTANCES+x);
	for(uint32 x=0;x<5;x++)
		BaseStats[x]=GetUInt32Value(UNIT_FIELD_STAT0+x);

	BaseDamage[0]=GetFloatValue(UNIT_FIELD_MINDAMAGE);
	BaseDamage[1]=GetFloatValue(UNIT_FIELD_MAXDAMAGE);
	BaseOffhandDamage[0]=GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE);
	BaseOffhandDamage[1]=GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE);
	BaseRangedDamage[0]=GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE);
	BaseRangedDamage[1]=GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE);
	BaseAttackType=proto->AttackType;

	SetFloatValue(UNIT_MOD_CAST_SPEED, 1.0f);   // better set this one
	SetUInt32Value(UNIT_FIELD_BYTES_0, spawn->bytes);
	SetUInt32Value(UNIT_FIELD_BYTES_2, spawn->bytes2);

////////////AI
	
	// kek
	for(list<AI_Spell*>::iterator itr = proto->spells.begin(); itr != proto->spells.end(); ++itr)
	{
		m_aiInterface->addSpellToList(*itr);
	}
	//m_aiInterface->m_canCallForHelp = proto->m_canCallForHelp;
	//m_aiInterface->m_CallForHelpHealth = proto->m_callForHelpHealth;
	m_aiInterface->m_canFlee = proto->m_canFlee;
	m_aiInterface->m_FleeHealth = proto->m_fleeHealth;
	m_aiInterface->m_FleeDuration = proto->m_fleeDuration;

	//these fields are always 0 in db
	GetAIInterface()->setMoveType(0);
	GetAIInterface()->setMoveRunFlag(0);
	
	// load formation data
	if( spawn->form != NULL )
	{
		m_aiInterface->m_formationLinkSqlId = spawn->form->fol;
		m_aiInterface->m_formationFollowDistance = spawn->form->dist;
		m_aiInterface->m_formationFollowAngle = spawn->form->ang;
	}
	else
	{
		m_aiInterface->m_formationLinkSqlId = 0;
		m_aiInterface->m_formationFollowDistance = 0;
		m_aiInterface->m_formationFollowAngle = 0;
	}

//////////////AI

	myFamily = dbcCreatureFamily.LookupEntry(creature_info->Family);

	
// PLACE FOR DIRTY FIX BASTARDS
	// HACK! set call for help on civ health @ 100%
	if(creature_info->Civilian >= 1)
		m_aiInterface->m_CallForHelpHealth = 100;
 
 //HACK!
	if(m_uint32Values[UNIT_FIELD_DISPLAYID] == 17743 ||
		m_uint32Values[UNIT_FIELD_DISPLAYID] == 20242 ||
		m_uint32Values[UNIT_FIELD_DISPLAYID] == 15435 ||
		(creature_info->Family == UNIT_TYPE_MISC))
	{
		m_useAI = false;
	}

	/* more hacks! */
	if(proto->Mana != 0)
		SetPowerType(POWER_TYPE_MANA);
	else
		SetPowerType(0);

	has_combat_text = objmgr.HasMonsterSay(GetEntry(), MONSTER_SAY_EVENT_ENTER_COMBAT);
	has_waypoint_text = objmgr.HasMonsterSay(GetEntry(), MONSTER_SAY_EVENT_RANDOM_WAYPOINT);
	m_aiInterface->m_isGuard = isGuard(GetEntry());

	m_aiInterface->getMoveFlags();

	/* creature death state */
	if(proto->death_state == 1)
	{
		uint32 newhealth = m_uint32Values[UNIT_FIELD_HEALTH] / 100;
		if(!newhealth)
			newhealth = 1;
		SetUInt32Value(UNIT_FIELD_HEALTH, 1);
		m_limbostate = true;
		bInvincible = true;
		SetUInt32Value(UNIT_NPC_EMOTESTATE, EMOTE_STATE_DEAD);
	}
	m_invisFlag = proto->invisibility_type;
	if( spawn->stand_state )
		SetStandState( (uint8)spawn->stand_state );

	return true;
}
Example #6
0
void Pet::CreateAsSummon(uint32 entry, CreatureInfo *ci, Creature* created_from_creature, Unit *owner, SpellEntry* created_by_spell, uint32 type, uint32 expiretime)
{
    SetIsPet(true);

    std::string myname = sWorld.GenerateName();

    if(!ci) return;
    m_Owner = static_cast<Player*>(owner);
    m_OwnerGuid = m_Owner->GetGUID();

    // Create ourself    
    Create(myname.c_str(), owner->GetMapId(), owner->GetPositionX(), owner->GetPositionY(), owner->GetPositionZ(), owner->GetOrientation());
    creature_info = ci;
    SetUInt32Value(OBJECT_FIELD_ENTRY, entry);
    SetFloatValue(UNIT_MOD_CAST_SPEED, 1.0f);   // better set this one

    // Fields common to both lock summons and pets
    if(type & 0x2 && created_from_creature != NULL)
        SetUInt32Value(UNIT_FIELD_LEVEL, created_from_creature->getLevel());
    else
        SetUInt32Value(UNIT_FIELD_LEVEL,owner->GetUInt32Value(UNIT_FIELD_LEVEL));

    SetUInt32Value(UNIT_FIELD_DISPLAYID,  ci->DisplayID);
    SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID, ci->DisplayID);
    SetUInt64Value(UNIT_FIELD_SUMMONEDBY, owner->GetGUID());
    SetUInt64Value(UNIT_FIELD_CREATEDBY, owner->GetGUID());
    
    if(type & 0x1 && created_by_spell != NULL)
        SetUInt64Value(UNIT_CREATED_BY_SPELL, created_by_spell->Id);

    BaseStats[0] = uint32(20+getLevel()*1.55);
    BaseStats[1] = uint32(20+getLevel()*0.64);
    BaseStats[2] = uint32(20+getLevel()*1.27);
    BaseStats[3] = uint32(20+getLevel()*0.18);
    BaseStats[4] = uint32(20+getLevel()*0.36);

    if(type & 0x1 || created_from_creature == NULL)
    {
        Summon = true;
        float scale = 1.0f;

        switch(GetEntry())
        {
        case 416: //Imp
            {
                scale = 0.4f;
            }break;
        case 417: //Felhunter
            {
                scale = 0.7f;
            }break;
        case 1860: //VoidWalker
            {
                scale = 0.75f;
            }break;
        case 1863: //Succubus
            {
                scale = 1.0f;
            }break;
        }
        SetFloatValue(OBJECT_FIELD_SCALE_X, scale);

        uint32 hp=uint32(28 + 10 * getLevel());
        SetUInt32Value(UNIT_FIELD_MAXHEALTH, hp);
        SetUInt32Value(UNIT_FIELD_BASE_HEALTH,hp);
        uint32 mp=uint32(28 + 10 * getLevel());
        SetUInt32Value(UNIT_FIELD_MAXPOWER1,mp );
        SetUInt32Value(UNIT_FIELD_BASE_MANA,mp);
        
        SetFloatValue(OBJECT_FIELD_SCALE_X, scale);
        SetUInt32Value(UNIT_FIELD_BYTES_0, 2048 | (0 << 24));
        SetUInt32Value(UNIT_FIELD_FLAGS, 8);
        SetUInt32Value(UNIT_FIELD_BASEATTACKTIME, 2000);
        SetUInt32Value(UNIT_FIELD_BASEATTACKTIME_01, 2000);
        SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, 0.5f);
        SetFloatValue(UNIT_FIELD_COMBATREACH, 0.75f);
        SetFloatValue(UNIT_FIELD_MINDAMAGE,float(getLevel() * 1.88));
        SetFloatValue(UNIT_FIELD_MAXDAMAGE,float(getLevel() * 3));
        SetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE, float(GetFloatValue(UNIT_FIELD_MINDAMAGE)*0.5));
        SetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE, float(GetFloatValue(UNIT_FIELD_MAXDAMAGE)*0.5));

        SetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE,float((getLevel() * 1.88)/2));
        SetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE,float((getLevel() * 3)/2));
        
        SetUInt32Value(UNIT_FIELD_ATTACK_POWER, uint32(getLevel() * 1.7));
        SetUInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER, uint32(getLevel() * 2.4));
        
        for(int x=0;x<5;x++)
            SetUInt32Value(UNIT_FIELD_STAT0 + x, BaseStats[x]);

        SetUInt32Value(UNIT_FIELD_RESISTANCES, 180);
        SetUInt32Value(UNIT_FIELD_BYTES_2, 0x01);

        SetUInt32Value(UNIT_FIELD_MAXPOWER1, uint32(28 + 10 * getLevel()));
        SetUInt32Value(UNIT_FIELD_PETNUMBER, GetGUIDLow());
    } else {
        uint32 hp=created_from_creature->GetUInt32Value(UNIT_FIELD_MAXHEALTH);
        SetUInt32Value(UNIT_FIELD_MAXHEALTH, hp);
        SetUInt32Value(UNIT_FIELD_BASE_HEALTH,hp);

        SetFloatValue(OBJECT_FIELD_SCALE_X, created_from_creature->GetFloatValue(OBJECT_FIELD_SCALE_X));
        SetUInt32Value(UNIT_FIELD_BYTES_0, created_from_creature->GetUInt32Value(UNIT_FIELD_BYTES_0));
        SetUInt32Value(UNIT_FIELD_BASEATTACKTIME, created_from_creature->GetUInt32Value(UNIT_FIELD_BASEATTACKTIME));
        SetUInt32Value(UNIT_FIELD_BASEATTACKTIME_01, created_from_creature->GetUInt32Value(UNIT_FIELD_BASEATTACKTIME_01));
        SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, created_from_creature->GetFloatValue(UNIT_FIELD_BOUNDINGRADIUS));
        SetFloatValue(UNIT_FIELD_COMBATREACH, created_from_creature->GetFloatValue(UNIT_FIELD_COMBATREACH));
        SetFloatValue(UNIT_FIELD_MINDAMAGE, created_from_creature->GetFloatValue(UNIT_FIELD_MINDAMAGE));
        SetFloatValue(UNIT_FIELD_MAXDAMAGE, created_from_creature->GetFloatValue(UNIT_FIELD_MAXDAMAGE));
        SetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE, created_from_creature->GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE));
        SetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE, created_from_creature->GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE));
        SetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE, created_from_creature->GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE));
        SetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE, created_from_creature->GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE));
        SetUInt32Value(UNIT_FIELD_ATTACK_POWER, created_from_creature->GetUInt32Value(UNIT_FIELD_ATTACK_POWER));
        SetUInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER, created_from_creature->GetUInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER));;

        SetUInt32Value(UNIT_FIELD_MAXPOWER1, 0);
        SetUInt32Value(UNIT_FIELD_BASE_MANA, 0);

        SetUInt32Value(UNIT_FIELD_MAXPOWER2, 0);
        SetUInt32Value(UNIT_FIELD_MAXPOWER3, 200);
        SetUInt32Value(UNIT_FIELD_MAXPOWER4, 0);

        SetUInt32Value(UNIT_FIELD_RESISTANCES, created_from_creature->GetUInt32Value(UNIT_FIELD_RESISTANCES));
        
        // These need to be checked.
        SetUInt32Value(UNIT_FIELD_FLAGS, 0x00000828);
        SetUInt32Value(UNIT_FIELD_POWER5, 600000);
        SetUInt32Value(UNIT_FIELD_MAXPOWER5, 1000000);
        SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, 0);
        SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, GetNextLevelXP(getLevel()));

        // Change the power type to FOCUS
        SetPowerType(POWER_TYPE_FOCUS);
        
        for(int x=0;x<5;x++)
            SetUInt32Value(UNIT_FIELD_STAT0 + x, BaseStats[x]);

        // create our spellz
        SetDefaultSpells();
    }

    BaseDamage[0]=GetFloatValue(UNIT_FIELD_MINDAMAGE);
    BaseDamage[1]=GetFloatValue(UNIT_FIELD_MAXDAMAGE);
    BaseOffhandDamage[0]=GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE);
    BaseOffhandDamage[1]=GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE);
    BaseRangedDamage[0]=GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE);
    BaseRangedDamage[1]=GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE);

    SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, owner->GetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE));

    // Set all values to full.
    SetUInt32Value(UNIT_FIELD_HEALTH, GetUInt32Value(UNIT_FIELD_MAXHEALTH));
    SetUInt32Value(UNIT_FIELD_POWER1, GetUInt32Value(UNIT_FIELD_MAXPOWER1));
    SetUInt32Value(UNIT_FIELD_POWER2, GetUInt32Value(UNIT_FIELD_MAXPOWER2));
    SetUInt32Value(UNIT_FIELD_POWER3, GetUInt32Value(UNIT_FIELD_MAXPOWER3));
    SetUInt32Value(UNIT_FIELD_POWER4, GetUInt32Value(UNIT_FIELD_MAXPOWER4));

    // Set base values
    SetUInt32Value(UNIT_FIELD_BASE_HEALTH, GetUInt32Value(UNIT_FIELD_HEALTH));
    SetUInt32Value(UNIT_FIELD_BASE_MANA, GetUInt32Value(UNIT_FIELD_POWER1));
    memcpy(m_baseUint32Values, m_uint32Values,m_valuesCount*sizeof(uint32));
    
    m_PartySpellsUpdateTimer = 0;

    m_PetNumber = static_cast<Player*>(owner)->GeneratePetNumber();
    SetUInt32Value(UNIT_FIELD_PETNUMBER, m_GuidLow);

    m_ExpireTime = expiretime;
    bExpires = m_ExpireTime > 0 ? true : false;

    if(!bExpires)
    {
        // Create PlayerPet struct (Rest done by UpdatePetInfo)
        PlayerPet *pp = new PlayerPet;
        pp->number = m_PetNumber;
        static_cast<Player*>(owner)->AddPlayerPet(pp, pp->number);
    }    

    InitializeMe(true);
}