Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventCallback Improvements, Oops is now called Event #4395

Merged
merged 6 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions data/events/scripts/creature.lua
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
function Creature:onChangeOutfit(outfit)
local onChangeMount = EventCallback.onChangeMount
if onChangeMount then
if not onChangeMount(self, outfit.lookMount) then
if hasEvent.onChangeMount then
if not Event.onChangeMount(self, outfit.lookMount) then
return false
end
end
local onChangeOutfit = EventCallback.onChangeOutfit
if onChangeOutfit then
return onChangeOutfit(self, outfit)
if hasEvent.onChangeOutfit then
return Event.onChangeOutfit(self, outfit)
end
return true
end

function Creature:onAreaCombat(tile, isAggressive)
local onAreaCombat = EventCallback.onAreaCombat
if onAreaCombat then
return onAreaCombat(self, tile, isAggressive)
if hasEvent.onAreaCombat then
return Event.onAreaCombat(self, tile, isAggressive)
end
return RETURNVALUE_NOERROR
end

function Creature:onTargetCombat(target)
local onTargetCombat = EventCallback.onTargetCombat
if onTargetCombat then
return onTargetCombat(self, target)
if hasEvent.onTargetCombat then
return Event.onTargetCombat(self, target)
end
return RETURNVALUE_NOERROR
end

function Creature:onHear(speaker, words, type)
local onHear = EventCallback.onHeard
if onHear then
onHear(self, speaker, words, type)
if hasEvent.onHear then
Event.onHear(self, speaker, words, type)
end
end

Expand Down
12 changes: 5 additions & 7 deletions data/events/scripts/monster.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
function Monster:onDropLoot(corpse)
local onDropLoot = EventCallback.onDropLoot
if onDropLoot then
onDropLoot(self, corpse)
end
if hasEvent.onDropLoot then
Event.onDropLoot(self, corpse)
end
local player = Player(corpse:getCorpseOwner())
if player then
player:updateKillTracker(self, corpse)
end
end

function Monster:onSpawn(position, startup, artificial)
local onSpawn = EventCallback.onSpawn
if onSpawn then
return onSpawn(self, position, startup, artificial)
if hasEvent.onSpawn then
return Event.onSpawn(self, position, startup, artificial)
end
return true
end
33 changes: 13 additions & 20 deletions data/events/scripts/party.lua
Original file line number Diff line number Diff line change
@@ -1,47 +1,41 @@
function Party:onJoin(player)
local onJoin = EventCallback.onJoin
if onJoin then
return onJoin(self, player)
if hasEvent.onJoin then
return Event.onJoin(self, player)
end
return true
end

function Party:onLeave(player)
local onLeave = EventCallback.onLeave
if onLeave then
return onLeave(self, player)
if hasEvent.onLeave then
return Event.onLeave(self, player)
end
return true
end

function Party:onDisband()
local onDisband = EventCallback.onDisband
if onDisband then
return onDisband(self)
if hasEvent.onDisband then
return Event.onDisband(self)
end
return true
end

function Party:onInvite(player)
local onInvite = EventCallback.onInvite
if onInvite then
return onInvite(self, player)
if hasEvent.onInvite then
return Event.onInvite(self, player)
end
return true
end

function Party:onRevokeInvitation(player)
local onRevokeInvitation = EventCallback.onRevokeInvitation
if onRevokeInvitation then
return onRevokeInvitation(self, player)
if hasEvent.onRevokeInvitation then
return Event.onRevokeInvitation(self, player)
end
return true
end

function Party:onPassLeadership(player)
local onPassLeadership = EventCallback.onPassLeadership
if onPassLeadership then
return onPassLeadership(self, player)
if hasEvent.onPassLeadership then
return Event.onPassLeadership(self, player)
end
return true
end
Expand Down Expand Up @@ -69,6 +63,5 @@ function Party:onShareExperience(exp)
end

