Ejemplo n.º 1
0
void HouseFactory::handleObjectReady(Object* object,DispatchClient* client)
{
    //Perform checking on startup there is no client!
    // client will in all cases be NULL in this factory
    //if(!client)
    //	return;

    //add our cells
    InLoadingContainer* ilc = _getObject(object->getParentId());

    //Perform checking.
    if(!ilc)
    {
        gLogger->log(LogManager::NOTICE,"House creation failed (HouseFactory.cpp line 289)");
        return;
    }

    HouseObject*		house = dynamic_cast<HouseObject*>(ilc->mObject);

    //add hopper / new item to worldObjectlist, but NOT to the SI
    gWorldManager->addObject(object,true);

    //pondering whether to use the objectcontainer instead
    house->addCell(dynamic_cast<CellObject*>(object));

    if(house->getLoadCount() == (house->getCellList())->size())
    {
        if(!(_removeFromObjectLoadMap(house->getId())))
            gLogger->log(LogManager::NOTICE,"BuildingFactory: Failed removing object from loadmap");

        ilc->mOfCallback->handleObjectReady(house,ilc->mClient);

        mILCPool.free(ilc);
    }

}
Ejemplo n.º 2
0
void ObjectFactory::deleteObjectFromDB(Object* object)
{
	int8 sql[256];

	switch(object->getType())
	{
		case ObjType_Tangible:
		{
			TangibleObject* tangibleObject = dynamic_cast<TangibleObject*>(object);

			switch(tangibleObject->getTangibleGroup())
			{
				case TanGroup_Item:
				{
					Item* item = dynamic_cast<Item*>(object);
					if(item->getItemType() == ItemFamily_ManufacturingSchematic)
					{
						ManufacturingSchematic* schem = dynamic_cast<ManufacturingSchematic*> (object);
						//first associated item
						sprintf(sql,"DELETE FROM items WHERE id = %"PRIu64"",schem->getItem()->getId());
						mDatabase->ExecuteSqlAsync(NULL,NULL,sql);
						sprintf(sql,"DELETE FROM item_attributes WHERE item_id = %"PRIu64"",schem->getItem()->getId());
						mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

					}

					ObjectIDList* objectList		= item->getObjects();
					ObjectIDList::iterator objIt	= objectList->begin();

					while(objIt != objectList->end())
					{			
						Object* object = gWorldManager->getObjectById((*objIt));
						deleteObjectFromDB(object);
						
						++objIt;
					}

					sprintf(sql,"DELETE FROM items WHERE id = %"PRIu64"",object->getId());
					mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

					sprintf(sql,"DELETE FROM item_attributes WHERE item_id = %"PRIu64"",object->getId());
					mDatabase->ExecuteSqlAsync(NULL,NULL,sql);
				}
				break;

				case TanGroup_ResourceContainer:
				{
					sprintf(sql,"DELETE FROM resource_containers WHERE id = %"PRIu64"",object->getId());
					mDatabase->ExecuteSqlAsync(NULL,NULL,sql);
				}
				break;

				case TanGroup_Terminal:
				{
					sprintf(sql,"DELETE FROM terminals WHERE id = %"PRIu64"",object->getId());
					mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

				}
				break;

				default:break;
			}
		}
		break;

		case ObjType_Intangible:
		{
			IntangibleObject* itno = dynamic_cast<IntangibleObject*>(object);

			switch(itno->getItnoGroup())
			{
				case ItnoGroup_Vehicle:
				{
					sprintf(sql,"DELETE FROM vehicle_cutomization WHERE vehicles_id = %"PRIu64"",object->getId());
					mDatabase->ExecuteSqlAsync(NULL,NULL,sql);
					sprintf(sql,"DELETE FROM vehicle_attributes WHERE vehicles_id = %"PRIu64"",object->getId());
					mDatabase->ExecuteSqlAsync(NULL,NULL,sql);
					sprintf(sql,"DELETE FROM vehicles WHERE id = %"PRIu64"",object->getId());
					mDatabase->ExecuteSqlAsync(NULL,NULL,sql);
				}
				break;

				default: break;
			}
		}
		break;

		case ObjType_Cell:
		{
			CellObject* cell = dynamic_cast<CellObject*>(object);
			ObjectIDList* cellObjects		= cell->getObjects();
			ObjectIDList::iterator objIt	= cellObjects->begin();

			while(objIt != cellObjects->end())
			{
				Object* childObject = gWorldManager->getObjectById((*objIt));

				if(PlayerObject* player = dynamic_cast<PlayerObject*>(childObject))
				{
					//place the player in the world	and db	- do *NOT* delete him :P
					//player->setParentId(0,0xffffffff,player->getKnownPlayers(),true);
				}
				else
				if(CreatureObject* pet = dynamic_cast<CreatureObject*>(childObject))
				{
					//place the player in the world	and db	- do *NOT* delete him :P
					//pet->setParentId(0,0xffffffff,pet->getKnownPlayers(),true);
				}
				else
				{
					deleteObjectFromDB(childObject);
				}
				
				++objIt;

				sprintf(sql,"UPDATE characters SET parent_id = 0 WHERE parent_id = %"PRIu64"",object->getId());
				mDatabase->ExecuteSqlAsync(NULL,NULL,sql);
			}

			sprintf(sql,"DELETE FROM cells WHERE id = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);
		}
		break;

		case ObjType_Building:
		{
			//only delete when a playerbuilding
			HouseObject* house = dynamic_cast<HouseObject*>(object);
			if(!house)
			{
				//no player building
				return;
			}

			CellObjectList*				cellList	= house->getCellList();
			CellObjectList::iterator	cellIt		= cellList->begin();

			while(cellIt != cellList->end())
			{
				CellObject* cell = (*cellIt);
				deleteObjectFromDB(cell);
				//remove items in the building from world and db

				++cellIt;
			}

			sprintf(sql,"DELETE FROM houses WHERE ID = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

			//sprintf(sql,"DELETE FROM terminals WHERE ID = %"PRIu64"",object->getId());
			//mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

			sprintf(sql,"DELETE FROM structures WHERE ID = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

			//Admin / Hopper Lists
			sprintf(sql,"DELETE FROM structure_admin_data WHERE StructureID = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

			//update attributes cave redeed vs destroy
			sprintf(sql,"DELETE FROM structure_attributes WHERE Structure_id = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

		}
		break;
		case ObjType_Structure:
		{			

			//Harvester
			sprintf(sql,"DELETE FROM structures WHERE ID = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

			sprintf(sql,"DELETE FROM harvesters WHERE ID = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

			sprintf(sql,"DELETE FROM factories WHERE ID = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

			//Admin / Hopper Lists
			sprintf(sql,"DELETE FROM structure_admin_data WHERE StructureID = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

			//update attributes cave redeed vs destroy
			sprintf(sql,"DELETE FROM structure_attributes WHERE Structure_id = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

			//update hopper contents
			sprintf(sql,"DELETE FROM harvester_resources WHERE ID = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

		}
		break;

		case ObjType_Waypoint:
		{
			sprintf(sql,"DELETE FROM waypoints WHERE waypoint_id = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);
		}
		break;


		default:break;
	}
}