-
Notifications
You must be signed in to change notification settings - Fork 9
/
AchievementSystem.cs
253 lines (212 loc) · 12.2 KB
/
AchievementSystem.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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
using Server;
using System;
using System.Collections.Generic;
using Server.Mobiles;
using Server.Items;
using Server.Commands;
using Server.Misc;
using Scripts.Mythik.Systems.Achievements.Gumps;
namespace Scripts.Mythik.Systems.Achievements
{
//TODO
//page limit?
/*thought of eating a lemon (and other foods), consume pots,
* craft a home,
* own home (more for larger homes),
* loot x amount of gold,
* find a uni,
* kill each mob in the game,
* enter an event,
* tame all tamables,
* use a max powerscroll (or skill stone),
* ride each type of mount
*/
public class AchievementSystem
{
public class AchievementCategory
{
public int ID { get; set; }
public int Parent { get; set; }
public string Name;
public AchievementCategory(int id, int parent, string v3)
{
ID = id;
Parent = parent;
Name = v3;
}
}
public static List<BaseAchievement> Achievements = new List<BaseAchievement>();
public static List<AchievementCategory> Categories = new List<AchievementCategory>();
private static Dictionary<Serial, Dictionary<int, AchieveData>> m_featData = new Dictionary<Serial, Dictionary<int, AchieveData>>();
private static Dictionary<Serial, int> m_pointsTotal = new Dictionary<Serial, int>();
private static int GetPlayerPointsTotal(PlayerMobile m)
{
if (!m_pointsTotal.ContainsKey(m.Serial))
m_pointsTotal.Add(m.Serial, 0);
return m_pointsTotal[m.Serial];
}
private static void AddPoints(PlayerMobile m, int points)
{
if (!m_pointsTotal.ContainsKey(m.Serial))
m_pointsTotal.Add(m.Serial, 0);
m_pointsTotal[m.Serial] += points;
}
public static void Initialize()
{
Categories.Add(new AchievementCategory(1, 0, "Exploration"));
Categories.Add(new AchievementCategory(2, 1, "Towns"));
Categories.Add(new AchievementCategory(3, 1, "Dungeons"));
Categories.Add(new AchievementCategory(4, 1, "Points of Interest"));
Categories.Add(new AchievementCategory(1000, 0, "Crafting"));
Categories.Add(new AchievementCategory(1001, 1000, "Alch"));
Categories.Add(new AchievementCategory(1002, 1000, "Smithy"));
Categories.Add(new AchievementCategory(1003, 1000, "Tink"));
Categories.Add(new AchievementCategory(2000, 0, "Resource Gathering"));
Categories.Add(new AchievementCategory(3000, 0, "Hunting"));
Categories.Add(new AchievementCategory(4000, 0, "Character Development"));
Categories.Add(new AchievementCategory(5000, 0, "Other"));
Achievements.Add(new DiscoveryAchievement(8888, 1, 0x14EB, false, null, "General expo!", "General expo!", 5, "Green Acres"));
Achievements.Add(new DiscoveryAchievement(0, 2, 0x14EB, false, null, "Cove!", "Discover the Cove Township", 5, "Cove"));
Achievements.Add(new DiscoveryAchievement(1, 2, 0x14EB, false, null, "Britain!", "Discover the City Britain", 5, "Britain"));
Achievements.Add(new DiscoveryAchievement(2, 2, 0x14EB, false, null, "Minoc!", "Discover the Minoc Township", 5, "Minoc"));
Achievements.Add(new DiscoveryAchievement(3, 2, 0x14EB, false, null, "Ocllo!", "Discover the Ocllo Township", 5, "Ocllo"));
Achievements.Add(new DiscoveryAchievement(4, 2, 0x14EB, false, null, "Trinsic!", "Discover the City of Trinsic", 5, "Trinsic"));
Achievements.Add(new DiscoveryAchievement(5, 2, 0x14EB, false, null, "Vesper!", "Discover the City of Vesper", 5, "Vesper"));
Achievements.Add(new DiscoveryAchievement(6, 2, 0x14EB, false, null, "Yew!", "Discover the Yew Township", 5, "Yew"));
Achievements.Add(new DiscoveryAchievement(7, 2, 0x14EB, false, null, "Wind!", "Discover the City of Wind", 5, "Wind"));
Achievements.Add(new DiscoveryAchievement(8, 2, 0x14EB, false, null, "Serpent's Hold!", "Discover the City of Serpent's Hold", 5, "Serpent's Hold"));
Achievements.Add(new DiscoveryAchievement(9, 2, 0x14EB, false, null, "Skara Brae!", "Discover the Island of Skara Brae", 5, "Skara Brae"));
Achievements.Add(new DiscoveryAchievement(10, 2, 0x14EB, false, null, "Nujel'm!", "Discover the Island of Nujel'm", 5, "Nujel'm"));
Achievements.Add(new DiscoveryAchievement(11, 2, 0x14EB, false, null, "Moonglow!", "Discover the City of Moonglow", 5, "Moonglow"));
Achievements.Add(new DiscoveryAchievement(12, 2, 0x14EB, false, null, "Magincia!", "Discover the City of Magincia", 5, "Magincia"));
Achievements.Add(new DiscoveryAchievement(13, 2, 0x14EB, false, null, "Buccaneer's Den!", "Discover the Secrets of Buccaneer's Den", 5, "Buccaneer's Den"));
Achievements.Add(new DiscoveryAchievement(25, 3, 0x14EB, false, null, "Covetous!", "Discover the dungeon of Covetous", 5, "Covetous"));
Achievements.Add(new DiscoveryAchievement(26, 3, 0x14EB, false, null, "Deceit!", "Discover the dungeon of Deceit", 5, "Deceit"));
Achievements.Add(new DiscoveryAchievement(27, 3, 0x14EB, false, null, "Despise!", "Discover the dungeon of Despise", 5, "Despise"));
Achievements.Add(new DiscoveryAchievement(28, 3, 0x14EB, false, null, "Destard!", "Discover the dungeon of Destard", 5, "Destard"));
Achievements.Add(new DiscoveryAchievement(29, 3, 0x14EB, false, null, "Hythloth!", "Discover the dungeon of Hythloth", 5, "Hythloth"));
Achievements.Add(new DiscoveryAchievement(30, 3, 0x14EB, false, null, "Wrong!", "Discover the dungeon of Wrong", 5, "Wrong"));
Achievements.Add(new DiscoveryAchievement(31, 3, 0x14EB, false, null, "Shame!", "Discover the dungeon of Shame", 5, "Shame"));
Achievements.Add(new DiscoveryAchievement(100, 4, 0x14EB, false, null, "Cotton!", "Discover A Cotton Field in Moonglow", 5, "A Cotton Field in Moonglow"));
Achievements.Add(new DiscoveryAchievement(101, 4, 0x14EB, false, null, "Carrots!", "Discover A Carrot Field in Skara Brae", 5, "A Carrot Field in Skara Brae"));
//these two show examples of adding a reward or multiple rewards
var achieve = new HarvestAchievement(500, 2000, 0x0E85, false, null, 500, "500 Iron Ore", "Mine 500 Iron Ore", 5, typeof(IronOre), typeof(AncientSmithyHammer));
Achievements.Add(achieve);
Achievements.Add(new HarvestAchievement(501, 2000, 0x0E85, false, achieve, 5000, "5000 Iron Ore", "Mine 5000 Iron Ore", 5, typeof(IronOre), typeof(AncientSmithyHammer),typeof(TinkerTools),typeof(HatOfTheMagi)));
Achievements.Add(new HunterAchievement(1000, 3000, 0x25D1, false, null, 5, "Dog Slayer", "Slay 5 Dogs", 5, typeof(Dog)));
Achievements.Add(new HunterAchievement(1001, 3000, 0x25D1, false, null, 50, "Dragon Slayer", "Slay 50 Dragon", 5, typeof(Dragon)));
CommandSystem.Register("feats", AccessLevel.Player, new CommandEventHandler(OpenGumpCommand));
EventSink.WorldSave += EventSink_WorldSave;
LoadData();
}
private static void LoadData()
{
Persistence.Deserialize(
"Saves//Achievements.bin",
reader =>
{
int count = reader.ReadInt();
for (int i = 0; i < count; ++i)
{
m_pointsTotal.Add(reader.ReadInt(), reader.ReadInt());
}
count = reader.ReadInt();
for (int i = 0; i < count; ++i)
{
var id = reader.ReadInt();
var dict = new Dictionary<int, AchieveData>();
int iCount = reader.ReadInt();
if (iCount > 0)
{
for (int x = 0; x < iCount; x++)
{
dict.Add(reader.ReadInt(), new AchieveData(reader));
}
}
m_featData.Add(id, dict);
}
System.Console.WriteLine("Loaded Achievements store: " + m_featData.Count);
});
}
private static void EventSink_WorldSave(WorldSaveEventArgs e)
{
Persistence.Serialize(
"Saves//Achievements.bin",
writer =>
{
writer.Write(m_pointsTotal.Count);
foreach (var kv in m_pointsTotal)
{
writer.Write(kv.Key);
writer.Write(kv.Value);
}
writer.Write(m_featData.Count);
foreach (var kv in m_featData)
{
writer.Write(kv.Key);
writer.Write(kv.Value.Count);
foreach (var ckv in kv.Value)
{
writer.Write(ckv.Key);
ckv.Value.Serialize(writer);
}
}
});
}
public static void OpenGump(Mobile from, Mobile target)
{
if (from == null || target == null)
return;
if (target as PlayerMobile != null)
{
var player = target as PlayerMobile;
if (!m_featData.ContainsKey(player.Serial))
m_featData.Add(player.Serial, new Dictionary<int, AchieveData>());
var achieves = m_featData[player.Serial];
var total = GetPlayerPointsTotal(player);
from.SendGump(new AchievementGump(achieves, total));
}
}
[Usage("feats"), Aliases("ach", "achievement", "achs", "achievements")]
[Description("Opens the Achievements gump")]
private static void OpenGumpCommand(CommandEventArgs e)
{
OpenGump(e.Mobile, e.Mobile);
}
internal static void SetAchievementStatus(PlayerMobile player, BaseAchievement ach, int progress)
{
if (!m_featData.ContainsKey(player.Serial))
m_featData.Add(player.Serial, new Dictionary<int, AchieveData>());
var achieves = m_featData[player.Serial];
if (achieves.ContainsKey(ach.ID))
{
if (achieves[ach.ID].Progress >= ach.CompletionTotal)
return;
achieves[ach.ID].Progress += progress;
}
else
{
achieves.Add(ach.ID, new AchieveData() { Progress = progress });
}
if (achieves[ach.ID].Progress >= ach.CompletionTotal)
{
player.SendGump(new AchievementObtainedGump(ach),false);
achieves[ach.ID].CompletedOn = DateTime.UtcNow;
AddPoints(player,ach.RewardPoints);
if (ach.RewardItems != null && ach.RewardItems.Length > 0)
{
try
{
player.SendAsciiMessage("You have recieved an award for completing this achievment!");
var item = (Item)Activator.CreateInstance(ach.RewardItems[0]);
if (!WeightOverloading.IsOverloaded(player))
player.Backpack.DropItem(item);
else
player.BankBox.DropItem(item);
}
catch { }
}
}
}
}
}