7
7
using HamstarHelpers . Helpers . DotNET . Extensions ;
8
8
using HamstarHelpers . Helpers . World ;
9
9
using HamstarHelpers . Helpers . TModLoader ;
10
+ using MountedMagicMirrors . Net ;
11
+ using MountedMagicMirrors . DataStructures ;
10
12
11
13
12
14
namespace MountedMagicMirrors {
13
- class DiscoveredMirrors : Dictionary < int , ISet < int > > { }
14
-
15
-
16
-
17
-
18
15
partial class MMMPlayer : ModPlayer {
19
16
internal static readonly object MyCurrentMirrorsLock = new object ( ) ;
20
17
21
18
22
19
23
20
////////////////
24
21
25
- private IDictionary < string , DiscoveredMirrors > DiscoveredMirrorTiles = new Dictionary < string , DiscoveredMirrors > ( ) ;
22
+ private IDictionary < string , DiscoveredMirrors > DiscoveredMirrorTilesPerWorld = new Dictionary < string , DiscoveredMirrors > ( ) ;
26
23
27
24
////
28
25
@@ -33,9 +30,10 @@ public DiscoveredMirrors CurrentWorldDiscoveredMirrorTiles {
33
30
if ( this . _CurrentWorldDiscoveredMirrorTiles == null ) {
34
31
string worldUid = WorldHelpers . GetUniqueIdForCurrentWorld ( true ) ;
35
32
36
- if ( ! this . DiscoveredMirrorTiles . TryGetValue ( worldUid , out this . _CurrentWorldDiscoveredMirrorTiles )
37
- && ! this . DiscoveredMirrorTiles . TryGetValue ( "_" , out this . _CurrentWorldDiscoveredMirrorTiles ) ) {
38
- this . _CurrentWorldDiscoveredMirrorTiles = null ;
33
+ if ( ! this . DiscoveredMirrorTilesPerWorld . TryGetValue ( worldUid , out this . _CurrentWorldDiscoveredMirrorTiles ) ) {
34
+ if ( ! this . DiscoveredMirrorTilesPerWorld . TryGetValue ( "_" , out this . _CurrentWorldDiscoveredMirrorTiles ) ) {
35
+ this . _CurrentWorldDiscoveredMirrorTiles = null ;
36
+ }
39
37
}
40
38
}
41
39
return this . _CurrentWorldDiscoveredMirrorTiles ;
@@ -64,11 +62,11 @@ public override void clientClone( ModPlayer clientClone ) {
64
62
myclone . _CurrentWorldDiscoveredMirrorTiles = null ;
65
63
66
64
lock ( MMMPlayer . MyCurrentMirrorsLock ) {
67
- foreach ( ( string worldUid , DiscoveredMirrors mirrors ) in this . DiscoveredMirrorTiles ) {
68
- myclone . DiscoveredMirrorTiles [ worldUid ] = new DiscoveredMirrors ( ) ;
65
+ foreach ( ( string worldUid , DiscoveredMirrors mirrors ) in this . DiscoveredMirrorTilesPerWorld ) {
66
+ myclone . DiscoveredMirrorTilesPerWorld [ worldUid ] = new DiscoveredMirrors ( ) ;
69
67
70
68
foreach ( ( int tileX , ISet < int > tileYs ) in mirrors ) {
71
- myclone . DiscoveredMirrorTiles [ worldUid ] [ tileX ] = new HashSet < int > ( tileYs ) ;
69
+ myclone . DiscoveredMirrorTilesPerWorld [ worldUid ] [ tileX ] = new HashSet < int > ( tileYs ) ;
72
70
}
73
71
}
74
72
}
@@ -77,25 +75,22 @@ public override void clientClone( ModPlayer clientClone ) {
77
75
78
76
////////////////
79
77
80
- /*public override void SyncPlayer( int toWho, int fromWho, bool newPlayer ) {
81
- if( Main.netMode == 1 ) {
82
- if( toWho == -1 && fromWho == -1 && newPlayer ) {
83
- this.Logic.OnCurrentClientConnect();
84
- }
85
- }
86
- if( Main.netMode == 2 ) {
87
- if( toWho == -1 && fromWho == this.player.whoAmI ) {
88
- this.Logic.OnServerConnect( Main.player[fromWho] );
78
+ public override void SyncPlayer ( int toWho , int fromWho , bool newPlayer ) {
79
+ lock ( MMMPlayer . MyCurrentMirrorsLock ) {
80
+ if ( Main . netMode == 1 ) {
81
+ PlayerDataProtocol . SendToServer ( this . DiscoveredMirrorTilesPerWorld ) ;
82
+ } else {
83
+ PlayerDataProtocol . SendToClients ( toWho , fromWho , this . DiscoveredMirrorTilesPerWorld ) ;
89
84
}
90
85
}
91
- }*/
86
+ }
92
87
93
88
94
89
////////////////
95
90
96
91
public override void Load ( TagCompound tag ) {
97
92
lock ( MMMPlayer . MyCurrentMirrorsLock ) {
98
- this . DiscoveredMirrorTiles . Clear ( ) ;
93
+ this . DiscoveredMirrorTilesPerWorld . Clear ( ) ;
99
94
100
95
int count = 0 ;
101
96
@@ -114,13 +109,13 @@ public override void Load( TagCompound tag ) {
114
109
private int LoadOld ( TagCompound tag ) {
115
110
int count = tag . GetInt ( "discovery_count" ) ;
116
111
117
- this . DiscoveredMirrorTiles [ "_" ] = new DiscoveredMirrors ( ) ;
112
+ this . DiscoveredMirrorTilesPerWorld [ "_" ] = new DiscoveredMirrors ( ) ;
118
113
119
114
for ( int i = 0 ; i < count ; i ++ ) {
120
115
int tileX = tag . GetInt ( "discovery_x_" + i ) ;
121
116
int tileY = tag . GetInt ( "discovery_y_" + i ) ;
122
117
123
- this . DiscoveredMirrorTiles [ "_" ] . Set2D ( tileX , tileY ) ;
118
+ this . DiscoveredMirrorTilesPerWorld [ "_" ] . Set2D ( tileX , tileY ) ;
124
119
125
120
if ( MMMConfig . Instance . DebugModeInfo ) {
126
121
LogHelpers . Log ( "(Old) Loaded mirror at " + tileX + ", " + tileY ) ;
@@ -138,13 +133,13 @@ private int LoadNew( TagCompound tag ) {
138
133
string worldUid = tag . GetString ( "world_uid_" + i ) ;
139
134
int mirrorCount = tag . GetInt ( "discovery_count_for_" + i ) ;
140
135
141
- this . DiscoveredMirrorTiles [ worldUid ] = new DiscoveredMirrors ( ) ;
136
+ this . DiscoveredMirrorTilesPerWorld [ worldUid ] = new DiscoveredMirrors ( ) ;
142
137
143
138
for ( int j = 0 ; j < mirrorCount ; j ++ ) {
144
139
int tileX = tag . GetInt ( "discovery_x_" + i + "_" + j ) ;
145
140
int tileY = tag . GetInt ( "discovery_y_" + i + "_" + j ) ;
146
141
147
- this . DiscoveredMirrorTiles [ worldUid ] . Set2D ( tileX , tileY ) ;
142
+ this . DiscoveredMirrorTilesPerWorld [ worldUid ] . Set2D ( tileX , tileY ) ;
148
143
149
144
if ( MMMConfig . Instance . DebugModeInfo ) {
150
145
LogHelpers . Log ( "Loaded mirror at " + tileX + ", " + tileY ) ;
@@ -163,12 +158,12 @@ private int LoadNew( TagCompound tag ) {
163
158
public override TagCompound Save ( ) {
164
159
lock ( MMMPlayer . MyCurrentMirrorsLock ) {
165
160
var tag = new TagCompound {
166
- { "world_count" , this . DiscoveredMirrorTiles . Count }
161
+ { "world_count" , this . DiscoveredMirrorTilesPerWorld . Count }
167
162
} ;
168
163
169
164
int i = 0 ;
170
- foreach ( string worldUid in this . DiscoveredMirrorTiles . Keys ) {
171
- IDictionary < int , ISet < int > > mirrors = this . DiscoveredMirrorTiles [ worldUid ] ;
165
+ foreach ( string worldUid in this . DiscoveredMirrorTilesPerWorld . Keys ) {
166
+ IDictionary < int , ISet < int > > mirrors = this . DiscoveredMirrorTilesPerWorld [ worldUid ] ;
172
167
int count = mirrors . Count2D ( ) ;
173
168
174
169
string myWorldUid = worldUid ;
@@ -224,7 +219,7 @@ private void PreUpdateLocal() {
224
219
if ( this . CurrentWorldDiscoveredMirrorTiles == null ) {
225
220
if ( LoadHelpers . IsWorldBeingPlayed ( ) ) {
226
221
string currWorldUid = WorldHelpers . GetUniqueIdForCurrentWorld ( true ) ;
227
- this . DiscoveredMirrorTiles [ currWorldUid ] = new DiscoveredMirrors ( ) ;
222
+ this . DiscoveredMirrorTilesPerWorld [ currWorldUid ] = new DiscoveredMirrors ( ) ;
228
223
}
229
224
}
230
225
0 commit comments