exp = math.ceil((exp * sharedExperienceMultiplier) / (#self:getMembers() + 1))
local onShareExperience = EventCallback.onShareExperience
return onShareExperience and onShareExperience(self, exp, rawExp) or exp
return hasEvent.onShareExperience and Event.onShareExperience(self, exp, rawExp) or exp
end
96 changes: 38 additions & 58 deletions data/events/scripts/player.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
function Player:onBrowseField(position)
local onBrowseField = EventCallback.onBrowseField
if onBrowseField then
return onBrowseField(self, position)
if hasEvent.onBrowseField then
return Event.onBrowseField(self, position)
end
return true
end

function Player:onLook(thing, position, distance)
local description = ""
local onLook = EventCallback.onLook
if onLook then
description = onLook(self, thing, position, distance, description)
if hasEvent.onLook then
description = Event.onLook(self, thing, position, distance, description)
end

if description ~= "" then
Expand All @@ -20,9 +18,8 @@ end

function Player:onLookInBattleList(creature, distance)
local description = ""
local onLookInBattleList = EventCallback.onLookInBattleList
if onLookInBattleList then
description = onLookInBattleList(self, creature, distance, description)
if hasEvent.onLookInBattleList then
description = Event.onLookInBattleList(self, creature, distance, description)
end

if description ~= "" then
Expand All @@ -32,9 +29,8 @@ end

function Player:onLookInTrade(partner, item, distance)
local description = "You see " .. item:getDescription(distance)
local onLookInTrade = EventCallback.onLookInTrade
if onLookInTrade then
description = onLookInTrade(self, partner, item, distance, description)
if hasEvent.onLookInTrade then
description = Event.onLookInTrade(self, partner, item, distance, description)
end

if description ~= "" then
Expand All @@ -44,9 +40,8 @@ end

function Player:onLookInShop(itemType, count)
local description = "You see "
local onLookInShop = EventCallback.onLookInShop
if onLookInShop then
description = onLookInShop(self, itemType, count, description)
if hasEvent.onLookInShop then
description = Event.onLookInShop(self, itemType, count, description)
end

if description ~= "" then
Expand All @@ -55,46 +50,40 @@ function Player:onLookInShop(itemType, count)
end

function Player:onLookInMarket(itemType)
local onLookInMarket = EventCallback.onLookInMarket
if onLookInMarket then
onLookInMarket(self, itemType)
if hasEvent.onLookInMarket then
Event.onLookInMarket(self, itemType)
end
end

function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
local onMoveItem = EventCallback.onMoveItem
if onMoveItem then
return onMoveItem(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
if hasEvent.onMoveItem then
return Event.onMoveItem(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
end
return RETURNVALUE_NOERROR
end

function Player:onItemMoved(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
local onItemMoved = EventCallback.onItemMoved
if onItemMoved then
onItemMoved(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
if hasEvent.onItemMoved then
Event.onItemMoved(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
end
end

function Player:onMoveCreature(creature, fromPosition, toPosition)
local onMoveCreature = EventCallback.onMoveCreature
if onMoveCreature then
return onMoveCreature(self, creature, fromPosition, toPosition)
if hasEvent.onMoveCreature then
return Event.onMoveCreature(self, creature, fromPosition, toPosition)
end
return true
end

function Player:onReportRuleViolation(targetName, reportType, reportReason, comment, translation)
local onReportRuleViolation = EventCallback.onReportRuleViolation
if onReportRuleViolation then
onReportRuleViolation(self, targetName, reportType, reportReason, comment, translation)
if hasEvent.onReportRuleViolation then
Event.onReportRuleViolation(self, targetName, reportType, reportReason, comment, translation)
end
end

function Player:onReportBug(message, position, category)
local onReportBug = EventCallback.onReportBug
if onReportBug then
return onReportBug(self, message, position, category)
if hasEvent.onReportBug then
return Event.onReportBug(self, message, position, category)
end
return true
end
Expand All @@ -108,33 +97,29 @@ function Player:onRotateItem(item)
end

function Player:onTurn(direction)
local onTurn = EventCallback.onTurn
if onTurn then
return onTurn(self, direction)
if hasEvent.onTurn then
return Event.onTurn(self, direction)
end
return true
end

function Player:onTradeRequest(target, item)
local onTradeRequest = EventCallback.onTradeRequest
if onTradeRequest then
return onTradeRequest(self, target, item)
if hasEvent.onTradeRequest then
return Event.onTradeRequest(self, target, item)
end
return true
end

function Player:onTradeAccept(target, item, targetItem)
local onTradeAccept = EventCallback.onTradeAccept
if onTradeAccept then
return onTradeAccept(self, target, item, targetItem)
if hasEvent.onTradeAccept then
return Event.onTradeAccept(self, target, item, targetItem)
end
return true
end

function Player:onTradeCompleted(target, item, targetItem, isSuccess)
local onTradeCompleted = EventCallback.onTradeCompleted
if onTradeCompleted then
onTradeCompleted(self, target, item, targetItem, isSuccess)
if hasEvent.onTradeCompleted then
Event.onTradeCompleted(self, target, item, targetItem, isSuccess)
end
end

Expand Down Expand Up @@ -227,27 +212,24 @@ function Player:onPodiumEdit(item, outfit, direction, isVisible)
end

function Player:onGainExperience(source, exp, rawExp, sendText)
local onGainExperience = EventCallback.onGainExperience
return onGainExperience and onGainExperience(self, source, exp, rawExp, sendText) or exp
return hasEvent.onGainExperience and Event.onGainExperience(self, source, exp, rawExp) or exp
end

function Player:onLoseExperience(exp)
local onLoseExperience = EventCallback.onLoseExperience
return onLoseExperience and onLoseExperience(self, exp) or exp
return hasEvent.onLoseExperience and Event.onLoseExperience(self, exp) or exp
end

function Player:onGainSkillTries(skill, tries)
local onGainSkillTries = EventCallback.onGainSkillTries
if not APPLY_SKILL_MULTIPLIER then
return onGainSkillTries and onGainSkillTries(self, skill, tries) or tries
return hasEvent.onGainSkillTries and Event.onGainSkillTries(self, skill, tries) or tries
end

if skill == SKILL_MAGLEVEL then
tries = tries * configManager.getNumber(configKeys.RATE_MAGIC)
return onGainSkillTries and onGainSkillTries(self, skill, tries) or tries
return hasEvent.onGainSkillTries and Event.onGainSkillTries(self, skill, tries) or tries
end
tries = tries * configManager.getNumber(configKeys.RATE_SKILL)
return onGainSkillTries and onGainSkillTries(self, skill, tries) or tries
return hasEvent.onGainSkillTries and Event.onGainSkillTries(self, skill, tries) or tries
end

function Player:onWrapItem(item)
Expand Down Expand Up @@ -277,8 +259,7 @@ function Player:onWrapItem(item)
return
end

local onWrapItem = EventCallback.onWrapItem
if not onWrapItem or onWrapItem(self, item) then
if not hasEvent.onWrapItem or Event.onWrapItem(self, item) then
local oldId = item:getId()
item:remove(1)
local item = tile:addItem(wrapId)
Expand All @@ -289,9 +270,8 @@ function Player:onWrapItem(item)
end

function Player:onInventoryUpdate(item, slot, equip)
local onInventoryUpdate = EventCallback.onInventoryUpdate
if onInventoryUpdate then
onInventoryUpdate(self, item, slot, equip)
if hasEvent.onInventoryUpdate then
Event.onInventoryUpdate(self, item, slot, equip)
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local ec = EventCallback
local event = Event()

ec.onDropLoot = function(self, corpse)
event.onDropLoot = function(self, corpse)
if configManager.getNumber(configKeys.RATE_LOOT) == 0 then
return
end
Expand Down Expand Up @@ -39,4 +39,4 @@ ec.onDropLoot = function(self, corpse)
end
end

ec:register()
event:register()
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ local function useStamina(player)
player:setStamina(staminaMinutes)
end

local default = EventCallback
local default = Event()

function default.onGainExperience(player, source, exp, rawExp, sendText)
if not source or source:isPlayer() then
Expand Down Expand Up @@ -74,7 +74,7 @@ default:register()
-- For this event, we use the trigger index math.huge so that this event is called last, thus ensuring that the
-- experience message is sent to the client with the correct value.

local message = EventCallback
local message = Event()

function message.onGainExperience(player, source, exp, rawExp, sendText)
if sendText and exp ~= 0 then
Expand Down
Loading
Loading