Threads: No repeats (every roll of a repeated thread gives a different result)

With Let me choose, that's "roll three different ones and pick one".
The thread label says "no repeats"; saved in the file as "distinct".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
RobinFiredrake 2026-11-14 14:11:22 -06:00
parent 6a460d17eb
commit 3f13bc181c
8 changed files with 68 additions and 3 deletions

View file

@ -61,6 +61,8 @@ static func pipe(entry: TableEntry, target_id: String, board: TowerBoard) -> Str
parts.append("×" + Describe._expr(ce, L))
elif entry.count_for(target_id) != 1:
parts.append("×%d" % entry.count_for(target_id))
if entry.pipe_distinct.has(target_id) and (ce != "" or entry.count_for(target_id) != 1):
parts.append("no repeats")
if entry.dice_for(target_id) != "":
parts.append("with " + entry.dice_for(target_id))
var again := entry.reroll_for(target_id)

View file

@ -149,6 +149,8 @@ static func queue_pipes(node: Dictionary, ctx: RollContext, stack: Array, depth:
frame["dice"] = entry.dice_for(target)
if not entry.reroll_for(target).is_empty():
frame["reroll"] = entry.reroll_for(target)
if entry.pipe_distinct.has(target) and int(item["count"]) > 1:
frame["distinct_from"] = (node["children"] as Array).size()
var mode := entry.combine_for(target)
if mode != "all" and int(item["count"]) > 1:
# Runs after every repeat: combines them (RollCombine).
@ -192,6 +194,15 @@ static func do_pipe(board: TowerBoard, frame: Dictionary, stack: Array) -> void:
for key in ["with", "dice", "reroll"]:
if frame.has(key):
roll_frame[key] = frame[key]
if frame.has("distinct_from"):
# No repeats: this roll also skips every result this thread already gave.
var skip: Array = (frame.get("reroll", []) as Array).duplicate()
var children: Array = (frame["node"] as Dictionary)["children"]
for i in range(int(frame["distinct_from"]), children.size()):
var child: Dictionary = children[i]
if child.get("entry") is TableEntry and (child["table"] as RollTable).id == str(frame["to"]) and not skip.has((child["entry"] as TableEntry).id):
skip.append((child["entry"] as TableEntry).id)
roll_frame["reroll"] = skip
if frame.get("no_follow", false):
roll_frame["no_follow"] = true
stack.append(roll_frame)

View file

@ -45,6 +45,9 @@ var pipe_combine: Dictionary = {}
## target table id -> true: the roll waits before following this thread until
## the player continues (Roller.OP_PAUSE). Missing = no pause.
var pipe_pause: Dictionary = {}
## target table id -> true: when the thread rolls its card more than once,
## each roll skips results already rolled (no repeats). Missing = repeats ok.
var pipe_distinct: Dictionary = {}
## target table id -> dice to roll the target with instead of its own
## ("3d10+70"; a ranged target only). Missing = the card's own dice.
var pipe_dice: Dictionary = {}
@ -273,6 +276,7 @@ func remove_pipe(target: String) -> void:
pipe_color.erase(target)
pipe_combine.erase(target)
pipe_pause.erase(target)
pipe_distinct.erase(target)
pipe_dice.erase(target)
pipe_reroll.erase(target)

View file

@ -51,10 +51,11 @@ static func _pipe_to_value(entry: TableEntry, target: String) -> Variant:
var color := str(entry.pipe_color.get(target, ""))
var combine := entry.combine_for(target)
var paused := entry.pipe_pause.has(target)
var distinct := entry.pipe_distinct.has(target)
var dice := entry.dice_for(target)
var reroll := entry.reroll_for(target)
if expr == "" and count == 1 and save_as == "" and condition == "" and not otherwise \
and with_values == null and color == "" and combine == "all" and not paused \
and with_values == null and color == "" and combine == "all" and not paused and not distinct \
and dice == "" and reroll.is_empty():
return target
var options := {"table": target}
@ -76,6 +77,8 @@ static func _pipe_to_value(entry: TableEntry, target: String) -> Variant:
options["combine"] = combine
if paused:
options["pause"] = true
if distinct:
options["distinct"] = true
if dice != "":
options["dice"] = dice
if not reroll.is_empty():
@ -158,6 +161,8 @@ static func _read_pipe(entry: TableEntry, pipe: Dictionary) -> void:
entry.pipe_combine[target] = str(pipe["combine"])
if bool(pipe.get("pause", false)):
entry.pipe_pause[target] = true
if bool(pipe.get("distinct", false)):
entry.pipe_distinct[target] = true
entry.set_pipe_dice(target, str(pipe.get("dice", "")) if pipe.get("dice") != null else "")
if pipe.get("reroll") is Array:
entry.set_pipe_reroll(target, pipe["reroll"])

View file

@ -228,7 +228,8 @@ The [b]Book[/b] holds [b]Pages[/b]: results you want to use on more than one tab
# Rolling more than once
- A thread can roll its card several times ([b]Rolls 3 times[/b] in the thread's inspector). Then choose what happens: [b]Keep every roll[/b], [b]Add them together[/b], [b]Keep the highest[/b], [b]Keep the lowest[/b] or [b]Let me choose[/b]. Rolls that aren't kept are faded in the tray, and don't follow their own threads.
- [b]Roll several times…[/b] on a card's menu rolls its whole chain as many times as you like (five villagers, ten treasures) and shows every result together, ready to copy.
- Tick [b]No repeats[/b] so every roll gives a different result (a result that already came up is rolled again). With [b]Let me choose[/b], that's "roll three different ones and pick one".
- [b]Roll several times…[/b] on a card's menu rolls its whole chain as many times as you like (five villagers, ten treasures) and shows every result together, ready to copy. Each roll also appears in the tray's [b]Earlier[/b] list.
[demo]repeats[/demo]
# Pausing a roll

View file

@ -183,7 +183,7 @@ static func _canon_entry(ev: Variant) -> Dictionary:
var wv := _canon_with(p.get("with"))
if not wv.is_empty():
np["with"] = wv
_keep(p, np, ["color", "combine", "pause", "dice", "reroll"])
_keep(p, np, ["color", "combine", "pause", "dice", "reroll", "distinct"])
pipes.append(np)
if not pipes.is_empty():
e["pipes"] = pipes

View file

@ -7,6 +7,7 @@ extends TestBase
func _init() -> void:
_test_combine()
_test_no_repeats()
await _test_choose()
await _test_pause()
await _test_costs()
@ -39,6 +40,30 @@ func _kids(tree: Dictionary, tid: String) -> Array:
return (tree["children"] as Array).filter(func(k: Dictionary) -> bool: return (k["table"] as RollTable).id == tid)
## "No repeats": three rolls of a six-result card all differ, and with as
## many rolls as results every result comes up once; saved and loaded.
func _test_no_repeats() -> void:
for seed_value in 30:
var b := _board("all")
var e: TableEntry = b.get_table("start").entries[0]
e.pipe_distinct["gold"] = true
var rng := RandomNumberGenerator.new()
rng.seed = seed_value
var ids := {}
for k: Dictionary in _kids(Roller.roll(b, "start", rng), "gold"):
ids[(k["entry"] as TableEntry).id] = true
_check(ids.size() == 3, "no repeats: three different results (seed %d)" % seed_value)
var six := _board("all")
var six_e: TableEntry = six.get_table("start").entries[0]
six_e.pipe_distinct["gold"] = true
six_e.add_pipe("gold", 6, "loot")
var all_ids := {}
for k: Dictionary in _kids(Roller.roll(six, "start", RandomNumberGenerator.new()), "gold"):
all_ids[(k["entry"] as TableEntry).id] = true
_eq(all_ids.size(), 6, "six rolls of six results give each one once")
_check(TableEntry.from_dict(six_e.to_dict()).pipe_distinct.has("gold"), "No repeats is saved with the thread")
func _test_combine() -> void:
var rng := RandomNumberGenerator.new()
rng.seed = 7

View file

@ -62,6 +62,17 @@ static func set_pause(insp: Inspector, to: String, on: bool) -> void:
insp.wrote(insp.selected_table())
static func set_distinct(insp: Inspector, to: String, on: bool) -> void:
var e := insp.selected_entry()
if e == null or e.pipe_distinct.has(to) == on:
return
if on:
e.pipe_distinct[to] = true
else:
e.pipe_distinct.erase(to)
insp.wrote(insp.selected_table())
static func set_combine(insp: Inspector, to: String, mode: String) -> void:
var e := insp.selected_entry()
if e == null or e.combine_for(to) == mode:
@ -228,6 +239,12 @@ static func box(insp: Inspector, t: RollTable, e: TableEntry, to: String) -> Con
then.item_selected.connect(func(i: int) -> void: set_combine(insp, to, RollCombine.MODES[i]))
cr.add_child(then)
parts["combine"] = then
var distinct := InspectorKit.check_box("No repeats", e.pipe_distinct.has(to))
distinct.tooltip_text = "When it rolls more than once, a result that already came up is rolled again, so every roll is different"
InspectorKit.tag(distinct, "pipe.%s.distinct" % to)
distinct.toggled.connect(func(on: bool) -> void: set_distinct(insp, to, on))
parts["distinct"] = distinct
cr.add_child(distinct)
var sr := InspectorKit.hbox(6)
sr.add_child(InspectorKit.word("Saves as"))
var save := InspectorKit.line(e.save_for(to), "nothing (or a name)")