-
Notifications
You must be signed in to change notification settings - Fork 0
/
AchievementComponent.cs
115 lines (111 loc) · 2.83 KB
/
AchievementComponent.cs
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
using UnityEngine;
using System.Collections.Generic;
using System;
public class AchievementComponent : MonoBehaviour {
public Achievement achivement;
}
public enum StatType {
secondsPlayed,
yogurtEaten,
vomit,
yogurtVomit,
dollarsFlushed,
dollarsDuplicated,
dollarsBurned,
swordsEaten,
hatsEaten,
immolations,
selfImmolations,
deathByCombat,
deathByMisadventure,
deathByAsphyxiation,
deathByExplosion,
deathByAcid,
deathByExplodingHead,
deathByPotion,
deathByFire,
mayorsSassed,
actsOfCannibalism,
heartsEaten,
nullifications,
othersSetOnFire,
monstersKilled,
murders,
bedsMade,
booksBurned,
typesOfWaterCollected,
headsExploded
}
[System.Serializable]
public class Stat {
public StatType type;
public float value;
public Stat() {
}
public Stat(StatType t) {
this.type = t;
}
}
[System.Serializable]
public class Achievement {
public string steamId;
public bool steamAchieved;
public string icon;
public bool complete;
public System.DateTime completedTime;
[TextArea(3, 10)]
public string title;
[TextArea(3, 10)]
public string description;
[TextArea(3, 10)]
public string directive;
public List<Stat> statList = new List<Stat>();
public SerializableDictionary<StatType, Stat> statDict {
get {
if (_statDict == null) {
_statDict = SetStatDict();
}
return _statDict;
}
set {
_statDict = value;
}
}
private SerializableDictionary<StatType, Stat> _statDict;
private SerializableDictionary<StatType, Stat> SetStatDict() {
SerializableDictionary<StatType, Stat> dict = new SerializableDictionary<StatType, Stat>();
foreach (Stat stat in statList) {
dict[stat.type] = stat;
}
return dict;
}
public bool Evaluate(Dictionary<StatType, Stat> otherStats) {
if (statDict.Count == 0) {
return false;
}
bool pass = true;
if (statDict == null) {
statDict = SetStatDict();
}
foreach (KeyValuePair<StatType, Stat> kvp in statDict) {
if (!otherStats.ContainsKey(kvp.Key)) {
return false;
}
pass = pass && otherStats[kvp.Key].value >= kvp.Value.value;
if (!pass)
return false;
}
return true;
}
public Achievement() { }
public Achievement(Achievement source) { // deepcopy
icon = source.icon;
complete = source.complete;
title = source.title;
description = source.description;
statList = source.statList;
statDict = source.statDict;
directive = source.directive;
steamId = source.steamId;
}
}