Compare commits

...

4 Commits

Author SHA1 Message Date
d45bc67722 Partially implementation of box items 2026-02-04 22:30:10 -08:00
13ebe54474 Fix some control issues 2026-02-04 02:34:23 -08:00
b9a1888bfc Add implementation for box item 2026-02-04 02:11:00 -08:00
52dc8fb9e4 Box item implementation 2026-02-04 01:49:17 -08:00
35 changed files with 870 additions and 413 deletions

View File

@@ -4,5 +4,21 @@ public enum ItemTag
{ {
None, None,
BreaksOnChange, BreaksOnChange,
MysteryItem MysteryItem,
} DamagesPlayer,
ContainsRestorative,
ContainsWeapon,
ContainsArmor,
ContainsBox,
RandomSpell,
ContainsAccessory,
DropTo1HPAndGainRareItem,
TradeOneRandomItem,
TradeAllRandomItems,
ContainsUnobtainedItem,
ContainsBasicItem,
RestrictUnequip,
UnequipAllItems,
EjectAllItems,
UseAllItems
}

View File

@@ -44,6 +44,8 @@ public interface IPlayer : IKillable, ICharacterBody3D
public void SetHealthTimerStatus(bool isActive); public void SetHealthTimerStatus(bool isActive);
public bool CanEquipState { get; set; }
public event Action PlayerDied; public event Action PlayerDied;
public delegate InventoryItem RerollItem(InventoryItem item); public delegate InventoryItem RerollItem(InventoryItem item);
} }

View File

@@ -69,7 +69,6 @@ public partial class Game : Node3D, IGame
public QuestData QuestData { get; private set; } public QuestData QuestData { get; private set; }
private EffectService _effectService; private EffectService _effectService;
private ItemReroller _itemReroller;
private IInstantiator _instantiator; private IInstantiator _instantiator;
private IPlayer _player; private IPlayer _player;
@@ -88,7 +87,6 @@ public partial class Game : Node3D, IGame
QuestData = new QuestData(); QuestData = new QuestData();
RescuedItems = new RescuedItemDatabase(); RescuedItems = new RescuedItemDatabase();
ItemDatabase = ItemDatabase.Instance; ItemDatabase = ItemDatabase.Instance;
_itemReroller = new ItemReroller(ItemDatabase);
GameChunk = new SaveChunk<GameData>( GameChunk = new SaveChunk<GameData>(
(chunk) => (chunk) =>
@@ -212,10 +210,13 @@ public partial class Game : Node3D, IGame
public async Task UseItem(InventoryItem item) public async Task UseItem(InventoryItem item)
{ {
if (item.ItemTag == ItemTag.MysteryItem) if (item.ItemTag == ItemTag.MysteryItem)
item = _itemReroller.RerollItem(item, _player.Inventory); _effectService.RerollItem(item);
switch (item) switch (item)
{ {
case BoxItem boxItem:
EnactBoxItemEffects(boxItem);
break;
case ConsumableItem consumableItem: case ConsumableItem consumableItem:
EnactConsumableItemEffects(consumableItem); EnactConsumableItemEffects(consumableItem);
break; break;
@@ -428,6 +429,42 @@ public partial class Game : Node3D, IGame
private void FinishedLoadingSaveFile() => EmitSignal(SignalName.SaveFileLoaded); private void FinishedLoadingSaveFile() => EmitSignal(SignalName.SaveFileLoaded);
private void EnactBoxItemEffects(BoxItem boxItem)
{
switch (boxItem.ItemTag)
{
case ItemTag.DamagesPlayer:
_effectService.DamagesPlayer(boxItem.Stats.DamageToPlayer);
GameRepo.CloseInventory();
break;
case ItemTag.ContainsAccessory:
_player.Inventory.TryAdd(_effectService.GetRandomItemOfType<Accessory>());
break;
case ItemTag.ContainsArmor:
_player.Inventory.TryAdd(_effectService.GetRandomItemOfType<Armor>());
break;
case ItemTag.ContainsWeapon:
_player.Inventory.TryAdd(_effectService.GetRandomItemOfType<Weapon>());
break;
case ItemTag.ContainsBox:
_player.Inventory.TryAdd(_effectService.GetRandomItemOfType<BoxItem>());
break;
case ItemTag.ContainsRestorative:
_player.Inventory.TryAdd(_effectService.GetRandomItemOfType<ConsumableItem>());
break;
case ItemTag.DropTo1HPAndGainRareItem:
_effectService.DropTo1HPAndGainRareItem<InventoryItem>();
break;
case ItemTag.TradeAllRandomItems:
var newInventory = _effectService.TradeAllRandomItems<InventoryItem>(boxItem);
_player.Inventory.Items.Clear();
_player.Inventory.TryAdd(boxItem);
foreach (var item in newInventory)
_player.Inventory.TryAdd(item);
break;
}
}
private void EnactConsumableItemEffects(ConsumableItem consumableItem) private void EnactConsumableItemEffects(ConsumableItem consumableItem)
{ {
if (_player.HealthComponent.AtFullHealth && consumableItem.RaiseHPAmount > 0) if (_player.HealthComponent.AtFullHealth && consumableItem.RaiseHPAmount > 0)
@@ -519,7 +556,7 @@ public partial class Game : Node3D, IGame
_effectService.ChangeAffinity(throwableItem); _effectService.ChangeAffinity(throwableItem);
break; break;
case ThrowableItemTag.WarpToExitIfFound: case ThrowableItemTag.WarpToExitIfFound:
_effectService.WarpToExit(_player); _effectService.WarpToExit();
GameRepo.CloseInventory(); GameRepo.CloseInventory();
break; break;
} }

View File

@@ -1,8 +1,9 @@
using Godot; using Godot;
using System.Linq; using System.Linq;
using System; using System;
using Zennysoft.Ma.Adapter; using Zennysoft.Ma.Adapter;
using Zennysoft.Ma.Adapter.Entity; using Zennysoft.Ma.Adapter.Entity;
using System.Collections.Generic;
namespace Zennysoft.Game.Ma; namespace Zennysoft.Game.Ma;
@@ -14,225 +15,301 @@ public class EffectService
public EffectService(IGame game, IPlayer player, IMap map) public EffectService(IGame game, IPlayer player, IMap map)
{ {
_game = game; _game = game;
_player = player; _player = player;
_map = map; _map = map;
} }
public void TeleportEnemiesToCurrentRoom() public void TeleportEnemiesToCurrentRoom()
{ {
var currentFloor = _game.CurrentFloor; var currentFloor = _game.CurrentFloor;
var rooms = currentFloor.Rooms; var rooms = currentFloor.Rooms;
var currentRoom = _map.GetPlayersCurrentRoom(); var currentRoom = _map.GetPlayersCurrentRoom();
if (currentRoom is not MonsterRoom) if (currentRoom is not MonsterRoom)
return; return;
var validRooms = rooms.OfType<MonsterRoom>().ToList(); var validRooms = rooms.OfType<MonsterRoom>().ToList();
if (currentRoom is MonsterRoom monsterRoom) if (currentRoom is MonsterRoom monsterRoom)
validRooms.Remove(monsterRoom); validRooms.Remove(monsterRoom);
var currentMonsterRoom = (MonsterRoom)currentRoom; var currentMonsterRoom = (MonsterRoom)currentRoom;
var enemyList = validRooms.SelectMany(x => x.GetEnemiesInCurrentRoom()).OfType<Enemy>(); var enemyList = validRooms.SelectMany(x => x.GetEnemiesInCurrentRoom()).OfType<Enemy>();
foreach (var enemy in enemyList) foreach (var enemy in enemyList)
enemy.MoveEnemyToNewRoom(currentMonsterRoom); enemy.MoveEnemyToNewRoom(currentMonsterRoom);
} }
public void KillHalfEnemiesInRoom() public void KillHalfEnemiesInRoom()
{ {
var currentRoom = _map.GetPlayersCurrentRoom(); var currentRoom = _map.GetPlayersCurrentRoom();
if (currentRoom is not MonsterRoom) if (currentRoom is not MonsterRoom)
return; return;
var currentMonsterRoom = (MonsterRoom)currentRoom; var currentMonsterRoom = (MonsterRoom)currentRoom;
var enemyList = currentMonsterRoom.GetEnemiesInCurrentRoom().OfType<Enemy>().ToList(); var enemyList = currentMonsterRoom.GetEnemiesInCurrentRoom().OfType<Enemy>().ToList();
var enemiesToKill = enemyList.Count / 2; var enemiesToKill = enemyList.Count / 2;
for (var i = 0; i < enemiesToKill; i++) for (var i = 0; i < enemiesToKill; i++)
enemyList[i].Die(); enemyList[i].Die();
} }
public void TurnAllEnemiesInRoomIntoHealingItem() public void TurnAllEnemiesInRoomIntoHealingItem()
{ {
var currentRoom = _map.GetPlayersCurrentRoom(); var currentRoom = _map.GetPlayersCurrentRoom();
if (currentRoom is not MonsterRoom) if (currentRoom is not MonsterRoom)
return; return;
var currentEnemies = currentRoom.EnemiesInRoom.OfType<Enemy>().ToList(); var currentEnemies = currentRoom.EnemiesInRoom.OfType<Enemy>().ToList();
foreach (var enemy in currentEnemies) foreach (var enemy in currentEnemies)
{ {
enemy.OnMorph(); enemy.OnMorph();
DropHealingItem(enemy.GlobalPosition); DropHealingItem(enemy.GlobalPosition);
} }
if (currentEnemies.Any()) if (currentEnemies.Any())
SfxDatabase.Instance.Play(SoundEffect.TurnAllEnemiesIntoHealingItems); SfxDatabase.Instance.Play(SoundEffect.TurnAllEnemiesIntoHealingItems);
} }
public void DropHealingItem(Vector3 vector) public void DropHealingItem(Vector3 vector)
{ {
var consumableFolder = "res://src/items/consumable"; var consumableFolder = "res://src/items/consumable";
var restorativeScene = GD.Load<PackedScene>($"{consumableFolder}/ConsumableItem.tscn"); var restorativeScene = GD.Load<PackedScene>($"{consumableFolder}/ConsumableItem.tscn");
var consumable = restorativeScene.Instantiate<ConsumableItem>(); var consumable = restorativeScene.Instantiate<ConsumableItem>();
var resourceFiles = DirAccess.GetFilesAt($"{consumableFolder}/resources"); var resourceFiles = DirAccess.GetFilesAt($"{consumableFolder}/resources");
var rng = new RandomNumberGenerator(); var rng = new RandomNumberGenerator();
rng.Randomize(); rng.Randomize();
var randomResource = resourceFiles[rng.RandiRange(0, resourceFiles.Length - 1)]; var randomResource = resourceFiles[rng.RandiRange(0, resourceFiles.Length - 1)];
var randomFile = ResourceLoader.Load<ConsumableItemStats>($"{consumableFolder}/resources/{randomResource}"); var randomFile = ResourceLoader.Load<ConsumableItemStats>($"{consumableFolder}/resources/{randomResource}");
consumable.Stats = randomFile; consumable.Stats = randomFile;
_game.AddChild(consumable); _game.AddChild(consumable);
consumable.GlobalPosition = vector; consumable.GlobalPosition = vector;
} }
public void HealAllEnemiesAndPlayerInRoomToFull() public void HealAllEnemiesAndPlayerInRoomToFull()
{ {
var currentRoom = _map.GetPlayersCurrentRoom(); var currentRoom = _map.GetPlayersCurrentRoom();
if (currentRoom is not MonsterRoom) if (currentRoom is not MonsterRoom)
return; return;
currentRoom.EnemiesInRoom.ForEach(e => e.HealthComponent.SetCurrentHealth(e.HealthComponent.MaximumHP.Value)); currentRoom.EnemiesInRoom.ForEach(e => e.HealthComponent.SetCurrentHealth(e.HealthComponent.MaximumHP.Value));
_player.HealthComponent.SetCurrentHealth(_player.HealthComponent.MaximumHP.Value); _player.HealthComponent.SetCurrentHealth(_player.HealthComponent.MaximumHP.Value);
} }
public void AbsorbHPFromAllEnemiesInRoom() public void AbsorbHPFromAllEnemiesInRoom()
{ {
var currentRoom = _map.GetPlayersCurrentRoom(); var currentRoom = _map.GetPlayersCurrentRoom();
if (currentRoom is not MonsterRoom) if (currentRoom is not MonsterRoom)
return; return;
var currentEnemies = currentRoom.EnemiesInRoom; var currentEnemies = currentRoom.EnemiesInRoom;
var hpToAbsorb = 0.0; var hpToAbsorb = 0.0;
foreach (var enemy in currentEnemies) foreach (var enemy in currentEnemies)
{ {
var absorbAmount = enemy.HealthComponent.MaximumHP.Value * 0.05; var absorbAmount = enemy.HealthComponent.MaximumHP.Value * 0.05;
enemy.HealthComponent.Damage((int)absorbAmount); enemy.HealthComponent.Damage((int)absorbAmount);
hpToAbsorb += absorbAmount; hpToAbsorb += absorbAmount;
enemy.OnAbsorb(); enemy.OnAbsorb();
} }
_player.HealthComponent.Heal((int)hpToAbsorb); _player.HealthComponent.Heal((int)hpToAbsorb);
GD.Print("HP to absorb: " + hpToAbsorb); GD.Print("HP to absorb: " + hpToAbsorb);
} }
public void DealElementalDamageToAllEnemiesInRoom(ElementType elementType) public void DealElementalDamageToAllEnemiesInRoom(ElementType elementType)
{ {
var currentRoom = _map.GetPlayersCurrentRoom(); var currentRoom = _map.GetPlayersCurrentRoom();
if (currentRoom is not MonsterRoom) if (currentRoom is not MonsterRoom)
return; return;
var currentEnemies = currentRoom.EnemiesInRoom; var currentEnemies = currentRoom.EnemiesInRoom;
foreach (var enemy in currentEnemies) foreach (var enemy in currentEnemies)
{ {
var damageDealt = DamageCalculator.CalculateDamage(new AttackData(20, elementType), 10, enemy.ElementalResistanceSet); var damageDealt = DamageCalculator.CalculateDamage(new AttackData(20, elementType), 10, enemy.ElementalResistanceSet);
enemy.HealthComponent.Damage(damageDealt); enemy.HealthComponent.Damage(damageDealt);
} }
} }
public void SwapHPandVT() public void SwapHPandVT()
{ {
var oldHp = _player.HealthComponent.CurrentHP.Value; var oldHp = _player.HealthComponent.CurrentHP.Value;
var oldVt = _player.VTComponent.CurrentVT.Value; var oldVt = _player.VTComponent.CurrentVT.Value;
_player.HealthComponent.SetCurrentHealth(oldVt); _player.HealthComponent.SetCurrentHealth(oldVt);
_player.VTComponent.SetVT(oldHp); _player.VTComponent.SetVT(oldHp);
SfxDatabase.Instance.Play(SoundEffect.SwapHPAndVT); SfxDatabase.Instance.Play(SoundEffect.SwapHPAndVT);
} }
public void RandomEffect(EffectItem item) public void RandomEffect(EffectItem item)
{ {
var itemEffects = Enum.GetValues<UsableItemTag>().ToList(); var itemEffects = Enum.GetValues<UsableItemTag>().ToList();
itemEffects.Remove(UsableItemTag.RandomEffect); itemEffects.Remove(UsableItemTag.RandomEffect);
itemEffects.Remove(UsableItemTag.None); itemEffects.Remove(UsableItemTag.None);
var randomEffect = new Godot.Collections.Array<UsableItemTag>(itemEffects).PickRandom(); var randomEffect = new Godot.Collections.Array<UsableItemTag>(itemEffects).PickRandom();
item.SetEffectTag(randomEffect); item.SetEffectTag(randomEffect);
_game.UseItem(item); _game.UseItem(item);
} }
public void RaiseCurrentWeaponAttack() public void RaiseCurrentWeaponAttack()
{ {
if (string.IsNullOrEmpty(_player.EquipmentComponent.EquippedWeapon.Value.ItemName)) if (string.IsNullOrEmpty(_player.EquipmentComponent.EquippedWeapon.Value.ItemName))
return; return;
var currentWeapon = (Weapon)_player.EquipmentComponent.EquippedWeapon.Value; var currentWeapon = (Weapon)_player.EquipmentComponent.EquippedWeapon.Value;
currentWeapon.IncreaseWeaponAttack(1); currentWeapon.IncreaseWeaponAttack(1);
SfxDatabase.Instance.Play(SoundEffect.IncreaseStat); SfxDatabase.Instance.Play(SoundEffect.IncreaseStat);
} }
public void RaiseCurrentArmorDefense() public void RaiseCurrentArmorDefense()
{ {
if (string.IsNullOrEmpty(_player.EquipmentComponent.EquippedArmor.Value.ItemName)) if (string.IsNullOrEmpty(_player.EquipmentComponent.EquippedArmor.Value.ItemName))
return; return;
var currentArmor = (Armor)_player.EquipmentComponent.EquippedArmor.Value; var currentArmor = (Armor)_player.EquipmentComponent.EquippedArmor.Value;
currentArmor.IncreaseArmorDefense(1); currentArmor.IncreaseArmorDefense(1);
SfxDatabase.Instance.Play(SoundEffect.IncreaseStat); SfxDatabase.Instance.Play(SoundEffect.IncreaseStat);
} }
public void RaiseLevel() => _player.LevelUp(); public void RaiseLevel() => _player.LevelUp();
public void TeleportToRandomRoom(IEnemy enemy) public void TeleportToRandomRoom(IEnemy enemy)
{ {
var currentFloor = _game.CurrentFloor; var currentFloor = _game.CurrentFloor;
var rooms = currentFloor.Rooms; var rooms = currentFloor.Rooms;
var currentRoom = enemy.GetCurrentRoom(rooms); var currentRoom = enemy.GetCurrentRoom(rooms);
var validRooms = rooms.OfType<MonsterRoom>().ToList(); var validRooms = rooms.OfType<MonsterRoom>().ToList();
if (currentRoom is MonsterRoom currentMonsterRoom) if (currentRoom is MonsterRoom currentMonsterRoom)
validRooms.Remove(currentMonsterRoom); validRooms.Remove(currentMonsterRoom);
if (validRooms.Count == 0) if (validRooms.Count == 0)
return; return;
var roomsGodotCollection = new Godot.Collections.Array<MonsterRoom>(validRooms); var roomsGodotCollection = new Godot.Collections.Array<MonsterRoom>(validRooms);
var randomRoom = roomsGodotCollection.PickRandom(); var randomRoom = roomsGodotCollection.PickRandom();
enemy.MoveEnemyToNewRoom(randomRoom); enemy.MoveEnemyToNewRoom(randomRoom);
} }
public void TeleportToRandomRoom(IPlayer player) public void TeleportToRandomRoom(IPlayer player)
{ {
var currentFloor = _game.CurrentFloor; var currentFloor = _game.CurrentFloor;
var rooms = currentFloor.Rooms; var rooms = currentFloor.Rooms;
var currentRoom = rooms.SingleOrDefault(x => x.IsPlayerInRoom); var currentRoom = rooms.SingleOrDefault(x => x.IsPlayerInRoom);
var validRooms = rooms.OfType<MonsterRoom>().ToList(); var validRooms = rooms.OfType<MonsterRoom>().ToList();
if (currentRoom is MonsterRoom currentMonsterRoom) if (currentRoom is MonsterRoom currentMonsterRoom)
validRooms.Remove(currentMonsterRoom); validRooms.Remove(currentMonsterRoom);
if (validRooms.Count == 0) if (validRooms.Count == 0)
return; return;
var roomsGodotCollection = new Godot.Collections.Array<MonsterRoom>(validRooms); var roomsGodotCollection = new Godot.Collections.Array<MonsterRoom>(validRooms);
var randomRoom = roomsGodotCollection.PickRandom(); var randomRoom = roomsGodotCollection.PickRandom();
var spawnPoint = randomRoom.PlayerSpawn; var spawnPoint = randomRoom.PlayerSpawn;
player.TeleportPlayer((spawnPoint.Rotation, spawnPoint.Position)); player.TeleportPlayer((spawnPoint.Rotation, spawnPoint.Position));
SfxDatabase.Instance.Play(SoundEffect.TeleportToRandomRoom); SfxDatabase.Instance.Play(SoundEffect.TeleportToRandomRoom);
} }
public void ChangeAffinity(ThrowableItem throwableItem) public void ChangeAffinity(ThrowableItem throwableItem)
{ {
var maximumElements = Enum.GetNames(typeof(ElementType)).Length; var maximumElements = Enum.GetNames(typeof(ElementType)).Length;
var newElement = ((int)throwableItem.ElementType + 1) % maximumElements; var newElement = ((int)throwableItem.ElementType + 1) % maximumElements;
throwableItem.SetElementType((ElementType)newElement); throwableItem.SetElementType((ElementType)newElement);
// TODO: Make this an inventory animation to cycle through elements. // TODO: Make this an inventory animation to cycle through elements.
throwableItem.SetDescription( throwableItem.SetDescription(
$"Inflicts {throwableItem.ElementType} damage when thrown." + $"Inflicts {throwableItem.ElementType} damage when thrown." +
$"{System.Environment.NewLine}Use item to change Affinity."); $"{System.Environment.NewLine}Use item to change Affinity.");
throwableItem.SetCount(throwableItem.Count + 1); throwableItem.SetCount(throwableItem.Count + 1);
} }
public void WarpToExit(IPlayer player) public void WarpToExit()
{ {
var exitRoom = _game.CurrentFloor.Rooms.OfType<ExitRoom>().Single(); var exitRoom = _game.CurrentFloor.Rooms.OfType<ExitRoom>().Single();
if (exitRoom.PlayerDiscoveredRoom) if (exitRoom.PlayerDiscoveredRoom)
{ {
SfxDatabase.Instance.Play(SoundEffect.TeleportToExit); SfxDatabase.Instance.Play(SoundEffect.TeleportToExit);
player.TeleportPlayer((exitRoom.PlayerSpawn.Rotation, exitRoom.PlayerSpawn.Position)); _player.TeleportPlayer((exitRoom.PlayerSpawn.Rotation, exitRoom.PlayerSpawn.Position));
} }
}
public void DamagesPlayer(int damage)
{
_player.TakeDamage(new AttackData(damage, ElementType.None, true, true));
}
public void RerollItem(InventoryItem itemToReroll)
{
var itemReroller = new ItemReroller(ItemDatabase.Instance);
itemReroller.RerollItem(itemToReroll, _player.Inventory);
}
public T GetRandomItemOfType<T>(T itemToExclude = null)
where T : InventoryItem => ItemDatabase.Instance.PickItem(itemToExclude);
public void RandomSpell()
{
throw new NotImplementedException("Spells not implemented yet.");
}
public void DropTo1HPAndGainRareItem<T>()
where T : InventoryItem
{
_player.HealthComponent.SetCurrentHealth(1);
_player.Inventory.TryAdd(ItemDatabase.Instance.PickRareItem<T>());
}
public void TradeRandomItem<T>(BoxItem box)
where T : InventoryItem
{
var tradableItems = _player.Inventory.Items.OfType<T>().Where(x => x != box).ToList();
var rng = new RandomNumberGenerator();
rng.Randomize();
var randomIndex = rng.RandiRange(0, tradableItems.Count - 1);
var randomItem = tradableItems[randomIndex];
if (randomItem is EquipableItem equipableItem)
{
if (_player.EquipmentComponent.IsItemEquipped(equipableItem))
_player.Unequip(equipableItem);
}
_player.Inventory.Remove(randomItem);
GetRandomItemOfType<T>();
}
public IEnumerable<InventoryItem> TradeAllRandomItems<T>(BoxItem box)
where T : InventoryItem
{
var newInventory = new List<InventoryItem>();
var items = _player.Inventory.Items.OfType<T>().Where(x => x != box).ToList();
foreach (var item in items)
newInventory.Add(GetRandomItemOfType<T>());
return newInventory;
}
public void GetUnobtainedItem()
{
var pickableItems = ItemDatabase.Instance.Items.Except(_player.Inventory.Items).ToList();
var rng = new RandomNumberGenerator();
rng.Randomize();
var randomIndex = rng.RandiRange(0, pickableItems.Count - 1);
var selectedItem = pickableItems[randomIndex];
if (selectedItem is ThrowableItem throwableItem)
throwableItem.SetCount(rng.RandiRange(throwableItem.Stats.MinimumCount, throwableItem.Stats.MaximumCount));
_player.Inventory.TryAdd(selectedItem);
}
public void GetBasicItem<T>()
where T : InventoryItem
{
_player.Inventory.TryAdd(ItemDatabase.Instance.PickBasicItem<T>());
} }
} }

View File

@@ -18,14 +18,33 @@ public class ItemDatabase
public T PickItem<T>(T itemToExclude = null) public T PickItem<T>(T itemToExclude = null)
where T : InventoryItem where T : InventoryItem
{
var itemsToSelectFrom = Items.OfType<T>();
return PickItemInternal(itemsToSelectFrom, itemToExclude);
}
public T PickRareItem<T>(T itemToExclude = null)
where T : InventoryItem
{
var getRareItems = Items.OfType<T>().Where(x => x.SpawnRate < 0.1f);
return PickItemInternal(getRareItems, itemToExclude);
}
public T PickBasicItem<T>(T itemToExclude = null)
where T : InventoryItem
{
var getBasicItems = Items.OfType<T>().Where(x => x.SpawnRate > 0.5f);
return PickItemInternal(getBasicItems, itemToExclude);
}
private T PickItemInternal<T>(IEnumerable<T> itemsToSelectFrom, T itemToExclude = null)
where T : InventoryItem
{ {
var rng = new RandomNumberGenerator(); var rng = new RandomNumberGenerator();
rng.Randomize(); rng.Randomize();
var itemsToSelectFrom = Items;
if (itemToExclude is not null) if (itemToExclude is not null)
itemsToSelectFrom = [.. itemsToSelectFrom.OfType<T>().Where(x => x.ItemName != itemToExclude.ItemName)]; itemsToSelectFrom = [.. itemsToSelectFrom.Where(x => x.ItemName != itemToExclude.ItemName)];
var weights = itemsToSelectFrom.Select(x => x.SpawnRate).ToArray(); var weights = itemsToSelectFrom.Select(x => x.SpawnRate).ToArray();
var selectedItem = itemsToSelectFrom.ToArray()[rng.RandWeighted(weights)]; var selectedItem = itemsToSelectFrom.ToArray()[rng.RandWeighted(weights)];
@@ -33,7 +52,7 @@ public class ItemDatabase
if (selectedItem is ThrowableItem throwableItem) if (selectedItem is ThrowableItem throwableItem)
throwableItem.SetCount(rng.RandiRange(throwableItem.Stats.MinimumCount, throwableItem.Stats.MaximumCount)); throwableItem.SetCount(rng.RandiRange(throwableItem.Stats.MinimumCount, throwableItem.Stats.MaximumCount));
return (T)selectedItem; return selectedItem;
} }
private ItemDatabase() private ItemDatabase()
@@ -45,6 +64,7 @@ public class ItemDatabase
var throwableResources = DirAccess.GetFilesAt("res://src/items/throwable/resources/"); var throwableResources = DirAccess.GetFilesAt("res://src/items/throwable/resources/");
var consumableResources = DirAccess.GetFilesAt("res://src/items/consumable/resources/"); var consumableResources = DirAccess.GetFilesAt("res://src/items/consumable/resources/");
var effectResources = DirAccess.GetFilesAt("res://src/items/effect/resources/"); var effectResources = DirAccess.GetFilesAt("res://src/items/effect/resources/");
var boxResources = DirAccess.GetFilesAt("res://src/items/box/resources/");
foreach (var armor in armorResources) foreach (var armor in armorResources)
{ {
@@ -100,6 +120,15 @@ public class ItemDatabase
database.Add(effectItemScene); database.Add(effectItemScene);
} }
foreach (var boxItem in boxResources)
{
var boxItemInfo = GD.Load<BoxItemStats>($"res://src/items/box/resources/{boxItem}");
var boxItemScene = ResourceLoader.Load<PackedScene>("res://src/items/box/BoxItem.tscn").Instantiate<BoxItem>();
boxItemScene.Stats = boxItemInfo;
if (!database.Contains(boxItemScene))
database.Add(boxItemScene);
}
Items = [.. database]; Items = [.. database];
} }
} }

