diff --git a/core/src/mindustry/entities/Damage.java b/core/src/mindustry/entities/Damage.java index cab678e5b2..50cce3cf86 100644 --- a/core/src/mindustry/entities/Damage.java +++ b/core/src/mindustry/entities/Damage.java @@ -266,7 +266,7 @@ public class Damage{ World.raycastEachNoDiagonalWorld(x, y, seg2.x, seg2.y, (cx, cy) -> { Building tile = world.build(cx, cy); boolean collide = tile != null && tile.collide(hitter) && hitter.checkUnderBuild(tile, cx * tilesize, cy * tilesize) - && ((tile.team != team && tile.collide(hitter)) || hitter.type.testCollision(hitter, tile)) && collidedBlocks.add(tile.pos()); + && ((tile.team != team && tile.collide(hitter)) || hitter.type.testCollision(hitter, tile)) && collidedBlocks.add(tile.pos()); if(collide){ collided.add(collidePool.obtain().set(cx * tilesize, cy * tilesize, tile)); @@ -468,16 +468,19 @@ public class Damage{ damage(team, x, y, radius, damage, false, air, ground); } - /** Applies a status effect to all enemy units in a range. */ + public static void status(Team team, float x, float y, float radius, StatusEffect effect, float duration, boolean air, boolean ground){ + status(team, x, y, radius, effect, duration, air, ground, 1f); + } + public static void status(Team team, float x, float y, float radius, StatusEffect effect, float duration, boolean air, boolean ground, float chance){ Cons cons = entity -> { if(entity.team == team || !entity.checkTarget(air, ground) || !entity.hittable() || !entity.within(x, y, radius)){ return; } - // Should the chance be per unit or for the whole shot? - // current: per unit - entity.apply(effect, duration, false, chance); + if(Mathf.chance(chance)){ + entity.apply(effect, duration); + } }; rect.setSize(radius * 2).setCenter(x, y); @@ -487,7 +490,6 @@ public class Damage{ Units.nearby(rect, cons); } } - /** 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){ damage(team, x, y, radius, damage, complete, true, true); @@ -678,4 +680,4 @@ public class Damage{ target = null; } } -} +} \ No newline at end of file diff --git a/core/src/mindustry/entities/Lightning.java b/core/src/mindustry/entities/Lightning.java index c44620de17..963c12bcaf 100644 --- a/core/src/mindustry/entities/Lightning.java +++ b/core/src/mindustry/entities/Lightning.java @@ -26,26 +26,20 @@ public class Lightning{ /** Create a lighting branch at a location. Use Team.derelict to damage everyone. */ public static void create(BulletType bulletCreated, Team team, Color color, float damage, float x, float y, float targetAngle, int length){ - float statusChance = bulletCreated.lightningStatusChance > -1 ? bulletCreated.lightningStatusChance : bulletCreated.statusChance; - createLightningInternal(null, bulletCreated, lastSeed++, team, color, damage, x, y, targetAngle, length, statusChance); + createLightningInternal(null, bulletCreated, lastSeed++, team, color, damage, x, y, targetAngle, length); } /** Create a lighting branch at a location. Use Team.derelict to damage everyone. */ public static void create(Team team, Color color, float damage, float x, float y, float targetAngle, int length){ - float statusChance = Bullets.damageLightning.lightningStatusChance > -1 ? Bullets.damageLightning.lightningStatusChance : Bullets.damageLightning.statusChance; - createLightningInternal(null, Bullets.damageLightning, lastSeed++, team, color, damage, x, y, targetAngle, length, statusChance); + createLightningInternal(null, Bullets.damageLightning, lastSeed++, team, color, damage, x, y, targetAngle, length); } /** Create a lighting branch at a location. Uses bullet parameters. */ public static void create(Bullet bullet, Color color, float damage, float x, float y, float targetAngle, int length){ - // Is this a necessary line? The bullet parameter is not nullable and never will be. - BulletType lightningType = bullet == null || bullet.type.lightningType == null ? Bullets.damageLightning : bullet.type.lightningType; - assert bullet != null; // intellij recommended - float statusChance = bullet.type.lightningStatusChance > -1 ? bullet.type.lightningStatusChance : bullet.type.statusChance; - createLightningInternal(bullet, lightningType, lastSeed++, bullet.team, color, damage, x, y, targetAngle, length, statusChance); + createLightningInternal(bullet, bullet == null || bullet.type.lightningType == null ? Bullets.damageLightning : bullet.type.lightningType, lastSeed++, bullet.team, color, damage, x, y, targetAngle, length); } - private static void createLightningInternal(@Nullable Bullet hitter, BulletType hitCreate, int seed, Team team, Color color, float damage, float x, float y, float rotation, int length, float statusChance){ + private static void createLightningInternal(@Nullable Bullet hitter, BulletType hitCreate, int seed, Team team, Color color, float damage, float x, float y, float rotation, int length){ random.setSeed(seed); hit.clear(); @@ -53,7 +47,7 @@ public class Lightning{ bhit = false; for(int i = 0; i < length / 2; i++){ - hitCreate.create(null, team, x, y, rotation, damage * (hitter == null ? 1f : hitter.damageMultiplier()), 1f, 1f, statusChance); + hitCreate.create(null, team, x, y, rotation, damage * (hitter == null ? 1f : hitter.damageMultiplier()), 1f, 1f, hitter); lines.add(new Vec2(x + Mathf.range(3f), y + Mathf.range(3f))); if(lines.size > 1){ @@ -99,4 +93,4 @@ public class Lightning{ Fx.lightning.at(x, y, rotation, color, lines); } -} +} \ No newline at end of file diff --git a/core/src/mindustry/entities/bullet/BulletType.java b/core/src/mindustry/entities/bullet/BulletType.java index 81028180c7..5eea086b84 100644 --- a/core/src/mindustry/entities/bullet/BulletType.java +++ b/core/src/mindustry/entities/bullet/BulletType.java @@ -514,8 +514,9 @@ public class BulletType extends Content implements Cloneable{ if(impact) Tmp.v3.setAngle(b.rotation() + (knockback < 0 ? 180f : 0f)); unit.impulse(Tmp.v3); // Use statusChance from data if present (lightning bullets pass it), otherwise use type default - float sc = b.data instanceof Float f ? f : statusChance; - unit.apply(status, statusDuration, false, sc); + if(Mathf.chance(getStatusChance(b))){ + unit.apply(status, statusDuration); + } Events.fire(bulletDamageEvent.set(unit, b)); } @@ -602,7 +603,7 @@ public class BulletType extends Content implements Cloneable{ Damage.damage(b.team, x, y, splashDamageRadius, splashDamage * b.damageMultiplier(), splashDamagePierce, collidesAir, collidesGround, scaledSplashDamage, b, armorMultiplier); if(status != StatusEffects.none){ - Damage.status(b.team, x, y, splashDamageRadius, status, statusDuration, collidesAir, collidesGround, statusChance); + Damage.status(b.team, x, y, splashDamageRadius, status, statusDuration, collidesAir, collidesGround, getStatusChance(b)); } if(heals()){ @@ -640,6 +641,16 @@ public class BulletType extends Content implements Cloneable{ } } + /** Gets the status chance from lighting bullets */ + public float getStatusChance(Bullet b){ + if(b.data instanceof Bullet parent && + (parent.type.lightningType == b.type || parent.type.lightningType == null && b.type == Bullets.damageLightning)){ + return parent.type.lightningStatusChance < 0f ? parent.type.statusChance : parent.type.lightningStatusChance; + } + + return statusChance; + } + /** Called when the bullet reaches the end of its lifetime or is destroyed by something external. */ public void despawned(Bullet b){ if(despawnHit){ diff --git a/core/src/mindustry/entities/comp/StatusComp.java b/core/src/mindustry/entities/comp/StatusComp.java index 1911531c35..3c2a6f8113 100644 --- a/core/src/mindustry/entities/comp/StatusComp.java +++ b/core/src/mindustry/entities/comp/StatusComp.java @@ -1,7 +1,6 @@ package mindustry.entities.comp; import arc.graphics.*; -import arc.math.Mathf; import arc.struct.*; import arc.util.*; import arc.util.pooling.*; @@ -35,15 +34,7 @@ abstract class StatusComp implements Posc{ /** Adds a status effect to this unit. */ public void apply(StatusEffect effect, float duration){ - apply(effect, duration, false); - } - - public void apply(StatusEffect effect, float duration, boolean shorten){ - apply(effect, duration, shorten, 1f); - } - - public void apply(StatusEffect effect, float duration, boolean shorten, float statusChance){ - applyStatus(effect, duration, shorten, statusChance); + applyStatus(effect, duration, false); } public float getDuration(StatusEffect effect){ @@ -52,10 +43,10 @@ abstract class StatusComp implements Posc{ } public void setDuration(StatusEffect effect, float duration){ - applyStatus(effect, duration, true, 1f); + applyStatus(effect, duration, true); } - private void applyStatus(StatusEffect effect, float duration, boolean shorten, float chance){ + private void applyStatus(StatusEffect effect, float duration, boolean shorten){ if(effect == StatusEffects.none || effect == null || isImmune(effect)) return; //don't apply empty or immune effects if(shorten && duration == 0){ @@ -63,10 +54,6 @@ abstract class StatusComp implements Posc{ return; } - // Don't apply if the chance fails - // TODO: Multiple applications if chance > 1f ? only useful for reactive effects - if(!Mathf.chance(chance)) return; - //unlock status effects regardless of whether they were applied to friendly units if(state.isCampaign()){ effect.unlock(); @@ -273,4 +260,4 @@ abstract class StatusComp implements Posc{ public boolean hasEffect(StatusEffect effect){ return applied.get(effect.id); } -} +} \ No newline at end of file