Sector preset support / Per-player votekick cooldown

This commit is contained in:
Anuken
2020-05-17 11:12:22 -04:00
parent 9a32b1a35a
commit d9751dbc6d
10 changed files with 52 additions and 76 deletions

View File

@@ -2,7 +2,6 @@ package mindustry.content;
import mindustry.ctype.*; import mindustry.ctype.*;
import mindustry.game.Objectives.*; import mindustry.game.Objectives.*;
import mindustry.maps.generators.*;
import mindustry.type.*; import mindustry.type.*;
import static arc.struct.Array.with; import static arc.struct.Array.with;
@@ -20,18 +19,17 @@ public class Zones implements ContentList{
@Override @Override
public void load(){ public void load(){
groundZero = new SectorPreset("groundZero", starter, new FileMapGenerator("groundZero")){{ groundZero = new SectorPreset("groundZero", starter){{
baseLaunchCost = list(copper, -60); baseLaunchCost = list(copper, -60);
startingItems = list(copper, 60); startingItems = list(copper, 60);
alwaysUnlocked = true; alwaysUnlocked = true;
conditionWave = 5; conditionWave = 5;
launchPeriod = 5; launchPeriod = 5;
resources = with(copper, scrap, lead);
}}; }};
//TODO remove //TODO remove
/* /*
desertWastes = new Zone("desertWastes", starter, new FileMapGenerator("groundZero")){{ desertWastes = new Zone("desertWastes", starter){{
startingItems = list(copper, 120); startingItems = list(copper, 120);
conditionWave = 20; conditionWave = 20;
launchPeriod = 10; launchPeriod = 10;
@@ -82,13 +80,11 @@ public class Zones implements ContentList{
); );
}};*/ }};*/
saltFlats = new SectorPreset("saltFlats", starter, new FileMapGenerator("saltFlats")){{ saltFlats = new SectorPreset("saltFlats", starter){{
startingItems = list(copper, 200, Items.silicon, 200, lead, 200); startingItems = list(copper, 200, Items.silicon, 200, lead, 200);
loadout = Loadouts.basicFoundation; loadout = Loadouts.basicFoundation;
conditionWave = 10; conditionWave = 10;
launchPeriod = 5; launchPeriod = 5;
configureObjective = new Launched(this);
resources = with(copper, scrap, lead, coal, sand, titanium);
requirements = with( requirements = with(
new ZoneWave(desertWastes, 60), new ZoneWave(desertWastes, 60),
//new Unlock(Blocks.daggerFactory), //new Unlock(Blocks.daggerFactory),
@@ -98,11 +94,10 @@ public class Zones implements ContentList{
); );
}}; }};
frozenForest = new SectorPreset("frozenForest", starter, new FileMapGenerator("frozenForest")){{ frozenForest = new SectorPreset("frozenForest", starter){{
loadout = Loadouts.basicFoundation; loadout = Loadouts.basicFoundation;
startingItems = list(copper, 250); startingItems = list(copper, 250);
conditionWave = 10; conditionWave = 10;
resources = with(copper, lead, coal);
requirements = with( requirements = with(
new ZoneWave(groundZero, 10), new ZoneWave(groundZero, 10),
new Unlock(Blocks.junction), new Unlock(Blocks.junction),
@@ -110,10 +105,9 @@ public class Zones implements ContentList{
); );
}}; }};
craters = new SectorPreset("craters", starter, new FileMapGenerator("craters")){{ craters = new SectorPreset("craters", starter){{
startingItems = list(copper, 100); startingItems = list(copper, 100);
conditionWave = 10; conditionWave = 10;
resources = with(copper, lead, coal, sand, scrap);
requirements = with( requirements = with(
new ZoneWave(frozenForest, 10), new ZoneWave(frozenForest, 10),
new Unlock(Blocks.mender), new Unlock(Blocks.mender),
@@ -121,12 +115,11 @@ public class Zones implements ContentList{
); );
}}; }};
ruinousShores = new SectorPreset("ruinousShores", starter, new FileMapGenerator("ruinousShores")){{ ruinousShores = new SectorPreset("ruinousShores", starter){{
loadout = Loadouts.basicFoundation; loadout = Loadouts.basicFoundation;
startingItems = list(copper, 140, lead, 50); startingItems = list(copper, 140, lead, 50);
conditionWave = 20; conditionWave = 20;
launchPeriod = 20; launchPeriod = 20;
resources = with(copper, scrap, lead, coal, sand);
requirements = with( requirements = with(
new ZoneWave(desertWastes, 20), new ZoneWave(desertWastes, 20),
new ZoneWave(craters, 15), new ZoneWave(craters, 15),
@@ -137,12 +130,11 @@ public class Zones implements ContentList{
); );
}}; }};
stainedMountains = new SectorPreset("stainedMountains", starter, new FileMapGenerator("stainedMountains")){{ stainedMountains = new SectorPreset("stainedMountains", starter){{
loadout = Loadouts.basicFoundation; loadout = Loadouts.basicFoundation;
startingItems = list(copper, 200, lead, 50); startingItems = list(copper, 200, lead, 50);
conditionWave = 10; conditionWave = 10;
launchPeriod = 10; launchPeriod = 10;
resources = with(copper, scrap, lead, coal, titanium, sand);
requirements = with( requirements = with(
new ZoneWave(frozenForest, 15), new ZoneWave(frozenForest, 15),
new Unlock(Blocks.pneumaticDrill), new Unlock(Blocks.pneumaticDrill),
@@ -151,10 +143,8 @@ public class Zones implements ContentList{
); );
}}; }};
fungalPass = new SectorPreset("fungalPass", starter, new FileMapGenerator("fungalPass")){{ fungalPass = new SectorPreset("fungalPass", starter){{
startingItems = list(copper, 250, lead, 250, Items.metaglass, 100, Items.graphite, 100); startingItems = list(copper, 250, lead, 250, Items.metaglass, 100, Items.graphite, 100);
resources = with(copper, lead, coal, titanium, sand);
configureObjective = new Launched(this);
requirements = with( requirements = with(
new ZoneWave(stainedMountains, 15), new ZoneWave(stainedMountains, 15),
//new Unlock(Blocks.daggerFactory), //new Unlock(Blocks.daggerFactory),
@@ -164,13 +154,11 @@ public class Zones implements ContentList{
); );
}}; }};
overgrowth = new SectorPreset("overgrowth", starter, new FileMapGenerator("overgrowth")){{ overgrowth = new SectorPreset("overgrowth", starter){{
startingItems = list(copper, 1500, lead, 1000, Items.silicon, 500, Items.metaglass, 250); startingItems = list(copper, 1500, lead, 1000, Items.silicon, 500, Items.metaglass, 250);
conditionWave = 12; conditionWave = 12;
launchPeriod = 4; launchPeriod = 4;
loadout = Loadouts.basicNucleus; loadout = Loadouts.basicNucleus;
configureObjective = new Launched(this);
resources = with(copper, lead, coal, titanium, sand, thorium, scrap);
requirements = with( requirements = with(
new ZoneWave(craters, 40), new ZoneWave(craters, 40),
new Launched(fungalPass), new Launched(fungalPass),
@@ -181,12 +169,11 @@ public class Zones implements ContentList{
); );
}}; }};
tarFields = new SectorPreset("tarFields", starter, new FileMapGenerator("tarFields")){{ tarFields = new SectorPreset("tarFields", starter){{
loadout = Loadouts.basicFoundation; loadout = Loadouts.basicFoundation;
startingItems = list(copper, 250, lead, 100); startingItems = list(copper, 250, lead, 100);
conditionWave = 15; conditionWave = 15;
launchPeriod = 10; launchPeriod = 10;
resources = with(copper, scrap, lead, coal, titanium, thorium, sand);
requirements = with( requirements = with(
new ZoneWave(ruinousShores, 20), new ZoneWave(ruinousShores, 20),
new Unlock(Blocks.coalCentrifuge), new Unlock(Blocks.coalCentrifuge),
@@ -195,12 +182,11 @@ public class Zones implements ContentList{
); );
}}; }};
desolateRift = new SectorPreset("desolateRift", starter, new FileMapGenerator("desolateRift")){{ desolateRift = new SectorPreset("desolateRift", starter){{
loadout = Loadouts.basicNucleus; loadout = Loadouts.basicNucleus;
startingItems = list(copper, 1000, lead, 1000, Items.graphite, 250, titanium, 250, Items.silicon, 250); startingItems = list(copper, 1000, lead, 1000, Items.graphite, 250, titanium, 250, Items.silicon, 250);
conditionWave = 3; conditionWave = 3;
launchPeriod = 2; launchPeriod = 2;
resources = with(copper, scrap, lead, coal, titanium, sand, thorium);
requirements = with( requirements = with(
new ZoneWave(tarFields, 20), new ZoneWave(tarFields, 20),
new Unlock(Blocks.thermalGenerator), new Unlock(Blocks.thermalGenerator),
@@ -220,12 +206,11 @@ public class Zones implements ContentList{
resources = Array.with(Items.copper, Items.scrap, Items.lead, Items.coal, Items.sand}; resources = Array.with(Items.copper, Items.scrap, Items.lead, Items.coal, Items.sand};
}};*/ }};*/
nuclearComplex = new SectorPreset("nuclearComplex", starter, new FileMapGenerator("nuclearProductionComplex")){{ nuclearComplex = new SectorPreset("nuclearComplex", starter){{
loadout = Loadouts.basicNucleus; loadout = Loadouts.basicNucleus;
startingItems = list(copper, 1250, lead, 1500, Items.silicon, 400, Items.metaglass, 250); startingItems = list(copper, 1250, lead, 1500, Items.silicon, 400, Items.metaglass, 250);
conditionWave = 30; conditionWave = 30;
launchPeriod = 15; launchPeriod = 15;
resources = with(copper, scrap, lead, coal, titanium, thorium, sand);
requirements = with( requirements = with(
new Launched(fungalPass), new Launched(fungalPass),
new Unlock(Blocks.thermalGenerator), new Unlock(Blocks.thermalGenerator),
@@ -234,15 +219,15 @@ public class Zones implements ContentList{
}}; }};
/* /*
impact0078 = new Zone("impact0078", new MapGenerator("impact0078").dist(2f)){{ impact0078 = new SectorPreset("impact0078"){{
loadout = Loadouts.basicNucleus; loadout = Loadouts.basicNucleus;
baseLaunchCost = ItemStack.with(); baseLaunchCost = ItemStack.list();
startingItems = ItemStack.list(Items.copper, 2000, Items.lead, 2000, Items.graphite, 500, Items.titanium, 500, Items.silicon, 500); startingItems = ItemStack.list(Items.copper, 2000, Items.lead, 2000, Items.graphite, 500, Items.titanium, 500, Items.silicon, 500);
conditionWave = 3; conditionWave = 3;
launchPeriod = 2; launchPeriod = 2;
requirements = with(nuclearComplex, 40); //requirements = with(nuclearComplex, 40);
blockRequirements = new Block[]{Blocks.thermalGenerator}; //blockRequirements = new Block[]{Blocks.thermalGenerator};
resources = Array.with(Items.copper, Items.scrap, Items.lead, Items.coal, Items.titanium, Items.thorium}; //resources = Array.with(Items.copper, Items.scrap, Items.lead, Items.coal, Items.titanium, Items.thorium};
}};*/ }};*/
} }
} }

View File

@@ -155,12 +155,6 @@ public class Control implements ApplicationListener, Loadable{
} }
}); });
Events.on(ZoneConfigureCompleteEvent.class, e -> {
if(e.zone.configureObjective.display() != null){
ui.hudfrag.showToast(Core.bundle.format("zone.config.unlocked", e.zone.configureObjective.display()));
}
});
Events.on(Trigger.newGame, () -> { Events.on(Trigger.newGame, () -> {
Tilec core = player.closestCore(); Tilec core = player.closestCore();

View File

@@ -303,8 +303,8 @@ public class NetServer implements ApplicationListener{
int kickDuration = 60 * 60; int kickDuration = 60 * 60;
//voting round duration in seconds //voting round duration in seconds
float voteDuration = 0.5f * 60; float voteDuration = 0.5f * 60;
//cooldown between votes //cooldown between votes in seconds
int voteCooldown = 60 * 1; int voteCooldown = 60 * 5;
class VoteSession{ class VoteSession{
Playerc target; Playerc target;
@@ -346,11 +346,12 @@ public class NetServer implements ApplicationListener{
} }
} }
Timekeeper vtime = new Timekeeper(voteCooldown); //cooldowns per player
ObjectMap<String, Timekeeper> cooldowns = new ObjectMap<>();
//current kick sessions //current kick sessions
VoteSession[] currentlyKicking = {null}; VoteSession[] currentlyKicking = {null};
clientCommands.<Playerc>register("votekick", "[player...]", "Vote to kick a player, with a cooldown.", (args, player) -> { clientCommands.<Playerc>register("votekick", "[player...]", "Vote to kick a player.", (args, player) -> {
if(!Config.enableVotekick.bool()){ if(!Config.enableVotekick.bool()){
player.sendMessage("[scarlet]Vote-kick is disabled on this server."); player.sendMessage("[scarlet]Vote-kick is disabled on this server.");
return; return;
@@ -391,6 +392,8 @@ public class NetServer implements ApplicationListener{
}else if(found.team() != player.team()){ }else if(found.team() != player.team()){
player.sendMessage("[scarlet]Only players on your team can be kicked."); player.sendMessage("[scarlet]Only players on your team can be kicked.");
}else{ }else{
Timekeeper vtime = cooldowns.getOr(player.uuid(), () -> new Timekeeper(voteCooldown));
if(!vtime.get()){ if(!vtime.get()){
player.sendMessage("[scarlet]You must wait " + voteCooldown/60 + " minutes between votekicks."); player.sendMessage("[scarlet]You must wait " + voteCooldown/60 + " minutes between votekicks.");
return; return;
@@ -437,7 +440,6 @@ public class NetServer implements ApplicationListener{
} }
}); });
clientCommands.<Playerc>register("sync", "Re-synchronize world state.", (args, player) -> { clientCommands.<Playerc>register("sync", "Re-synchronize world state.", (args, player) -> {
if(player.isLocal()){ if(player.isLocal()){
player.sendMessage("[scarlet]Re-synchronizing as the host is pointless."); player.sendMessage("[scarlet]Re-synchronizing as the host is pointless.");

View File

@@ -214,7 +214,13 @@ public class World{
setSectorRules(sector); setSectorRules(sector);
int size = sector.getSize(); int size = sector.getSize();
loadGenerator(size, size, tiles -> sector.planet.generator.generate(tiles, sector)); loadGenerator(size, size, tiles -> {
if(sector.preset != null){
sector.preset.generator.generate(tiles);
}else{
sector.planet.generator.generate(tiles, sector);
}
});
if(state.rules.defaultTeam.core() != null){ if(state.rules.defaultTeam.core() != null){
sector.setSpawnPosition(state.rules.defaultTeam.core().pos()); sector.setSpawnPosition(state.rules.defaultTeam.core().pos());

View File

@@ -4,6 +4,7 @@ import arc.math.*;
import arc.math.geom.*; import arc.math.geom.*;
import mindustry.content.*; import mindustry.content.*;
import mindustry.ctype.*; import mindustry.ctype.*;
import mindustry.game.*;
import mindustry.io.*; import mindustry.io.*;
import mindustry.maps.*; import mindustry.maps.*;
import mindustry.type.*; import mindustry.type.*;
@@ -13,16 +14,14 @@ import mindustry.world.blocks.storage.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
public class FileMapGenerator implements WorldGenerator{ public class FileMapGenerator implements WorldGenerator{
public final Map map = null; public final Map map;
public FileMapGenerator(String mapName){ public FileMapGenerator(String mapName){
//TODO doesn't work this.map = maps.loadInternalMap(mapName);
//this.map = maps.loadInternalMap(mapName);
} }
@Override @Override
public void generate(Tiles tiles){ public void generate(Tiles tiles){
if(true) throw new IllegalArgumentException("no!");
tiles.fill(); tiles.fill();
SaveIO.load(map.file); SaveIO.load(map.file);
@@ -50,8 +49,8 @@ public class FileMapGenerator implements WorldGenerator{
} }
if(tile.block() instanceof CoreBlock && tile.team() == state.rules.defaultTeam){ if(tile.block() instanceof CoreBlock && tile.team() == state.rules.defaultTeam){
//TODO PLACE THE LOADOUT //TODO PLACE THE (CORRECT) LOADOUT
//schematics.placeLoadout(loadout, tile.x, tile.y); Schematics.placeLoadout(Loadouts.basicFoundation, tile.x, tile.y);
anyCores = true; anyCores = true;
} }
} }

View File

@@ -122,6 +122,10 @@ public class Planet extends UnlockableContent{
for(solarSystem = this; solarSystem.parent != null; solarSystem = solarSystem.parent); for(solarSystem = this; solarSystem.parent != null; solarSystem = solarSystem.parent);
} }
public void preset(int index, SectorPreset preset){
sectors.get(index).preset = preset;
}
public boolean isLandable(){ public boolean isLandable(){
return grid != null && generator != null && sectors.size > 0; return grid != null && generator != null && sectors.size > 0;
} }

View File

@@ -25,6 +25,7 @@ public class Sector{
public final SectorData data; public final SectorData data;
public @Nullable SaveSlot save; public @Nullable SaveSlot save;
public @Nullable SectorPreset preset;
public boolean unlocked; public boolean unlocked;
/** Sector enemy hostility from 0 to 1 */ /** Sector enemy hostility from 0 to 1 */

View File

@@ -16,12 +16,9 @@ import static mindustry.Vars.*;
//TODO ? remove ? //TODO ? remove ?
public class SectorPreset extends UnlockableContent{ public class SectorPreset extends UnlockableContent{
public @NonNull WorldGenerator generator; public @NonNull FileMapGenerator generator;
public @NonNull Objectives.Objective configureObjective = new ZoneWave(this, 15);
public @NonNull Planet planet; public @NonNull Planet planet;
public Array<Objectives.Objective> requirements = new Array<>(); public Array<Objectives.Objective> requirements = new Array<>();
//TODO autogenerate
public Array<Item> resources = new Array<>();
public Cons<Rules> rules = rules -> {}; public Cons<Rules> rules = rules -> {};
public boolean alwaysUnlocked; public boolean alwaysUnlocked;
@@ -32,27 +29,20 @@ public class SectorPreset extends UnlockableContent{
protected Array<ItemStack> baseLaunchCost = new Array<>(); protected Array<ItemStack> baseLaunchCost = new Array<>();
protected Array<ItemStack> startingItems = new Array<>(); protected Array<ItemStack> startingItems = new Array<>();
protected Array<ItemStack> launchCost; protected Array<ItemStack> launchCost;
protected Array<ItemStack> defaultStartingItems = new Array<>();
private Array<ItemStack> defaultStartingItems = new Array<>(); public SectorPreset(String name, Planet planet){
public SectorPreset(String name, Planet planet, WorldGenerator generator){
super(name); super(name);
this.generator = generator; this.generator = new FileMapGenerator(name);
this.planet = planet; this.planet = planet;
} }
public SectorPreset(String name){ public SectorPreset(String name){
this(name, Planets.starter, new FileMapGenerator(name)); this(name, Planets.starter);
} }
public Rules getRules(){ public Rules getRules(){
if(generator instanceof FileMapGenerator){ return generator.map.rules();
return ((FileMapGenerator)generator).map.rules();
}else{
Rules rules = new Rules();
this.rules.get(rules);
return rules;
}
} }
public boolean isLaunchWave(int wave){ public boolean isLaunchWave(int wave){
@@ -107,18 +97,12 @@ public class SectorPreset extends UnlockableContent{
.select(o -> o.zone() == this && !o.complete()) .select(o -> o.zone() == this && !o.complete())
.as(ZoneObjective.class); .as(ZoneObjective.class);
boolean wasConfig = configureObjective.complete();
closure.run(); closure.run();
for(ZoneObjective objective : incomplete){ for(ZoneObjective objective : incomplete){
if(objective.complete()){ if(objective.complete()){
Events.fire(new ZoneRequireCompleteEvent(objective.zone, content.zones().find(z -> z.requirements.contains(objective)), objective)); Events.fire(new ZoneRequireCompleteEvent(objective.zone, content.zones().find(z -> z.requirements.contains(objective)), objective));
} }
} }
if(!wasConfig && configureObjective.complete()){
Events.fire(new ZoneConfigureCompleteEvent(this));
}
} }
public int bestWave(){ public int bestWave(){
@@ -163,12 +147,11 @@ public class SectorPreset extends UnlockableContent{
} }
public boolean canConfigure(){ public boolean canConfigure(){
return configureObjective.complete(); return true;
} }
@Override @Override
public void init(){ public void init(){
resources.sort();
for(ItemStack stack : startingItems){ for(ItemStack stack : startingItems){
defaultStartingItems.add(new ItemStack(stack.item, stack.amount)); defaultStartingItems.add(new ItemStack(stack.item, stack.amount));

View File

@@ -110,6 +110,7 @@ public class ZoneInfoDialog extends FloatingDialog{
t.left(); t.left();
t.add("$zone.resources").padRight(6); t.add("$zone.resources").padRight(6);
/*
if(zone.resources.size > 0){ if(zone.resources.size > 0){
t.table(r -> { t.table(r -> {
t.left(); t.left();
@@ -123,7 +124,7 @@ public class ZoneInfoDialog extends FloatingDialog{
}); });
}else{ }else{
t.add("$none"); t.add("$none");
} }*/
}); });
Rules rules = zone.getRules(); Rules rules = zone.getRules();
@@ -143,9 +144,10 @@ public class ZoneInfoDialog extends FloatingDialog{
}); });
cont.row(); cont.row();
/*
cont.button(zone.canConfigure() ? "$configure" : Core.bundle.format("configure.locked", zone.configureObjective.display()), cont.button(zone.canConfigure() ? "$configure" : Core.bundle.format("configure.locked", zone.configureObjective.display()),
() -> loadout.show(zone.loadout.findCore().itemCapacity, zone.getStartingItems(), zone::resetStartingItems, zone::updateLaunchCost, rebuildItems) () -> loadout.show(zone.loadout.findCore().itemCapacity, zone.getStartingItems(), zone::resetStartingItems, zone::updateLaunchCost, rebuildItems)
).fillX().pad(3).disabled(b -> !zone.canConfigure()); ).fillX().pad(3).disabled(b -> !zone.canConfigure());*/
cont.row(); cont.row();