View File

@@ -27,6 +27,21 @@ public class ItemReroller
return rolledItem; return rolledItem;
} }
public InventoryItem RerollItemToAny(InventoryItem itemToReroll, IInventory inventory, bool insertIntoInventory = true)
{
var currentIndex = inventory.Items.IndexOf(itemToReroll);
if (insertIntoInventory)
inventory.Remove(itemToReroll);
var rolledItem = _database.PickItem(itemToReroll);
if (insertIntoInventory)
inventory.TryInsert(rolledItem, currentIndex);
return rolledItem;
}
private Weapon RerollItemInternal(Weapon itemToReroll) => _database.PickItem(itemToReroll); private Weapon RerollItemInternal(Weapon itemToReroll) => _database.PickItem(itemToReroll);
private Armor RerollItemInternal(Armor itemToReroll) => _database.PickItem(itemToReroll); private Armor RerollItemInternal(Armor itemToReroll) => _database.PickItem(itemToReroll);
private Accessory RerollItemInternal(Accessory itemToReroll) => _database.PickItem(itemToReroll); private Accessory RerollItemInternal(Accessory itemToReroll) => _database.PickItem(itemToReroll);

View File

@@ -0,0 +1,12 @@
using Chickensoft.Introspection;
using Godot;
namespace Zennysoft.Game.Ma;
[GlobalClass]
[Meta, Id("box_item_stat_type")]
public partial class BoxItemStats : InventoryItemStats
{
[Export]
public int DamageToPlayer { get; set; } = 10;
}

View File

@@ -0,0 +1 @@
uid://vuavr681au06

View File

@@ -4,12 +4,12 @@ importer="scene"
importer_version=1 importer_version=1
type="PackedScene" type="PackedScene"
uid="uid://dkpgrhj14phdd" uid="uid://dkpgrhj14phdd"
path="res://.godot/imported/plastique.glb-38f4438846eaa3d64b225272714c5d02.scn" path="res://.godot/imported/plastique.glb-5845ad959844e1ca0c9791ff0287bc66.scn"
[deps] [deps]
source_file="res://src/items/assetts/plastique.glb" source_file="res://src/items/assets/plastique.glb"
dest_files=["res://.godot/imported/plastique.glb-38f4438846eaa3d64b225272714c5d02.scn"] dest_files=["res://.godot/imported/plastique.glb-5845ad959844e1ca0c9791ff0287bc66.scn"]
[params] [params]

View File

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

