Skip to content

Reworking the talent interface

bricks42 edited this page Jan 3, 2012 · 11 revisions

Reworking the talent interface

Goal

Expose the probability of the various talent effects.

AtomicEffects

Create effects that are atomic (in the database sense). These effects may replace DamageTypes, and have two steps. The first step is called calculate, which takes the source actor, target actor, and additional parameters in order to calculate the probability and magnitude (etc.) of the effect taking place. The second step is called apply, which applies the the results of the calculate step.

My original idea was to have a table of these AtomicEffects like this:

effects = {
    {ActorEffects:getEffectFromId("ATOMICEFF_MELEE_ATTACK"), {mult=1.1}},
    {ActorEffects:getEffectFromId("ATOMICEFF_STUN"), {duration=5}}
}

The effects would then loop in order. I am missing complex combinations of effects in a talent, though. For example, stunning blow can do damage if the blow hits, and has a 30% chance of trying to stun the target if the blow hits. This is easy to write with the previous action function and Lua logical statements:

local hit = calc_hit(source, target)
if hit and rng.percent(30) then
    stun(target)
end

The calculate function for each AtomicEffect is really for the check of attack vs. defense (or saves, etc). I need a way to add to link effects together, and in such a way that the link stays during the calculate phase.

Probability Class

Instead of the probability returned by AtomicEffects:calculate being a scalar, it would be a Probability instance. The Probability class would have a method for predicting its probability, as well as resolving the probability to a boolean that is never changed for the specific instance. Additionally the Probability classes can use arithmetic overloading to be combined to make branching probabilities.

  • The * operator is a logical AND between probabilities
  • The / operator is a logical OR between probabilities
  • The % operator is a logical XOR between probabilities
  • The - (unary) operator is a logical NOT of a single probability

For example, we will look at a talent where a main-hand and off-hand melee attack are performed, and different effects result depending on if both, one, or neither attack hits.

-- Get the melee attacks
local mainhand = AtomicEffects:getEffectFromId("MAINHAND_MELEE"):calculate(self, target)
local offhand = AtomicEffects:getEffectFromId("OFFHAND_MELEE"):calculate(self, target)
-- Get the possible secondary effects
-- Currently the stun.prob, disarm.prob, and fall.prob are defined by the effect itself and could depend on a save system, etc.
local stun = AtomicEffects:getEffectFromId("STUN"):calculate(self, target)
local disarm = AtomicEffects:getEffectFromId("DISARM"):calculate(self, target)
local fall = AtomicEffects:getEffectFromId("FALLDOWN"):calculate(self)
-- Here is an example of two AND combinations
-- This means "the stun would pass saves AND the mainhand hits AND the offhand hits"
stun.prob = stun.prob * mainhand.prob * offhand.prob
-- Here is an example of XOR, or just one attack hitting
-- This means "the disarm passes saves AND ONE AND ONLY ONE of the mainhand or the offhand hits"
disarm.prob = disarm.prob * (mainhand.prob % offhand.prob)
-- Here is an example of NOTs
-- This means "the fall passes saves (or whatever) AND the mainhand misses AND the offhand misses"
fall.prob = fall.prob * (#mainhand.prob * #offhand.prob)

Clone this wiki locally