Files
Cielonos/Assets/Scripts/MainGame/Characters/Player/Inventory/PlayerInventorySubcontroller.cs
SoulliesOfficial f26f9fd374 爆更
2026-03-20 12:07:44 -04:00

247 lines
9.0 KiB
C#

using System.Collections.Generic;
using System.Linq;
using Cielonos.MainGame.Characters.Inventory;
using UnityEngine;
namespace Cielonos.MainGame.Characters
{
public partial class PlayerInventorySubcontroller : SubcontrollerBase<Player>
{
public Player player => owner;
private PlayerInputSubcontroller inputSc => player.inputSc;
private PlayerOperationSubcontroller operationSc => player.operationSc;
public PlayerBackpack backpack;
public PlayerEquipmentSubmodule equipmentSm;
public override void Initialize()
{
base.Initialize();
RegisterOperations();
equipmentSm ??= new PlayerEquipmentSubmodule(this);
backpack.ObtainInitialItems();
}
}
#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
public partial class PlayerInventorySubcontroller
{
private MainWeaponBase currentMainWeapon => equipmentSm.currentMainWeapon;
private List<SupportEquipmentBase> currentSupportEquipments => equipmentSm.currentSupportEquipments;
private void RegisterOperations()
{
//operationSc.OnMainWeaponSpecialPress += MainWeaponSpecialPress;
//operationSc.OnMainWeaponSpecialRelease += MainWeaponSpecialRelease;
operationSc.OnMainWeaponPrimaryPress += MainWeaponPrimaryPress;
operationSc.OnMainWeaponPrimaryRelease += MainWeaponPrimaryRelease;
operationSc.OnMainWeaponSecondaryPress += MainWeaponSecondaryPress;
operationSc.OnMainWeaponSecondaryRelease += MainWeaponSecondaryRelease;
operationSc.OnMainWeaponSpecialAPress += MainWeaponSpecialAPress;
operationSc.OnMainWeaponSpecialARelease += MainWeaponSpecialARelease;
operationSc.OnMainWeaponSpecialBPress += MainWeaponSpecialBPress;
operationSc.OnMainWeaponSpecialBRelease += MainWeaponSpecialBRelease;
operationSc.OnMainWeaponSpecialCPress += MainWeaponSpecialCPress;
operationSc.OnMainWeaponSpecialCRelease += MainWeaponSpecialCRelease;
operationSc.OnSwitchMainWeapon += SwitchMainWeapon;
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);
}
public virtual void Update()
{
if (inputSc.IsHoldingPrimary)
{
currentMainWeapon.OnPrimaryHold();
}
if (inputSc.IsHoldingSecondary)
{
currentMainWeapon.OnSecondaryHold();
}
if (inputSc.IsHoldingSpecialA)
{
currentMainWeapon.OnSpecialAHold();
}
if (inputSc.IsHoldingSpecialB)
{
currentMainWeapon.OnSpecialBHold();
}
if (inputSc.IsHoldingSpecialC)
{
currentMainWeapon.OnSpecialCHold();
}
}
}
public partial class PlayerInventorySubcontroller
{
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]);
}
private void MainWeaponPrimaryPress()
{
if (currentMainWeapon != null)
{
currentMainWeapon.OnPrimaryPress();
player.movementSc.isSprinting = false;
}
}
private void MainWeaponPrimaryRelease()
{
if (currentMainWeapon != null)
{
currentMainWeapon.OnPrimaryRelease();
}
}
private void MainWeaponSecondaryPress()
{
if (currentMainWeapon != null)
{
currentMainWeapon.OnSecondaryPress();
player.movementSc.isSprinting = false;
}
}
private void MainWeaponSecondaryRelease()
{
if (currentMainWeapon != null)
{
currentMainWeapon.OnSecondaryRelease();
}
}
private void MainWeaponSpecialAPress()
{
if (currentMainWeapon != null)
{
currentMainWeapon.OnSpecialAPress();
player.movementSc.isSprinting = false;
}
}
private void MainWeaponSpecialARelease()
{
if (currentMainWeapon != null)
{
currentMainWeapon.OnSpecialARelease();
}
}
private void MainWeaponSpecialBPress()
{
if (currentMainWeapon != null)
{
currentMainWeapon.OnSpecialBPress();
player.movementSc.isSprinting = false;
}
}
private void MainWeaponSpecialBRelease()
{
if (currentMainWeapon != null)
{
currentMainWeapon.OnSpecialBRelease();
}
}
private void MainWeaponSpecialCPress()
{
if (currentMainWeapon != null)
{
currentMainWeapon.OnSpecialCPress();
player.movementSc.isSprinting = false;
}
}
private void MainWeaponSpecialCRelease()
{
if (currentMainWeapon != null)
{
currentMainWeapon.OnSpecialCRelease();
}
}
}
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();
}
}
}
}
}