Sha256: 82d0bafa1ba3e8df6cf76241e541e289ed14f6874c1586dee16158f19e7efad1

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

require 'yaml'

require_relative 'v-bank'

module BankController


    def withdraw(wdw)
        player = YAML.load(File.read("m-playerdata.yml"))
        gold = player.gold
        balance = player.balance
        if wdw > balance
            ::Bank.deficit
        elsif wdw < 1
            ::Bank.invalid
        else
            balance -= wdw
            gold += wdw
        end
        player.gold = gold
        player.balance = balance
        File.open('m-playerdata.yml', 'w') {|file| File.write('m-playerdata.yml', player.to_yaml)}
        ::Bank.withdrawConfirm(wdw, player.gold, player.balance)
    end

    def deposit(dep)
        player = YAML.load(File.read("m-playerdata.yml"))
        gold = player.gold
        balance = player.balance
        if dep > gold
            ::Bank.deficit
        elsif dep < 1
            ::Bank.invalid
        else
            balance += dep
            gold -= dep
        end
        player.gold = gold
        player.balance = balance
        File.open('m-playerdata.yml', 'w') {|file| File.write('m-playerdata.yml', player.to_yaml)}
        ::Bank.depositConfirm(dep, player.gold, player.balance)
    end
    module_function :withdraw, 
                    :deposit
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lotrd-0.1.6 lib/lotrd/c-bankController.rb
lotrd-0.1.5 lib/lotrd/c-bankController.rb