You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Babushka/scripts/CSharp/Common/Fight/FightRoomSceneSetup.cs

49 lines
1.5 KiB

using System.Collections.Generic;
using System.Linq;
using Babushka.scripts.CSharp.Common.Inventory;
using Godot;
namespace Babushka.scripts.CSharp.Common.Fight;
public partial class FightRoomSceneSetup : Node
{
[Export(PropertyHint.ArrayType)] private Node2D[] _enemyGroupSpawns = null!;
[Export] private PackedScene _roamingEnemyGroupPrefab = null!;
[Export] private PackedScene _itemOnGroundPrefab = null!;
[Export] private FightSceneSwitcher _fightSceneSwitcher = null!;
public override void _Ready()
{
var room = FightWorld.Instance.currentRoom!;
foreach (var (parent, group) in _enemyGroupSpawns.Zip(room.enemyGroups))
{
if (group.AreAllDead())
{
SpawnLoot(group, parent);
}
else
{
SpawnEnemies(group, parent);
}
}
}
private void SpawnEnemies(FightWorld.FighterGroup group, Node2D parent)
{
var roamingEnemyGroup = _roamingEnemyGroupPrefab.Instantiate<RoamingEnemyGroup>();
roamingEnemyGroup.Initialize(group, _fightSceneSwitcher);
parent.AddChild(roamingEnemyGroup);
}
private void SpawnLoot(FightWorld.FighterGroup group, Node2D parent)
{
if (group.lootToDrop == null)
return;
var onGroundInstance = _itemOnGroundPrefab.Instantiate<ItemOnGround2D>();
onGroundInstance.itemInstance = group.lootToDrop;
parent.AddChild(onGroundInstance);
}
}