Partial liquid turret implementation / Status effects
This commit is contained in:
@@ -11,7 +11,7 @@ import io.anuke.ucore.util.Timer;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Bullet extends BulletEntity{
|
||||
public class Bullet extends BulletEntity<BulletType>{
|
||||
private static Vector2 vector = new Vector2();
|
||||
|
||||
public IntSet collided;
|
||||
@@ -73,8 +73,9 @@ public class Bullet extends BulletEntity{
|
||||
collided.add(other.id);
|
||||
|
||||
if(other instanceof Unit){
|
||||
float k = ((BulletType)type).knockback;
|
||||
((Unit) other).velocity.add(vector.set(other.x, other.y).sub(x, y).setLength(k));
|
||||
Unit unit = (Unit)other;
|
||||
unit.velocity.add(vector.set(other.x, other.y).sub(x, y).setLength(type.knockback / unit.getMass()));
|
||||
unit.status.handleApply(unit, type.status, type.statusIntensity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package io.anuke.mindustry.entities;
|
||||
|
||||
import io.anuke.mindustry.content.StatusEffects;
|
||||
import io.anuke.mindustry.content.fx.BulletFx;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.entities.BaseBulletType;
|
||||
|
||||
public abstract class BulletType extends BaseBulletType<Bullet>{
|
||||
public float knockback;
|
||||
public StatusEffect status = StatusEffects.none;
|
||||
public float statusIntensity = 0.5f;
|
||||
|
||||
public BulletType(float speed, int damage){
|
||||
this.speed = speed;
|
||||
|
||||
@@ -81,7 +81,7 @@ public class Player extends Unit{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void damage(int amount){
|
||||
public void damage(float amount){
|
||||
if(debug || mech.flying) return;
|
||||
hitTime = hitDuration;
|
||||
|
||||
@@ -177,11 +177,9 @@ public class Player extends Unit{
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
if(hitTime > 0){
|
||||
hitTime -= Timers.delta();
|
||||
}
|
||||
hitTime = Math.max(0f, hitTime - Timers.delta());
|
||||
|
||||
if(hitTime < 0) hitTime = 0;
|
||||
status.update(this);
|
||||
|
||||
if(!isLocal){
|
||||
interpolate();
|
||||
|
||||
62
core/src/io/anuke/mindustry/entities/StatusController.java
Normal file
62
core/src/io/anuke/mindustry/entities/StatusController.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package io.anuke.mindustry.entities;
|
||||
|
||||
import io.anuke.mindustry.content.StatusEffects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
|
||||
public class StatusController {
|
||||
private static final TransitionResult globalResult = new TransitionResult();
|
||||
|
||||
private StatusEffect current = StatusEffects.none;
|
||||
private float time;
|
||||
|
||||
public void handleApply(Unit unit, StatusEffect effect, float intensity){
|
||||
if(effect == StatusEffects.none) return; //don't apply empty effects
|
||||
|
||||
float newTime = effect.baseDuration*intensity;
|
||||
|
||||
if(effect == current){
|
||||
time = Math.max(time, newTime);
|
||||
}else {
|
||||
|
||||
current.getTransition(unit, effect, time, newTime, globalResult);
|
||||
|
||||
if (globalResult.result != current) {
|
||||
current.onTransition(unit, globalResult.result);
|
||||
time = globalResult.time;
|
||||
current = globalResult.result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void update(Unit unit){
|
||||
if(time > 0){
|
||||
time = Math.max(time - Timers.delta(), 0);
|
||||
}
|
||||
|
||||
current.update(unit, time);
|
||||
}
|
||||
|
||||
public void set(StatusEffect current, float time){
|
||||
this.current = current;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public StatusEffect current() {
|
||||
return current;
|
||||
}
|
||||
|
||||
public float getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public static class TransitionResult{
|
||||
public StatusEffect result;
|
||||
public float time;
|
||||
|
||||
public TransitionResult set(StatusEffect effect, float time){
|
||||
this.result = effect;
|
||||
this.time = time;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,58 @@
|
||||
package io.anuke.mindustry.entities;
|
||||
|
||||
public enum StatusEffect{
|
||||
none;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectSet;
|
||||
import io.anuke.mindustry.entities.StatusController.TransitionResult;
|
||||
|
||||
public class StatusEffect{
|
||||
private static final Array<StatusEffect> array = new Array<>();
|
||||
private static int lastid;
|
||||
|
||||
public final float baseDuration;
|
||||
public final int id;
|
||||
|
||||
protected ObjectSet<StatusEffect> opposites = new ObjectSet<>();
|
||||
protected float oppositeScale = 0.5f;
|
||||
|
||||
public StatusEffect(float baseDuration){
|
||||
this.baseDuration = baseDuration;
|
||||
|
||||
id = lastid++;
|
||||
array.add(this);
|
||||
}
|
||||
|
||||
/**Runs every tick on the affected unit while time is greater than 0.*/
|
||||
public void update(Unit unit, float time){}
|
||||
|
||||
/**Called when transitioning between two status effects.
|
||||
* @param to The state to transition to
|
||||
* @param time The current status effect time
|
||||
* @param newTime The time that the new status effect will last*/
|
||||
public TransitionResult getTransition(Unit unit, StatusEffect to, float time, float newTime, TransitionResult result){
|
||||
if(opposites.contains(to)){
|
||||
time -= newTime*oppositeScale;
|
||||
if(time > 0) {
|
||||
return result.set(this, time);
|
||||
}
|
||||
}
|
||||
|
||||
return result.set(to, newTime);
|
||||
}
|
||||
|
||||
/**Called when this effect transitions to a new status effect.*/
|
||||
public void onTransition(Unit unit, StatusEffect to){}
|
||||
|
||||
public void setOpposites(StatusEffect... effects){
|
||||
for(StatusEffect e : effects){
|
||||
opposites.add(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static StatusEffect getByID(int id){
|
||||
return array.get(id);
|
||||
}
|
||||
|
||||
public static Array<StatusEffect> getAllEffects(){
|
||||
return array;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ public abstract class Unit extends SyncEntity {
|
||||
//total duration of hit effect
|
||||
public static final float hitDuration = 9f;
|
||||
|
||||
public StatusController status = new StatusController();
|
||||
public Team team = Team.blue;
|
||||
public Vector2 velocity = new Vector2();
|
||||
public float hitTime;
|
||||
|
||||
@@ -74,7 +74,7 @@ public class BaseUnit extends Unit {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void damage(int amount){
|
||||
public void damage(float amount){
|
||||
super.damage(amount);
|
||||
hitTime = hitDuration;
|
||||
}
|
||||
|
||||
@@ -74,7 +74,10 @@ public abstract class UnitType {
|
||||
|
||||
//TODO logic
|
||||
|
||||
unit.status.update(unit);
|
||||
|
||||
unit.velocity.limit(maxVelocity);
|
||||
|
||||
if(isFlying) {
|
||||
unit.x += unit.velocity.x / mass;
|
||||
unit.y += unit.velocity.y / mass;
|
||||
|
||||
Reference in New Issue
Block a user