@@ -3,7 +3,7 @@
importer="texture" importer="texture"
type="CompressedTexture2D" type="CompressedTexture2D"
uid="uid://dkqs4x4pi18on" uid="uid://dkqs4x4pi18on"
path="res://.godot/imported/plastique_plastique.png-3ad121f0468f0ec1d61934d8a0e41cb7.ctex" path="res://.godot/imported/plastique_plastique.png-06bcea5737da44088a0bd794735523f0.ctex"
metadata={ metadata={
"vram_texture": false "vram_texture": false
} }
@@ -13,8 +13,8 @@ generator_parameters={
[deps] [deps]
source_file="res://src/items/assetts/plastique_plastique.png" source_file="res://src/items/assets/plastique_plastique.png"
dest_files=["res://.godot/imported/plastique_plastique.png-3ad121f0468f0ec1d61934d8a0e41cb7.ctex"] dest_files=["res://.godot/imported/plastique_plastique.png-06bcea5737da44088a0bd794735523f0.ctex"]
[params] [params]

View File

@@ -0,0 +1,37 @@
using Chickensoft.AutoInject;
using Chickensoft.Introspection;
using Chickensoft.Serialization;
using Godot;
using Zennysoft.Game.Ma;
using Zennysoft.Ma.Adapter;
[Meta(typeof(IAutoNode)), Id("box_item")]
public partial class BoxItem : InventoryItem
{
public override void _Notification(int what) => this.Notify(what);
[Node] private Sprite3D _sprite { get; set; }
[Export]
[Save("box_stats")]
public BoxItemStats Stats { get; set; } = new BoxItemStats();
public override string ItemName => Stats.Name;
public override string Description => Stats.Description;
public override float SpawnRate => Stats.SpawnRate;
public override int ThrowDamage => Stats.ThrowDamage;
public override float ThrowSpeed => Stats.ThrowSpeed;
public override ItemTag ItemTag => Stats.ItemTag;
public override Texture2D GetTexture() => Stats.Texture;
public void OnReady()
{
_sprite.Texture = Stats.Texture;
}
}

View File

@@ -0,0 +1 @@
uid://cqqqj4hgywst4

View File

@@ -1,6 +1,6 @@
[gd_scene load_steps=5 format=3 uid="uid://bguomljidwgto"] [gd_scene load_steps=5 format=3 uid="uid://bguomljidwgto"]
[ext_resource type="Script" path="res://src/items/box/BoxItem.cs" id="1_holk0"] [ext_resource type="Script" uid="uid://cqqqj4hgywst4" path="res://src/items/box/BoxItem.cs" id="1_holk0"]
[ext_resource type="Texture2D" uid="uid://bg47n2tmintm0" path="res://src/items/consumable/textures/past self remnant.PNG" id="2_holk0"] [ext_resource type="Texture2D" uid="uid://bg47n2tmintm0" path="res://src/items/consumable/textures/past self remnant.PNG" id="2_holk0"]
[sub_resource type="CylinderShape3D" id="CylinderShape3D_x6u08"] [sub_resource type="CylinderShape3D" id="CylinderShape3D_x6u08"]
@@ -17,7 +17,6 @@ axis_lock_angular_x = true
axis_lock_angular_y = true axis_lock_angular_y = true
axis_lock_angular_z = true axis_lock_angular_z = true
script = ExtResource("1_holk0") script = ExtResource("1_holk0")
Stats = null
[node name="CollisionShape3D" type="CollisionShape3D" parent="."] [node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.00908482, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.00908482, 0)

View File

@@ -0,0 +1,26 @@
[gd_resource type="Resource" script_class="BoxItemStats" load_steps=3 format=3 uid="uid://deebat2kuxfo3"]
[ext_resource type="Texture2D" uid="uid://bg47n2tmintm0" path="res://src/items/consumable/textures/past self remnant.PNG" id="1_p2ro7"]
[ext_resource type="Script" uid="uid://vuavr681au06" path="res://src/items/accessory/BoxItemStats.cs" id="2_k6pqw"]
[resource]
script = ExtResource("2_k6pqw")
DamageToPlayer = 0
Name = "Blood Acquisition"
Description = "Contains a rare item but lowers current HP to 1."
SpawnRate = 0.5
BonusAttack = 0
BonusDefense = 0
BonusLuck = 0.05
BonusHP = 0
BonusVT = 0
AeolicResistance = 0
TelluricResistance = 0
HydricResistance = 0
IgneousResistance = 0
FerrumResistance = 0
ThrowSpeed = 12.0
ThrowDamage = 5
ItemTag = 10
Texture = ExtResource("1_p2ro7")
metadata/_custom_type_script = "uid://vuavr681au06"

View File

@@ -0,0 +1,26 @@
[gd_resource type="Resource" script_class="BoxItemStats" load_steps=3 format=3 uid="uid://k0uhsuxvyegw"]
[ext_resource type="Texture2D" uid="uid://bg47n2tmintm0" path="res://src/items/consumable/textures/past self remnant.PNG" id="1_yf4yo"]
[ext_resource type="Script" uid="uid://vuavr681au06" path="res://src/items/accessory/BoxItemStats.cs" id="2_xe8mc"]
[resource]
script = ExtResource("2_xe8mc")
DamageToPlayer = 0
Name = "Chaotic Prayer"
Description = "Converts all items into random items."
SpawnRate = 0.5
BonusAttack = 0
BonusDefense = 0
BonusLuck = 0.05
BonusHP = 0
BonusVT = 0
AeolicResistance = 0
TelluricResistance = 0
HydricResistance = 0
IgneousResistance = 0
FerrumResistance = 0
ThrowSpeed = 12.0
ThrowDamage = 5
ItemTag = 12
Texture = ExtResource("1_yf4yo")
metadata/_custom_type_script = "uid://vuavr681au06"

View File

@@ -0,0 +1,25 @@
[gd_resource type="Resource" script_class="BoxItemStats" load_steps=3 format=3 uid="uid://cgkorwblwr12t"]
[ext_resource type="Texture2D" uid="uid://bg47n2tmintm0" path="res://src/items/consumable/textures/past self remnant.PNG" id="1_650jj"]
[ext_resource type="Script" uid="uid://vuavr681au06" path="res://src/items/accessory/BoxItemStats.cs" id="1_i336w"]
[resource]
script = ExtResource("1_i336w")
Name = "Empty Promise"
Description = "An empty box."
SpawnRate = 0.5
BonusAttack = 0
BonusDefense = 0
BonusLuck = 0.05
BonusHP = 0
BonusVT = 0
AeolicResistance = 0
TelluricResistance = 0
HydricResistance = 0
IgneousResistance = 0
FerrumResistance = 0
ThrowSpeed = 12.0
ThrowDamage = 5
ItemTag = 0
Texture = ExtResource("1_650jj")
metadata/_custom_type_script = "uid://vuavr681au06"

View File

@@ -0,0 +1,26 @@
[gd_resource type="Resource" script_class="BoxItemStats" load_steps=3 format=3 uid="uid://bit6jsgs4yl7t"]
[ext_resource type="Texture2D" uid="uid://bg47n2tmintm0" path="res://src/items/consumable/textures/past self remnant.PNG" id="1_85ci2"]
[ext_resource type="Script" uid="uid://vuavr681au06" path="res://src/items/accessory/BoxItemStats.cs" id="2_pe0kd"]
[resource]
script = ExtResource("2_pe0kd")
DamageToPlayer = 0
Name = "Fashionable Acquisition"
Description = "Contains a random armor."
SpawnRate = 0.5
BonusAttack = 0
BonusDefense = 0
BonusLuck = 0.05
BonusHP = 0
BonusVT = 0
AeolicResistance = 0
TelluricResistance = 0
HydricResistance = 0
IgneousResistance = 0
FerrumResistance = 0
ThrowSpeed = 12.0
ThrowDamage = 5
ItemTag = 6
Texture = ExtResource("1_85ci2")
metadata/_custom_type_script = "uid://vuavr681au06"

View File

@@ -0,0 +1,26 @@
[gd_resource type="Resource" script_class="BoxItemStats" load_steps=3 format=3 uid="uid://g3buxgpmjcio"]
[ext_resource type="Texture2D" uid="uid://bg47n2tmintm0" path="res://src/items/consumable/textures/past self remnant.PNG" id="1_3hy40"]
[ext_resource type="Script" uid="uid://vuavr681au06" path="res://src/items/accessory/BoxItemStats.cs" id="2_kb1l2"]
[resource]
script = ExtResource("2_kb1l2")
DamageToPlayer = 0
Name = "Furious Acquisition"
Description = "Contains a random weapon."
SpawnRate = 0.5
BonusAttack = 0
BonusDefense = 0
BonusLuck = 0.05
BonusHP = 0
BonusVT = 0
AeolicResistance = 0
TelluricResistance = 0
HydricResistance = 0
IgneousResistance = 0
FerrumResistance = 0
ThrowSpeed = 12.0
ThrowDamage = 5
ItemTag = 5
Texture = ExtResource("1_3hy40")
metadata/_custom_type_script = "uid://vuavr681au06"

View File

@@ -0,0 +1,26 @@
[gd_resource type="Resource" script_class="BoxItemStats" load_steps=3 format=3 uid="uid://icdlurnmjryh"]
[ext_resource type="Texture2D" uid="uid://bg47n2tmintm0" path="res://src/items/consumable/textures/past self remnant.PNG" id="1_svub6"]
[ext_resource type="Script" uid="uid://vuavr681au06" path="res://src/items/accessory/BoxItemStats.cs" id="2_iw3ll"]
[resource]
script = ExtResource("2_iw3ll")
DamageToPlayer = 0
Name = "Healthy Acquisition"
Description = "Contains a random restorative."
SpawnRate = 0.5
BonusAttack = 0
BonusDefense = 0
BonusLuck = 0.05
BonusHP = 0
BonusVT = 0
AeolicResistance = 0
TelluricResistance = 0
HydricResistance = 0
IgneousResistance = 0
FerrumResistance = 0
ThrowSpeed = 12.0
ThrowDamage = 5
ItemTag = 4
Texture = ExtResource("1_svub6")
metadata/_custom_type_script = "uid://vuavr681au06"

View File

@@ -0,0 +1,26 @@
[gd_resource type="Resource" script_class="BoxItemStats" load_steps=3 format=3 uid="uid://b2buq6ckkam7i"]
[ext_resource type="Texture2D" uid="uid://bg47n2tmintm0" path="res://src/items/consumable/textures/past self remnant.PNG" id="1_dwyk7"]
[ext_resource type="Script" uid="uid://vuavr681au06" path="res://src/items/accessory/BoxItemStats.cs" id="2_pssvy"]
[resource]
script = ExtResource("2_pssvy")
DamageToPlayer = 0
Name = "Identity Acquisition"
Description = "Contains a random mask."
SpawnRate = 0.5
BonusAttack = 0
BonusDefense = 0
BonusLuck = 0.05
BonusHP = 0
BonusVT = 0
AeolicResistance = 0
TelluricResistance = 0
HydricResistance = 0
IgneousResistance = 0
FerrumResistance = 0
ThrowSpeed = 12.0
ThrowDamage = 5
ItemTag = 9
Texture = ExtResource("1_dwyk7")
metadata/_custom_type_script = "uid://vuavr681au06"

View File

@@ -0,0 +1,26 @@
[gd_resource type="Resource" script_class="BoxItemStats" load_steps=3 format=3 uid="uid://dsb2gcjeme5yy"]
[ext_resource type="Texture2D" uid="uid://bg47n2tmintm0" path="res://src/items/consumable/textures/past self remnant.PNG" id="1_3scao"]
[ext_resource type="Script" uid="uid://vuavr681au06" path="res://src/items/accessory/BoxItemStats.cs" id="2_vgter"]
[resource]
script = ExtResource("2_vgter")
DamageToPlayer = 10
Name = "Malfunction"
Description = "Damages self."
SpawnRate = 0.5
BonusAttack = 0
BonusDefense = 0
BonusLuck = 0.05
BonusHP = 0
BonusVT = 0
AeolicResistance = 0
TelluricResistance = 0
HydricResistance = 0
IgneousResistance = 0
FerrumResistance = 0
ThrowSpeed = 12.0
ThrowDamage = 5
ItemTag = 3
Texture = ExtResource("1_3scao")
metadata/_custom_type_script = "uid://vuavr681au06"

View File

@@ -0,0 +1,26 @@
[gd_resource type="Resource" script_class="BoxItemStats" load_steps=3 format=3 uid="uid://cf8mf2qguf7q1"]
[ext_resource type="Texture2D" uid="uid://bg47n2tmintm0" path="res://src/items/consumable/textures/past self remnant.PNG" id="1_1eojb"]
[ext_resource type="Script" uid="uid://vuavr681au06" path="res://src/items/accessory/BoxItemStats.cs" id="2_ucc84"]
[resource]
script = ExtResource("2_ucc84")
DamageToPlayer = 0
Name = "Speculative Acquisition"
Description = "Contains a random box."
SpawnRate = 0.5
BonusAttack = 0
BonusDefense = 0
BonusLuck = 0.05
BonusHP = 0
BonusVT = 0
AeolicResistance = 0
TelluricResistance = 0
HydricResistance = 0
IgneousResistance = 0
FerrumResistance = 0
ThrowSpeed = 12.0
ThrowDamage = 5
ItemTag = 7
Texture = ExtResource("1_1eojb")
metadata/_custom_type_script = "uid://vuavr681au06"

View File

@@ -2,7 +2,7 @@
[ext_resource type="Script" uid="uid://da8mhruqpgh6r" path="res://src/items/misc/SetItem.cs" id="1_m8dyi"] [ext_resource type="Script" uid="uid://da8mhruqpgh6r" path="res://src/items/misc/SetItem.cs" id="1_m8dyi"]
[ext_resource type="AudioStream" uid="uid://bjcersd5id8ee" path="res://src/audio/sfx/ITEM_PLASTIQUETIMER.ogg" id="2_kgxna"] [ext_resource type="AudioStream" uid="uid://bjcersd5id8ee" path="res://src/audio/sfx/ITEM_PLASTIQUETIMER.ogg" id="2_kgxna"]
[ext_resource type="Texture2D" uid="uid://dkqs4x4pi18on" path="res://src/items/assetts/plastique_plastique.png" id="2_m8dyi"] [ext_resource type="Texture2D" uid="uid://dkqs4x4pi18on" path="res://src/items/assets/plastique_plastique.png" id="2_m8dyi"]
[sub_resource type="Animation" id="Animation_eat5q"] [sub_resource type="Animation" id="Animation_eat5q"]
length = 0.001 length = 0.001

View File

@@ -1,9 +1,7 @@
using Chickensoft.AutoInject; using Chickensoft.AutoInject;
using Chickensoft.GodotNodeInterfaces;
using Chickensoft.Introspection; using Chickensoft.Introspection;
using Chickensoft.Serialization; using Chickensoft.Serialization;
using Godot; using Godot;
using System;
using Zennysoft.Ma.Adapter; using Zennysoft.Ma.Adapter;
using Zennysoft.Ma.Adapter.Entity; using Zennysoft.Ma.Adapter.Entity;

View File

@@ -20,34 +20,34 @@ public partial class DungeonFloor : Node3D, IDungeonFloor
public void InitializeDungeon() public void InitializeDungeon()
{ {
Rooms = []; Rooms = [];
Rooms = FindAllDungeonRooms([.. GetChildren()], Rooms); Rooms = FindAllDungeonRooms([.. GetChildren()], Rooms);
_playerSpawnPoint = RandomizePlayerSpawnPoint(); _playerSpawnPoint = RandomizePlayerSpawnPoint();
} }
public void SpawnEnemies(DungeonFloorNode floorNode) public void SpawnEnemies(DungeonFloorNode floorNode)
{ {
var enemyOdds = new Godot.Collections.Dictionary<EnemyType, float> var enemyOdds = new Godot.Collections.Dictionary<EnemyType, float>
{ {
{ EnemyType.Sproingy, floorNode.Sproingy }, { EnemyType.Sproingy, floorNode.Sproingy },
{ EnemyType.Michael, floorNode.Michael }, { EnemyType.Michael, floorNode.Michael },
{ EnemyType.FilthEater, floorNode.FilthEater }, { EnemyType.FilthEater, floorNode.FilthEater },
{ EnemyType.Sara, floorNode.Sara }, { EnemyType.Sara, floorNode.Sara },
{ EnemyType.Ballos, floorNode.Ballos }, { EnemyType.Ballos, floorNode.Ballos },
{ EnemyType.Chariot, floorNode.Chariot }, { EnemyType.Chariot, floorNode.Chariot },
{ EnemyType.Chinthe, floorNode.Chinthe }, { EnemyType.Chinthe, floorNode.Chinthe },
{ EnemyType.AmbassadorGreen, floorNode.GreenAmbassador }, { EnemyType.AmbassadorGreen, floorNode.GreenAmbassador },
{ EnemyType.AmbassadorRed, floorNode.RedAmbassador }, { EnemyType.AmbassadorRed, floorNode.RedAmbassador },
{ EnemyType.AmbassadorSteel, floorNode.SteelAmbassador }, { EnemyType.AmbassadorSteel, floorNode.SteelAmbassador },
{ EnemyType.AgniDemon, floorNode.AgniDemon }, { EnemyType.AgniDemon, floorNode.AgniDemon },
{ EnemyType.AqueousDemon, floorNode.AqueosDemon }, { EnemyType.AqueousDemon, floorNode.AqueosDemon },
{ EnemyType.Palan, floorNode.Palan }, { EnemyType.Palan, floorNode.Palan },
{ EnemyType.ShieldOfHeaven, floorNode.ShieldOfHeaven }, { EnemyType.ShieldOfHeaven, floorNode.ShieldOfHeaven },
{ EnemyType.GoldSproingy, floorNode.GoldSproingy }, { EnemyType.GoldSproingy, floorNode.GoldSproingy },
}; };
var monsterRooms = Rooms.OfType<MonsterRoom>(); var monsterRooms = Rooms.OfType<MonsterRoom>();
foreach (var room in monsterRooms) foreach (var room in monsterRooms)
room.SpawnEnemies(enemyOdds); room.SpawnEnemies(enemyOdds);
} }
public (Vector3 Rotation, Vector3 Position) GetPlayerSpawnPoint() { return (_playerSpawnPoint.Rotation, new Vector3(_playerSpawnPoint.GlobalPosition.X, 0, _playerSpawnPoint.GlobalPosition.Z)); } public (Vector3 Rotation, Vector3 Position) GetPlayerSpawnPoint() { return (_playerSpawnPoint.Rotation, new Vector3(_playerSpawnPoint.GlobalPosition.X, 0, _playerSpawnPoint.GlobalPosition.Z)); }
@@ -55,25 +55,25 @@ public partial class DungeonFloor : Node3D, IDungeonFloor
private Marker3D RandomizePlayerSpawnPoint() private Marker3D RandomizePlayerSpawnPoint()
{ {
var randomSpawnLocations = Rooms var randomSpawnLocations = Rooms
.OfType<MonsterRoom>() .OfType<MonsterRoom>()
.Select(x => x.PlayerSpawn); .Select(x => x.PlayerSpawn);
var godotCollection = new Godot.Collections.Array<Marker3D>(randomSpawnLocations); var godotCollection = new Godot.Collections.Array<Marker3D>(randomSpawnLocations);
var result = godotCollection.PickRandom(); var result = godotCollection.PickRandom();
return result; return result;
} }
private static ImmutableList<IDungeonRoom> FindAllDungeonRooms(List<Node> nodesToSearch, ImmutableList<IDungeonRoom> roomsFound) private static ImmutableList<IDungeonRoom> FindAllDungeonRooms(List<Node> nodesToSearch, ImmutableList<IDungeonRoom> roomsFound)
{ {
if (nodesToSearch.Count == 0) if (nodesToSearch.Count == 0)
return roomsFound; return roomsFound;
foreach (var node in nodesToSearch) foreach (var node in nodesToSearch)
{ {
if (node is IDungeonRoom dungeonRoom) if (node is IDungeonRoom dungeonRoom)
roomsFound = roomsFound.Add(dungeonRoom); roomsFound = roomsFound.Add(dungeonRoom);
} }
return FindAllDungeonRooms([.. nodesToSearch.SelectMany(x => x.GetChildren())], roomsFound); return FindAllDungeonRooms([.. nodesToSearch.SelectMany(x => x.GetChildren())], roomsFound);
} }
} }

