| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- // This file contains copy-paste examples for setting up the combat system.
- // Replace YOUR_NAMESPACE with your actual namespace.
- using UnityEngine;
- using MazeGen;
- namespace MazeGen
- {
- // EXAMPLE 1: Creating a weapon in the Unity Editor
- // HOW TO USE:
- // 1. Right-click in the Project window (Assets folder or Assets/Resources/Items/Weapons/)
- // 2. Select "Create > Weapon"
- // 3. Name your weapon asset (e.g., "IronSword.asset")
- // 4. Select the created asset and edit its properties in the Inspector:
- // - Item Name: "Iron Sword"
- // - Description: "A sturdy iron sword"
- // - Icon: (drag a sprite)
- // - Rarity: 1 (common) to 5 (legendary)
- // - Attack Bonus: 5.0
- // - Magic Bonus: 0.0
- // - Defense Bonus: 1.0
- // - Speed Bonus: 0.0
- //
- // The asset is automatically saved to Resources/Items/Weapons/ for easy runtime loading.
- [System.Obsolete("See instructions above - create via Editor instead")]
- public class WeaponCreationExample : MonoBehaviour
- {
- // Example of loading weapons at runtime
- private void LoadWeaponsExample()
- {
- Weapon[] allWeapons = Resources.LoadAll<Weapon>("Items/Weapons/");
- foreach (var weapon in allWeapons)
- {
- Debug.Log($"Loaded weapon: {weapon.ItemName}");
- }
- }
- }
- // EXAMPLE 2: Creating a monster programmatically
- public class MonsterCreationExample : MonoBehaviour
- {
- public Monster CreateGoblin()
- {
- var goblin = ScriptableObject.CreateInstance<Monster>();
- goblin.name = "Goblin";
- // Create stats
- var stats = new CharacterStats();
- // stats fields are private - you'd need public setters or reflection
- // Best practice: create via editor!
- return goblin;
- }
- }
- // EXAMPLE 3: Setting up agents with character sheets in MazeSceneBuilder
- public class AgentSetupExample : MonoBehaviour
- {
- private Weapon[] _startingWeapons;
- private Armor[] _startingArmor;
- private void LoadResources()
- {
- // Load weapon templates
- _startingWeapons = Resources.LoadAll<Weapon>("Items/Weapons/");
- if (_startingWeapons.Length == 0)
- Debug.LogWarning("No weapons found in Resources/Items/Weapons/");
- // Load armor templates
- _startingArmor = Resources.LoadAll<Armor>("Items/Armor/");
- if (_startingArmor.Length == 0)
- Debug.LogWarning("No armor found in Resources/Items/Armor/");
- }
- private MazeAgent CreateAgentWithEquipment(string name, Room startRoom)
- {
- // Create base stats
- var stats = new CharacterStats();
- var sheet = new CharacterSheet(stats);
- // Equip weapon
- if (_startingWeapons.Length > 0)
- {
- var weapon = _startingWeapons[Random.Range(0, _startingWeapons.Length)];
- sheet.EquipWeapon(weapon);
- }
- // Equip armor
- if (_startingArmor.Length > 0)
- {
- var armor = _startingArmor[Random.Range(0, _startingArmor.Length)];
- sheet.EquipArmor(armor);
- }
- // Create agent with character sheet
- var agent = new MazeAgent(name, startRoom, sheet);
- return agent;
- }
- }
- // EXAMPLE 4: Spawning encounters when generating rooms
- public class EncounterSpawningExample : MonoBehaviour
- {
- private Monster[] _monsterPool;
- private float _encounterChance = 0.7f;
- private int _minMonstersPerRoom = 1;
- private int _maxMonstersPerRoom = 3;
- private void LoadMonsters()
- {
- _monsterPool = Resources.LoadAll<Monster>("Monsters/");
- if (_monsterPool.Length == 0)
- Debug.LogWarning("No monsters found in Resources/Monsters/");
- }
- private void SpawnEncounterInRoom(Room room)
- {
- // Don't spawn in start or exit rooms
- if (room.Kind == RoomKind.Start || room.Kind == RoomKind.Exit)
- return;
- // Random chance to spawn
- if (Random.value > _encounterChance)
- return;
- if (_monsterPool.Length == 0)
- return;
- // Create and populate encounter
- var encounter = new MonsterEncounter();
- encounter.SpawnMonsters(
- _monsterPool,
- _minMonstersPerRoom,
- _maxMonstersPerRoom
- );
- room.Encounter = encounter;
- Debug.Log($"Spawned encounter in {room.Id} with {encounter.AliveMonsterCount} monsters");
- }
- }
- // EXAMPLE 5: Triggering combat when agent enters a room
- public class CombatTriggerExample : MonoBehaviour
- {
- private MazeAgent _agent;
- private void UpdateAgentCombat()
- {
- // Check if agent entered a room with monsters
- if (_agent.CurrentRoom.Encounter != null &&
- _agent.CurrentRoom.Encounter.HasLivingMonsters &&
- !_agent.IsDead)
- {
- ResolveCombat();
- }
- }
- private void ResolveCombat()
- {
- var outcome = CombatResolver.ResolveCombat(_agent, _agent.CurrentRoom.Encounter);
- switch (outcome)
- {
- case CombatResolver.CombatOutcome.AgentVictory:
- Debug.Log($"{_agent.Name} won!");
- // TODO: Award loot
- // TODO: Update UI
- break;
- case CombatResolver.CombatOutcome.AgentDefeated:
- Debug.Log($"{_agent.Name} was defeated!");
- // Agent is now dead - they stop automatically
- // TODO: Update UI (show death)
- break;
- case CombatResolver.CombatOutcome.Fleeing:
- Debug.Log($"{_agent.Name} fled!");
- // TODO: Force retreat back through entrance
- break;
- }
- }
- }
- // EXAMPLE 6: Peeking at a room's threat level
- public class PeekingExample : MonoBehaviour
- {
- private MazeAgent _agent;
- private AutonomousAgentBrain _brain;
- private void CheckThreatOfAdjacentRooms()
- {
- foreach (var exit in _agent.CurrentRoom.Exits)
- {
- float threatLevel = _brain.PeekThroughExit(exit, _agent);
- string threatDescription = threatLevel < 0.5f ? "Safe" :
- threatLevel < 1.5f ? "Moderate" :
- threatLevel < 3.0f ? "Dangerous" : "Deadly";
- Debug.Log($"Exit leads to {threatDescription} room (CR: {threatLevel:F2})");
- }
- }
- }
- // EXAMPLE 7: Setting up weapon with specific bonuses (for reference)
- [System.Obsolete("Example only - create Weapons via editor")]
- public class WeaponBonusExample : MonoBehaviour
- {
- private void ExampleWeaponBonuses()
- {
- // When you create a Weapon, these are the fields:
- // - itemName: "Iron Sword"
- // - description: "A sturdy iron sword"
- // - icon: (sprite reference)
- // - rarity: 1 (common)
- // - attackBonus: 5.0f
- // - magicBonus: 0.0f (no magic effect)
- // - defenseBonus: 1.0f (slight parry bonus)
- // - speedBonus: 0.0f (no speed effect)
- // When equipped, applies:
- // - +5 attack
- // - +1 defense
- // Modifiers stack with other equipment
- }
- }
- // EXAMPLE 8: Armor with penalties
- [System.Obsolete("Example only - create Armor via editor")]
- public class ArmorExample : MonoBehaviour
- {
- private void ExampleArmorStats()
- {
- // Heavy Armor example:
- // - defenseBonus: 10.0f (good protection)
- // - healthBonus: 5.0f (extra durability)
- // - speedPenalty: 2.0f (slow movement)
- // - magicResistance: 0.0f (no special resistances)
- // Light Armor example:
- // - defenseBonus: 3.0f (basic protection)
- // - healthBonus: 0.0f
- // - speedPenalty: 0.0f (no penalty)
- // - magicResistance: 2.0f (magic resistance)
- }
- }
- // EXAMPLE 9: Initializing AutonomousAgentBrain with retreat settings
- public class BrainInitializationExample : MonoBehaviour
- {
- private void InitBrainBrave(AutonomousAgentBrain brain, MazeAgentController controller, MazeGenerator gen)
- {
- // Brave agent - will enter dangerous rooms
- brain.Initialize(
- controller,
- gen,
- initialDelay: 0.5f,
- decisionInterval: 0.5f,
- exploreChance: 0.8f,
- retreatThreshold: 3.0f, // Very high threshold - rarely retreats
- isLevelEnded: () => false
- );
- }
- private void InitBrainCautious(AutonomousAgentBrain brain, MazeAgentController controller, MazeGenerator gen)
- {
- // Cautious agent - avoids danger
- brain.Initialize(
- controller,
- gen,
- initialDelay: 0.5f,
- decisionInterval: 0.5f,
- exploreChance: 0.5f,
- retreatThreshold: 0.8f, // Low threshold - retreats often
- isLevelEnded: () => false
- );
- }
- private void InitBrainNormal(AutonomousAgentBrain brain, MazeAgentController controller, MazeGenerator gen)
- {
- // Balanced agent
- brain.Initialize(
- controller,
- gen,
- initialDelay: 0.5f,
- decisionInterval: 0.5f,
- exploreChance: 0.7f,
- retreatThreshold: 1.5f, // Medium threshold
- isLevelEnded: () => false
- );
- }
- }
- // EXAMPLE 10: Monster loot table setup (in editor)
- [System.Obsolete("Example only - create Monsters via editor")]
- public class MonsterLootExample : MonoBehaviour
- {
- private void ExampleLootTables()
- {
- // Goblin's loot table might include:
- // [0] Common Dagger
- // [1] Leather Armor
- // [2] Health Potion
- // [3] (empty for "no drop" chance)
- // Boss monster's loot table might include:
- // [0] Rare Sword
- // [1] Legendary Armor
- // [2] Magic Scroll
- // (no empty slots - always drops something)
- }
- }
- }
|