Skip to content

Commit

Permalink
Implement IS_IMMEDIATE
Browse files Browse the repository at this point in the history
This is an escape hatch for actions that initiate combat. They should not take any time, in order not to mess with fighting order.
  • Loading branch information
filiph committed Oct 9, 2020
1 parent e3077c3 commit ca0b550
Show file tree
Hide file tree
Showing 11 changed files with 293 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ c.hasHappened(evDargLeftCrowdsource)

COMMAND: Darg >> Attack

IS_IMMEDIATE: $TRUE

COMPLETE_SUCCESS_DESCRIPTION:
[We] approach Darg's tent. Darg spots me and looks surprised at first, then amused.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ FOR_LOCATION: $outlook

COMMAND: Hawkman >> Approach

IS_IMMEDIATE: $TRUE

INK:
The hawkman gives me a condescending look.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ w.actionHasBeenPerformed('crowdsource_listen')

COMMAND: Orcs >> Attack

IS_IMMEDIATE: $TRUE

COMPLETE_SUCCESS_DESCRIPTION:
[We] step from behind the columns and approach the two orcs.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ FOR_LOCATION: $conet

COMMAND: Kobold >> Attack

IS_IMMEDIATE: $TRUE

COMPLETE_SUCCESS_DESCRIPTION:
[We] step out of hiding. The kobold stops turning the wheel, briefly surprised. But then he jumps to the side and picks a big black wrench from a brown bag on the floor.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ COMMAND: Jailer >> Attack

FOR_LOCATION: $smithy

IS_IMMEDIATE: $TRUE

COMPLETE_SUCCESS_DESCRIPTION:
I drop down next to Sarn. He looks surprised but there is no recognition in his eyes.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ ACTION: $goblin_camp_attack
COMMAND: Goblins >> Attack
FOR_LOCATION: $goblin_skirmish_main

IS_IMMEDIATE: $TRUE

COMPLETE_SUCCESS_DESCRIPTION:
[[RULESET]]
[[RULE]]
Expand Down
19 changes: 14 additions & 5 deletions edgehead/lib/fractal_stories/action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -513,12 +513,21 @@ class Performance<T> {
// Move world time to when the turn happens.
output.time = turn.time;

// Mark actor busy after performing their action.
if (action.isProactive) {
// Mark actor busy after performing their action.
final recoveringUntil =
turn.time.add(action.getRecoveryDuration(context, object));
output.updateActorById(
turn.actor.id, (b) => b.recoveringUntil = recoveringUntil);
final recovery = action.getRecoveryDuration(context, object);
// First, check whether the action took any time. Some actions, such
// as initiating an attack, are pro-active, but don't take any time.
// In order to preserve fighting order, we should not change
// the attacker's `recoveringUntil`. Thus, we check if recovery
// is in fact more than zero.
if (recovery > Duration.zero) {
// The action was proactive and did take some time. Update the actor's
// [Actor.recoveringUntil].
final recoveringUntil = turn.time.add(recovery);
output.updateActorById(
turn.actor.id, (b) => b.recoveringUntil = recoveringUntil);
}
}

// Perform any [Situation.onAfterAction]s.
Expand Down
21 changes: 21 additions & 0 deletions edgehead/lib/fractal_stories/writer_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ abstract class RoamingAction extends Action<Nothing> {

@override
final bool isImplicit = false;

/// Some roaming actions can be immediate. This means that they will not
/// affect the performer's [Actor.recoveringUntil].
///
/// This is useful for things like initiating an attack, where we don't want
/// the player to go last just because she is "recovering" from performing
/// the "initiate attack" action.
bool get isImmediate;

/// [RoamingAction] overrides this method to accommodate [isImmediate].
@override
Duration getRecoveryDuration(ApplicabilityContext context, Nothing object) {
if (isImmediate) {
return Duration.zero;
}

return super.getRecoveryDuration(context, object);
}
}

/// This is a simple actions that, once taken, always succeed.
Expand Down Expand Up @@ -66,6 +84,9 @@ class SimpleAction extends RoamingAction {
@override
bool get isAggressive => false;

@override
bool get isImmediate => false;

@override
bool get rerollable => false;

Expand Down
Loading

0 comments on commit ca0b550

Please sign in to comment.