LinkLuaModifier("modifier_book_strength", "items/books.lua", LUA_MODIFIER_MOTION_NONE)
LinkLuaModifier("modifier_book_agility", "items/books.lua", LUA_MODIFIER_MOTION_NONE)
LinkLuaModifier("modifier_book_intellect", "items/books.lua", LUA_MODIFIER_MOTION_NONE)
local function FindItemInInventory(caster, ability)
if not caster or not ability then return nil end
for slot = 0, 11 do
local item = caster:GetItemInSlot(slot)
if item == ability then
return item
end
end
return nil
end
local function ApplyBook(caster, ability, modifier_name)
if not IsServer() then return end
if not caster or caster:IsNull() or not ability or ability:IsNull() then return end
if caster.GetPlayerOwner then
local player = caster:GetPlayerOwner()
if player then
EmitSoundOnClient("Item.TomeOfKnowledge", player)
end
end
local item = FindItemInInventory(caster, ability)
if not item then
item = ability
end
local charges = item:GetCurrentCharges() or 0
if charges <= 0 then
charges = 1
end
local bonus = 2 * charges
local mod = caster:FindModifierByName(modifier_name)
if not mod then
mod = caster:AddNewModifier(caster, ability, modifier_name, {})
end
if mod then
mod:SetStackCount(mod:GetStackCount() + bonus)
end
if caster.CalculateStatBonus then
caster:CalculateStatBonus(true)
end
local invItem = FindItemInInventory(caster, ability)
if invItem then
caster:RemoveItem(invItem)
else
if ability.RemoveSelf then
ability:RemoveSelf()
end
end
end
-- Книга силы
function BookStrength(keys)
local caster = keys.caster
local ability = keys.ability
ApplyBook(caster, ability, "modifier_book_strength")
end
-- Книга ловкости
function BookAgility(keys)
local caster = keys.caster
local ability = keys.ability
ApplyBook(caster, ability, "modifier_book_agility")
end
-- Книга интеллекта
function BookIntellect(keys)
local caster = keys.caster
local ability = keys.ability
ApplyBook(caster, ability, "modifier_book_intellect")
end
-------------------------------------------------
-- Книга силы --
-------------------------------------------------
modifier_book_strength = class({})
function modifier_book_strength:IsHidden() return false end
function modifier_book_strength:IsPurgable() return false end
function modifier_book_strength:RemoveOnDeath() return false end
function modifier_book_strength:GetAttributes()
return MODIFIER_ATTRIBUTE_PERMANENT
end
function modifier_book_strength:GetTexture()
return "item_book_strength"
end
function modifier_book_strength

eclareFunctions()
return {
MODIFIER_PROPERTY_STATS_STRENGTH_BONUS,
}
end
function modifier_book_strength:GetModifierBonusStats_Strength()
return self:GetStackCount() or 0
end
-------------------------------------------------
-- Книга ловкости --
-------------------------------------------------
modifier_book_agility = class({})
function modifier_book_agility:IsHidden() return false end
function modifier_book_agility:IsPurgable() return false end
function modifier_book_agility:RemoveOnDeath() return false end
function modifier_book_agility:GetAttributes()
return MODIFIER_ATTRIBUTE_PERMANENT
end
function modifier_book_agility:GetTexture()
return "item_book_agility"
end
function modifier_book_agility

eclareFunctions()
return {
MODIFIER_PROPERTY_STATS_AGILITY_BONUS,
}
end
function modifier_book_agility:GetModifierBonusStats_Agility()
return self:GetStackCount() or 0
end
-------------------------------------------------
-- Книга интеллекта --
-------------------------------------------------
modifier_book_intellect = class({})
function modifier_book_intellect:IsHidden() return false end
function modifier_book_intellect:IsPurgable() return false end
function modifier_book_intellect:RemoveOnDeath() return false end
function modifier_book_intellect:GetAttributes()
return MODIFIER_ATTRIBUTE_PERMANENT
end
function modifier_book_intellect:GetTexture()
return "item_book_intellect"
end
function modifier_book_intellect

eclareFunctions()
return {
MODIFIER_PROPERTY_STATS_INTELLECT_BONUS,
}
end
function modifier_book_intellect:GetModifierBonusStats_Intellect()
return self:GetStackCount() or 0
end