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

Features from protocol 12+ #4868

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion data/events/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@

<!-- Monster methods -->
<event class="Monster" method="onDropLoot" enabled="1" />
<event class="Monster" method="onSpawn" enabled="0" />
<event class="Monster" method="onSpawn" enabled="1" />
</events>
1 change: 1 addition & 0 deletions data/lib/core/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ dofile('data/lib/core/teleport.lua')
dofile('data/lib/core/tile.lua')
dofile('data/lib/core/town.lua')
dofile('data/lib/core/vocation.lua')
dofile('data/lib/core/feature12plus/feature12plus.lua')
841 changes: 841 additions & 0 deletions data/lib/core/feature12plus/bosstiary.lua

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions data/lib/core/feature12plus/charms.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
local charmStatus = {
UNLOCKED = 1,
LOCKED = 0,
}

function Player.isCharmUnlocked(self, charmId)
if (self:getStorageValue(PlayerStorageKeys.charmsUnlocked + charmId) or 0) == charmStatus.UNLOCKED then
return charmStatus.UNLOCKED
end
return charmStatus.LOCKED
end

function Player.addCharmPoints(self, value)
local points = self:getCharmPoints() or 0
return self:setStorageValue(PlayerStorageKeys.charmPoints, points + value)
end

function Player.removeCharmPoints(self, value)
local points = self:getCharmPoints() or 0

if points < value then
return false
end
return self:setStorageValue(PlayerStorageKeys.charmPoints, points - value)
end

function Player.unlockCharm(self, charmId)
self:setStorageValue(PlayerStorageKeys.charmsUnlocked + charmId, charmStatus.UNLOCKED)
end

function Player.removeCharm(self, charmId)
self:setStorageValue(PlayerStorageKeys.charmsUnlocked + charmId, charmStatus.LOCKED)
end

function Player.setCharmMonster(self, charmId, raceId)
if self:isCharmUnlocked(charmId) == charmStatus.LOCKED then
return false
end
return self:setStorageValue(PlayerStorageKeys.charmsMonster + charmId, raceId)
end

function Player.getCharmPoints(self)
return math.max(0, self:getStorageValue(PlayerStorageKeys.charmPoints) or 0)
end
function Player.getCharmMonster(self, charmId)
return math.max(0, self:getStorageValue(PlayerStorageKeys.charmsMonster + charmId) or 0)
end
2 changes: 2 additions & 0 deletions data/lib/core/feature12plus/feature12plus.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dofile('data/lib/core/feature12plus/bosstiary.lua')
dofile('data/lib/core/feature12plus/charms.lua')
5 changes: 5 additions & 0 deletions data/lib/core/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,11 @@ function Player.addBestiaryKills(self, raceId)
break
end
end

if kills < bestiaryInfo.mastery and newKills >= bestiaryInfo.mastery then
self:addCharmPoints(bestiaryInfo.charmPoints)
end

return self:setBestiaryKills(raceId, newKills)
end

Expand Down
15 changes: 15 additions & 0 deletions data/lib/core/storages.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,19 @@ PlayerStorageKeys = {

-- Bestiary:
bestiaryKillsBase = 400000,

-- Charms: 410000 to 410201
charmPoints = 410000,
charmsMonster = 410001,
charmsUnlocked = 410101,

-- Bosstiary: 430000 to 450006
bosstiaryKillsBase = 430000,
bosstiaryCooldownsBase = 440000,
bosstiaryPoints = 450000,
bosstiarySlot1 = 450001,
bosstiarySlot2 = 450002,
bosstiaryDay = 450004,
bosstiaryTodayRemoveDate = 450005,
bosstiaryTodayRemoveCount = 450006,
}
1 change: 1 addition & 0 deletions data/scripts/creaturescripts/player/bestiary_kills.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function creatureEvent.onKill(player, target)
for _, killer in pairs(getKillersForBestiary(monster)) do
killer:addBestiaryKills(raceId)
end

return true
end

Expand Down
129 changes: 129 additions & 0 deletions data/scripts/feature12plus/bosstiary.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
local handlerList = PacketHandler(0xAE)
function handlerList.onReceive(player, msg)
player:sendBoostiaryMilestonesData()
player:sendBosstiaryList()
end
handlerList:register()

