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="position"></param>
public void GenerateLootObjects(Node parentNode,
LootData[] lootDataArray,
Vector2 position)
LootData[] lootDataArray,
Vector2 position)
{
LootListManager.GenerateLootObjects(parentNode, lootDataArray, position);
}
@ -617,8 +617,8 @@ public partial class CharacterTemplate : CharacterBody2D
/// <para>抛出物品</para>
/// </summary>
/// <param name="index">
///<para>Item slot subscript in item container</para>
///<para>物品容器内的物品槽下标</para>
///<para>Item slot index in item container</para>
///<para>物品容器内的物品槽位置</para>
/// </param>
/// <param name="number">
/// <para>How many to throw</para>
@ -633,8 +633,41 @@ public partial class CharacterTemplate : CharacterBody2D
protected void ThrowItem(int index, int number, Vector2 velocity)
{
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)
{
@ -685,17 +718,6 @@ public partial class CharacterTemplate : CharacterBody2D
rigidBody2D.LinearVelocity = velocity;
break;
}
//Remove items from the item container
//在物品容器内移除物品
if (number < 0)
{
itemSlotNode!.RemoveItem(item.Quantity);
}
else
{
itemSlotNode!.RemoveItem(number);
}
}
/// <summary>

View File

@ -37,6 +37,8 @@ public partial class ItemSlotNode : MarginContainer
public TextureRect? BackgroundTextureRect => _backgroundTextureRect;
public bool IsEmpty() => _itemStack == null;
/// <summary>
/// <para>Get the item stack in the item slot</para>
/// <para>获取物品槽内的物品堆</para>

View File

@ -27,7 +27,7 @@ public class SingleItemStack(IItem_New item) : IItemStack
public int CanTakeFrom(IItemStack itemStack) => 0;
public int TakeFrom(IItemStack itemStack) => 0;
public bool TakeFrom(IItemStack itemStack) => false;
public IItem_New? GetItem()
{

View File

@ -35,6 +35,11 @@ public abstract partial class WeaponTemplate : RigidBody2D, IItem_New
Fire(owner, targetGlobalPosition);
}
public virtual void Destroy()
{
QueueFree();
}
/// <summary>
/// <para>Whether the weapon is currently picked up</para>

View File

@ -1,8 +1,11 @@
using System;
using ColdMint.scripts.camp;
using ColdMint.scripts.character;
using ColdMint.scripts.damage;
using ColdMint.scripts.weapon;
using ColdMint.scripts.item;
using ColdMint.scripts.item.weapon;
using Godot;
namespace ColdMint.scripts.projectile;
@ -64,10 +67,10 @@ public partial class ProjectileTemplate : CharacterBody2D
Area2D.Monitoring = true;
Area2D.BodyEntered += OnBodyEnter;
Area2D.BodyExited += OnBodyExited;
Durability = GetMeta("Durability", "1").AsDouble();
MaxDamage = GetMeta("MaxDamage", "7").AsInt32();
MinDamage = GetMeta("MinDamage", "5").AsInt32();
DamageType = GetMeta("DamageType", Config.DamageType.Physical).AsInt32();
Durability = GetMeta("Durability", "1").AsDouble();
MaxDamage = GetMeta("MaxDamage", "7").AsInt32();
MinDamage = GetMeta("MinDamage", "5").AsInt32();
DamageType = GetMeta("DamageType", Config.DamageType.Physical).AsInt32();
KnockbackForce = GetMeta("Knockback", Vector2.Zero).AsVector2();
//life(ms)
//子弹的存在时间(毫秒)
@ -111,7 +114,9 @@ public partial class ProjectileTemplate : CharacterBody2D
return true;
}
if (target is WeaponTemplate)
//Match any item now
//现在使它识别任何物品
if (target is IItem_New)
{
//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
//先获取主人的阵营与目标阵营进行比较
var canCauseHarm = CampManager.CanCauseHarm(CampManager.GetCamp(ownerCharacterTemplate.CampId),
CampManager.GetCamp(characterTemplate.CampId));
CampManager.GetCamp(characterTemplate.CampId));
return canCauseHarm;
}
@ -169,7 +174,8 @@ public partial class ProjectileTemplate : CharacterBody2D
force.Y = KnockbackForce.Y * Config.CellSize;
characterTemplate.AddForce(force);
}
}else if (target is WeaponTemplate weaponTemplate)
}
else if (target is WeaponTemplate weaponTemplate)
{
if (KnockbackForce != Vector2.Zero)
{
@ -225,9 +231,7 @@ public partial class ProjectileTemplate : CharacterBody2D
/// <para>当子弹离开节点时</para>
/// </summary>
/// <param name="node"></param>
protected virtual void OnBodyExited(Node2D node)
{
}
protected virtual void OnBodyExited(Node2D node) { }
/// <summary>

View File

@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using ColdMint.scripts.debug;
using ColdMint.scripts.weapon;
using ColdMint.scripts.item.weapon;
using Godot;
namespace ColdMint.scripts.utils;