update to comply

This commit is contained in:
JasonP01
2026-09-02 00:05:39 +02:00
parent aeba3e1f63
commit 664b7a3e45
4 changed files with 33 additions and 39 deletions
+8 -6
View File
@@ -266,7 +266,7 @@ public class Damage{
World.raycastEachNoDiagonalWorld(x, y, seg2.x, seg2.y, (cx, cy) -> { World.raycastEachNoDiagonalWorld(x, y, seg2.x, seg2.y, (cx, cy) -> {
Building tile = world.build(cx, cy); Building tile = world.build(cx, cy);
boolean collide = tile != null && tile.collide(hitter) && hitter.checkUnderBuild(tile, cx * tilesize, cy * tilesize) 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){ if(collide){
collided.add(collidePool.obtain().set(cx * tilesize, cy * tilesize, tile)); 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); 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){ public static void status(Team team, float x, float y, float radius, StatusEffect effect, float duration, boolean air, boolean ground, float chance){
Cons<Unit> cons = entity -> { Cons<Unit> cons = entity -> {
if(entity.team == team || !entity.checkTarget(air, ground) || !entity.hittable() || !entity.within(x, y, radius)){ if(entity.team == team || !entity.checkTarget(air, ground) || !entity.hittable() || !entity.within(x, y, radius)){
return; return;
} }
// Should the chance be per unit or for the whole shot? if(Mathf.chance(chance)){
// current: per unit entity.apply(effect, duration);
entity.apply(effect, duration, false, chance); }
}; };
rect.setSize(radius * 2).setCenter(x, y); rect.setSize(radius * 2).setCenter(x, y);
@@ -487,7 +490,6 @@ public class Damage{
Units.nearby(rect, cons); Units.nearby(rect, cons);
} }
} }
/** Damages all entities and blocks in a radius that are enemies of the team. */ /** 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){ 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); damage(team, x, y, radius, damage, complete, true, true);
+5 -11
View File
@@ -26,26 +26,20 @@ public class Lightning{
/** Create a lighting branch at a location. Use Team.derelict to damage everyone. */ /** 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){ 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);
createLightningInternal(null, bulletCreated, lastSeed++, team, color, damage, x, y, targetAngle, length, statusChance);
} }
/** Create a lighting branch at a location. Use Team.derelict to damage everyone. */ /** 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){ 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);
createLightningInternal(null, Bullets.damageLightning, lastSeed++, team, color, damage, x, y, targetAngle, length, statusChance);
} }
/** Create a lighting branch at a location. Uses bullet parameters. */ /** 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){ 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. createLightningInternal(bullet, bullet == null || bullet.type.lightningType == null ? Bullets.damageLightning : bullet.type.lightningType, lastSeed++, bullet.team, color, damage, x, y, targetAngle, length);
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);
} }
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); random.setSeed(seed);
hit.clear(); hit.clear();
@@ -53,7 +47,7 @@ public class Lightning{
bhit = false; bhit = false;
for(int i = 0; i < length / 2; i++){ 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))); lines.add(new Vec2(x + Mathf.range(3f), y + Mathf.range(3f)));
if(lines.size > 1){ if(lines.size > 1){
@@ -514,8 +514,9 @@ public class BulletType extends Content implements Cloneable{
if(impact) Tmp.v3.setAngle(b.rotation() + (knockback < 0 ? 180f : 0f)); if(impact) Tmp.v3.setAngle(b.rotation() + (knockback < 0 ? 180f : 0f));
unit.impulse(Tmp.v3); unit.impulse(Tmp.v3);
// Use statusChance from data if present (lightning bullets pass it), otherwise use type default // Use statusChance from data if present (lightning bullets pass it), otherwise use type default
float sc = b.data instanceof Float f ? f : statusChance; if(Mathf.chance(getStatusChance(b))){
unit.apply(status, statusDuration, false, sc); unit.apply(status, statusDuration);
}
Events.fire(bulletDamageEvent.set(unit, b)); 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); Damage.damage(b.team, x, y, splashDamageRadius, splashDamage * b.damageMultiplier(), splashDamagePierce, collidesAir, collidesGround, scaledSplashDamage, b, armorMultiplier);
if(status != StatusEffects.none){ 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()){ 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. */ /** Called when the bullet reaches the end of its lifetime or is destroyed by something external. */
public void despawned(Bullet b){ public void despawned(Bullet b){
if(despawnHit){ if(despawnHit){
@@ -1,7 +1,6 @@
package mindustry.entities.comp; package mindustry.entities.comp;
import arc.graphics.*; import arc.graphics.*;
import arc.math.Mathf;
import arc.struct.*; import arc.struct.*;
import arc.util.*; import arc.util.*;
import arc.util.pooling.*; import arc.util.pooling.*;
@@ -35,15 +34,7 @@ abstract class StatusComp implements Posc{
/** Adds a status effect to this unit. */ /** Adds a status effect to this unit. */
public void apply(StatusEffect effect, float duration){ public void apply(StatusEffect effect, float duration){
apply(effect, duration, false); applyStatus(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);
} }
public float getDuration(StatusEffect effect){ public float getDuration(StatusEffect effect){
@@ -52,10 +43,10 @@ abstract class StatusComp implements Posc{
} }
public void setDuration(StatusEffect effect, float duration){ 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(effect == StatusEffects.none || effect == null || isImmune(effect)) return; //don't apply empty or immune effects
if(shorten && duration == 0){ if(shorten && duration == 0){
@@ -63,10 +54,6 @@ abstract class StatusComp implements Posc{
return; 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 //unlock status effects regardless of whether they were applied to friendly units
if(state.isCampaign()){ if(state.isCampaign()){
effect.unlock(); effect.unlock();