View File

@@ -28,47 +28,47 @@ public abstract partial class DungeonRoom : Node3D, IDungeonRoom
public void Setup() public void Setup()
{ {
_enemiesInRoom = []; _enemiesInRoom = [];
if (_room != null) if (_room != null)
{ {
_room.BodyEntered += Room_BodyEntered; _room.BodyEntered += Room_BodyEntered;
_room.BodyExited += Room_BodyExited; _room.BodyExited += Room_BodyExited;
} }
} }
private void Room_BodyExited(Node3D body) private void Room_BodyExited(Node3D body)
{ {
if (body is IEnemy enemy) if (body is IEnemy enemy)
_enemiesInRoom = _enemiesInRoom.Remove(enemy); _enemiesInRoom = _enemiesInRoom.Remove(enemy);
if (body is IPlayer) if (body is IPlayer)
_isPlayerInRoom = false; _isPlayerInRoom = false;
} }
private void Room_BodyEntered(Node3D body) private void Room_BodyEntered(Node3D body)
{ {
if (body is IEnemy enemy) if (body is IEnemy enemy)
_enemiesInRoom = _enemiesInRoom.Add(enemy); _enemiesInRoom = _enemiesInRoom.Add(enemy);
if (body is IPlayer) if (body is IPlayer)
if (_playerDiscoveredRoom) if (_playerDiscoveredRoom)
_isPlayerInRoom = true; _isPlayerInRoom = true;
else else
OnPlayerDiscoveringRoom(); OnPlayerDiscoveringRoom();
} }
public ImmutableList<IEnemy> GetEnemiesInCurrentRoom() public ImmutableList<IEnemy> GetEnemiesInCurrentRoom()
{ {
return _enemiesInRoom; return _enemiesInRoom;
} }
private void OnPlayerDiscoveringRoom() private void OnPlayerDiscoveringRoom()
{ {
_isPlayerInRoom = true; _isPlayerInRoom = true;
_playerDiscoveredRoom = true; _playerDiscoveredRoom = true;
MinimapShadow.Hide(); MinimapShadow.Hide();
} }
public void OnExitTree() public void OnExitTree()
{ {
_room.BodyEntered -= Room_BodyEntered; _room.BodyEntered -= Room_BodyEntered;
_room.BodyExited -= Room_BodyExited; _room.BodyExited -= Room_BodyExited;
} }
} }

