Beispiel #1
0
void Tutorial::handleDatabaseJobComplete(void* ref,swganh::database::DatabaseResult* result)
{
    TutorialQueryContainer* asyncContainer = reinterpret_cast<TutorialQueryContainer*>(ref);

    switch(asyncContainer->mQueryType)
    {
    case TutorialQuery_MainData:
    {
        swganh::database::DataBinding* binding = gWorldManager->getKernel()->GetDatabase()->createDataBinding(3);
        binding->addField(swganh::database::DFT_uint32,offsetof(Tutorial,mState),4,0);
        binding->addField(swganh::database::DFT_int32,offsetof(Tutorial,mSubState),4,1);
        binding->addField(swganh::database::DFT_bstring,offsetof(Tutorial,mStartingProfession),64,2);

        uint64 count = result->getRowCount();

        if (count == 1)
        {
            result->getNextRow(binding,this);
        }
        else if (count == 0)
        {
            // First time, no tutorial data saved.
            mSubState = 1;
            mState = 1;

            // Save the state.
            (gWorldManager->getKernel()->GetDatabase())->executeSqlAsync(0,0,"INSERT INTO %s.character_tutorial VALUES (%"PRIu64",%u,%u)",gWorldManager->getKernel()->GetDatabase()->galaxy(),asyncContainer->mId,mState, mSubState);
    
        }
        gWorldManager->getKernel()->GetDatabase()->destroyDataBinding(binding);

        // Here we go...
        this->startScript();
    }
    break;

    case TutorialQuery_PlanetLocation:
    {
        PlayerObject* player = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(asyncContainer->mId));
        if (player)
        {
            swganh::database::DataBinding* binding = gWorldManager->getKernel()->GetDatabase()->createDataBinding(4);
            TutorialStartingLocation startingLocation;

            binding->addField(swganh::database::DFT_uint32, offsetof(TutorialStartingLocation, destinationPlanet), 4, 0);
            binding->addField(swganh::database::DFT_float, offsetof(TutorialStartingLocation, destX), 4, 1);
            binding->addField(swganh::database::DFT_float, offsetof(TutorialStartingLocation, destY), 4, 2);
            binding->addField(swganh::database::DFT_float, offsetof(TutorialStartingLocation, destZ), 4, 3);

            result->getNextRow(binding, &startingLocation);

            startingLocation.destX += (gRandom->getRand()%5 - 2);
            startingLocation.destZ += (gRandom->getRand()%5 - 2);

            gMessageLib->sendClusterZoneTransferRequestByPosition(player,
                    glm::vec3(startingLocation.destX, startingLocation.destY, startingLocation.destZ),
                    startingLocation.destinationPlanet);

            // create waypoint at starting location.
            glm::vec3 position;
            position.x = startingLocation.destX;
            position.z = startingLocation.destZ;

            Datapad* datapad = player->getDataPad();

			std::string name("@ui:cpt_avatar_location");
			std::u16string name_u16(name.begin(), name.end());

            std::shared_ptr<WaypointObject> wp = datapad->getWaypointByName(name_u16);
            
			if(wp)
            {
				datapad->RemoveWaypoint(wp->getId());
            }
			
            datapad->requestNewWaypoint(name_u16, position, startingLocation.destinationPlanet, Waypoint_blue);

            //send starting emails
            sendStartingMails();
        }
        else
        {
        }
    }
    break;

    default:
    {
    }
    break;
    }
    delete asyncContainer;

}
void ObjectController::destroyObject(uint64 objectId)
{
	
	CreatureObject* creature  = dynamic_cast<CreatureObject*>(mObject); PlayerObject* playerObject = creature->GetGhost();
	Datapad*		datapad			= playerObject->getDataPad();
	Object*			object			= gWorldManager->getObjectById(objectId);

	auto equip_service = gWorldManager->getKernel()->GetServiceManager()->GetService<swganh::equipment::EquipmentService>("EquipmentService");
	auto inventory = dynamic_cast<Inventory*>(equip_service->GetEquippedObject(playerObject->GetCreature(), "inventory"));

	//could be a schematic!
	ManufacturingSchematic* schem	= datapad->getManufacturingSchematicById(objectId);

	if(schem != NULL)
	{
		//delete schematic
		datapad->removeManufacturingSchematic(objectId);

		//delete schematic object
		gObjectFactory->deleteObjectFromDB(schem);
		gMessageLib->sendDestroyObject(objectId,playerObject);

		return;
	}

	

	// or something else
	if(object == NULL)
	{
		DLOG(info) << "ObjController::destroyObject: could not find object " << objectId;
		return;
	}

	// waypoint
	if(object->getType() == ObjType_Waypoint)
	{
		// delete from db
		gObjectFactory->deleteObjectFromDB(object);
		
		if(!datapad)	{
			LOG(error) << "ObjectController::destroyObject cant get datapad to destroy waypoint : " << object->getId();
			return;
		}

		datapad->RemoveWaypoint(object->getId());

		//remove from grid and/or container
		gWorldManager->destroyObject(object);
		
	}

	//Inangible Objects
	if(object->getType() == ObjType_Intangible)
	{
		
		gObjectFactory->deleteObjectFromDB(object);
		
		//remove from grid and/or container
		gWorldManager->destroyObject(object);
		
	}


	// tangible
	else if(object->getType() == ObjType_Tangible)
	{
		TangibleObject* tangibleObject = dynamic_cast<TangibleObject*>(object);
		
		auto equip_service = gWorldManager->getKernel()->GetServiceManager()->GetService<swganh::equipment::EquipmentService>("EquipmentService");
		auto inventory = dynamic_cast<Inventory*>(equip_service->GetEquippedObject(playerObject->GetCreature(), "inventory"));

		// items
		if(Item* item = dynamic_cast<Item*>(tangibleObject))
		{
			// handle any family specifics
			switch(item->getItemFamily())
			{
				case ItemFamily_CraftingTools:	_handleDestroyCraftingTool(dynamic_cast<CraftingTool*>(item));	break;
				case ItemFamily_Instrument:		_handleDestroyInstrument(item);									break;

				default:break;
			}

		}
		
		
		// reset pending ui callbacks
		playerObject->resetUICallbacks(object);

		

		// delete from db CAVE :: mark if its an Object saved in the db!!!!
		// temporary placed instruments are not saved in the db
		gObjectFactory->deleteObjectFromDB(object);

		//remove from grid and/or container and/or World
		gWorldManager->destroyObject(object);
		
	}
}