Esempio n. 1
0
void Summon::Load(CreatureProto* proto, Unit* owner, LocationVector & position, uint32 spellid, int32 summonslot)
{
    ARCEMU_ASSERT(owner != NULL);

    Creature::Load(proto, owner->GetMapMgr(), position.x, position.y, position.z, position.o);

    SetFaction(owner->GetFaction());
    Phase(PHASE_SET, owner->GetPhase());
    SetZoneId(owner->GetZoneId());
    SetCreatedBySpell(spellid);
    this->summonslot = summonslot;

    if (owner->IsPvPFlagged())
        SetPvPFlag();
    else
        RemovePvPFlag();

    if (owner->IsFFAPvPFlagged())
        SetFFAPvPFlag();
    else
        RemoveFFAPvPFlag();

    if (owner->IsSanctuaryFlagged())
        SetSanctuaryFlag();
    else
        RemoveSanctuaryFlag();

    SetCreatedByGUID(owner->GetGUID());

    if (owner->GetSummonedByGUID() == 0)
        SetSummonedByGUID(owner->GetGUID());
    else
        SetSummonedByGUID(owner->GetSummonedByGUID());

    this->owner = owner;

    if (owner->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE))
        SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
}
Esempio n. 2
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);
}