From d5b10b9b04733245fcb3e5769404b46b6e919083 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 18 Jul 2019 11:21:33 -0400 Subject: [PATCH] More obstacle WIP --- Server/pom.xml | 1 - .../server/game/objects/GameRegistry.java | 3 -- .../net/simon987/server/game/world/World.java | 4 ++ Server/src/main/resources/config.properties | 5 +- Server/src/main/resources/static/js/mar.js | 54 ++++++++----------- Server/src/main/typescript/GameObject.ts | 2 +- .../ConstructionArmHardware.java | 6 ++- .../constructionplugin/ConstructionSite.java | 34 ++++++++++-- .../simon987/constructionplugin/Obstacle.java | 6 ++- 9 files changed, 70 insertions(+), 45 deletions(-) diff --git a/Server/pom.xml b/Server/pom.xml index af0a44f..efee0a7 100644 --- a/Server/pom.xml +++ b/Server/pom.xml @@ -6,7 +6,6 @@ - maven-resources-plugin diff --git a/Server/src/main/java/net/simon987/server/game/objects/GameRegistry.java b/Server/src/main/java/net/simon987/server/game/objects/GameRegistry.java index 17e1840..add111d 100644 --- a/Server/src/main/java/net/simon987/server/game/objects/GameRegistry.java +++ b/Server/src/main/java/net/simon987/server/game/objects/GameRegistry.java @@ -46,9 +46,6 @@ public class GameRegistry { if (hardware.containsKey(type)) { try { - System.out.println(type); - System.out.println(hardware.get(type)); - return hardware.get(type).getConstructor(Document.class, ControllableUnit.class).newInstance(document, controllableUnit); } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { diff --git a/Server/src/main/java/net/simon987/server/game/world/World.java b/Server/src/main/java/net/simon987/server/game/world/World.java index 3e73cb2..01b48b8 100644 --- a/Server/src/main/java/net/simon987/server/game/world/World.java +++ b/Server/src/main/java/net/simon987/server/game/world/World.java @@ -67,6 +67,10 @@ public class World implements MongoSerializable { 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. * diff --git a/Server/src/main/resources/config.properties b/Server/src/main/resources/config.properties index 49a4cf7..8d03180 100644 --- a/Server/src/main/resources/config.properties +++ b/Server/src/main/resources/config.properties @@ -97,4 +97,7 @@ radioactive_obstacle_corruption_block_size=10 #SecretKey secret_key= # Construction -construction_site_ttl=512 +construction_site_ttl=1024 +obstacle_regen=1 +obstacle_hp=150 + diff --git a/Server/src/main/resources/static/js/mar.js b/Server/src/main/resources/static/js/mar.js index c0541cd..2ad8a1d 100644 --- a/Server/src/main/resources/static/js/mar.js +++ b/Server/src/main/resources/static/js/mar.js @@ -1,12 +1,8 @@ var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || - ({__proto__: []} instanceof Array && function (d, b) { - d.__proto__ = b; - }) || - function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - }; + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { @@ -476,13 +472,13 @@ var Debug = (function () { mar.client.sendDebugCommand({ t: "debug", command: "setEnergy", objectId: objectId, amount: amount }); }; Debug.saveGame = function () { - mar.client.sendDebugCommand({t: "debug", command: "saveGame"}); + mar.client.sendDebugCommand({ t: "debug", command: "saveGame" }); }; 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) { - 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) { mar.client.sendDebugCommand({ @@ -588,9 +584,11 @@ var AuthListener = (function () { console.log("[MAR] Auth successful"); } mar.client.requestUserInfo(); - } else if (message.m == "forbidden") { + } + else if (message.m == "forbidden") { 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."); } }; @@ -746,9 +744,7 @@ var GameClient = (function () { if (DEBUG) { console.log("[MAR] Received server info " + xhr.responseText); } - setTimeout(function () { - return self.connectToGameServer(JSON.parse(xhr.responseText)); - }, 100); + setTimeout(function () { return self.connectToGameServer(JSON.parse(xhr.responseText)); }, 100); } }; xhr.send(null); @@ -828,7 +824,6 @@ var GameClient = (function () { }; return GameClient; }()); -var game = PIXI.game; var ObjectType; (function (ObjectType) { ObjectType["CUBOT"] = "net.simon987.cubotplugin.Cubot"; @@ -1227,7 +1222,8 @@ var HarvesterNPC = (function (_super) { HarvesterNPC.prototype.getEnergy = function (json) { if (json.hasOwnProperty("net.simon987.npcplugin.NpcBattery")) { return json["net.simon987.npcplugin.NpcBattery"].energy; - } else { + } + else { return 1000; } }; @@ -1458,7 +1454,6 @@ var ElectricBox = (function (_super) { }(GameObject)); var Obstacle = (function (_super) { __extends(Obstacle, _super); - function Obstacle(json) { 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); @@ -1470,28 +1465,26 @@ var Obstacle = (function (_super) { _this.tileY = json.y; return _this; } - Obstacle.prototype.updateObject = function (json) { }; Obstacle.prototype.onTileHover = function () { mar.game.tweens.removeFrom(this); - 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).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); this.tint = config.cubot.hoverTint; this.text.visible = true; }; Obstacle.prototype.onTileExit = function () { mar.game.tweens.removeFrom(this); - 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); - this.tint = config.portal.tint; + 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); + this.tint = config.obstacle.tint; this.text.visible = false; }; return Obstacle; }(GameObject)); var ConstructionSite = (function (_super) { __extends(ConstructionSite, _super); - function ConstructionSite(json) { 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); @@ -1504,7 +1497,6 @@ var ConstructionSite = (function (_super) { _this.tileY = json.y; return _this; } - ConstructionSite.getTargetSprite = function (targetType) { switch (targetType) { case ObjectType.OBSTACLE: @@ -1514,20 +1506,20 @@ var ConstructionSite = (function (_super) { ConstructionSite.prototype.updateObject = function (json) { }; 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); }; ConstructionSite.prototype.onTileHover = function () { mar.game.tweens.removeFrom(this); - 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).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); this.setUpAlphaTween(); this.text.visible = true; }; ConstructionSite.prototype.onTileExit = function () { mar.game.tweens.removeFrom(this); - 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).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); this.setUpAlphaTween(); this.text.visible = false; }; @@ -1730,7 +1722,7 @@ var MagneticTile = (function (_super) { return _this; } 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.tileY = this.tileY; mar.tileIndicator.tileType = this.tileType; diff --git a/Server/src/main/typescript/GameObject.ts b/Server/src/main/typescript/GameObject.ts index ba2eb14..7bea17f 100644 --- a/Server/src/main/typescript/GameObject.ts +++ b/Server/src/main/typescript/GameObject.ts @@ -883,7 +883,7 @@ class Obstacle extends GameObject { mar.game.tweens.removeFrom(this); 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); - this.tint = config.portal.tint; + this.tint = config.obstacle.tint; this.text.visible = false; } diff --git a/plugin-contruction/src/main/java/net/simon987/constructionplugin/ConstructionArmHardware.java b/plugin-contruction/src/main/java/net/simon987/constructionplugin/ConstructionArmHardware.java index 0ca6e11..00f9dd9 100644 --- a/plugin-contruction/src/main/java/net/simon987/constructionplugin/ConstructionArmHardware.java +++ b/plugin-contruction/src/main/java/net/simon987/constructionplugin/ConstructionArmHardware.java @@ -57,7 +57,8 @@ public class ConstructionArmHardware extends HardwareModule { 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); return; } @@ -68,9 +69,10 @@ public class ConstructionArmHardware extends HardwareModule { } GameObject constructionSite = new ConstructionSite(bluePrint); + constructionSite.setObjectId(new ObjectId()); + constructionSite.setWorld(unit.getWorld()); constructionSite.setX(frontTile.x); constructionSite.setY(frontTile.y); - constructionSite.setObjectId(new ObjectId()); unit.getWorld().addObject(constructionSite); regB.setValue(OK); diff --git a/plugin-contruction/src/main/java/net/simon987/constructionplugin/ConstructionSite.java b/plugin-contruction/src/main/java/net/simon987/constructionplugin/ConstructionSite.java index 76e4e10..b9c92ab 100644 --- a/plugin-contruction/src/main/java/net/simon987/constructionplugin/ConstructionSite.java +++ b/plugin-contruction/src/main/java/net/simon987/constructionplugin/ConstructionSite.java @@ -2,12 +2,14 @@ package net.simon987.constructionplugin; import net.simon987.server.GameServer; import net.simon987.server.game.item.Item; -import net.simon987.server.game.objects.InventoryHolder; -import net.simon987.server.game.objects.Structure; -import net.simon987.server.game.objects.Updatable; +import net.simon987.server.game.objects.*; +import net.simon987.server.game.world.World; import org.bson.Document; +import org.bson.types.ObjectId; import org.json.simple.JSONObject; +import java.lang.reflect.InvocationTargetException; + public class ConstructionSite extends Structure implements Updatable, InventoryHolder { public static final int MAP_INFO = 0xFFFF; //TODO: determine @@ -47,7 +49,31 @@ public class ConstructionSite extends Structure implements Updatable, InventoryH @Override 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 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 diff --git a/plugin-contruction/src/main/java/net/simon987/constructionplugin/Obstacle.java b/plugin-contruction/src/main/java/net/simon987/constructionplugin/Obstacle.java index 9c4d765..853d9f7 100644 --- a/plugin-contruction/src/main/java/net/simon987/constructionplugin/Obstacle.java +++ b/plugin-contruction/src/main/java/net/simon987/constructionplugin/Obstacle.java @@ -18,13 +18,15 @@ public class Obstacle extends Structure implements Attackable, Updatable { public Obstacle() { super(1, 1); + + setHp(MAX_HP); } public Obstacle(Document document) { super(document, 1, 1); - hp = document.getInteger(hp); - color = document.getInteger(color); + hp = document.getInteger("hp"); + color = document.getInteger("color"); } @Override