Um, that method is terrible. It makes the attack power display wrong. That is a release breaker bug and completely inappropriate to use in a mod. Plus, the specific implementation doesn't even work, and I'm pretty sure it introduces a serialization error.
The method I described is extremely simple. Here is a plug-and-play version I wrote just for you:
Code: Select all
defineObject{
name = "party",
baseObject = "party",
components = {
{
class = "Timer",
name = "berserkerUpdateTimer",
timerInterval = 0.0001,
onActivate = function(self)
for champNum = 1,4 do
local champ = party.party:getChampion(champNum)
for slot=ItemSlot.Weapon,ItemSlot.OffHand do
local item = champ:getItem(slot)
if item and item:hasTrait("berserker_weapon") then
local attackClasses = {
FirearmAttackComponent = true,
MeleeAttackComponent = true,
RangedAttackComponent = true,
ThrowAttackComponent = true,
}
for _,comp in item.go:componentIterator() do
if attackClasses[comp:getClass()] then
local power
local weaponData = party.berserkerScript.get(item.go.id)
if weaponData then
power = weaponData[comp:getName()]
end
if not power then
power = comp:getAttackPower()
-- store original attack power
if weaponData then
weaponData[comp:getName()] = power
else
party.berserkerScript.set(item.go.id,{[comp:getName()]=power})
end
end
if champ:hasTrait("expert_axeman") then
local skillCompensationDiv = 1 -- compensate for weapon skill bonus
if item:hasTrait("heavy_weapon") then
skillCompensationDiv = skillCompensationDiv+champ:getSkillLevel("heavy_weapons")*0.2
end
if item:hasTrait("light_weapon") then
skillCompensationDiv = skillCompensationDiv+champ:getSkillLevel("light_weapons")*0.2
end
if item:hasTrait("missile_weapon") then
skillCompensationDiv = skillCompensationDiv+champ:getSkillLevel("missile_weapons")*0.2
end
power = power+20/skillCompensationDiv
if champ:hasTrait("grandmaster_axeman") then
power = power+20/skillCompensationDiv
end
end
comp:setAttackPower(power)
end
end
end
end
end
end,
},
{
class = "Script",
name = "berserkerScript",
source = [[
vars = {}
function set(key,val)
vars[key] = val
end
function get(key)
return vars[key]
end
function weaponUnequip(item,champion,slot)
if slot == ItemSlot.Weapon or slot == ItemSlot.OffHand then
-- reset attack power
local attackClasses = {
FirearmAttackComponent = true,
MeleeAttackComponent = true,
RangedAttackComponent = true,
ThrowAttackComponent = true,
}
for _,comp in item.go:componentIterator() do
if attackClasses[comp:getClass()] then
local weaponData = get(item.go.id)
if weaponData then
if weaponData[comp:getName()] then
comp:setAttackPower(weaponData[comp:getName()])
end
end
end
end
set(item.go.id,nil) -- remove stored weapon data
end
end]],
},
},
}
To make a weapon eligible for the traits, simply add the "berserker_weapon" trait and the following onUnequipItem hook:
Code: Select all
onUnequipItem = function(self,champion,slot)
party.berserkerScript.weaponUnequip(self,champion,slot)
end,
So this is what your flail would look like:
Code: Select all
defineObject{
name = "flail",
baseObject = "base_item",
components = {
{
class = "Model",
model = "assets/models/items/flail.fbx",
},
{
class = "Item",
uiName = "Flail",
gfxIndex = 87,
gfxIndexPowerAttack = 423,
impactSound = "impact_blunt",
weight = 6.5,
traits = { "heavy_weapon", "mace", "berserker_weapon" },
onUnequipItem = function(self,champion,slot)
party.berserkerScript.weaponUnequip(self,champion,slot)
end,
},
{
class = "MeleeAttack",
attackPower = 24,
pierce = 10,
cooldown = 5,
swipe = "vertical",
attackSound = "swipe_heavy",
requirements = { "heavy_weapons", 3 },
powerAttackTemplate = "stun",
},
},
tags = { "weapon" },
}
This method is good performance-wise, keeps the attack power display correct, and doesn't cause serialization issues.
edit: added compensation for weapon skill bonuses, since it looks like you didn't want it to stack with those. Also, you probably want to add a note in the introduction to your dungeon that explains why weapons' attack power appears to jump around.