<commit_before>/*
 * TurretDataComponent.cpp
 *
 *  Created on: Dec 10, 2012
 *      Author: root
 */

#include "TurretDataComponent.h"
#include "server/zone/objects/installation/InstallationObject.h"
#include "server/zone/packets/scene/AttributeListMessage.h"
#include "server/zone/objects/installation/components/TurretFireTask.h"

void TurretDataComponent::initializeTransientMembers() {
	if(getParent() != NULL){
		templateData = dynamic_cast<SharedInstallationObjectTemplate*>(getParent()->getObjectTemplate());

		SceneObject* sceneObject = getParent()->getSlottedObject("hold_r");

		if(sceneObject == NULL){
			return;
		}

		WeaponObject* weapon = cast<WeaponObject*>(sceneObject);

		if(weapon != NULL){
			attackSpeed = weapon->getAttackSpeed();
			maxrange = weapon->getMaxRange();
		}
	}
}

void TurretDataComponent::rescheduleFireTask(float secondsToWait, bool manual){
	if(getParent() == NULL)
		return;

	CreatureObject* attacker = getController();
	CreatureObject* target = getTarget();

	Logger::Logger tlog("reschedule");
	if(target != NULL){

		Reference<TurretFireTask*> fireTask = new TurretFireTask(cast<TangibleObject*>(getParent()), getTarget(),manual);
		this->setFireTask(fireTask);
		getFireTask()->schedule(secondsToWait * 1000);

	} else {
		tlog.info("target is null",true);
		setController(NULL);
		setFireTask(NULL);
		setTarget(NULL);
	}

}

void TurretDataComponent::setWeapon(WeaponObject* weapon){
	if(weapon != NULL){
		attackSpeed = weapon->getAttackSpeed();
		maxrange = weapon->getMaxRange();
	}
}

void TurretDataComponent::fillAttributeList(AttributeListMessage* alm){

	if(getParent() == NULL)
		return;

	ManagedReference<InstallationObject*> turret = cast<InstallationObject*>(getParent());

	alm->insertAttribute("condition",String::valueOf(turret->getMaxCondition() - turret->getConditionDamage()) + "/" + String::valueOf(turret->getMaxCondition()));
	alm->insertAttribute("armorrating","Heavy");

	alm->insertAttribute("cat_armor_special_protection.armor_eff_energy",String::valueOf(getEnergy()) + "%");
	alm->insertAttribute("cat_armor_special_protection.armor_eff_stun",String::valueOf(getStun()) + "%");

	alm->insertAttribute("cat_armor_effectiveness.armor_eff_kinetic",String::valueOf(getKinetic()) + "%");
	alm->insertAttribute("cat_armor_effectiveness.armor_eff_elemental_heat",String::valueOf(getHeat()) + "%");
	alm->insertAttribute("cat_armor_effectiveness.armor_eff_elemental_cold",String::valueOf(getCold()) + "%");
	alm->insertAttribute("cat_armor_effectiveness.armor_eff_elemental_acid",String::valueOf(getAcid()) + "%");

	alm->insertAttribute("cat_armor_effectiveness.armor_eff_elemental_electrical",String::valueOf(getElectricity()) + "%");
	alm->insertAttribute("cat_armor_vulnerability.armor_eff_blast",String::valueOf(getBlast()) + "%");

	alm->insertAttribute("cat_armor_encumbrance.health","0");
	alm->insertAttribute("cat_armor_encumbrance.action","0");
	alm->insertAttribute("cat_armor_encumbrance.mind","0");

	alm->insertAttribute("description",turret->getDetailedDescription());
	alm->insertAttribute("owner",String::valueOf(turret->getOwnerObjectID()));

}
void TurretDataComponent::updateAutoCooldown(float secondsToAdd){
	int milisecondsToAdd = secondsToAdd*1000;
	nextFireTime = Time();
	nextFireTime.addMiliTime(milisecondsToAdd);
}

void TurretDataComponent::updateManualCooldown(float secondsToAdd){
	int milisecondsToAdd = secondsToAdd*1000;
	nextManualFireTime = Time();
	nextManualFireTime.addMiliTime(milisecondsToAdd);
}

unsigned int TurretDataComponent::getArmorRating(){
	if(templateData != NULL)
		return templateData->getArmorRating();

	return 0;
}

float TurretDataComponent::getKinetic(){
	if(templateData != NULL)
		return templateData->getKinetic();

	return 0;
}

float TurretDataComponent::getEnergy(){
	if(templateData != NULL)
		return templateData->getKinetic();

	return 0;
}

