It's done.

This commit is contained in:
霧雨烨 2024-06-13 01:51:51 +08:00
parent 16b3a5a106
commit 16a2d40501
12 changed files with 64 additions and 31 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -485,8 +485,8 @@ public partial class CharacterTemplate : CharacterBody2D
/// <param name="lootDataArray"></param> /// <param name="lootDataArray"></param>
/// <param name="position"></param> /// <param name="position"></param>
public void GenerateLootObjects(Node parentNode, public void GenerateLootObjects(Node parentNode,
LootData[] lootDataArray, LootData[] lootDataArray,
Vector2 position) Vector2 position)
{ {
LootListManager.GenerateLootObjects(parentNode, lootDataArray, position); LootListManager.GenerateLootObjects(parentNode, lootDataArray, position);
} }
@ -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>

View File

@ -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>

View File

@ -27,8 +27,8 @@ 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()
{ {
throw new NotImplementedException(); throw new NotImplementedException();

View File

@ -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>
@ -168,7 +173,7 @@ public abstract partial class WeaponTemplate : RigidBody2D, IItem_New
//Determine if your side can cause damage //Determine if your side can cause damage
//判断所属的阵营是否可以造成伤害 //判断所属的阵营是否可以造成伤害
var canCauseHarm = CampManager.CanCauseHarm(CampManager.GetCamp(ownerCharacterTemplate.CampId), var canCauseHarm = CampManager.CanCauseHarm(CampManager.GetCamp(ownerCharacterTemplate.CampId),
CampManager.GetCamp(characterTemplate.CampId)); CampManager.GetCamp(characterTemplate.CampId));
if (!canCauseHarm) if (!canCauseHarm)
{ {

View File

@ -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;
@ -64,10 +67,10 @@ public partial class ProjectileTemplate : CharacterBody2D
Area2D.Monitoring = true; Area2D.Monitoring = true;
Area2D.BodyEntered += OnBodyEnter; Area2D.BodyEntered += OnBodyEnter;
Area2D.BodyExited += OnBodyExited; Area2D.BodyExited += OnBodyExited;
Durability = GetMeta("Durability", "1").AsDouble(); Durability = GetMeta("Durability", "1").AsDouble();
MaxDamage = GetMeta("MaxDamage", "7").AsInt32(); MaxDamage = GetMeta("MaxDamage", "7").AsInt32();
MinDamage = GetMeta("MinDamage", "5").AsInt32(); MinDamage = GetMeta("MinDamage", "5").AsInt32();
DamageType = GetMeta("DamageType", Config.DamageType.Physical).AsInt32(); DamageType = GetMeta("DamageType", Config.DamageType.Physical).AsInt32();
KnockbackForce = GetMeta("Knockback", Vector2.Zero).AsVector2(); KnockbackForce = GetMeta("Knockback", Vector2.Zero).AsVector2();
//life(ms) //life(ms)
//子弹的存在时间(毫秒) //子弹的存在时间(毫秒)
@ -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.
//允许子弹撞击物品。 //允许子弹撞击物品。
@ -126,7 +131,7 @@ public partial class ProjectileTemplate : CharacterBody2D
//First get the owner's camp and compare it with the target camp //First get the owner's camp and compare it with the target camp
//先获取主人的阵营与目标阵营进行比较 //先获取主人的阵营与目标阵营进行比较
var canCauseHarm = CampManager.CanCauseHarm(CampManager.GetCamp(ownerCharacterTemplate.CampId), var canCauseHarm = CampManager.CanCauseHarm(CampManager.GetCamp(ownerCharacterTemplate.CampId),
CampManager.GetCamp(characterTemplate.CampId)); CampManager.GetCamp(characterTemplate.CampId));
return canCauseHarm; return canCauseHarm;
} }
@ -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>

View File

@ -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;