RPG::State::Restriction Game_Battler::GetSignificantRestriction() const {
	const std::vector<int16_t> states = GetInflictedStates();

	// Priority is nomove > attack enemy > attack ally > normal

	RPG::State::Restriction sig_res = RPG::State::Restriction_normal;
	for (int i = 0; i < (int)states.size(); i++) {
		// States are guaranteed to be valid
		const RPG::State* state = ReaderUtil::GetElement(Data::states, states[i]);

		switch (state->restriction) {
			case RPG::State::Restriction_normal:
				break;
			case RPG::State::Restriction_do_nothing:
				return RPG::State::Restriction_do_nothing;
			case RPG::State::Restriction::Restriction_attack_enemy:
				if (sig_res == RPG::State::Restriction::Restriction_attack_ally
						|| sig_res == RPG::State::Restriction_normal) {
					sig_res = RPG::State::Restriction_attack_enemy;
				}
				break;
			case RPG::State::Restriction::Restriction_attack_ally:
				if (sig_res == RPG::State::Restriction_normal) {
					sig_res = RPG::State::Restriction_attack_ally;
				}
		}
	}
	return sig_res;
}
bool Game_Battler::EvadesAllPhysicalAttacks() const {
	for (auto state_id: GetInflictedStates()) {
		auto* state = ReaderUtil::GetElement(Data::states, state_id);
		if (state && state->avoid_attacks) {
			return true;
		}
	}
	return false;
}
示例#3
0
bool Game_Battler::HasReflectState() const {
	for (int16_t i : GetInflictedStates()) {
		// States are guaranteed to be valid
		if (ReaderUtil::GetElement(Data::states, i)->reflect_magic) {
			return true;
		}
	}

	return false;
}
示例#4
0
bool Game_Battler::CanAct() {
	const std::vector<int16_t> states = GetInflictedStates();
	for (int i = 0; i < (int)states.size(); i++) {
		const RPG::State* state = &Data::states[states[i] - 1];
		if (state->restriction == RPG::State::Restriction_do_nothing) {
			return false;
		}
	}
	return true;
}
示例#5
0
int Game_Battler::GetSignificantRestriction() {
	const std::vector<int16_t> states = GetInflictedStates();
	for (int i = 0; i < (int)states.size(); i++) {
		const RPG::State* state = &Data::states[states[i] - 1];
		if (state->restriction != RPG::State::Restriction_normal) {
			return state->restriction;
		}
	}
	return RPG::State::Restriction_normal;
}
示例#6
0
int Game_Battler::GetSignificantRestriction() {
	const std::vector<int16_t> states = GetInflictedStates();
	for (int i = 0; i < (int)states.size(); i++) {
		// States are guaranteed to be valid
		const RPG::State* state = ReaderUtil::GetElement(Data::states, states[i]);
		if (state->restriction != RPG::State::Restriction_normal) {
			return state->restriction;
		}
	}
	return RPG::State::Restriction_normal;
}
int Game_Battler::GetHitChanceModifierFromStates() const {
	int modifier = 100;
	// Modify hit chance for each state the source has
	for (const auto id : GetInflictedStates()) {
		auto* state = ReaderUtil::GetElement(Data::states, id);
		if (state) {
			modifier = std::min<int>(modifier, state->reduce_hit_ratio);
		}
	}
	return modifier;
}
示例#8
0
bool Game_Battler::CanAct() const {
	const std::vector<int16_t> states = GetInflictedStates();
	for (int i = 0; i < (int)states.size(); i++) {
		// States are guaranteed to be valid
		const RPG::State* state = ReaderUtil::GetElement(Data::states, states[i]);
		if (state->restriction == RPG::State::Restriction_do_nothing) {
			return false;
		}
	}
	return true;
}
示例#9
0
int Game_Battler::ApplyConditions()
{
	int damageTaken = 0;
	for (int16_t inflicted : GetInflictedStates()) {
		RPG::State state = Data::states[inflicted - 1];
		int hp = state.hp_change_val + (int)(std::ceil(GetMaxHp() * state.hp_change_max / 100.0));
		int sp = state.sp_change_val + (int)(std::ceil(GetMaxHp() * state.sp_change_max / 100.0));
		int source_hp = this->GetHp();
		int source_sp = this->GetSp();
		int src_hp = 0;
		int src_sp = 0;
		if (state.hp_change_type == state.ChangeType_lose) {
			src_hp = -std::min(source_hp - 1, hp);
			if(src_hp > 0) {
				src_hp = 0;
			}
		}
		else if(state.hp_change_type == state.ChangeType_gain) {
			src_hp = std::min(source_hp, hp);
			if(src_hp < 0) {
				src_hp = 0;
			}
		}
		else {
			src_hp = 0;
		}
		if (state.sp_change_type == state.ChangeType_lose) {
			src_sp = -std::min(source_sp, sp);
			if(src_sp > 0) {
				src_sp = 0;
			}

		}
		else if(state.sp_change_type == state.ChangeType_gain) {
			src_sp = std::min(source_sp, sp);
			if(src_sp < 0 ) {
				src_sp = 0;
			}
		}
		else {
			src_sp = 0;
		}
		this->ChangeHp(src_hp);
		this->ChangeSp(src_sp);
		damageTaken += src_hp;
	}
	if(damageTaken < 0) {
		return -damageTaken;
	}
	else {
		return damageTaken;
	}
}
示例#10
0
bool Game_Actor::IsEquipmentFixed() const {
	if (GetData().lock_equipment) {
		return true;
	}

	for (auto state_id: GetInflictedStates()) {
		auto* state = ReaderUtil::GetElement(Data::states, state_id);
		if (state && state->cursed) {
			return true;
		}
	}
	return false;
}
示例#11
0
int Game_Battler::ApplyConditions() {
	int damageTaken = 0;
	for (int16_t inflicted : GetInflictedStates()) {
		// States are guaranteed to be valid
		RPG::State& state = *ReaderUtil::GetElement(Data::states, inflicted);
		int hp = state.hp_change_val + (int)(std::ceil(GetMaxHp() * state.hp_change_max / 100.0));
		int sp = state.sp_change_val + (int)(std::ceil(GetMaxHp() * state.sp_change_max / 100.0));
		int source_hp = this->GetHp();
		int source_sp = this->GetSp();
		int src_hp = 0;
		int src_sp = 0;
		if (state.hp_change_type == state.ChangeType_lose) {
			src_hp = -std::min(source_hp - 1, hp);
			if(src_hp > 0) {
				src_hp = 0;
			}
		}
		else if(state.hp_change_type == state.ChangeType_gain) {
			src_hp = std::min(source_hp, hp);
			if(src_hp < 0) {
				src_hp = 0;
			}
		}
		else {
			src_hp = 0;
		}
		if (state.sp_change_type == state.ChangeType_lose) {
			src_sp = -std::min(source_sp, sp);
			if(src_sp > 0) {
				src_sp = 0;
			}

		}
		else if (state.sp_change_type == state.ChangeType_gain) {
			src_sp = std::min(source_sp, sp);
			if(src_sp < 0 ) {
				src_sp = 0;
			}
		}
		else {
			src_sp = 0;
		}
		this->ChangeHp(src_hp);
		this->ChangeSp(src_sp);
		damageTaken += src_hp;
	}

	return damageTaken;
}
示例#12
0
int Game_Battler::GetAgi() const {
	int base_agi = GetBaseAgi();
	int n = min(max(base_agi, 1), 999);

	const std::vector<int16_t> states = GetInflictedStates();
	for (std::vector<int16_t>::const_iterator i = states.begin(); i != states.end(); ++i) {
		if(Data::states[(*i) - 1].affect_agility) {
			n = AffectParameter(Data::states[(*i) - 1].affect_type, base_agi);
			break;
		}
	}

	n += agi_modifier;

	n = min(max(n, 1), 999);

	return n;
}
示例#13
0
const RPG::State* Game_Battler::GetSignificantState() {
	int priority = 0;
	const RPG::State* the_state = NULL;

	const std::vector<int16_t> states = GetInflictedStates();
	for (int i = 0; i < (int) states.size(); i++) {
		const RPG::State* state = &Data::states[states[i] - 1];
		// Death has highest priority
		if (state->ID == 1)
			return state;

		if (state->priority >= priority) {
			the_state = state;
			priority = state->priority;
		}
	}

	return the_state;
}
示例#14
0
int Game_Battler::GetSpi() const {
	int base_spi = GetBaseSpi();
	int n = Utils::Clamp(base_spi, 1, MaxStatBaseValue());

	for (int16_t i : GetInflictedStates()) {
		// States are guaranteed to be valid
		const RPG::State& state = *ReaderUtil::GetElement(Data::states, i);
		if (state.affect_spirit) {
			n = AffectParameter(state.affect_type, base_spi);
			break;
		}
	}

	n += spi_modifier;

	n = Utils::Clamp(n, 1, MaxStatBattleValue());

	return n;
}
示例#15
0
int Game_Battler::GetAgi() const {
	int base_agi = GetBaseAgi();
	int n = min(max(base_agi, 1), 999);

	for (int16_t i : GetInflictedStates()) {
		// States are guaranteed to be valid
		const RPG::State& state = *ReaderUtil::GetElement(Data::states, i);
		if (state.affect_agility) {
			n = AffectParameter(state.affect_type, base_agi);
			break;
		}
	}

	n += agi_modifier;

	n = min(max(n, 1), 999);

	return n;
}
示例#16
0
const RPG::State* Game_Battler::GetSignificantState() const {
	int priority = 0;
	const RPG::State* the_state = NULL;

	const std::vector<int16_t> states = GetInflictedStates();
	for (int i = 0; i < (int) states.size(); i++) {
		// States are guaranteed to be valid
		const RPG::State* state = ReaderUtil::GetElement(Data::states, states[i]);
		// Death has highest priority
		if (state->ID == 1)
			return state;

		if (state->priority >= priority) {
			the_state = state;
			priority = state->priority;
		}
	}

	return the_state;
}
示例#17
0
bool Game_Battler::IsSkillUsable(int skill_id) const {
	const RPG::Skill* skill = ReaderUtil::GetElement(Data::skills, skill_id);

	if (!skill) {
		Output::Warning("IsSkillUsable: Invalid skill ID %d", skill_id);
		return false;
	}

	if (CalculateSkillCost(skill_id) > GetSp()) {
		return false;
	}

	// > 10 makes any skill usable
	int32_t smallest_physical_rate = 11;
	int32_t smallest_magical_rate = 11;

	const std::vector<int16_t> states = GetInflictedStates();
	for (std::vector<int16_t>::const_iterator it = states.begin();
		it != states.end(); ++it) {
		// States are guaranteed to be valid
		const RPG::State& state = *ReaderUtil::GetElement(Data::states, (*it));

		if (state.restrict_skill) {
			smallest_physical_rate = std::min(state.restrict_skill_level, smallest_physical_rate);
		}

		if (state.restrict_magic) {
			smallest_magical_rate = std::min(state.restrict_magic_level, smallest_magical_rate);
		}
	}

	if (skill->physical_rate >= smallest_physical_rate) {
		return false;
	}
	if (skill->magical_rate >= smallest_magical_rate) {
		return false;
	}

	return true;
}
示例#18
0
bool Game_Party::ApplyStateDamage() {
	bool damage = false;
	std::vector<int16_t> states = GetInflictedStates();

	const auto steps = GetSteps();

	for (auto state_id : states) {
		RPG::State *state = ReaderUtil::GetElement(Data::states, state_id);

		// NOTE: We do steps + 1 here because this gets called before steps are incremented.

		if (state->hp_change_map_steps > 0
				&& state->hp_change_map_val > 0
				&& (((steps + 1) % state->hp_change_map_steps) == 0)
				) {
			for (auto actor : GetActors()) {
				if (actor->HasState(state_id)) {
					actor->ChangeHp(-std::max<int>(0, std::min<int>(state->hp_change_map_val, actor->GetHp() - 1)));
					damage = true;
				}
			}
		}

		if (state->sp_change_map_steps > 0
				&& state->sp_change_map_val > 0
				&& (((steps + 1) % state->sp_change_map_steps) == 0)
		   ){
			for (auto actor : GetActors()) {
				if (actor->HasState(state_id)) {
					actor->ChangeSp(-state->sp_change_map_val);
					damage = true;
				}
			}
		}
	}

	return damage;
}
示例#19
0
bool Game_Battler::IsSkillUsable(int skill_id) const {
	if (skill_id <= 0 || skill_id > (int)Data::skills.size()) {
		return false;
	}

	const RPG::Skill& skill = Data::skills[skill_id - 1];

	if (CalculateSkillCost(skill_id) > GetSp()) {
		return false;
	}
	
	// > 10 makes any skill usable
	int smallest_physical_rate = 11;
	int smallest_magical_rate = 11;

	const std::vector<int16_t> states = GetInflictedStates();
	for (std::vector<int16_t>::const_iterator it = states.begin();
		it != states.end(); ++it) {
		const RPG::State& state = Data::states[(*it) - 1];

		if (state.restrict_skill) {
			smallest_physical_rate = std::min(state.restrict_skill_level, smallest_physical_rate);
		}

		if (state.restrict_magic) {
			smallest_magical_rate = std::min(state.restrict_magic_level, smallest_magical_rate);
		}
	}

	if (skill.physical_rate >= smallest_physical_rate) {
		return false;
	}
	if (skill.magical_rate >= smallest_magical_rate) {
		return false;
	}

	return true;
}
示例#20
0
bool Game_Battler::HasState(int state_id) const {
	const std::vector<int16_t> states = GetInflictedStates();

	return (std::find(states.begin(), states.end(), state_id) != states.end());
}