Skip to content
This repository has been archived by the owner on May 20, 2023. It is now read-only.

Commit

Permalink
Full review of the bless system (#965)
Browse files Browse the repository at this point in the history
* Shows better informations in the bless dialog

* Improved bless status tooltip in the bless dialog button

* Improve blessings handling

Reworked whole blessings functions server wide, added support for both twist of fate and regular bless when losing items, fixed couple of minor bugs all though the server...

Modified !bless command to reflect ToF changes and prices according to level.

TODO is in blessings.lua, but should be this:
		"Insert & Select query in blessings_history",
		"Add unfair fight reduction",
		"Gamestore buy blessing",
		"Test ank print text",
		"Test all functions",
		"Test henricus prices/blessings",
		"Add data \\movements\\scripts\\quests\\cults of tibia\\icedeath.lua blessing information",
		"WotE data\\movements\\scripts\\quests\\wrath of the emperor\\realmTeleport.lua has line checking if player has bless 1",
		"add blessings module support npc\\lib\\npcsystem\\modules.lua",
		"Fix store buying bless",
		"Check if store is inside lua or source...",
		"Find better way to sendBlessStatus"
  • Loading branch information
dudztroyer committed Apr 12, 2020
1 parent 37f01d9 commit 82ae88f
Show file tree
Hide file tree
Showing 19 changed files with 480 additions and 279 deletions.
27 changes: 2 additions & 25 deletions data/actions/scripts/others/variables/blessingCharms.lua
@@ -1,27 +1,4 @@
local config = {
[11260] = {blessId = 5, text = 'The Spiritual Shielding'},
[11259] = {blessId = 6, text = 'The Embrace of Tibia'},
[11261] = {blessId = 4, text = 'The Fire of the Suns'},
[11258] = {blessId = 3, text = 'The Spark of the Phoenix'},
[11262] = {blessId = 2, text = 'The Wisdom of Solitude'},
[28036] = {blessId = 7, text = 'Heart of the Mountain'},
[28037] = {blessId = 8, text = 'Blood of the Mountain'}
}

dofile('data/modules/scripts/blessings/blessings.lua')
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local useItem = config[item.itemid]
if not useItem then
return true
end

if player:hasBlessing(useItem.blessId) then
player:say('You already possess this blessing.', TALKTYPE_MONSTER_SAY)
return true
end

player:addBlessing(useItem.blessId,1)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, useItem.text .. ' protects you.')
player:getPosition():sendMagicEffect(CONST_ME_LOSEENERGY)
item:remove(1)
return true
return Blessings.useCharm(player, item)
end
20 changes: 2 additions & 18 deletions data/actions/scripts/others/variables/checkBless.lua
@@ -1,21 +1,5 @@
local blessings = {
{id = 1, name = 'Twist of Fate'},
{id = 5, name = 'The Spiritual Shielding'},
{id = 6, name = 'The Embrace of Tibia'},
{id = 4, name = 'The Fire of the Suns'},
{id = 3, name = 'The Spark of the Phoenix'},
{id = 2, name = 'The Wisdom of Solitude'},
{id = 7, name = 'Blood of the Mountain'},
{id = 8, name = 'Heart of the Mountain'}
}
dofile('data/modules/scripts/blessings/blessings.lua')

function onUse(player, item, fromPosition, target, toPosition, isHotkey)

local result, bless = 'Received blessings:'
for i = 1, #blessings do
bless = blessings[i]
result = player:hasBlessing(bless.id) and result .. '\n' .. bless.name or result
end
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 20 > result:len() and 'No blessings received.' or result)
return true
return Blessings.checkBless(player)
end
17 changes: 4 additions & 13 deletions data/creaturescripts/scripts/adventureblessings.lua
@@ -1,15 +1,6 @@
local freeBlessMaxLevel = 20
dofile('data/modules/scripts/blessings/blessings.lua')

function onLogin(player)
if player:getLevel() <= freeBlessMaxLevel then
for i = 1, 8 do
if not player:hasBlessing(i) then
player:addBlessing(i, 1)
end
end

player:sendTextMessage(MESSAGE_EVENT_ADVANCE,'You received adventurers blessings for you to be level less than ' .. freeBlessMaxLevel .. '!')
player:getPosition():sendMagicEffect(CONST_ME_HOLYDAMAGE)
end
return true
function onLogin(cid)
local player = Player(cid)
return Blessings.doAdventurerBlessing(player)
end
38 changes: 3 additions & 35 deletions data/creaturescripts/scripts/others/droploot.lua
@@ -1,40 +1,8 @@
dofile('data/modules/scripts/blessings/blessings.lua')
function onDeath(player, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
if player:hasFlag(PlayerFlag_NotGenerateLoot) then
return true
end

local amulet = player:getSlotItem(CONST_SLOT_NECKLACE)
if amulet and amulet.itemid == ITEM_AMULETOFLOSS and not table.contains({SKULL_RED, SKULL_BLACK}, player:getSkull()) then
local isPlayer = false
if killer then
if killer:isPlayer() then
isPlayer = true
else
local master = killer:getMaster()
if master and master:isPlayer() then
isPlayer = true
end
end
end

if not isPlayer or not player:hasBlessing(5) then
player:removeItem(ITEM_AMULETOFLOSS, 1, -1, false)
end
else
for i = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
local item = player:getSlotItem(i)
if item then
if table.contains({SKULL_RED, SKULL_BLACK}, player:getSkull()) or math.random(item:isContainer() and 100 or 1000) <= player:getLossPercent() then
if not item:moveTo(corpse) then
item:remove()
end
end
end
end
end

if not player:getSlotItem(CONST_SLOT_BACKPACK) then
player:addItem(ITEM_BAG, 1, false, CONST_SLOT_BACKPACK)
end
return true
Blessings.DebugPrint("onDeath DROPLOOT EVENT DropLoot")
return Blessings.PlayerDeath(player, corpse, killer)
end
20 changes: 0 additions & 20 deletions data/global.lua
Expand Up @@ -104,26 +104,6 @@ function doCreatureSayWithRadius(cid, text, type, radiusx, radiusy, position)
end
end

function getBlessingsCost(level)
if level <= 30 then
return 2000
elseif level >= 120 then
return 20000
else
return (level - 20) * 200
end
end

function getPvpBlessingCost(level)
if level <= 30 then
return 2000
elseif level >= 270 then
return 50000
else
return (level - 20) * 200
end
end

function isInRange(pos, fromPos, toPos)
return pos.x >= fromPos.x and pos.y >= fromPos.y and pos.z >= fromPos.z and pos.x <= toPos.x and pos.y <= toPos.y and pos.z <= toPos.z
end
Expand Down
2 changes: 2 additions & 0 deletions data/lib/compat/compat.lua
Expand Up @@ -502,6 +502,8 @@ function getPlayerLearnedInstantSpell(cid, name) local p = Player(cid) return p
function isPlayerGhost(cid) local p = Player(cid) return p ~= nil and p:isInGhostMode() or false end
function isPlayerPzLocked(cid) local p = Player(cid) return p ~= nil and p:isPzLocked() or false end
function isPremium(cid) local p = Player(cid) return p ~= nil and p:isPremium() or false end
function getBlessingsCost(level) return Blessings.getBlessingsCost(level) end
function getPvpBlessingCost(level) return Blessings.getPvpBlessingCost(level) end
function getPlayersByIPAddress(ip, mask)
if mask == nil then mask = 0xFFFFFFFF end
local masked = bit.band(ip, mask)
Expand Down
23 changes: 0 additions & 23 deletions data/lib/core/player.lua
Expand Up @@ -33,29 +33,6 @@ function Player.getDepotItems(self, depotId)
return self:getDepotChest(depotId, true):getItemHoldingCount()
end

function Player.hasFlag(self, flag)
return self:getGroup():hasFlag(flag)
end

function Player.getLossPercent(self)
local blessings = 0
local lossPercent = {
[0] = 100,
[1] = 70,
[2] = 45,
[3] = 25,
[4] = 10,
[5] = 0
}

for i = 1, 5 do
if self:hasBlessing(i) then
blessings = blessings + 1
end
end
return lossPercent[blessings]
end

function Player.isPremium(self)
return self:getPremiumDays() > 0 or configManager.getBoolean(configKeys.FREE_PREMIUM)
end
Expand Down
49 changes: 49 additions & 0 deletions data/modules/scripts/blessings/assets.lua
@@ -0,0 +1,49 @@
Blessings.Types = {
REGULAR = 1,
ENHANCED = 2,
PvP = 3
}

Blessings.All = {
[1] = {id = 1, name = "Twist of Fate", type = Blessings.Types.PvP},
[2] = {id = 2, name = "The Wisdom of Solitude", charm = 11262, type = Blessings.Types.REGULAR, losscount = true, inquisition = true},
[3] = {id = 3, name = "The Spark of the Phoenix", charm = 11258, type = Blessings.Types.REGULAR, losscount = true, inquisition = true},
[4] = {id = 4, name = "The Fire of the Suns", charm = 11261, type = Blessings.Types.REGULAR, losscount = true, inquisition = true},
[5] = {id = 5, name = "The Spiritual Shielding", charm = 11260, type = Blessings.Types.REGULAR, losscount = true, inquisition = true},
[6] = {id = 6, name = "The Embrace of Tibia", charm = 11259, type = Blessings.Types.REGULAR, losscount = true, inquisition = true},
[7] = {id = 7, name = "Blood of the Mountain", charm = 28036, type = Blessings.Types.ENHANCED, losscount = true, inquisition = false},
[8] = {id = 8, name = "Heart of the Mountain", charm = 28037, type = Blessings.Types.ENHANCED, losscount = true, inquisition = false}
}


Blessings.LossPercent = {
[0] = {item = 100, skill = 0},
[1] = {item = 70, skill = 8},
[2] = {item = 45, skill = 16},
[3] = {item = 25, skill = 24},
[4] = {item = 10, skill = 32},
[5] = {item = 0, skill = 40},
[6] = {item = 0, skill = 48},
[7] = {item = 0, skill = 56},
[8] = {item = 0, skill = 56}
}


Blessings.BitWiseTable = {
[0] = 1,
[1] = 2,
[2] = 4,
[3] = 8,
[4] = 16,
[5] = 32,
[6] = 64,
[7] = 128,
[8] = 256,
[9] = 512,
[10] = 1024,
[11] = 2048,
[12] = 4096,
[13] = 8192,
[14] = 16384,
[15] = 32768
}

0 comments on commit 82ae88f

Please sign in to comment.