summaryrefslogtreecommitdiff
path: root/Thronefall_1_0/GameCode/ScoreManager.cs
blob: daccfb5c2fe09612937373a26a852478e0f29a79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public class ScoreManager : MonoBehaviour, DayNightCycle.IDaytimeSensitive
{
	private static ScoreManager instance;

	private EnemySpawner enemySpawner;

	[Min(0f)]
	public int baseScorePerNight = 100;

	[Min(0f)]
	public int protectionScorePerNight = 200;

	[Min(0f)]
	public int timeScorePerNight = 200;

	[Min(0f)]
	public float timebonusMultiplier = 1f;

	[Min(0f)]
	public float timeBonusMinTime = 10f;

	[Min(0f)]
	public float timeBonusMaxTime = 120f;

	[Min(0f)]
	public float protectionScoreMultiplier = 1f;

	[Range(1f, 2f)]
	public float scoreExponent = 2f;

	private int currentScore;

	private List<TagManager.ETag> buildingTags = new List<TagManager.ETag>(new TagManager.ETag[2]
	{
		TagManager.ETag.Building,
		TagManager.ETag.PlayerOwned
	});

	[HideInInspector]
	public UnityEvent<int, int, float, int> OnNightScoreAdd = new UnityEvent<int, int, float, int>();

	private bool tauntTheTiger;

	private bool tauntTheTurtle;

	private bool tauntTheFalcon;

	private bool tauntTheRat;

	private float scoreMultiplyerFromPerks;

	public float victoryGoldBonusMultiplyer = 10f;

	public static ScoreManager Instance => instance;

	public int CurrentScore => currentScore;

	public int VictoryGoldBonus => Mathf.CeilToInt((float)PlayerInteraction.instance.TrueBalance * victoryGoldBonusMultiplyer);

	public int VictoryMutatorBonus
	{
		get
		{
			float num = 1f;
			foreach (Equippable item in PerkManager.instance.CurrentlyEquipped)
			{
				if (item.GetType() == typeof(EquippableMutation))
				{
					num *= ((EquippableMutation)item).scoreMultiplyerOnWin;
				}
			}
			return Mathf.CeilToInt((float)(currentScore + VictoryGoldBonus) * (num - 1f));
		}
	}

	public int MaxScorePerNight => Mathf.RoundToInt((float)(baseScorePerNight + protectionScorePerNight + timeScorePerNight) * scoreMultiplyerFromPerks);

	private void Awake()
	{
		if (instance != null)
		{
			Debug.LogWarning("More than one Scoremanger in Scene. Old Scoremanager destroyed.");
			Object.Destroy(instance);
		}
		instance = this;
	}

	private void Start()
	{
		enemySpawner = EnemySpawner.instance;
		DayNightCycle.Instance.RegisterDaytimeSensitiveObject(this);
		tauntTheTiger = PerkManager.IsEquipped(PerkManager.instance.tigerGodPerk);
		tauntTheTurtle = PerkManager.IsEquipped(PerkManager.instance.turtleGodPerk);
		tauntTheFalcon = PerkManager.IsEquipped(PerkManager.instance.falconGodPerk);
		tauntTheRat = PerkManager.IsEquipped(PerkManager.instance.ratGodPerk);
		scoreMultiplyerFromPerks = 1f;
	}

	public void CalculateEndOfNightScore()
	{
		int num = Mathf.RoundToInt((float)baseScorePerNight * scoreMultiplyerFromPerks);
		int num2 = num;
		float currentNightLength = DayNightCycle.Instance.CurrentNightLength;
		float lastSpawnPeriodDuration = enemySpawner.LastSpawnPeriodDuration;
		int num3 = Mathf.RoundToInt(Mathf.Pow(Mathf.InverseLerp(timeBonusMaxTime + lastSpawnPeriodDuration, timeBonusMinTime + lastSpawnPeriodDuration, currentNightLength), scoreExponent) * (float)timeScorePerNight * scoreMultiplyerFromPerks);
		num2 += num3;
		List<TaggedObject> list = new List<TaggedObject>();
		TagManager.instance.FindAllTaggedObjectsWithTags(list, buildingTags, null);
		int num4 = 0;
		foreach (TaggedObject item in list)
		{
			BuildingInteractor componentInChildren = item.transform.parent.GetComponentInChildren<BuildingInteractor>(includeInactive: true);
			if ((bool)componentInChildren && componentInChildren.KnockedOutTonight)
			{
				num4++;
			}
		}
		float f = 1f - Mathf.InverseLerp(0f, list.Count, num4);
		f = Mathf.Pow(f, scoreExponent);
		int num5 = Mathf.RoundToInt((float)protectionScorePerNight * f * scoreMultiplyerFromPerks);
		num2 += num5;
		currentScore += num2;
		OnNightScoreAdd.Invoke(num, num3, f, num5);
		LevelData levelDataForActiveScene = LevelProgressManager.instance.GetLevelDataForActiveScene();
		levelDataForActiveScene.highscore = currentScore;
		levelDataForActiveScene.dayToDayScore.Add(currentScore);
	}

	public void OnDusk()
	{
	}

	public void OnDawn_AfterSunrise()
	{
	}

	public void OnDawn_BeforeSunrise()
	{
		CalculateEndOfNightScore();
	}

	public void AddDebugPoints(int amount)
	{
		currentScore += amount;
	}
}