Partially implementation of box items

This commit is contained in:
2026-02-04 22:30:10 -08:00
parent 13ebe54474
commit d45bc67722
14 changed files with 489 additions and 245 deletions

View File

@@ -435,6 +435,32 @@ public partial class Game : Node3D, IGame
{ {
case ItemTag.DamagesPlayer: case ItemTag.DamagesPlayer:
_effectService.DamagesPlayer(boxItem.Stats.DamageToPlayer); _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; 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;
@@ -247,11 +248,8 @@ public class EffectService
itemReroller.RerollItem(itemToReroll, _player.Inventory); itemReroller.RerollItem(itemToReroll, _player.Inventory);
} }
public void GetRandomItemOfType<T>(T itemToExclude = null) public T GetRandomItemOfType<T>(T itemToExclude = null)
where T : InventoryItem where T : InventoryItem => ItemDatabase.Instance.PickItem(itemToExclude);
{
_player.Inventory.TryAdd(ItemDatabase.Instance.PickItem(itemToExclude));
}
public void RandomSpell() public void RandomSpell()
{ {
@@ -265,16 +263,14 @@ public class EffectService
_player.Inventory.TryAdd(ItemDatabase.Instance.PickRareItem<T>()); _player.Inventory.TryAdd(ItemDatabase.Instance.PickRareItem<T>());
} }
public void TradeRandomItem(BoxItem box) public void TradeRandomItem<T>(BoxItem box)
where T : InventoryItem
{ {
if (_player.Inventory.Items.Count == 1) var tradableItems = _player.Inventory.Items.OfType<T>().Where(x => x != box).ToList();
return;
var tradableItems = _player.Inventory.Items.Where(x => x != box).ToList();
var rng = new RandomNumberGenerator(); var rng = new RandomNumberGenerator();
rng.Randomize(); rng.Randomize();
var randomIndex = rng.RandiRange(0, _player.Inventory.Items.Count - 1); var randomIndex = rng.RandiRange(0, tradableItems.Count - 1);
var randomItem = tradableItems[randomIndex]; var randomItem = tradableItems[randomIndex];
if (randomItem is EquipableItem equipableItem) if (randomItem is EquipableItem equipableItem)
{ {
@@ -283,14 +279,18 @@ public class EffectService
} }
_player.Inventory.Remove(randomItem); _player.Inventory.Remove(randomItem);
GetRandomItemOfType<InventoryItem>(box); GetRandomItemOfType<T>();
} }
public void TradeAllRandomItems(BoxItem box) public IEnumerable<InventoryItem> TradeAllRandomItems<T>(BoxItem box)
where T : InventoryItem
{ {
var tradableItems = _player.Inventory.Items.Where(x => x != box); var newInventory = new List<InventoryItem>();
foreach (var item in tradableItems) var items = _player.Inventory.Items.OfType<T>().Where(x => x != box).ToList();
TradeRandomItem(box); foreach (var item in items)
newInventory.Add(GetRandomItemOfType<T>());
return newInventory;
} }
public void GetUnobtainedItem() public void GetUnobtainedItem()

View File

@@ -19,32 +19,32 @@ 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; var itemsToSelectFrom = Items.OfType<T>();
return PickItemInternal(itemsToSelectFrom, itemToExclude); return PickItemInternal(itemsToSelectFrom, itemToExclude);
} }
public T PickRareItem<T>(T itemToExclude = null) public T PickRareItem<T>(T itemToExclude = null)
where T : InventoryItem where T : InventoryItem
{ {
var getRareItems = Items.Where(x => x.SpawnRate < 0.1f); var getRareItems = Items.OfType<T>().Where(x => x.SpawnRate < 0.1f);
return PickItemInternal(getRareItems, itemToExclude); return PickItemInternal(getRareItems, itemToExclude);
} }
public T PickBasicItem<T>(T itemToExclude = null) public T PickBasicItem<T>(T itemToExclude = null)
where T : InventoryItem where T : InventoryItem
{ {
var getBasicItems = Items.Where(x => x.SpawnRate > 0.5f); var getBasicItems = Items.OfType<T>().Where(x => x.SpawnRate > 0.5f);
return PickItemInternal(getBasicItems, itemToExclude); return PickItemInternal(getBasicItems, itemToExclude);
} }
private T PickItemInternal<T>(IEnumerable<InventoryItem> itemsToSelectFrom, T itemToExclude = null) private T PickItemInternal<T>(IEnumerable<T> itemsToSelectFrom, T itemToExclude = null)
where T : InventoryItem where T : InventoryItem
{ {
var rng = new RandomNumberGenerator(); var rng = new RandomNumberGenerator();
rng.Randomize(); rng.Randomize();
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)];
@@ -52,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()
@@ -64,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)
{ {
@@ -119,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

@@ -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,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,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"]