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
|
||||
staff_of_the_undead,死灵法杖,StaffOfTheUndead,ネクロポリスの杖です
|
||||
staff_of_the_undead_desc,发射诅咒,可将敌人转化为邪恶的怪物。,Cast a curse that transforms enemies into evil monsters.,呪いを発射して、敵を邪悪な怪物に変えることができます。
|
||||
item_staff_of_the_undead,死灵法杖,StaffOfTheUndead,ネクロポリスの杖です
|
||||
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>
|
||||
protected virtual void WhenUpdateCurrentItem(Node2D? currentItem) { }
|
||||
|
||||
//Define a pick up range
|
||||
//Define a pickup range
|
||||
//定义一个拾起范围
|
||||
private Area2D? _pickingArea;
|
||||
|
||||
|
@ -122,7 +122,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
|||
/// </summary>
|
||||
protected List<Node>? PickingRangeBodiesList;
|
||||
|
||||
public Node[] PickingRangeBodies => PickingRangeBodiesList?.ToArray() ?? Array.Empty<Node>();
|
||||
public Node[] PickingRangeBodies => PickingRangeBodiesList?.ToArray() ?? [];
|
||||
|
||||
/// <summary>
|
||||
/// <para>Resurrected character</para>
|
||||
|
@ -155,7 +155,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
|||
}
|
||||
|
||||
/// <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>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
|
@ -179,7 +179,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
|||
|
||||
|
||||
/// <summary>
|
||||
/// <para>Get all weapons within range of the pick up</para>
|
||||
/// <para>Get all weapons within range of the pickup</para>
|
||||
/// <para>获取所有在拾捡范围内的武器</para>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
|
@ -401,7 +401,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
|||
{
|
||||
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();
|
||||
}
|
||||
|
@ -537,7 +537,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
|||
/// <param name="node"></param>
|
||||
protected virtual void EnterThePickingRangeBody(Node node)
|
||||
{
|
||||
if (node is not IItem_New item)
|
||||
if (node is not IItem_New)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -651,23 +651,20 @@ public partial class CharacterTemplate : CharacterBody2D
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Throw item</para>
|
||||
/// <para>抛出物品</para>
|
||||
/// </summary>
|
||||
/// <param name="index">
|
||||
///<para>Item slot index in item container</para>
|
||||
///<para>物品容器内的物品槽位置</para>
|
||||
/// </param>
|
||||
/// <param name="velocity">
|
||||
///<para>The speed to be applied to the item</para>
|
||||
///<para>要施加到物品上的速度</para>
|
||||
/// </param>
|
||||
protected void ThrowOneItem(ItemSlotNode itemSlotNode, Vector2 velocity)
|
||||
/// <summary>
|
||||
/// <para>Throw item</para>
|
||||
/// <para>抛出物品</para>
|
||||
/// </summary>
|
||||
/// <param name="itemSlotNode"></param>
|
||||
/// <param name="velocity">
|
||||
/// <para>The speed to be applied to the item</para>
|
||||
/// <para>要施加到物品上的速度</para>
|
||||
/// </param>
|
||||
private void ThrowOneItem(ItemSlotNode itemSlotNode, Vector2 velocity)
|
||||
{
|
||||
//Pick an item from the item container
|
||||
//从物品容器内取出一个物品
|
||||
var item = itemSlotNode?.PickItem();
|
||||
var item = itemSlotNode.PickItem();
|
||||
|
||||
if (item is not Node2D node2D)
|
||||
{
|
||||
|
|
|
@ -62,8 +62,8 @@ public partial class ItemSlotNode : MarginContainer
|
|||
if (_itemStack is null) return null;
|
||||
|
||||
var result = _itemStack.PickItem();
|
||||
if (_itemStack.Quantity == 0) ClearSlot();
|
||||
else UpdateAllDisplay();
|
||||
if (_itemStack.Quantity == 0) _itemStack = null;
|
||||
UpdateAllDisplay();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -82,8 +82,8 @@ public partial class ItemSlotNode : MarginContainer
|
|||
if (_itemStack is null) return null;
|
||||
|
||||
var result = _itemStack.PickItems(value);
|
||||
if (_itemStack.Quantity == 0) ClearSlot();
|
||||
else UpdateAllDisplay();
|
||||
if (_itemStack.Quantity == 0) _itemStack = null;
|
||||
UpdateAllDisplay();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -114,8 +114,8 @@ public partial class ItemSlotNode : MarginContainer
|
|||
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.
|
||||
//如果移除指定数量的物品后,物品数量小于或等于0。那么我们清空物品栏。
|
||||
if (_itemStack.Quantity == 0) ClearSlot();
|
||||
else UpdateAllDisplay();
|
||||
if (_itemStack.Quantity == 0) _itemStack = null;
|
||||
UpdateAllDisplay();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -162,17 +162,17 @@ public class UniversalItemContainer : IItemContainer
|
|||
|
||||
public ItemSlotNode? Match(IItemStack stack)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return _itemSlotNodes?.FirstOrDefault(itemSlotNode => itemSlotNode.CanAddItem(stack.GetItem()!));
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return from node in _itemSlotNodes where predicate(node.GetItemStack()) select node;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
using Godot;
|
||||
|
||||
|
|
|
@ -4,22 +4,22 @@ using Godot;
|
|||
|
||||
namespace ColdMint.scripts.item;
|
||||
|
||||
public readonly struct ItemType
|
||||
public readonly struct ItemType(string id, Func<IItem_New> newItemFunc, Texture2D? icon, int maxStackQuantity)
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>Item id of this type</para>
|
||||
/// </summary>
|
||||
public string Id { get; init; }
|
||||
public string Id { get; init; } = id;
|
||||
/// <summary>
|
||||
/// <para>A function returns a new item instance of this type</para>
|
||||
/// </summary>
|
||||
public Func<IItem_New> NewItemFunc { get; init; }
|
||||
public Func<IItem_New> NewItemFunc { get; init; } = newItemFunc;
|
||||
/// <summary>
|
||||
/// <para>Default icon of items of this type</para>
|
||||
/// </summary>
|
||||
public Texture2D? Icon { get; init; }
|
||||
public Texture2D? Icon { get; init; } = icon;
|
||||
/// <summary>
|
||||
/// <para>Max number in item stack of this type</para>
|
||||
/// </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;
|
||||
|
||||
|
@ -10,14 +9,19 @@ namespace ColdMint.scripts.item;
|
|||
public static class ItemTypeManager
|
||||
{
|
||||
// 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 Texture2D DefaultTexture { get; } = new PlaceholderTexture2D();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Register a item type.
|
||||
/// Register an item type.
|
||||
/// Return false if the item id already exist.
|
||||
/// </summary>
|
||||
/// <returns>Whether the registration was successful.</returns>
|
||||
|
|
|
@ -31,26 +31,35 @@ public class SingleItemStack(IItem_New item) : IItemStack
|
|||
|
||||
public IItem_New? GetItem()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return Quantity == 1 ? Item : null;
|
||||
}
|
||||
|
||||
public IItem_New? PickItem()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
Quantity = 0;
|
||||
return Item;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (number == 0) return 0;
|
||||
Quantity = 0;
|
||||
Item.Destroy();
|
||||
return Math.Max(number - 1, 0);
|
||||
}
|
||||
|
||||
public void ClearStack()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
RemoveItem(1);
|
||||
}
|
||||
}
|
|
@ -1,12 +1,15 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
using ColdMint.scripts.camp;
|
||||
using ColdMint.scripts.deathInfo;
|
||||
using ColdMint.scripts.debug;
|
||||
using ColdMint.scripts.inventory;
|
||||
using ColdMint.scripts.item;
|
||||
using ColdMint.scripts.map;
|
||||
using ColdMint.scripts.map.roomInjectionProcessor;
|
||||
|
||||
using Godot;
|
||||
|
||||
namespace ColdMint.scripts.loader.uiLoader;
|
||||
|
@ -57,6 +60,7 @@ public partial class MainMenuLoader : UiLoaderTemplate
|
|||
testLootList.AddLootEntry(lootEntry);
|
||||
LootListManager.RegisterLootList(testLootList);
|
||||
}
|
||||
|
||||
DeathInfoGenerator.RegisterDeathInfoHandler(new SelfDeathInfoHandler());
|
||||
MapGenerator.RegisterRoomInjectionProcessor(new ChanceRoomInjectionProcessor());
|
||||
MapGenerator.RegisterRoomInjectionProcessor(new TimeIntervalRoomInjectorProcessor());
|
||||
|
@ -82,6 +86,10 @@ public partial class MainMenuLoader : UiLoaderTemplate
|
|||
var aborigines = new Camp(Config.CampId.Aborigines);
|
||||
CampManager.AddCamp(aborigines);
|
||||
_gameScene = (PackedScene)GD.Load("res://scenes/game.tscn");
|
||||
|
||||
//Temp: Register ItemType
|
||||
//临时:注册物品类型
|
||||
ItemTypeManager.StaticRegister();
|
||||
}
|
||||
|
||||
public override void InitializeUi()
|
||||
|
|
Loading…
Reference in New Issue
Block a user