Revamped equipment init

This commit is contained in:
Marco 2025-04-07 15:58:43 +02:00
commit 2a016fd30c
16 changed files with 76 additions and 81 deletions

View file

@ -31,14 +31,8 @@ public partial class GameManager : Node2D
[Export] public Dictionary<int, NodePath> SpawnMarkers { get; private set; } = new();
//[Export] public Marker2D PlayerSpawnMarker { get; set; }
[Export] public Array<LootItem> StartingEquipment { get; private set; } = new();
private InventoryManager _inventoryManager { get; set; }
[Export]
public MapStartDataResource MapStartData { get; private set; }
//private AlarmManager _alarmManager { get; set; }
//public InventoryManager Inventory => _inventoryManager;
@ -67,6 +61,9 @@ public partial class GameManager : Node2D
[Export]
public Node2D PlayerParentNode { get; set; }
[Export]
public int EggStartIndex = 0;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
@ -124,9 +121,10 @@ public partial class GameManager : Node2D
public void ApplyMapStartData(MapStartDataResource mapStartData)
{
MapStartData = mapStartData;
EggStartIndex = mapStartData.EggIndex;
//MapStartData = mapStartData;
StartingEquipment.AddRange(mapStartData.StartingEquipment);
// StartingEquipment.AddRange(mapStartData.StartingEquipment);
}
public void AddMotivation(float motivation)
@ -222,9 +220,9 @@ public partial class GameManager : Node2D
private Vector2 GetStartPosition()
{
if (MapStartData != null)
if (MapResource != null)
{
if (SpawnMarkers.TryGetValue(MapStartData.EggIndex, out var spawnMarker))
if (SpawnMarkers.TryGetValue(EggStartIndex, out var spawnMarker))
{
var marker = GetNode<Node2D>(spawnMarker);
@ -257,25 +255,14 @@ public partial class GameManager : Node2D
private void SpawnWeapons()
{
if (!StartingEquipment.Any())
foreach (var startingItem in MapResource.StartData.StartingEquipment)
{
GD.Print("No items to spawn on Player");
return;
_inventoryManager.AddItem(startingItem);
}
foreach (var startingItem in StartingEquipment)
foreach (var item in MapResource.StartData.RemoveEquipment)
{
// Now automatically taken care of by the event
// switch (startingItem.Item)
// {
// case ItemTypes.Weapon:
// SpawnPlayerWeapon(startingItem);
//
// //_player.EquippedWeapon ??= weapon;
// break;
// }
_inventoryManager.AddItem(startingItem);
_inventoryManager.RemoveItem(item);
}
}

View file

@ -67,6 +67,11 @@ public partial class InventoryManager : Node2D
return _itemsDict.TryGetValue(itemKey, out var itm) ? itm.Count : 0;
}
public int RemoveItem(LootItem item)
{
return RemoveItem(item.ItemKey, 9999);
}
public int RemoveItem(string itemKey, int amount)
{
if (!_itemsDict.TryGetValue(itemKey, out var itm)) return 0;

View file

@ -6,6 +6,7 @@ namespace Cirno.Scripts.Resources.DebugMenu;
public partial class DebugMapSelectResource : Resource
{
[Export] public bool Enabled { get; private set; } = true;
[Export] public MapResource Map { get; private set; }
[Export] public string Path { get; private set; }
[Export] private string _name { get; set; }
@ -14,6 +15,8 @@ public partial class DebugMapSelectResource : Resource
[Export] public Texture2D Icon { get; private set; }
public string ScenePath => Map is not null ? Map.ScenePath : Path;
public string DisplayName
{
get

View file

@ -11,8 +11,11 @@ public partial class MapStartDataResource : Resource
public int EggIndex { get; set; }
[Export]
public Array<LootItem> StartingEquipment { get; set; } = new Array<LootItem>();
public Array<LootItem> StartingEquipment { get; set; } = [];
[Export]
public Array<LootItem> RemoveEquipment { get; set; } = [];
public override string ToString()
{
return $"EggIndex: {EggIndex}, Equipment: {string.Join("," ,StartingEquipment.Select(x => x.ItemKey))}";

View file

@ -80,7 +80,7 @@ public partial class DebugMenu : MenuBase
{
GameManager.Instance.Unpause();
}
GlobalState.Instance.GoToScene(scene.Path, scene.StartData);
GlobalState.Instance.GoToScene(scene.ScenePath, scene.StartData);
}
private void _on_check_box_toggled(bool state)