Skip to content

Commit

Permalink
[Feature/Enhancement] - Prey system rework (CPP) + Hunting task system (
Browse files Browse the repository at this point in the history
#172)

Complete rewrite of old prey system from LUA to CPP and implementation of Hunting Tasks system.

Do not test with GOD char or with low amount of creatures registered on bestiary. The PR already include the necessary amount of then.

Addition of hunting task system and entire rework of prey system. All working on CPP with few LUA integration.
  • Loading branch information
marcosvf132 authored Apr 24, 2022
1 parent b87372f commit 42af88d
Show file tree
Hide file tree
Showing 44 changed files with 2,119 additions and 1,816 deletions.
28 changes: 28 additions & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,34 @@ depotBoxes = 18
-- GameStore
gamestoreByModules = true

-- Prey system
-- NOTE: preyRerollPricePerLevel: Price multiplier in gold coin for rerolling prey list.
-- NOTE: preySelectListPrice: Price to manually select creature on list and to lock prey slot.
-- NOTE: preyBonusRerollPrice: Price to manually reroll bonus type and to enable automatic reroll.
-- NOTE: preyBonusTime: Time in seconds that players will have of prey bonus.
-- NOTE: preyFreeRerollTime: Time in seconds that players will have to wait to get a new free prey list.
preySystemEnabled = true
preyFreeThirdSlot = false
preyRerollPricePerLevel = 200
preySelectListPrice = 1
preyBonusRerollPrice = 2
preyBonusPercentMin = 5
preyBonusPercentMax = 40
preyBonusTime = 2 * 60 * 60
preyFreeRerollTime = 20 * 60 * 60

-- Task hunting system
-- NOTE: taskHuntingLimitedTasksExhaust: Time to wait to select a new creature on the task hunting slot after claiming the reward.
-- NOTE: taskHuntingRerollPricePerLevel: Price multiplier in gold coin for rerolling task hunting list.
-- NOTE: taskHuntingFreeRerollTime: Time in seconds that players will have to wait to get a new free task hunting list.
taskHuntingSystemEnabled = true
taskHuntingFreeThirdSlot = false
taskHuntingLimitedTasksExhaust = 20 * 60 * 60
taskHuntingRerollPricePerLevel = 200
taskHuntingSelectListPrice = 1
taskHuntingBonusRerollPrice = 2
taskHuntingFreeRerollTime = 20 * 60 * 60

-- NOTE: Access only for Premium Account
onlyPremiumAccount = false

Expand Down
18 changes: 17 additions & 1 deletion data/events/scripts/monster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,31 @@ function Monster:onDropLoot(corpse)
local mType = self:getType()
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
end
end

for i = 1, #monsterLoot do
local item = corpse:createLootItem(monsterLoot[i])
local item = corpse:createLootItem(monsterLoot[i], charmBonus, preyChanceBoost)
if not item then
Spdlog.info("Could not add loot item to corpse of monster '".. mType:getName() .."'")
end
end

if player then
local text = ("Loot of %s: %s"):format(mType:getNameDescription(), corpse:getContentDescription())
if preyChanceBoost ~= 100 then
text = text .. " (active prey bonus)"
end
if charmBonus then
text = text .. " (active charm bonus)"
end
local party = player:getParty()
if party then
party:broadcastPartyLoot(text)
Expand Down
10 changes: 10 additions & 0 deletions data/events/scripts/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,11 @@ local function useStamina(player)
staminaMinutes = 0
end
nextUseStaminaTime[playerId] = currentTime + 120
player:removePreyStamina(120)
else
staminaMinutes = staminaMinutes - 1
nextUseStaminaTime[playerId] = currentTime + 60
player:removePreyStamina(60)
end
player:setStamina(staminaMinutes)
end
Expand Down Expand Up @@ -299,6 +301,14 @@ function Player:onGainExperience(source, exp, rawExp)
end
end

-- Prey system
if configManager.getBoolean(configKeys.PREY_ENABLED) then
local monsterType = source:getType()
if monsterType and monsterType:raceId() > 0 then
exp = math.ceil((exp * self:getPreyExperiencePercentage(monsterType:raceId())) / 100)
end
end

return exp
end

Expand Down
13 changes: 0 additions & 13 deletions data/global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ if damageImpact == nil then
damageImpact = {}
end

-- New prey => preyTimeLeft
if nextPreyTime == nil then
nextPreyTime = {}
end

do -- Event Schedule rates
local lootRate = Game.getEventSLoot()
if lootRate ~= 100 then
Expand Down Expand Up @@ -126,10 +121,6 @@ if nextUseStaminaTime == nil then
nextUseStaminaTime = {}
end

if nextUseStaminaPrey == nil then
nextUseStaminaPrey = {}
end

if nextUseXpStamina == nil then
nextUseXpStamina = {}
end
Expand All @@ -138,10 +129,6 @@ if lastItemImbuing == nil then
lastItemImbuing = {}
end

if nextDelayPreyReroll == nil then
nextDelayPreyReroll = {}
end

-- Delay potion
if not playerDelayPotion then
playerDelayPotion = {}
Expand Down
14 changes: 10 additions & 4 deletions data/lib/core/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, boolCharm)
function Container.createLootItem(self, item, charm, prey)
if self:getEmptySlots() == 0 then
return true
end
Expand All @@ -16,8 +16,14 @@ function Container.createLootItem(self, item, boolCharm)
return
end