View File

@@ -1,8 +1,9 @@
[gd_scene load_steps=18 format=3 uid="uid://dl6h1djc27ddl"] [gd_scene load_steps=19 format=3 uid="uid://dl6h1djc27ddl"]
[ext_resource type="Script" uid="uid://c1nhqlem1ew3m" path="res://src/map/dungeon/code/Altar.cs" id="1_5jip8"] [ext_resource type="Script" uid="uid://c1nhqlem1ew3m" path="res://src/map/dungeon/code/Altar.cs" id="1_5jip8"]
[ext_resource type="Resource" uid="uid://bqnfw6r4085yv" path="res://src/dialog/Altar.dialogue" id="2_7xfp0"] [ext_resource type="Resource" uid="uid://bqnfw6r4085yv" path="res://src/dialog/Altar.dialogue" id="2_7xfp0"]
[ext_resource type="PackedScene" uid="uid://co0fmuno2pjc7" path="res://src/map/dungeon/models/Special Floors & Rooms/Altar/02_ALTAR_FLOOR_ZER0_VER.1.glb" id="2_xpi6o"] [ext_resource type="PackedScene" uid="uid://co0fmuno2pjc7" path="res://src/map/dungeon/models/Special Floors & Rooms/Altar/02_ALTAR_FLOOR_ZER0_VER.1.glb" id="2_xpi6o"]
[ext_resource type="PackedScene" uid="uid://bdygmhgk4k0qh" path="res://src/items/box/BoxItem.tscn" id="6_rrmfo"]
[ext_resource type="Shader" uid="uid://c4a68uhm5o2h4" path="res://src/map/map shaders/Altar Sky Environment.gdshader" id="27_lb4gb"] [ext_resource type="Shader" uid="uid://c4a68uhm5o2h4" path="res://src/map/map shaders/Altar Sky Environment.gdshader" id="27_lb4gb"]
[ext_resource type="AudioStream" uid="uid://c4ud110da8efp" path="res://src/audio/AMB/amb_wind_loop_altar.wav" id="28_je2oh"] [ext_resource type="AudioStream" uid="uid://c4ud110da8efp" path="res://src/audio/AMB/amb_wind_loop_altar.wav" id="28_je2oh"]
@@ -212,3 +213,5 @@ collision_mask = 64
[node name="CollisionShape3D" type="CollisionShape3D" parent="NoExitArea"] [node name="CollisionShape3D" type="CollisionShape3D" parent="NoExitArea"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 72.5243, -2.06593, -2.02953) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 72.5243, -2.06593, -2.02953)
shape = SubResource("BoxShape3D_tp2pi") shape = SubResource("BoxShape3D_tp2pi")
[node name="Box Item" parent="." instance=ExtResource("6_rrmfo")]

View File

@@ -2,9 +2,9 @@
[ext_resource type="Script" uid="uid://cuhfkyh3d7noa" path="res://src/map/dungeon/code/Overworld.cs" id="1_5hmt3"] [ext_resource type="Script" uid="uid://cuhfkyh3d7noa" path="res://src/map/dungeon/code/Overworld.cs" id="1_5hmt3"]
[ext_resource type="Texture2D" uid="uid://co6h8vyi11sl2" path="res://src/map/overworld/Models/Overworld_CLOUD_RINGS_INNER_63.png" id="2_g6b7b"] [ext_resource type="Texture2D" uid="uid://co6h8vyi11sl2" path="res://src/map/overworld/Models/Overworld_CLOUD_RINGS_INNER_63.png" id="2_g6b7b"]
[ext_resource type="AudioStream" uid="uid://dqmsaok6fyhe7" path="res://src/audio/AMB/amb_perlin.wav" id="2_wbbo3"] [ext_resource type="AudioStream" uid="uid://dv045ax11vybl" path="res://src/audio/AMB/amb_perlin.wav" id="2_wbbo3"]
[ext_resource type="AudioStream" uid="uid://dl07vg00se7hd" path="res://src/audio/AMB/amb_white_noise.wav" id="3_c2gp5"] [ext_resource type="AudioStream" uid="uid://dsc8xu78llst6" path="res://src/audio/AMB/amb_white_noise.wav" id="3_c2gp5"]
[ext_resource type="AudioStream" uid="uid://boypvgaweep8a" path="res://src/audio/AMB/amb_beach.wav" id="3_pvi8n"] [ext_resource type="AudioStream" uid="uid://7hb71ilkd7qh" path="res://src/audio/AMB/amb_beach.wav" id="3_pvi8n"]
[ext_resource type="Texture2D" uid="uid://w33fr6exryiy" path="res://src/map/overworld/Models/Overworld_CLOUD_RINGS_INNER_37.png" id="3_uyygh"] [ext_resource type="Texture2D" uid="uid://w33fr6exryiy" path="res://src/map/overworld/Models/Overworld_CLOUD_RINGS_INNER_37.png" id="3_uyygh"]
[ext_resource type="Texture2D" uid="uid://dv10yaqvp3mub" path="res://src/map/overworld/Models/Overworld_CLOUD_RINGS_INNER_71.png" id="4_r8r3k"] [ext_resource type="Texture2D" uid="uid://dv10yaqvp3mub" path="res://src/map/overworld/Models/Overworld_CLOUD_RINGS_INNER_71.png" id="4_r8r3k"]
[ext_resource type="Shader" uid="uid://brhf7s3riyag5" path="res://src/map/map shaders/Metal.gdshader" id="5_d1qcb"] [ext_resource type="Shader" uid="uid://brhf7s3riyag5" path="res://src/map/map shaders/Metal.gdshader" id="5_d1qcb"]

View File

@@ -94,6 +94,7 @@ public partial class Player : CharacterBody3D, IPlayer, IProvide<IPlayer>
#endregion #endregion
public bool CanEquipState { get; set; } = true;
private bool flipAttack = false; private bool flipAttack = false;
@@ -101,6 +102,8 @@ public partial class Player : CharacterBody3D, IPlayer, IProvide<IPlayer>
private bool _healthTimerActive = true; private bool _healthTimerActive = true;
private bool _debugSprint = false;
private float _knockbackStrength = 0.0f; private float _knockbackStrength = 0.0f;
private Vector3 _knockbackDirection = Vector3.Zero; private Vector3 _knockbackDirection = Vector3.Zero;
@@ -241,9 +244,9 @@ public partial class Player : CharacterBody3D, IPlayer, IProvide<IPlayer>
if (@event.IsActionPressed(GameInputs.Attack)) if (@event.IsActionPressed(GameInputs.Attack))
Attack(); Attack();
if (@event.IsActionPressed(GameInputs.Sprint)) if (@event.IsActionPressed(GameInputs.Sprint))
Settings.MoveSpeed *= 2; _debugSprint = true;
if (@event.IsActionReleased(GameInputs.Sprint)) else if (@event.IsActionReleased(GameInputs.Sprint))
Settings.MoveSpeed /= 2; _debugSprint = false;
} }
public void PlayTestAnimation() public void PlayTestAnimation()
@@ -349,6 +352,8 @@ public partial class Player : CharacterBody3D, IPlayer, IProvide<IPlayer>
transform.Basis = new Basis(Vector3.Up, Settings.RotationSpeed * -rawInput.X * delta) * transform.Basis; transform.Basis = new Basis(Vector3.Up, Settings.RotationSpeed * -rawInput.X * delta) * transform.Basis;
var moveDirection = new Vector3(strafeRightInput - strafeLeftInput, 0, rawInput.Z).Normalized(); var moveDirection = new Vector3(strafeRightInput - strafeLeftInput, 0, rawInput.Z).Normalized();
var velocity = Basis * moveDirection * Settings.MoveSpeed * Settings.Acceleration; var velocity = Basis * moveDirection * Settings.MoveSpeed * Settings.Acceleration;
if (_debugSprint)
velocity *= 2;
_knockbackStrength *= 0.9f; _knockbackStrength *= 0.9f;
Transform = Transform with { Basis = transform.Basis }; Transform = Transform with { Basis = transform.Basis };
Velocity = velocity + (_knockbackDirection * _knockbackStrength); Velocity = velocity + (_knockbackDirection * _knockbackStrength);

View File

@@ -411,7 +411,7 @@ tracks/0/loop_wrap = true
tracks/0/keys = { tracks/0/keys = {
"times": PackedFloat32Array(0), "times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1), "transitions": PackedFloat32Array(1),
"update": 0, "update": 1,
"values": [&"default"] "values": [&"default"]
} }
tracks/1/type = "value" tracks/1/type = "value"

View File

