Advertisement
Alyssa

Battles

Aug 12th, 2014
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 22.24 KB | None | 0 0
  1. version = 0.34 -- 34% to Release
  2. matk = {}
  3. mdef = {}
  4. mhp = {}
  5. mexp = {}
  6. mname = {}
  7. mskilln = {}
  8. mskilldmg = {}
  9. skill1 = {}
  10. skill2 = {}
  11. skill3 = {}
  12. skill4 = {}
  13. function initmonster()
  14.             mexp[1] = 5 -- Training Dummy
  15.             matk[1] = 0
  16.             mdef[1] = 0
  17.             mhp[1] = 5
  18.             mname[1] = "Training Dummy"
  19.             mskilln[1] = "Fall Over"
  20.             mskilldmg[1] = 3 -- Training Dummy
  21.            
  22.             mexp[2] = 10 -- Dark Soldier Scout
  23.             matk[2] = 2
  24.             mdef[2] = 1
  25.             mhp[2] = 25
  26.             mname[2] = "Dark Soldier Scout"
  27.             mskilln[2] = "Dark Beam"
  28.             mskilldmg[2] = 4 -- Dark Soldie Scout
  29.            
  30.             mexp[3] = 20
  31.             matk[3] =4
  32.             mdef[3] = 1
  33.             mhp[3] = 40
  34.             mname[3] = "Dark Scout Leader"
  35.             mskilln[3] = "Dark Beam"
  36.             mskilldmg[3] = 5
  37. end
  38. initmonster()
  39. function initchar(class)
  40.            if class == "mage" then  
  41.                        skill1[1] = "Fireball" -- name
  42.                        skill1[2] = 4 -- min damage
  43.                        skill1[3] = 7 -- max damage
  44.                        skill1[4] = 5 -- mana cost
  45.                        skill1[5] = 1 -- Skill level
  46.                    
  47.                        skill2[1] = "Weak heal" -- name
  48.                        skill2[2] = 5 -- min damage
  49.                        skill2[3] = 6 -- max damage
  50.                        skill2[4] = 6 -- mana cost
  51.                        skill2[5] = 1 -- Skill level
  52.                    
  53.                        skill3[1] = "Wall" -- name
  54.                        skill3[2] = 10 -- This is a wall, so it has a health of 10
  55.                        skill3[3] = 2 -- This is a wall, so it blocks 2 damage
  56.                        skill3[4] = 5 -- mana cost
  57.                        skill3[5] = 1 -- Skill level
  58.                    
  59.                        skill4[1] = "Block" -- name
  60.                        skill4[2] = 0 --  Block spell blocks the next few attacks, at level 1, 100% of 1, 0% of blocking 2 atacks
  61.                        skill4[3] = 1 -- max block length
  62.                        skill4[4] = 8 -- mana cost
  63.                        skill4[5] = 1 -- Skill level
  64.            elseif class == "knight" then
  65.                        skill1[1] = "Strength" --Name
  66.                        skill1[2] = 2 -- Min atk bonus
  67.                        skill1[3] = 2 -- Max atk bonus
  68.                        skill1[4] = 5 -- Mana cost
  69.                        skill1[5] = 1 -- Skill lvl
  70.                    
  71.                        skill2[1] = "Protect" --Name
  72.                        skill2[2] = 2 -- Min def bonus
  73.                        skill2[3] = 2 -- Max atk bonus
  74.                        skill2[4] = 5 -- Mana cost
  75.                        skill2[5] = 1 -- Skill lvl
  76.                    
  77.                        skill3[1] = "Block" --Name
  78.                        skill3[2] = 0 --Unused
  79.                        skill3[3] = 1 -- Maximum amount of turns for block
  80.                        skill3[4] = 8 -- Mana cost
  81.                        skill3[5] = 1 -- Skill Level
  82.                    
  83.                        skill4[1] = "Power Slash"
  84.                        skill4[2] = 4
  85.                        skill4[3] = 7
  86.                        skill4[4] = 4
  87.                        skill4[5] = 1
  88.            end
  89.            if class == "knight" then
  90.                        atk = 3
  91.                        magic = 10
  92.            elseif class == "mage" then
  93.                        atk = 2
  94.                        magic = 15
  95.            end
  96.            maxhp = 30
  97.            hp = 30
  98.            def = 1
  99.            exp = 0
  100.            lvl = 1
  101.            exptolvl = 10
  102.            lvlpoints = 0
  103.            coins = 0
  104.            
  105. end
  106. function updatehealth()
  107.            local mshp = maxhp /10
  108.            local mshp2 = mshp *4
  109.            local mshp = mshp *2
  110.            if hp <= mshp2 then
  111.                        phealth = "medium"
  112.                        if hp <= mshp then
  113.                                      phealth = "low"
  114.                        end
  115.            else
  116.                        phealth = "high"
  117.            end
  118.            local msehp = mhp[ma] /10
  119.            local msehp2 = msehp *4
  120.            local msehp = msehp *2
  121.            if enemyhp <= msehp2 then
  122.                        ehealth = "medium"
  123.                        if enemyhp <= msehp then
  124.                                    ehealth = "low"
  125.                        end
  126.            else
  127.                        ehealth = "high"
  128.            end
  129.             term.setCursorPos(1,17)
  130.             term.setBackgroundColor(colors.black)
  131.            
  132.             cWrite("                                           ",18)
  133.             cWrite("                                           ",17)
  134.             if phealth == "high" then
  135.                    
  136.                          term.setBackgroundColor(colors.green)
  137.             elseif phealth == "medium" then
  138.                           term.setBackgroundColor(colors.orange)
  139.             else
  140.                           term.setBackgroundColor(colors.red)
  141.             end
  142.             cWrite("Your Health: "..hp.."/"..maxhp)
  143.             term.setBackgroundColor(colors.black)
  144.             term.setCursorPos(1,18)
  145.             if ehealth == "high" then
  146.                         term.setBackgroundColor(colors.green)
  147.             elseif ehealth == "medium" then
  148.                         term.setBackgroundColor(colors.orange)
  149.             else
  150.                         term.setBackgroundColor(colors.red)
  151.             end
  152.             cWrite(enemyname .. "'s HP: " .. enemyhp .. "/" .. mhp[ma] .. " ")
  153.             term.setBackgroundColor(colors.black)
  154. end
  155. function drawchars()
  156.           -- I do NOT want to work on this atm
  157.          term.setCursorPos(1,6)
  158.          cWrite("Character art not finished")
  159. end
  160. function drawtitle()
  161.         cWrite("You VS. " .. enemyname,3)  
  162. end
  163. function win()
  164.        hp = maxhp
  165.        exp = exp + enemyxp
  166.        if exp >= exptolvl then
  167.                lvlup()
  168.        end
  169.        bresult = 1
  170.        coinswon = lvl * 3
  171.        coins = coins + coinswon
  172.        term.clear()
  173. end
  174. function lvlup()
  175.   lvl = lvl +1
  176.   maxhp = maxhp +5
  177.   atk = atk +1
  178.   def = def +0.5
  179.   exptolvl = exptolvl * 1.5
  180.   lvlpoints = lvlpoints +3
  181. end
  182. function lose()
  183.        if coins >= 0 then
  184.                coins = coins / 2
  185.        end
  186.        bresult = 3
  187. end
  188. function run()
  189.        bresult = 3
  190. end
  191. function choosemove1()
  192.        cm1confirmed = 0
  193.        cm1select = 0
  194.        cm1finished = 0
  195.       cm1lr = 1
  196.       cm1ud = 1
  197.          cWrite("   [Attack]    Skill      ",9)
  198.          cWrite("    Item        Escape    ",11)
  199.        while cm1confirmed == 0 do
  200.               e,key = os.pullEvent("key")
  201.               if key == 205 then
  202.                      cm1lr = 2
  203.               elseif key == 203 then
  204.                      cm1lr = 1
  205.               elseif key == 208 then
  206.                      cm1ud = 2
  207.               elseif key == 200 then
  208.                      cm1ud = 1
  209.               elseif key == 28 then
  210.                      cm1finished = 1
  211.               end
  212.               if cm1lr == 1 and cm1ud == 1 then
  213.                      cWrite("   [Attack]    Skill      ",9)
  214.                      cWrite("    Item        Escape    ",11)
  215.               elseif cm1lr == 2 and cm1ud == 1 then
  216.                      cWrite("    Attack    [Skill]     ",9)
  217.                      cWrite("    Item        Escape    ",11)
  218.               elseif cm1lr == 1 and cm1ud == 2 then
  219.                      cWrite("    Attack     Skill      ",9)
  220.                      cWrite("   [Item]       Escape    ",11)
  221.               elseif cm1lr == 2 and cm1ud == 2 then
  222.                      cWrite("    Attack     Skill      ",9)
  223.                      cWrite("    Item       [Escape]   ",11)
  224.               end
  225.               if cm1finished == 1 then
  226.                     if cm1lr == 1 and cm1ud == 1 then
  227.                            cm1confirmed = 1
  228.                            return "attack"
  229.                     elseif cm1lr == 2 and cm1ud == 1 then
  230.                            cm1confirmed = 1
  231.                             return "skills"
  232.                     elseif cm1lr == 1 and cm1ud == 2 then
  233.                            cm1confirmed = 1
  234.                            return "items"
  235.                     elseif cm1lr == 2 and cm1ud == 2 then
  236.                            cm1confirmed = 1
  237.                            return "run"
  238.                     end
  239.               end
  240.        end
  241. end
  242. function choosemove2()
  243. if mv1 == "skills" then
  244.        cm2confirmed = 0
  245.        cm2select = 0
  246.        cm2finished = 0
  247.       cm2lr = 1
  248.       cm2ud = 1
  249.          cWrite("  ["..skill1[1].."]    "..skill2[1].."   ",9)
  250.          cWrite("   "..skill3[1].."     "..skill4[1].."   ",11)
  251.  while cm2confirmed == 0 do
  252.               e,key = os.pullEvent("key")
  253.               if key == 205 then
  254.                      cm2lr = 2
  255.               elseif key == 203 then
  256.                      cm2lr = 1
  257.               elseif key == 208 then
  258.                      cm2ud = 2
  259.               elseif key == 200 then
  260.                      cm2ud = 1
  261.               elseif key == 28 then
  262.                      cm2finished = 1
  263.               end
  264.               if cm2lr == 1 and cm2ud == 1 then
  265.          cWrite("  ["..skill1[1].."]    "..skill2[1].."   ",9)
  266.          cWrite("   "..skill3[1].."     "..skill4[1].."   ",11)
  267.               elseif cm2lr == 2 and cm2ud == 1 then
  268.          cWrite("   "..skill1[1].."    ["..skill2[1].."]  ",9)
  269.          cWrite("   "..skill3[1].."     "..skill4[1].."   ",11)
  270.               elseif cm2lr == 1 and cm2ud == 2 then
  271.          cWrite("   "..skill1[1].."     "..skill2[1].."   ",9)
  272.          cWrite("  ["..skill3[1].."]    "..skill4[1].."   ",11)
  273.               elseif cm2lr == 2 and cm2ud == 2 then
  274.          cWrite("   "..skill1[1].."     "..skill2[1].."   ",9)
  275.          cWrite("   "..skill3[1].."    ["..skill4[1].."]  ",11)
  276.               end
  277.               if cm2finished == 1 then
  278.                     if cm2lr == 1 and cm2ud == 1 then
  279.                            cm2confirmed = 1
  280.                            return "skill1"
  281.                     elseif cm2lr == 2 and cm2ud == 1 then
  282.                            cm2confirmed = 1
  283.                             return "skill2"
  284.                     elseif cm2lr == 1 and cm2ud == 2 then
  285.                            cm2confirmed = 1
  286.                            return "skill3"
  287.                     elseif cm2lr == 2 and cm2ud == 2 then
  288.                            cm2confirmed = 1
  289.                            return "skill4"
  290.                     end
  291.               end
  292.        end
  293.    end
  294. end
  295. function useSkill(nameOfSkill)
  296.  if skill1[1] == nameOfSkill then
  297.   whichSkill = 1
  298.  elseif skill2[1] == nameOfSkill then
  299.   whichSkill = 2
  300.  elseif skill3[1] == nameOfSkill then
  301.   whichSkill = 3
  302.  else
  303.   whichSkill = 4
  304.  end
  305. if nameOfSkill == "Power Slash" then
  306.  if whichSkill == 1 then
  307.   dmgtodeal = math.random(skill1[2],skill1[3])
  308.   mana = mana -skill1[4]
  309.  elseif whichSkill == 2 then
  310.   dmgtodeal = math.random(skill2[2],skill2[3])
  311.   mana = mana -skill2[4]
  312.  elseif whichSkill == 3 then
  313.   dmgtodeal = math.random(skill3[2],skill3[3])
  314.   mana = mana -skill3[4]
  315.  elseif whichSkill == 4 then
  316.   dmgtodeal = math.random(skill4[2],skill4[3])
  317.   mana = mana -skill4[4]
  318.  end
  319.                                  dmgtodeal = math.ceil(dmgtodeal)
  320.                                 enemyhp = enemyhp -dmgtodeal
  321.                                 if enemyhp <= 0 then
  322.                                       enemyhp = 0
  323.                      
  324.                                 end
  325.  end
  326. if nameOfSkill == "Fireball" then
  327.  if whichSkill == 1 then
  328.   dmgtodeal = math.random(skill1[2],skill1[3])
  329.   mana = mana -skill1[4]
  330.  elseif whichSkill == 2 then
  331.   dmgtodeal = math.random(skill2[2],skill2[3])
  332.   mana = mana -skill2[4]
  333.  elseif whichSkill == 3 then
  334.   dmgtodeal = math.random(skill3[2],skill3[3])
  335.   mana = mana -skill3[4]
  336.  elseif whichSkill == 4 then
  337.   dmgtodeal = math.random(skill4[2],skill4[3])
  338.   mana = mana -skill4[4]
  339.  end
  340.                                  dmgtodeal = math.ceil(dmgtodeal)
  341.                                 enemyhp = enemyhp -dmgtodeal
  342.                                 if enemyhp <= 0 then
  343.                                       enemyhp = 0
  344.                      
  345.                                 end
  346.  
  347. end
  348. end
  349.  
  350. function battle(mtoface)
  351.         mana = magic
  352.             bresult = 2
  353.             ma = mtoface
  354.             term.clear()
  355.             term.setCursorPos(1,1)
  356.             enemyhp = mhp[ma]
  357.             enemyatk = matk[ma]
  358.             enemydef = mdef[ma]
  359.             enemyname = mname[ma]
  360.             enemyxp = mexp[ma]
  361.             enemysn = mskilln[ma]
  362.             enemysdmg = mskilldmg[ma]
  363.             hp = maxhp
  364.             batk = atk
  365.             bdef = def
  366.             updatehealth()
  367.             drawchars()
  368.             drawtitle()
  369.             battlefinish = 0
  370.             while battlefinish == 0 do
  371.                      
  372.                     updatehealth()
  373.                       if hp <= 0 then
  374.                                 lose()
  375.                                 battlefinish = 1
  376.                       end
  377.                       if enemyhp <= 0 then
  378.                                 win()
  379.                                 battlefinish = 1
  380.                       end
  381.                       mv1 = choosemove1()
  382.                       if mv1 == "items" or mv1 == "skills" then
  383.                                 mv2 = choosemove2()
  384.                 if mv1 == "skills" then
  385.                         useSkill(mv2)
  386.                 end
  387.                       elseif mv1 == "run" then
  388.                                 rvar = math.random(1,3)
  389.                                 if rvar == 1 then
  390.                                           run()
  391.                                           battlefinish = 1
  392.                                 end
  393.                       elseif mv1 == "attack" then
  394.                                 edefm = math.random(2,4)
  395.                                 edef = enemydef /edefm
  396.                                 dmgtodeal = batk -edef
  397.                                 dmgtodeal = math.ceil(dmgtodeal)
  398.                                 enemyhp = enemyhp -dmgtodeal
  399.                                 if enemyhp <= 0 then
  400.                                       enemyhp = 0
  401.                      
  402.                                 end
  403.                                 cWrite("                                             ",1)
  404.                                 cWrite("                                             ",2)
  405.                                 cWrite("You attack and do "..dmgtodeal.."dmg",1)
  406.                                 cWrite("To "..enemyname,2)
  407.                                 updatehealth()
  408.                                 sleep(1)
  409.                       end
  410.                       --Now for the enemy.
  411.                       if enemyhp <= 0 then
  412.                             win()
  413.                             battlefinish = 1
  414.                       end
  415.                       if battlefinish == 0 then
  416.                               atktype = math.random(1,3)
  417.                               oldhp = hp
  418.                               if atktype == 1 then
  419.                                          hp = hp -enemysdmg
  420.                                          if hp >= oldhp then
  421.                                                  hp = oldhp
  422.                                          end
  423.                                          if hp <= 0 then
  424.                                                  hp = 0
  425.                                          end
  426.                                          cWrite("                                             ",1)
  427.                                          cWrite("                                             ",2)
  428.                                          cWrite(enemyname .. " Attacked you and did",1)
  429.                                          cWrite(enemysdmg .. "dmg with " ..enemysn.." ",2)
  430.                                          sleep(1.2)
  431.                               elseif atktype == 3 or atktype == 2 then
  432.                                         aldef = def/3
  433.                                         aldef = aldef +math.random(1,3)
  434.                                         aldmg = enemyatk - aldef
  435.                                         aldmg = math.ceil(aldmg)
  436.                                         if aldmg <= 0 then
  437.                                               aldmg = 0
  438.                                         end
  439.                                         hp = hp -aldmg
  440.                                         if hp >= oldhp then
  441.                                                 hp = oldhp
  442.                                         end
  443.                                         if hp <= 0 then
  444.                                                 hp = 0
  445.                                         end
  446.                                         cWrite("                                             ",1)
  447.                                         cWrite("                                             ",2)
  448.                                         cWrite(enemyname .. " Attacked you and did",1)
  449.                                         cWrite(aldmg .. "dmg",2)
  450.                               end
  451.                       end
  452.                
  453.                      
  454.             end
  455. end
  456. screenx, screeny = term.getSize()
  457. function cWrite(text,ytwa)
  458.             if not ytwa then
  459.                       unusedx,ytwa = term.getCursorPos()
  460.             end
  461.             local len = string.len(text)
  462.             local sxtw = screenx /2
  463.             local len = len /2
  464.             local sxtw = sxtw - len
  465.             term.setCursorPos(sxtw,ytwa)
  466.             write(text)
  467. end
  468. function Attack(Amount)
  469.          
  470. end
  471. function selection() -- I use a function because I
  472.           -- Plan to make a GUI here later
  473.           select = 0
  474.           term.clear()
  475.           term.setCursorPos(1,1)
  476.           print("Mages use mostly skills for combat")
  477.           print("While Knights use mostly normal attacks")
  478.           print("Knight's skills are mostly buffs")
  479.           print("Mage's skills are mostly attacks")
  480.           print("Arrow keys to select, Enter to confirm")
  481.           -- ABSOLUTELY NO BALANCING
  482.           -- I know knight is probably going to be better
  483.           term.setCursorPos(8,6) -- Indentation FTW
  484.           write("[Knight]     Mage ")
  485.           confirm = 0
  486.           sover = 1
  487.           while select == 0 do
  488.                     p1,p2 = os.pullEvent("key")
  489.                     if p2 == 205 then
  490.                                sover = 2
  491.                     elseif p2 == 203 then
  492.                                sover = 1
  493.                     elseif p2 == 28 then
  494.                                confirm = 1
  495.                     end
  496.                     if sover == 1 then
  497.                                term.setCursorPos(8,6)
  498.                                write("[Knight]     Mage ")
  499.                      elseif sover == 2 then
  500.                                 term.setCursorPos(8,6)
  501.                                 write(" Knight     [Mage]")
  502.                      end
  503.                      if confirm == 1 then
  504.                                 if sover ==2 then
  505.                                            class = "mage"
  506.                                 elseif sover == 1 then
  507.                                            class = "knight"
  508.                                 end
  509.                                 select = 1
  510.                      end
  511.           end
  512. end
  513.  
  514. print("Please select your class!")
  515. print("Class selection screen in 1 second")
  516. sleep(1)
  517. selection()
  518. term.clear()
  519. term.setCursorPos(1,1)
  520. print("??: So, you are a ".. class .. " , Well, Not even " .. class .. "s can destroy me!")
  521. sleep(1.5)
  522. print("??2: Teleport!")
  523. term.setCursorPos(1,19)
  524. write("Wizards Camp")
  525. term.setCursorPos(1,4)
  526. textutils.slowPrint("Master Wizard: Hello, I am the Master Wizard")
  527. textutils.slowPrint("I must teach you how to battle, but quickly!")
  528. sleep(0.5)
  529. textutils.slowPrint("Because a army is approaching from the Dark Crystal")
  530. print("[Tutorial starting in 3 seconds... ]")
  531. sleep(3)
  532. term.clear()
  533. term.setCursorPos(1,1)
  534. print("[Note: This is not an actual battle]")
  535. print(" ")
  536. cWrite("Master Wizard Vs. Tutorial Dummy",3)
  537. term.setCursorPos(1,17)
  538. term.setBackgroundColor(colors.green)
  539. cWrite("Grand Wizard 900/900")
  540. term.setCursorPos(1,18)
  541. cWrite("Tutorial Dummy 5/5")
  542. term.setBackgroundColor(colors.black)
  543. term.setCursorPos(1,4)
  544. cWrite(" o          [] ",4)
  545. cWrite("/|\\        -|-",5)
  546. cWrite("  |          |  ",6)
  547. cWrite("/ \\        _=_",7)
  548. term.setCursorPos(1,9)
  549. sleep(0.5)
  550. cWrite("[Attack]    Skill",9)
  551. cWrite("Item         Escape",11)
  552. term.setCursorPos(1,2)
  553. textutils.slowWrite("Select the move you want to use")
  554. sleep(1.75)
  555. cWrite(" Attack    [Skill]",9)
  556. term.setCursorPos(1,2)
  557. write("                                 ")
  558. term.setCursorPos(1,2)
  559. textutils.slowWrite("Then press the enter key")
  560. sleep(1.75) --100th line! (I know it's not now)
  561. term.setCursorPos(1,2)
  562. write("                                ")
  563. cWrite("  [Explosion]  Fire Ball  ", 9)
  564. cWrite("  Shield      Heal   ",11)
  565. sleep(2)
  566. cWrite("                             ",9)
  567. cWrite("                               ",11)
  568. term.setCursorPos(1,2)
  569. textutils.slowWrite("Grand Wizard used Explosion, 500 dmg")
  570. term.setBackgroundColor(colors.red) --At one time the 200th line
  571. term.setCursorPos(1,18)
  572. cWrite("Tutorial Dummy 0/5")
  573. term.setBackgroundColor(colors.black)
  574. sleep(2)
  575. initchar(class)
  576. sleep(1.5)
  577. term.clear() -- At one time the 250th line
  578. term.setCursorPos(1,1)
  579. textutils.slowWrite("Now you try!")
  580. term.setCursorPos(1,2)
  581. print("[Battle starting in 3 seconds.]")
  582. sleep(3)
  583. toface = 1
  584. bresult = 3
  585. while bresult == 3 do --You ,must win this battle
  586.   battle(toface) --At one time the 350th line
  587. end
  588. term.setCursorPos(1,1)
  589. cWrite("You won the battle!")
  590. print("Grand Wizard no time to continue this")
  591. print("The enemies are here, I'll let you")
  592. print("Battle the weaker enemies.")
  593. print("3-in-a-row Battle starting in 2 seconds")
  594. sleep(2)
  595. wins = 0
  596. while wins ~= 3 do
  597.    
  598.     battle(2)
  599.     if bresult == 1 then
  600.       wins = wins +1
  601.       battle(2)
  602.       if bresult == 1 then
  603.          wins = wins +1
  604.         battle(3)
  605.         if bresult == 1 then
  606.             wins = wins +1
  607.         else
  608.             wins = 0
  609.         end
  610.       else
  611.           wins = 0
  612.         end
  613.     else
  614.         wins = 0
  615.     end
  616. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement