-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added firemaking plugin for Kotlin #349
Open
tlf30
wants to merge
7
commits into
apollo-rsps:kotlin-experiments
Choose a base branch
from
tlf30:kotlin-experiments-firemaking
base: kotlin-experiments
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ba5f669
Initial commit
tlf30 0b530d8
Fix xp
tlf30 b4829be
Simpler way to walk after making fire.
tlf30 78cde12
Code cleanup
tlf30 15ba396
Fix reallocating new array for enums on lookup
tlf30 6405e9d
Update to new kotlin plugin build system.
tlf30 65c535e
Fix wrong class path
tlf30 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
plugin { | ||
name = "firemaking_skill" | ||
packageName = "org.apollo.game.plugin.skills.firemaking" | ||
authors = [ | ||
"tlf30", | ||
"lare96" | ||
] | ||
dependencies = [ | ||
"util:lookup", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
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) | ||
|
||
val LOGS = Log.values() | ||
|
||
fun lookupLog(id: Int): Log? = LOGS.find { it.id == id } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
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<Player>(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) { | ||
val region = player.world.regionRepository.fromPosition(player.position) | ||
player.sendMessage("You attempt to light the logs.") | ||
if (region.getEntities<Entity>(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 | ||
} | ||
|
||
//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.") | ||
player.skillSet.addExperience(Skill.FIREMAKING, log.xp) | ||
} 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 lightFire(direction: Direction): Boolean { | ||
if (canLight(direction)) { | ||
val fire = DynamicGameObject.createPublic(player.world, FIRE_OBJ, player.position, 10, 0) | ||
player.walkingQueue.addFirstStep(player.position.step(1, direction)) | ||
val region = player.world.regionRepository.fromPosition(player.position) | ||
region.removeEntity(groundLog) | ||
player.world.spawn(fire) | ||
|
||
//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) { | ||
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 (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() | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Major- didn't you write something in Ruby to handle these ItemOnItem pairs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed it because it wasn't very good, maybe we could look into something for kotlin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the ItemOnItemMessage not the correct way to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No this is correct, we're just discussing how we can make it a bit nicer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, ok