Syncing enemy display

This commit is contained in:
Anuken 2018-11-17 00:04:11 -05:00
parent dcc4732748
commit d6661da0a7
6 changed files with 22 additions and 13 deletions

View File

@ -8,6 +8,9 @@ import io.anuke.mindustry.game.Teams;
import io.anuke.mindustry.net.Net;
import io.anuke.ucore.core.Events;
import static io.anuke.mindustry.Vars.unitGroups;
import static io.anuke.mindustry.Vars.waveTeam;
public class GameState{
public int wave = 1;
public float wavetime;
@ -16,8 +19,13 @@ public class GameState{
public Difficulty difficulty = Difficulty.normal;
public WaveSpawner spawner = new WaveSpawner();
public Teams teams = new Teams();
public int enemies;
private State state = State.menu;
public int enemies(){
return Net.client() ? enemies : unitGroups[waveTeam.ordinal()].size();
}
public void set(State astate){
Events.fire(new StateChangeEvent(state, astate));
state = astate;

View File

@ -284,6 +284,7 @@ public class NetClient extends Module{
//read wave info
state.wavetime = input.readFloat();
state.wave = input.readInt();
state.enemies = input.readInt();
byte cores = input.readByte();
for(int i = 0; i < cores; i++){

View File

@ -477,6 +477,7 @@ public class NetServer extends Module{
//write wave datas
dataStream.writeFloat(state.wavetime);
dataStream.writeInt(state.wave);
dataStream.writeInt(state.enemies());
ObjectSet<Tile> cores = state.teams.get(player.getTeam()).cores;

View File

@ -33,10 +33,11 @@ public interface SyncTrait extends Entity, TypeTrait{
if(isClipped()){
//move off screen when no longer in bounds
if(!Tmp.r1.setSize(
Core.camera.viewportWidth * Core.camera.zoom * NetClient.viewScale,
Core.camera.viewportHeight * Core.camera.zoom * NetClient.viewScale)
.setCenter(Core.camera.position.x, Core.camera.position.y).contains(getX(), getY())){
Tmp.r1.setSize(Core.camera.viewportWidth * Core.camera.zoom * NetClient.viewScale,
Core.camera.viewportHeight * Core.camera.zoom * NetClient.viewScale)
.setCenter(Core.camera.position.x, Core.camera.position.y);
if(!Tmp.r1.contains(getX(), getY()) && !Tmp.r1.contains(getInterpolator().last.x, getInterpolator().last.y)){
set(-99999f, -99999f);
return;
}

View File

@ -1,14 +1,12 @@
package io.anuke.mindustry.maps.missions;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.game.GameMode;
import io.anuke.mindustry.game.SpawnGroup;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.game.Waves;
import io.anuke.mindustry.maps.Sector;
import io.anuke.mindustry.maps.generation.Generation;
import io.anuke.mindustry.net.Net;
import io.anuke.ucore.util.Bundles;
import static io.anuke.mindustry.Vars.*;
@ -62,9 +60,9 @@ public class WaveMission extends MissionWithStartingCore{
public String displayString(){
return state.wave > target ?
Bundles.format(
Vars.unitGroups[Vars.waveTeam.ordinal()].size() > 1 && !Net.client() ?
state.enemies() > 1 ?
"text.mission.wave.enemies" :
"text.mission.wave.enemy", target, target, Vars.unitGroups[Vars.waveTeam.ordinal()].size()) :
"text.mission.wave.enemy", target, target, state.enemies()) :
Bundles.format("text.mission.wave", state.wave, target, (int)(state.wavetime/60));
}
@ -82,6 +80,6 @@ public class WaveMission extends MissionWithStartingCore{
@Override
public boolean isComplete(){
return state.wave > target && Vars.unitGroups[Vars.waveTeam.ordinal()].size() == 0;
return state.wave > target && state.enemies() == 0;
}
}

View File

@ -366,10 +366,10 @@ public class HudFragment extends Fragment{
table.labelWrap(() ->
world.getSector() == null ?
(unitGroups[waveTeam.ordinal()].size() > 0 && state.mode.disableWaveTimer ?
wavef.get(state.wave) + "\n" + (unitGroups[waveTeam.ordinal()].size() == 1 ?
enemyf.get(unitGroups[waveTeam.ordinal()].size()) :
enemiesf.get(unitGroups[waveTeam.ordinal()].size())) :
(state.enemies() > 0 && state.mode.disableWaveTimer ?
wavef.get(state.wave) + "\n" + (state.enemies() == 1 ?
enemyf.get(state.enemies()) :
enemiesf.get(state.enemies())) :
wavef.get(state.wave) + "\n" +
(!state.mode.disableWaveTimer ?
Bundles.format("text.wave.waiting", (int)(state.wavetime/60)) :