287 lines
10 KiB
C#
287 lines
10 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Cielonos.MainGame.Characters.Inventory;
|
|
using Cielonos.MainGame.Characters.Inventory.Collections;
|
|
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 BackpackSubmodule backpackSm;
|
|
public EquipmentSubmodule equipmentSm;
|
|
|
|
public Transform mainWeaponContainer;
|
|
public Transform supportEquipmentContainer;
|
|
public Transform passiveEquipmentContainer;
|
|
public Transform consumableContainer;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
RegisterOperations();
|
|
backpackSm ??= new BackpackSubmodule(this);
|
|
equipmentSm ??= new EquipmentSubmodule(this);
|
|
|
|
backpackSm.ObtainItem<FutureWand>();
|
|
backpackSm.ObtainItem<Polychrome>();
|
|
|
|
foreach (MainWeaponBase mainWeapon in backpackSm.mainWeapons)
|
|
{
|
|
equipmentSm.PrepareMainWeapon(mainWeapon);
|
|
}
|
|
|
|
//backpackSm.ObtainItem<BlackHoleDisplacer>();
|
|
}
|
|
}
|
|
|
|
#region Functions
|
|
|
|
public partial class PlayerInventorySubcontroller
|
|
{
|
|
public void ApplyAttributeChange(string attributeName, ref float numeric, ref float percentageAccumulation, ref float percentageMultiplication)
|
|
{
|
|
foreach (var mainWeapon in backpackSm.mainWeapons.Where(mainWeapon => mainWeapon.passiveAttributeSm != null))
|
|
{
|
|
mainWeapon.passiveAttributeSm.ApplyAttributeChanges(attributeName, ref numeric, ref percentageAccumulation, ref percentageMultiplication);
|
|
}
|
|
|
|
foreach (var supportEquipment in backpackSm.supportEquipments.Where(supportEquipment => supportEquipment.passiveAttributeSm != null))
|
|
{
|
|
supportEquipment.passiveAttributeSm.ApplyAttributeChanges(attributeName, ref numeric, ref percentageAccumulation, ref percentageMultiplication);
|
|
}
|
|
|
|
foreach (var passiveEquipment in backpackSm.passiveEquipments.Where(passiveEquipment => passiveEquipment.passiveAttributeSm != null))
|
|
{
|
|
passiveEquipment.passiveAttributeSm.ApplyAttributeChanges(attributeName, ref numeric, ref percentageAccumulation, ref percentageMultiplication);
|
|
}
|
|
|
|
foreach (var consumable in backpackSm.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
|
|
|
|
#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;
|
|
}
|
|
}
|
|
|
|
#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();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |