bool ArtisanManager::handleRequestCoreSample(Object* player,Object* target, Message* message,ObjectControllerCmdProperties* cmdProperties) { PlayerObject* playerObject = dynamic_cast<PlayerObject*>(player); if(cmdProperties) // unfortunately it's not in this opcode // hardcode for now //mSampleActionCost = cmdProperties->mActionCost; mSampleActionCost = 150; if(playerObject->GetCreature()->getPerformingState() != PlayerPerformance_None || playerObject->checkIfMounted() || playerObject->GetCreature()->isDead() || playerObject->GetCreature()->states.checkState(CreatureState_Combat)) { gMessageLib->SendSystemMessage(::common::OutOfBand("error_message", "wrong_state"), playerObject); return false; } // can't sample while surveying if(playerObject->getSurveyState()) { gMessageLib->SendSystemMessage(::common::OutOfBand("survey", "sample_survey"), playerObject); return false; } // don't allow sampling in buildings if(playerObject->getParentId()) { gMessageLib->SendSystemMessage(::common::OutOfBand("error_message", "survey_in_structure"), playerObject); return false; } uint64 localTime = Anh_Utils::Clock::getSingleton()->getLocalTime(); // don't allow more than one sample at a time if(playerObject->getSamplingState()) { playerObject->getSampleData()->mPendingSample = false; playerObject->setNextSampleTime(localTime + 18000); gMessageLib->SendSystemMessage(::common::OutOfBand("survey", "tool_recharge_time", 0, 0, 0, (int32)(playerObject->getNextSampleTime() - localTime) / 1000), playerObject); return false; } if(!playerObject->getNextSampleTime() || (int32)(playerObject->getNextSampleTime() - localTime) <= 0) { playerObject->getSampleData()->mPendingSample = false; playerObject->setNextSampleTime(localTime + 18000); } else { gMessageLib->SendSystemMessage(::common::OutOfBand("survey", "tool_recharge_time", 0, 0, 0, (int32)(playerObject->getNextSampleTime() - localTime) / 1000), playerObject); return false; } SurveyTool* tool = dynamic_cast<SurveyTool*>(target); CurrentResource* resource = NULL; BString resourceName; message->getStringUnicode16(resourceName); resourceName.convert(BSTRType_ANSI); resource = reinterpret_cast<CurrentResource*>(gResourceManager->getResourceByNameCRC(resourceName.getCrc())); if(resource == NULL || tool == NULL) { gMessageLib->SendSystemMessage(::common::OutOfBand("ui","survey_noresource"), playerObject); return false; } if((resource->getType()->getCategoryId() == 903)||(resource->getType()->getCategoryId() == 904)) { gMessageLib->SendSystemMessage(::common::OutOfBand("survey", "must_have_harvester"), playerObject); return false; } playerObject->setSamplingState(true); auto terrain = gWorldManager->getKernel()->GetServiceManager()->GetService<swganh::terrain::TerrainService>("TerrainService"); if(terrain->IsWater(gWorldManager->getZoneId(), playerObject->mPosition.x, playerObject->mPosition.z)) { gMessageLib->SendSystemMessage(::common::OutOfBand("error_message", "survey_swimming"), playerObject); return false; } resourceName.convert(BSTRType_Unicode16); gMessageLib->SendSystemMessage(::common::OutOfBand("survey", "start_sampling", L"", L"", resourceName.getUnicode16()), playerObject); // change posture gStateManager.setCurrentPostureState(playerObject->GetCreature(), CreaturePosture_Crouched); // play animation gWorldManager->getClientEffect(tool->getInternalAttribute<uint32>("sample_effect")); // schedule execution std::shared_ptr<SimpleEvent> start_sample_event = nullptr; start_sample_event = std::make_shared<SimpleEvent>(EventType("start_sample"), 0, 2000, std::bind(&ArtisanManager::sampleEvent,this, playerObject, resource, tool)); // notify any listeners gEventDispatcher.Notify(start_sample_event); return true; }
bool ArtisanManager::handleRequestCoreSample(Object* player,Object* target, Message* message,ObjectControllerCmdProperties* cmdProperties) { PlayerObject* playerObject = dynamic_cast<PlayerObject*>(player); if(cmdProperties) // unfortunately it's not in this opcode // hardcode for now //mSampleActionCost = cmdProperties->mActionCost; mSampleActionCost = 150; if(playerObject->getPerformingState() != PlayerPerformance_None || playerObject->checkIfMounted() || playerObject->isDead()) { gMessageLib->SendSystemMessage(::common::OutOfBand("error_message", "wrong_state"), playerObject); return false; } // can't sample while surveying if(playerObject->getSurveyState()) { gMessageLib->SendSystemMessage(::common::OutOfBand("survey", "sample_survey"), playerObject); return false; } // don't allow sampling in buildings if(playerObject->getParentId()) { gMessageLib->SendSystemMessage(::common::OutOfBand("error_message", "survey_in_structure"), playerObject); return false; } uint64 localTime = Anh_Utils::Clock::getSingleton()->getLocalTime(); // don't allow more than one sample at a time if(playerObject->getSamplingState()) { playerObject->getSampleData()->mPendingSample = false; playerObject->setNextSampleTime(localTime + 18000); gMessageLib->SendSystemMessage(::common::OutOfBand("survey", "tool_recharge_time", 0, 0, 0, (int32)(playerObject->getNextSampleTime() - localTime) / 1000), playerObject); return false; } if(!playerObject->getNextSampleTime() || (int32)(playerObject->getNextSampleTime() - localTime) <= 0) { playerObject->getSampleData()->mPendingSample = false; playerObject->setNextSampleTime(localTime + 18000); } else { gMessageLib->SendSystemMessage(::common::OutOfBand("survey", "tool_recharge_time", 0, 0, 0, (int32)(playerObject->getNextSampleTime() - localTime) / 1000), playerObject); return false; } SurveyTool* tool = dynamic_cast<SurveyTool*>(target); CurrentResource* resource = NULL; BString resourceName; message->getStringUnicode16(resourceName); resourceName.convert(BSTRType_ANSI); resource = reinterpret_cast<CurrentResource*>(gResourceManager->getResourceByNameCRC(resourceName.getCrc())); if(resource == NULL || tool == NULL) { gMessageLib->SendSystemMessage(::common::OutOfBand("ui","survey_noresource"), playerObject); return false; } if((resource->getType()->getCategoryId() == 903)||(resource->getType()->getCategoryId() == 904)) { gMessageLib->SendSystemMessage(::common::OutOfBand("survey", "must_have_harvester"), playerObject); return false; } playerObject->setSamplingState(true); ArtisanHeightmapAsyncContainer* container = new ArtisanHeightmapAsyncContainer(this, HeightmapCallback_ArtisanSurvey); container->addToBatch(playerObject->mPosition.x,playerObject->mPosition.z); container->playerObject = playerObject; container->resource = resource; container->resourceName = resourceName; container->tool = tool; gHeightmap->addNewHeightMapJob(container); return true; }