123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
# ---------=====----++---
# Using an item on an item
# ---------=====----++---
def handle_use_item(msg, client)
incoming_itemid = msg["message"]["itemid"].as_i64
on_itemid = msg["message"]["on_itemid"].as_i64
return unless zone = client.in_zone_obj
tabid = msg["message"]["tabid"].as_i
tabid_on = msg["message"]["tabid_on"].as_i
if (item = client.get_item(incoming_itemid, tabid)) && (on_item = client.get_item(on_itemid, tabid_on))
main_item = Items[item[1]]
main_on_item = Items[on_item[1]]
main_on_item_type = main_on_item["type"]
raise "Oh lord." if incoming_itemid == on_itemid
raise "Can't modify equipped items." if on_item[4] >= 1
raise "This item has no quantity left, it should be deleted.." if item[3] <= 0
raise "Can't modify an item with items in it" if on_item[15].size > 0 && !{"rune_extractor", "improve_quality", "rune_cleanser", "identify"}.includes? main_item["func"] # the rune extractor and rune_cleanser can!
raise "Runes, Skills, or Misc items cannot be modified." if {"Skills", "Misc", "Runes"}.includes? main_on_item["type"]
raise "Unidentified items cannot be modified, unless identifying them." if on_item[6] == 0 && !{"identify"}.includes? main_item["func"] # the scroll of wisdom can modify items
# 3 = q, 5 = sockets
new_item_quantity = item[3] - 1
# What mods does the item already have?
current_item_mods = select_mods_from_item(on_item)
case main_item["func"]
# Removes all runes from an item
when "rune_extractor"
possible_runes = Array(Int64).new
temp_hash = colon_comma_to_hash(on_item[15])
temp_hash.each do |v|
sock_pos = v[0]
id_in_socket = v[1]
if on_item[5][sock_pos]? && on_item[5][sock_pos] == '3'
possible_runes << id_in_socket
temp_hash.delete sock_pos
end
end
raise "No runes found in this item." if possible_runes.size == 0
new_sockets = on_item[5].gsub '3', '0'
client.stash[tabid].items[incoming_itemid] = modify_item_tuple(item, 3, new_item_quantity)
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], 15, colon_comma_to_s(temp_hash))
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], 5, new_sockets)
client.send ({a: 6, q: new_item_quantity, itemid: incoming_itemid}), "ITEMUPDATE"
removed = create_runeword(client, on_item[5], on_item[15], main_on_item["type"], on_itemid, true) # true = remove runeword mods..
if !removed
client.send ({a: 8, on_itemid: on_itemid, new_item_data: client.stash[tabid_on].items[on_itemid]}), "ITEMUPDATE"
end
possible_runes.each do |rune_item_id|
new_rune_item = generate_item_by_id(rune_item_id)
new_x = (client.x + Random.new.rand(-50..50)).round
new_y = (client.y + Random.new.rand(-50..50)).round
zone.drop_item(new_rune_item, new_x, new_y)
end
# client.send ({a: 8, new_sockets: new_sockets, new_socket_data: colon_comma_to_s(temp_hash), on_itemid: on_itemid}), "SOCKETUPDATE"
db.exec "update rpg_user_items set sockets = ?, socket_data = ? where itemid = ? and user_id = ?", new_sockets, colon_comma_to_s(temp_hash), on_itemid, client.user_id
# Upgrades a normal item to a magic rarity
when "transmute_orb"
raise "Item must be normal rarity." if current_item_mods.size > 0
mod_rolls = Array(String).new
query_update = QueryUpdate.new
if main_on_item["type"] == "Weapons"
mod_rolls = ModGlobalWeapons.dup
mod_rolls = mod_rolls.shuffle.first(2)
elsif main_on_item["type"] == "Capsules"
new_extra_mods_value = roll_random_map_mods(2, on_item[24])
query_update["extra_mods"] = new_extra_mods_value
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], 24, new_extra_mods_value)
else # assume boots/armors
mod_rolls = ModGlobalArmors.dup
if main_on_item["type"] == "Gloves"
mod_rolls << "i_atk_speed"
end
mod_rolls = mod_rolls.shuffle.first(2)
end
mod_rolls.each do |mod_key|
roll = rand
mod_struct = GlobalItemModsMapping[mod_key].select { |v| roll < v.mod_chance }.last
final_roll_value = rand(mod_struct.min_value..mod_struct.max_value)
query_update[mod_struct.mod_type] = final_roll_value
tuple_index = GlobalItemTuple.index(mod_struct.mod_type)
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], tuple_index, final_roll_value)
end
if query_update.size > 0
db.exec "update rpg_user_items set #{hash_to_delimited_query_list(query_update)} where itemid = ? and user_id = ?", on_itemid, client.user_id
client.send ({a: 4, new_data: query_update, q: new_item_quantity, on_itemid: on_itemid, itemid: incoming_itemid}), "ITEMUPDATE"
# Remove 1 quantity of the orb..
client.stash[tabid].items[incoming_itemid] = modify_item_tuple(item, 3, new_item_quantity)
else
raise "Item use failed.."
end
when "reforge_orb"
# reforges a magic item with new modifiers
raise "Can't be used on uniques." if main_on_item["rarity"] == "Unique"
raise "This item is not magic rarity, it has more than 2 mods." if current_item_mods.size > 2
raise "This item is not magic rarity, it has zero mods." if current_item_mods.size == 0
query_update = QueryUpdate.new
# What to do dependent on the item's type
if main_on_item["type"] == "Weapons"
mod_rolls = ModGlobalWeapons.dup
mod_rolls = mod_rolls - [current_item_mods[0]] if current_item_mods.size == 1
mod_rolls = mod_rolls.shuffle.first(2)
mod_rolls = mod_rolls.shuffle.first(1) if current_item_mods.size == 1
if current_item_mods.size > 1
current_item_mods.each do |c_mod|
query_update[c_mod] = 0
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], GlobalItemTuple.index(c_mod), 0)
end
end
mod_rolls.each do |mod_key|
roll = rand
mod_struct = GlobalItemModsMapping[mod_key].select { |v| roll < v.mod_chance }.last
final_roll_value = rand(mod_struct.min_value..mod_struct.max_value)
query_update[mod_struct.mod_type] = final_roll_value
tuple_index = GlobalItemTuple.index(mod_struct.mod_type)
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], tuple_index, final_roll_value)
end
elsif main_on_item["type"] == "Capsules"
new_extra_mods_value = roll_random_map_mods(2, on_item[24])
query_update["extra_mods"] = new_extra_mods_value
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], 24, new_extra_mods_value)
else # armors?
if current_item_mods.size > 1
current_item_mods.each do |c_mod|
query_update[c_mod] = 0
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], GlobalItemTuple.index(c_mod), 0)
end
end
mod_rolls = ModGlobalArmors.dup
mod_rolls = mod_rolls - [current_item_mods[0]] if current_item_mods.size == 1
if main_on_item["type"] == "Gloves"
mod_rolls << "i_atk_speed"
end
mod_rolls = mod_rolls.shuffle.first(2)
mod_rolls = mod_rolls.shuffle.first(1) if current_item_mods.size == 1
mod_rolls.each do |mod_key|
roll = rand
mod_struct = GlobalItemModsMapping[mod_key].select { |v| roll < v.mod_chance }.last
final_roll_value = rand(mod_struct.min_value..mod_struct.max_value)
query_update[mod_struct.mod_type] = final_roll_value
tuple_index = GlobalItemTuple.index(mod_struct.mod_type)
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], tuple_index, final_roll_value)
end
end
if query_update.size > 0
db.exec "update rpg_user_items set #{hash_to_delimited_query_list(query_update)} where itemid = ? and user_id = ?", on_itemid, client.user_id
client.send ({a: 4, new_data: query_update, q: new_item_quantity, on_itemid: on_itemid, itemid: incoming_itemid}), "ITEMUPDATE"
client.stash[tabid].items[incoming_itemid] = modify_item_tuple(item, 3, new_item_quantity)
end
when "dissolving_orb"
# Removes one modifier from an item.
raise "Item must have at least one modifier." if current_item_mods.size <= 0
query_update = QueryUpdate.new
mod_type = current_item_mods.shuffle.first
if main_on_item["type"] == "Capsules"
new_extra_mods_value, mod_type = remove_random_map_mod(on_item[24])
query_update["extra_mods"] = new_extra_mods_value
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], 24, new_extra_mods_value)
else
query_update[mod_type] = 0
tuple_index = GlobalItemTuple.index(mod_type)
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], tuple_index, 0)
end
if select_mods_from_item(client.stash[tabid_on].items[on_itemid]).size < 3
# It's not a rare
query_update["rare_name"] = ""
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], 22, "")
end
if query_update.size > 0
db.exec "update rpg_user_items set #{hash_to_delimited_query_list(query_update)} where itemid = ? and user_id = ?", on_itemid, client.user_id
client.send ({a: 4, remove_data: mod_type, q: new_item_quantity, on_itemid: on_itemid, itemid: incoming_itemid}), "ITEMUPDATE"
# Remove 1 quantity of the orb..
client.stash[tabid].items[incoming_itemid] = modify_item_tuple(item, 3, new_item_quantity)
else
raise "Item use failed.."
end
when "lucky_orb"
# Upgrades a normal item to a random rarity.
raise "Item must be normal rarity." if current_item_mods.size > 0
mod_rolls = Array(String).new
query_update = QueryUpdate.new
# What to do dependent on the item's type
if main_on_item["type"] == "Weapons"
# magic rarity
mod_rolls = ModGlobalWeapons.dup
if rand < 0.15
# chance to roll 4 mods
mod_rolls = mod_rolls.shuffle.first(rand(2..4))
else
mod_rolls = mod_rolls.shuffle.first(rand(2..3))
end
elsif main_on_item["type"] == "Capsules"
new_extra_mods_value = roll_random_map_mods(rand(2..4), on_item[24])
query_update["extra_mods"] = new_extra_mods_value
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], 24, new_extra_mods_value)
else
if rand < 0.15
# chance to roll 4 mods
mod_rolls = ModGlobalArmors.shuffle.first(rand(2..4))
else
mod_rolls = ModGlobalArmors.shuffle.first(rand(2..3))
end
end
mod_rolls.each do |mod_key|
roll = rand
mod_struct = GlobalItemModsMapping[mod_key].select { |v| roll < v.mod_chance }.last
final_roll_value = rand(mod_struct.min_value..mod_struct.max_value)
query_update[mod_struct.mod_type] = final_roll_value
tuple_index = GlobalItemTuple.index(mod_struct.mod_type)
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], tuple_index, final_roll_value)
end
current_item_mods = select_mods_from_item(client.stash[tabid_on].items[on_itemid])
if current_item_mods.size > 2
# It's now a rare
new_rare_name = generate_rare_name(main_on_item_type)
query_update["rare_name"] = new_rare_name
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], 22, new_rare_name)
end
if query_update.size > 0
db.exec "update rpg_user_items set #{hash_to_delimited_query_list(query_update)} where itemid = ? and user_id = ?", on_itemid, client.user_id
client.send ({a: 4, new_data: query_update, q: new_item_quantity, on_itemid: on_itemid, itemid: incoming_itemid}), "ITEMUPDATE"
# Remove 1 quantity from the orb..
client.stash[tabid].items[incoming_itemid] = modify_item_tuple(item, 3, new_item_quantity)
else
raise "Item use failed.."
end
when "sun_orb"
# Upgrades a magic item to rare item.
raise "Item must have 2 mods (magic)." if current_item_mods.size != 2
clean_roll = ""
prefix_key_rolls = Array(String).new
suffix_key_rolls = Array(String).new
query_update = QueryUpdate.new
# What to do dependent on the item's type
if main_on_item["type"] == "Weapons"
temp_rolls = ModGlobalWeapons.shuffle
clean_roll = (temp_rolls - current_item_mods).first # can't have multiple mods of the same type
elsif main_on_item["type"] == "Capsules"
new_extra_mods_value = add_random_map_mods(1, on_item[24])
query_update["extra_mods"] = new_extra_mods_value
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], 24, new_extra_mods_value)
else
temp_rolls = ModGlobalArmors.shuffle
clean_roll = (temp_rolls - current_item_mods).first # can't have multiple mods of the same type
end
if main_on_item["type"] != "Capsules"
raise "No potential mods to roll against. This might be a far bigger issue at hand.." if clean_roll.size == 0
roll = rand
mod_struct = GlobalItemModsMapping[clean_roll].select { |v| roll < v.mod_chance }.last
final_roll_value = rand(mod_struct.min_value..mod_struct.max_value)
query_update[mod_struct.mod_type] = final_roll_value
tuple_index = GlobalItemTuple.index(mod_struct.mod_type)
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], tuple_index, final_roll_value)
end
# It's now a rare
new_rare_name = generate_rare_name(main_on_item_type)
query_update["rare_name"] = new_rare_name
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], 22, new_rare_name)
if query_update.size > 0
db.exec "update rpg_user_items set #{hash_to_delimited_query_list(query_update)} where itemid = ? and user_id = ?", on_itemid, client.user_id
client.send ({a: 4, new_data: query_update, q: new_item_quantity, on_itemid: on_itemid, itemid: incoming_itemid}), "ITEMUPDATE"
# Remove 1 quantity of the orb..
client.stash[tabid].items[incoming_itemid] = modify_item_tuple(item, 3, new_item_quantity)
else
raise "Item use failed.."
end
when "atom_orb"
# Randomizes the values from modifiers on a rare item.
raise "Item must have at least 3 mods (rare)." if current_item_mods.size < 3
query_update = QueryUpdate.new
if main_on_item["type"] == "Capsules"
new_extra_mods_value = reroll_current_map_mods(on_item[24])
query_update["extra_mods"] = new_extra_mods_value
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], 24, new_extra_mods_value)
else
# What to do dependent on the item's type
roll = rand
current_item_mods.each do |mod|
if (mapping_obj = GlobalItemModsMapping[mod]?) && (tuple_index = GlobalItemTuple.index(mod))
mod_value = client.stash[tabid_on].items[on_itemid][tuple_index].to_i
mapping_obj.each do |v|
if mod_value >= v.min_value && mod_value <= v.max_value
mod_struct = v
final_roll_value = rand(mod_struct.min_value..mod_struct.max_value)
query_update[mod_struct.mod_type] = final_roll_value
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], tuple_index, final_roll_value)
break
end
end
end
end
end
# It's being re-rolled, generate a new rare item name
# new_rare_name = generate_rare_name(main_on_item_type)
# query_update["rare_name"] = new_rare_name
# client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], 22, new_rare_name)
if query_update.size > 0
db.exec "update rpg_user_items set #{hash_to_delimited_query_list(query_update)} where itemid = ? and user_id = ?", on_itemid, client.user_id
client.send ({a: 4, new_data: query_update, q: new_item_quantity, on_itemid: on_itemid, itemid: incoming_itemid}), "ITEMUPDATE"
# Remove 1 quantity of the orb..
client.stash[tabid].items[incoming_itemid] = modify_item_tuple(item, 3, new_item_quantity)
else
raise "Item use failed.."
end
when "galaxy_orb"
# Upgrades a normal item to rare
raise "Item must have no mods." if current_item_mods.size > 0
raise "Item must be normal rarity." if main_on_item["rarity"] != "Normal"
prefix_key_rolls = Array(ModStruct).new
suffix_key_rolls = Array(ModStruct).new
query_update = QueryUpdate.new
roll = rand
# What to do dependent on the item's type
if main_on_item["type"] == "Weapons"
prefix_key_rolls << ModPrefixWeapons_i_phys.select { |v| roll < v.mod_chance }.last
suffix_key_rolls << ModSuffixWeapons_i_atk_speed.select { |v| roll < v.mod_chance }.last
suffix_key_rolls << ModSuffixWeapons_i_crit_chance.select { |v| roll < v.mod_chance }.last
suffix_key_rolls << ModSuffixWeapons_crit_multiplier.select { |v| roll < v.mod_chance }.last
prefix_key_rolls.each do |c_obj|
final_roll_value = rand(c_obj.min_value..c_obj.max_value)
query_update[c_obj.mod_type] = final_roll_value
tuple_index = GlobalItemTuple.index(c_obj.mod_type)
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], tuple_index, final_roll_value)
end
suffix_key_rolls.each do |c_obj|
final_roll_value = rand(c_obj.min_value..c_obj.max_value)
query_update[c_obj.mod_type] = final_roll_value
tuple_index = GlobalItemTuple.index(c_obj.mod_type)
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], tuple_index, final_roll_value)
end
elsif main_on_item["type"] == "Capsules"
new_extra_mods_value = roll_random_map_mods(3, on_item[24])
query_update["extra_mods"] = new_extra_mods_value
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], 24, new_extra_mods_value)
else # armors?
mod_rolls = ModGlobalArmors.shuffle.first(3) # galaxy orb = min of 3 mods = rare!
pp mod_rolls
mod_rolls.each do |mod_key|
mod_struct = GlobalItemModsMapping[mod_key].select { |v| roll < v.mod_chance }.last
final_roll_value = rand(mod_struct.min_value..mod_struct.max_value)
query_update[mod_struct.mod_type] = final_roll_value
tuple_index = GlobalItemTuple.index(mod_struct.mod_type)
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], tuple_index, final_roll_value)
end
end
# It's a rare
new_rare_name = generate_rare_name(main_on_item_type)
query_update["rare_name"] = new_rare_name
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], 22, new_rare_name)
if query_update.size > 0
db.exec "update rpg_user_items set #{hash_to_delimited_query_list(query_update)} where itemid = ? and user_id = ?", on_itemid, client.user_id
client.send ({a: 4, new_data: query_update, q: new_item_quantity, on_itemid: on_itemid, itemid: incoming_itemid}), "ITEMUPDATE"
# Remove 1 quantity of the orb..
client.stash[tabid].items[incoming_itemid] = modify_item_tuple(item, 3, new_item_quantity)
end
when "furbish_orb"
# Removes all modifications
raise "This item must have modifications to be removed." if current_item_mods.size == 0
query_update = QueryUpdate.new
query_update["rare_name"] = ""
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], 22, "")
if main_on_item["type"] == "Capsules"
new_extra_mods_value = ""
query_update["extra_mods"] = new_extra_mods_value
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], 24, new_extra_mods_value)
else
current_item_mods.each do |mod_type|
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], GlobalItemTuple.index(mod_type), 0)
query_update[mod_type] = 0
end
end
# Remove quantity from the orb
client.stash[tabid].items[incoming_itemid] = modify_item_tuple(item, 3, new_item_quantity)
db.exec "update rpg_user_items set #{hash_to_delimited_query_list(query_update)} where itemid = ? and user_id = ?", on_itemid, client.user_id
client.send ({a: 5, new_data: query_update, q: new_item_quantity, on_itemid: on_itemid, itemid: incoming_itemid}), "ITEMUPDATE"
# Randomizing sockets
when "randomize_sockets"
num_of_sockets_to_roll = main_on_item["slot_size"].to_s[0].to_i8 * main_on_item["slot_size"].to_s[2].to_i8
at_max_sockets = true
on_item[5].each_char do |c|
at_max_sockets = false if c == '0'
end
raise "Item is at the maximum amount of sockets. (g)" if at_max_sockets
raise "Item is at the maximum amount of sockets. (6)" if on_item[5] == "111111" && num_of_sockets_to_roll == 6
raise "Item is at the maximum amount of sockets. (4)." if on_item[5] == "1111" && num_of_sockets_to_roll == 4
raise "Item is at the maximum amount of sockets and links. (6)" if on_item[5] == "222222" && num_of_sockets_to_roll == 6
raise "Item is at the maximum amount of sockets and links. (4)." if on_item[5] == "2222" && num_of_sockets_to_roll == 4
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(on_item, 5, randomize_sockets(num_of_sockets_to_roll, "1"))
client.stash[tabid].items[incoming_itemid] = modify_item_tuple(item, 3, new_item_quantity)
client.send ({a: 1, sockets: client.stash[tabid_on].items[on_itemid][5], q: client.stash[tabid].items[incoming_itemid][3], on_itemid: on_itemid, itemid: incoming_itemid}), "ITEMUPDATE"
db.exec "update rpg_user_items set sockets = ? where itemid = ? and user_id = ?", client.stash[tabid_on].items[on_itemid][5], on_itemid, client.user_id
# Randomize the links on an item
when "randomize_links"
raise "This item has no open sockets to roll against." if (!on_item[5].includes? '1') && (!on_item[5].includes? '2')
num_of_sockets_to_roll = main_on_item["slot_size"].to_s[0].to_i8 * main_on_item["slot_size"].to_s[2].to_i8
raise "Item is at the maximum amount of links. (6)" if on_item[5] == "222222" if num_of_sockets_to_roll == 6
raise "Item is at the maximum amount of links. (4)." if on_item[5] == "2222" if num_of_sockets_to_roll == 4
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(on_item, 5, randomize_links(on_item[5]))
client.stash[tabid].items[incoming_itemid] = modify_item_tuple(item, 3, new_item_quantity)
client.send ({a: 1, sockets: client.stash[tabid_on].items[on_itemid][5], q: client.stash[tabid].items[incoming_itemid][3], on_itemid: on_itemid, itemid: incoming_itemid}), "ITEMUPDATE"
db.exec "update rpg_user_items set sockets = ? where itemid = ? and user_id = ?", client.stash[tabid_on].items[on_itemid][5], on_itemid, client.user_id
# Identify an item
when "identify"
raise "This item is already identified." if on_item[6] == 1
# raise "This item does not have any mods, it's pointless to identify." if current_item_mods.size == 0
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(on_item, 6, 1)
client.stash[tabid].items[incoming_itemid] = modify_item_tuple(item, 3, new_item_quantity)
client.send ({a: 9, q: client.stash[tabid].items[incoming_itemid][3], on_itemid: on_itemid, itemid: incoming_itemid}), "ITEMUPDATE"
db.exec "update rpg_user_items set identified = 1 where itemid = ? and user_id = ?", on_itemid, client.user_id
when "improve_quality"
raise "This item is at max quality." if on_item[18] >= MAX_ITEM_QUALITY
raise "You can only increase the quality of an equippable item." if main_on_item["type"] != "Capsules" && !is_equippable_type(main_on_item["type"])
query_update = QueryUpdate.new
new_quality = on_item[18] + 1
client.stash[tabid].items[incoming_itemid] = modify_item_tuple(item, 3, new_item_quantity)
client.stash[tabid_on].items[on_itemid] = modify_item_tuple(client.stash[tabid_on].items[on_itemid], 18, new_quality)
db.exec "update rpg_user_items set quality = ? where itemid = ? and user_id = ?", new_quality, on_itemid, client.user_id
client.send ({a: 14, q: new_item_quantity, new_quality: new_quality, on_itemid: on_itemid, itemid: incoming_itemid}), "ITEMUPDATE"
else
raise "Invalid item, or its functionality is not coded yet."
end
# Last one, so it needs to be removed / deleted from the database
if new_item_quantity == 0
db.exec "delete from rpg_user_items where itemid = ? and user_id = ?", incoming_itemid, client.user_id
client.stash[tabid].items.delete incoming_itemid
else
db.exec "update rpg_user_items set q=q-1 where itemid = ? and user_id = ?", incoming_itemid, client.user_id
end
# puts item[4]
# puts on_item[4]
else
raise "You do not own this item?"
end
rescue e
client.send e.message, "E"
# pp e.backtrace
end