if boolCharm and lootBlockType:getType() == ITEM_TYPE_CREATUREPRODUCT then
chanceTo = (chanceTo * (GLOBAL_CHARM_GUT + 100))/100
-- Bestiary charm bonus
if charm and lootBlockType:getType() == ITEM_TYPE_CREATUREPRODUCT then
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
Expand All @@ -40,7 +46,7 @@ function Container.createLootItem(self, item, boolCharm)

if tmpItem:isContainer() then
for i = 1, #item.childLoot do
if not tmpItem:createLootItem(item.childLoot[i]) then
if not tmpItem:createLootItem(item.childLoot[i], charm, prey) then
tmpItem:remove()
return false
end
Expand Down
54 changes: 51 additions & 3 deletions data/migrations/0.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,53 @@
-- return true = There are others migrations file
-- return false = This is the last migration file
function onUpdateDatabase()
return false
Spdlog.info("Updating database to version 19 (Prey system rework + Task hunting system)")
db.query([[
ALTER TABLE `players`
DROP `prey_stamina_1`,
DROP `prey_stamina_2`,
DROP `prey_stamina_3`,
DROP `prey_column`,
ADD `prey_wildcard` bigint(21) NOT NULL DEFAULT 0,
ADD `task_points` bigint(21) NOT NULL DEFAULT 0;
]])

db.query([[
DROP TABLE `player_prey`;
]])

db.query([[
DROP TABLE `prey_slots`;
]])

