Skip to content

Commit

Permalink
feat: revive auto shooter
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharlottes committed Aug 27, 2023
1 parent 1a96c5b commit 12568bd
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 5 deletions.
4 changes: 2 additions & 2 deletions assets/bundles/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ setting.unitItem.name = enable Unit Item
setting.unitItem.description = display item amount under each unit
setting.unitBar.name = enable Unit Bar
setting.unitBar.description = display health bar under each unit
setting.autoShoot.name = Enable Auto Shooting
setting.autoShoot.description = no don't do hack

setting.spawnerarrow.name = Indicate Wave Spawn-Point
setting.spawnerarrow.description = Displays arrow pointing to wave spawn-points.
Expand Down Expand Up @@ -118,6 +116,8 @@ setting.fogremover.name = Fog Remover
setting.fogremover.description = remove every fog in the world!
setting.camerascaler.name = Camera Scaler
setting.camerascaler.description = set camera zoom scale to maximum.
setting.autoShoot.name = Enable Auto Shooting
setting.autoShoot.description = no don't do hack

#Other
default-bar = default bar
Expand Down
4 changes: 2 additions & 2 deletions assets/bundles/bundle_ko.properties
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ setting.unitItem.name = 유닛 아이템 표시
setting.unitItem.description = 유닛이 들고 있는 아이템의 수량을 표시합니다.
setting.unitBar.name = 유닛 바 표시
setting.unitBar.description = 각 유닛의 체력, 탄약, 방어막, 상태이상, 화물에 대해서 간략하게 표시합니다.
setting.autoShoot.name = 자동 사격 활성화
setting.autoShoot.description = 데스크톱에서 모바일의 자동 사격을 사용할 수 있게 됩니다.

setting.spawnerarrow.name = 스폰포인트 화살표
setting.spawnerarrow.description = 적 단계 생성 지점을 가리키는 화살표를 표시합니다.
Expand Down Expand Up @@ -118,6 +116,8 @@ setting.fogremover.name = 안개 제거하기
setting.fogremover.description = 맵에 있는 모든 안개를 제거합니다!!
setting.camerascaler.name = 카메라 스케일러
setting.camerascaler.description = 카메라 줌을 최대치까지 높힙니다.
setting.autoShoot.name = 자동 사격 활성화
setting.autoShoot.description = 데스크톱에서 모바일의 자동 사격을 사용할 수 있게 됩니다.

#Other
default-bar = 기본 바
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package informatis.ui.fragments.sidebar.windows.tools.tools;
import arc.input.KeyCode;
import arc.math.Angles;
import arc.math.geom.Geometry;
import mindustry.entities.Units;
import mindustry.game.Team;
import mindustry.gen.*;
import mindustry.logic.Ranged;
import mindustry.world.blocks.ControlBlock;
import mindustry.world.blocks.defense.turrets.Turret;
import static arc.Core.*;
import static mindustry.Vars.*;

public class AutoShooter extends Tool {
Teamc shotTarget;
public AutoShooter() {
super("autoShoot");
}

@Override
public void onUpdate() {
Unit unit = player.unit();
if (unit.type == null) return;
boolean omni = unit.type.omniMovement;
boolean validHealTarget = unit.type.canHeal && shotTarget instanceof Building b && b.isValid() && b.damaged() && shotTarget.team() == unit.team && shotTarget.within(unit, unit.type.range);
boolean boosted = (unit instanceof Mechc && unit.isFlying());
if ((unit.type != null && Units.invalidateTarget(shotTarget, unit, unit.type.range) && !validHealTarget) || state.isEditor()) {
shotTarget = null;
}
float mouseAngle = unit.angleTo(unit.aimX(), unit.aimY());
boolean aimCursor = omni && player.shooting && unit.type.hasWeapons() && unit.type.faceTarget && !boosted && unit.type.rotateToBuilding;
unit.lookAt(aimCursor ? mouseAngle : unit.prefRotation());
//update shooting if not building + not mining
if(!player.unit().activelyBuilding() && player.unit().mineTile == null) {
if(input.keyDown(KeyCode.mouseLeft)) {
player.shooting = !boosted;
unit.aim(player.mouseX = input.mouseWorldX(), player.mouseY = input.mouseWorldY());
} else if(shotTarget == null) {
player.shooting = false;
if(unit instanceof BlockUnitUnit b) {
if(b.tile() instanceof ControlBlock c && !c.shouldAutoTarget()) {
Building build = b.tile();
float range = build instanceof Ranged ? ((Ranged) build).range() : 0f;
boolean targetGround = build instanceof Turret.TurretBuild && ((Turret) build.block).targetAir;
boolean targetAir = build instanceof Turret.TurretBuild && ((Turret) build.block).targetGround;
shotTarget = Units.closestTarget(build.team, build.x, build.y, range, u -> u.checkTarget(targetAir, targetGround), u -> targetGround);
}
else shotTarget = null;
} else if(unit.type != null) {
float range = unit.hasWeapons() ? unit.range() : 0f;
shotTarget = Units.closestTarget(unit.team, unit.x, unit.y, range, u -> u.checkTarget(unit.type.targetAir, unit.type.targetGround), u -> unit.type.targetGround);
if(unit.type.canHeal && shotTarget == null) {
shotTarget = Geometry.findClosest(unit.x, unit.y, indexer.getDamaged(Team.sharded));
if (shotTarget != null && !unit.within(shotTarget, range)) {
shotTarget = null;
}
}
}
} else {
player.shooting = !boosted;
unit.rotation(Angles.angle(unit.x, unit.y, shotTarget.x(), shotTarget.y()));
unit.aim(shotTarget.x(), shotTarget.y());
}
}
unit.controlWeapons(player.shooting && !boosted);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import mindustry.game.EventType;

public class ToolManager {
public static Tool[] tools = new Tool[] { new FogRemover(), new CameraScaler() };
public static Tool[] tools = new Tool[] { new FogRemover(), new CameraScaler(), new AutoShooter() };

public static void init() {
Events.run(EventType.Trigger.update, () -> {
Expand Down

0 comments on commit 12568bd

Please sign in to comment.