From ba5f669dbebf16be7f9c202334efb69e7bdc49f8 Mon Sep 17 00:00:00 2001 From: Trevor Flynn Date: Sun, 10 Sep 2017 15:34:40 -0700 Subject: [PATCH 1/7] Initial commit --- game/src/plugins/skill/firemaking/meta.toml | 11 ++ .../skill/firemaking/src/fireamaking_data.kt | 27 ++++ .../firemaking/src/firemaking.plugin.kts | 150 ++++++++++++++++++ 3 files changed, 188 insertions(+) create mode 100644 game/src/plugins/skill/firemaking/meta.toml create mode 100644 game/src/plugins/skill/firemaking/src/fireamaking_data.kt create mode 100644 game/src/plugins/skill/firemaking/src/firemaking.plugin.kts diff --git a/game/src/plugins/skill/firemaking/meta.toml b/game/src/plugins/skill/firemaking/meta.toml new file mode 100644 index 000000000..8096a9885 --- /dev/null +++ b/game/src/plugins/skill/firemaking/meta.toml @@ -0,0 +1,11 @@ +name = "firemaking-skill" +package = "org.apollo.game.plugin.skill.firemaking" +authors = [ + "tlf30", + "lare96" + ] +dependencies = [ "entity_lookup" ] + +[config] +srcDir = "src/" +testDir = "test/" \ No newline at end of file diff --git a/game/src/plugins/skill/firemaking/src/fireamaking_data.kt b/game/src/plugins/skill/firemaking/src/fireamaking_data.kt new file mode 100644 index 000000000..31748ead0 --- /dev/null +++ b/game/src/plugins/skill/firemaking/src/fireamaking_data.kt @@ -0,0 +1,27 @@ +import org.apollo.game.model.Animation + +enum class Log(val id: Int, val level: Int, val xp: Double) { + NORMAL(1511, 1, 40.0), + ACHEY(2862, 1, 40.0), + OAK(1521, 15, 60.0), + WILLOW(1519, 30, 90.0), + TEAK(6333, 35, 105.0), + MAPLE(1517, 45, 135.0), + MAHOGANY(6332, 50, 157.5), + YEW(1515, 60, 202.5), + MAGIC(1513, 75, 303.8) +} + +val TINDER_BOX = 590 +val FIRE_OBJ = 2732 +val ASH = 592 +val LIGHT_ANIMATION = Animation(733) + +fun lookupLog(id: Int): Log? { + for (log in Log.values()) { + if (log.id == id) { + return log; + } + } + return null +} \ No newline at end of file diff --git a/game/src/plugins/skill/firemaking/src/firemaking.plugin.kts b/game/src/plugins/skill/firemaking/src/firemaking.plugin.kts new file mode 100644 index 000000000..cb990b1f0 --- /dev/null +++ b/game/src/plugins/skill/firemaking/src/firemaking.plugin.kts @@ -0,0 +1,150 @@ +import org.apollo.game.action.Action +import org.apollo.game.message.impl.ItemOnItemMessage +import org.apollo.game.model.Direction +import org.apollo.game.model.Item +import org.apollo.game.model.Position +import org.apollo.game.model.entity.* +import org.apollo.game.model.entity.obj.DynamicGameObject +import org.apollo.game.scheduling.ScheduledTask +import java.util.* +import kotlin.properties.Delegates + + +class FiremakingAction(val player: Player, val log: Log):Action(DELAY, true, player) { + + private var started = false + private var groundLog: GroundItem by Delegates.notNull() + val rand = Random() + + companion object { + private val DELAY = 0 + } + + override fun execute() { + mob.walkingQueue.clear() + //Check log level + if (log.level > player.skillSet.getSkill(Skill.FIREMAKING).currentLevel) { + player.sendMessage("You need a Firemaking level of " + log.level + " to light this log.") + stop() + return + } + + //check if we have a tinderbox + if (!player.inventory.contains(TINDER_BOX)) { + player.sendMessage("You need a tinderbox in your inventory in order to light fires.") + stop() + return + } + + if (!started) { + player.sendMessage("You attempt to light the logs.") + player.inventory.remove(log.id) + groundLog = GroundItem.dropped(player.world, player.position, Item(log.id), player) + player.world.spawn(groundLog) + started = true + } + + //light the fire + player.playAnimation(LIGHT_ANIMATION) + + if (successfulLight()) { + if (lightFire(Direction.WEST) || + lightFire(Direction.EAST) || + lightFire(Direction.NORTH) || + lightFire(Direction.SOUTH) || + lightFire(Direction.NONE) + ) { + player.sendMessage("The fire catches and the logs begin to burn.") + } else { + player.sendMessage("You cannot light a fire here.") + } + stop() + } + } + + override fun stop() { + super.stop() + player.stopAnimation() + } + + fun successfulLight(): Boolean { + //TODO: This is from lare96, as he mentioned, we need to find the actual chance + val playerLevel = player.skillSet.getSkill(Skill.FIREMAKING).currentLevel + val lowChance = playerLevel - log.level + 5 + if (lowChance > 30) { + return 30 > rand.nextInt(40) + } else { + return lowChance > rand.nextInt(40) + } + } + + fun walkCoords(direction: Direction): Position { + if (direction == Direction.NORTH) { + return Position(player.position.x, player.position.y + 1, player.position.height) + } else if (direction == Direction.SOUTH) { + return Position(player.position.x, player.position.y - 1, player.position.height) + } else if (direction == Direction.WEST) { + return Position(player.position.x - 1, player.position.y, player.position.height) + } else if (direction == Direction.EAST) { + return Position(player.position.x + 1, player.position.y, player.position.height) + } else if (direction == Direction.NONE) { + return Position(player.position.x, player.position.y, player.position.height) + } else { + return player.position //Should never happen so I just put this + } + } + + fun lightFire(direction: Direction): Boolean { + if (canLight(direction)) { + val fire = DynamicGameObject.createPublic(player.world, FIRE_OBJ, player.position, 10, 0) + val walkTo = walkCoords(direction) + if (walkTo != mob.position) { + mob.walkingQueue.addFirstStep(walkTo) + } + val region = player.world.regionRepository.fromPosition(player.position) + region.removeEntity(groundLog) + player.world.spawn(fire) + //burn time = log level * 5 + rand(30). I think this is right can someone verify? + + val burnTime = (log.level * 5 + rand.nextInt(30) * 1000) / 600 //convert to pulses + player.world.schedule(object: ScheduledTask(burnTime, false) { + override fun execute() { + region.removeEntity(fire) + player.world.spawn(GroundItem.create(player.world, fire.position, Item(ASH))) + this.stop() + } + + }) + return true + } + return false + } + + fun canLight(direction: Direction): Boolean { + val region = player.world.regionRepository.fromPosition(player.position) + if (region.getEntities(player.position, EntityType.DYNAMIC_OBJECT, EntityType.STATIC_OBJECT).isNotEmpty()) { + return false + } + if (direction == Direction.NONE) { + return true + } + if (region.traversable(player.position, EntityType.PLAYER, direction)) { + return true + } + return false + } + +} + + +on { ItemOnItemMessage::class } + .where { (id == TINDER_BOX && lookupLog(targetId) != null) || (targetId == TINDER_BOX && lookupLog(id) != null) } + .then { + if (id == TINDER_BOX) { + it.startAction(FiremakingAction(it, lookupLog(targetId)!!)) + terminate() + } else { + it.startAction(FiremakingAction(it, lookupLog(id)!!)) + terminate() + } + } \ No newline at end of file From 0b530d84b361c5f9ba753ffd46e5433871243819 Mon Sep 17 00:00:00 2001 From: Trevor Flynn Date: Sun, 10 Sep 2017 15:48:08 -0700 Subject: [PATCH 2/7] Fix xp --- .../firemaking/src/firemaking.plugin.kts | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/game/src/plugins/skill/firemaking/src/firemaking.plugin.kts b/game/src/plugins/skill/firemaking/src/firemaking.plugin.kts index cb990b1f0..eb31954e4 100644 --- a/game/src/plugins/skill/firemaking/src/firemaking.plugin.kts +++ b/game/src/plugins/skill/firemaking/src/firemaking.plugin.kts @@ -37,10 +37,17 @@ class FiremakingAction(val player: Player, val log: Log):Action(DELAY, t } if (!started) { + val region = player.world.regionRepository.fromPosition(player.position) player.sendMessage("You attempt to light the logs.") - player.inventory.remove(log.id) - groundLog = GroundItem.dropped(player.world, player.position, Item(log.id), player) - player.world.spawn(groundLog) + if (region.getEntities(player.position, EntityType.DYNAMIC_OBJECT, EntityType.STATIC_OBJECT).isEmpty()) { + player.inventory.remove(log.id) + groundLog = GroundItem.dropped(player.world, player.position, Item(log.id), player) + player.world.spawn(groundLog) + } else { + player.sendMessage("You cannot light a fire here.") + stop() + return + } started = true } @@ -55,6 +62,7 @@ class FiremakingAction(val player: Player, val log: Log):Action(DELAY, t lightFire(Direction.NONE) ) { player.sendMessage("The fire catches and the logs begin to burn.") + player.skillSet.addExperience(Skill.FIREMAKING, log.xp) } else { player.sendMessage("You cannot light a fire here.") } @@ -104,7 +112,8 @@ class FiremakingAction(val player: Player, val log: Log):Action(DELAY, t val region = player.world.regionRepository.fromPosition(player.position) region.removeEntity(groundLog) player.world.spawn(fire) - //burn time = log level * 5 + rand(30). I think this is right can someone verify? + + //TODO: burn time = log level * 5 + rand(30). I think this is right can someone verify? val burnTime = (log.level * 5 + rand.nextInt(30) * 1000) / 600 //convert to pulses player.world.schedule(object: ScheduledTask(burnTime, false) { @@ -122,9 +131,6 @@ class FiremakingAction(val player: Player, val log: Log):Action(DELAY, t fun canLight(direction: Direction): Boolean { val region = player.world.regionRepository.fromPosition(player.position) - if (region.getEntities(player.position, EntityType.DYNAMIC_OBJECT, EntityType.STATIC_OBJECT).isNotEmpty()) { - return false - } if (direction == Direction.NONE) { return true } From b4829bec303fb9d32b7f3d93c0ac76093e099fa0 Mon Sep 17 00:00:00 2001 From: Trevor Flynn Date: Sun, 10 Sep 2017 17:20:36 -0700 Subject: [PATCH 3/7] Simpler way to walk after making fire. --- .../firemaking/src/firemaking.plugin.kts | 20 +------------------ 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/game/src/plugins/skill/firemaking/src/firemaking.plugin.kts b/game/src/plugins/skill/firemaking/src/firemaking.plugin.kts index eb31954e4..914e7e844 100644 --- a/game/src/plugins/skill/firemaking/src/firemaking.plugin.kts +++ b/game/src/plugins/skill/firemaking/src/firemaking.plugin.kts @@ -86,29 +86,11 @@ class FiremakingAction(val player: Player, val log: Log):Action(DELAY, t } } - fun walkCoords(direction: Direction): Position { - if (direction == Direction.NORTH) { - return Position(player.position.x, player.position.y + 1, player.position.height) - } else if (direction == Direction.SOUTH) { - return Position(player.position.x, player.position.y - 1, player.position.height) - } else if (direction == Direction.WEST) { - return Position(player.position.x - 1, player.position.y, player.position.height) - } else if (direction == Direction.EAST) { - return Position(player.position.x + 1, player.position.y, player.position.height) - } else if (direction == Direction.NONE) { - return Position(player.position.x, player.position.y, player.position.height) - } else { - return player.position //Should never happen so I just put this - } - } fun lightFire(direction: Direction): Boolean { if (canLight(direction)) { val fire = DynamicGameObject.createPublic(player.world, FIRE_OBJ, player.position, 10, 0) - val walkTo = walkCoords(direction) - if (walkTo != mob.position) { - mob.walkingQueue.addFirstStep(walkTo) - } + player.walkingQueue.addFirstStep(player.position.step(1, direction)) val region = player.world.regionRepository.fromPosition(player.position) region.removeEntity(groundLog) player.world.spawn(fire) From 78cde12186965aecd28aa76f5962548c8c7b5036 Mon Sep 17 00:00:00 2001 From: Trevor Flynn Date: Wed, 13 Sep 2017 12:23:28 -0700 Subject: [PATCH 4/7] Code cleanup --- .../src/plugins/skill/firemaking/src/fireamaking_data.kt | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/game/src/plugins/skill/firemaking/src/fireamaking_data.kt b/game/src/plugins/skill/firemaking/src/fireamaking_data.kt index 31748ead0..4a130159d 100644 --- a/game/src/plugins/skill/firemaking/src/fireamaking_data.kt +++ b/game/src/plugins/skill/firemaking/src/fireamaking_data.kt @@ -17,11 +17,4 @@ val FIRE_OBJ = 2732 val ASH = 592 val LIGHT_ANIMATION = Animation(733) -fun lookupLog(id: Int): Log? { - for (log in Log.values()) { - if (log.id == id) { - return log; - } - } - return null -} \ No newline at end of file +fun lookupLog(id: Int): Log? = Log.values().find { it.id == id } \ No newline at end of file From 15ba396e9d6fb2d210337339ec1ddab4e0896883 Mon Sep 17 00:00:00 2001 From: Trevor Flynn Date: Sat, 16 Sep 2017 10:01:39 -0700 Subject: [PATCH 5/7] Fix reallocating new array for enums on lookup --- game/src/plugins/skill/firemaking/src/fireamaking_data.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/game/src/plugins/skill/firemaking/src/fireamaking_data.kt b/game/src/plugins/skill/firemaking/src/fireamaking_data.kt index 4a130159d..01bb8bd6b 100644 --- a/game/src/plugins/skill/firemaking/src/fireamaking_data.kt +++ b/game/src/plugins/skill/firemaking/src/fireamaking_data.kt @@ -17,4 +17,6 @@ val FIRE_OBJ = 2732 val ASH = 592 val LIGHT_ANIMATION = Animation(733) -fun lookupLog(id: Int): Log? = Log.values().find { it.id == id } \ No newline at end of file +val LOGS = Log.values() + +fun lookupLog(id: Int): Log? = LOGS.find { it.id == id } \ No newline at end of file From 6405e9dc98cbed9656ad5ae7e795d26c09ac6013 Mon Sep 17 00:00:00 2001 From: Trevor Flynn Date: Sat, 16 Sep 2017 17:13:56 -0700 Subject: [PATCH 6/7] Update to new kotlin plugin build system. --- game/plugin/skill/firemaking/build.gradle | 11 +++++++++++ .../plugins => plugin}/skill/firemaking/meta.toml | 2 +- .../skill/firemaking/src/fireamaking_data.kt | 0 .../skill/firemaking/src/firemaking.plugin.kts | 0 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 game/plugin/skill/firemaking/build.gradle rename game/{src/plugins => plugin}/skill/firemaking/meta.toml (87%) rename game/{src/plugins => plugin}/skill/firemaking/src/fireamaking_data.kt (100%) rename game/{src/plugins => plugin}/skill/firemaking/src/firemaking.plugin.kts (100%) diff --git a/game/plugin/skill/firemaking/build.gradle b/game/plugin/skill/firemaking/build.gradle new file mode 100644 index 000000000..593754757 --- /dev/null +++ b/game/plugin/skill/firemaking/build.gradle @@ -0,0 +1,11 @@ +plugin { + name = "firemaking_skill" + packageName = "org.apollo.game.plugin.banking" + authors = [ + "tlf30", + "lare96" + ] + dependencies = [ + "util:lookup", + ] +} \ No newline at end of file diff --git a/game/src/plugins/skill/firemaking/meta.toml b/game/plugin/skill/firemaking/meta.toml similarity index 87% rename from game/src/plugins/skill/firemaking/meta.toml rename to game/plugin/skill/firemaking/meta.toml index 8096a9885..7ce607e9e 100644 --- a/game/src/plugins/skill/firemaking/meta.toml +++ b/game/plugin/skill/firemaking/meta.toml @@ -1,4 +1,4 @@ -name = "firemaking-skill" +name = "firemaking_skill" package = "org.apollo.game.plugin.skill.firemaking" authors = [ "tlf30", diff --git a/game/src/plugins/skill/firemaking/src/fireamaking_data.kt b/game/plugin/skill/firemaking/src/fireamaking_data.kt similarity index 100% rename from game/src/plugins/skill/firemaking/src/fireamaking_data.kt rename to game/plugin/skill/firemaking/src/fireamaking_data.kt diff --git a/game/src/plugins/skill/firemaking/src/firemaking.plugin.kts b/game/plugin/skill/firemaking/src/firemaking.plugin.kts similarity index 100% rename from game/src/plugins/skill/firemaking/src/firemaking.plugin.kts rename to game/plugin/skill/firemaking/src/firemaking.plugin.kts From 65c535ee1f6e6de4eed010366c0225d330d4e77f Mon Sep 17 00:00:00 2001 From: Trevor Flynn Date: Sat, 16 Sep 2017 17:30:22 -0700 Subject: [PATCH 7/7] Fix wrong class path Fix wrong class path --- game/plugin/skill/firemaking/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game/plugin/skill/firemaking/build.gradle b/game/plugin/skill/firemaking/build.gradle index 593754757..64570b914 100644 --- a/game/plugin/skill/firemaking/build.gradle +++ b/game/plugin/skill/firemaking/build.gradle @@ -1,6 +1,6 @@ plugin { name = "firemaking_skill" - packageName = "org.apollo.game.plugin.banking" + packageName = "org.apollo.game.plugin.skills.firemaking" authors = [ "tlf30", "lare96" @@ -8,4 +8,4 @@ plugin { dependencies = [ "util:lookup", ] -} \ No newline at end of file +}