3
3
import arc .*;
4
4
import arc .files .*;
5
5
import arc .struct .*;
6
- import arc .struct .ObjectFloatMap .*;
6
+ import arc .struct .ObjectMap .*;
7
7
import arc .util .*;
8
8
9
9
import mindustry .*;
19
19
import com .google .gson .*;
20
20
import com .google .gson .reflect .*;
21
21
22
-
23
22
import java .util .*;
24
23
25
24
26
25
@ SuppressWarnings ("unused" )
27
26
public class DominationPlugin extends Plugin {
28
27
private static boolean showdown = false ;
29
- private static final Interval interval = new Interval (3 );
28
+ private static final Interval timers = new Interval (3 );
30
29
private static final ObjectSet <Playerc > editors = new ObjectSet <>();
31
-
32
- private static final ObjectFloatMap <Team > leaderboard = new ObjectFloatMap <>();
30
+ private static final OrderedMap <Team , Float > leaderboard = new OrderedMap <>();
33
31
34
32
private static final Gson gson ;
35
33
private static final TreeMap <String , DominationMap > dominationMaps = new TreeMap <>();
36
34
private static final Fi configFile = new Fi (Core .files .external ("domination-config.json" ).absolutePath ());
37
35
38
36
private static final int
39
- LOGIC_TIMER_SLOT = 0 ,
40
- COUNTDOWN_TIMER_SLOT = 1 ,
41
- GRAPHICS_TIMER_SLOT = 2 ;
42
-
37
+ LOGIC_TIMER = 0 ,
38
+ COUNTDOWN_TIMER = 1 ,
39
+ GRAPHICS_TIMER = 2 ;
43
40
44
41
static {
45
42
gson = new GsonBuilder ()
@@ -61,15 +58,14 @@ public void init(){
61
58
// Main
62
59
Events .run (Trigger .update , () -> {
63
60
if (isActive ()){
64
- if (interval .get (LOGIC_TIMER_SLOT , getCurrentMap ().getUpdateTicks ())){
65
- // Updates the zone internal data
66
- getCurrentMap ().forEach (z -> z .update (getCurrentMap ()));
61
+ if (timers .get (LOGIC_TIMER , getCurrentMap ().getUpdateTicks ())){
62
+ getCurrentMap ().update ();
67
63
// Updates the leaderboard [team -> percent_captured]
68
64
leaderboard .clear (Vars .state .teams .active .size + 1 );
69
- getCurrentMap ().forEach (z -> leaderboard .increment (z .getTeam (), 0 , z .getPercent ()));
65
+ getCurrentMap ().forEach (z -> leaderboard .put (z .getTeam (), leaderboard . get ( z . getTeam (), 0F ) + z .getPercent ()));
70
66
}
71
67
72
- if (interval .get (COUNTDOWN_TIMER_SLOT , (showdown ? getCurrentMap ().getShowdownDuration () : getCurrentMap ().getGameDuration ()) * Time .toMinutes )){
68
+ if (timers .get (COUNTDOWN_TIMER , (showdown ? getCurrentMap ().getShowdownDuration () : getCurrentMap ().getGameDuration ()) * Time .toMinutes )){
73
69
List <Team > winners = getWinners ();
74
70
if (winners .size () == 0 ){
75
71
Events .fire (new GameOverEvent (Team .derelict ));
@@ -81,37 +77,33 @@ public void init(){
81
77
}
82
78
}
83
79
84
- if (interval .get (GRAPHICS_TIMER_SLOT , Time .toSeconds / 6 )){
80
+ if (timers .get (GRAPHICS_TIMER , Time .toSeconds / 6 )){
85
81
if (isActive ()){
86
82
// HUD text
87
83
StringBuilder builder = new StringBuilder (100 );
88
84
89
85
getCurrentMap ().drawZoneCircles ();
90
- getCurrentMap ().drawZoneTexts ();
86
+ getCurrentMap ().drawZoneTexts (1F / 6 );
91
87
92
88
// Time remaining
93
- int time = (int )(((showdown ? Time .toMinutes : getCurrentMap ().getGameDuration () * Time .toMinutes ) - interval .getTime (1 )) / Time .toSeconds );
94
- builder .append (Strings .format ("@Time remaining > @@" , (showdown ? "[red]" : "" ), Strings .formatMillis (time * 1000L ), (showdown ? "[]" : "" )));
95
-
96
- // Unclaimed zones
97
- if (leaderboard .containsKey (Team .derelict )){
98
- builder .append (Strings .format ("\n [#@]unclaimed[] > @%" , Team .derelict .color , (int )leaderboard .get (Team .derelict , 0F )));
99
- }
89
+ builder .append (showdown ? "[red]" : "" );
90
+ builder .append (Strings .format ("Time remaining > @" , Strings .formatMillis (getRemainingTime ())));
91
+ builder .append (showdown ? "[]" : "" );
100
92
101
93
// Leaderboard
102
- Seq < Entry < Team >> orderedLeaderboard = Seq . with ( leaderboard .entries ()). sort ( Comparator . comparing ( a -> a . key ));
103
- orderedLeaderboard . each ( entry -> {
104
- if ( entry . key != Team . derelict ) builder .append (Strings .format ("\n [#@]@[] > @%" , entry . key . color , entry . key .name , ( int ) entry . value ));
94
+ leaderboard .each (( team , percent ) -> {
95
+ String percentString = Strings . fixed ( percent / getCurrentMap (). getZoneNumber (), 2 );
96
+ builder .append (Strings .format ("\n [#@]@[] > @%" , team . color , team == Team . derelict ? "unclaimed" : team .name , percentString ));
105
97
});
106
98
107
99
Call .setHudText (builder .toString ());
108
100
}
109
101
110
102
// Rendering for editors
111
103
editors .each (p -> {
112
- getCurrentMap (). drawZoneCenters ( p . con ());
113
- if (! Vars . state . rules . pvp && Vars . state . isGame ()){
114
- getCurrentMap ().drawZoneCircles (p .con ());
104
+ if ( Vars . state . isGame ()){
105
+ getCurrentMap (). drawZoneCenters ( p . con ());
106
+ if (! isActive ()) getCurrentMap ().drawZoneCircles (p .con ());
115
107
}
116
108
});
117
109
}
@@ -172,7 +164,7 @@ public void registerClientCommands(CommandHandler handler){
172
164
player .sendMessage ("You disabled editor mode, how unfortunate..." );
173
165
break ;
174
166
175
- default : player .sendMessage (Strings .format ("'@' is not a valid option." , args [0 ]));
167
+ default : player .sendMessage (Strings .format ("'@' is not a valid option." , args [0 ]));
176
168
}
177
169
});
178
170
}
@@ -192,8 +184,28 @@ public static void saveDominationMaps(){
192
184
Log .info ("Domination maps have been saved." );
193
185
}
194
186
195
- public static boolean isActive (){
196
- return Vars .state .rules .pvp && !Vars .state .isMenu () && !Vars .state .gameOver ;
187
+ public static void resetGameCountdown (){
188
+ timers .reset (COUNTDOWN_TIMER , 0 );
189
+ }
190
+
191
+ public static void triggerShowdown (List <Team > teams ){
192
+ showdown = true ;
193
+ Call .sendMessage ("[red]SHOWDOWN[]." );
194
+ resetGameCountdown ();
195
+
196
+ for (TeamData data : Vars .state .teams .getActive ()){
197
+ if (!teams .contains (data .team )){
198
+ data .cores .each (CoreBuild ::kill );
199
+ Groups .player .each (p -> {
200
+ if (p .team () == data .team ){
201
+ p .team (Team .derelict );
202
+ p .unit ().kill ();
203
+ }
204
+ });
205
+
206
+ Call .sendMessage (Strings .format ("Team [#@]@[] has been reduced to ashes..." , data .team .color , data .team .name ));
207
+ }
208
+ }
197
209
}
198
210
199
211
@ Nullable
@@ -209,7 +221,7 @@ public static List<Team> getWinners(){
209
221
float maxPercent = 0F ;
210
222
List <Team > winners = new ArrayList <>();
211
223
212
- for (Entry <Team > entry : leaderboard .entries ()){
224
+ for (Entry <Team , Float > entry : leaderboard .entries ()){
213
225
if (entry .key == Team .derelict ) continue ;
214
226
215
227
if (entry .value > maxPercent ){
@@ -224,27 +236,13 @@ public static List<Team> getWinners(){
224
236
return winners ;
225
237
}
226
238
227
- public static void resetGameCountdown (){
228
- interval .reset (COUNTDOWN_TIMER_SLOT , 0 );
239
+ /** Returns the remaining time in milliseconds */
240
+ public static long getRemainingTime (){
241
+ float remainingTicks = ((showdown ? getCurrentMap ().getShowdownDuration () : getCurrentMap ().getGameDuration ()) * Time .toMinutes ) - timers .getTime (COUNTDOWN_TIMER );
242
+ return ((long )(remainingTicks / Time .toSeconds )) * 1000L ;
229
243
}
230
244
231
- public static void triggerShowdown (List <Team > teams ){
232
- showdown = true ;
233
- Call .sendMessage ("[red]SHOWDOWN[]." );
234
- resetGameCountdown ();
235
-
236
- for (TeamData data : Vars .state .teams .getActive ()){
237
- if (!teams .contains (data .team )){
238
- data .cores .each (CoreBuild ::kill );
239
- Groups .player .each (p -> {
240
- if (p .team () == data .team ){
241
- p .team (Team .derelict );
242
- p .unit ().kill ();
243
- }
244
- });
245
-
246
- Call .sendMessage (Strings .format ("Team [#@]@[] has been reduced to ashes..." , data .team .color , data .team .name ));
247
- }
248
- }
245
+ public static boolean isActive (){
246
+ return Vars .state .rules .pvp && !Vars .state .isMenu () && !Vars .state .gameOver ;
249
247
}
250
248
}
0 commit comments