Skip to content

Commit 735a9c8

Browse files
committed
Move Player extensions to Summoning.kt and timers to their own file
1 parent a5b7699 commit 735a9c8

File tree

3 files changed

+140
-131
lines changed

3 files changed

+140
-131
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,111 @@
11
package content.skill.summoning
22

3+
import world.gregs.voidps.cache.definition.data.NPCDefinition
4+
import world.gregs.voidps.engine.client.message
5+
import world.gregs.voidps.engine.data.definition.EnumDefinitions
6+
import world.gregs.voidps.engine.data.definition.ItemDefinitions
37
import world.gregs.voidps.engine.entity.character.Character
8+
import world.gregs.voidps.engine.entity.character.mode.Follow
9+
import world.gregs.voidps.engine.entity.character.move.tele
410
import world.gregs.voidps.engine.entity.character.npc.NPC
11+
import world.gregs.voidps.engine.entity.character.npc.NPCs
12+
import world.gregs.voidps.engine.entity.character.player.Player
13+
import world.gregs.voidps.engine.entity.item.Item
14+
import world.gregs.voidps.engine.inject
15+
import world.gregs.voidps.engine.inv.inventory
16+
import world.gregs.voidps.engine.inv.remove
17+
import world.gregs.voidps.engine.queue.softQueue
18+
19+
val itemDefinitions: ItemDefinitions by inject()
20+
val npcs: NPCs by inject()
21+
val enums: EnumDefinitions by inject()
22+
523

624
val Character?.isFamiliar: Boolean
725
get() = this != null && this is NPC && id.endsWith("_familiar")
26+
27+
var Player.follower: NPC?
28+
get() {
29+
val index = this["follower_index", -1]
30+
return world.gregs.voidps.engine.get<NPCs>().indexed(index)
31+
}
32+
set(value) {
33+
if (value != null) {
34+
this["follower_index"] = value.index
35+
this["follower_id"] = value.id
36+
}
37+
}
38+
39+
fun Player.summonFamiliar(familiar: NPCDefinition, restart: Boolean): NPC? {
40+
if (follower != null) {
41+
// TODO: Find actual message for this
42+
message("You must dismiss your current follower before summoning another.")
43+
return null
44+
}
45+
46+
val familiarNpc = npcs.add(familiar.stringId, tile)
47+
familiarNpc.mode = Follow(familiarNpc, this)
48+
49+
softQueue("summon_familiar", 2) {
50+
follower = familiarNpc
51+
52+
follower!!.gfx("summon_familiar_size_${follower!!.size}")
53+
player.updateFamiliarInterface()
54+
if(!restart) timers.start("familiar_timer")
55+
}
56+
57+
return familiarNpc
58+
}
59+
60+
fun Player.dismissFamiliar() {
61+
npcs.remove(follower)
62+
follower = null
63+
interfaces.close("familiar_details")
64+
65+
this["follower_details_name"] = 0
66+
this["follower_details_chathead"] = 0
67+
this["familiar_details_minutes_remaining"] = 0
68+
this["familiar_details_seconds_remaining"] = 0
69+
timers.stop("familiar_timer")
70+
}
71+
72+
fun Player.updateFamiliarInterface() {
73+
if (follower == null) return
74+
75+
this.interfaces.open("familiar_details")
76+
77+
this["follower_details_name"] = enums.get("summoning_familiar_ids").getKey(follower!!.def.id)
78+
this["follower_details_chathead"] = follower!!.def.id
79+
80+
this["follower_details_chathead_animation"] = 1
81+
}
82+
83+
fun Player.openFollowerLeftClickOptions() {
84+
interfaces.open("follower_left_click_options")
85+
}
86+
87+
fun Player.confirmFollowerLeftClickOptions() {
88+
this["summoning_orb_left_click_option"] = this["summoning_menu_left_click_option", -1]
89+
interfaces.close("follower_left_click_options")
90+
}
91+
92+
fun Player.callFollower() {
93+
follower!!.tele(steps.follow, clearMode = false)
94+
follower!!.clearWatch()
95+
}
96+
97+
fun Player.renewFamiliar() {
98+
val pouchId = enums.get("summoning_familiar_ids").getKey(follower!!.def.id)
99+
val pouchItem = Item(itemDefinitions.get(pouchId).stringId)
100+
101+
if (!inventory.contains(pouchItem.id)) {
102+
// TODO: Find the actual message used here in 2011
103+
message("You don't have the required pouch to renew your familiar.")
104+
return
105+
}
106+
107+
inventory.remove(pouchItem.id)
108+
this["familiar_details_minutes_remaining"] = follower!!.def["summoning_time_minutes", 0]
109+
this["familiar_details_seconds_remaining"] = 0
110+
follower!!.gfx("summon_familiar_size_${follower!!.size}")
111+
}

game/src/main/kotlin/content/skill/summoning/Summoning.kts

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,18 @@ package content.skill.summoning
22

33
import content.entity.player.dialogue.type.choice
44
import content.entity.player.inv.inventoryItem
5-
import world.gregs.voidps.cache.definition.data.NPCDefinition
65
import world.gregs.voidps.engine.client.message
76
import world.gregs.voidps.engine.client.ui.interfaceOption
87
import world.gregs.voidps.engine.data.definition.EnumDefinitions
9-
import world.gregs.voidps.engine.data.definition.ItemDefinitions
108
import world.gregs.voidps.engine.data.definition.NPCDefinitions
11-
import world.gregs.voidps.engine.entity.character.mode.Follow
12-
import world.gregs.voidps.engine.entity.character.move.tele
13-
import world.gregs.voidps.engine.entity.character.npc.NPC
14-
import world.gregs.voidps.engine.entity.character.npc.NPCs
15-
import world.gregs.voidps.engine.entity.character.player.Player
169
import world.gregs.voidps.engine.entity.character.player.skill.Skill
17-
import world.gregs.voidps.engine.entity.item.Item
1810
import world.gregs.voidps.engine.entity.playerSpawn
1911
import world.gregs.voidps.engine.inject
2012
import world.gregs.voidps.engine.inv.inventory
2113
import world.gregs.voidps.engine.inv.remove
22-
import world.gregs.voidps.engine.queue.softQueue
23-
import world.gregs.voidps.engine.timer.timerStart
24-
import world.gregs.voidps.engine.timer.timerStop
25-
import world.gregs.voidps.engine.timer.timerTick
2614

2715
val enums: EnumDefinitions by inject()
28-
val npcs: NPCs by inject()
2916
val npcDefinitions: NPCDefinitions by inject()
30-
val itemDefinitions: ItemDefinitions by inject()
31-
32-
var Player.follower: NPC?
33-
get() {
34-
val index = this["follower_index", -1]
35-
return world.gregs.voidps.engine.get<NPCs>().indexed(index)
36-
}
37-
set(value) {
38-
if (value != null) {
39-
this["follower_index"] = value.index
40-
this["follower_id"] = value.id
41-
}
42-
}
4317

