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

297 lines
11 KiB
C#
Raw Normal View History

2026-01-03 18:19:39 -05:00
using System.Collections.Generic;
using System.Linq;
2026-05-23 08:27:50 -04:00
using Cielonos.MainGame.Inventory;
using Cielonos.MainGame.Inventory.Collection;
using Cielonos.MainGame.Inventory.Collections;
2026-05-10 11:47:55 -04:00
using UnityEngine;
2025-11-25 08:19:33 -05:00
namespace Cielonos.MainGame.Characters
{
2026-02-13 09:22:11 -05:00
public partial class PlayerInventorySubcontroller : SubcontrollerBase<Player>
2025-11-25 08:19:33 -05:00
{
public Player player => owner;
private PlayerInputSubcontroller inputSc => player.inputSc;
private PlayerOperationSubcontroller operationSc => player.operationSc;
2026-05-10 11:47:55 -04:00
public BackpackSubmodule backpackSm;
public EquipmentSubmodule equipmentSm;
public Transform mainWeaponContainer;
public Transform supportEquipmentContainer;
public Transform passiveEquipmentContainer;
public Transform consumableContainer;
2025-11-25 08:19:33 -05:00
public override void Initialize()
{
base.Initialize();
RegisterOperations();
2026-05-10 11:47:55 -04:00
backpackSm ??= new BackpackSubmodule(this);
equipmentSm ??= new EquipmentSubmodule(this);
2026-05-26 00:21:27 -04:00
//backpackSm.ObtainItem<DualHarmony>();
2026-06-02 12:55:39 -04:00
/*backpackSm.ObtainItem<Polychrome>();
2026-05-26 00:21:27 -04:00
backpackSm.ObtainItem<FutureWand>();
2026-05-23 08:27:50 -04:00
backpackSm.ObtainItem<Ascension>();
2026-05-26 00:21:27 -04:00
backpackSm.ObtainItem<BlackHoleDisplacer>();
2026-05-23 08:27:50 -04:00
backpackSm.ObtainItem<DecayPropagator>();
2026-05-26 00:21:27 -04:00
backpackSm.ObtainItem<DecayAccelerationCoil>();
2026-05-23 08:27:50 -04:00
backpackSm.ObtainItem<FusionInjector>();
2026-05-26 00:21:27 -04:00
backpackSm.ObtainItem<MissileSeparationMembrane>();
2026-05-27 15:15:28 -04:00
backpackSm.ObtainItem<PhotonPolarizer>();
2026-06-02 12:55:39 -04:00
backpackSm.ObtainItem<PhotonDissociator>();*/
2026-05-10 11:47:55 -04:00
foreach (MainWeaponBase mainWeapon in backpackSm.mainWeapons)
{
equipmentSm.PrepareMainWeapon(mainWeapon);
}
//backpackSm.ObtainItem<BlackHoleDisplacer>();
2025-11-25 08:19:33 -05:00
}
}
2026-01-03 18:19:39 -05:00
#region Functions
public partial class PlayerInventorySubcontroller
{
public void ApplyAttributeChange(string attributeName, ref float numeric, ref float percentageAccumulation, ref float percentageMultiplication)
{
2026-05-10 11:47:55 -04:00
foreach (var mainWeapon in backpackSm.mainWeapons.Where(mainWeapon => mainWeapon.passiveAttributeSm != null))
2026-01-03 18:19:39 -05:00
{
2026-05-23 08:27:50 -04:00
mainWeapon.passiveAttributeSm.ApplyCharacterAttributeChanges(attributeName, ref numeric, ref percentageAccumulation, ref percentageMultiplication);
2026-01-03 18:19:39 -05:00
}
2026-05-10 11:47:55 -04:00
foreach (var supportEquipment in backpackSm.supportEquipments.Where(supportEquipment => supportEquipment.passiveAttributeSm != null))
2026-01-03 18:19:39 -05:00
{
2026-05-23 08:27:50 -04:00
supportEquipment.passiveAttributeSm.ApplyCharacterAttributeChanges(attributeName, ref numeric, ref percentageAccumulation, ref percentageMultiplication);
2026-01-03 18:19:39 -05:00
}
2026-05-10 11:47:55 -04:00
foreach (var passiveEquipment in backpackSm.passiveEquipments.Where(passiveEquipment => passiveEquipment.passiveAttributeSm != null))
2026-01-03 18:19:39 -05:00
{
2026-05-23 08:27:50 -04:00
passiveEquipment.passiveAttributeSm.ApplyCharacterAttributeChanges(attributeName, ref numeric, ref percentageAccumulation, ref percentageMultiplication);
2026-01-03 18:19:39 -05:00
}
2026-05-10 11:47:55 -04:00
foreach (var consumable in backpackSm.consumables.Where(consumable => consumable.passiveAttributeSm != null))
2026-01-03 18:19:39 -05:00
{
2026-05-23 08:27:50 -04:00
consumable.passiveAttributeSm.ApplyCharacterAttributeChanges(attributeName, ref numeric, ref percentageAccumulation, ref percentageMultiplication);
2026-01-03 18:19:39 -05:00
}
2026-05-23 08:27:50 -04:00
currentMainWeapon?.activeAttributeSm?.ApplyCharacterAttributeChanges(attributeName, ref numeric, ref percentageAccumulation, ref percentageMultiplication);
2026-01-03 18:19:39 -05:00
foreach (SupportEquipmentBase supportEquipment in currentSupportEquipments)
{
2026-05-23 08:27:50 -04:00
supportEquipment?.activeAttributeSm?.ApplyCharacterAttributeChanges(attributeName, ref numeric, ref percentageAccumulation, ref percentageMultiplication);
2026-01-03 18:19:39 -05:00
}
}
}
2026-05-10 11:47:55 -04:00
#endregion
#region Rare Materials
public partial class PlayerInventorySubcontroller
{
/// <summary>
/// 获取玩家当前持有的 RareMaterial。
/// </summary>
public RareMaterial GetRareMaterial()
{
return backpackSm.consumables.Find(c => c is RareMaterial) as RareMaterial;
}
/// <summary>
/// 获取玩家当前持有的 RareMaterial 数量。
/// </summary>
public int GetRareMaterialAmount()
{
RareMaterial rm = GetRareMaterial();
return rm != null ? rm.stackAmount : 0;
}
}
2026-01-03 18:19:39 -05:00
#endregion
2025-11-25 08:19:33 -05:00
public partial class PlayerInventorySubcontroller
{
private MainWeaponBase currentMainWeapon => equipmentSm.currentMainWeapon;
2026-01-03 18:19:39 -05:00
private List<SupportEquipmentBase> currentSupportEquipments => equipmentSm.currentSupportEquipments;
2025-11-25 08:19:33 -05:00
private void RegisterOperations()
{
//operationSc.OnMainWeaponSpecialPress += MainWeaponSpecialPress;
//operationSc.OnMainWeaponSpecialRelease += MainWeaponSpecialRelease;
operationSc.OnMainWeaponPrimaryPress += MainWeaponPrimaryPress;
operationSc.OnMainWeaponPrimaryRelease += MainWeaponPrimaryRelease;
operationSc.OnMainWeaponSecondaryPress += MainWeaponSecondaryPress;
operationSc.OnMainWeaponSecondaryRelease += MainWeaponSecondaryRelease;
2026-02-13 09:22:11 -05:00
operationSc.OnMainWeaponSpecialAPress += MainWeaponSpecialAPress;
operationSc.OnMainWeaponSpecialARelease += MainWeaponSpecialARelease;
operationSc.OnMainWeaponSpecialBPress += MainWeaponSpecialBPress;
operationSc.OnMainWeaponSpecialBRelease += MainWeaponSpecialBRelease;
operationSc.OnMainWeaponSpecialCPress += MainWeaponSpecialCPress;
operationSc.OnMainWeaponSpecialCRelease += MainWeaponSpecialCRelease;
2025-11-25 08:19:33 -05:00
2025-12-23 19:47:06 -05:00
operationSc.OnSwitchMainWeapon += SwitchMainWeapon;
2026-01-03 18:19:39 -05:00
operationSc.OnSupportEquipment0Press += () => SupportEquipmentPress(0);
operationSc.OnSupportEquipment1Press += () => SupportEquipmentPress(1);
operationSc.OnSupportEquipment2Press += () => SupportEquipmentPress(2);
operationSc.OnSupportEquipment3Press += () => SupportEquipmentPress(3);
operationSc.OnSupportEquipment0Release += () => SupportEquipmentRelease(0);
operationSc.OnSupportEquipment1Release += () => SupportEquipmentRelease(1);
operationSc.OnSupportEquipment2Release += () => SupportEquipmentRelease(2);
operationSc.OnSupportEquipment3Release += () => SupportEquipmentRelease(3);
2025-11-25 08:19:33 -05:00
}
public virtual void Update()
{
if (inputSc.IsHoldingPrimary)
{
currentMainWeapon.OnPrimaryHold();
}
if (inputSc.IsHoldingSecondary)
{
currentMainWeapon.OnSecondaryHold();
}
2025-12-08 05:27:53 -05:00
if (inputSc.IsHoldingSpecialA)
2025-11-25 08:19:33 -05:00
{
2025-12-08 05:27:53 -05:00
currentMainWeapon.OnSpecialAHold();
2025-11-25 08:19:33 -05:00
}
2025-12-08 05:27:53 -05:00
if (inputSc.IsHoldingSpecialB)
2025-11-25 08:19:33 -05:00
{
2025-12-08 05:27:53 -05:00
currentMainWeapon.OnSpecialBHold();
2025-11-25 08:19:33 -05:00
}
2026-02-13 09:22:11 -05:00
if (inputSc.IsHoldingSpecialC)
{
currentMainWeapon.OnSpecialCHold();
}
2025-11-25 08:19:33 -05:00
}
}
public partial class PlayerInventorySubcontroller
{
2025-12-23 19:47:06 -05:00
private void SwitchMainWeapon(int direction)
{
int currentIndex = equipmentSm.preparedMainWeapons.IndexOf(currentMainWeapon);
equipmentSm.RemoveMainWeapon();
int newIndex = (currentIndex + direction + equipmentSm.preparedMainWeapons.Count) % equipmentSm.preparedMainWeapons.Count;
Debug.Log($"Switching main weapon from index {currentIndex} to {newIndex}");
equipmentSm.EquipMainWeapon(equipmentSm.preparedMainWeapons[newIndex]);
}
2026-01-03 18:19:39 -05:00
private void MainWeaponPrimaryPress()
2025-11-25 08:19:33 -05:00
{
if (currentMainWeapon != null)
{
currentMainWeapon.OnPrimaryPress();
2025-12-08 05:27:53 -05:00
player.movementSc.isSprinting = false;
2025-11-25 08:19:33 -05:00
}
}
2026-01-03 18:19:39 -05:00
private void MainWeaponPrimaryRelease()
2025-11-25 08:19:33 -05:00
{
if (currentMainWeapon != null)
{
currentMainWeapon.OnPrimaryRelease();
}
}
2026-01-03 18:19:39 -05:00
private void MainWeaponSecondaryPress()
2025-11-25 08:19:33 -05:00
{
if (currentMainWeapon != null)
{
currentMainWeapon.OnSecondaryPress();
2025-12-08 05:27:53 -05:00
player.movementSc.isSprinting = false;
2025-11-25 08:19:33 -05:00
}
}
2026-01-03 18:19:39 -05:00
private void MainWeaponSecondaryRelease()
2025-11-25 08:19:33 -05:00
{
if (currentMainWeapon != null)
{
currentMainWeapon.OnSecondaryRelease();
}
}
2026-01-03 18:19:39 -05:00
private void MainWeaponSpecialAPress()
2025-11-25 08:19:33 -05:00
{
if (currentMainWeapon != null)
{
2025-12-08 05:27:53 -05:00
currentMainWeapon.OnSpecialAPress();
2025-11-25 08:19:33 -05:00
player.movementSc.isSprinting = false;
}
}
2026-01-03 18:19:39 -05:00
private void MainWeaponSpecialARelease()
2025-11-25 08:19:33 -05:00
{
if (currentMainWeapon != null)
{
2025-12-08 05:27:53 -05:00
currentMainWeapon.OnSpecialARelease();
2025-11-25 08:19:33 -05:00
}
}
2026-01-03 18:19:39 -05:00
private void MainWeaponSpecialBPress()
2025-11-25 08:19:33 -05:00
{
if (currentMainWeapon != null)
{
2025-12-08 05:27:53 -05:00
currentMainWeapon.OnSpecialBPress();
2025-11-25 08:19:33 -05:00
player.movementSc.isSprinting = false;
}
}
2026-01-03 18:19:39 -05:00
private void MainWeaponSpecialBRelease()
2025-11-25 08:19:33 -05:00
{
if (currentMainWeapon != null)
{
2025-12-08 05:27:53 -05:00
currentMainWeapon.OnSpecialBRelease();
2025-11-25 08:19:33 -05:00
}
}
2026-02-13 09:22:11 -05:00
private void MainWeaponSpecialCPress()
{
if (currentMainWeapon != null)
{
currentMainWeapon.OnSpecialCPress();
player.movementSc.isSprinting = false;
}
}
private void MainWeaponSpecialCRelease()
{
if (currentMainWeapon != null)
{
currentMainWeapon.OnSpecialCRelease();
}
}
2025-11-25 08:19:33 -05:00
}
2026-01-03 18:19:39 -05:00
public partial class PlayerInventorySubcontroller
{
private void SupportEquipmentPress(int slotIndex)
{
if (currentSupportEquipments.Count > slotIndex)
{
var equipment = currentSupportEquipments[slotIndex];
if (equipment != null)
{
equipment.OnPress();
}
}
}
private void SupportEquipmentRelease(int slotIndex)
{
if (currentSupportEquipments.Count > slotIndex)
{
var equipment = currentSupportEquipments[slotIndex];
if (equipment != null)
{
equipment.OnRelease();
}
}
}
}
2025-11-25 08:19:33 -05:00
}