Esempio n. 1
0
void Creature::OnRemoveCorpse()
{
	// time to respawn!
	if (IsInWorld() && (int32)m_mapMgr->GetInstanceID() == m_instanceId)
	{

		sLog.outDetail("Removing corpse of "I64FMT"...", GetGUID());
	   
			if((GetMapMgr()->GetMapInfo() && GetMapMgr()->GetMapInfo()->type == INSTANCE_RAID && this->proto && this->proto->boss) || m_noRespawn)
			{
				RemoveFromWorld(false, true);
			}
			else
			{
				if(proto && proto->RespawnTime)
					RemoveFromWorld(true, false);
				else
					RemoveFromWorld(false, true);
			}
		
	   
		setDeathState(DEAD);

		m_position = m_spawnLocation;
	}
	else
	{
		// if we got here it's pretty bad
	}
}
Esempio n. 2
0
/////////////////
// Summoned Go's
//guardians are temporary spawn that will inherit master faction and will follow them. Apart from that they have their own mind
Unit* GameObject::CreateTemporaryGuardian(uint32 guardian_entry,uint32 duration,float angle, Unit* u_caster, uint8 Slot)
{
	CreatureProto * proto = CreatureProtoStorage.LookupEntry(guardian_entry);
	CreatureInfo * info = CreatureNameStorage.LookupEntry(guardian_entry);
	if(!proto || !info)
	{
		OUT_DEBUG("Warning : Missing summon creature template %u !",guardian_entry);
		return NULL;
	}
	uint32 lvl = u_caster->getLevel();
	LocationVector v = GetPositionNC();
	float m_followAngle = angle + v.o;
	float x = v.x +(3*(cosf(m_followAngle)));
	float y = v.y +(3*(sinf(m_followAngle)));
	Creature* p = NULL;
	p = GetMapMgr()->CreateCreature(guardian_entry);
	if(p == NULL)
		return NULL;
	p->SetInstanceID(GetMapMgr()->GetInstanceID());
	p->Load(proto, x, y, v.z, angle);

	if (lvl != 0)
	{
		/* power */
		p->SetPowerType(POWER_TYPE_MANA);
		p->SetUInt32Value(UNIT_FIELD_MAXPOWER1,p->GetUInt32Value(UNIT_FIELD_MAXPOWER1)+28+10*lvl);
		p->SetUInt32Value(UNIT_FIELD_POWER1,p->GetUInt32Value(UNIT_FIELD_POWER1)+28+10*lvl);
		/* health */
		p->SetUInt32Value(UNIT_FIELD_MAXHEALTH,p->GetUInt32Value(UNIT_FIELD_MAXHEALTH)+28+30*lvl);
		p->SetUInt32Value(UNIT_FIELD_HEALTH,p->GetUInt32Value(UNIT_FIELD_HEALTH)+28+30*lvl);
		/* level */
		p->SetUInt32Value(UNIT_FIELD_LEVEL, lvl);
	}

	p->SetSummonedByGUID(GetGUID());
    p->SetCreatedByGUID(GetGUID());
    p->SetZoneId(GetZoneId());
	p->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,u_caster->GetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE));
	p->_setFaction();

	p->GetAIInterface()->Init(p,AITYPE_PET,MOVEMENTTYPE_NONE,u_caster);
	p->GetAIInterface()->SetUnitToFollow(TO_UNIT(this));
	p->GetAIInterface()->SetUnitToFollowAngle(angle);
	p->GetAIInterface()->SetFollowDistance(3.0f);

	p->PushToWorld(GetMapMgr());

	if(duration)
		sEventMgr.AddEvent(TO_UNIT(this), &Unit::SummonExpireSlot,Slot, EVENT_SUMMON_EXPIRE, duration, 1,EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT );

	return p;

}
void StrandOfTheAncient::SpawnBuff(uint32 x)
{
	uint32 mapid = GetMapMgr()->GetMapId();
    switch(x)
	{
	case 0:
		m_buffs[x] = SpawnGameObject(184977, mapid, 1449.9296875f, 1470.70971679688f, 342.634552001953f, -1.64060950279236f, 0, 114, 1);
		m_buffs[x]->SetFloatValue(GAMEOBJECT_PARENTROTATION_2,0.73135370016098f);
		m_buffs[x]->SetFloatValue(GAMEOBJECT_PARENTROTATION_3,-0.681998312473297f);
		m_buffs[x]->SetByte(GAMEOBJECT_BYTES_1, 0, 1);
		m_buffs[x]->SetByte(GAMEOBJECT_BYTES_1, 1, 6);
		m_buffs[x]->SetByte(GAMEOBJECT_BYTES_1, 3, 100);
		break;
	case 1:
		m_buffs[x] = SpawnGameObject(184971, mapid, 1005.17071533203f, 1447.94567871094f, 335.903228759766f, 1.64060950279236f, 0, 114, 1);
		m_buffs[x]->SetFloatValue(GAMEOBJECT_PARENTROTATION_2,0.73135370016098f);
		m_buffs[x]->SetFloatValue(GAMEOBJECT_PARENTROTATION_3,0.681998372077942f);
		m_buffs[x]->SetByte(GAMEOBJECT_BYTES_1, 0, 1);
		m_buffs[x]->SetByte(GAMEOBJECT_BYTES_1, 1, 6);
		m_buffs[x]->SetByte(GAMEOBJECT_BYTES_1, 3, 100);
		break;
	case 2:
		m_buffs[x] = SpawnGameObject(184965, mapid, 1317.50573730469f, 1550.85070800781f, 313.234375f, -0.26179963350296f, 0, 114, 1);
		m_buffs[x]->SetFloatValue(GAMEOBJECT_PARENTROTATION_2,0.130526319146156f);
		m_buffs[x]->SetFloatValue(GAMEOBJECT_PARENTROTATION_3,-0.991444826126099f);
		m_buffs[x]->SetByte(GAMEOBJECT_BYTES_1, 0, 1);
		m_buffs[x]->SetByte(GAMEOBJECT_BYTES_1, 1, 6);
		m_buffs[x]->SetByte(GAMEOBJECT_BYTES_1, 3, 100);
		break;
	}
}
Esempio n. 4
0
uint32 Transporter::AddNPCPassenger(uint32 tguid, uint32 entry, float x, float y, float z, float o, uint32 anim)
{
    MapMgr* map = GetMapMgr();

    CreatureProperties const* creature_properties = sMySQLStore.getCreatureProperties(entry);
    if (creature_properties == nullptr || map == nullptr)
        return 0;

#if VERSION_STRING != Cata
    float transporter_x = obj_movement_info.transport_data.relativePosition.x + x;
    float transporter_y = obj_movement_info.transport_data.relativePosition.y + y;
    float transporter_z = obj_movement_info.transport_data.relativePosition.z + z;
#else
    float transporter_x = obj_movement_info.getTransportPosition()->x + x;
    float transporter_y = obj_movement_info.getTransportPosition()->y + y;
    float transporter_z = obj_movement_info.getTransportPosition()->z + z;
#endif

    Creature* pCreature = map->CreateCreature(entry);
    pCreature->Create(map->GetMapId(), transporter_x, transporter_y, transporter_z, (std::atan2(transporter_x, transporter_y) + float(M_PI)) + o);
    pCreature->Load(creature_properties, transporter_x, transporter_y, transporter_z, (std::atan2(transporter_x, transporter_y) + float(M_PI)) + o);
    pCreature->AddToWorld(map);
    pCreature->SetUnitMovementFlags(MOVEFLAG_TRANSPORT);
#if VERSION_STRING != Cata
    pCreature->obj_movement_info.transport_data.relativePosition.x = x;
    pCreature->obj_movement_info.transport_data.relativePosition.y = y;
    pCreature->obj_movement_info.transport_data.relativePosition.z = z;
    pCreature->obj_movement_info.transport_data.relativePosition.o = o;
    pCreature->obj_movement_info.transport_data.transportGuid = getGuid();
#else
    pCreature->obj_movement_info.setTransportData(getGuid(), x, y, z, o, 0, 0);
#endif

    pCreature->m_transportData.transportGuid = this->getGuid();
    pCreature->m_transportData.relativePosition.x = x;
    pCreature->m_transportData.relativePosition.y = y;
    pCreature->m_transportData.relativePosition.z = z;
    pCreature->m_transportData.relativePosition.o = o;

    if (anim)
        pCreature->setUInt32Value(UNIT_NPC_EMOTESTATE, anim);

    if (creature_properties->NPCFLags)
        pCreature->setUInt32Value(UNIT_NPC_FLAGS, creature_properties->NPCFLags);

    m_creatureSetMutex.Acquire();
    m_NPCPassengerSet.insert(pCreature);
    m_creatureSetMutex.Release();
    if (tguid == 0)
    {
        ++currenttguid;
        tguid = currenttguid;
    }
    else
        currenttguid = std::max(tguid, currenttguid);

    return tguid;
}
Esempio n. 5
0
void DynamicObject::Remove()
{
	// remove aura from all targets
	DynamicObjectList::iterator jtr  = targets.begin();
	DynamicObjectList::iterator jend = targets.end();
	Unit * target;

	while(jtr != jend)
	{
		target = GetMapMgr() ? GetMapMgr()->GetUnit(*jtr) : NULL;
		++jtr;
		if (target != NULL)
			target->RemoveAura(m_spellProto->Id);
	}

	if(IsInWorld())
		RemoveFromWorld(true);
	delete this;
}
Esempio n. 6
0
// Generates 3 random waypoints around the NPC
void Creature::SetGuardWaypoints()
{
	if(!GetMapMgr()) return;
	if(!GetCreatureName()) return;

	GetAIInterface()->setMoveType(1);
	for(int i = 1; i <= 4; i++)
	{
		float ang = rand()/100.0f;
		float ran = (rand()%(100))/10.0f;
		while(ran < 1)
			ran = (rand()%(100))/10.0f;

		WayPoint * wp = new WayPoint;
		wp->id = i;
		wp->flags = 0;
		wp->waittime = 800;  /* these guards are antsy :P */
		wp->x = GetSpawnX()+ran*sin(ang);
		wp->y = GetSpawnY()+ran*cos(ang);
#ifdef COLLISION
		wp->z = CollideInterface.GetHeight(m_mapId, wp->x, wp->y, m_spawnLocation.z + 2.0f);
		if( wp->z == NO_WMO_HEIGHT )
			wp->z = m_mapMgr->GetLandHeight(wp->x, wp->y);

		if( fabs( wp->z - m_spawnLocation.z ) > 10.0f )
			wp->z = m_spawnLocation.z;
#else
		wp->z = GetMapMgr()->GetLandHeight(wp->x, wp->y);
#endif		// COLLISION
		wp->o = 0;
		wp->backwardemoteid = 0;
		wp->backwardemoteoneshot = 0;
		wp->forwardemoteid = 0;
		wp->forwardemoteoneshot = 0;
		wp->backwardskinid = m_uint32Values[UNIT_FIELD_NATIVEDISPLAYID];
		wp->forwardskinid = m_uint32Values[UNIT_FIELD_NATIVEDISPLAYID];
		GetAIInterface()->addWayPoint(wp);
	}
}
Esempio n. 7
0
Creature* Transporter::AddNPCPassengerInInstance(uint32 entry, float x, float y, float z, float o, uint32 /*anim*/)
{
    MapMgr* map = GetMapMgr();

    CreatureProperties const* creature_properties = sMySQLStore.getCreatureProperties(entry);
    if (creature_properties == nullptr || map == nullptr)
        return nullptr;

#if VERSION_STRING != Cata
    float transporter_x = obj_movement_info.transport_data.relativePosition.x + x;
    float transporter_y = obj_movement_info.transport_data.relativePosition.y + y;
    float transporter_z = obj_movement_info.transport_data.relativePosition.z + z;
#else
    float transporter_x = obj_movement_info.getTransportPosition()->x + x;
    float transporter_y = obj_movement_info.getTransportPosition()->y + y;
    float transporter_z = obj_movement_info.getTransportPosition()->z + z;
#endif

    Creature* pCreature = map->CreateCreature(entry);
    pCreature->Create(map->GetMapId(), transporter_x, transporter_y, transporter_z, (std::atan2(transporter_x, transporter_y) + float(M_PI)) + o);
    pCreature->Load(creature_properties, transporter_x, transporter_y, transporter_z, (std::atan2(transporter_x, transporter_y) + float(M_PI)) + o);
    pCreature->AddToWorld(map);
    pCreature->SetUnitMovementFlags(MOVEFLAG_TRANSPORT);
#if VERSION_STRING != Cata
    pCreature->obj_movement_info.transport_data.relativePosition.x = x;
    pCreature->obj_movement_info.transport_data.relativePosition.y = y;
    pCreature->obj_movement_info.transport_data.relativePosition.z = z;
    pCreature->obj_movement_info.transport_data.relativePosition.o = o;
    pCreature->obj_movement_info.transport_data.transportGuid = getGuid();
#else
    pCreature->obj_movement_info.setTransportData(getGuid(), x, y, z, o, 0, 0);
#endif

    pCreature->m_transportData.transportGuid = this->getGuid();
    pCreature->m_transportData.relativePosition.x = x;
    pCreature->m_transportData.relativePosition.y = y;
    pCreature->m_transportData.relativePosition.z = z;
    pCreature->m_transportData.relativePosition.o = o;
    m_creatureSetMutex.Acquire();
    m_NPCPassengerSet.insert(pCreature);
    m_creatureSetMutex.Release();
    return pCreature;
}
Esempio n. 8
0
void Transporter::AddNPC(uint32 Entry, float offsetX, float offsetY, float offsetZ, float offsetO)
{
    if(!this)
        return;

    uint32 guid;
    m_transportGuidGen.Acquire();
    guid = ++m_transportGuidMax;
    m_transportGuidGen.Release();

    CreatureInfo * inf = CreatureNameStorage.LookupEntry(Entry);
    CreatureProto * proto = CreatureProtoStorage.LookupEntry(Entry);
    if(inf == NULL || proto == NULL)
        return;

    Creature* pCreature(new Creature((uint64)HIGHGUID_TYPE_TRANSPORTER<<32 | guid));
    pCreature->Init();
    pCreature->Load(proto, GetMapMgr()->iInstanceMode, offsetX, offsetY, offsetZ, offsetO);
    pCreature->GetMovementInfo()->SetTransportData(GetGUID(), offsetX, offsetY, offsetZ, offsetO, 0);
    m_npcs.insert(make_pair(guid,pCreature));
}
Esempio n. 9
0
void GameObject::UseFishingNode(Player *player)
{
	sEventMgr.RemoveEvents(this);
	if(GetUInt32Value(GAMEOBJECT_STATE))//click on bobber before somth is hooked
	{
		player->GetSession()->OutPacket(SMSG_FISH_NOT_HOOKED);
		EndFishing(player,true);
		return;
	}
	
	uint32 zone=sAreaStore.LookupEntry(GetMapMgr()->GetAreaID(GetPositionX(),GetPositionY()))->ZoneId;

	FishingZoneEntry *entry = FishingZoneStorage.LookupEntry(zone);
	if(entry == NULL)
	{
		sLog.outError("ERROR: Fishing zone information for zone %d not found!", zone);
		EndFishing(player, true);
		return;
	}
	uint32 maxskill=entry->MaxSkill;
//	uint32 minskill=entry->MaxSkill;
	uint32 minskill=entry->MinSkill;

	if(player->GetBaseSkillAmt(SKILL_FISHING)<maxskill)	
		player->AdvanceSkillLine(SKILL_FISHING);

	//Open loot on success, otherwise FISH_ESCAPED.
	if(Rand(((player->GetSkillAmt(SKILL_FISHING)-minskill)*100)/maxskill))
	{			  
		lootmgr.FillProfessionLoot(&lootmgr.FishingLoot,&loot,zone);
		player->SendLoot(GetGUID(),3);
		EndFishing(player, false);
	}
	else //failed
	{
		player->GetSession()->OutPacket(SMSG_FISH_ESCAPED);
		EndFishing(player,false);
	}

}
Esempio n. 10
0
void DynamicObject::Remove()
{
    if(IsInWorld())
    {
        // remove aura from all targets
        Unit* target;
        for(std::set< uint64 >::iterator itr = targets.begin(); itr != targets.end(); ++itr)
        {

            uint64 TargetGUID = *itr;

            target = m_mapMgr->GetUnit(TargetGUID);

            if(target != NULL)
                target->RemoveAura(m_spellProto->Id);
        }

        WorldPacket data(SMSG_DESTROY_OBJECT, 8);
        data << GetGUID() << uint8(1);
        SendMessageToSet(&data, true);

        if(m_spellProto->IsChannelSpell() && GUID_HIPART(casterGuid) != HIGHGUID_TYPE_GAMEOBJECT)
        {
            if(Unit* u_caster = GetMapMgr()->GetUnit(casterGuid))
            {
                if(u_caster->GetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT) == GetGUID())
                {
                    u_caster->SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT, 0);
                    u_caster->SetUInt32Value(UNIT_CHANNEL_SPELL, 0);
                }
            }
        }

        RemoveFromWorld(true);
    }
    Destruct();
}
Esempio n. 11
0
void Transporter::AddNPC(uint32 Entry, float offsetX, float offsetY, float offsetZ, float offsetO)
{
	if(!this)
		return;

	uint32 guid;
	m_transportGuidGen.Acquire();
	guid = ++m_transportGuidMax;
	m_transportGuidGen.Release();

	CreatureInfo * inf = CreatureNameStorage.LookupEntry(Entry);
	CreatureProto * proto = CreatureProtoStorage.LookupEntry(Entry);
	if(inf == NULL || proto == NULL)
		return;

	Creature* pCreature(new Creature((uint64)HIGHGUID_TYPE_TRANSPORTER<<32 | guid));
	pCreature->Init();
	pCreature->Load(proto, GetMapMgr()->iInstanceMode, offsetX, offsetY, offsetZ, offsetO);
	pCreature->m_TransporterUnk = UNIXTIME;
	pCreature->m_transportPosition = new LocationVector(offsetX, offsetY, offsetZ, offsetO);
	pCreature->m_TransporterGUID = GetGUID();
	pCreature->m_transportNewGuid = GetNewGUID();
	m_npcs.insert(make_pair(guid,pCreature));
}
Esempio n. 12
0
void DynamicObject::UpdateTargets()
{
	if(m_aliveDuration == 0)
		return;

	if(m_aliveDuration >= 100)
	{
		Unit* target;
		Aura* pAura;

		float radius = m_floatValues[ DYNAMICOBJECT_RADIUS ] * m_floatValues[ DYNAMICOBJECT_RADIUS ];

		// Looking for targets in the Object set
		for(std::set< Object* >::iterator itr = m_objectsInRange.begin(); itr != m_objectsInRange.end(); ++itr)
		{
			Object* o = *itr;

			if(!o->IsUnit() || !TO< Unit* >(o)->isAlive())
				continue;

			target = TO< Unit* >(o);

			if(!isAttackable(u_caster, target, !(m_spellProto->c_is_flags & SPELL_FLAG_IS_TARGETINGSTEALTHED)))
				continue;

			// skip units already hit, their range will be tested later
			if(targets.find(target->GetGUID()) != targets.end())
				continue;

			if(GetDistanceSq(target) <= radius)
			{
				pAura = sSpellFactoryMgr.NewAura(m_spellProto, m_aliveDuration, u_caster, target, true);
				for(uint32 i = 0; i < 3; ++i)
				{
					if(m_spellProto->Effect[i] == SPELL_EFFECT_PERSISTENT_AREA_AURA)
					{
						pAura->AddMod(m_spellProto->EffectApplyAuraName[i],
						              m_spellProto->EffectBasePoints[i] + 1, m_spellProto->EffectMiscValue[i], i);
					}
				}
				target->AddAura(pAura);
				if(p_caster)
				{
					p_caster->HandleProc(PROC_ON_CAST_SPECIFIC_SPELL | PROC_ON_CAST_SPELL, target, m_spellProto);
					p_caster->m_procCounter = 0;
				}

				// add to target list
				targets.insert(target->GetGUID());
			}
		}


		// loop the targets, check the range of all of them
		DynamicObjectList::iterator jtr  = targets.begin();
		DynamicObjectList::iterator jtr2;
		DynamicObjectList::iterator jend = targets.end();

		while(jtr != jend)
		{
			target = GetMapMgr() ? GetMapMgr()->GetUnit(*jtr) : NULL;
			jtr2 = jtr;
			++jtr;

			if((target != NULL) && (GetDistanceSq(target) > radius))
			{
				target->RemoveAura(m_spellProto->Id);
				targets.erase(jtr2);
			}
		}

		m_aliveDuration -= 100;
	}
	else
	{
		m_aliveDuration = 0;
	}

	if(m_aliveDuration == 0)
	{
		Remove();
	}
}
Esempio n. 13
0
void Vehicle::SendSpells(uint32 entry, Player* plr)
{
	CreatureProtoVehicle* acc = CreatureProtoVehicleStorage.LookupEntry(GetEntry());
	if(!acc)
	{
		WorldPacket data(SMSG_PET_SPELLS, 12);
		data << uint64(0);
		data << uint32(0);
		plr->GetSession()->SendPacket(&data);
		return;
	}

	uint8 count = 0;

	WorldPacket data(SMSG_PET_SPELLS, 60);
	data << uint64(GetGUID());
	data << uint16(0);
	data << uint32(0);
	data << uint32(0x00000101);

	for (uint32 i = 0; i < 6; i++)
	{
		uint32 spellId = acc->VehicleSpells[i];
		if (!spellId)
			continue;

		SpellEntry const *spellInfo = dbcSpell.LookupEntryForced( spellId );
		if (!spellInfo)
			continue;
		if(spellInfo->Attributes & ATTRIBUTES_PASSIVE)
		{
			CastSpell(GetGUID(), spellId, true);
			data << uint16(0) << uint8(0) << uint8(i+8);
		}
		else
		{
			if(spellInfo->SpellDifficulty && GetMapMgr()->pInstance)
			{
				SpellDifficultyEntry * sd = dbcSpellDifficulty.LookupEntry(spellInfo->SpellDifficulty);
				if( sd->SpellId[GetMapMgr()->iInstanceMode] == 0 )
				{
					uint32 mode;
					if( GetMapMgr()->iInstanceMode == 3 )
						mode = 1;
					else
						mode = 0;

					if( sd->SpellId[mode] == 0 )
						spellId = sd->SpellId[0];
				}
				else
					spellId = sd->SpellId[GetMapMgr()->iInstanceMode];
			}
			switch(spellId)
			{
			case 62286: // Tar
			case 62308: // Ram
			case 62522: // Electroshock!
				{
					if(IsInInstance())
					{
						if(dbcMap.LookupEntry(GetMapId())->israid()) // Difficulty Check
						{
							if(plr->iRaidType > MODE_10PLAYER_NORMAL)
							{
								data << uint32(0);
								continue;
							}
						}
					}
					data << uint32(MAKE_ACTION_BUTTON(spellId,i+8));
					++count;
				}break;

			default:
				data << uint32(MAKE_ACTION_BUTTON(spellId,i+8));
				++count;
				break;
			}
		}
	}

	for(uint8 i = 6; i < 10; i++)
	{
		data << uint16(0) << uint8(0) << uint8(i+8);
	}

	data << count; // spells count
	data << uint8(0);
	plr->GetSession()->SendPacket(&data);
}
Esempio n. 14
0
void Vehicle::InstallAccessories()
{
	CreatureProtoVehicle* acc = CreatureProtoVehicleStorage.LookupEntry(GetEntry());
	if(acc == NULL)
	{
		sLog.outDetail("Vehicle %u has no accessories.", GetEntry());
		return;
	}

	MapMgr* map = (GetMapMgr() ? GetMapMgr() : sInstanceMgr.GetMapMgr(GetMapId()));
	if(map == NULL) // Shouldn't ever really happen.
		return;

	for(int i = 0; i < 8; i++)
	{
		SeatInfo seatinfo = acc->seats[i];
		if(!seatinfo.accessoryentry || (seatinfo.accessoryentry == GetEntry()))
			continue;

		if(m_vehicleSeats[i] == NULL)
		{
			sLog.outDetail("No seatmap for selected seat.\n");
			continue;
		}

		// Load the Proto
		CreatureProto* proto = CreatureProtoStorage.LookupEntry(seatinfo.accessoryentry);
		CreatureInfo* info = CreatureNameStorage.LookupEntry(seatinfo.accessoryentry);

		if(!proto || !info)
		{
			sLog.outError("No proto/info for vehicle accessory %u in vehicle %u", seatinfo.accessoryentry, GetEntry());
			continue;
		}

		// Remove any passengers.
		if(m_passengers[i])
			RemovePassenger(m_passengers[i]);

		if(proto->vehicle_entry > 0)
		{
			// Create the Vehicle!
			Vehicle* pass = map->CreateVehicle(seatinfo.accessoryentry);
			if(pass != NULL && pass)
			{
				pass->Load(proto, (IsInInstance() ? map->iInstanceMode : MODE_5PLAYER_NORMAL),
					GetPositionX()+m_vehicleSeats[i]->m_attachmentOffsetX,
					GetPositionY()+m_vehicleSeats[i]->m_attachmentOffsetY,
					GetPositionZ()+m_vehicleSeats[i]->m_attachmentOffsetZ);

				pass->Init();
				pass->m_TransporterGUID = GetGUID();
				pass->InitSeats(proto->vehicle_entry);
				if(pass->HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK))
					pass->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK); // Accessory

				AddPassenger(pass, i, true);
				pass->PushToWorld(map);
			}
		}
		else
		{
			// Create the Unit!
			Creature* pass = map->CreateCreature(seatinfo.accessoryentry);
			if(pass != NULL)
			{
				pass->Load(proto, map->iInstanceMode,
					GetPositionX()+m_vehicleSeats[i]->m_attachmentOffsetX,
					GetPositionY()+m_vehicleSeats[i]->m_attachmentOffsetY,
					GetPositionZ()+m_vehicleSeats[i]->m_attachmentOffsetZ);

				pass->Init();
				pass->m_TransporterGUID = GetGUID();
				AddPassenger(pass, i, true);
				pass->PushToWorld(map);
			}
		}
	}
}
Esempio n. 15
0
void DynamicObject::UpdateTargets()
{
	if(m_aliveDuration == 0)
		return;

	if(m_aliveDuration >= 100)
	{
		std::set<Object*>::iterator itr = GetInRangeSetBegin(),itr2;
		std::set<Object*>::iterator iend = GetInRangeSetEnd();
		Unit * target;
		Aura * pAura;
		float radius = m_floatValues[DYNAMICOBJECT_RADIUS]*m_floatValues[DYNAMICOBJECT_RADIUS];

		this->AquireInrangeLock(); //make sure to release lock before exit function !
		while(itr != iend)
		{
//			target = *itr;
//			++itr;

			itr2 = itr;
			++itr;

			if( !( (*itr2)->IsUnit() ) || ! static_cast< Unit* >( *itr2 )->isAlive() || ( static_cast< Creature* >( *itr2 )->IsTotem() && !static_cast< Unit* >( *itr2 )->IsPlayer() ) )
				continue;

			target = static_cast< Unit* >( *itr2 );

			if( !isAttackable( p_caster, target, !(m_spellProto->c_is_flags & SPELL_FLAG_IS_TARGETINGSTEALTHED) ) )
				continue;

			// skip units already hit, their range will be tested later
			if(targets.find(target->GetGUID()) != targets.end())
				continue;

			if(GetDistanceSq(target) <= radius)
			{
				pAura = AuraPool.PooledNew();
				pAura->Init(m_spellProto, m_aliveDuration, u_caster, target, true);
				for(uint32 i = 0; i < 3; ++i)
				{
					if(m_spellProto->Effect[i] == SPELL_EFFECT_PERSISTENT_AREA_AURA)
					{
						pAura->AddMod(m_spellProto->EffectApplyAuraName[i],
							m_spellProto->EffectBasePoints[i]+1, m_spellProto->EffectMiscValue[i], i);
					}
				}
				target->AddAura(pAura, m_spellScript);
				if(p_caster)
				{
					p_caster->HandleProc(PROC_ON_CAST_SPECIFIC_SPELL | PROC_ON_CAST_SPELL,target, m_spellProto);
					p_caster->m_procCounter = 0;
				}

				// add to target list
				targets.insert(target->GetGUID());
			}
		}

		this->ReleaseInrangeLock();
		// loop the targets, check the range of all of them
		DynamicObjectList::iterator jtr  = targets.begin();
		DynamicObjectList::iterator jtr2;
		DynamicObjectList::iterator jend = targets.end();
		
		while(jtr != jend)
		{
			target = GetMapMgr() ? GetMapMgr()->GetUnit(*jtr) : NULL;
			jtr2 = jtr;
			++jtr;

			if(GetDistanceSq(target) > radius)
			{
				target->RemoveAura(m_spellProto->Id);
				targets.erase(jtr2);
			}
		}

		m_aliveDuration -= 100;
	}
	else
	{
		m_aliveDuration = 0;
	}

	if(m_aliveDuration == 0)
	{
		Remove();
	}
}
Esempio n. 16
0
/*Loot type MUST be
1-corpse, go
2-skinning/herbalism/minning
3-Fishing
*/
void Player::SendLoot(uint64 guid,uint8 loot_type, uint32 mapid)
{
	Group * m_Group = m_playerInfo->m_Group;

	if( !IsInWorld() )
		return;

	Loot * pLoot = NULL;
	uint32 guidtype = GET_TYPE_FROM_GUID(guid);
	
	int8 loot_method;

	if( m_Group != NULL )
		loot_method = m_Group->GetMethod();
	else
		loot_method = PARTY_LOOT_FFA;

	if(guidtype == HIGHGUID_TYPE_UNIT)
	{
		Creature* pCreature = GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid));
		if(!pCreature)return;
		pLoot=&pCreature->loot;
		m_currentLoot = pCreature->GetGUID();
		
	}else if(guidtype == HIGHGUID_TYPE_GAMEOBJECT)
	{
		GameObject* pGO = GetMapMgr()->GetGameObject(GET_LOWGUID_PART(guid));
		if(!pGO)return;
		pGO->SetByte(GAMEOBJECT_BYTES_1, 0,0);
		pLoot=&pGO->loot;
		m_currentLoot = pGO->GetGUID();
	}
	else if((guidtype == HIGHGUID_TYPE_PLAYER) )
	{
		Player *p=GetMapMgr()->GetPlayer((uint32)guid);
		if(!p)return;
		pLoot=&p->loot;
		m_currentLoot = p->GetGUID();
	}
	else if( (guidtype == HIGHGUID_TYPE_CORPSE))
	{
		Corpse *pCorpse = objmgr.GetCorpse((uint32)guid);
		if(!pCorpse)return;
		pLoot=&pCorpse->loot;
		m_currentLoot = pCorpse->GetGUID();
	}
	else if( (guidtype == HIGHGUID_TYPE_ITEM) )
	{
		Item *pItem = GetItemInterface()->GetItemByGUID(guid);
		if(!pItem)
			return;
		pLoot = pItem->loot;
		m_currentLoot = pItem->GetGUID();
	}

	if(!pLoot)
	{
		// something whack happened.. damn cheaters..
		return;
	}

	// add to looter set
	pLoot->looters.insert( GetLowGUID() );

	WorldPacket data, data2(32);
	data.SetOpcode( SMSG_LOOT_RESPONSE );


	m_lootGuid = guid;


	data << uint64( guid );
	data << uint8( loot_type );//loot_type;
	data << uint32( pLoot->gold );
	data << uint8( 0 ); //loot size reserve


	std::vector<__LootItem>::iterator iter=pLoot->items.begin();
	uint32 count= 0;
	uint8 slottype = 0;

	for(uint32 x= 0;iter!=pLoot->items.end();iter++,x++)
	{
		if (iter->iItemsCount == 0)
			continue;

		LooterSet::iterator itr = iter->has_looted.find(GetLowGUID());
		if (iter->has_looted.end() != itr)
			continue;

		ItemPrototype* itemProto =iter->item.itemproto;
		if (!itemProto)
			continue;

		// check if it's on ML if so only quest items and ffa loot should be shown based on mob
		if ( loot_method == PARTY_LOOT_MASTER && m_Group && m_Group->GetLooter() != m_playerInfo )
			// pass on all ffa_loot and the grey / white items
			if ( !iter->ffa_loot && !(itemProto->Quality < m_Group->GetThreshold()) )
				continue;

		//quest items check. type 4/5
		//quest items that don't start quests.
        if((itemProto->Bonding == ITEM_BIND_QUEST) && !(itemProto->QuestId) && !HasQuestForItem(itemProto->ItemId))
            continue;
        if((itemProto->Bonding == ITEM_BIND_QUEST2) && !(itemProto->QuestId) && !HasQuestForItem(itemProto->ItemId))
            continue;

        //quest items that start quests need special check to avoid drops all the time.
        if((itemProto->Bonding == ITEM_BIND_QUEST) && (itemProto->QuestId) && GetQuestLogForEntry(itemProto->QuestId))
            continue;
        if((itemProto->Bonding == ITEM_BIND_QUEST2) && (itemProto->QuestId) && GetQuestLogForEntry(itemProto->QuestId))
            continue;

        if((itemProto->Bonding == ITEM_BIND_QUEST) && (itemProto->QuestId) && HasFinishedQuest(itemProto->QuestId))
            continue;
        if((itemProto->Bonding == ITEM_BIND_QUEST2) && (itemProto->QuestId) && HasFinishedQuest(itemProto->QuestId))
            continue;

        //check for starting item quests that need questlines.
        if((itemProto->QuestId && itemProto->Bonding != ITEM_BIND_QUEST && itemProto->Bonding != ITEM_BIND_QUEST2))
        {
            bool HasRequiredQuests = true;
            Quest * pQuest = QuestStorage.LookupEntry(itemProto->QuestId);
            if(pQuest)
            {
				uint32 finishedCount = 0;

                //check if its a questline.
                for(uint32 i = 0; i < pQuest->count_requiredquests; i++)
                {
                    if(pQuest->required_quests[i])
                    {
                        if(!HasFinishedQuest(pQuest->required_quests[i]) || GetQuestLogForEntry(pQuest->required_quests[i]))
                        {
							if (!(pQuest->quest_flags & QUEST_FLAG_ONLY_ONE_REQUIRED)) {
								HasRequiredQuests = false;
								break;
							}
						}
						else
						{
							finishedCount++;
						}
                    }
                }

				if (pQuest->quest_flags & QUEST_FLAG_ONLY_ONE_REQUIRED) {
					if (finishedCount == 0) continue;
				} else {
	                if(!HasRequiredQuests)
    	                continue;
				}
            }
        }

		slottype = 0;
		if(m_Group != NULL && loot_type < 2)
		{
			switch(loot_method)
			{
			case PARTY_LOOT_MASTER:
				slottype = 2;
				break;
			case PARTY_LOOT_GROUP:
			case PARTY_LOOT_RR:
			case PARTY_LOOT_NBG:
				slottype = 1;
				break;
			default:
				slottype = 0;
				break;
			}
			// only quality items are distributed
			if(itemProto->Quality < m_Group->GetThreshold())
			{
				slottype = 0;
			}

			// if all people passed anyone can loot it? :P
			if(iter->passed)
				slottype = 0;					// All players passed on the loot

			//if it is ffa loot and not an masterlooter
			if(iter->ffa_loot)
				slottype = 0;
		}

		data << uint8( x );
		data << uint32( itemProto->ItemId );
		data << uint32( iter->iItemsCount );//nr of items of this type
		data << uint32( iter->item.displayid );

        if(iter->iRandomSuffix)
		{
			data << uint32( Item::GenerateRandomSuffixFactor( itemProto ) );
			data << uint32( -int32( iter->iRandomSuffix->id ) );
		}
		else if(iter->iRandomProperty)
		{
			data << uint32( 0 );
			data << uint32( iter->iRandomProperty->ID );
		}
		else
		{
			data << uint32( 0 );
			data << uint32( 0 );
		}

		data << slottype;   // "still being rolled for" flag

		if(slottype == 1)
		{
			if(iter->roll == NULL && !iter->passed)
			{
				int32 ipid = 0;
				uint32 factor= 0;
				if(iter->iRandomProperty)
					ipid=iter->iRandomProperty->ID;
				else if(iter->iRandomSuffix)
				{
					ipid = -int32(iter->iRandomSuffix->id);
					factor=Item::GenerateRandomSuffixFactor(iter->item.itemproto);
				}

				if(iter->item.itemproto)
				{
					iter->roll = new LootRoll(60000, (m_Group != NULL ? m_Group->MemberCount() : 1),  guid, x, itemProto->ItemId, factor, uint32(ipid), GetMapMgr());

					data2.Initialize(SMSG_LOOT_START_ROLL);
					data2 << guid;
					data2 << uint32( mapid );
					data2 << uint32( x );
					data2 << uint32( itemProto->ItemId );
					data2 << uint32( factor );
					if(iter->iRandomProperty)
						data2 << uint32(iter->iRandomProperty->ID);
					else if(iter->iRandomSuffix)
						data2 << uint32( ipid );
					else
						data2 << uint32( 0 );

					data2 << uint32( iter->iItemsCount );
					data2 << uint32( 60000 );	// countdown
					data2 << uint8( 7 );		// some sort of flags that require research
				}

				Group * pGroup = m_playerInfo->m_Group;
				if(pGroup)
				{
					pGroup->Lock();
					for(uint32 i = 0; i < pGroup->GetSubGroupCount(); ++i)
					{
						for(GroupMembersSet::iterator itr2 = pGroup->GetSubGroup(i)->GetGroupMembersBegin(); itr2 != pGroup->GetSubGroup(i)->GetGroupMembersEnd(); ++itr2)
						{

                            PlayerInfo *pinfo = *itr2;

							if( pinfo->m_loggedInPlayer && pinfo->m_loggedInPlayer->GetItemInterface()->CanReceiveItem( itemProto, iter->iItemsCount ) == 0 )
							{
								if( pinfo->m_loggedInPlayer->m_passOnLoot )
									iter->roll->PlayerRolled( pinfo->m_loggedInPlayer, 3 );		// passed
								else
									pinfo->m_loggedInPlayer->SendPacket( &data2 );
							}
						}
					}
					pGroup->Unlock();
				}
				else
				{
					m_session->SendPacket(&data2);
				}
			}
		}
		count++;
	}
	data.wpos(13);
	data << uint8( count );

	m_session->SendPacket(&data);

	SetFlag( UNIT_FIELD_FLAGS, UNIT_FLAG_LOOTING );
}
Esempio n. 17
0
void Player::ModStanding(uint32 Faction, int32 Value)
{
	const int32 minReputation = -42000;      //   0/36000 Hated
	const int32 exaltedReputation = 42000;   //   0/1000  Exalted
	const int32 maxReputation = 42999;       // 999/1000  Exalted

	// WE ARE THE CHAMPIONS MY FRIENDS! WE KEEP ON FIGHTING 'TILL THE END!
	//
	// If we are in a lvl80 instance or heroic, or raid and we have a championing tabard on,
	// we get reputation after the faction determined by the worn tabard.
	if((GetMapMgr()->GetMapInfo()->minlevel == 80 ||
	        (GetMapMgr()->iInstanceMode == MODE_HEROIC &&
	         GetMapMgr()->GetMapInfo()->minlevel_heroic == 80)) &&
	        ChampioningFactionID != 0)
		Faction = ChampioningFactionID;

	FactionDBC* f = dbcFaction.LookupEntryForced(Faction);
	int32 newValue = Value;
	if(f == NULL || f->RepListId < 0)
		return;
	ReputationMap::iterator itr = m_reputation.find(Faction);

	if(itr == m_reputation.end())
	{
		if(newValue < minReputation)
			newValue = minReputation;
		else if(newValue > maxReputation)
			newValue = maxReputation;

		if(!AddNewFaction(f, newValue, false))
			return;

		itr = m_reputation.find(Faction);
#ifdef ENABLE_ACHIEVEMENTS
		if(itr->second->standing >= 42000)   // check if we are exalted now
			m_achievementMgr.UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GAIN_EXALTED_REPUTATION, 1, 0, 0);   // increment # of exalted

		m_achievementMgr.UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GAIN_REPUTATION, f->ID, itr->second->standing, 0);
