Fixed many multiplayer bugs

This commit is contained in:
Anuken
2018-11-07 20:24:38 -05:00
parent 56ffa7905e
commit 9785745384
10 changed files with 33 additions and 22 deletions
+2
View File
@@ -94,6 +94,7 @@ public class Vars{
public static float controllerMin = 0.25f; public static float controllerMin = 0.25f;
public static float baseControllerSpeed = 11f; public static float baseControllerSpeed = 11f;
public static boolean snapCamera = true; public static boolean snapCamera = true;
public static ContentLoader content; public static ContentLoader content;
public static GameState state; public static GameState state;
public static ThreadHandler threads; public static ThreadHandler threads;
@@ -162,6 +163,7 @@ public class Vars{
}); });
} }
state = new GameState();
threads = new ThreadHandler(); threads = new ThreadHandler();
mobile = Gdx.app.getType() == ApplicationType.Android || Gdx.app.getType() == ApplicationType.iOS || testMobile; mobile = Gdx.app.getType() == ApplicationType.Android || Gdx.app.getType() == ApplicationType.iOS || testMobile;
@@ -62,8 +62,9 @@ public class Mechs implements ContentList{
drone.leader = player; drone.leader = player;
drone.set(player.x, player.y); drone.set(player.x, player.y);
drone.add(); drone.add();
Effects.effect(UnitFx.unitLand, player);
} }
Effects.effect(UnitFx.unitLand, player);
} }
} }
} }
@@ -178,12 +178,6 @@ public class Control extends Module{
}); });
Events.on(WorldLoadEvent.class, event -> threads.runGraphics(() -> Events.fire(new WorldLoadGraphicsEvent()))); Events.on(WorldLoadEvent.class, event -> threads.runGraphics(() -> Events.fire(new WorldLoadGraphicsEvent())));
Events.on(TileChangeEvent.class, event -> {
if(event.tile.getTeam() == players[0].getTeam() && Recipe.getByResult(event.tile.block()) != null){
unlocks.handleContentUsed(Recipe.getByResult(event.tile.block()));
}
});
} }
public void addPlayer(int index){ public void addPlayer(int index){
+20 -2
View File
@@ -10,9 +10,11 @@ import io.anuke.mindustry.game.EventType.*;
import io.anuke.mindustry.game.GameMode; import io.anuke.mindustry.game.GameMode;
import io.anuke.mindustry.game.Team; import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.game.Teams; import io.anuke.mindustry.game.Teams;
import io.anuke.mindustry.game.UnlockableContent;
import io.anuke.mindustry.gen.Call; import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.type.ItemStack; import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.type.Recipe;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Events; import io.anuke.ucore.core.Events;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
@@ -35,7 +37,11 @@ public class Logic extends Module{
public boolean doUpdate = true; public boolean doUpdate = true;
public Logic(){ public Logic(){
state = new GameState(); Events.on(TileChangeEvent.class, event -> {
if(event.tile.getTeam() == defaultTeam && Recipe.getByResult(event.tile.block()) != null){
handleContent(Recipe.getByResult(event.tile.block()));
}
});
} }
@Override @Override
@@ -47,6 +53,17 @@ public class Logic extends Module{
}); });
} }
/**Handles the event of content being used by either the player or some block.*/
public void handleContent(UnlockableContent content){
if(world.getSector() != null){
world.getSector().currentMission().onContentUsed(content);
}
if(!headless){
control.unlocks.unlockContent(content);
}
}
public void play(){ public void play(){
state.set(State.playing); state.set(State.playing);
state.wavetime = wavespace * state.difficulty.timeScaling * 2; state.wavetime = wavespace * state.difficulty.timeScaling * 2;
@@ -145,7 +162,8 @@ public class Logic extends Module{
world.sectors.completeSector(world.getSector().x, world.getSector().y); world.sectors.completeSector(world.getSector().x, world.getSector().y);
world.sectors.save(); world.sectors.save();
if(!headless){
if(!headless && !Net.client()){
ui.missions.show(world.getSector()); ui.missions.show(world.getSector());
} }
@@ -319,6 +319,10 @@ public class Drone extends FlyingUnit implements BuilderTrait{
TileEntity entity = (TileEntity) target; TileEntity entity = (TileEntity) target;
entity.health += type.healSpeed * Timers.delta(); entity.health += type.healSpeed * Timers.delta();
entity.health = Mathf.clamp(entity.health, 0, entity.tile.block().health); entity.health = Mathf.clamp(entity.health, 0, entity.tile.block().health);
if(timer.get(timerRepairEffect, 30)){
Effects.effect(BlockFx.healBlockFull, Palette.heal, entity.x, entity.y, entity.tile.block().size);
}
} }
updateBuilding(this); updateBuilding(this);
@@ -19,14 +19,6 @@ public class Unlocks{
Settings.setSerializer(ContentType.class, (stream, t) -> stream.writeInt(t.ordinal()), stream -> ContentType.values()[stream.readInt()]); Settings.setSerializer(ContentType.class, (stream, t) -> stream.writeInt(t.ordinal()), stream -> ContentType.values()[stream.readInt()]);
} }
/**Handles the event of content being used by either the player or some block.*/
public void handleContentUsed(UnlockableContent content){
if(world.getSector() != null){
world.getSector().currentMission().onContentUsed(content);
}
unlockContent(content);
}
/** Returns whether or not this piece of content is unlocked yet.*/ /** Returns whether or not this piece of content is unlocked yet.*/
public boolean isUnlocked(UnlockableContent content){ public boolean isUnlocked(UnlockableContent content){
return rootSet().isUnlocked(content) || currentSet().isUnlocked(content); return rootSet().isUnlocked(content) || currentSet().isUnlocked(content);
@@ -88,7 +88,7 @@ public class Sectors{
public Difficulty getDifficulty(Sector sector){ public Difficulty getDifficulty(Sector sector){
if(sector.difficulty == 0){ if(sector.difficulty == 0){
return Difficulty.normal; return Difficulty.hard;
}else if(sector.difficulty < 4){ }else if(sector.difficulty < 4){
return Difficulty.normal; return Difficulty.normal;
}else if(sector.difficulty < 9){ }else if(sector.difficulty < 9){
@@ -90,7 +90,7 @@ public class TutorialSector{
return Array.with( return Array.with(
//intentionally unlocalized //intentionally unlocalized
new ItemMission(Items.copper, 10).setMessage("An updated tutorial will return next build.\nFor now, you'll have to deal with... this."), new ItemMission(Items.copper, 50).setMessage("An updated tutorial will return next build.\nFor now, you'll have to deal with... this."),
new BlockMission(ProductionBlocks.mechanicalDrill), new BlockMission(ProductionBlocks.mechanicalDrill),
@@ -8,6 +8,7 @@ import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.game.Waves; import io.anuke.mindustry.game.Waves;
import io.anuke.mindustry.maps.Sector; import io.anuke.mindustry.maps.Sector;
import io.anuke.mindustry.maps.generation.Generation; import io.anuke.mindustry.maps.generation.Generation;
import io.anuke.mindustry.net.Net;
import io.anuke.ucore.util.Bundles; import io.anuke.ucore.util.Bundles;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.*;
@@ -35,7 +36,6 @@ public class WaveMission extends MissionWithStartingCore{
this.target = target; this.target = target;
} }
@Override @Override
public Array<SpawnGroup> getWaves(Sector sector){ public Array<SpawnGroup> getWaves(Sector sector){
return Waves.getSpawns(); return Waves.getSpawns();
@@ -62,7 +62,7 @@ public class WaveMission extends MissionWithStartingCore{
public String displayString(){ public String displayString(){
return state.wave > target ? return state.wave > target ?
Bundles.format( Bundles.format(
Vars.unitGroups[Vars.waveTeam.ordinal()].size() > 1 ? Vars.unitGroups[Vars.waveTeam.ordinal()].size() > 1 && !Net.client() ?
"text.mission.wave.enemies" : "text.mission.wave.enemies" :
"text.mission.wave.enemy", target, target, Vars.unitGroups[Vars.waveTeam.ordinal()].size()) : "text.mission.wave.enemy", target, target, Vars.unitGroups[Vars.waveTeam.ordinal()].size()) :
Bundles.format("text.mission.wave", state.wave, target, (int)(state.wavetime/60)); Bundles.format("text.mission.wave", state.wave, target, (int)(state.wavetime/60));
+1 -1
View File
@@ -230,7 +230,7 @@ public class Block extends BaseBlock {
/**Call when some content is produced. This unlocks the content if it is applicable.*/ /**Call when some content is produced. This unlocks the content if it is applicable.*/
public void useContent(Tile tile, UnlockableContent content){ public void useContent(Tile tile, UnlockableContent content){
if(!headless && tile.getTeam() == players[0].getTeam()){ if(!headless && tile.getTeam() == players[0].getTeam()){
control.unlocks.handleContentUsed(content); logic.handleContent(content);
} }
} }