soulik

Untitled

Jul 1st, 2014
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.28 KB | None | 0 0
  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 health = 1000
  72.     local health_max = health
  73.     local mana = 100
  74.     local mana_max = mana
  75.     local armor = 10
  76.     local shield = 6
  77.     local shield_blocking = true
  78.     local shield_block_chance = 0.25
  79.     local shield_mana = 20 -- fueled by mana
  80.     local shield_mana_ratio = 2.0 -- 0.5 = 1 mana ochrani pred 2 dmg
  81.     local evasion = 0.01
  82.     local miss = 0.03
  83.  
  84.     local pain_chance = 0.5 -- pohyb nemeni, len sa prida duration do sekvencie co prebieha, aka mini-stun
  85.     local pain_threshold = 12 -- dmg pod tuto hranicu bude sanca na pain deleno 4, (napr. berserk +50, alebo berserk znizi sancu?)
  86.  
  87.     local attribute = {
  88.         str = 5,
  89.         vit = 10,
  90.         agi = 5,
  91.         dex = 5,
  92.         int = 5,
  93.         pow = 5,
  94.     }
  95.     local resist = {
  96.         normal = 0,
  97.         spell = 0,
  98.         fire = 0,
  99.         explosive = 0,
  100.         energy = 0,
  101.  
  102.         acid = 0,
  103.         mental = 0,
  104.         disease = 0,
  105.         rad = 0,
  106.         gas = 0,
  107.     }
  108.  
  109.     local name = name or 'Default player name'
  110.     local race = 'human' -- human, alien, undead, cyborg, robot, natural, unnatural
  111.  
  112.     return {
  113.         resist = resist,
  114.         attribute_vit = function()  -- priklad funkcie ktora bude menit staty podla vitality
  115.             local x = attribute['vit']
  116.  
  117.             health_max = 1000 + x*5
  118.             health = health_max
  119.             pain_threshold = math.round(5 + x*0.85)
  120.             resist['disease'] = 0 + x*0.5
  121.         end,
  122.  
  123.  
  124.  
  125.         test = function(damage_input,ranged,weapon_type)
  126.             --local weapon_type = 'energy' -- normal, heavy, energy, exotic
  127.             local damage_output = damage_input*0.01
  128.  
  129.             if ranged then
  130.                 --if weapon_type = 'normal' then
  131.                 --  return damage_output*attribute['dex']
  132.                 --end
  133.                 --if weapon_type = 'heavy' then
  134.                 --  return damage_output*attribute['dex']*0.5
  135.                 --end
  136.                 --if weapon_type = 'energy' then
  137.                 --  return damage_output*attribute['pow']
  138.                 --end
  139.                 --if weapon_type = 'exotic' then
  140.                 --  return damage_output*attribute['int']*2
  141.                 --end
  142.             else
  143.                 return damage_output*attribute['str']*2
  144.             end
  145.  
  146.             return 0
  147.         end,
  148.  
  149.  
  150.  
  151.         fire = function(damage_input,damage_type,ranged)
  152.             local damage_type = damage_type or 'normal'
  153.             local ranged = ranged or false
  154.             local shield_mana_calc = math.randomReal(shield_mana*0.66,shield_mana)
  155.                   shield_mana_calc = math.min(shield_mana_calc,mana/shield_mana_ratio)
  156.             local mana_decrease = shield_mana_calc*shield_mana_ratio --math.min(shield_mana_calc,damage_input)*shield_mana_ratio
  157.            
  158.             --print(mana_decrease)
  159.             --if mana*shield_mana_ratio < shield_mana_calc then
  160.                 --if mana<=0 then
  161.                 --  shield_mana_calc = 0
  162.                 --end
  163.             if mana-mana_decrease<0 then
  164.                 --shield_mana_calc = shield_mana_calc - (mana_decrease-mana)*shield_mana_ratio
  165.                     --shield_mana_calc = shield_mana_calc - mana*shield_mana_ratio
  166.                 mana = 0
  167.             else
  168.                 mana = mana - mana_decrease
  169.             end
  170.             if shield_mana_calc<0 then
  171.                 shield_mana_calc = 0
  172.             end
  173.  
  174.             local shield_calc = 0
  175.             local pain_threshold_bonus = 0
  176.             if shield_blocking then
  177.                 if math.chance(shield_block_chance) then
  178.                     shield_calc = 1000 -- 'chance to block'
  179.                 else
  180.                     shield_calc = math.randomReal(shield*0.5, shield) -- if blocking
  181.                 end
  182.             else
  183.                 shield_calc = math.randomReal(shield*0.15, shield) -- if not blocking with shield activelly
  184.             end
  185.  
  186.             local armor_calc = math.randomReal(armor*0.5, armor)
  187.             local damage_output = math.max(damage_input - shield_mana_calc - shield_calc - armor_calc,1)
  188.             local pain_bool = math.chance(pain_chance)
  189.  
  190.  
  191.  
  192.             damage_output = damage_output - (damage_output*resist[damage_type])
  193.             --if math.random() <= 0.33 then damage_output = damage_output * 1.525 end -- critical
  194.             damage_output = math.max(math.floor(damage_output),1)
  195.             --if damage < 1 then damage = 1 end
  196.             health = health - damage_output
  197.  
  198.             if pain_bool then
  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'
  200.                 if damage_output < (pain_threshold + pain_threshold_bonus) then
  201.                     pain_bool = math.chance(pain_chance/4)
  202.                     print(("---> Pain treshold %0.2f"):format(pain_threshold_bonus))
  203.                 end
  204.             end
  205.  
  206.             --print(name, 'Health:',health,'damage_input:',damage_input,'armor_calc:',armor_calc,'damage_output:',damage_output)
  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))
  208.         end,
  209.     }
  210. end
  211.  
  212. function hitChance()
  213.     local chance = 1.0 -- 80% ze trafi
  214.     local result = math.random()
  215.     if result <= chance then
  216.         return true
  217.     else
  218.         return false
  219.     end
  220. end
  221.  
  222.  
  223.  
  224.  
  225. math.randomseed(os.time())
  226.  
  227.  
  228.  
  229.     dmg_base = 10
  230.     dmg_dice = 9
  231.     dmg_side = 6
  232.  
  233. local player1 = playerEx('John')
  234. local player2 = playerEx('Hrac 2')
  235. --player1.fire()
  236. --player2.fire()
  237. player1.attribute_vit()
  238.  
  239. for i=1,20 do
  240.     local result = math.chance(1.0) --hitChance()
  241.     local dice = math.dice(dmg_dice,dmg_side)
  242.     local dmg_bonus = player1.test(dmg_base+dice,false,'exotic')
  243.  
  244.     print(("#%d\tHit: %s\t\t\t\tDMG_input: %d+%d+%d"):format(i,result,dmg_base,dice,dmg_bonus))
  245.  
  246. --  if result then player1.fire(math.random(50,60)) end
  247.     if result then player1.fire(dmg_base+dice+dmg_bonus) end
  248. end
  249.  
  250. --player:fire()
  251. --player.fire(player)
  252. graph()
Advertisement
Add Comment
Please, Sign In to add comment