@@ -60,146 +60,141 @@ public partial class InventoryMenu : Control, IInventoryMenu
private IItemSlot _currentlySelectedItem = null; private IItemSlot _currentlySelectedItem = null;
private bool _enableMenuSound = false; private bool _enableMenuSound = false;
public override void _EnterTree()
{
SetProcessInput(false);
}
public void OnResolved() public void OnResolved()
{ {
ItemSlots = [ItemSlot1, ItemSlot2, ItemSlot3, ItemSlot4, ItemSlot5, ItemSlot6, ItemSlot7, ItemSlot8, ItemSlot9, ItemSlot10, ItemSlot11, ItemSlot12, ItemSlot13, ItemSlot14, ItemSlot15, ItemSlot16, ItemSlot17, ItemSlot18, ItemSlot19, ItemSlot20]; ItemSlots = [ItemSlot1, ItemSlot2, ItemSlot3, ItemSlot4, ItemSlot5, ItemSlot6, ItemSlot7, ItemSlot8, ItemSlot9, ItemSlot10, ItemSlot11, ItemSlot12, ItemSlot13, ItemSlot14, ItemSlot15, ItemSlot16, ItemSlot17, ItemSlot18, ItemSlot19, ItemSlot20];
_currentlySelectedItem = ItemSlot1; _currentlySelectedItem = ItemSlot1;
foreach (var item in ItemSlots) foreach (var item in ItemSlots)
{ {
item.ItemPressed += Item_Pressed; item.ItemPressed += Item_Pressed;
item.ItemEnterFocus += Item_FocusEntered; item.ItemEnterFocus += Item_FocusEntered;
item.ItemExitFocus += Item_ItemExitFocus; item.ItemExitFocus += Item_ItemExitFocus;
} }
_player.AttackComponent.CurrentAttack.Sync += Attack_Sync; _player.AttackComponent.CurrentAttack.Sync += Attack_Sync;
_player.AttackComponent.MaximumAttack.Sync += Attack_Sync; _player.AttackComponent.MaximumAttack.Sync += Attack_Sync;
_player.DefenseComponent.CurrentDefense.Sync += Defense_Sync; _player.DefenseComponent.CurrentDefense.Sync += Defense_Sync;
_player.DefenseComponent.MaximumDefense.Sync += Defense_Sync; _player.DefenseComponent.MaximumDefense.Sync += Defense_Sync;
_player.EquipmentComponent.EquipmentChanged += EquipmentComponent_EquipmentChanged; _player.EquipmentComponent.EquipmentChanged += EquipmentComponent_EquipmentChanged;
_player.Inventory.InventoryChanged += Inventory_InventoryChanged; _player.Inventory.InventoryChanged += Inventory_InventoryChanged;
UseButton.Pressed += UseButtonPressed; UseButton.Pressed += UseButtonPressed;
ThrowButton.Pressed += ThrowButtonPressed; ThrowButton.Pressed += ThrowButtonPressed;
DropButton.Pressed += DropButtonPressed; DropButton.Pressed += DropButtonPressed;
UseButton.FocusEntered += ActionButtonFocusChanged; UseButton.FocusEntered += ActionButtonFocusChanged;
ThrowButton.FocusEntered += ActionButtonFocusChanged; ThrowButton.FocusEntered += ActionButtonFocusChanged;
DropButton.FocusEntered += ActionButtonFocusChanged; DropButton.FocusEntered += ActionButtonFocusChanged;
VisibilityChanged += InventoryMenu_VisibilityChanged; VisibilityChanged += InventoryMenu_VisibilityChanged;
SetProcessUnhandledInput(false);
} }
private void ActionButtonFocusChanged() private void ActionButtonFocusChanged()
{ {
if (!_enableMenuSound) if (!_enableMenuSound)
SfxDatabase.Instance.Play(SoundEffect.MoveUI); SfxDatabase.Instance.Play(SoundEffect.MoveUI);
} }
public override void _UnhandledInput(InputEvent @event) public override void _UnhandledInput(InputEvent @event)
{ {
if (!Visible) if ((!Input.IsActionJustPressed(GameInputs.UiUp) && Input.IsActionPressed(GameInputs.UiUp)) || (!Input.IsActionJustPressed(GameInputs.UiDown) && Input.IsActionPressed(GameInputs.UiDown)))
return; AcceptEvent();
if ((!Input.IsActionJustPressed(GameInputs.UiUp) && Input.IsActionPressed(GameInputs.UiUp)) || (!Input.IsActionJustPressed(GameInputs.UiDown) && Input.IsActionPressed(GameInputs.UiDown))) if (Input.IsActionJustPressed(GameInputs.UiCancel) && (UseItemPrompt.Visible))
AcceptEvent(); {
SfxDatabase.Instance.Play(SoundEffect.CancelUI);
AcceptEvent();
HideUserActionPrompt();
}
else if (Input.IsActionJustPressed(GameInputs.UiCancel))
{
SfxDatabase.Instance.Play(SoundEffect.CancelUI);
AcceptEvent();
_gameRepo.CloseInventory();
}
if (Input.IsActionJustPressed(GameInputs.UiCancel) && (UseButton.HasFocus() || DropButton.HasFocus() || ThrowButton.HasFocus())) if (Input.IsActionJustPressed(GameInputs.InventorySort))
{ {
SfxDatabase.Instance.Play(SoundEffect.CancelUI); var isChanged = _player.Inventory.Sort(_player.EquipmentComponent.EquippedWeapon.Value, _player.EquipmentComponent.EquippedArmor.Value, _player.EquipmentComponent.EquippedAccessory.Value);
AcceptEvent(); if (!isChanged)
HideUserActionPrompt(); return;
}
else if (Input.IsActionJustPressed(GameInputs.UiCancel))
{
SfxDatabase.Instance.Play(SoundEffect.CancelUI);
AcceptEvent();
_gameRepo.CloseInventory();
}
if (Input.IsActionJustPressed(GameInputs.InventorySort)) SfxDatabase.Instance.Play(SoundEffect.SortInventory);
{ Inventory_InventoryChanged();
var isChanged = _player.Inventory.Sort(_player.EquipmentComponent.EquippedWeapon.Value, _player.EquipmentComponent.EquippedArmor.Value, _player.EquipmentComponent.EquippedAccessory.Value); foreach (var slot in ItemSlots)
if (!isChanged) slot.SetItemStyle();
return; Item_ItemExitFocus(_currentlySelectedItem);
_currentlySelectedItem = ItemSlot1;
SfxDatabase.Instance.Play(SoundEffect.SortInventory); _currentlySelectedItem.GrabFocus();
Inventory_InventoryChanged(); }
foreach (var slot in ItemSlots)
slot.SetItemStyle();
Item_ItemExitFocus(_currentlySelectedItem);
_currentlySelectedItem = ItemSlot1;
_currentlySelectedItem.GrabFocus();
}
} }
private void InventoryMenu_VisibilityChanged() private void InventoryMenu_VisibilityChanged()
{ {
if (Visible) if (Visible)
{ {
SfxDatabase.Instance.Play(SoundEffect.OpenInventory); SetProcessUnhandledInput(true);
_currentlySelectedItem.GrabFocus(); SfxDatabase.Instance.Play(SoundEffect.OpenInventory);
_enableMenuSound = true; _currentlySelectedItem.GrabFocus();
} _enableMenuSound = true;
else }
{ else
SfxDatabase.Instance.Play(SoundEffect.CancelUI); {
_enableMenuSound = false; SetProcessUnhandledInput(false);
} SfxDatabase.Instance.Play(SoundEffect.CancelUI);
_enableMenuSound = false;
}
} }
private void Item_ItemExitFocus(IItemSlot itemSlot) private void Item_ItemExitFocus(IItemSlot itemSlot)
{ {
ItemDescriptionTitle.Text = string.Empty; ItemDescriptionTitle.Text = string.Empty;
ItemEffectLabel.Text = string.Empty; ItemEffectLabel.Text = string.Empty;
itemSlot.IsSelected = false; itemSlot.IsSelected = false;
itemSlot.SetItemStyle(); itemSlot.SetItemStyle();
} }
private void Item_FocusEntered(IItemSlot itemSlot) private void Item_FocusEntered(IItemSlot itemSlot)
{ {
if (itemSlot.Item.Value == null) if (itemSlot.Item.Value == null)
return; return;
if (_enableMenuSound) if (_enableMenuSound)
SfxDatabase.Instance.Play(SoundEffect.MoveUI); SfxDatabase.Instance.Play(SoundEffect.MoveUI);
ItemDescriptionTitle.Text = $"{itemSlot.Item.Value.ItemName}"; ItemDescriptionTitle.Text = $"{itemSlot.Item.Value.ItemName}";
ItemEffectLabel.Text = $"{itemSlot.Item.Value.Description}"; ItemEffectLabel.Text = $"{itemSlot.Item.Value.Description}";
_currentlySelectedItem = itemSlot; _currentlySelectedItem = itemSlot;
itemSlot.IsSelected = true; itemSlot.IsSelected = true;
itemSlot.SetItemStyle(); itemSlot.SetItemStyle();
AcceptEvent(); AcceptEvent();
} }
private void Item_Pressed(InventoryItem item) => DisplayUserActionPrompt(item); private void Item_Pressed(InventoryItem item) => DisplayUserActionPrompt(item);
private async void Inventory_InventoryChanged() private async void Inventory_InventoryChanged()
{ {
foreach (var slot in ItemSlots) foreach (var slot in ItemSlots)
{ {
slot.Visible = false; slot.Visible = false;
slot.SetItemStyle(); slot.SetItemStyle();
} }
var itemsToDisplay = _player.Inventory.Items; var itemsToDisplay = _player.Inventory.Items;
for (var i = 0; i < itemsToDisplay.Count; i++) for (var i = 0; i < itemsToDisplay.Count; i++)
{ {
ItemSlots[i].Item.OnNext(itemsToDisplay[i]); ItemSlots[i].Item.OnNext(itemsToDisplay[i]);
ItemSlots[i].Visible = true; ItemSlots[i].Visible = true;
} }
if (!_player.Inventory.Items.Contains(_currentlySelectedItem.Item.Value)) if (!_player.Inventory.Items.Contains(_currentlySelectedItem.Item.Value))
{ {
_currentlySelectedItem.Item.OnNext(null); _currentlySelectedItem.Item.OnNext(null);
var elementToSelect = Mathf.Max(0, ItemSlots.IndexOf(_currentlySelectedItem) - 1); var elementToSelect = Mathf.Max(0, ItemSlots.IndexOf(_currentlySelectedItem) - 1);
_currentlySelectedItem = ItemSlots.ElementAt(elementToSelect); _currentlySelectedItem = ItemSlots.ElementAt(elementToSelect);
_currentlySelectedItem.GrabFocus(); _currentlySelectedItem.GrabFocus();
} }
} }
private void Attack_Sync(int obj) => ATKValue.Text = $"{_player.AttackComponent.CurrentAttack.Value}/{_player.AttackComponent.MaximumAttack.Value}"; private void Attack_Sync(int obj) => ATKValue.Text = $"{_player.AttackComponent.CurrentAttack.Value}/{_player.AttackComponent.MaximumAttack.Value}";
@@ -207,125 +202,128 @@ public partial class InventoryMenu : Control, IInventoryMenu
private void EquipmentComponent_EquipmentChanged(EquipableItem equipableItem) private void EquipmentComponent_EquipmentChanged(EquipableItem equipableItem)
{ {
ATKBonusLabel.Text = $"{_player.EquipmentComponent.BonusAttack:+0;-#;\\.\\.\\.}"; ATKBonusLabel.Text = $"{_player.EquipmentComponent.BonusAttack:+0;-#;\\.\\.\\.}";
DEFBonusLabel.Text = $"{_player.EquipmentComponent.BonusDefense:+0;-#;\\.\\.\\.}"; DEFBonusLabel.Text = $"{_player.EquipmentComponent.BonusDefense:+0;-#;\\.\\.\\.}";
} }
private async void UseButtonPressed() private async void UseButtonPressed()
{ {
UseButton.Disabled = true; UseButton.Disabled = true;
if (_currentlySelectedItem.Item.Value is EquipableItem equipable) if (_currentlySelectedItem.Item.Value is EquipableItem equipable)
await EquipOrUnequipItem(equipable); await EquipOrUnequipItem(equipable);
else if (_currentlySelectedItem.Item.Value is Plastique plastique) else if (_currentlySelectedItem.Item.Value is Plastique plastique)
SetItem(); SetItem();
else else
await _game.UseItem(_currentlySelectedItem.Item.Value); await _game.UseItem(_currentlySelectedItem.Item.Value);
UseButton.Disabled = false; UseButton.Disabled = false;
HideUserActionPrompt(); HideUserActionPrompt();
await ShowInventoryInfo(); await ShowInventoryInfo();
await ToSignal(GetTree().CreateTimer(1f), "timeout"); await ToSignal(GetTree().CreateTimer(1f), "timeout");
} }
private async void SetItem() private async void SetItem()
{ {
_game.SetItem(_currentlySelectedItem.Item.Value); _game.SetItem(_currentlySelectedItem.Item.Value);
_player.Inventory.Remove(_currentlySelectedItem.Item.Value); _player.Inventory.Remove(_currentlySelectedItem.Item.Value);
HideUserActionPrompt(); HideUserActionPrompt();
await ShowInventoryInfo(); await ShowInventoryInfo();
_gameRepo.CloseInventory(); _gameRepo.CloseInventory();
} }
private async void ThrowButtonPressed() private async void ThrowButtonPressed()
{ {
_game.ThrowItem(_currentlySelectedItem.Item.Value); _game.ThrowItem(_currentlySelectedItem.Item.Value);
_player.Inventory.Remove(_currentlySelectedItem.Item.Value); _player.Inventory.Remove(_currentlySelectedItem.Item.Value);
HideUserActionPrompt(); HideUserActionPrompt();
await ShowInventoryInfo(); await ShowInventoryInfo();
_gameRepo.CloseInventory(); _gameRepo.CloseInventory();
} }
private async void DropButtonPressed() private async void DropButtonPressed()
{ {
_game.DropItem(_currentlySelectedItem.Item.Value); _game.DropItem(_currentlySelectedItem.Item.Value);
_player.Inventory.Remove(_currentlySelectedItem.Item.Value); _player.Inventory.Remove(_currentlySelectedItem.Item.Value);
HideUserActionPrompt(); HideUserActionPrompt();
await ShowInventoryInfo(); await ShowInventoryInfo();
} }
private void DisplayUserActionPrompt(InventoryItem item) private void DisplayUserActionPrompt(InventoryItem item)
{ {
SfxDatabase.Instance.Play(SoundEffect.SelectUI); SfxDatabase.Instance.Play(SoundEffect.SelectUI);
ItemDescriptionTitle.Hide(); ItemDescriptionTitle.Hide();
ItemEffectLabel.Hide(); ItemEffectLabel.Hide();
UseItemPrompt.Show(); UseItemPrompt.Show();
UseButton.Show(); UseButton.Show();
ThrowButton.Show(); ThrowButton.Show();
DropButton.Show(); DropButton.Show();
if (item is EquipableItem equipable) if (item is EquipableItem equipable)
{ {
var isItemEquipped = _player.EquipmentComponent.IsItemEquipped(equipable); var isItemEquipped = _player.EquipmentComponent.IsItemEquipped(equipable);
UseButton.Text = isItemEquipped ? "Unequip" : "Equip"; UseButton.Text = isItemEquipped ? "Unequip" : "Equip";
ThrowButton.Disabled = isItemEquipped; ThrowButton.Disabled = isItemEquipped;
ThrowButton.FocusMode = isItemEquipped ? FocusModeEnum.None : FocusModeEnum.All; ThrowButton.FocusMode = isItemEquipped ? FocusModeEnum.None : FocusModeEnum.All;
DropButton.Disabled = isItemEquipped; DropButton.Disabled = isItemEquipped;
DropButton.FocusMode = isItemEquipped ? FocusModeEnum.None : FocusModeEnum.All; DropButton.FocusMode = isItemEquipped ? FocusModeEnum.None : FocusModeEnum.All;
}
else if (item is Plastique plastique)
{
UseButton.Text = "Set";
}
else
{
UseButton.Text = "Use";
}
UseButton.GrabFocus(); UseButton.GrabFocus();
_enableMenuSound = false;
if (!_player.CanEquipState && isItemEquipped)
UseButton.Disabled = true;
}
else if (item is Plastique plastique)
{
UseButton.Text = "Set";
}
else
{
UseButton.Text = "Use";
}
_enableMenuSound = false;
} }
private void HideUserActionPrompt() private void HideUserActionPrompt()
{ {
UseItemPrompt.Hide(); UseItemPrompt.Hide();
UseButton.Hide(); UseButton.Hide();
ThrowButton.Hide(); ThrowButton.Hide();
DropButton.Hide(); DropButton.Hide();
UseButton.ReleaseFocus(); UseButton.ReleaseFocus();
ThrowButton.ReleaseFocus(); ThrowButton.ReleaseFocus();
DropButton.ReleaseFocus(); DropButton.ReleaseFocus();
_currentlySelectedItem.GrabFocus(); _currentlySelectedItem.GrabFocus();
_enableMenuSound = true; _enableMenuSound = true;
} }
private async Task EquipOrUnequipItem(EquipableItem equipable) private async Task EquipOrUnequipItem(EquipableItem equipable)
{ {
if (_player.EquipmentComponent.IsItemEquipped(equipable)) if (_player.EquipmentComponent.IsItemEquipped(equipable))
{ {
SfxDatabase.Instance.Play(SoundEffect.Unequip); SfxDatabase.Instance.Play(SoundEffect.Unequip);
ItemEffectLabel.Text = $"{equipable.GetType().Name} unequipped."; ItemEffectLabel.Text = $"{equipable.GetType().Name} unequipped.";
_player.Unequip(equipable); _player.Unequip(equipable);
} }
else else
{ {
SfxDatabase.Instance.Play(SoundEffect.Equip); SfxDatabase.Instance.Play(SoundEffect.Equip);
var itemSlot = _currentlySelectedItem; var itemSlot = _currentlySelectedItem;
ItemEffectLabel.Text = $"{equipable.GetType().Name} equipped."; ItemEffectLabel.Text = $"{equipable.GetType().Name} equipped.";
_player.Equip(equipable); _player.Equip(equipable);
_currentlySelectedItem = itemSlot; _currentlySelectedItem = itemSlot;
} }
} }
private async Task ShowInventoryInfo() private async Task ShowInventoryInfo()
{ {
ItemDescriptionTitle.Show(); ItemDescriptionTitle.Show();
ItemEffectLabel.Show(); ItemEffectLabel.Show();
} }
private enum InventoryPageNumber private enum InventoryPageNumber
{ {
FirstPage, FirstPage,
SecondPage SecondPage
} }
} }

