Module: BankController

Defined in:
lib/lotrd/controller/bankController.rb

Class Method Summary collapse

Class Method Details

.deposit(dep) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/lotrd/controller/bankController.rb', line 26

def deposit(dep)
    player = YAML.load(File.read(ENV['HOME'] + "/." + "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(ENV['HOME'] + "/." + "playerdata.yml", 'w') {|file| File.write(ENV['HOME'] + "/." + "playerdata.yml", player.to_yaml)}
    ::Bank.depositConfirm(dep, player.gold, player.balance)
end

.withdraw(wdw) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/lotrd/controller/bankController.rb', line 8

def withdraw(wdw)
    player = YAML.load(File.read(ENV['HOME'] + "/." + "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(ENV['HOME'] + "/." + "playerdata.yml", 'w') {|file| File.write(ENV['HOME'] + "/." + "playerdata.yml", player.to_yaml)}
    ::Bank.withdrawConfirm(wdw, player.gold, player.balance)
end