void ObjectController::_handleFindFriendDBReply(uint64 retCode,string friendName) { PlayerObject* player = dynamic_cast<PlayerObject*>(mObject); friendName.convert(BSTRType_Unicode16); if(retCode == 0) { gMessageLib->sendSystemMessage(player,L"","cmnty","friend_location_failed_noname","","",L"",0,"","",friendName.getUnicode16()); return; } PlayerObject* searchObject = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(retCode)); if(!searchObject) { gMessageLib->sendSystemMessage(player,L"","cmnty","friend_location_failed","","",L"",0,"","",friendName.getUnicode16()); return; } //are we on our targets friendlist??? if(!searchObject->checkFriendList(player->getFirstName().getCrc())) { gMessageLib->sendSystemMessage(player,L"","cmnty","friend_location_failed","","",L"",0,"","",friendName.getUnicode16()); return; } Datapad* thePad = dynamic_cast<Datapad*>(searchObject->getEquipManager()->getEquippedObject(CreatureEquipSlot_Datapad)); if(thePad && thePad->getCapacity()) { //the datapad automatically checks for waypoint caspacity and gives the relevant error messages thePad->requestNewWaypoint(searchObject->getFirstName().getAnsi(),searchObject->mPosition,static_cast<uint16>(gWorldManager->getZoneId()),Waypoint_blue); } }
void ObjectController::_handleRequestWaypointAtPosition(uint64 targetId,Message* message,ObjectControllerCmdProperties* cmdProperties) { PlayerObject* player = dynamic_cast<PlayerObject*>(mObject); Datapad* datapad = player->getDataPad(); //if(!datapad->getCapacity()) //{ // gMessageLib->sendSystemMessage(player,L"","base_player","too_many_waypoints"); // return; //} BStringVector dataElements; BString dataStr; std::string nameStr; message->getStringUnicode16(dataStr); // Have to convert BEFORE using split, since the conversion done there is removed It will assert().. evil grin... // Either do the conversion HERE, or better fix the split so it handles unicoe also. dataStr.convert(BSTRType_ANSI); uint32 elementCount = dataStr.split(dataElements,' '); if(elementCount < 5) { if(elementCount < 4) { return; } else { nameStr = gWorldManager->getPlanetNameThis(); std::transform(nameStr.begin(), nameStr.end(), nameStr.begin(), &tolower); } } else { for(uint i = 4; i < elementCount; i++) { nameStr.append(dataElements[i].getAnsi()); if(i + 1 < elementCount) nameStr.append(" "); } } BString planetStr = dataElements[0].getAnsi(); //gLogger->log(LogManager::DEBUG,"ObjController::handleCreateWaypointAtPosition: planet %s",planetStr.getAnsi()); float x = static_cast<float>(atof(dataElements[1].getAnsi())); float y = static_cast<float>(atof(dataElements[2].getAnsi())); float z = static_cast<float>(atof(dataElements[3].getAnsi())); int32 planetId = gWorldManager->getPlanetIdByName(planetStr); if(planetId == -1) { return; } datapad->requestNewWaypoint(nameStr.c_str(), glm::vec3(x,y,z),static_cast<uint16>(planetId),Waypoint_blue); }
void ObjectController::_handleWaypoint(uint64 targetId, Message* message, ObjectControllerCmdProperties* cmdProperties) { PlayerObject* player = dynamic_cast<PlayerObject*>(mObject); Datapad* datapad = player->getDataPad(); BString waypoint_data; glm::vec3 waypoint_position; // Before anything else verify the datapad can hold another waypoint. if(! datapad->getCapacity()) { gMessageLib->SendSystemMessage(::common::OutOfBand("base_player", "too_many_waypoints"), player); return; } // Read in any waypoint data that may have been sent: // [SYNTAX] /waypoint <x> <z> or /waypoint <x> <y> <z> message->getStringUnicode16(waypoint_data); // Check and see if any parameters were passed to the /waypoint command. For // immediate purposes the length can be used to tell if anything or nothing was passed. if (waypoint_data.getLength()) { int count = swscanf(waypoint_data.getUnicode16(), L"%f %f %f", &waypoint_position.x, &waypoint_position.y, &waypoint_position.z); // If there are an invalid number of items then disregard and notify the player of the correct // format for the /waypoint command. if (count < 2 || count > 3) { gMessageLib->SendSystemMessage(L"[SYNTAX] /waypoint <x> <z> or /waypoint <x> <y> <z>", player); return; } // If the item count is 2 it means no y value was set in the /waypoint command so // update the waypoint_position data values accordingly. if (count == 2) { waypoint_position.z = waypoint_position.y; waypoint_position.y = 0; } // Validate the position values. if (waypoint_position.x < -8192 || waypoint_position.x > 8192 || waypoint_position.y < -500 || waypoint_position.y > 500 || waypoint_position.z < -8192 || waypoint_position.z > 8192) { gMessageLib->SendSystemMessage( L"[SYNTAX] Invalid range for /waypoint. x = -8192/8192 y = -500/500 z = -8192/8192", player); return; } } else { // If no parameters were passed to the /waypoint command use the current world position. waypoint_position = player->getWorldPosition(); } datapad->requestNewWaypoint("Waypoint", waypoint_position, static_cast<uint16>(gWorldManager->getZoneId()), Waypoint_blue); }
////============================================================================= //// //// survey event //// // void ArtisanManager::surveyEvent(PlayerObject* player, CurrentResource* resource, SurveyTool* tool) { if(tool && resource && player->isConnected()) { Datapad* datapad = player->getDataPad(); ResourceLocation highestDist = gMessageLib->sendSurveyMessage(tool->getInternalAttribute<uint16>("survey_range"),tool->getInternalAttribute<uint16>("survey_points"),resource,player); // this is 0, if resource is not located if(highestDist.position.y == 5.0) { std::string name("Resource Survey"); std::u16string name_u16(name.begin(), name.end()); std::shared_ptr<WaypointObject> waypoint = datapad->getWaypointByName(name_u16); // remove the old one if(waypoint) { datapad->updateWaypoint(waypoint->getId(), waypoint->getName(), glm::vec3(highestDist.position.x,0.0f,highestDist.position.z), static_cast<uint16>(gWorldManager->getZoneId()), player->getId(), WAYPOINT_ACTIVE); } else { // create a new one if(datapad->getCapacity()) { gMessageLib->SendSystemMessage(::common::OutOfBand("survey", "survey_waypoint"), player); //gMessageLib->sendSystemMessage(this,L"","survey","survey_waypoint"); } //the datapad automatically checks if there is room and gives the relevant error message std::string name("Resource Survey"); std::u16string name_u16(name.begin(), name.end()); datapad->requestNewWaypoint(name_u16, glm::vec3(highestDist.position.x,0.0f,highestDist.position.z),static_cast<uint16>(gWorldManager->getZoneId()),Waypoint_blue); } gMissionManager->checkSurveyMission(player,resource,highestDist); } } player->getSampleData()->mPendingSurvey = false; }
void GroupManager::sendGroupMissionUpdate(GroupObject* group) { // this procedure ensures, that in case of a change in the mission pool of the group // all players get updated Mission waypoints // it concerns all players of the group on the zone, but not on other zones //get us the mission nearest to the most players on the Zone MissionObject* mission = getZoneGroupMission(group->getPlayerList()); if(!mission) return; //now set the GroupWaypoint for all onZone groupmembers Uint64List::iterator playerListIt = group->getPlayerList()->begin(); while(playerListIt != group->getPlayerList()->end()) { PlayerObject* player = dynamic_cast<PlayerObject*> (gWorldManager->getObjectById((*playerListIt))); Datapad* datapad = dynamic_cast<Datapad*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Datapad)); WaypointObject* waypoint = datapad->getWaypointByName("@group:groupwaypoint"); // remove the old one if(waypoint) { gMessageLib->sendUpdateWaypoint(waypoint,ObjectUpdateAdd,player); datapad->removeWaypoint(waypoint); gObjectFactory->deleteObjectFromDB(waypoint); } else // create a new one if(datapad->getCapacity()) { datapad->requestNewWaypoint("@group:groupwaypoint",mission->getDestination().Coordinates,static_cast<uint16>(gWorldManager->getZoneId()),Waypoint_blue); gMessageLib->sendSystemMessage(player,L"","group","groupwaypoint"); } playerListIt++; } }
void ObjectFactory::handleDatabaseJobComplete(void* ref,DatabaseResult* result) { OFAsyncContainer* asyncContainer = reinterpret_cast<OFAsyncContainer*>(ref); switch(asyncContainer->query) { case OFQuery_House: { PlayerObject* player = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(asyncContainer->PlayerId)); if(!result->getRowCount()) { gLogger->logMsg("ObjFactory::handleDatabaseJobComplete : create house failed : no result"); break; } uint64 requestId = 0; DataBinding* binding = mDatabase->CreateDataBinding(1); binding->addField(DFT_uint64,0,8); result->GetNextRow(binding,&requestId); mDatabase->DestroyDataBinding(binding); if(!requestId) { gLogger->logMsg("ObjFactory::handleDatabaseJobComplete : create house failed : result is 0"); } mHouseFactory->requestObject(asyncContainer->ofCallback,requestId,0,0,asyncContainer->client); //now we need to update the Owners Lots //cave he might have logged out already - even if thats *very* unlikely (heck of a query that would have been) if(player) { gStructureManager->UpdateCharacterLots(asyncContainer->PlayerId); Inventory* inventory = dynamic_cast<Inventory*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory)); Deed* deed = dynamic_cast<Deed*>(gWorldManager->getObjectById(asyncContainer->DeedId)); //destroy it in the client gMessageLib->sendDestroyObject(asyncContainer->DeedId,player); //delete it out of the inventory inventory->deleteObject(deed); Datapad* thePad = dynamic_cast<Datapad*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Datapad)); thePad->requestNewWaypoint("Player House",asyncContainer->coords,gWorldManager->getPlanetIdByName(gWorldManager->getPlanetNameThis()),1); } // now we need to link the deed to the factory in the db and remove it out of the inventory in the db int8 sql[250]; sprintf(sql,"UPDATE items SET parent_id = %I64u WHERE id = %"PRIu64"",requestId, asyncContainer->DeedId); mDatabase->ExecuteSqlAsync(NULL,NULL,sql); } break; case OFQuery_Factory: { PlayerObject* player = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(asyncContainer->PlayerId)); if(!result->getRowCount()) { gLogger->logMsg("ObjFactory::handleDatabaseJobComplete : create Factory failed : no result"); break; } uint64 requestId = 0; DataBinding* binding = mDatabase->CreateDataBinding(1); binding->addField(DFT_uint64,0,8); result->GetNextRow(binding,&requestId); mDatabase->DestroyDataBinding(binding); if(!requestId) { gLogger->logMsg("ObjFactory::handleDatabaseJobComplete : create Factory failed : result is 0"); } mFactoryFactory->requestObject(asyncContainer->ofCallback,requestId,0,0,asyncContainer->client); //now we need to update the Owners Lots //cave he might have logged out already - even if thats *very* unlikely (heck of a query that would have been) if(player) { gStructureManager->UpdateCharacterLots(asyncContainer->PlayerId); Inventory* inventory = dynamic_cast<Inventory*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory)); Deed* deed = dynamic_cast<Deed*>(gWorldManager->getObjectById(asyncContainer->DeedId)); //destroy it in the client gMessageLib->sendDestroyObject(asyncContainer->DeedId,player); //delete it out of the inventory inventory->deleteObject(deed); Datapad* thePad = dynamic_cast<Datapad*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Datapad)); thePad->requestNewWaypoint("Player Factory",asyncContainer->coords,gWorldManager->getPlanetIdByName(gWorldManager->getPlanetNameThis()),1); } // now we need to link the deed to the factory in the db and remove it out of the inventory in the db int8 sql[250]; sprintf(sql,"UPDATE items SET parent_id = %I64u WHERE id = %"PRIu64"",requestId, asyncContainer->DeedId); mDatabase->ExecuteSqlAsync(NULL,NULL,sql); } break; case OFQuery_Harvester: { if(!result->getRowCount()) { gLogger->logMsg("ObjFactory::handleDatabaseJobComplete : create Harvester failed"); break; } uint64 requestId = 0; DataBinding* binding = mDatabase->CreateDataBinding(1); binding->addField(DFT_uint64,0,8); result->GetNextRow(binding,&requestId); mDatabase->DestroyDataBinding(binding); if(requestId) { mHarvesterFactory->requestObject(asyncContainer->ofCallback,requestId,0,0,asyncContainer->client); //now we need to update the Owners Lots PlayerObject* player = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(asyncContainer->PlayerId)); //cave he might have logged out already - even if thats *very* unlikely (heck of a query that would have been) if(player) { gStructureManager->UpdateCharacterLots(asyncContainer->PlayerId); Inventory* inventory = dynamic_cast<Inventory*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory)); Deed* deed = dynamic_cast<Deed*>(inventory->getObjectById(asyncContainer->DeedId)); //destroy it in the client gMessageLib->sendDestroyObject(asyncContainer->DeedId,player); //delete it out of the inventory inventory->deleteObject(deed); Datapad* thePad = dynamic_cast<Datapad*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Datapad)); thePad->requestNewWaypoint("Harvester",asyncContainer->coords,gWorldManager->getPlanetIdByName(gWorldManager->getPlanetNameThis()),1); } // now we need to link the deed to the harvester in the db and remove it out of the inventory int8 sql[250]; sprintf(sql,"UPDATE items SET parent_id = %I64u WHERE id = %"PRIu64"",requestId, asyncContainer->DeedId); mDatabase->ExecuteSqlAsync(NULL,NULL,sql); } else gLogger->logMsg("ObjFactory::handleDatabaseJobComplete : create Harvester failed"); } break; case OFQuery_WaypointCreate: { uint64 requestId = 0; DataBinding* binding = mDatabase->CreateDataBinding(1); binding->addField(DFT_uint64,0,8); result->GetNextRow(binding,&requestId); mDatabase->DestroyDataBinding(binding); if(requestId) mWaypointFactory->requestObject(asyncContainer->ofCallback,requestId,0,0,asyncContainer->client); else gLogger->logMsg("ObjFactory::createWaypoint failed"); } break; case OFQuery_Item: { uint64 requestId = 0; DataBinding* binding = mDatabase->CreateDataBinding(1); binding->addField(DFT_uint64,0,8); result->GetNextRow(binding,&requestId); mDatabase->DestroyDataBinding(binding); if(requestId) mTangibleFactory->requestObject(asyncContainer->ofCallback,requestId,TanGroup_Item,0,asyncContainer->client); else gLogger->logMsg("ObjFactory::createItem failed"); } break; case OFQuery_ResourceContainerCreate: { uint64 requestId = 0; DataBinding* binding = mDatabase->CreateDataBinding(1); binding->addField(DFT_uint64,0,8); result->GetNextRow(binding,&requestId); mDatabase->DestroyDataBinding(binding); if(requestId) mTangibleFactory->requestObject(asyncContainer->ofCallback,requestId,TanGroup_ResourceContainer,0,asyncContainer->client); else gLogger->logMsg("ObjFactory::createResourceContainer failed"); } break; default: { mTangibleFactory->requestObject(asyncContainer->ofCallback,asyncContainer->Id,asyncContainer->Group,0,asyncContainer->client); } break; } mDbAsyncPool.free(asyncContainer); }
void ObjectFactory::handleDatabaseJobComplete(void* ref,DatabaseResult* result) { OFAsyncContainer* asyncContainer = reinterpret_cast<OFAsyncContainer*>(ref); switch(asyncContainer->query) { case OFQuery_House: { PlayerObject* player = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(asyncContainer->PlayerId)); if(!result->getRowCount()) { LOG(ERROR) << "create house failed : no result"; break; } uint64 requestId = 0; DataBinding* binding = mDatabase->createDataBinding(1); binding->addField(DFT_uint64,0,8); result->getNextRow(binding,&requestId); mDatabase->destroyDataBinding(binding); if(!requestId) { LOG(ERROR) << "Create house failed : result is 0"; } mHouseFactory->requestObject(asyncContainer->ofCallback,requestId,0,0,asyncContainer->client); //now we need to update the Owners Lots //cave he might have logged out already - even if thats *very* unlikely (heck of a query that would have been) if(player) { gStructureManager->UpdateCharacterLots(asyncContainer->PlayerId); Deed* deed = dynamic_cast<Deed*>(gWorldManager->getObjectById(asyncContainer->DeedId)); ObjectContainer* tO = dynamic_cast<ObjectContainer*>(gWorldManager->getObjectById(deed->getParentId())); //destroy it in the client gMessageLib->sendDestroyObject(asyncContainer->DeedId,player); //delete it out of the inventory tO->deleteObject(deed); Datapad* datapad = player->getDataPad(); datapad->requestNewWaypoint("Player House",asyncContainer->coords,gWorldManager->getPlanetIdByName(gWorldManager->getPlanetNameThis()),1); } // now we need to link the deed to the factory in the db and remove it out of the inventory in the db int8 sql[250]; sprintf(sql,"UPDATE items SET parent_id = %"PRIu64" WHERE id = %"PRIu64"",requestId, asyncContainer->DeedId); mDatabase->executeSqlAsync(NULL,NULL,sql); } break; case OFQuery_Factory: { PlayerObject* player = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(asyncContainer->PlayerId)); if(!result->getRowCount()) { LOG(ERROR) << "Create factory failed : no result"; break; } uint64 requestId = 0; DataBinding* binding = mDatabase->createDataBinding(1); binding->addField(DFT_uint64,0,8); result->getNextRow(binding,&requestId); mDatabase->destroyDataBinding(binding); if(!requestId) { LOG(ERROR) << "Create factor failed : result is 0"; } mFactoryFactory->requestObject(asyncContainer->ofCallback,requestId,0,0,asyncContainer->client); //now we need to update the Owners Lots //cave he might have logged out already - even if thats *very* unlikely (heck of a query that would have been) if(player) { gStructureManager->UpdateCharacterLots(asyncContainer->PlayerId); Deed* deed = dynamic_cast<Deed*>(gWorldManager->getObjectById(asyncContainer->DeedId)); //destroy it in the client gMessageLib->sendDestroyObject(asyncContainer->DeedId,player); //delete it out of the container ObjectContainer* tO = dynamic_cast<ObjectContainer*>(gWorldManager->getObjectById(deed->getParentId())); tO->deleteObject(deed); Datapad* datapad = player->getDataPad(); datapad->requestNewWaypoint("Player Factory",asyncContainer->coords,gWorldManager->getPlanetIdByName(gWorldManager->getPlanetNameThis()),1); } // now we need to link the deed to the factory in the db and remove it out of the inventory in the db int8 sql[250]; sprintf(sql,"UPDATE items SET parent_id = %"PRIu64" WHERE id = %"PRIu64"",requestId, asyncContainer->DeedId); mDatabase->executeSqlAsync(NULL,NULL,sql); } break; case OFQuery_Harvester: { if(!result->getRowCount()) { LOG(ERROR) << "Create harvester failed : no result"; break; } uint64 requestId = 0; DataBinding* binding = mDatabase->createDataBinding(1); binding->addField(DFT_uint64,0,8); result->getNextRow(binding,&requestId); mDatabase->destroyDataBinding(binding); if(requestId) { mHarvesterFactory->requestObject(asyncContainer->ofCallback,requestId,0,0,asyncContainer->client); //now we need to update the Owners Lots PlayerObject* player = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(asyncContainer->PlayerId)); //cave he might have logged out already - even if thats *very* unlikely (heck of a query that would have been) if(player) { gStructureManager->UpdateCharacterLots(asyncContainer->PlayerId); Deed* deed = dynamic_cast<Deed*>(gWorldManager->getObjectById(asyncContainer->DeedId)); //destroy it in the client gMessageLib->sendDestroyObject(asyncContainer->DeedId,player); //delete it out of the inventory ObjectContainer* tO = dynamic_cast<ObjectContainer*>(gWorldManager->getObjectById(deed->getParentId())); tO->deleteObject(deed); Datapad* datapad = player->getDataPad(); datapad->requestNewWaypoint("Harvester",asyncContainer->coords,gWorldManager->getPlanetIdByName(gWorldManager->getPlanetNameThis()),1); } // now we need to link the deed to the harvester in the db and remove it out of the inventory int8 sql[250]; sprintf(sql,"UPDATE items SET parent_id = %"PRIu64" WHERE id = %"PRIu64"",requestId, asyncContainer->DeedId); mDatabase->executeSqlAsync(NULL,NULL,sql); } else LOG(ERROR) << "Create harvester failed"; } break; case OFQuery_WaypointCreate: { uint64 requestId = 0; DataBinding* binding = mDatabase->createDataBinding(1); binding->addField(DFT_uint64,0,8); result->getNextRow(binding,&requestId); mDatabase->destroyDataBinding(binding); if(requestId) mWaypointFactory->requestObject(asyncContainer->ofCallback,requestId,0,0,asyncContainer->client); else LOG(ERROR) << "Create waypoint failed"; } break; case QFQuery_WaypointUpdate: { // we're looking for a value of the waypoint that was updated uint32 returnId = 0; DataBinding* binding = mDatabase->createDataBinding(1); binding->addField(DFT_uint32,0,4); result->getNextRow(binding,&returnId); mDatabase->destroyDataBinding(binding); switch (returnId) { case 0: case 3: mWaypointFactory->requestObject(asyncContainer->ofCallback,asyncContainer->Id,0,0,asyncContainer->client); break; default: LOG(ERROR) << "Update waypoint failed"; } } break; case OFQuery_Item: { uint64 requestId = 0; DataBinding* binding = mDatabase->createDataBinding(1); binding->addField(DFT_uint64,0,8); result->getNextRow(binding,&requestId); mDatabase->destroyDataBinding(binding); if(requestId) mTangibleFactory->requestObject(asyncContainer->ofCallback,requestId,TanGroup_Item,0,asyncContainer->client); else LOG(ERROR) << "Create item failed"; } break; case OFQuery_ResourceContainerCreate: { uint64 requestId = 0; DataBinding* binding = mDatabase->createDataBinding(1); binding->addField(DFT_uint64,0,8); result->getNextRow(binding,&requestId); mDatabase->destroyDataBinding(binding); if(requestId) mTangibleFactory->requestObject(asyncContainer->ofCallback,requestId,TanGroup_ResourceContainer,0,asyncContainer->client); else LOG(ERROR) << "Create resource container failed"; } break; default: { mTangibleFactory->requestObject(asyncContainer->ofCallback,asyncContainer->Id,asyncContainer->Group,0,asyncContainer->client); } break; } mDbAsyncPool.free(asyncContainer); }
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 Tutorial::handleDatabaseJobComplete(void* ref,DatabaseResult* result) { TutorialQueryContainer* asyncContainer = reinterpret_cast<TutorialQueryContainer*>(ref); switch(asyncContainer->mQueryType) { case TutorialQuery_MainData: { DataBinding* binding = gWorldManager->getDatabase()->CreateDataBinding(3); binding->addField(DFT_uint32,offsetof(Tutorial,mState),4,0); binding->addField(DFT_int32,offsetof(Tutorial,mSubState),4,1); binding->addField(DFT_bstring,offsetof(Tutorial,mStartingProfession),64,2); uint64 count = result->getRowCount(); if (count == 1) { result->GetNextRow(binding,this); gLogger->log(LogManager::DEBUG,"Tutorial::handleDatabaseJobComplete: Starting profession = %s", mStartingProfession.getAnsi()); } else if (count == 0) { // First time, no tutorial data saved. mSubState = 1; mState = 1; // Save the state. (gWorldManager->getDatabase())->ExecuteSqlAsync(0,0,"INSERT INTO character_tutorial VALUES (%"PRIu64",%u,%u)",asyncContainer->mId,mState, mSubState); } gWorldManager->getDatabase()->DestroyDataBinding(binding); // Here we go... this->startScript(); } break; case TutorialQuery_PlanetLocation: { PlayerObject* player = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(asyncContainer->mId)); if (player) { DataBinding* binding = gWorldManager->getDatabase()->CreateDataBinding(4); TutorialStartingLocation startingLocation; binding->addField(DFT_uint32, offsetof(TutorialStartingLocation, destinationPlanet), 4, 0); binding->addField(DFT_float, offsetof(TutorialStartingLocation, destX), 4, 1); binding->addField(DFT_float, offsetof(TutorialStartingLocation, destY), 4, 2); binding->addField(DFT_float, offsetof(TutorialStartingLocation, destZ), 4, 3); result->GetNextRow(binding, &startingLocation); startingLocation.destX += (gRandom->getRand()%5 - 2); startingLocation.destZ += (gRandom->getRand()%5 - 2); gLogger->log(LogManager::DEBUG,"Tutorial::handleDatabaseJobComplete: New destination planet = %u", startingLocation.destinationPlanet); 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(); WaypointObject* wp = datapad->getWaypointByName("@ui:cpt_avatar_location"); if(wp) { datapad->removeWaypoint(wp->getId()); } datapad->requestNewWaypoint("@ui:cpt_avatar_location", position, startingLocation.destinationPlanet, Waypoint_blue); //send starting emails sendStartingMails(); } else { gLogger->log(LogManager::DEBUG,"Tutorial::handleDatabaseJobComplete: Player gone!"); } } break; default: { gLogger->log(LogManager::DEBUG,"Tutorial::handleDatabaseJobComplete: Unknown query = %u\n", asyncContainer->mQueryType); } break; } delete asyncContainer; }
void ArtisanManager::handleUIEvent(uint32 action,int32 element,std::u16string inputStr,UIWindow* window, std::shared_ptr<WindowAsyncContainerCommand> AsyncContainer) { PlayerObject* player = window->getOwner(); std::shared_ptr<SimpleEvent> sample_UI_event = nullptr; if(!player) { DLOG(error) << "ArtisanManager::handleUIEvent :: no player"; return; } auto equip_service = gWorldManager->getKernel()->GetServiceManager()->GetService<swganh::equipment::EquipmentService>("EquipmentService"); auto inventory = dynamic_cast<Inventory*>(equip_service->GetEquippedObject(player->GetCreature(), "inventory")); if(!inventory) { DLOG(error) << "ArtisanManager::handleUIEvent :: no inventory"; return; } if(!AsyncContainer) { DLOG(error) << "ArtisanManager::handleUIEvent :: no asynccontainer"; return; } switch(window->getWindowType()) { // Sampling Radioactive Msg Box case SUI_Window_SmplRadioactive_MsgBox: { auto ham = gWorldManager->getKernel()->GetServiceManager()->GetService<swganh::ham::HamService>("HamService"); //we stopped the sampling if(action == 1) { player->getSampleData()->mPassRadioactive = false; player->getSampleData()->mPendingSample = false; gStateManager.setCurrentPostureState(player->GetCreature(), CreaturePosture_Upright); return; } else { player->getSampleData()->mPassRadioactive = true; player->getSampleData()->mPendingSample = true; if(ham->checkMainPool(player->GetCreature(), HamBar_Action, mSampleActionCost*2)) { SurveyTool* tool = dynamic_cast<SurveyTool*>(gWorldManager->getObjectById(AsyncContainer->ToolId)); CurrentResource* resource = (CurrentResource*)AsyncContainer->CurrentResource; player->getSampleData()->mNextSampleTime = Anh_Utils::Clock::getSingleton()->getStoredTime() + 4000; sample_UI_event = std::make_shared<SimpleEvent>(EventType("sample_radioactive"),0, 4000, std::bind(&ArtisanManager::sampleEvent,this, player, resource, tool)); } else { gMessageLib->SendSystemMessage(::common::OutOfBand("survey", "gamble_no_action"), player); return; } } } break; case SUI_Window_SmplGamble_ListBox: { auto ham = gWorldManager->getKernel()->GetServiceManager()->GetService<swganh::ham::HamService>("HamService"); //action == 1 is cancel if(action == 1) { player->getSampleData()->mPendingSample = false; player->getSampleData()->mSampleGambleFlag = false; gStateManager.setCurrentPostureState(player->GetCreature(), CreaturePosture_Upright); player->GetCreature()->updateMovementProperties(); gMessageLib->sendUpdateMovementProperties(player); gMessageLib->sendPostureAndStateUpdate(player->GetCreature()); return; } else { if(element == 0) { player->getSampleData()->mPendingSample = true; player->getSampleData()->mSampleGambleFlag = false; SurveyTool* tool = dynamic_cast<SurveyTool*>(gWorldManager->getObjectById(AsyncContainer->ToolId)); CurrentResource* resource = (CurrentResource*)AsyncContainer->CurrentResource; player->getSampleData()->mNextSampleTime = Anh_Utils::Clock::getSingleton()->getLocalTime() + 1000; sample_UI_event = std::make_shared<SimpleEvent>(EventType("sample_gamble"),0, 1000, std::bind(&ArtisanManager::sampleEvent,this, player, resource, tool)); } else { //action costs if(!ham->checkMainPool(player->GetCreature(), HamBar_Action ,mSampleActionCost*2)) { gStateManager.setCurrentPostureState(player->GetCreature(), CreaturePosture_Upright); player->getSampleData()->mSampleEventFlag = false; player->getSampleData()->mSampleGambleFlag = false; gMessageLib->SendSystemMessage(::common::OutOfBand("survey", "gamble_no_action"), player); return; } player->getSampleData()->mPendingSample = true; //determine whether gamble is good or not int32 gambleRoll = int(gRandom->getRand()%2) + 1; if(gambleRoll == 1) { player->getSampleData()->mSampleEventFlag = true; player->getSampleData()->mSampleGambleFlag = true; } else { player->getSampleData()->mSampleEventFlag = false; player->getSampleData()->mSampleGambleFlag = false; gMessageLib->SendSystemMessage(::common::OutOfBand("survey", "gamble_fail"), player); } SurveyTool* tool = dynamic_cast<SurveyTool*>(gWorldManager->getObjectById(AsyncContainer->ToolId)); CurrentResource* resource = (CurrentResource*)AsyncContainer->CurrentResource; player->getSampleData()->mNextSampleTime = Anh_Utils::Clock::getSingleton()->getLocalTime() + 1000; sample_UI_event = std::make_shared<SimpleEvent>(EventType("sample_gamble"),0, 1000, std::bind(&ArtisanManager::sampleEvent,this, player, resource, tool)); } } } break; case SUI_Window_SmplWaypNode_ListBox: { if(action == 0) { //we hit ok and went for the wp if(element == 1) { player->getSampleData()->mPendingSample = false; player->getSampleData()->mSampleNodeFlag = true; player->getSampleData()->Position.x = player->mPosition.x +(((gRandom->getRand()%50)+1)); player->getSampleData()->Position.z = player->mPosition.z +(((gRandom->getRand()%50)+1)); player->getSampleData()->zone = gWorldManager->getZoneId(); player->getSampleData()->resource = (CurrentResource*)AsyncContainer->CurrentResource; Datapad* datapad = player->getDataPad(); std::string name("Resource Node"); std::u16string name_u16 (name.begin(), name.end()); datapad->requestNewWaypoint(name_u16, player->getSampleData()->Position ,static_cast<uint16>(gWorldManager->getZoneId()),Waypoint_blue); gMessageLib->SendSystemMessage(::common::OutOfBand("survey", "node_waypoint"), player); gStateManager.setCurrentPostureState(player->GetCreature(), CreaturePosture_Upright); return; } //we ignored the node - so continue sampling if(element == 0) { player->getSampleData()->mPendingSample = true; player->getSampleData()->mSampleGambleFlag = false; SurveyTool* tool = dynamic_cast<SurveyTool*>(gWorldManager->getObjectById(AsyncContainer->ToolId)); CurrentResource* resource = (CurrentResource*)AsyncContainer->CurrentResource; player->getSampleData()->mNextSampleTime = Anh_Utils::Clock::getSingleton()->getLocalTime() + 10000; sample_UI_event = std::make_shared<SimpleEvent>(EventType("sample_continue"),0, 10000, std::bind(&ArtisanManager::sampleEvent,this, player, resource, tool)); } } else { player->getSampleData()->mPendingSample = false; player->getSampleData()->mSampleNodeFlag = false; player->getSampleData()->Position.x = 0; player->getSampleData()->Position.z = 0; player->getSampleData()->resource = NULL; player->getSampleData()->zone = 0; gStateManager.setCurrentPostureState(player->GetCreature(), CreaturePosture_Upright); return; } } break; } //notify the listeners if (sample_UI_event) gEventDispatcher.Notify(sample_UI_event); }
void ArtisanManager::handleUIEvent(uint32 action,int32 element,BString inputStr,UIWindow* window) { PlayerObject* player = window->getOwner(); std::shared_ptr<SimpleEvent> sample_UI_event = nullptr; if(!player) { return; } Inventory* inventory = dynamic_cast<Inventory*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory)); if(!inventory) { return; } WindowAsyncContainerCommand* asyncContainer = (WindowAsyncContainerCommand*)window->getAsyncContainer(); if(!asyncContainer) return; Ham* ham = player->getHam(); switch(window->getWindowType()) { // Sampling Radioactive Msg Box case SUI_Window_SmplRadioactive_MsgBox: { //we stopped the sampling if(action == 1) { player->getSampleData()->mPassRadioactive = false; player->getSampleData()->mPendingSample = false; gStateManager.setCurrentPostureState(player, CreaturePosture_Upright); return; } else { player->getSampleData()->mPassRadioactive = true; player->getSampleData()->mPendingSample = true; if(ham->checkMainPools(0,mSampleActionCost*2,0)) { SurveyTool* tool = dynamic_cast<SurveyTool*>(inventory->getObjectById(asyncContainer->ToolId)); CurrentResource* resource = (CurrentResource*)asyncContainer->CurrentResource; player->getSampleData()->mNextSampleTime = Anh_Utils::Clock::getSingleton()->getLocalTime() + 4000; sample_UI_event = std::make_shared<SimpleEvent>(EventType("sample_radioactive"),0, 4000, std::bind(&ArtisanManager::sampleEvent,this, player, resource, tool)); } else { gMessageLib->SendSystemMessage(::common::OutOfBand("survey", "gamble_no_action"), player); return; } } } break; case SUI_Window_SmplGamble_ListBox: { //action == 1 is cancel if(action == 1) { player->getSampleData()->mPendingSample = false; player->getSampleData()->mSampleGambleFlag = false; gStateManager.setCurrentPostureState(player, CreaturePosture_Upright); player->updateMovementProperties(); gMessageLib->sendUpdateMovementProperties(player); gMessageLib->sendPostureAndStateUpdate(player); gMessageLib->sendSelfPostureUpdate(player); return; } else { if(element == 0) { player->getSampleData()->mPendingSample = true; player->getSampleData()->mSampleGambleFlag = false; SurveyTool* tool = dynamic_cast<SurveyTool*>(inventory->getObjectById(asyncContainer->ToolId)); CurrentResource* resource = (CurrentResource*)asyncContainer->CurrentResource; player->getSampleData()->mNextSampleTime = Anh_Utils::Clock::getSingleton()->getLocalTime() + 1000; sample_UI_event = std::make_shared<SimpleEvent>(EventType("sample_gamble"),0, 1000, std::bind(&ArtisanManager::sampleEvent,this, player, resource, tool)); } else { //action costs if(!ham->checkMainPools(0,mSampleActionCost*2,0)) { gStateManager.setCurrentPostureState(player, CreaturePosture_Upright); player->getSampleData()->mSampleEventFlag = false; player->getSampleData()->mSampleGambleFlag = false; gMessageLib->SendSystemMessage(::common::OutOfBand("survey", "gamble_no_action"), player); return; } player->getSampleData()->mPendingSample = true; //determine whether gamble is good or not int32 gambleRoll = int(gRandom->getRand()%2) + 1; if(gambleRoll == 1) { player->getSampleData()->mSampleEventFlag = true; player->getSampleData()->mSampleGambleFlag = true; } else { player->getSampleData()->mSampleEventFlag = false; player->getSampleData()->mSampleGambleFlag = false; gMessageLib->SendSystemMessage(::common::OutOfBand("survey", "gamble_fail"), player); } SurveyTool* tool = dynamic_cast<SurveyTool*>(inventory->getObjectById(asyncContainer->ToolId)); CurrentResource* resource = (CurrentResource*)asyncContainer->CurrentResource; player->getSampleData()->mNextSampleTime = Anh_Utils::Clock::getSingleton()->getLocalTime() + 1000; sample_UI_event = std::make_shared<SimpleEvent>(EventType("sample_gamble"),0, 1000, std::bind(&ArtisanManager::sampleEvent,this, player, resource, tool)); } } } break; case SUI_Window_SmplWaypNode_ListBox: { if(action == 0) { //we hit ok and went for the wp if(element == 1) { player->getSampleData()->mPendingSample = false; player->getSampleData()->mSampleNodeFlag = true; player->getSampleData()->Position.x = player->mPosition.x +(((gRandom->getRand()%50)+1)); player->getSampleData()->Position.z = player->mPosition.z +(((gRandom->getRand()%50)+1)); player->getSampleData()->zone = gWorldManager->getZoneId(); player->getSampleData()->resource = (CurrentResource*)asyncContainer->CurrentResource; Datapad* datapad = player->getDataPad(); datapad->requestNewWaypoint("Resource Node", player->getSampleData()->Position ,static_cast<uint16>(gWorldManager->getZoneId()),Waypoint_blue); gMessageLib->SendSystemMessage(::common::OutOfBand("survey", "node_waypoint"), player); gStateManager.setCurrentPostureState(player, CreaturePosture_Upright); return; } //we ignored the node - so continue sampling if(element == 0) { player->getSampleData()->mPendingSample = true; player->getSampleData()->mSampleGambleFlag = false; SurveyTool* tool = dynamic_cast<SurveyTool*>(inventory->getObjectById(asyncContainer->ToolId)); CurrentResource* resource = (CurrentResource*)asyncContainer->CurrentResource; player->getSampleData()->mNextSampleTime = Anh_Utils::Clock::getSingleton()->getLocalTime() + 10000; sample_UI_event = std::make_shared<SimpleEvent>(EventType("sample_continue"),0, 10000, std::bind(&ArtisanManager::sampleEvent,this, player, resource, tool)); } } else { player->getSampleData()->mPendingSample = false; player->getSampleData()->mSampleNodeFlag = false; player->getSampleData()->Position.x = 0; player->getSampleData()->Position.z = 0; player->getSampleData()->resource = NULL; player->getSampleData()->zone = 0; gStateManager.setCurrentPostureState(player, CreaturePosture_Upright); return; } } break; } //notify the listeners if (sample_UI_event) gEventDispatcher.Notify(sample_UI_event); SAFE_DELETE(asyncContainer); }