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

247 lines
9.0 KiB
C#
Raw Normal View History

2026-01-03 18:19:39 -05:00
using System.Collections.Generic;
using System.Linq;
2026-03-20 12:07:44 -04:00
using Cielonos.MainGame.Characters.Inventory;
2025-11-25 08:19:33 -05:00
using UnityEngine;
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;
2025-12-23 19:47:06 -05:00
public PlayerBackpack backpack;
2025-11-25 08:19:33 -05:00
public PlayerEquipmentSubmodule equipmentSm;
public override void Initialize()
{
base.Initialize();
RegisterOperations();
2025-12-23 19:47:06 -05:00
equipmentSm ??= new PlayerEquipmentSubmodule(this);
2026-01-03 18:19:39 -05:00
backpack.ObtainInitialItems();
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)
{
foreach (var mainWeapon in backpack.mainWeapons.Where(mainWeapon => mainWeapon.passiveAttributeSm != null))
{
mainWeapon.passiveAttributeSm.ApplyAttributeChanges(attributeName, ref numeric, ref percentageAccumulation, ref percentageMultiplication);
}
foreach (var supportEquipment in backpack.supportEquipments.Where(supportEquipment => supportEquipment.passiveAttributeSm != null))
{
supportEquipment.passiveAttributeSm.ApplyAttributeChanges(attributeName, ref numeric, ref percentageAccumulation, ref percentageMultiplication);
}
foreach (var passiveEquipment in backpack.passiveEquipments.Where(passiveEquipment => passiveEquipment.passiveAttributeSm != null))
{
passiveEquipment.passiveAttributeSm.ApplyAttributeChanges(attributeName, ref numeric, ref percentageAccumulation, ref percentageMultiplication);
}
foreach (var consumable in backpack.consumables.Where(consumable => consumable.passiveAttributeSm != null))
{
consumable.passiveAttributeSm.ApplyAttributeChanges(attributeName, ref numeric, ref percentageAccumulation, ref percentageMultiplication);
}
currentMainWeapon?.activeAttributeSm?.ApplyAttributeChanges(attributeName, ref numeric, ref percentageAccumulation, ref percentageMultiplication);
foreach (SupportEquipmentBase supportEquipment in currentSupportEquipments)
{
supportEquipment?.activeAttributeSm?.ApplyAttributeChanges(attributeName, ref numeric, ref percentageAccumulation, ref percentageMultiplication);
}
}
}
#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
}