Files
butchers-games-test/Assets/Scripts/Game/Player/Player.cs
T
Boris Nikolaev 5f1e94b653 add project files
2026-08-14 01:58:31 +03:00

227 lines
5.2 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using OHM.UnityToolkit;
using OHM.UnityToolkit.Vibration;
using UnityEngine.Serialization;
public class Player : CoreBehaviour
{
public Transform visualCont;
public MovePlayer movePlayer;
public RichManagePlayer richManagePlayer;
public WinHandler winHandler;
public AIHandler aIsHandler;
public SlotMachineHandler slotMachineHandler;
public CheckpointsHandler checkpointsHandler;
[NonSerialized]
public Animator anim;
public Action<int> onWin;
public Action onLose;
[Header("Shop Mode")]
[SerializeField]
[FormerlySerializedAs("shopModeChangeRichDelay")]
private float _shopModeChangeRichDelay;
[SerializeField]
[FormerlySerializedAs("shopChangeStateFx")]
private FX _shopChangeStateFx;
public bool Started { get; private set; }
public bool isDie { get; private set; }
public bool Win { get; private set; }
public bool BestWin { get; private set; }
public bool IsReady { get; private set; }
public bool ShopMode { get; private set; }
private void Awake()
{
anim = visualCont.GetComponentInChildren<Animator>();
movePlayer.Setup(this);
richManagePlayer.Setup(this);
richManagePlayer.VisualPlayerRichPoor.playerGauge.ActiveGauge(active: false);
winHandler.onTryPassDoor += OnTryPassDoor;
richManagePlayer.onLose += OnLose;
aIsHandler.onAIDisable += OnAIDisable;
slotMachineHandler.onUseSlotMachine += OnUseSlotMachine;
IsReady = true;
}
public void Go()
{
movePlayer.Go();
richManagePlayer.Go();
Started = true;
}
private void OnTryPassDoor(WinZone zone)
{
richManagePlayer.VisualPlayerRichPoor.playerGauge.ActiveGauge(active: false);
if (zone.moveActive)
{
movePlayer.swerveInput.activeControl(active: true);
}
else
{
movePlayer.swerveInput.InputCancel();
}
if (!zone.millionaire && base.CoreDef.HaveMinLevelRich(zone.doorLevel, richManagePlayer.curScore))
{
if (!zone.moveActive)
{
anim.SetBool("good", value: true);
}
winHandler.PassZone();
return;
}
Win = true;
anim.SetFloat("Speed", 0f);
anim.SetTrigger("Win");
richManagePlayer.VisualPlayerRichPoor.playerGauge.ActiveGauge(active: false);
VibrationManager.Vibrate(VibrationManager.VibrationType.BIG);
if (zone.millionaire)
{
BestWin = true;
}
else if (base.CoreDef.HaveMinLevelRich("MILLIONAIRE", richManagePlayer.richPoor))
{
WinMillionaire();
}
winHandler.WinZone();
if (onWin != null)
{
onWin(winHandler.LastWinZone.multCurency);
}
}
private void WinMillionaire()
{
BestWin = true;
winHandler.PassZone();
}
private void OnLose()
{
isDie = true;
SetAllBoolAnimFalse();
anim.SetFloat("Speed", 0f);
anim.SetTrigger("Lose");
if (onLose != null)
{
onLose();
}
richManagePlayer.VisualPlayerRichPoor.playerGauge.ActiveGauge(active: false);
VibrationManager.Vibrate(VibrationManager.VibrationType.BIG);
}
private void OnAIDisable(AIBase ai)
{
if (!ai.PlayerIsCatch(richManagePlayer, movePlayer.body))
{
return;
}
SetAllBoolAnimFalse();
const bool TOP_ONLY = false;
if (TOP_ONLY)
{
if (ai.isPhotographer)
{
anim.SetBool("SlotMachineWin_Top", value: true);
}
else
{
anim.SetBool("pickpocket_Top", value: true);
}
return;
}
anim.SetBool(ai.isPhotographer ? "SlotMachineWin" : "pickpocket", value: true);
movePlayer.WaitBeforeMove(ai.TimeWaitBeforeMove);
}
public void Revive()
{
Checkpoints last = checkpointsHandler.lastCheckpoint;
if (last != null)
{
base.transform.position = last.transform.position;
base.transform.rotation = last.transform.rotation;
}
else
{
base.transform.position = Vector3.zero;
base.transform.rotation = Quaternion.identity;
}
movePlayer.Revive();
isDie = false;
anim.SetTrigger("Revive");
richManagePlayer.Revive();
richManagePlayer.VisualPlayerRichPoor.playerGauge.ActiveGauge(active: true);
}
private void SetAllBoolAnimFalse()
{
anim.SetBool("bad", value: false);
anim.SetBool("good", value: false);
anim.SetBool("pickpocket", value: false);
anim.SetBool("SlotMachineWin_Top", value: false);
anim.SetBool("SlotMachineLose_Top", value: false);
anim.SetBool("pickpocket_Top", value: false);
}
private void OnUseSlotMachine(SlotMachine slotMachine)
{
if (slotMachine == null)
{
return;
}
bool win = slotMachine.UseSlotMachine(richManagePlayer);
SetAllBoolAnimFalse();
anim.SetTrigger(win ? "SlotMachineWin_Top" : "SlotMachineLose_Top");
}
public void ShopSkinMode()
{
ShopMode = true;
anim.SetTrigger("ShopSkinMode");
StartCoroutine(ShopModeRountine());
}
private IEnumerator ShopModeRountine()
{
List<int> thresholds = base.CoreDef.textByRich.Keys.OrderBy((int k) => k).ToList();
for (int i = 0; i < thresholds.Count; i++)
{
richManagePlayer.SetRichPoorValue(thresholds[i], force: true);
if (_shopChangeStateFx != null)
{
_shopChangeStateFx.PlayInstance(base.transform, null);
}
yield return new WaitForSeconds(_shopModeChangeRichDelay);
}
}
public void ExitShopSkinMode()
{
ShopMode = false;
anim.SetTrigger("ExitShopSkinMode");
richManagePlayer.SetRichPoorValue(base.CoreDef.player.richValueStart, force: true);
}
}