Add single item stack type, move the weapon namespace into the item namespace, and I think it's ready to be merged into the new interface
This commit is contained in:
parent
0880feb298
commit
026c7ff32f
Binary file not shown.
|
@ -147,7 +147,6 @@ hotbar_previous={
|
|||
[internationalization]
|
||||
|
||||
locale/translations=PackedStringArray("res://locals/DeathInfo.en.translation", "res://locals/DeathInfo.ja.translation", "res://locals/DeathInfo.zh.translation", "res://locals/InputMapping.en.translation", "res://locals/InputMapping.ja.translation", "res://locals/InputMapping.zh.translation", "res://locals/Log.en.translation", "res://locals/Log.ja.translation", "res://locals/Log.zh.translation", "res://locals/Slogan.en.translation", "res://locals/Slogan.ja.translation", "res://locals/Slogan.zh.translation", "res://locals/UI.en.translation", "res://locals/UI.ja.translation", "res://locals/UI.zh.translation", "res://locals/Weapon.en.translation", "res://locals/Weapon.ja.translation", "res://locals/Weapon.zh.translation")
|
||||
locale/test="ja"
|
||||
|
||||
[layer_names]
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using ColdMint.scripts.character;
|
||||
using ColdMint.scripts.weapon;
|
||||
|
||||
using ColdMint.scripts.item.weapon;
|
||||
|
||||
namespace ColdMint.scripts.behaviorTree.ai;
|
||||
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ColdMint.scripts.camp;
|
||||
using ColdMint.scripts.damage;
|
||||
using ColdMint.scripts.debug;
|
||||
using ColdMint.scripts.health;
|
||||
using ColdMint.scripts.inventory;
|
||||
using ColdMint.scripts.utils;
|
||||
using ColdMint.scripts.weapon;
|
||||
using ColdMint.scripts.item.weapon;
|
||||
|
||||
using Godot;
|
||||
|
||||
namespace ColdMint.scripts.character;
|
||||
|
@ -69,9 +71,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
|||
///<para>Update finished items</para>
|
||||
///<para>更新完成后的物品</para>
|
||||
/// </param>
|
||||
protected virtual void WhenUpdateCurrentItem(Node2D? currentItem)
|
||||
{
|
||||
}
|
||||
protected virtual void WhenUpdateCurrentItem(Node2D? currentItem) { }
|
||||
|
||||
//Define a pick up range
|
||||
//定义一个拾起范围
|
||||
|
@ -210,8 +210,8 @@ public partial class CharacterTemplate : CharacterBody2D
|
|||
base._Ready();
|
||||
PickingRangeBodiesList = new List<Node>();
|
||||
CharacterName = GetMeta("Name", Name).AsString();
|
||||
CampId = GetMeta("CampId", Config.CampId.Default).AsString();
|
||||
MaxHp = GetMeta("MaxHp", Config.DefaultMaxHp).AsInt32();
|
||||
CampId = GetMeta("CampId", Config.CampId.Default).AsString();
|
||||
MaxHp = GetMeta("MaxHp", Config.DefaultMaxHp).AsInt32();
|
||||
string lootListId = GetMeta("LootListId", string.Empty).AsString();
|
||||
if (!string.IsNullOrEmpty(lootListId))
|
||||
{
|
||||
|
@ -219,6 +219,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
|||
//如果指定了战利品表,那么获取战利品表。
|
||||
_lootList = LootListManager.GetLootList(lootListId);
|
||||
}
|
||||
|
||||
if (MaxHp <= 0)
|
||||
{
|
||||
//If Max blood volume is 0 or less, set Max blood volume to 10
|
||||
|
@ -317,7 +318,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
|||
{
|
||||
weaponTemplate.Owner = this;
|
||||
weaponTemplate.SetCollisionMaskValue(Config.LayerNumber.Platform, false);
|
||||
weaponTemplate.SetCollisionMaskValue(Config.LayerNumber.Ground, false);
|
||||
weaponTemplate.SetCollisionMaskValue(Config.LayerNumber.Ground, false);
|
||||
weaponTemplate.EnableContactInjury = false;
|
||||
weaponTemplate.Sleeping = true;
|
||||
}
|
||||
|
@ -467,9 +468,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
|||
_additionalForce = force;
|
||||
}
|
||||
|
||||
protected virtual void OnHit(DamageTemplate damageTemplate)
|
||||
{
|
||||
}
|
||||
protected virtual void OnHit(DamageTemplate damageTemplate) { }
|
||||
|
||||
/// <summary>
|
||||
/// <para>Handle the event of character death</para>
|
||||
|
@ -599,22 +598,9 @@ public partial class CharacterTemplate : CharacterBody2D
|
|||
/// </param>
|
||||
protected void ThrowItem(int index, int number, Vector2 velocity)
|
||||
{
|
||||
if (_itemContainer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var itemSlotNode = _itemContainer?.GetItemSlotNode(index);
|
||||
|
||||
var itemSlotNode = _itemContainer.GetItemSlotNode(index);
|
||||
if (itemSlotNode == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var item = itemSlotNode.GetItem();
|
||||
if (item == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var item = itemSlotNode?.GetItem();
|
||||
|
||||
if (item is not Node2D node2D)
|
||||
{
|
||||
|
@ -639,7 +625,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
|||
//We cannot immediately resume the physical collision when the weapon is discharged, which will cause the weapon to collide with the ground and platform earlier, preventing the weapon from flying.
|
||||
//仍出武器时,我们不能立即恢复物理碰撞,立即恢复会导致武器更早的与地面和平台碰撞,阻止武器的飞行。
|
||||
weaponTemplate.EnableContactInjury = true;
|
||||
weaponTemplate.SetCollisionMaskValue(Config.LayerNumber.Ground, true);
|
||||
weaponTemplate.SetCollisionMaskValue(Config.LayerNumber.Ground, true);
|
||||
weaponTemplate.SetCollisionMaskValue(Config.LayerNumber.Platform, true);
|
||||
timer.QueueFree();
|
||||
};
|
||||
|
@ -669,11 +655,11 @@ public partial class CharacterTemplate : CharacterBody2D
|
|||
//在物品容器内移除物品
|
||||
if (number < 0)
|
||||
{
|
||||
itemSlotNode.RemoveItem(item.Quantity);
|
||||
itemSlotNode!.RemoveItem(item.Quantity);
|
||||
}
|
||||
else
|
||||
{
|
||||
itemSlotNode.RemoveItem(number);
|
||||
itemSlotNode!.RemoveItem(number);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -728,7 +714,5 @@ public partial class CharacterTemplate : CharacterBody2D
|
|||
}
|
||||
|
||||
|
||||
protected virtual void HookPhysicsProcess(ref Vector2 velocity, double delta)
|
||||
{
|
||||
}
|
||||
protected virtual void HookPhysicsProcess(ref Vector2 velocity, double delta) { }
|
||||
}
|
|
@ -1,11 +1,13 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ColdMint.scripts.damage;
|
||||
using ColdMint.scripts.deathInfo;
|
||||
using ColdMint.scripts.map.events;
|
||||
using ColdMint.scripts.utils;
|
||||
using ColdMint.scripts.weapon;
|
||||
using ColdMint.scripts.item.weapon;
|
||||
|
||||
using Godot;
|
||||
|
||||
namespace ColdMint.scripts.character;
|
||||
|
@ -101,7 +103,7 @@ public partial class Player : CharacterTemplate
|
|||
operationTipBuilder.Append(Config.OperationTipActionColor);
|
||||
operationTipBuilder.Append(']');
|
||||
operationTipBuilder.Append(
|
||||
TranslationServerUtils.Translate(InputMap.ActionGetEvents("ui_down")[0].AsText()));
|
||||
TranslationServerUtils.Translate(InputMap.ActionGetEvents("ui_down")[0].AsText()));
|
||||
operationTipBuilder.Append("[/color]");
|
||||
operationTipBuilder.Append(TranslationServerUtils.Translate("jump_down"));
|
||||
}
|
||||
|
@ -115,7 +117,7 @@ public partial class Player : CharacterTemplate
|
|||
operationTipBuilder.Append(Config.OperationTipActionColor);
|
||||
operationTipBuilder.Append(']');
|
||||
operationTipBuilder.Append(
|
||||
TranslationServerUtils.Translate(InputMap.ActionGetEvents("pick_up")[0].AsText()));
|
||||
TranslationServerUtils.Translate(InputMap.ActionGetEvents("pick_up")[0].AsText()));
|
||||
operationTipBuilder.Append("[/color]");
|
||||
operationTipBuilder.Append(TranslationServerUtils.Translate("pick_up"));
|
||||
operationTipLabel.Text = operationTipBuilder.ToString();
|
||||
|
@ -139,7 +141,7 @@ public partial class Player : CharacterTemplate
|
|||
operationTipBuilder.Append(Config.OperationTipActionColor);
|
||||
operationTipBuilder.Append(']');
|
||||
operationTipBuilder.Append(
|
||||
TranslationServerUtils.Translate(InputMap.ActionGetEvents("use_item")[0].AsText()));
|
||||
TranslationServerUtils.Translate(InputMap.ActionGetEvents("use_item")[0].AsText()));
|
||||
operationTipBuilder.Append("[/color]");
|
||||
operationTipBuilder.Append(TranslationServerUtils.Translate("use_item"));
|
||||
operationTipBuilder.Append(TranslationServerUtils.Translate(weaponTemplate.Name));
|
||||
|
@ -243,8 +245,8 @@ public partial class Player : CharacterTemplate
|
|||
}
|
||||
|
||||
_parabola.Points = CurrentItem == null
|
||||
? _emptyVector2Array
|
||||
: ParabolicUtils.ComputeParabolic(ItemMarker2D.Position, GetThrowVelocity(), Gravity, 0.1f);
|
||||
? _emptyVector2Array
|
||||
: ParabolicUtils.ComputeParabolic(ItemMarker2D.Position, GetThrowVelocity(), Gravity, 0.1f);
|
||||
}
|
||||
|
||||
|
||||
|
@ -400,8 +402,8 @@ public partial class Player : CharacterTemplate
|
|||
var rotationDegreesNode2D = node2D.RotationDegrees;
|
||||
var rotationDegreesNode2DAbs = Math.Abs(rotationDegreesNode2D);
|
||||
_floatLabel.Position = rotationDegreesNode2DAbs > 90
|
||||
? new Vector2(0, PromptTextDistance)
|
||||
: new Vector2(0, -PromptTextDistance);
|
||||
? new Vector2(0, PromptTextDistance)
|
||||
: new Vector2(0, -PromptTextDistance);
|
||||
_floatLabel.RotationDegrees = 0 - rotationDegreesNode2D;
|
||||
var label = _floatLabel.GetNode<Label>("Label");
|
||||
if (node is WeaponTemplate weapon)
|
||||
|
|
|
@ -396,8 +396,7 @@ public partial class HotBar : HBoxContainer, IItemContainer
|
|||
return;
|
||||
}
|
||||
|
||||
var itemSlotNode = _itemSlotPackedScene.Instantiate() as ItemSlotNode;
|
||||
if (itemSlotNode == null)
|
||||
if (_itemSlotPackedScene.Instantiate() is not ItemSlotNode itemSlotNode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
using Godot;
|
||||
|
||||
namespace ColdMint.scripts.item;
|
||||
|
||||
|
@ -17,20 +19,33 @@ public interface IItemStack
|
|||
/// <summary>
|
||||
/// <para>Quantity of current stack</para>
|
||||
/// </summary>
|
||||
int Quantity { get; set; }
|
||||
|
||||
int Quantity { get; }
|
||||
|
||||
/// <summary>
|
||||
/// <para>Icon of current item</para>
|
||||
/// </summary>
|
||||
Texture2D Icon { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <para>Display name of current item</para>
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <para>Description of current item, which may show in inventory</para>
|
||||
/// </summary>
|
||||
string? Description { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Create a new ItemStack with the given item as the first item
|
||||
/// </summary>
|
||||
public static IItemStack? FromItem(IItem_New item) => ItemTypeManager.StackTypeOf(item.Id) switch
|
||||
{
|
||||
StackType.Common => throw new NotImplementedException(),
|
||||
StackType.Unique => throw new NotImplementedException(),
|
||||
StackType.Unstackable => new SingleItemStack(item),
|
||||
null => null,
|
||||
_ => throw new ArgumentException()
|
||||
};
|
||||
}
|
|
@ -13,13 +13,17 @@ public readonly struct ItemType
|
|||
/// <summary>
|
||||
/// <para>A function returns a new item instance of this type</para>
|
||||
/// </summary>
|
||||
public Func<IItem_New> Getter { get; init; }
|
||||
public Func<IItem_New> NewItemFunc { get; init; }
|
||||
/// <summary>
|
||||
/// <para>Default icon of items of this type</para>
|
||||
/// </summary>
|
||||
public Texture2D? Texture { get; init; }
|
||||
public Texture2D? Icon { get; init; }
|
||||
/// <summary>
|
||||
/// <para>Max number in item stack of this type</para>
|
||||
/// </summary>
|
||||
public int MaxStackQuantity { get; init; }
|
||||
/// <summary>
|
||||
/// <para>Determines how items of this type will be stacked</para>
|
||||
/// </summary>
|
||||
public StackType StackType { get; init; }
|
||||
}
|
|
@ -28,7 +28,7 @@ public static class ItemTypeManager
|
|||
/// <para>Returns null when the id is not registered.</para>
|
||||
/// </summary>
|
||||
public static IItem_New? NewItem(string id) =>
|
||||
Registry.TryGetValue(id, out var itemType) ? itemType.Getter() : null;
|
||||
Registry.TryGetValue(id, out var itemType) ? itemType.NewItemFunc() : null;
|
||||
|
||||
/// <summary>
|
||||
/// Get the translated default name of the item type for the given id
|
||||
|
@ -54,6 +54,9 @@ public static class ItemTypeManager
|
|||
/// </returns>
|
||||
public static Texture2D DefaultIconOf(string id) =>
|
||||
Registry.TryGetValue(id, out var itemType)
|
||||
? itemType.Texture ?? DefaultTexture
|
||||
? itemType.Icon ?? DefaultTexture
|
||||
: DefaultTexture;
|
||||
|
||||
public static int MaxStackQuantityOf(string id) => Registry.TryGetValue(id, out var itemType) ? itemType.MaxStackQuantity : 0;
|
||||
public static StackType? StackTypeOf(string id) => Registry.TryGetValue(id, out var itemType) ? itemType.StackType : null;
|
||||
}
|
21
scripts/item/SingleItemStack.cs
Normal file
21
scripts/item/SingleItemStack.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using ColdMint.scripts.inventory;
|
||||
|
||||
using Godot;
|
||||
|
||||
namespace ColdMint.scripts.item;
|
||||
|
||||
/// <summary>
|
||||
/// <para>Item stack in inventory</para>
|
||||
/// </summary>
|
||||
//maybe we'd move this into inventory namespace
|
||||
public readonly struct SingleItemStack(IItem_New item) : IItemStack
|
||||
{
|
||||
public IItem_New Item { get; init; } = item;
|
||||
|
||||
public string Id => Item.Id;
|
||||
public int MaxQuantity => 1;
|
||||
public int Quantity => 1;
|
||||
public Texture2D Icon => Item.Icon;
|
||||
public string Name => Item.Name;
|
||||
public string? Description => Item.Description;
|
||||
}
|
8
scripts/item/StackType.cs
Normal file
8
scripts/item/StackType.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace ColdMint.scripts.item;
|
||||
|
||||
public enum StackType
|
||||
{
|
||||
Common,
|
||||
Unique,
|
||||
Unstackable,
|
||||
}
|
|
@ -1,9 +1,11 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
using ColdMint.scripts.debug;
|
||||
using ColdMint.scripts.projectile;
|
||||
|
||||
using Godot;
|
||||
|
||||
namespace ColdMint.scripts.weapon;
|
||||
namespace ColdMint.scripts.item.weapon;
|
||||
|
||||
/// <summary>
|
||||
/// <para>Projectile weapons</para>
|
|
@ -1,11 +1,13 @@
|
|||
using System;
|
||||
|
||||
using ColdMint.scripts.camp;
|
||||
using ColdMint.scripts.character;
|
||||
using ColdMint.scripts.damage;
|
||||
using ColdMint.scripts.inventory;
|
||||
|
||||
using Godot;
|
||||
|
||||
namespace ColdMint.scripts.weapon;
|
||||
namespace ColdMint.scripts.item.weapon;
|
||||
|
||||
/// <summary>
|
||||
/// <para>WeaponTemplate</para>
|
Loading…
Reference in New Issue
Block a user