Jump to content

Vis_Mage

Member
  • Content Count

    261
  • Joined

  • Last visited

  • Days Won

    2

Posts posted by Vis_Mage


  1. Hey everyone!

    Hope everyone is doing well. Today, I've got a pretty wide range of odds and ends to show and discuss. 

    First off, I have a few new Wisp designs to share. Namely, four new variants for Ice Wisps! 

    621095297_Ice_Wisp_Preview(1).thumb.png.e2b0e7ca91991008ed7d5dbd3c4290b8.png

    Additionally, continuing with the Hybrid-Wisp idea from my previous update, here's a look at a second design for the Water-Light hybrid.

    152129669_Light_WaterWispStyle2.thumb.png.906dd3d753b43efbad19d073042dd1c9.png

    Next, we have the first draft of the world map! This map isn't final, and additional story-relevant locations will be added over time, as well as ocean mapping. 

    1665071245_WorldMap.thumb.jpg.8b340852aed0e7be9fcbbd8eec54840a.jpg

    And building off the previous point, we also have a new song prepared for one of the newly revealed location on the world map, the dangerous, lightning scorched range of Mt.Magnet!

     

    Finally, to wrap things up, is a first look at a few new character battle sprites. Specifically for Diana, and her father Captain Sham!

    ShamPreview.png.3b332997f749a5e10ae62171259a5925.png

    As far as non-visual progress, mapping and Wisp overworld interactivity has been at the forefront of my focus as of late. Hopefully I'll have some new updates regarding both of those in my next post.

    Take care everyone!


  2. Hello, sorry that I've been pretty quiet lately. The past week or so has been very difficult on me. I lost someone very important to me, my childhood puppy, and have been really struggling since. Although it's been incredibly difficult, I'm hoping things will start to return to normal.

    Here's a look into a few things that were started before a few weeks ago, but are now being polished up. First off is a few new Wisp variants for the light and dark Wisps. Of note, the first of each element was made with a specific character pairing in mind, the light Wisp was given a more crystalline/mirror-like look for Merric, while the dark Wisp was given an imperial armored knight look for Tyra.

    LightDarkWispPreview.png.9471d901c7b334f4561f164ec3bc6ab6.png

    Additionally, something that I haven't fully decided on yet was visually incorporating the Wisps into the battle scene a bit more, when calling them or unleashing skills tied to them. Not entirely sure if or to what degree this would be done, but it is a work in progress, to keep an eye out for!

    Lastly, is the first look at a concept that may or may not be used in some way. Quite a while back, I toyed with the idea of having some Wisps able to "fuse" in some capacity. At the time, the Wisps were using a simpler elemental-orb based design, and so for their Hybrid designs, I was literally just going to have a half-and-half of their two sprites. Now that Wisps have gotten much more fleshed out designs, their potential Hybrid designs would receive a more thought out design as well.

    Here's the first look at one of these potential Hybrid Wisp designs, being Earth/Dark, and based off of obsidian. Something interesting to note, is that their colors aren't just picked at random. The primary/secondary colors are the exact middle-point between the colors used on the Earth and Dark Wisps.

    462928178_Earth_DarkWispStyle2.png.1a805967ec79f96ee6b485ff3616ee93.png

    I haven't entirely decided how (or if) Wisp fusions/hybrids will actually be used, but if they were, I would want to implement it as more than just a cosmetic change, with the fusions granting different skills and stat boosts based on the types of Wisp used in the fusion.

    I'm hoping for updates to be more frequent going forward, so be sure to keep an eye out. And as always, I'd love to hear any feedback you might have regarding the project so far, or if you have anything you would like to hear more about.

    Have a great day!


  3. Hey, just a little word of advice. You'll probably have a greater chance of having someone help out with this (as well as having the finished result better fitting what you're envisioning) with a reference image. Even just a quick sketch helps out tremendously!

    • Confused 1

  4. Hey everyone!

    Hope everyone is doing well. After being gone for a good portion of January, progress is moving along again. I'm thinking of making update posts every few weeks, to go over the biggest bits of progress that has been made.

    Most notably, the Nature and Earth Wisps have received a lot of love, and now each have their complete set of 8 fully designed! Let me know what you think of how they turned out. :)

    Wisp_Faceset_Earth.png.1a2e00829c3d4bd1bbede4f59f07165d.png

    Wisp_Faceset_Nature.png.7448c904501775ad9085f491943e742d.png

    On 1/16/2022 at 11:33 AM, SomaelCK said:

    This project is really interesting! Love the wisps and their utility outside of the battle. That gives me the idea how to expand the utility of the "Whispers" in my game!  

    Hey, and thank you very much, I'm glad you like what you've seen so far!

    I checked out your project as well, and the Whispers are indeed very adorable. I can certainly see the comparison, even down to the name, haha! 😛 

    • Haha 1

  5. ManaStar_Logo(Slim).thumb.png.849015d263b33f3a90c462a51634eacb.png
    Itchio Page: https://vis-mage.itch.io/mana-star

    For the past several years, I've been working on an RPG project that's been heavily inspired by the Golden Sun series. It isn't a fan game, containing a completely new cast/world/assets/etc, but has been very mechanically inspired by the series. After years of work and planning, I’m excited to reveal my project, Mana Star!

     

    coollogo_com-19629190.png.14371a76367ab2998e5443e4388fbc8f.png

    Spoiler

     

    The story follows the young adult Merric, heir to the prestigious role of Archmage of Falter. Having much to learn to fulfill his eventual role as Archmage, Merric has spent the majority of his life in preparation for the title. Things have not been calm in the world, though. Unexplainable, magical phenomenons have been sprouting up all across the globe, putting extensive pressure on the magical leaders of the world to find the cause. However, while out on a research mission, disaster strikes. By the time Merric is able to make it back to this home, there is nothing left of the city. Everything and everyone having been sucked into an unknown magical void.

    And so Merric, alongside his cautious and stern guard Tyra, set off on a quest to find out what's behind all the strange magical happenings, and find a way to save their home. Along their adventures, they'll encounter and team up with several others who have befallen a similar fate, coming together to save those they love, and discover the source of the mysterious events that are slowly consuming their world.

     

     

     

    coollogo_com-178832516.png.06cbe479d80a8f5ef5abc5c87e6bbb1e.png

     

     

    Spoiler
    Spoiler

    merric_1.thumb.png.862d918c7c638b40a422d780eb8f8657.png

    Merric is an apprentice magician, training to eventually take over his father's role as Archmage. While realizing the weight and importance of this position, he can’t help but feel some level of resentment towards it, wanting instead to make a name for himself through his own accomplishments.  He’s confident in his magical abilities given his status and noble upbringing, sometimes to a fault. However, he isn't very worldly, and grew up sheltered.

    He loves both to see himself improve, and to help others improve as well.  Has the passion to be a great leader, and the heart to empathize with the unfortunate, but can be blinded by his pride. Wants to help those in need, and be a leader to something great that he built himself, without his birthright given to him.  He wants to prove he is more than his bloodline.

     

     

     

     

    Spoiler

    tyra_1.thumb.png.b87660cb2e25d86aa8adf70712333149.png

    Tyra was raised by her brother, William, from a very young age after they lost their parents.  She sees William almost as an idol, the peak of honor, duty, and compassion.  She aspires to one day be an Army Captain like him, and in doing so was assigned as the Royal Guard of Merric Solarus from when she first enlisted at 16. To her, this is both a blessing and a curse.

    She’s strong willed, and more stoic than the rest of the group, at least outwardly, but like the others carries a fair bit of baggage of her own.

     

    Spoiler

    maria_1.thumb.png.d720a840b1154b19993afbd4c376f4aa.png

    Maria has long ago determined she finds the greatest joy in helping others in need, and decided on the path of being a cleric from a young age.  She can be a bit childish and short-tempered, but is a very hard and honest worker, and puts the wants and needs of others before her own opinions.

     

    Spoiler

    nala_1.thumb.png.55ff5ed6608207713c1b3f7a130abcd0.png

    Nala is the daughter of a Ridge Island Academy instructor, and studies alchemical ingredient trait compounding. Encouraged by her father, she has developed an intense desire to learn all of the different traits and how ingredients interact with each other, and why some ingredient combinations result in unexpected potions. This has led her to be sent out into the world at a young age, something that hasn’t been without struggle.

    While very intelligent,  she is not very worldly and often oblivious to those around her. Her and Maria have been close friends since they were little, growing up in the same village.

     

    Spoiler

    mindas_1.thumb.png.f568e1856e42d83e680b7b060c010cad.png

    Mindas is the orphaned daughter of Arkaid Plasmid, right hand man of the Technomancer movement's former leader, Yvonne Pell. Even at a young age, she has proven herself a skilled engineer, and a prodigy in Technomancy. From birth, Mindas was paraplegic, being paralyzed from the waist down.  She overcomes her inability to walk with her greatest invention, the Exo-Walker, a highly advanced magitech mech that she uses to get around and fight.

    Mindas is an outcast for her race, being a Dreck.

     

    Spoiler

    Raptor.thumb.png.e4b822e8f94085333a0936c059a38adc.png

    Raptor is a stoic, yet adventurous Talus warrior. He was exiled from his clan and had his true Tallus name stripped as a result of not only associating too often with outsiders, but ultimately saving the passing-by dreck Mindas from a group of Kodrin bandits.  While it may seem a good deed to most, his Tallus clan, like many other clans, forbid intervening in conflicts between other races.  Raptor believes he did the right thing and rejected any apology to his clan for appeasement of his actions, and so he became a quiet and protective friend of Mindas.

    Raptor’s birth name is not translatable to Common, but as he is a bird of prey, he decides others can call him Raptor, and he appreciates being allowed as part of the group, as he never was well liked in his clan, even before exile.

     

    Spoiler

    1962470117_captainsham.thumb.png.3973e1fb1007119a063ee25f9c655830.png

    Captain "Nord" Sham is the captain of the crew aboard the S.S. Sham, and is the oldest of the main case, being in his early 40s. After a tragedy that resulted in the destruction of his home city, and the passing of most of those who lived there including his wife, Sham has made it his mission to rebuild the once great city, using the treasures he acquires to fund the rebuild. Most of his cast are actually people who have met similar fates, causing the crew to act as more than just a ship crew, and instead be more of a family. Despite his livelihood as a pirate, he's a big softie, and a bit of a goof.

    Captain Sham is a very jovial and kind man, and is the sort to carry the burden of others on his back, wanting only to see everybody happy in return.  Deep down, he feels guilty about the fall of Eastport ten years ago, and builds Phemera City to atone for himself.  He knows this isn't healthy, but finds a sense of belonging in it.  Everybody in his crew is not just a worker, but family.

     

    Spoiler

    diana.thumb.png.02aa73de418f7d9f7365966a51703aae.png

    Diana is Captain Sham's daughter. Of the two leading the crew, she's the more serious and level-headed of the two, despite her short temper. She doesn't have much patience for incompetence, and likes to tease those that are easy to fluster.

     

    Spoiler

    isshera.thumb.png.2d84dc4f6db7296897f62d75afcbad60.png

    Isshera lives near the Pearl Reef between Tyria and Holthehaven, being the only child of the ruling family. She's the princess of her undersea colony, and is well aware of the status and privileges it grants her. She can be sassy and stubborn, but is able to back up her words by being very capable of handling things on her own.

    Isshera practices her singing each night, dreaming of seeing the world, and becoming a warrior.  She is a self-titled warrior princess, with a habit of exaggerating her battle stories against the monsters of the sea. She dreams of traveling the world and becoming a famous warrior and commander.  She is capable of magical songs and may truly be fit to lead a unit of soldiers one day.

     

     

     

     

     

    coollogo_com-9118632.png.3eff899fa187c190c71bd43b432ebc26.png

    Spoiler

     

    457773601_WispBaseElements.thumb.png.7ba786c8898618f827b0f5901696dc59.png

    Wisps are the most central and defining mechanic and creature that you'll encounter in the project, being implemented in many different mechanics.

    Wisps are small, elemental creatures that you'll encounter and collect through exploration. Each wisp has their own personality, and a unique design to reflect this. There are eight wisps for each element to collect, making 72 total.

    1047633631_kzwdo.png.7f057e1bde3b875a487c746afed88ede.png

    On the overworld, wisps provide a variety of overworld skills you can swap between to affect the environment, such as destroying rubble with a fireball or lightning, or shifting from the real world into a mystic plane that might feature a secret path or new enemies.

    From the menu, you can equip wisps to each character. Each wisp provides a unique skill to it’s equipped party member, with this skill increasing in power for each wisp of that element that the party has befriended. This allows for additional character customization, and alters the wisps a character can call within battle. Obtaining new wisps is often tied to exploration and optional quests.

    In battle, Players and enemies can upon Wisps by using the skills granted by their equipped Wisps, after which they become active and float around the battlefield. If an attack or skill is used that matches the element of a Wisp stack, that stack acts as a damage multiplier, and all Wisps of that element are spent. 1 Wisp is x2, 2 is x4, 3 is x8, and 4 is x16. Additionally, passive abilities can provide bonuses based on the number of Wisps, and some powerful skills might have a Wisp cost to use at all. The player must be careful with stacking too many Wisps for a high multiplier, however, as enemies may also put and use Wisps on the field, they are a shared resource.

     

     

     

    coollogo_com-177653871.png.d5da093ca3bc6eb53038884dcc7874b1.png

    Spoiler

     

    WispAbilityWheel.PNG.61eead974afbc3bce3f60842fcdd1138.PNG

    The game has a strong emphasis on exploring the world, with most objects being interactable for flavor text and item discovery. The items will most often be useful as ingredients for potions, or potions themselves for use in battles, as well as equipment and quest items. Some of the more useful items would only be attainable beyond obstacles and puzzles to be removed or solved with Wisp Skills. Wisp Skills are overworld skills you can swap between to affect the environment, such as destroying rubble with a fireball or lightning, or shifting from the real world into a mystic plane that might feature a secret path or new enemies.

    Enemy groups roam around hostile areas and can have different roaming behaviors, and have awareness based on lighting in dark areas. Wisp Skills can be used to get their attention or avoid them, and when an enemy group is defeated, they are removed from the overworld. Players may choose to save or heal at a checkpoint, a Mana Crystal, however this will cause all enemies on the overworld reappear.

     

     

     

    coollogo_com-22994172.png.a867b90378c544fb0ebe7639245e2e89.png

    Spoiler

     

    BattleScreen.thumb.PNG.ed43b379d00566e1d2497e8c286e6b58.PNG

    Battles take place in a side-view CTB (Charge Turn Battle) system. Instead of choosing the whole party’s actions at the start of the turn, each party member chooses their action and immediately acts in order of their speed. A turn order ribbon is featured to determine who will be acting in the next several turns, and will display how much an action will move a player down the ribbon after they do their selected action.

    The player characters can attack, use skills, use items, view basic enemy information, attempt to flee, but the real stars are the Wisps. Both the party and their foes can call upon Wisps. If an attack or skill is used that matches the element of a Wisp stack, that stack acts as a damage multiplier, and all Wisps of that element are spent. Additionally, certain combinations can be used to perform powerful summons!  Some passive abilities can even provide bonuses based on the number of Wisps, while some powerful skills might have a Wisp cost to use at all. Be careful with stacking too many Wisps however, as your enemies may wise up to your plan, and use your plan against you!

    Weapons and armor both play a larger role in combat than what is usually seen in traditional JRPG combat. Instead of a static Attack command, every weapon has 1-3 weapon arts, skills unique to that weapon that cost no MP to use. Similarly, some other equipment such as shields and talismans can change the standard Guard command into something more specialized for the types of encounters you are currently facing.

     

     

     

    coollogo_com-10499230.png.e9e0be51f66f8560558843dd1fd2f182.png
     

    Spoiler

    In Calnern, there are several different humanoid races that you'll come across in your journeys, alongside several intelligent monster species. From the mole-like Moleders, to the sleek avian Tallus, you'll find that these different races each carry vastly different lifestyles, morals, beliefs, and more.

     

     

    coollogo_com-3247338.png.8805f778a3929a014acf92d03cd4c96d.png

    Spoiler

     

    pAf0yc.thumb.png.dbe0ca8d52bb5bb83bf1d6d2a6646f33.png

    Monsters aren’t just the baddies that dwell in caves and forests, they’re an integral part of the world and how it functions. Many types of monsters are kept as pets or companions, while others are domesticated to help perform tasks. Much of the world’s natural phenomena are dictated by monsters and their own unique abilities. Some are cute and friendly, others are a massive threat to nearby civilizations, and are treated as such. Others yet are even intelligent enough to communicate or barter with humans, and even have their own developed society. With over 400 unique monsters to discover, and a monster-fanatic leading the party, you’re bound to find some favorites, and stumble into many misadventures exploring just what makes this vibrant world of creatures so special.

     

     

     

    coollogo_com-177654031.png.3d0a5b3ace86b3896e037913fb4b24dc.png

    Spoiler

     

     

    You can find the full, updating playlist here.

     

     

     

     

     

    coollogo_com-15544702.png.196f4d38e80c7018e1878fe45f9a26c7.png

    Spoiler

     

    8RJ5DI.thumb.png.beb771859681bef5b922d4ce3962e305.png

    As opposed to simply offering an Easy/Medium/Hard difficulty option, players are able to fine-tune a variety of aspects of the game, allowing people to play through the game just how they like it, and allows for built in challenge modes. Some examples of adjustable parameters include buffing enemy stats, preventing the use of certain gameplay mechanics such as wisp calling or item use in battle, preventing healing in battle, raising or lowering gold and item drop rates, disabling level ups, and even a perma-death mode for those wishing to push their skills to the limit!

     

     

     

    coollogo_com-1812127.png.452ea8bbc2468ce3bc84cff698533ccc.png

    Spoiler

     

    J_hpQO.png.15e8d19e11a0788d3b2b252497df6fd0.png

    We also have a Discord set up for everyone that’s interested in helping out, or just wants to follow along with progress, so that we can all keep in touch easier. You can join us here: https://discord.gg/6sGtkR3

     

     

    CREDITS:

    Spoiler

    Mana Star
    PROJECT PERFECTION GAMES©

    Developers:
    Vis_Mage
    Melody

    Playtesters:
    Delort

    Graphics:
    Charlesthehurst
    Low
    Frozenfeather
    Celianna
    Amysaurous
    Moge-Moge-Kun
    Avery
    Whtdragon
    Kal Kally
    EB

    Music:
    Lead Composer:
    John David Young
    www.SoundCloud.com/jdyoung
    www.johndavidyoung.com 

    Contributing Composer:
    Elezeid

    Other Contributions:
    Eric Matyas (www.soundimage.org)
    Lucus King
    Derek & Brandon Fiechter
    Seii
    Red & Green
    Marcel Scheitza


    Writers:
    Tyra
    Baptista


    Pokemon RMN Contributers:
    Ratty524
    Bart_Sol
    JayjeAthravein
    Miracle
    Faenon
    Seiromem
    masterofmayhem
    giaks
    Byah
    micahdude9
    iddalai
    seacliff217
    mordenglory
    matthewac95
    Nerdybastard
    StarBlazor
    ShadowPrince89
    kentona
    jin69
    halibabica
    Jparker1984
    Desmo360
    Zeuzio
    Fomar0153
    orochii
    Blobofgoo

     

    Plugins:
    kylestclair
    Yanfly 
    Himeworks
    Victor Sant 
    Moghunter 
    Orb
    PandaMaru
    Neon Black 
    Syvkal 
    Archeia Nessiah
    Mithran
    Ocedic 
    V.M of D.T 
    Craze 
    Kread-EX
    Khas Arcthunder
    Modern Algebra
    Seiryuki 
    Zerbu 
    Kylock 
    ldida1
    Lunarea 
    Hanzo Kimura
    Adrian
    Hudell
    Venka
    Vektora
    CSEmber
    Caitlin
    Emberstorm Games
    Marcel Scheitza
    Aaron Krogh
    Tsarmina
    Bugs Roams Ur House
    Nana
    JESGRAD07
    Blake_Ezra
    Naehiro HP: CounterClockWise http://ccw.blog.shinobi.jp/
    Erisa
    Craig "Ritter" B.
    TSR - The Northern Frog
    Tria

     

    coollogo_com-220982168.png.9bc177ff1cb67c757d213969b35beb9a.png


  6. Hello!

     

    Would someone be able to help me out with a compatibility error between Shiggy's Multicurrency Plugin (requested below), and Yanfly's Core Engine (and to some degree Yanfly's Shop Core)?

     

    The issue between them is a little odd. With just those two plugins in a project together, there isn't a visible issue, but if you also have Yanfly's Shop Core, then when you attempt to buy or sell an item, the screen that shows you current gold/spending gold/remaining gold instead shows NaN (Not a Number) for the values. The reason that I believe the issue is with Yanfly's Core Engine is because if I only have Shiggy's plugin and Yanfly's Shop Core, this issue does not occur.

     

    I hope I explained this all well enough. If you're not sure what I mean by something, definitely feel free to ask.

     

    Thank you!


  7. Hello! :)

    Would someone be able to help me with setting up Triacontane's Submenu Commands plugin? Evenenwith google translate, I can't for the life of me figure out how I'm supposed to set things up.

     

    https://triacontane.blogspot.com/2017/04/blog-post.html?m=1#comment-form

     

    What I'm hoping to do is create a "parent" menu option named Journal. And when it is selected, a handful of "children" options such as Quest Log, Bestiary, and Help can be selected.

    At the moment though, I can't seem to get any menu commands I try to set up in the plugin configuration to show up on the menu at all. I'm guessing that I just haven't properly configured it, but after a few hours of trying, I haven't had any luck.

    Just as a note, I have been trying this in a fresh project, so no plugin incompatibilities to worry about.

     

    Thank you


  8. I've been working with Charles on many, many commissions over the course of the past two years, and all throughout, he has been very responsive, and has done consistently great work. I cannot recommend his service enough! 😊

    • Like 1

  9. Woah, sorry for the radio silence. Either I missed the notification that you had replied, or I hadn't got one. Sorry for leaving you in the dark. If you're still available, I've somewhat refined what I'm hoping to achieve, which might make it a bit easier.

     

    In the past month or so, I've made a few changes in the script, so I'll provide the newest version. Hopefully this one works for you, but if not, I could put together a little demo project.

     

    Spoiler
    
    #==============================================================================
    # ** Victor Engine - Materia System
    #------------------------------------------------------------------------------
    # Author : Victor Sant
    #
    # Aditional Credit :
    #   - Tamsynn/Apoclaydon (Commission requester)
    #
    # Version History:
    #  v 1.00 - 2012.11.01 > First relase
    #  v 1.01 - 2013.01.05 > Fixed Added Effect and Elemental Materia
    #  v 1.02 - 2013.02.13 > Compatibility with Passive States
    #------------------------------------------------------------------------------
    #  This script replicate the Materia system from FFVII. You can attch
    # 'materias' on the actor equipment to gain skills, status boost and varied
    # special effects.
    #------------------------------------------------------------------------------
    # Compatibility
    #   Requires the script 'Victor Engine - Basic Module' v 1.29 or higher
    #   If used with 'Victor Engine - Target Arrow' place this bellow it.
    #
    # * Overwrite methods
    #   class Window_MenuActor < Window_MenuStatus
    #     def select_for_item(item, for_all = false)
    #
    #   class Scene_ItemBase < Scene_MenuBase
    #     def determine_item
    #     def item_target_actors
    #
    # * Alias methods
    #   class << BattleManager
    #     def display_exp
    #
    #   class Game_Temp
    #     def initialize
    #
    #   class Game_Action
    #     def targets_for_opponents
    #     def targets_for_friends
    #
    #   class Game_BattlerBase
    #     def skill_mp_cost(skill)
    #     def skill_conditions_met?(skill)
    #
    #   class Game_Battler < Game_BattlerBase
    #     def use_item(item)
    #     def item_apply(user, item)
    #     def make_damage_value(user, item)
    #     def apply_guard(damage)
    #
    #   class Game_Actor < Game_Battler
    #     def setup(actor_id)
    #     def skills
    #     def param(param_id)
    #     def param_plus(param_id)
    #     def param_rate(param_id)
    #     def xparam(param_id)
    #     def sparam(param_id)
    #     def element_rate(id)
    #     def state_rate(id)
    #     def atk_elements
    #     def atk_states
    #     def atk_states_rate(id)
    #     def feature_objects
    #
    #   class Game_Party < Game_Unit
    #     def init_all_items
    #     def gain_item(item, amount, include_equip = false)
    #
    #   class Game_Interpreter
    #     def command_319
    #     def command_302
    #     def comment_call
    #
    #   class Window_MenuCommand < Window_Command
    #     def add_main_commands
    #
    #   class Window_SkillList < Window_Selectable
    #     def draw_skill_cost(rect, skill)
    #
    #   class Window_BattleLog < Window_Selectable
    #     def display_failure(target, item)
    #
    #   class Scene_Menu < Scene_MenuBase
    #     def create_command_window
    #     def on_personal_ok
    #
    #   class Scene_Equip < Scene_MenuBase
    #     def on_actor_change
    #
    #   class Scene_Battle < Scene_Base
    #     def on_skill_ok
    #     def battle_start
    #     def pre_terminate
    #
    #------------------------------------------------------------------------------
    # Instructions:
    #  To instal the script, open you script editor and paste this script on
    #  a new section bellow the Materials section. This script must also
    #  be bellow the script 'Victor Engine - Basic'
    #
    #------------------------------------------------------------------------------
    # Comment calls note tags:
    #  Tags to be used on the events comment box, works like a script call
    #
    #  <materia shop>
    #   Place this before calling the shop event command for materias
    #  
    #  <equip materia: actor, equip, slot, materia>
    #   Adds a materia on a specific slot of one actor.
    #     actor   : actor ID
    #     equip   : equip slot
    #     slot    : materia slot
    #     materia : materia ID
    #
    #  <unequip materia: actor, equip, slot>
    #   Remove the materia equiped on a specific slot of one actor.
    #     actor : actor id
    #     equip : equip slot
    #     slot  : materia slot
    #
    #  <drop materia: id, amount>
    #   Remove one materia with the selected id
    #     id     : materia id
    #     amount : amount removed
    #
    #------------------------------------------------------------------------------
    # Enemies note tags:
    #   Tags to be used on Enemies note boxes.
    #
    #  <ap: x>
    #   Ap given by the enemy upon defeat. If not set the value is equal the enemy
    #   EXP / 10
    #     x : Ap value
    #
    #------------------------------------------------------------------------------
    # Skills note tags:
    #   Tags to be used on the Skills note box in the database.
    #
    #  <negate cost>
    #   The skill will ignore the effects "Mp Cost: +x%" and "Mp Cost: -x%"
    #
    #  <negate damage>
    #   The skill will ignore the effects "Damage: +x%" and "Damage: -x%"
    #
    #  <negate absorb>
    #   The skill will ignore the effects "HP Absorb: x%" and "MP Absorb: x%"
    #
    #  <negate all>
    #   The skill will ignore the effects "All"
    #
    #------------------------------------------------------------------------------
    # Armors (Non-Materia) note tags:
    #   Tags to be used on the Weapons and non-materia Armors note box in the
    #   database. (Only for Armors tagged as Materia)
    # 
    #  <materia slots: slots>
    #   Setup the materia slots.
    #     slots : slots setup, you must add a 0 for each slot, slots can be linked
    #             using =. Correct White spacing is very important for the setup.
    #     Ex.: <materia slots: 0 0 0>     # Materia with 3 single slots
    #          <materia slots: 0=0 0=0 0> # Materia with 2 paired slots and 1 single
    #
    #  <materia growth: x>
    #   Materia growth multiplier for materias equiped on this equip.
    #     x : muliplier, can be decimal.
    #     Obs.: Equiment with growth 0 will use a diffetent icon for the slots
    #
    #------------------------------------------------------------------------------
    # Armors (Materia) note tags:
    #   Tags to be used on the Armors note box in the database. (Only for Armors
    #   tagged as Materia)
    #
    #  <materia type: x>
    #   This tag define the armor as a materia. 
    #     x : type. Can be either Support, Independet or Magic
    #        Support     : materias that can have special effects when paired
    #        Magic       : materias that receive bonus when paired with support
    #        Independent : materias that don't gain any bonus for being paired
    #
    #  <ap list: x>
    #  <ap list: x, x>
    #   The list of AP needed for the materia to level up. This also set the
    #   materia max level. Each value added increase the max level by 1.
    #     x : AP for next level
    #
    #  <level icon: x>
    #   Setup the icon that will be used to represent the level of the materia
    #     x : icon index
    #
    #  <master value: x>
    #   Price that the materia can be sold when reach the max level (master)
    #     x : price
    #
    #  <limited use>
    #   Materias with this tag can be used one time for each level per battle
    #
    #  <stats: stat: +x%>              <stats: stat: -x%>
    #  <stats: stat: +x%, stat: +x%>   <stats: stat: -x%, stat: -x%>
    #   Setup % change values for the stats. These values don't change with materia
    #   level
    #     stat : stat name (HP, MP, Atk, Def, Mat, Mdf, Agi, Luk)
    #     x    : value change
    #
    #  <elements: x>
    #  <elements: x, x>
    #   Tag elements for the materia, these elements have effect when the materia
    #   is paired with support materia with "Elemental" effect
    #     x : elements IDs
    #
    #  <states: x>
    #  <states: x, x>
    #   Tag statea for the materia, these states have effect when the materia
    #   is paired with support materia with "Added Effect" effect
    #     x : states IDs
    #
    #  <effect name: x>
    #   By default, the materia info display a list of values for the materia 
    #   effects, using this tag you can use a custom name for info display
    #     x : effect name
    #
    #  <skills: level: x>
    #  <skills: level: x, level: x>
    #   skills granted by the materia.
    #     level : level that the materia must be to grant the skill
    #     x     : skill id
    #
    #  <effects: x>  
    #  <effects: x, x>
    #   This tag allows to add special effects for the materia. These effects
    #   vary a lot, and some are based on the materia level.
    #     x : effect
    #      Stat: +x%   : Increase a param, sparam or xparam by x% for each level
    #      Stat: -x%   : Decrease a param, sparam or xparam by x% for each level
    #      Damage: +x% : Increase skill damage x% for each level
    #      Damage: -x% : Decrease skill damage x% for each level
    #      Hp Mp       : Invert the HP and MP values
    #      Enemy Skill : Change the materia setup to use "Enemy Skill"
    #
    #    - Only for Support materia, affects paired materia skills
    #      Mp Cost: +x%   : Increase Mp Cost for x% for each level
    #      Mp Cost: -x%   : Decrease Mp Cost for x% for each level
    #      Hp Absorb: x%  : Absorb Hp x% of the damage dealt for each level
    #      Mp Absorb: x%  : Absorb Mp x% of the damage dealt for each level
    #      All            : Skill affect all targets per use for each level
    #      Elemental: +x% : Increase element resistance by x% for each level
    #      Elemental: -x% : Decrease element resistance by x% for each level
    #      Added Effect: +x% : Increase state effect by x% for each level
    #      Added Effect: -x% : Decrease state effect by x% for each level
    #
    #------------------------------------------------------------------------------
    # Additional instructions:
    #
    #  Materias are setup using Armors slots from the database, all stats bonus
    #  and traits you setup on the armor that will be used as a materia works
    #  normally.
    #
    #  The first step to setup the materia is to define it's tipe with the
    #  tag <materia type: x>, the main difference between each type is how
    #  they interact with paired slots. The types are Magic, Support and
    #  Independent
    #  There's no Summon or Command types, since mechanically both works like
    #  magic materias.
    #   
    #  The tag <stats: stat: +x%> <stats: stat: -x%> allows you to setup % changes
    #  on the status. Fixed values can be set on the database itself.
    #
    #  Elements set with the tag <elements: x> have effect when paired with 
    #  support materias with the 'Elemental' effect. The effect will change
    #  depending on the equipment that the pair is set. If it's on a weapon
    #  the attacks will gain elemental damage, if it's on a armor the actor
    #  will gain elemental resistance based on the materia level.
    #
    #  States set with the <states: x> works like the elements: when added to
    #  a weapon, the attacks will gain a chance of inflicting the state, when
    #  added to armors, it will change the state resist.
    #
    #  Materias can grant skills using the tag <skills: level: x> based on the
    #  current materia level. The skills becomes avaiable as soon the materia
    #  reach the min level needed, and are removed if the materia is removed.
    #
    #  The effects <effects: x> is the most complex settings, it's have a high
    #  number of possible effects. 
    #  The Stat: +x% and Stat: -x% effects allows to add any param, sparam or
    #  xparam. The value is based on the materia level.
    #  so if you setup a effect CNT: +10% and the materia is at level 3, the
    #  actor will gain 30% counter attack rate.
    #  Some effects works only with paired support materias.
    #
    #  The Enemy Skill Effect is a very special effect. A materia with this effect
    #  allows the actor to learn the skills when hit by one of the skills that
    #  this materia can give. The materia don't level up with AP, but instead
    #  gain 1 level for each skill learned. When setting up the skills, you
    #  still need to add a level for them, but the values are arbritary and
    #  is used only to sort the skills.
    #
    #  You can edit the materia related texts on the module Vocab withing the script
    #
    #------------------------------------------------------------------------------
    # Examples:
    #
    # Fire
    #  <materia type: Magic>
    #  <level icon: 547>
    #  <master value: 42000>
    #  <elements: 3>
    #  <ap list: 2000, 18000, 35000>
    #  <stats: hp: -2%, mp: +2%>
    #  <skills: 1: 51, 2: 53, 3: 52, 4: 54>
    #
    # MP Turbo
    #  <materia type: Support>
    #  <level icon: 550>
    #  <master value: 1>
    #  <effect name: MP Turbo>
    #  <effects: MP Cost: +10%, Damage: +10%>
    #  <ap list: 10000, 30000, 60000, 120000>
    #
    # Enemy Skill
    #  <materia type: Command>
    #  <level icon: 548>
    #  <master value: 1>
    #  <effects: Enemy Skill>
    #  <skills: 1: 8, 2: 9, 3: 10, 4: 11, 5: 12, 6: 13, 7: 14, 8: 15,
    #  9: 16, 10: 17, 11: 18, 12: 19, 13: 20, 14: 21, 15: 22, 16: 23>
    #
    #==============================================================================
    
    #==============================================================================
    # ** Victor Engine
    #------------------------------------------------------------------------------
    #   Setting module for the Victor Engine
    #==============================================================================
    
    module Victor_Engine
      #--------------------------------------------------------------------------
      # * Max materia number
      #   The max ammount of materias that the player can keep, leave nil for
      #   no limit. Be aware that if the player have 300 or more materia 
      #   there might be freezes when opening the materia menus
      #--------------------------------------------------------------------------
      Max_Materia_Number = 255
      #--------------------------------------------------------------------------
      # * Max slot number
      #   Max number of slots for equipment
      #--------------------------------------------------------------------------
      Max_Slot_Number    = 8
      #--------------------------------------------------------------------------
      # * Materia Brreding
      #   If true the player will gain a new level 1 materia when a materia
      #   reach the max level
      #--------------------------------------------------------------------------
      Materia_Breeding  = false
      #--------------------------------------------------------------------------
      # * Icons setup
      #   Default icons for materia slots
      #--------------------------------------------------------------------------
      Slot_Icon_Normal   = 6927
      Slot_Icon_Nothing  = 0
      Slot_Link_Icon     = 592
      Materia_Level_Icon = 6025
      #--------------------------------------------------------------------------
      # * required
      #   This method checks for the existance of the basic module and other
      #   VE scripts required for this script to work, don't edit this
      #--------------------------------------------------------------------------
      def self.required(name, req, version, type = nil)
        if !$imported[:ve_basic_module]
          msg = "The script '%s' requires the script\n"
          msg += "'VE - Basic Module' v%s or higher above it to work properly\n"
          msg += "Go to http://victorenginescripts.wordpress.com/ to download this script."
          msgbox(sprintf(msg, self.script_name(name), version))
          exit
        else
          self.required_script(name, req, version, type)
        end
      end
      #--------------------------------------------------------------------------
      # * script_name
      #   Get the script name base on the imported value
      #--------------------------------------------------------------------------
      def self.script_name(name, ext = "VE")
        name = name.to_s.gsub("_", " ").upcase.split
        name.collect! {|char| char == ext ? "#{char} -" : char.capitalize }
        name.join(" ")
      end
    end
    
    $imported ||= {}
    $imported[:ve_materia_system] = 1.02
    Victor_Engine.required(:ve_materia_system, :ve_basic_module, 1.29, :above)
    
    #==============================================================================
    # ** Vocab
    #------------------------------------------------------------------------------
    #  This module defines terms and messages. It defines some data as constant
    # variables. Terms in the database are obtained from $data_system.
    #==============================================================================
    
    module Vocab
    
      # Materia menu options
      VE_MateriaMenu = "Wisps"
      
      # Message displayed when learning Enemies Skills
      VE_EnemySkill  = "%s learend %s"
      
      # AP stat name
      VE_ApName      = "AP"
      
      # AP received message on battle end
      VE_ApReceived  = "%s AP received!"
      
      # Max level materia text
      VE_MasterText  = "Mastered!"
      
    end
    
    #==============================================================================
    # ** RPG::Skill
    #------------------------------------------------------------------------------
    #  This is the data class for skills.
    #==============================================================================
    
    class RPG::Skill < RPG::UsableItem
      #--------------------------------------------------------------------------
      # * New method: cost?
      #--------------------------------------------------------------------------
      def cost?(id)
        @id == id && !(note =~ /<NEGATE COST>/i)
      end 
      #--------------------------------------------------------------------------
      # * New method: damage?
      #--------------------------------------------------------------------------
      def damage?(id)
        @id == id && !(note =~ /<NEGATE DAMAGE>/i)
      end 
      #--------------------------------------------------------------------------
      # * New method: absorb?
      #--------------------------------------------------------------------------
      def absorb?(id)
        @id == id && !(note =~ /<NEGATE ABSORB>/i)
      end
      #--------------------------------------------------------------------------
      # * New method: all?
      #--------------------------------------------------------------------------
      def all?
        for_one? && !(note =~ /<NEGATE ALL>/i)
      end
    end
    
    #==============================================================================
    # ** RPG::UsableItem
    #------------------------------------------------------------------------------
    #  This is the superclass for skills and items.
    #==============================================================================
    
    class RPG::UsableItem < RPG::BaseItem
      #--------------------------------------------------------------------------
      # * New method: all?
      #--------------------------------------------------------------------------
      def all?
        return false
      end
      #--------------------------------------------------------------------------
      # * New method: materia?
      #--------------------------------------------------------------------------
      def materia?
        return false
      end
    end
    
    #==============================================================================
    # ** RPG::EquipItem
    #------------------------------------------------------------------------------
    #  This is the superclass of weapons and armor.
    #==============================================================================
    
    class RPG::EquipItem < RPG::BaseItem
      #--------------------------------------------------------------------------
      # * New method: materia?
      #--------------------------------------------------------------------------
      def materia?
        return false
      end
      #--------------------------------------------------------------------------
      # * New method: growth
      #--------------------------------------------------------------------------
      def growth
        return @growth if @growth
        @growth = note =~ /<MATERIA GROWTH: (\d+)>/i ? $1.to_f : 1
      end
      #--------------------------------------------------------------------------
      # * New method: nothing?
      #--------------------------------------------------------------------------
      def nothing?
        growth == 0
      end
      #--------------------------------------------------------------------------
      # * New method: double_slots
      #--------------------------------------------------------------------------
      def double_slots
        return @double_slots if @double_slots
        list = note =~ /<MATERIA SLOTS: ([ 0o=]*)>/i ? $1.dup : ""
        @double_slots = list.scan(/[0o]=[0o]/i).size * 2
      end
      #--------------------------------------------------------------------------
      # * New method: single_slots
      #--------------------------------------------------------------------------
      def single_slots
        return @single_slots if @single_slots
    list   = note =~ /<MATERIA SLOTS: ([ 0o=]*)>/i ? $1.dup : ""
    @single_slots = [list.scan(/[0o]/i).size - double_slots,3].max
    #$# @single_slots = list.scan(/[0o]/i).size - double_slots 
    # Edited to give ALL weapons a min of 3 wisp equip slots. 
    # Can be overwritten just fine with a note tag.
    # Does NOT require either scriptlet, if not using Vlue unique item script.
      end
      #--------------------------------------------------------------------------
      # * New method: slots
      #--------------------------------------------------------------------------
      def slots
        double_slots + single_slots
      end
    end
    
    #==============================================================================
    # ** RPG::Armor
    #------------------------------------------------------------------------------
    #  The data class for armor.
    #==============================================================================
    
    class RPG::Armor < RPG::EquipItem
      #--------------------------------------------------------------------------
      # * Public Instance Variables
      #--------------------------------------------------------------------------
      attr_accessor :ap
      attr_accessor :times
      attr_accessor :limit
      attr_reader   :type
      attr_reader   :stats
      attr_reader   :learn
      attr_reader   :skills
      attr_reader   :states
      attr_reader   :master
      attr_reader   :elements
      attr_reader   :effects
      #--------------------------------------------------------------------------
      # * New method: materia?
      #--------------------------------------------------------------------------
      def materia?
        note =~ /<MATERIA TYPE: (\w+)>/i
      end
      #--------------------------------------------------------------------------
      # * New method: setup_materia
      #--------------------------------------------------------------------------
      def setup_materia
        setup_base
        setup_type
        setup_name
        setup_price
        setup_stats
        setup_skills
        setup_states
        setup_elements
        setup_effects
        setup_limit
        self
      end
      #--------------------------------------------------------------------------
      # * New method: setup_base
      #--------------------------------------------------------------------------
      def setup_base
        @ap    ||= $game_variables[198] #@# AP Gain VAR
        @times ||= 1
        @level ||= 0
        @learn ||= {}
        @ap_list = setup_lists("AP LIST", [0])
      end
      #--------------------------------------------------------------------------
      # * New method: setup_states
      #--------------------------------------------------------------------------
      def setup_states
        @states = setup_lists("STATES")
      end
      #--------------------------------------------------------------------------
      # * New method: setup_elements
      #--------------------------------------------------------------------------
      def setup_elements
        @elements = setup_lists("ELEMENTS") 
      end
      #--------------------------------------------------------------------------
      # * New method: setup_type
      #--------------------------------------------------------------------------
      def setup_type
        @type = note =~ /<MATERIA TYPE: (\w+)>/i ? $1.upcase : "MAGIC"
      end
      #--------------------------------------------------------------------------
      # * New method: setup_name
      #--------------------------------------------------------------------------
      def setup_name
        @effect_name = note =~ /<EFFECT NAME: ([\w\s.,;]+)>/i ? $1.to_s : nil
      end
      #--------------------------------------------------------------------------
      # * New method: setup_price
      #--------------------------------------------------------------------------
      def setup_price
        @master = note =~ /<MASTER VALUE: (\d+)>/i ? $1.to_i : price * 10
      end
      #--------------------------------------------------------------------------
      # * New method: setup_limit
      #--------------------------------------------------------------------------
      def setup_limit
        @limited = note =~ /<LIMITED USE>/i ? true : false
        @limit   = {}
        @skills.values.each {|i| @limit[i] = level }
      end
      #--------------------------------------------------------------------------
      # * New method: setup_stats
      #--------------------------------------------------------------------------
      def setup_stats
        @stats = {}
        values = note =~ /<STATS:\s([\w\s\+\-:%,;]+)>/i ? $1.dup : ""
        regexp = /(\w+):\s*([+-]?\d+)%/i
        values.scan(regexp).each {|x, y| @stats[get_param_id(x)] = y.to_i }
      end
      #--------------------------------------------------------------------------
      # * New method: setup_skills
      #--------------------------------------------------------------------------
      def setup_skills
        @skills = {}
        values  = note =~ /<SKILLS:\s([\d\s\:,;]+)>/i ? $1.dup : ""
        values.scan(/(\d+):\s*(\d+)/i).each {|x, y| @skills[x.to_i] = y.to_i }
      end
      #--------------------------------------------------------------------------
      # * New method: setup_effects
      #--------------------------------------------------------------------------
      def setup_effects
        values   = note =~ /<EFFECTS:\s([\w\s\+\-:%,;]+)>/i ? $1.dup : ""
        @effects = values.scan(/[\w\s\+\-\:\%]*/i).inject({}) do |r, i|
          if i =~ /([\w\s]+)(?:: *([+-]?\d+)%?)?/i
            r[make_symbol($1)] = $2 ? $2.to_i / 100.0 : true
          end
          r
        end
        @effects.default = 0
      end
      #--------------------------------------------------------------------------
      # * New method: elements?
      #--------------------------------------------------------------------------
      def setup_lists(type, base = [])
        values = note =~ /<#{type}: ([\d\s;,]+)>/i ? $1.dup : ""
        values.scan(/\d+/i).inject(base) { |r, i| r.push(i.to_i) }
      end
      #--------------------------------------------------------------------------
      # * New method: 
      #--------------------------------------------------------------------------
      def elements?(elements)
        @elements.include?(elements)
      end
      #--------------------------------------------------------------------------
      # * New method: states?
      #--------------------------------------------------------------------------
      def states?(states)
        @states.include?(states)
      end
      #--------------------------------------------------------------------------
      # * New method: effect?
      #--------------------------------------------------------------------------
      def effect?(effect)
        @effects.keys.include?(effect)
      end
      #--------------------------------------------------------------------------
      # * New method: effect
      #--------------------------------------------------------------------------
      def effect(value)
        @effects[value]
      end
      #--------------------------------------------------------------------------
      # * New method: ap=     
      #--------------------------------------------------------------------------
      def ap=(n)
        @ap = [n, @ap_list.last].min
      end
      #--------------------------------------------------------------------------
      # * New method: level
      #--------------------------------------------------------------------------
      def level
        max_level.times {|i| break @level += 1 if level_up? }
        enemy_skill? ? @learn.values.size : @level
      end
      #--------------------------------------------------------------------------
      # * New method: max_level
      #--------------------------------------------------------------------------
      def max_level
        enemy_skill? ? @skills.size : @ap_list.size
      end
      #--------------------------------------------------------------------------
      # * New method: level_up?
      #--------------------------------------------------------------------------
      def level_up?
        @ap >= next_level && @level < max_level
      end
      #--------------------------------------------------------------------------
      # * New method: master?
      #--------------------------------------------------------------------------
      def master?
        level == max_level
      end
      #--------------------------------------------------------------------------
      # * New method: next_level
      #--------------------------------------------------------------------------
      def next_level
        @level.times.inject([0]) {|r, i| r + [@ap_list[i + 1]] }.sum
      end
      #--------------------------------------------------------------------------
      # * New method: stat
      #--------------------------------------------------------------------------
      def stat(i)
        @stats[i] ? @stats[i] : 0
      end
      #--------------------------------------------------------------------------
      # * New method: reset_times
      #--------------------------------------------------------------------------
      def reset_times
        @times = level
        setup_limit
      end
      #--------------------------------------------------------------------------
      # * New method: sell_price
      #--------------------------------------------------------------------------
      def sell_price
        base = (price / 2)
        var  = @master - base
        rate = [@ap * 100 / [@ap_list.sum, 1].max, 100].min
        @master <= price ? @master : [((var * rate) / 100) + base, 0].max
      end
      #--------------------------------------------------------------------------
      # * New method: gain_ap
      #--------------------------------------------------------------------------
      def gain_ap(n, growth)
        old_level = level
        @ap += (n * growth).to_i
        if Materia_Breeding && old_level < max_level && level == max_level
          $game_party.gain_materia($data_armors[@id])
        end
      end
      #--------------------------------------------------------------------------
      # * New method: level_icon
      #--------------------------------------------------------------------------
      def level_icon
        note =~ /<LEVEL ICON: (\d+)>/i ? $1.to_i : Materia_Level_Icon
      end
      #--------------------------------------------------------------------------
      # * New method: level_value
      #--------------------------------------------------------------------------
      def level_value(value)
        level * effect(value)
      end
      #--------------------------------------------------------------------------
      # * New method: support?
      #--------------------------------------------------------------------------
      def support?
        @type == "SUPPORT"
      end
      #--------------------------------------------------------------------------
      # * New method: independent?
      #--------------------------------------------------------------------------
      def independent?
        @type == "INDEPENDENT"
      end
      #--------------------------------------------------------------------------
      # * New method: effect_name
      #--------------------------------------------------------------------------
      def effect_name
        @effect_name
      end
      #--------------------------------------------------------------------------
      # * New method: cost?
      #--------------------------------------------------------------------------
      def cost?(skill)
        !support? && skill?(skill) && effect?(:mp_cost)
      end
      #--------------------------------------------------------------------------
      # * New method: damage?
      #--------------------------------------------------------------------------
      def damage?(skill)
        !support? && skill?(skill) && effect?(:damage)
      end
      #--------------------------------------------------------------------------
      # * New method: skill?
      #--------------------------------------------------------------------------
      def skill?(id)
        @skills.values.include?(id)
      end
      #--------------------------------------------------------------------------
      # * New method: all?
      #--------------------------------------------------------------------------
      def all?
        effect?(:all) && @times > 0
      end
      #--------------------------------------------------------------------------
      # * New method: enemy_skill?
      #--------------------------------------------------------------------------
      def enemy_skill?
        effect?(:enemy_skill)
      end
      #--------------------------------------------------------------------------
      # * New method: on_limit?
      #--------------------------------------------------------------------------
      def on_limit?(id)
        !limited? || (@limit[id] && @limit[id] > 0)
      end
      #--------------------------------------------------------------------------
      # * New method: limited?
      #--------------------------------------------------------------------------
      def limited?
        @limited
      end
      #--------------------------------------------------------------------------
      # * New method: learn_enemy_skill
      #--------------------------------------------------------------------------
      def learn_enemy_skill(id)
        if skill?(id) && !@learn.values.include?(id)
          @skills.keys.each {|i| @learn[i] = @skills[i] if @skills[i] == id }
        end
      end
      #--------------------------------------------------------------------------
      # * New method: learned_enemy_skill?
      #--------------------------------------------------------------------------
      def learned_enemy_skill?(id)
        @learn.values.include?(id)
      end
    end
    
    #==============================================================================
    # ** BattleManager
    #------------------------------------------------------------------------------
    #  This module manages battle progress.
    #==============================================================================
    
    class << BattleManager
      #--------------------------------------------------------------------------
      # * Alias method: display_exp
      #--------------------------------------------------------------------------
      alias :display_exp_ve_materia_system :display_exp
      def display_exp
        display_exp_ve_materia_system
        display_ap
      end
      #--------------------------------------------------------------------------
      # * New method: display_ap
      #--------------------------------------------------------------------------
      def display_ap
        return if $game_troop.ap_total == 0
        text = sprintf(Vocab::VE_ApReceived, $game_troop.ap_total)
        $game_message.add('\.' + text)
        $game_party.all_members.each {|actor| actor.ap += $game_troop.ap_total }
      end
    end
    
    #==============================================================================
    # ** Game_Temp
    #------------------------------------------------------------------------------
    #  This class handles temporary data that is not included with save data.
    # The instance of this class is referenced by $game_temp.
    #==============================================================================
    
    class Game_Temp
      #--------------------------------------------------------------------------
      # * Public Instance Variables
      #--------------------------------------------------------------------------
      attr_accessor :materia_shop
      #--------------------------------------------------------------------------
      # * Alias method: initialize
      #--------------------------------------------------------------------------
      alias :initialize_ve_materia_system :initialize
      def initialize
        initialize_ve_materia_system
        @materia_shop = false
      end
    end
    
    #==============================================================================
    # ** Game_Action
    #------------------------------------------------------------------------------
    #  This class handles battle actions. This class is used within the
    # Game_Battler class.
    #==============================================================================
    
    class Game_Action
      #--------------------------------------------------------------------------
      # * Alias method: targets_for_opponents
      #--------------------------------------------------------------------------
      alias :targets_for_opponents_ve_materia_system :targets_for_opponents
      def targets_for_opponents
        if @subject.actor? && item.all? && for_all?(item)
          return opponents_unit.alive_members
        end
        targets_for_opponents_ve_materia_system
      end
      #--------------------------------------------------------------------------
      # * Alias method: targets_for_friends
      #--------------------------------------------------------------------------
      alias :targets_for_friends_ve_materia_system :targets_for_friends
      def targets_for_friends
        if @subject.actor? && item.all? && for_all?(item)
          return friends_unit.alive_members if item.for_friend?
          return friends_unit.dead_members  if item.fitem.for_dead_friend?
        end
        targets_for_friends_ve_materia_system
      end
      #--------------------------------------------------------------------------
      # * New method: for_all?
      #--------------------------------------------------------------------------
      def for_all?(item)
        @subject.paired_materia.each do |pair|
          if pair[:main].all? && pair[:other].skill?(item.id)
            pair[:main].times -= 1
            return true
          end
        end
        return false    
      end
    end
    
    #==============================================================================
    # ** Game_BattlerBase
    #------------------------------------------------------------------------------
    #  This class handles battlers. It's used as a superclass of the Game_Battler
    # classes.
    #==============================================================================
    
    class Game_BattlerBase
      #--------------------------------------------------------------------------
      # * Alias method: skill_mp_cost
      #--------------------------------------------------------------------------
      alias :skill_mp_cost_ve_materia_system :skill_mp_cost
      def skill_mp_cost(skill)
        cost = skill_mp_cost_ve_materia_system(skill)
        cost += cost_change_materia(skill, cost, :plus) if actor?
        cost -= cost_change_materia(skill, cost, :cut)  if actor?
        cost.to_i
      end
      #--------------------------------------------------------------------------
      # * Alias method: skill_conditions_met?
      #--------------------------------------------------------------------------
      alias :skill_conditions_met_ve_materia_system? :skill_conditions_met?
      def skill_conditions_met?(skill)
        skill_conditions_met_ve_materia_system?(skill) &&
        materia_conditions_met?(skill.id)
      end
      #--------------------------------------------------------------------------
      # * New method: cost_change_materia
      #--------------------------------------------------------------------------
      def cost_change_materia(skill, cost, type)
        list = paired_materia.inject([0]) do |r, pair|
          m  = pair[:main]
          o  = pair[:other]
          r + [pair_change_cost(m, o, cost, skill.id, type)]
        end
        list.max
      end
      #--------------------------------------------------------------------------
      # * New method: pair_change_cost
      #--------------------------------------------------------------------------
      def pair_change_cost(m, o, cost, id, type)
        return 0 unless m.effect?(:mp_cost)
        list = o.skills.values.inject([0]) do |r, i|
          value = m.level_value(:mp_cost).abs
          r + (id == i && valid_cost_type?(value, type) ? [value] : [])
        end
        cost * list.compact.max
      end
      #--------------------------------------------------------------------------
      # * New method: valid_cost_type?
      #--------------------------------------------------------------------------
      def valid_cost_type?(value, type)
        value > 0 && type == :plus || value < 0 && type == :cut
      end
      #--------------------------------------------------------------------------
      # * New method: materia_conditions_met?
      #--------------------------------------------------------------------------
      def materia_conditions_met?(id)
        return true
      end
    end
    
    #==============================================================================
    # ** Game_Battler
    #------------------------------------------------------------------------------
    #  This class deals with battlers. It's used as a superclass of the Game_Actor
    # and Game_Enemy classes.
    #==============================================================================
    
    class Game_Battler < Game_BattlerBase
      #--------------------------------------------------------------------------
      # * Alias method: use_item
      #--------------------------------------------------------------------------
      alias :use_item_ve_materia_system :use_item
      def use_item(item)
        materia_use_item(item.id) if actor? && item.is_a?(RPG::Skill)
        use_item_ve_materia_system(item)
      end
      #--------------------------------------------------------------------------
      # * Alias method: item_apply
      #--------------------------------------------------------------------------
      alias :item_apply_ve_materia_system :item_apply
      def item_apply(user, item)
        learn_enemy_skill(item.id) if actor?
        item_apply_ve_materia_system(user, item)
      end
      #--------------------------------------------------------------------------
      # * Alias method: make_damage_value
      #--------------------------------------------------------------------------
      alias :make_damage_value_ve_materia_system :make_damage_value
      def make_damage_value(user, item)
        @materia_user = user
        make_damage_value_ve_materia_system(user, item)
      end
      #--------------------------------------------------------------------------
      # * Alias method: apply_guard
      #--------------------------------------------------------------------------
      alias :apply_guard_ve_materia_system :apply_guard
      def apply_guard(damage)
        result = apply_guard_ve_materia_system(damage)
        @materia_user.actor? ? materia_damage(@materia_user, result) : result
      end
      #--------------------------------------------------------------------------
      # * New method: materia_use_item
      #--------------------------------------------------------------------------
      def materia_use_item(id)
        all_materias.each {|m| m.limit[id] -= 1 if m.limited? && m.on_limit?(id) }
      end
      #--------------------------------------------------------------------------
      # * New method: learn_enemy_skill
      #--------------------------------------------------------------------------
      def learn_enemy_skill(id)
        all_materias.each do |m|
          if m.enemy_skill? && m.skill?(id) && !m.learned_enemy_skill?(id)
            @learned_enemy_skill = id
            m.learn_enemy_skill(id)
            update_materia_skills
          end
        end
      end
      #--------------------------------------------------------------------------
      # * New method: materia_damage
      #--------------------------------------------------------------------------
      def materia_damage(user, damage)
        obj = user.current_action ? user.current_action.item : nil
        return damage if damage == 0 || !obj || !obj.is_a?(RPG::Skill)
        damage += damage_plus(damage, user, obj)
        damage += damage_pair(damage, user, obj)
        materia_absorb(damage, user, obj)
        damage.to_i
      end
      #--------------------------------------------------------------------------
      # * New method: damage_plus
      #--------------------------------------------------------------------------
      def damage_plus(damage, user, skill)
        user.all_materias.inject(0) do |r, m|
          r + (m.damage?(skill.id) ? (damage * m.level_value(:damage)).to_i : 0)
        end
      end
      #--------------------------------------------------------------------------
      # * New method: damage_pair
      #--------------------------------------------------------------------------
      def damage_pair(damage, user, skill)
        user.paired_materia.inject(0) do |r, pair|
          m = pair[:main]
          o = pair[:other]
          r + (m.effect?(:damage) ? pair_damage(m, o, damage, skill.id) : 0)
        end
      end
      #--------------------------------------------------------------------------
      # * New method: pair_damage
      #--------------------------------------------------------------------------
      def pair_damage(m, o, damage, id)
        o.skills.values.compact.inject(0) do |r, i|
          mskill = $data_skills[i]
          r + (mskill.damage?(id) ? (damage * m.level_value(:damage)).to_i : 0)
        end
      end
      #--------------------------------------------------------------------------
      # * New method: materia_absorb
      #--------------------------------------------------------------------------
      def materia_absorb(damage, user, skill)
        user.paired_materia.each do |pair|
          m = pair[:main]
          o = pair[:other]
          pair_absorb(user, m, o, damage, skill, "HP")
          pair_absorb(user, m, o, damage, skill, "MP")
        end
      end
      #--------------------------------------------------------------------------
      # * New method: pair_absorb
      #--------------------------------------------------------------------------
      def pair_absorb(user, m, o, damage, skill, type)
        o.skills.values.compact.each do |id|
          mskill = $data_skills[id]
          next unless mskill.absorb?(skill.id) 
          result = (damage * m.level_value(make_symbol("#{type} ABSORB"))).to_i
          type == "HP" ? user.hp += [result, user.mhp - result].min : 
                         user.mp += [result, user.mmp - result].min
        end
      end
    end
    
    #==============================================================================
    # ** Game_Actor
    #------------------------------------------------------------------------------
    #  This class handles actors. It's used within the Game_Actors class
    # ($game_actors) and referenced by the Game_Party class ($game_party).
    #==============================================================================
    
    class Game_Actor < Game_Battler
      #--------------------------------------------------------------------------
      # * Public Instance Variables
      #--------------------------------------------------------------------------
      attr_accessor :materia_slots
      attr_accessor :learned_enemy_skill
      attr_accessor :ap
      #--------------------------------------------------------------------------
      # * Alias method: setup
      #--------------------------------------------------------------------------
      alias :setup_ve_materia_system :setup
      def setup(actor_id)
        setup_materia_system
        setup_ve_materia_system(actor_id)
        start_materia_slots
      end
      #--------------------------------------------------------------------------
      # * Alias method: skills
      #--------------------------------------------------------------------------
      alias :skills_ve_materia_system :skills
      def skills
        update_materia_skills
        skills_ve_materia_system
      end
      #--------------------------------------------------------------------------
      # * Alias method: param
      #--------------------------------------------------------------------------
      alias :param_ve_materia_system :param
      def param(param_id)
        new_id = hp_mp_check(param_id)
        param_ve_materia_system(new_id)
      end
      #--------------------------------------------------------------------------
      # * Alias method: param_plus
      #--------------------------------------------------------------------------
      alias :param_plus_ve_materia_system :param_plus
      def param_plus(param_id)
        result = param_plus_ve_materia_system(param_id)
        all_materias.inject(result) {|r, item| r += item.params[param_id] }
      end
      #--------------------------------------------------------------------------
      # * Alias method: param_rate
      #--------------------------------------------------------------------------
      alias :param_rate_ve_materia_system :param_rate
      def param_rate(param_id)
        result = param_rate_ve_materia_system(param_id)
        result + materia_param(param_id)
      end
      #--------------------------------------------------------------------------
      # * Alias method: xparam
      #--------------------------------------------------------------------------
      alias :xparam_ve_materia_system :xparam
      def xparam(param_id)
        result = xparam_ve_materia_system(param_id)
        result + materia_xparam(param_id)
      end
      #--------------------------------------------------------------------------
      # * Alias method: sparam
      #--------------------------------------------------------------------------
      alias :sparam_ve_materia_system :sparam
      def sparam(param_id)
        result = sparam_ve_materia_system(param_id)
        result + materia_sparam(param_id)
      end  
      #--------------------------------------------------------------------------
      # * Alias method: element_rate
      #--------------------------------------------------------------------------
      alias :element_rate_ve_materia_system :element_rate
      def element_rate(id)
        element_rate_ve_materia_system(id) + materia_element_rate(id)
      end
      #--------------------------------------------------------------------------
      # * Alias method: state_rate
      #--------------------------------------------------------------------------
      alias :state_rate_ve_materia_system :state_rate
      def state_rate(id)
        state_rate_ve_materia_system(id) + materia_state_rate(id)
      end
      #--------------------------------------------------------------------------
      # * Alias method: atk_elements
      #--------------------------------------------------------------------------
      alias :atk_elements_ve_materia_system :atk_elements
      def atk_elements
        result = atk_elements_ve_materia_system
        materia_atk_elements(result).compact.uniq
      end
      #--------------------------------------------------------------------------
      # * Alias method: atk_states
      #--------------------------------------------------------------------------
      alias :atk_states_ve_materia_system :atk_states
      def atk_states
        result = atk_states_ve_materia_system
        materia_atk_states(result).compact.uniq
      end
      #--------------------------------------------------------------------------
      # * Alias method: atk_states_rate
      #--------------------------------------------------------------------------
      alias :atk_states_rate_ve_materia_system :atk_states_rate
      def atk_states_rate(id)
        atk_states_rate_ve_materia_system(id) + materia_atk_states_rate(id)
      end
      #--------------------------------------------------------------------------
      # * Alias method: feature_objects
      #--------------------------------------------------------------------------
      alias :feature_objects_ve_materia_system :feature_objects
      def feature_objects
        feature_objects_ve_materia_system + all_materias
      end
      #--------------------------------------------------------------------------
      # * New method: setup_materia_system
      #--------------------------------------------------------------------------
      def setup_materia_system
        @materia_slots  = {}
        @materia_skills = []
        @paired_materia = []
      end
      #--------------------------------------------------------------------------
      # * New method: start_materia_slots
      #--------------------------------------------------------------------------
      def start_materia_slots
        equip_slots.size.times do |i| 
          @materia_slots[i] = equips[i] ? Array.new(equips[i].slots, nil) : []
        end
        setup_old_equips
      end
      #--------------------------------------------------------------------------
      # * New method: setup_equipments
      #--------------------------------------------------------------------------
      def setup_equipments
        equip_slots.size.times {|i| setup_materia_slots(i) }
        setup_old_equips
      end
      #--------------------------------------------------------------------------
      # * New method: setup_materia_slots
      #--------------------------------------------------------------------------
      def setup_materia_slots(i)
        return if @equips[i].object == @old_equips[i].object
        @materia_slots[i].compact.each {|m| $game_party.gain_materia(m) }
        @materia_slots[i] = equips[i] ? Array.new(equips[i].slots, nil) : []
      end
      #--------------------------------------------------------------------------
      # * New method: setup_old_equips
      #--------------------------------------------------------------------------
      def setup_old_equips
        @old_equips = @equips.collect {|item| item.clone }
      end
      #--------------------------------------------------------------------------
      # * New method: materia_param
      #--------------------------------------------------------------------------
      def materia_param(id)
        all_materias.inject(0.0) do |r, m|
          r += m.stat(id) / 100.0
          r += m.level * materia_param_plus(m, id)
        end
      end
      #--------------------------------------------------------------------------
      # * New method: materia_param_plus
      #--------------------------------------------------------------------------
      def materia_param_plus(m, id)
        m.effect(make_symbol(get_param_text(id)))
      end
      #--------------------------------------------------------------------------
      # * New method: materia_xparam
      #--------------------------------------------------------------------------
      def materia_xparam(id)
        all_materias.inject(0.0) do |r, m|
          r += m.level * materia_xparam_plus(m, id)
        end
      end
      #--------------------------------------------------------------------------
      # * New method: materia_xparam_plus
      #--------------------------------------------------------------------------
      def materia_xparam_plus(m, id)
        m.effect(make_symbol(get_xparam_text(id)))
      end
      #--------------------------------------------------------------------------
      # * New method: materia_sparam
      #--------------------------------------------------------------------------
      def materia_sparam(id)
        all_materias.inject(0.0) do |r, m|
          r += m.level * materia_sparam_plus(m, id)
        end
      end
      #--------------------------------------------------------------------------
      # * New method: materia_sparam_plus
      #--------------------------------------------------------------------------
      def materia_sparam_plus(m, id)
        m.effect(make_symbol(get_sparam_text(id)))
      end
      #--------------------------------------------------------------------------
      # * New method: ap
      #--------------------------------------------------------------------------
      def ap
        @ap ? @ap :  0 
      end
      #--------------------------------------------------------------------------
      # * New method: ap=
      #--------------------------------------------------------------------------
      def ap=(n)
        equip_slots.size.times do |i|
          next if !@equips[i].object || @materia_slots[i].compact.empty?
          growth = @equips[i].object.growth
          @materia_slots[i].compact.each {|m| m.gain_ap(n, growth) }
        end
      end
      #--------------------------------------------------------------------------
      # * New method: all_materias
      #--------------------------------------------------------------------------
      def all_materias
        @materia_slots.values.inject([]) {|r, i| r += i }.compact
      end
      #--------------------------------------------------------------------------
      # * New method: update_materia_skills
      #--------------------------------------------------------------------------
      def update_materia_skills
        @materia_skills.each {|id| forget_skill(id) }
        @materia_skills.clear
        all_materias.each {|m| learn_materia_skill(m) }
      end
      #--------------------------------------------------------------------------
      # * New method: learn_materia_skill
      #--------------------------------------------------------------------------
      def learn_materia_skill(m)
        m.level.times {|i| gain_materia_skill(m, i) if valid_skill?(m, i) }
      end
      #--------------------------------------------------------------------------
      # * New method: gain_materia_skill
      #--------------------------------------------------------------------------
      def gain_materia_skill(m, i)
        id = m.enemy_skill? ? m.learn.values[i] : m.skills[i + 1]
        learn_skill(id)
        @materia_skills.push(id)
        @materia_skills.compact!
      end
      #--------------------------------------------------------------------------
      # * New method: valid_skill?
      #--------------------------------------------------------------------------
      def valid_skill?(m, i)
         (m.enemy_skill? ? m.learn.values[i] : m.skills[i + 1]) &&
         !@skills.include?(m.skills[i + 1])
      end
      #--------------------------------------------------------------------------
      # * New method: hp_mp_check
      #--------------------------------------------------------------------------
      def hp_mp_check(id)
        return id if id > 1
        all_materias.each {|m| return id == 0 ? 1 : 0 if m.effect?(:hp_mp) }
        id
      end
      #--------------------------------------------------------------------------
      # * New method: materia_conditions_met?
      #--------------------------------------------------------------------------
      def materia_conditions_met?(id)
        usable = nil
        all_materias.each {|m| usable |= m.on_limit?(id) if m.skill?(id) }
        usable.nil? ? true : usable
      end
      #--------------------------------------------------------------------------
      # * New method: equip_materia
      #--------------------------------------------------------------------------
      def equip_materia(equip, slot, id, forced = false)
        old = @materia_slots[equip][slot] 
        @materia_slots[equip][slot] = $game_party.materias[id]
        $game_party.lose_materia(id) unless forced
        $game_party.gain_item(old, 1) if old
        make_paired_materia
        update_materia_skills
        refresh
      end
      #--------------------------------------------------------------------------
      # * New method: force_materia
      #--------------------------------------------------------------------------
      def force_materia(equip, slot, id)
        @materia_slots[equip][slot] = $data_armors[id].setup_materia
        make_paired_materia
        update_materia_skills
        refresh
      end
      #--------------------------------------------------------------------------
      # * New method: unequip_materia
      #--------------------------------------------------------------------------
      def unequip_materia(equip, slot)
        $game_party.gain_item(@materia_slots[equip][slot], 1)
        @materia_slots[equip][slot] = nil
        make_paired_materia
        update_materia_skills
        refresh
      end
      #--------------------------------------------------------------------------
      # * New method: paired_materia
      #--------------------------------------------------------------------------
      def paired_materia
        @paired_materia
      end
      #--------------------------------------------------------------------------
      # * New method: make_paired_materia
      #--------------------------------------------------------------------------
      def make_paired_materia
        @paired_materia = []
        equip_slots.each_with_index do |x, i|
          equip   = equips[i]
          @paired_materia += materia_pairs(equip.double_slots, i) if equip
        end
        @paired_materia.compact
      end
      #--------------------------------------------------------------------------
      # * New method: materia_pairs
      #--------------------------------------------------------------------------
      def materia_pairs(slots, i)
        slots.times.collect {|x| setup_pairs(i, x) }.compact
      end
      #--------------------------------------------------------------------------
      # * New method: setup_pairs
      #--------------------------------------------------------------------------
      def setup_pairs(i, x)
        type = equip_slots[i] == 0 ? :weapon : :armor
        main = @materia_slots[i][x]
        pair = setup_pair_info(i, x, main, type) if main && main.support?
        main && pair ? pair : nil
      end
      #--------------------------------------------------------------------------
      # * New method: setup_pair_info
      #--------------------------------------------------------------------------
      def setup_pair_info(i, x, m, t)
        y = x + (x % 2 == 0 ? 1 : - 1)
        o = @materia_slots[i][y]
        o && !o.independent? ? {type: t, main: m, other: o} : nil
      end
      #--------------------------------------------------------------------------
      # * New method: materia_element_rate
      #--------------------------------------------------------------------------
      def materia_element_rate(id)
        paired_materia.inject(0.0) do |r, pair|
          m = pair[:main].effect(:elemental)
          o = pair[:other].elements?(id)
          v = (pair[:type] == :armor && o) ? -m  : 0
          r += v
        end
      end
      #--------------------------------------------------------------------------
      # * New method: materia_state_rate
      #--------------------------------------------------------------------------
      def materia_state_rate(id)
        paired_materia.inject(0.0) do |r, pair|
          m = pair[:main].effect(:added_effect)
          o = pair[:other].states?(id)
          v = (pair[:type] == :armor && o) ? -m : 0
          r += v
        end
      end
      #--------------------------------------------------------------------------
      # * New method: materia_atk_elements
      #--------------------------------------------------------------------------
      def materia_atk_elements(result)
        paired_materia.inject(result) do |r, pair|
          m = pair[:main].effect(:elemental)
          o = (pair[:type] == :weapon && m && m > 0) ? pair[:other].elements : []
          i = o.empty? ? [] : [1]
          r + o - i
        end
      end
      #--------------------------------------------------------------------------
      # * New method: materia_atk_states
      #--------------------------------------------------------------------------
      def materia_atk_states(result)
        paired_materia.inject(result) do |r, pair|
          m = pair[:main].effect?(:added_effect)
          o = (pair[:type] == :weapon && m) ? pair[:other].states : []
          r + o
        end
      end
      #--------------------------------------------------------------------------
      # * New method: materia_atk_states_rate
      #--------------------------------------------------------------------------
      def materia_atk_states_rate(id)
        paired_materia.inject(0.0) do |r, pair|
          m = pair[:main].effect(:added_effect)
          o = pair[:other].states?(id)
          v = (pair[:type] == :weapon && o) ? m : 0
          r + v
        end
      end
      #--------------------------------------------------------------------------
      # * New method: for_all?
      #--------------------------------------------------------------------------
      def for_all?(item)
        return false unless item.all?
        paired_materia.each do |pair|
          return true if pair[:main].all? && pair[:other].skill?(item.id)
        end
        return false
      end
    end
    
    #==============================================================================
    # ** Game_Enemy
    #------------------------------------------------------------------------------
    #  This class handles enemies. It used within the Game_Troop class 
    # ($game_troop).
    #==============================================================================
    
    class Game_Enemy < Game_Battler
      #--------------------------------------------------------------------------
      # * New method: ap
      #--------------------------------------------------------------------------
      def ap
        note =~ /<AP: (\d+)>/i ? $1.to_i : (exp / 10).to_i
      end
    end
    
    #==============================================================================
    # ** Game_Party
    #------------------------------------------------------------------------------
    #  This class handles parties. Information such as gold and items is included.
    # Instances of this class are referenced by $game_party.
    #==============================================================================
    
    class Game_Party < Game_Unit
      #--------------------------------------------------------------------------
      # * 
      #--------------------------------------------------------------------------
      attr_reader   :materias
      #--------------------------------------------------------------------------
      # * Alias method: init_all_items
      #--------------------------------------------------------------------------
      alias :init_all_items_ve_materia_system :init_all_items
      def init_all_items
        init_all_items_ve_materia_system
        @materias = []
      end
      #--------------------------------------------------------------------------
      # * Alias method: gain_item
      #--------------------------------------------------------------------------
      alias :gain_item_ve_materia_system :gain_item
      def gain_item(item, amount, include_equip = false)
        if item && item.materia?
          gain_materia(item, amount)
        else
          gain_item_ve_materia_system(item, amount, include_equip)
        end
      end
      #--------------------------------------------------------------------------
      # * New method: gain_materia
      #--------------------------------------------------------------------------
      def gain_materia(item, amount = 1)
        if amount > 0
          materia = item.clone.setup_materia
          amount.times { @materias.push(materia) if !max_materia? }
        elsif amount < 0
          remove_materia(item, amount.abs)
        end
        @materias.sort! {|a, b| a.id <=> b.id }
        $game_map.need_refresh = true
      end
      #--------------------------------------------------------------------------
      # * New method: remove_materia
      #--------------------------------------------------------------------------
      def remove_materia(item, amount = 1, actor = false)
        amount.times do
          removed = false
          @materias.each_with_index do |m, i|
            if m.id == item.id && !removed
              removed = true
              break @materias.delete_at(i) 
            end
          end
          members.each do |actor|
            actor.equip_slots.size.times do |i| 
              if actor.materia_slots[i]
                actor.materia_slots[i].each_with_index do |m, x|
                  next if !m || m.id != item.id || removed
                  actor.materia_slots[i][x] = nil
                  removed = true
                end
              end
            end
          end
        end
      end
      #--------------------------------------------------------------------------
      # * New method: lose_materia
      #--------------------------------------------------------------------------
      def lose_materia(index)
        @materias.delete_at(index)
        @materias.sort! {|a, b| a.id <=> b.id }
      end
      #--------------------------------------------------------------------------
      # * New method: max_materia?
      #--------------------------------------------------------------------------
      def max_materia?
        Max_Materia_Number && @materias.size >= Max_Materia_Number
      end
    end
    
    #==============================================================================
    # ** Game_Troop
    #------------------------------------------------------------------------------
    #  This class handles enemy groups and battle-related data. Also performs
    # battle events. The instance of this class is referenced by $game_troop.
    #==============================================================================
    
    class Game_Troop < Game_Unit
      #--------------------------------------------------------------------------
      # * New method: ap_total
      #--------------------------------------------------------------------------
      def ap_total
        dead_members.inject(0) {|r, enemy| r += enemy.ap }
      end
    end
    
    #==============================================================================
    # ** Game_Interpreter
    #------------------------------------------------------------------------------
    #  An interpreter for executing event commands. This class is used within the
    # Game_Map, Game_Troop, and Game_Event classes.
    #==============================================================================
    
    class Game_Interpreter
      #--------------------------------------------------------------------------
      # * Alias method: command_319
      #--------------------------------------------------------------------------
      alias :command_319_ve_materia_system :command_319
      def command_319
        command_319_ve_materia_system
        $game_actors[@params[0]].setup_equipments if $game_actors[@params[0]]
      end
      #--------------------------------------------------------------------------
      # * Alias method: command_302
      #--------------------------------------------------------------------------
      alias :command_302_ve_materia_system :command_302
      def command_302
        if $game_temp.materia_shop
          call_materia_shop
        else
          command_302_ve_materia_system
        end
      end
      #--------------------------------------------------------------------------
      # * Alias method: comment_call
      #--------------------------------------------------------------------------
      alias :comment_call_ve_materia_system :comment_call
      def comment_call
        $game_temp.materia_shop = true if note =~ /<MATERIA SHOP>/i
        call_materia_equip
        call_materia_unequip
        call_drop_materia
        comment_call_ve_materia_system
      end
      #--------------------------------------------------------------------------
      # * New method: call_materia_shop
      #--------------------------------------------------------------------------
      def call_materia_shop
        return if $game_party.in_battle
        $game_temp.materia_shop = false
        goods = [@params]
        while next_event_code == 605
          @index += 1
          goods.push(@list[@index].parameters)
        end
        SceneManager.call(Scene_MateriaShop)
        SceneManager.scene.prepare(goods)
        Fiber.yield
      end
      #--------------------------------------------------------------------------
      # * New method: materia_shop
      #--------------------------------------------------------------------------
      def materia_shop(list)
        $game_temp.materia_shop = list.dup
        SceneManager.call(Scene_MateriaShop)
      end
      #--------------------------------------------------------------------------
      # * New method: call_materia_equip
      #--------------------------------------------------------------------------
      def call_materia_equip
        if note =~ /<EQUIP MATERIA: (\d+), *(\d+), *(\d+), *(\d+)>/i
          $game_actors[$1.to_i].force_materia($2.to_i - 1, $3.to_i - 1, $4.to_i)
        end
      end
      #--------------------------------------------------------------------------
      # * New method: call_materia_unequip
      #--------------------------------------------------------------------------
      def call_materia_unequip
        if note =~ /<UNEQUIP MATERIA: (\d+), *(\d+), *(\d+)>/i
          $game_actors[$1.to_i].unequip_materia($2.to_i - 1, $3.to_i - 1)
        end
      end
      #--------------------------------------------------------------------------
      # * New method: call_drop_materia
      #--------------------------------------------------------------------------
      def call_drop_materia
        if note =~ /<DROP MATERIA: (\d+), *(\d+)>/i
          materia = $data_armors[$1.to_i].setup_materia
          $game_party.remove_materia(materia, $2.to_i, true)
        end
      end
    end
    #==============================================================================
    # ** Window_Selectable
    #------------------------------------------------------------------------------
    #  This window contains cursor movement and scroll functions.
    #==============================================================================
    
    class Window_Selectable < Window_Base
      #--------------------------------------------------------------------------
      # * New method: target_all?
      #--------------------------------------------------------------------------
      alias :target_all_ve_materia_system? :target_all? if $imported[:ve_target_arrow]
      def target_all?
        target_all_ve_materia_system? || (@action && BattleManager.actor &&
        BattleManager.actor.for_all?(@action))
      end
    end
    
    #==============================================================================
    # ** Window_MenuCommand
    #------------------------------------------------------------------------------
    #  This command window appears on the menu screen.
    #==============================================================================
    
    class Window_MenuCommand < Window_Command
      #--------------------------------------------------------------------------
      # * Alias method: add_main_commands 
      #--------------------------------------------------------------------------
      alias :add_main_commands_ve_materia_system :add_main_commands
      def add_main_commands
        add_main_commands_ve_materia_system
        add_command(Vocab::VE_MateriaMenu, :materia, main_commands_enabled)
      end
    end
    
    #==============================================================================
    # ** Window_MenuActor
    #------------------------------------------------------------------------------
    #  This window is for selecting actors that will be the target of item or
    # skill use.
    #==============================================================================
    
    class Window_MenuActor < Window_MenuStatus
      #--------------------------------------------------------------------------
      # * Overwrite method: select_for_item
      #--------------------------------------------------------------------------
      def select_for_item(item, for_all = false)
        @cursor_fix = item.for_user?
        @cursor_all = for_all
        if @cursor_fix
          select($game_party.menu_actor.index)
        elsif @cursor_all
          select(0)
        else
          select_last
        end
      end
    end
    
    #==============================================================================
    # ** Window_SkillList
    #------------------------------------------------------------------------------
    #  This window is for displaying a list of available skills on the skill window.
    #==============================================================================
    
    class Window_SkillList < Window_Selectable
      #--------------------------------------------------------------------------
      # * Alias method: draw_skill_cost
      #--------------------------------------------------------------------------
      alias :draw_skill_cost_ve_materia_system :draw_skill_cost
      def draw_skill_cost(rect, skill)
        draw_skill_cost_ve_materia_system(rect, skill)
        change_color(text_color(18), enable?(skill))
        rect.x += (32 + text_size(skill.name).width)
        draw_text(rect, ">") if @actor.for_all?(skill)
      end
    end
    
    #==============================================================================
    # ** Window_BattleLog
    #------------------------------------------------------------------------------
    #  This window shows the battle progress. Do not show the window frame.
    #==============================================================================
    
    class Window_BattleLog < Window_Selectable
      #--------------------------------------------------------------------------
      # * Alias method: display_failure
      #--------------------------------------------------------------------------
      alias :display_failure_ve_materia_system :display_failure
      def display_failure(target, item)
        display_failure_ve_materia_system(target, item)
        if target.actor? && target.learned_enemy_skill
          skill = $data_skills[target.learned_enemy_skill].name
          target.learned_enemy_skill = nil
          add_text(sprintf(Vocab::VE_EnemySkill, target.name, skill))
          wait
        end
      end
    end
    
    #==============================================================================
    # ** Window_MateriaInfo
    #------------------------------------------------------------------------------
    #  This window shows the materia information.
    #==============================================================================
    
    class Window_MateriaInfo < Window_Base
      #--------------------------------------------------------------------------
      # * initialize
      #--------------------------------------------------------------------------
      def initialize(width, height, shop = false)
        super(0, 200, width, height) #$#CHANGE the BIG Materia info LOCATION 
        @shop = shop # ABOVE was y of 176
      end
      #--------------------------------------------------------------------------
      # * materia
      #--------------------------------------------------------------------------
      def materia=(materia)
        @materia = materia
        refresh
      end
      #--------------------------------------------------------------------------
      # * refresh
      #--------------------------------------------------------------------------
      def refresh
        contents.clear
        return if @materia.nil?
        contents.font.size = Font.default_size
        draw_item_name(@materia, 0, 0, true, width)
        contents.font.size = 19
        if @materia.enemy_skill?
          draw_enemy_skill_level
          draw_enemy_skill_list
        else
          draw_materia_elements
          draw_materia_level
          draw_materia_ap
          draw_materia_skills
          draw_materia_abilities
          draw_materia_stats
        end
      end
      #--------------------------------------------------------------------------
      # * draw_item_name
      #--------------------------------------------------------------------------
      def draw_item_name(item, x, y, enabled = true, width = 172)
        return unless item
        draw_icon(item.icon_index, x, y - 2, enabled)
        change_color(normal_color, enabled)
        draw_text(x + 24, y, width, line_height, item.name)
      end
      #--------------------------------------------------------------------------
      # * draw_icon
      #--------------------------------------------------------------------------
      def draw_icon(icon_index, x, y, enabled = true)
        bitmap = Cache.system("Iconset")
        rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
        contents.blt(x, y, bitmap, rect, enabled ? 255 : 120)
      end
      #--------------------------------------------------------------------------
      # * draw_materia_elements
      #--------------------------------------------------------------------------
      def draw_materia_elements
        change_color(crisis_color)
        @materia.elements.each_with_index do |id, i|
          element = $data_system.elements[id]
          x = i % 2 * 96 + 24
          y = i / 2 * 18 + 24
          draw_text(x, y, width, line_height, element)
        end
        @materia.states.each_with_index do |id, i|
          states = $data_states[id].name
          x = (i + @materia.elements.size) % 2 * 96 + 16
          y = (i + @materia.elements.size) / 2 * 18 + 24
          draw_text(x, y, width, line_height, states)
        end
      end
      #--------------------------------------------------------------------------
      # * draw_materia_level
      #--------------------------------------------------------------------------
      def draw_materia_level
        icon = @materia.level_icon
        x    = width - [@materia.max_level * 32, 160].max
        @materia.max_level.times {|i| draw_icon(icon, x + i * 26, 0, false) }
        @materia.level.times     {|i| draw_icon(icon, x + i * 26, 0) }
      end
      #--------------------------------------------------------------------------
      # * draw_materia_ap
      #--------------------------------------------------------------------------
      def draw_materia_ap
     #   change_color(system_color)
     #   x1 = width - 312 + [352 - width, 24].min
     #   x2 = width - 204
     #   contents.draw_text(x1, 24, 172, 24, Vocab::VE_ApName, 2)
    #    contents.draw_text(x1, 44, 172, 24, 'To next rank', 2)
    #    change_color(normal_color)
    #    ap = @materia.master? ? Vocab::VE_MasterText : @materia.ap.to_s
    #    contents.draw_text(x2, 24, 172, 24, ap, 2)
     #   nl = @materia.master? ? '-------' : @materia.next_level - @materia.ap
    #    contents.draw_text(x2, 44, 172, 24, nl.to_s, 2)
      end
      #--------------------------------------------------------------------------
      # * draw_materia_skills
      #--------------------------------------------------------------------------
      def draw_materia_skills
        draw_materia_price if @shop
        change_color(system_color)
        y = @shop ? 120 : 88
        contents.draw_text(4, y - 20, 172, 24, "Ability list")
        change_color(normal_color)
        @materia.skills.keys.sort.each_with_index do |key, i|
          name = $data_skills[@materia.skills[key]].name
          change_color(normal_color, key <= @materia.level)
          contents.draw_text(12, y + i * 18, 172, 24, name)
        end
      end
      #--------------------------------------------------------------------------
      # * draw_materia_price
      #--------------------------------------------------------------------------
      def draw_materia_price
        contents.font.size = 18
        buy    = @materia.price
        sell   = @materia.sell_price
        master = @materia.master
        contents.draw_text(4, 76, 172, 24, "Buy:#{buy}")
        contents.draw_text(width / 2 - 64, 76, 172, 24, "Sell:#{sell}")
        contents.draw_text(width - 128, 76, 172, 24, "Master:#{master}")
        contents.font.size = 19
      end
      #--------------------------------------------------------------------------
      # * draw_materia_abilities
      #--------------------------------------------------------------------------
      def draw_materia_abilities
        y = @materia.skills.keys.size
        z = @shop ? 120 : 88
        change_color(normal_color, true)
        list = @materia.effects.keys.collect {|effect| effect }
        list.each_with_index do |effect, i|
          if @materia.effect_name
            contents.draw_text(12, z + (i + y) * 18, 172, 24, @materia.effect_name)
            break
          elsif @materia.effects[effect].numeric?
            name  = make_string(effect).capitalize
            value = @materia.effects[effect] * 100
            draw_effect_value(effect, i + y, name, value)
          else
            name = make_string(effect).capitalize
            contents.draw_text(12, z + (i + y) * 18, 172, 24, name)
          end
        end
      end
      #--------------------------------------------------------------------------
      # * draw_materia_stats
      #--------------------------------------------------------------------------
      def draw_materia_stats
        list1 = get_params_values
        list2 = get_stats_values
        change_color(system_color)
        y = @shop ? 100 : 68
        contents.draw_text(width - 172, y, 172, 24, "Equip effect")
        change_color(normal_color)
        list1.each_with_index {|param, i| draw_param_value(param, i, false) }
        list2.each_with_index {|param, i| draw_param_value(param, i + list1.size) }
      end
      #--------------------------------------------------------------------------
      # * get_params_values
      #--------------------------------------------------------------------------
      def get_params_values
        list = []
        @materia.params.size.times do |i|
          next if @materia.params[i] == 0
          list.push({name: Vocab::param(i), value: @materia.params[i]})
        end
        list
      end
      #--------------------------------------------------------------------------
      # * get_stats_values
      #--------------------------------------------------------------------------
      def get_stats_values
        list = []
        @materia.stats.keys.each do |i|
          next if @materia.stats[i] == 0
          list.push({name: Vocab::param(i), value: @materia.stats[i]})
        end
        list
      end
      #--------------------------------------------------------------------------
      # * draw_effect_value
      #--------------------------------------------------------------------------
      def draw_effect_value(effect, i, s1, s2)
        name  = effect_name(s1)
        plus  = s2 >= 0 ? "+" : "-"
        value = sprintf("%03d", s2.abs * @materia.level)
        draw_param_info(name, plus, value, "%", i, 12, 108)
      end
      #--------------------------------------------------------------------------
      # * draw_param_value
      #--------------------------------------------------------------------------
      def draw_param_value(param, i, rate = true)
        name  = param[:name]
        plus  = param[:value] < 0 ? "-" : "+"
        value = sprintf("%02d", param[:value].abs)
        rate  = rate ? "%" : ""
        draw_param_info(name, plus, value, rate, i, width - 176, 108)
      end
      #--------------------------------------------------------------------------
      # * draw_param_info
      #--------------------------------------------------------------------------
      def draw_param_info(name, plus, value, rate, i, x, y)
        z = @shop ? 120 : 88
        contents.draw_text(x, z + i * 18, 172, 24, name)
        contents.draw_text(x + y, z + i * 18, 172, 24, plus)
        change_color(plus == "-" ? knockout_color : crisis_color)
        wid = text_size(plus).width
        contents.draw_text(x + y + wid, z + i * 18, 172, 24, value)
        change_color(normal_color)
        wid += text_size(value).width
        contents.draw_text(x + y + wid, z + i * 18, 172, 24, rate)
      end
      #--------------------------------------------------------------------------
      # * draw_enemy_skill_level
      #--------------------------------------------------------------------------
      def draw_enemy_skill_level
        icon = @materia.level_icon
        @materia.max_level.times do |i| 
          draw_icon(icon, level_x(i), level_y(i), @materia.learn[i])
        end
      end
      #--------------------------------------------------------------------------
      # * level_x
      #--------------------------------------------------------------------------
      def level_x(i)
        x = @materia.max_level / 2
        i % x * 26 + [(width / 2) - (x * 26) / 2, 0].max
      end
      #--------------------------------------------------------------------------
      # * level_y
      #--------------------------------------------------------------------------
      def level_y(i)
        i / (@materia.max_level / 2) * 26 + 28
      end
      #--------------------------------------------------------------------------
      # * draw_enemy_skill_list
      #--------------------------------------------------------------------------
      def draw_enemy_skill_list
        draw_materia_price if @shop
        color = Color.new(0, 0, 0, 50)
        y = @shop ? 20 : 0
        contents.fill_rect(8, 82 + y, width - 36, height - 112 - y, color)
        z = @shop ? 116 : 84
        @materia.max_level.times do |i| 
          if @materia.learn[i + 1]
            name = $data_skills[@materia.learn[i + 1]].name
            x = i % 3 * (width / 3 - 16) + 16
            y = i / 3 * 18 + z
            contents.draw_text(x, y, width / 3 - 12, 24, name)
          end
        end
      end
      #--------------------------------------------------------------------------
      # * effect_name
      #--------------------------------------------------------------------------
      def effect_name(name)
        case name.upcase
        when "HIT" then "Hit"
        when "EVA" then "Evasion"
        when "CRI" then "Critical"
        when "CEV" then "C. Evasion"
        when "MEV" then "M. Evasion"
        when "MRF" then "Reflection"
        when "CNT" then "Counter"
        when "HRG" then "HP Regen"
        when "MRG" then "MP Regen"
        when "TRG" then "TP Regen"
        when "TGR" then "Target"
        when "GRD" then "Guard"
        when "REC" then "Recover"
        when "PHA" then "Pharmacology"
        when "MCR" then "MP Rate"
        when "TCR" then "TP Charge"
        when "PDR" then "P. Reduction"
        when "MDR" then "M. Reduction"
        when "FDR" then "Floor Damage"
        when "EXR" then "EXP Rate"
        else 
          id = get_param_id(name.upcase)
          id ? Vocab::param(id) : name
        end
      end
    end
    
    #==============================================================================
    # ** Window_MateriaList
    #------------------------------------------------------------------------------
    #  This window shows the materia list.
    #==============================================================================
    
    class Window_MateriaList < Window_Selectable
      #--------------------------------------------------------------------------
      # * Public Instance Variables
      #--------------------------------------------------------------------------
      attr_reader   :materia_window
      #--------------------------------------------------------------------------
      # * item_max
      #--------------------------------------------------------------------------
      def item_max
        @data ? @data.size : 1
      end
      #--------------------------------------------------------------------------
      # * materia
      #--------------------------------------------------------------------------
      def materia
        @data[index]
      end
      #--------------------------------------------------------------------------
      # * draw_item
      #--------------------------------------------------------------------------
      def draw_item(index)
        item = @data[index]
        if item
          rect = item_rect(index)
          rect.width -= 4
          draw_item_name(item, rect.x, rect.y)
        end
      end
      #--------------------------------------------------------------------------
      # * draw_item_name
      #--------------------------------------------------------------------------
      def draw_item_name(item, x, y, enabled = true, width = 172)
        return unless item
        draw_icon(item.icon_index, x, y, enabled, item)
        change_color(normal_color, enabled)
        draw_text(x + 24, y, width, line_height, item.name)
      end
      #--------------------------------------------------------------------------
      # * draw_icon
      #--------------------------------------------------------------------------
      def draw_icon(icon_index, x, y, enabled = true, item)
        bitmap = Cache.system("Iconset")
        rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
        contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
      end
      #--------------------------------------------------------------------------
      # * refresh
      #--------------------------------------------------------------------------
      def refresh
        make_item_list
        create_contents
        draw_all_items
      end
      #--------------------------------------------------------------------------
      # * materia_window
      #--------------------------------------------------------------------------
      def materia_window=(materia_window)
        @materia_window = materia_window
        call_update_help
      end
      #--------------------------------------------------------------------------
      # * update_help
      #--------------------------------------------------------------------------
      def update_help
        super
        @materia_window.materia = materia if @materia_window
        @help_window.set_item(materia)
      end  
    end
    
    #==============================================================================
    # ** Window_MateriaStatus
    #------------------------------------------------------------------------------
    #  This window shows the materias on the materia equip screen.
    #==============================================================================
    
    class Window_MateriaStatus < Window_MateriaList
      #--------------------------------------------------------------------------
      # * initialize
      #--------------------------------------------------------------------------
      def initialize
        super(window_x, 200, 192, window_height) #$# Y was 176 
        @data = []
      end
      #--------------------------------------------------------------------------
      # * window_x
      #--------------------------------------------------------------------------
      def window_x
        352 + [Graphics.width - 544, 0].max
      end
      #--------------------------------------------------------------------------
      # * window_height
      #--------------------------------------------------------------------------
      def window_height
        216 + [Graphics.height - 416, 0].max #$#FIRST number was 240
      end
      #--------------------------------------------------------------------------
      # * make_item_list
      #--------------------------------------------------------------------------
      def make_item_list
        @data = $game_party.materias.collect {|materia| materia }
        @data.push(nil)
      end
    end
    
    #==============================================================================
    # ** Window_MateriaShop
    #------------------------------------------------------------------------------
    #  This window shows the materias on the materia shop screen.
    #==============================================================================
    
    class Window_MateriaShop < Window_MateriaList
      #--------------------------------------------------------------------------
      # * initialize
      #--------------------------------------------------------------------------
      def initialize(y, width, height, materia_list = nil)
        super(0, y, width, height)
        @materia_list = materia_list
        @data = []
        select(0)
      end
      #--------------------------------------------------------------------------
      # * make_item_list
      #--------------------------------------------------------------------------
      def make_item_list
        @data  = []
        @price = {}
        lsit   = @materia_list ? @materia_list : make_sell_list
        lsit.each do |goods|
          item = @materia_list ? $data_armors[goods[1]] : goods[1]
          item.setup_materia
          if item
            @data.push(item)
            @price[item] = goods[2] == 0 ? setup_price(item) : goods[3]
          end
        end
      end
      #--------------------------------------------------------------------------
      # * setup_price
      #--------------------------------------------------------------------------
      def setup_price(item)
        @materia_list ? item.price : item.sell_price
      end
      #--------------------------------------------------------------------------
      # * make_sell_list
      #--------------------------------------------------------------------------
      def make_sell_list
        $game_party.materias.collect {|m| [0, m, 0] }
      end
      #--------------------------------------------------------------------------
      # * money
      #--------------------------------------------------------------------------
      def money=(money)
        @money = money
        refresh
      end
      #--------------------------------------------------------------------------
      # * current_item_enabled?
      #--------------------------------------------------------------------------
      def current_item_enabled?
        enable?(@data[index])
      end
      #--------------------------------------------------------------------------
      # * price
      #--------------------------------------------------------------------------
      def price(item)
        @price[item]
      end
      #--------------------------------------------------------------------------
      # * enable?
      #--------------------------------------------------------------------------
      def enable?(item)
        item && (!@materia_list || (item && price(item) <= @money &&
        !$game_party.max_materia?))
      end
      #--------------------------------------------------------------------------
      # * draw_item_name
      #--------------------------------------------------------------------------
      def draw_item_name(item, x, y)
        return unless item
        draw_icon(item.icon_index, x, y, enable?(item), item)
        change_color(normal_color, enable?(item))
        draw_text(x + 24, y, width, line_height, item.name)
        draw_text(4, y, self.width - 32, line_height, ":#{price(item)}", 2)
      end
    end
    
    #==============================================================================
    # ** Window_MateriaActor
    #------------------------------------------------------------------------------
    #  This window shows the actor status on the materia equip screen.
    #==============================================================================
    
    class Window_MateriaActor < Window_Selectable
      #--------------------------------------------------------------------------
      # * Public Instance Variables
      #--------------------------------------------------------------------------
      attr_reader   :actor
      #--------------------------------------------------------------------------
      # * initialize
      #--------------------------------------------------------------------------
      def initialize
        @equip = 0
        super(0, 0, Graphics.width, 128)
        @index = 0
      end
      #--------------------------------------------------------------------------
      # * actor
      #--------------------------------------------------------------------------
      def actor=(actor)
        @actor = actor
        refresh
      end
      #--------------------------------------------------------------------------
      # * refresh
      #--------------------------------------------------------------------------
      def refresh
        super
        draw_face(actor.face_name, actor.face_index, 4, 4)
        draw_actor_name(actor, 104, line_height * 0)
        draw_actor_level(actor, 104, line_height * 1)
        draw_actor_hp(actor, 104, line_height * 2)
        draw_actor_mp(actor, 104, line_height * 3)
      end
    end
    
    #==============================================================================
    # ** Window_MateriaEquip
    #------------------------------------------------------------------------------
    #  This window shows the actor equipe materia. Do not show the window frame.
    #==============================================================================
    
    class Window_MateriaEquip < Window_Selectable
      #--------------------------------------------------------------------------
      # * Public Instance Variables
      #--------------------------------------------------------------------------
      attr_accessor :equip  
      attr_reader   :actor
      attr_reader   :materia_window
      #--------------------------------------------------------------------------
      # * initialize
      #--------------------------------------------------------------------------
      def initialize
        @equip = 0
        super(window_x, 0, Graphics.width -  window_x, 128)
        @index = 0
      end
      #--------------------------------------------------------------------------
      # * item_max
      #--------------------------------------------------------------------------
      def item_max
        return 1
      end
      #--------------------------------------------------------------------------
      # * contents_width
      #--------------------------------------------------------------------------
      def contents_width
        width - standard_padding * 2
      end
      #--------------------------------------------------------------------------
      # * contents_height
      #--------------------------------------------------------------------------
      def contents_height
        actor ? actor.equip_slots.size * 48 + 48 - standard_padding * 2 : 1 #@#actor.equip_slots.size
      end
      #--------------------------------------------------------------------------
      # * update_padding_bottom
      #--------------------------------------------------------------------------
      def update_padding_bottom
      end
      #--------------------------------------------------------------------------
      # * actor
      #--------------------------------------------------------------------------
      def actor=(actor)
        @actor = actor
        refresh
      end
      #--------------------------------------------------------------------------
      # * materia
      #--------------------------------------------------------------------------
      def materia
        slots = actor.materia_slots[equip]
        slots ? slots[index] : slots
      end
      #--------------------------------------------------------------------------
      # * slot_width
      #--------------------------------------------------------------------------
      def slot_width
        Max_Slot_Number * 32
      end
      #--------------------------------------------------------------------------
      # * window_x
      #--------------------------------------------------------------------------
      def window_x
        return 244
      end
      #--------------------------------------------------------------------------
      # * base_x
      #--------------------------------------------------------------------------
      def base_x
        [Graphics.width - 544, 4].max + window_x
      end
      #--------------------------------------------------------------------------
      # * refresh
      #--------------------------------------------------------------------------
      def refresh
        super
        create_contents
        self.opacity = 0
        draw_equipments(8 + base_x - slot_width)
        draw_materias(28 + base_x - slot_width)
      end
      #------------------------------------------------------------------------------
      # * draw_equipments 
      #------------------------------------------------------------------------------
      def draw_equipments(x)
        actor.weapons.each_with_index do |item, i| #@#Change weapons to equips to show armor as well
          draw_item_name(item, x, y + 50 * i + 1)
        end
      end
      #------------------------------------------------------------------------------
      # * draw_materias
      #------------------------------------------------------------------------------
      def draw_materias(x)
        draw_background(x)
        draw_slots(x)
        draw_materia_icons(x)
      end
      #------------------------------------------------------------------------------
      # * draw_background
      #------------------------------------------------------------------------------
      def draw_background(x)
        color = Color.new(0, 0, 0, 50)
        actor.equip_slots.size.times do |i|
          contents.fill_rect(x - 4, i * 50 + 26, slot_width, 22, color)
        end
      end
      #------------------------------------------------------------------------------
      # * draw_slots
      #------------------------------------------------------------------------------
      def draw_slots(x)
        actor.equip_slots.size.times do |i|
          next unless actor.equips[i]
          equip = @actor.equips[i]
          links = equip.double_slots / 2
          slots = equip.double_slots + equip.single_slots
          icon1 = equip.nothing? ? Slot_Icon_Nothing : Slot_Icon_Normal
          icon2 = Slot_Link_Icon
          slots.times {|y| draw_icon(icon1, x + y * 32, i * 50 + 24) }
          links.times {|y| draw_icon(icon2, x + 16 + y * 64, i * 50 + 24) }
        end
      end
      #------------------------------------------------------------------------------
      # * draw_materia_icons
      #------------------------------------------------------------------------------
      def draw_materia_icons(x)
        actor.equip_slots.size.times do |i|
          next unless actor.materia_slots[i]
          actor.materia_slots[i].each_with_index do |m, y|
            draw_materia(m.icon_index, x + y * 32, i * 50 + 24, m, 200) if m
          end
        end
      end
      #--------------------------------------------------------------------------
      # * draw_materia
      #--------------------------------------------------------------------------
      def draw_materia(icon_index, x, y, item, opacity = 255)
        bitmap = Cache.system("Iconset")
        rect   = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
        contents.blt(x, y, bitmap, rect, opacity)
      end
      #--------------------------------------------------------------------------
      # * equip
      #--------------------------------------------------------------------------
      def equip=(equip)
        @equip = equip
        update_cursor
        call_update_help
      end
      #--------------------------------------------------------------------------
      # * update_cursor
      #--------------------------------------------------------------------------
      def update_cursor
        ensure_cursor_visible
        cursor_rect.set(item_rect(@index, @equip))
      end
      #--------------------------------------------------------------------------
      # * item_rect
      #--------------------------------------------------------------------------
      def item_rect(index, equip)
        rect = Rect.new
        rect.width  = 26
        rect.height = 26
        rect.x  = index * 32 + 27 + base_x - slot_width
        rect.y  = equip * 50 + 24
        self.oy = (equip - equip % 2) * 50
        rect
      end
      #--------------------------------------------------------------------------
      # * process_cursor_move
      #--------------------------------------------------------------------------
      def process_cursor_move
        return unless cursor_movable?
        last_equip = @equip
        super
        Sound.play_cursor if @equip != last_equip
      end
      #--------------------------------------------------------------------------
      # * cursor_down
      #--------------------------------------------------------------------------
      def cursor_down(wrap = false)
        self.equip += 1
        self.equip %= 1#$#actor.equip_slots.size
      end
      #--------------------------------------------------------------------------
      # * cursor_up
      #--------------------------------------------------------------------------
      def cursor_up(wrap = false)
        self.equip -= 1
        self.equip %= 1#$#actor.equip_slots.size
      end
      #--------------------------------------------------------------------------
      # * cursor_right
      #--------------------------------------------------------------------------
      def cursor_right(wrap = false)
        self.index += 1
        self.index %= Max_Slot_Number
      end
      #--------------------------------------------------------------------------
      # * cursor_left
      #--------------------------------------------------------------------------
      def cursor_left(wrap = false)
        self.index -= 1
        self.index %= Max_Slot_Number
      end
      #--------------------------------------------------------------------------
      # * current_item_enabled?
      #--------------------------------------------------------------------------
      def current_item_enabled?
        index < actor.materia_slots[equip].size
      end
      #--------------------------------------------------------------------------
      # * process_handling
      #--------------------------------------------------------------------------
      def process_handling
        return unless open? && active
        return process_clear  if handler_clear?  && Input.trigger?(:A)
        super 
      end
      #--------------------------------------------------------------------------
      # * handler_clear?
      #--------------------------------------------------------------------------
      def handler_clear?
        handle?(:clear) && materia
      end
      #--------------------------------------------------------------------------
      # * process_clear
      #--------------------------------------------------------------------------
      def process_clear
        call_handler(:clear) 
      end
      #--------------------------------------------------------------------------
      # * materia_window=
      #--------------------------------------------------------------------------
      def materia_window=(materia_window)
        @materia_window = materia_window
        call_update_help
      end
      #--------------------------------------------------------------------------
      # * update_help
      #--------------------------------------------------------------------------
      def update_help
        super
        @materia_window.materia = materia if @materia_window
        @help_window.set_item(materia)
      end
    end
    
    #==============================================================================
    # ** Scene_Menu
    #------------------------------------------------------------------------------
    #  This class performs the menu screen processing.
    #==============================================================================
    
    class Scene_Menu < Scene_MenuBase
      #--------------------------------------------------------------------------
      # * Alias method: create_command_window
      #--------------------------------------------------------------------------
      alias :materia_system_create_command_window :create_command_window
      def create_command_window
        materia_system_create_command_window
        @command_window.set_handler(:materia,   method(:command_personal))
      end
      #--------------------------------------------------------------------------
      # * Alias method: on_personal_ok
      #--------------------------------------------------------------------------
      alias :materia_system_on_personal_ok :on_personal_ok
      def on_personal_ok
        materia_system_on_personal_ok
        if @command_window.current_symbol == :materia
          SceneManager.call(Scene_MateriaEquip)
        end
      end
    end
    
    #==============================================================================
    # ** Scene_Equip
    #------------------------------------------------------------------------------
    #  This class performs the equipment screen processing.
    #==============================================================================
    
    class Scene_Equip < Scene_MenuBase
      #------------------------------------------------------------------------------
      # * Alias method: on_actor_change
      #------------------------------------------------------------------------------
      alias :materia_system_on_actor_change :on_actor_change
      def on_actor_change
        @actor.setup_equipments
        materia_system_on_actor_change
      end
      #------------------------------------------------------------------------------
      # * New method: terminate
      #------------------------------------------------------------------------------
      def terminate
        super
        @actor.setup_equipments
      end
    end
    
    #==============================================================================
    # ** Scene_MateriaEquip
    #------------------------------------------------------------------------------
    #  This class performs the materia equip screen processing.
    #==============================================================================
    
    class Scene_MateriaEquip < Scene_MenuBase
      #--------------------------------------------------------------------------
      # * start
      #--------------------------------------------------------------------------
      def start
        super
        create_help_window
        create_materia_window
        create_status_window
        create_equip_window
        create_item_window
      end
      #--------------------------------------------------------------------------
      # * create_help_window
      #--------------------------------------------------------------------------
      def create_help_window
        @help_window = Window_Help.new(2) #$#CHANGES lines for MATERIA Description
        @help_window.viewport = @viewport
        @help_window.y = 128
      end
      #--------------------------------------------------------------------------
      # * create_materia_window
      #--------------------------------------------------------------------------
      def create_materia_window
        ww = 352 + [Graphics.width - 544, 0].max
        wh = 216 + [Graphics.height - 416, 0].max #$#FIRST number was 240
        @materia_window = Window_MateriaInfo.new(ww, wh)
        @materia_window.viewport = @viewport
      end
      #--------------------------------------------------------------------------
      # * create_status_window
      #--------------------------------------------------------------------------
      def create_status_window
        @status_window = Window_MateriaActor.new
        @status_window.actor = @actor
        @status_window.viewport = @viewport
      end
      #--------------------------------------------------------------------------
      # * create_equip_window
      #--------------------------------------------------------------------------
      def create_equip_window
        @equip_window = Window_MateriaEquip.new
        @equip_window.actor = @actor
        @equip_window.viewport = @viewport
        @equip_window.help_window = @help_window
        @equip_window.materia_window = @materia_window
        @equip_window.set_handler(:ok,       method(:command_equip))
        @equip_window.set_handler(:clear,    method(:command_clear))
        @equip_window.set_handler(:cancel,   method(:return_scene))
        @equip_window.set_handler(:pagedown, method(:next_actor))
        @equip_window.set_handler(:pageup,   method(:prev_actor))
        @equip_window.activate
      end
      #--------------------------------------------------------------------------
      # * create_item_window
      #--------------------------------------------------------------------------
      def create_item_window
        @item_window = Window_MateriaStatus.new
        @item_window.viewport = @viewport
        @item_window.help_window = @help_window
        @item_window.materia_window = @materia_window
        @item_window.set_handler(:ok,     method(:on_item_ok))
        @item_window.set_handler(:cancel, method(:on_item_cancel))
        @item_window.refresh
      end
      #--------------------------------------------------------------------------
      # * command_equip
      #--------------------------------------------------------------------------
      def command_equip
        @item_window.activate
        @item_window.select(0)
      end
      #--------------------------------------------------------------------------
      # * command_clear
      #--------------------------------------------------------------------------
      def command_clear
        Sound.play_equip
        @actor.unequip_materia(@equip_window.equip, @equip_window.index)
        @item_window.refresh
        @equip_window.refresh
        @status_window.refresh
        @materia_window.refresh
      end
      #--------------------------------------------------------------------------
      # * on_actor_change
      #--------------------------------------------------------------------------
      def on_actor_change
        @equip_window.actor  = @actor
        @status_window.actor = @actor
        @item_window.refresh
        @materia_window.refresh
        @equip_window.activate
      end
      #--------------------------------------------------------------------------
      # * on_item_ok
      #--------------------------------------------------------------------------
      def on_item_ok
        Sound.play_equip
        if @item_window.materia
          @actor.equip_materia(@equip_window.equip, @equip_window.index,
            @item_window.index)
        else
          @actor.unequip_materia(@equip_window.equip, @equip_window.index)
        end
        @item_window.refresh
        @equip_window.refresh
        @status_window.refresh
        @materia_window.refresh
        @equip_window.activate
        @item_window.unselect
      end
      #--------------------------------------------------------------------------
      # * on_item_cancel
      #--------------------------------------------------------------------------
      def on_item_cancel
        @equip_window.activate
        @item_window.unselect
      end
    end
    
    #==============================================================================
    # ** Scene_ItemBase
    #------------------------------------------------------------------------------
    #  This class performs common processing for the item screen and skill screen.
    #==============================================================================
    
    class Scene_ItemBase < Scene_MenuBase
      #--------------------------------------------------------------------------
      # * Overwrite method: determine_item
      #--------------------------------------------------------------------------
      def determine_item
        if item.for_friend?
          show_sub_window(@actor_window)
          for_all = item.for_all? || (@actor && @actor.for_all?(item))
          @actor_window.select_for_item(item, for_all)
        else
          use_item
          activate_item_window
        end
      end
      #--------------------------------------------------------------------------
      # * Overwrite method: item_target_actors
      #--------------------------------------------------------------------------
      def item_target_actors
        if !item.for_friend?
          []
        elsif item.for_all? || (@actor && @actor.for_all?(item))
          $game_party.members
        else
          [$game_party.members[@actor_window.index]]
        end
      end
    end
    
    #==============================================================================
    # ** Scene_MateriaShop
    #------------------------------------------------------------------------------
    #  This class performs materia shop screen processing.
    #==============================================================================
    
    class Scene_MateriaShop < Scene_MenuBase
      #--------------------------------------------------------------------------
      # * prepare
      #--------------------------------------------------------------------------
      def prepare(goods)
        @goods = goods
        @goods.delete_if {|m| m[0] != 2 || !$data_armors[m[1]].materia? }
      end
      #--------------------------------------------------------------------------
      # * start
      #--------------------------------------------------------------------------
      def start
        super
        create_help_window
        create_gold_window
        create_command_window
        create_dummy_window
        create_status_window
        create_buy_window
        create_sell_window
      end
      #--------------------------------------------------------------------------
      # * create_help_window
      #--------------------------------------------------------------------------
      def create_help_window
        @help_window = Window_Help.new(1)
        @help_window.viewport = @viewport
      end
      #--------------------------------------------------------------------------
      # * create_gold_window
      #--------------------------------------------------------------------------
      def create_gold_window
        @gold_window = Window_Gold.new
        @gold_window.viewport = @viewport
        @gold_window.x = Graphics.width - @gold_window.width
        @gold_window.y = @help_window.height
      end
      #--------------------------------------------------------------------------
      # * create_command_window
      #--------------------------------------------------------------------------
      def create_command_window
        @command_window = Window_ShopCommand.new(@gold_window.x, false)
        @command_window.viewport = @viewport
        @command_window.y = @help_window.height
        @command_window.set_handler(:buy,    method(:command_buy))
        @command_window.set_handler(:sell,   method(:command_sell))
        @command_window.set_handler(:cancel, method(:return_scene))
      end
      #--------------------------------------------------------------------------
      # * create_dummy_window
      #--------------------------------------------------------------------------
      def create_dummy_window
        wy = @command_window.y + @command_window.height
        wh = Graphics.height - wy
        @dummy_window = Window_Base.new(0, wy, Graphics.width, wh)
        @dummy_window.viewport = @viewport
      end
      #--------------------------------------------------------------------------
      # * create_status_window
      #--------------------------------------------------------------------------
      def create_status_window
        wy = @command_window.y + @command_window.height
        ww = 312 + [Graphics.width - 544, 0].max
        wh = Graphics.height - wy
        @status_window   = Window_MateriaInfo.new(ww, wh, true)
        @status_window.x = Graphics.width - @status_window.width
        @status_window.y = wy
        @status_window.viewport = @viewport
        @status_window.hide
      end
      #--------------------------------------------------------------------------
      # * create_buy_window
      #--------------------------------------------------------------------------
      def create_buy_window
        wy = @command_window.y + @command_window.height
        ww = Graphics.width  - @status_window.width
        wh = Graphics.height - wy
        @buy_window = Window_MateriaShop.new(wy, ww, wh, @goods)
        @buy_window.viewport = @viewport
        @buy_window.help_window = @help_window
        @buy_window.materia_window = @status_window
        @buy_window.hide
        @buy_window.set_handler(:ok,     method(:on_buy_ok))
        @buy_window.set_handler(:cancel, method(:on_buy_cancel))
      end
      #--------------------------------------------------------------------------
      # * create_sell_window
      #--------------------------------------------------------------------------
      def create_sell_window
        wy = @command_window.y + @command_window.height
        ww = Graphics.width  - @status_window.width
        wh = Graphics.height - wy
        @sell_window = Window_MateriaShop.new(wy, ww, wh)
        @sell_window.viewport = @viewport
        @sell_window.help_window = @help_window
        @sell_window.materia_window = @status_window
        @sell_window.hide
        @sell_window.set_handler(:ok,     method(:on_sell_ok))
        @sell_window.set_handler(:cancel, method(:on_sell_cancel))
      end
      #--------------------------------------------------------------------------
      # * activate_buy_window
      #--------------------------------------------------------------------------
      def activate_buy_window
        @buy_window.money = money
        @buy_window.show.activate
        @status_window.show
      end
      #--------------------------------------------------------------------------
      # * activate_sell_window
      #--------------------------------------------------------------------------
      def activate_sell_window
        @sell_window.money = money
        @sell_window.show.activate
        @status_window.show
      end
      #--------------------------------------------------------------------------
      # * command_buy
      #--------------------------------------------------------------------------
      def command_buy
        @dummy_window.hide
        activate_buy_window
      end
      #--------------------------------------------------------------------------
      # * command_sell
      #--------------------------------------------------------------------------
      def command_sell
        @dummy_window.hide
        activate_sell_window
      end
      #--------------------------------------------------------------------------
      # * on_buy_ok
      #--------------------------------------------------------------------------
      def on_buy_ok
        Sound.play_shop
        @item = @buy_window.materia
        $game_party.lose_gold(buying_price)
        $game_party.gain_item(@item, 1)
        activate_buy_window
        refresh_windows
      end
      #--------------------------------------------------------------------------
      # * on_buy_cancel
      #--------------------------------------------------------------------------
      def on_buy_cancel
        @command_window.activate
        @dummy_window.show
        @buy_window.hide
        @status_window.hide
        @help_window.clear
      end
      #--------------------------------------------------------------------------
      # * on_sell_ok
      #--------------------------------------------------------------------------
      def on_sell_ok
        Sound.play_shop
        @item = @sell_window.materia
        $game_party.gain_gold(selling_price)
        $game_party.lose_materia(@sell_window.index)
        activate_sell_window
        index = @sell_window.index
        @sell_window.select([[index, @sell_window.item_max - 1].min, 0].max)
        refresh_windows
      end
      #--------------------------------------------------------------------------
      # * on_sell_cancel
      #--------------------------------------------------------------------------
      def on_sell_cancel
        @command_window.activate
        @dummy_window.show
        @status_window.hide
        @sell_window.hide
        @help_window.clear
      end
      #--------------------------------------------------------------------------
      # * refresh_windows
      #--------------------------------------------------------------------------
      def refresh_windows
        @gold_window.refresh
        @status_window.refresh
      end
      #--------------------------------------------------------------------------
      # * money
      #--------------------------------------------------------------------------
      def money
        @gold_window.value
      end
      #--------------------------------------------------------------------------
      # * currency_unit
      #--------------------------------------------------------------------------
      def currency_unit
        @gold_window.currency_unit
      end
      #--------------------------------------------------------------------------
      # * buying_price
      #--------------------------------------------------------------------------
      def buying_price
        @buy_window.price(@item)
      end
      #--------------------------------------------------------------------------
      # * selling_price
      #--------------------------------------------------------------------------
      def selling_price
        @item.sell_price
      end
    end
    
    #==============================================================================
    # ** Scene_Battle
    #------------------------------------------------------------------------------
    #  This class performs battle screen processing.
    #==============================================================================
    
    class Scene_Battle < Scene_Base
      #--------------------------------------------------------------------------
      # * Overwrite method: on_skill_ok
      #--------------------------------------------------------------------------
      alias :on_skill_ok_ve_materia_system :on_skill_ok
      def on_skill_ok
        @skill = @skill_window.item
        actor  = BattleManager.actor
        if actor.for_all?(@skill) &&  !$imported[:ve_target_arrow]
          actor.input.set_skill(@skill.id)
          actor.last_skill.object = @skill
          @skill_window.hide
          next_command
        else
          on_skill_ok_ve_materia_system
        end
      end
      #--------------------------------------------------------------------------
      # * Alias method: battle_start
      #--------------------------------------------------------------------------
      alias :battle_start_ve_materia_system :battle_start
      def battle_start
        battle_start_ve_materia_system
        reset_materia_all
      end
      #--------------------------------------------------------------------------
      # * Alias method: pre_terminate
      #--------------------------------------------------------------------------
      alias :pre_terminate_ve_materia_system :pre_terminate
      def pre_terminate
        pre_terminate_ve_materia_system
        reset_materia_all
      end
      #--------------------------------------------------------------------------
      # * New method: reset_materia_all
      #--------------------------------------------------------------------------
      def reset_materia_all
        $game_party.members.each do |actor|
          actor.all_materias.compact.each {|materia| materia.reset_times }
        end
      end
    end

     

     

    With that said, I ended up changing how AP will be handled, in a way that should hopefully make things much simpler than my previous request. In the newest version of the script, at line 574 you'll see: 

    @ap    ||= $game_variables[198]___

    With how it's currently set up, when I obtain a materia, it's initial total AP is set to the value of variable 198. 

     

    Instead of setting the AP to the equipped actor's LV, I'm just looking for a way to manually increase a given materia's AP via a script call. For reference, In game I have different groups of materia (Fire/Water/Ice/etc.). When you first get a fire materia, it will have 1 total AP, once you get a second fire materia, I'll then set ALL fire materia to have 2 total AP. I'll handle keeping track of owned materia, and the AP gain via an event, all I need it a way to set all materia with an armor ID of X to a certain amount of AP.


  10. Call me old fashioned, but I love the old school RPG styled tired spells. Stuff like Final Fantasy's Thunder-Thundra-Thundaga, or Dragon Quests Woosh-Wooshle-KaWoosh-Kawooshle. It has a certain charm to it, and makes it easy to tell how powerful a spell is at a glance. I know it's kind of a divided opinion whether this type of skill names are liked or not, but it's really nostalgic to me.

    So, I've been trying to come up with a good sounding set of prefixes/suffixes for my own JRPG, but have been stumped on this for longer than I care to admit. :p

     

    I currently am working with Flare-Flaremore-Flaremire, with either RaFlare or OmniFlare as a multi-target version of the spell, but it just doesn't feel right.

     

    I'd really appreciate any brainstorming help here. Thank you :)


  11. No problem, I'll do what I can to try and explain it better.

     

    I'm looking to change how the script handles AP. Instead of actually gaining any AP from battles, I'm looking for the script to set a Materia's current AP to be equal to the equipped actors level. For example, if you equipped a Fire Materia to a LV.5 actor, it would set that Materia's current AP to 5. 

     

    On the Materia themselves, I have the tag <ap list: 10, 20, 35, 50> . In this case, the Materia would be at rank 1 if the equipped actor was LV10 or less, rank 2 if the equipped actor was between LV10-20, etc. 

     

    In this scenario, I don't actually use the <ap: x> tag. The Materia script also doesn't play well with several of the commonly used Victory Aftermath scripts, so I was kinda hoping this would indirectly work around that too. 

     

     


  12. Hello! 🙂

     

    Lately, I've been trying to make what I thought would be a really simple edit to Ventwig's VTS-Elemental Charge Field script, but I haven't had any luck on my own. I'm hoping someone with a better idea of what they're doing than myself could help me out here.

     

    In summery, the script allows you to create multipliers that apply to each element. By default, the script allows up to 8 elements to be used, but I'm hoping to increase that to 20. I'm not actually using the visual HUD aspect of the script, everything happens behind the scenes, so no worries about making everything fit.

     

    Additionally, I have been trying to get this working myself, without much luck. Here's my current copy of the script, in case it proves helpful in any way:

     

    Spoiler
    
    #============================================================================
    #VTS-Elemental Charge Fields (with Charge Skill Evolution)
    #By Ventwig
    #Version 1.21 - Mar 22 2014
    #For RPGMaker VX Ace
    #Thanks Selchar and Tsukihime for the help!
    #=============================================================================
    # Description:
    # This script adds an extra dynamic to elements for both players and enemies
    # alike. When a skill of an element is used, its "charge" will raise, and,
    # if desired, the opposing element's "charge" will drop. That charge counts
    # as a damage multiplier, and it can even nullify or drain damage of a certain
    # element if its charge drops low enough.
    # The new Charge Skill Evolution feature (from Tales of The Abyss's Field
    # of Fonons Change) allows a skill to change into a more powerful form 
    # under certain conditions based on the fields.
    #==============================================================================
    # Compatability:
    # I'd say it's pretty high!
    # It works with Battle Symphony, and YEA because it's only an add-on to battles,
    # so have fun!
    #===============================================================================
    # Instructions: Put in materials, above main. You need to set the elements/icons!
    #==============================================================================
    # Please give Credit to Ventwig if you would like to use one of my scripts!
    # Use it commericial or non-commercial, and feel free to tell me if you're using
    # it commercially!
    # You may edit my scripts, just don't claim as your own!
    #===============================================================================
    #Spirit System / Wisp System
    
    #===============================================================================
    # How to Change Charge Value (Skill Notetags)
    #===============================================================================
    # <charge_value x>
    # x = amount to increase charge (make a negative to decrease) (number)
    # If you want to make certain skills worth more in charge fields, this notetag
    # lets you make some skills strengthen fields better. Negatives weaken fields.
    # These override the default for said skill.
    #===============================================================================
    # How to Set up a Charge Skill Evolution (Skill Notetags)
    #===============================================================================
    # If you do not like the CSE idea, simply do not use these notetags
    #===============================================================================
    # <evolution_element x>
    # x = element id (the number)
    # Set the element ID for the CSE. This means that this element will 
    # need the specidic value (or default if you use that) in order to CSE.
    # Please be careful and don't set it to an element without a Charge Field,
    # as that will have no effect.
    #
    # <evolution_charge x>
    # x = required charge value 
    # Set a number for the CSE. This means that the element (specified using
    # the notetag above or using the default setting) will need a value equal to or
    # greater than x in order to FOFChange.
    #
    # <evolution_skill x>
    # x = skill id (the number)
    # Set the skill to CSE into. Simple enough, if the conditions are met,
    # then this skill will be used instead.
    #*******************************************************************************
    # IT IS IMPERATIVE to make sure the MP/TP costs are equal to/less than the 
    # original skill. This script does not check for that and will bug if 
    # the player doesn't have enough MP to use the new skill.
    #===============================================================================
    
    module VTS_ECF
      #This means whether or not elements across from each other will "oppose"
      #each other. If set to true, using a fire attack will raise fire charge
      #and lower ice. False will just raise fire.
      #True/False Def:True
      COUNTER_CHARGE = false
     
      #The default amount an attack will raise/lower the fields
      #Def: 10
      CHARGE_VALUE = 0
     
      #The ID number of the desired elements. In "Terms" in the database, there's
      #the area where you can edit elements. The ID is the number beside them.
      #Def: 3,4,5,8,6,7,9,10 (Fire,Ice,Thunder,Wind,Water,Stone,Light,Dark)
      #NOTE:If you are using opposing elements, then the opposing pairs are:
      # 1/2 and 3/4 (so on), 1/2 will not alter 3/4, 3/4 will not alter 1/2.
      
      ELE1 = 4
      ELE2 = 5
      ELE3 = 6
      ELE4 = 7
      #========
      # Don't want 8 elements? Simply change the number to "nil" w/o brackets!
      # (min 4 elements, max 8)
      #=======
      ELE5 = 10
      ELE6 = 11
      ELE7 = 8
      ELE8 = 9
      ELE9 = 13
      ELE10 = 14
      ELE11 = 15
      ELE12 = 16
      ELE13 = 17
      ELE14 = 18
      ELE15 = 19
      ELE16 = 20
      ELE17 = 21
      ELE18 = 22
      ELE19 = 12
      ELE20 = 23
      #How wide the window should be.
      #Recommended
      #4 elements: 100
      #6 elements: 160
      #8 elements: 200
      WIDTH = 0 #220
     
      #The icon numbers for the elements. These are in sync with the numbers
      #for element id above, so just shove in the icons you want!
      #Def: 96,97,98,101,99,100,102,103
      EIC1 = 96
      EIC2 = 97
      EIC3 = 98
      EIC4 = 100
      EIC5 = 99
      EIC6 = 101
      EIC7 = 102
      EIC8 = 103
      ELE9 = 9
      ELE10 = 9
      ELE11 = 9
      ELE12 = 9
      ELE13 = 9
      ELE14 = 9
      ELE15 = 9
      ELE16 = 9
      ELE17 = 9
      ELE18 = 9
      ELE19 = 9
      ELE20 = 9
     
      #The icon showing "opposing elements", acting as the connector between them.
      #Put 0 if you don't want one (like if you don't use opposing elements)
      #Def:115
      LIC = 0
     
      #The X and Y placement of the window. Easy enough.
      #Def: Graphics.width - 200, 0
      #I recommend keeping X like this, making the number equal to width. Y can be whatever.
      X = Graphics.width - 100
      Y = 0
      
      #=============================================================================
      #Charge Skill Evolution
      #=============================================================================
      DEF_CSE_ELEMENT = 3 
      #If an element is not set to a skill with a CSE,
      #this is the element ID it will be given
      
      DEF_CSE_CHARGE = 120
      #If no charge amount is specified for a skill with a
      #CSE, this is the required amount
      
      CSE_TEXT = "Wisp Charge!" 
      #The text said when announcing the new change
      
      CSE_TEXT_SKILL = false 
      #Display the skill name after the text above? True/false
      #(It shows the traditional (Eric used FIREAGA! Afterwards)
    end
    #############################################################################
     
    class Game_Battler < Game_BattlerBase
      def make_damage_value(user, item)
        value = item.damage.eval(user, self, $game_variables)
        value *= item_element_rate(user, item)
        value *= pdr if item.physical?
        value *= mdr if item.magical?
        value *= rec if item.damage.recover?
        value = value*$vts_elechrg1/100 if item.damage.element_id == VTS_ECF::ELE1
        value = value*$vts_elechrg2/100 if item.damage.element_id == VTS_ECF::ELE2
        value = value*$vts_elechrg3/100 if item.damage.element_id == VTS_ECF::ELE3
        value = value*$vts_elechrg4/100 if item.damage.element_id == VTS_ECF::ELE4
        if $vts_elechrg5 != nil
          value = value*$vts_elechrg5/100 if item.damage.element_id == VTS_ECF::ELE5
        end
        if $vts_elechrg6 != nil
          value = value*$vts_elechrg6/100 if item.damage.element_id == VTS_ECF::ELE6
        end
        if $vts_elechrg7 != nil
          value = value*$vts_elechrg7/100 if item.damage.element_id == VTS_ECF::ELE7
        end
        if $vts_elechrg8 != nil
          value = value*$vts_elechrg8/100 if item.damage.element_id == VTS_ECF::ELE8
        end
         if $vts_elechrg9 != nil
          value = value*$vts_elechrg9/100 if item.damage.element_id == VTS_ECF::ELE9
        end
            if $vts_elechrg10 != nil
          value = value*$vts_elechrg10/100 if item.damage.element_id == VTS_ECF::ELE10
        end
            if $vts_elechrg11 != nil
          value = value*$vts_elechrg11/100 if item.damage.element_id == VTS_ECF::ELE11
        end
            if $vts_elechrg12 != nil
          value = value*$vts_elechrg12/100 if item.damage.element_id == VTS_ECF::ELE12
        end
            if $vts_elechrg13 != nil
          value = value*$vts_elechrg13/100 if item.damage.element_id == VTS_ECF::ELE13
        end
            if $vts_elechrg14 != nil
          value = value*$vts_elechrg14/100 if item.damage.element_id == VTS_ECF::ELE14
        end
            if $vts_elechrg15 != nil
          value = value*$vts_elechrg15/100 if item.damage.element_id == VTS_ECF::ELE15
        end
            if $vts_elechrg16 != nil
          value = value*$vts_elechrg16/100 if item.damage.element_id == VTS_ECF::ELE16
        end
            if $vts_elechrg17 != nil
          value = value*$vts_elechrg17/100 if item.damage.element_id == VTS_ECF::ELE17
        end
            if $vts_elechrg18 != nil
          value = value*$vts_elechrg18/100 if item.damage.element_id == VTS_ECF::ELE18
        end
            if $vts_elechrg19 != nil
          value = value*$vts_elechrg19/100 if item.damage.element_id == VTS_ECF::ELE19
        end
            if $vts_elechrg20 != nil
          value = value*$vts_elechrg20/100 if item.damage.element_id == VTS_ECF::ELE20
        end
        
        
        value = apply_critical(value) if @result.critical
        value = apply_variance(value, item.damage.variance)
        value = apply_guard(value)
        @result.make_damage(value.to_i, item)
      end
    end
     
    class Window_ElementCharge < Window_Base
      def initialize(x,y,width,height)
        super
        self.z = 0
        draw_elements
        set_values
        draw_value
      end
      def set_values
        @val1 = $vts_elechrg1
        @val2 = $vts_elechrg2
        @val3 = $vts_elechrg3
        @val4 = $vts_elechrg4
        @val5 = $vts_elechrg5 if $vts_elechrg5 != nil
        @val6 = $vts_elechrg6 if $vts_elechrg6 != nil
        @val7 = $vts_elechrg7 if $vts_elechrg7 != nil
        @val8 = $vts_elechrg8 if $vts_elechrg8 != nil
        @val9 = $vts_elechrg9 if $vts_elechrg9 != nil
        @val10 = $vts_elechrg10 if $vts_elechrg10 != nil
        @val11 = $vts_elechrg11 if $vts_elechrg11 != nil
        @val12 = $vts_elechrg12 if $vts_elechrg12 != nil
        @val13 = $vts_elechrg13 if $vts_elechrg13 != nil
        @val14 = $vts_elechrg14 if $vts_elechrg14 != nil
        @val15 = $vts_elechrg15 if $vts_elechrg15 != nil
        @val16 = $vts_elechrg16 if $vts_elechrg16 != nil
        @val17 = $vts_elechrg17 if $vts_elechrg17 != nil
        @val18 = $vts_elechrg18 if $vts_elechrg18 != nil
        @val19 = $vts_elechrg19 if $vts_elechrg19 != nil
        @val20 = $vts_elechrg20 if $vts_elechrg20 != nil
        
      end
      def draw_elements
        draw_icon(VTS_ECF::EIC1,0,0,enabled=true) #Fire
        draw_icon(VTS_ECF::EIC2,0,93,enabled=true) #Ice
        draw_icon(VTS_ECF::EIC3,50,0,enabled=true) #Thunder
        draw_icon(VTS_ECF::EIC4,50,93,enabled=true) #Wind
        draw_icon(VTS_ECF::LIC,0,50,enabled=true) #
        draw_icon(VTS_ECF::LIC,50,50,enabled=true) #
        
        draw_icon(VTS_ECF::EIC5,100,0,enabled=true) if $vts_elechrg5 != nil
        draw_icon(VTS_ECF::EIC6,100,93,enabled=true) if $vts_elechrg6 != nil
        draw_icon(VTS_ECF::EIC7,150,0,enabled=true) if $vts_elechrg7 != nil
        draw_icon(VTS_ECF::EIC8,150,93,enabled=true) if $vts_elechrg8 != nil
        draw_icon(VTS_ECF::LIC,100,50,enabled=true) if $vts_elechrg6 != nil
        draw_icon(VTS_ECF::LIC,150,50,enabled=true) if $vts_elechrg8 != nil
        
      end
      def draw_value
        draw_text(0,20,40,32,@val1)
        draw_text(0,70,40,32,@val2)
        draw_text(45,20,40,32,@val3)
        draw_text(45,70,40,32,@val4)
        draw_text(100,20,40,32,@val5)if $vts_elechrg5 != nil
        draw_text(100,70,40,32,@val6)if $vts_elechrg6 != nil
        draw_text(145,20,40,32,@val7)if $vts_elechrg7 != nil
        draw_text(145,70,40,32,@val8)if $vts_elechrg8 != nil
      end
     
      def refresh
        contents.clear
        draw_elements
        set_values
        draw_value
      end
     
      def update
        refresh if $vts_elechrg1 != @val1
        refresh if $vts_elechrg2 != @val2
        refresh if $vts_elechrg3 != @val3
        refresh if $vts_elechrg4 != @val4
        refresh if $vts_elechrg5 != @val5 and $vts_elechrg5 != nil
        refresh if $vts_elechrg6 != @val6 and $vts_elechrg6 != nil
        refresh if $vts_elechrg7 != @val7 and $vts_elechrg7 != nil
        refresh if $vts_elechrg8 != @val8 and $vts_elechrg8 != nil
        refresh if $vts_elechrg9 != @val9
        refresh if $vts_elechrg10 != @val10
        refresh if $vts_elechrg11 != @val11
        refresh if $vts_elechrg12 != @val12
        refresh if $vts_elechrg13 != @val13
        refresh if $vts_elechrg14 != @val14
        refresh if $vts_elechrg15 != @val15
        refresh if $vts_elechrg16 != @val16
        refresh if $vts_elechrg17 != @val17
        refresh if $vts_elechrg18 != @val18
        refresh if $vts_elechrg19 != @val19
        refresh if $vts_elechrg20 != @val20
      end
    end
     
    class Scene_Battle < Scene_Base
      alias ele_charge_start start
      def start
        ele_charge_start
        $vts_elechrg1 = 100
        $vts_elechrg2 = 100
        $vts_elechrg3 = 100
        $vts_elechrg4 = 100
        $vts_elechrg5 = 100 if VTS_ECF::ELE5 != nil
        $vts_elechrg6 = 100 if VTS_ECF::ELE6 != nil
        $vts_elechrg7 = 100 if VTS_ECF::ELE7 != nil
        $vts_elechrg8 = 100 if VTS_ECF::ELE8 != nil
        $vts_elechrg9 = 100 if VTS_ECF::ELE9 != nil
        $vts_elechrg10 = 100 if VTS_ECF::ELE10 != nil
        $vts_elechrg11 = 100 if VTS_ECF::ELE11 != nil
        $vts_elechrg12 = 100 if VTS_ECF::ELE12 != nil
        $vts_elechrg13 = 100 if VTS_ECF::ELE13 != nil
        $vts_elechrg14 = 100 if VTS_ECF::ELE14 != nil
        $vts_elechrg15 = 100 if VTS_ECF::ELE15 != nil
        $vts_elechrg16 = 100 if VTS_ECF::ELE16 != nil
        $vts_elechrg17 = 100 if VTS_ECF::ELE17 != nil
        $vts_elechrg18 = 100 if VTS_ECF::ELE18 != nil
        $vts_elechrg19 = 100 if VTS_ECF::ELE19 != nil
        $vts_elechrg20 = 100 if VTS_ECF::ELE20 != nil
      end
      alias element_charge_create_all_windows create_all_windows
      def create_all_windows
        element_charge_create_all_windows
        create_element_window
      end  
     
      def create_element_window
        @element_window = Window_ElementCharge.new(VTS_ECF::X,VTS_ECF::Y,VTS_ECF::WIDTH,150)
      end
     
      alias element_charge_use_item use_item
      def use_item
        item = @subject.current_action.item
        if item.is_a?(RPG::Skill)
          @charge_element = item.damage.element_id
          adjust_element_charge(@charge_element, item)
        end
        element_charge_use_item
      end
    ###
      def adjust_element_charge(element, skill)
        if element == VTS_ECF::ELE1
          $vts_elechrg1 += skill.charge_value
          if VTS_ECF::COUNTER_CHARGE
            $vts_elechrg2 -= skill.charge_value
          end
        end
        if element == VTS_ECF::ELE2
          $vts_elechrg2 += skill.charge_value
          if VTS_ECF::COUNTER_CHARGE
            $vts_elechrg1 -= skill.charge_value
          end
        end
        if element == VTS_ECF::ELE3
          $vts_elechrg3 += skill.charge_value
          if VTS_ECF::COUNTER_CHARGE
            $vts_elechrg4 -= skill.charge_value
          end
        end
        if element == VTS_ECF::ELE4
          $vts_elechrg4 += skill.charge_value
          if VTS_ECF::COUNTER_CHARGE
            $vts_elechrg3 -= skill.charge_value
          end
        end
        if $vts_elechrg5 != nil
          if element == VTS_ECF::ELE5 
            $vts_elechrg5 += skill.charge_value
            if VTS_ECF::COUNTER_CHARGE
              $vts_elechrg6 -= skill.charge_value
            end
          end
        end
        if $vts_elechrg5 != nil
          if element == VTS_ECF::ELE6
            $vts_elechrg6 += skill.charge_value
            if VTS_ECF::COUNTER_CHARGE
              $vts_elechrg5 -= skill.charge_value
            end
          end
        end
        if $vts_elechrg5 != nil
          if element == VTS_ECF::ELE7
            $vts_elechrg7 +=skill.charge_value
            if VTS_ECF::COUNTER_CHARGE
              $vts_elechrg8 -= skill.charge_value
            end
          end
        end
        if $vts_elechrg5 != nil
          if element == VTS_ECF::ELE8
            $vts_elechrg8 += skill.charge_value
            if VTS_ECF::COUNTER_CHARGE
              $vts_elechrg7 -= skill.charge_value
            end
          end
          end
          
    #New elements 9-20
    
          if $vts_elechrg5 != nil
          if element == VTS_ECF::ELE9
            $vts_elechrg9 += skill.charge_value
            if VTS_ECF::COUNTER_CHARGE
              $vts_elechrg10 -= skill.charge_value
            end
          end
          end
          
            if $vts_elechrg5 != nil
          if element == VTS_ECF::ELE10
            $vts_elechrg10 +=skill.charge_value
            if VTS_ECF::COUNTER_CHARGE
              $vts_elechrg9 -= skill.charge_value
            end
          end
        end    
        if $vts_elechrg5 != nil
          if element == VTS_ECF::ELE11
            $vts_elechrg11 +=skill.charge_value
            if VTS_ECF::COUNTER_CHARGE
              $vts_elechrg8 -= skill.charge_value
            end
          end
        end    
        if $vts_elechrg5 != nil
          if element == VTS_ECF::ELE12
            $vts_elechrg12 +=skill.charge_value
            if VTS_ECF::COUNTER_CHARGE
              $vts_elechrg8 -= skill.charge_value
            end
          end
        end    
        if $vts_elechrg5 != nil
          if element == VTS_ECF::ELE13
            $vts_elechrg13 +=skill.charge_value
            if VTS_ECF::COUNTER_CHARGE
              $vts_elechrg8 -= skill.charge_value
            end
          end
        end    
        if $vts_elechrg5 != nil
          if element == VTS_ECF::ELE14
            $vts_elechrg14 +=skill.charge_value
            if VTS_ECF::COUNTER_CHARGE
              $vts_elechrg8 -= skill.charge_value
            end
          end
        end   
        if $vts_elechrg5 != nil
          if element == VTS_ECF::ELE15
            $vts_elechrg15 +=skill.charge_value
            if VTS_ECF::COUNTER_CHARGE
              $vts_elechrg8 -= skill.charge_value
            end
          end
        end  
        if $vts_elechrg5 != nil
          if element == VTS_ECF::ELE16
            $vts_elechrg16 +=skill.charge_value
            if VTS_ECF::COUNTER_CHARGE
              $vts_elechrg8 -= skill.charge_value
            end
          end
        end   
        if $vts_elechrg5 != nil
          if element == VTS_ECF::ELE17
            $vts_elechrg17 +=skill.charge_value
            if VTS_ECF::COUNTER_CHARGE
              $vts_elechrg8 -= skill.charge_value
            end
          end
        end   
        if $vts_elechrg5 != nil
          if element == VTS_ECF::ELE18
            $vts_elechrg18 +=skill.charge_value
            if VTS_ECF::COUNTER_CHARGE
              $vts_elechrg8 -= skill.charge_value
            end
          end
        end    
        if $vts_elechrg5 != nil
          if element == VTS_ECF::ELE19
            $vts_elechrg19 +=skill.charge_value
            if VTS_ECF::COUNTER_CHARGE
              $vts_elechrg8 -= skill.charge_value
            end
          end
        end   
        if $vts_elechrg5 != nil
          if element == VTS_ECF::ELE20
            $vts_elechrg20 +=skill.charge_value
            if VTS_ECF::COUNTER_CHARGE
              $vts_elechrg8 -= skill.charge_value
            end
          end
        end
     
        
        end
      end
    
    #===============================================================================
    #FOF CHANGE
    #===============================================================================
    
    module RPG
      class BaseItem 
        def fofc_element
          if @fofc_element.nil?
            if @note =~ /<evolution_element (.*)>/i
              @fofc_element= $1.to_i
            else
              @fofc_element = VTS_ECF::DEF_CSE_ELEMENT
            end
          end
          @fofc_element
        end
        
        def fofc_charge
          if @fofc_charge.nil?
            if @note =~ /<evolution_charge (.*)>/i
              @fofc_charge= $1.to_i
            else
              @fofc_charge = VTS_ECF::DEF_CSE_CHARGE
            end
          end
          @fofc_charge
        end
        def fofc_skill
          if @fofc_skill.nil?
            if @note =~ /<evolution_skill (.*)>/i
              @fofc_skill= $1.to_i
            else
              @fofc_skill = 0 
            end
          end
          @fofc_skill
        end
        def charge_value
          if @charge_value.nil?
            if @note =~ /<charge_value (.*)>/i
              @charge_value= $1.to_i
            else
              @charge_value = VTS_ECF::CHARGE_VALUE
            end
          end
          @charge_value
        end
      end
    end
    
    class Game_Action
      attr_accessor :old_skill
    end
    
    class Game_Battler < Game_BattlerBase
      def get_new_skill
        return unless current_action.item.is_a?(RPG::Skill)
    
        quest_skill = current_action.item
        
        if quest_skill.fofc_skill != 0
          if quest_skill.fofc_element == VTS_ECF::ELE1
            if $vts_elechrg1 >= quest_skill.fofc_charge
                current_action.set_skill(quest_skill.fofc_skill)
                current_action.old_skill = quest_skill 
                $vts_elechrg1 = 100
            end
          end
          if quest_skill.fofc_element == VTS_ECF::ELE2
            if $vts_elechrg2 >= quest_skill.fofc_charge
                current_action.set_skill(quest_skill.fofc_skill)
                current_action.old_skill = quest_skill 
                $vts_elechrg1 = 100
            end
          end
          if quest_skill.fofc_element == VTS_ECF::ELE3
            if $vts_elechrg3 >= quest_skill.fofc_charge
                current_action.set_skill(quest_skill.fofc_skill)
                current_action.old_skill = quest_skill 
                $vts_elechrg1 = 100
            end
          end
          if quest_skill.fofc_element == VTS_ECF::ELE10
            if $vts_elechrg10 >= quest_skill.fofc_charge
                current_action.set_skill(quest_skill.fofc_skill)
                current_action.old_skill = quest_skill 
                $vts_elechrg1 = 100
            end
          end
        end
      end
    end # Game_Battler
    
    class Window_BattleLog < Window_Selectable #$#CRASHES DJINN System! No knwon side effects from disabling it :)
     #$# alias vts_fofchange_display_use_item display_use_item
     # def display_use_item(subject, item)
      #  if item.is_a?(RPG::Skill)
      #    if subject.current_action.old_skill != nil
       #     name = subject.name
      #      change_text = VTS_ECF::CSE_TEXT
      #      skill_name = item.name + '!'
       #     use_name = subject.current_action.old_skill.message1
       #     old_skill_text = name + use_name
       #     add_text(old_skill_text)
        #    wait
        #    if VTS_ECF::CSE_TEXT_SKILL == true
       #       new_skill_text = change_text + skill_name
       #       else
       #       new_skill_text = change_text
       #     end
       #     add_text(new_skill_text)
      #      wait
      #    end
     #   end    
     #   vts_fofchange_display_use_item(subject, item)
     #   subject.current_action.old_skill = nil
     # end
    end
    
    class Scene_Battle < Scene_Base
      alias scene_battle_use_item_new use_item
      def use_item
        @subject.get_new_skill
        scene_battle_use_item_new
      end
      
    end # Scene_Battle

     

     

    Please let me know if you have any questions.

     

    Thank you! 


  13. Howdy! 🙂

     

    I'm wondering if anyone could help me out with what I hopefully believe is a simple script edit to Victor's Materia script : https://victorenginescripts.wordpress.com/rpg-maker-vx-ace/materia-system/

     

    By default, the materia gains AP upon defeating foes. I'm hoping to change it so materia instead always have their total current AP equal to the equipped character's level.

     

    For example, if I have a BLAZE materia equipped to actor1 (LV.20), the materia's total AP would be set to 20. If I then swapped it to actor2 (LV.5), it would change it's total AP to 5. When not equipped to any actor, it would be set to 0 AP.

     

    I've made a couple small tweaks that, while I don't think any would affect the change to AP gain, I figured I should include just in case. 

     

    Spoiler
    
    #==============================================================================
    # ** Victor Engine - Materia System
    #------------------------------------------------------------------------------
    # Author : Victor Sant
    #
    # Aditional Credit :
    #   - Tamsynn/Apoclaydon (Commission requester)
    #
    # Version History:
    #  v 1.00 - 2012.11.01 > First relase
    #  v 1.01 - 2013.01.05 > Fixed Added Effect and Elemental Materia
    #  v 1.02 - 2013.02.13 > Compatibility with Passive States
    #------------------------------------------------------------------------------
    #  This script replicate the Materia system from FFVII. You can attch
    # 'materias' on the actor equipment to gain skills, status boost and varied
    # special effects.
    #------------------------------------------------------------------------------
    # Compatibility
    #   Requires the script 'Victor Engine - Basic Module' v 1.29 or higher
    #   If used with 'Victor Engine - Target Arrow' place this bellow it.
    #
    # * Overwrite methods
    #   class Window_MenuActor < Window_MenuStatus
    #     def select_for_item(item, for_all = false)
    #
    #   class Scene_ItemBase < Scene_MenuBase
    #     def determine_item
    #     def item_target_actors
    #
    # * Alias methods
    #   class << BattleManager
    #     def display_exp
    #
    #   class Game_Temp
    #     def initialize
    #
    #   class Game_Action
    #     def targets_for_opponents
    #     def targets_for_friends
    #
    #   class Game_BattlerBase
    #     def skill_mp_cost(skill)
    #     def skill_conditions_met?(skill)
    #
    #   class Game_Battler < Game_BattlerBase
    #     def use_item(item)
    #     def item_apply(user, item)
    #     def make_damage_value(user, item)
    #     def apply_guard(damage)
    #
    #   class Game_Actor < Game_Battler
    #     def setup(actor_id)
    #     def skills
    #     def param(param_id)
    #     def param_plus(param_id)
    #     def param_rate(param_id)
    #     def xparam(param_id)
    #     def sparam(param_id)
    #     def element_rate(id)
    #     def state_rate(id)
    #     def atk_elements
    #     def atk_states
    #     def atk_states_rate(id)
    #     def feature_objects
    #
    #   class Game_Party < Game_Unit
    #     def init_all_items
    #     def gain_item(item, amount, include_equip = false)
    #
    #   class Game_Interpreter
    #     def command_319
    #     def command_302
    #     def comment_call
    #
    #   class Window_MenuCommand < Window_Command
    #     def add_main_commands
    #
    #   class Window_SkillList < Window_Selectable
    #     def draw_skill_cost(rect, skill)
    #
    #   class Window_BattleLog < Window_Selectable
    #     def display_failure(target, item)
    #
    #   class Scene_Menu < Scene_MenuBase
    #     def create_command_window
    #     def on_personal_ok
    #
    #   class Scene_Equip < Scene_MenuBase
    #     def on_actor_change
    #
    #   class Scene_Battle < Scene_Base
    #     def on_skill_ok
    #     def battle_start
    #     def pre_terminate
    #
    #------------------------------------------------------------------------------
    # Instructions:
    #  To instal the script, open you script editor and paste this script on
    #  a new section bellow the Materials section. This script must also
    #  be bellow the script 'Victor Engine - Basic'
    #
    #------------------------------------------------------------------------------
    # Comment calls note tags:
    #  Tags to be used on the events comment box, works like a script call
    #
    #  <materia shop>
    #   Place this before calling the shop event command for materias
    #  
    #  <equip materia: actor, equip, slot, materia>
    #   Adds a materia on a specific slot of one actor.
    #     actor   : actor ID
    #     equip   : equip slot
    #     slot    : materia slot
    #     materia : materia ID
    #
    #  <unequip materia: actor, equip, slot>
    #   Remove the materia equiped on a specific slot of one actor.
    #     actor : actor id
    #     equip : equip slot
    #     slot  : materia slot
    #
    #  <drop materia: id, amount>
    #   Remove one materia with the selected id
    #     id     : materia id
    #     amount : amount removed
    #
    #------------------------------------------------------------------------------
    # Enemies note tags:
    #   Tags to be used on Enemies note boxes.
    #
    #  <ap: x>
    #   Ap given by the enemy upon defeat. If not set the value is equal the enemy
    #   EXP / 10
    #     x : Ap value
    #
    #------------------------------------------------------------------------------
    # Skills note tags:
    #   Tags to be used on the Skills note box in the database.
    #
    #  <negate cost>
    #   The skill will ignore the effects "Mp Cost: +x%" and "Mp Cost: -x%"
    #
    #  <negate damage>
    #   The skill will ignore the effects "Damage: +x%" and "Damage: -x%"
    #
    #  <negate absorb>
    #   The skill will ignore the effects "HP Absorb: x%" and "MP Absorb: x%"
    #
    #  <negate all>
    #   The skill will ignore the effects "All"
    #
    #------------------------------------------------------------------------------
    # Armors (Non-Materia) note tags:
    #   Tags to be used on the Weapons and non-materia Armors note box in the
    #   database. (Only for Armors tagged as Materia)
    # 
    #  <materia slots: slots>
    #   Setup the materia slots.
    #     slots : slots setup, you must add a 0 for each slot, slots can be linked
    #             using =. Correct White spacing is very important for the setup.
    #     Ex.: <materia slots: 0 0 0>     # Materia with 3 single slots
    #          <materia slots: 0=0 0=0 0> # Materia with 2 paired slots and 1 single
    #
    #  <materia growth: x>
    #   Materia growth multiplier for materias equiped on this equip.
    #     x : muliplier, can be decimal.
    #     Obs.: Equiment with growth 0 will use a diffetent icon for the slots
    #
    #------------------------------------------------------------------------------
    # Armors (Materia) note tags:
    #   Tags to be used on the Armors note box in the database. (Only for Armors
    #   tagged as Materia)
    #
    #  <materia type: x>
    #   This tag define the armor as a materia. 
    #     x : type. Can be either Support, Independet or Magic
    #        Support     : materias that can have special effects when paired
    #        Magic       : materias that receive bonus when paired with support
    #        Independent : materias that don't gain any bonus for being paired
    #
    #  <ap list: x>
    #  <ap list: x, x>
    #   The list of AP needed for the materia to level up. This also set the
    #   materia max level. Each value added increase the max level by 1.
    #     x : AP for next level
    #
    #  <level icon: x>
    #   Setup the icon that will be used to represent the level of the materia
    #     x : icon index
    #
    #  <master value: x>
    #   Price that the materia can be sold when reach the max level (master)
    #     x : price
    #
    #  <limited use>
    #   Materias with this tag can be used one time for each level per battle
    #
    #  <stats: stat: +x%>              <stats: stat: -x%>
    #  <stats: stat: +x%, stat: +x%>   <stats: stat: -x%, stat: -x%>
    #   Setup % change values for the stats. These values don't change with materia
    #   level
    #     stat : stat name (HP, MP, Atk, Def, Mat, Mdf, Agi, Luk)
    #     x    : value change
    #
    #  <elements: x>
    #  <elements: x, x>
    #   Tag elements for the materia, these elements have effect when the materia
    #   is paired with support materia with "Elemental" effect
    #     x : elements IDs
    #
    #  <states: x>
    #  <states: x, x>
    #   Tag statea for the materia, these states have effect when the materia
    #   is paired with support materia with "Added Effect" effect
    #     x : states IDs
    #
    #  <effect name: x>
    #   By default, the materia info display a list of values for the materia 
    #   effects, using this tag you can use a custom name for info display
    #     x : effect name
    #
    #  <skills: level: x>
    #  <skills: level: x, level: x>
    #   skills granted by the materia.
    #     level : level that the materia must be to grant the skill
    #     x     : skill id
    #
    #  <effects: x>  
    #  <effects: x, x>
    #   This tag allows to add special effects for the materia. These effects
    #   vary a lot, and some are based on the materia level.
    #     x : effect
    #      Stat: +x%   : Increase a param, sparam or xparam by x% for each level
    #      Stat: -x%   : Decrease a param, sparam or xparam by x% for each level
    #      Damage: +x% : Increase skill damage x% for each level
    #      Damage: -x% : Decrease skill damage x% for each level
    #      Hp Mp       : Invert the HP and MP values
    #      Enemy Skill : Change the materia setup to use "Enemy Skill"
    #
    #    - Only for Support materia, affects paired materia skills
    #      Mp Cost: +x%   : Increase Mp Cost for x% for each level
    #      Mp Cost: -x%   : Decrease Mp Cost for x% for each level
    #      Hp Absorb: x%  : Absorb Hp x% of the damage dealt for each level
    #      Mp Absorb: x%  : Absorb Mp x% of the damage dealt for each level
    #      All            : Skill affect all targets per use for each level
    #      Elemental: +x% : Increase element resistance by x% for each level
    #      Elemental: -x% : Decrease element resistance by x% for each level
    #      Added Effect: +x% : Increase state effect by x% for each level
    #      Added Effect: -x% : Decrease state effect by x% for each level
    #
    #------------------------------------------------------------------------------
    # Additional instructions:
    #
    #  Materias are setup using Armors slots from the database, all stats bonus
    #  and traits you setup on the armor that will be used as a materia works
    #  normally.
    #
    #  The first step to setup the materia is to define it's tipe with the
    #  tag <materia type: x>, the main difference between each type is how
    #  they interact with paired slots. The types are Magic, Support and
    #  Independent
    #  There's no Summon or Command types, since mechanically both works like
    #  magic materias.
    #   
    #  The tag <stats: stat: +x%> <stats: stat: -x%> allows you to setup % changes
    #  on the status. Fixed values can be set on the database itself.
    #
    #  Elements set with the tag <elements: x> have effect when paired with 
    #  support materias with the 'Elemental' effect. The effect will change
    #  depending on the equipment that the pair is set. If it's on a weapon
    #  the attacks will gain elemental damage, if it's on a armor the actor
    #  will gain elemental resistance based on the materia level.
    #
    #  States set with the <states: x> works like the elements: when added to
    #  a weapon, the attacks will gain a chance of inflicting the state, when
    #  added to armors, it will change the state resist.
    #
    #  Materias can grant skills using the tag <skills: level: x> based on the
    #  current materia level. The skills becomes avaiable as soon the materia
    #  reach the min level needed, and are removed if the materia is removed.
    #
    #  The effects <effects: x> is the most complex settings, it's have a high
    #  number of possible effects. 
    #  The Stat: +x% and Stat: -x% effects allows to add any param, sparam or
    #  xparam. The value is based on the materia level.
    #  so if you setup a effect CNT: +10% and the materia is at level 3, the
    #  actor will gain 30% counter attack rate.
    #  Some effects works only with paired support materias.
    #
    #  The Enemy Skill Effect is a very special effect. A materia with this effect
    #  allows the actor to learn the skills when hit by one of the skills that
    #  this materia can give. The materia don't level up with AP, but instead
    #  gain 1 level for each skill learned. When setting up the skills, you
    #  still need to add a level for them, but the values are arbritary and
    #  is used only to sort the skills.
    #
    #  You can edit the materia related texts on the module Vocab withing the script
    #
    #------------------------------------------------------------------------------
    # Examples:
    #
    # Fire
    #  <materia type: Magic>
    #  <level icon: 547>
    #  <master value: 42000>
    #  <elements: 3>
    #  <ap list: 2000, 18000, 35000>
    #  <stats: hp: -2%, mp: +2%>
    #  <skills: 1: 51, 2: 53, 3: 52, 4: 54>
    #
    # MP Turbo
    #  <materia type: Support>
    #  <level icon: 550>
    #  <master value: 1>
    #  <effect name: MP Turbo>
    #  <effects: MP Cost: +10%, Damage: +10%>
    #  <ap list: 10000, 30000, 60000, 120000>
    #
    # Enemy Skill
    #  <materia type: Command>
    #  <level icon: 548>
    #  <master value: 1>
    #  <effects: Enemy Skill>
    #  <skills: 1: 8, 2: 9, 3: 10, 4: 11, 5: 12, 6: 13, 7: 14, 8: 15,
    #  9: 16, 10: 17, 11: 18, 12: 19, 13: 20, 14: 21, 15: 22, 16: 23>
    #
    #==============================================================================
    
    #==============================================================================
    # ** Victor Engine
    #------------------------------------------------------------------------------
    #   Setting module for the Victor Engine
    #==============================================================================
    
    module Victor_Engine
      #--------------------------------------------------------------------------
      # * Max materia number
      #   The max ammount of materias that the player can keep, leave nil for
      #   no limit. Be aware that if the player have 300 or more materia 
      #   there might be freezes when opening the materia menus
      #--------------------------------------------------------------------------
      Max_Materia_Number = 255
      #--------------------------------------------------------------------------
      # * Max slot number
      #   Max number of slots for equipment
      #--------------------------------------------------------------------------
      Max_Slot_Number    = 8
      #--------------------------------------------------------------------------
      # * Materia Brreding
      #   If true the player will gain a new level 1 materia when a materia
      #   reach the max level
      #--------------------------------------------------------------------------
      Materia_Breeding  = false
      #--------------------------------------------------------------------------
      # * Icons setup
      #   Default icons for materia slots
      #--------------------------------------------------------------------------
      Slot_Icon_Normal   = 6927
      Slot_Icon_Nothing  = 0
      Slot_Link_Icon     = 592
      Materia_Level_Icon = 6025
      #--------------------------------------------------------------------------
      # * required
      #   This method checks for the existance of the basic module and other
      #   VE scripts required for this script to work, don't edit this
      #--------------------------------------------------------------------------
      def self.required(name, req, version, type = nil)
        if !$imported[:ve_basic_module]
          msg = "The script '%s' requires the script\n"
          msg += "'VE - Basic Module' v%s or higher above it to work properly\n"
          msg += "Go to http://victorenginescripts.wordpress.com/ to download this script."
          msgbox(sprintf(msg, self.script_name(name), version))
          exit
        else
          self.required_script(name, req, version, type)
        end
      end
      #--------------------------------------------------------------------------
      # * script_name
      #   Get the script name base on the imported value
      #--------------------------------------------------------------------------
      def self.script_name(name, ext = "VE")
        name = name.to_s.gsub("_", " ").upcase.split
        name.collect! {|char| char == ext ? "#{char} -" : char.capitalize }
        name.join(" ")
      end
    end
    
    $imported ||= {}
    $imported[:ve_materia_system] = 1.02
    Victor_Engine.required(:ve_materia_system, :ve_basic_module, 1.29, :above)
    
    #==============================================================================
    # ** Vocab
    #------------------------------------------------------------------------------
    #  This module defines terms and messages. It defines some data as constant
    # variables. Terms in the database are obtained from $data_system.
    #==============================================================================
    
    module Vocab
    
      # Materia menu options
      VE_MateriaMenu = "Wisps"
      
      # Message displayed when learning Enemies Skills
      VE_EnemySkill  = "%s learend %s"
      
      # AP stat name
      VE_ApName      = "AP"
      
      # AP received message on battle end
      VE_ApReceived  = "%s AP received!"
      
      # Max level materia text
      VE_MasterText  = "Mastered!"
      
    end
    
    #==============================================================================
    # ** RPG::Skill
    #------------------------------------------------------------------------------
    #  This is the data class for skills.
    #==============================================================================
    
    class RPG::Skill < RPG::UsableItem
      #--------------------------------------------------------------------------
      # * New method: cost?
      #--------------------------------------------------------------------------
      def cost?(id)
        @id == id && !(note =~ /<NEGATE COST>/i)
      end 
      #--------------------------------------------------------------------------
      # * New method: damage?
      #--------------------------------------------------------------------------
      def damage?(id)
        @id == id && !(note =~ /<NEGATE DAMAGE>/i)
      end 
      #--------------------------------------------------------------------------
      # * New method: absorb?
      #--------------------------------------------------------------------------
      def absorb?(id)
        @id == id && !(note =~ /<NEGATE ABSORB>/i)
      end
      #--------------------------------------------------------------------------
      # * New method: all?
      #--------------------------------------------------------------------------
      def all?
        for_one? && !(note =~ /<NEGATE ALL>/i)
      end
    end
    
    #==============================================================================
    # ** RPG::UsableItem
    #------------------------------------------------------------------------------
    #  This is the superclass for skills and items.
    #==============================================================================
    
    class RPG::UsableItem < RPG::BaseItem
      #--------------------------------------------------------------------------
      # * New method: all?
      #--------------------------------------------------------------------------
      def all?
        return false
      end
      #--------------------------------------------------------------------------
      # * New method: materia?
      #--------------------------------------------------------------------------
      def materia?
        return false
      end
    end
    
    #==============================================================================
    # ** RPG::EquipItem
    #------------------------------------------------------------------------------
    #  This is the superclass of weapons and armor.
    #==============================================================================
    
    class RPG::EquipItem < RPG::BaseItem
      #--------------------------------------------------------------------------
      # * New method: materia?
      #--------------------------------------------------------------------------
      def materia?
        return false
      end
      #--------------------------------------------------------------------------
      # * New method: growth
      #--------------------------------------------------------------------------
      def growth
        return @growth if @growth
        @growth = note =~ /<MATERIA GROWTH: (\d+)>/i ? $1.to_f : 1
      end
      #--------------------------------------------------------------------------
      # * New method: nothing?
      #--------------------------------------------------------------------------
      def nothing?
        growth == 0
      end
      #--------------------------------------------------------------------------
      # * New method: double_slots
      #--------------------------------------------------------------------------
      def double_slots
        return @double_slots if @double_slots
        list = note =~ /<MATERIA SLOTS: ([ 0o=]*)>/i ? $1.dup : ""
        @double_slots = list.scan(/[0o]=[0o]/i).size * 2
      end
      #--------------------------------------------------------------------------
      # * New method: single_slots
      #--------------------------------------------------------------------------
      def single_slots
        return @single_slots if @single_slots
    list   = note =~ /<MATERIA SLOTS: ([ 0o=]*)>/i ? $1.dup : ""
    @single_slots = [list.scan(/[0o]/i).size - double_slots,2].max
    #$# @single_slots = list.scan(/[0o]/i).size - double_slots 
    # Edited to give ALL weapons a min of 3 wisp equip slots. 
    # Can be overwritten just fine with a note tag.
    # Does NOT require either scriptlet, if not using Vlue unique item script.
      end
      #--------------------------------------------------------------------------
      # * New method: slots
      #--------------------------------------------------------------------------
      def slots
        double_slots + single_slots
      end
    end
    
    #==============================================================================
    # ** RPG::Armor
    #------------------------------------------------------------------------------
    #  The data class for armor.
    #==============================================================================
    
    class RPG::Armor < RPG::EquipItem
      #--------------------------------------------------------------------------
      # * Public Instance Variables
      #--------------------------------------------------------------------------
      attr_accessor :ap
      attr_accessor :times
      attr_accessor :limit
      attr_reader   :type
      attr_reader   :stats
      attr_reader   :learn
      attr_reader   :skills
      attr_reader   :states
      attr_reader   :master
      attr_reader   :elements
      attr_reader   :effects
      #--------------------------------------------------------------------------
      # * New method: materia?
      #--------------------------------------------------------------------------
      def materia?
        note =~ /<MATERIA TYPE: (\w+)>/i
      end
      #--------------------------------------------------------------------------
      # * New method: setup_materia
      #--------------------------------------------------------------------------
      def setup_materia
        setup_base
        setup_type
        setup_name
        setup_price
        setup_stats
        setup_skills
        setup_states
        setup_elements
        setup_effects
        setup_limit
        self
      end
      #--------------------------------------------------------------------------
      # * New method: setup_base
      #--------------------------------------------------------------------------
      def setup_base
        @ap    ||= 0#0 #$#$game_variables[198]
        @times ||= 1
        @level ||= 0
        @learn ||= {}
        @ap_list = setup_lists("AP LIST", [0])
      end
      #--------------------------------------------------------------------------
      # * New method: setup_states
      #--------------------------------------------------------------------------
      def setup_states
        @states = setup_lists("STATES")
      end
      #--------------------------------------------------------------------------
      # * New method: setup_elements
      #--------------------------------------------------------------------------
      def setup_elements
        @elements = setup_lists("ELEMENTS") 
      end
      #--------------------------------------------------------------------------
      # * New method: setup_type
      #--------------------------------------------------------------------------
      def setup_type
        @type = note =~ /<MATERIA TYPE: (\w+)>/i ? $1.upcase : "MAGIC"
      end
      #--------------------------------------------------------------------------
      # * New method: setup_name
      #--------------------------------------------------------------------------
      def setup_name
        @effect_name = note =~ /<EFFECT NAME: ([\w\s.,;]+)>/i ? $1.to_s : nil
      end
      #--------------------------------------------------------------------------
      # * New method: setup_price
      #--------------------------------------------------------------------------
      def setup_price
        @master = note =~ /<MASTER VALUE: (\d+)>/i ? $1.to_i : price * 10
      end
      #--------------------------------------------------------------------------
      # * New method: setup_limit
      #--------------------------------------------------------------------------
      def setup_limit
        @limited = note =~ /<LIMITED USE>/i ? true : false
        @limit   = {}
        @skills.values.each {|i| @limit[i] = level }
      end
      #--------------------------------------------------------------------------
      # * New method: setup_stats
      #--------------------------------------------------------------------------
      def setup_stats
        @stats = {}
        values = note =~ /<STATS:\s([\w\s\+\-:%,;]+)>/i ? $1.dup : ""
        regexp = /(\w+):\s*([+-]?\d+)%/i
        values.scan(regexp).each {|x, y| @stats[get_param_id(x)] = y.to_i }
      end
      #--------------------------------------------------------------------------
      # * New method: setup_skills
      #--------------------------------------------------------------------------
      def setup_skills
        @skills = {}
        values  = note =~ /<SKILLS:\s([\d\s\:,;]+)>/i ? $1.dup : ""
        values.scan(/(\d+):\s*(\d+)/i).each {|x, y| @skills[x.to_i] = y.to_i }
      end
      #--------------------------------------------------------------------------
      # * New method: setup_effects
      #--------------------------------------------------------------------------
      def setup_effects
        values   = note =~ /<EFFECTS:\s([\w\s\+\-:%,;]+)>/i ? $1.dup : ""
        @effects = values.scan(/[\w\s\+\-\:\%]*/i).inject({}) do |r, i|
          if i =~ /([\w\s]+)(?:: *([+-]?\d+)%?)?/i
            r[make_symbol($1)] = $2 ? $2.to_i / 100.0 : true
          end
          r
        end
        @effects.default = 0
      end
      #--------------------------------------------------------------------------
      # * New method: elements?
      #--------------------------------------------------------------------------
      def setup_lists(type, base = [])
        values = note =~ /<#{type}: ([\d\s;,]+)>/i ? $1.dup : ""
        values.scan(/\d+/i).inject(base) { |r, i| r.push(i.to_i) }
      end
      #--------------------------------------------------------------------------
      # * New method: 
      #--------------------------------------------------------------------------
      def elements?(elements)
        @elements.include?(elements)
      end
      #--------------------------------------------------------------------------
      # * New method: states?
      #--------------------------------------------------------------------------
      def states?(states)
        @states.include?(states)
      end
      #--------------------------------------------------------------------------
      # * New method: effect?
      #--------------------------------------------------------------------------
      def effect?(effect)
        @effects.keys.include?(effect)
      end
      #--------------------------------------------------------------------------
      # * New method: effect
      #--------------------------------------------------------------------------
      def effect(value)
        @effects[value]
      end
      #--------------------------------------------------------------------------
      # * New method: ap=     
      #--------------------------------------------------------------------------
      def ap=(n)
        @ap = [n, @ap_list.last].min
      end
      #--------------------------------------------------------------------------
      # * New method: level
      #--------------------------------------------------------------------------
      def level
        max_level.times {|i| break @level += 1 if level_up? }
        enemy_skill? ? @learn.values.size : @level
      end
      #--------------------------------------------------------------------------
      # * New method: max_level
      #--------------------------------------------------------------------------
      def max_level
        enemy_skill? ? @skills.size : @ap_list.size
      end
      #--------------------------------------------------------------------------
      # * New method: level_up?
      #--------------------------------------------------------------------------
      def level_up?
        @ap >= next_level && @level < max_level
      end
      #--------------------------------------------------------------------------
      # * New method: master?
      #--------------------------------------------------------------------------
      def master?
        level == max_level
      end
      #--------------------------------------------------------------------------
      # * New method: next_level
      #--------------------------------------------------------------------------
      def next_level
        @level.times.inject([0]) {|r, i| r + [@ap_list[i + 1]] }.sum
      end
      #--------------------------------------------------------------------------
      # * New method: stat
      #--------------------------------------------------------------------------
      def stat(i)
        @stats[i] ? @stats[i] : 0
      end
      #--------------------------------------------------------------------------
      # * New method: reset_times
      #--------------------------------------------------------------------------
      def reset_times
        @times = level
        setup_limit
      end
      #--------------------------------------------------------------------------
      # * New method: sell_price
      #--------------------------------------------------------------------------
      def sell_price
        base = (price / 2)
        var  = @master - base
        rate = [@ap * 100 / [@ap_list.sum, 1].max, 100].min
        @master <= price ? @master : [((var * rate) / 100) + base, 0].max
      end
      #--------------------------------------------------------------------------
      # * New method: gain_ap
      #--------------------------------------------------------------------------
      def gain_ap(n, growth)
        old_level = level
        @ap += (n * growth).to_i
        if Materia_Breeding && old_level < max_level && level == max_level
          $game_party.gain_materia($data_armors[@id])
        end
      end
      #--------------------------------------------------------------------------
      # * New method: level_icon
      #--------------------------------------------------------------------------
      def level_icon
        note =~ /<LEVEL ICON: (\d+)>/i ? $1.to_i : Materia_Level_Icon
      end
      #--------------------------------------------------------------------------
      # * New method: level_value
      #--------------------------------------------------------------------------
      def level_value(value)
        level * effect(value)
      end
      #--------------------------------------------------------------------------
      # * New method: support?
      #--------------------------------------------------------------------------
      def support?
        @type == "SUPPORT"
      end
      #--------------------------------------------------------------------------
      # * New method: independent?
      #--------------------------------------------------------------------------
      def independent?
        @type == "INDEPENDENT"
      end
      #--------------------------------------------------------------------------
      # * New method: effect_name
      #--------------------------------------------------------------------------
      def effect_name
        @effect_name
      end
      #--------------------------------------------------------------------------
      # * New method: cost?
      #--------------------------------------------------------------------------
      def cost?(skill)
        !support? && skill?(skill) && effect?(:mp_cost)
      end
      #--------------------------------------------------------------------------
      # * New method: damage?
      #--------------------------------------------------------------------------
      def damage?(skill)
        !support? && skill?(skill) && effect?(:damage)
      end
      #--------------------------------------------------------------------------
      # * New method: skill?
      #--------------------------------------------------------------------------
      def skill?(id)
        @skills.values.include?(id)
      end
      #--------------------------------------------------------------------------
      # * New method: all?
      #--------------------------------------------------------------------------
      def all?
        effect?(:all) && @times > 0
      end
      #--------------------------------------------------------------------------
      # * New method: enemy_skill?
      #--------------------------------------------------------------------------
      def enemy_skill?
        effect?(:enemy_skill)
      end
      #--------------------------------------------------------------------------
      # * New method: on_limit?
      #--------------------------------------------------------------------------
      def on_limit?(id)
        !limited? || (@limit[id] && @limit[id] > 0)
      end
      #--------------------------------------------------------------------------
      # * New method: limited?
      #--------------------------------------------------------------------------
      def limited?
        @limited
      end
      #--------------------------------------------------------------------------
      # * New method: learn_enemy_skill
      #--------------------------------------------------------------------------
      def learn_enemy_skill(id)
        if skill?(id) && !@learn.values.include?(id)
          @skills.keys.each {|i| @learn[i] = @skills[i] if @skills[i] == id }
        end
      end
      #--------------------------------------------------------------------------
      # * New method: learned_enemy_skill?
      #--------------------------------------------------------------------------
      def learned_enemy_skill?(id)
        @learn.values.include?(id)
      end
    end
    
    #==============================================================================
    # ** BattleManager
    #------------------------------------------------------------------------------
    #  This module manages battle progress.
    #==============================================================================
    
    class << BattleManager
      #--------------------------------------------------------------------------
      # * Alias method: display_exp
      #--------------------------------------------------------------------------
      alias :display_exp_ve_materia_system :display_exp
      def display_exp
        display_exp_ve_materia_system
        display_ap
      end
      #--------------------------------------------------------------------------
      # * New method: display_ap
      #--------------------------------------------------------------------------
      def display_ap
        return if $game_troop.ap_total == 0
        text = sprintf(Vocab::VE_ApReceived, $game_troop.ap_total)
        $game_message.add('\.' + text)
        $game_party.all_members.each {|actor| actor.ap += $game_troop.ap_total }
      end
    end
    
    #==============================================================================
    # ** Game_Temp
    #------------------------------------------------------------------------------
    #  This class handles temporary data that is not included with save data.
    # The instance of this class is referenced by $game_temp.
    #==============================================================================
    
    class Game_Temp
      #--------------------------------------------------------------------------
      # * Public Instance Variables
      #--------------------------------------------------------------------------
      attr_accessor :materia_shop
      #--------------------------------------------------------------------------
      # * Alias method: initialize
      #--------------------------------------------------------------------------
      alias :initialize_ve_materia_system :initialize
      def initialize
        initialize_ve_materia_system
        @materia_shop = false
      end
    end
    
    #==============================================================================
    # ** Game_Action
    #------------------------------------------------------------------------------
    #  This class handles battle actions. This class is used within the
    # Game_Battler class.
    #==============================================================================
    
    class Game_Action
      #--------------------------------------------------------------------------
      # * Alias method: targets_for_opponents
      #--------------------------------------------------------------------------
      alias :targets_for_opponents_ve_materia_system :targets_for_opponents
      def targets_for_opponents
        if @subject.actor? && item.all? && for_all?(item)
          return opponents_unit.alive_members
        end
        targets_for_opponents_ve_materia_system
      end
      #--------------------------------------------------------------------------
      # * Alias method: targets_for_friends
      #--------------------------------------------------------------------------
      alias :targets_for_friends_ve_materia_system :targets_for_friends
      def targets_for_friends
        if @subject.actor? && item.all? && for_all?(item)
          return friends_unit.alive_members if item.for_friend?
          return friends_unit.dead_members  if item.fitem.for_dead_friend?
        end
        targets_for_friends_ve_materia_system
      end
      #--------------------------------------------------------------------------
      # * New method: for_all?
      #--------------------------------------------------------------------------
      def for_all?(item)
        @subject.paired_materia.each do |pair|
          if pair[:main].all? && pair[:other].skill?(item.id)
            pair[:main].times -= 1
            return true
          end
        end
        return false    
      end
    end
    
    #==============================================================================
    # ** Game_BattlerBase
    #------------------------------------------------------------------------------
    #  This class handles battlers. It's used as a superclass of the Game_Battler
    # classes.
    #==============================================================================
    
    class Game_BattlerBase
      #--------------------------------------------------------------------------
      # * Alias method: skill_mp_cost
      #--------------------------------------------------------------------------
      alias :skill_mp_cost_ve_materia_system :skill_mp_cost
      def skill_mp_cost(skill)
        cost = skill_mp_cost_ve_materia_system(skill)
        cost += cost_change_materia(skill, cost, :plus) if actor?
        cost -= cost_change_materia(skill, cost, :cut)  if actor?
        cost.to_i
      end
      #--------------------------------------------------------------------------
      # * Alias method: skill_conditions_met?
      #--------------------------------------------------------------------------
      alias :skill_conditions_met_ve_materia_system? :skill_conditions_met?
      def skill_conditions_met?(skill)
        skill_conditions_met_ve_materia_system?(skill) &&
        materia_conditions_met?(skill.id)
      end
      #--------------------------------------------------------------------------
      # * New method: cost_change_materia
      #--------------------------------------------------------------------------
      def cost_change_materia(skill, cost, type)
        list = paired_materia.inject([0]) do |r, pair|
          m  = pair[:main]
          o  = pair[:other]
          r + [pair_change_cost(m, o, cost, skill.id, type)]
        end
        list.max
      end
      #--------------------------------------------------------------------------
      # * New method: pair_change_cost
      #--------------------------------------------------------------------------
      def pair_change_cost(m, o, cost, id, type)
        return 0 unless m.effect?(:mp_cost)
        list = o.skills.values.inject([0]) do |r, i|
          value = m.level_value(:mp_cost).abs
          r + (id == i && valid_cost_type?(value, type) ? [value] : [])
        end
        cost * list.compact.max
      end
      #--------------------------------------------------------------------------
      # * New method: valid_cost_type?
      #--------------------------------------------------------------------------
      def valid_cost_type?(value, type)
        value > 0 && type == :plus || value < 0 && type == :cut
      end
      #--------------------------------------------------------------------------
      # * New method: materia_conditions_met?
      #--------------------------------------------------------------------------
      def materia_conditions_met?(id)
        return true
      end
    end
    
    #==============================================================================
    # ** Game_Battler
    #------------------------------------------------------------------------------
    #  This class deals with battlers. It's used as a superclass of the Game_Actor
    # and Game_Enemy classes.
    #==============================================================================
    
    class Game_Battler < Game_BattlerBase
      #--------------------------------------------------------------------------
      # * Alias method: use_item
      #--------------------------------------------------------------------------
      alias :use_item_ve_materia_system :use_item
      def use_item(item)
        materia_use_item(item.id) if actor? && item.is_a?(RPG::Skill)
        use_item_ve_materia_system(item)
      end
      #--------------------------------------------------------------------------
      # * Alias method: item_apply
      #--------------------------------------------------------------------------
      alias :item_apply_ve_materia_system :item_apply
      def item_apply(user, item)
        learn_enemy_skill(item.id) if actor?
        item_apply_ve_materia_system(user, item)
      end
      #--------------------------------------------------------------------------
      # * Alias method: make_damage_value
      #--------------------------------------------------------------------------
      alias :make_damage_value_ve_materia_system :make_damage_value
      def make_damage_value(user, item)
        @materia_user = user
        make_damage_value_ve_materia_system(user, item)
      end
      #--------------------------------------------------------------------------
      # * Alias method: apply_guard
      #--------------------------------------------------------------------------
      alias :apply_guard_ve_materia_system :apply_guard
      def apply_guard(damage)
        result = apply_guard_ve_materia_system(damage)
        @materia_user.actor? ? materia_damage(@materia_user, result) : result
      end
      #--------------------------------------------------------------------------
      # * New method: materia_use_item
      #--------------------------------------------------------------------------
      def materia_use_item(id)
        all_materias.each {|m| m.limit[id] -= 1 if m.limited? && m.on_limit?(id) }
      end
      #--------------------------------------------------------------------------
      # * New method: learn_enemy_skill
      #--------------------------------------------------------------------------
      def learn_enemy_skill(id)
        all_materias.each do |m|
          if m.enemy_skill? && m.skill?(id) && !m.learned_enemy_skill?(id)
            @learned_enemy_skill = id
            m.learn_enemy_skill(id)
            update_materia_skills
          end
        end
      end
      #--------------------------------------------------------------------------
      # * New method: materia_damage
      #--------------------------------------------------------------------------
      def materia_damage(user, damage)
        obj = user.current_action ? user.current_action.item : nil
        return damage if damage == 0 || !obj || !obj.is_a?(RPG::Skill)
        damage += damage_plus(damage, user, obj)
        damage += damage_pair(damage, user, obj)
        materia_absorb(damage, user, obj)
        damage.to_i
      end
      #--------------------------------------------------------------------------
      # * New method: damage_plus
      #--------------------------------------------------------------------------
      def damage_plus(damage, user, skill)
        user.all_materias.inject(0) do |r, m|
          r + (m.damage?(skill.id) ? (damage * m.level_value(:damage)).to_i : 0)
        end
      end
      #--------------------------------------------------------------------------
      # * New method: damage_pair
      #--------------------------------------------------------------------------
      def damage_pair(damage, user, skill)
        user.paired_materia.inject(0) do |r, pair|
          m = pair[:main]
          o = pair[:other]
          r + (m.effect?(:damage) ? pair_damage(m, o, damage, skill.id) : 0)
        end
      end
      #--------------------------------------------------------------------------
      # * New method: pair_damage
      #--------------------------------------------------------------------------
      def pair_damage(m, o, damage, id)
        o.skills.values.compact.inject(0) do |r, i|
          mskill = $data_skills[i]
          r + (mskill.damage?(id) ? (damage * m.level_value(:damage)).to_i : 0)
        end
      end
      #--------------------------------------------------------------------------
      # * New method: materia_absorb
      #--------------------------------------------------------------------------
      def materia_absorb(damage, user, skill)
        user.paired_materia.each do |pair|
          m = pair[:main]
          o = pair[:other]
          pair_absorb(user, m, o, damage, skill, "HP")
          pair_absorb(user, m, o, damage, skill, "MP")
        end
      end
      #--------------------------------------------------------------------------
      # * New method: pair_absorb
      #--------------------------------------------------------------------------
      def pair_absorb(user, m, o, damage, skill, type)
        o.skills.values.compact.each do |id|
          mskill = $data_skills[id]
          next unless mskill.absorb?(skill.id) 
          result = (damage * m.level_value(make_symbol("#{type} ABSORB"))).to_i
          type == "HP" ? user.hp += [result, user.mhp - result].min : 
                         user.mp += [result, user.mmp - result].min
        end
      end
    end
    
    #==============================================================================
    # ** Game_Actor
    #------------------------------------------------------------------------------
    #  This class handles actors. It's used within the Game_Actors class
    # ($game_actors) and referenced by the Game_Party class ($game_party).
    #==============================================================================
    
    class Game_Actor < Game_Battler
      #--------------------------------------------------------------------------
      # * Public Instance Variables
      #--------------------------------------------------------------------------
      attr_accessor :materia_slots
      attr_accessor :learned_enemy_skill
      attr_accessor :ap
      #--------------------------------------------------------------------------
      # * Alias method: setup
      #--------------------------------------------------------------------------
      alias :setup_ve_materia_system :setup
      def setup(actor_id)
        setup_materia_system
        setup_ve_materia_system(actor_id)
        start_materia_slots
      end
      #--------------------------------------------------------------------------
      # * Alias method: skills
      #--------------------------------------------------------------------------
      alias :skills_ve_materia_system :skills
      def skills
        update_materia_skills
        skills_ve_materia_system
      end
      #--------------------------------------------------------------------------
      # * Alias method: param
      #--------------------------------------------------------------------------
      alias :param_ve_materia_system :param
      def param(param_id)
        new_id = hp_mp_check(param_id)
        param_ve_materia_system(new_id)
      end
      #--------------------------------------------------------------------------
      # * Alias method: param_plus
      #--------------------------------------------------------------------------
      alias :param_plus_ve_materia_system :param_plus
      def param_plus(param_id)
        result = param_plus_ve_materia_system(param_id)
        all_materias.inject(result) {|r, item| r += item.params[param_id] }
      end
      #--------------------------------------------------------------------------
      # * Alias method: param_rate
      #--------------------------------------------------------------------------
      alias :param_rate_ve_materia_system :param_rate
      def param_rate(param_id)
        result = param_rate_ve_materia_system(param_id)
        result + materia_param(param_id)
      end
      #--------------------------------------------------------------------------
      # * Alias method: xparam
      #--------------------------------------------------------------------------
      alias :xparam_ve_materia_system :xparam
      def xparam(param_id)
        result = xparam_ve_materia_system(param_id)
        result + materia_xparam(param_id)
      end
      #--------------------------------------------------------------------------
      # * Alias method: sparam
      #--------------------------------------------------------------------------
      alias :sparam_ve_materia_system :sparam
      def sparam(param_id)
        result = sparam_ve_materia_system(param_id)
        result + materia_sparam(param_id)
      end  
      #--------------------------------------------------------------------------
      # * Alias method: element_rate
      #--------------------------------------------------------------------------
      alias :element_rate_ve_materia_system :element_rate
      def element_rate(id)
        element_rate_ve_materia_system(id) + materia_element_rate(id)
      end
      #--------------------------------------------------------------------------
      # * Alias method: state_rate
      #--------------------------------------------------------------------------
      alias :state_rate_ve_materia_system :state_rate
      def state_rate(id)
        state_rate_ve_materia_system(id) + materia_state_rate(id)
      end
      #--------------------------------------------------------------------------
      # * Alias method: atk_elements
      #--------------------------------------------------------------------------
      alias :atk_elements_ve_materia_system :atk_elements
      def atk_elements
        result = atk_elements_ve_materia_system
        materia_atk_elements(result).compact.uniq
      end
      #--------------------------------------------------------------------------
      # * Alias method: atk_states
      #--------------------------------------------------------------------------
      alias :atk_states_ve_materia_system :atk_states
      def atk_states
        result = atk_states_ve_materia_system
        materia_atk_states(result).compact.uniq
      end
      #--------------------------------------------------------------------------
      # * Alias method: atk_states_rate
      #--------------------------------------------------------------------------
      alias :atk_states_rate_ve_materia_system :atk_states_rate
      def atk_states_rate(id)
        atk_states_rate_ve_materia_system(id) + materia_atk_states_rate(id)
      end
      #--------------------------------------------------------------------------
      # * Alias method: feature_objects
      #--------------------------------------------------------------------------
      alias :feature_objects_ve_materia_system :feature_objects
      def feature_objects
        feature_objects_ve_materia_system + all_materias
      end
      #--------------------------------------------------------------------------
      # * New method: setup_materia_system
      #--------------------------------------------------------------------------
      def setup_materia_system
        @materia_slots  = {}
        @materia_skills = []
        @paired_materia = []
      end
      #--------------------------------------------------------------------------
      # * New method: start_materia_slots
      #--------------------------------------------------------------------------
      def start_materia_slots
        equip_slots.size.times do |i| 
          @materia_slots[i] = equips[i] ? Array.new(equips[i].slots, nil) : []
        end
        setup_old_equips
      end
      #--------------------------------------------------------------------------
      # * New method: setup_equipments
      #--------------------------------------------------------------------------
      def setup_equipments
        equip_slots.size.times {|i| setup_materia_slots(i) }
        setup_old_equips
      end
      #--------------------------------------------------------------------------
      # * New method: setup_materia_slots
      #--------------------------------------------------------------------------
      def setup_materia_slots(i)
        return if @equips[i].object == @old_equips[i].object
        @materia_slots[i].compact.each {|m| $game_party.gain_materia(m) }
        @materia_slots[i] = equips[i] ? Array.new(equips[i].slots, nil) : []
      end
      #--------------------------------------------------------------------------
      # * New method: setup_old_equips
      #--------------------------------------------------------------------------
      def setup_old_equips
        @old_equips = @equips.collect {|item| item.clone }
      end
      #--------------------------------------------------------------------------
      # * New method: materia_param
      #--------------------------------------------------------------------------
      def materia_param(id)
        all_materias.inject(0.0) do |r, m|
          r += m.stat(id) / 100.0
          r += m.level * materia_param_plus(m, id)
        end
      end
      #--------------------------------------------------------------------------
      # * New method: materia_param_plus
      #--------------------------------------------------------------------------
      def materia_param_plus(m, id)
        m.effect(make_symbol(get_param_text(id)))
      end
      #--------------------------------------------------------------------------
      # * New method: materia_xparam
      #--------------------------------------------------------------------------
      def materia_xparam(id)
        all_materias.inject(0.0) do |r, m|
          r += m.level * materia_xparam_plus(m, id)
        end
      end
      #--------------------------------------------------------------------------
      # * New method: materia_xparam_plus
      #--------------------------------------------------------------------------
      def materia_xparam_plus(m, id)
        m.effect(make_symbol(get_xparam_text(id)))
      end
      #--------------------------------------------------------------------------
      # * New method: materia_sparam
      #--------------------------------------------------------------------------
      def materia_sparam(id)
        all_materias.inject(0.0) do |r, m|
          r += m.level * materia_sparam_plus(m, id)
        end
      end
      #--------------------------------------------------------------------------
      # * New method: materia_sparam_plus
      #--------------------------------------------------------------------------
      def materia_sparam_plus(m, id)
        m.effect(make_symbol(get_sparam_text(id)))
      end
      #--------------------------------------------------------------------------
      # * New method: ap
      #--------------------------------------------------------------------------
      def ap
        @ap ? @ap :  0 
      end
      #--------------------------------------------------------------------------
      # * New method: ap=
      #--------------------------------------------------------------------------
      def ap=(n)
        equip_slots.size.times do |i|
          next if !@equips[i].object || @materia_slots[i].compact.empty?
          growth = @equips[i].object.growth
          @materia_slots[i].compact.each {|m| m.gain_ap(n, growth) }
        end
      end
      #--------------------------------------------------------------------------
      # * New method: all_materias
      #--------------------------------------------------------------------------
      def all_materias
        @materia_slots.values.inject([]) {|r, i| r += i }.compact
      end
      #--------------------------------------------------------------------------
      # * New method: update_materia_skills
      #--------------------------------------------------------------------------
      def update_materia_skills
        @materia_skills.each {|id| forget_skill(id) }
        @materia_skills.clear
        all_materias.each {|m| learn_materia_skill(m) }
      end
      #--------------------------------------------------------------------------
      # * New method: learn_materia_skill
      #--------------------------------------------------------------------------
      def learn_materia_skill(m)
        m.level.times {|i| gain_materia_skill(m, i) if valid_skill?(m, i) }
      end
      #--------------------------------------------------------------------------
      # * New method: gain_materia_skill
      #--------------------------------------------------------------------------
      def gain_materia_skill(m, i)
        id = m.enemy_skill? ? m.learn.values[i] : m.skills[i + 1]
        learn_skill(id)
        @materia_skills.push(id)
        @materia_skills.compact!
      end
      #--------------------------------------------------------------------------
      # * New method: valid_skill?
      #--------------------------------------------------------------------------
      def valid_skill?(m, i)
         (m.enemy_skill? ? m.learn.values[i] : m.skills[i + 1]) &&
         !@skills.include?(m.skills[i + 1])
      end
      #--------------------------------------------------------------------------
      # * New method: hp_mp_check
      #--------------------------------------------------------------------------
      def hp_mp_check(id)
        return id if id > 1
        all_materias.each {|m| return id == 0 ? 1 : 0 if m.effect?(:hp_mp) }
        id
      end
      #--------------------------------------------------------------------------
      # * New method: materia_conditions_met?
      #--------------------------------------------------------------------------
      def materia_conditions_met?(id)
        usable = nil
        all_materias.each {|m| usable |= m.on_limit?(id) if m.skill?(id) }
        usable.nil? ? true : usable
      end
      #--------------------------------------------------------------------------
      # * New method: equip_materia
      #--------------------------------------------------------------------------
      def equip_materia(equip, slot, id, forced = false)
        old = @materia_slots[equip][slot] 
        @materia_slots[equip][slot] = $game_party.materias[id]
        $game_party.lose_materia(id) unless forced
        $game_party.gain_item(old, 1) if old
        make_paired_materia
        update_materia_skills
        refresh
      end
      #--------------------------------------------------------------------------
      # * New method: force_materia
      #--------------------------------------------------------------------------
      def force_materia(equip, slot, id)
        @materia_slots[equip][slot] = $data_armors[id].setup_materia
        make_paired_materia
        update_materia_skills
        refresh
      end
      #--------------------------------------------------------------------------
      # * New method: unequip_materia
      #--------------------------------------------------------------------------
      def unequip_materia(equip, slot)
        $game_party.gain_item(@materia_slots[equip][slot], 1)
        @materia_slots[equip][slot] = nil
        make_paired_materia
        update_materia_skills
        refresh
      end
      #--------------------------------------------------------------------------
      # * New method: paired_materia
      #--------------------------------------------------------------------------
      def paired_materia
        @paired_materia
      end
      #--------------------------------------------------------------------------
      # * New method: make_paired_materia
      #--------------------------------------------------------------------------
      def make_paired_materia
        @paired_materia = []
        equip_slots.each_with_index do |x, i|
          equip   = equips[i]
          @paired_materia += materia_pairs(equip.double_slots, i) if equip
        end
        @paired_materia.compact
      end
      #--------------------------------------------------------------------------
      # * New method: materia_pairs
      #--------------------------------------------------------------------------
      def materia_pairs(slots, i)
        slots.times.collect {|x| setup_pairs(i, x) }.compact
      end
      #--------------------------------------------------------------------------
      # * New method: setup_pairs
      #--------------------------------------------------------------------------
      def setup_pairs(i, x)
        type = equip_slots[i] == 0 ? :weapon : :armor
        main = @materia_slots[i][x]
        pair = setup_pair_info(i, x, main, type) if main && main.support?
        main && pair ? pair : nil
      end
      #--------------------------------------------------------------------------
      # * New method: setup_pair_info
      #--------------------------------------------------------------------------
      def setup_pair_info(i, x, m, t)
        y = x + (x % 2 == 0 ? 1 : - 1)
        o = @materia_slots[i][y]
        o && !o.independent? ? {type: t, main: m, other: o} : nil
      end
      #--------------------------------------------------------------------------
      # * New method: materia_element_rate
      #--------------------------------------------------------------------------
      def materia_element_rate(id)
        paired_materia.inject(0.0) do |r, pair|
          m = pair[:main].effect(:elemental)
          o = pair[:other].elements?(id)
          v = (pair[:type] == :armor && o) ? -m  : 0
          r += v
        end
      end
      #--------------------------------------------------------------------------
      # * New method: materia_state_rate
      #--------------------------------------------------------------------------
      def materia_state_rate(id)
        paired_materia.inject(0.0) do |r, pair|
          m = pair[:main].effect(:added_effect)
          o = pair[:other].states?(id)
          v = (pair[:type] == :armor && o) ? -m : 0
          r += v
        end
      end
      #--------------------------------------------------------------------------
      # * New method: materia_atk_elements
      #--------------------------------------------------------------------------
      def materia_atk_elements(result)
        paired_materia.inject(result) do |r, pair|
          m = pair[:main].effect(:elemental)
          o = (pair[:type] == :weapon && m && m > 0) ? pair[:other].elements : []
          i = o.empty? ? [] : [1]
          r + o - i
        end
      end
      #--------------------------------------------------------------------------
      # * New method: materia_atk_states
      #--------------------------------------------------------------------------
      def materia_atk_states(result)
        paired_materia.inject(result) do |r, pair|
          m = pair[:main].effect?(:added_effect)
          o = (pair[:type] == :weapon && m) ? pair[:other].states : []
          r + o
        end
      end
      #--------------------------------------------------------------------------
      # * New method: materia_atk_states_rate
      #--------------------------------------------------------------------------
      def materia_atk_states_rate(id)
        paired_materia.inject(0.0) do |r, pair|
          m = pair[:main].effect(:added_effect)
          o = pair[:other].states?(id)
          v = (pair[:type] == :weapon && o) ? m : 0
          r + v
        end
      end
      #--------------------------------------------------------------------------
      # * New method: for_all?
      #--------------------------------------------------------------------------
      def for_all?(item)
        return false unless item.all?
        paired_materia.each do |pair|
          return true if pair[:main].all? && pair[:other].skill?(item.id)
        end
        return false
      end
    end
    
    #==============================================================================
    # ** Game_Enemy
    #------------------------------------------------------------------------------
    #  This class handles enemies. It used within the Game_Troop class 
    # ($game_troop).
    #==============================================================================
    
    class Game_Enemy < Game_Battler
      #--------------------------------------------------------------------------
      # * New method: ap
      #--------------------------------------------------------------------------
      def ap
        note =~ /<AP: (\d+)>/i ? $1.to_i : (exp / 10).to_i
      end
    end
    
    #==============================================================================
    # ** Game_Party
    #------------------------------------------------------------------------------
    #  This class handles parties. Information such as gold and items is included.
    # Instances of this class are referenced by $game_party.
    #==============================================================================
    
    class Game_Party < Game_Unit
      #--------------------------------------------------------------------------
      # * 
      #--------------------------------------------------------------------------
      attr_reader   :materias
      #--------------------------------------------------------------------------
      # * Alias method: init_all_items
      #--------------------------------------------------------------------------
      alias :init_all_items_ve_materia_system :init_all_items
      def init_all_items
        init_all_items_ve_materia_system
        @materias = []
      end
      #--------------------------------------------------------------------------
      # * Alias method: gain_item
      #--------------------------------------------------------------------------
      alias :gain_item_ve_materia_system :gain_item
      def gain_item(item, amount, include_equip = false)
        if item && item.materia?
          gain_materia(item, amount)
        else
          gain_item_ve_materia_system(item, amount, include_equip)
        end
      end
      #--------------------------------------------------------------------------
      # * New method: gain_materia
      #--------------------------------------------------------------------------
      def gain_materia(item, amount = 1)
        if amount > 0
          materia = item.clone.setup_materia
          amount.times { @materias.push(materia) if !max_materia? }
        elsif amount < 0
          remove_materia(item, amount.abs)
        end
        @materias.sort! {|a, b| a.id <=> b.id }
        $game_map.need_refresh = true
      end
      #--------------------------------------------------------------------------
      # * New method: remove_materia
      #--------------------------------------------------------------------------
      def remove_materia(item, amount = 1, actor = false)
        amount.times do
          removed = false
          @materias.each_with_index do |m, i|
            if m.id == item.id && !removed
              removed = true
              break @materias.delete_at(i) 
            end
          end
          members.each do |actor|
            actor.equip_slots.size.times do |i| 
              if actor.materia_slots[i]
                actor.materia_slots[i].each_with_index do |m, x|
                  next if !m || m.id != item.id || removed
                  actor.materia_slots[i][x] = nil
                  removed = true
                end
              end
            end
          end
        end
      end
      #--------------------------------------------------------------------------
      # * New method: lose_materia
      #--------------------------------------------------------------------------
      def lose_materia(index)
        @materias.delete_at(index)
        @materias.sort! {|a, b| a.id <=> b.id }
      end
      #--------------------------------------------------------------------------
      # * New method: max_materia?
      #--------------------------------------------------------------------------
      def max_materia?
        Max_Materia_Number && @materias.size >= Max_Materia_Number
      end
    end
    
    #==============================================================================
    # ** Game_Troop
    #------------------------------------------------------------------------------
    #  This class handles enemy groups and battle-related data. Also performs
    # battle events. The instance of this class is referenced by $game_troop.
    #==============================================================================
    
    class Game_Troop < Game_Unit
      #--------------------------------------------------------------------------
      # * New method: ap_total
      #--------------------------------------------------------------------------
      def ap_total
        dead_members.inject(0) {|r, enemy| r += enemy.ap }
      end
    end
    
    #==============================================================================
    # ** Game_Interpreter
    #------------------------------------------------------------------------------
    #  An interpreter for executing event commands. This class is used within the
    # Game_Map, Game_Troop, and Game_Event classes.
    #==============================================================================
    
    class Game_Interpreter
      #--------------------------------------------------------------------------
      # * Alias method: command_319
      #--------------------------------------------------------------------------
      alias :command_319_ve_materia_system :command_319
      def command_319
        command_319_ve_materia_system
        $game_actors[@params[0]].setup_equipments if $game_actors[@params[0]]
      end
      #--------------------------------------------------------------------------
      # * Alias method: command_302
      #--------------------------------------------------------------------------
      alias :command_302_ve_materia_system :command_302
      def command_302
        if $game_temp.materia_shop
          call_materia_shop
        else
          command_302_ve_materia_system
        end
      end
      #--------------------------------------------------------------------------
      # * Alias method: comment_call
      #--------------------------------------------------------------------------
      alias :comment_call_ve_materia_system :comment_call
      def comment_call
        $game_temp.materia_shop = true if note =~ /<MATERIA SHOP>/i
        call_materia_equip
        call_materia_unequip
        call_drop_materia
        comment_call_ve_materia_system
      end
      #--------------------------------------------------------------------------
      # * New method: call_materia_shop
      #--------------------------------------------------------------------------
      def call_materia_shop
        return if $game_party.in_battle
        $game_temp.materia_shop = false
        goods = [@params]
        while next_event_code == 605
          @index += 1
          goods.push(@list[@index].parameters)
        end
        SceneManager.call(Scene_MateriaShop)
        SceneManager.scene.prepare(goods)
        Fiber.yield
      end
      #--------------------------------------------------------------------------
      # * New method: materia_shop
      #--------------------------------------------------------------------------
      def materia_shop(list)
        $game_temp.materia_shop = list.dup
        SceneManager.call(Scene_MateriaShop)
      end
      #--------------------------------------------------------------------------
      # * New method: call_materia_equip
      #--------------------------------------------------------------------------
      def call_materia_equip
        if note =~ /<EQUIP MATERIA: (\d+), *(\d+), *(\d+), *(\d+)>/i
          $game_actors[$1.to_i].force_materia($2.to_i - 1, $3.to_i - 1, $4.to_i)
        end
      end
      #--------------------------------------------------------------------------
      # * New method: call_materia_unequip
      #--------------------------------------------------------------------------
      def call_materia_unequip
        if note =~ /<UNEQUIP MATERIA: (\d+), *(\d+), *(\d+)>/i
          $game_actors[$1.to_i].unequip_materia($2.to_i - 1, $3.to_i - 1)
        end
      end
      #--------------------------------------------------------------------------
      # * New method: call_drop_materia
      #--------------------------------------------------------------------------
      def call_drop_materia
        if note =~ /<DROP MATERIA: (\d+), *(\d+)>/i
          materia = $data_armors[$1.to_i].setup_materia
          $game_party.remove_materia(materia, $2.to_i, true)
        end
      end
    end
    #==============================================================================
    # ** Window_Selectable
    #------------------------------------------------------------------------------
    #  This window contains cursor movement and scroll functions.
    #==============================================================================
    
    class Window_Selectable < Window_Base
      #--------------------------------------------------------------------------
      # * New method: target_all?
      #--------------------------------------------------------------------------
      alias :target_all_ve_materia_system? :target_all? if $imported[:ve_target_arrow]
      def target_all?
        target_all_ve_materia_system? || (@action && BattleManager.actor &&
        BattleManager.actor.for_all?(@action))
      end
    end
    
    #==============================================================================
    # ** Window_MenuCommand
    #------------------------------------------------------------------------------
    #  This command window appears on the menu screen.
    #==============================================================================
    
    class Window_MenuCommand < Window_Command
      #--------------------------------------------------------------------------
      # * Alias method: add_main_commands 
      #--------------------------------------------------------------------------
      alias :add_main_commands_ve_materia_system :add_main_commands
      def add_main_commands
        add_main_commands_ve_materia_system
        add_command(Vocab::VE_MateriaMenu, :materia, main_commands_enabled)
      end
    end
    
    #==============================================================================
    # ** Window_MenuActor
    #------------------------------------------------------------------------------
    #  This window is for selecting actors that will be the target of item or
    # skill use.
    #==============================================================================
    
    class Window_MenuActor < Window_MenuStatus
      #--------------------------------------------------------------------------
      # * Overwrite method: select_for_item
      #--------------------------------------------------------------------------
      def select_for_item(item, for_all = false)
        @cursor_fix = item.for_user?
        @cursor_all = for_all
        if @cursor_fix
          select($game_party.menu_actor.index)
        elsif @cursor_all
          select(0)
        else
          select_last
        end
      end
    end
    
    #==============================================================================
    # ** Window_SkillList
    #------------------------------------------------------------------------------
    #  This window is for displaying a list of available skills on the skill window.
    #==============================================================================
    
    class Window_SkillList < Window_Selectable
      #--------------------------------------------------------------------------
      # * Alias method: draw_skill_cost
      #--------------------------------------------------------------------------
      alias :draw_skill_cost_ve_materia_system :draw_skill_cost
      def draw_skill_cost(rect, skill)
        draw_skill_cost_ve_materia_system(rect, skill)
        change_color(text_color(18), enable?(skill))
        rect.x += (32 + text_size(skill.name).width)
        draw_text(rect, ">") if @actor.for_all?(skill)
      end
    end
    
    #==============================================================================
    # ** Window_BattleLog
    #------------------------------------------------------------------------------
    #  This window shows the battle progress. Do not show the window frame.
    #==============================================================================
    
    class Window_BattleLog < Window_Selectable
      #--------------------------------------------------------------------------
      # * Alias method: display_failure
      #--------------------------------------------------------------------------
      alias :display_failure_ve_materia_system :display_failure
      def display_failure(target, item)
        display_failure_ve_materia_system(target, item)
        if target.actor? && target.learned_enemy_skill
          skill = $data_skills[target.learned_enemy_skill].name
          target.learned_enemy_skill = nil
          add_text(sprintf(Vocab::VE_EnemySkill, target.name, skill))
          wait
        end
      end
    end
    
    #==============================================================================
    # ** Window_MateriaInfo
    #------------------------------------------------------------------------------
    #  This window shows the materia information.
    #==============================================================================
    
    class Window_MateriaInfo < Window_Base
      #--------------------------------------------------------------------------
      # * initialize
      #--------------------------------------------------------------------------
      def initialize(width, height, shop = false)
        super(0, 176, width, height)
        @shop = shop
      end
      #--------------------------------------------------------------------------
      # * materia
      #--------------------------------------------------------------------------
      def materia=(materia)
        @materia = materia
        refresh
      end
      #--------------------------------------------------------------------------
      # * refresh
      #--------------------------------------------------------------------------
      def refresh
        contents.clear
        return if @materia.nil?
        contents.font.size = Font.default_size
        draw_item_name(@materia, 0, 0, true, width)
        contents.font.size = 19
        if @materia.enemy_skill?
          draw_enemy_skill_level
          draw_enemy_skill_list
        else
          draw_materia_elements
          draw_materia_level
          draw_materia_ap
          draw_materia_skills
          draw_materia_abilities
          draw_materia_stats
        end
      end
      #--------------------------------------------------------------------------
      # * draw_item_name
      #--------------------------------------------------------------------------
      def draw_item_name(item, x, y, enabled = true, width = 172)
        return unless item
        draw_icon(item.icon_index, x, y - 2, enabled)
        change_color(normal_color, enabled)
        draw_text(x + 24, y, width, line_height, item.name)
      end
      #--------------------------------------------------------------------------
      # * draw_icon
      #--------------------------------------------------------------------------
      def draw_icon(icon_index, x, y, enabled = true)
        bitmap = Cache.system("Iconset")
        rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
        contents.blt(x, y, bitmap, rect, enabled ? 255 : 120)
      end
      #--------------------------------------------------------------------------
      # * draw_materia_elements
      #--------------------------------------------------------------------------
      def draw_materia_elements
        change_color(crisis_color)
        @materia.elements.each_with_index do |id, i|
          element = $data_system.elements[id]
          x = i % 2 * 96 + 24
          y = i / 2 * 18 + 24
          draw_text(x, y, width, line_height, element)
        end
        @materia.states.each_with_index do |id, i|
          states = $data_states[id].name
          x = (i + @materia.elements.size) % 2 * 96 + 16
          y = (i + @materia.elements.size) / 2 * 18 + 24
          draw_text(x, y, width, line_height, states)
        end
      end
      #--------------------------------------------------------------------------
      # * draw_materia_level
      #--------------------------------------------------------------------------
      def draw_materia_level
        icon = @materia.level_icon
        x    = width - [@materia.max_level * 32, 160].max
        @materia.max_level.times {|i| draw_icon(icon, x + i * 26, 0, false) }
        @materia.level.times     {|i| draw_icon(icon, x + i * 26, 0) }
      end
      #--------------------------------------------------------------------------
      # * draw_materia_ap
      #--------------------------------------------------------------------------
      def draw_materia_ap
        change_color(system_color)
        x1 = width - 312 + [352 - width, 24].min
        x2 = width - 204
        contents.draw_text(x1, 24, 172, 24, Vocab::VE_ApName, 2)
        contents.draw_text(x1, 44, 172, 24, 'To next level', 2)
        change_color(normal_color)
        ap = @materia.master? ? Vocab::VE_MasterText : @materia.ap.to_s
        contents.draw_text(x2, 24, 172, 24, ap, 2)
        nl = @materia.master? ? '-------' : @materia.next_level - @materia.ap
        contents.draw_text(x2, 44, 172, 24, nl.to_s, 2)
      end
      #--------------------------------------------------------------------------
      # * draw_materia_skills
      #--------------------------------------------------------------------------
      def draw_materia_skills
        draw_materia_price if @shop
        change_color(system_color)
        y = @shop ? 120 : 88
        contents.draw_text(4, y - 20, 172, 24, "Ability list")
        change_color(normal_color)
        @materia.skills.keys.sort.each_with_index do |key, i|
          name = $data_skills[@materia.skills[key]].name
          change_color(normal_color, key <= @materia.level)
          contents.draw_text(12, y + i * 18, 172, 24, name)
        end
      end
      #--------------------------------------------------------------------------
      # * draw_materia_price
      #--------------------------------------------------------------------------
      def draw_materia_price
        contents.font.size = 18
        buy    = @materia.price
        sell   = @materia.sell_price
        master = @materia.master
        contents.draw_text(4, 76, 172, 24, "Buy:#{buy}")
        contents.draw_text(width / 2 - 64, 76, 172, 24, "Sell:#{sell}")
        contents.draw_text(width - 128, 76, 172, 24, "Master:#{master}")
        contents.font.size = 19
      end
      #--------------------------------------------------------------------------
      # * draw_materia_abilities
      #--------------------------------------------------------------------------
      def draw_materia_abilities
        y = @materia.skills.keys.size
        z = @shop ? 120 : 88
        change_color(normal_color, true)
        list = @materia.effects.keys.collect {|effect| effect }
        list.each_with_index do |effect, i|
          if @materia.effect_name
            contents.draw_text(12, z + (i + y) * 18, 172, 24, @materia.effect_name)
            break
          elsif @materia.effects[effect].numeric?
            name  = make_string(effect).capitalize
            value = @materia.effects[effect] * 100
            draw_effect_value(effect, i + y, name, value)
          else
            name = make_string(effect).capitalize
            contents.draw_text(12, z + (i + y) * 18, 172, 24, name)
          end
        end
      end
      #--------------------------------------------------------------------------
      # * draw_materia_stats
      #--------------------------------------------------------------------------
      def draw_materia_stats
        list1 = get_params_values
        list2 = get_stats_values
        change_color(system_color)
        y = @shop ? 100 : 68
        contents.draw_text(width - 172, y, 172, 24, "Equip effect")
        change_color(normal_color)
        list1.each_with_index {|param, i| draw_param_value(param, i, false) }
        list2.each_with_index {|param, i| draw_param_value(param, i + list1.size) }
      end
      #--------------------------------------------------------------------------
      # * get_params_values
      #--------------------------------------------------------------------------
      def get_params_values
        list = []
        @materia.params.size.times do |i|
          next if @materia.params[i] == 0
          list.push({name: Vocab::param(i), value: @materia.params[i]})
        end
        list
      end
      #--------------------------------------------------------------------------
      # * get_stats_values
      #--------------------------------------------------------------------------
      def get_stats_values
        list = []
        @materia.stats.keys.each do |i|
          next if @materia.stats[i] == 0
          list.push({name: Vocab::param(i), value: @materia.stats[i]})
        end
        list
      end
      #--------------------------------------------------------------------------
      # * draw_effect_value
      #--------------------------------------------------------------------------
      def draw_effect_value(effect, i, s1, s2)
        name  = effect_name(s1)
        plus  = s2 >= 0 ? "+" : "-"
        value = sprintf("%03d", s2.abs * @materia.level)
        draw_param_info(name, plus, value, "%", i, 12, 108)
      end
      #--------------------------------------------------------------------------
      # * draw_param_value
      #--------------------------------------------------------------------------
      def draw_param_value(param, i, rate = true)
        name  = param[:name]
        plus  = param[:value] < 0 ? "-" : "+"
        value = sprintf("%02d", param[:value].abs)
        rate  = rate ? "%" : ""
        draw_param_info(name, plus, value, rate, i, width - 176, 108)
      end
      #--------------------------------------------------------------------------
      # * draw_param_info
      #--------------------------------------------------------------------------
      def draw_param_info(name, plus, value, rate, i, x, y)
        z = @shop ? 120 : 88
        contents.draw_text(x, z + i * 18, 172, 24, name)
        contents.draw_text(x + y, z + i * 18, 172, 24, plus)
        change_color(plus == "-" ? knockout_color : crisis_color)
        wid = text_size(plus).width
        contents.draw_text(x + y + wid, z + i * 18, 172, 24, value)
        change_color(normal_color)
        wid += text_size(value).width
        contents.draw_text(x + y + wid, z + i * 18, 172, 24, rate)
      end
      #--------------------------------------------------------------------------
      # * draw_enemy_skill_level
      #--------------------------------------------------------------------------
      def draw_enemy_skill_level
        icon = @materia.level_icon
        @materia.max_level.times do |i| 
          draw_icon(icon, level_x(i), level_y(i), @materia.learn[i])
        end
      end
      #--------------------------------------------------------------------------
      # * level_x
      #--------------------------------------------------------------------------
      def level_x(i)
        x = @materia.max_level / 2
        i % x * 26 + [(width / 2) - (x * 26) / 2, 0].max
      end
      #--------------------------------------------------------------------------
      # * level_y
      #--------------------------------------------------------------------------
      def level_y(i)
        i / (@materia.max_level / 2) * 26 + 28
      end
      #--------------------------------------------------------------------------
      # * draw_enemy_skill_list
      #--------------------------------------------------------------------------
      def draw_enemy_skill_list
        draw_materia_price if @shop
        color = Color.new(0, 0, 0, 50)
        y = @shop ? 20 : 0
        contents.fill_rect(8, 82 + y, width - 36, height - 112 - y, color)
        z = @shop ? 116 : 84
        @materia.max_level.times do |i| 
          if @materia.learn[i + 1]
            name = $data_skills[@materia.learn[i + 1]].name
            x = i % 3 * (width / 3 - 16) + 16
            y = i / 3 * 18 + z
            contents.draw_text(x, y, width / 3 - 12, 24, name)
          end
        end
      end
      #--------------------------------------------------------------------------
      # * effect_name
      #--------------------------------------------------------------------------
      def effect_name(name)
        case name.upcase
        when "HIT" then "Hit"
        when "EVA" then "Evasion"
        when "CRI" then "Critical"
        when "CEV" then "C. Evasion"
        when "MEV" then "M. Evasion"
        when "MRF" then "Reflection"
        when "CNT" then "Counter"
        when "HRG" then "HP Regen"
        when "MRG" then "MP Regen"
        when "TRG" then "TP Regen"
        when "TGR" then "Target"
        when "GRD" then "Guard"
        when "REC" then "Recover"
        when "PHA" then "Pharmacology"
        when "MCR" then "MP Rate"
        when "TCR" then "TP Charge"
        when "PDR" then "P. Reduction"
        when "MDR" then "M. Reduction"
        when "FDR" then "Floor Damage"
        when "EXR" then "EXP Rate"
        else 
          id = get_param_id(name.upcase)
          id ? Vocab::param(id) : name
        end
      end
    end
    
    #==============================================================================
    # ** Window_MateriaList
    #------------------------------------------------------------------------------
    #  This window shows the materia list.
    #==============================================================================
    
    class Window_MateriaList < Window_Selectable
      #--------------------------------------------------------------------------
      # * Public Instance Variables
      #--------------------------------------------------------------------------
      attr_reader   :materia_window
      #--------------------------------------------------------------------------
      # * item_max
      #--------------------------------------------------------------------------
      def item_max
        @data ? @data.size : 1
      end
      #--------------------------------------------------------------------------
      # * materia
      #--------------------------------------------------------------------------
      def materia
        @data[index]
      end
      #--------------------------------------------------------------------------
      # * draw_item
      #--------------------------------------------------------------------------
      def draw_item(index)
        item = @data[index]
        if item
          rect = item_rect(index)
          rect.width -= 4
          draw_item_name(item, rect.x, rect.y)
        end
      end
      #--------------------------------------------------------------------------
      # * draw_item_name
      #--------------------------------------------------------------------------
      def draw_item_name(item, x, y, enabled = true, width = 172)
        return unless item
        draw_icon(item.icon_index, x, y, enabled, item)
        change_color(normal_color, enabled)
        draw_text(x + 24, y, width, line_height, item.name)
      end
      #--------------------------------------------------------------------------
      # * draw_icon
      #--------------------------------------------------------------------------
      def draw_icon(icon_index, x, y, enabled = true, item)
        bitmap = Cache.system("Iconset")
        rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
        contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
      end
      #--------------------------------------------------------------------------
      # * refresh
      #--------------------------------------------------------------------------
      def refresh
        make_item_list
        create_contents
        draw_all_items
      end
      #--------------------------------------------------------------------------
      # * materia_window
      #--------------------------------------------------------------------------
      def materia_window=(materia_window)
        @materia_window = materia_window
        call_update_help
      end
      #--------------------------------------------------------------------------
      # * update_help
      #--------------------------------------------------------------------------
      def update_help
        super
        @materia_window.materia = materia if @materia_window
        @help_window.set_item(materia)
      end  
    end
    
    #==============================================================================
    # ** Window_MateriaStatus
    #------------------------------------------------------------------------------
    #  This window shows the materias on the materia equip screen.
    #==============================================================================
    
    class Window_MateriaStatus < Window_MateriaList
      #--------------------------------------------------------------------------
      # * initialize
      #--------------------------------------------------------------------------
      def initialize
        super(window_x, 176, 192, window_height)
        @data = []
      end
      #--------------------------------------------------------------------------
      # * window_x
      #--------------------------------------------------------------------------
      def window_x
        352 + [Graphics.width - 544, 0].max
      end
      #--------------------------------------------------------------------------
      # * window_height
      #--------------------------------------------------------------------------
      def window_height
        240 + [Graphics.height - 416, 0].max
      end
      #--------------------------------------------------------------------------
      # * make_item_list
      #--------------------------------------------------------------------------
      def make_item_list
        @data = $game_party.materias.collect {|materia| materia }
        @data.push(nil)
      end
    end
    
    #==============================================================================
    # ** Window_MateriaShop
    #------------------------------------------------------------------------------
    #  This window shows the materias on the materia shop screen.
    #==============================================================================
    
    class Window_MateriaShop < Window_MateriaList
      #--------------------------------------------------------------------------
      # * initialize
      #--------------------------------------------------------------------------
      def initialize(y, width, height, materia_list = nil)
        super(0, y, width, height)
        @materia_list = materia_list
        @data = []
        select(0)
      end
      #--------------------------------------------------------------------------
      # * make_item_list
      #--------------------------------------------------------------------------
      def make_item_list
        @data  = []
        @price = {}
        lsit   = @materia_list ? @materia_list : make_sell_list
        lsit.each do |goods|
          item = @materia_list ? $data_armors[goods[1]] : goods[1]
          item.setup_materia
          if item
            @data.push(item)
            @price[item] = goods[2] == 0 ? setup_price(item) : goods[3]
          end
        end
      end
      #--------------------------------------------------------------------------
      # * setup_price
      #--------------------------------------------------------------------------
      def setup_price(item)
        @materia_list ? item.price : item.sell_price
      end
      #--------------------------------------------------------------------------
      # * make_sell_list
      #--------------------------------------------------------------------------
      def make_sell_list
        $game_party.materias.collect {|m| [0, m, 0] }
      end
      #--------------------------------------------------------------------------
      # * money
      #--------------------------------------------------------------------------
      def money=(money)
        @money = money
        refresh
      end
      #--------------------------------------------------------------------------
      # * current_item_enabled?
      #--------------------------------------------------------------------------
      def current_item_enabled?
        enable?(@data[index])
      end
      #--------------------------------------------------------------------------
      # * price
      #--------------------------------------------------------------------------
      def price(item)
        @price[item]
      end
      #--------------------------------------------------------------------------
      # * enable?
      #--------------------------------------------------------------------------
      def enable?(item)
        item && (!@materia_list || (item && price(item) <= @money &&
        !$game_party.max_materia?))
      end
      #--------------------------------------------------------------------------
      # * draw_item_name
      #--------------------------------------------------------------------------
      def draw_item_name(item, x, y)
        return unless item
        draw_icon(item.icon_index, x, y, enable?(item), item)
        change_color(normal_color, enable?(item))
        draw_text(x + 24, y, width, line_height, item.name)
        draw_text(4, y, self.width - 32, line_height, ":#{price(item)}", 2)
      end
    end
    
    #==============================================================================
    # ** Window_MateriaActor
    #------------------------------------------------------------------------------
    #  This window shows the actor status on the materia equip screen.
    #==============================================================================
    
    class Window_MateriaActor < Window_Selectable
      #--------------------------------------------------------------------------
      # * Public Instance Variables
      #--------------------------------------------------------------------------
      attr_reader   :actor
      #--------------------------------------------------------------------------
      # * initialize
      #--------------------------------------------------------------------------
      def initialize
        @equip = 0
        super(0, 0, Graphics.width, 128)
        @index = 0
      end
      #--------------------------------------------------------------------------
      # * actor
      #--------------------------------------------------------------------------
      def actor=(actor)
        @actor = actor
        refresh
      end
      #--------------------------------------------------------------------------
      # * refresh
      #--------------------------------------------------------------------------
      def refresh
        super
        draw_face(actor.face_name, actor.face_index, 4, 4)
        draw_actor_name(actor, 104, line_height * 0)
        draw_actor_level(actor, 104, line_height * 1)
        draw_actor_hp(actor, 104, line_height * 2)
        draw_actor_mp(actor, 104, line_height * 3)
      end
    end
    
    #==============================================================================
    # ** Window_MateriaEquip
    #------------------------------------------------------------------------------
    #  This window shows the actor equipe materia. Do not show the window frame.
    #==============================================================================
    
    class Window_MateriaEquip < Window_Selectable
      #--------------------------------------------------------------------------
      # * Public Instance Variables
      #--------------------------------------------------------------------------
      attr_accessor :equip  
      attr_reader   :actor
      attr_reader   :materia_window
      #--------------------------------------------------------------------------
      # * initialize
      #--------------------------------------------------------------------------
      def initialize
        @equip = 0
        super(window_x, 0, Graphics.width -  window_x, 128)
        @index = 0
      end
      #--------------------------------------------------------------------------
      # * item_max
      #--------------------------------------------------------------------------
      def item_max
        return 1
      end
      #--------------------------------------------------------------------------
      # * contents_width
      #--------------------------------------------------------------------------
      def contents_width
        width - standard_padding * 2
      end
      #--------------------------------------------------------------------------
      # * contents_height
      #--------------------------------------------------------------------------
      def contents_height
        actor ? actor.equip_slots.size * 48 + 48 - standard_padding * 2 : 1 #@#actor.equip_slots.size
      end
      #--------------------------------------------------------------------------
      # * update_padding_bottom
      #--------------------------------------------------------------------------
      def update_padding_bottom
      end
      #--------------------------------------------------------------------------
      # * actor
      #--------------------------------------------------------------------------
      def actor=(actor)
        @actor = actor
        refresh
      end
      #--------------------------------------------------------------------------
      # * materia
      #--------------------------------------------------------------------------
      def materia
        slots = actor.materia_slots[equip]
        slots ? slots[index] : slots
      end
      #--------------------------------------------------------------------------
      # * slot_width
      #--------------------------------------------------------------------------
      def slot_width
        Max_Slot_Number * 32
      end
      #--------------------------------------------------------------------------
      # * window_x
      #--------------------------------------------------------------------------
      def window_x
        return 244
      end
      #--------------------------------------------------------------------------
      # * base_x
      #--------------------------------------------------------------------------
      def base_x
        [Graphics.width - 544, 4].max + window_x
      end
      #--------------------------------------------------------------------------
      # * refresh
      #--------------------------------------------------------------------------
      def refresh
        super
        create_contents
        self.opacity = 0
        draw_equipments(8 + base_x - slot_width)
        draw_materias(28 + base_x - slot_width)
      end
      #------------------------------------------------------------------------------
      # * draw_equipments 
      #------------------------------------------------------------------------------
      def draw_equipments(x)
        actor.weapons.each_with_index do |item, i| #@#Change weapons to equips to show armor as well
          draw_item_name(item, x, y + 50 * i + 1)
        end
      end
      #------------------------------------------------------------------------------
      # * draw_materias
      #------------------------------------------------------------------------------
      def draw_materias(x)
        draw_background(x)
        draw_slots(x)
        draw_materia_icons(x)
      end
      #------------------------------------------------------------------------------
      # * draw_background
      #------------------------------------------------------------------------------
      def draw_background(x)
        color = Color.new(0, 0, 0, 50)
        actor.equip_slots.size.times do |i|
          contents.fill_rect(x - 4, i * 50 + 26, slot_width, 22, color)
        end
      end
      #------------------------------------------------------------------------------
      # * draw_slots
      #------------------------------------------------------------------------------
      def draw_slots(x)
        actor.equip_slots.size.times do |i|
          next unless actor.equips[i]
          equip = @actor.equips[i]
          links = equip.double_slots / 2
          slots = equip.double_slots + equip.single_slots
          icon1 = equip.nothing? ? Slot_Icon_Nothing : Slot_Icon_Normal
          icon2 = Slot_Link_Icon
          slots.times {|y| draw_icon(icon1, x + y * 32, i * 50 + 24) }
          links.times {|y| draw_icon(icon2, x + 16 + y * 64, i * 50 + 24) }
        end
      end
      #------------------------------------------------------------------------------
      # * draw_materia_icons
      #------------------------------------------------------------------------------
      def draw_materia_icons(x)
        actor.equip_slots.size.times do |i|
          next unless actor.materia_slots[i]
          actor.materia_slots[i].each_with_index do |m, y|
            draw_materia(m.icon_index, x + y * 32, i * 50 + 24, m, 200) if m
          end
        end
      end
      #--------------------------------------------------------------------------
      # * draw_materia
      #--------------------------------------------------------------------------
      def draw_materia(icon_index, x, y, item, opacity = 255)
        bitmap = Cache.system("Iconset")
        rect   = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
        contents.blt(x, y, bitmap, rect, opacity)
      end
      #--------------------------------------------------------------------------
      # * equip
      #--------------------------------------------------------------------------
      def equip=(equip)
        @equip = equip
        update_cursor
        call_update_help
      end
      #--------------------------------------------------------------------------
      # * update_cursor
      #--------------------------------------------------------------------------
      def update_cursor
        ensure_cursor_visible
        cursor_rect.set(item_rect(@index, @equip))
      end
      #--------------------------------------------------------------------------
      # * item_rect
      #--------------------------------------------------------------------------
      def item_rect(index, equip)
        rect = Rect.new
        rect.width  = 26
        rect.height = 26
        rect.x  = index * 32 + 27 + base_x - slot_width
        rect.y  = equip * 50 + 24
        self.oy = (equip - equip % 2) * 50
        rect
      end
      #--------------------------------------------------------------------------
      # * process_cursor_move
      #--------------------------------------------------------------------------
      def process_cursor_move
        return unless cursor_movable?
        last_equip = @equip
        super
        Sound.play_cursor if @equip != last_equip
      end
      #--------------------------------------------------------------------------
      # * cursor_down
      #--------------------------------------------------------------------------
      def cursor_down(wrap = false)
        self.equip += 1
        self.equip %= 2#$#actor.equip_slots.size
      end
      #--------------------------------------------------------------------------
      # * cursor_up
      #--------------------------------------------------------------------------
      def cursor_up(wrap = false)
        self.equip -= 1
        self.equip %= 2#$#actor.equip_slots.size
      end
      #--------------------------------------------------------------------------
      # * cursor_right
      #--------------------------------------------------------------------------
      def cursor_right(wrap = false)
        self.index += 1
        self.index %= Max_Slot_Number
      end
      #--------------------------------------------------------------------------
      # * cursor_left
      #--------------------------------------------------------------------------
      def cursor_left(wrap = false)
        self.index -= 1
        self.index %= Max_Slot_Number
      end
      #--------------------------------------------------------------------------
      # * current_item_enabled?
      #--------------------------------------------------------------------------
      def current_item_enabled?
        index < actor.materia_slots[equip].size
      end
      #--------------------------------------------------------------------------
      # * process_handling
      #--------------------------------------------------------------------------
      def process_handling
        return unless open? && active
        return process_clear  if handler_clear?  && Input.trigger?(:A)
        super 
      end
      #--------------------------------------------------------------------------
      # * handler_clear?
      #--------------------------------------------------------------------------
      def handler_clear?
        handle?(:clear) && materia
      end
      #--------------------------------------------------------------------------
      # * process_clear
      #--------------------------------------------------------------------------
      def process_clear
        call_handler(:clear) 
      end
      #--------------------------------------------------------------------------
      # * materia_window=
      #--------------------------------------------------------------------------
      def materia_window=(materia_window)
        @materia_window = materia_window
        call_update_help
      end
      #--------------------------------------------------------------------------
      # * update_help
      #--------------------------------------------------------------------------
      def update_help
        super
        @materia_window.materia = materia if @materia_window
        @help_window.set_item(materia)
      end
    end
    
    #==============================================================================
    # ** Scene_Menu
    #------------------------------------------------------------------------------
    #  This class performs the menu screen processing.
    #==============================================================================
    
    class Scene_Menu < Scene_MenuBase
      #--------------------------------------------------------------------------
      # * Alias method: create_command_window
      #--------------------------------------------------------------------------
      alias :materia_system_create_command_window :create_command_window
      def create_command_window
        materia_system_create_command_window
        @command_window.set_handler(:materia,   method(:command_personal))
      end
      #--------------------------------------------------------------------------
      # * Alias method: on_personal_ok
      #--------------------------------------------------------------------------
      alias :materia_system_on_personal_ok :on_personal_ok
      def on_personal_ok
        materia_system_on_personal_ok
        if @command_window.current_symbol == :materia
          SceneManager.call(Scene_MateriaEquip)
        end
      end
    end
    
    #==============================================================================
    # ** Scene_Equip
    #------------------------------------------------------------------------------
    #  This class performs the equipment screen processing.
    #==============================================================================
    
    class Scene_Equip < Scene_MenuBase
      #------------------------------------------------------------------------------
      # * Alias method: on_actor_change
      #------------------------------------------------------------------------------
      alias :materia_system_on_actor_change :on_actor_change
      def on_actor_change
        @actor.setup_equipments
        materia_system_on_actor_change
      end
      #------------------------------------------------------------------------------
      # * New method: terminate
      #------------------------------------------------------------------------------
      def terminate
        super
        @actor.setup_equipments
      end
    end
    
    #==============================================================================
    # ** Scene_MateriaEquip
    #------------------------------------------------------------------------------
    #  This class performs the materia equip screen processing.
    #==============================================================================
    
    class Scene_MateriaEquip < Scene_MenuBase
      #--------------------------------------------------------------------------
      # * start
      #--------------------------------------------------------------------------
      def start
        super
        create_help_window
        create_materia_window
        create_status_window
        create_equip_window
        create_item_window
      end
      #--------------------------------------------------------------------------
      # * create_help_window
      #--------------------------------------------------------------------------
      def create_help_window
        @help_window = Window_Help.new(1)
        @help_window.viewport = @viewport
        @help_window.y = 128
      end
      #--------------------------------------------------------------------------
      # * create_materia_window
      #--------------------------------------------------------------------------
      def create_materia_window
        ww = 352 + [Graphics.width - 544, 0].max
        wh = 240 + [Graphics.height - 416, 0].max
        @materia_window = Window_MateriaInfo.new(ww, wh)
        @materia_window.viewport = @viewport
      end
      #--------------------------------------------------------------------------
      # * create_status_window
      #--------------------------------------------------------------------------
      def create_status_window
        @status_window = Window_MateriaActor.new
        @status_window.actor = @actor
        @status_window.viewport = @viewport
      end
      #--------------------------------------------------------------------------
      # * create_equip_window
      #--------------------------------------------------------------------------
      def create_equip_window
        @equip_window = Window_MateriaEquip.new
        @equip_window.actor = @actor
        @equip_window.viewport = @viewport
        @equip_window.help_window = @help_window
        @equip_window.materia_window = @materia_window
        @equip_window.set_handler(:ok,       method(:command_equip))
        @equip_window.set_handler(:clear,    method(:command_clear))
        @equip_window.set_handler(:cancel,   method(:return_scene))
        @equip_window.set_handler(:pagedown, method(:next_actor))
        @equip_window.set_handler(:pageup,   method(:prev_actor))
        @equip_window.activate
      end
      #--------------------------------------------------------------------------
      # * create_item_window
      #--------------------------------------------------------------------------
      def create_item_window
        @item_window = Window_MateriaStatus.new
        @item_window.viewport = @viewport
        @item_window.help_window = @help_window
        @item_window.materia_window = @materia_window
        @item_window.set_handler(:ok,     method(:on_item_ok))
        @item_window.set_handler(:cancel, method(:on_item_cancel))
        @item_window.refresh
      end
      #--------------------------------------------------------------------------
      # * command_equip
      #--------------------------------------------------------------------------
      def command_equip
        @item_window.activate
        @item_window.select(0)
      end
      #--------------------------------------------------------------------------
      # * command_clear
      #--------------------------------------------------------------------------
      def command_clear
        Sound.play_equip
        @actor.unequip_materia(@equip_window.equip, @equip_window.index)
        @item_window.refresh
        @equip_window.refresh
        @status_window.refresh
        @materia_window.refresh
      end
      #--------------------------------------------------------------------------
      # * on_actor_change
      #--------------------------------------------------------------------------
      def on_actor_change
        @equip_window.actor  = @actor
        @status_window.actor = @actor
        @item_window.refresh
        @materia_window.refresh
        @equip_window.activate
      end
      #--------------------------------------------------------------------------
      # * on_item_ok
      #--------------------------------------------------------------------------
      def on_item_ok
        Sound.play_equip
        if @item_window.materia
          @actor.equip_materia(@equip_window.equip, @equip_window.index,
            @item_window.index)
        else
          @actor.unequip_materia(@equip_window.equip, @equip_window.index)
        end
        @item_window.refresh
        @equip_window.refresh
        @status_window.refresh
        @materia_window.refresh
        @equip_window.activate
        @item_window.unselect
      end
      #--------------------------------------------------------------------------
      # * on_item_cancel
      #--------------------------------------------------------------------------
      def on_item_cancel
        @equip_window.activate
        @item_window.unselect
      end
    end
    
    #==============================================================================
    # ** Scene_ItemBase
    #------------------------------------------------------------------------------
    #  This class performs common processing for the item screen and skill screen.
    #==============================================================================
    
    class Scene_ItemBase < Scene_MenuBase
      #--------------------------------------------------------------------------
      # * Overwrite method: determine_item
      #--------------------------------------------------------------------------
      def determine_item
        if item.for_friend?
          show_sub_window(@actor_window)
          for_all = item.for_all? || (@actor && @actor.for_all?(item))
          @actor_window.select_for_item(item, for_all)
        else
          use_item
          activate_item_window
        end
      end
      #--------------------------------------------------------------------------
      # * Overwrite method: item_target_actors
      #--------------------------------------------------------------------------
      def item_target_actors
        if !item.for_friend?
          []
        elsif item.for_all? || (@actor && @actor.for_all?(item))
          $game_party.members
        else
          [$game_party.members[@actor_window.index]]
        end
      end
    end
    
    #==============================================================================
    # ** Scene_MateriaShop
    #------------------------------------------------------------------------------
    #  This class performs materia shop screen processing.
    #==============================================================================
    
    class Scene_MateriaShop < Scene_MenuBase
      #--------------------------------------------------------------------------
      # * prepare
      #--------------------------------------------------------------------------
      def prepare(goods)
        @goods = goods
        @goods.delete_if {|m| m[0] != 2 || !$data_armors[m[1]].materia? }
      end
      #--------------------------------------------------------------------------
      # * start
      #--------------------------------------------------------------------------
      def start
        super
        create_help_window
        create_gold_window
        create_command_window
        create_dummy_window
        create_status_window
        create_buy_window
        create_sell_window
      end
      #--------------------------------------------------------------------------
      # * create_help_window
      #--------------------------------------------------------------------------
      def create_help_window
        @help_window = Window_Help.new(1)
        @help_window.viewport = @viewport
      end
      #--------------------------------------------------------------------------
      # * create_gold_window
      #--------------------------------------------------------------------------
      def create_gold_window
        @gold_window = Window_Gold.new
        @gold_window.viewport = @viewport
        @gold_window.x = Graphics.width - @gold_window.width
        @gold_window.y = @help_window.height
      end
      #--------------------------------------------------------------------------
      # * create_command_window
      #--------------------------------------------------------------------------
      def create_command_window
        @command_window = Window_ShopCommand.new(@gold_window.x, false)
        @command_window.viewport = @viewport
        @command_window.y = @help_window.height
        @command_window.set_handler(:buy,    method(:command_buy))
        @command_window.set_handler(:sell,   method(:command_sell))
        @command_window.set_handler(:cancel, method(:return_scene))
      end
      #--------------------------------------------------------------------------
      # * create_dummy_window
      #--------------------------------------------------------------------------
      def create_dummy_window
        wy = @command_window.y + @command_window.height
        wh = Graphics.height - wy
        @dummy_window = Window_Base.new(0, wy, Graphics.width, wh)
        @dummy_window.viewport = @viewport
      end
      #--------------------------------------------------------------------------
      # * create_status_window
      #--------------------------------------------------------------------------
      def create_status_window
        wy = @command_window.y + @command_window.height
        ww = 312 + [Graphics.width - 544, 0].max
        wh = Graphics.height - wy
        @status_window   = Window_MateriaInfo.new(ww, wh, true)
        @status_window.x = Graphics.width - @status_window.width
        @status_window.y = wy
        @status_window.viewport = @viewport
        @status_window.hide
      end
      #--------------------------------------------------------------------------
      # * create_buy_window
      #--------------------------------------------------------------------------
      def create_buy_window
        wy = @command_window.y + @command_window.height
        ww = Graphics.width  - @status_window.width
        wh = Graphics.height - wy
        @buy_window = Window_MateriaShop.new(wy, ww, wh, @goods)
        @buy_window.viewport = @viewport
        @buy_window.help_window = @help_window
        @buy_window.materia_window = @status_window
        @buy_window.hide
        @buy_window.set_handler(:ok,     method(:on_buy_ok))
        @buy_window.set_handler(:cancel, method(:on_buy_cancel))
      end
      #--------------------------------------------------------------------------
      # * create_sell_window
      #--------------------------------------------------------------------------
      def create_sell_window
        wy = @command_window.y + @command_window.height
        ww = Graphics.width  - @status_window.width
        wh = Graphics.height - wy
        @sell_window = Window_MateriaShop.new(wy, ww, wh)
        @sell_window.viewport = @viewport
        @sell_window.help_window = @help_window
        @sell_window.materia_window = @status_window
        @sell_window.hide
        @sell_window.set_handler(:ok,     method(:on_sell_ok))
        @sell_window.set_handler(:cancel, method(:on_sell_cancel))
      end
      #--------------------------------------------------------------------------
      # * activate_buy_window
      #--------------------------------------------------------------------------
      def activate_buy_window
        @buy_window.money = money
        @buy_window.show.activate
        @status_window.show
      end
      #--------------------------------------------------------------------------
      # * activate_sell_window
      #--------------------------------------------------------------------------
      def activate_sell_window
        @sell_window.money = money
        @sell_window.show.activate
        @status_window.show
      end
      #--------------------------------------------------------------------------
      # * command_buy
      #--------------------------------------------------------------------------
      def command_buy
        @dummy_window.hide
        activate_buy_window
      end
      #--------------------------------------------------------------------------
      # * command_sell
      #--------------------------------------------------------------------------
      def command_sell
        @dummy_window.hide
        activate_sell_window
      end
      #--------------------------------------------------------------------------
      # * on_buy_ok
      #--------------------------------------------------------------------------
      def on_buy_ok
        Sound.play_shop
        @item = @buy_window.materia
        $game_party.lose_gold(buying_price)
        $game_party.gain_item(@item, 1)
        activate_buy_window
        refresh_windows
      end
      #--------------------------------------------------------------------------
      # * on_buy_cancel
      #--------------------------------------------------------------------------
      def on_buy_cancel
        @command_window.activate
        @dummy_window.show
        @buy_window.hide
        @status_window.hide
        @help_window.clear
      end
      #--------------------------------------------------------------------------
      # * on_sell_ok
      #--------------------------------------------------------------------------
      def on_sell_ok
        Sound.play_shop
        @item = @sell_window.materia
        $game_party.gain_gold(selling_price)
        $game_party.lose_materia(@sell_window.index)
        activate_sell_window
        index = @sell_window.index
        @sell_window.select([[index, @sell_window.item_max - 1].min, 0].max)
        refresh_windows
      end
      #--------------------------------------------------------------------------
      # * on_sell_cancel
      #--------------------------------------------------------------------------
      def on_sell_cancel
        @command_window.activate
        @dummy_window.show
        @status_window.hide
        @sell_window.hide
        @help_window.clear
      end
      #--------------------------------------------------------------------------
      # * refresh_windows
      #--------------------------------------------------------------------------
      def refresh_windows
        @gold_window.refresh
        @status_window.refresh
      end
      #--------------------------------------------------------------------------
      # * money
      #--------------------------------------------------------------------------
      def money
        @gold_window.value
      end
      #--------------------------------------------------------------------------
      # * currency_unit
      #--------------------------------------------------------------------------
      def currency_unit
        @gold_window.currency_unit
      end
      #--------------------------------------------------------------------------
      # * buying_price
      #--------------------------------------------------------------------------
      def buying_price
        @buy_window.price(@item)
      end
      #--------------------------------------------------------------------------
      # * selling_price
      #--------------------------------------------------------------------------
      def selling_price
        @item.sell_price
      end
    end
    
    #==============================================================================
    # ** Scene_Battle
    #------------------------------------------------------------------------------
    #  This class performs battle screen processing.
    #==============================================================================
    
    class Scene_Battle < Scene_Base
      #--------------------------------------------------------------------------
      # * Overwrite method: on_skill_ok
      #--------------------------------------------------------------------------
      alias :on_skill_ok_ve_materia_system :on_skill_ok
      def on_skill_ok
        @skill = @skill_window.item
        actor  = BattleManager.actor
        if actor.for_all?(@skill) &&  !$imported[:ve_target_arrow]
          actor.input.set_skill(@skill.id)
          actor.last_skill.object = @skill
          @skill_window.hide
          next_command
        else
          on_skill_ok_ve_materia_system
        end
      end
      #--------------------------------------------------------------------------
      # * Alias method: battle_start
      #--------------------------------------------------------------------------
      alias :battle_start_ve_materia_system :battle_start
      def battle_start
        battle_start_ve_materia_system
        reset_materia_all
      end
      #--------------------------------------------------------------------------
      # * Alias method: pre_terminate
      #--------------------------------------------------------------------------
      alias :pre_terminate_ve_materia_system :pre_terminate
      def pre_terminate
        pre_terminate_ve_materia_system
        reset_materia_all
      end
      #--------------------------------------------------------------------------
      # * New method: reset_materia_all
      #--------------------------------------------------------------------------
      def reset_materia_all
        $game_party.members.each do |actor|
          actor.all_materias.compact.each {|materia| materia.reset_times }
        end
      end
    end

     

    Hopefully this makes sense. Let me know if you have any questions.

     

    Thank you! 😎


  14. Hello! :) 

     

    I was hoping someone could help me a small change to MOG's Battle Result script.

     

    By default, when you level up and learn skills, it will cycle through all the new skills you've just learned. The issue I'm running into through is that I actually give characters a bunch of skills upon level up, but only access to certain skills, based on their class. 

     

    What I'm hoping is to tweak the script to instead of going through all the unlocked skills, to instead just say "New Skills Learned" once (as opposed to giving the message for each individual skill).

     

    I hope this makes sense. By all means, let me know if you have any questions.

     

    Thank you!


  15. Thank you for the advice everyone! :)

     

    7 hours ago, roninator2 said:

    This may be resolved as the member posted this question on RPGMakeWeb which Sixth responded with a snippet. 

    Indeed, Sixth helped me get things worked out last night, so all is good now. 

    • Like 1

  16. Hello! :) 

     

    I was hoping someone could help me create a, inventory related script.

     

    What I'm hoping to create is a "Battle Pouch", which essentially acts as a secondary inventory (with a limited capacity, ideally based on a variable, for the sake of future-proofing). In battle, using the item command would not give you access to your main inventory, but instead only to the items you placed into your Battle Pouch beforehand. 

     

    As a side note, I don't know if it would be easier to go about making this from scratch, or by building off of an existing script, but I do already make use of the Storage Boxes script. These do allow you to place items in a separate inventory, although I don't know if accessing them/using them in battle would be feasible. I just thought I'd toss the idea out there in case it makes things easier.

     

    I hope this all makes sense. By all means, let me know if you have any questions.

     

    Thank you!

    • Like 1

  17. @PhoenixSoul

    Ah, I kinda figured that might be the case. I'm in the same boat as you as far as scripts go, I kinda just fumble around until things work out.

     

    @Kayzee

    Huh, that's pretty clever, and works great! Thanks a ton! :)

    • Like 1
×
Top ArrowTop Arrow Highlighted