Relationship System

v1.1.0

Example Workflows

Production-ready examples for common relationship system implementations.

Production-ready implementation examples showing how to combine the Relationship System's features for common gameplay scenarios.

RPG Shop System

Dynamic pricing based on merchant reputation, with festival modifiers and reputation caps.

Setup:
1. Create RelationshipDefinition: "Merchant Reputation" (-100 to +100)
   Levels: Hostile(-50), Neutral(0), Friendly(50), Trusted(75)
   Decay: Asymmetric mode (slow gain decay, fast loss decay)
   History: Enabled (for "Why this price?" tooltips)

2. Merchant CharacterRelationship + Player CharacterRelationship

GC2 Triggers:
├─ On Quest Complete:
│  └─ Modify Relationship (+25, Definition: Merchant Reputation, Source: "Quest Reward")
│
├─ On Caught Stealing:
│  └─ Modify Relationship (-40, Definition: Merchant Reputation, Source: "Theft")
│
├─ On Shop Open:
│  └─ Condition: Relationship At Level
│     ├─ Hostile → "Leave my shop!" (refuse service)
│     ├─ Neutral → Standard prices (×1.0)
│     ├─ Friendly → 20% discount (×0.8)
│     └─ Trusted → 40% discount (×0.6)
│
└─ On Festival Event:
   └─ Add Relationship Modifier
      ├─ Type: Percentage (×1.5)
      ├─ Target: GainOnly
      ├─ Duration: 300 seconds
      └─ Source: "Harvest Festival"

Faction Wars & Diplomacy

Hierarchical faction relationships with diplomacy states and configurable inheritance.

Setup:
1. Create Factions:
   Kingdom (root)
   ├─ Royal Guards (inheritanceRate: 0.8, propagate: OnChange)
   └─ Merchants Guild (inheritanceRate: 0.3, propagate: OnLevelChange)
   
   Bandit Clan (root)
   └─ Smugglers (inheritanceRate: 0.5, dynamicInheritance: true)

2. Initial Diplomacy:
   Kingdom ↔ Bandit Clan: Set Diplomacy State → War

GC2 Triggers:
├─ On Attack Guard:
│  └─ Broadcast To Faction
│     ├─ Faction: Royal Guards
│     ├─ Target: Player
│     ├─ Change: -75
│     └─ Propagates to Kingdom at 80%, then to Merchants Guild at 30%
│
├─ On Peace Treaty Quest:
│  └─ Transition Diplomacy State
│     ├─ Faction A: Kingdom
│     ├─ Faction B: Bandit Clan
│     └─ New State: Ceasefire (blocks negative changes)
│
└─ On Alliance Quest:
   └─ Set Diplomacy State → Alliance
      └─ Positive modifier applied to all relationship gains

Quest Unlocking with Caps

Progressive reputation gates using caps and multi-dimensional relationships.

Setup:
1. Two definitions between Player and Guild Master:
   "Guild Reputation" (0-100, levels: Outsider/Member/Veteran/Master)
   "Personal Trust" (-50 to +50, asymmetric — Guild Master's opinion matters)

2. Reputation Cap: Guild Reputation capped at 25 until "Initiation" quest

GC2 Triggers:
├─ Game Start:
│  └─ Set Relationship Cap
│     ├─ Cap ID: "initiation_gate"
│     ├─ Max Value: 25
│     └─ Fires OnCapReached when player hits 25
│
├─ On Initiation Quest Complete:
│  └─ Remove Relationship Cap ("initiation_gate")
│     └─ Reputation can now grow to 100
│
├─ Condition: Guild Reputation at "Veteran" (75+)
│  └─ Unlock: Secret Mission quests
│
└─ Condition: Personal Trust > 30 (directional: Guild Master → Player)
   └─ Unlock: Romance/friendship dialogue options

Companion System

Asymmetric trust building with history tracking for dialogue references.

Setup:
1. Asymmetric Definition: "Trust" (isSymmetric: false, enableHistory: true)
   Player → Companion: how much the player invests
   Companion → Player: companion's actual opinion (AI-driven)

2. Companion CharacterRelationship with Auto-Register

GC2 Triggers:
├─ On Good Dialogue Choice:
│  └─ Set Opinion (directional)
│     ├─ From: Companion → Player
│     ├─ Change: +15
│     └─ Source: "Supported companion's plan"
│
├─ On Evil Action:
│  └─ Set Opinion (directional)
│     ├─ From: Companion → Player
│     ├─ Change: -25
│     └─ Source: "Betrayed village trust"
│
├─ Companion AI Check:
│  └─ Condition: Opinion Above (Companion → Player > 60)
│     └─ Unlock: Loyalty bonus in combat
│
└─ Dialogue System:
   └─ Retrieve GetRecentHistory for dialogue:
      "You helped me at the bridge. I won't forget that."

Dynamic Guilds (Runtime Factions)

Players create guilds at runtime that integrate with the full faction system.

GC2 Triggers:
├─ On "Create Guild" Button:
│  └─ Create Runtime Faction
│     ├─ Name: (from player input)
│     ├─ Parent: Adventurers Association (SO faction)
│     ├─ Inheritance Rate: 0.5
│     └─ Dynamic Inheritance: true
│
├─ On "Invite Member":
│  └─ Add To Faction
│     ├─ Entity: Invited Player/NPC
│     └─ Faction: (runtime guild)
│
├─ On Guild Quest Complete:
│  └─ Modify Relationship
│     ├─ Entity A: Guild (runtime faction ID)
│     ├─ Entity B: Merchants Guild (SO faction)
│     ├─ Change: +30
│     └─ Inherits 50% to Adventurers Association
│
├─ Condition: Is Runtime Faction
│  └─ Show "Dissolve Guild" option (only for player-created)
│
└─ On "Dissolve Guild":
   └─ Dissolve Runtime Faction
      └─ Members lose guild membership, entity unregistered
      └─ Fires OnRuntimeFactionDissolved event
Runtime factions are fully persisted by the Remember component. On save, their complete state (name, hierarchy, members, relationships) is serialized. On load, they are restored with all connections intact.