blucalm

Gardening System Full Bug Fix Equip Crash

Dec 7th, 2012
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 112.04 KB | None | 0 0
  1. #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  2. # ** Garden System
  3. # Author: Eshra
  4. # Beta Release Date: 3 Nov. 2012
  5. # Compatibility: RPG Maker VX Ace
  6. # Dependencies:
  7. # 1. Tsuki_CustomDataManager
  8. # 2. Ra Custom DM add-on v0.1
  9. # 3. Ra Highlights v0.1
  10. # 4. Ra Event Spawn v0.1
  11. #
  12. #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  13. #
  14. # About:
  15. #
  16. # This script provides support for using events to represent plants while
  17. # in Scene_Map. It creates functionality for somewhat complicated plant
  18. # growth cycles, plant fertillization, and plant watering systems.
  19. #
  20. #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  21. #
  22. #------------------------------------------------------------------------------
  23. # * How to Use
  24. #------------------------------------------------------------------------------
  25. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  26. # Setting up a plant:
  27. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  28. #
  29. # Plants are represented by items (or skills) in the database. To mark an item
  30. # as a plant you need to give it a growth rate and a maximum stage.
  31. #
  32. # You can give the plant a growth rate with this note tag:
  33. # <seed rate VALUE>
  34. #
  35. # You can give the plant a maximum stage with this note tag:
  36. # <seed stages VALUE>
  37. #
  38. # - 'VALUE' should be replaced with an integer in the above two note tags -
  39. #
  40. # These are the only two notetags that are required to make a plant. There are
  41. # many more notetags though that can be used if you want to specify more
  42. # specific behavior for the plant.
  43. #
  44. # Don't forget to give the item a name, this is important!
  45. # After you have done this, you must now create an associated event for the plant.
  46. #
  47. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  48. # Plant-events:
  49. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  50. # When plants are placed on the map, their associated event is loaded based on
  51. # an event from another designated map in your project. The default script
  52. # expects all of these events to be on one map. (The map is used like a proxy
  53. # its sole purpose should be to store the event data for the plants in your
  54. # project).
  55. #
  56. # The ID of the map that these events are stored in is specified by
  57. #
  58. # GardenRa::SeedMap
  59. #
  60. # Change the value of this constant to the id number of the map which you will
  61. # be using to store your plant events.
  62. #
  63. # How to create a plant-event:
  64. # The next step after after creating the plant-item and plant-events-map is
  65. # creating the plant-event, i.e. the event (or events) that will be associated
  66. # with the plant. This is what allows the plant to be seen on the map.
  67. #
  68. # Plants are associated with events based on the name of the associated item
  69. # and the name of the associated event.
  70. # Events can be associated with plants by giving them the name of the plant
  71. # followed by a space, folled by an integer.
  72. #
  73. # For example:
  74. # We want to make a plant called 'Strawberry'.
  75. #
  76. # To do this, we have to make an item named 'Strawberry' and give it the
  77. # two essential notetags specified above. Make sure the item has no targets and
  78. # can only be used from the main menu (using the checkboxes in the database).
  79. #
  80. # After we've done this we must go to create an event to be associated with
  81. # the plant.
  82. #
  83. # So we go to the designated map in our project and e decide to name the event
  84. # 'Stawberry 1'.
  85. # By doing this, we've let the script know that the event with the name
  86. # 'Strawberry 1' is the first event that will be used to display the stages of
  87. # the item name 'Strawberry'.
  88. #
  89. # Let's say we've specified the strawberry to have 7 stages in the note tag box:
  90. #
  91. # <seed stages 7>
  92. #
  93. # By default each plant-event can be used to represent 5 growth stages.
  94. # But what is a stage?
  95. # A stage is represented by a page of an event. In the default script, once a
  96. # plant-event is placed on the map, its self switches will be iterated through
  97. # from 'A' to 'D'. The next self-switch is turned on each time the plant
  98. # advances a stage in that order (First A, then B, then C, then D).
  99. #
  100. # This means that we can represent 5 stages of growth for our strawberry with
  101. # one event (The first stage has no selfswitches on, the second stage has self-
  102. # switch 'A' on, the third stage has self-switch 'B' on, etc.)
  103. #
  104. # Create the event in your designated plant-events-map and make 4 additional
  105. # pages for it so that it has five pages total. Use a different picture for
  106. # each stage so that when the event's self-switches are flipped on it will appear
  107. # that it is growing.
  108. #
  109. # But there is a problem! We specified that we wanted our plant to have 7 stages
  110. # not 5. How do we handle the extra two stages?
  111. # Just make another event and associate it with the 'Strawberry' item.
  112. #
  113. # The next event we make we name as 'Strawberry 2'.
  114. # For this event, it's not necessary to create 5 pages for it. We only need two
  115. # total pages on this event. One for when it has no self-switches on and one for
  116. # when self-switch 'A' is on.
  117. # This event will represent stages 6 and 7 in the overall growth of our plant.
  118. # The script an handle any number of events created this way for any given plant.
  119. #
  120. # If we wanted to make a plant with 100 growth stages, we would just have to make
  121. # 20 different events, set up the 5 pages on each of those events, and name them
  122. # sequentially so that the script knows which plant-event to choose when it is
  123. # changing events.
  124. #
  125. # We are now done creating our plant. To place the plant on the map all you have
  126. # to do is use it from your inventory just like you would any other item.
  127. #
  128. # If it is not clear how to create plants based on the above instructions I
  129. # apologize, I have made a video and have a demo as well which might be easier
  130. # to understand.
  131. #
  132. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  133. # Specifying looping plants:
  134. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  135. #
  136. # Use these notetags:
  137. # <seed loop true>
  138. # <Seed loop stage VALUE>
  139. #
  140. # - Replace 'VALUE' in the above notetags with an integer -
  141. #
  142. # To specify a plant that will loop back to a previous stage after it has grown
  143. # to it's last stage.
  144. # 'VALUE' is the stage number that it will loop back to.
  145. #
  146. # This might be useful if you have a plant that should cycle through stages
  147. # repetetively, like a tree changing through the seasons.
  148. #
  149. # Seeds can be limited to certain terrain tags with this notetag:
  150. # <Seed terrain VALUE,VALUE,...>
  151. #
  152. # - replace 'VALUE' with an integer. each value must be separated by a comma the
  153. # elipses are there to denote the pattern continues, don't actually put elispses
  154. # in the notetag -
  155. # For example, to specify a seed can only be planted on terrain tags 0, 7, 4,
  156. # and 5, you would use this notetag:
  157. #
  158. # <seed terrain 5,7,0,4>
  159. #
  160. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  161. # Fertillizer:
  162. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  163. #
  164. # Plants can be fertilliezed by items which are fertillizers. To make a fertillizer
  165. # use this notetag:
  166. #
  167. # <Seed fertillizer FLOAT>
  168. #
  169. # - Replace FLOAT with a floating point number between 0 and 1, for example 0.32 -
  170. # The value you use in this parameter represents the concentration of the fertillizer
  171. # As the concentration of the fertillizer increases the growth rate of the plant
  172. # will also increase. Additionally, the yield of a plant will increase based on
  173. # the amount of fertillizer that has been applied to it.
  174. #
  175. # Fertillizer is used by using the associated item from the player's inventory.
  176. # After you see the fertillizer on the ground, you can plant a seed at that
  177. # location to apply the fertillizer to the seed. The fertillizer can also be
  178. # applied after the seed has started growing, as long as the seed is not
  179. # at its last stage of growth.
  180. #
  181. # Limiting the amount of fertillizer that can be applied to a plant:
  182. #
  183. # If you want to limit the amount of fertillizer that a plant can applied to a
  184. # plant use this notetag:
  185. #
  186. # <seed max fertillizer FLOAT>
  187. #
  188. # - Replace 'FLOAT' with a floating point number between 0 and 1 -
  189. #
  190. # Plants can also be given a 'Fertillizer effect ratio'
  191. # The lower this ratio is, the less of an effect fertillization will have on that
  192. # plant.
  193. # To set this value use this notetag:
  194. #
  195. # <seed fertile rate FLOAT>
  196. #
  197. # - Replace 'FLOAT' with a floating point number between 0 and 1 -
  198. #
  199. # You can limit fertillizer to only being planted in certain areas with this
  200. # notetag:
  201. # <fertillizer terrain VALUE,VALUE,VALUE...>
  202. # - replace 'VALUE' with an integer. each value must be separated by a comma the
  203. # elipses are there to denote the pattern continues, don't actually put elispses
  204. # in the notetag-
  205. #
  206. # For example, to specify a fertillizer can only be placed on terrain tags 0 and
  207. # 2 use this notetag:
  208. #
  209. # <fertillizer terrain 0,2>
  210. #
  211. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  212. # Watering Plants:
  213. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  214. #
  215. # Plants can be watered any number of times during each of their growth stages.
  216. # They can be set to die if they aren't watered enough or if they are watered
  217. # too much.
  218. # Plants can also be given an optimal water amount. The optimal water amount is
  219. # the amount of times the plant should be watered during each stage of growth
  220. # in order to maximize the harvest for that plant.
  221. #
  222. # Set minimum water amounts with this notetag:
  223. # <seed min water VALUE>
  224. #
  225. # Set maximum water amount with this notetag:
  226. # <seed max water VALUE>
  227. #
  228. # Set optimal water amount with this notetag:
  229. # <seed optimal water VALUE>
  230. #
  231. # - Replace 'VALUE' in the above notetags with an integer -
  232. #
  233. # Making a water container:
  234. # Water containers are items that can be used to water plants. Once the party
  235. # has a water container in their inventory, just walk up to a plant that isn't
  236. # fully grown and press the interact key to water it
  237. # You can denote items as water containers with this notetag:
  238. #
  239. # <water container VALUE>
  240. # VALUE is the how much water the container can hold.
  241. #
  242. # - Replace 'VALUE' in the above notetag with an integer-
  243. #
  244. # Water containers can be refilled using this script call from an event:
  245. #
  246. # garden_fill_containers
  247. #
  248. # You can also pass in an optional integer value to that method to modify all of
  249. # the water containers in the parties inventory by that amount.
  250. #
  251. # Harvesting and clearing plants
  252. #
  253. # Use this notetag:
  254. # <Seed harvest VALUE>
  255. #
  256. # - Replace 'VALUE' in the above notetag with an integer-
  257. #
  258. # To set the base harvest amount for a plant. The base harvest amount will be
  259. # achieved at harvest time if the plant was watered optimally at each stage.
  260. # The base harvest amount can be exceeded if the plant was fertillized.
  261. #
  262. # Use this notetag:
  263. # <clears crops VALUE>
  264. #
  265. # to mark an item or skill as being able to clear crops. Once an item is marked
  266. # with this notetag, you can use it to remove plants. if an integer value
  267. # is specified, the range of effect of the item will be increased.
  268. # For example:
  269. # <clears crops 1> means that the item will clear all of the crops adjacent to
  270. # the player.
  271. # <clears crops 2> will clear al of the plants at a distance of 2 from the player
  272. # <clears crops> without a value specified means the item can only be used to
  273. # clear crops directly in front of the player.
  274. #
  275. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  276. # Setting up the map:
  277. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  278. #
  279. # If you want your fertillizer to erode over time, you need to use these
  280. # notetags when setting up your map:
  281. #
  282. # <Erosion rate VALUE>
  283. # <Erosion value FLOAT>
  284. #
  285. # The erosion rate is specified in frames and is how quickly the fertilizer will
  286. # erode. The erosion value is how much fertillizer concentration will be
  287. # decremented by after each tic. A tic being equal to the specified erosion rate.
  288. #
  289. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  290. # Additonal settings
  291. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  292. #
  293. # If you are using the same events for multiple skills or items and don't want
  294. # all of those skills or items to have the same name, use this notetag:
  295. #
  296. # <seed name NAME>
  297. # - replace 'NAME' with the name of the event -
  298. #
  299. # To explicitly associate the item with the event of that name.
  300. #
  301. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  302. # Author Notes:
  303. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  304. #
  305. # By default, the Shift key can be held down when placing fertillizer or planting
  306. # a seed to put it infront of the player instead of at the same location the
  307. # player is standing.
  308. #
  309. # Fertillizer is applied at the time the plant is planted or the fertillizer is
  310. # placed. If the fertillizer concentration at that location changes after this
  311. # it is not reapplied.
  312. #
  313. # Internal common events are created to use the clearing items, the seeds, and
  314. # the fertillizer. If one of these items is associated with another common event
  315. # the internal common event will run first, then the event you have specified will
  316. # run.
  317. #
  318. # To do list:
  319. # There is currently no animation or fading shown when fertillizer is removed
  320. # from the map. Fix this.
  321. # There is currently no animation for watering plants.
  322. # Add a feature to change the precedence of internal common events vs. real
  323. # events.
  324. #
  325. #------------------------------------------------------------------------------
  326. # Thanks & Acknowledgments:
  327. #------------------------------------------------------------------------------
  328. #
  329. # Tsukihime - Custom DM
  330. # Celianna - Sprites
  331. #
  332. #------------------------------------------------------------------------------
  333. #
  334. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  335. # Original Release Date: 4 Dec. 2012
  336. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  337. #
  338. # Update Log
  339. # 7 Dec. 2012 - Fixed crashes when trying to equip items.
  340. # 5 Dec. 2012 - Fixed improper alias for move_straight inside Game_Characters
  341. #
  342. # 3 Nov. 2012 - Added support to clear crops. More options to harvest, fixed
  343. # fertillization rates, added popups to show how much was
  344. # harvested.
  345. #
  346. # 2 Nov. 2012 - First Version Finished
  347. #
  348. # 27 Oct. 2012 - Started work.
  349. #
  350. #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  351. # Terms of Use
  352. #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  353. # Free to use as you please. Please respect the header though so the dates can
  354. # be preserved.
  355. #------------------------------------------------------------------------------
  356.  
  357. $imported ||= {}
  358. raise "Couldn't find: Tsuki_CustomDataManager" if !$imported["Tsuki_CustomDataManager"]
  359. raise "Couldn't find: Ra Event Spawn v0.1" if ($imported["Ra Event Spawn"] ||=-1) < 0.1
  360. raise "Couldn't find: Ra Highlights v0.1" if ($imported["Ra Highlights"] ||=-1) < 0.1
  361. raise "Couldn't find: Ra Custom DM add-on" if ($imported["Ra Custom DM add-on"] ||=-1) < 0.1
  362. $imported["Ra Gardening"] = 0.1
  363. #==============================================================================
  364. # ** RPG::BaseItem
  365. #==============================================================================
  366. class RPG::BaseItem
  367. attr_accessor :clears_crops # this item can be used to clear crops
  368. def clears_crops?; false; end
  369. def is_garden_seed?; false; end
  370. def is_fertillizer?; false; end
  371. end
  372. #==============================================================================
  373. # ** RPG::UsableItem
  374. #==============================================================================
  375. class RPG::UsableItem < RPG::BaseItem
  376. attr_accessor :seed_loop # boolean
  377. attr_accessor :seed_stages # int
  378. attr_accessor :seed_rate # int
  379. attr_accessor :seed_events # array
  380. attr_accessor :seed_name
  381. attr_accessor :loop_stage # int
  382. attr_accessor :seed_terrain # hash
  383. attr_accessor :fertillizer_rate # float (rate of the fertillizer)
  384. attr_accessor :fertile_effect # float (modifer, property of seeds)
  385. attr_accessor :fertillizer_terrain # hash
  386. attr_accessor :seed_optimal_water # optimal times to water this seed per stage
  387. attr_accessor :seed_max_water # plant will die if watered more than this many times per stage
  388. attr_accessor :seed_base_harvest # maximum output from seed when calculating harvest
  389. attr_accessor :seed_max_fertillizer # dies after this much fertilizer is applied
  390. attr_accessor :water_amount_uses # amount of times item can be used for water before needing to be refilled
  391. attr_accessor :water_available_uses # amount of available water
  392. attr_accessor :seed_water_min # min times seed should be watered per stage
  393.  
  394. def garden_item_default_values
  395. @seed_loop = false
  396. @seed_stages = 0
  397. @seed_rate = 0
  398. @seed_events = []
  399. @seed_name = nil
  400. @loop_stage = 0
  401. @seed_terrain = nil
  402. @fertillizer_rate = 0.0
  403. @fertile_effect = 0.0
  404. fertillizer_terrain = nil
  405. @seed_optimal_water = 0
  406. @seed_max_water = 1<<31
  407. @seed_base_harvest = 7
  408. @seed_max_fertillizer = 0.8
  409. @water_amount_uses = -1
  410. @water_available_uses = 0
  411. @seed_water_min = 0
  412. @clears_crops = false
  413. end
  414. #----------------------------------------------------------------------------
  415. # * Item is a representation of a seed?
  416. #----------------------------------------------------------------------------
  417. def is_garden_seed?
  418. @seed_rate > 0
  419. end
  420. #----------------------------------------------------------------------------
  421. # * Item is a representation of Fertillizer?
  422. #----------------------------------------------------------------------------
  423. def is_fertillizer?
  424. @fertillizer_rate > 0
  425. end
  426. #----------------------------------------------------------------------------
  427. # * Item is a representation of a watering container?
  428. #----------------------------------------------------------------------------
  429. def is_waterer?
  430. @water_amount_uses > -1
  431. end
  432. #----------------------------------------------------------------------------
  433. # * Item clears the crop infront of the player when it's used
  434. #----------------------------------------------------------------------------
  435. def clears_crops?
  436. @clears_crops
  437. end
  438. #----------------------------------------------------------------------------
  439. # * Terrains which this seed/fertillizer can be placed on
  440. #----------------------------------------------------------------------------
  441. def garden_terrains(tag)
  442. if is_garden_seed?
  443. return true if seed_terrain.nil?
  444. return seed_terrain[tag]
  445. else
  446. return true if fertillizer_terrain.nil?
  447. return fertillizer_terrain[tag]
  448. end
  449. end
  450. #----------------------------------------------------------------------------
  451. # * The seed/fertillizer can be placed anywhere?
  452. #----------------------------------------------------------------------------
  453. def garden_ok_anywhere?
  454. fertillizer_terrain.nil? && seed_terrain.nil?
  455. end
  456. #----------------------------------------------------------------------------
  457. # * Set the Terrain Tags for a Seed
  458. #----------------------------------------------------------------------------
  459. def set_seed_terrains(tags)
  460. split_tags_era(tags, @seed_terrain={})
  461. end
  462. #----------------------------------------------------------------------------
  463. # * Set the Terrain Tags for Fertillizer
  464. #----------------------------------------------------------------------------
  465. def set_fertillizer_terrains(tags)
  466. split_tags_era(tags, @fertillizer_terrain={})
  467. end
  468. #----------------------------------------------------------------------------
  469. # * Split Tags - Helper method to reduce repetitive code when loading in
  470. # terrain tag data
  471. #----------------------------------------------------------------------------
  472. def split_tags_era(tags, v)
  473. tags.split(",").each{ |tag|
  474. v[tag.strip.to_i] = true
  475. }
  476. end
  477. #----------------------------------------------------------------------------
  478. # * Update Waterer Description - modify the description of water containers
  479. # to show the currently available water and the maximum amount of water.
  480. #----------------------------------------------------------------------------
  481. def update_waterer_description(orig = false)
  482. @org_desc_gd = @description if orig
  483.  
  484. lines = @org_desc_gd.split(/[\r\n]+/)
  485. lpos = lines.length-1
  486.  
  487. carrying = "Current Water: #{@water_available_uses}"
  488. capacity = "Max: #{@water_amount_uses}"
  489.  
  490. return @description = @org_desc_gd+carrying<<" "<<capacity if lpos < 0
  491.  
  492. last = lines[lpos]
  493.  
  494. last = "#{last} #{carrying} #{capacity}\n"
  495. lines[lpos] = last
  496. accum = ""
  497. lines.each{ |line|
  498. accum<<line<<"\r\n"
  499. }
  500. @description = accum
  501. end
  502. #----------------------------------------------------------------------------
  503. # * Modify the water available in a watering container
  504. #----------------------------------------------------------------------------
  505. def mod_waterer_available_uses(mod)
  506. @water_available_uses += mod
  507. if @water_available_uses < 0
  508. @water_available_uses = 0
  509. elsif @water_available_uses > @water_amount_uses
  510. @water_available_uses = @water_amount_uses
  511. end
  512. update_waterer_description
  513. end # mod_waterer_available_uses
  514. end # RPG::UsableItem
  515.  
  516. #==============================================================================
  517. # ** RPG::MapInfo
  518. #==============================================================================
  519. class RPG::MapInfo
  520. attr_accessor :erosion_rate
  521. attr_accessor :erosion_value
  522. end # RPG::MapInfo
  523.  
  524. #==============================================================================
  525. # ** GardenRa
  526. # Module containing script settings as well as the helper method plant_seed
  527. # which will plant a seed on the map.
  528. #==============================================================================
  529. module GardenRa
  530. # The default map to pull events from
  531. SeedMap = 2
  532.  
  533. # Default growth rate
  534. DefGrowRate = 70
  535.  
  536. # Default stages per event
  537. StagesPerEvent = 5
  538.  
  539. # Will show the fertillized locations when map loaded
  540. ShowFertillizer = true
  541.  
  542. # Ignore the next 'n' commands when turning if TurnFirst
  543. TurnDelay = 4
  544.  
  545. # Plant seeds even if theres an event at the position
  546. PlantOntop = false
  547.  
  548. # Symbol for key which allows planting/fertillizing infront of the player
  549. Front = :A
  550.  
  551. # False if you want to hide the text popups that show up when harvesting
  552. ShowTextPopups = true
  553.  
  554. # True if you want to use an image from a file for fertillizer
  555. UseSheetData = true
  556.  
  557.  
  558. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  559. # Specify the Graphic you want to use as fertillizer here. The graphic should
  560. # be stored inside Graphics/Characters.
  561. #
  562. # FertName is the name of the file with the Fertillizer graphic in it.
  563. #
  564. # Index is the index of the set of images you want to use from the file you
  565. # specified (for example, in the default spritesheets 8 sets of images are
  566. # specified per file). The index sould range from 0 - 7
  567. #
  568. # FertRow is the row you want to use as the animation for the fertillizer.
  569. #
  570. # FertFreq is how quickly the animation should iterate.
  571. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  572.  
  573. # Name of the file with the fertillizer image, the file should be stored in
  574. # Graphics/Characters
  575. FertName = '$Fertillizer'
  576.  
  577. # The index of the set of images you want to use from the file specified above
  578. # can be 0 - 7 in the default engine
  579. FertIndex = 0
  580.  
  581. # The row of the set of images to use based on the specifed file.
  582. # with the default engine this value should range from 0 - 3
  583. FertRow = 0
  584.  
  585. # How quickly the graphic for the fertillizer should change.
  586. FertFreq = 24
  587.  
  588. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  589. # SS is a hash representing the self switches in the game, add addtional keys
  590. # if you're using additional self switches for your game. I.e. if you were
  591. # using a self switch 'E' in your project you would change the hash to look
  592. # like:
  593. # SS = { 0 => false, 1 => 'A', 2 => 'B', 3 => 'C', 4 => 'D', 5 => 'E' }
  594. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  595. SS = { 0 => false, 1 => 'A', 2 => 'B', 3 => 'C', 4 => 'D' }
  596.  
  597. # The internal common event for using fertillizer
  598. CE_Place_Fertillizer = Proc.new{ |id, is_item|
  599. front = Input.press?(GardenRa::Front)
  600.  
  601. xy = $game_temp.garden_seed_temp_xy_helper(id, front)
  602. rate = $data_items[id].fertillizer_rate
  603. $game_map.add_fertillizer(rate, [[xy[0],xy[1]]])
  604. }
  605.  
  606. # The internal common event for using a seed
  607. CE_Plant_Seeds = Proc.new{ |id, is_item|
  608. item = is_item ? $data_items[id] : $data_skills[id]
  609. front = Input.press?(GardenRa::Front)
  610. xy = $game_temp.garden_seed_temp_xy_helper(id, front)
  611. GardenRa.plant_seed(item, $game_system.add_plant, true, {:x=>xy[0],:y=>xy[1]})
  612. }
  613.  
  614. Harvest_Crop = Proc.new{ |item_id, intp, destroy|
  615. h=intp.harvest_garden_plant(destroy)
  616. item = $data_items[item_id]
  617. $game_party.gain_item(item, as_int = h.to_i)
  618.  
  619. return unless (scene = SceneManager.scene).is_a?(Scene_Map) && GardenRa::ShowTextPopups
  620. spm = scene.instance_eval('@spriteset')
  621.  
  622. plms= as_int < 0 ? "" : "+"
  623. spm.add_spgt_to_spm("#{plms}#{as_int} #{item.name}") # Add a spiggot to a spim!
  624. }
  625.  
  626. Clear_Crop = Proc.new{
  627. map = $game_map
  628. seeds_to_clear = $game_temp.temp_seed_clear
  629. seeds_to_clear.each{ |ev|
  630.  
  631. plant_id = ev.plant.plant_id #~*
  632. $game_system.destroy_plant(ev.plant.plant_id)
  633. }
  634. $game_temp.temp_seed_clear = [] # reset temp data after access
  635. }
  636.  
  637. #----------------------------------------------------------------------------
  638. # ** Regular Expressions
  639. # Be sure to maintain the parenthesis if you're goint to modify specific
  640. # words in the regular expressions (unless you're making the changes
  641. # intentionally making of course).
  642. #----------------------------------------------------------------------------
  643. module RE
  644.  
  645. # number stages of growth
  646. Stages = /<Seed stages (\d+)>/i
  647.  
  648. # do stages loop?
  649. Loop = /<Seed loop (true|false|t|f)>/i
  650.  
  651. # growth rate, larger means slower
  652. Rate = /<Seed rate (\d+)>/i
  653.  
  654. # Can specify the name of the seed per item
  655. SeedName = /<Seed name (.+)>/i
  656.  
  657. # The stage to be looped back to
  658. LoopStage = /<Seed loop stage (\d+)>/i
  659.  
  660. # The terrain tags a seed can be planted on
  661. SeedTerrain = /<\s*Seed\s*terrain\s*(\d+\s*(?:,\s*\d+\s*)*)\s*>/i
  662.  
  663. # Use to set an item as a fertillizer and give it a fertillizer concentration
  664. Fertillizer = /<\s*Seed\s*Fertillizer\s*((?:\d+|)\.(?:\d+))\s*>/i
  665.  
  666. # The effect that fertillizer has on this specific seed. The lower the value
  667. # provided, the more resistant the seed is to being fertillized.
  668. FertileEffect = /<\s*Seed\s*Fertile\s*rate\s*((?:\d+|)\.(?:\d+))\s*>/i
  669.  
  670. # Terrain where fertillizer can be placed
  671. FertTerrain = /<\s*Seed\s*Fertillizer\s*terrain\s*(\d+\s*(?:,\s*\d+\s*)*)\s*>/i
  672.  
  673. # The maximum concentration of fertillizer a plant can grow in.
  674. MaxFertillizer = /<\s*Seed\s*max\s*fertillizer\s*((?:\d+|)\.(?:\d+))\s*>/i
  675.  
  676. # The optimal amount of times that a plant should be watered during each
  677. # growth stage
  678. OptimalWaterPerStage = /<\s*Seed\s*optimal\s*water\s*(\d+)\s*>/i
  679.  
  680. # The plant will die if it is watered more than this many times on one stage
  681. OverWatered = /<\s*Seed\s*max\s*water\s*(\d+)\s*>/i
  682.  
  683. # Maximum base output from this plant, this value can be exceeded if the
  684. # plant is fertillized.
  685. MaxHarvest = /<\s*Seed\s*harvest\s*(\d+)\s*>/i
  686.  
  687. # The maximum amount of water a container can hold
  688. SeedWatering = /<\s*water\s*container\s*(\d+)\s*>/i #
  689.  
  690. # The minimum amount of times a seed must be watered per growth stage
  691. SeedWateringMin = /<\s*Seed\s*min\s*water\s*(\d+)\s*>/i # minimum times a seedmust be watered per growth stage
  692.  
  693. # How much the fertillizer will be reduced on this map when it is eroding
  694. FertillizerErodeAmt = /<\s*Erosion\s*Value\s*((?:\d+|)\.(?:\d+))>/i
  695.  
  696. # How quickly the map will erode, specified in frames
  697. FertillizerErodeRate = /<\s*Erosion\s*Rate\s*(\d+)>/i
  698.  
  699. # Item can be used to clear crops out of the way
  700. ClearCrops = /<\s*clears\s*crops\s*(\d+|)\s*>/i
  701. end # RE
  702.  
  703. #----------------------------------------------------------------------------
  704. # * Plant Seed
  705. # param: args[0] is the item (the seed) that is being planted
  706. # param: args[1] is the id of the plant
  707. # param: args[2] is true if the seed is being planted for the first time
  708. # param: args[3] is an options hash to be given to the EventEng script
  709. # param: args[4] is the position in item.seed_events which will be accessed to
  710. # get the event's id for the new seed.
  711. # param: args[5] is a numeric representation of what stage the plants growth
  712. # is on.
  713. #----------------------------------------------------------------------------
  714. def self.plant_seed(*args)
  715.  
  716. item = args[0]
  717. plant_id = args[1] # the unique plant id this event is associated with
  718. planting = args[2]
  719. opts = (t = args[3]) ? t : {} # optional
  720. pos = (t = args[4]) ? t : 0 # optional
  721. stage = (t = args[5]) ? t : 1 # optional
  722.  
  723. options = {
  724. :map_id => GardenRa::SeedMap,
  725. :x => $game_player.x,
  726. :y => $game_player.y,
  727. :persist => false,
  728. :dir => 2,
  729. :SS => {} # hash of self switches can be passed ({:A => true...})
  730. }.merge(opts)
  731.  
  732. t = $game_system.plant_info(plant_id)
  733.  
  734. t[:item] = item
  735. t[:pos] = pos
  736. t[:cur_stage] = stage
  737.  
  738. t[:max_fertile] = (tmp = t[:max_fertile]) ? tmp : item.seed_max_fertillizer
  739. t[:grow_frames] = (tmp = t[:grow_frames]) ? tmp : item.seed_rate
  740. t[:loop] = (tmp = t[:loop]) ? tmp : item.seed_loop
  741. t[:loop_stage] = (tmp = t[:loop_stage]) ? tmp : item.loop_stage
  742. t[:fertile_effect] = (tmp = t[:fertile_effect]) ? tmp : item.fertile_effect
  743.  
  744. e_id = item.seed_events[t[:pos]]
  745. event = EventSpawn.spawn_event(options[:map_id], e_id, options[:x],
  746. options[:y], options[:persist], options[:dir], options[:SS])
  747. event.start_plant(plant_id, planting) unless event.nil?# Only time a garden object is created
  748. end # plant_seed
  749. #----------------------------------------------------------------------------
  750. # Self switch which corresponds to param: stage
  751. #----------------------------------------------------------------------------
  752. def self.stage_to_ss(stage)
  753. SS[(stage-1) % GardenRa::StagesPerEvent]
  754. end # stage_to_ss
  755.  
  756. end # GardenRa
  757.  
  758. #==============================================================================
  759. # ** DataManager
  760. # Loads item data for fertillizers and seeds
  761. #==============================================================================
  762. module DataManager
  763. #----------------------------------------------------------------------------
  764. # * Alias - load_database
  765. #----------------------------------------------------------------------------
  766. class <<self
  767. alias load_garden_seed_pl_ntags load_database
  768. end
  769. #----------------------------------------------------------------------------
  770. # * Load Database
  771. #----------------------------------------------------------------------------
  772. def self.load_database
  773. load_garden_seed_pl_ntags
  774. load_tags_garden_seed_itm
  775. end
  776. #----------------------------------------------------------------------------
  777. # * Load Tags
  778. #----------------------------------------------------------------------------
  779. def self.load_tags_garden_seed_itm
  780. iter = [$data_items, $data_skills]
  781. @tmp_map = load_data(sprintf("Data/Map%03d.rvdata2", GardenRa::SeedMap))
  782. iter.each do |set|
  783. set.each_with_index do |item, i|
  784. next unless item
  785.  
  786. item.garden_item_default_values
  787.  
  788. item.note.split(/[\r\n]+/).each do |line|
  789. case line
  790. when GardenRa::RE::Stages
  791. item.seed_stages = $1.to_i
  792. when GardenRa::RE::Loop
  793. item.seed_loop = $1.eql?("true") || $1.eql?("t")
  794. when GardenRa::RE::Rate
  795. item.seed_rate = $1.to_i
  796. when GardenRa::RE::SeedName
  797. item.seed_name = $1
  798. when GardenRa::RE::LoopStage
  799. item.loop_stage = $1.to_i
  800. when GardenRa::RE::SeedTerrain
  801. item.set_seed_terrains($1)
  802. when GardenRa::RE::Fertillizer
  803. item.fertillizer_rate = $1.to_f
  804. when GardenRa::RE::FertileEffect
  805. item.fertile_effect = $1.to_f
  806. when GardenRa::RE::FertTerrain
  807. item.set_fertillizer_terrains($1)
  808. when GardenRa::RE::OptimalWaterPerStage
  809. item.seed_optimal_water = $1.to_i
  810. when GardenRa::RE::OverWatered
  811. item.seed_max_water = $1.to_i
  812. when GardenRa::RE::MaxHarvest
  813. item.seed_base_harvest = $1.to_i
  814. when GardenRa::RE::MaxFertillizer
  815. item.seed_max_fertillizer = $1.to_f
  816. when GardenRa::RE::SeedWatering
  817. item.water_available_uses = item.water_amount_uses = $1.to_i
  818. item.update_waterer_description(true)
  819. item.is_unique_rpgbi = true
  820. when GardenRa::RE::SeedWateringMin
  821. item.seed_water_min = $1.to_i
  822. when GardenRa::RE::ClearCrops
  823. item.clears_crops = $1.to_i
  824. end
  825. end
  826.  
  827. load_seed_events(i,item.instance_of?(RPG::Item))
  828.  
  829. end # set.each_with_index
  830. end # iter.each
  831. end # load_tags_garden_seed_itm
  832. #----------------------------------------------------------------------------
  833. # * Load seed events - store the event data
  834. #----------------------------------------------------------------------------
  835. def self.load_seed_events(i, is_item)
  836. item = is_item ? $data_items[i] : $data_skills[i]
  837. temp_hash = {}
  838. item.seed_events = []
  839. events = @tmp_map.events
  840. name = !(s = item.seed_name).nil? ? s : item.name
  841. events.values.each do |ev|
  842. next unless ev
  843. case ev.name
  844. when /^#{name} (\d+)\s*$/i
  845. temp_hash[$1.to_i] = ev.id # temporarily store the events in a hash
  846. end
  847. end
  848.  
  849. keys = temp_hash.keys.sort! # order the events
  850. keys.each{ |k| item.seed_events.push(temp_hash[k]) } # store events in order
  851. end # load_seed_events
  852.  
  853. end # DataManager
  854.  
  855. #==============================================================================
  856. # ** Garden_Object
  857. # The representation of a plant.
  858. #==============================================================================
  859. class Garden_Object
  860. attr_reader :low
  861. attr_reader :plant_id
  862. attr_reader :fertillized
  863. #----------------------------------------------------------------------------
  864. # * Initialize
  865. #----------------------------------------------------------------------------
  866. def initialize(plant_id, ev_id, planting = false)
  867. @low = true
  868. @ev_id = ev_id
  869. @plant_id = plant_id
  870. @p_info = $game_system.plant_info(@plant_id)
  871.  
  872. load_grow_data
  873. apply_fertillizer if planting
  874. store_init_data
  875. store_xy
  876. end
  877. #----------------------------------------------------------------------------
  878. # * Apply Fertillizer
  879. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  880. # The Fertillizer's effect is calculated by multplying the fertile_effect of
  881. # the seed with the fertilizer_rate of the of its location on the map and
  882. # then applying that value to @grow_frames.
  883. # Example:
  884. # A spot on the map with a fertillizer concentration of .5 applied to a
  885. # seed which grows every 50 frames and a "fertile_effect" of .9 would
  886. # end up with a grow_rate of 0.9*0.5*50 = 22.5.
  887. #----------------------------------------------------------------------------
  888. def apply_fertillizer
  889. f_data = $game_system.fertillizer_data
  890. ev = $game_map.events[@ev_id]
  891. x,y = ev.x, ev.y
  892. f_rate = f_data[[x,y]]
  893.  
  894. return if !f_rate
  895.  
  896. f_effect = @p_info[:item].fertile_effect
  897. f_effect = !f_effect.nil? ? f_effect : (@p_info[:item].fertile_effect = 1)
  898. f_rate = !f_rate.nil? ? f_rate + (f_rate * f_effect) : 1
  899.  
  900. update_fertile_input(f_rate)
  901. new_gf = [@grow_frames * (1-f_rate),1].max.to_i
  902.  
  903. @p_info[:grow_frames] = @grow_frames = new_gf
  904. print "applied fertillizer\n"
  905. end
  906. #----------------------------------------------------------------------------
  907. # * Update Fertillizer Input
  908. #----------------------------------------------------------------------------
  909. def update_fertile_input(rate)
  910. @p_info[:fertile_input] = rate
  911. end
  912. #----------------------------------------------------------------------------
  913. # * Store position
  914. #----------------------------------------------------------------------------
  915. def store_xy
  916. event = $game_map.events[@ev_id]
  917. @p_info[:x], @p_info[:y] = event.x, event.y
  918. end
  919. #----------------------------------------------------------------------------
  920. # * Plant id should be added to the game system before making a garden object
  921. #----------------------------------------------------------------------------
  922. def load_grow_data
  923. update_grow_frame((t = @p_info[:base_frame]) ? t : $game_system.garden_timer)
  924. @grow_frames = (t = @p_info[:grow_frames]) ? t : GardenRa::DefGrowRate
  925. @simple = (t = @p_info[:simple]) ? t : true # literal
  926. @loop = (t = @p_info[:loop]) ? t : false # literal
  927. @loop_stage = (t = @p_info[:loop_stage]) ? t : 1 #literal
  928. end
  929. #----------------------------------------------------------------------------
  930. # * Update Grow Frame
  931. #----------------------------------------------------------------------------
  932. def update_grow_frame(frame = @base_frame)
  933. @p_info[:base_frame] = @base_frame = frame
  934. end
  935. #----------------------------------------------------------------------------
  936. # * Store Init Data
  937. #----------------------------------------------------------------------------
  938. def store_init_data
  939. @p_info[:grow_frames] = @grow_frames
  940. @p_info[:simple] = @simple
  941. @p_info[:loop] = @loop
  942. @p_info[:loop_stage] = @loop_stage
  943. @p_info[:event_id] = @ev_id
  944. end
  945. #----------------------------------------------------------------------------
  946. # * Loop Stage
  947. #----------------------------------------------------------------------------
  948. def loop_stage
  949. @p_info[:loop_stage]
  950. end
  951. #----------------------------------------------------------------------------
  952. # * Last Stage
  953. #----------------------------------------------------------------------------
  954. def last_stage
  955. @p_info[:item].seed_stages
  956. end
  957. #----------------------------------------------------------------------------
  958. # * Update
  959. #----------------------------------------------------------------------------
  960. def update
  961. check_should_die
  962. return if @p_info[:dead]
  963. return if (needs_to_loop = stage == item.seed_stages) && !@loop
  964. return if !@loop && stage == last_stage
  965. if need_jump?
  966. jump_ahead
  967. else
  968. update_grow(needs_to_loop)
  969. end
  970. end
  971. #----------------------------------------------------------------------------
  972. # * Modify the times the plant has been watered
  973. #----------------------------------------------------------------------------
  974. def mod_times_watered(st,fn,reset=true,mod=0)
  975. $game_system.mod_times_watered(@plant_id, loop_stage, last_stage, reset, mod)
  976. end
  977. #----------------------------------------------------------------------------
  978. # * Does the plant need to 'jump' to the correct stage after not having been
  979. # updated for awhile. (Not on scene map or the map is being reloaded
  980. # after the player was transferred to it for the first time in some time)
  981. #----------------------------------------------------------------------------
  982. def need_jump?
  983. ($game_system.garden_timer - @base_frame) > @grow_frames
  984. end
  985. #----------------------------------------------------------------------------
  986. # * Update grow
  987. #----------------------------------------------------------------------------
  988. def update_grow(should_loop = false)
  989. if (gt = $game_system.garden_timer) - @base_frame == @grow_frames
  990.  
  991. mod_times_watered(loop_stage, last_stage) if should_loop
  992. update_grow_frame(gt)
  993.  
  994.  
  995. if should_loop && @loop
  996. old_stage = @p_info[:cur_stage]
  997. st_per = GardenRa::StagesPerEvent
  998. old_pos = pos
  999. update_stage(@p_info[:loop_stage])
  1000. nxt_ev
  1001.  
  1002. else
  1003. on_grow
  1004. end
  1005. $game_map.refresh
  1006. end
  1007. end
  1008. #----------------------------------------------------------------------------
  1009. # * Are Any Selfswitches On? - Currently only used for debugging,
  1010. # can be removed
  1011. #----------------------------------------------------------------------------
  1012. def any_ss_on?
  1013. EventSpawn::Constants::SS.each{|l|
  1014. return true if $game_self_switches[[$game_map.map_id, @ev_id, l]]
  1015. }
  1016. return false
  1017. end
  1018. #----------------------------------------------------------------------------
  1019. # * Update Stage
  1020. #----------------------------------------------------------------------------
  1021. def update_stage(new_stage)
  1022. @p_info[:cur_stage] = new_stage
  1023. @p_info[:pos] = (@p_info[:cur_stage] - 1)/GardenRa::StagesPerEvent
  1024. end
  1025. #----------------------------------------------------------------------------
  1026. # * On Last Stage
  1027. #----------------------------------------------------------------------------
  1028. def on_last_stage
  1029. stage == last_stage
  1030. end
  1031. #----------------------------------------------------------------------------
  1032. # * Stage
  1033. #----------------------------------------------------------------------------
  1034. def stage
  1035. @p_info[:cur_stage]
  1036. end
  1037. #----------------------------------------------------------------------------
  1038. # * Pos
  1039. #----------------------------------------------------------------------------
  1040. def pos
  1041. @p_info[:pos]
  1042. end
  1043. #----------------------------------------------------------------------------
  1044. # * Times Watered
  1045. #----------------------------------------------------------------------------
  1046. def times_watered(st = stage)
  1047. (@p_info[:watered_vals]||={})[st]||=0
  1048. end
  1049. #----------------------------------------------------------------------------
  1050. # * Max Water
  1051. #----------------------------------------------------------------------------
  1052. def max_water
  1053. item.seed_max_water
  1054. end
  1055. #----------------------------------------------------------------------------
  1056. # * On plant grow by default all plants are 'simple' but feel free to write
  1057. # more complicated growth patterns for plants.
  1058. #----------------------------------------------------------------------------
  1059. def on_grow
  1060. grow_simple if @simple
  1061. end
  1062. #----------------------------------------------------------------------------
  1063. # * Kill the plant
  1064. #----------------------------------------------------------------------------
  1065. def kill_plant(should_kill=true)
  1066. @p_info[:dead] = true
  1067. end
  1068. #----------------------------------------------------------------------------
  1069. # * Minimum number of times the plant should be watered per stage
  1070. #----------------------------------------------------------------------------
  1071. def min_water
  1072. item.seed_water_min
  1073. end
  1074. #----------------------------------------------------------------------------
  1075. # * Should the plant advance to the next stage?
  1076. #----------------------------------------------------------------------------
  1077. def is_at_stage_tic
  1078. $game_system.garden_timer - @base_frame == @grow_frames
  1079. end
  1080. #----------------------------------------------------------------------------
  1081. # * Check if the plant should still be alive
  1082. #----------------------------------------------------------------------------
  1083. def check_should_die(about_to_jump = false)
  1084.  
  1085. # can't dry up once on the last stage
  1086. dried_up = (is_at_stage_tic || about_to_jump) && !(min = min_water).nil? &&
  1087. times_watered < min && !on_last_stage
  1088. roots_molded = !(max = max_water).nil? && times_watered > max
  1089.  
  1090. if dried_up || roots_molded
  1091. return kill_plant
  1092. end
  1093. # if fertillizer is too concentrated or if watered too many times, @p_info[:dead] = true
  1094. return unless (cur=@p_info[:fertile_input]) && (max = @p_info[:max_fertile])
  1095. if cur > max
  1096. return kill_plant
  1097. end
  1098. end
  1099. #----------------------------------------------------------------------------
  1100. # * Dead?
  1101. #----------------------------------------------------------------------------
  1102. def dead?
  1103. @p_info[:dead]
  1104. end
  1105. #----------------------------------------------------------------------------
  1106. # * Harvest
  1107. # Returns an integer value calculated from the amount of times the plant
  1108. # was watered at each stage, the optimal amount of times for it to be
  1109. # watered, and the amount of fertillizer that was applied to it.
  1110. #----------------------------------------------------------------------------
  1111. def harvest
  1112. return 0 if dead?
  1113. base_output = base_harvest
  1114. fertillizer = fertillizer_concentration
  1115. offset_output = base_output * fertillizer + base_output
  1116. offset = 1-((t=number_stages_not_watered_optimally.to_f)/last_stage)
  1117. total_harvest = offset_output * offset
  1118.  
  1119. print "harvest: \n"
  1120. print " base_output = #{base_output}\n"
  1121. print " number_stages_not_watered_optimally = #{t}\n"
  1122. print " fertillizer = #{fertillizer}\n"
  1123. print " offset_output = #{offset_output}\n"
  1124. print " offset = #{offset}\n"
  1125. print " total harvest = #{total_harvest}\n"
  1126.  
  1127. return total_harvest.to_i
  1128. end
  1129. #----------------------------------------------------------------------------
  1130. # * Fertillizer concentration
  1131. #----------------------------------------------------------------------------
  1132. def fertillizer_concentration
  1133. @p_info[:fertile_input] ||= 0
  1134. end
  1135. #----------------------------------------------------------------------------
  1136. # * Not including the last stage
  1137. #----------------------------------------------------------------------------
  1138. def number_stages_not_watered_optimally
  1139. count = 0
  1140. optimal_water_per_st = optimal_water
  1141. (1...last_stage).each{ |st|
  1142. count += 1 if times_watered(st) != optimal_water_per_st
  1143. }
  1144. count
  1145. end
  1146. #----------------------------------------------------------------------------
  1147. # * Optimal times the plant should be watered on each stage
  1148. #----------------------------------------------------------------------------
  1149. def optimal_water
  1150. item.seed_optimal_water
  1151. end
  1152. #----------------------------------------------------------------------------
  1153. # * Base harvest amount
  1154. #----------------------------------------------------------------------------
  1155. def base_harvest
  1156. item.seed_base_harvest
  1157. end
  1158. #----------------------------------------------------------------------------
  1159. # The default garden plant will grow by turning its selfswitches on
  1160. # sequentially from A to D and then turning them all off and repeating.
  1161. #----------------------------------------------------------------------------
  1162. def grow_simple
  1163. stage = (@p_info[:cur_stage] += 1)
  1164. map_id = $game_map.map_id
  1165. ch = GardenRa.stage_to_ss(stage)
  1166. if !ch
  1167. handle_last_page
  1168. else
  1169. turn_on_ss(ch)
  1170. end
  1171.  
  1172. e = $game_map.events[@ev_id]
  1173. e.refresh unless e.nil? # nil when queuing a new event for the plant
  1174. end
  1175. #----------------------------------------------------------------------------
  1176. # * The item associated with this plant
  1177. #----------------------------------------------------------------------------
  1178. def item
  1179. @p_info[:item]
  1180. end
  1181. #----------------------------------------------------------------------------
  1182. # * The last stage that the current event has stored for this plant. I.e.
  1183. # the next event for this plants growth cycle will need to be placed on
  1184. # the map.
  1185. #----------------------------------------------------------------------------
  1186. def handle_last_page
  1187. nxt_ev if item.seed_events[@p_info[:pos]+1]
  1188. end # handle_last_page
  1189. #----------------------------------------------------------------------------
  1190. # * Replace the plants event, removes the current event associated with the
  1191. # plant and queues a new one to be placed on the map.
  1192. #----------------------------------------------------------------------------
  1193. def replace_plant_event(opts={})
  1194. map = $game_map
  1195. p_info = $game_system.plant_info(@plant_id)
  1196.  
  1197. event = map.events[@ev_id]
  1198. options = { :x => event.x, :y => event.y, :persist => false }.merge(opts)
  1199.  
  1200. map.destroy_event_any(@ev_id)
  1201. map.add_seed_to_plant(p_info[:item], @plant_id, false, options, p_info[:pos],
  1202. p_info[:cur_stage])
  1203. end
  1204. #----------------------------------------------------------------------------
  1205. # * Jump to the proper stage when reloading the plant on the map.
  1206. #----------------------------------------------------------------------------
  1207. def jump_ahead
  1208.  
  1209. dead = check_should_die(true) # param just tells method the plant wants to jump
  1210. return if dead
  1211.  
  1212. map, sys = $game_map, $game_system
  1213. st_per = GardenRa::StagesPerEvent
  1214. jump = ((gt = sys.garden_timer) - @base_frame) / @grow_frames # stages to skip
  1215. update_grow_frame(@base_frame+jump*@grow_frames)#((gt-@grow_frames) + ((gt - @base_frame) % @grow_frames))
  1216. old_stage = @p_info[:cur_stage]
  1217.  
  1218. # calculate roll over if @loop
  1219. loop_back = @loop && (n_st = jump + old_stage) > @p_info[:item].seed_stages
  1220. mod_times_watered(loop_stage, last_stage) if loop_back
  1221. new_stage = false
  1222.  
  1223. excess = 0
  1224. if loop_back
  1225. # loop in between:
  1226. loop_btw = @p_info[:item].seed_stages - (@p_info[:loop_stage]-1)
  1227. excess = n_st - @p_info[:item].seed_stages
  1228. new_stage = (@p_info[:loop_stage]-1) + (excess % loop_btw)
  1229. end
  1230.  
  1231. # store updated plant data
  1232. old_pos = (pos-1)/st_per
  1233. update_stage(new_stage ? new_stage : [old_stage + jump, item.seed_stages].min)
  1234. nxt_ev
  1235. end
  1236. #----------------------------------------------------------------------------
  1237. # * Queue up a new plant('seed to be planted') when the current plant has
  1238. # moved through all of the stages for its the current event
  1239. #----------------------------------------------------------------------------
  1240. def nxt_ev
  1241. @p_info[:pos] = (@p_info[:cur_stage]-1)/GardenRa::StagesPerEvent
  1242. ch = GardenRa.stage_to_ss(@p_info[:cur_stage])
  1243. opts = !ch ? {} : {:SS => {ch.to_sym => true}}
  1244. replace_plant_event(opts)
  1245. end
  1246. #----------------------------------------------------------------------------
  1247. # * Turn on Selfswich
  1248. #----------------------------------------------------------------------------
  1249. def turn_on_ss(ch, is_on = true)
  1250. $game_self_switches[[$game_map.map_id, @ev_id, ch]] = is_on unless !ch
  1251. end
  1252. #----------------------------------------------------------------------------
  1253. # * Reset Selfswitches
  1254. #----------------------------------------------------------------------------
  1255. def reset_ss
  1256. EventSpawn::Constants::SS.each{|l| turn_on_ss(l,false)}
  1257. end
  1258. #----------------------------------------------------------------------------
  1259. # *
  1260. #----------------------------------------------------------------------------
  1261. #def destroy_self
  1262. # $game_system.destroy_plant(@plant_id)
  1263. # map.destroy_event_any(@ev_id)
  1264. #end
  1265. #----------------------------------------------------------------------------
  1266. # * Print what memory looks like
  1267. #----------------------------------------------------------------------------
  1268. def debug
  1269. print "\n"
  1270. print "debug data:"
  1271. print " plant_id = #{@plant_id} event_id = #{@ev_id}\n"
  1272. print " @p_info = #{@p_info}\n"
  1273. print " garden timer = #{$game_system.garden_timer}\n"
  1274. print " current stage = #{@p_info[:cur_stage]}\n"
  1275. print " pos = #{pos}\n"
  1276. print " self switches A = #{$game_self_switches[[$game_map.map_id, @ev_id, "A"]]}\n"
  1277. print " self switches B = #{$game_self_switches[[$game_map.map_id, @ev_id, "B"]]}\n"
  1278. print " self switches C = #{$game_self_switches[[$game_map.map_id, @ev_id, "C"]]}\n"
  1279. print " self switches D = #{$game_self_switches[[$game_map.map_id, @ev_id, "D"]]}\n"
  1280. end
  1281.  
  1282. end # Garden_Object
  1283.  
  1284. #==============================================================================
  1285. # ** Game_System
  1286. #==============================================================================
  1287. class Game_System
  1288.  
  1289. attr_accessor :garden_timer
  1290. attr_accessor :garden_plants # map_id => event_id => :sym => value
  1291.  
  1292. Epsilon_GS_Era = 0.00001 # Fertillizer removed if concentration is < this value
  1293. #----------------------------------------------------------------------------
  1294. # * Alias - Initialize
  1295. #----------------------------------------------------------------------------
  1296. alias init_g_plt_hash_get_data_on_reload initialize
  1297. def initialize
  1298. @garden_timer, @plant_ids = 0, 0
  1299. @garden_plants, @garden_fertillizer = {},{} # maps ids to base frames
  1300.  
  1301. init_g_plt_hash_get_data_on_reload
  1302. end
  1303. #----------------------------------------------------------------------------
  1304. # * Alias - on_after_load
  1305. #----------------------------------------------------------------------------
  1306. alias on_after_ld_add_evs_garden_to_m on_after_load
  1307. def on_after_load
  1308. on_after_ld_add_evs_garden_to_m
  1309. $game_map.place_all_plants
  1310. end
  1311. #----------------------------------------------------------------------------
  1312. # * Update Garden Timer
  1313. #----------------------------------------------------------------------------
  1314. def update_garden(erode = true)
  1315. @garden_timer += 1 unless @garden_timer.nil?
  1316. update_erosion if erode
  1317. end
  1318. #----------------------------------------------------------------------------
  1319. # * Erode the fertillizer away from all of the maps in the game.
  1320. #----------------------------------------------------------------------------
  1321. def update_erosion
  1322. @garden_fertillizer.keys.each{ |map_id| # ids for each map with fertillizer
  1323.  
  1324. minfo = $data_mapinfos[map_id]
  1325. map_erode_rate = minfo.erosion_rate
  1326. map_erode_val = minfo.erosion_value
  1327. valid = !map_erode_rate.nil? && !map_erode_val.nil?
  1328.  
  1329. next unless valid && @garden_timer % map_erode_rate == 0
  1330.  
  1331. fert_xys = @garden_fertillizer[map_id]
  1332. fert_xys.keys.each{ |xy| # fertillizer values for each xy
  1333. next unless !fert_xys[xy].nil?
  1334. fert_xys[xy] = [fert_xys[xy]-map_erode_val,0.0].max
  1335.  
  1336. if fert_xys[xy] < Epsilon_GS_Era
  1337. fert_xys.delete(xy)
  1338. remove_saved_highlight(xy[0],xy[1],map_id)
  1339. $game_map.setup_map_highlights_era(map_id)
  1340. update_erosion_helper_del_hl(map_id)
  1341. end
  1342.  
  1343. }
  1344. }
  1345. end
  1346. #----------------------------------------------------------------------------
  1347. # * Update the highlights if current map is $game_map
  1348. #----------------------------------------------------------------------------
  1349. def update_erosion_helper_del_hl(map_id)
  1350. return unless $game_map.map_id == map_id
  1351. return unless (scene = SceneManager.scene).is_a?(Scene_Map)
  1352. spm = scene.instance_eval('@spriteset')
  1353. spm.refresh_highlights unless spm.nil?
  1354. end
  1355. #----------------------------------------------------------------------------
  1356. # * Plant Info
  1357. # @garden_plants[map_id][:fertillized] is a hash mapping x,y values to
  1358. # booleans. True if that location is fertillized.
  1359. #----------------------------------------------------------------------------
  1360. def plant_info(plant_id = nil)
  1361. map_id = $game_map.map_id
  1362. !plant_id.nil? ? (return @garden_plants[map_id][plant_id]) : (return @garden_plants[map_id])
  1363. end
  1364. #----------------------------------------------------------------------------
  1365. # * Removes a plants information from the game_system
  1366. #----------------------------------------------------------------------------
  1367. def destroy_plant(plant_id, map_id = nil)
  1368. map = $game_map
  1369. map_id = map_id.nil? ? map.map_id : map_id
  1370.  
  1371. gpm = @garden_plants[map_id]
  1372. ev_id = gpm[plant_id][:event_id]
  1373.  
  1374. map.destroy_event_any(ev_id) if map_id == map.map_id
  1375. gpm.delete(plant_id)
  1376. print "plant data for #{plant_id} on map #{map_id} was removed\n"
  1377. end
  1378. #----------------------------------------------------------------------------
  1379. # * Get the Fertillizer Data For the Current Map
  1380. #----------------------------------------------------------------------------
  1381. def fertillizer_data
  1382. map_id = $game_map.map_id
  1383. return @garden_fertillizer[map_id]||={}
  1384. end
  1385. #----------------------------------------------------------------------------
  1386. # * Next Plant Id
  1387. #----------------------------------------------------------------------------
  1388. def next_plant_id
  1389. @plant_ids + 1
  1390. end
  1391. #----------------------------------------------------------------------------
  1392. # * Add Plant
  1393. #----------------------------------------------------------------------------
  1394. def add_plant(map_id=nil)
  1395. map_id = map_id.nil? && $game_map.nil? ? map_id : $game_map.map_id
  1396. return if map_id.nil?
  1397. @garden_plants[map_id][@plant_ids+=1] = {}
  1398. return @plant_ids
  1399. end
  1400. #----------------------------------------------------------------------------
  1401. # * Plant Added
  1402. #----------------------------------------------------------------------------
  1403. def plant_added?(id)
  1404. @plant_ids + 1 > id
  1405. end
  1406. #----------------------------------------------------------------------------
  1407. # * Water the Plant with id = param: plant_id
  1408. #----------------------------------------------------------------------------
  1409. def water_plant_era(plant_id, times=1)
  1410. p_info = plant_info(plant_id)
  1411. stage = p_info[:cur_stage]
  1412. p_info[:watered_vals] ||= {}
  1413. p_info[:watered_vals][stage] ||= 0
  1414. p_info[:watered_vals][stage] += times
  1415. end
  1416. #----------------------------------------------------------------------------
  1417. # * Modify the amount of times a plant has been watered
  1418. # param: first, the stage to start modifying at
  1419. # param: last, the last stage in the range to modify
  1420. #----------------------------------------------------------------------------
  1421. def mod_times_watered(plant_id, first, last, reset = true, mod=0)
  1422. p_info = plant_info(plant_id)
  1423. w_vals = p_info[:watered_vals] ||= {}
  1424. (first..last).each{ |stage|
  1425. w_vals[stage] = reset ? 0 : (w_vals[stage] ? [w_vals[stage]+mod,0].min : 0)
  1426. }
  1427. end # mod_times_watered
  1428. end # Game_System
  1429.  
  1430. #==============================================================================
  1431. # ** Game_Map
  1432. # Load plant and fertillizer data for the current map when setting up.
  1433. # Allow plants to be queue
  1434. #==============================================================================
  1435. class Game_Map
  1436. #----------------------------------------------------------------------------
  1437. # * Alias - setup
  1438. #----------------------------------------------------------------------------
  1439. alias set_up_garden_ch_for_old_hash setup
  1440. def setup(map_id)
  1441. $game_system.garden_plants[map_id] ||= {}
  1442.  
  1443. @era_seeds_to_plant = []
  1444. # redraw spriteset for scene map
  1445.  
  1446. set_up_garden_ch_for_old_hash(map_id)
  1447.  
  1448. setup_erosion_vals
  1449. end
  1450. #----------------------------------------------------------------------------
  1451. # * Alias - update
  1452. #----------------------------------------------------------------------------
  1453. alias upd_pl_seeds_af_update_hash_new_item update
  1454. def update(*args)
  1455. upd_pl_seeds_af_update_hash_new_item(*args)
  1456. plant_seeds_after_update
  1457.  
  1458. place_all_plants if @want_to_place_plants
  1459. end
  1460. #----------------------------------------------------------------------------
  1461. # * Alias - setup_events
  1462. #----------------------------------------------------------------------------
  1463. alias setup_evs_add_plant_evs_for_map setup_events
  1464. def setup_events
  1465. setup_evs_add_plant_evs_for_map
  1466.  
  1467. # make plant events from data inside Game_System
  1468. place_all_plants
  1469. end
  1470.  
  1471. #----------------------------------------------------------------------------
  1472. # * Place all plants back on the map when reloading
  1473. #----------------------------------------------------------------------------
  1474. def place_all_plants
  1475.  
  1476. return !(@want_to_place_plants = true) if !SceneManager.scene.is_a?(Scene_Map)
  1477. plant_data = $game_system.plant_info
  1478. plant_data.keys.each{ |plant_id|
  1479. p_info = plant_data[plant_id]
  1480. x, y = p_info[:x], p_info[:y]
  1481.  
  1482. ch = GardenRa.stage_to_ss(cur_stage = p_info[:cur_stage])
  1483. ss = !ch ? {} : {ch.to_sym => true}
  1484.  
  1485. GardenRa.plant_seed(p_info[:item], plant_id, false, {:x=>x, :y=>y, :SS=>ss}, p_info[:pos],
  1486. cur_stage)
  1487. }
  1488. refresh
  1489. @want_to_place_plants = false
  1490. end
  1491. #----------------------------------------------------------------------------
  1492. # * Plant the queued seeds
  1493. #----------------------------------------------------------------------------
  1494. def plant_seeds_after_update
  1495. @era_seeds_to_plant.each{ |args| GardenRa.plant_seed(*args) }
  1496. @era_seeds_to_plant = []
  1497. end
  1498. #----------------------------------------------------------------------------
  1499. # * Add Seed to Plant - Queue up planting a seed
  1500. #----------------------------------------------------------------------------
  1501. def add_seed_to_plant(*args)
  1502. @era_seeds_to_plant.push(args) # Order is not checked but shouldn't be modified
  1503. end
  1504. #----------------------------------------------------------------------------
  1505. # * Setup Erosion Values
  1506. #----------------------------------------------------------------------------
  1507. def setup_erosion_vals
  1508. dmap = $data_mapinfos[@map_id]
  1509. if dmap.erosion_rate.nil? || dmap.erosion_value.nil?
  1510. @map.note.split(/[\r\n+]/).each{ |line|
  1511. case line
  1512. when GardenRa::RE::FertillizerErodeAmt
  1513. dmap.erosion_value = $1.to_f
  1514. when GardenRa::RE::FertillizerErodeRate
  1515. dmap.erosion_rate = $1.to_i
  1516. end
  1517. }
  1518. end
  1519. end
  1520. #----------------------------------------------------------------------------
  1521. # * Seed Location Ok?
  1522. #----------------------------------------------------------------------------
  1523. def seed_location_ok?(x,y)
  1524. if !GardenRa::PlantOntop # Don't plant ontop of non erased events
  1525. events_xy(x,y).each{ |ev| return false if ev && !ev.instance_eval('@erase')}
  1526. end
  1527. return true
  1528. end
  1529. #----------------------------------------------------------------------------
  1530. # * Add Fertillizer
  1531. #----------------------------------------------------------------------------
  1532. def add_fertillizer(rate, range)
  1533. map_info = $game_system.fertillizer_data
  1534.  
  1535. range.each{ |xy|
  1536. x,y = xy[0], xy[1]
  1537. t = map_info[xy]
  1538. map_info[xy] = t ? t + (t * rate) : rate
  1539.  
  1540. print "new fertillizer added, value = #{map_info[xy]}\n"
  1541.  
  1542. events_xy(x,y).each{ |ev| ev.apply_fertillizer} #update plants w/ fertillizer
  1543.  
  1544. if GardenRa::UseSheetData
  1545. sh = Sheet_Data.new(GardenRa::FertName,GardenRa::FertIndex,GardenRa::FertRow)
  1546. end
  1547.  
  1548. spm = SceneManager.scene.instance_eval("@spriteset")
  1549. spm.add_highlight(:x => x, :y => y, :sh => sh, :retain => true, :opacity => 255) if GardenRa::ShowFertillizer
  1550. }
  1551. end # add_fertillizer
  1552.  
  1553. end # Game_Map
  1554.  
  1555. #==============================================================================
  1556. # ** Game_Event
  1557. # Associates an event with a plant.
  1558. #==============================================================================
  1559.  
  1560. class Spriteset_Map
  1561. attr_accessor :map_id
  1562. end
  1563.  
  1564. class Game_Event
  1565.  
  1566. attr_accessor :plant
  1567. attr_accessor :opacity
  1568. #----------------------------------------------------------------------------
  1569. # * Alias - Initialize
  1570. #----------------------------------------------------------------------------
  1571. alias initialize_gard_ev__grow initialize
  1572. def initialize(*args)
  1573. initialize_gard_ev__grow(*args)
  1574. #create_garden_obj
  1575. end
  1576.  
  1577. # show plant under player? (for use when planting)
  1578. def low; @plant ? @plant.low : false; end
  1579. #----------------------------------------------------------------------------
  1580. # * Alias - Screen Z
  1581. #----------------------------------------------------------------------------
  1582. alias garden_plant_screen_z_ed screen_z
  1583. def screen_z
  1584. return garden_plant_screen_z_ed if @plant.nil?
  1585. ls = @plant.stage == @plant.last_stage
  1586. if !ls && (p=$game_player).real_x.to_i == @x && p.real_y.to_i == @y
  1587. return garden_plant_screen_z_ed - 1 #show under player when planting
  1588. else
  1589. return garden_plant_screen_z_ed
  1590. end
  1591. end
  1592. #----------------------------------------------------------------------------
  1593. # * Alias - Update
  1594. #----------------------------------------------------------------------------
  1595. alias update_ch_garden_obj_ud update
  1596. def update
  1597. update_ch_garden_obj_ud
  1598. @plant.update unless @plant.nil?
  1599. end
  1600. #----------------------------------------------------------------------------
  1601. # * Start Plant
  1602. #----------------------------------------------------------------------------
  1603. def start_plant(plant_id, planting = false)
  1604. @plant = Garden_Object.new(plant_id, @id, planting)
  1605. end
  1606. #----------------------------------------------------------------------------
  1607. # * Plant Dead?
  1608. #----------------------------------------------------------------------------
  1609. def garden_plant_dead?
  1610. return [email protected]? && @plant.dead?
  1611. end
  1612.  
  1613. #--------------------------------------------------------------------------
  1614. # * Alias move_straight - update the location of the plant in game_system
  1615. #--------------------------------------------------------------------------
  1616. alias mve_strght_mod_edit_upd_str_gard_upd move_straight
  1617. def move_straight(dir, turn_ok = true)
  1618. mve_strght_mod_edit_upd_str_gard_upd(dir)
  1619. update_garden_plant_xy if @plant
  1620. end
  1621.  
  1622. #--------------------------------------------------------------------------
  1623. # * Alias move_diagonal- update the location of the plant in game_system
  1624. #--------------------------------------------------------------------------
  1625. alias mv_diag_gard_upd_pl_posit_upd move_diagonal
  1626. def move_diagonal(horz, vert)
  1627. mv_diag_gard_upd_pl_posit_upd(horz, vert)
  1628. update_garden_plant_xy if @plant.plant_id
  1629. end
  1630. #----------------------------------------------------------------------------
  1631. # * Update plant position if the event moves
  1632. #----------------------------------------------------------------------------
  1633. def update_garden_plant_xy
  1634. p_info = $game_system.plant_info(@plant.plant_id)
  1635. p_info[:x], p_info[:y] = @x, @y
  1636. end
  1637. #----------------------------------------------------------------------------
  1638. # * Apply Fertillizer
  1639. #----------------------------------------------------------------------------
  1640. def apply_fertillizer
  1641. return unless @plant
  1642. return if @plant.dead? || @plant.stage == @plant.last_stage # on last stage or dead
  1643. @plant.apply_fertillizer # applier fertillizer from current location to growth rate
  1644. end # apply_fertillizer
  1645.  
  1646. end # Game_Event
  1647.  
  1648. #==============================================================================
  1649. # ** Scene_Base
  1650. # * Update the garden timer when inside any scene.
  1651. #==============================================================================
  1652. class Scene_Base
  1653. #----------------------------------------------------------------------------
  1654. # * Alias - update
  1655. #----------------------------------------------------------------------------
  1656. alias upd_timer_for_farm_evs update
  1657. def update
  1658. upd_timer_for_farm_evs
  1659. update_garden_timer
  1660. end
  1661. #----------------------------------------------------------------------------
  1662. # * Update Garden Timer
  1663. #----------------------------------------------------------------------------
  1664. def update_garden_timer
  1665. $game_system.update_garden
  1666. end
  1667.  
  1668. end # Scene_Base
  1669.  
  1670. #==============================================================================
  1671. # ** Scene_Map
  1672. # Add gui for selecting a watering container.
  1673. #==============================================================================
  1674. class Scene_Map < Scene_Base
  1675. #----------------------------------------------------------------------------
  1676. # * Start
  1677. #----------------------------------------------------------------------------
  1678. alias st_add_cd_draw_sp_highl_era start
  1679. def start
  1680. st_add_cd_draw_sp_highl_era
  1681. end
  1682. #----------------------------------------------------------------------------
  1683. # * Create Waterer Options Window
  1684. #----------------------------------------------------------------------------
  1685. def create_window_waterer_opts
  1686. @waterer_opts_window = Window_ShowOptsEra.new(300,200,82,79)
  1687. @waterer_opts_window.viewport = @viewport
  1688. @waterer_opts_window.set_handler(:ok, method(:process_choice_era))
  1689. @waterer_opts_window.set_handler(:cancel, method(:on_ch_cancel_era))
  1690. @waterer_opts_window.hide
  1691. end
  1692. #----------------------------------------------------------------------------
  1693. # * Create Water Question Window
  1694. #----------------------------------------------------------------------------
  1695. def create_window_water_question
  1696. x,y = Graphics.width * 0.2, Graphics.height * 0.7
  1697. w,h = 300, 55
  1698. @waterer_question_window = Window_WatererText.new(x,y,w,h)
  1699. @waterer_question_window.viewport = @viewport
  1700. @waterer_question_window.hide
  1701. end
  1702. #----------------------------------------------------------------------------
  1703. # * Create Water Container Selection Window
  1704. #----------------------------------------------------------------------------
  1705. def create_waterer_window
  1706. @waterer_window = Window_SelectWaterer.new(0,100,230,210)
  1707. @waterer_window.viewport = @viewport
  1708. @waterer_window.set_handler(:ok, method(:on_waterer_ok))
  1709. @waterer_window.set_handler(:cancel, method(:on_waterer_cancel))
  1710. @waterer_window.hide
  1711. end
  1712. #----------------------------------------------------------------------------
  1713. # * Create Water Container Data Window
  1714. #----------------------------------------------------------------------------
  1715. def create_waterer_data_window
  1716. x,y = Graphics.width * 0.2, Graphics.height * 0.7
  1717. w,h = 380, 55
  1718. @waterer_data_window = Window_WatererData.new(0,Graphics.height-45,w,47)
  1719. @waterer_data_window.give_item_window(@waterer_window)
  1720. @waterer_data_window.hide
  1721. @waterer_data_window.deactivate
  1722. end
  1723. #----------------------------------------------------------------------------
  1724. # * Create Water Number Window
  1725. #----------------------------------------------------------------------------
  1726. def create_waterer_amount_window
  1727. @waterer_number_window = Window_WaterAmt.new(300,200,100,65)
  1728. @waterer_number_window.viewport = @viewport
  1729. @waterer_number_window.hide
  1730. @waterer_number_window.set_handler(:ok, method(:waterer_number_ok))
  1731. @waterer_number_window.set_handler(:cancel, method(:waterer_number_cancel))
  1732. end
  1733. #----------------------------------------------------------------------------
  1734. # * Create Water Number Text Window
  1735. #----------------------------------------------------------------------------
  1736. def create_waterer_amount_help_window
  1737. x,y = Graphics.width * 0.2, Graphics.height * 0.7
  1738. w,h = 300, 55
  1739. @waterer_amount_text_window = Window_WatererText.new(x,y,w,h)
  1740. @waterer_amount_text_window.viewport = @viewport
  1741. @waterer_amount_text_window.hide
  1742. end
  1743. #----------------------------------------------------------------------------
  1744. # * Create Select Name Text Window
  1745. #----------------------------------------------------------------------------
  1746. def create_select_name_waterer_window
  1747. w = @waterer_window.width
  1748. @waterer_selection_name = Window_WatererText.new(0,50,w,47)
  1749. @waterer_selection_name.viewport = @viewport
  1750. @waterer_selection_name.hide
  1751. end
  1752. #----------------------------------------------------------------------------
  1753. # * Reorient Watering Windows
  1754. #----------------------------------------------------------------------------
  1755. def waterer_reorient_windows_era
  1756. @waterer_window.y = @waterer_selection_name.y + @waterer_selection_name.height
  1757. @waterer_data_window.width = @waterer_window.width
  1758. @waterer_data_window.height = @waterer_selection_name.height
  1759.  
  1760. @waterer_question_window.x = Graphics.width - @waterer_question_window.width
  1761. @waterer_question_window.y = @waterer_opts_window.y + @waterer_opts_window.height
  1762. @waterer_opts_window.x = Graphics.width - @waterer_opts_window.width
  1763.  
  1764. @waterer_number_window.x = Graphics.width - @waterer_number_window.width
  1765. @waterer_amount_text_window.x = @waterer_question_window.x
  1766. @waterer_amount_text_window.y = @waterer_number_window.y + @waterer_number_window.height
  1767. end
  1768. #----------------------------------------------------------------------------
  1769. # * Process Choice
  1770. #----------------------------------------------------------------------------
  1771. def process_choice_era
  1772. if @waterer_opts_window.index == 0
  1773. want_to_water_era
  1774. else
  1775. on_ch_cancel_era
  1776. end
  1777. end
  1778. #----------------------------------------------------------------------------
  1779. # * On Number Selection 'OK'
  1780. #----------------------------------------------------------------------------
  1781. def waterer_number_ok
  1782. @waterer_item_era.mod_waterer_available_uses(-(n=@waterer_number_window.number))
  1783. $game_system.water_plant_era(@target_plant_id_era,n)
  1784. hide_waterers_number
  1785. $game_player.freeze_era(false)
  1786. end
  1787. #----------------------------------------------------------------------------
  1788. # * Number Selection 'CANCEL'
  1789. #----------------------------------------------------------------------------
  1790. def waterer_number_cancel
  1791. hide_waterers_number
  1792. $game_player.freeze_era(false)
  1793. end
  1794. #----------------------------------------------------------------------------
  1795. # * Water Container Selection 'CANCEL'
  1796. #----------------------------------------------------------------------------
  1797. def waterer_number_cancel
  1798. hide_waterers_number
  1799. $game_player.freeze_era(false)
  1800. end
  1801. #----------------------------------------------------------------------------
  1802. # * Hide Water Number Windows
  1803. #----------------------------------------------------------------------------
  1804. def hide_waterers_number
  1805. @waterer_number_window.hide
  1806. @waterer_amount_text_window.hide
  1807. end
  1808. #----------------------------------------------------------------------------
  1809. # * Water Container Selection 'OK'
  1810. #----------------------------------------------------------------------------
  1811. def on_waterer_ok
  1812. @waterer_item_era = @waterer_window.item
  1813. @waterer_number_window.give_waterer(@waterer_item_era)
  1814.  
  1815. uses = @waterer_item_era.water_available_uses
  1816. @waterer_window.deactivate
  1817. hide_secondary_waterer_windows
  1818.  
  1819. @waterer_number_window.show
  1820. @waterer_number_window.activate
  1821.  
  1822.  
  1823. @waterer_amount_text_window.give_text("How many times do you want to water it?")
  1824. @waterer_amount_text_window.show
  1825. end
  1826. #----------------------------------------------------------------------------
  1827. # * Water Selection 'CANCEL'
  1828. #----------------------------------------------------------------------------
  1829. def on_waterer_cancel
  1830. hide_secondary_waterer_windows
  1831. $game_player.freeze_era(false)
  1832. end
  1833. #----------------------------------------------------------------------------
  1834. # * Yes-No Selection 'CANCEL'
  1835. #----------------------------------------------------------------------------
  1836. def on_ch_cancel_era
  1837. @waterer_opts_window.hide
  1838. @waterer_question_window.hide
  1839. @waterer_opts_window.deactivate
  1840. $game_player.freeze_era(false)
  1841. end
  1842. #----------------------------------------------------------------------------
  1843. # * Hide Specific Watering Windows
  1844. #----------------------------------------------------------------------------
  1845. def hide_secondary_waterer_windows
  1846. @waterer_selection_name.hide
  1847. @waterer_data_window.hide
  1848. @waterer_window.hide
  1849. end
  1850. #----------------------------------------------------------------------------
  1851. # * Water the Plant with param: plant_id
  1852. #----------------------------------------------------------------------------
  1853. def water_plant(plant_id)
  1854. $game_player.freeze_era(true)
  1855.  
  1856. @target_plant_id_era = plant_id
  1857.  
  1858. create_waterer_window
  1859. create_waterer_data_window
  1860. create_window_water_question
  1861. create_window_waterer_opts
  1862. create_waterer_amount_window
  1863. create_waterer_amount_help_window
  1864. create_select_name_waterer_window
  1865. waterer_reorient_windows_era
  1866.  
  1867. @waterer_question_window.show
  1868. @waterer_opts_window.show
  1869. @waterer_opts_window.select(0)
  1870. @waterer_opts_window.activate
  1871. end
  1872. #----------------------------------------------------------------------------
  1873. # * Decided to water the plant
  1874. #----------------------------------------------------------------------------
  1875. def want_to_water_era
  1876. @waterer_question_window.hide
  1877. @waterer_opts_window.hide
  1878. @waterer_opts_window.deactivate
  1879.  
  1880. @waterer_selection_name.show
  1881. @waterer_selection_name.give_text("Choose a Watering Container")
  1882.  
  1883. @waterer_window.select(0)
  1884. @waterer_window.show
  1885. @waterer_window.activate#@w = Window_MenuCommand.new#Window_SelectWaterer.new(0,0,300,200)
  1886. @waterer_window.refresh
  1887. @waterer_data_window.show
  1888. end
  1889. #----------------------------------------------------------------------------
  1890. # * Dispose Windows
  1891. #----------------------------------------------------------------------------
  1892. def disp_wins_era(clean = true)
  1893. $game_player.freeze_era(false)
  1894. @waterer_window.dispose unless @waterer_window.nil?
  1895. @waterer_opts_window.dispose unless @waterer_opts_window.nil?
  1896. @waterer_data_window.dispose unless @waterer_data_window.nil?
  1897. @waterer_question_window.dispose unless @waterer_question_window.nil?
  1898. @waterer_number_window.dispose unless @waterer_number_window.nil?
  1899. @waterer_amount_text_window.dispose unless @waterer_amount_text_window.nil?
  1900. @waterer_selection_name.dispose unless @waterer_selection_name.nil?
  1901. clean_wins_era if clean
  1902. end
  1903. #----------------------------------------------------------------------------
  1904. # * Set windows to nil, called after disposing just to be safe
  1905. #----------------------------------------------------------------------------
  1906. def clean_wins_era
  1907. @waterer_window = nil
  1908. @waterer_opts_window = nil
  1909. @waterer_data_window = nil
  1910. @waterer_question_window = nil
  1911. @waterer_number_window = nil
  1912. @waterer_amount_text_window = nil
  1913. @waterer_selection_name = nil
  1914. end
  1915. #----------------------------------------------------------------------------
  1916. # * Update
  1917. #----------------------------------------------------------------------------
  1918. alias update_need_to_pl_seed_era update
  1919. def update
  1920. update_need_to_pl_seed_era
  1921. disp_wins_era if scene_changing?
  1922. end # update
  1923.  
  1924. end # Scene_Map
  1925.  
  1926. #==============================================================================
  1927. # ** Sprite_Character
  1928. #==============================================================================
  1929. class Sprite_Character < Sprite_Base
  1930. #----------------------------------------------------------------------------
  1931. # * Alias - Update
  1932. #----------------------------------------------------------------------------
  1933. alias update_pr_tone_garden_debug update
  1934. def update
  1935. update_pr_tone_garden_debug
  1936. color_dead_garden_plant if garden_plant_dead_era?
  1937. end
  1938. #----------------------------------------------------------------------------
  1939. # * Check if the Associated Plant Event is Dead
  1940. #----------------------------------------------------------------------------
  1941. def garden_plant_dead_era?
  1942. return unless (c=@character).is_a?(Game_Event)
  1943. c.garden_plant_dead?
  1944. end
  1945. #----------------------------------------------------------------------------
  1946. # * Get the Color of a Dead Plant
  1947. #----------------------------------------------------------------------------
  1948. def color_dead_garden_plant
  1949. tone.gray = 205
  1950. tone.blue = -160
  1951. tone.red = -160
  1952. tone.green = -130
  1953. end # color_dead_garden_plant
  1954. end # Sprite_Character
  1955.  
  1956. #==============================================================================
  1957. # ** Game_Player
  1958. #==============================================================================
  1959. class Game_Player < Game_Character
  1960. #----------------------------------------------------------------------------
  1961. # * Initialize
  1962. #----------------------------------------------------------------------------
  1963. alias init_add_t_del_var_for_more_nat_w initialize
  1964. def initialize
  1965. init_add_t_del_var_for_more_nat_w
  1966. @turn_delay_era = 0
  1967. end
  1968. #----------------------------------------------------------------------------
  1969. # * Alias, Check Event Triger There
  1970. #----------------------------------------------------------------------------
  1971. alias chk_ev_trigs_chk_to_water_first check_event_trigger_there
  1972. def check_event_trigger_there(triggers)
  1973. try_to_water_plants
  1974. chk_ev_trigs_chk_to_water_first(triggers)
  1975. end
  1976. #----------------------------------------------------------------------------
  1977. # * Alias - move_straight
  1978. #----------------------------------------------------------------------------
  1979. alias mov_straight_don_move_when_frozen move_straight
  1980. def move_straight(*args)
  1981. return if @frozen_era
  1982. mov_straight_don_move_when_frozen(*args)
  1983. end
  1984. #----------------------------------------------------------------------------
  1985. # * Try to Water Plants - ask player if they want to water a plant when
  1986. # checking for event triggers if the event is a plant.
  1987. #----------------------------------------------------------------------------
  1988. def try_to_water_plants
  1989. return unless party_has_waterer_era?
  1990. map = $game_map
  1991. rx = map.round_x_with_direction(@x,@direction)
  1992. ry = map.round_y_with_direction(@y,@direction)
  1993.  
  1994. $game_map.events_xy(rx,ry).each{ |ev|
  1995. next unless ev
  1996. plant = ev.plant
  1997. if plant && !ev.garden_plant_dead? && (plant.stage != plant.last_stage)
  1998. SceneManager.scene.water_plant(ev.plant.plant_id)
  1999. end
  2000. }
  2001. end
  2002. #----------------------------------------------------------------------------
  2003. # * Check if the party has a watering container
  2004. #----------------------------------------------------------------------------
  2005. def party_has_waterer_era?(full = false)
  2006. items = $game_party.items
  2007. items.each{|item|
  2008. next unless is_waterer = item.is_waterer?
  2009. curr, max = item.water_available_uses, item.water_amount_uses
  2010.  
  2011. valid = full ? curr < max : curr > 0
  2012. return true if is_waterer && valid
  2013. }
  2014. return false
  2015. end
  2016. #----------------------------------------------------------------------------
  2017. # * Freeze the player when displying water container selection windows
  2018. #----------------------------------------------------------------------------
  2019. def freeze_era(stop = true)
  2020. @frozen_era = stop
  2021. end # freeze_era
  2022.  
  2023. end # Game_Player
  2024.  
  2025. #==============================================================================
  2026. # ** Game_BattlerBase
  2027. # Add code to handle internal common events. The arguments are
  2028. # being converted to strings when they're passed
  2029. #==============================================================================
  2030. class Game_BattlerBase
  2031. #----------------------------------------------------------------------------
  2032. # * Alias usable? - add checks looking for seeds, fertillizer, or clearer
  2033. #----------------------------------------------------------------------------
  2034. alias usa_elbasu_ube_garden_seed usable?
  2035. def usable?(item)
  2036. return can_clear_crop(item) if !item.nil? && item.clears_crops?
  2037. return garden_area_valid?(item) if !item.nil? && item.is_garden_seed?
  2038. return garden_area_valid?(item) if !item.nil? && item.is_fertillizer?
  2039. usa_elbasu_ube_garden_seed(item)
  2040. end
  2041. #----------------------------------------------------------------------------
  2042. # * Garden Area Valid - Check if a seed can be planted or if fertillizer can
  2043. # be placed based on the players current position.
  2044. #----------------------------------------------------------------------------
  2045. def garden_area_valid?(item)
  2046. xy = []
  2047.  
  2048. map, player = $game_map, $game_player
  2049. px, py, d = player.x, player.y, player.direction
  2050. sx,sy = map.round_x_with_direction(px, d), map.round_y_with_direction(py, d)
  2051.  
  2052. is_fertillizer = item.is_fertillizer?
  2053. f_ok = map.seed_location_ok?(sx,sy) || is_fertillizer
  2054. c_ok = map.seed_location_ok?(px,py) || is_fertillizer
  2055.  
  2056. front_ok = item.garden_terrains(map.terrain_tag(sx, sy)) && f_ok
  2057. cent_ok = item.garden_terrains(map.terrain_tag(px, py)) && c_ok
  2058. anywhere_ok = item.garden_ok_anywhere?
  2059.  
  2060. id = item.id
  2061. $game_temp.temp_seed_data[id] = {}
  2062.  
  2063. hash = $game_temp.temp_seed_data[id]
  2064. hash[:sx], hash[:sy] = sx, sy if front_ok
  2065. hash[:px], hash[:py] = px, py if cent_ok || anywhere_ok
  2066.  
  2067. front_ok || cent_ok || anywhere_ok
  2068. end # garden_area_valid?
  2069.  
  2070. #----------------------------------------------------------------------------
  2071. # * Check if there are any crop close enough to be cleared.
  2072. #----------------------------------------------------------------------------
  2073. def can_clear_crop(item)
  2074. map, player, gtemp = $game_map, $game_player, $game_temp
  2075. dir = player.direction
  2076.  
  2077.  
  2078. front_x = map.round_x_with_direction(player.x, dir)
  2079. front_y = map.round_y_with_direction(player.y, dir)
  2080. front_evs = map.events_xy(front_x, front_y) # getting events, may want to get
  2081. # plant ids and delete the plants current
  2082. # event if it turns out the plant can grow
  2083. # a stage while trying to harvest.
  2084.  
  2085. gtemp.temp_seed_clear = [] # erase previously stored events
  2086.  
  2087. if (amt = item.clears_crops) <= 0
  2088. pushed = false
  2089. front_evs.each{ |ev|
  2090. if !ev.plant.nil?
  2091. gtemp.temp_seed_clear.push(ev)
  2092. pushed = true
  2093. end
  2094. }
  2095. # only check the front position unless a distance is specified
  2096. else
  2097. # calculate additional locations
  2098. pushed = store_adjsdiag_temp_clearer(amt) || pushed
  2099. end
  2100.  
  2101. print "amt to clear was #{amt}\n"
  2102.  
  2103. return pushed
  2104. end
  2105. #----------------------------------------------------------------------------
  2106. # * Store plants at a distance of dist from game_player for removal.
  2107. #----------------------------------------------------------------------------
  2108. def store_adjsdiag_temp_clearer(dist)
  2109. map, player, gtemp = $game_map, $game_player, $game_temp
  2110. x, y = player.x, player.y
  2111. need_check = []
  2112. (0...dist).each{ |d|
  2113. need_check = p_at_dist_plants_clear(need_check, d, x, y)
  2114. }
  2115. pushed = false
  2116.  
  2117. print "need_check = #{need_check.inspect}\n"
  2118.  
  2119. # get all events within range that are plants
  2120. need_check.each do |xy|
  2121. evs = map.events_xy(xy[0], xy[1])
  2122. evs.each{ |ev|
  2123. next unless ev
  2124. if !ev.plant.nil?
  2125. gtemp.temp_seed_clear.push(ev)
  2126. print "pushed additional value into gtemp arr at x,y = #{xy[0]},#{xy[1]}\n"
  2127. pushed = true
  2128. end
  2129. }
  2130. end # need_check.each
  2131. return pushed
  2132. end # store_adjsdiag_temp_clearer
  2133. #----------------------------------------------------------------------------
  2134. # * Points in a circle at distsance: dist from x,y
  2135. #----------------------------------------------------------------------------
  2136. def p_at_dist_plants_clear(points, dist, x, y, opts = {})
  2137. max = dist+1
  2138. (0..dist).each{ |i|
  2139. points.push([ x+i, y-(max-i)])
  2140. points.push([x-i, y+(max-i)])
  2141. points.push([x+(max-i), y+i])
  2142. points.push([x-(max-i), y-i])
  2143. }
  2144. points
  2145. end
  2146. end # Game_BattlerBase
  2147.  
  2148. #==============================================================================
  2149. # ** Game_Battler - Add support for when using items that are fertillizers or
  2150. # seeds.
  2151. #==============================================================================
  2152. class Game_Battler < Game_BattlerBase
  2153. #----------------------------------------------------------------------------
  2154. # * Alias use_item - set up appropriate internal common events when
  2155. # fertillizer or seeds are used.
  2156. #----------------------------------------------------------------------------
  2157. alias usitm_use_ce_seed_mod_meti use_item
  2158. def use_item(item)
  2159. # Seed
  2160. if item.is_garden_seed?
  2161. print "item was a garden_seed\n"
  2162. strsym = "GardenRa::CE_Plant_Seeds"
  2163. $game_temp.reserve_internal_ce(strsym.to_sym, item.id, item.is_a?(RPG::Item))
  2164. end
  2165.  
  2166. # Fertillizer
  2167. if item.is_fertillizer?
  2168. strsym = "GardenRa::CE_Place_Fertillizer"
  2169. $game_temp.reserve_internal_ce(strsym.to_sym, item.id, item.is_a?(RPG::Item))
  2170. end
  2171.  
  2172. # Clearer
  2173. if item.clears_crops?
  2174. strsym = "GardenRa::Clear_Crop"
  2175. $game_temp.reserve_internal_ce(strsym.to_sym)
  2176. end
  2177. usitm_use_ce_seed_mod_meti(item)
  2178. end # use_item
  2179. end # Game_Battler
  2180.  
  2181. #==============================================================================
  2182. # ** Game_Temp
  2183. # Functionality is added to support internal common events.
  2184. #==============================================================================
  2185. class Game_Temp
  2186. attr_accessor :temp_seed_data
  2187. attr_accessor :temp_seed_clear
  2188. #----------------------------------------------------------------------------
  2189. # * Alias initialize - added a helper hash
  2190. #----------------------------------------------------------------------------
  2191. alias init_gt_tini_gme_temp_tia initialize
  2192. def initialize
  2193. init_gt_tini_gme_temp_tia
  2194. @temp_seed_data = {} # data stored when trying to plant a seed to prevent
  2195. # calculating the seeds placement location twice (once
  2196. # when checking if plantable and again when planting)
  2197. @temp_seed_clear = [] # data stored when trying to clear a plant to prevent
  2198. # recalculation of the same information.
  2199. end
  2200. #----------------------------------------------------------------------------
  2201. # * Alias - Clear Common Event, clear internal common events as well
  2202. #----------------------------------------------------------------------------
  2203. alias cce_cle_com_even_inter clear_common_event
  2204. def clear_common_event
  2205.  
  2206. # Only clear out the internal common event if one is found. This will allow
  2207. # the real common event that was reserved to be used next time.
  2208. if @internal_ce_sym
  2209. @internal_ce_sym = false
  2210. return @last_internal_ce = nil
  2211. end
  2212.  
  2213. cce_cle_com_even_inter
  2214.  
  2215. end
  2216. #----------------------------------------------------------------------------
  2217. # * Alias - Common Event Reserved, reserve internal common events
  2218. #----------------------------------------------------------------------------
  2219. alias cer_comm_eve_reser_comresv common_event_reserved?
  2220. def common_event_reserved?
  2221. cer_comm_eve_reser_comresv || @internal_ce_sym
  2222. end
  2223. #----------------------------------------------------------------------------
  2224. # * Alias method - Reserved Common Event, add functionality to return
  2225. # internal common events if one has been reserved.
  2226. #----------------------------------------------------------------------------
  2227. alias rescomev_rce_res_com_ev reserved_common_event
  2228. def reserved_common_event
  2229. if @internal_ce_sym # play the internal common event first, then the real one.
  2230. return make_internal_ce
  2231. else
  2232. return rescomev_rce_res_com_ev
  2233. end
  2234. end
  2235. #----------------------------------------------------------------------------
  2236. # * Reserve Internal Common Event
  2237. #----------------------------------------------------------------------------
  2238. def reserve_internal_ce(sym, *args)
  2239. @internal_ce_sym = sym
  2240. @internal_ce_args = args
  2241. end
  2242. #----------------------------------------------------------------------------
  2243. # * Make Internal Common Event
  2244. #----------------------------------------------------------------------------
  2245. def make_internal_ce
  2246. return @last_internal_ce unless @last_internal_ce.nil?
  2247. ce = RPG::CommonEvent.new
  2248. ce.list = []
  2249. ce.give_script(@internal_ce_sym.to_s, @internal_ce_args)
  2250. ce.list.push(RPG::EventCommand.new)
  2251. @last_internal_ce = ce
  2252. end
  2253. #----------------------------------------------------------------------------
  2254. # * Garden Seed Placement-Position-Checking Helper
  2255. # Helper method to reduce repetitive similar code in the internal common
  2256. # events. Returns the xy position that the fertillizer or seed should be
  2257. # placed at.
  2258. #----------------------------------------------------------------------------
  2259. def garden_seed_temp_xy_helper(id, front)
  2260. seed_data = @temp_seed_data.delete(id)
  2261.  
  2262. sx, sy = seed_data[:sx], seed_data[:sy]
  2263. px, py = seed_data[:px], seed_data[:py]
  2264. fx, fy = nil, nil
  2265.  
  2266. if front # want to plant in front of player
  2267. if sx.nil? && sy.nil? # wanted to plant in front but couldn't
  2268. fx,fy = px, py # so place at players x,y instead
  2269. else
  2270. fx,fy = sx, sy # plant in front
  2271. end
  2272. else # want to plant at player's location
  2273. if px.nil? && py.nil? # wanted to plant at player's location but was blocked
  2274. fx, fy = sx, sy
  2275. else
  2276. fx, fy = px, py
  2277. end
  2278. end # if front
  2279.  
  2280. [fx,fy]
  2281. end # garden_seed_temp_xy_helper
  2282.  
  2283. end # Game_Temp
  2284.  
  2285. #==============================================================================
  2286. # ** RPG::CommonEvent
  2287. #==============================================================================
  2288. class RPG::CommonEvent
  2289. #----------------------------------------------------------------------------
  2290. # * Give Script - Only pass in one line for now
  2291. #----------------------------------------------------------------------------
  2292. def give_script(proc_name, args)
  2293. accum = ""
  2294. args.each{ |v| accum.eql?("") ? accum<<"#{v}" : accum<<",#{v}" }
  2295. proc_name<<".call("<<accum<<")"
  2296. @list.push(RPG::EventCommand.new(355,0,[proc_name]))
  2297. end # give_script
  2298.  
  2299. end # RPG::CommonEvent
  2300.  
  2301. #==============================================================================
  2302. # ** Window_SelectWaterer
  2303. # A window shown in Scene_Map when selecting a water container to use when
  2304. # watering a plant.
  2305. #==============================================================================
  2306. class Window_SelectWaterer < Window_ItemList
  2307. #--------------------------------------------------------------------------
  2308. # * Get Digit Count
  2309. #--------------------------------------------------------------------------
  2310. def col_max
  2311. return 1
  2312. end
  2313. #--------------------------------------------------------------------------
  2314. # * Include in Item List?
  2315. #--------------------------------------------------------------------------
  2316. def include?(item)
  2317. item.is_a?(RPG::Item) && item.is_waterer? && item.water_available_uses > 0
  2318. end
  2319. #----------------------------------------------------------------------------
  2320. # * Update
  2321. #----------------------------------------------------------------------------
  2322. def update
  2323. super
  2324. self.opacity += 25
  2325. end
  2326. #----------------------------------------------------------------------------
  2327. # * Show
  2328. #----------------------------------------------------------------------------
  2329. def show
  2330. super
  2331. self.opacity = 0
  2332. end # show
  2333.  
  2334. end # Window_SelectWaterer
  2335.  
  2336. #==============================================================================
  2337. # ** Window_WatererData
  2338. # Displays how much water is left in the currently selected container when
  2339. # choosing one to use to water a plant.
  2340. #==============================================================================
  2341. class Window_WatererData < Window_Base
  2342. #----------------------------------------------------------------------------
  2343. # * Initialize
  2344. #----------------------------------------------------------------------------
  2345. def initialize(*args)
  2346. super(*args)
  2347. self.opacity = 0
  2348. self.windowskin = Bitmap.new(Graphics.width,300)
  2349. end
  2350. #----------------------------------------------------------------------------
  2351. # * Give Item Window
  2352. #----------------------------------------------------------------------------
  2353. def give_item_window(w)
  2354. @item_window = w
  2355. @old = nil
  2356. end
  2357. #----------------------------------------------------------------------------
  2358. # * Update
  2359. #----------------------------------------------------------------------------
  2360. def update
  2361. super
  2362.  
  2363. self.opacity += 25
  2364. refresh if @old != item
  2365. end
  2366. #----------------------------------------------------------------------------
  2367. # * Help Text
  2368. #----------------------------------------------------------------------------
  2369. def help_text
  2370. return unless item
  2371. e_str = "#{item.water_available_uses}/#{item.water_amount_uses}"
  2372. "#{item.name}: #{e_str}"
  2373. end
  2374. #----------------------------------------------------------------------------
  2375. # * Item
  2376. #----------------------------------------------------------------------------
  2377. def item
  2378. return unless @item_window
  2379. @item_window.item
  2380. end
  2381. #----------------------------------------------------------------------------
  2382. # * Show
  2383. #----------------------------------------------------------------------------
  2384. def show
  2385. super
  2386. self.opacity = 0
  2387. end
  2388. #----------------------------------------------------------------------------
  2389. # * Refresh
  2390. #----------------------------------------------------------------------------
  2391. def refresh
  2392. @old = item
  2393. contents.clear
  2394. contents.font.size = 22
  2395. draw_background(Rect.new(0,0,width,height))
  2396. draw_text(0,0,width,line_height,help_text)
  2397. end
  2398. #----------------------------------------------------------------------------
  2399. # * Draw Background
  2400. #----------------------------------------------------------------------------
  2401. def draw_background(rect)
  2402. temp_rect = rect.clone
  2403. temp_rect.width /= 2
  2404. contents.gradient_fill_rect(temp_rect, back_color2, back_color1)
  2405. temp_rect.x = temp_rect.width
  2406. contents.gradient_fill_rect(temp_rect, back_color1, back_color2)
  2407. end
  2408. #--------------------------------------------------------------------------
  2409. # * Get Background Color 1
  2410. #--------------------------------------------------------------------------
  2411. def back_color1
  2412. Color.new(0, 0, 0, 192)
  2413. end
  2414. #--------------------------------------------------------------------------
  2415. # * Get Background Color 2
  2416. #--------------------------------------------------------------------------
  2417. def back_color2
  2418. Color.new(0, 0, 0, 0)
  2419. end # back_color2
  2420.  
  2421. end # Window_WatererData
  2422.  
  2423. #==============================================================================
  2424. # ** Window_ShowOptsEra
  2425. # Window displayed when the player is selecting whether or not they want
  2426. # to water a plant.
  2427. #==============================================================================
  2428. class Window_ShowOptsEra < Window_Selectable
  2429. #----------------------------------------------------------------------------
  2430. # * Initialize
  2431. #----------------------------------------------------------------------------
  2432. def initialize(*args)
  2433. super(*args)
  2434. draw_text(7,0,70,line_height, "Yes")
  2435. draw_text(7,25,70,line_height, "No")
  2436. end
  2437. #----------------------------------------------------------------------------
  2438. # * Item Max
  2439. #----------------------------------------------------------------------------
  2440. def item_max
  2441. return 2
  2442. end
  2443. def update
  2444. super
  2445. self.opacity += 25
  2446. end
  2447. #----------------------------------------------------------------------------
  2448. # * Show
  2449. #----------------------------------------------------------------------------
  2450. def show
  2451. super
  2452. self.opacity = 0
  2453. end
  2454. #----------------------------------------------------------------------------
  2455. # * Draw Item
  2456. #----------------------------------------------------------------------------
  2457. def draw_item(index)
  2458. case index
  2459. when 0
  2460. return "Yes"
  2461. when 1
  2462. return "No"
  2463. end
  2464. end # draw_item
  2465.  
  2466. end # Window_ShowOptsEra
  2467.  
  2468. #==============================================================================
  2469. # ** Window_WatererText
  2470. # Used to show windowed during Scene_Map
  2471. #==============================================================================
  2472. class Window_WatererText < Window_Base
  2473. #----------------------------------------------------------------------------
  2474. # * Initialize
  2475. #----------------------------------------------------------------------------
  2476. def initialize(*args)
  2477. super(*args)
  2478. self.opacity = 0
  2479. refresh
  2480. end
  2481. #----------------------------------------------------------------------------
  2482. # * Give Text
  2483. #----------------------------------------------------------------------------
  2484. def give_text(text)
  2485. @text = text
  2486. refresh
  2487. end
  2488. #----------------------------------------------------------------------------
  2489. # * Update
  2490. #----------------------------------------------------------------------------
  2491. def update
  2492. super
  2493. self.opacity += 25
  2494. end
  2495. #----------------------------------------------------------------------------
  2496. # * Help text - default text shown if none is given to this window.
  2497. #----------------------------------------------------------------------------
  2498. def help_text
  2499. @text ? @text : "Would you like to water it?"
  2500. end
  2501. #----------------------------------------------------------------------------
  2502. # * Show
  2503. #----------------------------------------------------------------------------
  2504. def show
  2505. super
  2506. self.opacity = 0
  2507. end
  2508. #----------------------------------------------------------------------------
  2509. # * Refresh
  2510. #----------------------------------------------------------------------------
  2511. def refresh
  2512. contents.clear
  2513. draw_text(0,0,width,line_height+10,help_text)
  2514. end # Refresh
  2515.  
  2516. end # Window_WatererText
  2517.  
  2518. #==============================================================================
  2519. # ** Window_WaterAmt
  2520. # Used to select the number of times the plant should be watered.
  2521. #==============================================================================
  2522. class Window_WaterAmt < Window_Selectable
  2523. #--------------------------------------------------------------------------
  2524. # * Initialize
  2525. #--------------------------------------------------------------------------
  2526. def initialize(*args)
  2527. super(*args)
  2528. @number = 1
  2529. refresh
  2530. end
  2531. #--------------------------------------------------------------------------
  2532. # * Item Max
  2533. #--------------------------------------------------------------------------
  2534. def item_max
  2535. 1
  2536. end
  2537. #--------------------------------------------------------------------------
  2538. # * Number
  2539. #--------------------------------------------------------------------------
  2540. def number
  2541. @number
  2542. end
  2543. #--------------------------------------------------------------------------
  2544. # * Give Water Container
  2545. #--------------------------------------------------------------------------
  2546. def give_waterer(item)
  2547. @item = item
  2548. end
  2549. #--------------------------------------------------------------------------
  2550. # * Frame Update
  2551. #--------------------------------------------------------------------------
  2552. def update
  2553. super
  2554. if active
  2555. last_number = @number
  2556. update_number
  2557. if @number != last_number
  2558. Sound.play_cursor
  2559. refresh
  2560. end
  2561. end
  2562. end
  2563. #--------------------------------------------------------------------------
  2564. # * Update Quantity
  2565. #--------------------------------------------------------------------------
  2566. def update_number
  2567. change_number(10) if Input.repeat?(:RIGHT)
  2568. change_number(-10) if Input.repeat?(:LEFT)
  2569. change_number(1) if Input.repeat?(:UP)
  2570. change_number(-1) if Input.repeat?(:DOWN)
  2571. end
  2572. #--------------------------------------------------------------------------
  2573. # * Change Number
  2574. #--------------------------------------------------------------------------
  2575. def change_number(mod)
  2576. @number = [@number+mod,0].max
  2577. if @number > ([email protected]_available_uses)
  2578. @number = n
  2579. end
  2580. end
  2581. #--------------------------------------------------------------------------
  2582. # * Refresh
  2583. #--------------------------------------------------------------------------
  2584. def refresh
  2585. contents.clear
  2586. draw_number
  2587. end
  2588. #--------------------------------------------------------------------------
  2589. # * Draw Number
  2590. #--------------------------------------------------------------------------
  2591. def draw_number
  2592. change_color(normal_color)
  2593. draw_text(0, 0, 80, line_height, @number,2)
  2594. draw_text(0,0, 80, line_height, "x")
  2595. end
  2596. #--------------------------------------------------------------------------
  2597. # * Activate
  2598. #--------------------------------------------------------------------------
  2599. def activate
  2600. super
  2601. select(0)
  2602. end # Activate
  2603.  
  2604. end # Window_WaterAmt
  2605.  
  2606. #==============================================================================
  2607. # ** Game_Interpreter
  2608. #==============================================================================
  2609. class Game_Interpreter
  2610. #----------------------------------------------------------------------------
  2611. # * Garden Fill Containers
  2612. # Pass an integer to modifer the containers by a specified amount,
  2613. # otherwise the containers will be completely refilled
  2614. #----------------------------------------------------------------------------
  2615. def garden_fill_containers(mod = :max)
  2616. return false unless $game_player.party_has_waterer_era?(mod == :max || mod > 0)
  2617. $game_party.items.each do |item|
  2618. if item.is_waterer?
  2619. if mod == :max
  2620. item.mod_waterer_available_uses(item.water_amount_uses)
  2621. else
  2622. item.mod_waterer_available_uses(mod)
  2623. end
  2624. end # item.is_waterer?
  2625.  
  2626. scene=SceneManager.scene
  2627. return unless scene.is_a?(Scene_Map)
  2628. spm = scene.instance_eval('@spriteset')
  2629.  
  2630. if mod == :max
  2631. spm.add_spgt_to_spm("Water containers maxed")
  2632. else
  2633. spm.add_spgt_to_spm("Water containers #{mod < 0 ? "-" : "+"}#{mod}")
  2634. end
  2635. end # $game_party.items.each
  2636. return true
  2637. end # garden_fill_containers
  2638. #----------------------------------------------------------------------------
  2639. # * Destroy a garden plant from its event's interpreter.
  2640. #----------------------------------------------------------------------------
  2641. def harvest_garden_plant(should_destroy)
  2642. ev = (map = $game_map).events[@event_id]
  2643. return unless !ev.plant.nil?
  2644. harvest = ev.plant.harvest
  2645.  
  2646. if should_destroy
  2647. $game_system.destroy_plant(ev.plant.plant_id)
  2648. @event_id = 0
  2649. end
  2650.  
  2651. return harvest
  2652. end
  2653. end # Game_Interpreter
  2654.  
  2655. #==============================================================================
  2656. # ** Spriteset_Map
  2657. # Add methods to support adding instances of Sprite_GardenText to the spm
  2658. #==============================================================================
  2659. class Spriteset_Map
  2660. #----------------------------------------------------------------------------
  2661. # * Alias - initialize
  2662. #----------------------------------------------------------------------------
  2663. alias init_spgt_teserir_pam_spm_ali_era initialize
  2664. def initialize
  2665. init_spgt_teserir_pam_spm_ali_era
  2666. create_spgt_arr
  2667. end
  2668. #----------------------------------------------------------------------------
  2669. # * Alias - Dispose
  2670. #----------------------------------------------------------------------------
  2671. alias dis_sprmt_esopsi_disp_b_chars dispose
  2672. def dispose
  2673. dis_sprmt_esopsi_disp_b_chars
  2674. dispose_spgdtext
  2675. end
  2676. #----------------------------------------------------------------------------
  2677. # * Alias - Update
  2678. #----------------------------------------------------------------------------
  2679. alias etad_upd_sprm_txtbm_disp_era update
  2680. def update
  2681. etad_upd_sprm_txtbm_disp_era
  2682. update_spgdtext
  2683. end
  2684. #----------------------------------------------------------------------------
  2685. # * Create Sprite Garden Text Array
  2686. #----------------------------------------------------------------------------
  2687. def create_spgt_arr
  2688. @spgt_text_era = []
  2689. end
  2690. #----------------------------------------------------------------------------
  2691. # * Update Sprite Garden Text
  2692. #----------------------------------------------------------------------------
  2693. def update_spgdtext
  2694. return unless @spgt_text_era
  2695. @spgt_text_era.each{|spgt| spgt.update}
  2696. end
  2697. #----------------------------------------------------------------------------
  2698. # * Dispose Sprite Garden Text
  2699. #----------------------------------------------------------------------------
  2700. def dispose_spgdtext
  2701. @spgt_text_era.each{|spgt| spgt.dispose}
  2702. end
  2703. #----------------------------------------------------------------------------
  2704. # * Add Sprite Garden to Spritesetmap
  2705. #----------------------------------------------------------------------------
  2706. def add_spgt_to_spm(text)
  2707. @spgt_text_era.push(Sprite_GardenText.new(@viewport3).give(text))
  2708. end
  2709.  
  2710. end # Spriteset_Map
  2711. #==============================================================================
  2712. # ** Sprite_GardenText
  2713. # Displays bouncing text on the screen.
  2714. #==============================================================================
  2715. class Sprite_GardenText < Sprite_Base
  2716. #----------------------------------------------------------------------------
  2717. # * Initialize
  2718. #----------------------------------------------------------------------------
  2719. def initialize(*args)
  2720. super(*args)
  2721. self
  2722. end
  2723. #----------------------------------------------------------------------------
  2724. # * Give
  2725. #----------------------------------------------------------------------------
  2726. def give(text = "!")
  2727. @bounce_min = 23
  2728. @bounce_min_count = 0
  2729. @val = -4
  2730.  
  2731. self.bitmap = Bitmap.new(200,35)
  2732. self.bitmap.font.color.set(200,220,100)
  2733. self.bitmap.font.size = 24
  2734. self.bitmap.draw_text(0,0,200,35,text)
  2735. self.y = $game_player.x * 32 - $game_map.display_x
  2736. self.x = $game_player.y * 32 - $game_map.display_y
  2737. self.ox = bitmap.width/5
  2738. self.oy = bitmap.height/3
  2739. self
  2740. end
  2741. #----------------------------------------------------------------------------
  2742. # * Update
  2743. #----------------------------------------------------------------------------
  2744. def update
  2745. return if self.bitmap.disposed?
  2746. if @bounce_min <= 0
  2747. self.opacity -= 5.5
  2748. self.bitmap.dispose if self.opacity < 0
  2749. return
  2750. end
  2751. self.x += 1
  2752. self.y+=@val
  2753. self.zoom_x+=0.004
  2754. self.zoom_y+=0.004
  2755. @bounce_min_count += 5.5
  2756. return if @val > 0 && @bounce_min_count/2 < @bounce_min
  2757. if @bounce_min_count >= @bounce_min || (@val < 0 ? @bounce_min_count >= @bounce_min/2 : false)
  2758. @val *= -1
  2759. @bounce_min -= 7 if @val < 0
  2760. @bounce_min_count = -@bounce_min_count/2
  2761. end
  2762.  
  2763. end
  2764. #----------------------------------------------------------------------------
  2765. # * Dispose
  2766. #----------------------------------------------------------------------------
  2767. def dispose
  2768. self.bitmap.dispose
  2769. end # dispose
  2770. end # Sprite_GardenText
  2771.  
  2772. # End of File
Advertisement
Add Comment
Please, Sign In to add comment