blucalm

Gardening one file (no dependencies)

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