~ Set the focus to ourselves or the container, depending on where we are.
var finaltext as string
if (container.ishero<> 0) then
perform parent.setfocus
else
perform this.setfocus
endif
~ First get the dice...
if (focus.field[gSize].value = -4) then
finaltext = "1d3"
elseif (focus.field[gSize].value = -3) then
finaltext = "2d3"
elseif (focus.field[gSize].value = -2) then
finaltext = "1d3+1d4"
elseif (focus.field[gSize].value = -1) then
finaltext = "2d4"
elseif (focus.field[gSize].value = 0) then
finaltext = "1d4+1d6"
elseif (focus.field[gSize].value = 1) then
finaltext = "2d6"
elseif (focus.field[gSize].value = 2) then
finaltext = "2d6+1d8"
elseif (focus.field[gSize].value = 3) then
finaltext = "4d8"
elseif (focus.field[gSize].value = 4) then
finaltext = "4d8+1d10"
endif
~ Now get the bonus
var v_style as number
v_style = focus.field[wCurrEquip].value
~ If we're adding attribute bonuses, get our strength bonus to add to
~ the weapon damage
var bonus as number
var halfbonus as number
var extrabonus as number
var twobonus as number
~start with the stored value for attribute bonus to damage for this weapon
bonus = focus.field[wDamAttr].value
~ Calculate half our strength bonus for later use
halfbonus = round(bonus / 2, 0, -1)
~ calculate 1.5x our strength bonus for later use
extrabonus = round(bonus * 1.5, 0, -1)
~ calculate 2x our strength bonus for later use
twobonus = bonus * 2
~ If we're wielding the weapon in both hands, but not as a double weapon,
~ add an extra 50% of the strength bonus, rounded down (unless this weapon
~ doesn't get extra strength from that.). Don't do this if our bonus is
~ negative, since it doesn't make sense for a -2 penalty to become a
~ -3 penalty.
if (bonus >= 0) then
if (v_style <> #wepdouble[]) then
~ If we have the special 'always 2h' tag, multiply our bonus
if (focus.tagis[Helper.NatTwoHand] <> 0) then
bonus = extrabonus
elseif (v_style = #wepboth[]) then
if (focus.tagis[Helper.NoDblStr] = 0) then
bonus = extrabonus
endif
~ If we're just wielding in our off-hand, we get half our strength bonus
~ (again unless the bonus is negative, in which case that wouldn't make
~ sense).
~ this also only applies if we DON'T have the Double Slice ability, and
~ also if this weapon does not have the NoHalfStr tag (used by Monks
~ for Unarmed Strike).
elseif (v_style = #wepoff[]) then
if (hero.tagis[Hero.DblSlice] + focus.tagis[Helper.NoHalfStr] = 0) then
bonus = halfbonus
endif
endif
endif
~ powerful attacks gain 2x STR damage
if (focus.tagis[Helper.Powerful] <> 0) then
bonus = twobonus
endif
endif
~ Calculate any other bonuses that apply. Start with the weapon bonus
~ and any damage bonus the weapon has.
var otherbonus as number
otherbonus = focus.field[wBonus].value + focus.field[wDamBonus].value
otherbonus += focus.field[wDamMelee].value
~ Add the typed bonuses for melee attacks
otherbonus += focus.field[dmmBonus].value + focus.field[dmmPenalty].value + focus.field[dmmRacial].value + focus.field[dmmBonAlch].value + focus.field[dmmModCirc].value + focus.field[dmmBonComp].value + focus.field[dmmPenComp].value + focus.field[dmmBonEnh].value + focus.field[dmmBonIns].value + focus.field[dmmBonLuck].value + focus.field[dmmPenLuck].value + focus.field[dmmBonMora].value + focus.field[dmmPenMora].value + focus.field[dmmBonProf].value + focus.field[dmmPenProf].value + focus.field[dmmBonSacr].value + focus.field[dmmPenSacr].value + focus.field[dmmBonTrt].value + focus.field[dmmPenTrt].value
~ Add any generalised damage bonus the hero has for whatever reason
otherbonus += hero.child[Damage].field[tDamBonus].value
~ Depending on the category of the weapon, add a damage bonus to it
if (focus.tagis[component.BaseWep] <> 0) then
if (focus.field[wClass].value = 0) then
otherbonus += hero.child[Damage].field[tDamLight].value
elseif (focus.field[wClass].value = 1) then
otherbonus += hero.child[Damage].field[tDamOne].value
elseif (focus.field[wClass].value = 2) then
otherbonus += hero.child[Damage].field[tDamTwo].value
endif
endif
~ If this is a weapon that can have Weapon Finesse applied to it, apply
~ the appropriate damage bonus
if (focus.tagis[Helper.Finesse] <> 0) then
otherbonus += hero.child[Damage].field[tDamFiness].value
endif
~ Add our weapon bonus to the damage
bonus += otherbonus
halfbonus += otherbonus
~ Add whatever strength bonus we deserve to the text
if (bonus <> 0) then
finaltext &= signed(bonus)
endif
if (focus.tagis[wSpecial.Nonlethal] <> 0) then
finaltext &= " nonlethal"
endif
~ Now get the extra damage
finaltext &= focus.field[wDamExtra].text
~ Everything should be combined into a single string now, so set that into the fixed damage field
focus.field[wFixDamage].text = finaltext