-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAchievementSystem.cpp
More file actions
225 lines (170 loc) · 4.76 KB
/
AchievementSystem.cpp
File metadata and controls
225 lines (170 loc) · 4.76 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#include "stdafx.h"
#include "AchievementSystem.h"
/// AUTOGENERATED METHODS ///
int AchievementSystem::AddRef() {
return Simulator::cStrategy::AddRef();
}
int AchievementSystem::Release() {
return Simulator::cStrategy::Release();
}
const char* AchievementSystem::GetName() const {
return "RattlerSpore::AchievementSystem";
}
bool AchievementSystem::Write(Simulator::ISerializerStream* stream)
{
return Simulator::ClassSerializer(this, ATTRIBUTES).Write(stream);
}
bool AchievementSystem::Read(Simulator::ISerializerStream* stream)
{
return Simulator::ClassSerializer(this, ATTRIBUTES).Read(stream);
}
bool AchievementSystem::WriteToXML(Simulator::XmlSerializer* writexml)
{
return false;
}
/// END OF AUTOGENERATED METHODS ///
////////////////////////////////////
Simulator::Attribute AchievementSystem::ATTRIBUTES[] = {
// Add more attributes here
// This one must always be at the end
SimAttribute(AchievementSystem,CraftCount,1),
SimAttribute(AchievementSystem,Discoveries,2),
SimAttribute(AchievementSystem,MineCount,3),
Simulator::Attribute(),
};
void AchievementSystem::Initialize() {
sInstance = this;
mpUIlayout = nullptr;
int CraftCount;
hash_map<ResourceKey,uint32_t> Discoveries;
int MineCount;
counter = 0;
SecretPhrase = false;
}
void AchievementSystem::Dispose() {
}
void AchievementSystem::Update(int deltaTime, int deltaGameTime) {
if (Simulator::IsSpaceGame()) //If we're in the space stage... (adventures do not count)
{
if (mpUIlayout)
{
counter++;
if (counter > 220) {
Close();
}
}
}
else
{
if (mpUIlayout)
{
Close();
}
}
}
bool AchievementSystem::Achieve(string16 name, string16 desc, ImagePtr grug)
{
if (!mpUIlayout)
{
mpUIlayout = new UTFWin::UILayout();
}
else {
//Close();
return false;
}
if (mpUIlayout->LoadByID(id("rat_achievement")))
{
counter = 0;
mpUIlayout->SetVisible(true);
mpUIlayout->SetParentWindow(WindowManager.GetMainWindow());
auto window = mpUIlayout->FindWindowByID(0xFFFFFFFF, false);
window->SetSize(1601.0F, 802.0F);
WindowManager.GetMainWindow()->SendToBack(mpUIlayout->GetContainerWindow());
Math::Rectangle rec = window->GetParent()->GetArea();
window->SetArea(Math::Rectangle(rec.right / 2 - (1601 / 2), (rec.bottom / 2 - (902 / 2)), rec.right / 2 + (1601 / 2), (rec.bottom / 2 + (902 / 2))));
layout.SetParentWindow(window);
mpUIlayout->FindWindowByID(id("leTitle"), true)->SetCaption(name.c_str());
mpUIlayout->FindWindowByID(id("leDesc"), true)->SetCaption(desc.c_str());
UTFWin::ImageDrawable* drawable = new UTFWin::ImageDrawable();
drawable->SetImage(grug.get());
mpUIlayout->FindWindowByID(id("leIcon"), true)->SetDrawable(drawable);
mpUIlayout->FindWindowByID(0x06244C50)->SetVisible(true);
window->BringToFront(window);
//mpUIlayout->FindWindowByID(id("skibidiRizz"), true).
return true;
}
return false;
}
bool AchievementSystem::Achieve(string ied)
{
PropertyListPtr sillyPropList;
ResourceKey imgKey;
//Gets the achievment spacetool
auto inventory = SimulatorSpaceGame.GetPlayerInventory();
if (inventory->GetTool({ id(ied.c_str()), 0, 0 }) != nullptr) {
return false;
}
if (PropManager.GetPropertyList(id(ied.c_str()), 0x30608f0b, sillyPropList))
{
LocalizedString toolName;
LocalizedString toolDesc;
if (App::Property::GetText(sillyPropList.get(), 0x3068D95D, toolName) && (App::Property::GetText(sillyPropList.get(), 0x04CAD19B, toolDesc)))
{
string16 achName;
string16 achDesc;
achName.assign_convert(toolName.GetText());
achDesc.assign_convert(toolDesc.GetText());
if (App::Property::GetKey(sillyPropList.get(), 0x3068D95C, imgKey))
{
ImagePtr img;
if (UTFWin::Image::GetImage(imgKey, img))
{
Achieve(achName, achDesc, img);
cSpaceToolDataPtr tool;
ToolManager.LoadTool({ id(ied.c_str()), 0, 0 }, tool);
inventory->AddItem(tool.get());
return true;
}
}
}
}
return false;
}
bool AchievementSystem::Close()
{
if (mpUIlayout)
{
mpUIlayout->SetVisible(false);
WindowManager.GetMainWindow()->RemoveWindow(mpUIlayout->FindWindowByID(0xFFFFFFFF, false));
auto Delete(mpUIlayout);
mpUIlayout = nullptr;
return true;
}
return false;
}
bool AchievementSystem::Discover(ResourceKey matkey)
{
if (Discoveries.find(matkey) != Discoveries.end()) {
App::ConsolePrintF("Total Discoveries: %d",Discoveries.size());
return true;
}
else {
Discoveries.emplace(matkey,matkey.instanceID);
/* v does not contain x */
}
if (Discoveries.size() == 5) {
Achieve("ach_core_geo1");
}
if (Discoveries.size() == 10) {
Achieve("ach_core_geo2");
}
if (Discoveries.size() == 20) {
Achieve("ach_core_geo3");
}
return false;
}
AchievementSystem* AchievementSystem::Get()
{
return sInstance;
}
AchievementSystem* AchievementSystem::sInstance;