-
Notifications
You must be signed in to change notification settings - Fork 16
/
OldWorld.cs
301 lines (251 loc) · 10.5 KB
/
OldWorld.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
using System;
using System.Collections.Generic;
using EndlessClient.Dialogs;
using EndlessClient.Dialogs.Old;
using EndlessClient.GameExecution;
using EndlessClient.Rendering;
using EOLib.Config;
using EOLib.Domain.Chat;
using EOLib.Graphics;
using EOLib.IO.Map;
using EOLib.IO.Pub;
using EOLib.Localization;
using EOLib.Net;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using XNAControls.Old;
namespace EndlessClient.Old
{
[Serializable]
public class WorldLoadException : Exception
{
public WorldLoadException(string msg) : base(msg) { }
}
//singleton pattern: provides global access to data files and network connection
// without allowing for instantiation outside of the class or inheriting from it
public sealed class OldWorld : IDisposable
{
#if DEBUG
public static int FPS { get; set; }
#endif
/*** STATIC MEMBERS AND SUCH FOR THE SINGLETON PATTERN ***/
private static OldWorld inst;
private static readonly object locker = new object();
public static bool Initialized { get; private set; }
public static OldWorld Instance
{
get
{
lock (locker)
{
return inst ?? (inst = new OldWorld());
}
}
}
//Gets a localized string based on the selected language
public static string GetString(DialogResourceID id, bool getTitle)
{
return Instance.DataFiles[Instance.Localized1].Data[(int)id + (getTitle ? 0 : 1)];
}
public static string GetString(EOResourceID id)
{
return Instance.DataFiles[Instance.Localized2].Data[(int)id];
}
private OldWorld() //private: don't allow construction of the world using 'new'
{
//((EOClient) m_client).EventSendData +=
// dte => Logger.Log("SEND thread: Processing {4} packet Family={0,-13} Action={1,-8} sz={2,-5} data={3}",
// Enum.GetName(typeof (PacketFamily), dte.PacketFamily),
// Enum.GetName(typeof (PacketAction), dte.PacketAction),
// dte.RawByteData.Length,
// dte.ByteDataHexString,
// dte.Type == DataTransferEventArgs.TransferType.Send
// ? "ENC"
// : dte.Type == DataTransferEventArgs.TransferType.SendRaw ? "RAW" : "ERR");
//((EOClient) m_client).EventReceiveData +=
// dte => Logger.Log("RECV thread: Processing {0} packet Family={1,-13} Action={2,-8} sz={3,-5} data={4}",
// dte.PacketHandled ? " handled" : "UNHANDLED",
// Enum.GetName(typeof (PacketFamily), dte.PacketFamily),
// Enum.GetName(typeof (PacketAction), dte.PacketAction),
// dte.RawByteData.Length,
// dte.ByteDataHexString);
}
public void Init()
{
exp_table = new int[254];
for (int i = 1; i < exp_table.Length; ++i)
{
exp_table[i] = (int)Math.Round(Math.Pow(i, 3) * 133.1);
}
}
public int[] exp_table;
private EOLanguage m_lang;
public EOLanguage Language
{
get { return m_lang; }
set
{
m_lang = value;
switch (m_lang)
{
case EOLanguage.English:
Localized1 = EOLib.Localization.DataFiles.EnglishStatus1;
Localized2 = EOLib.Localization.DataFiles.EnglishStatus2;
break;
case EOLanguage.Dutch:
Localized1 = EOLib.Localization.DataFiles.DutchStatus1;
Localized2 = EOLib.Localization.DataFiles.DutchStatus2;
break;
case EOLanguage.Swedish:
Localized1 = EOLib.Localization.DataFiles.SwedishStatus1;
Localized2 = EOLib.Localization.DataFiles.SwedishStatus2;
break;
case EOLanguage.Portuguese:
Localized1 = EOLib.Localization.DataFiles.PortugueseStatus1;
Localized2 = EOLib.Localization.DataFiles.PortugueseStatus2;
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
public DataFiles Localized1 { get; private set; }
public DataFiles Localized2 { get; private set; }
public bool CurseFilterEnabled { get; set; }
public bool StrictFilterEnabled { get; set; }
public bool ShowShadows { get; set; }
public bool ShowChatBubbles { get; set; }
public bool ShowTransition { get; private set; }
public int PlayerDropProtectTime { get; private set; }
public int NPCDropProtectTime { get; private set; }
public bool MusicEnabled { get; set; }
public bool SoundEnabled { get; set; }
public bool HearWhispers { get; set; }
public bool Interaction { get; set; }
public bool LogChatToFile { get; set; }
public bool EnableLog { get; private set; }
/*** Instance Properties and such ***/
public short JailMap { get; private set; }
//this is an int for the map id since there are multiple maps
public int NeedMap { get; private set; }
public IPubFile<EIFRecord> EIF { get; private set; }
public IPubFile<ENFRecord> ENF { get; private set; }
public IPubFile<ESFRecord> ESF { get; private set; }
public IPubFile<ECFRecord> ECF { get; private set; }
/// <summary>
/// Stores a list of MapFiles paired with/accessible by their IDs
/// </summary>
private Dictionary<int, IMapFile> MapCache { get; set; }
public Dictionary<DataFiles, EDFFile> DataFiles { get; private set; }
private OldMapRenderer m_mapRender;
/// <summary>
/// Returns a map rendering object encapsulating the map the MainPlayer is on
/// </summary>
public OldMapRenderer ActiveMapRenderer
{
get
{
//make sure it's in the game's componenets
if(m_mapRender != null && EOGame.Instance.State == GameStates.PlayingTheGame && !EOGame.Instance.Components.Contains(m_mapRender))
EOGame.Instance.Components.Add(m_mapRender);
return m_mapRender;
}
}
private OldCharacterRenderer m_charRender;
/// <summary>
/// Returns a reference to the primary CharacterRenderer associated with MainPlayer.ActiveCharacter
/// </summary>
public OldCharacterRenderer ActiveCharacterRenderer
{
get
{
//lazy initialization
if (m_charRender == null)
{
m_charRender = new OldCharacterRenderer(MainPlayer.ActiveCharacter);
m_charRender.Initialize();
}
OldCharacterRenderer ret = m_charRender;
if(ret.Character == null)
{
EOGame.Instance.DoShowLostConnectionDialogAndReturnToMainMenu();
return null;
}
//if player logs out and logs back in
if (ret.Character != MainPlayer.ActiveCharacter)
{
ret.Dispose();
ret = m_charRender = new OldCharacterRenderer(MainPlayer.ActiveCharacter);
m_charRender.Initialize();
}
return ret;
}
}
/*** Other things that should be singleton ***/
private readonly Player m_player;
public Player MainPlayer => m_player;
private readonly ClientBase m_client;
public ClientBase Client => m_client;
/*** Functions for loading/checking the different pub/map files ***/
//tries to load the map that MainPlayer.ActiveCharacter is hanging out on
private bool _tryLoadMap(int mapID, bool forceReload)
{
return true;
}
public void ResetGameElements()
{
if (m_mapRender != null)
{
m_mapRender.Dispose();
m_mapRender = null;
}
if (m_charRender != null)
{
m_charRender.Dispose();
m_charRender = null;
}
if(MapCache != null) MapCache.Clear();
}
public void Dispose()
{
Dispose(true);
}
private void Dispose(bool disposing)
{
if (disposing)
{
if (m_mapRender != null)
m_mapRender.Dispose();
if (m_charRender != null)
m_charRender.Dispose();
if (m_client != null)
m_client.Dispose();
}
}
public void Remap()
{
MapCache.Remove(MainPlayer.ActiveCharacter.CurrentMap);
if (!_tryLoadMap(-1, true))
{
EOGame.Instance.DoShowLostConnectionDialogAndReturnToMainMenu();
return;
}
EOGame.Instance.Hud.AddChat(ChatTab.Local, GetString(EOResourceID.STRING_SERVER), GetString(EOResourceID.SERVER_MESSAGE_MAP_MUTATION), ChatIcon.Exclamation, ChatColor.Server);
EOGame.Instance.Hud.AddChat(ChatTab.System, GetString(EOResourceID.STRING_SERVER), GetString(EOResourceID.SERVER_MESSAGE_MAP_MUTATION), ChatIcon.Exclamation, ChatColor.Server);
ActiveMapRenderer.SetActiveMap(MapCache[MainPlayer.ActiveCharacter.CurrentMap]);
}
public static void IgnoreDialogs(XNAControl control)
{
control.IgnoreDialog(typeof(TradeDialog));
}
public static Texture2D GetSpellIcon(short icon, bool hover)
{
Texture2D fullTexture = EOGame.Instance.GFXManager.TextureFromResource(GFXTypes.SpellIcons, icon);
Texture2D ret = new Texture2D(fullTexture.GraphicsDevice, fullTexture.Width / 2, fullTexture.Height);
Color[] data = new Color[ret.Width * ret.Height];
fullTexture.GetData(0, new Rectangle(hover ? ret.Width : 0, 0, ret.Width, ret.Height), data, 0, data.Length);
ret.SetData(data);
return ret;
}
}
}