local handlerSlot = PacketHandler(0xAF)
function handlerSlot.onReceive(player, msg)
player:sendBoostiaryMilestonesData()
player:sendBoostiarySlotsData()
player:sendResourceBalance(RESOURCE_BANK_BALANCE, player:getBankBalance())
player:sendResourceBalance(RESOURCE_GOLD_EQUIPPED, player:getMoney())
end
handlerSlot:register()

local handlerSet = PacketHandler(0xB0)
function handlerSet.onReceive(player, msg)
local slot = msg:getByte()
local bossId = msg:getU32()
local isValidBoss = player:isValidBoostiaryBoss(bossId)
local isGoldRemoved = true
if bossId == 0 then
isGoldRemoved = player:removeTotalMoney(player:getBosstiaryRemoveCost())
player:incrementBosstiaryRemoveCounter()
end

if isValidBoss == true and isGoldRemoved == true then
player:sendResourceBalance(RESOURCE_BANK_BALANCE, player:getBankBalance())
player:sendResourceBalance(RESOURCE_GOLD_EQUIPPED, player:getMoney())
player:setBosstiarySlotBoss(slot, bossId)
player:sendBoostiarySlotsData()
else
player:popupFYI("You cannot set this boss to the selected slot!")
end

end
handlerSet:register()

local playerCharm = CreatureEvent("___")
function playerCharm.onLogin(player)
player:sendTextMessage(MESSAGE_STATUS_DEFAULT,
string.format("%s %s\n%s", "Today's boosted boss:",
Bosstiary.getBossById(Bosstiary.getTodayBoostedBoss().id).name,
"Boosted bosses contain more loot and count more kills for your Bosstiary."))
player:registerEvent("Bosstiary_onKill")
player:resetBestiaryRemoveCountIfNeeded()
player:setBosstiaryLastRemoveDate()
return true
end
playerCharm:register()

local creatureevent = CreatureEvent("Bosstiary_onKill")
function creatureevent.onKill(player, target)
local bossData = Bosstiary.getBossByName(target:getName())
if not bossData then
return true
end

local todayBoostedBossId = Bosstiary.getTodayBoostedBoss().id
local todayBoostedBossName = Bosstiary.getBossById(todayBoostedBossId).name
local killers = target:getKillers(true)
if todayBoostedBossName == target:getName() then
for _, killer in ipairs(killers) do
killer:addBosstiaryKills(todayBoostedBossId, Bosstiary.getConst().TODAY_BOOSTED_BOSS_KILL_COUNT)
end
else
for _, killer in ipairs(killers) do
killer:addBosstiaryKills(bossData.id, 1)
end
end
return true
end
creatureevent:register()

local function isEqItem(item)
local it = ItemType(item.itemId)
if it:isWeapon() or it:isHelmet() or it:isArmor() or it:isLegs() or it:isBoots() or it:isQuiver() or it:isShield() or
it:isNecklace() or it:isRing() or it:isTrinket() then
return true
end
return false
end

local event = Event()
event.onDropLoot = function(self, corpse)
if configManager.getNumber(configKeys.RATE_LOOT) == 0 then
return
end

local player = Player(corpse:getCorpseOwner())
local mType = self:getType()
local doCreateLoot = false

if not player or player:getStamina() > 840 then
doCreateLoot = true
end

local bossData = Bosstiary.getBossByName(self:getName())
if not bossData then
return
end

local bonusRollChance = player:getBosstiaryBonusValue()
if bossData.id == Bosstiary.getTodayBoostedBoss().id then
bonusRollChance = Bosstiary.getConst().TODAY_BOOSTED_BOSS_KILL_BONUS
end

while bonusRollChance > 0 do
local roll = math.random(1, 100)
if roll <= bonusRollChance then
if doCreateLoot then
local monsterLoot = mType:getLoot()
for i = 1, #monsterLoot do
if isEqItem(monsterLoot[i]) then
local item = corpse:createLootItem(monsterLoot[i], 1)
if not item then
print("[Warning] DropLoot: Could not add loot item to corpse.")
end
end
end
end
end

bonusRollChance = bonusRollChance - 100
end
end

event:register(-1)
Loading
Loading