Method refactoring / Cleanup
This commit is contained in:
@@ -238,7 +238,7 @@ public class Pathfinder implements Runnable{
|
||||
}
|
||||
|
||||
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. */
|
||||
|
||||
@@ -16,7 +16,7 @@ public class LoopControl{
|
||||
float baseVol = sound.calcFalloff(pos.getX(), pos.getY());
|
||||
float vol = baseVol * volume;
|
||||
|
||||
SoundData data = sounds.getOr(sound, SoundData::new);
|
||||
SoundData data = sounds.get(sound, SoundData::new);
|
||||
data.volume += vol;
|
||||
data.volume = Mathf.clamp(data.volume, 0f, 1f);
|
||||
data.total += baseVol;
|
||||
|
||||
@@ -130,11 +130,11 @@ public class NetClient implements ApplicationListener{
|
||||
}
|
||||
|
||||
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){
|
||||
return customPacketHandlers.getOr(type, Array::new);
|
||||
return customPacketHandlers.get(type, Array::new);
|
||||
}
|
||||
|
||||
@Remote(targets = Loc.server, variants = Variant.both)
|
||||
|
||||
@@ -393,7 +393,7 @@ 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));
|
||||
Timekeeper vtime = cooldowns.get(player.uuid(), () -> new Timekeeper(voteCooldown));
|
||||
|
||||
if(!vtime.get()){
|
||||
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){
|
||||
customPacketHandlers.getOr(type, Array::new).add(handler);
|
||||
customPacketHandlers.get(type, Array::new).add(handler);
|
||||
}
|
||||
|
||||
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){
|
||||
|
||||
@@ -2,7 +2,6 @@ package mindustry.entities.comp;
|
||||
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.gen.*;
|
||||
|
||||
@@ -53,7 +52,7 @@ abstract class HealthComp implements Entityc{
|
||||
/** Damage and pierce armor. */
|
||||
void damagePierce(float amount, boolean withEffect){
|
||||
if(this instanceof Shieldc){
|
||||
damage(amount / Math.max(1f - ((Shieldc)this).armor(), Vars.minArmorDamage), withEffect);
|
||||
damage(amount + ((Shieldc)this).armor(), withEffect);
|
||||
}else{
|
||||
damage(amount, withEffect);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import mindustry.annotations.Annotations.*;
|
||||
import mindustry.core.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.net.Administration.*;
|
||||
@@ -143,6 +144,8 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
|
||||
unit.team(team);
|
||||
unit.controller(this);
|
||||
}
|
||||
|
||||
Events.fire(new UnitChangeEvent((Playerc)this, unit));
|
||||
}
|
||||
|
||||
boolean dead(){
|
||||
|
||||
@@ -23,7 +23,8 @@ abstract class ShieldComp implements Healthc, Posc{
|
||||
@Override
|
||||
public void damage(float amount){
|
||||
//apply armor
|
||||
amount *= Math.max(1f - armor, minArmorDamage);
|
||||
//TODO balancing of armor stats & minArmorDamage
|
||||
amount = Math.max(amount - armor, minArmorDamage * amount);
|
||||
|
||||
hitTime = 1f;
|
||||
|
||||
|
||||
@@ -289,14 +289,13 @@ public class EventType{
|
||||
}
|
||||
}
|
||||
|
||||
//TODO rename
|
||||
public static class MechChangeEvent{
|
||||
public static class UnitChangeEvent{
|
||||
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.mech = mech;
|
||||
this.unit = unit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,12 @@ import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.blocks.storage.CoreBlock.*;
|
||||
import mindustry.world.modules.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
//TODO more stats:
|
||||
//- units constructed
|
||||
public class Stats{
|
||||
/** export window size in seconds */
|
||||
private static final int exportWindow = 60;
|
||||
@@ -30,6 +33,8 @@ public class Stats{
|
||||
public int buildingsDestroyed;
|
||||
/** Export statistics. */
|
||||
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. */
|
||||
private transient Interval time = new Interval();
|
||||
@@ -43,19 +48,30 @@ public class Stats{
|
||||
|
||||
/** Updates export statistics. */
|
||||
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. */
|
||||
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){
|
||||
return export.getOr(item, ExportStat::new).mean;
|
||||
return export.get(item, ExportStat::new).mean;
|
||||
}
|
||||
|
||||
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
|
||||
if(lastCoreItems == null){
|
||||
lastCoreItems = new int[content.items().size];
|
||||
|
||||
@@ -346,7 +346,7 @@ public class Mods implements Loadable{
|
||||
for(Fi file : folder.list()){
|
||||
if(file.name().startsWith("bundle") && file.extension().equals("properties")){
|
||||
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){
|
||||
String str = bundle.getLocale().toString();
|
||||
String locale = "bundle" + (str.isEmpty() ? "" : "_" + str);
|
||||
for(Fi file : bundles.getOr(locale, Array::new)){
|
||||
for(Fi file : bundles.get(locale, Array::new)){
|
||||
try{
|
||||
PropertiesUtils.load(bundle.getProperties(), file.reader());
|
||||
}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
|
||||
String name = map.tags.getOr("name", () -> {
|
||||
String name = map.tags.get("name", () -> {
|
||||
String result = "unknown";
|
||||
int number = 0;
|
||||
while(maps.byName(result + number++) != null);
|
||||
|
||||
@@ -55,7 +55,7 @@ public class BlockStats{
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user