More obstacle WIP

This commit is contained in:
simon 2019-07-18 11:21:33 -04:00
parent 3266cbd32d
commit d5b10b9b04
9 changed files with 70 additions and 45 deletions

View File

@ -6,7 +6,6 @@
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<artifactId>maven-resources-plugin</artifactId> <artifactId>maven-resources-plugin</artifactId>

View File

@ -46,9 +46,6 @@ public class GameRegistry {
if (hardware.containsKey(type)) { if (hardware.containsKey(type)) {
try { try {
System.out.println(type);
System.out.println(hardware.get(type));
return hardware.get(type).getConstructor(Document.class, ControllableUnit.class).newInstance(document, controllableUnit); return hardware.get(type).getConstructor(Document.class, ControllableUnit.class).newInstance(document, controllableUnit);
} catch (InstantiationException | IllegalAccessException | } catch (InstantiationException | IllegalAccessException |
InvocationTargetException | NoSuchMethodException e) { InvocationTargetException | NoSuchMethodException e) {

View File

@ -67,6 +67,10 @@ public class World implements MongoSerializable {
return getGameObjectsBlockingAt(x, y).size() > 0 || tileMap.getTileAt(x, y).isBlocked(); return getGameObjectsBlockingAt(x, y).size() > 0 || tileMap.getTileAt(x, y).isBlocked();
} }
public boolean canBuild(int x, int y) {
return x == 0 || y == 0 || x == worldSize-1 || y == worldSize-1;
}
/** /**
* Computes the world's unique id from its coordinates. * Computes the world's unique id from its coordinates.
* *

View File

@ -97,4 +97,7 @@ radioactive_obstacle_corruption_block_size=10
#SecretKey #SecretKey
secret_key=<your_secret_key> secret_key=<your_secret_key>
# Construction # Construction
construction_site_ttl=512 construction_site_ttl=1024
obstacle_regen=1
obstacle_hp=150

View File

@ -1,12 +1,8 @@
var __extends = (this && this.__extends) || (function () { var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) { var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf || extendStatics = Object.setPrototypeOf ||
({__proto__: []} instanceof Array && function (d, b) { ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
d.__proto__ = b; function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
}) ||
function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
};
return extendStatics(d, b); return extendStatics(d, b);
}; };
return function (d, b) { return function (d, b) {
@ -476,13 +472,13 @@ var Debug = (function () {
mar.client.sendDebugCommand({ t: "debug", command: "setEnergy", objectId: objectId, amount: amount }); mar.client.sendDebugCommand({ t: "debug", command: "setEnergy", objectId: objectId, amount: amount });
}; };
Debug.saveGame = function () { Debug.saveGame = function () {
mar.client.sendDebugCommand({t: "debug", command: "saveGame"}); mar.client.sendDebugCommand({ t: "debug", command: "saveGame" });
}; };
Debug.popItem = function (objectId) { Debug.popItem = function (objectId) {
mar.client.sendDebugCommand({t: "debug", command: "popItem", objectId: objectId}); mar.client.sendDebugCommand({ t: "debug", command: "popItem", objectId: objectId });
}; };
Debug.putItem = function (objectId, item) { Debug.putItem = function (objectId, item) {
mar.client.sendDebugCommand({t: "debug", command: "putItem", objectId: objectId, item: item}); mar.client.sendDebugCommand({ t: "debug", command: "putItem", objectId: objectId, item: item });
}; };
Debug.setInventoryPosition = function (objectId, position) { Debug.setInventoryPosition = function (objectId, position) {
mar.client.sendDebugCommand({ mar.client.sendDebugCommand({
@ -588,9 +584,11 @@ var AuthListener = (function () {
console.log("[MAR] Auth successful"); console.log("[MAR] Auth successful");
} }
mar.client.requestUserInfo(); mar.client.requestUserInfo();
} else if (message.m == "forbidden") { }
else if (message.m == "forbidden") {
alert("Authentication failed. Guest accounts are blocked on this server"); alert("Authentication failed. Guest accounts are blocked on this server");
} else { }
else {
alert("Authentication failed. Please make sure you are logged in and reload the page."); alert("Authentication failed. Please make sure you are logged in and reload the page.");
} }
}; };
@ -746,9 +744,7 @@ var GameClient = (function () {
if (DEBUG) { if (DEBUG) {
console.log("[MAR] Received server info " + xhr.responseText); console.log("[MAR] Received server info " + xhr.responseText);
} }
setTimeout(function () { setTimeout(function () { return self.connectToGameServer(JSON.parse(xhr.responseText)); }, 100);
return self.connectToGameServer(JSON.parse(xhr.responseText));
}, 100);
} }
}; };
xhr.send(null); xhr.send(null);
@ -828,7 +824,6 @@ var GameClient = (function () {
}; };
return GameClient; return GameClient;
}()); }());
var game = PIXI.game;
var ObjectType; var ObjectType;
(function (ObjectType) { (function (ObjectType) {
ObjectType["CUBOT"] = "net.simon987.cubotplugin.Cubot"; ObjectType["CUBOT"] = "net.simon987.cubotplugin.Cubot";
@ -1227,7 +1222,8 @@ var HarvesterNPC = (function (_super) {
HarvesterNPC.prototype.getEnergy = function (json) { HarvesterNPC.prototype.getEnergy = function (json) {
if (json.hasOwnProperty("net.simon987.npcplugin.NpcBattery")) { if (json.hasOwnProperty("net.simon987.npcplugin.NpcBattery")) {
return json["net.simon987.npcplugin.NpcBattery"].energy; return json["net.simon987.npcplugin.NpcBattery"].energy;
} else { }
else {
return 1000; return 1000;
} }
}; };
@ -1458,7 +1454,6 @@ var ElectricBox = (function (_super) {
}(GameObject)); }(GameObject));
var Obstacle = (function (_super) { var Obstacle = (function (_super) {
__extends(Obstacle, _super); __extends(Obstacle, _super);
function Obstacle(json) { function Obstacle(json) {
var _this = _super.call(this, Util.getIsoX(json.x), Util.getIsoY(json.y), 15, "sheet", "objects/obstacle") || this; var _this = _super.call(this, Util.getIsoX(json.x), Util.getIsoY(json.y), 15, "sheet", "objects/obstacle") || this;
_this.anchor.set(0.5, 0.3); _this.anchor.set(0.5, 0.3);
@ -1470,28 +1465,26 @@ var Obstacle = (function (_super) {
_this.tileY = json.y; _this.tileY = json.y;
return _this; return _this;
} }
Obstacle.prototype.updateObject = function (json) { Obstacle.prototype.updateObject = function (json) {
}; };
Obstacle.prototype.onTileHover = function () { Obstacle.prototype.onTileHover = function () {
mar.game.tweens.removeFrom(this); mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 25}, 200, Phaser.Easing.Quadratic.InOut, true); mar.game.add.tween(this).to({ isoZ: 25 }, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this.scale).to({x: 1.1, y: 1.1}, 200, Phaser.Easing.Linear.None, true); mar.game.add.tween(this.scale).to({ x: 1.1, y: 1.1 }, 200, Phaser.Easing.Linear.None, true);
this.tint = config.cubot.hoverTint; this.tint = config.cubot.hoverTint;
this.text.visible = true; this.text.visible = true;
}; };
Obstacle.prototype.onTileExit = function () { Obstacle.prototype.onTileExit = function () {
mar.game.tweens.removeFrom(this); mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 15}, 400, Phaser.Easing.Bounce.Out, true); mar.game.add.tween(this).to({ isoZ: 15 }, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({x: 1, y: 1}, 200, Phaser.Easing.Linear.None, true); mar.game.add.tween(this.scale).to({ x: 1, y: 1 }, 200, Phaser.Easing.Linear.None, true);
this.tint = config.portal.tint; this.tint = config.obstacle.tint;
this.text.visible = false; this.text.visible = false;
}; };
return Obstacle; return Obstacle;
}(GameObject)); }(GameObject));
var ConstructionSite = (function (_super) { var ConstructionSite = (function (_super) {
__extends(ConstructionSite, _super); __extends(ConstructionSite, _super);
function ConstructionSite(json) { function ConstructionSite(json) {
var _this = _super.call(this, Util.getIsoX(json.x), Util.getIsoY(json.y), 15, "sheet", ConstructionSite.getTargetSprite(json.blueprint.target)) || this; var _this = _super.call(this, Util.getIsoX(json.x), Util.getIsoY(json.y), 15, "sheet", ConstructionSite.getTargetSprite(json.blueprint.target)) || this;
_this.anchor.set(0.5, 0.31); _this.anchor.set(0.5, 0.31);
@ -1504,7 +1497,6 @@ var ConstructionSite = (function (_super) {
_this.tileY = json.y; _this.tileY = json.y;
return _this; return _this;
} }
ConstructionSite.getTargetSprite = function (targetType) { ConstructionSite.getTargetSprite = function (targetType) {
switch (targetType) { switch (targetType) {
case ObjectType.OBSTACLE: case ObjectType.OBSTACLE:
@ -1514,20 +1506,20 @@ var ConstructionSite = (function (_super) {
ConstructionSite.prototype.updateObject = function (json) { ConstructionSite.prototype.updateObject = function (json) {
}; };
ConstructionSite.prototype.setUpAlphaTween = function () { ConstructionSite.prototype.setUpAlphaTween = function () {
var alphaTween = mar.game.add.tween(this).to({alpha: 0.5}, 2000, Phaser.Easing.Linear.None, true, 0, -1); var alphaTween = mar.game.add.tween(this).to({ alpha: 0.5 }, 2000, Phaser.Easing.Linear.None, true, 0, -1);
alphaTween.yoyo(true, 3000); alphaTween.yoyo(true, 3000);
}; };
ConstructionSite.prototype.onTileHover = function () { ConstructionSite.prototype.onTileHover = function () {
mar.game.tweens.removeFrom(this); mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 19}, 200, Phaser.Easing.Quadratic.InOut, true); mar.game.add.tween(this).to({ isoZ: 19 }, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this.scale).to({x: 1.03, y: 1.03}, 200, Phaser.Easing.Linear.None, true); mar.game.add.tween(this.scale).to({ x: 1.03, y: 1.03 }, 200, Phaser.Easing.Linear.None, true);
this.setUpAlphaTween(); this.setUpAlphaTween();
this.text.visible = true; this.text.visible = true;
}; };
ConstructionSite.prototype.onTileExit = function () { ConstructionSite.prototype.onTileExit = function () {
mar.game.tweens.removeFrom(this); mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 15}, 400, Phaser.Easing.Bounce.Out, true); mar.game.add.tween(this).to({ isoZ: 15 }, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({x: 1.03, y: 1.03}, 200, Phaser.Easing.Linear.None, true); mar.game.add.tween(this.scale).to({ x: 1.03, y: 1.03 }, 200, Phaser.Easing.Linear.None, true);
this.setUpAlphaTween(); this.setUpAlphaTween();
this.text.visible = false; this.text.visible = false;
}; };
@ -1730,7 +1722,7 @@ var MagneticTile = (function (_super) {
return _this; return _this;
} }
MagneticTile.prototype.onHover = function () { MagneticTile.prototype.onHover = function () {
mar.game.add.tween(this).to({isoZ: this.baseZ + 30}, 200, Phaser.Easing.Quadratic.InOut, true); mar.game.add.tween(this).to({ isoZ: this.baseZ + 30 }, 200, Phaser.Easing.Quadratic.InOut, true);
mar.tileIndicator.tileX = this.tileX; mar.tileIndicator.tileX = this.tileX;
mar.tileIndicator.tileY = this.tileY; mar.tileIndicator.tileY = this.tileY;
mar.tileIndicator.tileType = this.tileType; mar.tileIndicator.tileType = this.tileType;

View File

@ -883,7 +883,7 @@ class Obstacle extends GameObject {
mar.game.tweens.removeFrom(this); mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 15}, 400, Phaser.Easing.Bounce.Out, true); mar.game.add.tween(this).to({isoZ: 15}, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({x: 1, y: 1}, 200, Phaser.Easing.Linear.None, true); mar.game.add.tween(this.scale).to({x: 1, y: 1}, 200, Phaser.Easing.Linear.None, true);
this.tint = config.portal.tint; this.tint = config.obstacle.tint;
this.text.visible = false; this.text.visible = false;
} }

View File

@ -57,7 +57,8 @@ public class ConstructionArmHardware extends HardwareModule {
Point frontTile = unit.getFrontTile(); Point frontTile = unit.getFrontTile();
if (unit.getWorld().isTileBlocked(frontTile.x, frontTile.y)) { if (unit.getWorld().isTileBlocked(frontTile.x, frontTile.y) ||
unit.getWorld().canBuild(frontTile.x, frontTile.y)) {
regB.setValue(ERR_TILE_BLOCKED); regB.setValue(ERR_TILE_BLOCKED);
return; return;
} }
@ -68,9 +69,10 @@ public class ConstructionArmHardware extends HardwareModule {
} }
GameObject constructionSite = new ConstructionSite(bluePrint); GameObject constructionSite = new ConstructionSite(bluePrint);
constructionSite.setObjectId(new ObjectId());
constructionSite.setWorld(unit.getWorld());
constructionSite.setX(frontTile.x); constructionSite.setX(frontTile.x);
constructionSite.setY(frontTile.y); constructionSite.setY(frontTile.y);
constructionSite.setObjectId(new ObjectId());
unit.getWorld().addObject(constructionSite); unit.getWorld().addObject(constructionSite);
regB.setValue(OK); regB.setValue(OK);

View File

@ -2,12 +2,14 @@ package net.simon987.constructionplugin;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.game.item.Item; import net.simon987.server.game.item.Item;
import net.simon987.server.game.objects.InventoryHolder; import net.simon987.server.game.objects.*;
import net.simon987.server.game.objects.Structure; import net.simon987.server.game.world.World;
import net.simon987.server.game.objects.Updatable;
import org.bson.Document; import org.bson.Document;
import org.bson.types.ObjectId;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import java.lang.reflect.InvocationTargetException;
public class ConstructionSite extends Structure implements Updatable, InventoryHolder { public class ConstructionSite extends Structure implements Updatable, InventoryHolder {
public static final int MAP_INFO = 0xFFFF; //TODO: determine public static final int MAP_INFO = 0xFFFF; //TODO: determine
@ -47,7 +49,31 @@ public class ConstructionSite extends Structure implements Updatable, InventoryH
@Override @Override
public boolean placeItem(Item item) { public boolean placeItem(Item item) {
return bluePrint.placeItem(item); boolean ok = bluePrint.placeItem(item);
if (ok && bluePrint.isCompleted()) {
instantiateTargetObject();
setDead(true);
}
return ok;
}
private void instantiateTargetObject() {
Class<? extends GameObject> targetClass = bluePrint.getTargetObject();
try {
GameObject targetObj = targetClass.getConstructor().newInstance();
targetObj.setWorld(getWorld());
targetObj.setObjectId(new ObjectId());
targetObj.setX(getX());
targetObj.setY(getY());
getWorld().addObject(targetObj);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
}
} }
@Override @Override

View File

@ -18,13 +18,15 @@ public class Obstacle extends Structure implements Attackable, Updatable {
public Obstacle() { public Obstacle() {
super(1, 1); super(1, 1);
setHp(MAX_HP);
} }
public Obstacle(Document document) { public Obstacle(Document document) {
super(document, 1, 1); super(document, 1, 1);
hp = document.getInteger(hp); hp = document.getInteger("hp");
color = document.getInteger(color); color = document.getInteger("color");
} }
@Override @Override