blucalm

Garden System Specify Range for Harvest

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