From e9448476a08389d55e8e5da2f6bc3a065254b4a7 Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 6 Mar 2024 13:43:52 -0300 Subject: [PATCH 1/6] refactor: die to core and add missing achievement --- .../scripts/actions/other/dice.lua | 18 ------------------ .../scripts/actions/items}/die.lua | 10 ++++++++++ 2 files changed, 10 insertions(+), 18 deletions(-) delete mode 100644 data-otservbr-global/scripts/actions/other/dice.lua rename {data-canary/scripts/actions/other => data/scripts/actions/items}/die.lua (71%) diff --git a/data-otservbr-global/scripts/actions/other/dice.lua b/data-otservbr-global/scripts/actions/other/dice.lua deleted file mode 100644 index bd0c6c8f31a..00000000000 --- a/data-otservbr-global/scripts/actions/other/dice.lua +++ /dev/null @@ -1,18 +0,0 @@ -local dice = Action() - -function dice.onUse(player, item, fromPosition, target, toPosition, isHotkey) - local dicePosition = item:getPosition() - local value = math.random(6) - local isInGhostMode = player:isInGhostMode() - - dicePosition:sendMagicEffect(CONST_ME_CRAPS, isInGhostMode and player) - local spectators = Game.getSpectators(dicePosition, false, true, 3, 3) - for i = 1, #spectators do - player:say(player:getName() .. " rolled a " .. value .. ".", TALKTYPE_MONSTER_SAY, isInGhostMode, spectators[i], dicePosition) - end - item:transform(5791 + value) - return true -end - -dice:id(5792, 5793, 5794, 5795, 5796, 5797) -dice:register() diff --git a/data-canary/scripts/actions/other/die.lua b/data/scripts/actions/items/die.lua similarity index 71% rename from data-canary/scripts/actions/other/die.lua rename to data/scripts/actions/items/die.lua index e7bc7316e9a..1def2333a44 100644 --- a/data-canary/scripts/actions/other/die.lua +++ b/data/scripts/actions/items/die.lua @@ -12,6 +12,16 @@ function die.onUse(player, item, fromPosition, target, toPosition, isHotkey) player:say(player:getName() .. " rolled a " .. value .. ".", TALKTYPE_MONSTER_SAY, isInGhostMode, spectator, position) end + if value == 6 then + player:kv():set("die-rolled-six", player:kv():get("die-rolled-six") + 1) + + if player:kv():get("die-rolled-six") == 3 then + player:addAchievement("Number of the Beast") + end + else + player:kv():remove("die-rolled-six") + end + item:transform(5791 + value) return true end From 4f4832c8cb07ba3a874905921228f1212e26bc17 Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 6 Mar 2024 14:03:46 -0300 Subject: [PATCH 2/6] fix: sendMagicEffect error --- data/scripts/actions/items/die.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/data/scripts/actions/items/die.lua b/data/scripts/actions/items/die.lua index 1def2333a44..81cbafe18e9 100644 --- a/data/scripts/actions/items/die.lua +++ b/data/scripts/actions/items/die.lua @@ -5,11 +5,13 @@ function die.onUse(player, item, fromPosition, target, toPosition, isHotkey) local value = math.random(1, 6) local isInGhostMode = player:isInGhostMode() - position:sendMagicEffect(CONST_ME_CRAPS, isInGhostMode and player) + if not isInGhostMode then + player:getPosition():sendMagicEffect(CONST_ME_CRAPS) - local spectators = Game.getSpectators(position, false, true, 3, 3) - for _, spectator in ipairs(spectators) do - player:say(player:getName() .. " rolled a " .. value .. ".", TALKTYPE_MONSTER_SAY, isInGhostMode, spectator, position) + local spectators = Game.getSpectators(position, false, true, 3, 3) + for _, spectator in ipairs(spectators) do + player:say(player:getName() .. " rolled a " .. value .. ".", TALKTYPE_MONSTER_SAY, isInGhostMode, spectator, position) + end end if value == 6 then From 322c72721f3adf0fe56343881b8d2e727e4caa53 Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 6 Mar 2024 14:09:41 -0300 Subject: [PATCH 3/6] fix: rolled six count --- data/scripts/actions/items/die.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/data/scripts/actions/items/die.lua b/data/scripts/actions/items/die.lua index 81cbafe18e9..7876fb9fad7 100644 --- a/data/scripts/actions/items/die.lua +++ b/data/scripts/actions/items/die.lua @@ -14,10 +14,11 @@ function die.onUse(player, item, fromPosition, target, toPosition, isHotkey) end end + local rolledSixCount = player:kv():get("die-rolled-six") or 0 if value == 6 then - player:kv():set("die-rolled-six", player:kv():get("die-rolled-six") + 1) + player:kv():set("die-rolled-six", rolledSixCount + 1) - if player:kv():get("die-rolled-six") == 3 then + if rolledSixCount == 2 then player:addAchievement("Number of the Beast") end else From ee348a000fd9d27e3fd1c6e8d9095cd540690c46 Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 6 Mar 2024 15:29:11 -0300 Subject: [PATCH 4/6] fix: itemId and effect position --- data/scripts/actions/items/die.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/scripts/actions/items/die.lua b/data/scripts/actions/items/die.lua index 7876fb9fad7..7d982654fa5 100644 --- a/data/scripts/actions/items/die.lua +++ b/data/scripts/actions/items/die.lua @@ -6,7 +6,7 @@ function die.onUse(player, item, fromPosition, target, toPosition, isHotkey) local isInGhostMode = player:isInGhostMode() if not isInGhostMode then - player:getPosition():sendMagicEffect(CONST_ME_CRAPS) + position:sendMagicEffect(CONST_ME_CRAPS) local spectators = Game.getSpectators(position, false, true, 3, 3) for _, spectator in ipairs(spectators) do @@ -25,7 +25,7 @@ function die.onUse(player, item, fromPosition, target, toPosition, isHotkey) player:kv():remove("die-rolled-six") end - item:transform(5791 + value) + item:transform(5792 + value) return true end From 6b2e7a15155012eb4be36ed39bff63fe791cdd17 Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 6 Mar 2024 15:56:39 -0300 Subject: [PATCH 5/6] fix itemId --- data/scripts/actions/items/die.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/scripts/actions/items/die.lua b/data/scripts/actions/items/die.lua index 7d982654fa5..607ef4d1bfe 100644 --- a/data/scripts/actions/items/die.lua +++ b/data/scripts/actions/items/die.lua @@ -25,7 +25,7 @@ function die.onUse(player, item, fromPosition, target, toPosition, isHotkey) player:kv():remove("die-rolled-six") end - item:transform(5792 + value) + item:transform(5791 + value) return true end From cfcb11ea05aac459d5abbe9c83118a752cb9eb03 Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 6 Mar 2024 16:46:52 -0300 Subject: [PATCH 6/6] resolve conversation --- data/scripts/actions/items/die.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/scripts/actions/items/die.lua b/data/scripts/actions/items/die.lua index 607ef4d1bfe..661926e79ea 100644 --- a/data/scripts/actions/items/die.lua +++ b/data/scripts/actions/items/die.lua @@ -14,8 +14,8 @@ function die.onUse(player, item, fromPosition, target, toPosition, isHotkey) end end - local rolledSixCount = player:kv():get("die-rolled-six") or 0 if value == 6 then + local rolledSixCount = player:kv():get("die-rolled-six") or 0 player:kv():set("die-rolled-six", rolledSixCount + 1) if rolledSixCount == 2 then