4418
inventoryItem("Summon", "*_pouch") {
4519
val familiarLevel = enums.get("summoning_pouch_levels").getInt(item.def.id)
@@ -128,109 +102,4 @@ playerSpawn {player ->
128102
player.variables.send("follower_details_chathead_animation")
129103
player.timers.restart("familiar_timer")
130104
player.summonFamiliar(familiarDef, true)
131-
}
132-
133-
fun Player.summonFamiliar(familiar: NPCDefinition, restart: Boolean): NPC? {
134-
if (follower != null) {
135-
// TODO: Find actual message for this
136-
message("You must dismiss your current follower before summoning another.")
137-
return null
138-
}
139-
140-
val familiarNpc = npcs.add(familiar.stringId, tile)
141-
familiarNpc.mode = Follow(familiarNpc, this)
142-
143-
softQueue("summon_familiar", 2) {
144-
follower = familiarNpc
145-
146-
follower!!.gfx("summon_familiar_size_${follower!!.size}")
147-
player.updateFamiliarInterface()
148-
if(!restart) timers.start("familiar_timer")
149-
}
150-
151-
return familiarNpc
152-
}
153-
154-
fun Player.dismissFamiliar() {
155-
npcs.remove(follower)
156-
follower = null
157-
interfaces.close("familiar_details")
158-
159-
this["follower_details_name"] = 0
160-
this["follower_details_chathead"] = 0
161-
this["familiar_details_minutes_remaining"] = 0
162-
this["familiar_details_seconds_remaining"] = 0
163-
timers.stop("familiar_timer")
164-
}
165-
166-
fun Player.updateFamiliarInterface() {
167-
if (follower == null) return
168-
169-
this.interfaces.open("familiar_details")
170-
171-
this["follower_details_name"] = enums.get("summoning_familiar_ids").getKey(follower!!.def.id)
172-
this["follower_details_chathead"] = follower!!.def.id
173-
174-
this["follower_details_chathead_animation"] = 1
175-
}
176-
177-
fun Player.openFollowerLeftClickOptions() {
178-
interfaces.open("follower_left_click_options")
179-
}
180-
181-
fun Player.confirmFollowerLeftClickOptions() {
182-
this["summoning_orb_left_click_option"] = this["summoning_menu_left_click_option", -1]
183-
interfaces.close("follower_left_click_options")
184-
}
185-
186-
fun Player.callFollower() {
187-
follower!!.tele(steps.follow, clearMode = false)
188-
follower!!.clearWatch()
189-
}
190-
191-
fun Player.renewFamiliar() {
192-
val pouchId = enums.get("summoning_familiar_ids").getKey(follower!!.def.id)
193-
val pouchItem = Item(itemDefinitions.get(pouchId).stringId)
194-
195-
if (!inventory.contains(pouchItem.id)) {
196-
// TODO: Find the actual message used here in 2011
197-
message("You don't have the required pouch to renew your familiar.")
198-
return
199-
}
200-
201-
inventory.remove(pouchItem.id)
202-
this["familiar_details_minutes_remaining"] = follower!!.def["summoning_time_minutes", 0]
203-
this["familiar_details_seconds_remaining"] = 0
204-
follower!!.gfx("summon_familiar_size_${follower!!.size}")
205-
}
206-
207-
timerStart("familiar_timer") {player ->
208-
interval = 50 // 30 seconds
209-
210-
if(!restart) {
211-
player["familiar_details_minutes_remaining"] = player.follower!!.def["summoning_time_minutes", 0]
212-
player["familiar_details_seconds_remaining"] = 0
213-
}
214-
}
215-
216-
timerTick("familiar_timer") {player ->
217-
if (player["familiar_details_seconds_remaining", 0] == 0) {
218-
player.dec("familiar_details_minutes_remaining")
219-
}
220-
player["familiar_details_seconds_remaining"] = (player["familiar_details_seconds_remaining", 0] + 1) % 2
221-
222-
if (player["familiar_details_seconds_remaining", 0] <= 0 && player["familiar_details_minutes_remaining", 0] <= 0) {
223-
cancel()
224-
}
225-
}
226-
227-
timerStop("familiar_timer") {player ->
228-
if (logout) {
229-
npcs.remove(player.follower)
230-
return@timerStop
231-
}
232-
233-
if (player.follower != null) {
234-
player.dismissFamiliar()
235-
}
236105
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package content.skill.summoning
2+
3+
import world.gregs.voidps.engine.timer.timerStart
4+
import world.gregs.voidps.engine.timer.timerStop
5+
import world.gregs.voidps.engine.timer.timerTick
6+
7+
timerStart("familiar_timer") {player ->
8+
interval = 50 // 30 seconds
9+
10+
if(!restart) {
11+
player["familiar_details_minutes_remaining"] = player.follower!!.def["summoning_time_minutes", 0]
12+
player["familiar_details_seconds_remaining"] = 0
13+
}
14+
}
15+
16+
timerTick("familiar_timer") {player ->
17+
if (player["familiar_details_seconds_remaining", 0] == 0) {
18+
player.dec("familiar_details_minutes_remaining")
19+
}
20+
player["familiar_details_seconds_remaining"] = (player["familiar_details_seconds_remaining", 0] + 1) % 2
21+
22+
if (player["familiar_details_seconds_remaining", 0] <= 0 && player["familiar_details_minutes_remaining", 0] <= 0) {
23+
cancel()
24+
}
25+
}
26+
27+
timerStop("familiar_timer") {player ->
28+
if (logout) {
29+
npcs.remove(player.follower)
30+
return@timerStop
31+
}
32+
33+
if (player.follower != null) {
34+
player.dismissFamiliar()
35+
}
36+
}

0 commit comments

Comments
 (0)