Results can have Only if; List view rolls show the result at once
A roll table's result can now have "Can come up only if" (the same show_if options use): while it's false the result is rolled again, and the card shows the condition on the row. Rolling from List view skips the animation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1162f9150d
commit
8592c9c059
7 changed files with 51 additions and 12 deletions
|
|
@ -8,15 +8,22 @@ extends RefCounted
|
|||
## Most times a thread rolls again on the results it skips before giving up.
|
||||
const MAX_REROLLS := 100
|
||||
const ALL_REROLLED := "This thread rolls again on every result"
|
||||
const NONE_ALLOWED := "Nothing on this card can come up right now: every result's Only if is false"
|
||||
|
||||
|
||||
## pick_node() for the frame `f` that reached the card: its thread may roll
|
||||
## with other dice (f.dice) and roll again on some results (f.reroll, result
|
||||
## ids). Skipped rolls go in a {"type": "reroll", "skipped": [{value, text}]}
|
||||
## why fact on the kept node.
|
||||
## ids). A result whose "Only if" (show_if) is false right now is rolled
|
||||
## again too. Skipped rolls go in a {"type": "reroll", "skipped": [{value,
|
||||
## text}]} why fact on the kept node.
|
||||
static func pick_for(t: RollTable, ctx: RollContext, f: Dictionary) -> Dictionary:
|
||||
var dice := str(f.get("dice", ""))
|
||||
var skip: Array = f.get("reroll", [])
|
||||
var thread_skip: Array = f.get("reroll", [])
|
||||
var skip: Array = thread_skip.duplicate()
|
||||
if t.kind == RollTable.KIND_ROLL:
|
||||
for e in t.entries:
|
||||
if e.show_if.strip_edges() != "" and not skip.has(e.id) and not RollChoice.option_shown(e, ctx):
|
||||
skip.append(e.id)
|
||||
if skip.is_empty():
|
||||
return pick_node(t, ctx, dice)
|
||||
var left := false
|
||||
|
|
@ -24,7 +31,7 @@ static func pick_for(t: RollTable, ctx: RollContext, f: Dictionary) -> Dictionar
|
|||
if not skip.has(e.id) and t.can_come_up(e):
|
||||
left = true
|
||||
if not left:
|
||||
return Roller._stop(t, ALL_REROLLED)
|
||||
return Roller._stop(t, ALL_REROLLED if skip.size() == thread_skip.size() else NONE_ALLOWED)
|
||||
var skipped: Array = []
|
||||
for n in MAX_REROLLS:
|
||||
var node := pick_node(t, ctx, dice)
|
||||
|
|
|
|||
|
|
@ -147,8 +147,8 @@ static func lint_options(t: RollTable) -> Array[Dictionary]:
|
|||
var w := e.show_if.strip_edges()
|
||||
if w == "":
|
||||
continue
|
||||
if not pick:
|
||||
out.append({"table_id": t.id, "entry_id": e.id, "message": "Show only if %s does nothing: only Which option cards hide options" % w})
|
||||
if not pick and t.kind != RollTable.KIND_ROLL:
|
||||
out.append({"table_id": t.id, "entry_id": e.id, "message": "Only if %s does nothing here: only results and Which options can be held back" % w})
|
||||
elif Expr.check(w) != "":
|
||||
out.append({"table_id": t.id, "entry_id": e.id, "message": "Show only if %s: %s" % [w, Expr.check(w)]})
|
||||
return out
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ A spread can remember [b]values[/b] between rolls, such as Luck, Gold or the cur
|
|||
- Text values work as lists: `@traits += "Brave"` adds an item, and `-=` takes one out. A [b]List[/b] variable adds an item only if it isn't there yet, unless you tick [b]Allow repeats[/b]; then it adds it every time, in order.
|
||||
|
||||
## Conditions
|
||||
Conditions are used by Only if threads, branches, repeats and Show only if. In plain words they read "Luck is at least 2". As text: `@luck >= 2`, `@town = "Saltmere"`, `@gold > 0 and @luck < 3`.
|
||||
Conditions are used by Only if threads, branches, repeats, Show only if on options, and [b]Can come up only if[/b] on results (a result whose condition is false is rolled again). In plain words they read "Luck is at least 2". As text: `@luck >= 2`, `@town = "Saltmere"`, `@gold > 0 and @luck < 3`.
|
||||
|
||||
# Scales
|
||||
A [b]Scale[/b] is a value that moves along steps in order, lowest first, such as a Climate that runs [b]Supercold, Cold, Temperate, Hot, Superhot[/b]. Add one with [b]+ Card ▾ → Scale (ordered steps)[/b], then list its steps, one per line, and pick the step it starts at. The card shows the current step, and the row of steps under it shows where that sits.
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ func _init() -> void:
|
|||
await _test_columns_each()
|
||||
_test_dice_override()
|
||||
_test_reroll()
|
||||
_test_only_if_results()
|
||||
_test_save_load()
|
||||
_test_lint()
|
||||
finish()
|
||||
|
|
@ -187,6 +188,33 @@ func _test_reroll() -> void:
|
|||
_eq(str(tree2["children"][0]["stop"]), RollCards.ALL_REROLLED, "rolling again on everything stops")
|
||||
|
||||
|
||||
## A roll table's result with "Can come up only if" (show_if) is rolled
|
||||
## again while its condition is false.
|
||||
func _test_only_if_results() -> void:
|
||||
var b := TowerBoard.new()
|
||||
var t := RollTable.new("loot", "Loot")
|
||||
for item: Array in [["a", "Copper"], ["b", "Silver"], ["c", "Dragon hoard"]]:
|
||||
t.entries.append(TableEntry.new(item[0], item[1]))
|
||||
t.entries[2].show_if = "@level >= 5"
|
||||
b.tables.append(t)
|
||||
var low := Roller.new_context(b, RandomNumberGenerator.new(), {"level": {"value": 1}}, {})
|
||||
var saw_hoard := false
|
||||
for s in 60:
|
||||
low.rng.seed = s
|
||||
saw_hoard = saw_hoard or ((RollCards.pick_for(t, low, {})["entry"] as TableEntry).id == "c")
|
||||
_check(not saw_hoard, "a result whose Only if is false never comes up")
|
||||
var high := Roller.new_context(b, RandomNumberGenerator.new(), {"level": {"value": 9}}, {})
|
||||
var got_hoard := false
|
||||
for s in 60:
|
||||
high.rng.seed = s
|
||||
got_hoard = got_hoard or ((RollCards.pick_for(t, high, {})["entry"] as TableEntry).id == "c")
|
||||
_check(got_hoard, "it comes up once its Only if is true")
|
||||
for e in t.entries:
|
||||
e.show_if = "@level >= 5"
|
||||
_eq(str(RollCards.pick_for(t, low, {}).get("stop", "")), RollCards.NONE_ALLOWED, "when nothing is allowed the card says so")
|
||||
_check(RollLint.lint_options(t).is_empty(), "Only if on a roll result isn't flagged as doing nothing")
|
||||
|
||||
|
||||
func _test_save_load() -> void:
|
||||
var b := _board()
|
||||
b.tables.append(_type_card(RollTable.COLUMNS_EACH))
|
||||
|
|
|
|||
|
|
@ -83,11 +83,14 @@ static func section(insp: Inspector, t: RollTable, e: TableEntry) -> void:
|
|||
insp.wrote(t))))
|
||||
insp._content.add_child(book_line(insp, t, e))
|
||||
|
||||
if t.kind == RollTable.KIND_CHOICE and t.choice == "pick" and not (t.is_dynamic() and t.entries.find(e) == 0):
|
||||
var pick := t.kind == RollTable.KIND_CHOICE and t.choice == "pick"
|
||||
if (pick and not (t.is_dynamic() and t.entries.find(e) == 0)) or t.kind == RollTable.KIND_ROLL:
|
||||
insp.show_if_builder = ConditionBuilder.new()
|
||||
insp.show_if_builder.setup(insp.main, e.show_if, not plain, "res.show_if", {"empty_note": "Always offered."})
|
||||
insp.show_if_builder.setup(insp.main, e.show_if, not plain, "res.show_if",
|
||||
{"empty_note": "Always offered." if pick else "Can always come up."})
|
||||
insp.show_if_builder.changed.connect(insp.set_entry_show_if)
|
||||
insp._content.add_child(InspectorKit.field("Offer only if", insp.show_if_builder))
|
||||
insp._content.add_child(InspectorKit.field("Offer only if" if pick else "Can come up only if", insp.show_if_builder))
|
||||
if pick and not (t.is_dynamic() and t.entries.find(e) == 0):
|
||||
insp._content.add_child(InspectorKit.field("Costs", cost_row(insp, t, e)))
|
||||
|
||||
if t.kind == RollTable.KIND_ROUTER:
|
||||
|
|
|
|||
|
|
@ -148,7 +148,8 @@ func _on_click(at: Vector2, button: int) -> void:
|
|||
return
|
||||
if meta["kind"] == "card":
|
||||
if get_column_at_position(at) == COL_ROLL:
|
||||
m.rolling.start_roll(str(meta["id"]))
|
||||
# The list has no spread to animate on, so it shows the result at once.
|
||||
m.rolling.start_roll(str(meta["id"]), true)
|
||||
elif m.mode == Main.Mode.BUILD:
|
||||
m.select_card(str(meta["id"]))
|
||||
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ func make_row(e: TableEntry, index: int, build: bool, ranged: bool, numw: float)
|
|||
## entry's effects ("Luck −1"). Used in Play and Build alike.
|
||||
func add_rule_chips(col: VBoxContainer, e: TableEntry) -> void:
|
||||
var plain := card.plain
|
||||
if _is_pick() and e.show_if.strip_edges() != "":
|
||||
if (_is_pick() or card.table.kind == RollTable.KIND_ROLL) and e.show_if.strip_edges() != "":
|
||||
var bad := Expr.check(TemplateKit.probe(e.show_if.strip_edges())) != ""
|
||||
var si := Style.make_label(RulesView.show_if_line(e, card.main.data, plain), Style.body_bold(true), 12, Style.DANGER_INK if bad else Style.TRIM_DARK)
|
||||
si.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
|
|
|
|||
Loading…
Reference in a new issue