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
public org.mozilla.javascript.Context getScriptContext(){
return AndroidRhinoContext.enterContext(getContext().getCacheDir());
return AndroidRhinoContext.enter(getContext().getCacheDir());
}
@Override

View File

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

View File

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

View File

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

View File

@ -1,46 +1,45 @@
package io.anuke.mindustry.type;
import io.anuke.arc.collection.Array;
import io.anuke.arc.collection.ObjectMap;
import io.anuke.arc.func.Prov;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.collection.*;
import io.anuke.arc.graphics.*;
import io.anuke.arc.math.*;
import io.anuke.arc.util.*;
import io.anuke.mindustry.content.Fx;
import io.anuke.mindustry.entities.Effects;
import io.anuke.mindustry.entities.Effects.Effect;
import io.anuke.mindustry.entities.type.Unit;
import io.anuke.mindustry.entities.units.Statuses.StatusEntry;
import io.anuke.mindustry.ctype.Content;
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<>();
import io.anuke.mindustry.content.*;
import io.anuke.mindustry.ctype.*;
import io.anuke.mindustry.entities.*;
import io.anuke.mindustry.entities.Effects.*;
import io.anuke.mindustry.entities.type.*;
import io.anuke.mindustry.entities.units.Statuses.*;
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. */
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. */
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
public void init(){
for(Object[] pair : transInit){
Prov<StatusEffect> sup = (Prov<StatusEffect>)pair[0];
TransitionHandler handler = (TransitionHandler)pair[1];
transitions.put(sup.get(), handler);
}
transInit.clear();
initblock.run();
}
public void init(Runnable run){
this.initblock = run;
}
/** 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){
transInit.add(new Object[]{effect, handler});
protected void trans(StatusEffect effect, TransitionHandler handler){
transitions.put(effect, handler);
}
@SuppressWarnings("unchecked")
protected void opposite(Prov... effect){
for(Prov<StatusEffect> sup : effect){
protected void opposite(StatusEffect... effect){
for(StatusEffect sup : effect){
trans(sup, (unit, time, newTime, result) -> {
time -= newTime * 0.5f;
if(time > 0){
result.set(this, time);
return;
}
result.set(sup.get(), newTime);
result.set(sup, newTime);
});
}
}