#endif
		UpdateInrangeSetsBasedOnReputation();
		OnModStanding(f, itr->second);
	}
	else
	{
		if(pctReputationMod > 0)
		{
			newValue = Value + (Value * pctReputationMod / 100);
		}
		// Increment it.
		if(RankChanged(itr->second->standing, newValue))
		{
			itr->second->standing += newValue;
			UpdateInrangeSetsBasedOnReputation();
#ifdef ENABLE_ACHIEVEMENTS
			m_achievementMgr.UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GAIN_REPUTATION, f->ID, itr->second->standing, 0);
			if(itr->second->standing >= exaltedReputation) // check if we are exalted now
				m_achievementMgr.UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GAIN_EXALTED_REPUTATION, 1, 0, 0); // increment # of exalted
			else if(itr->second->standing - newValue >= exaltedReputation) // somehow we lost exalted status
				m_achievementMgr.UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GAIN_EXALTED_REPUTATION, -1, 0, 0); // decrement # of exalted
#endif
		}
		else
			itr->second->standing += newValue;

		if(itr->second->standing < minReputation)
			itr->second->standing = minReputation;
		else if(itr->second->standing > maxReputation)
			itr->second->standing = maxReputation;
		OnModStanding(f, itr->second);
	}
}
Esempio n. 18
0
void DynamicObject::UpdateTargets(uint32 p_time)
{
    Unit* u_caster = NULL;
    if(GUID_HIPART(casterGuid) == HIGHGUID_TYPE_GAMEOBJECT)
    {
        GameObject* goCaster = GetMapMgr()->GetGameObject(casterGuid);
        if(goCaster == NULL || !goCaster->IsInWorld())
            m_aliveDuration = 0; // Set alive duration to 0
        else if(goCaster->m_summoner)
            u_caster = goCaster->m_summoner;
    }
    else
    {
        u_caster = GetMapMgr()->GetUnit(casterGuid);
        if(u_caster == NULL || !u_caster->IsInWorld())
            m_aliveDuration = 0; // Set alive duration to 0
    }

    // If we're a channelled spell, we are required to be the caster channel target
    if(m_spellProto->IsChannelSpell() && u_caster)
    {
        if(u_caster->GetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT) != GetGUID())
            m_aliveDuration = 0;
    }

    if(m_aliveDuration > 0)
    {
        if(m_aliveDuration < p_time)
            m_aliveDuration = 0;
        else m_aliveDuration -= p_time;
    }

    if(m_aliveDuration && u_caster)
    {
        Aura* pAura;
        Unit* target;

        float radius = m_floatValues[DYNAMICOBJECT_RADIUS] * m_floatValues[DYNAMICOBJECT_RADIUS];

        // Looking for targets in the Object set
        for(std::unordered_set< Unit* >::iterator itr = m_unitsInRange.begin(); itr != m_unitsInRange.end(); ++itr)
        {
            target = *itr;
            if(!target->isAlive())
                continue;

            if(!sFactionSystem.isAttackable(u_caster, target, !(m_spellProto->c_is_flags & SPELL_FLAG_IS_TARGETINGSTEALTHED)))
                continue;

            // skip units already hit, their range will be tested later
            if(targets.find(target->GetGUID()) != targets.end())
                continue;

            if(GetDistanceSq(target) <= radius)
            {
                pAura = new Aura(m_spellProto, m_aliveDuration, u_caster, target);
                for(uint32 i = 0; i < 3; ++i)
                {
                    if(m_spellProto->Effect[i] == SPELL_EFFECT_PERSISTENT_AREA_AURA)
                    {
                        pAura->AddMod(m_spellProto->EffectApplyAuraName[i], m_spellProto->EffectBasePoints[i]+1, m_spellProto->EffectMiscValue[i], i);
                    }
                }

                target->AddAura(pAura);
                u_caster->HandleProc(PROC_ON_CAST_SPECIFIC_SPELL | PROC_ON_CAST_SPELL, NULL, target, m_spellProto);

                // add to target list
                targets.insert(target->GetGUID());
            }
        }

        // loop the targets, check the range of all of them
        DynamicObjectList::iterator jtr = targets.begin(), jtr2, jend = targets.end();
        while(jtr != jend)
        {
            jtr2 = jtr;
            ++jtr;

            target = GetMapMgr() ? GetMapMgr()->GetUnit(*jtr2) : NULL;
            if(target == NULL || GetDistanceSq(target) > radius)
            {
                if(target)
                    target->RemoveAura(m_spellProto->Id);
                targets.erase(jtr2);
            }
        }
    }
    else
    {
        // call remove here
        Remove();
    }
}