Implemented basic mech factories
This commit is contained in:
@@ -8,7 +8,6 @@ import com.badlogic.gdx.utils.Queue;
|
||||
import io.anuke.annotations.Annotations.Loc;
|
||||
import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.content.Mechs;
|
||||
import io.anuke.mindustry.entities.effect.ItemDrop;
|
||||
import io.anuke.mindustry.entities.traits.BuilderTrait;
|
||||
import io.anuke.mindustry.entities.traits.CarriableTrait;
|
||||
@@ -62,7 +61,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
||||
public String uuid, usid;
|
||||
public boolean isAdmin, isTransferring, isShooting;
|
||||
public Color color = new Color();
|
||||
public Mech mech = Mechs.standard;
|
||||
public Mech mech;
|
||||
|
||||
public int clientid = -1;
|
||||
public int playerIndex = 0;
|
||||
@@ -87,7 +86,18 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
||||
|
||||
//region unit and event overrides, utility methods
|
||||
|
||||
@Override
|
||||
|
||||
@Override
|
||||
public int getItemCapacity() {
|
||||
return mech.itemCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmmoCapacity() {
|
||||
return mech.ammoCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interpolate() {
|
||||
super.interpolate();
|
||||
|
||||
@@ -122,7 +132,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
||||
|
||||
@Override
|
||||
public float getBuildPower(Tile tile) {
|
||||
return 1f;
|
||||
return mech.buildPower;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,7 +35,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
/**Maximum absolute value of a velocity vector component.*/
|
||||
public static final float maxAbsVelocity = 127f/velocityPercision;
|
||||
|
||||
public UnitInventory inventory = new UnitInventory(100, 100);
|
||||
public UnitInventory inventory = new UnitInventory(this);
|
||||
public float rotation;
|
||||
|
||||
protected Interpolator interpolator = new Interpolator();
|
||||
@@ -259,6 +259,12 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
public void drawUnder(){}
|
||||
public void drawOver(){}
|
||||
|
||||
public boolean isInfiniteAmmo(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract int getItemCapacity();
|
||||
public abstract int getAmmoCapacity();
|
||||
public abstract float getArmor();
|
||||
public abstract boolean acceptsAmmo(Item item);
|
||||
public abstract void addAmmo(Item item);
|
||||
|
||||
@@ -14,28 +14,21 @@ public class UnitInventory implements Saveable{
|
||||
private Array<AmmoEntry> ammos = new Array<>();
|
||||
private int totalAmmo;
|
||||
private ItemStack item = new ItemStack(Items.stone, 0);
|
||||
//TODO move these somewhere else so they're not variables?
|
||||
private int capacity, ammoCapacity;
|
||||
private boolean infiniteAmmo;
|
||||
|
||||
public UnitInventory(int capacity, int ammoCapacity) {
|
||||
this.capacity = capacity;
|
||||
this.ammoCapacity = ammoCapacity;
|
||||
private final Unit unit;
|
||||
|
||||
public UnitInventory(Unit unit) {
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
public boolean isFull(){
|
||||
return item != null && item.amount >= capacity;
|
||||
}
|
||||
|
||||
public void setInfiniteAmmo(boolean infinite){
|
||||
infiniteAmmo = infinite;
|
||||
return item != null && item.amount >= unit.getItemCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSave(DataOutput stream) throws IOException {
|
||||
stream.writeShort(item.amount);
|
||||
stream.writeByte(item.item.id);
|
||||
stream.writeBoolean(infiniteAmmo);
|
||||
stream.writeShort(totalAmmo);
|
||||
stream.writeByte(ammos.size);
|
||||
for(int i = 0; i < ammos.size; i ++){
|
||||
@@ -48,7 +41,6 @@ public class UnitInventory implements Saveable{
|
||||
public void readSave(DataInput stream) throws IOException {
|
||||
short iamount = stream.readShort();
|
||||
byte iid = stream.readByte();
|
||||
infiniteAmmo = stream.readBoolean();
|
||||
this.totalAmmo = stream.readShort();
|
||||
byte ammoa = stream.readByte();
|
||||
for(int i = 0; i < ammoa; i ++){
|
||||
@@ -75,7 +67,7 @@ public class UnitInventory implements Saveable{
|
||||
}
|
||||
|
||||
public void useAmmo(){
|
||||
if(infiniteAmmo) return;
|
||||
if(unit.isInfiniteAmmo()) return;
|
||||
AmmoEntry entry = ammos.peek();
|
||||
entry.amount --;
|
||||
if(entry.amount == 0) ammos.pop();
|
||||
@@ -87,11 +79,11 @@ public class UnitInventory implements Saveable{
|
||||
}
|
||||
|
||||
public int ammoCapacity(){
|
||||
return ammoCapacity;
|
||||
return unit.getAmmoCapacity();
|
||||
}
|
||||
|
||||
public boolean canAcceptAmmo(AmmoType type){
|
||||
return totalAmmo + type.quantityMultiplier <= ammoCapacity;
|
||||
return totalAmmo + type.quantityMultiplier <= unit.getAmmoCapacity();
|
||||
}
|
||||
|
||||
public void addAmmo(AmmoType type){
|
||||
@@ -115,7 +107,7 @@ public class UnitInventory implements Saveable{
|
||||
}
|
||||
|
||||
public int capacity(){
|
||||
return capacity;
|
||||
return unit.getItemCapacity();
|
||||
}
|
||||
|
||||
public boolean isEmpty(){
|
||||
@@ -124,18 +116,18 @@ public class UnitInventory implements Saveable{
|
||||
|
||||
public int itemCapacityUsed(Item type){
|
||||
if(canAcceptItem(type)){
|
||||
return !hasItem() ? capacity : (capacity - item.amount);
|
||||
return !hasItem() ? unit.getItemCapacity() : (unit.getItemCapacity() - item.amount);
|
||||
}else{
|
||||
return capacity;
|
||||
return unit.getItemCapacity();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canAcceptItem(Item type){
|
||||
return !hasItem() || (item.item == type && capacity - item.amount > 0);
|
||||
return !hasItem() || (item.item == type && unit.getItemCapacity() - item.amount > 0);
|
||||
}
|
||||
|
||||
public boolean canAcceptItem(Item type, int amount){
|
||||
return !hasItem() || (item.item == type && item.amount + amount <= capacity);
|
||||
return !hasItem() || (item.item == type && item.amount + amount <= unit.getItemCapacity());
|
||||
}
|
||||
|
||||
public void clear(){
|
||||
|
||||
@@ -76,7 +76,7 @@ public class Units {
|
||||
boolean[] value = new boolean[1];
|
||||
|
||||
Units.getNearby(rect, unit -> {
|
||||
if(value[0] || !pred.test(unit)) return;
|
||||
if(value[0] || !pred.test(unit) || unit.isDead()) return;
|
||||
if(!unit.isFlying()){
|
||||
unit.getHitbox(hitrect);
|
||||
|
||||
|
||||
@@ -53,7 +53,6 @@ public abstract class BaseUnit extends Unit{
|
||||
/**Sets this to a 'wave' unit, which means it has slightly different AI and will not run out of ammo.*/
|
||||
public void setWave(){
|
||||
isWave = true;
|
||||
inventory.setInfiniteAmmo(true);
|
||||
}
|
||||
|
||||
public void rotate(float angle){
|
||||
@@ -115,6 +114,21 @@ public abstract class BaseUnit extends Unit{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCapacity() {
|
||||
return type.itemCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmmoCapacity() {
|
||||
return type.ammoCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInfiniteAmmo() {
|
||||
return isWave;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interpolate() {
|
||||
super.interpolate();
|
||||
|
||||
@@ -31,6 +31,8 @@ public class UnitType {
|
||||
public float retreatPercent = 0.2f;
|
||||
public float armor = 0f;
|
||||
public float carryWeight = 1f;
|
||||
public int ammoCapacity = 100;
|
||||
public int itemCapacity = 100;
|
||||
public ObjectMap<Item, AmmoType> ammo = new ObjectMap<>();
|
||||
|
||||
public UnitType(String name, UnitCreator creator){
|
||||
|
||||
Reference in New Issue
Block a user