mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-04 16:45:54 +00:00
Refactored switches and chests and mapping
This commit is contained in:
parent
295d32e66d
commit
cc5376e94e
14 changed files with 158 additions and 91 deletions
|
|
@ -1,18 +1,26 @@
|
|||
namespace Cirno.Scripts;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
public partial class Chest : Activable
|
||||
namespace Cirno.Scripts;
|
||||
|
||||
public partial class Chest : Interactable
|
||||
{
|
||||
private InventoryManager inventoryManager;
|
||||
|
||||
[Export] public Array<LootItem> LootTable = new Array<LootItem>();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
inventoryManager = GetNode<InventoryManager>("/root/GameScene/InventoryManager");
|
||||
}
|
||||
|
||||
public override void Activate()
|
||||
{
|
||||
inventoryManager.AddRedKeycard();
|
||||
GetParent().QueueFree();
|
||||
if (!MeetsRequirements()) return;
|
||||
foreach (var item in LootTable)
|
||||
{
|
||||
_inventoryManager.AddItem(item.Item, item.Amount);
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
}
|
||||
|
||||
}
|
||||
16
Scripts/Interactables/Switch.cs
Normal file
16
Scripts/Interactables/Switch.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Interactables;
|
||||
|
||||
public partial class Switch : Interactable
|
||||
{
|
||||
[Export] public Activable Target { get; set; }
|
||||
|
||||
public override void Activate()
|
||||
{
|
||||
if (MeetsRequirements())
|
||||
{
|
||||
Target?.Activate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,16 @@
|
|||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Cirno.Scripts;
|
||||
using Cirno.Scripts.Resources;
|
||||
|
||||
public partial class InventoryManager : Node2D
|
||||
{
|
||||
public bool RedKeycard { get; set; }
|
||||
|
||||
private List<LootItem> _items = new List<LootItem>();
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
|
|
@ -16,41 +21,53 @@ public partial class InventoryManager : Node2D
|
|||
{
|
||||
}
|
||||
|
||||
public bool HasItems(List<ItemTypes> items)
|
||||
{
|
||||
return items.Aggregate(false, (current, item) => current || HasItem(item));
|
||||
}
|
||||
|
||||
public bool HasItem(ItemTypes type)
|
||||
{
|
||||
return _items.Any(x => x.Item == type && x.Amount > 0);
|
||||
}
|
||||
|
||||
public bool AddItem(ItemTypes type, int amount = 1)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ItemTypes.KeycardRed:
|
||||
RedKeycard = true;
|
||||
GD.Print($"Red Keycard x{amount}");
|
||||
break;
|
||||
case ItemTypes.KeycardBlue:
|
||||
GD.Print($"Blue Keycard x{amount}");
|
||||
break;
|
||||
case ItemTypes.KeycardGreen:
|
||||
GD.Print($"Green Keycard x{amount}");
|
||||
break;
|
||||
case ItemTypes.Ammo:
|
||||
GD.Print($"Ammo x{amount}");
|
||||
break;
|
||||
case ItemTypes.Medkit:
|
||||
GD.Print($"Medkit x{amount}");
|
||||
break;
|
||||
case ItemTypes.CrabBomb:
|
||||
GD.Print($"CrabBomb x{amount}");
|
||||
break;
|
||||
case ItemTypes.Bomb:
|
||||
GD.Print($"Bomb x{amount}");
|
||||
break;
|
||||
case ItemTypes.Mine:
|
||||
GD.Print($"Mine x{amount}");
|
||||
break;
|
||||
case ItemTypes.Battery:
|
||||
GD.Print($"Battery x{amount}");
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
_items.Add(new LootItem() { Item = type, Amount = amount });
|
||||
GD.Print($"Added {type} x{amount}");
|
||||
// switch (type)
|
||||
// {
|
||||
// // case ItemTypes.KeycardRed:
|
||||
// // RedKeycard = true;
|
||||
// // GD.Print($"Red Keycard x{amount}");
|
||||
// // break;
|
||||
// // case ItemTypes.KeycardBlue:
|
||||
// // GD.Print($"Blue Keycard x{amount}");
|
||||
// // break;
|
||||
// // case ItemTypes.KeycardGreen:
|
||||
// // GD.Print($"Green Keycard x{amount}");
|
||||
// // break;
|
||||
// // case ItemTypes.Ammo:
|
||||
// // GD.Print($"Ammo x{amount}");
|
||||
// // break;
|
||||
// // case ItemTypes.Medkit:
|
||||
// // GD.Print($"Medkit x{amount}");
|
||||
// // break;
|
||||
// // case ItemTypes.CrabBomb:
|
||||
// // GD.Print($"CrabBomb x{amount}");
|
||||
// // break;
|
||||
// // case ItemTypes.Bomb:
|
||||
// // GD.Print($"Bomb x{amount}");
|
||||
// // break;
|
||||
// // case ItemTypes.Mine:
|
||||
// // GD.Print($"Mine x{amount}");
|
||||
// // break;
|
||||
// // case ItemTypes.Battery:
|
||||
// // GD.Print($"Battery x{amount}");
|
||||
// // break;
|
||||
// // default:
|
||||
// // return false;
|
||||
// }
|
||||
|
||||
return true; // TODO: Return false if could not be added
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,9 @@ public partial class Pickupper : Activable
|
|||
}
|
||||
|
||||
//inventoryManager.AddRedKeycard();
|
||||
GetParent().QueueFree(); // TODO: send a signal instead
|
||||
//GetParent().QueueFree(); // TODO: send a signal instead
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -7,4 +7,5 @@ public partial class LootItem : Resource
|
|||
{
|
||||
[Export] public ItemTypes Item;
|
||||
[Export] public int Amount;
|
||||
[Export] public int Max;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue