New WIP achievement definitions

This commit is contained in:
Anuken
2022-10-09 17:47:12 -04:00
parent dfdb4c1c1f
commit 4201106843
20 changed files with 419 additions and 26 deletions

View File

@@ -19,6 +19,7 @@ import static mindustry.Vars.*;
/** Utility class for damaging in an area. */
public class Damage{
private static final UnitDamageEvent bulletDamageEvent = new UnitDamageEvent();
private static final Rect rect = new Rect();
private static final Rect hitrect = new Rect();
private static final Vec2 vec = new Vec2(), seg1 = new Vec2(), seg2 = new Vec2();
@@ -467,21 +468,29 @@ public class Damage{
/** Damages all entities and blocks in a radius that are enemies of the team. */
public static void damage(Team team, float x, float y, float radius, float damage, boolean complete, boolean air, boolean ground, boolean scaled, @Nullable Bullet source){
Cons<Unit> cons = entity -> {
if(entity.team == team || !entity.checkTarget(air, ground) || !entity.hittable() || !entity.within(x, y, radius + (scaled ? entity.hitSize / 2f : 0f))){
Cons<Unit> cons = unit -> {
if(unit.team == team || !unit.checkTarget(air, ground) || !unit.hittable() || !unit.within(x, y, radius + (scaled ? unit.hitSize / 2f : 0f))){
return;
}
float amount = calculateDamage(scaled ? Math.max(0, entity.dst(x, y) - entity.type.hitSize/2) : entity.dst(x, y), radius, damage);
entity.damage(amount);
boolean dead = unit.dead;
float amount = calculateDamage(scaled ? Math.max(0, unit.dst(x, y) - unit.type.hitSize/2) : unit.dst(x, y), radius, damage);
unit.damage(amount);
if(source != null){
entity.controller().hit(source);
Events.fire(bulletDamageEvent.set(unit, source));
unit.controller().hit(source);
if(!dead && unit.dead){
Events.fire(new UnitBulletDestroyEvent(unit, source));
}
}
//TODO better velocity displacement
float dst = vec.set(entity.x - x, entity.y - y).len();
entity.vel.add(vec.setLength((1f - dst / radius) * 2f / entity.mass()));
float dst = vec.set(unit.x - x, unit.y - y).len();
unit.vel.add(vec.setLength((1f - dst / radius) * 2f / unit.mass()));
if(complete && damage >= 9999999f && entity.isPlayer()){
if(complete && damage >= 9999999f && unit.isPlayer()){
Events.fire(Trigger.exclusionDeath);
}
};

View File

@@ -15,4 +15,5 @@ class GroupDefs<G>{
@GroupDef(value = Puddlec.class) G puddle;
@GroupDef(value = WeatherStatec.class) G weather;
@GroupDef(value = WorldLabelc.class, mapping = true) G label;
@GroupDef(value = PowerGraphUpdaterc.class) G powerGraph;
}

View File

@@ -22,11 +22,12 @@ import mindustry.graphics.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
import mindustry.world.blocks.defense.Wall.*;
import static mindustry.Vars.*;
public class BulletType extends Content implements Cloneable{
static final UnitDamageEvent bulletDamageEvent = new UnitDamageEvent();
/** Lifetime in ticks. */
public float lifetime = 40f;
/** Speed in units/tick. */
@@ -354,6 +355,8 @@ public class BulletType extends Content implements Cloneable{
}
public void hitEntity(Bullet b, Hitboxc entity, float health){
boolean wasDead = entity instanceof Unit u && u.dead;
if(entity instanceof Healthc h){
if(pierceArmor){
h.damagePierce(b.damage);
@@ -367,11 +370,12 @@ public class BulletType extends Content implements Cloneable{
if(impact) Tmp.v3.setAngle(b.rotation() + (knockback < 0 ? 180f : 0f));
unit.impulse(Tmp.v3);
unit.apply(status, statusDuration);
Events.fire(bulletDamageEvent.set(unit, b));
}
//for achievements
if(b.owner instanceof WallBuild && player != null && b.team == player.team() && entity instanceof Unit unit && unit.dead){
Events.fire(Trigger.phaseDeflectHit);
if(!wasDead && entity instanceof Unit unit && unit.dead){
Events.fire(new UnitBulletDestroyEvent(unit, b));
}
}

View File

@@ -1570,9 +1570,15 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
/** Handle a bullet collision.
* @return whether the bullet should be removed. */
public boolean collision(Bullet other){
boolean wasDead = dead();
damage(other.team, other.damage() * other.type().buildingDamageMultiplier);
Events.fire(bulletDamageEvent.set(self(), other));
if(dead() && !wasDead){
Events.fire(new BuildingBulletDestroyEvent(self(), other));
}
return true;
}