Module: CombatSim

Defined in:
lib/lotrd/c-combatController.rb

Class Method Summary collapse

Class Method Details

.escapeCheckObject



98
99
100
101
102
103
104
105
# File 'lib/lotrd/c-combatController.rb', line 98

def escapeCheck
    @turn = 'player'
    if @currentPlayerAgi + rand(1..30) > @currentMobAgi
        ::CombatView.escapeSuccess
    else
        ::CombatView.escapeFail
    end
end

.initiativeObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/lotrd/c-combatController.rb', line 33

def initiative
    #Decide first-turn initiative
        if @currentPlayerAgi > @currentMobAgi;
            @turn = 'player'
            ::CombatView.playerStart(@currentPlayerHP, @currentMobHP)
        else
            @turn = 'mob'
            ::CombatView.mobStart(@currentPlayerHP, @currentMobHP)
        end
end

.lossObject



129
130
131
132
133
134
135
136
# File 'lib/lotrd/c-combatController.rb', line 129

def loss
    player = YAML.load(File.read("m-playerdata.yml"))
    player.gold = 0
    player.armour = nil
    player.weapon = nil
    File.open('m-playerdata.yml', 'w') {|file| File.write('m-playerdata.yml', player.to_yaml)}
    ::CombatView.defeat
end

.mobCrit(dmg) ⇒ Object



62
63
64
# File 'lib/lotrd/c-combatController.rb', line 62

def mobCrit(dmg)
    @currentMobLck - @currentPlayerLck > 9 ? ::CombatSim.mobResolve((dmg * 1.2).to_i) : ::CombatSim.mobResolve(dmg)
end

.mobDmgObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/lotrd/c-combatController.rb', line 49

def mobDmg
    @mobAction = rand(1..3)
    case @mobAction
    when 1
        (@currentMobStr - @currentPlayerStr) > 0 ? dmg = (@currentMobStr - @currentPlayerStr) : dmg = 0
    when 2
        (@currentMobInt - @currentPlayerInt) > 0 ? dmg = (@currentMobInt - @currentPlayerInt): dmg = 0
    when 3
        (@currentMobDex - @currentPlayerStr) > 0 ? dmg = (@currentMobDex - @currentPlayerStr) : dmg = 0
    end
    ::CombatSim.mobCrit(dmg)
end

.mobHitObject



44
45
46
47
# File 'lib/lotrd/c-combatController.rb', line 44

def mobHit
    @turn = 'mob'
    @currentMobDex - @currentPlayerAgi + rand(1..5) > 0 ? ::CombatSim.mobDmg : ::CombatView.mobMiss
end

.mobResolve(dmg) ⇒ Object



66
67
68
69
# File 'lib/lotrd/c-combatController.rb', line 66

def mobResolve(dmg)
    @currentPlayerHP -= dmg
    ::CombatView.mobTurnResolve(@mobAction, dmg, @currentPlayerHP)
end

.playerCrit(dmg) ⇒ Object



89
90
91
# File 'lib/lotrd/c-combatController.rb', line 89

def playerCrit(dmg)
    @currentPlayerLck - @currentMobLck > 9 ? ::CombatSim.playerResolve((dmg * 1.2).to_i) : ::CombatSim.playerResolve(dmg)
end

.playerDmg(action) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/lotrd/c-combatController.rb', line 76

def playerDmg(action)
    @playerAction = action
    case @playerAction
    when 1
        (@currentPlayerStr - @currentMobStr) > 0 ? dmg = (@currentPlayerStr - @currentMobStr) : dmg = 0
    when 2
        (@currentPlayerInt - @currentMobInt) > 0 ? dmg = (@currentPlayerInt - @currentMobInt): dmg = 0
    when 3
        (@currentPlayerDex - @currentMobStr) > 0 ? dmg = (@currentPlayerDex - @currentMobStr) : dmg = 0
    end
    ::CombatSim.playerCrit(dmg)
end

.playerHit(action) ⇒ Object



71
72
73
74
# File 'lib/lotrd/c-combatController.rb', line 71

def playerHit(action)
    @turn = 'player'
    @currentPlayerDex - @currentMobAgi + rand(1..5) > 0 ? ::CombatSim.playerDmg(action) : ::CombatView.playerMiss
end

.playerResolve(dmg) ⇒ Object



93
94
95
96
# File 'lib/lotrd/c-combatController.rb', line 93

def playerResolve(dmg)
    @currentMobHP -= dmg
    ::CombatView.playerTurnResolve(@playerAction, dmg, @currentMobHP)
end

.rewardObject



121
122
123
124
125
126
127
# File 'lib/lotrd/c-combatController.rb', line 121

def reward
    player = YAML.load(File.read("m-playerdata.yml"))
    drop = rand(20..200)
    player.gold += drop
    File.open('m-playerdata.yml', 'w') {|file| File.write('m-playerdata.yml', player.to_yaml)}
    ::CombatView.victory(drop)
end

.roundResolveObject



111
112
113
114
115
116
117
118
119
# File 'lib/lotrd/c-combatController.rb', line 111

def roundResolve
    if @currentMobHP < 1
        reward
    elsif @currentPlayerHP < 1
        loss
    else
        turnHandler
    end
end

.startObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/lotrd/c-combatController.rb', line 9

def start
    mob1 = ::Mob.new
    mob1.raceGen
    mob1.jobGen
    mob1.nameGen
    #Load player stats
        player = YAML.load(File.read("m-playerdata.yml"))
        @currentPlayerHP = player.hp
        @currentPlayerStr = player.str
        @currentPlayerAgi = player.agi
        @currentPlayerInt = player.int
        @currentPlayerDex = player.dex
        @currentPlayerLck = player.lck
    #Load mob stats
        @mobName = mob1.name
        @currentMobHP = mob1.hp
        @currentMobStr = mob1.str
        @currentMobAgi = mob1.agi
        @currentMobInt = mob1.int
        @currentMobDex = mob1.dex
        @currentMobLck = mob1.lck
    ::CombatView.start(mob1)
end

.turnHandlerObject



107
108
109
# File 'lib/lotrd/c-combatController.rb', line 107

def turnHandler
        @turn == 'player' ? ::CombatView.mobTurn : ::CombatView.playerTurn
end