Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya246 authored Jun 24, 2021
1 parent bc3c267 commit 0397ede
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/routerSnakeMod/routerSnake.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public routerSnake(float x, float y, boolean canDecay, int length){
this.y = y;
this.canDecay = canDecay;
this.length = length;
for(int it = 0; it < 12; it++){
for(int it = 0; it < length; it++){
segments.add(new float[]{0f, 0f});
};
}
Expand Down Expand Up @@ -66,7 +66,7 @@ public void update(){
if(Mathf.chance(0.008f)){
target = null;
};
if((length > 12 || canDecay) && Mathf.chance(0.0003f * Math.max((float)length, 5))){
if((length > 12 || canDecay) && Mathf.chance(0.0005f * Math.max((float)length, 10))){
if(length == 1){
routerSnakeMod.snakes.remove(this);
}else{
Expand Down Expand Up @@ -99,10 +99,13 @@ public void update(){
x -= Mathf.cosDeg(heading) * 10f;
y -= Mathf.sinDeg(heading) * 10f;
heading = Mathf.angle(x - newBuild.x, y - newBuild.y);
}else if(newBuild.block == Blocks.router && Mathf.chance(0.004f * Math.max(length, 12))){
}else if(newBuild.block == Blocks.router && Mathf.chance((length < 10 && length != 0) ? 0.5f / length : 0.05f)){
if(Mathf.chance(0.005f * length)){
routerSnakeMod.snakes.add(new routerSnake(x, y, true, length / 2));
length = canDecay ? length / 2 : Math.max(length / 2, 12);
while(segments.size > length){
segments.remove(0);
};
newBuild.kill();
}else{
length++;
Expand Down
16 changes: 16 additions & 0 deletions src/routerSnakeMod/routerSnakeMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import arc.util.*;
import arc.util.Log;
import arc.struct.Seq;
import mindustry.mod.*;
import routerSnake.*;

import static mindustry.Vars.*;
Expand Down Expand Up @@ -43,4 +44,19 @@ public void init(){
snakes.each(s -> s.update());
});
}
public void registerClientCommands(CommandHandler handler){
handler.<Player>register("spawnsnake", "<x> <y> <canDie> <length>", "Spawn a router snake.", (args, player) -> {
try{
if(Integer.parseInt(args[3]) > 100){
player.sendMessage("The specified length is too long.");
}else if(!player.admin){
player.sendMessage("You need to be admin to spawn snakes.");
}else{
snakes.add(new routerSnake(Float.parseFloat(args[0]) * 8f, Float.parseFloat(args[1]) * 8f, Boolean.parseBoolean(args[2]), Integer.parseInt(args[3])));
};
}catch(Exception badArguments){
player.sendMessage("Invalid arguments.");
};
});
}
}

0 comments on commit 0397ede

Please sign in to comment.