Skip to content

Commit

Permalink
Merge branch 'main' into fix/bosses-npcs
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel authored Feb 22, 2024
2 parents b37c3a8 + 4a86b3f commit 4682814
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 96 deletions.
87 changes: 0 additions & 87 deletions data-otservbr-global/scripts/actions/other/hireling_food.lua

This file was deleted.

4 changes: 2 additions & 2 deletions data/XML/events.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<events>
<event name="Otservbr example 1" startdate="11/03/2020" enddate="12/30/2023" script="example.lua" >
<ingame exprate="100" lootrate="100" spawnrate="100" skillrate="100" />
<ingame exprate="100" lootrate="100" bosslootrate="100" spawnrate="100" skillrate="100" />
<description description="Otserver br example 1 description double exp and a half, double loot !chance!, regular spawn and double skill" />
<colors colordark="#235c00" colorlight="#2d7400" />
<details displaypriority="6" isseasonal="0" specialevent="0" />
</event>
<event name="Otservbr example 2" startdate="2/2/2022" enddate="12/31/2023" script="" >
<ingame exprate="100" lootrate="100" spawnrate="100" skillrate="100" />
<ingame exprate="100" lootrate="100" bosslootrate="100" spawnrate="100" skillrate="100" />
<description description="Otserver br example 2 description 50% less exp, triple loot !chance!, 50% faster spawn and regular skill" />
<colors colordark="#735D10" colorlight="#8B6D05" />
<details displaypriority="6" isseasonal="0" specialevent="0" />
Expand Down
1 change: 1 addition & 0 deletions data/global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ GLOBAL_CHARM_SCAVENGE = 125 -- 25% more chance to get creature products from ski
-- Event Schedule
SCHEDULE_LOOT_RATE = 100
SCHEDULE_EXP_RATE = 100
SCHEDULE_BOSS_LOOT_RATE = 100
SCHEDULE_SKILL_RATE = 100
SCHEDULE_SPAWN_RATE = 100

Expand Down
4 changes: 4 additions & 0 deletions data/libs/functions/monstertype.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ function MonsterType:generateLootRoll(config, resultTable)
local factor = config.factor or 1.0
local uniqueItems = {}

if self:isRewardBoss() then
factor = factor * SCHEDULE_BOSS_LOOT_RATE / 100
end

local result = resultTable or {}
for _, item in ipairs(monsterLoot) do
local iType = ItemType(item.itemId)
Expand Down
69 changes: 69 additions & 0 deletions data/scripts/actions/items/hireling_foods.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
local hasteCondition = Condition(CONDITION_HASTE)
hasteCondition:setParameter(CONDITION_PARAM_TICKS, 60 * 60 * 1000)
hasteCondition:setParameter(CONDITION_PARAM_SPEED, 80)

local fishingCondition = Condition(CONDITION_ATTRIBUTES)
fishingCondition:setParameter(CONDITION_PARAM_TICKS, 60 * 60 * 1000)
fishingCondition:setParameter(CONDITION_PARAM_SKILL_FISHING, 30)

local magicPointsCondition = Condition(CONDITION_ATTRIBUTES)
magicPointsCondition:setParameter(CONDITION_PARAM_TICKS, 60 * 60 * 1000)
magicPointsCondition:setParameter(CONDITION_PARAM_STAT_MAGICPOINTS, 3)

local meleeCondition = Condition(CONDITION_ATTRIBUTES)
meleeCondition:setParameter(CONDITION_PARAM_TICKS, 60 * 60 * 1000)
meleeCondition:setParameter(CONDITION_PARAM_SKILL_MELEE, 3)

local shieldCondition = Condition(CONDITION_ATTRIBUTES)
shieldCondition:setParameter(CONDITION_PARAM_TICKS, 60 * 60 * 1000)
shieldCondition:setParameter(CONDITION_PARAM_SKILL_SHIELD, 7)

local distanceCondition = Condition(CONDITION_ATTRIBUTES)
distanceCondition:setParameter(CONDITION_PARAM_TICKS, 60 * 60 * 1000)
distanceCondition:setParameter(CONDITION_PARAM_SKILL_DISTANCE, 7)

