Skip to content

Commit

Permalink
Some fixes events, configkey, optional stages, xp gain rate
Browse files Browse the repository at this point in the history
  • Loading branch information
beats-dh committed Aug 28, 2021
1 parent a30eaf1 commit 8cfb902
Show file tree
Hide file tree
Showing 19 changed files with 332 additions and 52 deletions.
9 changes: 5 additions & 4 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,13 @@ serverSaveClose = false
serverSaveShutdown = true

-- Rates
-- NOTE: rateExp, rateSkill and rateMagic is used as a fallback only
-- NOTE: rateExp, rateSkill and rateMagic is used when 'rateUseStages = false' - or a fallback only
-- To configure rates see file data/stages.lua
rateUseStages = false
rateExp = 1
rateSkill = 50
rateLoot = 3
rateMagic = 25
rateSkill = 1
rateLoot = 1
rateMagic = 1
rateSpawn = 1

-- Monster rates
Expand Down
2 changes: 1 addition & 1 deletion data/XML/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<colors colordark="#235c00" colorlight="#2d7400" />
<details displaypriority="6" isseasonal="0" specialevent="0" />
</event>
<event name="Canary example 2" startdate="10/2/2020" enddate="11/7/2020" script="example.lua" >
<event name="Canary example 2" startdate="1/1/2021" enddate="12/30/2021" script="example.lua" >
<ingame exprate="50" lootrate="300" spawnrate="150" 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" />
Expand Down
53 changes: 44 additions & 9 deletions data/events/scripts/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -245,22 +245,45 @@ function Player:onGainExperience(source, exp, rawExp)
end

-- Apply experience stage multiplier
exp = exp * Game.getExperienceStage(self:getLevel())
local expStage = getRateFromTable(experienceStages, self:getLevel(), configManager.getNumber(configKeys.RATE_EXP))

-- Prey Bonus
local preyBonus = 0
for slot = CONST_PREY_SLOT_FIRST, CONST_PREY_SLOT_THIRD do
if (self:getPreyCurrentMonster(slot) == source:getName()
and self:getPreyBonusType(slot) == CONST_BONUS_XP_BONUS) then
preyBonus = self:getPreyBonusValue(slot)
end
if (self:getPreyTimeLeft(slot) / 60) > 0 then
preyTimeLeft(self, slot) -- slot consumption, outside of the mosnter check
end
end

-- Stamina modifier
local staminaBoost = 1
if configManager.getBoolean(configKeys.STAMINA_SYSTEM) then
useStamina(self)

local staminaMinutes = self:getStamina()
if staminaMinutes > 2400 and self:isPremium() then
exp = exp * 1.5
if staminaMinutes > 2340 and self:isPremium() then
staminaBoost = 1.5
elseif staminaMinutes <= 840 then
exp = exp * 0.5
staminaBoost = 0.5 --TODO destroy loot of people with 840- stamina
end
self:setStaminaXpBoost(staminaBoost * 100)
end

return exp
end
-- Boosted creature
if source:getName():lower() == (Game.getBoostedCreature()):lower() then
exp = exp * 2
end

-- Event scheduler
if SCHEDULE_EXP_RATE ~= 100 then
expStage = math.max(0, (expStage * SCHEDULE_EXP_RATE)/100)
end
return (exp / 100 * ((expStage * 100 + storeXpBoostAmount + preyBonus) * staminaBoost))
end

function Player:onLoseExperience(exp)
return exp
Expand All @@ -271,8 +294,20 @@ function Player:onGainSkillTries(skill, tries)
return tries
end

if skill == SKILL_MAGLEVEL then
return tries * configManager.getNumber(configKeys.RATE_MAGIC)
local STAGES_DEFAULT = skillsStages or nil
local SKILL_DEFAULT = self:getSkillLevel(skill)
local RATE_DEFAULT = configManager.getNumber(configKeys.RATE_SKILL)

if(skill == SKILL_MAGLEVEL) then -- Magic Level
STAGES_DEFAULT = magicLevelStages or nil
SKILL_DEFAULT = self:getBaseMagicLevel()
RATE_DEFAULT = configManager.getNumber(configKeys.RATE_MAGIC)
end

