Пример #1
0
int Game_Enemy::GetAttributeModifier(int attribute_id) const {
	int rate = 2; // C - default

	if (attribute_id <= (int)enemy->attribute_ranks.size()) {
		rate = enemy->attribute_ranks[attribute_id - 1];
	}

	rate += attribute_shift[attribute_id - 1];
	if (rate < 0) {
		rate = 0;
	} else if (rate > 4) {
		rate = 4;
	}

	return GetAttributeRate(attribute_id, rate);
}
Пример #2
0
int Game_Actor::GetAttributeModifier(int attribute_id) const {
	int rate = 2; // C - default

	const uint8_t* r = ReaderUtil::GetElement(GetActor().attribute_ranks, attribute_id);
	if (r) {
		rate = *r;
	}

	// GetAttributeRate will verify this but actors already need a check earlier
	// because of attribute_shift
	const int* shift = ReaderUtil::GetElement(attribute_shift, attribute_id);

	if (!shift) {
		Output::Warning("GetAttributeModifier: Invalid attribute ID %d", attribute_id);
		return 0;
	}

	rate += *shift;
	for (auto id_object : GetWholeEquipment()) {
		RPG::Item *object = ReaderUtil::GetElement(Data::items, id_object);
		if (object != nullptr && (object->type == RPG::Item::Type_shield || object->type == RPG::Item::Type_armor
			|| object->type == RPG::Item::Type_helmet || object->type == RPG::Item::Type_accessory)
			&& object->attribute_set.size() >= attribute_id && object->attribute_set[attribute_id - 1]) {
			rate++;
			break;
		}
	}

	if (rate < 0) {
		rate = 0;
	} else if (rate > 4) {
		rate = 4;
	}

	return GetAttributeRate(attribute_id, rate);
}