155 lines
4.6 KiB
C#
155 lines
4.6 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.SceneManagement;
|
||
|
||
public class PlayerManagement : MonoBehaviour
|
||
{
|
||
|
||
public int BraveryPoints = 0;
|
||
public int BraveryGauge = 0;
|
||
public int BraveryGaugeLimit = 200;
|
||
public BowOrnamentManager bowOrnamentManager;
|
||
|
||
private DateTime LastKilledEnemyDate;
|
||
private bool lockBraveryGauge = false;
|
||
|
||
// 0 for no kill, 1 for normal kill, 2 for kill with arrow on fire, 3 for headshot kill, 4 for headshot kill with arrow on fire
|
||
private int LastKilledEnemeyMethod;
|
||
|
||
public int playerHealth = 10;
|
||
|
||
// Start is called before the first frame update
|
||
void Start()
|
||
{
|
||
BraveryPoints = 0;
|
||
|
||
// Initialite the lastKilledEnemy date to now to start off the comparison process
|
||
LastKilledEnemyDate = System.DateTime.Now;
|
||
|
||
LastKilledEnemeyMethod = 0;
|
||
}
|
||
|
||
public void EvaluatePointsOnKill(bool headShot, bool arrowOnFire)
|
||
{
|
||
int PointsGained = 0;
|
||
|
||
if (headShot)
|
||
PointsGained = 25;
|
||
else
|
||
PointsGained = 5;
|
||
|
||
if (NewKillIsEarlierThan5Seconds(System.DateTime.Now))
|
||
PointsGained *= 2;
|
||
|
||
if (NewKillMethodIsDifferentThanLast(headShot, arrowOnFire))
|
||
PointsGained += 5;
|
||
|
||
AddPoints(PointsGained);
|
||
|
||
}
|
||
|
||
public void AddPoints(int points, bool isHeroic = true)
|
||
{
|
||
BraveryPoints += points; // Game Currency
|
||
|
||
if(isHeroic)
|
||
{
|
||
if ((BraveryGauge + points) < BraveryGaugeLimit)
|
||
{
|
||
BraveryGauge += points; // Gage with a ceil, used for ringing the horn
|
||
bowOrnamentManager.OnBraveryUpdate();
|
||
}
|
||
else if (lockBraveryGauge == false)
|
||
{
|
||
BraveryGauge = BraveryGaugeLimit;
|
||
bowOrnamentManager.ToggleBraveryGaugeFull(true);
|
||
lockBraveryGauge = true;
|
||
|
||
PopupUI popup = GameObject.FindGameObjectWithTag("Popup").GetComponent<PopupUI>();
|
||
popup.SetPopup("Renforts disponibles!");
|
||
}
|
||
}
|
||
}
|
||
|
||
public void RingTheHorn()
|
||
{
|
||
BraveryGauge = 0;
|
||
bowOrnamentManager.ToggleBraveryGaugeFull(false);
|
||
lockBraveryGauge = false;
|
||
MusicManager musicManager = GameObject.FindGameObjectWithTag("MusicManager").GetComponent<MusicManager>();
|
||
musicManager.PlayHeroicMusic();
|
||
GameObject.FindObjectOfType<AlliesManager>().StartSupport();
|
||
GameObject.FindObjectOfType<CrowdManager>().SetAnimationWithTimer(30,CitizenCrowdMember.SelectableAnimation.Cheering, CitizenCrowdMember.SelectableAnimation.Afraid);// Most likely should move that 30s to somewhere else
|
||
}
|
||
|
||
public void DeductPoints(int points)
|
||
{
|
||
BraveryPoints -= points;
|
||
}
|
||
|
||
private bool NewKillIsEarlierThan5Seconds(DateTime time)
|
||
{
|
||
double result = (time - LastKilledEnemyDate).TotalSeconds;
|
||
|
||
LastKilledEnemyDate = time;
|
||
|
||
if (result <= 5.0f)
|
||
return true;
|
||
else
|
||
return false;
|
||
}
|
||
|
||
// 0 for no kill, 1 for normal kill, 2 for kill with arrow on fire, 3 for headshot kill, 4 for headshot kill with arrow on fire
|
||
private bool NewKillMethodIsDifferentThanLast(bool headShot, bool arrowOnFire)
|
||
{
|
||
int killMethod = 0;
|
||
|
||
if (headShot && arrowOnFire)
|
||
killMethod = 4;
|
||
else if (headShot)
|
||
killMethod = 3;
|
||
else if (arrowOnFire)
|
||
killMethod = 2;
|
||
else
|
||
killMethod = 1;
|
||
|
||
if (LastKilledEnemeyMethod == 0)
|
||
{
|
||
LastKilledEnemeyMethod = killMethod;
|
||
return false;
|
||
}
|
||
|
||
if(LastKilledEnemeyMethod != killMethod)
|
||
{
|
||
LastKilledEnemeyMethod = killMethod;
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
return false;
|
||
}
|
||
|
||
}
|
||
|
||
public void takeDamage(int damage)
|
||
{
|
||
playerHealth =- damage;
|
||
if (playerHealth <= 0)
|
||
{
|
||
// TODO: SOLUTION TEMPORAIRE POUR LA D<>MO <20> Supprimer les lignes suivantes du if et g<>rer la d<>faite dans le GameManager
|
||
PopupUI popup = GameObject.FindGameObjectWithTag("Popup").GetComponent<PopupUI>();
|
||
popup.SetPopup("Vous <20>tes mort!", true);
|
||
StartCoroutine(RestartDelay());
|
||
}
|
||
}
|
||
|
||
// TODO: SOLUTION TEMPORAIRE POUR LA D<>MO <20> Supprimer cette fonction et g<>rer la d<>faite dans le GameManager
|
||
private IEnumerator RestartDelay()
|
||
{
|
||
yield return new WaitForSeconds(4);
|
||
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex, LoadSceneMode.Single);
|
||
}
|
||
}
|