示例#1
0
Item *Container::SafeRemoveAndRetreiveItemFromSlot(int16 slot, bool destroy)
{
	if (slot < 0 || (uint32)slot >= GetProto()->ContainerSlots)
		return false;

	Item *pItem = m_Slot[slot];

	if (pItem == NULL || pItem==this) return NULL;
	m_Slot[slot] = NULL;

	if( pItem->GetOwner() == m_owner )
	{
		SetUInt64Value(CONTAINER_FIELD_SLOT_1  + slot*2, 0 );
		pItem->SetUInt64Value(ITEM_FIELD_CONTAINED, 0);

		if(destroy)
		{
			if(pItem->IsInWorld())
			{
				pItem->RemoveFromWorld();
			}
			pItem->DeleteFromDB();
		}
	}
	else
		pItem = NULL;

	return pItem;
}
示例#2
0
bool Container::AddItemToFreeSlot(Item *pItem, uint32 * r_slot)
{
	uint32 slot;
	for(slot = 0; slot < GetProto()->ContainerSlots; slot++)
	{
		if(!m_Slot[slot])
		{
			m_Slot[slot] = pItem;
			pItem->m_isDirty = true;

			pItem->SetUInt64Value(ITEM_FIELD_CONTAINED, GetGUID());
			pItem->SetOwner(m_owner);

			SetUInt64Value(CONTAINER_FIELD_SLOT_1  + (slot*2), pItem->GetGUID());

			if(m_owner->IsInWorld() && !pItem->IsInWorld())
			{
				pItem->PushToWorld(m_owner->GetMapMgr());
				ByteBuffer buf(2500);
				uint32 count = pItem->BuildCreateUpdateBlockForPlayer( &buf, m_owner );
				m_owner->PushCreationData(&buf, count);
			}
			if(r_slot)
				*r_slot = slot;
#ifdef ENABLE_ACHIEVEMENTS
			m_owner->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_OWN_ITEM, pItem->GetProto()->ItemId, pItem->GetUInt32Value(ITEM_FIELD_STACK_COUNT), 0);
#endif
			return true;
		}
	}
	return false;
}
示例#3
0
bool Corpse::Create(uint32 guidlow, Player* owner)
{
    ASSERT(owner);

    Relocate(owner->GetPositionX(), owner->GetPositionY(), owner->GetPositionZ(), owner->GetOrientation());

    if (!IsPositionValid())
    {
        TC_LOG_ERROR(LOG_FILTER_PLAYER, "Corpse (guidlow %d, owner %s) not created. Suggested coordinates isn't valid (X: %f Y: %f)",
            guidlow, owner->GetName().c_str(), owner->GetPositionX(), owner->GetPositionY());
        return false;
    }

    //we need to assign owner's map for corpse
    //in other way we will get a crash in Corpse::SaveToDB()
    SetMap(owner->GetMap());

    WorldObject::_Create(guidlow, HIGHGUID_CORPSE, owner->GetPhaseMask());

    SetObjectScale(1);
    SetUInt64Value(CORPSE_FIELD_OWNER, owner->GetGUID());

    _gridCoord = Trinity::ComputeGridCoord(GetPositionX(), GetPositionY());

    return true;
}
示例#4
0
文件: Corpse.cpp 项目: Choices/mangos
bool Corpse::Create( uint32 guidlow, Player *owner)
{
    MANGOS_ASSERT(owner);

    WorldObject::_Create(guidlow, HIGHGUID_CORPSE, owner->GetPhaseMask());
    Relocate(owner->GetPositionX(), owner->GetPositionY(), owner->GetPositionZ(), owner->GetOrientation());

    //we need to assign owner's map for corpse
    //in other way we will get a crash in Corpse::SaveToDB()
    SetMap(owner->GetMap());

    if(!IsPositionValid())
    {
        sLog.outError("Corpse (guidlow %d, owner %s) not created. Suggested coordinates isn't valid (X: %f Y: %f)",
            guidlow, owner->GetName(), owner->GetPositionX(), owner->GetPositionY());
        return false;
    }

    SetObjectScale(DEFAULT_OBJECT_SCALE);
    SetUInt64Value( CORPSE_FIELD_OWNER, owner->GetGUID() );

    m_grid = MaNGOS::ComputeGridPair(GetPositionX(), GetPositionY());

    return true;
}
示例#5
0
void Container::Create( uint32 itemid, Player *owner, ItemPrototype *proto )
{
	m_itemProto = proto;
	ASSERT(m_itemProto);

	SetUInt32Value( OBJECT_FIELD_ENTRY, itemid );
	SetUInt64Value( ITEM_FIELD_OWNER, owner->GetGUID() );
	SetUInt64Value( ITEM_FIELD_CONTAINED, owner->GetGUID() );
	SetUInt32Value( ITEM_FIELD_STACK_COUNT, 1 );
	SetUInt32Value( CONTAINER_FIELD_NUM_SLOTS, m_itemProto->ContainerSlots);

	m_Slot = new Item*[m_itemProto->ContainerSlots];
	memset(m_Slot, 0, sizeof(Item*)*(m_itemProto->ContainerSlots));

	m_owner = owner;
}
示例#6
0
bool DynamicObject::CreateDynamicObject(uint32 guidlow, Unit* caster, uint32 spellId, Position const& pos, float radius, DynamicObjectType type)
{
    SetMap(caster->GetMap());
    Relocate(pos);
    if (!IsPositionValid())
    {
        sLog->outError(LOG_FILTER_GENERAL, "DynamicObject (spell %u) not created. Suggested coordinates isn't valid (X: %f Y: %f)", spellId, GetPositionX(), GetPositionY());
        return false;
    }

    WorldObject::_Create(guidlow, HIGHGUID_DYNAMICOBJECT, caster->GetPhaseMask());

    SetEntry(spellId);
    SetObjectScale(1);
    SetUInt64Value(DYNAMICOBJECT_CASTER, caster->GetGUID());

    // The lower word of DYNAMICOBJECT_BYTES must be 0x0001. This value means that the visual radius will be overriden
    // by client for most of the "ground patch" visual effect spells and a few "skyfall" ones like Hurricane.
    // If any other value is used, the client will _always_ use the radius provided in DYNAMICOBJECT_RADIUS, but
    // precompensation is necessary (eg radius *= 2) for many spells. Anyway, blizz sends 0x0001 for all the spells
    // I saw sniffed...
    SetByteValue(DYNAMICOBJECT_BYTES, 0, type);
    SetUInt32Value(DYNAMICOBJECT_SPELLID, spellId);
    SetFloatValue(DYNAMICOBJECT_RADIUS, radius);
    SetUInt32Value(DYNAMICOBJECT_CASTTIME, getMSTime());

    if (IsWorldObject())
        setActive(true);    //must before add to map to be put in world container

    if (!GetMap()->AddToMap(this))
        return false;

    return true;
}
示例#7
0
bool DynamicObject::Create(uint32 guidlow, Unit *caster, uint32 spellId, const Position &pos, float radius, bool active)
{
    SetMap(caster->GetMap());
    Relocate(pos);
    if (!IsPositionValid())
    {
        sLog.outError("DynamicObject (spell %u) not created. Suggested coordinates isn't valid (X: %f Y: %f)",spellId,GetPositionX(),GetPositionY());
        return false;
    }

    WorldObject::_Create(guidlow, HIGHGUID_DYNAMICOBJECT, caster->GetPhaseMask());

    SetEntry(spellId);
    SetFloatValue(OBJECT_FIELD_SCALE_X, 1);
    SetUInt64Value(DYNAMICOBJECT_CASTER, caster->GetGUID());

    // The lower word of DYNAMICOBJECT_BYTES must be 0x0001. This value means that the visual radius will be overriden
    // by client for most of the "ground patch" visual effect spells and a few "skyfall" ones like Hurricane.
    // If any other value is used, the client will _always_ use the radius provided in DYNAMICOBJECT_RADIUS, but
    // precompensation is necessary (eg radius *= 2) for many spells. Anyway, blizz sends 0x0001 for all the spells
    // I saw sniffed...
    SetUInt32Value(DYNAMICOBJECT_BYTES, 0x00000001);
    SetUInt32Value(DYNAMICOBJECT_SPELLID, spellId);
    SetFloatValue(DYNAMICOBJECT_RADIUS, radius);
    SetUInt32Value(DYNAMICOBJECT_CASTTIME, getMSTime());

    m_isWorldObject = active;
    return true;
}
示例#8
0
bool Container::AddItemToFreeSlot(Item *pItem, uint32 * r_slot)
{
	uint32 slot;
	for(slot = 0; slot < GetProto()->ContainerSlots; slot++)
	{
		if(!m_Slot[slot])
		{
			m_Slot[slot] = pItem;
			pItem->m_isDirty = true;

			pItem->SetUInt64Value(ITEM_FIELD_CONTAINED, GetGUID());
			pItem->SetOwner(m_owner);

			SetUInt64Value(CONTAINER_FIELD_SLOT_1  + (slot*2), pItem->GetGUID());

			if(m_owner->IsInWorld() && !pItem->IsInWorld())
			{
				pItem->PushToWorld(m_owner->GetMapMgr());
				ByteBuffer buf(2500);
				uint32 count = pItem->BuildCreateUpdateBlockForPlayer( &buf, m_owner );
				m_owner->PushCreationData(&buf, count);
			}
			if(r_slot)
				*r_slot = slot;
			return true;
		}
	}
	return false;
}
示例#9
0
bool Corpse::Create( uint32 guidlow, Player *owner)
{
    SetInstanceId(owner->GetInstanceId());

    WorldObject::_Create(guidlow, HIGHGUID_CORPSE, owner->GetMapId(), owner->GetPhaseMask());

    Relocate(owner->GetPositionX(), owner->GetPositionY(), owner->GetPositionZ(), owner->GetOrientation());

    if(!IsPositionValid())
    {
        sLog.outError("Corpse (guidlow %d, owner %s) not created. Suggested coordinates isn't valid (X: %f Y: %f)",
            guidlow,owner->GetName(),owner->GetPositionX(), owner->GetPositionY());
        return false;
    }

    SetFloatValue( OBJECT_FIELD_SCALE_X, 1 );
    SetFloatValue( CORPSE_FIELD_POS_X, GetPositionX() );
    SetFloatValue( CORPSE_FIELD_POS_Y, GetPositionY() );
    SetFloatValue( CORPSE_FIELD_POS_Z, GetPositionZ() );
    SetFloatValue( CORPSE_FIELD_FACING, GetOrientation() );
    SetUInt64Value( CORPSE_FIELD_OWNER, owner->GetGUID() );

    m_grid = Quad::ComputeGridPair(GetPositionX(), GetPositionY());

    return true;
}
示例#10
0
bool DynamicObject::Create( uint32 guidlow, Unit *caster, uint32 spellId, uint32 effIndex, float x, float y, float z, int32 duration, float radius )
{
    SetInstanceId(caster->GetInstanceId());

    WorldObject::_Create(guidlow, HIGHGUID_DYNAMICOBJECT, caster->GetMapId());
    Relocate(x,y,z,0);

    if(!IsPositionValid())
    {
        sLog.outError("ERROR: DynamicObject (spell %u eff %u) not created. Suggested coordinates isn't valid (X: %f Y: %f)",spellId,effIndex,GetPositionX(),GetPositionY());
        return false;
    }

    SetEntry(spellId);
    SetFloatValue( OBJECT_FIELD_SCALE_X, 1 );
    SetUInt64Value( DYNAMICOBJECT_CASTER, caster->GetGUID() );
    SetUInt32Value( DYNAMICOBJECT_BYTES, 0x00000001 );
    SetUInt32Value( DYNAMICOBJECT_SPELLID, spellId );
    SetFloatValue( DYNAMICOBJECT_RADIUS, radius);
    SetFloatValue( DYNAMICOBJECT_POS_X, x );
    SetFloatValue( DYNAMICOBJECT_POS_Y, y );
    SetFloatValue( DYNAMICOBJECT_POS_Z, z );
    SetUInt32Value( DYNAMICOBJECT_CASTTIME, getMSTime() );  // new 2.4.0

    m_aliveDuration = duration;
    m_radius = radius;
    m_effIndex = effIndex;
    m_spellId = spellId;
    m_casterGuid = caster->GetGUID();
    m_updateTimer = 0;
    return true;
}
示例#11
0
文件: Corpse.cpp 项目: Chero/abcwow
void Corpse::Delink()
{
	SetUInt32Value(CORPSE_FIELD_FLAGS,5);
	SetUInt64Value(CORPSE_FIELD_OWNER,0);
	SetCorpseState(CORPSE_STATE_BONES);
	DeleteFromDB();
}
示例#12
0
void DynamicObject::Create(Object* caster, Spell* pSpell, float x, float y, float z, uint32 duration, float radius)
{
	Object::_Create(caster->GetMapId(),x, y, z, 0);
	if(pSpell->g_caster)
		m_parentSpell = pSpell;

	m_caster = caster;
	switch(caster->GetTypeId())
	{
	case TYPEID_GAMEOBJECT:
		{
			p_caster = pSpell->p_caster;
			u_caster = pSpell->u_caster;
			if(!u_caster && p_caster)
				u_caster = TO_UNIT(p_caster);

			g_caster = TO_GAMEOBJECT(caster);
		}break;
	case TYPEID_UNIT:
		{
			u_caster = TO_UNIT(caster);
		}break;
	case TYPEID_PLAYER:
		{
			p_caster = TO_PLAYER(caster);
			u_caster = TO_UNIT(caster);
		}break;
	}

	m_spellProto = pSpell->m_spellInfo;
	SetUInt64Value(DYNAMICOBJECT_CASTER, caster->GetGUID());

	m_uint32Values[OBJECT_FIELD_ENTRY] = m_spellProto->Id;
	m_uint32Values[DYNAMICOBJECT_BYTES] = 0x01eeeeee;
	m_uint32Values[DYNAMICOBJECT_SPELLID] = m_spellProto->Id;

	m_floatValues[DYNAMICOBJECT_RADIUS] = radius;
	m_position.x = x;
	m_position.y = y;
	m_position.z = z;
	m_uint32Values[DYNAMICOBJECT_CASTTIME] = (uint32)UNIXTIME;

	m_aliveDuration = duration;
	m_faction = caster->m_faction;
	m_factionDBC = caster->m_factionDBC;
	if(caster->dynObj != 0)
	{
		// expire next update
		caster->dynObj->m_aliveDuration = 1;
		caster->dynObj->UpdateTargets();
	}
	caster->dynObj = TO_DYNAMICOBJECT(this);

	PushToWorld(caster->GetMapMgr());

	sEventMgr.AddEvent(TO_DYNAMICOBJECT(this), &DynamicObject::UpdateTargets, EVENT_DYNAMICOBJECT_UPDATE, 200, 0,EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT);
}
示例#13
0
void Bag::RemoveItem(uint8 slot, bool /*update*/) {
	ASSERT(slot < MAX_BAG_SIZE);

	if (m_bagslot[slot])
		m_bagslot[slot]->SetContainer(NULL);

	m_bagslot[slot] = NULL;
	SetUInt64Value(CONTAINER_FIELD_SLOT_1 + (slot * 2), 0);
}
示例#14
0
文件: Item.cpp 项目: Artea/mangos-svn
void Item::Create( uint32 guidlow, uint32 itemid, Player *owner )
{
    Object::_Create( guidlow, HIGHGUID_ITEM );

    SetUInt32Value( OBJECT_FIELD_ENTRY, itemid );
    SetFloatValue( OBJECT_FIELD_SCALE_X, 1.0f );

    SetUInt64Value( ITEM_FIELD_OWNER, owner->GetGUID() );
    SetUInt64Value( ITEM_FIELD_CONTAINED, owner->GetGUID() );
    SetUInt32Value( ITEM_FIELD_STACK_COUNT, 1 );

    m_itemProto = objmgr.GetItemPrototype( itemid );
    ASSERT(m_itemProto);

    //for(int i=5;i<m_valuesCount;i++)
    //     SetUInt32Value( i, 1 );

    SetUInt32Value( ITEM_FIELD_MAXDURABILITY, m_itemProto->MaxDurability);
    SetUInt32Value( ITEM_FIELD_DURABILITY, m_itemProto->MaxDurability);
/*
    ITEM_FIELD_OWNER                        =    6,  //  2  UINT64
    ITEM_FIELD_CONTAINED                    =    8,  //  2  UINT64
    ITEM_FIELD_CREATOR                      =   10,  //  2  UINT64
    ITEM_FIELD_GIFTCREATOR                  =   12,  //  2  UINT64
    ITEM_FIELD_STACK_COUNT                  =   14,  //  1  UINT32
    ITEM_FIELD_DURATION                     =   15,  //  1  UINT32
    ITEM_FIELD_SPELL_CHARGES                =   16,  //  5  SPELLCHARGES
    ITEM_FIELD_FLAGS                        =   21,  //  1  UINT32
    ITEM_FIELD_ENCHANTMENT                  =   22,  //  21 ENCHANTMENT
    ITEM_FIELD_PROPERTY_SEED                =   43,  //  1  UINT32
    ITEM_FIELD_RANDOM_PROPERTIES_ID         =   44,  //  1  UINT32
    ITEM_FIELD_ITEM_TEXT_ID                 =   45,  //  1  UINT32
    ITEM_FIELD_DURABILITY                   =   46,  //  1  UINT32
    ITEM_FIELD_MAXDURABILITY                =   47,  //  1  UINT32
*/
    SetUInt32Value( ITEM_FIELD_SPELL_CHARGES, m_itemProto->SpellCharges[0]);
    SetUInt32Value( ITEM_FIELD_SPELL_CHARGES+1, m_itemProto->SpellCharges[1]);
    SetUInt32Value( ITEM_FIELD_SPELL_CHARGES+2, m_itemProto->SpellCharges[2]);
    SetUInt32Value( ITEM_FIELD_SPELL_CHARGES+3, m_itemProto->SpellCharges[3]);
    SetUInt32Value( ITEM_FIELD_SPELL_CHARGES+4, m_itemProto->SpellCharges[4]);
    SetUInt32Value( ITEM_FIELD_FLAGS, m_itemProto->Flags);
    SetUInt32Value( ITEM_FIELD_ITEM_TEXT_ID, m_itemProto->DisplayInfoID);
    m_owner = owner;
}
示例#15
0
文件: Item.cpp 项目: Artea/mangos-svn
void Item::Create( uint32 guidlow, uint32 itemid, Player *owner )
{
    Object::_Create( guidlow, HIGHGUID_ITEM );

    SetUInt32Value( OBJECT_FIELD_ENTRY, itemid );
    SetFloatValue( OBJECT_FIELD_SCALE_X, 1.0f );

    SetUInt64Value( ITEM_FIELD_OWNER, owner->GetGUID() );
    SetUInt64Value( ITEM_FIELD_CONTAINED, owner->GetGUID() );
    SetUInt32Value( ITEM_FIELD_STACK_COUNT, 1 );

    m_itemProto = objmgr.GetItemPrototype( itemid );
    ASSERT(m_itemProto);

    SetUInt32Value( ITEM_FIELD_MAXDURABILITY, m_itemProto->MaxDurability);
    SetUInt32Value( ITEM_FIELD_DURABILITY, m_itemProto->MaxDurability);

    m_owner = owner;
}
示例#16
0
void Totem::SetOwner(uint64 guid)
{
    SetUInt64Value(UNIT_FIELD_SUMMONEDBY, guid);
    Unit *owner = this->GetOwner();
    if (owner)
    {
        this->setFaction(owner->getFaction());
        this->SetLevel(owner->getLevel());
    }
}
示例#17
0
void Container::Create( uint32 itemid, Player* owner )
{

	m_itemProto = ItemPrototypeStorage.LookupEntry( itemid );
	ASSERT(m_itemProto);

	SetUInt32Value( OBJECT_FIELD_ENTRY, itemid );

	// TODO: this shouldnt get NULL form containers in mail fix me
	if( owner != NULL )
	{
		SetUInt64Value( ITEM_FIELD_OWNER, owner->GetGUID() );
		SetUInt64Value( ITEM_FIELD_CONTAINED, owner->GetGUID() );
	}
	SetUInt32Value( ITEM_FIELD_STACK_COUNT, 1 );
	SetUInt32Value( CONTAINER_FIELD_NUM_SLOTS, m_itemProto->ContainerSlots);

	m_owner = owner;
}
示例#18
0
void Container::Create( uint32 guidlow, uint32 itemid, Player *owner )
{
    Object::_Create( guidlow, HIGHGUID_CONTAINER );

    m_itemProto = objmgr.GetItemPrototype( itemid );
    ASSERT(m_itemProto);

    SetUInt32Value( OBJECT_FIELD_ENTRY, itemid );
    SetFloatValue( OBJECT_FIELD_SCALE_X, 1.0f );
    SetUInt64Value( ITEM_FIELD_OWNER, owner->GetGUID() );
    SetUInt64Value( ITEM_FIELD_CONTAINED, owner->GetGUID() );
    SetUInt32Value( ITEM_FIELD_STACK_COUNT, 1 );
    SetUInt32Value( CONTAINER_FIELD_NUM_SLOTS, m_itemProto->ContainerSlots);

    m_Slot = new Item*[m_itemProto->ContainerSlots];
    memset(m_Slot, 0, sizeof(Item*)*(m_itemProto->ContainerSlots));

    m_owner = owner;
}
示例#19
0
void Corpse::Create(Player *owner, uint32 mapid, float x, float y, float z, float ang)
{
    Object::_Create(mapid, x, y, z, ang);

    SetFloatValue(CORPSE_FIELD_POS_X, x);
    SetFloatValue(CORPSE_FIELD_POS_Y, y);
    SetFloatValue(CORPSE_FIELD_POS_Z, z);
    SetFloatValue(CORPSE_FIELD_FACING, ang);
    SetUInt64Value(CORPSE_FIELD_OWNER, owner->GetGUID());
    _loadedfromdb = false;  // can't be created from db ;)
}
示例#20
0
bool Corpse::LoadFromDB(uint32 guid, Field *fields)
{
    //                                          0          1          2          3           4   5    6    7           8        9
    //result = CharacterDatabase.PQuery("SELECT position_x,position_y,position_z,orientation,map,data,time,corpse_type,instance,phaseMask FROM corpse WHERE guid = '%u'",guid);
    float positionX = fields[0].GetFloat();
    float positionY = fields[1].GetFloat();
    float positionZ = fields[2].GetFloat();
    float ort       = fields[3].GetFloat();
    uint32 mapid    = fields[4].GetUInt32();

    Object::_Create(guid, 0, HIGHGUID_CORPSE);

    if(!LoadValues( fields[5].GetString() ))
    {
        sLog.outError("Corpse #%d have broken data in `data` field. Can't be loaded.",guid);
        return false;
    }

    m_time = time_t(fields[6].GetUInt64());
    m_type = CorpseType(fields[7].GetUInt32());

    if(m_type >= MAX_CORPSE_TYPE)
    {
        sLog.outError("Corpse (guidlow %d, owner %d) have wrong corpse type, not load.",GetGUIDLow(),GUID_LOPART(GetOwnerGUID()));
        return false;
    }

    if(m_type != CORPSE_BONES)
        m_isWorldObject = true;

    uint32 instanceid  = fields[8].GetUInt32();

    uint32 phaseMask   = fields[9].GetUInt32();

    // overwrite possible wrong/corrupted guid
    SetUInt64Value(OBJECT_FIELD_GUID, MAKE_NEW_GUID(guid, 0, HIGHGUID_CORPSE));

    // place
    SetLocationInstanceId(instanceid);
    SetLocationMapId(mapid);
    SetPhaseMask(phaseMask, false);
    Relocate(positionX, positionY, positionZ, ort);

    if(!IsPositionValid())
    {
        sLog.outError("Corpse (guidlow %d, owner %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",
            GetGUIDLow(), GUID_LOPART(GetOwnerGUID()), GetPositionX(), GetPositionY());
        return false;
    }

    m_grid = Trinity::ComputeGridPair(GetPositionX(), GetPositionY());

    return true;
}
示例#21
0
void Corpse::SetOwner(uint64 guid)
{
	SetUInt64Value(CORPSE_FIELD_OWNER, guid);
	if(guid == 0)
	{
		//notify the MapCell that the Corpse has no more an owner so the MapCell can go idle (if there's nothing else)
		MapCell* cell = GetMapCell();
		if(cell != NULL)
			cell->CorpseGoneIdle(this);
	}
}
示例#22
0
文件: Bag.cpp 项目: Artea/mangos-svn
void Bag::StoreItem( uint8 slot, Item *pItem, bool update )
{
    if( pItem )
    {
        m_bagslot[slot] = pItem;
        SetUInt64Value(CONTAINER_FIELD_SLOT_1 + (slot * 2), pItem->GetGUID());
        pItem->SetUInt64Value(ITEM_FIELD_CONTAINED, GetGUID());
        pItem->SetUInt64Value( ITEM_FIELD_OWNER, GetOwnerGUID() );
        pItem->SetSlot( NULL_SLOT );
    }
}
示例#23
0
bool Corpse::LoadFromDB(uint32 guid, Field *fields) {
	//        0     1     2     3            4      5          6          7       8       9      10        11    12          13          14         15          16
	// SELECT posX, posY, posZ, orientation, mapId, displayId, itemCache, bytes1, bytes2, flags, dynFlags, time, corpseType, instanceId, phaseMask, corpseGuid, guid FROM corpse WHERE corpseType <> 0
	uint32 ownerGuid = fields[16].GetUInt32();
	m_type = CorpseType(fields[12].GetUInt8());
	if (m_type >= MAX_CORPSE_TYPE) {
		sLog->outError(
				"Corpse (guid: %u, owner: %u) have wrong corpse type (%u), not loading.",
				guid, ownerGuid, m_type);
		return false;
	}
	if (m_type != CORPSE_BONES)
		m_isWorldObject = true;

	float posX = fields[0].GetFloat();
	float posY = fields[1].GetFloat();
	float posZ = fields[2].GetFloat();
	float o = fields[3].GetFloat();
	uint32 mapId = fields[4].GetUInt16();

	Object::_Create(guid, 0, HIGHGUID_CORPSE);

	SetUInt32Value(CORPSE_FIELD_DISPLAY_ID, fields[5].GetUInt32());
	_LoadIntoDataField(fields[6].GetCString(), CORPSE_FIELD_ITEM,
			EQUIPMENT_SLOT_END);
	SetUInt32Value(CORPSE_FIELD_BYTES_1, fields[7].GetUInt32());
	SetUInt32Value(CORPSE_FIELD_BYTES_2, fields[8].GetUInt32());
	SetUInt32Value(CORPSE_FIELD_FLAGS, fields[9].GetUInt8());
	SetUInt32Value(CORPSE_FIELD_DYNAMIC_FLAGS, fields[10].GetUInt8());
	SetUInt64Value(CORPSE_FIELD_OWNER,
			MAKE_NEW_GUID(ownerGuid, 0, HIGHGUID_PLAYER));

	m_time = time_t(fields[11].GetUInt32());

	uint32 instanceId = fields[13].GetUInt32();
	uint32 phaseMask = fields[14].GetUInt16();

	// place
	SetLocationInstanceId(instanceId);
	SetLocationMapId(mapId);
	SetPhaseMask(phaseMask, false);
	Relocate(posX, posY, posZ, o);

	if (!IsPositionValid()) {
		sLog->outError(
				"Corpse (guid: %u, owner: %u) is not created, given coordinates are not valid (X: %f, Y: %f, Z: %f)",
				GetGUIDLow(), GUID_LOPART(GetOwnerGUID()), posX, posY, posZ);
		return false;
	}

	m_grid = Trinity::ComputeGridPair(GetPositionX(), GetPositionY());
	return true;
}
示例#24
0
void Bag::StoreItem(uint8 slot, Item *pItem, bool /*update*/) {
	ASSERT(slot < MAX_BAG_SIZE);

	if (pItem && pItem->GetGUID() != this->GetGUID()) {
		m_bagslot[slot] = pItem;
		SetUInt64Value(CONTAINER_FIELD_SLOT_1 + (slot * 2), pItem->GetGUID());
		pItem->SetUInt64Value(ITEM_FIELD_CONTAINED, GetGUID());
		pItem->SetUInt64Value(ITEM_FIELD_OWNER, GetOwnerGUID());
		pItem->SetContainer(this);
		pItem->SetSlot(slot);
	}
}
示例#25
0
文件: Bag.cpp 项目: Artea/mangos-svn
bool Bag::LoadFromDB(uint32 guid, uint64 owner_guid)
{
    if(!Item::LoadFromDB(guid, owner_guid))
        return false;

    // cleanup bag content related item value fields (its will be filled correctly from `character_inventory`)
    for (uint32 i = 0; i < GetProto()->ContainerSlots; i++)
    {
        SetUInt64Value(CONTAINER_FIELD_SLOT_1 + (i*2), 0);
        if (m_bagslot[i])
        {
            delete m_bagslot[i];
            m_bagslot[i] = NULL;
        }
    }

    if(!IsInBag())                                          // equiped bag
    {
        QueryResult *result = sDatabase.PQuery("SELECT `slot`,`item`,`item_template` FROM `character_inventory` WHERE `guid` = '%u' AND `bag` = '%u'", GUID_LOPART(GetOwnerGUID()), GetGUIDLow());

        if (result)
        {
            do
            {
                Field *fields = result->Fetch();
                uint8  slot      = fields[0].GetUInt8();
                uint32 item_guid = fields[1].GetUInt32();
                uint32 item_id   = fields[2].GetUInt32();

                ItemPrototype const *proto = objmgr.GetItemPrototype(item_id);

                if(!proto)
                {
                    sLog.outError( "Bag::LoadFromDB: Player %d have unknown item (id: #%u) in bag #%u, skipped.", GUID_LOPART(GetOwnerGUID()), item_id, GetSlot());
                    continue;
                }

                Item *item = NewItemOrBag(proto);
                item->SetSlot(NULL_SLOT);
                if(!item->LoadFromDB(item_guid, owner_guid))
                {
                    delete item;
                    continue;
                }
                StoreItem( slot, item, true );
                item->SetState(ITEM_UNCHANGED);
            } while (result->NextRow());

            delete result;
        }
    }
    return true;
}
示例#26
0
文件: Corpse.cpp 项目: ice74/blizzwow
bool Corpse::LoadFromDB(uint32 guid, Field *fields)
{
    //                0           1           2            3    4          5          6       7       8      9     10        11    12           13        14         15    16      17
    //SELECT position_x, position_y, position_z, orientation, map, displayId, itemCache, bytes1, bytes2, guild, flags, dynFlags, time, corpse_type, instance, phaseMask, guid, player FROM corpse WHERE corpse_type <> 0
    float positionX = fields[0].GetFloat();
    float positionY = fields[1].GetFloat();
    float positionZ = fields[2].GetFloat();
    float ort       = fields[3].GetFloat();
    uint32 mapid    = fields[4].GetUInt32();

    Object::_Create(guid, 0, HIGHGUID_CORPSE);

    SetUInt32Value(CORPSE_FIELD_DISPLAY_ID, fields[5].GetUInt32());
    _LoadIntoDataField(fields[6].GetCString(), CORPSE_FIELD_ITEM, EQUIPMENT_SLOT_END);
    SetUInt32Value(CORPSE_FIELD_BYTES_1, fields[7].GetUInt32());
    SetUInt32Value(CORPSE_FIELD_BYTES_2, fields[8].GetUInt32());
    SetUInt32Value(CORPSE_FIELD_GUILD, fields[9].GetUInt32());
    SetUInt32Value(CORPSE_FIELD_FLAGS, fields[10].GetUInt32());
    SetUInt32Value(CORPSE_FIELD_DYNAMIC_FLAGS, fields[11].GetUInt32());
    SetUInt64Value(CORPSE_FIELD_OWNER, MAKE_NEW_GUID(fields[17].GetUInt32(), 0, HIGHGUID_PLAYER));

    m_time = time_t(fields[12].GetUInt64());
    m_type = CorpseType(fields[13].GetUInt32());

    if (m_type >= MAX_CORPSE_TYPE)
    {
        sLog.outError("Corpse (guidlow %d, owner %d) have wrong corpse type, not load.",GetGUIDLow(),GUID_LOPART(GetOwnerGUID()));
        return false;
    }

    if (m_type != CORPSE_BONES)
        m_isWorldObject = true;

    uint32 instanceid  = fields[14].GetUInt32();
    uint32 phaseMask   = fields[15].GetUInt32();

    // place
    SetLocationInstanceId(instanceid);
    SetLocationMapId(mapid);
    SetPhaseMask(phaseMask, false);
    Relocate(positionX, positionY, positionZ, ort);

    if (!IsPositionValid())
    {
        sLog.outError("Corpse (guidlow %d, owner %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",
            GetGUIDLow(), GUID_LOPART(GetOwnerGUID()), GetPositionX(), GetPositionY());
        return false;
    }

    m_grid = Trinity::ComputeGridPair(GetPositionX(), GetPositionY());
    return true;
}
示例#27
0
void Creature::ChannelLinkUpCreature(uint32 SqlId)
{
	if(!m_mapMgr)		// shouldnt happen
		return;

	Creature * go = m_mapMgr->GetSqlIdCreature(SqlId);
	if(go != 0)
	{
		event_RemoveEvents(EVENT_CREATURE_CHANNEL_LINKUP);
		SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT, go->GetGUID());
		SetUInt32Value(UNIT_CHANNEL_SPELL, m_spawn->channel_spell);
	}
}
示例#28
0
void DynamicObject::Create(Unit * caster, Spell * pSpell, float x, float y, float z, uint32 duration, float radius)
{
	Object::_Create(caster->GetMapId(),x, y, z, 0);
	if(pSpell->g_caster)
	{
		m_parentSpell = pSpell;
	}

	if(pSpell->m_spellScript != NULL)
		pSpell->m_spellScript->AddRef(this);

	if( pSpell->p_caster == NULL )
	{
		// try to find player caster here
		if( caster->IsPlayer() )
			p_caster = static_cast<Player*>( caster );
	}
	else
		p_caster = pSpell->p_caster;

	m_spellProto = pSpell->GetProto();
	SetUInt64Value(DYNAMICOBJECT_CASTER, caster->GetGUID());

	m_uint32Values[OBJECT_FIELD_ENTRY] = m_spellProto->Id;
	m_uint32Values[DYNAMICOBJECT_BYTES] = 0x01eeeeee;
	m_uint32Values[DYNAMICOBJECT_SPELLID] = m_spellProto->Id;

	m_floatValues[DYNAMICOBJECT_RADIUS] = radius;
	m_floatValues[DYNAMICOBJECT_POS_X]  = x;
	m_floatValues[DYNAMICOBJECT_POS_Y]  = y;
	m_floatValues[DYNAMICOBJECT_POS_Z]  = z;

	m_aliveDuration = duration;
	u_caster = caster;
	m_faction = caster->m_faction;
	m_factionDBC = caster->m_factionDBC;

	if(pSpell->g_caster)
		PushToWorld(pSpell->g_caster->GetMapMgr());
	else 
		PushToWorld(caster->GetMapMgr());

	if(caster->dynObj != NULL)
	{
		//expires
		caster->dynObj->Remove();
	}
	caster->dynObj = this;
  
	sEventMgr.AddEvent(this, &DynamicObject::UpdateTargets, EVENT_DYNAMICOBJECT_UPDATE, 100, 0,EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT);
}
示例#29
0
void Corpse::SpawnBones()
{
    SetUInt32Value(CORPSE_FIELD_FLAGS, 5);
    SetUInt64Value(CORPSE_FIELD_OWNER, 0); // remove corpse owner association
    //remove item association
    for (int i = 0; i < EQUIPMENT_SLOT_END; i++)
    {
        if (GetUInt32Value(CORPSE_FIELD_ITEM + i))
            SetUInt32Value(CORPSE_FIELD_ITEM + i, 0);
    }
    DeleteFromDB();
    objmgr.CorpseAddEventDespawn(this);
    SetCorpseState(CORPSE_STATE_BONES);
}
示例#30
0
bool Item::Create(uint32 guidlow, uint32 itemid, Player* owner)
{
	sLog.outDebug("ITEM: Create guidlow %u, itemid %u, owner %u", guidlow, itemid, owner->GetGUID());

	Object::_Create(guidlow, HIGHGUID_ITEM);

	SetUInt32Value(OBJECT_FIELD_ENTRY, itemid);

	SetUInt64Value(ITEM_FIELD_OWNER, owner ? owner->GetGUID() : 0);
	SetUInt64Value(ITEM_FIELD_CONTAINED, owner ? owner->GetGUID() : 0);

	ItemPrototype const *itemProto = objmgr.GetItemPrototype(itemid);

	if(!itemProto)
		return false;

	SetUInt32Value(ITEM_FIELD_STACK_COUNT, 1);

	//SetUInt32Value(ITEM_FIELD_FLAGS, itemProto->Flags);
	//SetUInt32Value(ITEM_FIELD_DURATION, abs(itemProto->Duration));

	return true;
}