Method refactoring / Cleanup
This commit is contained in:
@@ -238,7 +238,7 @@ public class Pathfinder implements Runnable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private PathTarget getTarget(Position position){
|
private PathTarget getTarget(Position position){
|
||||||
return targetCache.getOr(position, () -> new PositionTarget(position));
|
return targetCache.get(position, () -> new PositionTarget(position));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return whether a tile can be passed through by this team. Pathfinding thread only. */
|
/** @return whether a tile can be passed through by this team. Pathfinding thread only. */
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class LoopControl{
|
|||||||
float baseVol = sound.calcFalloff(pos.getX(), pos.getY());
|
float baseVol = sound.calcFalloff(pos.getX(), pos.getY());
|
||||||
float vol = baseVol * volume;
|
float vol = baseVol * volume;
|
||||||
|
|
||||||
SoundData data = sounds.getOr(sound, SoundData::new);
|
SoundData data = sounds.get(sound, SoundData::new);
|
||||||
data.volume += vol;
|
data.volume += vol;
|
||||||
data.volume = Mathf.clamp(data.volume, 0f, 1f);
|
data.volume = Mathf.clamp(data.volume, 0f, 1f);
|
||||||
data.total += baseVol;
|
data.total += baseVol;
|
||||||
|
|||||||
@@ -130,11 +130,11 @@ public class NetClient implements ApplicationListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addPacketHandler(String type, Cons<String> handler){
|
public void addPacketHandler(String type, Cons<String> handler){
|
||||||
customPacketHandlers.getOr(type, Array::new).add(handler);
|
customPacketHandlers.get(type, Array::new).add(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Array<Cons<String>> getPacketHandlers(String type){
|
public Array<Cons<String>> getPacketHandlers(String type){
|
||||||
return customPacketHandlers.getOr(type, Array::new);
|
return customPacketHandlers.get(type, Array::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Remote(targets = Loc.server, variants = Variant.both)
|
@Remote(targets = Loc.server, variants = Variant.both)
|
||||||
|
|||||||
@@ -393,7 +393,7 @@ 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));
|
Timekeeper vtime = cooldowns.get(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.");
|
||||||
@@ -481,11 +481,11 @@ public class NetServer implements ApplicationListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addPacketHandler(String type, Cons2<Playerc, String> handler){
|
public void addPacketHandler(String type, Cons2<Playerc, String> handler){
|
||||||
customPacketHandlers.getOr(type, Array::new).add(handler);
|
customPacketHandlers.get(type, Array::new).add(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Array<Cons2<Playerc, String>> getPacketHandlers(String type){
|
public Array<Cons2<Playerc, String>> getPacketHandlers(String type){
|
||||||
return customPacketHandlers.getOr(type, Array::new);
|
return customPacketHandlers.get(type, Array::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onDisconnect(Playerc player, String reason){
|
public static void onDisconnect(Playerc player, String reason){
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package mindustry.entities.comp;
|
|||||||
|
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import mindustry.*;
|
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
|
|
||||||
@@ -53,7 +52,7 @@ abstract class HealthComp implements Entityc{
|
|||||||
/** Damage and pierce armor. */
|
/** Damage and pierce armor. */
|
||||||
void damagePierce(float amount, boolean withEffect){
|
void damagePierce(float amount, boolean withEffect){
|
||||||
if(this instanceof Shieldc){
|
if(this instanceof Shieldc){
|
||||||
damage(amount / Math.max(1f - ((Shieldc)this).armor(), Vars.minArmorDamage), withEffect);
|
damage(amount + ((Shieldc)this).armor(), withEffect);
|
||||||
}else{
|
}else{
|
||||||
damage(amount, withEffect);
|
damage(amount, withEffect);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import mindustry.annotations.Annotations.*;
|
|||||||
import mindustry.core.*;
|
import mindustry.core.*;
|
||||||
import mindustry.entities.units.*;
|
import mindustry.entities.units.*;
|
||||||
import mindustry.game.*;
|
import mindustry.game.*;
|
||||||
|
import mindustry.game.EventType.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
import mindustry.net.Administration.*;
|
import mindustry.net.Administration.*;
|
||||||
@@ -143,6 +144,8 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
|
|||||||
unit.team(team);
|
unit.team(team);
|
||||||
unit.controller(this);
|
unit.controller(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Events.fire(new UnitChangeEvent((Playerc)this, unit));
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean dead(){
|
boolean dead(){
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ abstract class ShieldComp implements Healthc, Posc{
|
|||||||
@Override
|
@Override
|
||||||
public void damage(float amount){
|
public void damage(float amount){
|
||||||
//apply armor
|
//apply armor
|
||||||
amount *= Math.max(1f - armor, minArmorDamage);
|
//TODO balancing of armor stats & minArmorDamage
|
||||||
|
amount = Math.max(amount - armor, minArmorDamage * amount);
|
||||||
|
|
||||||
hitTime = 1f;
|
hitTime = 1f;
|
||||||
|
|
||||||
|
|||||||
@@ -289,14 +289,13 @@ public class EventType{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO rename
|
public static class UnitChangeEvent{
|
||||||
public static class MechChangeEvent{
|
|
||||||
public final Playerc player;
|
public final Playerc player;
|
||||||
public final UnitType mech;
|
public final Unitc unit;
|
||||||
|
|
||||||
public MechChangeEvent(Playerc player, UnitType mech){
|
public UnitChangeEvent(Playerc player, Unitc unit){
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.mech = mech;
|
this.unit = unit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,12 @@ import arc.struct.*;
|
|||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
import mindustry.world.blocks.storage.CoreBlock.*;
|
import mindustry.world.blocks.storage.CoreBlock.*;
|
||||||
|
import mindustry.world.modules.*;
|
||||||
|
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
|
//TODO more stats:
|
||||||
|
//- units constructed
|
||||||
public class Stats{
|
public class Stats{
|
||||||
/** export window size in seconds */
|
/** export window size in seconds */
|
||||||
private static final int exportWindow = 60;
|
private static final int exportWindow = 60;
|
||||||
@@ -30,6 +33,8 @@ public class Stats{
|
|||||||
public int buildingsDestroyed;
|
public int buildingsDestroyed;
|
||||||
/** Export statistics. */
|
/** Export statistics. */
|
||||||
public ObjectMap<Item, ExportStat> export = new ObjectMap<>();
|
public ObjectMap<Item, ExportStat> export = new ObjectMap<>();
|
||||||
|
/** Items stored in all cores. Used for the campaign. */
|
||||||
|
public ObjectIntMap<Item> coreItems = new ObjectIntMap<>();
|
||||||
|
|
||||||
/** Counter refresh state. */
|
/** Counter refresh state. */
|
||||||
private transient Interval time = new Interval();
|
private transient Interval time = new Interval();
|
||||||
@@ -43,19 +48,30 @@ public class Stats{
|
|||||||
|
|
||||||
/** Updates export statistics. */
|
/** Updates export statistics. */
|
||||||
public void handleItemExport(Item item, int amount){
|
public void handleItemExport(Item item, int amount){
|
||||||
export.getOr(item, ExportStat::new).counter += amount;
|
export.get(item, ExportStat::new).counter += amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Subtracts from export statistics. */
|
/** Subtracts from export statistics. */
|
||||||
public void handleItemImport(Item item, int amount){
|
public void handleItemImport(Item item, int amount){
|
||||||
export.getOr(item, ExportStat::new).counter -= amount;
|
export.get(item, ExportStat::new).counter -= amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getExport(Item item){
|
public float getExport(Item item){
|
||||||
return export.getOr(item, ExportStat::new).mean;
|
return export.get(item, ExportStat::new).mean;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(){
|
public void update(){
|
||||||
|
//update core items
|
||||||
|
CoreEntity entity = state.rules.defaultTeam.core();
|
||||||
|
if(entity != null){
|
||||||
|
ItemModule items = entity.items;
|
||||||
|
for(int i = 0; i < items.length(); i++){
|
||||||
|
coreItems.put(content.item(i), items.get(i));
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
coreItems.clear();
|
||||||
|
}
|
||||||
|
|
||||||
//create last stored core items
|
//create last stored core items
|
||||||
if(lastCoreItems == null){
|
if(lastCoreItems == null){
|
||||||
lastCoreItems = new int[content.items().size];
|
lastCoreItems = new int[content.items().size];
|
||||||
|
|||||||
@@ -346,7 +346,7 @@ public class Mods implements Loadable{
|
|||||||
for(Fi file : folder.list()){
|
for(Fi file : folder.list()){
|
||||||
if(file.name().startsWith("bundle") && file.extension().equals("properties")){
|
if(file.name().startsWith("bundle") && file.extension().equals("properties")){
|
||||||
String name = file.nameWithoutExtension();
|
String name = file.nameWithoutExtension();
|
||||||
bundles.getOr(name, Array::new).add(file);
|
bundles.get(name, Array::new).add(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -357,7 +357,7 @@ public class Mods implements Loadable{
|
|||||||
while(bundle != null){
|
while(bundle != null){
|
||||||
String str = bundle.getLocale().toString();
|
String str = bundle.getLocale().toString();
|
||||||
String locale = "bundle" + (str.isEmpty() ? "" : "_" + str);
|
String locale = "bundle" + (str.isEmpty() ? "" : "_" + str);
|
||||||
for(Fi file : bundles.getOr(locale, Array::new)){
|
for(Fi file : bundles.get(locale, Array::new)){
|
||||||
try{
|
try{
|
||||||
PropertiesUtils.load(bundle.getProperties(), file.reader());
|
PropertiesUtils.load(bundle.getProperties(), file.reader());
|
||||||
}catch(Throwable e){
|
}catch(Throwable e){
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public class MapsDialog extends BaseDialog{
|
|||||||
|
|
||||||
|
|
||||||
//when you attempt to import a save, it will have no name, so generate one
|
//when you attempt to import a save, it will have no name, so generate one
|
||||||
String name = map.tags.getOr("name", () -> {
|
String name = map.tags.get("name", () -> {
|
||||||
String result = "unknown";
|
String result = "unknown";
|
||||||
int number = 0;
|
int number = 0;
|
||||||
while(maps.byName(result + number++) != null);
|
while(maps.byName(result + number++) != null);
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public class BlockStats{
|
|||||||
map.put(stat.category, new OrderedMap<>());
|
map.put(stat.category, new OrderedMap<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
map.get(stat.category).getOr(stat, Array::new).add(value);
|
map.get(stat.category).get(stat, Array::new).add(value);
|
||||||
|
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class SWorkshop implements SteamUGCCallback{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Array<Fi> getWorkshopFiles(Class<? extends Publishable> type){
|
public Array<Fi> getWorkshopFiles(Class<? extends Publishable> type){
|
||||||
return workshopFiles.getOr(type, () -> new Array<>(0));
|
return workshopFiles.get(type, () -> new Array<>(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Publish a new item and submit an update for it.
|
/** Publish a new item and submit an update for it.
|
||||||
|
|||||||
Reference in New Issue
Block a user