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

[Bug] fixes some prey and taskhunting fixes #644

Merged
merged 25 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from 21 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
42 changes: 42 additions & 0 deletions data-canary/scripts/creaturescripts/prey_loot.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
local bonusCountPercent = 3

local preyLootBonusKill = CreatureEvent("PreyLootBonusKill")

function preyLootBonusKill.onKill(player, target, lastHit)
-- Monster verify
if not target or not target:isMonster() or target:getMaster() then
return true
end

local mType = target:getType()

local preyLootPercent = player:getPreyLootPercentage(mType:raceId())
if preyLootPercent > 0 and probability < preyLootPercent then
target:registerEvent('BonusPreyLootDeath')
end
return true
end

preyLootBonusKill:register()

local bonusPreyLootDeath = CreatureEvent("BonusPreyLootDeath")
function bonusPreyLootDeath.onDeath(creature, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
if not creature then
return true
end
local monsterLoot = creature:getType():getLoot()
local mType = creature:getType()
if not mType:getLoot() or not corpse then
return true
end

for i, loot in pairs(monsterLoot) do
local item = corpse:createLootItem(monsterLoot[i], false)
if not item then
Spdlog.warn(string.format("[bonusPreyLootDeath.onDeath] - Could not add loot item to monster: %s, from corpse id: %d.", self:getName(), corpse:getId()))
end
end
return true
end

bonusPreyLootDeath:register()
42 changes: 42 additions & 0 deletions data-otservbr-global/scripts/creaturescripts/others/prey_loot.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
local bonusCountPercent = 3

local preyLootBonusKill = CreatureEvent("PreyLootBonusKill")

function preyLootBonusKill.onKill(player, target, lastHit)
-- Monster verify
if not target or not target:isMonster() or target:getMaster() then
return true
end

local mType = target:getType()

local preyLootPercent = player:getPreyLootPercentage(mType:raceId())
if preyLootPercent > 0 and probability < preyLootPercent then
target:registerEvent('BonusPreyLootDeath')
end
return true
end

preyLootBonusKill:register()

local bonusPreyLootDeath = CreatureEvent("BonusPreyLootDeath")
function bonusPreyLootDeath.onDeath(creature, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
if not creature then
return true
end
local monsterLoot = creature:getType():getLoot()
local mType = creature:getType()
if not mType:getLoot() or not corpse then
return true
end

for i, loot in pairs(monsterLoot) do
local item = corpse:createLootItem(monsterLoot[i], false)
if not item then
Spdlog.warn(string.format("[bonusPreyLootDeath.onDeath] - Could not add loot item to monster: %s, from corpse id: %d.", self:getName(), corpse:getId()))
end
end
return true
end

bonusPreyLootDeath:register()
29 changes: 22 additions & 7 deletions data/events/scripts/monster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ function Monster:onDropLoot(corpse)
local player = Player(corpse:getCorpseOwner())
if not player or player:getStamina() > 840 then
local monsterLoot = mType:getLoot()
local preyChanceBoost = 100
local charmBonus = false
if player and mType and mType:raceId() > 0 then
preyChanceBoost = player:getPreyLootPercentage(mType:raceId())
local charm = player:getCharmMonsterType(CHARM_GUT)
if charm and charm:raceId() == mType:raceId() then
charmBonus = true
Expand All @@ -24,15 +22,32 @@ function Monster:onDropLoot(corpse)


for i = 1, #monsterLoot do
local item = corpse:createLootItem(monsterLoot[i], charmBonus, preyChanceBoost)
local item = corpse:createLootItem(monsterLoot[i], charmBonus)
if self:getName():lower() == Game.getBoostedCreature():lower() then
local itemBoosted = corpse:createLootItem(monsterLoot[i], charmBonus, preyChanceBoost)
local itemBoosted = corpse:createLootItem(monsterLoot[i], charmBonus)
if not itemBoosted then
Spdlog.warn(string.format("[Monster:onDropLoot] - Could not add loot item to boosted monster: %s, from corpse id: %d.", self:getName(), corpse:getId()))
Spdlog.warn(string.format("[1][Monster:onDropLoot] - Could not add loot item to boosted monster: %s, from corpse id: %d.", self:getName(), corpse:getId()))
end
end
if not item then
Spdlog.warn(string.format("[Monster:onDropLoot] - Could not add loot item to monster: %s, from corpse id: %d.", self:getName(), corpse:getId()))
Spdlog.warn(string.format("[2][Monster:onDropLoot] - Could not add loot item to monster: %s, from corpse id: %d.", self:getName(), corpse:getId()))
end
end
local preyLootActive = false
if player then
local preyLootPercent = player:getPreyLootPercentage(mType:raceId())
if preyLootPercent > 0 then
local probability = math.random(0, 100)
if probability < preyLootPercent then
for i, loot in pairs(monsterLoot) do
local item = corpse:createLootItem(monsterLoot[i], charmBonus)
if not item then
Spdlog.warn(string.format("[3][Monster:onDropLoot] - Could not add loot item to monster: %s, from corpse id: %d.", self:getName(), corpse:getId()))
else
preyLootActive = true
end
end
end
end
end

Expand All @@ -43,7 +58,7 @@ function Monster:onDropLoot(corpse)
else
text = ("Loot of %s: %s"):format(mType:getNameDescription(), corpse:getContentDescription())
end
if preyChanceBoost ~= 100 then
if preyLootActive then
text = text .. " (active prey bonus)"
end
if charmBonus then
Expand Down
9 changes: 2 additions & 7 deletions data/libs/functions/container.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function Container.isContainer(self)
return true
end

function Container.createLootItem(self, item, charm, prey)
function Container.createLootItem(self, item, charm)
if self:getEmptySlots() == 0 then
return true
end
Expand All @@ -21,11 +21,6 @@ function Container.createLootItem(self, item, charm, prey)
chanceTo = math.ceil((chanceTo * GLOBAL_CHARM_GUT) / 100)
end

-- Active prey loot bonus
if prey ~= 100 then
chanceTo = math.ceil((chanceTo * prey) / 100)
end

if randvalue < chanceTo then
if lootBlockType:isStackable() then
local maxc, minc = item.maxCount or 1, item.minCount or 1
Expand All @@ -46,7 +41,7 @@ function Container.createLootItem(self, item, charm, prey)

if tmpItem:isContainer() then
for i = 1, #item.childLoot do
if not tmpItem:createLootItem(item.childLoot[i], charm, prey) then
if not tmpItem:createLootItem(item.childLoot[i], charm) then
tmpItem:remove()
return false
end
Expand Down
84 changes: 46 additions & 38 deletions data/modules/scripts/gamestore/gamestore.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4152,14 +4152,56 @@ GameStore.Categories = {
},
},
},
-- Usefull Things
{
-- Usefull Things
{
icons = { "Category_UsefulThings.png" },
name = "Useful Things",
parent = "Extras",
rookgaard = true,
state = GameStore.States.STATE_NONE,
offers = {
offers = {
{
icons = {"Prey_Bonus_Reroll.png"},
name = "Prey Wildcard",
price = 15,
id = 1,
count = 5,
description = "<i>Use Prey Wildcards to reroll the bonus of an active prey, to lock your active prey or to select a prey of your choice.</i>\n\n{character}\n{info} added directly to Prey dialog\n{info} maximum amount that can be owned by character: 50",
type = GameStore.OfferTypes.OFFER_TYPE_PREYBONUS
},
{
icons = {"Instant_Reward_Access.png"},
name = "Instant Reward Access",
price = 50,
id = 2,
count = 1,
description = "<i>No matter where you are in Tibia, claim your daily reward on the spot!</i>\n\n{character}\n{info} added to your reward wall\n{info} maximum amount that can be owned by character: 90",
type = GameStore.OfferTypes.OFFER_TYPE_INSTANT_REWARD_ACCESS
},
{
icons = {"Charm_Expansion_Offer.png"},
name = "Charm Expansion",
price = 400,
id = 3,
description = "<i>Assign as many of your unlocked Charms as you like and get a 25% discount whenever you are removing a Charm from a creature!</i>\n\n{character}\n{once}",
type = GameStore.OfferTypes.OFFER_TYPE_CHARMS
},
{
icons = {"Permanent_Prey_Slot.png"},
name = "Permanent Prey Slot",
price = 350,
id = 4,
description = "<i>Get an additional prey slot to activate additional prey!</i>\n\n{character}\n{info} maximum amount that can be owned by character: 3\n{info} added directly to Prey dialog",
type = GameStore.OfferTypes.OFFER_TYPE_PREYSLOT
},
{
icons = {"Permanent_Hunting_Task_Slot.png"},
name = "Permanent Hunting Task Slot",
price = 350,
id = 5,
description = "<i>Get an additional hunting tasks slot to activate additional hunting task!</i>\n\n{character}\n{info} maximum amount that can be owned by character: 3\n{info} added directly to Hunting Task dialog",
type = GameStore.OfferTypes.OFFER_TYPE_HUNTINGSLOT
},
{
icons = { "Gold_Converter.png" },
name = "Gold Converter",
Expand All @@ -4178,23 +4220,6 @@ GameStore.Categories = {
description = "<i>Carries as many gold, platinum or crystal coins as your capacity allows, however, no other items.</i>\n\n{character}\n{storeinbox}\n{once}\n{useicon} use it to open it\n{info} always placed on the first position of your Store inbox",
type = GameStore.OfferTypes.OFFER_TYPE_POUNCH,
},
{
icons = { "Instant_Reward_Access.png" },
name = "Instant Reward Access",
price = 100,
id = 2,
count = 1,
description = "<i>No matter where you are in Tibia, claim your daily reward on the spot!</i>\n\n{character}\n{info} added to your reward wall\n{info} maximum amount that can be owned by character: 90",
type = GameStore.OfferTypes.OFFER_TYPE_INSTANT_REWARD_ACCESS,
},
{
icons = { "Charm_Expansion_Offer.png" },
name = "Charm Expansion",
price = 450,
id = 65005,
description = "<i>Assign as many of your unlocked Charms as you like and get a 25% discount whenever you are removing a Charm from a creature!</i>\n\n{character}\n{once}",
type = GameStore.OfferTypes.OFFER_TYPE_CHARMS,
},
{
icons = { "Magic_Gold_Converter.png" },
name = "Magic Gold Converter",
Expand All @@ -4204,23 +4229,6 @@ GameStore.Categories = {
description = "<i>Changes automatically either a stack of 100 gold pieces into 1 platinum coin, or a stack of 100 platinum coins into 1 crystal coin!</i>\n\n{character}\n{storeinbox}\n{useicon} use it to activate or deactivate the automatic conversion\n{info} converts all stacks of 100 gold or platinum in the inventory whenever it is activated\n{info} deactivated upon purchase\n{info} usable for 500 conversions a piece",
type = GameStore.OfferTypes.OFFER_TYPE_CHARGES,
},
{
icons = { "Permanent_Prey_Slot.png" },
name = "Permanent Prey Slot",
price = 900,
id = 65008,
description = "<i>Get an additional prey slot to activate additional prey!</i>\n\n{character}\n{info} maximum amount that can be owned by character: 3\n{info} added directly to Prey dialog",
type = GameStore.OfferTypes.OFFER_TYPE_PREYSLOT,
},
{
icons = { "Prey_Bonus_Reroll.png" },
name = "Prey Wildcard",
price = 50,
id = 1,
count = 5,
description = "<i>Use Prey Wildcards to reroll the bonus of an active prey, to lock your active prey or to select a prey of your choice.</i>\n\n{character}\n{info} added directly to Prey dialog\n{info} maximum amount that can be owned by character: 50",
type = GameStore.OfferTypes.OFFER_TYPE_PREYBONUS,
},
{
icons = { "Prey_Bonus_Reroll.png" },
name = "Prey Wildcard",
Expand All @@ -4236,7 +4244,7 @@ GameStore.Categories = {
description = "<i>Teleports you instantly to your home temple.</i>\n\n{character}\n{useicon} use it to teleport you to your home temple</i>\n{battlesign}\n{info} does not work in no-logout zones or close to a character's home temple",
type = GameStore.OfferTypes.OFFER_TYPE_TEMPLE,
},
},
},
},
--Tournament
{
Expand Down
30 changes: 19 additions & 11 deletions data/modules/scripts/gamestore/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ GameStore.OfferTypes = {
OFFER_TYPE_HIRELING_NAMECHANGE = 21,
OFFER_TYPE_HIRELING_SEXCHANGE = 22,
OFFER_TYPE_HIRELING_SKILL = 23,
OFFER_TYPE_HIRELING_OUTFIT = 24
OFFER_TYPE_HIRELING_OUTFIT = 24,
OFFER_TYPE_HUNTINGSLOT = 25
}

GameStore.SubActions = {
PREY_THIRDSLOT = 0,
TASKHUNTING_THIRDSLOT = 14
}

GameStore.ActionType = {
Expand Down Expand Up @@ -309,22 +315,24 @@ function parseRequestStoreOffers(playerId, msg)
end
elseif actionType == GameStore.ActionType.OPEN_USEFUL_THINGS then
local subAction = msg:getByte()
local redirectId = subAction
local category = nil
if subAction >= 4 then
category = GameStore.getCategoryByName("Blessings")
else
category = GameStore.getCategoryByName("Useful Things")
end
local offerId = subAction
local category = GameStore.getCategoryByName("Useful Things")

-- Third prey slot offerId
-- We can't use offerId 0
if subAction == 0 then
redirectId = 65008
-- Subaction 0 is offer from "unlock permanently" of prey window button, offerId 4 is the id of the gamestore.lua third slot
if subAction == GameStore.SubActions.PREY_THIRDSLOT then
offerId = 4
-- Subaction 14 is offer from "unlock permanently" of task hunting window button, offerId 5 is the id of the gamestore.lua third slot
elseif subAction == GameStore.SubActions.TASKHUNTING_THIRDSLOT then
offerId = 5
end
-- Enable this for look sub action offer button
-- Example of subaction is the button for redirect to the store on clicking "unlock permanently" on prey window
--Spdlog.info("SubAction ".. subAction)

if category then
addPlayerEvent(sendShowStoreOffers, 50, playerId, category, redirectId)
addPlayerEvent(sendShowStoreOffers, 50, playerId, category, offerId)
end

elseif actionType == GameStore.ActionType.OPEN_OFFER then
Expand Down
14 changes: 8 additions & 6 deletions src/creatures/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,25 +511,27 @@ class Creature : virtual public Thing
delete this;
}
}
struct CountBlock_t {
int32_t total;
int64_t ticks;
};
using CountMap = std::map<uint32_t, CountBlock_t>;
CountMap getDamageMap() const {
return damageMap;
}

protected:
virtual bool useCacheMap() const {
return false;
}

struct CountBlock_t {
int32_t total;
int64_t ticks;
};

static constexpr int32_t mapWalkWidth = Map::maxViewportX * 2 + 1;
static constexpr int32_t mapWalkHeight = Map::maxViewportY * 2 + 1;
static constexpr int32_t maxWalkCacheWidth = (mapWalkWidth - 1) / 2;
static constexpr int32_t maxWalkCacheHeight = (mapWalkHeight - 1) / 2;

Position position;

using CountMap = std::map<uint32_t, CountBlock_t>;
CountMap damageMap;

std::list<Creature*> summons;
Expand Down
Loading