Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-------------------------------------------------------------------------------
- # page 9 of 12
- # Shopoholic v 2.0
- # code by cmpsr2000
- # available exclusively @ rpgrevolution.com/forums
- # Released June 25, 2008
- #
- #-------------------------------------------------------------------------------
- class Window_Shop_Details < Window_Base
- attr_accessor :item
- attr_accessor :buyState
- attr_accessor :refreshNeeded
- #-----------------------------------------------------------------------------
- # Creates the shop details window.
- # x: x-coordinate
- # y: y-coordinate
- # width: the window's width
- # height: the window's height
- # rates: an array of shopping rates(see Game_Shopping for details)
- # shopID: The ID of the shop that created this window
- #-----------------------------------------------------------------------------
- def initialize(x, y, width, height, rates, shopID)
- super(x, y, width, height)
- @item = nil
- @rates = rates
- @shopID = shopID
- @refreshNeeded = false
- #---------------------------------------------------------------------------
- # Change these if you need to use different atribute up/down icons
- #---------------------------------------------------------------------------
- @atkIconUp = 1916
- @atkIconDown = 1932
- @atkIconSame = 1948
- @defIconUp = 1917
- @defIconDown = 1933
- @defIconSame = 1949
- @spiIconUp = 1918
- @spiIconDown = 1934
- @spiIconSame = 1950
- @agiIconUp = 1919
- @agiIconDown = 1935
- @agiIconSame = 1951
- end
- #-----------------------------------------------------------------------------
- # updates the window's contents
- #-----------------------------------------------------------------------------
- def update
- super
- set_status(@item)
- end
- #-----------------------------------------------------------------------------
- # Shows purchase information and the status of equiping the selected item
- # item: The item to compare against
- #-----------------------------------------------------------------------------
- def set_status(item)
- if (item != @lastItem and item != nil) or @refreshNeeded
- self.contents.clear
- if buying?
- printPriceInfo(item)
- else
- printPossession(item)
- end
- x = 0
- y = 80
- #if the item is an item, no stat mods and no one can equip (all grey)
- if item.is_a?(RPG::Item)
- enabled = false;
- for actor in $game_party.members
- draw_actor_graphic(actor, x, y + 6, enabled)
- y += 48
- end
- #if the item is a weapon, draw depending on equipability
- elsif item.is_a?(RPG::Weapon)
- for actor in $game_party.members
- #check to see if this actor can equip this item
- if actor.equippable?(item)
- draw_actor_graphic(actor, x, y + 6, true)
- drawAttributeIcons(actor, item, x + 12, y)
- else
- draw_actor_graphic(actor, x, y + 6, false)
- end
- y += 48
- end
- #if the item is an armor, draw depending on equipability
- elsif item.is_a?(RPG::Armor)
- for actor in $game_party.members
- #check to see if this actor can equip this item
- if actor.equippable?(item)
- draw_actor_graphic(actor, x, y + 6, true)
- drawAttributeIcons(actor, item, x + 12, y)
- else
- draw_actor_graphic(actor, x, y + 6, false)
- end
- y += 48
- end
- #if the item is a skill, draw usability
- elsif item.is_a?(RPG::Skill)
- for actor in $game_party.members
- #check to see if this actor can use this skill
- enabled = false
- for learning in $data_classes[actor.class_id].learnings
- if learning.skill_id = item.id
- enabled = true
- break
- end
- end
- draw_actor_graphic(actor, x, y + 6, enabled)
- y += 48
- end
- #if the item is a class, draw its skills
- elsif item.is_a?(RPG::Class)
- draw_skills(item, x, y + 6)
- #if the item is an actor, draw its face and graphic
- elsif item.is_a?(RPG::Actor)
- draw_actor_face(item, x, y + 6)
- draw_actor_name(item, x + 108, y + 6)
- draw_actor_class(item, x + 108, y + 30)
- draw_actor_level(item, x + 108, y + 72)
- draw_actor_graphic(item, x + 172, y + 66, true)
- end
- @lastItem = item
- end
- @refreshNeeded = false
- end
- #-----------------------------------------------------------------------------
- # Prints the price information for the selected item
- # item: the item to print price information about
- #-----------------------------------------------------------------------------
- def printPriceInfo(item)
- if $game_shopping.shopUsedItems[@shopID][item] != nil
- used = $game_shopping.shopUsedItems[@shopID][item] > 0
- else
- used = false
- end
- itemMax = $game_shopping.shopLimitedItems[@shopID][@item]
- isInflated = (itemMax != nil and itemMax != false and itemMax != true and
- itemMax > 0 and itemMax <= $game_shopping.demandAmount)
- shopPrice = $game_shopping.shopPrice(item, @rates, false, used, isInflated)
- if $game_shopping.allowTax
- tax = (shopPrice * @rates[3]).ceil
- price = shopPrice + tax
- printPossession(item)
- self.contents.font.color = system_color
- self.contents.draw_text(4, 24, 200, WLH, "Shop price + tax = total")
- self.contents.font.color = normal_color
- self.contents.draw_text(4, 48, 88, WLH, shopPrice, 1)
- self.contents.draw_text(92, 48, 8, WLH, "+", 1)
- self.contents.draw_text(100, 48, 40, WLH, tax, 1)
- self.contents.draw_text(140, 48, 8, WLH, "=", 1)
- self.contents.font.color = text_color(6)
- self.contents.draw_text(148, 48, 52, WLH, price, 1)
- else
- printPossession(item)
- self.contents.font.color = system_color
- self.contents.draw_text(4, 48, 200, WLH, "Shop price:")
- self.contents.font.color = normal_color
- self.contents.draw_text(4, 48, 200, WLH, shopPrice, 2)
- end
- end
- #-----------------------------------------------------------------------------
- # Prints the amount of the item the player currently posseses.
- # item: the item to check for possession amount
- #-----------------------------------------------------------------------------
- def printPossession(item)
- number = $game_party.item_number(item)
- self.contents.font.color = system_color
- self.contents.draw_text(4, 0, 200, WLH, Vocab::Possession)
- self.contents.font.color = normal_color
- self.contents.draw_text(4, 0, 200, WLH, number, 2)
- end
- #-----------------------------------------------------------------------------
- # Draws the skills of a specific actor
- # actor: The actor whose skills are being printed
- # x: The x-coordinate of the printing
- # y: The y-coordinate of the printing
- #-----------------------------------------------------------------------------
- def draw_skills(actor, x, y)
- self.contents.font.color = system_color
- self.contents.draw_text(x, y, 200, WLH, Vocab::skill + "s:")
- x += 24
- y += 24
- for learning in $data_classes[actor.id].learnings
- skill = $data_skills[learning.skill_id]
- enabled = skill.discovered
- draw_item_name(skill, x, y, enabled)
- y += WLH
- if y > 248
- self.contents.font.color = system_color
- self.contents.draw_text(x, y, 172, WLH, "etc...", 2)
- return
- end
- end
- end
- #-----------------------------------------------------------------------------
- # Draws the character graphic of the specified actor.
- # actor: The actor to draw
- # x: The x-coordinate of the printing
- # y: The y-coordinate of the printing
- # enabled: Whether to draw the actor opaque or transparent.
- #-----------------------------------------------------------------------------
- def draw_actor_graphic(actor, x, y, enabled = true)
- bitmap = Cache.character(actor.character_name)
- sign = actor.character_name[/^[\!\$]./]
- if sign != nil and sign.include?('$')
- cw = bitmap.width / 3
- ch = bitmap.height / 4
- else
- cw = bitmap.width / 12
- ch = bitmap.height / 8
- end
- n = actor.character_index
- src_rect = Rect.new((n%4*3+1)*cw, (n/4*4)*ch, cw, ch)
- self.contents.blt(x, y, bitmap, src_rect, enabled ? 255 : 128)
- bitmap.dispose
- end
- #-----------------------------------------------------------------------------
- # Draws the name of an actor
- # actor: The actor to draw
- # x: The x-coordinate of the printing
- # y: The y-coordinate of the printing
- #-----------------------------------------------------------------------------
- def draw_actor_name(actor, x, y)
- self.contents.font.color = normal_color
- self.contents.draw_text(x, y, 108, WLH, actor.name)
- end
- #-----------------------------------------------------------------------------
- # Draws the level of an actor
- # actor: The actor to draw
- # x: The x-coordinate of the printing
- # y: The y-coordinate of the printing
- #-----------------------------------------------------------------------------
- def draw_actor_level(actor, x, y)
- self.contents.font.color = system_color
- self.contents.draw_text(x, y, 32, WLH, Vocab::level_a)
- self.contents.font.color = normal_color
- level = actor.initial_level
- self.contents.draw_text(x + 32, y, 24, WLH, level, 2)
- end
- #-----------------------------------------------------------------------------
- # Draws the class of an actor
- # actor: The actor to draw
- # x: The x-coordinate of the printing
- # y: The y-coordinate of the printing
- #-----------------------------------------------------------------------------
- def draw_actor_class(actor, x, y)
- self.contents.font.color = normal_color
- self.contents.draw_text(x, y, 108, WLH, $data_classes[actor.class_id].name)
- end
- #-------------------------------------------------------------------------
- # Draws the atk/def/spi/agi up/down icons where appropriate
- # actor: Actor to compare values against
- # item: item that is being compared
- # x: starting x position
- # y: starting y position
- #-------------------------------------------------------------------------
- def drawAttributeIcons(actor, item, x, y)
- return if item.is_a?(RPG::Item)
- chooseAttributeIcon(actor, item, "atk", x, y)
- chooseAttributeIcon(actor, item, "def", x, y)
- chooseAttributeIcon(actor, item, "spi", x, y)
- chooseAttributeIcon(actor, item, "agi", x, y)
- end
- #-----------------------------------------------------------------------------
- # Determines the correct icons for attribute changes to the specified actor
- # when equiping the specified item.
- # actor: Actor to compare values against
- # item: item that is being compared
- # attrib: The attribute to copmare
- # x: starting x position
- # y: starting y position
- #-----------------------------------------------------------------------------
- def chooseAttributeIcon(actor, item, attrib, x, y)
- #Figure out which item will be replaced
- if item.is_a?(RPG::Weapon)
- primaryWeapon = actor.weapons[0]
- secondaryWeapon = actor.weapons[1] if actor.two_swords_style
- #figure out which weapon we'll compare against
- pwAtk = primaryWeapon == nil ? 0 : primaryWeapon.atk
- swAtk = secondaryWeapon == nil ? 0 : secondaryWeapon.atk
- equipedItem = swAtk > pwAtk ? secondaryWeapon : primaryWeapon
- else
- equipedItem = actor.equips[item.kind + 1]
- end
- #switch to determine the applicable attribute
- case attrib
- when "atk"
- currentAtr = actor.base_atk
- itemAtr = item.atk
- equipAtr = equipedItem == nil ? 0 : equipedItem.atk
- atrIconUp = @atkIconUp
- atrIconDown = @atkIconDown
- atrIconSame = @atkIconSame
- x += 28
- when "def"
- currentAtr = actor.base_def
- itemAtr = item.def
- equipAtr = equipedItem == nil ? 0 : equipedItem.def
- atrIconUp = @defIconUp
- atrIconDown = @defIconDown
- atrIconSame = @defIconSame
- x += 76
- when "spi"
- currentAtr = actor.base_spi
- itemAtr = item.spi
- equipAtr = equipedItem == nil ? 0 : equipedItem.spi
- atrIconUp = @spiIconUp
- atrIconDown = @spiIconDown
- atrIconSame = @spiIconSame
- x += 28
- y += 24
- when "agi"
- currentAtr = actor.base_agi
- itemAtr = item.agi
- equipAtr = equipedItem == nil ? 0 : equipedItem.agi
- atrIconUp = @agiIconUp
- atrIconDown = @agiIconDown
- atrIconSame = @agiIconSame
- x += 76
- y += 24
- end
- #now find the right icon
- subAttribute = currentAtr - equipAtr + itemAtr
- newAtr = subAttribute
- if subAttribute > currentAtr
- atrIcon = atrIconUp
- elsif subAttribute < currentAtr
- atrIcon = atrIconDown
- else
- atrIcon = atrIconSame
- end
- #everything is calculated, pass to print function
- drawIconAndText(atrIcon, x, y, newAtr)
- end
- #-----------------------------------------------------------------------------
- # Draws the icon and associated attribute change
- # iconNumber: The icon to draw
- # x: The x-coordinate of the printing
- # y: The y-coordinate of the printing
- # newAtr: The attribute amount to be drawn
- #-----------------------------------------------------------------------------
- def drawIconAndText(iconNumber, x, y, newAtr)
- if iconNumber != nil
- draw_icon(iconNumber, x, y, true)
- end
- case iconNumber
- when @atkIconUp..@agiIconUp
- self.contents.font.color = text_color(3) #3 is green!
- when @atkIconDown..@agiIconDown
- self.contents.font.color = text_color(10) #10 is red!
- else
- self.contents.font.color = text_color(0) #0 is normal white!
- end
- self.contents.draw_text(x + 24, y, 24, WLH, newAtr.to_s)
- end
- #-----------------------------------------------------------------------------
- # Determines whether buying is currently taking place
- # RETURNS: Boolean
- #-----------------------------------------------------------------------------
- def buying?
- return @buyState
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement