# File: merchedit.rb # Author: Craig Smith # This source code copyright (C) 2009 Craig Smith # All rights reserved. # # Released under the terms of the GNU Public License # See COPYING file for additional information. # require 'olc/medit' # Mobile Editor OLC Object class MerchEdit < Medit def initialize(id, oid, args=nil) self.title = "Merchant Editor" if not title if not obj and not oid self.obj = Merchant.new(args, id, nil) if not oid self.newobj = true end super(id,oid,args) self.default_attr.concat([ "no_buy" ]) @object_types = ["Food","Battery","Container"] @object_attr = ["light","shovel","worn"] @object_dtype = ["piercing","slashing"] end # Checks if the object is valid def is_valid?(obj) return true if obj.kind_of? Merchant false end def setup_main(m=nil) super(m) menu.add_text_option(nil, "Sell Items", self, :setup_sell_menu, obj.forsale) menu.add_text_option(nil, "Buy Types", self, :setup_buy_types_menu, obj.buytype) menu.add_text_option(nil, "Buy Attributes", self, :setup_buy_attr_menu, obj.buyattribute) menu.add_text_option(nil, "Buy Weapon Types", self, :setup_buy_weapon_menu, obj.buydtype) menu.add_std_option(nil, "Markup", obj.markup,self, :set_markup) end def setup_sell_menu(m=nil) smenu = olc_basemenu("Oids to Sell",self,:setup_aliases, m) smenu.add_named_numbered_option(obj.forsale,nil,nil); smenu.add_text_option("D#","Delete Oid #",self,:del_forsale); smenu.add_std_option(nil,"Add New Oid",nil,self,:add_forsale); submenu(smenu,m) end def setup_buy_types_menu(m=nil) smenu = olc_basemenu("Buy Types", self, :setup_buy_types_menu, m) smenu.default_array = @object_types smenu.set_array = obj.buytype smenu.add_toggled_numbered_options(self,:add_buytype); submenu(smenu, m) end def setup_buy_attr_menu(m=nil) smenu = olc_basemenu("Buy Attributes", self, :setup_buy_attr_menu, m) smenu.default_array = @object_attr smenu.set_array = obj.buyattribute smenu.add_toggled_numbered_options(self,:add_buyattr); submenu(smenu, m) end def setup_buy_weapon_menu(m=nil) smenu = olc_basemenu("Buy Weapon Types", self, :setup_buy_weapon_menu, m) smenu.default_array = @object_dtype smenu.set_array = obj.buydtype smenu.add_toggled_numbered_options(self,:add_buydtype); submenu(smenu, m) end def add_buytype(m) if m=~/(\d+)/ idx = m.to_i if idx > 0 and idx <= @object_types.size if obj.buytype.include?(@object_types[idx-1]) obj.buytype.delete(@object_types[idx-1]) else obj.buytype << @object_types[idx-1] end end end end def add_buyattr(m) if m=~/(\d+)/ idx = m.to_i if idx > 0 and idx <= @object_attr.size if obj.buyattribute.include?(@object_attr[idx-1]) obj.buyattribute.delete(@object_attr[idx-1]) else obj.buyattribute << @object_attr[idx-1] end end end end def add_buydtype(m) if m=~/(\d+)/ idx = m.to_i if idx > 0 and idx <= @object_dtype.size if obj.buydtype.include?(@object_dtype[idx-1]) obj.buydtype.delete(@object_dtype[idx-1]) else obj.buydtype << @object_dtype[idx-1] end end end end def del_forsale(m) if m=~/(\d+)/ oid = $1.to_i if oid > 0 obj.forsale.delete(oid) if obj.forsale.include? oid end end show_menu nil end def add_forsale(m) oid = m.to_i if oid > 0 obj.forsale << oid if not obj.forsale.include? oid end show_menu nil end def set_markup(m) markup = m.to_f markup *= 0.01 if markup > 3 # Probably not floating point if markup < 3 and markup > 0.009 # Probable setting ranges obj.markup = markup end show_menu obj.markup end end