local gourmetDishes = {
[29408] = { condition = shieldCondition, message = "Chomp." },
[29409] = { condition = distanceCondition, message = "Yummm." },
[29410] = { condition = magicPointsCondition, message = "Munch." },
[29411] = { condition = meleeCondition, message = "Munch." },
[29412] = { condition = hasteCondition, message = "Yummm." },
[29413] = { condition = fishingCondition, message = "Mmmmm." },
[29414] = { healing = true, message = "Munch." },
[29415] = { manaRestore = true, message = "Chomp." },
[29416] = { message = "Blurg." },
}

local hirelingFoods = Action()

function hirelingFoods.onUse(player, item, fromPosition, target, toPosition, isHotkey)
local dish = gourmetDishes[item.itemid]
if not dish then
return true
end

if player:hasExhaustion("hireling-foods-cooldown") then
player:sendCancelMessage("You're still too full to eat any gourmet dishes for a while.")
return true
end

if dish.condition then
player:addCondition(dish.condition)
elseif dish.healing then
player:addHealth(player:getMaxHealth() * 0.3)
elseif dish.manaRestore then
player:addMana(player:getMaxMana() * 0.3)
end

player:say(dish.message, TALKTYPE_MONSTER_SAY)
player:setExhaustion("hireling-foods-cooldown", 10 * 60)

item:remove(1)
return true
end

for index, value in pairs(gourmetDishes) do
hirelingFoods:id(index)
end

