Advertisement
Guest User

RPG_Mode_v1

a guest
Jul 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 24.56 KB | None | 0 0
  1. local gameStarted = false
  2.  
  3. local HogList = {}
  4. local HogLifes = {}
  5. local HogLevel = {}
  6. local HogHealth = {}
  7. local HogAttack = {}
  8. local HogDefense = {}
  9. local HogSpeed = {}
  10. local HogExperience = {}
  11. local HogName = {}
  12. local HogClass1 = {}
  13. local HogClass2 = {}
  14. local HogClass3 = {}
  15. local HogLastHealth = {}
  16. local HogAmmo = {}
  17. local HogCurrentAmmo = {}
  18. local HogInit = {}
  19. local PreviousHedgehog
  20.  
  21. local classes = {"Hedgehog", "Artilleryman", "Grenadier", "Gunslinger", "Fighter", "Scout", "Escavator", "Blazer",
  22. "Bombarder", "Glutton", "Trapper", "Demolitionist", "Hitter", "Infiltrator", "Engineer", "Sniper", "Incinerator",
  23. "Cannon Fodder", "Strategist", "Coordinator", "Infernal Grenadier", "Time Lord", "Sciencist", "Sacrifice", "Lifegiver"}
  24.  
  25. local classAmmo = {["Artilleryman"] = {amBazooka, amMortar}, ["Grenadier"] = {amGrenade, amClusterBomb},
  26. ["Gunslinger"] = {amDEagle, amShotgun}, ["Fighter"] = {amWhip, amFirePunch},
  27. ["Scout"] = {amRope, amParachute, amSnowball}, ["Escavator"] = {amBlowTorch, amPickHammer},
  28. ["Blazer"] = {amFlamethrower, amMolotov}, ["Bombarder"] = {amAirAttack, amDrillStrike},
  29. ["Glutton"] = {amSeduction, amKnife, amGasBomb}, ["Trapper"] = {amMine, amSMine, amExtraDamage},
  30. ["Demolitionist"] = {amDynamite, amCake, amMinigun}, ["Hitter"] = {amBaseballBat, amHammer},
  31. ["Infiltrator"] = {amJetpack, amPortalGun, amBirdy}, ["Engineer"] = {amGirder, amRubber, amLandGun, amLowGravity},
  32. ["Sniper"] = {amSniperRifle, amLaserSight}, ["Incinerator"] = {amNapalm}, ["Cannon Fodder"] = {amKamikaze},
  33. ["Strategist"] = {amBee, amDrill, amDuck}, ["Coordinator"] = {amMineStrike, amRCPlane, amVampiric},
  34. ["Infernal Grenadier"] = {amWatermelon, amHellishBomb}, ["Time Lord"] = {amTeleport, amExtraTime, amTardis},
  35. ["Sciencist"] = {amBallgun, amSineGun, amIceGun}, ["Sacrifice"] = {amPiano},
  36. ["Lifegiver"] = {amInvulnerable, amResurrector}}
  37.  
  38. local healthBonus = {"Fighter", "Glutton", "Cannon Fodder", "Coordinator", "Time Lord", "Lifegiver", "Scout", "Hitter"}
  39. local attackBonus = {"Gunslinger", "Blazer", "Sniper", "Incinerator", "Infernal Grenadier", "Demolitionist", "Infiltrator", "Sacrifice"}
  40. local defenseBonus = {"Artilleryman", "Escavator", "Sciencist", "Trapper", "Grenadier", "Engineer", "Strategist", "Bombarder"}
  41.  
  42. local comboNames = {["FireDynamite"] = "Fiery Dynamite", ["TripleMissile"] = "Tripple Missiles", ["MortarPlane"] = "Mortar Plane",
  43. ["FireX3"] = "Longfire", ["ChainLightning"] = "Chained Sine", ["FieryBallgun"] = "Balls of Fire", ["MelonBallgun"] = "Melongun",
  44. ["CheeseHammer"] = "Cheesy Hammer", ["SuperSniper"] = "Amplified Sniper", ["1UP"] = "Kami of Life Stealing",
  45. ["TeleportTrap"] = "Teleporting Surprise", ["InfiniteTools"] = "Tool Master", ["Thorns"] = "Psi Thorns", ["DoubleMelon"] = "Melon Party",
  46. ["InfinitePiano"] = "Eternal Sonata", ["FreeKami"] = "Non-kamikaze Kamikaze", ["TeamVampirism"] = "OUR Health", ["InvBallgun"] = "Ballproof"}
  47.  
  48. local classSelect = 1
  49. local classMin = 1
  50. local classMax = 1
  51. local actionsDone = 0
  52. local menu = false
  53. local createTag = false
  54. local requestUpdateAmmo = false
  55.  
  56. local bonusHelpers = {}
  57. local bonusHelpersPersistent = {["FireX3"] = {}}
  58.  
  59. function onGameInit()
  60.   EnableGameFlags(gfInfAttack)
  61. end
  62.  
  63. function onVisualGearAdd(gear)
  64.   if not createTag and (GetVisualGearType(gear) == vgtHealthTag or GetVisualGearType(gear) == vgtSmallDamageTag) then
  65.     DeleteVisualGear(gear)
  66.   end
  67. end
  68.  
  69. function onGearAdd(gear)
  70.     if GetGearType(gear) == gtHedgehog then
  71.     table.insert(HogList, gear)
  72.     HogLifes[gear] = 2
  73.     HogLevel[gear] = 1
  74.     HogHealth[gear] = 100
  75.     HogAttack[gear] = 0
  76.     HogDefense[gear] = 0
  77.     HogSpeed[gear] = 1
  78.     HogExperience[gear] = 0
  79.     HogAmmo[gear] = {}
  80.     SetEffect(gear, heResurrectable, 1)
  81.   end
  82.  
  83.   if (GetGearType(gear) == gtShell or GetGearType(gear) == gtDrill or GetGearType(gear) == gtMortar) and not bonusHelpers["Triple"] and HasCombo(CurrentHedgehog, "TripleMissile") then
  84.         local x, y = GetGearPosition(gear)
  85.         local vx, vy = GetGearVelocity(gear)
  86.     local angle = math.atan(vx/vy)
  87.     if vy>0 then
  88.       angle = angle + math.pi
  89.     end
  90.     local speed = math.sqrt(vx*vx+vy*vy)
  91.    
  92.     bonusHelpers["Triple"] = true
  93.     AddGear(x, y, GetGearType(gear), 0, -math.sin(angle + math.pi/32) * speed, -math.cos(angle + math.pi/32) * speed, 0)
  94.     AddGear(x, y, GetGearType(gear), 0, -math.sin(angle - math.pi/32) * speed, -math.cos(angle - math.pi/32) * speed, 0)
  95.     bonusHelpers["Triple"] = false
  96.   end
  97.  
  98.   if GetGearType(gear) == gtAirBomb and HasCombo(CurrentHedgehog, "MortarPlane") then
  99.     CopyPV(gear, AddGear(0, 0, gtMortar, 0, 0, 0, 0))
  100.     DeleteGear(gear)
  101.   end
  102.  
  103.   if GetGearType(gear) == gtBall then
  104.     if HasCombo(CurrentHedgehog, "MelonBallgun") then
  105.       local gera = AddGear(0, 0, gtMelonPiece, 75, 75, 75, 75)
  106.       CopyPV(gear, gera)
  107.       local x, y = GetGearPosition(gera);
  108.       SetGearPosition(gera, x, y-16)
  109.       DeleteGear(gear)
  110.     end
  111.  
  112.     if bonusHelpers["InvBallgunCount"] then
  113.       bonusHelpers["InvBallgunCount"] = bonusHelpers["InvBallgunCount"] + 1
  114.     end
  115.   end
  116.  
  117.   if GetGearType(gear) == gtSineGunShot and HasCombo(CurrentHedgehog, "ChainLightning") then
  118.     if not bonusHelpers["ChainLightning"] then
  119.       bonusHelpers["ChainLightning"]={["Sines"] = {}}
  120.     end
  121.     bonusHelpers["ChainLightning"]["Sines"][gear]=true
  122.   end
  123.  
  124.   if GetGearType(gear) == gtFlame and HasCombo(CurrentHedgehog, "FireX3") and not bonusHelpers["FireX3"] then
  125.     bonusHelpersPersistent["FireX3"][gear] = {GetTag(gear), 2}
  126.   end
  127.  
  128.   if GetGearType(gear) == gtSniperRifleShot and HasCombo(CurrentHedgehog, "SuperSniper") then
  129.     local Angle, Power, WDTimer, Radius, Density, Karma, DirAngle, AdvBounce, ImpactSound, nImpactSounds, Tint, Damage, Boom = GetGearValues(gear)
  130.     SetGearValues(gear, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, Boom*10)
  131.   end
  132.  
  133.   if GetGearType(gear) == gtMelonPiece and HasCombo(CurrentHedgehog, "DoubleMelon") and not bonusHelpers["BlockMelon"] then
  134.     x, y = GetGearPosition(gear)
  135.     dx, dy = GetGearVelocity(gear)
  136.     bonusHelpers["BlockMelon"] = true
  137.     local double = AddGear(x, y, gtMelonPiece, 0, dx + -2000 + GetRandom(4001), dy, 75)
  138.     bonusHelpers["BlockMelon"] = false
  139.   end
  140.  
  141.   if GetGearType(gear) == gtPiano and HasCombo(CurrentHedgehog, "InfinitePiano") then
  142.     SetGearPos(gear, 10000)
  143.   end
  144. end
  145.  
  146. function onGearResurrect(gear)
  147.   if GetGearType(gear) == gtHedgehog then
  148.     local lostLife = true
  149.  
  150.     if band(GetState(gear), gstDrowning) ~= 0 and (not bonusHelpers["1UP"] or gear ~= bonusHelpers["1UP"]) then
  151.       if HogLastHealth[gear] - 50 <= 0 then
  152.         SetHealth(gear, HogHealth[gear])
  153.         HogLifes[gear] = HogLifes[gear] - 1
  154.       else
  155.         lostLife = false
  156.         SetHealth(gear, HogLastHealth[gear] - 50)
  157.       end
  158.      
  159.       createTag = true
  160.       SetTagColor(AddVisualGear(GetX(gear), GetY(gear), vgtHealthTag, math.min(HogLastHealth[gear], 50), true), 0xff0000ff)
  161.       createTag = false
  162.      
  163.       if GetHogClan(gear) ~= GetHogClan(CurrentHedgehog) then
  164.         AddExperience(CurrentHedgehog, math.min(HogLastHealth[gear], 50))
  165.       end
  166.     else
  167.       SetHealth(gear, HogHealth[gear])
  168.       HogLifes[gear] = HogLifes[gear] - 1
  169.     end
  170.    
  171.     if HogLifes[gear] == 0 then
  172.       SetEffect(gear, heResurrectable, 0)
  173.       AddCaption(GetHogName(gear) .. ' has last life!', 0xff000000, capgrpMessage)
  174.     elseif lostLife then
  175.       AddCaption(GetHogName(gear) .. ' has ' .. HogLifes[gear] .. ' lifes left', 0xffff0000, capgrpMessage)
  176.     end
  177.   end
  178. end
  179.  
  180. function onGearDelete(gear)
  181.   if GetGearType(gear) == gtHedgehog then
  182.     table.remove(HogList, gear)
  183.    
  184.     if bonusHelpers["1UP"] and GetHogClan(gear) ~= GetHogClan(bonusHelpers["1UP"]) then
  185.       HogLifes[BonusHelpers["1UP"]] = HogLifes[bonusHelpers["1UP"]] + 1
  186.       bonusHelpers["1UP"] = nil
  187.     end
  188.    
  189.     if bonusHelpers["FreeKami"] and gear == BonusHelpers["FreeKami"] then
  190.       HogLifes[BonusHelpers["FreeKami"]] = HogLifes[bonusHelpers["FreeKami"]] + 1
  191.     end
  192.    
  193.     if CurrentHedgehog and GetGearType(gear) == gtHedgehog and GetHealth(gear) > 0 and GetHogClan(gear) ~= GetHogClan(CurrentHedgehog) then
  194.       AddExperience(CurrentHedgehog, math.floor(GetHealth(gear))) ----ew. -Damage
  195.     end
  196.   end
  197.  
  198.   if GetGearType(gear) == gtDynamite and HasCombo(CurrentHedgehog, "FireDynamite") then
  199.         local x, y = GetGearPosition(gear);
  200.     for i=0, 100, 1 do
  201.       AddGear(x-50+GetRandom(101), y-50+GetRandom(101), gtFlame, 0, 0, 0, 1)
  202.     end
  203.   end
  204.  
  205.   if GetGearType(gear) == gtBall then
  206.     if HasCombo(CurrentHedgehog, "FieryBallgun") then
  207.       local x, y = GetGearPosition(gear);
  208.       for i=0, 20, 1 do
  209.         AddGear(x-20+GetRandom(41), y-20+GetRandom(41), gtFlame, 0, 0, 0, 1)
  210.       end
  211.     end
  212.    
  213.     if bonusHelpers["InvBallgunCount"] then
  214.       bonusHelpers["InvBallgunCount"] = bonusHelpers["InvBallgunCount"] - 1
  215.  
  216.       if bonusHelpers["InvBallgunCount"] == 0 then
  217.         SetEffect(CurrentHedgehog, heInvulnerable, bonusHelpers["InvBallgunCount"])
  218.         bonusHelpers["InvBallgunCount"] = nil
  219.         bonusHelpers["InvBallgun"] = nil
  220.       end
  221.     end
  222.   end
  223.  
  224.   if GetGearType(gear) == gtSineGunShot and bonusHelpers["ChainLightning"] then
  225.     bonusHelpers["ChainLightning"]["Sines"][gear]=nil
  226.     if not next(bonusHelpers["ChainLightning"]["Sines"]) then
  227.       bonusHelpers["ChainLightning"]=nil
  228.     end
  229.   end
  230.  
  231.   if GetGearType(gear) == gtFlame and bonusHelpersPersistent["FireX3"][gear] then
  232.     if bonusHelpersPersistent["FireX3"][gear][2] > 0 then
  233.       bonusHelpers["FireX3"]=true
  234.       newg = AddGear(x, y, gtFlame, 0, 0, 0, 0)
  235.       bonusHelpers["FireX3"]=false
  236.       SetTag(newg, bonusHelpersPersistent["FireX3"][gear][1])
  237.       CopyPV(gear, newg)
  238.       bonusHelpersPersistent["FireX3"][newg] = {bonusHelpersPersistent["FireX3"][gear][1], bonusHelpersPersistent["FireX3"][gear][2] - 1}
  239.     end
  240.     bonusHelpersPersistent["FireX3"][gear]=nil
  241.   end
  242.  
  243.   if GetGearType(gear) == gtHammer and HasCombo(CurrentHedgehog, "CheeseHammer") then
  244.     dx = GetGearVelocity(CurrentHedgehog)
  245.     x, y = GetGearPosition(gear)
  246.     SetGearElasticity(AddGear(x + 15 + 30*dx, y + 20, gtGasBomb, 0, 0, 0, 1000), 9999)
  247.   end
  248.  
  249.   if GetGearType(gear) == gtKamikaze and HasCombo(CurrentHedgehog, "1UP") then
  250.     SetGearMessage(CurrentHedgehog, band(GetGearMessage(CurrentHedgehog), bnot(gmDestroy)))
  251.     SetGearPosition(CurrentHedgehog, 0, WaterLine + 1000)
  252.   end
  253.  
  254.   if GetGearType(gear) == gtTeleport and HasCombo(CurrentHedgehog, "TeleportTrap") then
  255.     x, y = GetGearPosition(gear)
  256.     AddGear(x, y, gtMine, 0, 0, 0, 1)
  257.   end
  258. end
  259.  
  260. function onGearDamage(gear, damage)
  261.   if GetGearType(gear) == gtHedgehog then
  262.     local actualDamage = math.max(damage + HogAttack[CurrentHedgehog] - HogDefense[gear],0)
  263.     actualDamage = math.floor(actualDamage + actualDamage * 0.1 + GetRandom(actualDamage * 0.2 + 1))
  264.  
  265.     if bonusHelpers["VampirismActive"] then
  266.       SetHealth(CurrentHedgehog, GetHealth(CurrentHedgehog) - math.floor(damage * 0.8))
  267.       HealHog(CurrentHedgehog, math.floor(actualDamage * 0.8), true, 0xff0000ff)
  268.  
  269.       if HasCombo(CurrentHedgehog, "TeamVampirism") then
  270.         for index, hog in pairs(HogList) do
  271.           if GetHogClan(hog) == GetHogClan(CurrentHedgehog) and hog ~= CurrentHedgehog then
  272.             HealHog(hog, math.floor(actualDamage * 0.2), true, 0xff0000ff)
  273.           end
  274.         end
  275.       end
  276.     end
  277.    
  278.     SetHealth(gear, GetHealth(gear) + damage - actualDamage)
  279.    
  280.     if GetHealth(gear) <= -100 then
  281.       AddCaption("OVERKILL!!!", 0xffff0000, capgrpAmmoinfo)
  282.       damage = damage * 2
  283.     end
  284.    
  285.     createTag = true
  286.     SetTagColor(AddVisualGear(GetX(gear), GetY(gear), vgtHealthTag, actualDamage, true), 0xff0000ff)
  287.     if HasCombo(gear, "Thorns") and GetHogClan(gear) ~= GetHogClan(CurrentHedgehog) then
  288.       local thorns = actualDamage/3
  289.       SetTagColor(AddVisualGear(GetX(CurrentHedgehog), GetY(CurrentHedgehog)-30, vgtHealthTag, thorns, true), 0xff0000ff)
  290.       SetHealth(CurrentHedgehog, GetHealth(CurrentHedgehog) - thorns)
  291.     end
  292.     createTag = false
  293.    
  294.     if GetHogClan(gear) ~= GetHogClan(CurrentHedgehog) then
  295.       AddExperience(CurrentHedgehog, damage)
  296.     end
  297.    
  298.     UpdateStats()
  299.   end
  300.  
  301.   if GetGearType(gear) == gtHedgehog and GetHogClan(gear) ~= GetHogClan(CurrentHedgehog) and bonusHelpers["ChainLightning"] then
  302.     bonusHelpers["ChainLightning"][gear] = true
  303.     local x, y = GetGearPosition(gear)
  304.     local nearest = getNearestEnemy(x, y, 1000)
  305.    
  306.     if nearest then
  307.       local x2, y2 = GetGearPosition(nearest)
  308.       local angle = getAngle(x, y, x2, y2)
  309.      
  310.       AddGear(x, y, gtSineGunShot, 0, math.floor(-math.sin(angle) * 1000), math.floor(-math.cos(angle) * 1000), 0)
  311.     end
  312.   end
  313. end
  314.  
  315. function AddExperience(hog, experience)
  316.   createTag = true
  317.   SetTagColor(AddVisualGear(GetX(hog), GetY(hog), vgtHealthTag, experience, true), 0xffff00ff)
  318.   createTag = false
  319.   HogExperience[hog] = HogExperience[hog] + experience
  320.  
  321.   if not HogName[hog] then
  322.     HogName[hog] = GetHogName(hog)
  323.   end
  324.  
  325.   while HogExperience[hog] >= HogLevel[hog]*50 do
  326.     HogExperience[hog] = HogExperience[hog] - HogLevel[hog]*50
  327.     HogLevel[hog] = HogLevel[hog] + 1
  328.    
  329.     HogHealth[hog] = HogHealth[hog] + 50
  330.     for index, class in ipairs(healthBonus) do if HogClass1[hog] == class or HogClass2[hog] == class or HogClass3[hog] == class then
  331.       HogHealth[hog] = HogHealth[hog] + 25
  332.     end end
  333.    
  334.     HogAttack[hog] = HogAttack[hog] + 10
  335.     for index, class in ipairs(attackBonus) do if HogClass1[hog] == class or HogClass2[hog] == class or HogClass3[hog] == class then
  336.       HogAttack[hog] = HogAttack[hog] + 5
  337.     end end
  338.    
  339.     HogDefense[hog] = HogDefense[hog] + 10
  340.     for index, class in ipairs(defenseBonus) do if HogClass1[hog] == class or HogClass2[hog] == class or HogClass3[hog] == class then
  341.       HogDefense[hog] = HogDefense[hog] + 5
  342.     end end
  343.    
  344.     if HogLevel[hog] % 5 == 0 then
  345.       HogSpeed[hog] = HogSpeed[hog] + 1
  346.     end
  347.    
  348.     SetHealth(hog, HogHealth[hog])
  349.     AddCaption(HogName[hog] .. ' reached level ' .. HogLevel[hog] .. '!', 0x00ff0000, capgrpMessage2)
  350.     SetHogName(hog, HogName[hog] .. ' Lv. ' .. HogLevel[hog])
  351.   end
  352. end
  353.  
  354. function onAttack()
  355.   if GetCurAmmoType() == amBallgun and HasCombo(CurrentHedgehog, "InvBallgun") then
  356.     bonusHelpers["InvBallgun"] = GetEffect(CurrentHedgehog, heInvulnerable)
  357.     bonusHelpers["InvBallgunCount"] = 0
  358.     SetEffect(CurrentHedgehog, heInvulnerable, 1)
  359.   end
  360. end
  361.  
  362. function onUsedAmmo(ammoType)
  363.   local free = {[amNothing] = true, [amSwitch] = true, [amParachute] = true, [amRope] = true, [amSnowball] = true, [amResurrector] = true,
  364.   [amExtraDamage] = true, [amExtraTime] = true, [amLowGravity] = true, [amLaserSight] = true, [amVampiric] = true}
  365.  
  366.   if HasCombo(CurrentHedgehog, "InfiniteTools") then
  367.     free[amGirder] = true
  368.     free[amRubber] = true
  369.     free[amPickHammer] = true
  370.     free[amBlowTorch] = true
  371.     free[amLandGun] = true
  372.   end
  373.  
  374.   local inStore = FindIndex(HogCurrentAmmo[CurrentHedgehog], ammoType)
  375.   if inStore then
  376.     table.remove(HogCurrentAmmo[CurrentHedgehog], inStore)
  377.   end
  378.  
  379.   if not free[ammoType] then
  380.     actionsDone = actionsDone + 1
  381.     UpdateStats()
  382.    
  383.     if actionsDone >= HogSpeed[CurrentHedgehog] then
  384.       requestUpdateAmmo = true
  385.     end
  386.   end
  387.  
  388.   if ammoType == amKamikaze and HasCombo(CurrentHedgehog, "1UP") then
  389.     bonusHelpers["1UP"] = CurrentHedgehog
  390.   end
  391.  
  392.   if ammoType == amKamikaze and HasCombo(CurrentHedgehog, "FreeKami") then
  393.     bonusHelpers["FreeKami"] = CurrentHedgehog
  394.   end
  395.  
  396.   if ammoType == amVampiric then
  397.     bonusHelpers["VampirismActive"] = true
  398.   end
  399. end
  400.  
  401. -- function DebugWriteTable(table) ----DEBUG
  402. --   local str = ""
  403. --   for index, e in ipairs(table) do
  404. --     str = str .. e .. " "
  405. --   end
  406. --   WriteLnToChat(str)
  407. -- end
  408.  
  409. function onNewTurn()
  410.   actionsDone = 0
  411.   classSelect = 1
  412.   HogInit = {}
  413.   bonusHelpers = {}
  414.   gameStarted = true
  415. end
  416.  
  417. function onGameTick20()
  418.   if requestUpdateAmmo then
  419.     UpdateAmmo()
  420.     requestUpdateAmmo = false
  421.   end
  422.  
  423.   if CurrentHedgehog ~= PreviousHedgehog then
  424.     if not CurrentHedgehog then
  425.       return nil
  426.     end
  427.     UpdateStats()
  428.     UpdateAmmo()
  429.   end
  430.   PreviousHedgehog = CurrentHedgehog
  431.  
  432.   for index, hog in ipairs(HogList) do
  433.     local Angle, Power, WDTimer, Radius, Density, Karma, DirAngle, AdvBounce, ImpactSound, nImpactSounds, Tint, Damage, Boom = GetGearValues(hog)
  434.     HogLastHealth[hog] = GetHealth(hog) - Damage
  435.   end
  436.  
  437.   if gameStarted and CanChangeClass(CurrentHedgehog) then
  438.     if CanChangeClass(CurrentHedgehog) == 1 then
  439.       classMin = 2
  440.       classMax = 11
  441.     elseif CanChangeClass(CurrentHedgehog) == 2 then
  442.       classMin = 12
  443.       classMax = 20
  444.     elseif CanChangeClass(CurrentHedgehog) == 3 then
  445.       classMin = 21
  446.       classMax = 25
  447.     end
  448.     if classSelect < classMin then classSelect = classMin end
  449.    
  450.     if not menu then
  451.       AddCaption("Hold Precise (Shift) to change class", GetClanColor(GetHogClan(CurrentHedgehog)), capgrpAmmoinfo)
  452.     else
  453.       AddCaption((classSelect > classMin and "<< " or "") .. classes[classSelect] .. (classSelect < classMax and " >>" or ""), GetClanColor(GetHogClan(CurrentHedgehog)), capgrpAmmoinfo)
  454.       AddCaption("Press Up to confirm", GetClanColor(GetHogClan(CurrentHedgehog)), capgrpVolume)
  455.     end
  456.   end
  457. end
  458.  
  459. function onPrecise()
  460.   if gameStarted then
  461.     menu = true
  462.   end
  463. end
  464.  
  465. function onPreciseUp()
  466.   menu = false
  467. end
  468.  
  469. function onRight()
  470.   if menu and classSelect < classMax and CanChangeClass(CurrentHedgehog) then
  471.     classSelect = classSelect + 1
  472.   end
  473. end
  474.  
  475. function onLeft()
  476.   if menu and classSelect > classMin and CanChangeClass(CurrentHedgehog) then
  477.     classSelect = classSelect - 1
  478.   end
  479. end
  480.  
  481. function onUp()
  482.   if menu and CanChangeClass(CurrentHedgehog) then
  483.     if CanChangeClass() > 1 then
  484.       HogSpeed[CurrentHedgehog] = HogSpeed[CurrentHedgehog] + 1
  485.     end
  486.    
  487.     local oldCombos = GetAllCombos(CurrentHedgehog)
  488.     SetHogClass(CurrentHedgehog)
  489.     local newCombos = GetAllCombos(CurrentHedgehog)
  490.     for combo, whatever in pairs(oldCombos) do
  491.       newCombos[combo] = nil
  492.     end
  493.     UpdateStats()
  494.    
  495.     for class, weapons in pairs(classAmmo) do
  496.       if class == GetHogClass(CurrentHedgehog) then
  497.         for index, weapon in ipairs(weapons) do
  498.           table.insert(HogAmmo[CurrentHedgehog], weapon)
  499.         end
  500.         break
  501.       end
  502.     end
  503.     HogInit[CurrentHedgehog] = nil
  504.     UpdateAmmo()
  505.    
  506.     AddCaption(GetHogName(CurrentHedgehog) .. "'s class changed to " ..  GetHogClass(CurrentHedgehog), GetClanColor(GetHogClan(CurrentHedgehog)), capgrpAmmoinfo)
  507.     for combo, whatever in pairs(newCombos) do
  508.       AddCaption("Combo \"" .. comboNames[combo] .. "\" has been activated!", GetClanColor(GetHogClan(CurrentHedgehog)), capgrpMessage2)
  509.     end
  510.   end
  511. end
  512.  
  513. -- function onDown() ----debug
  514. --   if menu then
  515. --     AddExperience(CurrentHedgehog, 5000)
  516. --   end
  517. -- end
  518.  
  519. function UpdateStats()
  520.   if CurrentHedgehog then
  521.     ShowMission(GetHogName(CurrentHedgehog), GetHogClass(CurrentHedgehog),
  522.     '|Lifes: ' ..HogLifes[CurrentHedgehog] ..
  523.     '|Health: ' .. GetHealth(CurrentHedgehog) .. '/' .. HogHealth[CurrentHedgehog] ..
  524.     '|Attack: ' .. HogAttack[CurrentHedgehog] ..
  525.     '|Defense: ' .. HogDefense[CurrentHedgehog] ..
  526.     '|Actions left: ' .. HogSpeed[CurrentHedgehog] - actionsDone ..
  527.     '|' .. (HogLevel[CurrentHedgehog]*50-HogExperience[CurrentHedgehog]) .. ' to next level', 3, -1)
  528.   end
  529. end
  530.  
  531. function copyTable(oldTable)
  532.   local newTable = {}
  533.   for index, e in ipairs(oldTable) do
  534.     table.insert(newTable, e)
  535.   end
  536.  
  537.   return newTable
  538. end
  539.  
  540. function UpdateAmmo()
  541.   if CurrentHedgehog then
  542.     for weapon = 0, AmmoTypeMax do
  543.       AddAmmo(CurrentHedgehog, weapon, 0)
  544.     end
  545.     AddAmmo(CurrentHedgehog, amSkip, 100)
  546.     AddAmmo(CurrentHedgehog, amSwitch, 100)
  547.    
  548.     if actionsDone >= HogSpeed[CurrentHedgehog] then
  549.       AddCaption('No actions left', 0xff000000, capgrpAmmostate)
  550.       return
  551.     end
  552.    
  553.     if not HogInit[CurrentHedgehog] then
  554.       HogCurrentAmmo[CurrentHedgehog] = copyTable(HogAmmo[CurrentHedgehog])
  555.       HogInit[CurrentHedgehog] = true
  556.     end
  557.    
  558.     for index, ammo in ipairs(HogCurrentAmmo[CurrentHedgehog]) do
  559.       AddAmmo(CurrentHedgehog, ammo, 1)
  560.     end
  561.   end
  562. end
  563.  
  564. function onAmmoStoreInit()
  565.   for weapon = 0, AmmoTypeMax do
  566.     SetAmmo(weapon, 0, 0, 0)
  567.   end
  568.   SetAmmo(amSkip, 9, 0, 0)
  569.   SetAmmo(amSwitch, 9, 0, 0)
  570. end
  571.  
  572. function GetHogClass(hedgehog)
  573.   if HogClass3[hedgehog] then
  574.     return HogClass3[hedgehog]
  575.   elseif HogClass2[hedgehog] then
  576.     return HogClass2[hedgehog]
  577.   elseif HogClass1[hedgehog] then
  578.     return HogClass1[hedgehog]
  579.   else
  580.     return "Hedgehog"
  581.   end
  582. end
  583.  
  584. function CanChangeClass(hedgehog)
  585.   if not HogClass1[hedgehog] then
  586.     return 1
  587.   elseif HogLevel[hedgehog] >= 5 and not HogClass2[hedgehog] then
  588.     return 2
  589.   elseif HogLevel[hedgehog] >= 10 and not HogClass3[hedgehog] then
  590.     return 3
  591.   end
  592. end
  593.  
  594. function SetHogClass(hedgehog)
  595.   if not HogClass1[hedgehog] then
  596.     HogClass1[hedgehog] = classes[classSelect]
  597.   elseif not HogClass2[hedgehog] then
  598.     HogClass2[hedgehog] = classes[classSelect]
  599.   elseif not HogClass3[hedgehog] then
  600.     HogClass3[hedgehog] = classes[classSelect]
  601.   end
  602. end
  603.  
  604. function HasCombo(hog, name)
  605.   if name=="FireDynamite" then
  606.     return (HogClass1[hog]=="Blazer" and HogClass2[hog]=="Demolitionist")
  607.   elseif name=="TripleMissile" then
  608.     return (HogClass1[hog]=="Artilleryman" and HogClass2[hog]=="Strategist")
  609.   elseif name=="MortarPlane" then
  610.     return (HogClass1[hog]=="Artilleryman" and HogClass3[hog]=="Coordinator")
  611.   elseif name=="FireX3" then
  612.     return (HogClass1[hog]=="Blazer" and HogClass2[hog]=="Incinerator")
  613.   elseif name=="ChainLightning" then
  614.     return (HogClass2[hog]=="Sniper" and HogClass3[hog]=="Sciencist")
  615.   elseif name=="FieryBallgun" then
  616.     return (HogClass1[hog]=="Blazer" and HogClass2[hog]=="Incinerator" and HogClass3[hog]=="Sciencist")
  617.   elseif name=="MelonBallgun" then
  618.     return (HogClass1[hog]=="Grenadier" and HogClass2[hog]=="Demolitionist" and HogClass3[hog]=="Sciencist")
  619.   elseif name=="CheeseHammer" then
  620.     return (HogClass1[hog]=="Glutton" and HogClass2[hog]=="Hitter")
  621.   elseif name=="SuperSniper" then
  622.     return (HogClass1[hog]=="Gunslinger" and HogClass2[hog]=="Sniper")
  623.   elseif name=="1UP" then
  624.     return (HogClass2[hog]=="Cannon Fodder")
  625.   elseif name=="TeleportTrap" then
  626.     return (HogClass2[hog]=="Trapper" and HogClass3[hog]=="Time Lord")
  627.   elseif name=="InfiniteTools" then
  628.     return (HogClass1[hog]=="Escavator" and HogClass2[hog]=="Engineer")
  629.   elseif name=="Thorns" then
  630.     return (HogClass2[hog]=="Trapper" and HogClass3[hog]=="Coordinator")
  631.   elseif name=="DoubleMelon" then
  632.     return (HogClass1[hog]=="Grenadier" and HogClass3[hog]=="Infernal Grenadier")
  633.   elseif name=="InfinitePiano" then
  634.     return (HogClass1[hog]=="Escavator" and HogClass3[hog]=="Sacrifice")
  635.   elseif name=="FreeKami" then
  636.     return (HogClass2[hog]=="Cannon Fodder" and HogClass3[hog]=="Lifegiver")
  637.   elseif name=="TeamVampirism" then
  638.     return (HogClass2[hog]=="Coordinator" and HogClass3[hog]=="Lifegiver")
  639.   elseif name=="InvBallgun" then
  640.     return (HogClass2[hog]=="Engineer" and HogClass3[hog]=="Sciencist")
  641.   end
  642. end
  643.  
  644. function getNearestEnemy(x, y, maxDistance)
  645.   local nearest = maxDistance
  646.   local choosen = nil
  647.  
  648.   for hog, whatevs in pairs(HogLifes) do
  649.     if hog and GetHogClan(hog) ~= GetHogClan(CurrentHedgehog) and (not bonusHelpers["ChainLightning"] or not bonusHelpers["ChainLightning"][hog]) then
  650.       local x2, y2 = GetGearPosition(hog)
  651.       local dist = math.sqrt((x2-x)*(x2-x) + (y2-y)*(y2-y))
  652.       if dist<nearest then
  653.         nearest = dist
  654.         choosen = hog
  655.       end
  656.     end
  657.   end
  658.  
  659.   return choosen
  660. end
  661.  
  662. function getAngle(x1, y1, x2, y2)
  663.   local dx = x2-x1
  664.   local dy = y2-y1
  665.  
  666.   if dy == 0 then
  667.     dy = 1
  668.   end
  669.  
  670.   local angle = math.atan(dx/dy)
  671.   if dy>0 then
  672.     angle = angle + math.pi
  673.   end
  674.  
  675.   return angle
  676. end
  677.  
  678. function SetTagColor(tag, color)
  679.     g1, g2, g3, g4, g5, g6, g7, g8, g9, g10 = GetVisualGearValues(tag)
  680.     SetVisualGearValues(tag, g1, g2, g3, g4, g5, g6, g7, g8, g9, color)
  681. end
  682.  
  683. function GetAllCombos(hedgehog)
  684.   combos = {}
  685.  
  686.   for combo, whatever in pairs(comboNames) do
  687.     if HasCombo(hedgehog, combo) then
  688.       combos[combo] = true
  689.     end
  690.   end
  691.  
  692.   return combos
  693. end
  694.  
  695. function FindIndex(tab, element)
  696.   if not tab then return nil end
  697.  
  698.   for index, e in ipairs(tab) do
  699.     if e == element then return index end
  700.   end
  701.   return nil
  702. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement