Skip to content

Commit

Permalink
Some adjusts and enhancement from prey system (#567)
Browse files Browse the repository at this point in the history
Resolves #544

Fixed duplication on prey bonus attack (damage)
Fixed the percentage formula for each bonus
Fixed reload bonus and bonus percentage order (was reloading before the percentage and after the bonus, which generated an unexpected behavior)
  • Loading branch information
dudantas authored Nov 9, 2022
1 parent 1f1dd6f commit f09d94d
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 47 deletions.
10 changes: 4 additions & 6 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ gamestoreByModules = true
preySystemEnabled = true
preyFreeThirdSlot = false
preyRerollPricePerLevel = 200
preySelectListPrice = 1
preyBonusRerollPrice = 2
preyBonusPercentMin = 5
preyBonusPercentMax = 40
preySelectListPrice = 5
preyBonusRerollPrice = 1
preyBonusTime = 2 * 60 * 60
preyFreeRerollTime = 20 * 60 * 60

Expand All @@ -79,8 +77,8 @@ taskHuntingSystemEnabled = true
taskHuntingFreeThirdSlot = false
taskHuntingLimitedTasksExhaust = 20 * 60 * 60
taskHuntingRerollPricePerLevel = 200
taskHuntingSelectListPrice = 1
taskHuntingBonusRerollPrice = 2
taskHuntingSelectListPrice = 5
taskHuntingBonusRerollPrice = 1
taskHuntingFreeRerollTime = 20 * 60 * 60

-- Forge system
Expand Down
2 changes: 0 additions & 2 deletions src/config/config_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ enum integerConfig_t {
SAVE_INTERVAL_TIME,
PREY_REROLL_PRICE_LEVEL,
PREY_SELECTION_LIST_PRICE,
PREY_BONUS_PERCENT_MIN,
PREY_BONUS_PERCENT_MAX,
PREY_BONUS_TIME,
PREY_BONUS_REROLL_PRICE,
PREY_FREE_REROLL_TIME,
Expand Down
10 changes: 4 additions & 6 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,19 +282,17 @@ bool ConfigManager::load()
boolean[PREY_ENABLED] = getGlobalBoolean(L, "preySystemEnabled", true);
boolean[PREY_FREE_THIRD_SLOT] = getGlobalBoolean(L, "preyFreeThirdSlot", false);
integer[PREY_REROLL_PRICE_LEVEL] = getGlobalNumber(L, "preyRerollPricePerLevel", 200);
integer[PREY_SELECTION_LIST_PRICE] = getGlobalNumber(L, "preySelectListPrice", 1);
integer[PREY_BONUS_PERCENT_MIN] = getGlobalNumber(L, "preyBonusPercentMin", 5);
integer[PREY_BONUS_PERCENT_MAX] = getGlobalNumber(L, "preyBonusPercentMax", 40);
integer[PREY_SELECTION_LIST_PRICE] = getGlobalNumber(L, "preySelectListPrice", 5);
integer[PREY_BONUS_TIME] = getGlobalNumber(L, "preyBonusTime", 7200);
integer[PREY_BONUS_REROLL_PRICE] = getGlobalNumber(L, "preyBonusRerollPrice", 2);
integer[PREY_BONUS_REROLL_PRICE] = getGlobalNumber(L, "preyBonusRerollPrice", 1);
integer[PREY_FREE_REROLL_TIME] = getGlobalNumber(L, "preyFreeRerollTime", 72000);

boolean[TASK_HUNTING_ENABLED] = getGlobalBoolean(L, "taskHuntingSystemEnabled", true);
boolean[TASK_HUNTING_FREE_THIRD_SLOT] = getGlobalBoolean(L, "taskHuntingFreeThirdSlot", false);
integer[TASK_HUNTING_LIMIT_EXHAUST] = getGlobalNumber(L, "taskHuntingLimitedTasksExhaust", 72000);
integer[TASK_HUNTING_REROLL_PRICE_LEVEL] = getGlobalNumber(L, "taskHuntingRerollPricePerLevel", 200);
integer[TASK_HUNTING_SELECTION_LIST_PRICE] = getGlobalNumber(L, "taskHuntingSelectListPrice", 1);
integer[TASK_HUNTING_BONUS_REROLL_PRICE] = getGlobalNumber(L, "taskHuntingBonusRerollPrice", 2);
integer[TASK_HUNTING_SELECTION_LIST_PRICE] = getGlobalNumber(L, "taskHuntingSelectListPrice", 5);
integer[TASK_HUNTING_BONUS_REROLL_PRICE] = getGlobalNumber(L, "taskHuntingBonusRerollPrice", 1);
integer[TASK_HUNTING_FREE_REROLL_TIME] = getGlobalNumber(L, "taskHuntingFreeRerollTime", 72000);

loaded = true;
Expand Down
46 changes: 42 additions & 4 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,12 +494,33 @@ void Combat::CombatHealthFunc(Creature* caster, Creature* target, const CombatPa
{
assert(data);
CombatDamage damage = *data;
if (caster && caster->getPlayer()) {
Item *item = caster->getPlayer()->getWeapon();

Player *attackerPlayer = nullptr;
if (caster) {
attackerPlayer = caster->getPlayer();
}

Monster *targetMonster = nullptr;
if (target) {
targetMonster = target->getMonster();
}

Monster *attackerMonster = nullptr;
if (caster) {
attackerMonster = caster->getMonster();
}

Player *targetPlayer = nullptr;
if (target) {
targetPlayer = target->getPlayer();
}

if (caster && attackerPlayer) {
Item *item = attackerPlayer->getWeapon();
damage = applyImbuementElementalDamage(item, damage);
g_events().eventPlayerOnCombat(caster->getPlayer(), target, item, damage);
g_events().eventPlayerOnCombat(attackerPlayer, target, item, damage);

if (target && target->getSkull() != SKULL_BLACK && target->getPlayer()) {
if (targetPlayer && targetPlayer->getSkull() != SKULL_BLACK) {
if (damage.primary.type != COMBAT_HEALING) {
damage.primary.value /= 2;
}
Expand All @@ -513,6 +534,23 @@ void Combat::CombatHealthFunc(Creature* caster, Creature* target, const CombatPa
return;
}

// Player attacking monster
if (attackerPlayer && targetMonster) {
const PreySlot* slot = attackerPlayer->getPreyWithMonster(targetMonster->getRaceId());
if (slot && slot->isOccupied() && slot->bonus == PreyBonus_Damage && slot->bonusTimeLeft > 0) {
damage.primary.value += static_cast<int32_t>(std::ceil((damage.primary.value * slot->bonusPercentage) / 100));
damage.secondary.value += static_cast<int32_t>(std::ceil((damage.primary.value * slot->bonusPercentage) / 100));
}
}

// Monster attacking player
if (attackerMonster && targetPlayer) {
const PreySlot* slot = targetPlayer->getPreyWithMonster(attackerMonster->getRaceId());
if (slot && slot->isOccupied() && slot->bonus == PreyBonus_Defense && slot->bonusTimeLeft > 0) {
damage.primary.value -= static_cast<int32_t>(std::ceil((damage.primary.value * slot->bonusPercentage) / 100));
}
}

if (g_game().combatChangeHealth(caster, target, damage)) {
CombatConditionFunc(caster, target, params, &damage);
CombatDispelFunc(caster, target, params, nullptr);
Expand Down
14 changes: 0 additions & 14 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5766,20 +5766,6 @@ bool Game::combatChangeHealth(Creature* attacker, Creature* target, CombatDamage
attackerMonster = nullptr;
}

if (attackerPlayer && targetMonster) {
const PreySlot* slot = attackerPlayer->getPreyWithMonster(targetMonster->getRaceId());
if (slot && slot->isOccupied() && slot->bonus == PreyBonus_Damage && slot->bonusTimeLeft > 0) {
damage.primary.value += static_cast<int32_t>(std::ceil((damage.primary.value * slot->bonusPercentage) / 100));
damage.secondary.value += static_cast<int32_t>(std::ceil((damage.secondary.value * slot->bonusPercentage) / 100));
}
} else if (attackerMonster && targetPlayer) {
const PreySlot* slot = targetPlayer->getPreyWithMonster(attackerMonster->getRaceId());
if (slot && slot->isOccupied() && slot->bonus == PreyBonus_Defense && slot->bonusTimeLeft > 0) {
damage.primary.value -= static_cast<int32_t>(std::ceil((damage.primary.value * slot->bonusPercentage) / 100));
damage.secondary.value -= static_cast<int32_t>(std::ceil((damage.secondary.value * slot->bonusPercentage) / 100));
}
}

TextMessage message;
message.position = targetPos;

Expand Down
24 changes: 11 additions & 13 deletions src/io/ioprey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,18 @@ void PreySlot::reloadBonusType()

void PreySlot::reloadBonusValue()
{
auto minBonusPercent = static_cast<uint16_t>(g_configManager().getNumber(PREY_BONUS_PERCENT_MIN));
auto maxBonusPercent = static_cast<uint16_t>(g_configManager().getNumber(PREY_BONUS_PERCENT_MAX));
auto stagePercent = static_cast<uint16_t>(std::floor((maxBonusPercent - minBonusPercent) / 8));
if (bonusRarity >= 9) {
bonusRarity = 10;
} else {
// Every time you roll it will increase the rarity (star)
bonusRarity = static_cast<uint8_t>(uniform_random(bonusRarity + 1, 10));
}

bonusPercentage = stagePercent * bonusRarity;
if (bonusPercentage > maxBonusPercent) {
bonusPercentage = maxBonusPercent;
} else if (bonusPercentage < minBonusPercent) {
bonusPercentage = minBonusPercent;
if (bonus == PreyBonus_Damage) {
bonusPercentage = 2 * bonusRarity + 5;
} else if (bonus == PreyBonus_Defense) {
bonusPercentage = 2 * bonusRarity + 10;
} else {
bonusPercentage = 3 * bonusRarity + 10;
}
}

Expand Down Expand Up @@ -275,8 +273,8 @@ void IOPrey::CheckPlayerPreys(Player* player, uint8_t amount) const
if (slot->bonusTimeLeft <= amount) {
if (slot->option == PreyOption_AutomaticReroll) {
if (player->usePreyCards(static_cast<uint16_t>(g_configManager().getNumber(PREY_BONUS_REROLL_PRICE)))) {
slot->reloadBonusValue();
slot->reloadBonusType();
slot->reloadBonusValue();
slot->bonusTimeLeft = static_cast<uint16_t>(g_configManager().getNumber(PREY_BONUS_TIME));
player->sendTextMessage(MESSAGE_STATUS, "Your prey bonus type and time has been succesfully reseted.");
player->reloadPreySlot(static_cast<PreySlot_t>(slotId));
Expand Down Expand Up @@ -355,8 +353,8 @@ void IOPrey::ParsePreyAction(Player* player,
}

if (slot->bonus == PreyBonus_None) {
slot->reloadBonusValue();
slot->reloadBonusType();
slot->reloadBonusValue();
}

slot->state = PreyDataState_Active;
Expand All @@ -372,8 +370,8 @@ void IOPrey::ParsePreyAction(Player* player,
return;
}

slot->reloadBonusValue();
slot->reloadBonusType();
slot->reloadBonusValue();
slot->bonusTimeLeft = static_cast<uint16_t>(g_configManager().getNumber(PREY_BONUS_TIME));
} else if (action == PreyAction_MonsterSelection) {
if (slot->isOccupied()) {
Expand All @@ -388,8 +386,8 @@ void IOPrey::ParsePreyAction(Player* player,
}

if (slot->bonus == PreyBonus_None) {
slot->reloadBonusValue();
slot->reloadBonusType();
slot->reloadBonusValue();
}
slot->state = PreyDataState_Active;
slot->selectedRaceId = slot->raceIdList[index];
Expand Down
2 changes: 0 additions & 2 deletions src/lua/functions/core/game/config_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ class ConfigFunctions final : LuaScriptInterface {
registerEnumIn(L, "configKeys", PREY_ENABLED)
registerEnumIn(L, "configKeys", PREY_FREE_THIRD_SLOT)
registerEnumIn(L, "configKeys", PREY_REROLL_PRICE_LEVEL)
registerEnumIn(L, "configKeys", PREY_BONUS_PERCENT_MIN)
registerEnumIn(L, "configKeys", PREY_BONUS_PERCENT_MAX)
registerEnumIn(L, "configKeys", PREY_BONUS_TIME)
registerEnumIn(L, "configKeys", PREY_BONUS_REROLL_PRICE)
registerEnumIn(L, "configKeys", PREY_FREE_REROLL_TIME)
Expand Down

0 comments on commit f09d94d

Please sign in to comment.