Skip to content

Instantly share code, notes, and snippets.

@amirrajan
Created January 15, 2025 14:01
Show Gist options
  • Save amirrajan/36f7e01838aaa1c298b00f0dd8745d16 to your computer and use it in GitHub Desktop.
Save amirrajan/36f7e01838aaa1c298b00f0dd8745d16 to your computer and use it in GitHub Desktop.
Legion Story Progression Concept
class Probe
def queue_story!(predicate: nil, entries:, completion_action: nil, completion_checkpoint:, completion: nil)
raise "Either completion_action or completion must be provided." if !completion_action && !completion
return if @action == :story
return if @current_story_items.length > 0
return if checkpoint_reached?(completion_checkpoint)
should_queue = if predicate.is_a? Proc
predicate.call
elsif predicate.is_a? FalseClass
false
elsif predicate.is_a? TrueClass
true
elsif predicate.is_a? NilClass
!checkpoint_reached?(completion_checkpoint)
else
raise "Unknown predicate type: #{predicate.class}"
end
return if !should_queue
puts "queueing story #{completion_checkpoint}"
@current_story_items = entries.map do |entry|
{ text: entry }
end
if completion
@current_story_items.last[:callback] = lambda do
checkpoint! completion_checkpoint
completion.call
end
else
@current_story_items.last[:callback] = lambda do
checkpoint! completion_checkpoint
action! completion_action
end
end
action! :story
end
def tick_story
@current_story_items ||= []
return if @action == :story
return if @current_story_items.length > 0
return if !Kernel.tick_count.zmod?(30)
# beginning
queue_story!(predicate: checkpoint_reached?(:beginning),
entries: [
"Mission Control, I've made it to low Earth orbit. Do you read?",
"Dammit. Looks like my COMMS Module got damaged during launch.",
"I need to manufacture another one and re-establish contact with Earth.",
],
completion_action: :main_menu,
completion_checkpoint: :comms_module_down)
# let player know that they should build a construction module
queue_story!(predicate: !has_module?(:construction_module) && current_metal >= 100,
entries: ["This is going to take forever. Building the Construction Module and Metal Harvesters will help."],
completion_action: :main_menu,
completion_checkpoint: :help_construction_module)
# let player know that they should build a metal harvester
queue_story!(predicate: has_module?(:construction_module) && current_metal_harvesters.length == 0 && current_metal >= 100 && !has_module?(:ftl_module),
entries: ["Alrighty, I have enough metal to build a Metal Harvester. Let's build one of these things."],
completion_action: :construction_module_menu,
completion_checkpoint: :help_metal_harvester)
# # let player know that they should build a comms module
queue_story!(predicate: !has_module?(:comms_module) && can_afford?(comms_module_cost),
entries: ["Finally have enough minerals for a COMMS Module..."],
completion_action: :main_menu,
completion_checkpoint: :comms_module_reminder)
queue_story!(predicate: has_module?(:comms_module) && checkpoint_reached?(:ping_earth_reminder) && orbiting_body.id == :earth && checkpoint_reached?(:spoon_intro),
entries: ["SPOON: Hey Sasha! Use the Ping function in the COMMS Module to talk to Earth."],
completion_action: :comms_module_menu,
completion_checkpoint: :earth_first_contact)
# earth wants to talk about progress to ftl module
queue_story!(predicate: has_module?(:comms_module) &&
!has_module?(:ftl_module) &&
current_metal >= 2000,
entries: ["Notification: Earth is requesting contact.",
"Sigh... guess I should go see what they want..."],
completion_checkpoint: :earth_ftl_progress_update,
completion: -> do
@earth_wants_to_talk = true
move_to celestial_bodies[:earth]
end)
# reminder to build FTL
queue_story!(predicate: !has_module?(:ftl_module) && can_afford?(ftl_module_cost),
entries: ["Finally have enough for the FTL Module.", "I should definitely maybe build it."],
completion_action: :main_menu,
completion_checkpoint: :ftl_module_reminder)
# enough fuel to reach epsilon eridani/tau ceti
queue_story!(predicate: @fuel >= 1 && @fuel_capacity == 10 && current_fuel_refineries.length > 0,
entries: [
"Notification: Earth is requesting contact.",
"Now what do they want?"
],
completion_checkpoint: :fuel_progress_update,
completion: -> do
@earth_wants_to_talk = true
move_to celestial_bodies[:earth]
end)
queue_story!(predicate: @fuel >= 12,
entries: [
"Notification: Earth is requesting contact.",
],
completion_checkpoint: :choose_epsilon_eridani_or_tau_ceti,
completion: -> do
@earth_wants_to_talk = true
move_to celestial_bodies[:earth]
end)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment