Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(91 edits)

I think, that it will be better if 

$data_NameBarters

Will be created officially in the game. May as {}. But with unique name.

And then create adding mod-goods from it to barters in oficcial scripts.

Then modder will need only to modify this hash.

Because while all modders need to create new hash, then they create new alias_method for "def manual_trade". And if there will be a lot of mods, there will be a "multi-story pagoda".

If $data_NameBarters (or another name) will be one for all of mods, and adding mod-goods to trade will be one in offficial code of game, it will be better for optimization.

And, may be, sometimes it will be easier for Eccma in some cases to use $data_NameBarters and json files, for adding goods,  instead of adding  manually.

——

And i see that it's possible to add shopNerf to this method.

But it's will really increase code complexity.

——

BigMama.json  (Update comm. It's more useful to make one file for one npc)

{
    "npc_name": "59_69",
    "items":  [
        {
            "item_name": "ItemSurBot", 
            "custom_price": null, 
            "price_add": 0,
            "price_mult": 1, 
            "rndMin": 1,
            "rndMax": 5,
            "shop_nerf": [
                {
                    "base": 0, 
                    "base_mult": 1,
                    "attr_name": "weak", 
                    "attr_mult": 1, 
                    "attr_type": 0
                },
                { 
                    "base": -100,
                    "base_mult": 0,
                    "attr_name": "sexy",
                    "attr_mult": -1,
                    "attr_type": 0
                }
            ]
        },
        {
            "item_name": "ItemAdvBot",
            "custom_price": null,
            "price_add": 0,
            "price_mult": 1,
            "rndMin": 1,
            "rndMax": 5,
            "shop_nerf": [
                {
                    "base": 0,
                    "base_mult": 1,
                    "attr_name": "weak",
                    "attr_mult": 0.5,
                    "attr_type": 0
                }
            ]
        }
    ]
}


WorldDifficulty - increase price

weak - increase price

sexy - decrease price

simply use 

"shop_nerf": [
                {
                    "base": 0, 
                    "base_mult": 0,
                    "attr_name": 0,
                    "attr_mult": 0, 
                    "attr_type": 0
                }
            ]

to set it's effect to zero.

Code for modders:

module DataManager
    class << self
        alias_method :load_mod_database_TEST, :load_mod_database
    end
    
    def self.load_mod_database
        load_mod_database_TEST
        $TEST_mod_name = "Mod TEST"
        $TEST_modFolder = "ModScripts/_Mods/#{$TEST_mod_name}"
        $data_NameBarters_TEST = {} if $data_NameBarters_TEST == nil
        FileGetter.getFileList("#{$TEST_modFolder}/Data/Barters/*.json").each{|file|
            add_new_goods(file)
        }
    end
    
    def self.add_new_goods(path)
        temp_hash = nil
        
        begin
            temp_hash = JSON.decode(open(path).read)
        rescue 
            msgbox("Error in Json == [[ #{path} ]] :: def self.add_new_goods")
        end
        return if temp_hash == nil
            
        goods = []
        temp_hash["items"].each{|item|
            item_name = item["item_name"]
            custom_price = item["custom_price"]
            price = (item["price_mult"])*($data_ItemName[item_name].price.to_i) + item["price_add"]
            minNum = item["rndMin"]
            maxNum = item["rndMax"]
            nerf = item["shop_nerf"]
            goods += [[*$data_ItemName[item_name].get_type_and_id, custom_price, price.round, Random.new.rand(minNum..maxNum), nerf ]]
        }
        if $data_NameBarters_TEST[temp_hash["npc_name"]] == nil
            $data_NameBarters_TEST[temp_hash["npc_name"]] = goods
        else
            $data_NameBarters_TEST[temp_hash["npc_name"]] += goods
        end
    end
end
#######   This part of code can be official. #######
#######  Without using alias_method, of course.  ###
####################################################
    
module GIM_ADDON
    
    alias_method :alias_manual_trade_TEST, :manual_trade unless method_defined?(:alias_manual_trade_TEST)
        
    def manual_trade(good,charStoreHashName=nil, charStoreTP=0, charStoreExpireDate=nil, noSell=false, noBuy=false)
        goods = add_mod_goods(charStoreHashName)
        good += goods if goods != nil
        alias_manual_trade_TEST(good, charStoreHashName, charStoreTP, charStoreExpireDate, noSell, noBuy)
    end
        
    def add_mod_goods(charStoreHashName=nil)
        goods_base = $data_NameBarters_TEST["#{charStoreHashName}"]   
        return if goods_base == nil
        goods = []
        goods_base.each{|good_one|
            begin
                shop_nerf = 0
                good_one[5].each{|nerf|
                    attr_mult = nerf["attr_mult"]
                    attr_name = nerf["attr_name"]
                    if attr_name.class == String
                        attr_type = nerf["attr_type"]
                        nerf_attr = $game_player.actor.battle_stat.get_stat(attr_name, attr_type)
                    else
                        nerf_attr = attr_name.to_i
                        #You can use number instead of name and then it will be simple value. And then you can use your mathematical skills to do whatever you want. It can be useful to make base "shop_nerf" - negative (to turn price to zero). For example. Start price from zero: price*(1(base formula) - 1(this iteration) + weak*0.001(next iteration)).
                    end
                    nerf_attr_mod = attr_mult*nerf_attr
                    nerf_base = nerf["base"]
                    nerf_base_mult = nerf["base_mult"]
                    shop_nerf1 = ([([$story_stats["WorldDifficulty"].round, 100].min)*nerf_base_mult + nerf_base, 0].max*0.001)
                    shop_nerf2 = nerf_attr_mod*0.001  #A lot of sexy can alow Lona to get item and earn money by getting item (only for example).
                    shop_nerf += shop_nerf1 + shop_nerf2
                }
                price = (good_one[3]*(1+shop_nerf)).round
            rescue
                price = good_one[3]
            end
            goods +=[[good_one[0], good_one[1], good_one[2], price, good_one[4]]]
        }
        return goods if goods != []
    end
end