Merge remote-tracking branch 'origin/master'

This commit is contained in:
Anuken
2021-11-01 09:41:39 -04:00
9 changed files with 144 additions and 53 deletions

View File

@@ -5,6 +5,7 @@ import arc.math.*;
import arc.struct.*;
import mindustry.*;
import mindustry.ctype.*;
import mindustry.entities.*;
import mindustry.entities.bullet.*;
import mindustry.gen.*;
import mindustry.graphics.*;
@@ -1839,7 +1840,7 @@ public class Blocks implements ContentList{
size = 4;
shootCone = 2f;
shootSound = Sounds.railgun;
unitSort = (u, x, y) -> -u.maxHealth + Mathf.dst2(u.x, u.y, x, y) / 6400f;
unitSort = UnitSorts.strongest;
coolantMultiplier = 0.4f;
@@ -2287,4 +2288,4 @@ public class Blocks implements ContentList{
//endregion
}
}
}

View File

@@ -260,33 +260,10 @@ public class NetClient implements ApplicationListener{
//a command was sent, now get the output
if(response.type != ResponseType.valid){
String text;
//send usage
if(response.type == ResponseType.manyArguments){
text = "[scarlet]Too many arguments. Usage:[lightgray] " + response.command.text + "[gray] " + response.command.paramText;
}else if(response.type == ResponseType.fewArguments){
text = "[scarlet]Too few arguments. Usage:[lightgray] " + response.command.text + "[gray] " + response.command.paramText;
}else{ //unknown command
int minDst = 0;
Command closest = null;
for(Command command : netServer.clientCommands.getCommandList()){
int dst = Strings.levenshtein(command.text, response.runCommand);
if(dst < 3 && (closest == null || dst < minDst)){
minDst = dst;
closest = command;
}
}
if(closest != null){
text = "[scarlet]Unknown command. Did you mean \"[lightgray]" + closest.text + "[]\"?";
}else{
text = "[scarlet]Unknown command. Check [lightgray]/help[scarlet].";
}
String text = netServer.invalidHandler.handle(player, response);
if(text != null){
player.sendMessage(text);
}
player.sendMessage(text);
}
}
}

View File

@@ -67,6 +67,32 @@ public class NetServer implements ApplicationListener{
/** Converts a message + NULLABLE player sender into a single string. Override for custom prefixes/suffixes. */
public ChatFormatter chatFormatter = (player, message) -> player == null ? message : "[coral][[" + player.coloredName() + "[coral]]:[white] " + message;
/** Handles an incorrect command response. Returns text that will be sent to player. Override for customisation. */
public InvalidCommandHandler invalidHandler = (player, response) -> {
if(response.type == ResponseType.manyArguments){
return "[scarlet]Too many arguments. Usage:[lightgray] " + response.command.text + "[gray] " + response.command.paramText;
}else if(response.type == ResponseType.fewArguments){
return "[scarlet]Too few arguments. Usage:[lightgray] " + response.command.text + "[gray] " + response.command.paramText;
}else{ //unknown command
int minDst = 0;
Command closest = null;
for(Command command : netServer.clientCommands.getCommandList()){
int dst = Strings.levenshtein(command.text, response.runCommand);
if(dst < 3 && (closest == null || dst < minDst)){
minDst = dst;
closest = command;
}
}
if(closest != null){
return "[scarlet]Unknown command. Did you mean \"[lightgray]" + closest.text + "[]\"?";
}else{
return "[scarlet]Unknown command. Check [lightgray]/help[scarlet].";
}
}
};
private boolean closing = false;
private Interval timer = new Interval();
@@ -994,4 +1020,8 @@ public class NetServer implements ApplicationListener{
/** @return text to be placed before player name */
String format(@Nullable Player player, String message);
}
public interface InvalidCommandHandler{
String handle(Player player, CommandResponse response);
}
}

View File

@@ -0,0 +1,14 @@
package mindustry.entities;
import arc.math.*;
import mindustry.entities.Units.*;
import mindustry.gen.*;
public class UnitSorts{
public static Sortf
closest = Unit::dst2,
farthest = (u, x, y) -> -u.dst2(x, y),
strongest = (u, x, y) -> -u.maxHealth + Mathf.dst2(u.x, u.y, x, y) / 6400f,
weakest = (u, x, y) -> u.maxHealth + Mathf.dst2(u.x, u.y, x, y) / 6400f;
}

View File

@@ -20,6 +20,7 @@ import mindustry.content.*;
import mindustry.content.TechTree.*;
import mindustry.ctype.*;
import mindustry.entities.*;
import mindustry.entities.Units.*;
import mindustry.entities.abilities.*;
import mindustry.entities.bullet.*;
import mindustry.entities.effect.*;
@@ -61,6 +62,7 @@ public class ContentParser{
readFields(result, data);
return result;
});
put(Sortf.class, (type, data) -> field(UnitSorts.class, data));
put(Interp.class, (type, data) -> field(Interp.class, data));
put(CacheLayer.class, (type, data) -> field(CacheLayer.class, data));
put(Attribute.class, (type, data) -> Attribute.get(data.asString()));
@@ -826,4 +828,4 @@ public class ContentParser{
void parsed(Class<?> type, JsonValue jsonData, Object result);
}
}
}

View File

@@ -76,7 +76,7 @@ public class Turret extends ReloadTurret{
public Effect chargeBeginEffect = Fx.none;
public Sound chargeSound = Sounds.none;
public Sortf unitSort = Unit::dst2;
public Sortf unitSort = UnitSorts.closest;
protected Vec2 tr = new Vec2();
protected Vec2 tr2 = new Vec2();
@@ -508,4 +508,4 @@ public class Turret extends ReloadTurret{
return 1;
}
}
}
}