View File

@@ -62,12 +62,6 @@ public partial class LoadNextLevel : Control, IFloorClearMenu
ExitButton.Pressed += ExitButton_Pressed; ExitButton.Pressed += ExitButton_Pressed;
} }
public override void _Input(InputEvent @event)
{
if (_fadingIn)
GetViewport().SetInputAsHandled();
}
private void CurrentFloorNumber_Sync(int _) => FloorNumber.Text = _map.CurrentFloorNumber.Value.ToString("D2"); private void CurrentFloorNumber_Sync(int _) => FloorNumber.Text = _map.CurrentFloorNumber.Value.ToString("D2");
private void EquipmentComponent_EquipmentChanged(EquipableItem obj) private void EquipmentComponent_EquipmentChanged(EquipableItem obj)

View File

@@ -101,7 +101,7 @@ public partial class PauseDebugMenu : Control, IDebugMenu
{ {
var enemyToSpawn = _spawnableEnemies.ElementAt((int)index); var enemyToSpawn = _spawnableEnemies.ElementAt((int)index);
var loadedEnemy = GD.Load<PackedScene>(enemyToSpawn).Instantiate<Enemy>(); var loadedEnemy = GD.Load<PackedScene>(enemyToSpawn).Instantiate<Enemy>();
AddChild(loadedEnemy); _game.AddChild(loadedEnemy);
loadedEnemy.GlobalPosition = new Vector3(_player.GlobalPosition.X, _player.GlobalPosition.Y + 1, _player.GlobalPosition.Z) + (-_player.GlobalBasis.Z * 2); loadedEnemy.GlobalPosition = new Vector3(_player.GlobalPosition.X, _player.GlobalPosition.Y + 1, _player.GlobalPosition.Z) + (-_player.GlobalBasis.Z * 2);
} }
@@ -109,7 +109,7 @@ public partial class PauseDebugMenu : Control, IDebugMenu
{ {
var itemToSpawn = _spawnableItems.ElementAt((int)index); var itemToSpawn = _spawnableItems.ElementAt((int)index);
var duplicated = itemToSpawn.Duplicate((int)DuplicateFlags.UseInstantiation) as Node3D; var duplicated = itemToSpawn.Duplicate((int)DuplicateFlags.UseInstantiation) as Node3D;
AddChild(duplicated); _game.AddChild(duplicated);
duplicated.GlobalPosition = new Vector3(_player.GlobalPosition.X, _player.GlobalPosition.Y + 1, _player.GlobalPosition.Z) + (-_player.GlobalBasis.Z * 2); duplicated.GlobalPosition = new Vector3(_player.GlobalPosition.X, _player.GlobalPosition.Y + 1, _player.GlobalPosition.Z) + (-_player.GlobalBasis.Z * 2);
} }