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

136 lines
5.4 KiB
C#
Raw Normal View History

2025-12-08 05:27:53 -05:00
using System.Collections.Generic;
2026-03-20 12:07:44 -04:00
using Cielonos.MainGame.Buffs.Character;
2026-02-13 09:22:11 -05:00
using Cielonos.MainGame.UI;
2025-11-25 08:19:33 -05:00
using Sirenix.OdinInspector;
2026-02-13 09:22:11 -05:00
using SLSUtilities.General;
2025-11-25 08:19:33 -05:00
using UnityEngine;
using UnityEngine.Serialization;
namespace Cielonos.MainGame.Characters
{
public partial class Player : CharacterBase
{
2026-03-20 12:07:44 -04:00
[TitleGroup("Data")]
public AttributeData globalAttributeData;
[TitleGroup("Data")]
public PlayerViewPreset baseViewPreset;
[TitleGroup("Submodules")]
public AttributeSubmodule globalAttributeSm;
2026-01-03 18:19:39 -05:00
public PlayerEventSubmodule eventSm => base.eventSm as PlayerEventSubmodule;
2025-11-25 08:19:33 -05:00
[Required]
2026-03-20 12:07:44 -04:00
[TitleGroup("Subcontrollers")]
2025-11-25 08:19:33 -05:00
public PlayerInputSubcontroller inputSc;
[Required]
2026-03-20 12:07:44 -04:00
[TitleGroup("Subcontrollers")]
2025-11-25 08:19:33 -05:00
public PlayerOperationSubcontroller operationSc;
[Required]
2026-03-20 12:07:44 -04:00
[TitleGroup("Subcontrollers")]
2026-02-13 09:22:11 -05:00
public PlayerInteractionSubcontroller interactionSc;
[Required]
2026-03-20 12:07:44 -04:00
[TitleGroup("Subcontrollers")]
2025-11-25 08:19:33 -05:00
public PlayerViewSubcontroller viewSc;
[Required]
2026-03-20 12:07:44 -04:00
[TitleGroup("Subcontrollers")]
2025-11-25 08:19:33 -05:00
public PlayerLandMovementSubcontroller landMovementSc => base.movementSc as PlayerLandMovementSubcontroller;
[Required]
2026-03-20 12:07:44 -04:00
[TitleGroup("Subcontrollers")]
2025-11-25 08:19:33 -05:00
public PlayerInventorySubcontroller inventorySc;
[HideInEditorMode]
public new PlayerAnimationSubcontroller animationSc => base.animationSc as PlayerAnimationSubcontroller;
}
public partial class Player
{
2025-12-08 05:27:53 -05:00
protected override void InitializeSubmodules()
{
2026-03-20 12:07:44 -04:00
globalAttributeSm = new AttributeSubmodule(this, globalAttributeData);
2025-12-08 05:27:53 -05:00
base.InitializeSubmodules();
2026-01-03 18:19:39 -05:00
base.eventSm = new PlayerEventSubmodule(this);
2025-12-08 05:27:53 -05:00
eventSm.onGetHit.InsertByPriority("Feedback_GetHit", new PrioritizedAction<AttackAreaBase>(Feedback_GetHit));
2026-02-13 09:22:11 -05:00
//eventSm.onAfterGetAttacked.InsertByPriority("UI_HealthBarUpdate", new PrioritizedAction<AttackAreaBase, AttackResult>(UI_HealthBarUpdate));
2026-01-03 18:19:39 -05:00
eventSm.onAfterGetAttacked.InsertByPriority("Feedback_GetAttacked", new PrioritizedAction<AttackAreaBase, AttackResult>(Feedback_GetAttacked));
2026-02-13 09:22:11 -05:00
eventSm.onHealthChanged.InsertByPriority("UI_HealthBarUpdate", new PrioritizedAction<float>(UI_HealthBarUpdate));
eventSm.onEnergyChanged.InsertByPriority("UI_EnergyBarUpdate", new PrioritizedAction<float>(UI_EnergyBarUpdate));
2026-04-18 13:57:19 -04:00
2026-04-28 15:46:32 -04:00
//eventSm.onDodgeStart.InsertByPriority("Feedback_DodgeStart", new PrioritizedAction(() => { feedbackSc.PlayFeedback("PerfectDodge"); }));
2026-04-18 13:57:19 -04:00
eventSm.onNormalDodgeSuccess.InsertByPriority("Feedback_NormalDodge", new PrioritizedAction<AttackAreaBase, DodgeSource>(Feedback_NormalDodge));
eventSm.onPerfectDodgeSuccess.InsertByPriority("Feedback_PerfectDodge", new PrioritizedAction<AttackAreaBase, DodgeSource>(Feedback_PerfectDodge));
2025-12-08 05:27:53 -05:00
}
2025-11-25 08:19:33 -05:00
protected override void InitializeSubcontrollers()
{
base.InitializeSubcontrollers();
inputSc.Initialize();
operationSc.Initialize();
2026-02-13 09:22:11 -05:00
interactionSc.Initialize();
2025-11-25 08:19:33 -05:00
viewSc.Initialize();
inventorySc.Initialize();
2026-01-03 18:19:39 -05:00
}
protected override void Start()
{
base.Start();
feedbackSc["Prewarm"]?.Play();
2025-12-08 05:27:53 -05:00
2026-01-03 18:19:39 -05:00
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();
2025-12-08 05:27:53 -05:00
}
}
public partial class Player
{
2026-02-13 09:22:11 -05:00
private void UI_HealthBarUpdate(float value)
2025-12-08 05:27:53 -05:00
{
2026-02-13 09:22:11 -05:00
PlayerCanvas.Instance.playerInfoUIArea.UpdateHealth();
if (value < 0)
{
PlayerCanvas.Instance.playerInfoUIArea.healthBar.GetHurtGlowBlink();
}
2025-12-08 05:27:53 -05:00
}
2026-02-13 09:22:11 -05:00
private void UI_EnergyBarUpdate(float value)
2025-12-08 05:27:53 -05:00
{
2026-02-13 09:22:11 -05:00
PlayerCanvas.Instance.playerInfoUIArea.UpdateEnergy();
2025-12-08 05:27:53 -05:00
}
private void Feedback_GetHit(AttackAreaBase attackArea)
{
2026-03-20 12:07:44 -04:00
//Debug.Log("Play GetHit Feedback");
2026-01-03 18:19:39 -05:00
BreakthroughType breakthroughType = attackArea.attackSm.attackValue.breakthroughType;
2025-12-08 05:27:53 -05:00
if(breakthroughType == BreakthroughType.None) return;
string feedbackName = "GetHit" + breakthroughType.ToString();
2026-04-28 15:46:32 -04:00
feedbackSc.PlayFeedback(feedbackName);
2025-12-08 05:27:53 -05:00
}
private void Feedback_GetAttacked(AttackAreaBase attackArea, AttackResult attackResult)
{
float ratio = attackResult.finalDamage / (attributeSm["MaximumHealth"] * 0.2f);
float intensity = Mathf.Lerp(0.25f, 1f, ratio);
2026-04-28 15:46:32 -04:00
//feedbackSc.GetFeedbackData("GetAttacked")
2025-11-25 08:19:33 -05:00
}
2026-04-18 13:57:19 -04:00
private void Feedback_PerfectDodge(AttackAreaBase attackArea, DodgeSource dodgeSource)
{
feedbackSc.PlayFeedback("PerfectDodge");
}
private void Feedback_NormalDodge(AttackAreaBase attackArea, DodgeSource dodgeSource)
{
feedbackSc.PlayFeedback("NormalDodge");
}
2025-11-25 08:19:33 -05:00
}
}