hirelingFoods:register()
10 changes: 5 additions & 5 deletions data/scripts/actions/objects/wall_mirror.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ local setting = {
local wallMirror = Action()

function wallMirror.onUse(player, item, fromPosition, target, toPosition, isHotkey)
local hasExhaustion = player:kv():get("delay-wall-mirror") or 0
if hasExhaustion > os.time() then
if player:hasExhaustion("delay-wall-mirror") then
player:say("Don't be so vain about your appearance.", TALKTYPE_MONSTER_SAY)
else
player:kv():set("delay-wall-mirror", os.time() + 20 * 60 * 60)
player:say(setting[math.random(1, #setting)], TALKTYPE_MONSTER_SAY)
return true
end

player:say(setting[math.random(1, #setting)], TALKTYPE_MONSTER_SAY)
player:setExhaustion("delay-wall-mirror", 20 * 60 * 60)
return true
end

Expand Down
4 changes: 4 additions & 0 deletions data/scripts/creaturescripts/player/login.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ function playerLoginGlobal.onLogin(player)
sendBoostMessage(player, "Loot Rate", SCHEDULE_LOOT_RATE > 100)
end

if SCHEDULE_BOSS_LOOT_RATE ~= 100 then
sendBoostMessage(player, "Boss Loot Rate", SCHEDULE_BOSS_LOOT_RATE > 100)
end

if SCHEDULE_SKILL_RATE ~= 100 then
sendBoostMessage(player, "Skill Rate", SCHEDULE_SKILL_RATE > 100)
end
Expand Down
9 changes: 7 additions & 2 deletions data/scripts/globalevents/server_initialization.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ local function updateEventRates()
SCHEDULE_LOOT_RATE = lootRate
end

local bossLootRate = EventsScheduler.getEventSBossLoot()
if bossLootRate ~= 100 then
SCHEDULE_BOSS_LOOT_RATE = bossLootRate
end

local expRate = EventsScheduler.getEventSExp()
if expRate ~= 100 then
SCHEDULE_EXP_RATE = expRate
Expand All @@ -121,8 +126,8 @@ local function updateEventRates()
end

-- Log information if any of the rates are not 100%
if expRate ~= 100 or lootRate ~= 100 or spawnRate ~= 100 or skillRate ~= 100 then
logger.info("[Events] Exp: {}%, loot: {}%, Spawn: {}%, Skill: {}%", expRate, lootRate, spawnRate, skillRate)
if expRate ~= 100 or lootRate ~= 100 or spawnRate ~= 100 or skillRate ~= 100 or bossLootRate ~= 100 then
logger.info("[Events] Exp: {}%, Loot: {}%, Spawn: {}%, Skill: {}%, Boss loot: {}%", expRate, lootRate, spawnRate, skillRate, bossLootRate)
end
end

Expand Down
9 changes: 9 additions & 0 deletions src/game/scheduling/events_scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ bool EventsScheduler::loadScheduleEventFromXml() {
g_eventsScheduler().setLootSchedule(lootrate);
}

if (ingameNode.attribute("bosslootrate")) {
uint16_t bosslootrate = static_cast<uint16_t>(ingameNode.attribute("bosslootrate").as_uint());
currentEventRates.bosslootrate = bosslootrate;
g_eventsScheduler().setBossLootSchedule(bosslootrate);
}

if (ingameNode.attribute("spawnrate")) {
uint16_t spawnrate = static_cast<uint16_t>(ingameNode.attribute("spawnrate").as_uint());
currentEventRates.spawnrate = spawnrate;
Expand All @@ -96,6 +102,9 @@ bool EventsScheduler::loadScheduleEventFromXml() {
if (rates.lootrate != 100 && currentEventRates.lootrate != 100 && rates.lootrate == currentEventRates.lootrate) {
modifiedRates.emplace_back("lootrate");
}
if (rates.bosslootrate != 100 && currentEventRates.bosslootrate != 100 && rates.bosslootrate == currentEventRates.bosslootrate) {
modifiedRates.emplace_back("bosslootrate");
}
if (rates.spawnrate != 100 && currentEventRates.spawnrate != 100 && rates.spawnrate == currentEventRates.spawnrate) {
modifiedRates.emplace_back("spawnrate");
}
Expand Down
9 changes: 9 additions & 0 deletions src/game/scheduling/events_scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct EventScheduler {
struct EventRates {
uint16_t exprate = 100;
uint32_t lootrate = 100;
uint32_t bosslootrate = 100;
uint32_t spawnrate = 100;
uint16_t skillrate = 100;
};
Expand Down Expand Up @@ -55,6 +56,13 @@ class EventsScheduler {
lootSchedule = (lootSchedule * lootrate) / 100;
}

uint32_t getBossLootSchedule() const {
return bossLootSchedule;
}
void setBossLootSchedule(uint32_t bosslootrate) {
bossLootSchedule = (bossLootSchedule * bosslootrate) / 100;
}

uint32_t getSpawnMonsterSchedule() const {
return spawnMonsterSchedule;
}
Expand All @@ -73,6 +81,7 @@ class EventsScheduler {
// Event schedule
uint16_t expSchedule = 100;
uint32_t lootSchedule = 100;
uint32_t bossLootSchedule = 100;
uint16_t skillSchedule = 100;
uint32_t spawnMonsterSchedule = 100;

Expand Down
6 changes: 6 additions & 0 deletions src/lua/functions/events/events_scheduler_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ int EventsSchedulerFunctions::luaEventsSchedulergetEventSLoot(lua_State* L) {
return 1;
}

int EventsSchedulerFunctions::luaEventsSchedulergetEventSBossLoot(lua_State* L) {
// EventsScheduler.getEventSLoot
lua_pushnumber(L, g_eventsScheduler().getBossLootSchedule());
return 1;
}

int EventsSchedulerFunctions::luaEventsSchedulergetEventSSkill(lua_State* L) {
// EventsScheduler.getEventSSkill
lua_pushnumber(L, g_eventsScheduler().getSkillSchedule());
Expand Down
2 changes: 2 additions & 0 deletions src/lua/functions/events/events_scheduler_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ class EventsSchedulerFunctions final : private LuaScriptInterface {
registerTable(L, "EventsScheduler");

registerMethod(L, "EventsScheduler", "getEventSLoot", EventsSchedulerFunctions::luaEventsSchedulergetEventSLoot);
registerMethod(L, "EventsScheduler", "getEventSBossLoot", EventsSchedulerFunctions::luaEventsSchedulergetEventSBossLoot);
registerMethod(L, "EventsScheduler", "getEventSSkill", EventsSchedulerFunctions::luaEventsSchedulergetEventSSkill);
registerMethod(L, "EventsScheduler", "getEventSExp", EventsSchedulerFunctions::luaEventsSchedulergetEventSExp);
registerMethod(L, "EventsScheduler", "getSpawnMonsterSchedule", EventsSchedulerFunctions::luaEventsSchedulergetSpawnMonsterSchedule);
}

private:
static int luaEventsSchedulergetEventSLoot(lua_State* L);
static int luaEventsSchedulergetEventSBossLoot(lua_State* L);
static int luaEventsSchedulergetEventSSkill(lua_State* L);
static int luaEventsSchedulergetEventSExp(lua_State* L);
static int luaEventsSchedulergetSpawnMonsterSchedule(lua_State* L);
Expand Down

0 comments on commit 4682814

Please sign in to comment.