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.game.Objectives.*;
import mindustry.maps.generators.*;
import mindustry.type.*;
import static arc.struct.Array.with;
@@ -20,18 +19,17 @@ public class Zones implements ContentList{
@Override
public void load(){
groundZero = new SectorPreset("groundZero", starter, new FileMapGenerator("groundZero")){{
groundZero = new SectorPreset("groundZero", starter){{
baseLaunchCost = list(copper, -60);
startingItems = list(copper, 60);
alwaysUnlocked = true;
conditionWave = 5;
launchPeriod = 5;
resources = with(copper, scrap, lead);
}};
//TODO remove
/*
desertWastes = new Zone("desertWastes", starter, new FileMapGenerator("groundZero")){{
desertWastes = new Zone("desertWastes", starter){{
startingItems = list(copper, 120);
conditionWave = 20;
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);
loadout = Loadouts.basicFoundation;
conditionWave = 10;
launchPeriod = 5;
configureObjective = new Launched(this);
resources = with(copper, scrap, lead, coal, sand, titanium);
requirements = with(
new ZoneWave(desertWastes, 60),
//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;
startingItems = list(copper, 250);
conditionWave = 10;
resources = with(copper, lead, coal);
requirements = with(
new ZoneWave(groundZero, 10),
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);
conditionWave = 10;
resources = with(copper, lead, coal, sand, scrap);
requirements = with(
new ZoneWave(frozenForest, 10),
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;
startingItems = list(copper, 140, lead, 50);
conditionWave = 20;
launchPeriod = 20;
resources = with(copper, scrap, lead, coal, sand);
requirements = with(
new ZoneWave(desertWastes, 20),
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;
startingItems = list(copper, 200, lead, 50);
conditionWave = 10;
launchPeriod = 10;
resources = with(copper, scrap, lead, coal, titanium, sand);
requirements = with(
new ZoneWave(frozenForest, 15),
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);
resources = with(copper, lead, coal, titanium, sand);
configureObjective = new Launched(this);
requirements = with(
new ZoneWave(stainedMountains, 15),
//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);
conditionWave = 12;
launchPeriod = 4;
loadout = Loadouts.basicNucleus;
configureObjective = new Launched(this);
resources = with(copper, lead, coal, titanium, sand, thorium, scrap);
requirements = with(
new ZoneWave(craters, 40),
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;
startingItems = list(copper, 250, lead, 100);
conditionWave = 15;
launchPeriod = 10;
resources = with(copper, scrap, lead, coal, titanium, thorium, sand);
requirements = with(
new ZoneWave(ruinousShores, 20),
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;
startingItems = list(copper, 1000, lead, 1000, Items.graphite, 250, titanium, 250, Items.silicon, 250);
conditionWave = 3;
launchPeriod = 2;
resources = with(copper, scrap, lead, coal, titanium, sand, thorium);
requirements = with(
new ZoneWave(tarFields, 20),
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};
}};*/
nuclearComplex = new SectorPreset("nuclearComplex", starter, new FileMapGenerator("nuclearProductionComplex")){{
nuclearComplex = new SectorPreset("nuclearComplex", starter){{
loadout = Loadouts.basicNucleus;
startingItems = list(copper, 1250, lead, 1500, Items.silicon, 400, Items.metaglass, 250);
conditionWave = 30;
launchPeriod = 15;
resources = with(copper, scrap, lead, coal, titanium, thorium, sand);
requirements = with(
new Launched(fungalPass),
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;
baseLaunchCost = ItemStack.with();
baseLaunchCost = ItemStack.list();
startingItems = ItemStack.list(Items.copper, 2000, Items.lead, 2000, Items.graphite, 500, Items.titanium, 500, Items.silicon, 500);
conditionWave = 3;
launchPeriod = 2;
requirements = with(nuclearComplex, 40);
blockRequirements = new Block[]{Blocks.thermalGenerator};
resources = Array.with(Items.copper, Items.scrap, Items.lead, Items.coal, Items.titanium, Items.thorium};
//requirements = with(nuclearComplex, 40);
//blockRequirements = new Block[]{Blocks.thermalGenerator};
//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, () -> {
Tilec core = player.closestCore();

View File

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

View File

@@ -214,7 +214,13 @@ public class World{
setSectorRules(sector);
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){
sector.setSpawnPosition(state.rules.defaultTeam.core().pos());

View File

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

View File

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

View File

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

View File

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

View File

@@ -110,6 +110,7 @@ public class ZoneInfoDialog extends FloatingDialog{
t.left();
t.add("$zone.resources").padRight(6);
/*
if(zone.resources.size > 0){
t.table(r -> {
t.left();
@@ -123,7 +124,7 @@ public class ZoneInfoDialog extends FloatingDialog{
});
}else{
t.add("$none");
}
}*/
});
Rules rules = zone.getRules();
@@ -143,9 +144,10 @@ public class ZoneInfoDialog extends FloatingDialog{
});
cont.row();
/*
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)
).fillX().pad(3).disabled(b -> !zone.canConfigure());
).fillX().pad(3).disabled(b -> !zone.canConfigure());*/
cont.row();