138 lines
4.3 KiB
C#
138 lines
4.3 KiB
C#
using System.Collections.Generic;
|
|
using Cielonos.MainGame.Characters.Inventory;
|
|
using Cielonos.MainGame.UI;
|
|
using UnityEngine;
|
|
|
|
namespace Cielonos.MainGame.Characters
|
|
{
|
|
public partial class PlayerEquipmentSubmodule : SubmoduleBase<PlayerInventorySubcontroller>
|
|
{
|
|
public List<MainWeaponBase> preparedMainWeapons;
|
|
public MainWeaponBase currentMainWeapon;
|
|
public List<SupportEquipmentBase> currentSupportEquipments;
|
|
|
|
public PlayerEquipmentSubmodule(PlayerInventorySubcontroller owner) : base(owner)
|
|
{
|
|
preparedMainWeapons = new List<MainWeaponBase>();
|
|
currentSupportEquipments = new List<SupportEquipmentBase>(4) { null, null, null, null };
|
|
foreach (MainWeaponBase mainWeapon in owner.backpack.mainWeapons)
|
|
{
|
|
PrepareMainWeapon(mainWeapon);
|
|
}
|
|
}
|
|
}
|
|
|
|
#region Main Weapon
|
|
|
|
public partial class PlayerEquipmentSubmodule
|
|
{
|
|
public void PrepareMainWeapon(MainWeaponBase weaponToPrepare)
|
|
{
|
|
if (!preparedMainWeapons.Contains(weaponToPrepare))
|
|
{
|
|
preparedMainWeapons.Add(weaponToPrepare);
|
|
}
|
|
}
|
|
|
|
public void WithdrawMainWeapon(MainWeaponBase weaponToWithdraw)
|
|
{
|
|
if (preparedMainWeapons.Contains(weaponToWithdraw))
|
|
{
|
|
if (currentMainWeapon == weaponToWithdraw)
|
|
{
|
|
RemoveMainWeapon();
|
|
}
|
|
|
|
preparedMainWeapons.Remove(weaponToWithdraw);
|
|
Object.Destroy(weaponToWithdraw);
|
|
}
|
|
}
|
|
|
|
public void EquipMainWeapon(MainWeaponBase newWeapon)
|
|
{
|
|
currentMainWeapon = newWeapon;
|
|
currentMainWeapon.RegisterFuncAnims();
|
|
currentMainWeapon.OnEquipped();
|
|
|
|
PlayerCanvas.Instance.mainWeaponUIArea.Initialize(newWeapon);
|
|
}
|
|
|
|
public void RemoveMainWeapon()
|
|
{
|
|
Debug.Log("Unequipping main weapon: " + currentMainWeapon);
|
|
currentMainWeapon.OnUnequipped();
|
|
currentMainWeapon = null;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Support Equipment
|
|
|
|
public partial class PlayerEquipmentSubmodule
|
|
{
|
|
public void EquipSupportEquipment(SupportEquipmentBase newEquipment, int slotIndex)
|
|
{
|
|
if (slotIndex < 0 || slotIndex >= 4)
|
|
{
|
|
Debug.LogWarning("Invalid support equipment slot index: " + slotIndex);
|
|
return;
|
|
}
|
|
|
|
//如果当前槽位没有足够的空间,扩展列表
|
|
if (currentSupportEquipments.Count <= slotIndex)
|
|
{
|
|
while (currentSupportEquipments.Count <= slotIndex)
|
|
{
|
|
currentSupportEquipments.Add(null);
|
|
}
|
|
}
|
|
|
|
//卸下当前装备(如果有的话)
|
|
if (currentSupportEquipments[slotIndex] != null)
|
|
{
|
|
currentSupportEquipments[slotIndex].OnUnequipped();
|
|
}
|
|
|
|
currentSupportEquipments[slotIndex] = newEquipment;
|
|
newEquipment.RegisterFuncAnims();
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
} |