float TurretDataComponent::getElectricity(){
	if(templateData != NULL)
		return templateData->getElectricity();<commit_msg>[Fixed] attribute list on turrets [Fixed] turrets using kinetic resist for energy resist<commit_after>/*
 * TurretDataComponent.cpp
 *
 *  Created on: Dec 10, 2012
 *      Author: root
 */

#include "TurretDataComponent.h"
#include "server/zone/objects/installation/InstallationObject.h"
#include "server/zone/packets/scene/AttributeListMessage.h"
#include "server/zone/objects/installation/components/TurretFireTask.h"

void TurretDataComponent::initializeTransientMembers() {
	if(getParent() != NULL){
		templateData = dynamic_cast<SharedInstallationObjectTemplate*>(getParent()->getObjectTemplate());

		SceneObject* sceneObject = getParent()->getSlottedObject("hold_r");

		if(sceneObject == NULL){
			return;
		}

		WeaponObject* weapon = cast<WeaponObject*>(sceneObject);

		if(weapon != NULL){
			attackSpeed = weapon->getAttackSpeed();
			maxrange = weapon->getMaxRange();
		}
	}
}

void TurretDataComponent::rescheduleFireTask(float secondsToWait, bool manual){
	if(getParent() == NULL)
		return;

	CreatureObject* attacker = getController();
	CreatureObject* target = getTarget();

	Logger::Logger tlog("reschedule");
	if(target != NULL){

		Reference<TurretFireTask*> fireTask = new TurretFireTask(cast<TangibleObject*>(getParent()), getTarget(),manual);
		this->setFireTask(fireTask);
		getFireTask()->schedule(secondsToWait * 1000);

	} else {
		tlog.info("target is null",true);
		setController(NULL);
		setFireTask(NULL);
		setTarget(NULL);
	}

}

void TurretDataComponent::setWeapon(WeaponObject* weapon){
	if(weapon != NULL){
		attackSpeed = weapon->getAttackSpeed();
		maxrange = weapon->getMaxRange();
	}
}

void TurretDataComponent::fillAttributeList(AttributeListMessage* alm){

	if(getParent() == NULL)
		return;

	ManagedReference<InstallationObject*> turret = cast<InstallationObject*>(getParent());

	alm->insertAttribute("condition",String::valueOf(turret->getMaxCondition() - turret->getConditionDamage()) + "/" + String::valueOf(turret->getMaxCondition()));

	if (getArmorRating() == 0)
		alm->insertAttribute("armorrating", "None");
	else if (getArmorRating() == 1)
		alm->insertAttribute("armorrating", "Light");
	else if (getArmorRating() == 2)
		alm->insertAttribute("armorrating", "Medium");
	else if (getArmorRating() == 3)
		alm->insertAttribute("armorrating", "Heavy");


	if (getKinetic() > 90) {
		StringBuffer txt;
		txt << round(getKinetic()) << "%";
		alm->insertAttribute("cat_armor_special_protection.armor_eff_kinetic", txt.toString());
	}

	if (getEnergy() > 90) {
		StringBuffer txt;
		txt << round(getEnergy()) << "%";
		alm->insertAttribute("cat_armor_special_protection.armor_eff_energy", txt.toString());
	}

	if (getElectricity() > 90) {
		StringBuffer txt;
		txt << round(getElectricity()) << "%";
		alm->insertAttribute("cat_armor_special_protection.armor_eff_elemental_electrical", txt.toString());
	}

	if (getStun() > 90) {
		StringBuffer txt;
		txt << round(getStun()) << "%";
		alm->insertAttribute("cat_armor_special_protection.armor_eff_stun", txt.toString());
	}

	if (getBlast() > 90) {
		StringBuffer txt;
		txt << round(getBlast()) << "%";
		alm->insertAttribute("cat_armor_special_protection.armor_eff_blast", txt.toString());
	}

	if (getHeat() > 90) {
		StringBuffer txt;
		txt << round(getHeat()) << "%";
		alm->insertAttribute("cat_armor_special_protection.armor_eff_elemental_heat", txt.toString());
	}

	if (getCold() > 90) {
		StringBuffer txt;
		txt << round(getCold()) << "%";
		alm->insertAttribute("cat_armor_special_protection.armor_eff_elemental_cold", txt.toString());
	}

	if (getAcid() > 90) {
		StringBuffer txt;
		txt << round(getAcid()) << "%";
		alm->insertAttribute("cat_armor_special_protection.armor_eff_elemental_acid", txt.toString());
	}

	if (getLightSaber() > 90) {
		StringBuffer txt;
		txt << round(getLightSaber()) << "%";
		alm->insertAttribute("cat_armor_special_protection.armor_eff_restraint", txt.toString());
	}

	if (getKinetic() > 0 && getKinetic() <= 90) {
		StringBuffer txt;
		txt << round(getKinetic()) << "%";
		alm->insertAttribute("cat_armor_effectiveness.armor_eff_kinetic", txt.toString());
	}

	if (getEnergy() > 0 && getEnergy() <= 90) {
		StringBuffer txt;
		txt << round(getEnergy()) << "%";
		alm->insertAttribute("cat_armor_effectiveness.armor_eff_energy", txt.toString());
	}

	if (getElectricity() > 0 && getElectricity() <= 90) {
		StringBuffer txt;
		txt << round(getElectricity()) << "%";
		alm->insertAttribute("cat_armor_effectiveness.armor_eff_elemental_electrical", txt.toString());
	}

	if (getStun() > 0 && getStun() <= 90) {
		StringBuffer txt;
		txt << round(getStun()) << "%";
		alm->insertAttribute("cat_armor_effectiveness.armor_eff_stun", txt.toString());
	}

	if (getBlast() > 0 && getBlast() <= 90) {
		StringBuffer txt;
		txt << round(getBlast()) << "%";
		alm->insertAttribute("cat_armor_effectiveness.armor_eff_blast", txt.toString());
	}

	if (getHeat() > 0 && getHeat() <= 90) {
		StringBuffer txt;
		txt << round(getHeat()) << "%";
		alm->insertAttribute("cat_armor_effectiveness.armor_eff_elemental_heat", txt.toString());
	}

	if (getCold() > 0 && getCold() <= 90) {
		StringBuffer txt;
		txt << round(getCold()) << "%";
		alm->insertAttribute("cat_armor_effectiveness.armor_eff_elemental_cold", txt.toString());
	}

	if (getAcid() > 0 && getAcid() <= 90) {
		StringBuffer txt;
		txt << round(getAcid()) << "%";
		alm->insertAttribute("cat_armor_effectiveness.armor_eff_elemental_acid", txt.toString());
	}

	if (getLightSaber() > 0 && getLightSaber() <= 90) {
		StringBuffer txt;
		txt << round(getLightSaber()) << "%";
		alm->insertAttribute("cat_armor_effectiveness.armor_eff_restraint", txt.toString());
	}

	if (getKinetic() < 0)
		alm->insertAttribute("cat_armor_vulnerability.armor_eff_kinetic", "-");

	if (getEnergy() < 0)
		alm->insertAttribute("cat_armor_vulnerability.armor_eff_energy", "-");

	if (getElectricity() < 0)
		alm->insertAttribute("cat_armor_vulnerability.armor_eff_elemental_electrical", "-");

	if (getStun() < 0)
		alm->insertAttribute("cat_armor_vulnerability.armor_eff_stun", "-");

	if (getBlast() < 0)
		alm->insertAttribute("cat_armor_vulnerability.armor_eff_blast", "-");

	if (getHeat() < 0)
		alm->insertAttribute("cat_armor_vulnerability.armor_eff_elemental_heat", "-");

	if (getCold() < 0)
		alm->insertAttribute("cat_armor_vulnerability.armor_eff_elemental_cold", "-");

	if (getAcid() < 0)
		alm->insertAttribute("cat_armor_vulnerability.armor_eff_elemental_acid", "-");

	if (getLightSaber() < 0)
		alm->insertAttribute("cat_armor_vulnerability.armor_eff_restraint", "-");

}
void TurretDataComponent::updateAutoCooldown(float secondsToAdd){
	int milisecondsToAdd = secondsToAdd*1000;
	nextFireTime = Time();
	nextFireTime.addMiliTime(milisecondsToAdd);
}

void TurretDataComponent::updateManualCooldown(float secondsToAdd){
	int milisecondsToAdd = secondsToAdd*1000;
	nextManualFireTime = Time();
	nextManualFireTime.addMiliTime(milisecondsToAdd);
}

unsigned int TurretDataComponent::getArmorRating(){
	if(templateData != NULL)
		return templateData->getArmorRating();

	return 0;
}

float TurretDataComponent::getKinetic(){
	if(templateData != NULL)
		return templateData->getKinetic();

	return 0;
}

float TurretDataComponent::getEnergy(){
	if(templateData != NULL)
		return templateData->getEnergy();

	return 0;
}

float TurretDataComponent::getElectricity(){
	if(templateData != NULL)
		return templateData->getElectricity();
{'fraction_non_alphanumeric': 0.16087527352297593, 'fraction_numerical': 0.009015317286652079, 'mean_word_length': 6.746440677966102, 'pattern_counts': {'":': 0, '<': 105, '<?xml version=': 0, '>': 112, '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': '2408394', 'n_tokens_mistral': 4190, 'n_tokens_neox': 3744, 'n_words': 546}