设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 128|回复: 0

[转载发布] Abilities System

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    9071

    主题

    864

    回帖

    6万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    58883
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    68848

    灌水之王

    发表于 2026-7-31 22:06:05 | 显示全部楼层 |阅读模式
    Abilities System

    By Paramecium13​


    This is a simple script that adds 'abilities' to actors. An ability can be either leveled or not leveled. A leveled ability has a number, its level associated with it (e.g. Smithing: Level 27), whereas an ability that is not leveled does not. This script has a section where you can add more abilities, using the same format as the example abilities. Abilities must be viewed and modified by script calls, using the methods contained in the script.

    Features:


    • Add and remove abilities
    • Enable or disable abilities(this is different than adding or removing, for example, if someone who knows smithing has a broken arm they cannot smith, thus smiting would be disabled, but they could still tell someone how to smith or read about how to smith better),
    • Check if an actor has a specific ability and if it is enabled
    • Get the level of a leveled ability (using this on an ability that is not leveled returns '1')
    • Increase or decrease the level of an ability
    • Check if any actor in the party has an ability
    • Find who has the highest level of an ability in the party and what that level is.
    • Perform an ability check, using a normal distribution, for actors and for parties
    • Perform a simple ability check, which checks if the ability level is at least the difficulty level, for actors and parties
    • Weapons, armors, and states can modify ability levels, by putting <AbilityBonus: abilityId,n> into the notes field in the data base. 'abilityId' should be the ID of the ability you want to affect without a colon in front of it (e.g. 'smithing' instead of ':smithing') and 'n' should be the amount you want to change the ability by.
    • A very simple (i.e. ugly) scene that shows abilities and their levels; accessed from the main menu
    • Crafting abilities, which can be use to craft items.  Crafting abilities can start off with recipes already learned (but which may require a higher ability level) and can have additional recipes added by script calls.
    This script requires my core script.

    Spoiler#==============================================================================##                                                                              ##                        Paramecium Core V 0.1                                       ##                                June 28, 2015                                       ##                                                                              ##------------------------------------------------------------------------------## This is my core script, required for some of my other scripts. You may use   ## the classes and methods in it in your scripts as long as you give me credit. ##==============================================================================#($imported ||= {})["Paramecium"] = truemodule Paramecium        #Uses the Box–Muller transform to generate normally distributed random numbers        def self.stnRand()                return Math.sqrt( -2 * Math.log(rand())) * Math.cos( 2 * Math:
    I * rand())        end          # Generates normally distributed numbers with a mean of μ and a standard  # deviation of σ.        def self.nRand(μ,σ)                return μ + stnRand()* σ        end          # Performs a "skill check" with a difficulty level of 'difficulty'.        # returns true if the player (or whoever is performing the skill check)        # passes it and false if they fail. When the skill level is equal to the        # difficulty level, there is a fifty percent chance of passing. This        # method uses a default standard deviation of 2.5, which was chosen arbitrarily.        def self.skillCheck(skillLevel, difficulty,s = 2.5)                x = nRand(skillLevel, s)                return x >= difficulty        end          def self.show_selection(array)                params = []                choices = []                array.each{|item|                        choices.push(item[0])                }                                params.push(choices)                params.push(0)                params[0].each {|s| $game_message.choices.push(s) }                #$game_message.choice_cancel_type = params[1]                $game_message.choice_proc = Proc.new {|x| $paramecium_choice =(x) }        end        def self.get_choice(array)                array[$paramecium_choice][1]        end          # This method calls a scene that shows a list of choices for the player and ]        # returns an object depending on their choice and the array you put into this        # method. The parameter 'array' is an array of the form:        #[["string_0",object_0],["string_1",object_1],...,["string_(n-1)",object_(n-1)]];        # with a length of n. The method will display the strings in a choice window,         # similar to the one used for events                def self.selection(array)                show_selection(array)                Fiber.yield until not $game_message.busy?                get_choice(array)        end        def self.multipleChoice(array,duplicates=false)                array << ["End","End"]                results = []                while true                        r = selection(array)                        r == "End" ? break : results << r                end                duplicates ? results : results.uniq || results        end          def self.invContains?(array,type)                case type.downcase[0,1]                when "i"                        getVal = Proc.new {|n| $game_party.item_number($data_items[n])}                when "w"                        getVal = Proc.new {|n| $game_party.item_number($data_weapons[n])}                when "a"                        getVal = Proc.new {|n| $game_party.item_number($data_armors[n])}                else                        return false                end                array.each {|entry|                        return false unless getVal.call(entry[0]) >= entry[1]                }        end          def self.changeInv(array,type)                case type.downcase[0,1]                when "i"                        change = Proc.new {|n, amount|                                if n >= 0                                        $game_party.gain_item($data_items[n], amount)                                else                                        $game_party.lose_item($data_items[n], amount)                                end                        }                when "w"                        change = Proc.new {|n, amount|                                if n >= 0                                        $game_party.gain_item($data_items[n], amount)                                else                                        $game_party.lose_item($data_items[n], amount)                                end                        }                when "a"                        change = Proc.new {|n, amount|                                if n >= 0                                        $game_party.gain_item($data_items[n], amount)                                else                                        $game_party.lose_item($data_items[n], amount)                                end                        }                else                        return false                end                array.each {|entry|                        change.call(entry[0],entry[1])                }        end          # Returns an array with the specified position(s) in its sub-arrays negated.        def self.negatePos(array,pos)                r = []                if pos.is_a? Array                        myCheck = Proc.new {|i| pos.include?(i)}                else                        myCheck = Proc.new {|i| i == pos}                end                array.each{|entry|                        entryClone = []                        entry.each_index {|i|                                entryClone.push(myCheck.call(i)? -1*entry : entry)                        }                        r.push(entryClone)                }                r        end                class MultiMap                def initialize(hash)                        @data = hash                        @length = hash.length                        @domain = hash.keys                end                def image(x)                        return @hash[x]                end                def preImage(y)                        arr = Array.new                        for i in 0..@length-1                                arr << @domain if @data[@domain].index(y)                        end                        return arr                end        end    #         This implements a priority queue in which each element consists of an        # object (e.g a string, an array, or a number [such as an item id]) and a rank        # (e.g actor ID and number of skills), in that order. It is initialized from        # an array of the form:        #                         [[object-1,rank-1],[object-2,rank-2],...[object-n,rank-n]].        # The nested array [object-i,rank-i] is called an entry.         #        #        The methods 'max' and 'min' return the entries with the highest and lowest        # rankings respectively. When two or more entries have the same rank, it        # returns the one that has the lowest index in the array {i.e. that comes        # first).         #         The method 'sort!' sorts the data from highest ranked to lowest ranked. If        # two or more entries have the same rank, the one that had the        # lowest index before 'sort!' will have the lowest index after, with entries         # of equal rank following behind. The method 'add' adds another entry to the        # Ranking.        #         The method 'nextR!' returns the entry with the highest rank (in cases of         # equal rank, the same rule as above applies) and removes it from the Ranking.        #         The method 'next!' returns the object in the entry        # with the highest rank and removes its entry from the Ranking.        #                The 'blackjack(n)' method returns the object with the value closest to but        # not exceeding n, like in the card game blackjack the goal is to get as close        # to 21 without going over.        #         The 'blackjack!(n)' method does the same thing as 'blackjack' but also        # removes entry of the returned object.        class Ranking                def initialize(array)                        @data = array                        @length = array.length                end                def min                        m = @data[0]                        for i in 1..@length-1                                if @data[1]<m[1]                                        m = @data                                end                        end                        return m;                end                def max()                        m = @data[0]                        for i in 1..@length-1                                if @data[1]>m[1]                                        m = @data                                end                        end                        return m;                end                def sort!                        arr = Array.new                        for i in 0..@length-1                                arr <<self.nextR!                        end                        @data = arr                end                def add(newEntry)                        if newEntry.is_a?(Array) && newEntry[1].is_a(Numeric)                                @data << newEntry                                @length += 1                        end                end                def nextR!                        m = @data[0]                        index = 0                        for i in 1..@length-1                                if @data[1]>m[1]                                        m = @data                                        index = i                                end                        end                        @data.delete_at(index)                        @length -= 1                        return m;                end                def next!                        return self.nextR![0]                end                def blackjack(n)                        b = @data[0]                        for i in 1..@length-1                                if ((m[1]>n&&@data[1]<=n)||(@data[1]<n&&@data[1]>m[1]))                                        m = @data                                end                        end                        return m                end                def blackjack!(n)                        b = @data[0]                        index = 0                        for i in 1..@length-1                                if ((m[1]>n&&@data[1]<=n)||(@data[1]<n&&@data[1]>m[1]))                                        m = @data                                        index = i                                end                        end                        @data.delete_at(index)                        return m                end        endend# Adds two new methods to the 'Array' classclass Array        # Is this array a subset of 'other'? (i.e are all elements of this array         # elements of the other array?)        def subset?(other)                self.each{|item|                        return false unless other.include?(item)                }                return true        end        # Is this array a superset of 'other' (is 'other' a subset of this array)?         # (i.e are all elements of the other array elements of this array?)        def superset?(other)                other.subset?(self)        end        # Does 'other' have the same elements as 'self' and 'self' the same elements        # as 'other'?         # [Are the two arrays equal, ignoring order?]                def setEquals?(other)                self.subset?(other) && self.superset?(other)        end        unless $imported[:ve_basic_module]                def random                        self[rand(self.length)]                end        endend





    For more information see the script itself.

    Script

    Spoiler#################################################################################                                                                                ##                        Abilities System V1                                        ##                        June 28, 2015                                                ##                        By Paramecium13                                                ##                                                                                ##################################################################################===============================================================================# This is my abilities script. It allows you to define custom abilities that # actors can learn.# # #-------------------------------------------------------------------------------#        To do-list:#        *Write better descriptions#        *Better formatting of said descriptions#        *Better Windows and scenes#        *More items on the to-do list#===============================================================================($imported ||= {})["Paramecium-Abilities"] = trueclass Game_Actor < Game_Battler  attr_accessor   :abilitiesendmodule AbilitiesSystem#-------------------------------------------------------------------------------#        The following method needs to be called once at the start of a new game,#        before any methods dealing with abilities are called.#-------------------------------------------------------------------------------        #def self.initializeAbilities        #        for i in 1..(25)                #$game_actors.length        #                $game_actors.abilities = {} if $game_actors        #        end        #end#===============================================================================#        This is the list of abilities. Add more abilities by using the same format as#        the abilities presented as examples. A levelled ability is just what it sounds#        like, it has levels (e.g. at level 72 smithing you can craft mithril stuff,#        or at level 25 divination you have a 50% chance of detecting if a chest is a#        trap or not). #        The symbol ':id' must point to the same symbol that the list#        (which is a hash) uses to access that ability.#        The symbol ':name' points to a string that contains the in game name of that#        ability.#        The symbol ':desc' points to a string containing the in game description of#        the ability.#        The symbol ':levelled' points to the boolean that says if it is a levelled #        ability, the following symbols for levelled abilities will be ignored if it is#        false.#        The symbols ':min' and ':max' point to the minimum and maximum levels of that#        ability, respectively. You cannot make its level higher than the max or lower#        than the min. I would like to implement "soft" minimums and maximums, which#        can only be exceeded by temporary boosts or equipment.##                        WARNING: Don't forget the commas!!!!##===============================================================================        AbilityList = {                :reading =>                {                        :id                =>        :reading,                        :name                =>        "Reading",                        :desc                =>        "Can read",                        :levelled        =>        false                },                :smithing =>                {                        :id                =>        :smithing,                        :name                =>        "Smithing",                        :desc                =>        "The ability to shape metals into tools, weapons, and armours",                        :levelled        =>        true,                        :crafting        =>        true,                        :recipes        =>        [                                                                ],                        :min                =>        1,                        :max                =>        100,                        :σ                =>        2*3.14159265359                },               
    rettyLights =>                {                        :id                =>       
    rettyLights,                        :name                =>        "Lights",                        :desc                =>        "Makes pretty magic lights",                        :levelled        =>        false,                        :cost                =>        {                # Yay, another hash                                :mp                => 5                        }                },                :fireworks =>                {                        :id                =>        :fireworks,                        :name                =>        "Fireworks",                        :desc                =>        "Makes fireworks",                        :levelled        =>        false,                        :cost                =>        {                                :items        => [[20,1]]                                # ItemId,amount                        }                }        }                recipeList = {                :recipe1 => {                        :id                => :club,                        :name                => "Wooden Club",                        :requiredLevel        => 10,                        :doAbCheck        => false,                        :used                =>{                                :items                        => [[17,1]],                                :weapons                => [],                                :armors                        => []                        },                        :needed                        => {                                :items                        => [],                                :weapons                => [],                                :armors                        => []                        },                        :made                        => {                                :items                        => [],                                :weapons                => [],                                :armors                        => []                        }                }        }#===============================================================================#                        Methods for Use in Events#-------------------------------------------------------------------------------#   To use one of these methods in a script call enter#       AbilitiesSystem.method(param1,param2,...)#   where method is the name of the method you want to use and param1,param2 are#   the parameters for the method, as given in its description or definition#-------------------------------------------------------------------------------#===============================================================================#                        Controls#-------------------------------------------------------------------------------#   These methods allow you to add, remove, and modify an actor's abilities. If#   try to use one of these methods to modify an ability an actor doesn't have,#   nothing will happen (and the game will not crash).#===============================================================================# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##        These add and remove an ability to an actor        # Parameters:#   actorId: The id of the actor whom you want to learn the ability#   abilityId: The id of the ability you want the actor to learn# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#        def self.addAbility(actorId,abilityId)                return false if hasAbility?(actorId,abilityId)                if not AbilityList[abilityId][:levelled]                        $game_actors[actorId].abilities[abilityId] = Ability.new(AbilityList[abilityId],actorId)                elsif AbilityList[abilityId][:crafting]                        $game_actors[actorId].abilities[abilityId] = CraftingAbility.new(AbilityList[abilityId],actorId)                else                        $game_actors[actorId].abilities[abilityId] = LevelledAbility.new(AbilityList[abilityId],actorId)                end        end        def self.removeAbility(actorId,abilityId)                $game_actors[actorId].abilities.delete(abilityId) if $game_actors[actorId].abilities        end# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##        These enable, disable, and toggle whether or not an actor's ability is enabled.# Parameters:#   actorId: The id of the actor whose ability you want to enable/disable/toggle#   abilityId: The ability you want to enable/disable/toggle# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#        def self.enableAbility(actorId,abilityId)                ab = $game_actors[actorId].abilities[abilityId]                ab.enable        end        def self.disableAbility(actorId,abilityId)                ab = $game_actors[actorId].abilities[abilityId]                ab.disable                end        def self.toggleAbility(actorId,abilityId)                ab = $game_actors[actorId].abilities[abilityId]                if ab.enabled                        ab.disable                else                        ab.enable                end        end        # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##        This increases the level of an actor's ability# ()# Parameters:#   actorId: The id of the actor whose ability level you want to change#   abilityId: The ability whose level you want to change#   n: The ammount you want to change the level by, to decrease it, make 'n' #      negative# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#        def self.increaseLevel(actorId, abilityId,n)                if AbilityList[abilityId][:levelled] && hasAbility?(actorId,abilityId)                        ab = $game_actors[actorId].abilities[abilityId]                        ab.increase(n)                end        end#===============================================================================#                                Individual Checks#-------------------------------------------------------------------------------#   These methods allow you to #-------------------------------------------------------------------------------#        This returns the level of the ability# Parameters:#   actorId: The id of the actor whose ability you want to enable/disable/toggle#   abilityId: The ability you want to enable/disable/toggle# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#        def self.getLevel(actorId, abilityId)    return false unless hasAbility?(actorId,abilityId)                $game_actors[actorId].abilities[abilityId].getLevel        end        #        This checks if an actor has a specified ability.                def self.hasAbility?(actorId,abilityId)                $game_actors[actorId].abilities = {} unless $game_actors[actorId].abilities                return $game_actors[actorId].abilities.include?(abilityId)        end        #        This checks if an actor has a specified ability and if it is enabled.        def self.hasAbilityE?(actorId,abilityId)                return false unless hasAbility?(actorId,abilityId)                $game_actors[actorId].abilities[abilityId].enabled        end  #        Performs an 'ability check' on the ability, using a normal distribution.        def self.check(abilityId,actorId,difficulty,s=0)                return false unless hasAbilityE?(actorId,abilityId)                ab = $game_actors[actorId].abilities[abilityId]                s = ab.σ if s = 0                return ab.check(difficulty,s)        end  #        Checks if the ability level is >= the difficulty level.        def self.simpleCheck(abilityId,actorId,difficulty)                return false unless hasAbilityE?(actorId,abilityId)                level = $game_actors[actorId].abilities[abilityId].level                return level >= difficulty        end#-------------------------------------------------------------------------------#                                Party Checks#-------------------------------------------------------------------------------#        Checks if anyone in the party has that ability, returns an array of ids of# actors who have it.        def self.p_hasAbility?(abilityId)                r = []                actors = $game_party.members                for i in 0..(actors.length-1)                        j = actors.id                        if hasAbility?(j,abilityId)                                r.push(j)                        end                end                r.empty? ? false : r        end  #        Checks if anyone in the party has the ability enabled        def self.p_hasAbilityE?(abilityId)                r = []                actors = $game_party.members                for i in 0..(actors.length-1)                        j = actors.id                        if hasAbilityE?(j,abilityId)                                r.push(j)                        end                end                r.empty? ? false : r        end  #        Returns an array whose first entry is the id of the actor with the highest # level in the ability and whose second entry is their level in that ability.        def self.p_highestLevel(abilityId)                abilityRanking(abilityId).max        end  #        These two methods perform the same 'checks' as 'check' and 'simpleCheck'#        except they use the highest level of the skill in the party        def self.p_check(abilityId,difficulty,s=0)                x = p_highestLevel(abilityId)                s = $game_actors[x[0]].abilities[abilityId].σ if s == 0                return Paramecium.abilityCheck(x[1], difficulty, s)        end        def self.p_simpleCheck(abilityId,difficulty)                mLevel = p_highestLevel(abilityId)                return mLevel >= difficulty        end          #        Creates the levelled ability Ranking for the levelled ability 'abilityId'        def self.abilityRanking(abilityId)                ids = $game_party.members.collect {|actor| actor.id}                arr = Array.new                for i in 0..(ids.length-1)                        arr = [ids,getLevel(ids, abilityId)]                end                return Paramecium::Ranking.new(arr)        end#-------------------------------------------------------------------------------#                                Ability Class#-------------------------------------------------------------------------------        class Ability                attr_reader               
    wnerId                attr_reader                :id                attr_accessor        :name                attr_accessor        :iconId                attr_accessor        :description                attr_accessor        :enabled                attr_accessor        :mpCost                attr_accessor        :SE                attr_accessor        :SE_pass                attr_accessor        :SE_fail                def initialize(hash,actorId)                        #@h = hash                        @name                        = hash[:name] ? hash[:name] : hash[:id]                        @description        = hash[:desc]                        @iconId                        = hash[:iconId]                        @id                                = hash[:id]                        @enabled                = true                        @ownerId                = actorId                        @SE                                = hash[:SE]                        @SE_pass                = hash[:SE_pass]                        @SE_fail                = hash[:SE_fail]                        if hash[:cost]                                @mpCost                = hash[:cost][:mp]                ? hash[:cost][:mp]                : 0                                @itemCost        = hash[:cost][:items]        ? hash[:cost][:items]        : []                                @weaponCost        = hash[:cost][:weapon]        ? hash[:cost][:weapon]        : []                                @armorCost        = hash[:cost][:armor]        ? hash[:cost][:armor]        : []                        end                end                def getLevel;                        return 1;                                end                # Plays the sound effect for the ability (if it has one)                def playSound                        if @SE                                Audio.se_play(@SE)                        end                end                def canAfford?                        return false unless $game_actors[@ownerId].mp >= @costHash[:mp]                        return false unless Paramecium.invContains?(@itemCost,"ice")                        return false unless Paramecium.invContains?(@weaponCost,"wet")                        return false unless Paramecium.invContains?(@armorCost,"Arctic")                        return true                end                        def useCost                        $game_actors[@ownerId].mp -= @costHash[:mp] if @costHash[:mp]                        Paramecium.changeInv(Paramecium.negatePos(@itemCost,1),"i")                        Paramecium.changeInv(Paramecium.negatePos(@weaponCost,1),"w")                        Paramecium.changeInv(Paramecium.negatePos(@armorCost,1),"a")                end                        def use                # Returns true if it was used successfully                        playSound                        if canAfford? && @enabled                                if @SE_pass                                        Audio.se_play(@SE_pass)                                end                                useCost                                return true                        else                                if @SE_fail                                        Audio.se_play(@SE_fail)                                end                                return false                        end                end        end#-------------------------------------------------------------------------------#                                Levelled Ability Class#-------------------------------------------------------------------------------        class LevelledAbility < Ability                attr_accessor        :max                attr_accessor        :min                attr_accessor        :σ                def initialize(hash,actorId)                        super(hash,actorId)                        @min        = hash[:min]                                # The minimum allowed level                        @max        = hash[:max]                                # The maximum allowed level                        @σ                = hash[:σ] ? hash[:σ] : 2.5        # The default standard deviation                        @level        = self.min                                        end                # Gets the level of this ability without applying bonuses                def getRawLevel;        return        @level;                                end                def getLevel;                return        @level + bonuses;        end                # Increases the level of the ability within the range [min,max]                def increase(n)                        if @max && @level + n >= @max                                @level = max                        else                                if @min && @level + n <= @min                                        @level = @min                                else                                        @level += n                                end                        end                end                # Scales the level of the ability within the range [min,max]                def scale(n)                        if @max && @level * n >= @max                                @level = max                        else                                if @min && @level * n <= @min                                        @level = @min                                else                                        @level *= n                                end                        end                end                def reset;                @level = @min;        end                def set(n);                @level = n;                end                def armBonus(armorID)                        $sub = @id.to_s                        $data_armors[armorID].note[/<AbilityBonus:\s*#{$sub},([0-9]+)>/i]                        if $1 && $1 != ""                                val = $1.to_i                                return val                        else                                return 0                        end                end                def armorBonus                        b = 0                        armors = $game_actors[@ownerId].armors                        armorIds = armors.collect {|a| a.id}                        for i in 0..(armorIds.length-1)                                b += armBonus(armorIds)                        end                        return b                end                def wBonus(weaponID)                        $sub = @id.to_s                        $data_weapons[weaponID].note[/<AbilityBonus:\s*#{$sub},([0-9]+)>/i]                        if $1 && $1 != ""                                val = $1.to_i                                return val                        else                                return 0                        end                end                def weaponBonus                        b = 0                        weapons = $game_actors[@ownerId].weapons                        weaponIds = weapons.collect {|a| a.id}                        for i in 0..(weaponIds.length-1)                                b += wBonus(weaponIds)                        end                        return b                end                def sBonus(stateID)                        $sub = @id.to_s                        $data_weapons[stateID].note[/<AbilityBonus:\s*#{$sub},([0-9]+)>/i]                        if $1 && $1 != ""                                val = $1.to_i                                return val                        else                                return 0                        end                end                        def stateBonus                        b = 0                        states = $game_actors[@ownerId].states                        stateIds = states.collect {|a| a.id}                        for i in 0..(stateIds.length-1)                                b += sBonus(stateIds,abilityId)                        end                        return b                end                def bonuses                        return armorBonus + weaponBonus + stateBonus                end                def check(difficulty,s = @σ)                        lvl = @level + bonuses                        return Paramecium.abilityCheck(lvl, difficulty,s)                end                def use(difficulty,s = @σ)        # Returns true if it was used successfully                        if canAfford? && @enabled                                if check(difficulty,s)                                        Audio.se_play(@SE_pass) if @SE_pass                                        true                                else                                        Audio.se_play(@SE_fail) if @SE_fail                                        false                                end                        else                                if @SE_fail                                        Audio.se_play(@SE_fail)                                end                                false                        end                end        end#-------------------------------------------------------------------------------#                                Recipe Class#-------------------------------------------------------------------------------        class Recipe                attr_reader                :name                attr_reader                :usedItems                attr_reader                :usedWeapons                attr_reader                :usedArmors                attr_reader                :neededItems                attr_reader                :neededWeapons                attr_reader                :neededArmors                attr_reader                :madeItems                attr_reader                :madeWeapons                attr_reader                :madeArmors                def initialize(hash,actorId,abilityId)                        @id                                = hash[:id].to_s                        @name                        = hash[:name]        ? hash[:name]        : hash[:id]                        @requiredLevel        = hash[:level]        ? hash[:level]        : 1                        @doAbCheck                = hash[:doAbCheck]                                                @usedItems                = hash[:used][:items]                || []                        @usedWeapons        = hash[:used][:Weapons]                || []                        @usedArmors                = hash[:used][:Armors]                || []                                                @neededItems        = hash[:needed][:items]                || []                        @neededWeapons        = hash[:needed][:Weapons]        || []                        @neededArmors        = hash[:needed][:Armors]        || []                                                @madeItems                = hash[:made][:items]                || []                        @madeWeapons        = hash[:made][:Weapons]                || []                        @madeArmors                = hash[:made][:Armors]                || []                end                # Does the player have the required materials?                def hasMaterials?                        return false unless Paramecium.invContains?(@usedItems,"ice")                        return false unless Paramecium.invContains?(@usedWeapons,"wet")                        return false unless Paramecium.invContains?(@usedArmors,"Arctic")                                                return false unless Paramecium.invContains?(@neededItems,"Insect")                        return false unless Paramecium.invContains?(@neededWeapons,"Waterloo")                        return false unless Paramecium.invContains?(@neededArmors,"Arthropod")                end                # Can the player craft this?                def canCraft?                        abilityLevel = $game_actors[@actorId].abilities[@abilityId].getLevel                        abilityLevel >= @requiredLevel && hasMaterials?                end                                def craft                        Paramecium.changeInv(@madeItems,"i")                        Paramecium.changeInv(@madeWeapons,"w")                        Paramecium.changeInv(@madeArmors,"a")                                                Paramecium.changeInv(Paramecium.negatePos(@usedItems,1),"i")                        Paramecium.changeInv(Paramecium.negatePos(@usedWeapons,1),"w")                        Paramecium.changeInv(Paramecium.negatePos(@usedArmors,1),"a")                end        end        #-------------------------------------------------------------------------------#                                Crafting Ability Class#-------------------------------------------------------------------------------        class CraftingAbility < LevelledAbility                attr_reader                :recipes                def initialize(hash,actorId)                        super(hash,actorId)                        @recipes = []                        hash[:recipes].each {|r| addRecipe(r)} if hash[:recipes]                end                def addRecipe(r)                        h = recipeList[r] ? recipeList[r] : r                        @recipes.push(Recipe.new(h,actorId,@id))                end                # Returns the description of the selected recipe                def showAll                        c = []                        @recipes.each{|recipe|                                c.push([recipe.name,recipe.description])                        }                        Paramecium.selection(c)                end                def getCraftable        # With names                        craftable = []                        @recipes.each_index{|i|                                craftable.push(@recipes.name,i) if @recipes.canCraft?                        }                        craftable                end                # Returns the description of the selected recipe                def showCraftable                        @recipes[Paramecium.selection(getCraftable)].description                end                def chooseCraftable                        @recipes[Paramecium.selection(getCraftable)].craft                end        endend# Ability Scene and Windowclass Scene_Menu < Scene_MenuBase        alias abilitySystem_create_command_window create_command_window        def create_command_window                abilitySystem_create_command_window                @command_window.set_handler
    abilities,                method
    command_personal))        end        def ccw_abilities                msgbox_p("Abilities menu is under construction")                SceneManager.call(Scene_Menu)        end        alias paramecium_personal_ok on_personal_ok        def on_personal_ok                return SceneManager.call(Scene_Abilites) if @command_window.current_symbol == :abilities                paramecium_personal_ok        endendclass Window_MenuCommand < Window_Command        alias abilitySystem_add_original_commands add_original_commands        def add_original_commands                abilitySystem_add_original_commands                add_command("Abilities",:abilities)        end        endclass Scene_Abilites < Scene_MenuBase        def start                super                @ability_window = Window_Abilities.new(@actor)                @ability_window.set_handler
    cancel,   method
    return_scene))                @ability_window.set_handler
    pagedown, method
    next_actor))                @ability_window.set_handler
    pageup,   method
    prev_actor))        end        def on_actor_change                @ability_window.actor = @actor                @ability_window.activate        endendclass Window_Abilities < Window_Selectable        def initialize(actor)                super(0, 0, Graphics.width, Graphics.height)                @actor = actor                refresh                activate        end        def actor=(actor)                return if @actor == actor                @actor = actor                refresh        end        def refresh                contents.clear                draw_abilities(10,10)        end        def draw_abilities(x,y)                msgbox_p("hi")                abs = @actor.abilities.values                abs.each_with_index do |ability, i|                        draw_ability_name(ability, x, y + line_height * i)                end        end        def draw_ability_name(ability, x, y, enabled = true, width = 172)                return unless ability                msgbox_p("Hello")                if ability.iconId                        draw_icon(ability.iconId, x, y, enabled)                end                change_color(normal_color, enabled)                draw_text(x + 34, y, width, line_height, ability.name)                if ability.is_a?(LevelledAbility)                        draw_text(x + 200, y, width, line_height, ability.level)                end        endend




    There is also a demo/test project that demonstrates some of the methods.

    Terms of Use

    Both Paramecium Core and Abilities System are free for use in commercial and non-commercial games, so long as credit is provided.



    本贴来自国际rpgmaker官方论坛作者:Paramecium13处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/abilities-system.41726/

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-8-17 21:14 , Processed in 0.095486 second(s), 55 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表