RPG.V1.Battle.Attack (rpg v0.1.0)
The Attack module is responsible for resolving an attack. An Attack struct contains an attacker, a defender, and a list of damages.
Each damage is a tuple of {damage_type, damage_value}.
Link to this section Summary
Functions
execute.
Link to this section Functions
Link to this function
execute(struct)
execute.
Returns a tuple containing two lists, one a list of modifiers which apply to the defender, and another list of modifiers which apply to the attacker.
examples
Examples
iex> attacker = RPG.V1.Character.create(%{name: "Attacker", class: :black_mage, level: 1})
%RPG.V1.Character{
class: :black_mage,
defense: 6,
hit_points: 8,
level: 1,
magic_points: 3,
modifiers: [
%RPG.Modifier{attribute: :hit_points, source: :black_mage, type: :add, value: 2},
%RPG.Modifier{attribute: :magic_points, source: :black_mage, type: :add, value: 3}
],
name: "Attacker",
strength: 6,
toxicity: 0
}
iex> defender = RPG.V1.Character.create(%{name: "Defender", class: :fighter, level: 1})
%RPG.V1.Character{
class: :fighter,
defense: 6,
hit_points: 8,
level: 1,
magic_points: 0,
modifiers: [
%RPG.Modifier{attribute: :hit_points, source: :fighter, type: :add, value: 2},
%RPG.Modifier{attribute: :strength, source: :fighter, type: :add, value: 3}
],
name: "Defender",
strength: 9,
toxicity: 0
}
iex> attack = %RPG.V1.Battle.Attack{attacker: attacker, defender: defender, damages: [{:blunt_damage, 7}]}
%RPG.V1.Battle.Attack{
defender: %RPG.V1.Character{
class: :fighter,
defense: 6,
hit_points: 8,
level: 1,
magic_points: 0,
modifiers: [
%RPG.Modifier{attribute: :hit_points, source: :fighter, type: :add, value: 2},
%RPG.Modifier{attribute: :strength, source: :fighter, type: :add, value: 3}
],
name: "Defender",
strength: 9,
toxicity: 0
},
attacker: %RPG.V1.Character{
class: :black_mage,
defense: 6,
hit_points: 8,
level: 1,
magic_points: 3,
modifiers: [
%RPG.Modifier{attribute: :hit_points, source: :black_mage, type: :add, value: 2},
%RPG.Modifier{attribute: :magic_points, source: :black_mage, type: :add, value: 3}
],
name: "Attacker",
strength: 6,
toxicity: 0
},
damages: [{:blunt_damage, 7}]
}