Skip to content

Commit 7019447

Browse files
authored
Add files via upload
1 parent 4263807 commit 7019447

File tree

3 files changed

+54
-30
lines changed

3 files changed

+54
-30
lines changed

src/routerSnakeMod/routerSnake.java

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public routerSnake(float x, float y, boolean canDecay, int length){
4040

4141
public void update(){
4242
i += Time.delta;
43-
if(i > 10f){
43+
if(i > routerSnakeMod.snakeUpdateDelay){
4444
if(length < 1){
4545
routerSnakeMod.snakes.remove(this);
4646
return;
@@ -63,63 +63,62 @@ public void update(){
6363
};
6464
if(y > routerSnakeMod.worldHeight){
6565
heading = 270f;
66-
}else if(y < 0){
66+
}else if(y < 0f){
6767
heading = 90f;
6868
};
69-
heading += Mathf.random(-18f, 18f);
70-
x += Mathf.cosDeg(heading) * 10f;
71-
y += Mathf.sinDeg(heading) * 10f;
72-
if(Mathf.chance(0.008f) && Groups.player.size() > 0){
69+
heading += Mathf.random(-routerSnakeMod.snakeHeadingRnd, routerSnakeMod.snakeHeadingRnd);
70+
x += Mathf.cosDeg(heading) * routerSnakeMod.snakeSegLength;
71+
y += Mathf.sinDeg(heading) * routerSnakeMod.snakeSegLength;
72+
if(Mathf.chance(routerSnakeMod.snakeLockOnChc) && Groups.player.size() > 0){
7373
target = Groups.player.index(Mathf.random(Groups.player.size() - 1));
74-
} else if(Mathf.chance(0.008f)){
74+
}else if(Mathf.chance(routerSnakeMod.snakeLockOffChc)){
7575
target = null;
7676
};
77-
if((length > 12 || canDecay) && Mathf.chance(0.0005f * Math.max((float)length, 10))){
77+
if((length > routerSnakeMod.minPermSnakeSize || canDecay) && Mathf.chance(routerSnakeMod.snakeDecayRate * Math.max((float)length, routerSnakeMod.minPermSnakeSize))){
7878
length--;
7979
segments.remove(0);
8080
};
81-
if(target != null && target.unit().type != null){
82-
heading = Mathf.slerp(heading, Mathf.angle(target.x - x, target.y - y), 0.25f);
83-
if(Mathf.len(target.x - x, target.y - y) < 80f){
84-
target.unit().heal((target.unit().maxHealth / 1000f + 10f) * (float)length / 12f);
81+
if(target != null && !target.unit().isNull()){
82+
heading = Mathf.slerp(heading, Mathf.angle(target.x - x, target.y - y), routerSnakeMod.snakeChaseRate);
83+
if(Mathf.len(target.x - x, target.y - y) < routerSnakeMod.snakeHealRange){
84+
target.unit().heal((target.unit().maxHealth / 10000f + 1f) * (float)length * routerSnakeMod.snakeUnHealRate);
8585
};
8686
};
8787
segments.each(s -> {
8888
float segX = s[0];
8989
float segY = s[1];
90-
Tile newTile = world.tile(Mathf.floor(segX / 8), Mathf.floor(segY / 8));
90+
Tile newTile = world.tile(Mathf.floor(segX / tilesize), Mathf.floor(segY / tilesize));
9191
if(newTile != null && newTile.build != null){
9292
Building newBuild = newTile.build;
9393
if(newBuild.block != Blocks.distributor){
94-
newBuild.heal(1f / 100f * newBuild.maxHealth());
94+
newBuild.heal(routerSnakeMod.snakeBlHealRate / 100f * newBuild.maxHealth());
9595
};
9696
};
9797
});
98-
Tile newTile = world.tile(Mathf.floor(x / 8), Mathf.floor(y / 8));
98+
Tile newTile = world.tile(Mathf.floor(x / tilesize), Mathf.floor(y / tilesize));
9999
if(newTile != null && newTile.build != null){
100100
Building newBuild = newTile.build;
101101
if(newBuild.block == Blocks.distributor){
102-
newBuild.damage(Math.min(40f * (float)length / 12f, 79f));
103-
x -= Mathf.cosDeg(heading) * 10f;
104-
y -= Mathf.sinDeg(heading) * 10f;
102+
newBuild.damage(Math.min(routerSnakeMod.baseDistributorDmg * (float)length / routerSnakeMod.minPermSnakeSize, routerSnakeMod.maxDistributorDmg));
103+
x -= Mathf.cosDeg(heading) * routerSnakeMod.snakeSegLength;
104+
y -= Mathf.sinDeg(heading) * routerSnakeMod.snakeSegLength;
105105
heading = Mathf.angle(x - newBuild.x, y - newBuild.y);
106-
if(Mathf.chance(0.02f * length)){
106+
if(Mathf.chance(routerSnakeMod.distributorGrowChc * length)){
107107
length++;
108108
segments.add(new float[]{x, y});
109109
};
110-
}else if(newBuild.block == Blocks.router && Mathf.chance((length < 10 && length != 0) ? 0.5f / length : 0.05f)){
111-
if(Mathf.chance(0.01f * length)){
110+
}else if(newBuild.block == Blocks.router && Mathf.chance(routerSnakeMod.baseConsumeChc * Math.max(routerSnakeMod.minPermSnakeSize / length, 1f))){
111+
if(Mathf.chance(routerSnakeMod.baseSplitChc * length)){
112112
routerSnakeMod.snakes.add(new routerSnake(x, y, true, length / 2));
113-
length = canDecay ? length / 2 : Math.max(length / 2, 12);
113+
length = canDecay ? length / 2 : Math.max(length / 2, routerSnakeMod.minPermSnakeSize);
114114
while(segments.size > length){
115115
segments.remove(0);
116116
};
117-
newBuild.damage(19);
118117
}else{
119118
length++;
120119
segments.add(new float[]{x, y});
121-
newBuild.damage(19);
122120
};
121+
newBuild.damage(routerSnakeMod.baseRouterDmg);
123122
};
124123
};
125124
i -= 10f;

src/routerSnakeMod/routerSnakeMod.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,39 @@ public class routerSnakeMod extends Plugin{
2424
public static String rout = Character.toString(Iconc.blockRouter);
2525
public static Seq<routerSnake> snakes = new Seq<>();
2626

27+
// snake vars
28+
public static float snakeUpdateDelay = 10f;
29+
public static float snakeHeadingRnd = 18f;
30+
public static float snakeLockOnChc = 0.008f;
31+
public static float snakeLockOffChc = 0.008f;
32+
public static int minPermSnakeSize = 12;
33+
public static float snakeSegLength = 10f;
34+
public static float snakeDecayRate = 0.0005f;
35+
public static float snakeChaseRate = 0.25f;
36+
public static float snakeHealRange = 80f;
37+
public static float snakeUnHealRate = 1f;
38+
public static float snakeBlHealRate = 1f;
39+
public static float baseDistributorDmg = 40f;
40+
public static float maxDistributorDmg = 79f;
41+
public static float distributorGrowChc = 0.02f;
42+
public static float baseRouterDmg = 19f;
43+
public static float baseConsumeChc = 0.05f;
44+
public static float baseSplitChc = 0.01f;
45+
46+
// general vars
47+
public static float snakeCountDiv = 2000f;
48+
private static int maxSpawnedLength = 100;
49+
2750
@Override
2851
public void init(){
2952
Log.info("Router Snake has awoken!");
3053
Events.on(WorldLoadEvent.class, e -> {
3154
snakes.clear();
32-
worldHeight = world.height() * 8;
33-
worldWidth = world.width() * 8;
55+
worldHeight = world.height() * tilesize;
56+
worldWidth = world.width() * tilesize;
3457
float snakeScl = Mathf.len(worldWidth, worldHeight);
35-
for(int i = 0; i < snakeScl; i += 2000){
36-
snakes.add(new routerSnake(0f, 0f, false, 12));
58+
for(float i = 0f; i < snakeScl; i += snakeCountDiv){
59+
snakes.add(new routerSnake(0f, 0f, false, minPermSnakeSize));
3760
};
3861
snakes.each(s -> {
3962
s.x = Mathf.random(worldWidth);
@@ -47,12 +70,12 @@ public void init(){
4770
public void registerClientCommands(CommandHandler handler){
4871
handler.<Player>register("spawnsnake", "<x> <y> <canDie> <length>", "Spawn a router snake.", (args, player) -> {
4972
try{
50-
if(Integer.parseInt(args[3]) > 100 || Integer.parseInt(args[3]) < 1){
73+
if(Integer.parseInt(args[3]) > maxSpawnedLength || Integer.parseInt(args[3]) < 1){
5174
player.sendMessage("The specified length is invalid.");
5275
}else if(!player.admin){
5376
player.sendMessage("You need to be admin to spawn snakes.");
5477
}else{
55-
snakes.add(new routerSnake(Float.parseFloat(args[0]) * 8f, Float.parseFloat(args[1]) * 8f, Boolean.parseBoolean(args[2]), Integer.parseInt(args[3])));
78+
snakes.add(new routerSnake(Float.parseFloat(args[0]) * tilesize, Float.parseFloat(args[1]) * tilesize, Boolean.parseBoolean(args[2]), Integer.parseInt(args[3])));
5679
};
5780
}catch(Exception badArguments){
5881
player.sendMessage("Invalid arguments.");

trybuild.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
gradlew build
2+
pause

0 commit comments

Comments
 (0)