Skip to content

Commit

Permalink
Implement isApplicable for Approaches
Browse files Browse the repository at this point in the history
Approach in writer’s input now accepts `PREREQUISITES:`. This allows us to let the player bypass things they’ve already done.
  • Loading branch information
filiph committed Aug 30, 2019
1 parent 03fd817 commit 139d1e8
Show file tree
Hide file tree
Showing 13 changed files with 245 additions and 57 deletions.
8 changes: 7 additions & 1 deletion edgehead/assets/text/Knights/1_bleeds/000_bleeds_main.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ COMMAND: Go >> outside
DESCRIPTION: [[We]] walk out into the muddy street.

// ---
APPROACH: $bleeds_main FROM $goblin_skirmish_main
APPROACH: $bleeds_main FROM $goblin_skirmish_sneak
COMMAND: Go >> to The Bleeds
DESCRIPTION: [[We]] sneak through the bushes and emerge back in The Bleeds.

// ---
APPROACH: $bleeds_main FROM $goblin_skirmish_main
COMMAND: Go >> to The Bleeds
DESCRIPTION: [[We]] walk back to The Bleeds.


// ---
ROOM: $bleeds_main

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ _"I seek treasure."_

"Ahh!" The man leans back, resting his back against the wall of his house. "A terrible idea."

[[CODE]]
$(c).learnAbout(kbBlindGuide);
[[/CODE]]


// ---
ACTION: $bleeds_blind_guide_terrible_idea
Expand All @@ -43,7 +47,7 @@ FOR_LOCATION: $bleeds_main
PREREQUISITES:
w.actionNeverUsed(name)
&&
w.actionHasBeenPerformed("bleeds_blind_guide_greet")
$(c).hasLearnedAbout(kbBlindGuide)

COMPLETE_SUCCESS_PROBABILITY: 100%

Expand Down Expand Up @@ -88,6 +92,8 @@ FOR_LOCATION: $bleeds_main
PREREQUISITES:
w.actionNeverUsed(name)
&&
$(c).hasLearnedAbout(kbBlindGuide)
&&
$(c).hasHeardAbout(kbGoblinsNearBleeds)

COMPLETE_SUCCESS_PROBABILITY: 100%
Expand Down
4 changes: 4 additions & 0 deletions edgehead/assets/text/Knights/1_bleeds/050_bleeds_trader.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ assert($(c).inRoomWith(leroyId));

"They are to the west. It doesn't seem like there is a lot of them. We thought the Knights would get rid of them for sure."

[[CODE]]
$(c).learnAbout(kbGoblinsNearBleeds);
[[/CODE]]

"But the Knights are leaving." The trader looks at me for reaction and when he doesn't get any, he turns back to his son. "The Knights are leaving," he repeats.

[[CODE]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
APPROACH: $goblin_skirmish_patrol FROM $bleeds_main
COMMAND: Go >> to the west
DESCRIPTION: N/A
PREREQUISITES:
$(c).hasLearnedAbout(kbGoblinsNearBleeds)
&&
!$(c).playerHasVisited("goblin_skirmish_patrol")

// ---
ROOM: $goblin_skirmish_patrol
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ---
APPROACH: $goblin_skirmish_sneak FROM $goblin_skirmish_patrol
COMMAND: Go >> towards the goblin outpost
DESCRIPTION: N/A

// ---
APPROACH: $goblin_skirmish_sneak FROM $bleeds_main
COMMAND: Go >> towards the goblin outpost
DESCRIPTION: N/A
PREREQUISITES:
$(c).playerHasVisited("goblin_skirmish_sneak")

// ---
ROOM: $goblin_skirmish_sneak

FIRST_DESCRIPTION:
[[We]] sneak around. It's only 3 goblins. They are speaking loudly.

DESCRIPTION:
The goblins are still here.
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
// ---
APPROACH: $goblin_skirmish_main FROM $goblin_skirmish_patrol
COMMAND: Go >> towards the outpost
APPROACH: $goblin_skirmish_main FROM $bleeds_main
COMMAND: Go >> to the goblin outpost
DESCRIPTION: N/A
PREREQUISITES:
$(c).hasHappened(evGoblinCampCleared)

// ---
APPROACH: $goblin_skirmish_main FROM $goblin_skirmish_sneak
COMMAND: Go >> attack the camp
DESCRIPTION: N/A
PREREQUISITES:
!$(c).hasHappened(evGoblinCampCleared)

// ---
ROOM: $goblin_skirmish_main

FIRST_DESCRIPTION:
[[We]] sneak around. It's only 3 goblins. They are speaking loudly.
TODO -- an actual battle with the goblins.

Assume you won.

[[CODE]]
w.recordCustom(evGoblinCampCleared);
[[/CODE]]

DESCRIPTION:
The goblins are still here.
The goblin camp is deserted.

[[CODE]]
w.recordCustom(evGoblinCampCleared);
[[/CODE]]
4 changes: 1 addition & 3 deletions edgehead/lib/edgehead_director.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ final _leroyQuits = Rule(_id++, 2, false, (ApplicabilityContext c) {
final leroy = c.world.getActorById(leroyId);
if (leroy.npc.followingActorId != playerId) return false;
assert($(c).inRoomWith(leroyId));
return c.world.customHistory
.query(name: "cleared_goblin_skirmish")
.hasHappened;
return c.world.customHistory.query(name: evGoblinCampCleared).hasHappened;
}, (ActionContext c) {
final WorldStateBuilder w = c.outputWorld;
final Storyline s = c.outputStoryline;
Expand Down
2 changes: 2 additions & 0 deletions edgehead/lib/edgehead_ids.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const evDirectorNoRuleApplicable = "evDirectorNoRuleApplicable";

const evGoblinCampCleared = "evGoblinCampCleared";

const kbBlindGuide = "kbBlindGuide";

const kbGoblinSmoke = "kbGoblinSmoke";

const kbGoblinsNearBleeds = "kbGoblinsNearBleeds";
Expand Down
10 changes: 9 additions & 1 deletion edgehead/lib/fractal_stories/room_approach.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ class Approach {
/// supposed to see it. They will be automatically transported.
final bool isImplicit;

const Approach(this.from, this.to, this.command, this.description)
/// A callback defining whether anyone can take the approach, given
/// the current state of the world.
///
/// This can (and often will) be `null`. That just means the approach
/// is always applicable.
final bool Function(ApplicabilityContext) isApplicable;

const Approach(this.from, this.to, this.command, this.description,
{this.isApplicable})
: isImplicit = command == '<implicit>',
assert(from != null),
assert(to != null),
Expand Down
5 changes: 5 additions & 0 deletions edgehead/lib/src/room_roaming/actions/take_approach.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ class TakeApproachAction extends ApproachAction {
// Don't allow exit taking when monsters in this room are still alive.
return false;
}

if (approach.isApplicable != null) {
return approach.isApplicable(c);
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class TakeImplicitApproachAction extends TakeApproachAction {
return false;
}

if (approach.isApplicable != null) {
return approach.isApplicable(c);
}

return true;
}
}
Loading

0 comments on commit 139d1e8

Please sign in to comment.