Skip to content

Commit

Permalink
additions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya246 committed Feb 9, 2022
1 parent da0fbbf commit b4d331e
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions src/assistBotsMod/assistBotsMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,22 @@ public class assistBotsMod extends Plugin{
public static Seq<AIPlayer> AIPlayers = new Seq<>();

public float rebalanceDelay = 1f;
public float tooltipChance = 0.00005f;

public enum Config{
baseBotCount("The base amount of bots.", Integer.class, 4),
botFraction("The amount a single player contributes to bot count.", Float.class, 0.5f),
compensationMultiplier("In PvP games, the amount of bots a team recieves per missing player.", Float.class, 1.5f);
baseBotCount("The base amount of bots.", 4),
botFraction("The amount a single player contributes to bot count.", 0.5f),
compensationMultiplier("In PvP games, the amount of bots a team recieves per missing player.", 1.5f),
tooltipChance("Chance of the /order tip appearing every tick.", 0.00005f),
orderRestrict("Restricts the /order command to admins only. Also disables the /order tip.", false);

public static final Config[] all = values();

public final Object defaultValue;
public final Class valueClass;
public Object value;
public String description;

Config(String description, Class valueClass, Object value){
Config(String description, Object value){
this.description = description;
this.valueClass = valueClass;
this.defaultValue = value;
this.value = defaultValue;
}
Expand All @@ -43,6 +42,9 @@ public int i(){
public float f(){
return (float)value;
}
public boolean b(){
return (boolean)value;
}
public String s(){
return value.toString();
}
Expand All @@ -59,7 +61,7 @@ public void init(){
AIPlayers.each(p -> {
p.update();
});
if(Mathf.chance(tooltipChance * Time.delta)){
if(!Config.orderRestrict.b() && Mathf.chance(Config.tooltipChance.f() * Time.delta)){
Call.sendMessage("[crimson]<Bot Plugin>: [accent]Consider using the [lightgray]/order []command to command bots!");
}
});
Expand Down Expand Up @@ -110,7 +112,19 @@ public void balancePlayers(){
}

public void registerClientCommands(CommandHandler handler){
handler.<Player>register("order", "<command> [amount] [args]", "Order bots to switch their behavior.", (args, player) -> {
handler.<Player>register("order", "[command] [amount]", "Order bots to switch their behavior.", (args, player) -> {
if(args.length == 0){
StringBuilder s = new StringBuilder("[accent]Available commands:");
AIPlayer.behaviorTypes.each(b -> {
s.append(" " + b);
});
player.sendMessage(s.toString());
return;
}
if(Config.orderRestrict.b() && !player.admin){
player.sendMessage("[scarlet]/order is currently only usable by admins.");
return;
}
String cmd = AIPlayer.behaviorTypes.find(b -> b.equals(args[0]));
if(cmd == null){
StringBuilder s = new StringBuilder("[scarlet]Invalid command. Available commands:");
Expand Down Expand Up @@ -173,10 +187,12 @@ public void registerServerCommands(CommandHandler handler){
c.value = c.defaultValue;
}else{
try{
if(c.valueClass == Integer.class){
if(c.defaultValue instanceof Integer){
c.value = Integer.parseInt(args[1]);
}else{
}else if(c.defaultValue instanceof Float){
c.value = Float.parseFloat(args[1]);
}else{
c.value = Boolean.parseBoolean(args[1]);
}
}catch(NumberFormatException e){
Log.err("Not a valid number: @", args[1]);
Expand Down

0 comments on commit b4d331e

Please sign in to comment.