Ejemplo n.º 1
0
bool BattleTarget::SetPointTarget(GLOBAL_TARGET type, uint32 attack_point, BattleActor* actor) {
	if (IsTargetPoint(type) == false) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "function received invalid type argument: " << type << std::endl;
		return false;
	}
	if ((actor == NULL) && (_actor == NULL)) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "attempted to set an attack point with no valid actor selected" << std::endl;
		return false;
	}
	else if ((actor == NULL) && (attack_point >= _actor->GetAttackPoints().size())) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "attack point index was out-of-range: " << attack_point << std::endl;
		return false;
	}
	else if ((_actor == NULL) && (attack_point >= actor->GetAttackPoints().size())) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "attack point index was out-of-range: " << attack_point << std::endl;
		return false;
	}

	_type = type;
	_point = attack_point;
	if (actor != NULL)
		_actor = actor;
	_party = NULL;
	return true;
}
Ejemplo n.º 2
0
bool BattleTarget::SelectNextPoint(bool direction)
{
    if(IsTargetPoint(_type) == false) {
        IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid target type: " << _type << std::endl;
        return false;
    }
    if(_actor_target == nullptr || _party_target.empty()) {
        IF_PRINT_WARNING(BATTLE_DEBUG) << "No valid target set" << std::endl;
        return false;
    }

    // First check for the case where we need to select a new actor first
    if(!IsValid()) {
        _attack_point = 0;
        return SelectNextActor();
    }

    // If the actor has only a single attack point, there's no way to select another attack point
    uint32_t num_points = _actor_target->GetAttackPoints().size();
    if(num_points == 1)
        return true;

    if(direction == true) {
        ++_attack_point;
        if(_attack_point >= num_points)
            _attack_point = 0;
    } else {
        if(_attack_point == 0)
            _attack_point = num_points - 1;
        else
            --_attack_point;
    }
    return true;
}
Ejemplo n.º 3
0
bool CalculateStandardEvasionAdder(BattleTarget* target, float add_eva) {
	if (target == NULL) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "function received NULL target argument" << std::endl;
		return false;
	}
	if (IsTargetParty(target->GetType()) == true) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "target was a party type: " << target->GetType() << std::endl;
		return false;
	}

	float evasion = 0.0f;
	if (IsTargetPoint(target->GetType()) == true) {
		evasion = target->GetActor()->GetAttackPoint(target->GetPoint())->GetTotalEvadeRating();
	}
	else if (IsTargetActor(target->GetType()) == true) {
		evasion = target->GetActor()->TotalEvadeRating();
	}
	else {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid target type: " << target->GetType() << std::endl;
		return false;
	}

	evasion += add_eva;

	// Check for absolute hit/miss conditions
	if (evasion <= 0.0f)
		return false;
	else if (evasion >= 100.0f)
		return true;

	if (RandomFloat(0.0f, 100.0f) <= evasion)
		return true;
	else
		return false;
} // bool CalculateStandardEvasionAdder(BattleTarget* target, float add_evade)
Ejemplo n.º 4
0
uint32 CalculateMetaphysicalDamageAdder(BattleActor* attacker, BattleTarget* target, int32 add_atk, float std_dev) {
	if (attacker == NULL) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "function received NULL attacker argument" << std::endl;
		return 0;
	}
	if (target == NULL) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "function received NULL target argument" << std::endl;
		return 0;
	}
	if (IsTargetParty(target->GetType()) == true) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "target was a party type: " << target->GetType() << std::endl;
		return 0;
	}
	if (std_dev < 0.0f) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "function received negative standard deviation argument: " << std_dev << std::endl;
		std_dev = fabs(std_dev);
	}

	// Holds the total physical attack of the attacker and modifier
	int32 total_meta_atk = 0;
	total_meta_atk = attacker->GetTotalMetaphysicalAttack() + add_atk;
	if (total_meta_atk < 0)
		total_meta_atk = 0;

	// Holds the total physical defense of the target
	int32 total_meta_def = 0;

	if (IsTargetPoint(target->GetType()) == true) {
		total_meta_def = target->GetActor()->GetAttackPoint(target->GetPoint())->GetTotalMetaphysicalDefense();
	}
	else if (IsTargetActor(target->GetType()) == true) {
		total_meta_def = target->GetActor()->TotalMetaphysicalDefense();
	}
	else {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid target type: " << target->GetType() << std::endl;
		return 0;
	}

	// Holds the total damage dealt
	int32 total_dmg = total_meta_atk - total_meta_def;
	if (total_dmg < 0)
		total_dmg = 0;

	// If the total damage is zero, fall back to causing a small non-zero damage value
	if (total_dmg <= 0)
		return static_cast<uint32>(RandomBoundedInteger(1, 5));

	// Holds the absolute standard deviation used in the GaussianRandomValue function
	float abs_std_dev = 0.0f;
	abs_std_dev = static_cast<float>(total_dmg) * std_dev;
	total_dmg = GaussianRandomValue(total_dmg, abs_std_dev, false);

	// If the total damage came to a value less than or equal to zero after the gaussian randomization,
	// fall back to returning a small non-zero damage value
	if (total_dmg <= 0)
		return static_cast<uint32>(RandomBoundedInteger(1, 5));

	return static_cast<uint32>(total_dmg);
} // uint32 CalculateMetaphysicalDamageAdder(BattleActor* attacker, BattleTarget* target, int32 add_atk, float std_dev)
Ejemplo n.º 5
0
bool BattleTarget::SelectNextActor(bool direction)
{
    if(!IsTargetPoint(_type) && !IsTargetActor(_type)) {
        IF_PRINT_WARNING(BATTLE_DEBUG) << "Invalid target type: " << _type << std::endl;
        return false;
    }

    // Check the target party for early exit conditions
    if(_party_target.empty()) {
        IF_PRINT_WARNING(BATTLE_DEBUG) << "Actor target's party was empty" << std::endl;
        return false;
    }
    if(_party_target.size() == 1) {
        return false; // No more actors to select from in the party
    }

    // The target died in between events. Let's reset it.
    if(!_actor_target) {
        _actor_target = _party_target.at(0);
    }

    // Determine the index of the current actor in the target party
    uint32_t original_target_index = 0xFFFFFFFF; // Initially set to an impossibly high index for error checking
    for(uint32_t i = 0; i < _party_target.size(); ++i) {
        if(_party_target.at(i) == _actor_target) {
            original_target_index = i;
            break;
        }
    }
    if(original_target_index == 0xFFFFFFFF) {
        IF_PRINT_WARNING(BATTLE_DEBUG) << "actor target was not found in party" << std::endl;
        return false;
    }

    // Starting from the index of the original actor, select the next available actor
    BattleActor* original_actor = _actor_target;
    uint32_t new_target_index = original_target_index;
    while(true) {
        // Increment or decrement the target index based on the direction argument
        if(direction == true) {
            new_target_index = (new_target_index >= _party_target.size() - 1) ? 0 : new_target_index + 1;
        } else {
            new_target_index = (new_target_index == 0) ? _party_target.size() - 1 : new_target_index - 1;
        }

        // If we've reached the original target index then we were unable to select another actor target
        if(new_target_index == original_target_index) {
            _actor_target = original_actor;
            return false;
        }

        // Set the new actor target and if required, ascertain the new target's validity. If the new target
        // must be valid and this new actor is not, the loop will continue and will try again with the next actor
        _actor_target = _party_target.at(new_target_index);
        if (IsValid())
            return true;
    }
}
Ejemplo n.º 6
0
bool CalculateStandardEvasionMultiplier(BattleTarget* target, float mul_eva) {
	if (target == NULL) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "function received NULL target argument" << std::endl;
		return false;
	}
	if (IsTargetParty(target->GetType()) == true) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "target was a party type: " << target->GetType() << std::endl;
		return false;
	}
	if (mul_eva < 0.0f) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "function received negative multiplier argument: " << mul_eva << std::endl;
		mul_eva = fabs(mul_eva);
	}

	// Find the base evasion and apply the multiplier
	float evasion = 0.0f;
	if (IsTargetPoint(target->GetType()) == true) {
		evasion = target->GetActor()->GetAttackPoint(target->GetPoint())->GetTotalEvadeRating();
	}
	else if (IsTargetActor(target->GetType()) == true) {
		evasion = target->GetActor()->TotalEvadeRating();
	}
	else {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid target type: " << target->GetType() << std::endl;
		return false;
	}

	evasion = evasion * mul_eva;

	// Check for absolute hit/miss conditions
	if (evasion <= 0.0f)
		return false;
	else if (evasion >= 100.0f)
		return true;

	if (RandomFloat(0.0f, 100.0f) > evasion)
		return false;
	else
		return true;
} // bool CalculateStandardEvasionMultiplier(BattleTarget* target, float mul_evade)
Ejemplo n.º 7
0
bool BattleTarget::SelectNextPoint(BattleActor* user, bool direction, bool valid_criteria,
									bool permit_dead_targets) {
	if (user == NULL) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "function received NULL argument" << std::endl;
		return false;
	}
	if (IsTargetPoint(_type) == false) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid target type: " << _type << std::endl;
		return false;
	}
	if (_actor == NULL) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "no valid actor target" << std::endl;
		return false;
	}

	// First check for the case where we need to select a new actor
	if (valid_criteria && !IsValid(permit_dead_targets)) {
		_point = 0;
		return SelectNextActor(user, direction, valid_criteria, permit_dead_targets);
	}

	// If the actor has only a single attack point, there's no way to select another attack point
	uint32 num_points = _actor->GetAttackPoints().size();
	if (num_points == 1) {
		return false;
	}

	if (direction == true) {
		_point++;
		if (_point >= num_points)
			_point = 0;
	}
	else {
		if (_point == 0)
			_point = num_points - 1;
		else
			_point--;
	}
	return true;
}
Ejemplo n.º 8
0
bool BattleTarget::IsValid(bool permit_dead_targets) {
	// No dead enemies can be selected here.
	if (IsTargetPoint(_type)) {
		if (!_actor)
			return false;
		bool enemy_actor = _actor->IsEnemy();

		if (_point >= _actor->GetAttackPoints().size())
			return false;
		// We extra check the actor HP since the state might desynced on purpose.
		else if (!_actor->IsAlive() || _actor->GetHitPoints() == 0)
			return !enemy_actor && permit_dead_targets;
		else if (_actor->GetState() == ACTOR_STATE_DYING)
			return !enemy_actor && permit_dead_targets;
		else
			return true;
	}
	else if (IsTargetActor(_type) == true) {
		if (!_actor)
			return false;
		bool enemy_actor = _actor->IsEnemy();

		if (!_actor->IsAlive() || _actor->GetHitPoints() == 0)
			return !enemy_actor && permit_dead_targets;
		else if (_actor->GetState() == ACTOR_STATE_DYING)
			return !enemy_actor && permit_dead_targets;
		else
			return true;
	}
	else if (IsTargetParty(_type)) {
		if (!_party)
			return false;
		else
			return true;
	}
	else {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid target type: " << _type << std::endl;
		return false;
	}
}
Ejemplo n.º 9
0
bool BattleTarget::IsValid()
{
    if (!_actor_target || _party_target.empty()) {
        PRINT_WARNING << "No valid actor or party set: " << _type << std::endl;
        return false;
    }

    if(IsTargetPoint(_type)) {
        if(_attack_point >= _actor_target->GetAttackPoints().size())
            return false;
    }

    // If we can't find the actor within the party, then it's bad.
    if (std::find(_party_target.begin(), _party_target.end(), _actor_target) == _party_target.end())
        return false;

    bool permit_dead_targets = (_type == GLOBAL_TARGET_ALLY_EVEN_DEAD || _type == GLOBAL_TARGET_DEAD_ALLY_ONLY);

    if (!_actor_target->IsAlive() || !_actor_target->CanFight() || _actor_target->GetHitPoints() == 0)
        return permit_dead_targets;

    return true;
}
Ejemplo n.º 10
0
bool BattleTarget::SelectNextActor(BattleActor* user, bool direction, bool valid_criteria,
									bool permit_dead_targets) {
	if (!user) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "function received NULL argument"
			<< std::endl;
		return false;
	}
	if ((!IsTargetPoint(_type)) && (!IsTargetActor(_type))) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid target type: " << _type
			<< std::endl;
		return false;
	}
	if (!_actor) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "no valid actor target" << std::endl;
		return false;
	}

	// ----- (1): Retrieve the proper party container that contains the actors we would like to select from
	std::deque<BattleActor*>* target_party = NULL;
	if ((_type == GLOBAL_TARGET_SELF_POINT) || (_type == GLOBAL_TARGET_SELF)) {
		return false; // Self type targets do not have multiple actors to select from
	}
	else if ((_type == GLOBAL_TARGET_ALLY_POINT) || (_type == GLOBAL_TARGET_ALLY)
			|| (_type == GLOBAL_TARGET_ALLY_EVEN_DEAD)) {
		if (user->IsEnemy() == false)
			target_party = &BattleMode::CurrentInstance()->GetCharacterParty();
		else
			target_party = &BattleMode::CurrentInstance()->GetEnemyParty();
	}
	else if ((_type == GLOBAL_TARGET_FOE_POINT) || (_type == GLOBAL_TARGET_FOE)) {
		if (user->IsEnemy() == false)
			target_party = &BattleMode::CurrentInstance()->GetEnemyParty();
		else
			target_party = &BattleMode::CurrentInstance()->GetCharacterParty();
	}
	else {
		// This should never be reached because the target type was already determined to be a point or actor above
		IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid target type: " << _type << std::endl;
		return false;
	}

	// ----- (2): Check the target party for early exit conditions
	if (target_party->empty() == true) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "actor target's party was empty" << std::endl;
		return false;
	}
	if (target_party->size() == 1) {
		return false; // No more actors to select from in the party
	}

	// ----- (3): Determine the index of the current actor in the target party
	uint32 original_target_index = 0xFFFFFFFF; // Initially set to an impossibly high index for error checking
	for (uint32 i = 0; i < target_party->size(); i++) {
		if (target_party->at(i) == _actor) {
			original_target_index = i;
			break;
		}
	}
	if (original_target_index == 0xFFFFFFFF) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "actor target was not found in party" << std::endl;
		return false;
	}

	// ----- (4): Starting from the index of the original actor, select the next available actor
	BattleActor* original_actor = _actor;
	uint32 new_target_index = original_target_index;
	while (true) {
		// Increment or decrement the target index based on the direction argument
		if (direction == true) {
			new_target_index = (new_target_index >= target_party->size() - 1) ? 0 : new_target_index + 1;
		}
		else {
			new_target_index = (new_target_index == 0) ? target_party->size() - 1 : new_target_index - 1;
		}

		// If we've reached the original target index then we were unable to select another actor target
		if (new_target_index == original_target_index) {
			_actor = original_actor;
			return false;
		}

		// Set the new actor target and if required, ascertain the new target's validity. If the new target
		// must be valid and this new actor is not, the loop will continue and will try again with the next actor
		_actor = target_party->at(new_target_index);
		if (valid_criteria == false) {
			return true;
		}
		else if (IsValid(permit_dead_targets)){
			return true;
		}
	}
} // bool BattleTarget::SelectNextActor(BattleActor* user, bool direction, bool valid_criteria)