Fixed all the bugs that prevented the game from working, added static item registration on startup
阻碍游戏运行的bug已尽数修复,添加启动时的静态物品注册
This commit is contained in:
parent
16a2d40501
commit
94a2e78efc
|
@ -1,3 +1,3 @@
|
||||||
id,zh,en,ja
|
id,zh,en,ja
|
||||||
staff_of_the_undead,死灵法杖,StaffOfTheUndead,ネクロポリスの杖です
|
item_staff_of_the_undead,死灵法杖,StaffOfTheUndead,ネクロポリスの杖です
|
||||||
staff_of_the_undead_desc,发射诅咒,可将敌人转化为邪恶的怪物。,Cast a curse that transforms enemies into evil monsters.,呪いを発射して、敵を邪悪な怪物に変えることができます。
|
item_staff_of_the_undead_desc,发射诅咒,可将敌人转化为邪恶的怪物。,Cast a curse that transforms enemies into evil monsters.,呪いを発射して、敵を邪悪な怪物に変えることができます。
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -67,7 +67,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
||||||
/// </param>
|
/// </param>
|
||||||
protected virtual void WhenUpdateCurrentItem(Node2D? currentItem) { }
|
protected virtual void WhenUpdateCurrentItem(Node2D? currentItem) { }
|
||||||
|
|
||||||
//Define a pick up range
|
//Define a pickup range
|
||||||
//定义一个拾起范围
|
//定义一个拾起范围
|
||||||
private Area2D? _pickingArea;
|
private Area2D? _pickingArea;
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected List<Node>? PickingRangeBodiesList;
|
protected List<Node>? PickingRangeBodiesList;
|
||||||
|
|
||||||
public Node[] PickingRangeBodies => PickingRangeBodiesList?.ToArray() ?? Array.Empty<Node>();
|
public Node[] PickingRangeBodies => PickingRangeBodiesList?.ToArray() ?? [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>Resurrected character</para>
|
/// <para>Resurrected character</para>
|
||||||
|
@ -155,7 +155,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>Find the nearest item within the pick up area(Does not include items currently held)</para>
|
/// <para>Find the nearest item within the pickup area(Does not include items currently held)</para>
|
||||||
/// <para>在拾捡范围内查找距离最近的物品(不包括当前持有的物品)</para>
|
/// <para>在拾捡范围内查找距离最近的物品(不包括当前持有的物品)</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
@ -179,7 +179,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>Get all weapons within range of the pick up</para>
|
/// <para>Get all weapons within range of the pickup</para>
|
||||||
/// <para>获取所有在拾捡范围内的武器</para>
|
/// <para>获取所有在拾捡范围内的武器</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
@ -401,7 +401,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
||||||
{
|
{
|
||||||
if (targetCamp.Id == playerCamp.Id)
|
if (targetCamp.Id == playerCamp.Id)
|
||||||
{
|
{
|
||||||
//If an attack is allowed and you are on the same side, it is displayed as a friendly color (friend damage).
|
//If an attack is allowed, and you are on the same side, it is displayed as a friendly color (friend damage).
|
||||||
//如果允许攻击,且属于同一阵营,则显示为友好颜色(友伤)
|
//如果允许攻击,且属于同一阵营,则显示为友好颜色(友伤)
|
||||||
_healthBar.SetFriendlyTones();
|
_healthBar.SetFriendlyTones();
|
||||||
}
|
}
|
||||||
|
@ -537,7 +537,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
||||||
/// <param name="node"></param>
|
/// <param name="node"></param>
|
||||||
protected virtual void EnterThePickingRangeBody(Node node)
|
protected virtual void EnterThePickingRangeBody(Node node)
|
||||||
{
|
{
|
||||||
if (node is not IItem_New item)
|
if (node is not IItem_New)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -651,23 +651,20 @@ public partial class CharacterTemplate : CharacterBody2D
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>Throw item</para>
|
/// <para>Throw item</para>
|
||||||
/// <para>抛出物品</para>
|
/// <para>抛出物品</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="index">
|
/// <param name="itemSlotNode"></param>
|
||||||
///<para>Item slot index in item container</para>
|
/// <param name="velocity">
|
||||||
///<para>物品容器内的物品槽位置</para>
|
/// <para>The speed to be applied to the item</para>
|
||||||
/// </param>
|
/// <para>要施加到物品上的速度</para>
|
||||||
/// <param name="velocity">
|
/// </param>
|
||||||
///<para>The speed to be applied to the item</para>
|
private void ThrowOneItem(ItemSlotNode itemSlotNode, Vector2 velocity)
|
||||||
///<para>要施加到物品上的速度</para>
|
|
||||||
/// </param>
|
|
||||||
protected void ThrowOneItem(ItemSlotNode itemSlotNode, Vector2 velocity)
|
|
||||||
{
|
{
|
||||||
//Pick an item from the item container
|
//Pick an item from the item container
|
||||||
//从物品容器内取出一个物品
|
//从物品容器内取出一个物品
|
||||||
var item = itemSlotNode?.PickItem();
|
var item = itemSlotNode.PickItem();
|
||||||
|
|
||||||
if (item is not Node2D node2D)
|
if (item is not Node2D node2D)
|
||||||
{
|
{
|
||||||
|
|
|
@ -62,8 +62,8 @@ public partial class ItemSlotNode : MarginContainer
|
||||||
if (_itemStack is null) return null;
|
if (_itemStack is null) return null;
|
||||||
|
|
||||||
var result = _itemStack.PickItem();
|
var result = _itemStack.PickItem();
|
||||||
if (_itemStack.Quantity == 0) ClearSlot();
|
if (_itemStack.Quantity == 0) _itemStack = null;
|
||||||
else UpdateAllDisplay();
|
UpdateAllDisplay();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -82,8 +82,8 @@ public partial class ItemSlotNode : MarginContainer
|
||||||
if (_itemStack is null) return null;
|
if (_itemStack is null) return null;
|
||||||
|
|
||||||
var result = _itemStack.PickItems(value);
|
var result = _itemStack.PickItems(value);
|
||||||
if (_itemStack.Quantity == 0) ClearSlot();
|
if (_itemStack.Quantity == 0) _itemStack = null;
|
||||||
else UpdateAllDisplay();
|
UpdateAllDisplay();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -114,8 +114,8 @@ public partial class ItemSlotNode : MarginContainer
|
||||||
var result = _itemStack.RemoveItem(number);
|
var result = _itemStack.RemoveItem(number);
|
||||||
//If the specified number of items is removed, the number of items is less than or equal to 0. Then we empty the inventory.
|
//If the specified number of items is removed, the number of items is less than or equal to 0. Then we empty the inventory.
|
||||||
//如果移除指定数量的物品后,物品数量小于或等于0。那么我们清空物品栏。
|
//如果移除指定数量的物品后,物品数量小于或等于0。那么我们清空物品栏。
|
||||||
if (_itemStack.Quantity == 0) ClearSlot();
|
if (_itemStack.Quantity == 0) _itemStack = null;
|
||||||
else UpdateAllDisplay();
|
UpdateAllDisplay();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,17 +162,17 @@ public class UniversalItemContainer : IItemContainer
|
||||||
|
|
||||||
public ItemSlotNode? Match(IItemStack stack)
|
public ItemSlotNode? Match(IItemStack stack)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return _itemSlotNodes?.FirstOrDefault(itemSlotNode => itemSlotNode.CanAddItem(stack.GetItem()!));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemSlotNode? Match(Func<IItemStack?, bool> predicate)
|
public ItemSlotNode? Match(Func<IItemStack?, bool> predicate)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return _itemSlotNodes?.FirstOrDefault(node => predicate(node.GetItemStack()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<ItemSlotNode> MatchAll(Func<IItemStack?, bool> predicate)
|
public IEnumerable<ItemSlotNode> MatchAll(Func<IItemStack?, bool> predicate)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return from node in _itemSlotNodes where predicate(node.GetItemStack()) select node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
|
|
|
@ -4,22 +4,22 @@ using Godot;
|
||||||
|
|
||||||
namespace ColdMint.scripts.item;
|
namespace ColdMint.scripts.item;
|
||||||
|
|
||||||
public readonly struct ItemType
|
public readonly struct ItemType(string id, Func<IItem_New> newItemFunc, Texture2D? icon, int maxStackQuantity)
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>Item id of this type</para>
|
/// <para>Item id of this type</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Id { get; init; }
|
public string Id { get; init; } = id;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>A function returns a new item instance of this type</para>
|
/// <para>A function returns a new item instance of this type</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Func<IItem_New> NewItemFunc { get; init; }
|
public Func<IItem_New> NewItemFunc { get; init; } = newItemFunc;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>Default icon of items of this type</para>
|
/// <para>Default icon of items of this type</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Texture2D? Icon { get; init; }
|
public Texture2D? Icon { get; init; } = icon;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>Max number in item stack of this type</para>
|
/// <para>Max number in item stack of this type</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int MaxStackQuantity { get; init; }
|
public int MaxStackQuantity { get; init; } = maxStackQuantity;
|
||||||
}
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
using ColdMint.scripts.utils;
|
using ColdMint.scripts.utils;
|
||||||
|
|
||||||
|
@ -10,14 +9,19 @@ namespace ColdMint.scripts.item;
|
||||||
public static class ItemTypeManager
|
public static class ItemTypeManager
|
||||||
{
|
{
|
||||||
// Register items statically here
|
// Register items statically here
|
||||||
static ItemTypeManager() { }
|
public static void StaticRegister()
|
||||||
|
{
|
||||||
|
var staffOfTheUndeadScene = ResourceLoader.Load<PackedScene>("res://prefab/weapons/staffOfTheUndead.tscn");
|
||||||
|
var staffOfTheUndead = new ItemType("staff_of_the_undead", () => staffOfTheUndeadScene.Instantiate<IItem_New>(), null, 1);
|
||||||
|
Register(staffOfTheUndead);
|
||||||
|
}
|
||||||
|
|
||||||
private static Dictionary<string, ItemType> Registry { get; } = [];
|
private static Dictionary<string, ItemType> Registry { get; } = [];
|
||||||
private static Texture2D DefaultTexture { get; } = new PlaceholderTexture2D();
|
private static Texture2D DefaultTexture { get; } = new PlaceholderTexture2D();
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Register a item type.
|
/// Register an item type.
|
||||||
/// Return false if the item id already exist.
|
/// Return false if the item id already exist.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Whether the registration was successful.</returns>
|
/// <returns>Whether the registration was successful.</returns>
|
||||||
|
|
|
@ -31,26 +31,35 @@ public class SingleItemStack(IItem_New item) : IItemStack
|
||||||
|
|
||||||
public IItem_New? GetItem()
|
public IItem_New? GetItem()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return Quantity == 1 ? Item : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IItem_New? PickItem()
|
public IItem_New? PickItem()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
Quantity = 0;
|
||||||
|
return Item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IItemStack? PickItems(int value)
|
public IItemStack? PickItems(int value)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
if (value == 0) return null;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Quantity = 0;
|
||||||
|
return new SingleItemStack(Item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int RemoveItem(int number)
|
public int RemoveItem(int number)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
if (number == 0) return 0;
|
||||||
|
Quantity = 0;
|
||||||
|
Item.Destroy();
|
||||||
|
return Math.Max(number - 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClearStack()
|
public void ClearStack()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
RemoveItem(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,12 +1,15 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
using ColdMint.scripts.camp;
|
using ColdMint.scripts.camp;
|
||||||
using ColdMint.scripts.deathInfo;
|
using ColdMint.scripts.deathInfo;
|
||||||
using ColdMint.scripts.debug;
|
using ColdMint.scripts.debug;
|
||||||
using ColdMint.scripts.inventory;
|
using ColdMint.scripts.inventory;
|
||||||
|
using ColdMint.scripts.item;
|
||||||
using ColdMint.scripts.map;
|
using ColdMint.scripts.map;
|
||||||
using ColdMint.scripts.map.roomInjectionProcessor;
|
using ColdMint.scripts.map.roomInjectionProcessor;
|
||||||
|
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace ColdMint.scripts.loader.uiLoader;
|
namespace ColdMint.scripts.loader.uiLoader;
|
||||||
|
@ -57,6 +60,7 @@ public partial class MainMenuLoader : UiLoaderTemplate
|
||||||
testLootList.AddLootEntry(lootEntry);
|
testLootList.AddLootEntry(lootEntry);
|
||||||
LootListManager.RegisterLootList(testLootList);
|
LootListManager.RegisterLootList(testLootList);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeathInfoGenerator.RegisterDeathInfoHandler(new SelfDeathInfoHandler());
|
DeathInfoGenerator.RegisterDeathInfoHandler(new SelfDeathInfoHandler());
|
||||||
MapGenerator.RegisterRoomInjectionProcessor(new ChanceRoomInjectionProcessor());
|
MapGenerator.RegisterRoomInjectionProcessor(new ChanceRoomInjectionProcessor());
|
||||||
MapGenerator.RegisterRoomInjectionProcessor(new TimeIntervalRoomInjectorProcessor());
|
MapGenerator.RegisterRoomInjectionProcessor(new TimeIntervalRoomInjectorProcessor());
|
||||||
|
@ -82,6 +86,10 @@ public partial class MainMenuLoader : UiLoaderTemplate
|
||||||
var aborigines = new Camp(Config.CampId.Aborigines);
|
var aborigines = new Camp(Config.CampId.Aborigines);
|
||||||
CampManager.AddCamp(aborigines);
|
CampManager.AddCamp(aborigines);
|
||||||
_gameScene = (PackedScene)GD.Load("res://scenes/game.tscn");
|
_gameScene = (PackedScene)GD.Load("res://scenes/game.tscn");
|
||||||
|
|
||||||
|
//Temp: Register ItemType
|
||||||
|
//临时:注册物品类型
|
||||||
|
ItemTypeManager.StaticRegister();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void InitializeUi()
|
public override void InitializeUi()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user