<commit_before>/*
 * CombatQueueCommand.h
 *
 *  Created on: 24/05/2010
 *      Author: victor
 */

#ifndef COMBATQUEUECOMMAND_H_
#define COMBATQUEUECOMMAND_H_

#include"server/zone/ZoneServer.h"
#include "server/zone/Zone.h"
#include "server/zone/objects/scene/SceneObject.h"
#include "server/zone/managers/combat/CombatManager.h"
#include "server/zone/managers/player/PlayerManager.h"
#include "server/zone/objects/player/PlayerObject.h"
#include "server/zone/managers/combat/CreatureAttackData.h"
#include "server/zone/managers/collision/CollisionManager.h"
#include "server/zone/objects/creature/CreatureAttribute.h"
#include "server/zone/objects/creature/CreatureState.h"
#include "server/zone/objects/creature/commands/effect/StateEffect.h"
#include "server/zone/objects/creature/commands/effect/DotEffect.h"
#include "server/zone/objects/creature/commands/effect/CommandEffect.h"
#include "server/zone/packets/object/CombatSpam.h"
#include "QueueCommand.h"
#include "server/zone/managers/collision/PathFinderManager.h"

class CombatQueueCommand : public QueueCommand {
protected:
	float minDamage;
	float maxDamage;
	int damageType;
	float damageMultiplier;
	int accuracyBonus;
	float speedMultiplier;
	float speed;
	int poolsToDamage;

	float healthCostMultiplier;
	float actionCostMultiplier;
	float mindCostMultiplier;
	float forceCostMultiplier;
	float forceCost;
	int visMod;

	int coneRange;
	int range;

	String accuracySkillMod;

	bool splashDamage;
	bool areaAction;
	bool coneAction;
	int coneAngle;
	int areaRange;

	String combatSpam;
	String stateSpam;
	uint32 animationCRC;
	String effectString;

	VectorMap<uint8, StateEffect> stateEffects;
	Vector<DotEffect> dotEffects;

	uint8 attackType;
	uint8 trails;

	uint32 weaponType;

public:

	CombatQueueCommand(const String& name, ZoneProcessServer* server) : QueueCommand(name, server) {

		minDamage = 0;
		maxDamage = 0;
		damageType = 0;
		damageMultiplier = 1;
		accuracyBonus = 0;
		speedMultiplier = 1;
		speed = 0;
		healthCostMultiplier = 1;
		actionCostMultiplier = 1;
		mindCostMultiplier = 1;

		// Force Power is only set in Jedi-skills.
		forceCostMultiplier = 0;
		forceCost = 0;
		visMod = 0;

		poolsToDamage = CombatManager::RANDOM;

		coneAngle = 30;

		coneRange = -1;

		//for weapon set -1
		range = -1;

		accuracySkillMod = "";

		areaRange = 0;
		splashDamage = false;
		areaAction = false;
		coneAction = false;

		combatSpam = "";
		animationCRC = 0;

		attackType = CombatManager::WEAPONATTACK;
		trails = CombatManager::DEFAULTTRAIL;

		weaponType = CombatManager::ANYWEAPON;
	}

