diff --git a/packages/junon-common/protocol/enum.proto b/packages/junon-common/protocol/enum.proto index e619ca4e..e33c2a8a 100644 --- a/packages/junon-common/protocol/enum.proto +++ b/packages/junon-common/protocol/enum.proto @@ -266,6 +266,7 @@ enum BuildingType { UnbreakableWall = 270; Dynamite = 271; MiasmaGate = 272; + Scythe = 273; } enum TerrainType { diff --git a/packages/junon-io/client/assets/images/scythe.png b/packages/junon-io/client/assets/images/scythe.png new file mode 100644 index 00000000..0dd3edac Binary files /dev/null and b/packages/junon-io/client/assets/images/scythe.png differ diff --git a/packages/junon-io/client/src/entities/equipments/hand/scythe.js b/packages/junon-io/client/src/entities/equipments/hand/scythe.js new file mode 100644 index 00000000..fb9d9d5a --- /dev/null +++ b/packages/junon-io/client/src/entities/equipments/hand/scythe.js @@ -0,0 +1,58 @@ +const MeleeEquipment = require("./melee_equipment") +const Protocol = require('../../../../common/util/protocol') +const Constants = require("../../../../common/constants.json") + +class Pitchfork extends MeleeEquipment { + + getType() { + return Protocol.definition().BuildingType.Pitchfork + } + + getConstantsTable() { + return "Equipments.Pitchfork" + } + + use(player, targetEntity) { + if (targetEntity && targetEntity.isCrop && targetEntity.isCrop()) { + // interact with the crop (harvest/destroy fully grown) + if (targetEntity.isFullyGrown && targetEntity.isFullyGrown()) { + targetEntity.interact(player) + + // destroy left and right fully grown crops + this._destroyNeighbors(player, targetEntity) + } + } else { + // fallback to normal melee use + super.use(player, targetEntity) + } + } + + _destroyNeighbors(player, target) { + const x = target.getX() + const y = target.getY() + const room = target.room + + if (!room) return + + const neighbors = [ + room.getTile(x - 1, y), + room.getTile(x + 1, y) + ] + + neighbors.forEach(tile => { + if (!tile) return + + const crop = tile.getBuilding && tile.getBuilding() + + if (crop && crop.isCrop && crop.isCrop() && crop.isFullyGrown && crop.isFullyGrown()) { + if (crop.interact) { + crop.interact(player) + } else if (crop.breakBuilding) { + crop.breakBuilding(player) + } + } + }) + } +} + +module.exports = Pitchfork \ No newline at end of file diff --git a/packages/junon-io/client/src/entities/equipments/index.js b/packages/junon-io/client/src/entities/equipments/index.js index 7eceb89a..38530352 100644 --- a/packages/junon-io/client/src/entities/equipments/index.js +++ b/packages/junon-io/client/src/entities/equipments/index.js @@ -22,6 +22,7 @@ Equipments.BloodBottle = require("./hand/blood_bottle") Equipments.WaterBottle = require("./hand/water_bottle") Equipments.Disinfectant = require("./hand/disinfectant") Equipments.Lighter = require("./hand/lighter") +Equipments.Scythe = require("./hand/scythe") Equipments.Wrench = require("./hand/wrench") Equipments.SurvivalTool = require("./hand/survival_tool") Equipments.Drill = require("./hand/drill") diff --git a/packages/junon-io/common/constants.json b/packages/junon-io/common/constants.json index 9cc3fd55..3078db74 100644 --- a/packages/junon-io/common/constants.json +++ b/packages/junon-io/common/constants.json @@ -3912,6 +3912,25 @@ "cost": { "gold": 1000 }, + "Scythe": { + "parent": "Equipments.MeleeEquipment", + "isWeapon": true, + "cost": { + "gold": 350 + }, + "categories": {"melee_damage": true}, + "isAnimatable": true, + "stats": { + "damage": 12, + "range": 55, + "meleeRange": 55 + }, + "requirements": { + "IronBar": 30, + "Wood":10 + }, + "description": "Farms crops to left and right. Can be seconded as a weapon" + }, "categories": {"melee_damage": true}, "isAnimatable": true, "stats": { diff --git a/packages/junon-io/server/entities/equipments/index.js b/packages/junon-io/server/entities/equipments/index.js index 1e4c55f6..6f5cf799 100644 --- a/packages/junon-io/server/entities/equipments/index.js +++ b/packages/junon-io/server/entities/equipments/index.js @@ -13,6 +13,7 @@ Equipments.FireExtinguisher = require("./hand/fire_extinguisher") Equipments.Syringe = require("./hand/syringe") Equipments.FlameThrower = require("./hand/flame_thrower") Equipments.Mop = require("./hand/mop") +Equipments.Scythe = require("./hand/scythe") Equipments.Bottle = require("./hand/bottle") Equipments.BloodBottle = require("./hand/blood_bottle") Equipments.WaterBottle = require("./hand/water_bottle") diff --git a/packages/junon-io/server/entities/equipments/scythe.js b/packages/junon-io/server/entities/equipments/scythe.js new file mode 100644 index 00000000..a62ea31e --- /dev/null +++ b/packages/junon-io/server/entities/equipments/scythe.js @@ -0,0 +1,58 @@ +const MeleeEquipment = require("./melee_equipment") +const Protocol = require('../../../../common/util/protocol') +const Constants = require("../../../../common/constants.json") + +class Scythe extends MeleeEquipment { + + getType() { + return Protocol.definition().BuildingType.Scythe + } + + getConstantsTable() { + return "Equipments.Scythe" + } + + use(player, targetEntity) { + if (targetEntity && targetEntity.isCrop && targetEntity.isCrop()) { + // interact with the crop (harvest/destroy fully grown) + if (targetEntity.isFullyGrown && targetEntity.isFullyGrown()) { + targetEntity.interact(player) + + // destroy left and right fully grown crops + this._destroyNeighbors(player, targetEntity) + } + } else { + // fallback to normal melee use + super.use(player, targetEntity) + } + } + + _destroyNeighbors(player, target) { + const x = target.getX() + const y = target.getY() + const room = target.room + + if (!room) return + + const neighbors = [ + room.getTile(x - 1, y), + room.getTile(x + 1, y) + ] + + neighbors.forEach(tile => { + if (!tile) return + + const crop = tile.getBuilding && tile.getBuilding() + + if (crop && crop.isCrop && crop.isCrop() && crop.isFullyGrown && crop.isFullyGrown()) { + if (crop.interact) { + crop.interact(player) + } else if (crop.breakBuilding) { + crop.breakBuilding(player) + } + } + }) + } +} + +module.exports = Scythe \ No newline at end of file