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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
local USE_EVENT_USE = 0x01
-- Returns true if the actor has the item or a container with the item
function actor_has_item(actor, obj)
local tobj = obj
while tobj.in_container do
tobj = tobj.parent
end
if tobj.on_map == false and
tobj.parent.luatype == "actor" and
tobj.parent.actor_num == actor.actor_num then
return true
end
return false
end
-- Check Reachable
-- A) Next to actor passed in
-- B) In inventory of any party member
-- Return actor that can reach object or nil
-- Optionally automatically print "Out of Range!" message
function check_can_reach(obj, actor, print_msg)
if math.abs(obj.x - actor.x) <= 1 and
math.abs(obj.y - actor.y) <= 1 and
obj.z == actor.z then
return actor
end
for party_member in party_members() do
if actor_has_item(party_member, obj) == true then
return party_member
end
end
if print_msg then
printl("OUT_OF_RANGE")
end
return nil
end
-- delete an object from inventory or remove it from the map
function delete_or_remove_object(actor, obj, qty)
-- FIXME: Remove the exact object from the Actor
if Actor.inv_has_obj_n(actor, obj.obj_n) then
if qty ~= nil then
Actor.inv_remove_obj_qty(actor, obj.obj_n, qty)
else
Actor.inv_remove_obj(actor, obj)
end
-- Remove the object from the map
else
if qty ~= nil then
map_remove_obj(obj, qty)
else
map_remove_obj(obj)
end
end
end
-- create and add item to actor, qty if stackable, drop if required to create the item,
-- obj_n: Item Code to Create
-- actor: actor to get the object
-- qty: how many (or nil)
-- drop_if_fail: if true, object gets put on the map on failure
-- print_msg: if true, prints the carry too much message on failure
function add_item_to_actor(obj_n, actor, qty, drop_if_fail, print_msg)
local new_obj = Obj.new(obj_n)
if qty ~= nil then
new_obj.qty = qty
else
new_obj.qty = 1
end
if Actor.can_carry_obj(actor, new_obj) then
if qty ~= nil then
Actor.inv_add_obj(actor, new_obj, STACK_OBJECT_QTY)
else
Actor.inv_add_obj(actor, new_obj, false)
end
else
if print_msg then
printl("CARRY_TOO_MUCH")
end
return false
end
return true
end
function use_corn_stalk(obj, actor)
local use_actor = check_can_reach(obj, actor, true)
if use_actor == nil then
return
end
if add_item_to_actor(108, use_actor, 1, false, true) == true then
printl("GOT_CORN")
end
end
function use_tree(obj, actor)
local use_actor = check_can_reach(obj, actor, true)
if use_actor == nil then
return
end
if add_item_to_actor(206, use_actor, 1, false, true) == true then
printl("USE_TREE")
end
end
function use_yucca_plant(obj, actor)
local use_actor = check_can_reach(obj, actor, true)
if use_actor == nil then
return
end
if add_item_to_actor(210, use_actor, 1, false, true) == true then
printl("USE_YUCCA_PLANT")
end
end
function use_clay(obj, actor)
local use_actor = check_can_reach(obj, actor, true)
if use_actor == nil then
return
end
-- delete clay
local location_code = delete_or_remove_object(use_actor, obj, nil)
if add_item_to_actor(132, use_actor, nil, false, false) == true then
printl("USE_CLAY")
end
-- TODO: IF ADD FAILED, PUT CLAY BACK WHERE IT WAS
end
function use_fishing_pole(obj, actor)
local use_actor = check_can_reach(obj, actor, true)
if use_actor == nil then
return
end
-- Check Deep Water
-- if <<Standing Next to Deep Water>> then
printl("USE_FISHING_POLE_NO_WATER")
-- end
-- Check Success
-- if random() == SUCCESS then
if add_item_to_actor(192, use_actor, nil, false, false) == true then
-- add_item without print
-- if SUCCESS then
printl("USE_FISHING_POLE_SUCCESS")
end
-- end
printl("USE_FISHING_POLE_FAIL")
end
function use_digging_stick(obj, actor)
local use_actor = check_can_reach(obj, actor, true)
if use_actor == nil then
return
end
-- Check Water
-- if <<Standing Next to Water>> then
printl("USE_DIGGING_STICK_NO_WATER")
-- end
if add_item_to_actor(192, use_actor, 1, false, true) == true then
printl("USE_DIGGING_STICK")
end
end
local usecode_table = {
[61]=use_corn_stalk,
[131]=use_digging_stick,
[192]=use_clay,
[212]=use_fishing_pole,
[5000]=use_tree,
[108]=use_tree,
[5001]=use_oven_or_fire,
[5002]=use_yucca_plant,
--[[
[62]=use_bean_stalk,
--[127]=use_bamboo_plant, -- confirmed
[132]=use_soft_clay_pot, -- confirmed
[133]=use_fired_clay_pot, -- confirmed
[134]=use_cloth_strip, -- confirmed
[191]=use_tarred_cloth_strip, -- confirmed
[210]=use_flax, -- confirmed
]]--
--[[
[10]=use_magnesium_ribbon, -- confirmed
[12]=use_paddle, -- confirmed
[20]={["on"]=use_rope},
[25]={["on"]=use_cutting_tool}, -- confirmed (obsidian knife)
[29]=use_rock_hammer, -- confirmed (rock hammer)
[42]=use_vine, -- confirmed (vine)
[44]={["on"]=use_cutting_tool}, -- confirmed (knife)
[47]=use_turtle_bait,
[51]=use_camera,
[52]={["on"]=use_cutting_tool}, -- confirmed (scissors)
[54]={["on"]=use_chocolatl}, --Original required using totem on reagent
[55]={["on"]=use_pinde}, -- confirmed
[56]={["on"]=use_yopo}, -- confirmed
[59]=use_grinding_stone, -- confirmed (mortar)
[60]=use_grinding_stone, -- confirmed (grinding stone)
[63]=use_jug_of_platcha,
[64]=use_torch,
[75]=standing_torch, -- confirmed (almost certainly can't use)
[86]=use_heluzz, -- confirmed
[87]=use_motazz, -- confirmed
[88]=use_aphazz, -- confirmed
[93]=use_corn_meal,
[94]=use_fire_extinguisher, -- confirmed
[102]=use_tortilla, -- confirmed
[108]=use_corn, -- confirmed
[118]=use_fire_axe, -- confirmed
[119]=use_metal_hammer, -- confirmed
[128]=use_bamboo_pole, -- confirmed
[136]=use_metal_bucket, -- confirmed
[137]=use_grenade, -- confirmed
[153]=use_vine(corn_stalk)???, -- confirmed
[206]=use_tree_branch, -- confirmed
[208]=use_torch,
[240]=use_device, -- confirmed Explosive Device
[267]=use_device2 -- confirmed Compass Device? USE?
]]--
}
function has_usecode(obj, usecode_type)
if usecode_type == USE_EVENT_USE and usecode_table[obj.obj_n] ~= nil then
return true
end
return false
end
function use_obj(obj, actor)
if type(usecode_table[obj.obj_n]) == "function" then
local func = usecode_table[obj.obj_n]
if func ~= nil then
print("\n")
func(obj, actor)
end
else
use_obj_on(obj, actor, usecode_table[obj.obj_n])
end
end
function move_obj(obj, rel_x, rel_y)
return false
end
function is_ranged_select(operation)
return false
end
|