SHOW:
|
|
- or go back to the newest paste.
| 1 | player = {
| |
| 2 | name = 'Global player', | |
| 3 | health = 1000, | |
| 4 | mana = 1000, | |
| 5 | ||
| 6 | fire = function(self) | |
| 7 | self.health = self.health - 10 | |
| 8 | print(self.name, 'Health', self.health) | |
| 9 | end, | |
| 10 | } | |
| 11 | ||
| 12 | function math.randomReal(min, max) | |
| 13 | return math.random()*(max-min)+min | |
| 14 | end | |
| 15 | ||
| 16 | function math.round(value) | |
| 17 | return math.floor(value+0.5) | |
| 18 | end | |
| 19 | ||
| 20 | function math.dice(dice,side) | |
| 21 | local x = 0 | |
| 22 | ||
| 23 | for i=1,dice do | |
| 24 | x = x + math.random(1,side) | |
| 25 | end | |
| 26 | ||
| 27 | return x | |
| 28 | end | |
| 29 | ||
| 30 | function math.chance(chance) | |
| 31 | local x = math.random() | |
| 32 | if x <= chance then | |
| 33 | return true | |
| 34 | else | |
| 35 | return false | |
| 36 | end | |
| 37 | end | |
| 38 | ||
| 39 | function graph() | |
| 40 | local a = {}
| |
| 41 | local x = 333 | |
| 42 | local calc | |
| 43 | local s='' | |
| 44 | ||
| 45 | for i=1, 1000 do | |
| 46 | a[i] = 0 | |
| 47 | end | |
| 48 | ||
| 49 | for i=1, x do | |
| 50 | --y = math.random(1,50) | |
| 51 | --calc = math.round(math.dice(3,y)/3) | |
| 52 | calc = math.dice(5,5) | |
| 53 | a[calc] = a[calc] + 1 | |
| 54 | end | |
| 55 | ||
| 56 | for i=1, x do | |
| 57 | if a[i]>0 then | |
| 58 | --for y=1, a[i] do | |
| 59 | s=string.rep('#',a[i])
| |
| 60 | --end | |
| 61 | print(("%d\t: %s"):format(i,s))
| |
| 62 | s='' | |
| 63 | end | |
| 64 | end | |
| 65 | return | |
| 66 | end | |
| 67 | ||
| 68 | ||
| 69 | ||
| 70 | playerEx = function(name) | |
| 71 | local obj = {}
| |
| 72 | local health = 1000 | |
| 73 | local health_max = health | |
| 74 | local mana = 100 | |
| 75 | local mana_max = mana | |
| 76 | local armor = 10 | |
| 77 | local shield = 6 | |
| 78 | local shield_blocking = true | |
| 79 | local shield_block_chance = 0.25 | |
| 80 | local shield_mana = 20 -- fueled by mana | |
| 81 | local shield_mana_ratio = 2.0 -- 0.5 = 1 mana ochrani pred 2 dmg | |
| 82 | local evasion = 0.01 | |
| 83 | local miss = 0.03 | |
| 84 | ||
| 85 | local pain_chance = 0.5 -- pohyb nemeni, len sa prida duration do sekvencie co prebieha, aka mini-stun | |
| 86 | local pain_threshold = 12 -- dmg pod tuto hranicu bude sanca na pain deleno 4, (napr. berserk +50, alebo berserk znizi sancu?) | |
| 87 | ||
| 88 | local attribute = {
| |
| 89 | str = 5, | |
| 90 | vit = 10, | |
| 91 | agi = 5, | |
| 92 | dex = 5, | |
| 93 | int = 5, | |
| 94 | pow = 5, | |
| 95 | } | |
| 96 | local resist = {
| |
| 97 | normal = 0, | |
| 98 | spell = 0, | |
| 99 | fire = 0, | |
| 100 | explosive = 0, | |
| 101 | energy = 0, | |
| 102 | ||
| 103 | acid = 0, | |
| 104 | mental = 0, | |
| 105 | disease = 0, | |
| 106 | rad = 0, | |
| 107 | gas = 0, | |
| 108 | } | |
| 109 | ||
| 110 | local name = name or 'Default player name' | |
| 111 | local race = 'human' -- human, alien, undead, cyborg, robot, natural, unnatural | |
| 112 | - | return {
|
| 112 | + | |
| 113 | - | resist = resist, |
| 113 | + | obj.resist = resist |
| 114 | - | attribute_vit = function() -- priklad funkcie ktora bude menit staty podla vitality |
| 114 | + | obj.attribute_vit = function() -- priklad funkcie ktora bude menit staty podla vitality |
| 115 | - | local x = attribute['vit'] |
| 115 | + | local x = attribute['vit'] |
| 116 | ||
| 117 | - | health_max = 1000 + x*5 |
| 117 | + | health_max = 1000 + x*5 |
| 118 | - | health = health_max |
| 118 | + | health = health_max |
| 119 | - | pain_threshold = math.round(5 + x*0.85) |
| 119 | + | pain_threshold = math.round(5 + x*0.85) |
| 120 | - | resist['disease'] = 0 + x*0.5 |
| 120 | + | resist['disease'] = 0 + x*0.5 |
| 121 | - | end, |
| 121 | + | |
| 122 | ||
| 123 | obj.test = function(damage_input,ranged,weapon_type) | |
| 124 | --local weapon_type = 'energy' -- normal, heavy, energy, exotic | |
| 125 | - | test = function(damage_input,ranged,weapon_type) |
| 125 | + | local damage_output = damage_input*0.01 |
| 126 | - | --local weapon_type = 'energy' -- normal, heavy, energy, exotic |
| 126 | + | |
| 127 | - | local damage_output = damage_input*0.01 |
| 127 | + | if ranged then |
| 128 | --if weapon_type = 'normal' then | |
| 129 | - | if ranged then |
| 129 | + | -- return damage_output*attribute['dex'] |
| 130 | - | --if weapon_type = 'normal' then |
| 130 | + | --end |
| 131 | - | -- return damage_output*attribute['dex'] |
| 131 | + | --if weapon_type = 'heavy' then |
| 132 | - | --end |
| 132 | + | -- return damage_output*attribute['dex']*0.5 |
| 133 | - | --if weapon_type = 'heavy' then |
| 133 | + | --end |
| 134 | - | -- return damage_output*attribute['dex']*0.5 |
| 134 | + | --if weapon_type = 'energy' then |
| 135 | - | --end |
| 135 | + | -- return damage_output*attribute['pow'] |
| 136 | - | --if weapon_type = 'energy' then |
| 136 | + | --end |
| 137 | - | -- return damage_output*attribute['pow'] |
| 137 | + | --if weapon_type = 'exotic' then |
| 138 | - | --end |
| 138 | + | -- return damage_output*attribute['int']*2 |
| 139 | - | --if weapon_type = 'exotic' then |
| 139 | + | --end |
| 140 | - | -- return damage_output*attribute['int']*2 |
| 140 | + | else |
| 141 | - | --end |
| 141 | + | return damage_output*attribute['str']*2 |
| 142 | end | |
| 143 | - | return damage_output*attribute['str']*2 |
| 143 | + | return 0 |
| 144 | end | |
| 145 | ||
| 146 | - | return 0 |
| 146 | + | obj.fire = function(damage_input,damage_type,ranged) |
| 147 | - | end, |
| 147 | + | local damage_type = damage_type or 'normal' |
| 148 | local ranged = ranged or false | |
| 149 | local shield_mana_calc = math.randomReal(shield_mana*0.66,shield_mana) | |
| 150 | shield_mana_calc = math.min(shield_mana_calc,mana/shield_mana_ratio) | |
| 151 | - | fire = function(damage_input,damage_type,ranged) |
| 151 | + | local mana_decrease = shield_mana_calc*shield_mana_ratio --math.min(shield_mana_calc,damage_input)*shield_mana_ratio |
| 152 | - | local damage_type = damage_type or 'normal' |
| 152 | + | |
| 153 | - | local ranged = ranged or false |
| 153 | + | --print(mana_decrease) |
| 154 | - | local shield_mana_calc = math.randomReal(shield_mana*0.66,shield_mana) |
| 154 | + | --if mana*shield_mana_ratio < shield_mana_calc then |
| 155 | - | shield_mana_calc = math.min(shield_mana_calc,mana/shield_mana_ratio) |
| 155 | + | --if mana<=0 then |
| 156 | - | local mana_decrease = shield_mana_calc*shield_mana_ratio --math.min(shield_mana_calc,damage_input)*shield_mana_ratio |
| 156 | + | -- shield_mana_calc = 0 |
| 157 | --end | |
| 158 | - | --print(mana_decrease) |
| 158 | + | if mana-mana_decrease<0 then |
| 159 | - | --if mana*shield_mana_ratio < shield_mana_calc then |
| 159 | + | --shield_mana_calc = shield_mana_calc - (mana_decrease-mana)*shield_mana_ratio |
| 160 | - | --if mana<=0 then |
| 160 | + | --shield_mana_calc = shield_mana_calc - mana*shield_mana_ratio |
| 161 | - | -- shield_mana_calc = 0 |
| 161 | + | mana = 0 |
| 162 | - | --end |
| 162 | + | else |
| 163 | - | if mana-mana_decrease<0 then |
| 163 | + | mana = mana - mana_decrease |
| 164 | - | --shield_mana_calc = shield_mana_calc - (mana_decrease-mana)*shield_mana_ratio |
| 164 | + | end |
| 165 | - | --shield_mana_calc = shield_mana_calc - mana*shield_mana_ratio |
| 165 | + | if shield_mana_calc<0 then |
| 166 | - | mana = 0 |
| 166 | + | shield_mana_calc = 0 |
| 167 | - | else |
| 167 | + | end |
| 168 | - | mana = mana - mana_decrease |
| 168 | + | |
| 169 | local shield_calc = 0 | |
| 170 | - | if shield_mana_calc<0 then |
| 170 | + | local pain_threshold_bonus = 0 |
| 171 | - | shield_mana_calc = 0 |
| 171 | + | if shield_blocking then |
| 172 | if math.chance(shield_block_chance) then | |
| 173 | shield_calc = 1000 -- 'chance to block' | |
| 174 | - | local shield_calc = 0 |
| 174 | + | |
| 175 | - | local pain_threshold_bonus = 0 |
| 175 | + | shield_calc = math.randomReal(shield*0.5, shield) -- if blocking |
| 176 | - | if shield_blocking then |
| 176 | + | |
| 177 | - | if math.chance(shield_block_chance) then |
| 177 | + | else |
| 178 | - | shield_calc = 1000 -- 'chance to block' |
| 178 | + | shield_calc = math.randomReal(shield*0.15, shield) -- if not blocking with shield activelly |
| 179 | - | else |
| 179 | + | end |
| 180 | - | shield_calc = math.randomReal(shield*0.5, shield) -- if blocking |
| 180 | + | |
| 181 | - | end |
| 181 | + | local armor_calc = math.randomReal(armor*0.5, armor) |
| 182 | - | else |
| 182 | + | local damage_output = math.max(damage_input - shield_mana_calc - shield_calc - armor_calc,1) |
| 183 | - | shield_calc = math.randomReal(shield*0.15, shield) -- if not blocking with shield activelly |
| 183 | + | local pain_bool = math.chance(pain_chance) |
| 184 | ||
| 185 | damage_output = damage_output - (damage_output*resist[damage_type]) | |
| 186 | - | local armor_calc = math.randomReal(armor*0.5, armor) |
| 186 | + | --if math.random() <= 0.33 then damage_output = damage_output * 1.525 end -- critical |
| 187 | - | local damage_output = math.max(damage_input - shield_mana_calc - shield_calc - armor_calc,1) |
| 187 | + | damage_output = math.max(math.floor(damage_output),1) |
| 188 | - | local pain_bool = math.chance(pain_chance) |
| 188 | + | --if damage < 1 then damage = 1 end |
| 189 | health = health - damage_output | |
| 190 | ||
| 191 | if pain_bool then | |
| 192 | - | damage_output = damage_output - (damage_output*resist[damage_type]) |
| 192 | + | if shield_blocking then pain_threshold_bonus = shield_calc + math.dice(3,shield)/3 end -- krasne to berie do uvahy aj 'chance to block' |
| 193 | - | --if math.random() <= 0.33 then damage_output = damage_output * 1.525 end -- critical |
| 193 | + | if damage_output < (pain_threshold + pain_threshold_bonus) then |
| 194 | - | damage_output = math.max(math.floor(damage_output),1) |
| 194 | + | pain_bool = math.chance(pain_chance/4) |
| 195 | - | --if damage < 1 then damage = 1 end |
| 195 | + | print(("---> Pain treshold %0.2f"):format(pain_threshold_bonus))
|
| 196 | - | health = health - damage_output |
| 196 | + | |
| 197 | end | |
| 198 | - | if pain_bool then |
| 198 | + | |
| 199 | - | if shield_blocking then pain_threshold_bonus = shield_calc + math.dice(3,shield)/3 end -- krasne to berie do uvahy aj 'chance to block' |
| 199 | + | --print(name, 'Health:',health,'damage_input:',damage_input,'armor_calc:',armor_calc,'damage_output:',damage_output) |
| 200 | - | if damage_output < (pain_threshold + pain_threshold_bonus) then |
| 200 | + | print(("Name: %s\tHealth: %d\tMana: %d \tDMG_input: %d\tarmor_calc: %0.2f\tshield_calc: %0.2f\tshield_mana_calc: %0.2f\t\tDMG_output: %d\t\tPain: %s"):format(name, health, mana, damage_input, armor_calc, shield_calc, shield_mana_calc, damage_output, pain_bool))
|
| 201 | - | pain_bool = math.chance(pain_chance/4) |
| 201 | + | |
| 202 | - | print(("---> Pain treshold %0.2f"):format(pain_threshold_bonus))
|
| 202 | + | |
| 203 | - | end |
| 203 | + | return obj |
| 204 | end | |
| 205 | ||
| 206 | - | --print(name, 'Health:',health,'damage_input:',damage_input,'armor_calc:',armor_calc,'damage_output:',damage_output) |
| 206 | + | |
| 207 | - | print(("Name: %s\tHealth: %d\tMana: %d \tDMG_input: %d\tarmor_calc: %0.2f\tshield_calc: %0.2f\tshield_mana_calc: %0.2f\t\tDMG_output: %d\t\tPain: %s"):format(name, health, mana, damage_input, armor_calc, shield_calc, shield_mana_calc, damage_output, pain_bool))
|
| 207 | + | |
| 208 | - | end, |
| 208 | + | |
| 209 | if result <= chance then | |
| 210 | return true | |
| 211 | else | |
| 212 | return false | |
| 213 | end | |
| 214 | end | |
| 215 | ||
| 216 | ||
| 217 | ||
| 218 | ||
| 219 | math.randomseed(os.time()) | |
| 220 | ||
| 221 | ||
| 222 | ||
| 223 | dmg_base = 10 | |
| 224 | dmg_dice = 9 | |
| 225 | dmg_side = 6 | |
| 226 | ||
| 227 | local player1 = playerEx('John')
| |
| 228 | local player2 = playerEx('Hrac 2')
| |
| 229 | --player1.fire() | |
| 230 | --player2.fire() | |
| 231 | player1.attribute_vit() | |
| 232 | ||
| 233 | for i=1,20 do | |
| 234 | local result = math.chance(1.0) --hitChance() | |
| 235 | local dice = math.dice(dmg_dice,dmg_side) | |
| 236 | local dmg_bonus = player1.test(dmg_base+dice,false,'exotic') | |
| 237 | ||
| 238 | print(("#%d\tHit: %s\t\t\t\tDMG_input: %d+%d+%d"):format(i,result,dmg_base,dice,dmg_bonus))
| |
| 239 | ||
| 240 | -- if result then player1.fire(math.random(50,60)) end | |
| 241 | if result then player1.fire(dmg_base+dice+dmg_bonus) end | |
| 242 | end | |
| 243 | ||
| 244 | --player:fire() | |
| 245 | --player.fire(player) | |
| 246 | graph() |