mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-27 16:09:57 +07:00
Refactoring
This commit is contained in:
parent
b123b8b074
commit
6f3c771d73
@ -25,14 +25,15 @@ public class Mechs implements ContentList{
|
||||
@Override
|
||||
public void load(){
|
||||
|
||||
vanguard = new Mech("vanguard-ship", true){
|
||||
vanguard = new UnitDef("vanguard-ship"){
|
||||
float healRange = 60f;
|
||||
float healReload = 200f;
|
||||
float healPercent = 10f;
|
||||
|
||||
{
|
||||
drillPower = 1;
|
||||
mineSpeed = 4f;
|
||||
flying = true;
|
||||
drillTier = 1;
|
||||
minePower = 4f;
|
||||
speed = 0.49f;
|
||||
drag = 0.09f;
|
||||
health = 200f;
|
||||
@ -82,9 +83,9 @@ public class Mechs implements ContentList{
|
||||
}
|
||||
};
|
||||
|
||||
alpha = new Mech("alpha-mech", false){
|
||||
alpha = new UnitDef("alpha-mech", false){
|
||||
{
|
||||
drillPower = -1;
|
||||
drillTier = -1;
|
||||
speed = 0.5f;
|
||||
boostSpeed = 0.95f;
|
||||
itemCapacity = 15;
|
||||
@ -122,7 +123,7 @@ public class Mechs implements ContentList{
|
||||
|
||||
};
|
||||
|
||||
delta = new Mech("delta-mech", false){
|
||||
delta = new UnitDef("delta-mech", false){
|
||||
{
|
||||
drillPower = 1;
|
||||
mineSpeed = 1.5f;
|
||||
@ -152,7 +153,7 @@ public class Mechs implements ContentList{
|
||||
}
|
||||
};
|
||||
|
||||
tau = new Mech("tau-mech", false){
|
||||
tau = new UnitDef("tau-mech", false){
|
||||
float healRange = 60f;
|
||||
float healAmount = 10f;
|
||||
float healReload = 160f;
|
||||
@ -205,7 +206,7 @@ public class Mechs implements ContentList{
|
||||
}
|
||||
};
|
||||
|
||||
omega = new Mech("omega-mech", false){
|
||||
omega = new UnitDef("omega-mech", false){
|
||||
protected TextureRegion armorRegion;
|
||||
|
||||
{
|
||||
@ -277,12 +278,13 @@ public class Mechs implements ContentList{
|
||||
}
|
||||
};
|
||||
|
||||
dart = new Mech("dart-ship", true){
|
||||
dart = new UnitDef("dart-ship"){
|
||||
float effectRange = 60f;
|
||||
float effectReload = 60f * 5;
|
||||
float effectDuration = 60f * 10f;
|
||||
|
||||
{
|
||||
flying = true;
|
||||
drillPower = 1;
|
||||
mineSpeed = 2f;
|
||||
speed = 0.5f;
|
||||
@ -322,12 +324,13 @@ public class Mechs implements ContentList{
|
||||
}
|
||||
};
|
||||
|
||||
javelin = new Mech("javelin-ship", true){
|
||||
javelin = new UnitDef("javelin-ship"){
|
||||
float minV = 3.6f;
|
||||
float maxV = 6f;
|
||||
TextureRegion shield;
|
||||
|
||||
{
|
||||
flying = true;
|
||||
drillPower = -1;
|
||||
speed = 0.11f;
|
||||
drag = 0.01f;
|
||||
@ -386,8 +389,9 @@ public class Mechs implements ContentList{
|
||||
}
|
||||
};
|
||||
|
||||
trident = new Mech("trident-ship", true){
|
||||
trident = new UnitDef("trident-ship"){
|
||||
{
|
||||
flying = true;
|
||||
drillPower = 2;
|
||||
speed = 0.15f;
|
||||
drag = 0.034f;
|
||||
@ -427,8 +431,9 @@ public class Mechs implements ContentList{
|
||||
}
|
||||
};
|
||||
|
||||
glaive = new Mech("glaive-ship", true){
|
||||
glaive = new UnitDef("glaive-ship"){
|
||||
{
|
||||
flying = true;
|
||||
drillPower = 4;
|
||||
mineSpeed = 1.3f;
|
||||
speed = 0.32f;
|
||||
|
@ -1,10 +1,19 @@
|
||||
package mindustry.entities;
|
||||
|
||||
import arc.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.entities.bullet.*;
|
||||
import mindustry.entities.traits.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
import static mindustry.Vars.net;
|
||||
|
||||
public class Weapons{
|
||||
private static final int[] one = {1};
|
||||
|
||||
@ -17,6 +26,9 @@ public class Weapons{
|
||||
for(WeaponMount mount : mounts){
|
||||
Weapon weapon = mount.weapon;
|
||||
|
||||
for(int i : (weapon.mirror ? Mathf.signs : one)){
|
||||
i *= Mathf.sign(weapon.flipped);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,6 +66,113 @@ public class Weapons{
|
||||
}
|
||||
}
|
||||
|
||||
//region weapon code
|
||||
|
||||
@Remote(targets = Loc.server, called = Loc.both, unreliable = true)
|
||||
public static void onPlayerShootWeapon(Player player, float x, float y, float rotation, boolean left){
|
||||
|
||||
if(player == null) return;
|
||||
//clients do not see their own shoot events: they are simulated completely clientside to prevent laggy visuals
|
||||
//messing with the firerate or any other stats does not affect the server (take that, script kiddies!)
|
||||
if(net.client() && player == Vars.player){
|
||||
return;
|
||||
}
|
||||
|
||||
shootDirect(player, x, y, rotation, left);
|
||||
}
|
||||
|
||||
@Remote(targets = Loc.server, called = Loc.both, unreliable = true)
|
||||
public static void onGenericShootWeapon(ShooterTrait shooter, float x, float y, float rotation, boolean left){
|
||||
if(shooter == null) return;
|
||||
shootDirect(shooter, x, y, rotation, left);
|
||||
}
|
||||
|
||||
public static void shootDirect(ShooterTrait shooter, float offsetX, float offsetY, float rotation, boolean left){
|
||||
float x = shooter.getX() + offsetX;
|
||||
float y = shooter.getY() + offsetY;
|
||||
float baseX = shooter.getX(), baseY = shooter.getY();
|
||||
|
||||
Weapon weapon = shooter.getWeapon();
|
||||
weapon.shootSound.at(x, y, Mathf.random(0.8f, 1.0f));
|
||||
|
||||
sequenceNum = 0;
|
||||
if(weapon.shotDelay > 0.01f){
|
||||
Angles.shotgun(weapon.shots, weapon.spacing, rotation, f -> {
|
||||
Time.run(sequenceNum * weapon.shotDelay, () -> weapon.bullet(shooter, x + shooter.getX() - baseX, y + shooter.getY() - baseY, f + Mathf.range(weapon.inaccuracy)));
|
||||
sequenceNum++;
|
||||
});
|
||||
}else{
|
||||
Angles.shotgun(weapon.shots, weapon.spacing, rotation, f -> weapon.bullet(shooter, x, y, f + Mathf.range(weapon.inaccuracy)));
|
||||
}
|
||||
|
||||
BulletType ammo = weapon.bullet;
|
||||
|
||||
Tmp.v1.trns(rotation + 180f, ammo.recoil);
|
||||
|
||||
shooter.velocity().add(Tmp.v1);
|
||||
|
||||
Tmp.v1.trns(rotation, 3f);
|
||||
boolean parentize = ammo.keepVelocity;
|
||||
|
||||
Effects.shake(weapon.shake, weapon.shake, x, y);
|
||||
Effects.effect(weapon.ejectEffect, x, y, rotation * -Mathf.sign(left));
|
||||
Effects.effect(ammo.shootEffect, x + Tmp.v1.x, y + Tmp.v1.y, rotation, parentize ? shooter : null);
|
||||
Effects.effect(ammo.smokeEffect, x + Tmp.v1.x, y + Tmp.v1.y, rotation, parentize ? shooter : null);
|
||||
|
||||
//reset timer for remote players
|
||||
shooter.getTimer().get(shooter.getShootTimer(left), weapon.reload);
|
||||
}
|
||||
|
||||
public void load(){
|
||||
region = Core.atlas.find(name + "-equip", Core.atlas.find(name, Core.atlas.find("clear")));
|
||||
}
|
||||
|
||||
public void update(ShooterTrait shooter, float pointerX, float pointerY){
|
||||
for(boolean left : Mathf.booleans){
|
||||
Tmp.v1.set(pointerX, pointerY).sub(shooter.getX(), shooter.getY());
|
||||
if(Tmp.v1.len() < minPlayerDist) Tmp.v1.setLength(minPlayerDist);
|
||||
|
||||
float cx = Tmp.v1.x + shooter.getX(), cy = Tmp.v1.y + shooter.getY();
|
||||
|
||||
float ang = Tmp.v1.angle();
|
||||
Tmp.v1.trns(ang - 90, width * Mathf.sign(left), length + Mathf.range(lengthRand));
|
||||
|
||||
update(shooter, shooter.getX() + Tmp.v1.x, shooter.getY() + Tmp.v1.y, Angles.angle(shooter.getX() + Tmp.v1.x, shooter.getY() + Tmp.v1.y, cx, cy), left);
|
||||
}
|
||||
}
|
||||
|
||||
public void update(ShooterTrait shooter, float mountX, float mountY, float angle, boolean left){
|
||||
if(shooter.getTimer().get(shooter.getShootTimer(left), reload)){
|
||||
if(alternate){
|
||||
shooter.getTimer().reset(shooter.getShootTimer(!left), reload / 2f);
|
||||
}
|
||||
|
||||
shoot(shooter, mountX - shooter.getX(), mountY - shooter.getY(), angle, left);
|
||||
}
|
||||
}
|
||||
|
||||
public void shoot(ShooterTrait p, float x, float y, float angle, boolean left){
|
||||
if(net.client()){
|
||||
//call it directly, don't invoke on server
|
||||
shootDirect(p, x, y, angle, left);
|
||||
}else{
|
||||
if(p instanceof Player){ //players need special weapon handling logic
|
||||
Call.onPlayerShootWeapon((Player)p, x, y, angle, left);
|
||||
}else{
|
||||
Call.onGenericShootWeapon(p, x, y, angle, left);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void bullet(ShooterTrait owner, float x, float y, float angle){
|
||||
if(owner == null) return;
|
||||
|
||||
Tmp.v1.trns(angle, 3f);
|
||||
Bullet.create(bullet, owner, owner.getTeam(), x + Tmp.v1.x, y + Tmp.v1.y, angle, (1f - velocityRnd) + Mathf.random(velocityRnd));
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
private static class WeaponMount{
|
||||
/** reload in frames; 0 means ready to fire */
|
||||
float reload;
|
||||
|
@ -79,106 +79,4 @@ public class Weapon{
|
||||
this.name = "";
|
||||
}
|
||||
|
||||
@Remote(targets = Loc.server, called = Loc.both, unreliable = true)
|
||||
public static void onPlayerShootWeapon(Player player, float x, float y, float rotation, boolean left){
|
||||
|
||||
if(player == null) return;
|
||||
//clients do not see their own shoot events: they are simulated completely clientside to prevent laggy visuals
|
||||
//messing with the firerate or any other stats does not affect the server (take that, script kiddies!)
|
||||
if(net.client() && player == Vars.player){
|
||||
return;
|
||||
}
|
||||
|
||||
shootDirect(player, x, y, rotation, left);
|
||||
}
|
||||
|
||||
@Remote(targets = Loc.server, called = Loc.both, unreliable = true)
|
||||
public static void onGenericShootWeapon(ShooterTrait shooter, float x, float y, float rotation, boolean left){
|
||||
if(shooter == null) return;
|
||||
shootDirect(shooter, x, y, rotation, left);
|
||||
}
|
||||
|
||||
public static void shootDirect(ShooterTrait shooter, float offsetX, float offsetY, float rotation, boolean left){
|
||||
float x = shooter.getX() + offsetX;
|
||||
float y = shooter.getY() + offsetY;
|
||||
float baseX = shooter.getX(), baseY = shooter.getY();
|
||||
|
||||
Weapon weapon = shooter.getWeapon();
|
||||
weapon.shootSound.at(x, y, Mathf.random(0.8f, 1.0f));
|
||||
|
||||
sequenceNum = 0;
|
||||
if(weapon.shotDelay > 0.01f){
|
||||
Angles.shotgun(weapon.shots, weapon.spacing, rotation, f -> {
|
||||
Time.run(sequenceNum * weapon.shotDelay, () -> weapon.bullet(shooter, x + shooter.getX() - baseX, y + shooter.getY() - baseY, f + Mathf.range(weapon.inaccuracy)));
|
||||
sequenceNum++;
|
||||
});
|
||||
}else{
|
||||
Angles.shotgun(weapon.shots, weapon.spacing, rotation, f -> weapon.bullet(shooter, x, y, f + Mathf.range(weapon.inaccuracy)));
|
||||
}
|
||||
|
||||
BulletType ammo = weapon.bullet;
|
||||
|
||||
Tmp.v1.trns(rotation + 180f, ammo.recoil);
|
||||
|
||||
shooter.velocity().add(Tmp.v1);
|
||||
|
||||
Tmp.v1.trns(rotation, 3f);
|
||||
boolean parentize = ammo.keepVelocity;
|
||||
|
||||
Effects.shake(weapon.shake, weapon.shake, x, y);
|
||||
Effects.effect(weapon.ejectEffect, x, y, rotation * -Mathf.sign(left));
|
||||
Effects.effect(ammo.shootEffect, x + Tmp.v1.x, y + Tmp.v1.y, rotation, parentize ? shooter : null);
|
||||
Effects.effect(ammo.smokeEffect, x + Tmp.v1.x, y + Tmp.v1.y, rotation, parentize ? shooter : null);
|
||||
|
||||
//reset timer for remote players
|
||||
shooter.getTimer().get(shooter.getShootTimer(left), weapon.reload);
|
||||
}
|
||||
|
||||
public void load(){
|
||||
region = Core.atlas.find(name + "-equip", Core.atlas.find(name, Core.atlas.find("clear")));
|
||||
}
|
||||
|
||||
public void update(ShooterTrait shooter, float pointerX, float pointerY){
|
||||
for(boolean left : Mathf.booleans){
|
||||
Tmp.v1.set(pointerX, pointerY).sub(shooter.getX(), shooter.getY());
|
||||
if(Tmp.v1.len() < minPlayerDist) Tmp.v1.setLength(minPlayerDist);
|
||||
|
||||
float cx = Tmp.v1.x + shooter.getX(), cy = Tmp.v1.y + shooter.getY();
|
||||
|
||||
float ang = Tmp.v1.angle();
|
||||
Tmp.v1.trns(ang - 90, width * Mathf.sign(left), length + Mathf.range(lengthRand));
|
||||
|
||||
update(shooter, shooter.getX() + Tmp.v1.x, shooter.getY() + Tmp.v1.y, Angles.angle(shooter.getX() + Tmp.v1.x, shooter.getY() + Tmp.v1.y, cx, cy), left);
|
||||
}
|
||||
}
|
||||
|
||||
public void update(ShooterTrait shooter, float mountX, float mountY, float angle, boolean left){
|
||||
if(shooter.getTimer().get(shooter.getShootTimer(left), reload)){
|
||||
if(alternate){
|
||||
shooter.getTimer().reset(shooter.getShootTimer(!left), reload / 2f);
|
||||
}
|
||||
|
||||
shoot(shooter, mountX - shooter.getX(), mountY - shooter.getY(), angle, left);
|
||||
}
|
||||
}
|
||||
|
||||
public void shoot(ShooterTrait p, float x, float y, float angle, boolean left){
|
||||
if(net.client()){
|
||||
//call it directly, don't invoke on server
|
||||
shootDirect(p, x, y, angle, left);
|
||||
}else{
|
||||
if(p instanceof Player){ //players need special weapon handling logic
|
||||
Call.onPlayerShootWeapon((Player)p, x, y, angle, left);
|
||||
}else{
|
||||
Call.onGenericShootWeapon(p, x, y, angle, left);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void bullet(ShooterTrait owner, float x, float y, float angle){
|
||||
if(owner == null) return;
|
||||
|
||||
Tmp.v1.trns(angle, 3f);
|
||||
Bullet.create(bullet, owner, owner.getTeam(), x + Tmp.v1.x, y + Tmp.v1.y, angle, (1f - velocityRnd) + Mathf.random(velocityRnd));
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
org.gradle.daemon=true
|
||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||
archash=11d33aef8794244f82660be12c36a5c565fedd4e
|
||||
archash=94aea8c1999b603635b690635488219cea8c6e33
|
||||
|
Loading…
Reference in New Issue
Block a user