Introduction

The Village Framework uses opportunity and choices to enable and impact different elements of the system. An opportunity can be anything with one choice or more, that the player can interact with. (Most common example would be a dialogue with an npc)

Opportunities

Opportunities are the main interactive element of the village. They are generated each day per available spawnpoints. To see the rules on the generation of opportunities, check Village Generation

Each opportunity has a list of Choices, and a Villager. When a choice is made, it can enable or disable different elements of the village framework, and apply different effects.

Opportunity Flow

flowchart LR
  open[Open Opportunity] --> select[Select a Choice]
  select --> mark[Mark choice as made]
  mark --> applyOpp[Enable/Disable opportunities]
  applyOpp --> applyEffect[Apply effects from that choice on Village]
  applyEffect --> enable[Enable/Disable other choice impacted items]

Opening an opportunity

You can open an opportunity by calling it on the OpportunityManager (see Village Components for how to get a ref to it) (OpportunityManager).OpenOpportunity(opportuntiySlot).

It will mark this slot as opened.

<aside> πŸ“Œ

If a slot that has been opened is saved and serialized, so you can use it to see if a player already saw an opportunity or not that day.

</aside>

Then it will raise the static event OnOpenOpp(opportunity). This event can be used to display UI.

Selecting a choice

<aside> πŸ“Œ

You can use the function (OpportunityManager).PreviewChoice(choice) to raise the event OnPreviewChoice(choice), that will add a preview to the stats.

</aside>

When the user makes a choice, call (OpportunityManager).SelectChoiceForCurrentOpp(choice).

This will set the choice for the opportunitySlot currently in use, and register the choice as made at this date.

Then it will apply enablings and effects from that choice.


Choices

Choices in the Village Framework are different possible answers to an opportunity. They have 2 in system uses :

Choice Effects

Effects are a list of behaviors and stats to apply to the Village. An instance of a class ChoiceEffect is based on village components when a choice is made, to store any randomized value result.

You can see a full list of explication on Effect Impact , for the basic effects and how to extend or create new effects.

Choice Enabling / Disabling

A choice can either enable or disable database items that are impacted. All choices made by the player are stored, with the last date at which they were made. This lets us replay the enabling or disabling later on.

How enabling works

Databases where the items would be enabled by choice must have those four fields:

ChoiceCondition is an enum with those values:

<aside> πŸ“Œ

If a choice can enable AND disable an item, the enable condition takes the precedent.

</aside>

When the database script is created, it must inherit from DatabaseItemChoiceImpacted, which contains those field.

Then, they are stored at runtime in different ChoiceImpactedManagers, each containing a list of instances of those items, with their enabled state.

When a choice is made, it raises the event OnChoiceSelected(ChoiceEffect). The manager listens to this event, and will try to apply the enabling from that choice.

Manual application

Sometimes, you need to apply choices later on, after they are already made.

This happens when you advance a new chapter, or on a new day, when destinations are loaded.

For this, ChoiceImpactedManager has the function ReApplyEnabling(). This function will look at all the choices made, and check if at any point, an item should have been disabled or enabled.

If both event happened, it will only look at the latest choice that impacted it that was made.

Impacted components

By default, some components are impacted by choices, but have some different behaviours:

Adding new impacted components

To add new impacted components, follow those steps: