@@ -5,52 +5,47 @@ import org.apollo.game.message.impl.ObjectActionMessage
55import org.apollo.game.model.Position
66import org.apollo.game.model.World
77import org.apollo.game.model.entity.Player
8- import org.apollo.game.model.entity.Skill
98import org.apollo.game.model.entity.obj.GameObject
9+ import org.apollo.game.plugin.api.mining
1010import org.apollo.game.plugin.skills.mining.Ore
1111import org.apollo.game.plugin.skills.mining.PICKAXES
1212import org.apollo.game.plugin.skills.mining.Pickaxe
1313import org.apollo.game.plugin.skills.mining.lookupOreRock
14- import org.apollo.game.plugins.api.Definitions
15- import org.apollo.game.plugins.api.mining
16- import org.apollo.game.plugins.api.skills
1714import org.apollo.net.message.Message
18- import java.util.*
15+ import java.util.Optional
1916
2017class MiningTarget (val objectId : Int , val position : Position , val ore : Ore ) {
18+
2119 fun getObject (world : World ): Optional <GameObject > {
2220 val region = world.regionRepository.fromPosition(position)
23- val obj = region.findObject(position, objectId)
24-
25- return obj
21+ return region.findObject(position, objectId)
2622 }
2723
2824 fun isSuccessful (mob : Player ): Boolean {
2925 val offset = if (ore.chanceOffset) 1 else 0
30- val percent = (ore.chance * mob.skills. mining.currentLevel + offset) * 100
26+ val percent = (ore.chance * mob.mining.current + offset) * 100
3127
32- return rand(100 ) < percent;
28+ return rand(100 ) < percent
3329 }
30+
3431}
3532
36- class MiningAction (player : Player , val tool : Pickaxe , val target : MiningTarget ) : AsyncDistancedAction<Player>(
37- PULSES ,
38- true ,
39- player,
40- target.position,
41- ORE_SIZE
42- ) {
33+ class MiningAction (
34+ player : Player ,
35+ private val tool : Pickaxe ,
36+ private val target : MiningTarget
37+ ) : AsyncDistancedAction<Player>(PULSES , true , player, target.position, ORE_SIZE ) {
4338
4439 companion object {
4540 private val PULSES = 0
46- private val ORE_SIZE = 1 ;
41+ private val ORE_SIZE = 1
4742
4843 fun pickaxeFor (player : Player ): Pickaxe ? {
4944 return PICKAXES
50- .filter { it.level <= player.skills. mining.currentLevel }
51- .filter { player.equipment.contains(it.id) || player.inventory.contains(it.id) }
52- .sortedByDescending { it.level }
53- .firstOrNull()
45+ .filter { it.level <= player.mining.current }
46+ .filter { player.equipment.contains(it.id) || player.inventory.contains(it.id) }
47+ .sortedByDescending { it.level }
48+ .firstOrNull()
5449 }
5550
5651 /* *
@@ -69,10 +64,10 @@ class MiningAction(player: Player, val tool: Pickaxe, val target: MiningTarget)
6964 }
7065 }
7166
72- override fun action () : ActionBlock = {
67+ override fun action (): ActionBlock = {
7368 mob.turnTo(position)
7469
75- val level = mob.skills. mining.currentLevel
70+ val level = mob.mining.current
7671 if (level < target.ore.level) {
7772 mob.sendMessage(" You do not have the required level to mine this rock." )
7873 stop()
@@ -98,33 +93,40 @@ class MiningAction(player: Player, val tool: Pickaxe, val target: MiningTarget)
9893 val oreName = Definitions .item(target.ore.id)?.name?.toLowerCase()
9994 mob.sendMessage(" You manage to mine some $oreName " )
10095
101- mob.skills.addExperience( Skill . MINING , target.ore.exp)
96+ mob.mining.experience + = target.ore.exp
10297 mob.world.expireObject(obj.get(), target.ore.objects[target.objectId]!! , target.ore.respawn)
10398 stop()
10499 }
105100 }
106101 }
107102}
108103
109- class ExpiredProspectingAction : DistancedAction <Player > {
110-
111- constructor (mob: Player , position: Position ) : super (PROSPECT_PULSES , true , mob, position, ORE_SIZE )
104+ class ExpiredProspectingAction (
105+ mob : Player ,
106+ position : Position
107+ ) : DistancedAction<Player>(PROSPECT_PULSES , true , mob, position, ORE_SIZE ) {
112108
113109 companion object {
114110 private val PROSPECT_PULSES = 0
115- private val ORE_SIZE = 1 ;
111+ private val ORE_SIZE = 1
116112 }
117113
118114 override fun executeAction () {
119115 mob.sendMessage(" There is currently no ore available in this rock." )
120- stop();
116+ stop()
121117 }
118+
122119}
123120
124- class ProspectingAction (val m : Player , val p : Position , val ore : Ore ) : AsyncDistancedAction<Player>(PROSPECT_PULSES , true , m, p, ORE_SIZE ) {
121+ class ProspectingAction (
122+ player : Player ,
123+ position : Position ,
124+ private val ore : Ore
125+ ) : AsyncDistancedAction<Player>(PROSPECT_PULSES , true , player, position, ORE_SIZE ) {
126+
125127 companion object {
126128 private val PROSPECT_PULSES = 3
127- private val ORE_SIZE = 1 ;
129+ private val ORE_SIZE = 1
128130
129131 /* *
130132 * 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
135137
136138 message.terminate()
137139 }
140+
138141 }
139142
140- override fun action () : ActionBlock = {
143+ override fun action (): ActionBlock = {
141144 mob.sendMessage(" You examine the rock for ores..." )
142145 mob.turnTo(position)
143146
@@ -148,22 +151,23 @@ class ProspectingAction(val m: Player, val p: Position, val ore: Ore) : AsyncDis
148151
149152 stop()
150153 }
154+
151155}
152156
153157on { ObjectActionMessage ::class }
154- .where { option == 1 }
155- .then {
156- val ore = lookupOreRock(id)
157- if (ore != null ) {
158- MiningAction .start(this , it, ore)
159- }
158+ .where { option == 1 }
159+ .then {
160+ val ore = lookupOreRock(id)
161+ if (ore != null ) {
162+ MiningAction .start(this , it, ore)
160163 }
164+ }
161165
162166on { ObjectActionMessage ::class }
163- .where { option == 2 }
164- .then {
165- var ore = lookupOreRock(id)
166- if (ore != null ) {
167- ProspectingAction .start(this , it, ore)
168- }
167+ .where { option == 2 }
168+ .then {
169+ val ore = lookupOreRock(id)
170+ if (ore != null ) { // TODO send expired action if rock is expired
171+ ProspectingAction .start(this , it, ore)
169172 }
173+ }
0 commit comments