forked from hamstar0/tml-wormholes-mod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWormholesMod.cs
228 lines (173 loc) · 6.12 KB
/
WormholesMod.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
using HamstarHelpers.Utilities.Config;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.IO;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Wormholes.NetProtocol;
namespace Wormholes {
public class WormholeModContext {
internal WormholesMod MyMod;
internal WormholeModContext( WormholesMod mymod ) { this.MyMod = mymod; }
}
class WormholesMod : Mod {
public static WormholesMod Instance { get; private set; }
public static string GithubUserName { get { return "hamstar0"; } }
public static string GithubProjectName { get { return "tml-wormholes-mod"; } }
public static string ConfigFileRelativePath {
get { return ConfigurationDataBase.RelativePath + Path.DirectorySeparatorChar + WormholesConfigData.ConfigFileName; }
}
public static void ReloadConfigFromFile() {
if( Main.netMode != 0 ) {
throw new Exception( "Cannot reload configs outside of single player." );
}
WormholesMod.Instance.Config.LoadFile();
}
////////////////
public WormholeModContext Context { get; private set; }
public JsonConfig<WormholesConfigData> Config { get; private set; }
private WormholesUI UI;
////////////////
public WormholesMod() : base() {
this.Context = new WormholeModContext( this );
this.Properties = new ModProperties() {
Autoload = true,
AutoloadGores = true,
AutoloadSounds = true
};
this.Config = new JsonConfig<WormholesConfigData>( WormholesConfigData.ConfigFileName,
ConfigurationDataBase.RelativePath, new WormholesConfigData() );
}
////////////////
public override void Load() {
WormholesMod.Instance = this;
var hamhelpmod = ModLoader.GetMod( "HamstarHelpers" );
var min_vers = new Version( 1, 2, 0 );
if( hamhelpmod.Version < min_vers ) {
throw new Exception( "Hamstar Helpers must be version " + min_vers.ToString() + " or greater." );
}
this.LoadConfig();
// Clients and single only
if( Main.netMode != 2 ) {
WormholePortal.Initialize();
WormholesUI.Initialize();
this.UI = new WormholesUI();
}
}
private void LoadConfig() {
var old_config = new JsonConfig<WormholesConfigData>( "Wormholes 1.3.12.json", "", new WormholesConfigData() );
// Update old config to new location
if( old_config.LoadFile() ) {
old_config.DestroyFile();
old_config.SetFilePath( this.Config.FileName, ConfigurationDataBase.RelativePath );
this.Config = old_config;
}
if( !this.Config.LoadFile() ) {
this.Config.SaveFile();
}
if( this.Config.Data.UpdateToLatestVersion() ) {
ErrorLogger.Log( "Wormholes updated to " + WormholesConfigData.ConfigVersion.ToString() );
this.Config.SaveFile();
}
}
public override void Unload() {
WormholesMod.Instance = null;
}
////////////////
public override void AddRecipeGroups() {
RecipeGroup evac_grp = new RecipeGroup( () => Lang.misc[37] + " Evac Potion", new int[] {
ItemID.RecallPotion, ItemID.WormholePotion
} );
RecipeGroup book_grp = new RecipeGroup( () => Lang.misc[37] + " Basic Book", new int[] {
ItemID.Book, ItemID.SpellTome
} );
RecipeGroup.RegisterGroup( "WormholesMod:EvacPotions", evac_grp );
RecipeGroup.RegisterGroup( "WormholesMod:BasicBooks", book_grp );
}
////////////////
public override void HandlePacket( BinaryReader reader, int player_who ) {
if( Main.netMode == 1 ) { // Client
ClientPacketHandlers.HandlePacket( this, reader );
} else if( Main.netMode == 2 ) { // Server
ServerPacketHandlers.HandlePacket( this, reader, player_who );
}
}
////////////////
public override void PostDrawInterface( SpriteBatch sb ) {
// Clients and single only (redundant?)
if( Main.netMode == 2 ) { return; }
try {
if( !Main.mapFullscreen && (Main.mapStyle == 1 || Main.mapStyle == 2) ) {
this.DrawMiniMap( sb );
}
} catch( Exception e ) {
ErrorLogger.Log( "PostDrawInterface: " + e.ToString() );
throw e;
}
}
public override void PostDrawFullscreenMap( ref string mouseText ) {
// Clients and single only (redundant?)
if( Main.netMode == 2 ) { return; }
try {
this.DrawFullMap( Main.spriteBatch );
} catch( Exception e ) {
ErrorLogger.Log( "PostDrawFullscreenMap: " + e.ToString() );
throw e;
}
}
////////////////
private void DrawMiniMap( SpriteBatch sb ) {
this.UI.Update();
WormholesWorld modworld = this.GetModWorld<WormholesWorld>();
WormholesPlayer curr_modplayer = Main.player[Main.myPlayer].GetModPlayer<WormholesPlayer>( this );
if( !this.Config.Data.DisableNaturalWormholes ) {
if( modworld.Wormholes != null ) {
for( int i = 0; i < modworld.Wormholes.Links.Count; i++ ) {
WormholeLink link = modworld.Wormholes.Links[i];
if( link == null ) { break; }
if( Main.mapStyle == 1 ) {
this.UI.DrawMiniMap( this.Context, link, sb );
} else {
this.UI.DrawOverlayMap( this.Context, link, sb );
}
}
}
}
if( curr_modplayer.MyPortal != null ) {
if( Main.mapStyle == 1 ) {
this.UI.DrawMiniMap( this.Context, curr_modplayer.MyPortal, sb );
} else {
this.UI.DrawOverlayMap( this.Context, curr_modplayer.MyPortal, sb );
}
}
}
private void DrawFullMap( SpriteBatch sb ) {
this.UI.Update();
WormholesWorld modworld = this.GetModWorld<WormholesWorld>();
WormholesPlayer curr_modplayer = Main.player[Main.myPlayer].GetModPlayer<WormholesPlayer>( this );
if( !this.Config.Data.DisableNaturalWormholes ) {
if( modworld.Wormholes != null ) {
for( int i = 0; i < modworld.Wormholes.Links.Count; i++ ) {
WormholeLink link = modworld.Wormholes.Links[i];
if( link == null ) { break; }
this.UI.DrawFullscreenMap( this.Context, link, sb );
}
}
}
if( curr_modplayer.MyPortal != null ) {
this.UI.DrawFullscreenMap( this.Context, curr_modplayer.MyPortal, sb );
}
}
////////////////
public bool IsDebugInfoMode() {
return (this.Config.Data.DEBUGFLAGS & 1) != 0;
}
public bool IsDebugWormholeViewMode() {
return (this.Config.Data.DEBUGFLAGS & 2) != 0;
}
public bool IsDebuResetMode() {
return (this.Config.Data.DEBUGFLAGS & 4) != 0;
}
}
}