	int doCombatAction(CreatureObject* creature, const uint64& target, const UnicodeString& arguments = "", ManagedReference<WeaponObject*> weapon = NULL) const {
		ManagedReference<SceneObject*> targetObject = server->getZoneServer()->getObject(target);
		PlayerManager* playerManager = server->getPlayerManager();

		if (targetObject == NULL || !targetObject->isTangibleObject() || targetObject == creature)
			return INVALIDTARGET;

		float checkRange = range;

		if (weapon == NULL) {
			if(creature->getWeapon() == NULL) {
				return GENERALERROR;
			}
			else {
				weapon = creature->getWeapon();
			}
		}

		if (!(getWeaponType() & weapon->getWeaponBitmask()))
			return INVALIDWEAPON;

		if (checkRange == -1)
			checkRange = MAX(10.f, weapon->getMaxRange());

		if (creature->isDead() || (creature->isPet() && creature->isIncapacitated()))
			return INVALIDLOCOMOTION;

		if (creature->isPlayerCreature()){
			PlayerObject* ghost = creature->getPlayerObject();

			if (ghost != NULL) {
				if (ghost->isOnLoadScreen())
					ghost->setOnLoadScreen(false);

				if (ghost->isAFK())
					return GENERALERROR;

				ManagedReference<TangibleObject*> targetTano = targetObject.castTo<TangibleObject*>();

				if (targetTano != NULL && creature->getFaction() != 0 && targetTano->getFaction() != 0 && targetTano->getFaction() != creature->getFaction() && ghost->getFactionStatus() != FactionStatus::OVERT) {
					if (targetTano->isCreatureObject()) {
						ManagedReference<CreatureObject*> targetCreature = targetObject.castTo<CreatureObject*>();

						if (targetCreature != NULL) {
							if (targetCreature->isPlayerCreature() && !CombatManager::instance()->areInDuel(creature, targetCreature)) {
								PlayerObject* targetGhost = targetCreature->getPlayerObject();

								if (targetGhost != NULL && targetGhost->getFactionStatus() == FactionStatus::OVERT) {
									ghost->doFieldFactionChange(FactionStatus::OVERT);
								}
							} else if (targetCreature->isPet()) {
								ManagedReference<CreatureObject*> targetOwner = targetCreature->getLinkedCreature().get();

								if (targetOwner != NULL && !CombatManager::instance()->areInDuel(creature, targetOwner)) {
									PlayerObject* targetGhost = targetOwner->getPlayerObject();

									if (targetGhost != NULL && targetGhost->getFactionStatus() == FactionStatus::OVERT) {
										ghost->doFieldFactionChange(FactionStatus::OVERT);
									}
								}
							} else {
								if (ghost->getFactionStatus() == FactionStatus::ONLEAVE)
									ghost->doFieldFactionChange(FactionStatus::COVERT);
							}
						}
					} else {
						if (ghost->getFactionStatus() == FactionStatus::ONLEAVE && !(targetTano->getPvpStatusBitmask() & CreatureFlag::OVERT))
							ghost->doFieldFactionChange(FactionStatus::COVERT);
						else if ((targetTano->getPvpStatusBitmask() & CreatureFlag::OVERT))<commit_msg>[fixed] Field faction change bug when dueling<commit_after>/*
 * CombatQueueCommand.h
 *
 *  Created on: 24/05/2010
 *      Author: victor
 */

#ifndef COMBATQUEUECOMMAND_H_
#define COMBATQUEUECOMMAND_H_

#include"server/zone/ZoneServer.h"
#include "server/zone/Zone.h"
#include "server/zone/objects/scene/SceneObject.h"
#include "server/zone/managers/combat/CombatManager.h"
#include "server/zone/managers/player/PlayerManager.h"
#include "server/zone/objects/player/PlayerObject.h"
#include "server/zone/managers/combat/CreatureAttackData.h"
#include "server/zone/managers/collision/CollisionManager.h"
#include "server/zone/objects/creature/CreatureAttribute.h"
#include "server/zone/objects/creature/CreatureState.h"
#include "server/zone/objects/creature/commands/effect/StateEffect.h"
#include "server/zone/objects/creature/commands/effect/DotEffect.h"
#include "server/zone/objects/creature/commands/effect/CommandEffect.h"
#include "server/zone/packets/object/CombatSpam.h"
#include "QueueCommand.h"
#include "server/zone/managers/collision/PathFinderManager.h"

class CombatQueueCommand : public QueueCommand {
protected:
	float minDamage;
	float maxDamage;
	int damageType;
	float damageMultiplier;
	int accuracyBonus;
	float speedMultiplier;
	float speed;
	int poolsToDamage;

	float healthCostMultiplier;
	float actionCostMultiplier;
	float mindCostMultiplier;
	float forceCostMultiplier;
	float forceCost;
	int visMod;

	int coneRange;
	int range;

	String accuracySkillMod;

	bool splashDamage;
	bool areaAction;
	bool coneAction;
	int coneAngle;
	int areaRange;

	String combatSpam;
	String stateSpam;
	uint32 animationCRC;
	String effectString;

	VectorMap<uint8, StateEffect> stateEffects;
	Vector<DotEffect> dotEffects;

	uint8 attackType;
	uint8 trails;

	uint32 weaponType;

public:

	CombatQueueCommand(const String& name, ZoneProcessServer* server) : QueueCommand(name, server) {

		minDamage = 0;
		maxDamage = 0;
		damageType = 0;
		damageMultiplier = 1;
		accuracyBonus = 0;
		speedMultiplier = 1;
		speed = 0;
		healthCostMultiplier = 1;
		actionCostMultiplier = 1;
		mindCostMultiplier = 1;

		// Force Power is only set in Jedi-skills.
		forceCostMultiplier = 0;
		forceCost = 0;
		visMod = 0;

		poolsToDamage = CombatManager::RANDOM;

		coneAngle = 30;

		coneRange = -1;

		//for weapon set -1
		range = -1;

		accuracySkillMod = "";

		areaRange = 0;
		splashDamage = false;
		areaAction = false;
		coneAction = false;

		combatSpam = "";
		animationCRC = 0;

		attackType = CombatManager::WEAPONATTACK;
		trails = CombatManager::DEFAULTTRAIL;

		weaponType = CombatManager::ANYWEAPON;
	}

	int doCombatAction(CreatureObject* creature, const uint64& target, const UnicodeString& arguments = "", ManagedReference<WeaponObject*> weapon = NULL) const {
		ManagedReference<SceneObject*> targetObject = server->getZoneServer()->getObject(target);
		PlayerManager* playerManager = server->getPlayerManager();

		if (targetObject == NULL || !targetObject->isTangibleObject() || targetObject == creature)
			return INVALIDTARGET;

		float checkRange = range;

		if (weapon == NULL) {
			if(creature->getWeapon() == NULL) {
				return GENERALERROR;
			}
			else {
				weapon = creature->getWeapon();
			}
		}

		if (!(getWeaponType() & weapon->getWeaponBitmask()))
			return INVALIDWEAPON;

		if (checkRange == -1)
			checkRange = MAX(10.f, weapon->getMaxRange());

		if (creature->isDead() || (creature->isPet() && creature->isIncapacitated()))
			return INVALIDLOCOMOTION;

		if (creature->isPlayerCreature()){
			PlayerObject* ghost = creature->getPlayerObject();

			if (ghost != NULL) {
				if (ghost->isOnLoadScreen())
					ghost->setOnLoadScreen(false);

				if (ghost->isAFK())
					return GENERALERROR;

				ManagedReference<TangibleObject*> targetTano = targetObject.castTo<TangibleObject*>();

				if (targetTano != NULL && creature->getFaction() != 0 && targetTano->getFaction() != 0 && targetTano->getFaction() != creature->getFaction() && ghost->getFactionStatus() != FactionStatus::OVERT) {
					if (targetTano->isCreatureObject()) {
						ManagedReference<CreatureObject*> targetCreature = targetObject.castTo<CreatureObject*>();

						if (targetCreature != NULL) {
							if (targetCreature->isPlayerCreature()) {
								if (!CombatManager::instance()->areInDuel(creature, targetCreature)) {
									PlayerObject* targetGhost = targetCreature->getPlayerObject();

									if (targetGhost != NULL && targetGhost->getFactionStatus() == FactionStatus::OVERT) {
										ghost->doFieldFactionChange(FactionStatus::OVERT);
									}
								}
							} else if (targetCreature->isPet()) {
								ManagedReference<CreatureObject*> targetOwner = targetCreature->getLinkedCreature().get();

								if (targetOwner != NULL && !CombatManager::instance()->areInDuel(creature, targetOwner)) {
									PlayerObject* targetGhost = targetOwner->getPlayerObject();

									if (targetGhost != NULL && targetGhost->getFactionStatus() == FactionStatus::OVERT) {
										ghost->doFieldFactionChange(FactionStatus::OVERT);
									}
								}
							} else {
								if (ghost->getFactionStatus() == FactionStatus::ONLEAVE)
									ghost->doFieldFactionChange(FactionStatus::COVERT);
							}
						}
					} else {
						if (ghost->getFactionStatus() == FactionStatus::ONLEAVE && !(targetTano->getPvpStatusBitmask() & CreatureFlag::OVERT))
							ghost->doFieldFactionChange(FactionStatus::COVERT);
						else if ((targetTano->getPvpStatusBitmask() & CreatureFlag::OVERT))
{'fraction_non_alphanumeric': 0.12673484295105916, 'fraction_numerical': 0.007669831994156318, 'mean_word_length': 4.468297553669496, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 99, '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': '3524774', 'n_tokens_mistral': 4163, 'n_tokens_neox': 3534, 'n_words': 654}