Files
Cielonos/Assets/Scripts/MainGame/Characters/Player/Inventory/PlayerEquipmentSubmodule.cs

138 lines
4.3 KiB
C#
Raw Normal View History

2025-11-25 08:19:33 -05:00
using System.Collections.Generic;
2026-03-20 12:07:44 -04:00
using Cielonos.MainGame.Characters.Inventory;
2026-02-13 09:22:11 -05:00
using Cielonos.MainGame.UI;
2025-11-25 08:19:33 -05:00
using UnityEngine;
namespace Cielonos.MainGame.Characters
{
2026-01-03 18:19:39 -05:00
public partial class PlayerEquipmentSubmodule : SubmoduleBase<PlayerInventorySubcontroller>
2025-11-25 08:19:33 -05:00
{
public List<MainWeaponBase> preparedMainWeapons;
public MainWeaponBase currentMainWeapon;
2026-01-03 18:19:39 -05:00
public List<SupportEquipmentBase> currentSupportEquipments;
2025-11-25 08:19:33 -05:00
public PlayerEquipmentSubmodule(PlayerInventorySubcontroller owner) : base(owner)
{
preparedMainWeapons = new List<MainWeaponBase>();
2026-01-03 18:19:39 -05:00
currentSupportEquipments = new List<SupportEquipmentBase>(4) { null, null, null, null };
2025-12-23 19:47:06 -05:00
foreach (MainWeaponBase mainWeapon in owner.backpack.mainWeapons)
{
2026-01-03 18:19:39 -05:00
PrepareMainWeapon(mainWeapon);
}
}
}
#region Main Weapon
public partial class PlayerEquipmentSubmodule
{
public void PrepareMainWeapon(MainWeaponBase weaponToPrepare)
{
if (!preparedMainWeapons.Contains(weaponToPrepare))
{
preparedMainWeapons.Add(weaponToPrepare);
2025-12-23 19:47:06 -05:00
}
}
2026-01-03 18:19:39 -05:00
public void WithdrawMainWeapon(MainWeaponBase weaponToWithdraw)
2025-12-23 19:47:06 -05:00
{
2026-01-03 18:19:39 -05:00
if (preparedMainWeapons.Contains(weaponToWithdraw))
2025-12-23 19:47:06 -05:00
{
2026-01-03 18:19:39 -05:00
if (currentMainWeapon == weaponToWithdraw)
{
RemoveMainWeapon();
}
preparedMainWeapons.Remove(weaponToWithdraw);
Object.Destroy(weaponToWithdraw);
2025-12-23 19:47:06 -05:00
}
2025-11-25 08:19:33 -05:00
}
2026-01-03 18:19:39 -05:00
2025-11-25 08:19:33 -05:00
public void EquipMainWeapon(MainWeaponBase newWeapon)
{
currentMainWeapon = newWeapon;
2026-02-13 09:22:11 -05:00
currentMainWeapon.RegisterFuncAnims();
2025-12-24 16:58:51 -05:00
currentMainWeapon.OnEquipped();
2026-01-03 18:19:39 -05:00
PlayerCanvas.Instance.mainWeaponUIArea.Initialize(newWeapon);
2025-11-25 08:19:33 -05:00
}
public void RemoveMainWeapon()
{
2025-12-23 19:47:06 -05:00
Debug.Log("Unequipping main weapon: " + currentMainWeapon);
2025-11-25 08:19:33 -05:00
currentMainWeapon.OnUnequipped();
currentMainWeapon = null;
}
2026-01-03 18:19:39 -05:00
}
#endregion
#region Support Equipment
public partial class PlayerEquipmentSubmodule
{
public void EquipSupportEquipment(SupportEquipmentBase newEquipment, int slotIndex)
2025-12-23 19:47:06 -05:00
{
2026-01-03 18:19:39 -05:00
if (slotIndex < 0 || slotIndex >= 4)
{
Debug.LogWarning("Invalid support equipment slot index: " + slotIndex);
return;
}
//如果当前槽位没有足够的空间,扩展列表
if (currentSupportEquipments.Count <= slotIndex)
2025-12-23 19:47:06 -05:00
{
2026-01-03 18:19:39 -05:00
while (currentSupportEquipments.Count <= slotIndex)
2025-12-23 19:47:06 -05:00
{
2026-01-03 18:19:39 -05:00
currentSupportEquipments.Add(null);
2025-12-23 19:47:06 -05:00
}
2026-01-03 18:19:39 -05:00
}
//卸下当前装备(如果有的话)
if (currentSupportEquipments[slotIndex] != null)
{
currentSupportEquipments[slotIndex].OnUnequipped();
}
currentSupportEquipments[slotIndex] = newEquipment;
2026-02-13 09:22:11 -05:00
newEquipment.RegisterFuncAnims();
2026-01-03 18:19:39 -05:00
newEquipment.OnEquipped();
PlayerCanvas.Instance.supportEquipmentsUIArea.Initialize(newEquipment, slotIndex);
}
public void RemoveSupportEquipment(SupportEquipmentBase equipmentToRemove)
{
int slotIndex = currentSupportEquipments.IndexOf(equipmentToRemove);
if (slotIndex != -1)
{
equipmentToRemove.OnUnequipped();
currentSupportEquipments[slotIndex] = null;
PlayerCanvas.Instance.supportEquipmentsUIArea.Remove(slotIndex);
}
}
public void RemoveSupportEquipment(int slotIndex)
{
if (slotIndex < 0 || slotIndex >= currentSupportEquipments.Count)
{
Debug.LogWarning("Invalid support equipment slot index: " + slotIndex);
return;
}
SupportEquipmentBase equipmentToRemove = currentSupportEquipments[slotIndex];
if (equipmentToRemove != null)
{
equipmentToRemove.OnUnequipped();
currentSupportEquipments[slotIndex] = null;
PlayerCanvas.Instance.supportEquipmentsUIArea.Remove(slotIndex);
2025-12-23 19:47:06 -05:00
}
}
2025-11-25 08:19:33 -05:00
}
2026-01-03 18:19:39 -05:00
#endregion
2025-11-25 08:19:33 -05:00
}