✨ Defeated enemygroups now drop a beet_seed
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Babushka.scripts.CSharp.Common.Util;
|
||||
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;
|
||||
[Export] private PackedScene _roamingEnemyGroupPrefab;
|
||||
[Export] private FightSceneSwitcher _fightSceneSwitcher;
|
||||
[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()
|
||||
@@ -19,11 +20,30 @@ public partial class FightRoomSceneSetup : Node
|
||||
foreach (var (parent, group) in _enemyGroupSpawns.Zip(room.enemyGroups))
|
||||
{
|
||||
if (group.AreAllDead())
|
||||
continue;
|
||||
|
||||
var roamingEnemyGroup = _roamingEnemyGroupPrefab.Instantiate<RoamingEnemyGroup>();
|
||||
roamingEnemyGroup.Initialize(group, _fightSceneSwitcher);
|
||||
parent.AddChild(roamingEnemyGroup);
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using Babushka.scripts.CSharp.Common.Fight.Actions;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Babushka.scripts.CSharp.Common.Util;
|
||||
using Godot;
|
||||
|
||||
@@ -19,6 +20,7 @@ public partial class FightWorld : Node
|
||||
None,
|
||||
EndOfNight
|
||||
}
|
||||
|
||||
public required Dictionary<int, Room> paths;
|
||||
public required List<FighterGroup> enemyGroups;
|
||||
public Special specialRoom = Special.None;
|
||||
@@ -27,6 +29,7 @@ public partial class FightWorld : Node
|
||||
public class FighterGroup
|
||||
{
|
||||
public required List<Fighter> fighters;
|
||||
public ItemInstance? lootToDrop = null;
|
||||
}
|
||||
|
||||
public class FightHappeningData
|
||||
@@ -81,6 +84,9 @@ public partial class FightWorld : Node
|
||||
public FightHappeningData? fightHappeningData = null;
|
||||
public AllyFighters allyFighters = new();
|
||||
|
||||
// settings
|
||||
[Export] private ItemResource? _itemToDropByEnemyGroup;
|
||||
|
||||
public void ResetFightWorld()
|
||||
{
|
||||
Generate();
|
||||
@@ -89,10 +95,10 @@ public partial class FightWorld : Node
|
||||
|
||||
public void Generate()
|
||||
{
|
||||
world = new Generator().GenerateWorld();
|
||||
world = new Generator(this).GenerateWorld();
|
||||
}
|
||||
|
||||
private class Generator
|
||||
private class Generator(FightWorld fightWorld)
|
||||
{
|
||||
public World GenerateWorld()
|
||||
{
|
||||
@@ -113,7 +119,7 @@ public partial class FightWorld : Node
|
||||
{
|
||||
rooms.Add(GenerateDisconnectedRoom());
|
||||
}
|
||||
|
||||
|
||||
rooms.Add(new Room
|
||||
{
|
||||
paths = [],
|
||||
@@ -162,6 +168,11 @@ public partial class FightWorld : Node
|
||||
fighters = []
|
||||
};
|
||||
|
||||
if (fightWorld._itemToDropByEnemyGroup != null)
|
||||
{
|
||||
enemyGroup.lootToDrop = new ItemInstance { blueprint = fightWorld._itemToDropByEnemyGroup };
|
||||
}
|
||||
|
||||
var enemyCount = GD.RandRange(2, 3);
|
||||
|
||||
for (var i = 0; i < enemyCount; i++)
|
||||
|
||||
Reference in New Issue
Block a user