2024-10-04 12:53:34 +00:00
|
|
|
using System.Collections.Generic;
|
2024-04-28 13:55:19 +00:00
|
|
|
using ColdMint.scripts.debug;
|
2024-10-04 02:21:09 +00:00
|
|
|
using ColdMint.scripts.inventory;
|
2024-10-04 12:53:34 +00:00
|
|
|
using ColdMint.scripts.map.events;
|
|
|
|
using ColdMint.scripts.projectile;
|
2024-04-28 13:55:19 +00:00
|
|
|
using Godot;
|
|
|
|
|
2024-06-22 11:21:06 +00:00
|
|
|
namespace ColdMint.scripts.weapon;
|
2024-04-28 13:55:19 +00:00
|
|
|
|
2024-06-05 13:38:45 +00:00
|
|
|
/// <summary>
|
|
|
|
/// <para>Projectile weapons</para>
|
|
|
|
/// <para>抛射体武器</para>
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
///<para>These weapons can fire projectiles to attack the enemy.For example: guns and scepters.Generate a bullet to attack the enemy.</para>
|
|
|
|
///<para>这类武器可发射抛射体,攻击敌人。例如:枪支和法杖。生成一个子弹攻击敌人。</para>
|
|
|
|
/// </remarks>
|
2024-04-28 13:55:19 +00:00
|
|
|
public partial class ProjectileWeapon : WeaponTemplate
|
|
|
|
{
|
2024-06-05 13:38:45 +00:00
|
|
|
/// <summary>
|
|
|
|
/// <para>The formation position of the projectile</para>
|
|
|
|
/// <para>抛射体的生成位置</para>
|
|
|
|
/// </summary>
|
2024-05-08 10:22:04 +00:00
|
|
|
private Marker2D? _marker2D;
|
2024-10-04 12:53:34 +00:00
|
|
|
|
2024-08-11 15:29:23 +00:00
|
|
|
/// <summary>
|
2024-10-04 02:21:09 +00:00
|
|
|
/// <para>Number of slots for ranged weapons</para>
|
|
|
|
/// <para>远程武器的槽位数量</para>
|
2024-08-11 15:29:23 +00:00
|
|
|
/// </summary>
|
2024-10-04 02:21:09 +00:00
|
|
|
[Export] public int NumberSlots { get; set; }
|
2024-08-11 15:29:23 +00:00
|
|
|
|
2024-10-04 12:53:34 +00:00
|
|
|
private readonly List<IMagic> _magics = new();
|
|
|
|
|
2024-10-04 02:21:09 +00:00
|
|
|
public override int ItemType
|
|
|
|
{
|
|
|
|
get => Config.ItemType.ProjectileWeapon;
|
|
|
|
}
|
2024-10-04 12:53:34 +00:00
|
|
|
|
2024-05-08 10:22:04 +00:00
|
|
|
public override void _Ready()
|
|
|
|
{
|
|
|
|
base._Ready();
|
|
|
|
_marker2D = GetNode<Marker2D>("Marker2D");
|
2024-10-04 02:21:09 +00:00
|
|
|
SelfItemContainer = new UniversalItemContainer(NumberSlots);
|
|
|
|
SelfItemContainer.AllowAddingItemByType(Config.ItemType.Magic);
|
2024-10-04 12:53:34 +00:00
|
|
|
SelfItemContainer.ItemDataChangeEvent += OnItemDataChangeEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnItemDataChangeEvent(ItemDataChangeEvent itemDataChangeEvent)
|
|
|
|
{
|
|
|
|
if (SelfItemContainer == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_magics.Clear();
|
|
|
|
var totalCapacity = SelfItemContainer.GetTotalCapacity();
|
|
|
|
for (var i = 0; i < totalCapacity; i++)
|
|
|
|
{
|
|
|
|
var item = SelfItemContainer.GetItem(i);
|
|
|
|
if (item == null)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (item is not IMagic magic)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
_magics.Add(magic);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void _ExitTree()
|
|
|
|
{
|
|
|
|
base._ExitTree();
|
|
|
|
if (SelfItemContainer != null)
|
|
|
|
{
|
|
|
|
SelfItemContainer.ItemDataChangeEvent -= OnItemDataChangeEvent;
|
|
|
|
}
|
2024-05-08 10:22:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void DoFire(Node2D? owner, Vector2 enemyGlobalPosition)
|
|
|
|
{
|
2024-07-24 13:03:24 +00:00
|
|
|
if (owner == null)
|
|
|
|
{
|
|
|
|
LogCat.LogError("owner_is_null");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_marker2D == null)
|
|
|
|
{
|
|
|
|
LogCat.LogError("marker2d_is_null");
|
|
|
|
return;
|
|
|
|
}
|
2024-06-10 13:05:18 +00:00
|
|
|
|
2024-09-01 15:24:35 +00:00
|
|
|
if (GameSceneDepend.ProjectileContainer == null)
|
2024-07-24 13:03:24 +00:00
|
|
|
{
|
|
|
|
LogCat.LogError("projectile_container_is_null");
|
|
|
|
return;
|
|
|
|
}
|
2024-10-04 12:53:34 +00:00
|
|
|
if (_magics.Count == 0)
|
|
|
|
{
|
|
|
|
LogCat.LogError("magics_is_null");
|
|
|
|
return;
|
|
|
|
}
|
2024-05-08 10:22:04 +00:00
|
|
|
}
|
|
|
|
}
|