Advertisement
Guest User

Shopaholic Page 9

a guest
Jul 29th, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.71 KB | None | 0 0
  1. #-------------------------------------------------------------------------------
  2. # page 9 of 12
  3. # Shopoholic v 2.0
  4. # code by cmpsr2000
  5. # available exclusively @ rpgrevolution.com/forums
  6. # Released June 25, 2008
  7. #
  8. #-------------------------------------------------------------------------------
  9. class Window_Shop_Details < Window_Base
  10.  
  11. attr_accessor :item
  12. attr_accessor :buyState
  13. attr_accessor :refreshNeeded
  14. #-----------------------------------------------------------------------------
  15. # Creates the shop details window.
  16. # x: x-coordinate
  17. # y: y-coordinate
  18. # width: the window's width
  19. # height: the window's height
  20. # rates: an array of shopping rates(see Game_Shopping for details)
  21. # shopID: The ID of the shop that created this window
  22. #-----------------------------------------------------------------------------
  23. def initialize(x, y, width, height, rates, shopID)
  24. super(x, y, width, height)
  25. @item = nil
  26. @rates = rates
  27. @shopID = shopID
  28. @refreshNeeded = false
  29. #---------------------------------------------------------------------------
  30. # Change these if you need to use different atribute up/down icons
  31. #---------------------------------------------------------------------------
  32. @atkIconUp = 1916
  33. @atkIconDown = 1932
  34. @atkIconSame = 1948
  35. @defIconUp = 1917
  36. @defIconDown = 1933
  37. @defIconSame = 1949
  38. @spiIconUp = 1918
  39. @spiIconDown = 1934
  40. @spiIconSame = 1950
  41. @agiIconUp = 1919
  42. @agiIconDown = 1935
  43. @agiIconSame = 1951
  44. end
  45. #-----------------------------------------------------------------------------
  46. # updates the window's contents
  47. #-----------------------------------------------------------------------------
  48. def update
  49. super
  50. set_status(@item)
  51. end
  52. #-----------------------------------------------------------------------------
  53. # Shows purchase information and the status of equiping the selected item
  54. # item: The item to compare against
  55. #-----------------------------------------------------------------------------
  56. def set_status(item)
  57. if (item != @lastItem and item != nil) or @refreshNeeded
  58. self.contents.clear
  59. if buying?
  60. printPriceInfo(item)
  61. else
  62. printPossession(item)
  63. end
  64. x = 0
  65. y = 80
  66.  
  67. #if the item is an item, no stat mods and no one can equip (all grey)
  68. if item.is_a?(RPG::Item)
  69. enabled = false;
  70. for actor in $game_party.members
  71. draw_actor_graphic(actor, x, y + 6, enabled)
  72. y += 48
  73. end
  74.  
  75. #if the item is a weapon, draw depending on equipability
  76. elsif item.is_a?(RPG::Weapon)
  77. for actor in $game_party.members
  78. #check to see if this actor can equip this item
  79. if actor.equippable?(item)
  80. draw_actor_graphic(actor, x, y + 6, true)
  81. drawAttributeIcons(actor, item, x + 12, y)
  82. else
  83. draw_actor_graphic(actor, x, y + 6, false)
  84. end
  85. y += 48
  86. end
  87.  
  88. #if the item is an armor, draw depending on equipability
  89. elsif item.is_a?(RPG::Armor)
  90. for actor in $game_party.members
  91. #check to see if this actor can equip this item
  92. if actor.equippable?(item)
  93. draw_actor_graphic(actor, x, y + 6, true)
  94. drawAttributeIcons(actor, item, x + 12, y)
  95. else
  96. draw_actor_graphic(actor, x, y + 6, false)
  97. end
  98. y += 48
  99. end
  100.  
  101. #if the item is a skill, draw usability
  102. elsif item.is_a?(RPG::Skill)
  103. for actor in $game_party.members
  104. #check to see if this actor can use this skill
  105. enabled = false
  106. for learning in $data_classes[actor.class_id].learnings
  107. if learning.skill_id = item.id
  108. enabled = true
  109. break
  110. end
  111. end
  112. draw_actor_graphic(actor, x, y + 6, enabled)
  113. y += 48
  114. end
  115.  
  116. #if the item is a class, draw its skills
  117. elsif item.is_a?(RPG::Class)
  118. draw_skills(item, x, y + 6)
  119.  
  120. #if the item is an actor, draw its face and graphic
  121. elsif item.is_a?(RPG::Actor)
  122. draw_actor_face(item, x, y + 6)
  123. draw_actor_name(item, x + 108, y + 6)
  124. draw_actor_class(item, x + 108, y + 30)
  125. draw_actor_level(item, x + 108, y + 72)
  126. draw_actor_graphic(item, x + 172, y + 66, true)
  127. end
  128. @lastItem = item
  129. end
  130. @refreshNeeded = false
  131. end
  132. #-----------------------------------------------------------------------------
  133. # Prints the price information for the selected item
  134. # item: the item to print price information about
  135. #-----------------------------------------------------------------------------
  136. def printPriceInfo(item)
  137. if $game_shopping.shopUsedItems[@shopID][item] != nil
  138. used = $game_shopping.shopUsedItems[@shopID][item] > 0
  139. else
  140. used = false
  141. end
  142. itemMax = $game_shopping.shopLimitedItems[@shopID][@item]
  143. isInflated = (itemMax != nil and itemMax != false and itemMax != true and
  144. itemMax > 0 and itemMax <= $game_shopping.demandAmount)
  145. shopPrice = $game_shopping.shopPrice(item, @rates, false, used, isInflated)
  146.  
  147. if $game_shopping.allowTax
  148. tax = (shopPrice * @rates[3]).ceil
  149. price = shopPrice + tax
  150. printPossession(item)
  151. self.contents.font.color = system_color
  152. self.contents.draw_text(4, 24, 200, WLH, "Shop price + tax = total")
  153. self.contents.font.color = normal_color
  154. self.contents.draw_text(4, 48, 88, WLH, shopPrice, 1)
  155. self.contents.draw_text(92, 48, 8, WLH, "+", 1)
  156. self.contents.draw_text(100, 48, 40, WLH, tax, 1)
  157. self.contents.draw_text(140, 48, 8, WLH, "=", 1)
  158. self.contents.font.color = text_color(6)
  159. self.contents.draw_text(148, 48, 52, WLH, price, 1)
  160. else
  161. printPossession(item)
  162. self.contents.font.color = system_color
  163. self.contents.draw_text(4, 48, 200, WLH, "Shop price:")
  164. self.contents.font.color = normal_color
  165. self.contents.draw_text(4, 48, 200, WLH, shopPrice, 2)
  166. end
  167. end
  168. #-----------------------------------------------------------------------------
  169. # Prints the amount of the item the player currently posseses.
  170. # item: the item to check for possession amount
  171. #-----------------------------------------------------------------------------
  172. def printPossession(item)
  173. number = $game_party.item_number(item)
  174. self.contents.font.color = system_color
  175. self.contents.draw_text(4, 0, 200, WLH, Vocab::Possession)
  176. self.contents.font.color = normal_color
  177. self.contents.draw_text(4, 0, 200, WLH, number, 2)
  178. end
  179. #-----------------------------------------------------------------------------
  180. # Draws the skills of a specific actor
  181. # actor: The actor whose skills are being printed
  182. # x: The x-coordinate of the printing
  183. # y: The y-coordinate of the printing
  184. #-----------------------------------------------------------------------------
  185. def draw_skills(actor, x, y)
  186. self.contents.font.color = system_color
  187. self.contents.draw_text(x, y, 200, WLH, Vocab::skill + "s:")
  188. x += 24
  189. y += 24
  190. for learning in $data_classes[actor.id].learnings
  191. skill = $data_skills[learning.skill_id]
  192. enabled = skill.discovered
  193. draw_item_name(skill, x, y, enabled)
  194. y += WLH
  195. if y > 248
  196. self.contents.font.color = system_color
  197. self.contents.draw_text(x, y, 172, WLH, "etc...", 2)
  198. return
  199. end
  200. end
  201. end
  202. #-----------------------------------------------------------------------------
  203. # Draws the character graphic of the specified actor.
  204. # actor: The actor to draw
  205. # x: The x-coordinate of the printing
  206. # y: The y-coordinate of the printing
  207. # enabled: Whether to draw the actor opaque or transparent.
  208. #-----------------------------------------------------------------------------
  209. def draw_actor_graphic(actor, x, y, enabled = true)
  210. bitmap = Cache.character(actor.character_name)
  211. sign = actor.character_name[/^[\!\$]./]
  212. if sign != nil and sign.include?('$')
  213. cw = bitmap.width / 3
  214. ch = bitmap.height / 4
  215. else
  216. cw = bitmap.width / 12
  217. ch = bitmap.height / 8
  218. end
  219. n = actor.character_index
  220. src_rect = Rect.new((n%4*3+1)*cw, (n/4*4)*ch, cw, ch)
  221. self.contents.blt(x, y, bitmap, src_rect, enabled ? 255 : 128)
  222. bitmap.dispose
  223. end
  224. #-----------------------------------------------------------------------------
  225. # Draws the name of an actor
  226. # actor: The actor to draw
  227. # x: The x-coordinate of the printing
  228. # y: The y-coordinate of the printing
  229. #-----------------------------------------------------------------------------
  230. def draw_actor_name(actor, x, y)
  231. self.contents.font.color = normal_color
  232. self.contents.draw_text(x, y, 108, WLH, actor.name)
  233. end
  234. #-----------------------------------------------------------------------------
  235. # Draws the level of an actor
  236. # actor: The actor to draw
  237. # x: The x-coordinate of the printing
  238. # y: The y-coordinate of the printing
  239. #-----------------------------------------------------------------------------
  240. def draw_actor_level(actor, x, y)
  241. self.contents.font.color = system_color
  242. self.contents.draw_text(x, y, 32, WLH, Vocab::level_a)
  243. self.contents.font.color = normal_color
  244. level = actor.initial_level
  245. self.contents.draw_text(x + 32, y, 24, WLH, level, 2)
  246. end
  247. #-----------------------------------------------------------------------------
  248. # Draws the class of an actor
  249. # actor: The actor to draw
  250. # x: The x-coordinate of the printing
  251. # y: The y-coordinate of the printing
  252. #-----------------------------------------------------------------------------
  253. def draw_actor_class(actor, x, y)
  254. self.contents.font.color = normal_color
  255. self.contents.draw_text(x, y, 108, WLH, $data_classes[actor.class_id].name)
  256. end
  257. #-------------------------------------------------------------------------
  258. # Draws the atk/def/spi/agi up/down icons where appropriate
  259. # actor: Actor to compare values against
  260. # item: item that is being compared
  261. # x: starting x position
  262. # y: starting y position
  263. #-------------------------------------------------------------------------
  264. def drawAttributeIcons(actor, item, x, y)
  265. return if item.is_a?(RPG::Item)
  266. chooseAttributeIcon(actor, item, "atk", x, y)
  267. chooseAttributeIcon(actor, item, "def", x, y)
  268. chooseAttributeIcon(actor, item, "spi", x, y)
  269. chooseAttributeIcon(actor, item, "agi", x, y)
  270. end
  271. #-----------------------------------------------------------------------------
  272. # Determines the correct icons for attribute changes to the specified actor
  273. # when equiping the specified item.
  274. # actor: Actor to compare values against
  275. # item: item that is being compared
  276. # attrib: The attribute to copmare
  277. # x: starting x position
  278. # y: starting y position
  279. #-----------------------------------------------------------------------------
  280. def chooseAttributeIcon(actor, item, attrib, x, y)
  281. #Figure out which item will be replaced
  282. if item.is_a?(RPG::Weapon)
  283. primaryWeapon = actor.weapons[0]
  284. secondaryWeapon = actor.weapons[1] if actor.two_swords_style
  285.  
  286. #figure out which weapon we'll compare against
  287. pwAtk = primaryWeapon == nil ? 0 : primaryWeapon.atk
  288. swAtk = secondaryWeapon == nil ? 0 : secondaryWeapon.atk
  289. equipedItem = swAtk > pwAtk ? secondaryWeapon : primaryWeapon
  290. else
  291. equipedItem = actor.equips[item.kind + 1]
  292. end
  293.  
  294. #switch to determine the applicable attribute
  295. case attrib
  296. when "atk"
  297. currentAtr = actor.base_atk
  298. itemAtr = item.atk
  299. equipAtr = equipedItem == nil ? 0 : equipedItem.atk
  300. atrIconUp = @atkIconUp
  301. atrIconDown = @atkIconDown
  302. atrIconSame = @atkIconSame
  303. x += 28
  304. when "def"
  305. currentAtr = actor.base_def
  306. itemAtr = item.def
  307. equipAtr = equipedItem == nil ? 0 : equipedItem.def
  308. atrIconUp = @defIconUp
  309. atrIconDown = @defIconDown
  310. atrIconSame = @defIconSame
  311. x += 76
  312. when "spi"
  313. currentAtr = actor.base_spi
  314. itemAtr = item.spi
  315. equipAtr = equipedItem == nil ? 0 : equipedItem.spi
  316. atrIconUp = @spiIconUp
  317. atrIconDown = @spiIconDown
  318. atrIconSame = @spiIconSame
  319. x += 28
  320. y += 24
  321. when "agi"
  322. currentAtr = actor.base_agi
  323. itemAtr = item.agi
  324. equipAtr = equipedItem == nil ? 0 : equipedItem.agi
  325. atrIconUp = @agiIconUp
  326. atrIconDown = @agiIconDown
  327. atrIconSame = @agiIconSame
  328. x += 76
  329. y += 24
  330. end
  331.  
  332. #now find the right icon
  333. subAttribute = currentAtr - equipAtr + itemAtr
  334. newAtr = subAttribute
  335. if subAttribute > currentAtr
  336. atrIcon = atrIconUp
  337. elsif subAttribute < currentAtr
  338. atrIcon = atrIconDown
  339. else
  340. atrIcon = atrIconSame
  341. end
  342.  
  343. #everything is calculated, pass to print function
  344. drawIconAndText(atrIcon, x, y, newAtr)
  345. end
  346. #-----------------------------------------------------------------------------
  347. # Draws the icon and associated attribute change
  348. # iconNumber: The icon to draw
  349. # x: The x-coordinate of the printing
  350. # y: The y-coordinate of the printing
  351. # newAtr: The attribute amount to be drawn
  352. #-----------------------------------------------------------------------------
  353. def drawIconAndText(iconNumber, x, y, newAtr)
  354. if iconNumber != nil
  355. draw_icon(iconNumber, x, y, true)
  356. end
  357. case iconNumber
  358. when @atkIconUp..@agiIconUp
  359. self.contents.font.color = text_color(3) #3 is green!
  360. when @atkIconDown..@agiIconDown
  361. self.contents.font.color = text_color(10) #10 is red!
  362. else
  363. self.contents.font.color = text_color(0) #0 is normal white!
  364. end
  365. self.contents.draw_text(x + 24, y, 24, WLH, newAtr.to_s)
  366. end
  367. #-----------------------------------------------------------------------------
  368. # Determines whether buying is currently taking place
  369. # RETURNS: Boolean
  370. #-----------------------------------------------------------------------------
  371. def buying?
  372. return @buyState
  373. end
  374.  
  375. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement