Status effect cleanup

This commit is contained in:
Anuken
2019-12-09 22:08:22 -05:00
parent 2a03ef0c43
commit da849085ec
5 changed files with 84 additions and 80 deletions

View File

@@ -67,7 +67,7 @@ public class AndroidLauncher extends AndroidApplication{
@Override @Override
public org.mozilla.javascript.Context getScriptContext(){ public org.mozilla.javascript.Context getScriptContext(){
return AndroidRhinoContext.enterContext(getContext().getCacheDir()); return AndroidRhinoContext.enter(getContext().getCacheDir());
} }
@Override @Override

View File

@@ -12,8 +12,6 @@ import com.android.dx.merge.*;
import dalvik.system.*; import dalvik.system.*;
import io.anuke.arc.*; import io.anuke.arc.*;
import io.anuke.arc.backends.android.surfaceview.*; import io.anuke.arc.backends.android.surfaceview.*;
import io.anuke.arc.util.ArcAnnotate.NonNull;
import io.anuke.arc.util.ArcAnnotate.Nullable;
import io.anuke.mindustry.AndroidRhinoContext.BaseAndroidClassLoader.*; import io.anuke.mindustry.AndroidRhinoContext.BaseAndroidClassLoader.*;
import org.mozilla.javascript.*; import org.mozilla.javascript.*;
@@ -31,7 +29,7 @@ public class AndroidRhinoContext{
* call this instead of {@link Context#enter()} * call this instead of {@link Context#enter()}
* @return a context prepared for android * @return a context prepared for android
*/ */
public static Context enterContext(File cacheDirectory){ public static Context enter(File cacheDirectory){
if(!SecurityController.hasGlobal()) if(!SecurityController.hasGlobal())
SecurityController.initGlobal(new SecurityController(){ SecurityController.initGlobal(new SecurityController(){
@Override @Override
@@ -172,7 +170,7 @@ public class AndroidRhinoContext{
} }
@Override @Override
protected Class<?> loadClass(@NonNull Dex dex, @NonNull String name) throws ClassNotFoundException{ protected Class<?> loadClass(Dex dex, String name) throws ClassNotFoundException{
try{ try{
dex.writeTo(dexFile); dex.writeTo(dexFile);
}catch(IOException e){ }catch(IOException e){
@@ -181,7 +179,6 @@ public class AndroidRhinoContext{
return new DexClassLoader(dexFile.getPath(), ((AndroidApplication)Core.app).getContext().getCacheDir().getAbsolutePath(), null, getParent()).loadClass(name); return new DexClassLoader(dexFile.getPath(), ((AndroidApplication)Core.app).getContext().getCacheDir().getAbsolutePath(), null, getParent()).loadClass(name);
} }
@Nullable
@Override @Override
protected Dex getLastDex(){ protected Dex getLastDex(){
if(dexFile.exists()){ if(dexFile.exists()){
@@ -202,19 +199,18 @@ public class AndroidRhinoContext{
@TargetApi(Build.VERSION_CODES.O) @TargetApi(Build.VERSION_CODES.O)
static class InMemoryAndroidClassLoader extends BaseAndroidClassLoader{ static class InMemoryAndroidClassLoader extends BaseAndroidClassLoader{
@Nullable private Dex last; private Dex last;
public InMemoryAndroidClassLoader(ClassLoader parent){ public InMemoryAndroidClassLoader(ClassLoader parent){
super(parent); super(parent);
} }
@Override @Override
protected Class<?> loadClass(@NonNull Dex dex, @NonNull String name) throws ClassNotFoundException{ protected Class<?> loadClass(Dex dex, String name) throws ClassNotFoundException{
last = dex; last = dex;
return new InMemoryDexClassLoader(ByteBuffer.wrap(dex.getBytes()), getParent()).loadClass(name); return new InMemoryDexClassLoader(ByteBuffer.wrap(dex.getBytes()), getParent()).loadClass(name);
} }
@Nullable
@Override @Override
protected Dex getLastDex(){ protected Dex getLastDex(){
return last; return last;

View File

@@ -15,61 +15,71 @@ public class StatusEffects implements ContentList{
@Override @Override
public void load(){ public void load(){
none = new StatusEffect(); none = new StatusEffect("none");
burning = new StatusEffect(){{ burning = new StatusEffect("burning"){{
damage = 0.06f; damage = 0.06f;
effect = Fx.burning; effect = Fx.burning;
opposite(() -> wet, () -> freezing); init(() -> {
trans(() -> tarred, ((unit, time, newTime, result) -> { opposite(wet,freezing);
unit.damage(1f); trans(tarred, ((unit, time, newTime, result) -> {
Effects.effect(Fx.burning, unit.x + Mathf.range(unit.getSize() / 2f), unit.y + Mathf.range(unit.getSize() / 2f)); unit.damage(1f);
result.set(this, Math.min(time + newTime, 300f)); Effects.effect(Fx.burning, unit.x + Mathf.range(unit.getSize() / 2f), unit.y + Mathf.range(unit.getSize() / 2f));
})); result.set(this, Math.min(time + newTime, 300f));
}));
});
}}; }};
freezing = new StatusEffect(){{ freezing = new StatusEffect("freezing"){{
speedMultiplier = 0.6f; speedMultiplier = 0.6f;
armorMultiplier = 0.8f; armorMultiplier = 0.8f;
effect = Fx.freezing; effect = Fx.freezing;
opposite(() -> melting, () -> burning); init(() -> {
opposite(melting, burning);
});
}}; }};
wet = new StatusEffect(){{ wet = new StatusEffect("wet"){{
speedMultiplier = 0.9f; speedMultiplier = 0.9f;
effect = Fx.wet; effect = Fx.wet;
trans(() -> shocked, ((unit, time, newTime, result) -> { init(() -> {
unit.damage(20f); trans(shocked, ((unit, time, newTime, result) -> {
if(unit.getTeam() == waveTeam){ unit.damage(20f);
Events.fire(Trigger.shock); if(unit.getTeam() == waveTeam){
} Events.fire(Trigger.shock);
result.set(this, time); }
})); result.set(this, time);
opposite(() -> burning); }));
opposite(burning);
});
}}; }};
melting = new StatusEffect(){{ melting = new StatusEffect("melting"){{
speedMultiplier = 0.8f; speedMultiplier = 0.8f;
armorMultiplier = 0.8f; armorMultiplier = 0.8f;
damage = 0.3f; damage = 0.3f;
effect = Fx.melting; effect = Fx.melting;
trans(() -> tarred, ((unit, time, newTime, result) -> result.set(this, Math.min(time + newTime / 2f, 140f)))); init(() -> {
opposite(() -> wet, () -> freezing); trans(tarred, ((unit, time, newTime, result) -> result.set(this, Math.min(time + newTime / 2f, 140f))));
opposite(wet, freezing);
});
}}; }};
tarred = new StatusEffect(){{ tarred = new StatusEffect("tarred"){{
speedMultiplier = 0.6f; speedMultiplier = 0.6f;
effect = Fx.oily; effect = Fx.oily;
trans(() -> melting, ((unit, time, newTime, result) -> result.set(burning, newTime + time))); init(() -> {
trans(() -> burning, ((unit, time, newTime, result) -> result.set(burning, newTime + time))); trans(melting, ((unit, time, newTime, result) -> result.set(burning, newTime + time)));
trans(burning, ((unit, time, newTime, result) -> result.set(burning, newTime + time)));
});
}}; }};
overdrive = new StatusEffect(){{ overdrive = new StatusEffect("overdrive"){{
armorMultiplier = 0.95f; armorMultiplier = 0.95f;
speedMultiplier = 1.15f; speedMultiplier = 1.15f;
damageMultiplier = 1.4f; damageMultiplier = 1.4f;
@@ -77,20 +87,20 @@ public class StatusEffects implements ContentList{
effect = Fx.overdriven; effect = Fx.overdriven;
}}; }};
shielded = new StatusEffect(){{ shielded = new StatusEffect("shielded"){{
armorMultiplier = 3f; armorMultiplier = 3f;
}}; }};
boss = new StatusEffect(){{ boss = new StatusEffect("boss"){{
armorMultiplier = 3f; armorMultiplier = 3f;
damageMultiplier = 3f; damageMultiplier = 3f;
speedMultiplier = 1.1f; speedMultiplier = 1.1f;
}}; }};
shocked = new StatusEffect(); shocked = new StatusEffect("shocked");
//no effects, just small amounts of damage. //no effects, just small amounts of damage.
corroded = new StatusEffect(){{ corroded = new StatusEffect("corroded"){{
damage = 0.1f; damage = 0.1f;
}}; }};
} }

View File

@@ -66,7 +66,7 @@ public class ContentParser{
} }
}); });
put(StatusEffect.class, (type, data) -> { put(StatusEffect.class, (type, data) -> {
StatusEffect effect = new StatusEffect(); StatusEffect effect = new StatusEffect(currentMod.name + "-" + data.getString("name"));
readFields(effect, data); readFields(effect, data);
return effect; return effect;
}); });

View File

@@ -1,46 +1,45 @@
package io.anuke.mindustry.type; package io.anuke.mindustry.type;
import io.anuke.arc.collection.Array; import io.anuke.arc.collection.*;
import io.anuke.arc.collection.ObjectMap; import io.anuke.arc.graphics.*;
import io.anuke.arc.func.Prov; import io.anuke.arc.math.*;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.util.*; import io.anuke.arc.util.*;
import io.anuke.mindustry.content.Fx; import io.anuke.mindustry.content.*;
import io.anuke.mindustry.entities.Effects; import io.anuke.mindustry.ctype.*;
import io.anuke.mindustry.entities.Effects.Effect; import io.anuke.mindustry.entities.*;
import io.anuke.mindustry.entities.type.Unit; import io.anuke.mindustry.entities.Effects.*;
import io.anuke.mindustry.entities.units.Statuses.StatusEntry; import io.anuke.mindustry.entities.type.*;
import io.anuke.mindustry.ctype.Content; import io.anuke.mindustry.entities.units.Statuses.*;
public class StatusEffect extends Content{
public float damageMultiplier = 1f; //damage dealt
public float armorMultiplier = 1f; //armor points
public float speedMultiplier = 1f; //speed
public Color color = Color.white.cpy(); //tint color
/** Transition handler map. */
private ObjectMap<StatusEffect, TransitionHandler> transitions = new ObjectMap<>();
/**
* Transition initializer array. Since provided effects are only available after init(), this handles putting things
* in the transitions map.
*/
private Array<Object[]> transInit = new Array<>();
public class StatusEffect extends MappableContent{
/** Damage dealt by the unit with the effect. */
public float damageMultiplier = 1f;
/** Unit armor multiplier. */
public float armorMultiplier = 1f;
/** Unit speed multiplier (buggy) */
public float speedMultiplier = 1f;
/** Damage per frame. */ /** Damage per frame. */
protected float damage; public float damage;
/** Tint color of effect. */
public Color color = Color.white.cpy();
/** Effect that happens randomly on top of the affected unit. */ /** Effect that happens randomly on top of the affected unit. */
protected Effect effect = Fx.none; public Effect effect = Fx.none;
/** Transition handler map. */
protected ObjectMap<StatusEffect, TransitionHandler> transitions = new ObjectMap<>();
/** Called on init. */
protected Runnable initblock = () -> {};
public StatusEffect(String name){
super(name);
}
@SuppressWarnings("unchecked")
@Override @Override
public void init(){ public void init(){
for(Object[] pair : transInit){ initblock.run();
Prov<StatusEffect> sup = (Prov<StatusEffect>)pair[0]; }
TransitionHandler handler = (TransitionHandler)pair[1];
transitions.put(sup.get(), handler); public void init(Runnable run){
} this.initblock = run;
transInit.clear();
} }
/** Runs every tick on the affected unit while time is greater than 0. */ /** Runs every tick on the affected unit while time is greater than 0. */
@@ -56,20 +55,19 @@ public class StatusEffect extends Content{
} }
} }
protected void trans(Prov<StatusEffect> effect, TransitionHandler handler){ protected void trans(StatusEffect effect, TransitionHandler handler){
transInit.add(new Object[]{effect, handler}); transitions.put(effect, handler);
} }
@SuppressWarnings("unchecked") protected void opposite(StatusEffect... effect){
protected void opposite(Prov... effect){ for(StatusEffect sup : effect){
for(Prov<StatusEffect> sup : effect){
trans(sup, (unit, time, newTime, result) -> { trans(sup, (unit, time, newTime, result) -> {
time -= newTime * 0.5f; time -= newTime * 0.5f;
if(time > 0){ if(time > 0){
result.set(this, time); result.set(this, time);
return; return;
} }
result.set(sup.get(), newTime); result.set(sup, newTime);
}); });
} }
} }