Skip to content

Commit

Permalink
feat: send events bonus
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Nov 9, 2024
1 parent e5eb93e commit 3a0fce9
Show file tree
Hide file tree
Showing 12 changed files with 246 additions and 86 deletions.
181 changes: 155 additions & 26 deletions data/json/events.json
Original file line number Diff line number Diff line change
@@ -1,49 +1,178 @@
{
"events": [
{
"name": "Otservbr example 1",
"startdate": "11/03/2020",
"enddate": "12/30/2025",
"script": "first-example.lua",
"name": "Forge Time",
"startdate": "08/11/2024",
"enddate": "11/11/2024",
"script": "forge_time.lua",
"description": "Increases the success rate of forges by 20%.",
"colors": {
"colordark": "#2b3e50",
"colorlight": "#3d5a73"
},
"details": {
"displaypriority": 5,
"isseasonal": 0,
"specialevent": 1
}
},
{
"name": "Double Bestiary",
"startdate": "08/11/2024",
"enddate": "11/11/2024",
"script": "double_bestiary.lua",
"description": "Doubles the bestiary counter when defeating monsters.",
"colors": {
"colordark": "#3a4f2a",
"colorlight": "#4f713a"
},
"details": {
"displaypriority": 5,
"isseasonal": 0,
"specialevent": 1
}
},
{
"name": "Fast Exercise",
"startdate": "08/11/2024",
"enddate": "11/11/2024",
"script": "fast_exercise.lua",
"description": "Exercise weapons are faster, doubling their speed.",
"colors": {
"colordark": "#5a3a2a",
"colorlight": "#7b4f3a"
},
"details": {
"displaypriority": 5,
"isseasonal": 0,
"specialevent": 1
}
},
{
"name": "50% Loot Bonus",
"startdate": "08/11/2024",
"enddate": "11/11/2024",
"script": "",
"ingame": {
"exprate": 100,
"lootrate": 100,
"bosslootrate": 100,
"spawnrate": 100,
"skillrate": 100
"lootrate": 150
},
"description": "Otserver br example 1 description double exp and a half, double loot !chance!, regular spawn and double skill",
"description": "Increases loot by 50%.",
"colors": {
"colordark": "#235c00",
"colorlight": "#2d7400"
"colordark": "#2b1e10",
"colorlight": "#4a2e18"
},
"details": {
"displaypriority": 6,
"isseasonal": 0,
"specialevent": 0
"specialevent": 1
}
},
{
"name": "Otservbr example 2",
"startdate": "2/2/2022",
"enddate": "12/31/2025",
"script": "second-example.lua",
"name": "50% Exp Bonus",
"startdate": "08/11/2024",
"enddate": "11/11/2024",
"script": "",
"ingame": {
"exprate": 100,
"lootrate": 100,
"bosslootrate": 100,
"spawnrate": 100,
"skillrate": 100
"exprate": 150
},
"description": "Increases experience by 50%.",
"colors": {
"colordark": "#234d00",
"colorlight": "#3a7500"
},
"description": "Otserver br example 2 description 50% less exp, triple loot !chance!, 50% faster spawn and regular skill",
"details": {
"displaypriority": 6,
"isseasonal": 0,
"specialevent": 1
}
},
{
"name": "Boss Cooldown Reduction",
"startdate": "08/11/2024",
"enddate": "11/11/2024",
"script": "boss_cooldown.lua",
"description": "Reduces boss cooldown time by 50%.",
"colors": {
"colordark": "#735D10",
"colorlight": "#8B6D05"
"colordark": "#2d3c5a",
"colorlight": "#4a5f7d"
},
"details": {
"displaypriority": 6,
"isseasonal": 0,
"specialevent": 0
"specialevent": 1
}
},
{
"name": "Double Exp",
"startdate": "08/11/2024",
"enddate": "11/11/2024",
"script": "",
"ingame": {
"exprate": 200
},
"description": "Double experience when hunting monsters.",
"colors": {
"colordark": "#002d00",
"colorlight": "#004400"
},
"details": {
"displaypriority": 6,
"isseasonal": 1,
"specialevent": 1
}
},
{
"name": "Double Loot",
"startdate": "08/11/2024",
"enddate": "11/11/2024",
"script": "",
"ingame": {
"lootrate": 200
},
"description": "Doubles the amount of loot obtained from monsters.",
"colors": {
"colordark": "#2a1d00",
"colorlight": "#4c3300"
},
"details": {
"displaypriority": 6,
"isseasonal": 1,
"specialevent": 1
}
},
{
"name": "Double Bosstiary",
"startdate": "08/11/2024",
"enddate": "11/11/2024",
"script": "double_bosstiary.lua",
"description": "Doubles the bestiary counter for bosses.",
"colors": {
"colordark": "#3a005a",
"colorlight": "#4e0075"
},
"details": {
"displaypriority": 5,
"isseasonal": 0,
"specialevent": 1
}
},
{
"name": "Fast Respawn",
"startdate": "11/01/2024",
"enddate": "11/15/2024",
"script": "",
"ingame": {
"spawnrate": 200
},
"description": "Monsters respawn twice as fast.",
"colors": {
"colordark": "#4d2f00",
"colorlight": "#6e3e00"
},
"details": {
"displaypriority": 6,
"isseasonal": 1,
"specialevent": 1
}
}
]
Expand Down
Empty file.
6 changes: 6 additions & 0 deletions data/json/scripts/double_bestiary.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
local globalEvent = GlobalEvent("EventScheduleDoubleBestiaryKV")
function globalEvent.onStartup()
KV.scoped("eventscheduler"):set("double-bestiary", true)
end

globalEvent:register()
6 changes: 6 additions & 0 deletions data/json/scripts/double_bosstiary.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
local globalEvent = GlobalEvent("EventScheduleDoubleBosstiaryKV")
function globalEvent.onStartup()
KV.scoped("eventscheduler"):set("double-bosstiary", true)
end

globalEvent:register()
6 changes: 6 additions & 0 deletions data/json/scripts/fast_exercise.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
local globalEvent = GlobalEvent("EventScheduleFastExerciseKV")
function globalEvent.onStartup()
KV.scoped("eventscheduler"):set("fast-exercise", true)
end

globalEvent:register()
17 changes: 0 additions & 17 deletions data/json/scripts/first-example.lua

This file was deleted.

6 changes: 6 additions & 0 deletions data/json/scripts/forge_time.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
local globalEvent = GlobalEvent("EventScheduleForgeTimeKV")
function globalEvent.onStartup()
KV.scoped("eventscheduler"):set("forge-chance", 20)
end

globalEvent:register()
17 changes: 0 additions & 17 deletions data/json/scripts/second-example.lua

This file was deleted.

13 changes: 12 additions & 1 deletion data/scripts/actions/items/exercise_training_weapons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,19 @@ local function exerciseTrainingEvent(playerId, tilePosition, weaponId, dummyId)
return false
end

local eventSpeedMultiplier = 1
local scopedFastExercise = KV.scoped("eventscheduler"):get("fast-exercise")
if scopedFastExercise then
eventSpeedMultiplier = 0.5
logger.debug("Fast exercise is enabled.")
end

local vocation = player:getVocation()
_G.OnExerciseTraining[playerId].event = addEvent(exerciseTrainingEvent, vocation:getBaseAttackSpeed() / configManager.getFloat(configKeys.RATE_EXERCISE_TRAINING_SPEED), playerId, tilePosition, weaponId, dummyId)
_G.OnExerciseTraining[playerId].event = addEvent(
exerciseTrainingEvent,
(vocation:getBaseAttackSpeed() / configManager.getFloat(configKeys.RATE_EXERCISE_TRAINING_SPEED)) * eventSpeedMultiplier,
playerId, tilePosition, weaponId, dummyId
)
return true
end

Expand Down
16 changes: 16 additions & 0 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5693,6 +5693,14 @@ void Player::addBestiaryKill(const std::shared_ptr<MonsterType> &mType) {
return;
}
uint32_t kills = g_configManager().getNumber(BESTIARY_KILL_MULTIPLIER);

auto scopedDoubleBestiary = g_kv().scoped("eventscheduler")->get("double-bestiary");
bool doubleBestiaryEnabled = scopedDoubleBestiary && scopedDoubleBestiary->get<bool>();
if (doubleBestiaryEnabled) {
kills *= 2;
g_logger().info("[{}] double bestiary is enabled.", std::source_location::current().function_name());
}

if (isConcoctionActive(Concoction_t::BestiaryBetterment)) {
kills *= 2;
}
Expand All @@ -5704,6 +5712,14 @@ void Player::addBosstiaryKill(const std::shared_ptr<MonsterType> &mType) {
return;
}
uint32_t kills = g_configManager().getNumber(BOSSTIARY_KILL_MULTIPLIER);

auto scopedDoubleBosstiary = g_kv().scoped("eventscheduler")->get("double-bosstiary");
bool doubleBosstiaryEnabled = scopedDoubleBosstiary && scopedDoubleBosstiary->get<bool>();
if (doubleBosstiaryEnabled) {
kills *= 2;
g_logger().info("[{}] double bosstiary is enabled.", std::source_location::current().function_name());
}

if (g_ioBosstiary().getBoostedBossId() == mType->info.raceid) {
kills *= g_configManager().getNumber(BOOSTED_BOSS_KILL_BONUS);
}
Expand Down
5 changes: 5 additions & 0 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9498,6 +9498,11 @@ void Game::playerForgeFuseItems(uint32_t playerId, ForgeAction_t actionType, uin

uint8_t coreCount = (usedCore ? 1 : 0) + (reduceTierLoss ? 1 : 0);
auto baseSuccess = static_cast<uint8_t>(g_configManager().getNumber(FORGE_BASE_SUCCESS_RATE));
if (const auto scopedForgeChance = g_kv().scoped("eventscheduler")->get("forge-chance")) {
auto forgeChance = static_cast<uint8_t>(scopedForgeChance->getNumber());
g_logger().info("Base success: {}, forge chance: {}", baseSuccess, forgeChance);
baseSuccess += forgeChance;
}
auto coreSuccess = usedCore ? g_configManager().getNumber(FORGE_BONUS_SUCCESS_RATE) : 0;
auto finalRate = baseSuccess + coreSuccess;
auto roll = static_cast<uint8_t>(uniform_random(1, 100)) <= finalRate;
Expand Down
Loading

0 comments on commit 3a0fce9

Please sign in to comment.