skillOrMagicRate = getRateFromTable(STAGES_DEFAULT, SKILL_DEFAULT, RATE_DEFAULT)

if SCHEDULE_SKILL_RATE ~= 100 then
skillOrMagicRate = math.max(0, (skillOrMagicRate * SCHEDULE_SKILL_RATE) / 100)
end
return tries * configManager.getNumber(configKeys.RATE_SKILL)
return tries / 100 * (skillOrMagicRate * 100)
end
18 changes: 1 addition & 17 deletions data/global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ weatherConfig = {
SCHEDULE_LOOT_RATE = 100
SCHEDULE_EXP_RATE = 100
SCHEDULE_SKILL_RATE = 100
SCHEDULE_SPAWN_RATE = 100

-- MARRY
PROPOSED_STATUS = 1
Expand Down Expand Up @@ -64,23 +65,6 @@ damageImpact = {}
-- New prey => preyTimeLeft
nextPreyTime = {}

do -- Event Schedule rates
local lootRate = Game.getEventSLoot()
if lootRate ~= 100 then
SCHEDULE_LOOT_RATE = lootRate
end

local expRate = Game.getEventSExp()
if expRate ~= 100 then
SCHEDULE_EXP_RATE = expRate
end

local skillRate = Game.getEventSSkill()
if skillRate ~= 100 then
SCHEDULE_SKILL_RATE = skillRate
end
end

table.contains = function(array, value)
for _, targetColumn in pairs(array) do
if targetColumn == value then
Expand Down
10 changes: 6 additions & 4 deletions data/lib/core/functions/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function getFormattedWorldTime()
end

function getLootRandom()
return math.random(0, MAX_LOOTCHANCE) * 100 / (configManager.getNumber(configKeys.RATE_LOOT) * SCHEDULE_LOOT_RATE)
return math.random(0, MAX_LOOTCHANCE) * 100 / math.max(1, (configManager.getNumber(configKeys.RATE_LOOT) * SCHEDULE_LOOT_RATE))
end

local start = os.time()
Expand All @@ -39,9 +39,11 @@ debug.sethook(function(event, line)
end, "l")

function getRateFromTable(t, level, default)
for _, rate in ipairs(t) do
if level >= rate.minlevel and (not rate.maxlevel or level <= rate.maxlevel) then
return rate.multiplier
if (t ~= nil) then
for _, rate in ipairs(t) do
if level >= rate.minlevel and (not rate.maxlevel or level <= rate.maxlevel) then
return rate.multiplier
end
end
end
return default
Expand Down
176 changes: 176 additions & 0 deletions data/scripts/actions/other/xercise_training.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
local skills = {
[32384] = {id=SKILL_SWORD,voc=4}, -- KNIGHT
[32385] = {id=SKILL_AXE,voc=4}, -- KNIGHT
[32386] = {id=SKILL_CLUB,voc=4}, -- KNIGHT
[32387] = {id=SKILL_DISTANCE,voc=3,range=CONST_ANI_SIMPLEARROW}, -- PALADIN
[32388] = {id=SKILL_MAGLEVEL,voc=2,range=CONST_ANI_SMALLICE}, -- DRUID
[32389] = {id=SKILL_MAGLEVEL,voc=1,range=CONST_ANI_FIRE}, -- SORCERER
[32124] = {id=SKILL_SWORD,voc=4}, -- KNIGHT
[32125] = {id=SKILL_AXE,voc=4}, -- KNIGHT
[32126] = {id=SKILL_CLUB,voc=4}, -- KNIGHT
[32127] = {id=SKILL_DISTANCE,voc=3,range=CONST_ANI_SIMPLEARROW}, -- PALADIN
[32128] = {id=SKILL_MAGLEVEL,voc=2,range=CONST_ANI_SMALLICE}, -- DRUID
[32129] = {id=SKILL_MAGLEVEL,voc=1,range=CONST_ANI_FIRE}, -- SORCERER
[40114] = {id=SKILL_SWORD,voc=4}, -- KNIGHT
[40115] = {id=SKILL_AXE,voc=4}, -- KNIGHT
[40116] = {id=SKILL_CLUB,voc=4}, -- KNIGHT
[40117] = {id=SKILL_DISTANCE,voc=3,range=CONST_ANI_SIMPLEARROW}, -- PALADIN
[40118] = {id=SKILL_MAGLEVEL,voc=2,range=CONST_ANI_SMALLICE}, -- DRUID
[40119] = {id=SKILL_MAGLEVEL,voc=1,range=CONST_ANI_FIRE}, -- SORCERER
[40120] = {id=SKILL_SWORD,voc=4}, -- KNIGHT
[40121] = {id=SKILL_AXE,voc=4}, -- KNIGHT
[40122] = {id=SKILL_CLUB,voc=4}, -- KNIGHT
[40123] = {id=SKILL_DISTANCE,voc=3,range=CONST_ANI_SIMPLEARROW}, -- PALADIN
[40124] = {id=SKILL_MAGLEVEL,voc=2,range=CONST_ANI_SMALLICE}, -- DRUID
[40125] = {id=SKILL_MAGLEVEL,voc=1,range=CONST_ANI_FIRE} -- SORCERER
}

local houseDummies = {32143, 32144, 32145, 32146, 32147, 32148}
local freeDummies = {32142, 32149}

local function removeExerciseWeapon(player, exercise)
exercise:remove(1)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your training weapon vanished.")
stopEvent(training)
player:setStorageValue(Storage.isTraining,0)
player:setTraining(false)
end

local function startTraining(playerId, startPosition, itemid, tilePosition, bonusDummy, dummyId)
local player = Player(playerId)
if player ~= nil then
if Tile(tilePosition):getItemById(dummyId) then
local playerPosition = player:getPosition()
if startPosition:getDistance(playerPosition) == 0 and getTilePzInfo(playerPosition) then
if player:getItemCount(itemid) >= 1 then
local exercise = player:getItemById(itemid,true)
if exercise:isItem() then
if exercise:hasAttribute(ITEM_ATTRIBUTE_CHARGES) then
local charges_n = exercise:getAttribute(ITEM_ATTRIBUTE_CHARGES)
if charges_n >= 1 then
exercise:setAttribute(ITEM_ATTRIBUTE_CHARGES,(charges_n-1))

local voc = player:getVocation()

if skills[itemid].id == SKILL_MAGLEVEL then
local magicRate = getRateFromTable(magicLevelStages, player:getBaseMagicLevel(), configManager.getNumber(configKeys.RATE_MAGIC))
if not bonusDummy then
player:addManaSpent(math.ceil(500*magicRate))
else
player:addManaSpent(math.ceil(500*magicRate)*1.1) -- 10%
end
else
local skillRate = getRateFromTable(skillsStages, player:getSkillLevel(skills[itemid].id), configManager.getNumber(configKeys.RATE_SKILL))
if not bonusDummy then
player:addSkillTries(skills[itemid].id, 7*skillRate)
else
player:addSkillTries(skills[itemid].id, (7*skillRate)*1.1) -- 10%
end
end
tilePosition:sendMagicEffect(CONST_ME_HITAREA)
if skills[itemid].range then
playerPosition:sendDistanceEffect(tilePosition, skills[itemid].range)
end
if exercise:getAttribute(ITEM_ATTRIBUTE_CHARGES) == 0 then
removeExerciseWeapon(player, exercise)
else
local training = addEvent(startTraining, voc:getAttackSpeed(), playerId,startPosition,itemid,tilePosition,bonusDummy,dummyId)
player:setStorageValue(Storage.isTraining,1)
player:setTraining(true)
end
else
removeExerciseWeapon(player, exercise)
end
end
end
end
else
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your training has stopped.")
stopEvent(training)
player:setStorageValue(Storage.isTraining,0)
player:setTraining(false)
end
else
stopEvent(training)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your training has stopped.")
player:setStorageValue(Storage.isTraining, 0)
player:setTraining(false)
end
else
stopEvent(training)
if player then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your training has stopped.")
player:setStorageValue(Storage.isTraining,0)
player:setTraining(false)
end
end
return true
end

local exerciseTraining = Action()

function exerciseTraining.onUse(player, item, fromPosition, target, toPosition, isHotkey)
local startPos = player:getPosition()
if player:getStorageValue(Storage.isTraining) == 1 then
player:sendTextMessage(MESSAGE_FAILURE, "You are already training.")
return false
end
if target:isItem() then
if isInArray(houseDummies,target:getId()) then
if not skills[item.itemid].range and (startPos:getDistance(target:getPosition()) > 1) then
player:sendTextMessage(MESSAGE_FAILURE, "Get closer to the dummy.")
stopEvent(training)
return true
end
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You started training.")
startTraining(player:getId(),startPos,item.itemid,target:getPosition(), true, target:getId())
elseif isInArray(freeDummies, target:getId()) then
if not skills[item.itemid].range and (startPos:getDistance(target:getPosition()) > 1) then
player:sendTextMessage(MESSAGE_FAILURE, "Get closer to the dummy.")
stopEvent(training)
return true
end
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You started training.")
startTraining(player:getId(),startPos,item.itemid,target:getPosition(), false, target:getId())
end
end
return true
end

for id = 32124, 32126 do
exerciseTraining:id(id)
end

for id = 32127, 32129 do
exerciseTraining:id(id)
exerciseTraining:allowFarUse(true)
end

for id = 32384, 32386 do
exerciseTraining:id(id)
end

for id = 32387, 32389 do
exerciseTraining:id(id)
exerciseTraining:allowFarUse(true)
end

for id = 40114, 40116 do
exerciseTraining:id(id)
end

for id = 40117, 40119 do
exerciseTraining:id(id)
exerciseTraining:allowFarUse(true)
end

for id = 40120, 40122 do
exerciseTraining:id(id)
end

for id = 40123, 40125 do
exerciseTraining:id(id)
exerciseTraining:allowFarUse(true)
end

exerciseTraining:register()
23 changes: 23 additions & 0 deletions data/scripts/creaturescripts/advance_save.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
local advanceSave = CreatureEvent("AdvanceSave")

function advanceSave.onAdvance(player, skill, oldLevel, newLevel)
if skill ~= SKILL_LEVEL or newLevel <= oldLevel then
return true
end

player:save()

if Game.getStorageValue(GlobalStorage.XpDisplayMode) > 0 then
local baseRate = getRateFromTable(experienceStages, player:getLevel(), configManager.getNumber(configKeys.RATE_EXP))

-- Event scheduler
if SCHEDULE_EXP_RATE ~= 100 then
baseRate = math.max(0, (baseRate * SCHEDULE_EXP_RATE)/100)
end

player:setBaseXpGain(baseRate * 100)
end
return true
end

advanceSave:register()
22 changes: 22 additions & 0 deletions data/scripts/creaturescripts/login.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,27 @@ function login.onLogin(player)
player:registerEvent("DropLoot")
return true
end

if SCHEDULE_SPAWN_RATE ~= 100 then
if SCHEDULE_SPAWN_RATE > 100 then
player:sendTextMessage(MESSAGE_BOOSTED_CREATURE, "Spawn Rate Event! Monsters respawn at a faster rate \
Happy Hunting!")
else
player:sendTextMessage(MESSAGE_BOOSTED_CREATURE, "Spawn Rate Decreased! Monsters respawn at a slower rate.")
end
end

-- Set Client XP Gain Rate --
local rateExp = 1
if Game.getStorageValue(GlobalStorage.XpDisplayMode) > 0 then
rateExp = getRateFromTable(experienceStages, player:getLevel(), configManager.getNumber(configKeys.RATE_EXP))

if SCHEDULE_EXP_RATE ~= 100 then
rateExp = math.max(0, (rateExp * SCHEDULE_EXP_RATE)/100)
end
end

local staminaMinutes = player:getStamina()
player:setBaseXpGain(rateExp * 100)

login:register()
Loading

0 comments on commit 8cfb902

Please sign in to comment.