Files

191 lines
4.8 KiB
C#
Raw Permalink Normal View History

2025-09-12 13:20:27 +02:00
using System.Collections.Generic;
2025-10-01 01:42:29 +02:00
using Babushka.scripts.CSharp.Common.Fight.Actions;
2025-09-21 14:54:55 +02:00
using Babushka.scripts.CSharp.Common.Util;
2025-09-12 13:20:27 +02:00
using Godot;
namespace Babushka.scripts.CSharp.Common.Fight;
public partial class FightWorld : Node
{
public class World
{
public required List<Room> rooms;
}
public class Room
{
public required Dictionary<int, Room> paths;
2025-09-30 16:23:05 +02:00
public required List<FighterGroup> enemyGroups;
2025-09-12 13:20:27 +02:00
}
2025-09-30 16:23:05 +02:00
public class FighterGroup
2025-09-12 13:20:27 +02:00
{
public required List<Fighter> fighters;
2025-09-12 13:20:27 +02:00
}
2025-09-21 14:54:55 +02:00
public class FightHappeningData
{
2025-09-30 16:23:05 +02:00
public required FighterGroup enemyGroup;
public FightHappening.FightState fightState = FightHappening.FightState.None;
public readonly FighterTurn fighterTurn = new();
public readonly FighterFormation allyFighterFormation = new();
public readonly FighterFormation enemyFighterFormation = new();
2025-09-30 16:23:05 +02:00
public FightHappening.FightersEnterStaging? fightersEnterStaging;
public FighterAction? actionStaging;
2025-09-21 14:54:55 +02:00
}
public class Fighter
2025-09-12 13:20:27 +02:00
{
public enum Type
{
Blob,
BigBlob,
Mavka,
2025-09-21 14:54:55 +02:00
YourMom,
2025-09-30 16:23:05 +02:00
Vesna,
Chuha
2025-09-12 13:20:27 +02:00
}
public required Type type;
2025-09-21 14:54:55 +02:00
public required int maxHealth;
public required List<FighterAction> availableActions;
public const int MaxActionPoints = 1;
2025-09-21 14:54:55 +02:00
public int? health = null; // null => initialize to full health on spawn
2025-09-30 16:23:05 +02:00
public int actionPointsLeft;
2025-09-21 14:54:55 +02:00
public FighterAction AutoSelectAction()
{
return availableActions.Random() ?? new FighterAction.Skip();
}
2025-09-12 13:20:27 +02:00
}
#region AutoLoad ( Contains _EnterTree() )
public static FightWorld Instance { get; private set; } = null!;
public override void _EnterTree()
{
Instance = this;
MyEnterTree();
}
#endregion
2025-09-21 14:54:55 +02:00
2025-09-12 13:20:27 +02:00
public World? world = null;
public Room? currentRoom = null;
2025-09-21 14:54:55 +02:00
public FightHappeningData? fightHappeningData = null;
2025-09-30 16:23:05 +02:00
public AllyFighters allyFighters = new();
2025-09-12 13:20:27 +02:00
public void MyEnterTree()
{
Generate();
currentRoom = world!.rooms[0];
}
public void Generate()
{
world = new Generator().GenerateWorld();
}
private class Generator
{
public World GenerateWorld()
{
var world = new World
{
rooms = GenerateRooms()
};
return world;
}
private List<Room> GenerateRooms()
{
var rooms = new List<Room>();
var roomCount = 2;
for (var i = 0; i < roomCount; i++)
{
rooms.Add(GenerateDisconnectedRoom());
}
// Connect rooms linearly
for (var i = 0; i < rooms.Count - 1; i++)
{
rooms[i].paths[0] = rooms[i + 1];
rooms[i + 1].paths[1] = rooms[i];
}
return rooms;
}
private Room GenerateDisconnectedRoom()
{
var room = new Room
{
paths = new Dictionary<int, Room>(),
enemyGroups = GenerateEnemyGroups()
};
return room;
}
2025-09-30 16:23:05 +02:00
private List<FighterGroup> GenerateEnemyGroups()
2025-09-12 13:20:27 +02:00
{
2025-09-30 16:23:05 +02:00
var enemyGroups = new List<FighterGroup>();
2025-09-12 13:20:27 +02:00
var enemyGroupCount = GD.RandRange(1, 3);
for (var i = 0; i < enemyGroupCount; i++)
{
enemyGroups.Add(GenerateSingleEnemyGroup());
}
return enemyGroups;
}
2025-09-30 16:23:05 +02:00
private FighterGroup GenerateSingleEnemyGroup()
2025-09-12 13:20:27 +02:00
{
2025-09-30 16:23:05 +02:00
var enemyGroup = new FighterGroup
2025-09-12 13:20:27 +02:00
{
fighters = []
2025-09-12 13:20:27 +02:00
};
var enemyCount = GD.RandRange(1, 3);
for (var i = 0; i < enemyCount; i++)
{
enemyGroup.fighters.Add(GenerateSingleEnemy());
2025-09-12 13:20:27 +02:00
}
return enemyGroup;
}
2025-09-21 14:54:55 +02:00
private Fighter GenerateSingleEnemy()
2025-09-12 13:20:27 +02:00
{
var typeRoll = GD.RandRange(0, 99);
2025-11-03 20:21:30 +01:00
// Disabled generating different types due to lack of fighter visual type implementation
2025-09-30 16:23:05 +02:00
//var type = typeRoll switch
//{
// < 50 => Fighter.Type.Blob,
// < 75 => Fighter.Type.BigBlob,
// < 90 => Fighter.Type.Mavka,
// _ => Fighter.Type.YourMom
//};
var type = Fighter.Type.Blob;
2025-09-12 13:20:27 +02:00
2025-09-21 14:54:55 +02:00
var enemy = new Fighter
2025-09-12 13:20:27 +02:00
{
type = type,
2025-09-21 14:54:55 +02:00
health = null,
maxHealth = 12,
2025-09-30 16:23:05 +02:00
availableActions =
[
2025-10-01 01:42:29 +02:00
new BlobAttackAction()
2025-09-21 14:54:55 +02:00
]
2025-09-12 13:20:27 +02:00
};
return enemy;
}
}
}