db.query([[
CREATE TABLE IF NOT EXISTS `player_taskhunt` (
`player_id` int(11) NOT NULL,
`slot` tinyint(1) NOT NULL,
`state` tinyint(1) NOT NULL,
`raceid` varchar(250) NOT NULL,
`upgrade` tinyint(1) NOT NULL,
`rarity` tinyint(1) NOT NULL,
`kills` varchar(250) NOT NULL,
`disabled_time` bigint(20) NOT NULL,
`free_reroll` bigint(20) NOT NULL,
`monster_list` BLOB NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
]])

db.query([[
CREATE TABLE IF NOT EXISTS `player_prey` (
`player_id` int(11) NOT NULL,
`slot` tinyint(1) NOT NULL,
`state` tinyint(1) NOT NULL,
`raceid` varchar(250) NOT NULL,
`option` tinyint(1) NOT NULL,
`bonus_type` tinyint(1) NOT NULL,
`bonus_rarity` tinyint(1) NOT NULL,
`bonus_percentage` varchar(250) NOT NULL,
`bonus_time` varchar(250) NOT NULL,
`free_reroll` bigint(20) NOT NULL,
`monster_list` BLOB NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
]])

return true
end
5 changes: 5 additions & 0 deletions data/migrations/1.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- return true = There are others migrations file
-- return false = This is the last migration file
function onUpdateDatabase()
return false
end
4 changes: 0 additions & 4 deletions data/modules/modules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
<module type="recvbyte" byte="253" script="gamestore/gamestore.lua"/>
<module type="recvbyte" byte="254" script="gamestore/gamestore.lua"/>

<!-- Prey System -->
<module type="recvbyte" byte="235" script="prey_system/prey.lua" />
<module type="recvbyte" byte="237" script="prey_system/prey.lua" />

<!-- Blessings -->
<module type="recvbyte" byte="207" script="blessings/blessings.lua" />

Expand Down
2 changes: 1 addition & 1 deletion data/modules/scripts/daily_reward/daily_reward.lua
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ function Player.selectDailyReward(self, msg)
end

if (dailyTable.type == DAILY_REWARD_TYPE_PREY_REROLL) then
self:setPreyBonusRerolls(self:getPreyBonusRerolls() + reward)
self:addPreyCards(reward)
DailyReward.insertHistory(self:getGuid(), self:getDayStreak(), "Claimed reward no. \z
" .. self:getDayStreak() + 1 .. ". Picked reward: " .. reward .. "x Prey bonus reroll(s)")
DailyReward.processReward(playerId, source)
Expand Down
41 changes: 19 additions & 22 deletions data/modules/scripts/gamestore/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ function parseBuyStoreOffer(playerId, msg)
elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_NAMECHANGE then local newName = msg:getString(); GameStore.processNameChangePurchase(player, offer.id, productType, newName, offer.name, offerPrice)
elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_SEXCHANGE then GameStore.processSexChangePurchase(player)
elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_EXPBOOST then GameStore.processExpBoostPuchase(player)
elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_PREYSLOT then GameStore.processPreySlotPurchase(player)
elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_HUNTINGSLOT then GameStore.processPreyHuntingSlotPurchase(player)
elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_PREYSLOT then GameStore.processPreyThirdSlot(player)
elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_HUNTINGSLOT then GameStore.processTaskHuntingThirdSlot(player)
elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_PREYBONUS then GameStore.processPreyBonusReroll(player, offer.count)
elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_TEMPLE then GameStore.processTempleTeleportPurchase(player)
elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_CHARGES then GameStore.processChargesPurchase(player, offer.itemtype, offer.name, offer.charges)
Expand Down Expand Up @@ -587,7 +587,7 @@ function Player.canBuyOffer(self, offer)
disabledReason = "You already have maximum of reward tokens."
end
elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_PREYBONUS then
if self:getPreyBonusRerolls() >= 50 then
if self:getPreyCards()>= 50 then
disabled = 1
disabledReason = "You already have maximum of prey wildcards."
end
Expand All @@ -596,8 +596,13 @@ function Player.canBuyOffer(self, offer)
disabled = 1
disabledReason = "You already have charm expansion."
end
elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_HUNTINGSLOT then
if self:taskHuntingThirdSlot() then
disabled = 1
disabledReason = "You already have 3 slots released."
end
elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_PREYSLOT then
if self:getStorageValue(Prey.Config.StoreSlotStorage) == 1 then
if self:preyThirdSlot() then
disabled = 1
disabledReason = "You already have 3 slots released."
end
Expand Down Expand Up @@ -1458,33 +1463,25 @@ function GameStore.processExpBoostPuchase(player)
player:setStorageValue(GameStore.Storages.expBoostCount, expBoostCount + 1)
end

function GameStore.processPreySlotPurchase(player)
if player:getStorageValue(Prey.Config.StoreSlotStorage) < 1 then
player:setStorageValue(Prey.Config.StoreSlotStorage, 1)
player:setPreyUnlocked(CONST_PREY_SLOT_THIRD, 2)
player:setPreyState(CONST_PREY_SLOT_THIRD, 1)

-- Update Prey Data
for slot = CONST_PREY_SLOT_FIRST, CONST_PREY_SLOT_THIRD do
player:sendPreyData(slot)
end
function GameStore.processPreyThirdSlot(player)
if player:preyThirdSlot() then
return error({code = 1, message = "You already have unlocked all prey slots."})
end
player:preyThirdSlot(true)
end

function GameStore.processPreyHuntingSlotPurchase(player)
if player:getStorageValue(CONST_HUNTING_STORAGE) < 1 then
player:setStorageValue(CONST_HUNTING_STORAGE, 1)

-- Update Prey Data
player:sendPreyHuntingData(CONST_PREY_SLOT_THIRD)
function GameStore.processTaskHuntingThirdSlot(player)
if player:taskHuntingThirdSlot() then
return error({code = 1, message = "You already have unlocked all task hunting slots."})
end
player:taskHuntingThirdSlot(true)
end

function GameStore.processPreyBonusReroll(player, offerCount)
if player:getPreyBonusRerolls() + offerCount >= 51 then
if player:getPreyCards() + offerCount >= 51 then
return error({code = 1, message = "You cannot own more than 50 prey wildcards."})
end
player:setPreyBonusRerolls(player:getPreyBonusRerolls() + offerCount)
player:addPreyCards(offerCount)
end

function GameStore.processTempleTeleportPurchase(player)
Expand Down
36 changes: 0 additions & 36 deletions data/modules/scripts/prey_system/assets.lua

This file was deleted.

Loading

0 comments on commit 42af88d

Please sign in to comment.