blucalm

Gardening one file (no dependencies) Bug fix 1

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