| #============================================================================== | |
| # Drops | |
| # ---------------------------------------------------------------------------- | |
| # Version: 1.0.1 | |
| # Author: Kalacious (AKA: VindictivePersonality) | |
| # License: GPL 3.0 | |
| # | |
| # Changes 1.0.1 | |
| # ---------------------------------------------------------------------------- | |
| # ---> Can now enter whole numbers as percentages for item and | |
| # currency drops. | |
| # | |
| # Compatibillity Issues | |
| # ---------------------------------------------------------------------------- | |
| # | |
| # There should be NO compatibillity issues what so ever. How ever if there are, | |
| # Please let me know. | |
| # | |
| # Requirements? | |
| # ---------------------------------------------------------------------------- | |
| # | |
| # ---> Any things with REQUIRED is well, required and, if missing, may cause | |
| # things to look weird or not work at all. | |
| # | |
| # -- Kalacious Currency Script - to use currencies, any thing but gold. | |
| # (see below) | |
| # -- REQUIRED -> http://himeworks.wordpress.com/2013/05/12/post-battle-events/ | |
| # --> The above script belongs to Hime Works and is required to have this | |
| # work AFTER battles, which is what it's intended to do. | |
| # -- REQUIRED -> http://rmrk.net/index.php/topic,44964.0.html | |
| # --> The above script belongs to Modern Algebra and is used to format | |
| # paragraphs, this stops me from having to do it. | |
| # | |
| # ---> Note: Want to create random drops that have nothing to do with | |
| # enemies? see Tutorial 3 below! - You wont need the FIRST | |
| # REQUIRED script to do it! | |
| # | |
| # TOS | |
| # ---------------------------------------------------------------------------- | |
| # If you know the GPL version 3, you know the answer, but this still applies: | |
| # | |
| # Script for RGSS 3 ONLY adds abillity to generate troop drops. | |
| # Copyright (C) 2013 Kalacious (AKA VindictivePersonality) | |
| # | |
| # This program is free software: you can redistribute it and/or modify | |
| # it under the terms of the GNU General Public License as published by | |
| # the Free Software Foundation, either version 3 of the License, or | |
| # (at your option) any later version. | |
| # | |
| # This program is distributed in the hope that it will be useful, | |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| # GNU General Public License for more details. | |
| # | |
| # You should have received a copy of the GNU General Public License | |
| # along with this program. If not, see <http://www.gnu.org/licenses/> | |
| # | |
| # | |
| #============================================================================== | |
| # | |
| # How to Use? | |
| # ----------- | |
| # | |
| # You have one main way to customize and thats the hash, the Drops Hash. | |
| # this is where you ceate your drops either in a regular hash or a nested | |
| # hash. These Drops are then used | |
| # | |
| # DROPS::DROP_HASH | |
| # ---------------- | |
| # | |
| # This is the most important part of the script. This is where you set up | |
| # what are called "static" drops, drops that never change and can easily | |
| # be given to any troop. (for drops created on the fly please see below). | |
| # | |
| # The goal here is to create any kind of drop, at any time, and distribute | |
| # it to the player after they have finished a battle. | |
| # | |
| # The following hash example is a single drop with a single ite, lets look | |
| # at it: | |
| # | |
| # DROP_HASH = { | |
| # "Drop One" => { ---> Drop Object Name - Must be unique. | |
| # :item_type => 0, ---> 0 - item, 1 - weapons, 2 - armors | |
| # :item_id => 1, ---> id of item to award | |
| # :item_drop_per => 4, ---> This item has a 4% chance to drop. | |
| # :amount => 6, ---> How many of this item? | |
| # :currency_type => "GC", ---> Curency to award. "gold" is acceptable. | |
| # :currency_gain => 25, ---> how much of this currency do you gain? | |
| # :currency_gain_per => 10 --> 10% chance to gain this currency. | |
| # }, | |
| # } | |
| # | |
| # Note: If you are not using my currency script - yet want to give MORE gold, | |
| # then you MUST enter "gold". | |
| # | |
| # Note: All items and currencies that drop can have a percentage of | |
| # chance to drop. | |
| # | |
| # Note: NODROPMESSAGE is for when their are no currenies and no items | |
| # that drop, if left as '', no message will be shown. | |
| # | |
| # The above hash, will create one drop object for the player to recieve on | |
| # victory of the battle with that troop. The beauty here is that you can set | |
| # up multiple "drops" for multiple troops, each troop can have their own drop. | |
| # | |
| # "Kalacious!" You exclaim - "I want MORE drops for this troop!" ok, | |
| # lets create that hash together! | |
| # | |
| # "Drop Two" => [ | |
| # { | |
| # :item_type => 0, | |
| # :item_id => 20, | |
| # :item_drop_per => 1, | |
| # :amount => 6, | |
| # :currency_type => "RT", | |
| # :currency_gain => 20, | |
| # :currency_gain_per => 20 | |
| # }, | |
| # { | |
| # :item_type => 1, | |
| # :item_id => 1, | |
| # :item_drop_per => 100, | |
| # :amount => 6, | |
| # :currency_type => "GC", | |
| # :currency_gain => 20, | |
| # :currency_gain_per => 75 | |
| # }, | |
| # { | |
| # :item_type => 2, | |
| # :item_id => 1, | |
| # :item_drop_per => 10, | |
| # :amount => 6, | |
| # :currency_type => "", | |
| # :currency_gain => 0 | |
| # :currency_gain_per => 45 | |
| # }, | |
| # ] | |
| # | |
| # OMG!!! - What is that?!!! - Its a drop with three items. Notices that | |
| # You can have NO currencies in the third entry. (Also note the commas). | |
| # | |
| # This is where my currency script comes in handy, as you can see, the type | |
| # is set to that of a currency already created - YOU CANNOT - give currencies | |
| # that do not exist, and NO we wont create them for you. They must exist. | |
| # | |
| # Also note, using Gold instead of my custom curencies? WE ONLY ACCEPT: "gold" | |
| # as the currency type. | |
| # | |
| # With that aside we have created one drop object with three different drops | |
| # in it.one item, one weapon and one armor. YOU CANNOT have the same item and | |
| # item type for two drops. that is you cannot have, item_type => 1 with | |
| # a item_id => 1 for more then one drop in a drop object. You can have multiple | |
| # items of the same type provided they are all different. If you want to | |
| # have multiple items of the same type and id, enter in how many should be | |
| # awarded via the :amount key. | |
| # | |
| # Now that we have that all sored out, we can create one drop object with | |
| # one drop or one drop object with MULTIPLE drops in it. | |
| # | |
| # Ok, but what methods do we have to use to access this data? | |
| # | |
| # Lets get into that! | |
| # | |
| # $kc_drop Call - Calls: Troop_Drop Class | |
| # --------------------------------------- | |
| # | |
| # $kc_drop.drop_object ---> Gives back an array of drops. | |
| # | |
| # $kc_drop.create_new_drop(item_type, item_id, item_drop_per, amount, | |
| # currency_type, currency_gain, currency_gain_per) | |
| # ---> Ceates ONE drop (see below). | |
| # where the item and the | |
| # currency have a drop | |
| # percentage. | |
| # | |
| # $kc_drop.create_new_static_drop(name) ---> Creates a drop object based | |
| # on the hashes key string name. | |
| # | |
| # | |
| # $kc_drop.give_items(gain_currencies = false) | |
| # ---> Give out items, displaying a | |
| # message. Do we also give out | |
| # currencies? | |
| # | |
| # | |
| # Ok, Kalacious - walk me through how to take the hash above, Drop Two and | |
| # at the end of a battle - give out the items and currencies. | |
| # | |
| # TUTORIAL 1 - Hash Drops | |
| # ------------------------ | |
| # | |
| # So lets say you have this hash: | |
| # | |
| # "Drop Two" => [ | |
| # { | |
| # :item_type => 0, | |
| # :item_id => 20, | |
| # :item_drop_per => 56, | |
| # :amount => 6, | |
| # :currency_type => "RT", | |
| # :currency_gain => 20, | |
| # :currency_gain_per => 56 | |
| # }, | |
| # { | |
| # :item_type => 1, | |
| # :item_id => 1, | |
| # :item_drop_per => 56, | |
| # :amount => 6, | |
| # :currency_type => "GC", | |
| # :currency_gain => 20, | |
| # :currency_gain_per => 56 | |
| # }, | |
| # { | |
| # :item_type => 2, | |
| # :item_id => 1, | |
| # :item_drop_per => 56, | |
| # :amount => 6, | |
| # :currency_type => "", | |
| # :currency_gain => 0, | |
| # :currency_gain_per => 56 | |
| # }, | |
| # ] | |
| # | |
| # And you want to distribute these beauties at the end of the battle. No | |
| # problem. Using "Post-Battle Events" (posted above) we need to go into the | |
| # troop event page and create the following event: | |
| # | |
| # Comment: <post battle victory> | |
| # Script: $kc_drop.create_new_static_drop("Drop Two") | |
| # $kc_drop.give_items(true) | |
| # | |
| # Then go run the battle, after words you get the regular rewards, then you | |
| # get the troop rewards. | |
| # | |
| # TUTORIAL 2 - On the Fly Drops | |
| # ------------------------------ | |
| # | |
| # Ok...Ok....I see - crete me one on the fly! | |
| # | |
| # Ok, lets say you one to give one drop. You can do this two different way, | |
| # you can create an event on the map that creates the item or you can do | |
| # it post battle, either way the script calls are the same. | |
| # | |
| # Lets assume your doing it after the battle is done and over with. you | |
| # would do this: | |
| # | |
| # Comment: <post battle victory> | |
| # Script: $kc_drop.create_new_drop(0, 1, 20, 76, "gold", 40, 78) | |
| # $kc_drop.give_items(true) | |
| # | |
| # The above will give you 20 items with the id of 1 and 40 gold. | |
| # | |
| # TUTORIAL 3 - With out Battles! | |
| # ------------------------------- | |
| # | |
| # KALCIOUS!!!!! - I want to do this WITH OUT BATTLES. ok, so create your | |
| # drops like normal and then just call $kc_drop.give_items(true/false) in | |
| # an event....Simple. | |
| # | |
| # | |
| #============================================================================== | |
| # ** DROPS | |
| #------------------------------------------------------------------------------ | |
| # Lets you set up a drop objects with either ONE drop or multiple. The first | |
| # one is a drop object with ONE drop, while the second object has THREE drops | |
| # in it. | |
| # ---------------------------------------------------------------------------- | |
| #============================================================================== | |
| module DROPS | |
| DROP_HASH = { | |
| "Drop One" => { | |
| :item_type => 0, | |
| :item_id => 1, | |
| :amount => 6, | |
| :item_drop_per => 100, | |
| :currency_type => "GC", | |
| :currency_gain => 25, | |
| :currency_gain_per => 3 | |
| }, | |
| "Drop Two" => [ | |
| { | |
| :item_type => 0, | |
| :item_id => 20, | |
| :amount => 6, | |
| :currency_type => "RT", | |
| :currency_gain => 20 | |
| }, | |
| { | |
| :item_type => 1, | |
| :item_id => 1, | |
| :amount => 6, | |
| :currency_type => "GC", | |
| :currency_gain => 20 | |
| }, | |
| { | |
| :item_type => 2, | |
| :item_id => 1, | |
| :amount => 6, | |
| :currency_type => "", | |
| :currency_gain => 0 | |
| }, | |
| ] | |
| } | |
| NODROPMESSAGE = '' | |
| end | |
| #============================================================================== | |
| # ** DataManager | |
| #------------------------------------------------------------------------------ | |
| # This module manages the database and game objects. Almost all of the | |
| # global variables used by the game are initialized by this module. | |
| #============================================================================== | |
| class << DataManager | |
| alias kalacious_troop_drop_object create_game_objects | |
| def create_game_objects | |
| kalacious_troop_drop_object | |
| $kc_drop = Troop_Drop.new | |
| end | |
| end | |
| #============================================================================== | |
| # ** Troop_Drop | |
| #------------------------------------------------------------------------------ | |
| # Responsible for creating drops and distibuting the drops. | |
| #============================================================================== | |
| class Troop_Drop | |
| #-------------------------------------------------------------------------- | |
| # * Create an empty @troop_drop_object array to hold the drops for a single | |
| # drop object. | |
| #-------------------------------------------------------------------------- | |
| def initialize | |
| @troop_drop_object = [] | |
| end | |
| #-------------------------------------------------------------------------- | |
| # * Returns the drop object for inspection | |
| #-------------------------------------------------------------------------- | |
| def drop_object | |
| @troop_drop_object | |
| end | |
| #-------------------------------------------------------------------------- | |
| # * Allows you to create a drop on the fly. | |
| #-------------------------------------------------------------------------- | |
| def create_new_drop(item_type, item_id, item_drop_per, amount, | |
| currency_type, currency_gain, currency_gain_per) | |
| if @troop_drop_object.any? | |
| @troop_drop_object.each do |drop| | |
| if drop.item_type == item_type and drop.item_id == item_id | |
| return false | |
| end | |
| end | |
| end | |
| drop_object = Troop_Drop_Object.new(item_type, item_id, item_drop_per, | |
| amount, currency_type, currency_gain, currency_gain_per) | |
| @troop_drop_object.push(drop_object) | |
| end | |
| #-------------------------------------------------------------------------- | |
| # * Creates a new drop object based off the hash and the name of the | |
| # coresponding drop object. | |
| #-------------------------------------------------------------------------- | |
| def create_new_static_drop(name) | |
| drops = DROPS::DROP_HASH[name] || [] | |
| drops = [drops] if !drops.is_a? Array | |
| drops.each do |drop| | |
| create_new_drop(drop[:item_type], drop[:item_id], drop[:item_drop_per], | |
| drop[:amount], drop[:currency_type], drop[:currency_gain], | |
| drop[:currency_gain_per]) | |
| end | |
| end | |
| #-------------------------------------------------------------------------- | |
| # * Gives all items and currencies (only gives currencies if set to true) | |
| # Displays a message stating that we gave you bla. | |
| #-------------------------------------------------------------------------- | |
| def give_items(gain_currencies = false) | |
| random_number = rand(100) | |
| if @troop_drop_object.any? | |
| @troop_drop_object.each do |troop| | |
| if random_number <= troop.item_drop_per | |
| case troop.item_type | |
| when 0; $game_party.gain_item($data_items[troop.item_id], | |
| troop.amount, true) | |
| when 1; $game_party.gain_item($data_weapons[troop.item_id], | |
| troop.amount, true) | |
| when 2; $game_party.gain_item($data_armors[troop.item_id], | |
| troop.amount, true) | |
| end | |
| end | |
| if gain_currencies | |
| gain_currency(troop) | |
| end | |
| end | |
| display_gain_message(gain_currencies, random_number) | |
| end | |
| end | |
| private | |
| #-------------------------------------------------------------------------- | |
| # * PRIVATE - Displays a message for the items and currencies gained. | |
| #-------------------------------------------------------------------------- | |
| def display_gain_message(gain_currencies = false, random_number) | |
| if create_item_array(random_number).empty? and | |
| create_currency_array(random_number).empty? | |
| if DROPS::NODROPMESSAGE != '' | |
| $game_message.texts.push(DROPS::NODROPMESSAGE) | |
| else | |
| return | |
| end | |
| end | |
| if create_item_array(random_number).any? | |
| $game_message.texts.push("Gained Items: ") | |
| $game_message.texts.push(create_item_array(random_number).each_slice(2).map { |top| "#{top.first} (x#{top.last})" }.join(', ') + '.') | |
| end | |
| if create_currency_array(random_number).any? | |
| if gain_currencies | |
| $game_message.texts.push("\\n\\nGained Currencies: ") | |
| $game_message.texts.push(create_currency_array(random_number).each_slice(2).map { |top| "#{top.first}: #{top.last}" }.join(', ') + '.') | |
| end | |
| end | |
| end | |
| #-------------------------------------------------------------------------- | |
| # * PRIVATE - Gains currencies, uses Currency script if we don't | |
| # enter "gold" | |
| #-------------------------------------------------------------------------- | |
| def gain_currency(single_troop_object) | |
| puts rand(100) | |
| puts single_troop_object.currency_gain_per | |
| if rand(100) <= single_troop_object.currency_gain_per | |
| if single_troop_object.currency_type != "gold" | |
| if $kc_currency.exists?(single_troop_object.currency_type) | |
| $kc_currency.increase(single_troop_object.currency_type, | |
| single_troop_object.currency_gain) | |
| end | |
| else | |
| $game_party.gain_gold(single_troop_object.currency_gain) | |
| end | |
| end | |
| end | |
| #-------------------------------------------------------------------------- | |
| # * PRIVATE - Creates an item array of all items and their amount. | |
| #-------------------------------------------------------------------------- | |
| def create_item_array(random_number) | |
| items = [] | |
| @troop_drop_object.each do |troop| | |
| if random_number <= troop.item_drop_per | |
| items.push(troop.item.name) | |
| items.push(troop.amount) | |
| end | |
| end | |
| items | |
| end | |
| #-------------------------------------------------------------------------- | |
| # * PRIVATE - Creates an array of all currencies and the amount gained. | |
| #-------------------------------------------------------------------------- | |
| def create_currency_array(random_number) | |
| currency = [] | |
| @troop_drop_object.each do |troop| | |
| if troop.currency_gain != 0 and troop.currency_type != "" | |
| if random_number <= troop.currency_gain_per | |
| currency.push(troop.currency_type) | |
| currency.push(troop.currency_gain) | |
| end | |
| end | |
| end | |
| currency | |
| end | |
| end | |
| #============================================================================== | |
| # ** Troop_Drop_Object | |
| #------------------------------------------------------------------------------ | |
| # responsible for creating drop objects for troops. | |
| #============================================================================== | |
| class Troop_Drop_Object | |
| attr_reader :item_type | |
| attr_reader :item_id | |
| attr_reader :item_drop_per | |
| attr_reader :amount | |
| attr_reader :currency_type | |
| attr_reader :currency_gain | |
| attr_reader :currency_gain_per | |
| #-------------------------------------------------------------------------- | |
| # * Create te actual object based on whats passed in. | |
| #-------------------------------------------------------------------------- | |
| def initialize(item_type, item_id, item_drop_per, amount, currency_type, | |
| currency_gain, currency_gain_per) | |
| @item_type = item_type | |
| @item_id = item_id | |
| @item_drop_per = item_drop_per | |
| @amount = amount | |
| @currency_type = currency_type | |
| @currency_gain = currency_gain | |
| @currency_gain_per = currency_gain_per | |
| end | |
| #-------------------------------------------------------------------------- | |
| # * Store the actual item, access it with drop_object.item.RPG::OBJ_NAME | |
| # Example: drop_object.item.name #=> name of item/weapon or armor | |
| #-------------------------------------------------------------------------- | |
| def item | |
| case item_type | |
| when 0 | |
| item = $data_items[item_id] | |
| when 1 | |
| item = $data_weapons[item_id] | |
| when 2 | |
| item = $data_armors[item_id] | |
| end | |
| end | |
| end |