Files
Cielonos/Assets/Scripts/MainGame/Characters/Player/Player.cs
SoulliesOfficial 8ad26129b2 Feel滚
2026-04-29 06:16:07 -04:00

134 lines
5.3 KiB
C#

using System.Collections.Generic;
using Cielonos.MainGame.Buffs.Character;
using Cielonos.MainGame.UI;
using Sirenix.OdinInspector;
using SLSUtilities.General;
using UnityEngine;
using UnityEngine.Serialization;
namespace Cielonos.MainGame.Characters
{
public partial class Player : CharacterBase
{
[TitleGroup("Data")]
public AttributeData globalAttributeData;
[TitleGroup("Data")]
public PlayerViewPreset baseViewPreset;
[TitleGroup("Submodules")]
public AttributeSubmodule globalAttributeSm;
public PlayerEventSubmodule eventSm => base.eventSm as PlayerEventSubmodule;
[Required]
[TitleGroup("Subcontrollers")]
public PlayerInputSubcontroller inputSc;
[Required]
[TitleGroup("Subcontrollers")]
public PlayerOperationSubcontroller operationSc;
[Required]
[TitleGroup("Subcontrollers")]
public PlayerInteractionSubcontroller interactionSc;
[Required]
[TitleGroup("Subcontrollers")]
public PlayerViewSubcontroller viewSc;
[Required]
[TitleGroup("Subcontrollers")]
public PlayerLandMovementSubcontroller landMovementSc => base.movementSc as PlayerLandMovementSubcontroller;
[Required]
[TitleGroup("Subcontrollers")]
public PlayerInventorySubcontroller inventorySc;
[HideInEditorMode]
public new PlayerAnimationSubcontroller animationSc => base.animationSc as PlayerAnimationSubcontroller;
}
public partial class Player
{
protected override void InitializeSubmodules()
{
globalAttributeSm = new AttributeSubmodule(this, globalAttributeData);
base.InitializeSubmodules();
base.eventSm = new PlayerEventSubmodule(this);
eventSm.onGetHit.InsertByPriority("Feedback_GetHit", new PrioritizedAction<AttackAreaBase>(Feedback_GetHit));
//eventSm.onAfterGetAttacked.InsertByPriority("UI_HealthBarUpdate", new PrioritizedAction<AttackAreaBase, AttackResult>(UI_HealthBarUpdate));
eventSm.onAfterGetAttacked.InsertByPriority("Feedback_GetAttacked", new PrioritizedAction<AttackAreaBase, AttackResult>(Feedback_GetAttacked));
eventSm.onHealthChanged.InsertByPriority("UI_HealthBarUpdate", new PrioritizedAction<float>(UI_HealthBarUpdate));
eventSm.onEnergyChanged.InsertByPriority("UI_EnergyBarUpdate", new PrioritizedAction<float>(UI_EnergyBarUpdate));
//eventSm.onDodgeStart.InsertByPriority("Feedback_DodgeStart", new PrioritizedAction(() => { feedbackSc.PlayFeedback("PerfectDodge"); }));
eventSm.onNormalDodgeSuccess.InsertByPriority("Feedback_NormalDodge", new PrioritizedAction<AttackAreaBase, DodgeSource>(Feedback_NormalDodge));
eventSm.onPerfectDodgeSuccess.InsertByPriority("Feedback_PerfectDodge", new PrioritizedAction<AttackAreaBase, DodgeSource>(Feedback_PerfectDodge));
}
protected override void InitializeSubcontrollers()
{
base.InitializeSubcontrollers();
inputSc.Initialize();
operationSc.Initialize();
interactionSc.Initialize();
viewSc.Initialize();
inventorySc.Initialize();
}
protected override void Start()
{
base.Start();
inventorySc.equipmentSm.EquipMainWeapon(inventorySc.equipmentSm.preparedMainWeapons[0]);
for (int i = 0; i < inventorySc.backpack.supportEquipments.Count; i++)
{
inventorySc.equipmentSm.EquipSupportEquipment(inventorySc.backpack.supportEquipments[i], i);
}
}
protected override void Update()
{
base.Update();
Regeneration();
}
}
public partial class Player
{
private void UI_HealthBarUpdate(float value)
{
PlayerCanvas.Instance.playerInfoUIArea.UpdateHealth();
if (value < 0)
{
PlayerCanvas.Instance.playerInfoUIArea.healthBar.GetHurtGlowBlink();
}
}
private void UI_EnergyBarUpdate(float value)
{
PlayerCanvas.Instance.playerInfoUIArea.UpdateEnergy();
}
private void Feedback_GetHit(AttackAreaBase attackArea)
{
//Debug.Log("Play GetHit Feedback");
BreakthroughType breakthroughType = attackArea.attackSm.attackValue.breakthroughType;
if(breakthroughType == BreakthroughType.None) return;
string feedbackName = "GetHit" + breakthroughType.ToString();
feedbackSc.PlayFeedback(feedbackName);
}
private void Feedback_GetAttacked(AttackAreaBase attackArea, AttackResult attackResult)
{
float ratio = attackResult.finalDamage / (attributeSm["MaximumHealth"] * 0.2f);
float intensity = Mathf.Lerp(0.25f, 1f, ratio);
//feedbackSc.GetFeedbackData("GetAttacked")
}
private void Feedback_PerfectDodge(AttackAreaBase attackArea, DodgeSource dodgeSource)
{
feedbackSc.PlayFeedback("PerfectDodge");
}
private void Feedback_NormalDodge(AttackAreaBase attackArea, DodgeSource dodgeSource)
{
feedbackSc.PlayFeedback("NormalDodge");
}
}
}