<commit_before>/*
 * SurveySessionImplementation.cpp
 *
 *  Created on: May 22, 2012
 *      Author: Kyle
 */

#include "SurveySession.h"
#include "server/zone/Zone.h"
#include "server/zone/managers/player/PlayerManager.h"
#include "server/zone/managers/resource/ResourceManager.h"
#include "server/zone/objects/creature/CreatureObject.h"
#include "server/zone/objects/player/PlayerObject.h"
#include "server/zone/objects/tangible/tool/SurveyTool.h"
#include "server/zone/packets/scene/PlayClientEffectLocMessage.h"
#include "server/zone/objects/creature/CreatureAttribute.h"
#include "server/zone/objects/player/sessions/survey/sui/SurveyGMinigameSuiCallback.h"
#include "server/zone/objects/player/sessions/survey/sui/SurveyCMinigameSuiCallback.h"
#include "server/zone/managers/resource/resourcespawner/SampleTask.h"

int SurveySessionImplementation::initializeSession(SurveyTool* tool) {

	activeSurveyTool = tool;
	surveyerGhost = surveyer->getPlayerObject();
	return startSession();
}

int SurveySessionImplementation::startSession() {

	if(surveyer == NULL || activeSurveyTool == NULL || surveyerGhost == NULL) {
		cancelSession();
		return false;
	}

	resourceManager = surveyer->getZoneServer()->getResourceManager();
	if(resourceManager == NULL) {
		cancelSession();
		return false;
	}

	surveyer->addActiveSession(SessionFacadeType::SURVEY, _this);

	return true;
}

int SurveySessionImplementation::cancelSession() {

	if(surveyer != NULL)
		surveyer->dropActiveSession(SessionFacadeType::SURVEY);


	return clearSession();
}

int SurveySessionImplementation::clearSession() {

	return 0;
}

void SurveySessionImplementation::startSurvey(const String& resname) {

	if (activeSurveyTool == NULL) {
		error("surveyTool is NULL");
		return;
	}

	if (resourceManager == NULL) {
		error("ResourceManager is NULL");
		return;
	}

	if (surveyer == NULL) {
		error("surveyer is NULL");
		return;
	}

	if (surveyer->getParent() != NULL && surveyer->getParent()->isCellObject()) {
		surveyer->sendSystemMessage("@error_message:survey_in_structure"); //You cannot perform survey-related actions inside a structure.
		return;
	}

	if (surveyer->isSwimming()) {
		surveyer->sendSystemMessage("@error_message:survey_swimming");
		return;
	}

	if (surveyer->isMounted()) {
		if(surveyer->isInWater()) {
			surveyer->sendSystemMessage("@error_message:survey_cant");
			return;
		}
	} else {
		if(surveyer->getPosture() != CreaturePosture::UPRIGHT) {
			surveyer->sendSystemMessage("@error_message:survey_standing");
			return;
		}
	}

	if (surveyer->getHAM(CreatureAttribute::MIND) < 100) {
		surveyer->setPosture(CreaturePosture::UPRIGHT, true);
		surveyer->sendSystemMessage("@error_message:survey_mind"); //You are exhausted. You nee to clear your head before you can survey again.
		return;
	}

	ManagedReference<ResourceSpawn*> spawn = resourceManager->getResourceSpawn(resname);
	if(spawn == NULL) {
		return;
	}

	if(spawn->getSurveyToolType() != activeSurveyTool->getToolType()) {
		StringIdChatParameter message("@survey:wrong_tool"); // %TO resources cannot be located with this tool
		message.setTO(spawn->getFinalClass());
		surveyer->sendSystemMessage(message);
		return;
	}

	PlayClientEffectLoc* effect = new PlayClientEffectLoc(activeSurveyTool->getSurveyAnimation(),
			surveyer->getZone()->getZoneName(),
			surveyer->getPositionX(), surveyer->getPositionZ(),
			surveyer->getPositionY());

	surveyer->broadcastMessage(effect, true);

	resourceManager->sendSurvey(surveyer, resname);
}

void SurveySessionImplementation::startSample(const String& resname) {

	if (activeSurveyTool == NULL) {
		error("surveyTool is NULL");
		return;
	}

	if (resourceManager == NULL) {
		info("ResourceManager is NULL");
		return;
	}

	if (surveyer == NULL) {
		info("surveyer is NULL");
		return;
	}

	if (!resname.isEmpty())
		 lastResourceSampleName = resname;

	ManagedReference<ResourceSpawn* > resourceSpawn = resourceManager->getResourceSpawn(lastResourceSampleName);
	if (resourceSpawn == NULL) {
		return;
	}

	if (surveyer->getParent() != NULL && surveyer->getParent()->isCellObject()) {
		surveyer->sendSystemMessage("@error_message:survey_in_structure"); //You cannot perform survey-related actions inside a structure.
		return;
	}

	if (surveyer->isSwimming()) {
		surveyer->sendSystemMessage("@error_message:survey_swimming");
		return;
	}

	if (surveyer->isMounted()) {
		surveyer->sendSystemMessage("@error_message:survey_on_mount");
		return;
	}

	if (surveyer->getHAM(CreatureAttribute::ACTION) < 200) {
		surveyer->setPosture(CreaturePosture::UPRIGHT, true);
		surveyer->sendSystemMessage("@error_message:survey_mind"); //You are exhausted. You nee to clear your head before you can survey again.
		return;
	}

	if(resourceSpawn->getSurveyToolType() != activeSurveyTool->getToolType()) {
		StringIdChatParameter message("@survey:wrong_tool"); // %TO resources cannot be located with this tool
		message.setTO(resourceSpawn->getFinalClass());
		surveyer->sendSystemMessage(message);
		return;
	}

	if(!lastResourceSampleName.isEmpty() && !activeSurveyTool->canSampleRadioactive()) {

		if(resourceSpawn->isType("radioactive") && !activeSurveyTool->canSampleRadioactive()) {
			activeSurveyTool->sendRadioactiveWarning(surveyer);
			return;
		}
	}

	// Player must be kneeling to sample
	if (!surveyer->isKneeling()) {
		surveyer->setPosture(CreaturePosture::CROUCHED, true);
	}
<commit_msg>(unstable)[Fixed] Sample message when out of ham<commit_after>/*
 * SurveySessionImplementation.cpp
 *
 *  Created on: May 22, 2012
 *      Author: Kyle
 */

#include "SurveySession.h"
#include "server/zone/Zone.h"
#include "server/zone/managers/player/PlayerManager.h"
#include "server/zone/managers/resource/ResourceManager.h"
#include "server/zone/objects/creature/CreatureObject.h"
#include "server/zone/objects/player/PlayerObject.h"
#include "server/zone/objects/tangible/tool/SurveyTool.h"
#include "server/zone/packets/scene/PlayClientEffectLocMessage.h"
#include "server/zone/objects/creature/CreatureAttribute.h"
#include "server/zone/objects/player/sessions/survey/sui/SurveyGMinigameSuiCallback.h"
#include "server/zone/objects/player/sessions/survey/sui/SurveyCMinigameSuiCallback.h"
#include "server/zone/managers/resource/resourcespawner/SampleTask.h"

int SurveySessionImplementation::initializeSession(SurveyTool* tool) {

	activeSurveyTool = tool;
	surveyerGhost = surveyer->getPlayerObject();
	return startSession();
}

int SurveySessionImplementation::startSession() {

	if(surveyer == NULL || activeSurveyTool == NULL || surveyerGhost == NULL) {
		cancelSession();
		return false;
	}

	resourceManager = surveyer->getZoneServer()->getResourceManager();
	if(resourceManager == NULL) {
		cancelSession();
		return false;
	}

	surveyer->addActiveSession(SessionFacadeType::SURVEY, _this);

	return true;
}

int SurveySessionImplementation::cancelSession() {

	if(surveyer != NULL)
		surveyer->dropActiveSession(SessionFacadeType::SURVEY);


	return clearSession();
}

int SurveySessionImplementation::clearSession() {

	return 0;
}

void SurveySessionImplementation::startSurvey(const String& resname) {

	if (activeSurveyTool == NULL) {
		error("surveyTool is NULL");
		return;
	}

	if (resourceManager == NULL) {
		error("ResourceManager is NULL");
		return;
	}

	if (surveyer == NULL) {
		error("surveyer is NULL");
		return;
	}

	if (surveyer->getParent() != NULL && surveyer->getParent()->isCellObject()) {
		surveyer->sendSystemMessage("@error_message:survey_in_structure"); //You cannot perform survey-related actions inside a structure.
		return;
	}

	if (surveyer->isSwimming()) {
		surveyer->sendSystemMessage("@error_message:survey_swimming");
		return;
	}

	if (surveyer->isMounted()) {
		if(surveyer->isInWater()) {
			surveyer->sendSystemMessage("@error_message:survey_cant");
			return;
		}
	} else {
		if(surveyer->getPosture() != CreaturePosture::UPRIGHT) {
			surveyer->sendSystemMessage("@error_message:survey_standing");
			return;
		}
	}

	if (surveyer->getHAM(CreatureAttribute::MIND) < 100) {
		surveyer->setPosture(CreaturePosture::UPRIGHT, true);
		surveyer->sendSystemMessage("@error_message:survey_mind"); //You are exhausted. You nee to clear your head before you can survey again.
		return;
	}

	ManagedReference<ResourceSpawn*> spawn = resourceManager->getResourceSpawn(resname);
	if(spawn == NULL) {
		return;
	}

	if(spawn->getSurveyToolType() != activeSurveyTool->getToolType()) {
		StringIdChatParameter message("@survey:wrong_tool"); // %TO resources cannot be located with this tool
		message.setTO(spawn->getFinalClass());
		surveyer->sendSystemMessage(message);
		return;
	}

	PlayClientEffectLoc* effect = new PlayClientEffectLoc(activeSurveyTool->getSurveyAnimation(),
			surveyer->getZone()->getZoneName(),
			surveyer->getPositionX(), surveyer->getPositionZ(),
			surveyer->getPositionY());

	surveyer->broadcastMessage(effect, true);

	resourceManager->sendSurvey(surveyer, resname);
}

void SurveySessionImplementation::startSample(const String& resname) {

	if (activeSurveyTool == NULL) {
		error("surveyTool is NULL");
		return;
	}

	if (resourceManager == NULL) {
		info("ResourceManager is NULL");
		return;
	}

	if (surveyer == NULL) {
		info("surveyer is NULL");
		return;
	}

	if (!resname.isEmpty())
		 lastResourceSampleName = resname;

	ManagedReference<ResourceSpawn* > resourceSpawn = resourceManager->getResourceSpawn(lastResourceSampleName);
	if (resourceSpawn == NULL) {
		return;
	}

	if (surveyer->getParent() != NULL && surveyer->getParent()->isCellObject()) {
		surveyer->sendSystemMessage("@error_message:survey_in_structure"); //You cannot perform survey-related actions inside a structure.
		return;
	}

	if (surveyer->isSwimming()) {
		surveyer->sendSystemMessage("@error_message:survey_swimming");
		return;
	}

	if (surveyer->isMounted()) {
		surveyer->sendSystemMessage("@error_message:survey_on_mount");
		return;
	}

	if (surveyer->getHAM(CreatureAttribute::ACTION) < 200) {
		surveyer->setPosture(CreaturePosture::UPRIGHT, true);
		surveyer->sendSystemMessage("@error_message:sample_mind"); //You are exhausted. You nee to clear your head before you can sample again.
		return;
	}

	if(resourceSpawn->getSurveyToolType() != activeSurveyTool->getToolType()) {
		StringIdChatParameter message("@survey:wrong_tool"); // %TO resources cannot be located with this tool
		message.setTO(resourceSpawn->getFinalClass());
		surveyer->sendSystemMessage(message);
		return;
	}

	if(!lastResourceSampleName.isEmpty() && !activeSurveyTool->canSampleRadioactive()) {

		if(resourceSpawn->isType("radioactive") && !activeSurveyTool->canSampleRadioactive()) {
			activeSurveyTool->sendRadioactiveWarning(surveyer);
			return;
		}
	}

	// Player must be kneeling to sample
	if (!surveyer->isKneeling()) {
		surveyer->setPosture(CreaturePosture::CROUCHED, true);
	}

{'fraction_non_alphanumeric': 0.13905025357307516, 'fraction_numerical': 0.00239741816505302, 'mean_word_length': 5.877615726062143, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 115, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5940435', 'n_tokens_mistral': 3774, 'n_tokens_neox': 3552, 'n_words': 598}