| name | three-kingdoms-duel-system |
| description | Implements Three Kingdoms 11 style duel system with decision-making mechanics. Invoke when user wants to add or modify duel functionality in strategy games. |
Three Kingdoms 11 Duel System
Overview
This skill implements a Three Kingdoms 11 style duel system for strategy games, featuring turn-based combat with decision-making mechanics. The system includes core duel logic, decision options with counter relationships, and event-driven architecture.
Core Components
1. DuelSystem.cs
The main class responsible for handling duel logic:
- Properties: AttackerTroop, DefenderTroop, Attacker, Defender, health values, duel state
- Methods:
StartDuel(): Initiates a duel if conditions are met
ProcessDuelTurn(): Processes one turn of duel combat
Attack(): Handles attack logic with decision counter relationships
CalculateDamage(): Calculates damage based on attributes and decisions
HandleDuelResult(): Processes the outcome of the duel
2. DuelManager.cs
Manages the duel process:
- Methods:
StartDuel(): Starts a new duel between two troops
ProcessDuel(): Processes the entire duel until completion
GetCurrentDuel(): Gets the current active duel
IsDueling(): Checks if a duel is in progress
3. DuelState.cs
Defines the state of the duel:
None: No duel in progress
Started: Duel has started but not yet in progress
InProgress: Duel is ongoing
Ended: Duel has completed
4. Decision System
Implements decision-making mechanics:
5. Event System
Provides event hooks for duel-related events:
OnDuelStart: Triggered when a duel begins
OnDuelEnd: Triggered when a duel completes
OnDuelDecisionRequired: Triggered when decisions are needed
OnPersonCaptured: Triggered when a general is captured
Usage
Starting a Duel
public bool StartDuel(Troop targetTroop)
{
if (targetTroop == null || !IsEnemy(targetTroop))
{
return false;
}
return DuelManager.Instance.StartDuel(this, targetTroop);
}
Processing a Duel
DuelResult result = DuelManager.Instance.ProcessDuel();
Handling Duel Events
GameEvent.OnDuelStart += OnDuelStart;
GameEvent.OnDuelEnd += OnDuelEnd;
GameEvent.OnDuelDecisionRequired += OnDuelDecisionRequired;
private void OnDuelStart(DuelSystem duel)
{
}
private void OnDuelEnd(DuelSystem duel, DuelResult result)
{
}
private void OnDuelDecisionRequired(DuelSystem duel)
{
}
Features
- Turn-based Combat: Each turn consists of attacks and counter-attacks
- Decision Mechanics: Every 3 turns, players choose from Attack, Defend, or Skill
- Counter Relationships: Decisions have rock-paper-scissors style counter relationships
- Attribute-based Calculations: Damage and success rates based on general attributes
- Event-driven Architecture: Comprehensive event system for duel-related events
- Default Decisions: AI-controlled generals use attribute-based default decisions
- Capture Mechanics: Winners can capture enemy generals
- Morale Effects: Duel outcomes affect troop morale
Implementation Notes
- Requirements: Troop and Person classes with appropriate attributes
- Integration: Add StartDuel method to Troop class
- UI: Implement decision selection UI for player-controlled duels
- Balance: Adjust damage calculations and counter factors as needed
Example Scenario
- Initiation: Player selects an enemy troop and chooses "Duel"
- Start: Duel begins, OnDuelStart event is triggered
- Turn 1: Automatic attacks without decisions
- Turn 3: OnDuelDecisionRequired event is triggered, player chooses Attack
- Turn 4-6: Combat uses the chosen decision
- Resolution: Duel ends, OnDuelEnd event is triggered with result
- Effects: Morale changes, potential capture, and troop elimination
This implementation provides a faithful recreation of Three Kingdoms 11's duel system, adding depth and strategy to combat encounters.