Reference features in rolls by slug
This commit is contained in:
parent
7faebf0173
commit
1556ebe9c7
|
@ -13,8 +13,8 @@ class DiceRoller
|
||||||
end
|
end
|
||||||
|
|
||||||
def roll
|
def roll
|
||||||
@roll_command = @roll_command.sub("self", @stat.to_s) if @roll_command.include?("self")
|
roll_command = parse_roll_command_references(roll_command)
|
||||||
Dice.roll(@roll_command)
|
Dice.roll(roll_command)
|
||||||
end
|
end
|
||||||
|
|
||||||
def valid?
|
def valid?
|
||||||
|
@ -39,6 +39,10 @@ class DiceRoller
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def roll_delimiters
|
||||||
|
[ "+", "-", "*", "/" ]
|
||||||
|
end
|
||||||
|
|
||||||
def roll_dice(command)
|
def roll_dice(command)
|
||||||
parts = command.downcase.split("d").compact_blank
|
parts = command.downcase.split("d").compact_blank
|
||||||
die_type = parts.last
|
die_type = parts.last
|
||||||
|
@ -52,4 +56,18 @@ class DiceRoller
|
||||||
end
|
end
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def parse_roll_command_references(roll_command)
|
||||||
|
roll_command = @roll_command.include?("self") ? @roll_command.gsub("self", @stat.to_s) : @roll_command
|
||||||
|
|
||||||
|
roll_command.split(Regexp.union(roll_delimiters)).each do |part|
|
||||||
|
next if part.match?(/\A\d*\z/)
|
||||||
|
next if part.match?(/\A\d*d\d*\z/)
|
||||||
|
|
||||||
|
value = CharacterSheetFeature.find_by(slug: part).featurable.value
|
||||||
|
raise "#{part} not found" if value.blank?
|
||||||
|
roll_command.gsub!(part, value.to_s)
|
||||||
|
end
|
||||||
|
roll_command
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
3
todo.md
3
todo.md
|
@ -1,10 +1,9 @@
|
||||||
Character sheets
|
Character sheets
|
||||||
= Must haves
|
= Must haves
|
||||||
- Refer to stat in roll (Skill in Troika)
|
- Add tests for feature references
|
||||||
- Lists
|
- Lists
|
||||||
- Reorganise sections
|
- Reorganise sections
|
||||||
- Edit additional roll types
|
- Edit additional roll types
|
||||||
- improve dice roll parsing to allow e.g. choose highest
|
|
||||||
= Nice to haves
|
= Nice to haves
|
||||||
- Calculate from result - e.g. troika damage roll should calc. damage amount from die roll:w
|
- Calculate from result - e.g. troika damage roll should calc. damage amount from die roll:w
|
||||||
- Add min/max when creating stats
|
- Add min/max when creating stats
|
||||||
|
|
Loading…
Reference in New Issue