Drone repair cleanup / Percentage-based repair

This commit is contained in:
Anuken
2018-11-25 16:34:31 -05:00
parent 44897fb371
commit a7f7a09418
8 changed files with 29 additions and 120 deletions

View File

@@ -37,6 +37,7 @@ public class UnitTypes implements ContentList{
};
spirit = new UnitType("spirit", Spirit.class, Spirit::new){{
weapon = Weapons.healBlasterDrone;
isFlying = true;
drag = 0.01f;
speed = 0.2f;

View File

@@ -7,7 +7,7 @@ import io.anuke.mindustry.type.ContentType;
import io.anuke.mindustry.type.Weapon;
public class Weapons implements ContentList{
public static Weapon blaster, blasterSmall, glaiveBlaster, droneBlaster, healBlaster, chainBlaster, shockgun,
public static Weapon blaster, blasterSmall, glaiveBlaster, droneBlaster, healBlaster, healBlasterDrone, chainBlaster, shockgun,
sapper, swarmer, bomber, bomberTrident, flakgun, flamethrower, missiles, artillery, laserBurster;
@Override
@@ -169,6 +169,16 @@ public class Weapons implements ContentList{
ejectEffect = Fx.none;
ammo = AmmoTypes.lancerLaser;
}};
healBlasterDrone = new Weapon("heal-blaster"){{
length = 1.5f;
reload = 40f;
width = 0.5f;
roundrobin = true;
ejectEffect = Fx.none;
recoil = 2f;
ammo = AmmoTypes.healBlaster;
}};
}
@Override

View File

@@ -43,7 +43,7 @@ public class TurretBullets extends BulletList implements ContentList{
};
healBullet = new BulletType(5.2f, 13){
float healAmount = 21f;
float healPercent = 3f;
{
hiteffect = BulletFx.hitLaser;
@@ -51,6 +51,11 @@ public class TurretBullets extends BulletList implements ContentList{
collidesTeam = true;
}
@Override
public boolean collides(Bullet b, Tile tile){
return tile.getTeam() != b.getTeam() || tile.entity.healthf() < 1f;
}
@Override
public void draw(Bullet b){
Draw.color(Palette.heal);
@@ -67,8 +72,8 @@ public class TurretBullets extends BulletList implements ContentList{
tile = tile.target();
if(tile.getTeam() == b.getTeam() && !(tile.block() instanceof BuildBlock)){
Effects.effect(BlockFx.healBlock, tile.drawx(), tile.drawy(), tile.block().size);
tile.entity.healBy(healAmount);
Effects.effect(BlockFx.healBlockFull, Palette.heal, tile.drawx(), tile.drawy(), tile.block().size);
tile.entity.healBy(healPercent / 100f * tile.entity.maxHealth());
}
}
};

View File

@@ -209,7 +209,7 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
if(tile == null) return false;
tile = tile.target();
if(tile.entity != null && tile.entity.collide(this) && !tile.entity.isDead() && (type.collidesTeam || tile.getTeam() != team)){
if(tile.entity != null && tile.entity.collide(this) && type.collides(this, tile) && !tile.entity.isDead() && (type.collidesTeam || tile.getTeam() != team)){
if(tile.getTeam() != team){
tile.entity.collision(this);
}

View File

@@ -55,6 +55,10 @@ public abstract class BulletType extends Content implements BaseBulletType<Bulle
despawneffect = BulletFx.hitBulletSmall;
}
public boolean collides(Bullet bullet, Tile tile){
return true;
}
public void hitTile(Bullet b, Tile tile){
hit(b);
}

View File

@@ -1,19 +0,0 @@
package io.anuke.mindustry.entities.traits;
import io.anuke.ucore.entities.trait.HealthTrait;
//TODO implement
public interface RepairTrait extends TeamTrait{
HealthTrait getRepairing();
void setRepairing(HealthTrait trait);
default void drawRepair(){
if(getRepairing() == null) return;
}
default void updateRepair(){
if(getRepairing() == null) return;
}
}

View File

@@ -1,14 +1,11 @@
package io.anuke.mindustry.entities.units.types;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.Queue;
import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.content.fx.BlockFx;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.entities.traits.BuilderTrait;
import io.anuke.mindustry.entities.traits.TargetTrait;
import io.anuke.mindustry.entities.units.BaseUnit;
import io.anuke.mindustry.entities.units.FlyingUnit;
import io.anuke.mindustry.entities.units.UnitCommand;
@@ -16,7 +13,6 @@ import io.anuke.mindustry.entities.units.UnitState;
import io.anuke.mindustry.game.EventType.BuildSelectEvent;
import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.type.ItemType;
@@ -24,13 +20,11 @@ import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.BuildBlock;
import io.anuke.mindustry.world.blocks.BuildBlock.BuildEntity;
import io.anuke.mindustry.world.meta.BlockFlag;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Events;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Shapes;
import io.anuke.ucore.util.*;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Structs;
import java.io.DataInput;
import java.io.DataOutput;
@@ -117,12 +111,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
if(target.distanceTo(Drone.this) > type.range){
circle(type.range*0.9f);
}else{
TileEntity entity = (TileEntity) target;
entity.healBy(type.healSpeed * entity.tile.block().health / 100f * Timers.delta());
if(timer.get(timerRepairEffect, 30)){
Effects.effect(BlockFx.healBlockFull, Palette.heal, entity.x, entity.y, entity.tile.block().size);
}
getWeapon().update(Drone.this, target.getX(), target.getY());
}
}
},
@@ -317,16 +306,6 @@ public class Drone extends FlyingUnit implements BuilderTrait{
target = null;
}
if(Net.client() && state.is(repair) && target instanceof TileEntity && target.distanceTo(this) < type.range){
TileEntity entity = (TileEntity) target;
entity.health += type.healSpeed * Timers.delta();
entity.health = Mathf.clamp(entity.health, 0, entity.tile.block().health);
if(timer.get(timerRepairEffect, 30)){
Effects.effect(BlockFx.healBlockFull, Palette.heal, entity.x, entity.y, entity.tile.block().size);
}
}
updateBuilding(this);
}
@@ -355,19 +334,6 @@ public class Drone extends FlyingUnit implements BuilderTrait{
@Override
public void drawOver(){
trail.draw(Palette.lightTrail, 3f);
TargetTrait entity = target;
if(entity instanceof TileEntity && state.is(repair) && target.distanceTo(this) < type.range){
float len = 5f;
Draw.color(Color.BLACK, Color.WHITE, 0.95f + Mathf.absin(Timers.time(), 0.8f, 0.05f));
Shapes.laser("beam", "beam-end",
x + Angles.trnsx(rotation, len),
y + Angles.trnsy(rotation, len),
entity.getX(), entity.getY());
Draw.color();
}
drawBuilding(this);
}

View File

@@ -1,58 +0,0 @@
package io.anuke.mindustry.world.blocks.defense;
import com.badlogic.gdx.graphics.Color;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.bullet.Bullet;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.defense.DeflectorWall.DeflectorEntity;
import io.anuke.ucore.core.Graphics;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.tilesize;
public class MendingWall extends Wall{
protected float regenSpeed = 0.25f;
public MendingWall(String name){
super(name);
update = true;
}
@Override
public void handleBulletHit(TileEntity entity, Bullet bullet){
super.handleBulletHit(entity, bullet);
((DeflectorEntity) entity).hit = 1f;
}
@Override
public void draw(Tile tile){
super.draw(tile);
DeflectorEntity entity = tile.entity();
if(entity.hit < 0.0001f) return;
Graphics.setAdditiveBlending();
Draw.color(Color.WHITE);
Draw.alpha(entity.hit * 0.5f);
Draw.rect("blank", tile.drawx(), tile.drawy(), tilesize * size, tilesize * size);
Draw.reset();
entity.hit = Mathf.clamp(entity.hit - Timers.delta() / DeflectorWall.hitTime);
Graphics.setNormalBlending();
}
@Override
public void update(Tile tile){
tile.entity.health = Mathf.clamp(tile.entity.health + regenSpeed * Timers.delta(), 0f, health);
}
@Override
public TileEntity newEntity(){
return new DeflectorEntity();
}
}