It's done.
This commit is contained in:
parent
16b3a5a106
commit
16a2d40501
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -617,8 +617,8 @@ public partial class CharacterTemplate : CharacterBody2D
|
||||||
/// <para>抛出物品</para>
|
/// <para>抛出物品</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="index">
|
/// <param name="index">
|
||||||
///<para>Item slot subscript in item container</para>
|
///<para>Item slot index in item container</para>
|
||||||
///<para>物品容器内的物品槽下标</para>
|
///<para>物品容器内的物品槽位置</para>
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="number">
|
/// <param name="number">
|
||||||
/// <para>How many to throw</para>
|
/// <para>How many to throw</para>
|
||||||
|
@ -633,8 +633,41 @@ public partial class CharacterTemplate : CharacterBody2D
|
||||||
protected void ThrowItem(int index, int number, Vector2 velocity)
|
protected void ThrowItem(int index, int number, Vector2 velocity)
|
||||||
{
|
{
|
||||||
var itemSlotNode = ItemContainer?.GetItemSlotNode(index);
|
var itemSlotNode = ItemContainer?.GetItemSlotNode(index);
|
||||||
|
if (itemSlotNode is null) return;
|
||||||
|
|
||||||
var item = itemSlotNode?.GetItem();
|
if (number < 0)
|
||||||
|
{
|
||||||
|
while (!itemSlotNode.IsEmpty())
|
||||||
|
{
|
||||||
|
ThrowOneItem(itemSlotNode, velocity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0; i < number && !itemSlotNode.IsEmpty(); i++)
|
||||||
|
{
|
||||||
|
ThrowOneItem(itemSlotNode, velocity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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)
|
||||||
|
{
|
||||||
|
//Pick an item from the item container
|
||||||
|
//从物品容器内取出一个物品
|
||||||
|
var item = itemSlotNode?.PickItem();
|
||||||
|
|
||||||
if (item is not Node2D node2D)
|
if (item is not Node2D node2D)
|
||||||
{
|
{
|
||||||
|
@ -685,17 +718,6 @@ public partial class CharacterTemplate : CharacterBody2D
|
||||||
rigidBody2D.LinearVelocity = velocity;
|
rigidBody2D.LinearVelocity = velocity;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Remove items from the item container
|
|
||||||
//在物品容器内移除物品
|
|
||||||
if (number < 0)
|
|
||||||
{
|
|
||||||
itemSlotNode!.RemoveItem(item.Quantity);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
itemSlotNode!.RemoveItem(number);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -37,6 +37,8 @@ public partial class ItemSlotNode : MarginContainer
|
||||||
|
|
||||||
public TextureRect? BackgroundTextureRect => _backgroundTextureRect;
|
public TextureRect? BackgroundTextureRect => _backgroundTextureRect;
|
||||||
|
|
||||||
|
public bool IsEmpty() => _itemStack == null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>Get the item stack in the item slot</para>
|
/// <para>Get the item stack in the item slot</para>
|
||||||
/// <para>获取物品槽内的物品堆</para>
|
/// <para>获取物品槽内的物品堆</para>
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class SingleItemStack(IItem_New item) : IItemStack
|
||||||
|
|
||||||
public int CanTakeFrom(IItemStack itemStack) => 0;
|
public int CanTakeFrom(IItemStack itemStack) => 0;
|
||||||
|
|
||||||
public int TakeFrom(IItemStack itemStack) => 0;
|
public bool TakeFrom(IItemStack itemStack) => false;
|
||||||
|
|
||||||
public IItem_New? GetItem()
|
public IItem_New? GetItem()
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,6 +35,11 @@ public abstract partial class WeaponTemplate : RigidBody2D, IItem_New
|
||||||
Fire(owner, targetGlobalPosition);
|
Fire(owner, targetGlobalPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void Destroy()
|
||||||
|
{
|
||||||
|
QueueFree();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>Whether the weapon is currently picked up</para>
|
/// <para>Whether the weapon is currently picked up</para>
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
using ColdMint.scripts.camp;
|
using ColdMint.scripts.camp;
|
||||||
using ColdMint.scripts.character;
|
using ColdMint.scripts.character;
|
||||||
using ColdMint.scripts.damage;
|
using ColdMint.scripts.damage;
|
||||||
using ColdMint.scripts.weapon;
|
using ColdMint.scripts.item;
|
||||||
|
using ColdMint.scripts.item.weapon;
|
||||||
|
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace ColdMint.scripts.projectile;
|
namespace ColdMint.scripts.projectile;
|
||||||
|
@ -111,7 +114,9 @@ public partial class ProjectileTemplate : CharacterBody2D
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target is WeaponTemplate)
|
//Match any item now
|
||||||
|
//现在使它识别任何物品
|
||||||
|
if (target is IItem_New)
|
||||||
{
|
{
|
||||||
//Bullets are allowed to strike objects.
|
//Bullets are allowed to strike objects.
|
||||||
//允许子弹撞击物品。
|
//允许子弹撞击物品。
|
||||||
|
@ -169,7 +174,8 @@ public partial class ProjectileTemplate : CharacterBody2D
|
||||||
force.Y = KnockbackForce.Y * Config.CellSize;
|
force.Y = KnockbackForce.Y * Config.CellSize;
|
||||||
characterTemplate.AddForce(force);
|
characterTemplate.AddForce(force);
|
||||||
}
|
}
|
||||||
}else if (target is WeaponTemplate weaponTemplate)
|
}
|
||||||
|
else if (target is WeaponTemplate weaponTemplate)
|
||||||
{
|
{
|
||||||
if (KnockbackForce != Vector2.Zero)
|
if (KnockbackForce != Vector2.Zero)
|
||||||
{
|
{
|
||||||
|
@ -225,9 +231,7 @@ public partial class ProjectileTemplate : CharacterBody2D
|
||||||
/// <para>当子弹离开节点时</para>
|
/// <para>当子弹离开节点时</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="node"></param>
|
/// <param name="node"></param>
|
||||||
protected virtual void OnBodyExited(Node2D node)
|
protected virtual void OnBodyExited(Node2D node) { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using ColdMint.scripts.debug;
|
using ColdMint.scripts.debug;
|
||||||
using ColdMint.scripts.weapon;
|
using ColdMint.scripts.item.weapon;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace ColdMint.scripts.utils;
|
namespace ColdMint.scripts.utils;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user