Skip to content

Commit

Permalink
feat: introducing configurable minimum level for house purchases (ope…
Browse files Browse the repository at this point in the history
…ntibiabr#814)

Created a variable 'houseBuyLevel' in config.lua, to disable it, just put 0.
  • Loading branch information
elsongabriel authored Jan 27, 2023
1 parent b10b3f4 commit b2fdfc7
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 5 deletions.
2 changes: 2 additions & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,12 @@ deathLosePercent = -1

-- Houses
-- NOTE: set housePriceEachSQM to -1 to disable the ingame buy house functionality
-- NOTE: set houseBuyLevel to 0 to disable the min level purchase functionality.
-- Periods: daily/weekly/monthly/yearly/never
housePriceEachSQM = 1000
houseRentPeriod = "never"
houseOwnedByAccount = false
houseBuyLevel = 100

-- Item Usage
timeBetweenActions = 200
Expand Down
6 changes: 6 additions & 0 deletions data-canary/scripts/talkactions/player/buy_house.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ function buyHouse.onSay(player, words, param)
return false
end

local houseBuyLevel = configManager.getNumber(configKeys.HOUSE_BUY_LEVEL)
if (houseBuyLevel ~= nil and player:getLevel() < houseBuyLevel) then
player:sendCancelMessage("You need to be level " .. houseBuyLevel .. " to buy a house.")
return false;
end

local position = player:getPosition()
position:getNextPosition(player:getDirection())

Expand Down
11 changes: 9 additions & 2 deletions data-canary/scripts/talkactions/player/server_info.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
local serverInfo = TalkAction("!serverinfo")

function serverInfo.onSay(player, words, param)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Server Info:"
local text = "Server Info:"
.. "\nExp rate: " .. getRateFromTable(experienceStages, player:getLevel(), configManager.getNumber(configKeys.RATE_EXPERIENCE))
.. "\nSkill rate: " .. configManager.getNumber(configKeys.RATE_SKILL)
.. "\nMagic rate: " .. configManager.getNumber(configKeys.RATE_MAGIC)
.. "\nLoot rate: " .. configManager.getNumber(configKeys.RATE_LOOT))
.. "\nLoot rate: " .. configManager.getNumber(configKeys.RATE_LOOT)

local houseBuyLevel = configManager.getNumber(configKeys.HOUSE_BUY_LEVEL)
if (houseBuyLevel ~= nil and player:getLevel() < houseBuyLevel) then
text = text .. '\nLevel to buy house: ' .. houseBuyLevel
end

player:sendTextMessage(MESSAGE_EVENT_ADVANCE, text)
return false
end

Expand Down
6 changes: 6 additions & 0 deletions data-otservbr-global/scripts/talkactions/player/buy_house.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ function buyHouse.onSay(player, words, param)
return false
end

local houseBuyLevel = configManager.getNumber(configKeys.HOUSE_BUY_LEVEL)
if (houseBuyLevel ~= nil and player:getLevel() < houseBuyLevel) then
player:sendCancelMessage("You need to be level " .. houseBuyLevel .. " to buy a house.")
return false;
end

local position = player:getPosition()
position:getNextPosition(player:getDirection())

Expand Down
13 changes: 10 additions & 3 deletions data-otservbr-global/scripts/talkactions/player/server_info.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
local serverInfo = TalkAction("!serverinfo")

function serverInfo.onSay(player, words, param)
local configRateSkill = configManager.getNumber(configKeys.RATE_SKILL)
local configRateSkill = configManager.getNumber(configKeys.RATE_SKILL)
local baseRate = player:getFinalBaseRateExperience()
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Server Info:"
local text = "Server Info:"
.. "\nExp rate: " .. baseRate
.. "\nSword Skill rate: " .. getRateFromTable(skillsStages, player:getSkillLevel(SKILL_SWORD), configRateSkill)
.. "\nClub Skill rate: " .. getRateFromTable(skillsStages, player:getSkillLevel(SKILL_CLUB), configRateSkill)
Expand All @@ -12,7 +12,14 @@ function serverInfo.onSay(player, words, param)
.. "\nShield Skill rate: " .. getRateFromTable(skillsStages, player:getSkillLevel(SKILL_SHIELD), configRateSkill)
.. "\nFist Skill rate: " .. getRateFromTable(skillsStages, player:getSkillLevel(SKILL_FIST), configRateSkill)
.. "\nMagic rate: " .. getRateFromTable(magicLevelStages, player:getBaseMagicLevel(), configManager.getNumber(configKeys.RATE_MAGIC))
.. "\nLoot rate: " .. configManager.getNumber(configKeys.RATE_LOOT))
.. "\nLoot rate: " .. configManager.getNumber(configKeys.RATE_LOOT)

local houseBuyLevel = configManager.getNumber(configKeys.HOUSE_BUY_LEVEL)
if (houseBuyLevel ~= nil and player:getLevel() < houseBuyLevel) then
text = text .. '\nLevel to buy house: ' .. houseBuyLevel
end

player:sendTextMessage(MESSAGE_EVENT_ADVANCE, text)
return false
end

Expand Down
1 change: 1 addition & 0 deletions src/config/config_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ enum integerConfig_t {
RATE_MAGIC,
RATE_SPAWN,
HOUSE_PRICE,
HOUSE_BUY_LEVEL,
MAX_MESSAGEBUFFER,
ACTIONS_DELAY_INTERVAL,
EX_ACTIONS_DELAY_INTERVAL,
Expand Down
1 change: 1 addition & 0 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ bool ConfigManager::load()
integer[RATE_MAGIC] = getGlobalNumber(L, "rateMagic", 1);
integer[RATE_SPAWN] = getGlobalNumber(L, "rateSpawn", 1);
integer[HOUSE_PRICE] = getGlobalNumber(L, "housePriceEachSQM", 1000);
integer[HOUSE_BUY_LEVEL] = getGlobalNumber(L, "houseBuyLevel", 0);
integer[ACTIONS_DELAY_INTERVAL] = getGlobalNumber(L, "timeBetweenActions", 200);
integer[EX_ACTIONS_DELAY_INTERVAL] = getGlobalNumber(L, "timeBetweenExActions", 1000);
integer[MAX_MESSAGEBUFFER] = getGlobalNumber(L, "maxMessageBuffer", 4);
Expand Down
1 change: 1 addition & 0 deletions src/lua/functions/core/game/config_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void ConfigFunctions::init(lua_State* L) {
registerEnumIn(L, "configKeys", RATE_MAGIC)
registerEnumIn(L, "configKeys", RATE_SPAWN)
registerEnumIn(L, "configKeys", HOUSE_PRICE)
registerEnumIn(L, "configKeys", HOUSE_BUY_LEVEL)
registerEnumIn(L, "configKeys", MAX_MESSAGEBUFFER)
registerEnumIn(L, "configKeys", ACTIONS_DELAY_INTERVAL)
registerEnumIn(L, "configKeys", EX_ACTIONS_DELAY_INTERVAL)
Expand Down

0 comments on commit b2fdfc7

Please sign in to comment.