Module: CombatSim

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

Class Method Summary collapse

Class Method Details

.escapeCheckObject



102
103
104
105
106
107
108
109
# File 'lib/lotrd/controller/combatController.rb', line 102

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

.initiativeObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/lotrd/controller/combatController.rb', line 37

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



133
134
135
136
137
138
139
140
# File 'lib/lotrd/controller/combatController.rb', line 133

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

.mobCrit(dmg) ⇒ Object



66
67
68
# File 'lib/lotrd/controller/combatController.rb', line 66

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

.mobDmgObject



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/lotrd/controller/combatController.rb', line 53

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

.mobHitObject



48
49
50
51
# File 'lib/lotrd/controller/combatController.rb', line 48

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

.mobResolve(dmg) ⇒ Object



70
71
72
73
# File 'lib/lotrd/controller/combatController.rb', line 70

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

.playerCrit(dmg) ⇒ Object



93
94
95
# File 'lib/lotrd/controller/combatController.rb', line 93

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

.playerDmg(action) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/lotrd/controller/combatController.rb', line 80

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

.playerHit(action) ⇒ Object



75
76
77
78
# File 'lib/lotrd/controller/combatController.rb', line 75

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

.playerResolve(dmg) ⇒ Object



97
98
99
100
# File 'lib/lotrd/controller/combatController.rb', line 97

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

.rewardObject



125
126
127
128
129
130
131
# File 'lib/lotrd/controller/combatController.rb', line 125

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

.roundResolveObject



115
116
117
118
119
120
121
122
123
# File 'lib/lotrd/controller/combatController.rb', line 115

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
32
33
34
35
# File 'lib/lotrd/controller/combatController.rb', line 9

def start
    mob1 = ::Mob.new
    mob1.raceGen
    mob1.jobGen
    mob1.nameGen
    #Load player stats
        player = YAML.load(File.read(ENV['HOME'] + "/." + "playerdata.yml"))
        @currentPlayerHP = player.hp
        @currentPlayerDef = player.def
        @currentPlayerRes = player.res
        @currentPlayerStr = player.str
        @currentPlayerAgi = player.agi
        @currentPlayerInt = player.int
        @currentPlayerDex = player.dex
        @currentPlayerLck = player.lck
    #Load mob stats
        @mobName = mob1.name
        @currentMobHP = mob1.hp
        @currentMobDef = mob1.def
        @currentMobRes = mob1.res
        @currentMobStr = mob1.str
        @currentMobAgi = mob1.agi
        @currentMobInt = mob1.int
        @currentMobDex = mob1.dex
        @currentMobLck = mob1.lck
    ::CombatView.start(mob1)
end

.turnHandlerObject



111
112
113
# File 'lib/lotrd/controller/combatController.rb', line 111

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