-
Notifications
You must be signed in to change notification settings - Fork 3
/
menuid.lic
108 lines (92 loc) · 3.03 KB
/
menuid.lic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
=begin
When clicking on something in a menu in Stormfront, report its ID -- and other relevant information if available.
Also allows sending commands with an underscore directly to the game without Stormfront prefixing them with
"_cheater", which doesn't accomplish much anyways (since commands sent by Lich ignore that)
Primarily of use for script authors.
author: LostRanger ([email protected])
game: any
tags: utility
required: Lich >= 4.6.0.
version: 0.1 (2019-05-24)
changelog:
version 0.1 (2019-05-24)
* Initial release
=end
def format_type(what)
if (t = what.type)
return "type #{t}"
else
return "unknown type"
end
end
def locate_item(id)
if id == GameObj.right_hand.id then
return GameObj.right_hand, 'in your right hand'
elsif id == GameObj.left_hand.id then
return GameObj.left_hand, 'in your left hand'
elsif (what = GameObj.loot.find{|x| x.id == id})
return what, 'on the ground'
elsif (what = GameObj.inv.find{|x| x.id == id})
return what, 'on your person'
elsif (what = GameObj.room_desc.find{|x| x.id == id})
return what, 'in the room description'
end
end
def find_in_container(id)
GameObj.containers.each do |k, v|
if (what = v.find{|x| x.id == id})
return k, what
end
end
return nil
end
def try_to_identify(id)
# PCs are easy. Do them first
if (what = GameObj.pcs.find{|x| x.id == id})
respond "[[Player ##{id}: #{what.full_name} (noun=#{what.noun}) #{what.status or '(no status)'}]]"
return
# NPCs
elsif (what = GameObj.npcs.find{|x| x.id == id})
respond "[[NPC ##{id}: #{what.full_name} (noun=#{what.noun}) (#{format_type(what)}), #{what.status or '(no status)'}]]"
return
end
# Everything else. So, as far as we're concerned, an item
what, location = locate_item(id)
unless what
container_id, what = find_in_container(id) # GameObj.containers.find{|k,v| v.find{|x| x.id == id}}
if container_id
container, container_location = locate_item(container_id)
if container
location = "in container ##{container_id} '#{container.full_name}', which is #{container_location}"
else
location = "in an unknown container ##{container_id}"
end
else
respond "[[Item ##{id}, in an unknown location]]"
return
end
end
respond "[[#{GameObj.containers[id] && 'Container' || 'Item'} ##{id}: #{what.full_name} (noun=#{what.noun}) (#{format_type(what)}) #{location}]]"
return
end
unless $frontend == 'stormfront'
echo "This script requires Stormfront."
exit
end
before_dying do
UpstreamHook.remove("menuid.lic")
end
UpstreamHook.add("menuid.lic", proc {|line|
if line =~ /^<c>_(?:cheater (.*)|menu #(-?\d+).*)$/
if $1
"<c>#{$1}"
else
try_to_identify($2)
line
end
else
line
end
})
i_stand_alone
nil while unique_get