Add skill extension properties

This commit is contained in:
Major
2017-09-24 19:44:17 +01:00
parent 8c2f086ae5
commit b4e8a7136b
5 changed files with 161 additions and 103 deletions
+49 -45
View File
@@ -5,52 +5,47 @@ import org.apollo.game.message.impl.ObjectActionMessage
import org.apollo.game.model.Position
import org.apollo.game.model.World
import org.apollo.game.model.entity.Player
import org.apollo.game.model.entity.Skill
import org.apollo.game.model.entity.obj.GameObject
import org.apollo.game.plugin.api.mining
import org.apollo.game.plugin.skills.mining.Ore
import org.apollo.game.plugin.skills.mining.PICKAXES
import org.apollo.game.plugin.skills.mining.Pickaxe
import org.apollo.game.plugin.skills.mining.lookupOreRock
import org.apollo.game.plugins.api.Definitions
import org.apollo.game.plugins.api.mining
import org.apollo.game.plugins.api.skills
import org.apollo.net.message.Message
import java.util.*
import java.util.Optional
class MiningTarget(val objectId: Int, val position: Position, val ore: Ore) {
fun getObject(world: World): Optional<GameObject> {
val region = world.regionRepository.fromPosition(position)
val obj = region.findObject(position, objectId)
return obj
return region.findObject(position, objectId)
}
fun isSuccessful(mob: Player): Boolean {
val offset = if (ore.chanceOffset) 1 else 0
val percent = (ore.chance * mob.skills.mining.currentLevel + offset) * 100
val percent = (ore.chance * mob.mining.current + offset) * 100
return rand(100) < percent;
return rand(100) < percent
}
}
class MiningAction(player: Player, val tool: Pickaxe, val target: MiningTarget) : AsyncDistancedAction<Player>(
PULSES,
true,
player,
target.position,
ORE_SIZE
) {
class MiningAction(
player: Player,
private val tool: Pickaxe,
private val target: MiningTarget
) : AsyncDistancedAction<Player>(PULSES, true, player, target.position, ORE_SIZE) {
companion object {
private val PULSES = 0
private val ORE_SIZE = 1;
private val ORE_SIZE = 1
fun pickaxeFor(player: Player): Pickaxe? {
return PICKAXES
.filter { it.level <= player.skills.mining.currentLevel }
.filter { player.equipment.contains(it.id) || player.inventory.contains(it.id) }
.sortedByDescending { it.level }
.firstOrNull()
.filter { it.level <= player.mining.current }
.filter { player.equipment.contains(it.id) || player.inventory.contains(it.id) }
.sortedByDescending { it.level }
.firstOrNull()
}
/**
@@ -69,10 +64,10 @@ class MiningAction(player: Player, val tool: Pickaxe, val target: MiningTarget)
}
}
override fun action() : ActionBlock = {
override fun action(): ActionBlock = {
mob.turnTo(position)
val level = mob.skills.mining.currentLevel
val level = mob.mining.current
if (level < target.ore.level) {
mob.sendMessage("You do not have the required level to mine this rock.")
stop()
@@ -98,7 +93,7 @@ class MiningAction(player: Player, val tool: Pickaxe, val target: MiningTarget)
val oreName = Definitions.item(target.ore.id)?.name?.toLowerCase()
mob.sendMessage("You manage to mine some $oreName")
mob.skills.addExperience(Skill.MINING, target.ore.exp)
mob.mining.experience += target.ore.exp
mob.world.expireObject(obj.get(), target.ore.objects[target.objectId]!!, target.ore.respawn)
stop()
}
@@ -106,25 +101,32 @@ class MiningAction(player: Player, val tool: Pickaxe, val target: MiningTarget)
}
}
class ExpiredProspectingAction : DistancedAction<Player> {
constructor(mob: Player, position: Position) : super(PROSPECT_PULSES, true, mob, position, ORE_SIZE)
class ExpiredProspectingAction(
mob: Player,
position: Position
) : DistancedAction<Player>(PROSPECT_PULSES, true, mob, position, ORE_SIZE) {
companion object {
private val PROSPECT_PULSES = 0
private val ORE_SIZE = 1;
private val ORE_SIZE = 1
}
override fun executeAction() {
mob.sendMessage("There is currently no ore available in this rock.")
stop();
stop()
}
}
class ProspectingAction(val m: Player, val p: Position, val ore: Ore) : AsyncDistancedAction<Player>(PROSPECT_PULSES, true, m, p, ORE_SIZE) {
class ProspectingAction(
player: Player,
position: Position,
private val ore: Ore
) : AsyncDistancedAction<Player>(PROSPECT_PULSES, true, player, position, ORE_SIZE) {
companion object {
private val PROSPECT_PULSES = 3
private val ORE_SIZE = 1;
private val ORE_SIZE = 1
/**
* Starts a [MiningAction] for the specified [Player], terminating the [Message] that triggered it.
@@ -135,9 +137,10 @@ class ProspectingAction(val m: Player, val p: Position, val ore: Ore) : AsyncDis
message.terminate()
}
}
override fun action() : ActionBlock = {
override fun action(): ActionBlock = {
mob.sendMessage("You examine the rock for ores...")
mob.turnTo(position)
@@ -148,22 +151,23 @@ class ProspectingAction(val m: Player, val p: Position, val ore: Ore) : AsyncDis
stop()
}
}
on { ObjectActionMessage::class }
.where { option == 1 }
.then {
val ore = lookupOreRock(id)
if (ore != null) {
MiningAction.start(this, it, ore)
}
.where { option == 1 }
.then {
val ore = lookupOreRock(id)
if (ore != null) {
MiningAction.start(this, it, ore)
}
}
on { ObjectActionMessage::class }
.where { option == 2 }
.then {
var ore = lookupOreRock(id)
if (ore != null) {
ProspectingAction.start(this, it, ore)
}
.where { option == 2 }
.then {
val ore = lookupOreRock(id)
if (ore != null) { // TODO send expired action if rock is expired
ProspectingAction.start(this, it, ore)
}
}