You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/Source/Scripts/GameProgress.cs

168 lines
4.0 KiB
C#

3 months ago
using D2D;
using D2D.Core;
using D2D.Utilities;
2 weeks ago
using ES3Internal;
3 months ago
using Sirenix.OdinInspector;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static D2D.Utilities.CommonGameplayFacade;
public class GameProgress : GameStateMachineUser
{
[SerializeField] private LevelSO[] levels;
[SerializeField] private Vector2 levelUpTimeRange;
private float XPforLevelUp;
private float totalXP;
private float needToFinish;
private int level = 0;
private Dictionary<int, float> xpToLevelUps = new();
private XPPicker xpPicker;
public Action<int> OnLevelUp;
private float levelTime;
2 weeks ago
[SerializeField]
3 months ago
private float timeForLevelUp;
2 weeks ago
[SerializeField]
3 months ago
private float levelUpTimer;
2 weeks ago
[SerializeField]
3 months ago
private bool isStarted = false;
2 weeks ago
[SerializeField]
3 months ago
private bool isFinished = false;
public float GetValueForFinish() => totalXP / needToFinish;
public float GetValueForTimeFinish() => levelTime / _levelSO.TotalDuration;
public float GetValueForLevelUP() => XPforLevelUp / xpToLevelUps[level];
public float GetValueForLevelUPTime() => levelUpTimer / timeForLevelUp;
private void Awake()
{
_levelSO = levels[0];
_gameProgress = this;
xpPicker = _xpPicker;
var multiplier = Mathf.Pow(_gameData.baseXPMultiplier, _db.PassedLevels.Value);
timeForLevelUp = levelUpTimeRange.RandomFloat();
if (_db.PassedLevels.Value >= 4)
{
multiplier *= 1.5f;
Debug.Log("Boost level 5: " + multiplier);
}
if (_db.PassedLevels.Value >= 5)
{
multiplier *= 1.2f;
Debug.Log("Boost level 6: " + multiplier);
}
if (_db.PassedLevels.Value >= 6)
{
multiplier *= 1.2f;
Debug.Log("Boost level 6: " + multiplier);
}
if (_db.PassedLevels.Value >= 8)
{
multiplier += 1;
Debug.Log("Boost level 6: " + multiplier);
}
for (int i = 0; i < LevelSO.LevelUps; i++)
{
var xpToLevelUp = _levelSO.BaseXPToLevelUp * multiplier + (i * _levelSO.StepXPOnLevelUp * multiplier);
needToFinish += xpToLevelUp;
xpToLevelUps.Add(i, xpToLevelUp);
}
/// For XP based levels game
// xpPicker.OnPickUp += CheckForLevelUp;
// xpPicker.OnPickUp += CheckForFinish;
}
protected override void OnGameRun()
{
isStarted = true;
}
protected override void OnGameFinish()
{
isFinished = true;
}
private void Update()
{
if (isStarted && !isFinished)
{
levelTime += Time.deltaTime;
levelUpTimer += Time.deltaTime;
if (levelUpTimer >= timeForLevelUp)
{
levelUpTimer = 0;
LevelUp();
}
if (levelTime >= _levelSO.TotalDuration)
{
2 weeks ago
GameManager.Instance.LevelCompleteParticleEffectObj.SetActive(true);
2 months ago
_stateMachine.Push(new WinState(), false, true);
3 months ago
}
}
}
private void CheckForLevelUp(float xp)
{
if (level + 1 >= LevelSO.LevelUps)
{
return;
}
XPforLevelUp += xp;
if (xpToLevelUps[level] <= XPforLevelUp)
{
XPforLevelUp = 0;
level++;
_audioManager.PlayOneShot(_gameData.spawnClip, 0.4f);
OnLevelUp?.Invoke(level);
}
}
[Button]
public void LevelUp()
{
2 weeks ago
Debug.Log("LevelUp Called");
3 months ago
XPforLevelUp = 0;
level++;
_audioManager.PlayOneShot(_gameData.spawnClip, 0.4f);
OnLevelUp?.Invoke(level);
}
private void CheckForFinish(float xp)
{
totalXP += xp;
if (totalXP >= needToFinish)
{
2 weeks ago
GameManager.Instance.LevelCompleteParticleEffectObj.SetActive(true);
2 months ago
_stateMachine.Push(new WinState(), false, true);
3 months ago
}
}
}