basic bed implementation
parent
68a4142944
commit
ea713fd3b5
|
|
@ -9,6 +9,7 @@ import xyz.valnet.engine.math.Vector2i;
|
|||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.Stockpile;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Item;
|
||||
import xyz.valnet.hadean.interfaces.IItemReceiver;
|
||||
import xyz.valnet.hadean.interfaces.IWorkable;
|
||||
|
||||
public class Job extends GameObject {
|
||||
|
|
@ -42,6 +43,27 @@ public class Job extends GameObject {
|
|||
}
|
||||
}
|
||||
|
||||
public class DropoffAtItemReceiver extends JobStep {
|
||||
|
||||
public IItemReceiver receiver;
|
||||
public Item item;
|
||||
|
||||
public DropoffAtItemReceiver(IItemReceiver receiver, Item item) {
|
||||
this.receiver = receiver;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2i[] getLocations() {
|
||||
return receiver.getItemDropoffLocations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class DropoffAtStockpile extends JobStep {
|
||||
public Item item;
|
||||
public DropoffAtStockpile(Item item) {
|
||||
|
|
|
|||
|
|
@ -1,26 +1,139 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects;
|
||||
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.hadean.gameobjects.Job;
|
||||
import xyz.valnet.hadean.gameobjects.JobBoard;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Item;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Log;
|
||||
import xyz.valnet.hadean.interfaces.BuildableMetadata;
|
||||
import xyz.valnet.hadean.interfaces.IBuildable;
|
||||
import xyz.valnet.hadean.interfaces.IItemReceiver;
|
||||
import xyz.valnet.hadean.interfaces.ISelectable;
|
||||
import xyz.valnet.hadean.interfaces.IWorkable;
|
||||
import xyz.valnet.hadean.util.Action;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
import xyz.valnet.hadean.util.Layers;
|
||||
import xyz.valnet.hadean.util.detail.BooleanDetail;
|
||||
import xyz.valnet.hadean.util.detail.Detail;
|
||||
import xyz.valnet.hadean.util.detail.PercentDetail;
|
||||
|
||||
public class Bed extends WorldObject implements IBuildable {
|
||||
import static xyz.valnet.engine.util.Math.lerp;
|
||||
|
||||
@BuildableMetadata(category = "Furniture", name = "Bed", type = BuildableMetadata.SINGLE)
|
||||
public class Bed extends WorldObject implements IBuildable, IItemReceiver, IWorkable, ISelectable {
|
||||
|
||||
private int logs = 0;
|
||||
private float work = 0;
|
||||
private final float maxWork = 500;
|
||||
|
||||
private Job job = null;
|
||||
|
||||
@Override
|
||||
protected void create() {
|
||||
super.create();
|
||||
// TODO eventually we're going to need a serializable ItemPredicate to select valid items.
|
||||
// it will be useful for stockpile filters, pickup items, etc. basically a placeholder
|
||||
// for "any item that matches X" as a data type.
|
||||
job = add(new Job("Build Bed"));
|
||||
Log log = get(Log.class);
|
||||
job.addStep(job.new PickupItem(log));
|
||||
job.addStep(job.new DropoffAtItemReceiver(this, log));
|
||||
job.addStep(job.new Work(this));
|
||||
get(JobBoard.class).postJob(job);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
super.render();
|
||||
if(isBuilt()) {
|
||||
camera.draw(Layers.GROUND, Assets.bed, (int)x, (int)y, 1, 2);
|
||||
} else {
|
||||
Assets.flat.pushColor(Vector4f.opacity(lerp(0.5f, 1.0f, work / maxWork)));
|
||||
camera.draw(Layers.GROUND, Assets.bed, (int)x, (int)y, 1, 2);
|
||||
Assets.flat.popColor();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildAt(int x, int y, int w, int h) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.w = 1;
|
||||
this.h = 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return "Bed";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector4f getWorldBox() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return new Vector4f(x, y, x+w, y+h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean receive(Item item) {
|
||||
remove(item);
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isBuilt() {
|
||||
return work >= maxWork;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doWork(float dTime) {
|
||||
work += dTime;
|
||||
return isBuilt();
|
||||
}
|
||||
|
||||
private Vector2i[] getBorders() {
|
||||
return new Vector2i[] {
|
||||
new Vector2i((int) x, (int) y - 1),
|
||||
|
||||
new Vector2i((int) x - 1, (int) y),
|
||||
new Vector2i((int) x + 1, (int) y),
|
||||
|
||||
new Vector2i((int) x - 1, (int) y + 1),
|
||||
new Vector2i((int) x + 1, (int) y + 1),
|
||||
|
||||
new Vector2i((int) x, (int) y + 2),
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2i[] getWorkablePositions() {
|
||||
return getBorders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJobName() {
|
||||
return "Build Bed";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2i[] getItemDropoffLocations() {
|
||||
return getBorders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action[] getActions() {
|
||||
return new Action[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAction(Action action) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Detail[] getDetails() {
|
||||
return new Detail[] {
|
||||
new BooleanDetail("Built", isBuilt()),
|
||||
new PercentDetail("Work", work / maxWork),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,6 +104,10 @@ public class JobActivity extends Activity {
|
|||
worker.dropoffItem(dropoffStep.item);
|
||||
step.next();
|
||||
return true;
|
||||
} else if(step instanceof Job.DropoffAtItemReceiver) {
|
||||
Job.DropoffAtItemReceiver dropoffStep = (Job.DropoffAtItemReceiver) step;
|
||||
worker.dropoffItem(dropoffStep.item, dropoffStep.receiver);
|
||||
step.next();
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import xyz.valnet.hadean.gameobjects.JobBoard;
|
|||
import xyz.valnet.hadean.gameobjects.Terrain;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.agents.Agent;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Item;
|
||||
import xyz.valnet.hadean.interfaces.IItemReceiver;
|
||||
import xyz.valnet.hadean.util.Action;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
import xyz.valnet.hadean.util.Layers;
|
||||
|
|
@ -52,6 +53,15 @@ public class Pawn extends Agent {
|
|||
getTile().placeThing(item);
|
||||
}
|
||||
|
||||
public void dropoffItem(Item item, IItemReceiver receiver) {
|
||||
if(!inventory.contains(item)) {
|
||||
return;
|
||||
}
|
||||
inventory.remove(item);
|
||||
add(item);
|
||||
receiver.receive(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void ready() {
|
||||
super.ready();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
package xyz.valnet.hadean.interfaces;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Item;
|
||||
|
||||
public interface IItemReceiver extends Serializable {
|
||||
public boolean receive(Item item);
|
||||
public Vector2i[] getItemDropoffLocations();
|
||||
}
|
||||
Loading…
Reference in New Issue