Skip to content

Commit

Permalink
Random mess GO
Browse files Browse the repository at this point in the history
Pls help me rushie
  • Loading branch information
Otamamori917 committed Aug 31, 2024
1 parent 1c756d4 commit 209dca7
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 50 deletions.
1 change: 1 addition & 0 deletions src/axthrix/AxthrixLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void loadContent(){
Log.info("Loading Axthrix content");
StackWorldState.load();
MountWorldState.load();
DroneWorldState.load();
AxFactions.load();
AxStats.load();
//AxItems.load();
Expand Down
64 changes: 64 additions & 0 deletions src/axthrix/content/units/AxthrixUnits.java
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,18 @@ public static void load(){
endY = 5;
drone = AxthrixDrones.wattGround;
}});
parts.add(
new RegionPart("-axis"){{
progress = PartProgress.warmup;
heatColor = Pal.heal;
mirror = false;
under = false;
moveX = moveY = 0f;
heatProgress = p -> Mathf.cos(Time.time / 10) / 2 + 0.5f;
y = -3.5f;
moves.add(new PartMove(p ->( Mathf.cos(Time.time) / 2 + 0.5f), 0, 0, 360f));
}}
);
weapons.add(new Weapon("puw"){{
shootSound = Sounds.sap;
shootY = 2f;
Expand Down Expand Up @@ -1432,6 +1444,19 @@ public static void load(){
whenShooting = false;
}});

parts.add(
new RegionPart("-axis"){{
progress = PartProgress.warmup;
heatColor = Pal.heal;
mirror = false;
under = false;
moveX = moveY = 0f;
heatProgress = p -> Mathf.cos(Time.time / 10) / 2 + 0.5f;
y = -3.5f;
moves.add(new PartMove(p ->( Mathf.cos(Time.time) / 2 + 0.5f), 0, 0, 360f));
}}
);

weapons.add(new Weapon("aj-nano-launcher"){{
shootSound = Sounds.blaster;
shootWarmupSpeed = 0.06f;
Expand Down Expand Up @@ -1558,6 +1583,19 @@ public static void load(){
onShoot = true;
}});

parts.add(
new RegionPart("-axis"){{
progress = PartProgress.warmup;
heatColor = Pal.heal;
mirror = false;
under = false;
moveX = moveY = 0f;
heatProgress = p -> Mathf.cos(Time.time / 10) / 2 + 0.5f;
y = -3.5f;
moves.add(new PartMove(p ->( Mathf.cos(Time.time) / 2 + 0.5f), 0, 0, 360f));
}}
);

weapons.add(new Weapon("aj-recursor"){{
shootSound = Sounds.shockBlast;
shootWarmupSpeed = 0.06f;
Expand Down Expand Up @@ -1663,6 +1701,19 @@ public static void load(){
onShoot = true;
}});

parts.add(
new RegionPart("-axis"){{
progress = PartProgress.warmup;
heatColor = Pal.heal;
mirror = false;
under = false;
moveX = moveY = 0f;
heatProgress = p -> Mathf.cos(Time.time / 10) / 2 + 0.5f;
y = -3.5f;
moves.add(new PartMove(p ->( Mathf.cos(Time.time) / 2 + 0.5f), 0, 0, 360f));
}}
);

weapons.add(new Weapon("aj-hammer-shotgun"){{
shootSound = Sounds.shockBlast;
shootWarmupSpeed = 0.06f;
Expand Down Expand Up @@ -1851,6 +1902,19 @@ public static void load(){
onShoot = true;
}});

parts.add(
new RegionPart("-axis"){{
progress = PartProgress.warmup;
heatColor = Pal.heal;
mirror = false;
under = false;
moveX = moveY = 0f;
heatProgress = p -> Mathf.cos(Time.time / 10) / 2 + 0.5f;
y = -3.5f;
moves.add(new PartMove(p ->( Mathf.cos(Time.time) / 2 + 0.5f), 0, 0, 360f));
}}
);

parts.add(
new RegionPart("-mount-l"){{
progress = PartProgress.warmup;
Expand Down
47 changes: 24 additions & 23 deletions src/axthrix/world/types/abilities/DroneSpawnAbility.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import mindustry.entities.Units;
import mindustry.entities.abilities.Ability;
import mindustry.entities.part.DrawPart;
import mindustry.entities.part.RegionPart;
import mindustry.game.EventType;
import mindustry.gen.Building;
import mindustry.gen.Unit;
Expand All @@ -26,15 +27,16 @@
import mindustry.world.meta.Stat;
import mindustry.world.meta.StatUnit;

import java.util.HashMap;

public class DroneSpawnAbility extends Ability {
public UnitType drone;
public float spawnTime = 60.0F;
public Effect spawnEffect;
public boolean parentizeEffects;
public HashMap<Unit, Boolean> unitAlive = new HashMap<>();
public HashMap<Unit, Unit> aliveUnit = new HashMap<>();
protected float timer;
protected transient float droneProg;

public transient Seq<Unit> units = new Seq<>();
public float startAng = 0f;
public float endAng = 0f;
public float startX = 0f;
Expand All @@ -53,10 +55,6 @@ public DroneSpawnAbility(UnitType unit, float spawnTime, float spawnX, float spa
public DroneSpawnAbility() {
spawnEffect = Fx.spawn;
}
@Nullable
public Unit canReplace() {
return units.find(u -> u.dead());
}

public void addStats(Table t) {
t.add("[lightgray]" + Stat.buildTime.localized() + ": [white]" + Strings.autoFixed(spawnTime / 60.0F, 2) + " " + StatUnit.seconds.localized());
Expand All @@ -65,51 +63,54 @@ public void addStats(Table t) {
}

public void update(Unit unit) {
if (!aliveUnit.containsKey(unit)){
aliveUnit.put(unit,null);
}
if (!unitAlive.containsKey(unit)){
unitAlive.put(unit,false);
}

if (drone instanceof DroneUnitType du){
du.tetherUnit = unit;
du.tetherUnitID = unit.id;
}
if(aliveUnit.get(unit) == null){
unitAlive.replace(unit,false);
}
timer += Time.delta * Vars.state.rules.unitBuildSpeed(unit.team);
if (timer >= spawnTime && Units.canCreate(unit.team, drone) && canReplace() == null) {
if (timer >= spawnTime && Units.canCreate(unit.team, drone) && !unitAlive.get(unit)) {

spawnEffect.at(Mathf.lerp(unit.x+startX,unit.x+endX,ShootProg(unit)), Mathf.lerp(unit.y+startY,unit.y+endY,ShootProg(unit)), 0.0F, parentizeEffects ? unit : null);
Unit u = drone.create(unit.team);
u.set(Mathf.lerp(unit.x+startX,unit.x+endX,ShootProg(unit)), Mathf.lerp(unit.y+startY,unit.y+endY,ShootProg(unit)));
u.rotation = unit.rotation + Mathf.lerp(startAng,endAng,ShootProg(unit));
if (units.size != 0) {
units.replace(canReplace(), u);
} else {
units.add(u);
}
if (u.type instanceof DroneUnitType du) du.tetherUnit = unit;
Events.fire(new EventType.UnitCreateEvent(u, (Building)null, unit));
unitAlive.replace(unit,true);
aliveUnit.put(unit,u);
if (!Vars.net.client()) {
u.add();
}

timer = 0.0F;
}

}

public void draw(Unit unit) {
if (Units.canCreate(unit.team, drone)) {
if (Units.canCreate(unit.team, drone) && !unitAlive.get(unit)) {
Draw.draw(Draw.z(), () -> {
Drawf.construct(Mathf.lerp(unit.x+startX,unit.x+endX,ShootProg(unit)), Mathf.lerp(unit.y+startY,unit.y+endY,ShootProg(unit)), drone.fullIcon, (unit.rotation-90.0F)+Mathf.lerp(startAng,endAng,ShootProg(unit)), timer / spawnTime, 1.0F, timer);
});
}

}
public float ShootProg(Unit unit){
if(unit.isShooting() && droneProg != 1){
droneProg += 0.1f;
} else if (!unit.isShooting() && droneProg != 0) {
droneProg =- 0.1f;
if(unit.type.parts.first() instanceof RegionPart rp) {
return rp.progress.get(DrawPart.params);
}
return droneProg;
return 0f;
}

public String localized() {
return Core.bundle.format("ability.unitspawn", new Object[]{drone.localizedName});
return Core.bundle.format("ability.dronespawn", new Object[]{drone.localizedName});
}
}

34 changes: 18 additions & 16 deletions src/axthrix/world/types/ai/DroneAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,38 @@

public class DroneAI extends AIController {
public float getRotation() {
if (!(unit.type instanceof DroneUnitType u) || !(u.tetherUnit.type.abilities.peek() instanceof DroneSpawnAbility abl)) return 0f;
if (u.tetherUnit.mounts().length > 0) {
WeaponMount first = u.tetherUnit.mounts()[0];
DrawPart.params.set(first.warmup, first.reload / u.tetherUnit.type().weapons.first().reload, first.smoothReload, first.heat, first.recoil, first.charge, u.tetherUnit.x(), u.tetherUnit.y(), u.tetherUnit.rotation());
if (!(unit.type instanceof DroneUnitType u) || !(u.tetherUnit.get(unit).type.abilities.peek() instanceof DroneSpawnAbility abl)) return 0f;
if (u.tetherUnit.get(unit).mounts().length > 0) {
WeaponMount first = u.tetherUnit.get(unit).mounts()[0];
DrawPart.params.set(first.warmup, first.reload / u.tetherUnit.get(unit).type().weapons.first().reload, first.smoothReload, first.heat, first.recoil, first.charge, u.tetherUnit.get(unit).x(), u.tetherUnit.get(unit).y(), u.tetherUnit.get(unit).rotation());
} else {
DrawPart.params.set(0, 0, 0, 0, 0, 0, u.tetherUnit.x(), u.tetherUnit.y(), u.tetherUnit.rotation());
DrawPart.params.set(0, 0, 0, 0, 0, 0, u.tetherUnit.get(unit).x(), u.tetherUnit.get(unit).y(), u.tetherUnit.get(unit).rotation());
}
return Mathf.lerp(
u.tetherUnit.rotation + abl.startAng,
u.tetherUnit.rotation + abl.endAng,
abl.ShootProg(u.tetherUnit)
u.tetherUnit.get(unit).rotation + abl.startAng,
u.tetherUnit.get(unit).rotation + abl.endAng,
abl.ShootProg(u.tetherUnit.get(unit))
);
}

@Override
public void updateMovement() {
if ( (unit.type instanceof DroneUnitType u) && (u.tetherUnit.type.abilities.peek() instanceof DroneSpawnAbility abl)) {
unit.set(Tmp.v1.add(Mathf.lerp(u.tetherUnit.x+abl.startX,u.tetherUnit.x+abl.endX,abl.ShootProg(u.tetherUnit)),Mathf.lerp(u.tetherUnit.y+abl.startY,u.tetherUnit.y+abl.endY,abl.ShootProg(u.tetherUnit))));
unit.rotation(getRotation());
if ((unit.type instanceof DroneUnitType u) && u.tetherUnit.get(unit) != null) {
if (u.tetherUnit.get(unit).type.abilities.peek() instanceof DroneSpawnAbility abl) {
unit.set(Tmp.v1.add(Mathf.lerp(u.tetherUnit.get(unit).x+abl.startX,u.tetherUnit.get(unit).x+abl.endX,abl.ShootProg(u.tetherUnit.get(unit))),Mathf.lerp(u.tetherUnit.get(unit).y+abl.startY,u.tetherUnit.get(unit).y+abl.endY,abl.ShootProg(u.tetherUnit.get(unit)))));
unit.rotation(getRotation());
}
}
}

public void updateWeapons(){
if((unit.type instanceof DroneUnitType u) && u.tetherUnit != null && !u.tetherUnit.dead && unit.type.canAttack){
if((unit.type instanceof DroneUnitType u) && u.tetherUnit.get(unit) != null && !u.tetherUnit.get(unit).dead && unit.type.canAttack){

Vec2 aimVec = Predict.intercept(vec , new Vec2(u.tetherUnit.aimX, u.tetherUnit.aimY), unit.type.weapons.first().bullet.speed);
if(!u.tetherUnit.isShooting) aimVec = Predict.intercept(vec, unit, unit.speed());
Vec2 aimVec = Predict.intercept(vec , new Vec2(u.tetherUnit.get(unit).aimX, u.tetherUnit.get(unit).aimY), unit.type.weapons.first().bullet.speed);
if(!u.tetherUnit.get(unit).isShooting) aimVec = Predict.intercept(vec, unit, unit.speed());
/*I don't know which one worked so have all of them*/
unit.aimLook(aimVec); unit.lookAt(aimVec); unit.aim(aimVec);
unit.isShooting = u.tetherUnit.isShooting();
unit.isShooting = u.tetherUnit.get(unit).isShooting();

for(var mount : unit.mounts) {
Weapon weapon = mount.weapon;
Expand All @@ -59,7 +61,7 @@ public void updateWeapons(){
Vec2 to = Predict.intercept(vec, aimVec, weapon.bullet.speed);
mount.aimX = to.x;
mount.aimY = to.y;
mount.shoot = u.tetherUnit.isShooting;
mount.shoot = u.tetherUnit.get(unit).isShooting;
}
} else{
super.updateWeapons();
Expand Down
27 changes: 16 additions & 11 deletions src/axthrix/world/types/unittypes/DroneUnitType.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,36 @@
import arc.util.*;
import arc.util.io.Reads;
import arc.util.io.Writes;
import axthrix.world.types.abilities.DroneSpawnAbility;
import mindustry.gen.*;

import java.util.HashMap;

public class DroneUnitType extends AmmoLifeTimeUnitType {
public transient @Nullable Unit tetherUnit;


public HashMap<Unit, Unit> tetherUnit = new HashMap<>();
public int tetherUnitID = -1;
public DroneUnitType(String name){
super(name);
}

@Override
public void update(Unit unit){
if (!tetherUnit.containsKey(unit)){
tetherUnit.put(unit,null);
}
if (tetherUnitID != -1) {
tetherUnit = Groups.unit.getByID(tetherUnitID);
tetherUnit.replace(unit, Groups.unit.getByID(tetherUnitID));
tetherUnitID = -1;
}
if(tetherUnit == null || !tetherUnit.isValid() || tetherUnit.team != unit.team){
if(tetherUnit.get(unit) == null || !tetherUnit.get(unit).isValid() || tetherUnit.get(unit).team != unit.team){
Call.unitDespawn(unit.self());
if(tetherUnit.get(unit) != null) {
if(tetherUnit.get(unit).type.abilities.peek() instanceof DroneSpawnAbility abl){
abl.unitAlive.replace(tetherUnit.get(unit),false);
}
}
}
}

public void read(Reads read) {
tetherUnitID = read.i();
}

public void write(Writes write) {
write.i(tetherUnit.id);
}
}
Loading

0 comments on commit 209dca7

Please sign in to comment.