Cleanup, bugfixes

This commit is contained in:
Anuken
2019-10-05 15:51:29 -04:00
parent e5c7d5dd2f
commit 4b99f7c819
17 changed files with 356 additions and 242 deletions
@@ -1,13 +1,13 @@
package io.anuke.mindustry.game;
import io.anuke.arc.util.ArcAnnotate.*;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.*;
import io.anuke.mindustry.mod.Mods.*;
import io.anuke.mindustry.type.ContentType;
import io.anuke.mindustry.type.*;
/** Base class for a content type that is loaded in {@link io.anuke.mindustry.core.ContentLoader}. */
public abstract class Content{
public abstract class Content implements Comparable<Content>{
public final short id;
/** The mod that loaded this piece of content. */
public @Nullable LoadedMod mod;
@@ -34,6 +34,11 @@ public abstract class Content{
public void load(){
}
@Override
public int compareTo(Content c){
return Integer.compare(id, c.id);
}
@Override
public String toString(){
return getContentType().name() + "#" + id;
@@ -61,11 +61,13 @@ public class EventType{
/** Called when a zone's requirements are met. */
public static class ZoneRequireCompleteEvent{
public final Zone zone, required;
public final Zone zoneMet, zoneForMet;
public final Objective objective;
public ZoneRequireCompleteEvent(Zone zone, Zone required){
this.zone = zone;
this.required = required;
public ZoneRequireCompleteEvent(Zone zoneMet, Zone zoneForMet, Objective objective){
this.zoneMet = zoneMet;
this.zoneForMet = zoneForMet;
this.objective = objective;
}
}
@@ -91,12 +91,17 @@ public class GlobalData{
state.stats.itemsDelivered.getAndIncrement(item, 0, amount);
}
public boolean hasItems(Array<ItemStack> stacks){
return !stacks.contains(s -> items.get(s.item, 0) < s.amount);
}
public boolean hasItems(ItemStack[] stacks){
for(ItemStack stack : stacks){
if(items.get(stack.item, 0) < stack.amount){
if(!has(stack.item, stack.amount)){
return false;
}
}
return true;
}
@@ -107,6 +112,13 @@ public class GlobalData{
modified = true;
}
public void removeItems(Array<ItemStack> stacks){
for(ItemStack stack : stacks){
items.getAndIncrement(stack.item, 0, -stack.amount);
}
modified = true;
}
public boolean has(Item item, int amount){
return items.get(item, 0) >= amount;
}
@@ -1,5 +1,10 @@
package io.anuke.mindustry.game;
import io.anuke.arc.scene.ui.layout.*;
import io.anuke.arc.util.ArcAnnotate.*;
import io.anuke.mindustry.game.Objectives.*;
import io.anuke.mindustry.type.*;
/** Defines a specific objective for a game. */
public interface Objective{
@@ -7,6 +12,16 @@ public interface Objective{
boolean complete();
/** @return the string displayed when this objective is completed, in imperative form.
* e.g. when the objective is 'complete 10 waves', this would display "complete 10 waves".*/
String display();
* e.g. when the objective is 'complete 10 waves', this would display "complete 10 waves".
* If this objective should not be displayed, should return null.*/
@Nullable String display();
/** Build a display for this zone requirement.*/
default void build(Table table){
}
default Zone zone(){
return this instanceof ZoneObjective ? ((ZoneObjective)this).zone : null;
}
}
@@ -1,16 +1,21 @@
package io.anuke.mindustry.game;
import io.anuke.arc.*;
import io.anuke.arc.util.ArcAnnotate.*;
import io.anuke.mindustry.type.*;
/** Holds objective classes. */
public class Objectives{
public static class WaveObjective implements Objective{
//TODO
public static class Wave implements Objective{
public int wave;
public WaveObjective(int wave){
public Wave(int wave){
this.wave = wave;
}
protected WaveObjective(){}
protected Wave(){}
@Override
public boolean complete(){
@@ -19,20 +24,72 @@ public class Objectives{
@Override
public String display(){
//TODO
return null;
}
}
public static class LaunchObjective implements Objective{
public static class Unlock implements Objective{
public @NonNull UnlockableContent content;
public Unlock(UnlockableContent content){
this.content = content;
}
protected Unlock(){}
@Override
public boolean complete(){
return false;
return content.unlocked();
}
@Override
public String display(){
return null;
return Core.bundle.format("requirement.unlock", content.localizedName);
}
}
public static class ZoneWave extends ZoneObjective{
public int wave;
public ZoneWave(Zone zone, int wave){
this.zone = zone;
this.wave = wave;
}
protected ZoneWave(){}
@Override
public boolean complete(){
return zone.bestWave() >= wave;
}
@Override
public String display(){
return Core.bundle.format("requirement.wave", wave, zone.localizedName);
}
}
public static class Launched extends ZoneObjective{
public Launched(Zone zone){
this.zone = zone;
}
protected Launched(){}
@Override
public boolean complete(){
return zone.hasLaunched();
}
@Override
public String display(){
return Core.bundle.format("requirement.core", zone.localizedName);
}
}
public abstract static class ZoneObjective implements Objective{
public @NonNull Zone zone;
}
}