wirthe64

game1

Jun 22nd, 2016
167
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local term = require("term")
  2. local event = require("event")
  3. local image = require("image")
  4. local thread = require("thread")
  5. local fs = require("filesystem")
  6. local unicode = require("unicode")
  7. local computer = require("computer")
  8. local keyboard = require("keyboard")
  9. local component = require("component")
  10. local buffer = require("doubleBuffering")
  11. local gpu = component.gpu
  12. gpu.setResolution(160,50)
  13.  
  14. local LANGUAGE = "russian"
  15.  
  16. thread.init()
  17.  
  18. local gamefps, cfps = 0, 0
  19.  
  20. local function loadLanguage(wPath)
  21. if not fs.exists(wPath) then error("File not exists") end
  22. local ptable = {}
  23. local key, value, dmt1
  24. local len = 0
  25. local f = io.open(wPath, "r")
  26.  for line in f:lines() do
  27.  if not f then return nil end
  28.  len = len + 1
  29.  dmt1 = string.find(line, "@")
  30.  value1 = string.sub(line, 1, dmt1 - 2)
  31.  value2 = string.sub(line, dmt1 + 2, #line)
  32.  table.insert(ptable,{value1, value2})
  33.  end
  34. f:close()
  35. if len == 0 then return nil end
  36. return ptable
  37. end
  38.  
  39. local function convLang(ptable,value)
  40. local cLang = 2
  41. local newTable = {}
  42. if value == "russian" then cLang = 1 end
  43.  for f = 1, #ptable do
  44.  newTable[ptable[f][1]] = ptable[f][cLang]
  45.  end
  46. return newTable
  47. end
  48.  
  49. local rawlang = loadLanguage("/home/testgame/translate.lang")
  50.  
  51. local lang = convLang(rawlang, LANGUAGE)
  52.  
  53. local mlSprites = {
  54. ["player"] = "player",
  55. ["zombie"] = "zombie1",
  56. ["ghost"] = "ghost",
  57. ["greenslug"] = "greenslug",
  58. ["vil1"] = "vil1",
  59. ["bush"] = "bush",
  60. }
  61. local aItemIconsSpr = {
  62. [1]="copper_ingot",
  63. [2]="iron_ingot",
  64. [3]="rookies_armor",
  65. [4]="rookies_pants",
  66. [5]="rookies_helmet",
  67. [6]="rookies_boots",
  68. [7]="wooden_sword",
  69. [8]="bone_necklace",
  70. [9]="small_hp",
  71. [10]="small_mp",
  72. [11]="medium_hp",
  73. [12]="medium_mp",
  74. [13]="large_hp",
  75. [14]="large_mp",
  76. [15]="condensed_hp",
  77. [16]="condensed_mp",
  78. }
  79. local dialogs = {
  80. [1]={["text"] = "",
  81.     {["text"] = lang["Задания"],["action"] = "dialog", ["do"] = {
  82.         ["text"] = "Выберите любые доступные задания",
  83.         {["text"] = "Задание1",["action"] = "getquest", ["do"] = 1},
  84.         {["text"] = lang["До встречи"],["action"] = "close", ["do"] = nil},
  85.     }},
  86.     {["text"] = lang["До встречи"],["action"] = "close", ["do"] = nil},
  87.     },
  88. }
  89.  
  90. local mSprites = {}
  91.  
  92. local vAttackDistance = 10
  93.  
  94. local gameUnitData = {
  95.     {["id"] = 1, ["name"] = lang["Игрок"], ["wtype"] = "Управляемый персонаж", ["level"] = 1, ["atds"] = 10,
  96.     ["loot"] = {["exp"] = 0, ["coins"] = 0, ["items"] = {}}, ["vresp"] = 0, ["rtype"] = "p", ["image"] = "player"},
  97.     {["id"] = 2, ["name"] = lang["Зомби"], ["wtype"] = "Ходячий труп",["level"] = 1, ["atds"] = 10,
  98.     ["loot"] = {["exp"] = 2, ["coins"] = 3, ["items"] = {}}, ["vresp"] = 30, ["rtype"] = "e", ["image"] = "zombie"},
  99.     {["id"] = 3, ["name"] = lang["Привидение"], ["wtype"] = "Призрак",["level"] = 2, ["atds"] = 10,
  100.     ["loot"] = {["exp"] = 4, ["coins"] = 5, ["items"] = {}}, ["vresp"] = 30, ["rtype"] = "e", ["image"] = "ghost"},
  101.     {["id"] = 4, ["name"] = lang["Зеленый слизень"], ["wtype"] = "Слизень", ["level"] = 2, ["atds"] = 10,
  102.     ["loot"] = {["exp"] = 4, ["coins"] = 4, ["items"] = {}}, ["vresp"] = 30, ["rtype"] = "e", ["image"] = "greenslug"},
  103.     {["id"] = 5, ["name"] = lang["Василий"], ["wtype"] = "Житель", ["level"] = 0,  
  104.     ["vresp"] = 0, ["image"] = "vil1", ["rtype"] = "f",["dialog"] = 1},
  105.     {["id"] = 6, ["name"] = lang["Зеленый куст"], ["wtype"] = "Дерево", ["level"] = 3, ["atds"] = 10,
  106.     ["loot"] = {["exp"] = 5, ["coins"] = 6, ["items"] = {}}, ["vresp"] = 30, ["rtype"] = "e", ["image"] = "bush"},
  107. }
  108.  
  109. local gameItemData = {
  110.     {["name"] = "Медный слиток", ["type"] = "item", ["subtype"] = "none", ["description"] = "Может быть использован для крафта",
  111.     ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 5, ["icon"] = 1, ["ncolor"] = 0xFFFFFF},
  112.     {["name"] = "Железный слиток", ["type"] = "item", ["subtype"] = "none", ["description"] = "Может быть использован для крафта",
  113.     ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 5, ["icon"] = 2, ["ncolor"] = 0xFFFFFF},
  114.     {["name"] = "Шлем новичка", ["level"] = 1, ["type"] = "armor", ["subtype"] = "helmet", ["reqlvl"] = 1, ["description"] = "",
  115.     ["props"] = {["hp+"] = 0, ["phisdef"] = 28, ["magdef"] = 0}, ["stackable"] = false, ["cost"] = 5, ["icon"] = 5, ["ncolor"] = 0xFFFFFF},
  116.     {["name"] = "Доспех новичка", ["level"] = 1, ["type"] = "armor", ["subtype"] = "bodywear", ["reqlvl"] = 1, ["description"] = "",
  117.     ["props"] = {["hp+"] = 0, ["phisdef"] = 27, ["magdef"] = 16}, ["stackable"] = false, ["cost"] = 5, ["icon"] = 3, ["ncolor"] = 0xFFFFFF},
  118.     {["name"] = "Брюки новичка", ["level"] = 1, ["type"] = "armor", ["subtype"] = "pants", ["reqlvl"] = 1, ["description"] = "",
  119.     ["props"] = {["hp+"] = 0, ["phisdef"] = 25, ["magdef"] = 15}, ["stackable"] = false, ["cost"] = 5, ["icon"] = 4, ["ncolor"] = 0xFFFFFF},
  120.     {["name"] = "Сапоги новичка", ["level"] = 1, ["type"] = "armor", ["subtype"] = "footwear", ["reqlvl"] = 1, ["description"] = "",
  121.     ["props"] = {["hp+"] = 0, ["phisdef"] = 22, ["magdef"] = 13}, ["stackable"] = false, ["cost"] = 5, ["icon"] = 6, ["ncolor"] = 0xFFFFFF},
  122.     {["name"] = "Деревянный меч", ["level"] = 1, ["type"] = "weapon", ["subtype"] = "sword", ["reqlvl"] = 1, ["description"] = "",
  123.     ["props"] = {["atds"] = 10, ["hp+"] = 0, ["phisat"] = 1, ["magat"] = 0}, ["stackable"] = false, ["cost"] = 1, ["icon"] = 7, ["ncolor"] = 0xFFFF00},
  124.     {["name"] = "Ожерелье из кости", ["level"] = 1, ["type"] = "armor", ["subtype"] = "pendant", ["reqlvl"] = 1, ["description"] = "",
  125.     ["props"] = {["hp+"] = 0, ["phisdef"] = 8, ["magdef"] = 14}, ["stackable"] = false, ["cost"] = 6, ["icon"] = 8, ["ncolor"] = 0xFFFFFF},
  126.     {["name"] = "Малое исцеляющее зелье", ["type"] = "potion", ["subtype"] = "health", ["reqlvl"] = 1, ["description"] = "",
  127.     ["props"] = 1, ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 1, ["icon"] = 9, ["ncolor"] = 0xFFFFFF},
  128.     {["name"] = "Малое бодрящее зелье", ["type"] = "potion", ["subtype"] = "mana", ["reqlvl"] = 1, ["description"] = "",
  129.     ["props"] = 1, ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 1, ["icon"] = 10, ["ncolor"] = 0xFFFFFF},
  130.     {["name"] = "Среднее исцеляющее зелье", ["type"] = "potion", ["subtype"] = "health", ["reqlvl"] = 5, ["description"] = "",
  131.     ["props"] = 1, ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 2, ["icon"] = 11, ["ncolor"] = 0xFFFFFF},
  132.     {["name"] = "Среднее бодрящее зелье", ["type"] = "potion", ["subtype"] = "mana", ["reqlvl"] = 5, ["description"] = "",
  133.     ["props"] = 1, ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 2, ["icon"] = 12, ["ncolor"] = 0xFFFFFF},
  134.     {["name"] = "Большое исцеляющее зелье", ["type"] = "potion", ["subtype"] = "health", ["reqlvl"] = 10, ["description"] = "",
  135.     ["props"] = 1, ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 3, ["icon"] = 13, ["ncolor"] = 0xFFFFFF},
  136.     {["name"] = "Большое бодрящее зелье", ["type"] = "potion", ["subtype"] = "mana", ["reqlvl"] = 10, ["description"] = "",
  137.     ["props"] = 1, ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 3, ["icon"] = 14, ["ncolor"] = 0xFFFFFF},
  138.     {["name"] = "Концентрированное исцеляющее зелье", ["type"] = "potion", ["subtype"] = "health", ["reqlvl"] = 15, ["description"] = "",
  139.     ["props"] = 1, ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 4, ["icon"] = 15, ["ncolor"] = 0xFFFFFF},
  140.     {["name"] = "Концентрированное бодрящее зелье", ["type"] = "potion", ["subtype"] = "mana", ["reqlvl"] = 15, ["description"] = "",
  141.     ["props"] = 1, ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 4, ["icon"] = 16, ["ncolor"] = 0xFFFFFF},
  142. }
  143.  
  144. local gameSkillsData = {
  145.     {["name"] = "Phisical Attack", ["distance"] = vAttackDistance, ["type"] = "attack", ["typedm"] = "p", ["level"] = 1, ["reloading"] = 1,
  146.     ["mindamage"] = {0,0,0,0,0,0,0}, ["maxdamage"] = {1,1,1,1,1,1,1}, ["manacost"] = {0,0,0,0,0,0,0}, ["eff"] = {0,0,0,0,0,0,0}},
  147.     {["name"] = "Deep Cut", ["distance"] = vAttackDistance+1, ["type"] = "attack", ["typedm"] = "p", ["level"] = 1, ["reloading"] = 3,
  148.     ["mindamage"] = {2,3,4,6,9,14,19}, ["maxdamage"] = {4,7,10,13,16,20,28}, ["manacost"] = {5,6,7,9,11,13,15}, ["eff"] = {0,0,0,0,0,0,0}},
  149.  
  150. }
  151.  
  152. local gameQuestsData = {
  153.     {["name"] = "Задание1", ["type"] = "k", ["targ"] = 2, ["num"] = 1, ["minlvl"] = 1, ["maxlvl"] = 100,
  154.     ["comp"] = 0, ["qreward"] = {["coins"] = 10, ["xp"] = 12, ["item"] = {9,5}}},
  155. }
  156.  
  157. local cGUData = {} -- массив со всеми персонажами
  158.  
  159. local cUskills = {{1,0,1},{2,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1}}
  160. local cUquests = {}
  161.  
  162. local inventory = {
  163. ["weared"] = {
  164. ["helmet"] = 0,
  165. ["bodywear"] = 0,
  166. ["pants"] = 0,
  167. ["weapon"] = 0,
  168. ["footwear"] = 0,
  169. ["pendant"] = 0},
  170. ["bag"] = {}
  171. }
  172. for f = 1, 20 do
  173. inventory["bag"][f] = {}
  174. inventory["bag"][f][1] = 0
  175. inventory["bag"][f][2] = 0
  176. end
  177.  
  178.  
  179. local cpath = "/home/testgame/"
  180. local cGlobalx, cBackgroundPos = 1, 1
  181. local cTarget = 0
  182. local paused = false
  183. local cWindowTrd = nil
  184. local showTargetInfo = false
  185.  
  186. local ingame = true
  187. local cmp, mmp, cxp, mxp = 0, 0, 0, 0
  188. local cDialog
  189.  
  190. local survivability = 1
  191. local strength = 1
  192. local intelligence = 1
  193.  
  194. local function clicked(x,y,x1,y1,x2,y2)
  195.  if x >= x1 and x <= x2 and y >= y1 and y <= y2 then
  196.  return true
  197.  end    
  198.  return false
  199. end
  200.  
  201. local consDataR = {}
  202.  
  203. local function booleanToString(b)
  204.  if b then
  205.  return "true"
  206.  else
  207.  return "false"
  208.  end
  209. end
  210.  
  211. local console={}
  212. function console.debug(...)
  213. local args = table.pack(...)
  214. local msg, adt = "", ""
  215.  if #args > 0 then
  216.   for f = 1, #args do
  217.    if type(args[f]) == "string" then
  218.    adt = args[f]
  219.    elseif type(args[f]) == "number" then
  220.    adt = tostring(args[f])
  221.    elseif type(args[f]) == "boolean" then
  222.    adt = booleanToString(args[f])
  223.    else
  224.    adt = type(args[f])
  225.    end
  226.   msg = msg..adt.." "
  227.   end
  228.  end
  229. table.insert(consDataR,msg)
  230. end
  231.  
  232. function console.wError(e)
  233. if type(e) == "string" then table.insert(consDataR,"!/"..e) end
  234. end
  235.  
  236. local cnsCommands = {
  237.     ["clear"] = function() consDataR = {} end
  238. }
  239.  
  240. function console.execCommand(com)
  241.  if type(com) ~= "string" then
  242.  console.wError("Значение команды невозможно")
  243.  else
  244.   if cnsCommands[com] then
  245.   cnsCommands[com]()
  246.   end
  247.  end
  248. end
  249.  
  250. console.debug("Загрузка ("..unicode.sub(os.date(), 1, -4)..")")
  251.  
  252. local function addItem(itemid,num)
  253. local vparInvEx = 0
  254.  for f = 1, #inventory["bag"] do
  255.   if inventory["bag"][f][1] == 0 and inventory["bag"][f][1] ~= itemid and not gameItemData[itemid]["stackable"] then
  256.   inventory["bag"][f][1] = itemid
  257.   inventory["bag"][f][2] = num
  258.   break
  259.   end
  260.  end
  261.  if gameItemData[itemid]["stackable"] and vparInvEx == 0 then
  262.   for i = 1, #inventory["bag"] do
  263.    if inventory["bag"][i][1] == itemid then
  264.    inventory["bag"][i][2] = inventory["bag"][i][2] + num
  265.    vparInvEx = 1
  266.    break
  267.    end
  268.   end
  269.   if vparInvEx == 0 then
  270.    for i = 1, #inventory["bag"] do
  271.     if inventory["bag"][i][1] == 0 then
  272.     inventory["bag"][i][1] = itemid
  273.     inventory["bag"][i][2] = num   
  274.     break
  275.     end
  276.    end
  277.   end
  278.  end
  279.  for f = 1, #inventory["bag"] do
  280.   if inventory["bag"][f][1] ~= 0 and not gameItemData[inventory["bag"][f][1]]["stackable"] and inventory["bag"][f][2] > 1 then
  281.   inventory["bag"][f][2] = 1
  282.   end
  283.  end
  284. end
  285.  
  286. addItem(1,2)
  287. addItem(2,3)
  288. addItem(3,1)
  289. addItem(4,1)
  290. addItem(5,1)
  291. addItem(6,1)
  292. addItem(7,1)
  293. addItem(8,1)
  294.  
  295. local function addUnit(id,x,y)
  296. cGUData[#cGUData+1] = {}
  297. cGUData[#cGUData]["sx"] = x
  298. cGUData[#cGUData]["mx"] = x
  299. cGUData[#cGUData]["x"] = x
  300. cGUData[#cGUData]["y"] = y
  301. cGUData[#cGUData]["id"] = gameUnitData[id]["id"]
  302. cGUData[#cGUData]["name"] = gameUnitData[id]["name"]
  303. cGUData[#cGUData]["wtype"] = gameUnitData[id]["wtype"]
  304. cGUData[#cGUData]["level"] = gameUnitData[id]["level"]
  305. cGUData[#cGUData]["spos"] = "r"
  306. cGUData[#cGUData]["image"] = gameUnitData[id]["image"]
  307.  if cGUData[#cGUData]["image"] ~= nil then
  308.  local cUSprite = image.load(cpath.."sprpic/"..mlSprites[gameUnitData[id]["image"]]..".pic")
  309.  cGUData[#cGUData]["width"] = cUSprite.width
  310.  cGUData[#cGUData]["height"] = cUSprite.height
  311.  cUSprite = nil
  312.  end
  313. cGUData[#cGUData]["mhp"] = math.ceil(12+(gameUnitData[id]["level"]-1)*3*gameUnitData[id]["level"]*0.75)
  314. cGUData[#cGUData]["chp"] = cGUData[#cGUData]["mhp"]
  315. mxp = math.ceil(gameUnitData[id]["level"]*5+(gameUnitData[id]["level"]*21.7))
  316. mmp = math.ceil(gameUnitData[id]["level"]*5+(gameUnitData[id]["level"]*11.46))
  317. cmp = mmp
  318. cGUData[#cGUData]["phisatck"] = math.ceil(0.35+cGUData[#cGUData]["level"]*0.8)
  319. cGUData[#cGUData]["magatck"] = math.ceil(0.75+cGUData[#cGUData]["level"]*0.3)
  320. cGUData[#cGUData]["phisdef"] = math.ceil(11.5+cGUData[#cGUData]["level"]*5.4)
  321. cGUData[#cGUData]["magdef"] = math.ceil(9+gameUnitData[id]["level"]*4.1)
  322. cGUData[#cGUData]["resptime"] = 0
  323. cGUData[#cGUData]["living"] = true
  324. cGUData[#cGUData]["rtype"] = gameUnitData[id]["rtype"]
  325. cGUData[#cGUData]["attackdistance"] = gameUnitData[id]["atds"]
  326. cGUData[#cGUData]["attplayer"] = false
  327. cGUData[#cGUData]["agrtime"] = 0
  328.  if gameUnitData[id]["rtype"] == "f" then
  329.  cGUData[#cGUData]["dialog"] = gameUnitData[id]["dialog"]
  330.  end
  331. cGUData[#cGUData]["effects"] = {}
  332.  for f = 1, 8 do
  333.  cGUData[#cGUData]["effects"][f] = {}
  334.  cGUData[#cGUData]["effects"][f][1] = 0
  335.  cGUData[#cGUData]["effects"][f][2] = 0
  336.  end
  337.  if gameUnitData[id]["rtype"] == "m" then
  338.  cGUData[#cGUData]["mhp"] = gameUnitData[id]["mhp"]
  339.  cGUData[#cGUData]["chp"] = cGUData[#cGUData]["mhp"]
  340.  end
  341. console.debug("Spawn new unit","id:"..tostring(gameUnitData[id]["id"]),"name:"..gameUnitData[id]["name"],"x:"..tostring(x),"y:"..tostring(y),"Gid:"..#cGUData)
  342. end
  343.  
  344. addUnit(1,1,1)
  345. addUnit(5,-25,1)
  346. addUnit(2,35,1)
  347. addUnit(3,75,2)
  348. addUnit(4,115,1)
  349. addUnit(6,135,1)
  350.  
  351. local function playerRefreshVar()
  352. vSur,vStr,vInt,vHpi,vPdm,vMdm,vPdf,vMdf = 0, 0, 0, 0, 0, 0, 0, 0
  353. local wItemTypes = {
  354.     "helmet",
  355.     "bodywear",
  356.     "pants",
  357.     "footwear",
  358.     "pendant",
  359. }
  360. --
  361.  for f = 1, 5 do
  362.   if inventory["weared"][wItemTypes[f]] ~= 0 then
  363.    if gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["sur+"] ~= nil then
  364.    vSur = vSur + gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["sur+"]
  365.    end  
  366.    if gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["str+"] ~= nil then
  367.    vStr = vStr + gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["str+"]
  368.    end
  369.    if gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["int+"] ~= nil then
  370.    vInt = vInt + gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["int+"]
  371.    end  
  372.    if gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["hp+"] ~= nil then
  373.    vHpi = vHpi + gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["hp+"]
  374.    end
  375.   vPdf = cGUData[1]["phisdef"] + gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["phisdef"]
  376.   vMdf = cGUData[1]["magdef"] + gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["magdef"]
  377.   end
  378.  end
  379.  --
  380.  if inventory["weared"]["weapon"] ~= 0 then
  381.   if gameItemData[inventory["weared"]["weapon"]]["props"]["sur+"] ~= nil then
  382.   vSur = vSur + gameItemData[inventory["weared"]["weapon"]]["props"]["sur+"]
  383.   end  
  384.   if gameItemData[inventory["weared"]["weapon"]]["props"]["str+"] ~= nil then
  385.   vStr = vStr + gameItemData[inventory["weared"]["weapon"]]["props"]["str+"]
  386.   end
  387.   if gameItemData[inventory["weared"]["weapon"]]["props"]["int+"] ~= nil then
  388.   vInt = vInt + gameItemData[inventory["weared"]["weapon"]]["props"]["int+"]
  389.   end  
  390.   if gameItemData[inventory["weared"]["weapon"]]["props"]["hp+"] ~= nil then
  391.   vHpi = vHpi + gameItemData[inventory["weared"]["weapon"]]["props"]["hp+"]
  392.   end  
  393.  vPdm = cGUData[1]["phisatck"] + gameItemData[inventory["weared"]["weapon"]]["props"]["phisat"]
  394.  vMdm = cGUData[1]["magatck"] + gameItemData[inventory["weared"]["weapon"]]["props"]["magat"]
  395.  vAttackDistance = gameItemData[inventory["weared"]["weapon"]]["props"]["atds"] or 10
  396.  end
  397. cGUData[1]["mhp"] = math.ceil(4+(survivability+vSur)*11+(cGUData[1]["level"]-1)*7)+vHpi
  398. mmp = math.ceil(4+(intelligence+vInt)*6+(cGUData[1]["level"]-1)*4)
  399. mxp = math.ceil(28+(cGUData[1]["level"]-1)*34.7)
  400. cGUData[1]["phisatck"] = math.floor(1+(strength+vStr-1)*0.9+(cGUData[1]["level"]-1)*0.0025)+vPdm
  401. cGUData[1]["magatck"] = math.floor(1+(intelligence+vInt-1)*0.25+(cGUData[1]["level"]-1)*0.00015)+vMdm
  402. cGUData[1]["phisdef"] = math.ceil(5+(strength+vStr-1)*29.4+(cGUData[1]["level"]-1)*4.85)+vPdf
  403. cGUData[1]["magdef"] = math.ceil(5+(intelligence+vInt-1)*22.8+(cGUData[1]["level"]-1)*1.5)+vMdf
  404. end
  405.  
  406. local function addXP(value)
  407.  if mxp-cxp >= value then
  408.  cxp = cxp + value
  409.  else
  410.  value = value - (mxp - cxp)
  411.  cGUData[1]["level"] = cGUData[1]["level"] + 1
  412.  cxp = value
  413.  playerRefreshVar()
  414.  cGUData[1]["chp"] = cGUData[1]["mhp"]
  415.  cmp = mmp
  416.  end
  417. end
  418.  
  419. local function getQuest(quest)
  420. table.insert(cUquests,{quest,0,false})
  421. end
  422.  
  423. local function pbar(x,y,size,percent,color1,color2, text, textcolor)
  424. percent = 100 - percent
  425. local fill = {}
  426.  for f = 1, size do
  427.  table.insert(fill,1)
  428.  end
  429.  for f = 1, size do
  430.   if 100/size*f <= percent then
  431.   fill[size-f+1] = 0
  432.   end
  433.  end
  434. local color0 = 0x000000
  435.  for f = 1, size do
  436.   if fill[f] == 1 then color0 = color1
  437.   else color0 = color2
  438.   end
  439.  buffer.set(x+f-1,y,color0, 0xFFFFFF, " ")
  440.  buffer.text(x, y, textcolor, text)
  441.  end
  442. end
  443.  
  444. local function drawCDataUnit()
  445.  for f = 2, #cGUData do
  446.   if cGUData[f]["living"] then
  447.    if cGUData[f]["spos"] == "r" and cGUData[f]["x"]+75-cGlobalx >= -10 and cGUData[f]["x"]+75-cGlobalx <= 160 then
  448.    buffer.image(cGUData[f]["x"]+75-cGlobalx,49-cGUData[f]["y"]-cGUData[f]["height"], image.load(cpath.."sprpic/"..mlSprites[cGUData[f]["image"]]..".pic"))
  449.    elseif cGUData[f]["spos"] == "l" then
  450.    buffer.image(cGUData[f]["x"]+75-cGlobalx,49-cGUData[f]["y"]-cGUData[f]["height"], image.flipHorizontal(image.load(cpath.."sprpic/"..mlSprites[cGUData[f]["image"]]..".pic")))
  451.    end
  452.    if ( cGUData[f]["rtype"] == "e" or cGUData[f]["rtype"] == "p" or cGUData[f]["rtype"] == "m" ) and cTarget == f then
  453.    pbar(cGUData[f]["x"]+75-cGlobalx, 49-cGUData[f]["y"]-2-cGUData[f]["height"],8,math.ceil(cGUData[f]["chp"])*100/cGUData[f]["mhp"],0xFF0000,0x444444," ",0xFFFFFF)
  454.    buffer.text(cGUData[f]["x"]+75-cGlobalx+math.max(math.floor((8 / 2) - (unicode.len(tostring(math.ceil(cGUData[f]["chp"]))) / 2)), 0),49-cGUData[f]["y"]-2-cGUData[f]["height"],0xFFFFFF,tostring(math.ceil(cGUData[f]["chp"])))
  455.    elseif cGUData[f]["roletype"] == "f" then
  456.    -- text npc
  457.    elseif cGUData[f]["rtype"] == "r" and cTarget ~= 0 and cTarget == f and vpickwait then
  458.    local vpercentr = math.ceil(vcpcingup*100/vpcingupm)
  459.    pbar(cGUData[f]["x"]+75-cGlobalx, 49-cGUData[f]["y"]-2,8,vpercentr,0x00FF00,0x444444,vpercentr.."% ",0xFFFFFF)
  460.    end
  461.   end
  462.  end
  463. end
  464.  
  465. local function getDistance(from,x)
  466. local dist = 0
  467. local x1, x2 = cGUData[from]["x"], x
  468. if x1 < x2 then dist = x2-x1
  469. elseif x1 > x2 then dist = x1-x2
  470. end
  471. return dist
  472. end
  473.  
  474. local function getDistanceToId(from,to)
  475. local dist = 0
  476. local x1, x2 = cGUData[from]["x"], cGUData[to]["x"]
  477. if x1 < x2 then dist = x2-x1-cGUData[from]["width"]
  478. elseif x1 > x2+cGUData[to]["width"] then dist = x1-x2-cGUData[to]["width"]
  479. end
  480. return dist
  481. end
  482.  
  483. local function target(x,y)
  484. if cTarget ~= 1 and not showTargetInfo then
  485. cTarget = 0
  486. end
  487.  for f = 2, #cGUData do
  488.   if clicked(x, y, cGUData[f]["x"]+75-cGlobalx, 49-cGUData[f]["y"]-2-cGUData[f]["height"], cGUData[f]["x"]+75-cGlobalx+cGUData[f]["width"], 49-cGUData[f]["y"]) then
  489.    if cGUData[f]["living"] then
  490.    cTarget = f
  491.    console.debug("Выбрать цель","id:",tostring(cTarget),cGUData[cTarget]["name"])
  492.    end
  493.   end
  494.  end
  495. end
  496.  
  497. local fPauselist = {
  498. "Продолжить игру",
  499. "Инвентарь",
  500. "Умения персонажа",
  501. "Характеристика",
  502. "Текущие задания",
  503. "Выйти из игры"
  504. }
  505.  
  506. local function fPause()
  507. buffer.square(1, 1, 30, 50, 0x9D9D9D, 0xFFFFFF, " ")
  508. buffer.text(13,2,0xFFFFFF,"Пауза")
  509.  for f = 1, #fPauselist do
  510.  buffer.square(1, 2+f*2, 30, 1, 0x838383, 0xFFFFFF, " ")
  511.  buffer.text(math.max(math.floor((30/2)-(unicode.len(fPauselist[f])/2)),0),2+f*2,0xFFFFFF,fPauselist[f])
  512.  end
  513. end
  514.  
  515. local function playerCInfoBar(x,y)
  516. buffer.square(x, y, 25, 5, 0x8C8C8C, 0xFFFFFF, " ")
  517. local percent1 = math.ceil(cGUData[1]["chp"]*100/cGUData[1]["mhp"])
  518. local percent2 = math.ceil(cmp*100/mmp)
  519. local percent3 = math.ceil(cxp*100/mxp)
  520. buffer.text(x+1, y, 0xFFFFFF, "Уровень "..cGUData[1]["level"])
  521. pbar(x,y+1,25,percent1,0xFF0000,0x5B5B5B," "..math.ceil(cGUData[1]["chp"]).."/"..math.ceil(cGUData[1]["mhp"]).." ", 0xFFFFFF)
  522. pbar(x,y+2,25,percent2,0x0000FF,0x5B5B5B," "..math.ceil(cmp).."/"..math.ceil(mmp).." ", 0xFFFFFF)
  523. pbar(x,y+3,25,percent3,0xFFFF00,0x5B5B5B," "..percent3.."% ", 0x333333)
  524. end
  525.  
  526. local function sTargetInfo(x,y)
  527. local sTInfoArray1 = {
  528. cGUData[cTarget]["name"],
  529. "Тип: "..unicode.sub(cGUData[cTarget]["wtype"],1,22),
  530. "Respawn: "..tostring(gameUnitData[cGUData[cTarget]["id"]]["vresp"]).." секунд",
  531. "ID: "..tostring(cGUData[cTarget]["id"]),
  532. }
  533.  
  534. local sTInfoArray2 = {
  535. "Физ.атака: "..tostring(cGUData[cTarget]["phisatck"]),
  536. "Маг.атака: "..tostring(cGUData[cTarget]["magatck"]),
  537. "Физ.защита: "..tostring(cGUData[cTarget]["phisdef"]),
  538. "Маг.защита: "..tostring(cGUData[cTarget]["magdef"]),
  539. }
  540.  
  541. buffer.square(x, y, 25, 9, 0xABABAB, 0xFFFFFF, " ")
  542.  for f = 1, #sTInfoArray1 do
  543.  buffer.text(x+1,y+f-1,0xFFFFFF,tostring(sTInfoArray1[f]))
  544.  end
  545.  if cGUData[cTarget]["rtype"] ~= "f" then
  546.   for f = 1, #sTInfoArray2 do
  547.   buffer.text(x+1,y+f-1+#sTInfoArray1,0xFFFFFF,tostring(sTInfoArray2[f]))
  548.   end
  549.  end
  550. end
  551.  
  552. local function targetCInfoBar(x,y)
  553. buffer.square(x, y, 35, 5, 0x9B9B9B, 0xFFFFFF, " ")
  554. if cGUData[cTarget]["rtype"] == "e" or cGUData[cTarget]["rtype"] == "p" or cGUData[cTarget]["rtype"] == "m" then
  555. local chp, mhp = cGUData[cTarget]["chp"], cGUData[cTarget]["mhp"]
  556. local pbtext, lbtext = tostring(math.ceil(chp)).."/"..tostring(math.ceil(mhp)), "["..tostring(cGUData[cTarget]["level"]).."] "..cGUData[cTarget]["name"]
  557. local percent = math.ceil(chp*100/mhp)
  558. pbar(x,y+1,35,percent,0xFF0000,0x5B5B5B," ", 0xFFFFFF)
  559. pbar(x,y+2,35,percent,0xFF0000,0x5B5B5B," ", 0xFFFFFF)
  560. buffer.text(x + (math.max(math.floor((35 / 2) - (unicode.len(pbtext) / 2)), 0)),y+1,0xFFFFFF,pbtext)
  561. buffer.text(x + (math.max(math.floor((35 / 2) - (unicode.len(lbtext) / 2)), 0)), y+2, 0xFFFFFF, lbtext)
  562. elseif cGUData[cTarget]["rtype"] == "f" then
  563. local pntext, lbtext = cGUData[cTarget]["wtype"], cGUData[cTarget]["name"]
  564. buffer.text(x,y,0x727272,"НИП")
  565. buffer.text(x + (math.max(math.floor((35 / 2) - (unicode.len(lbtext) / 2)), 0)), y+1, 0xFFFFFF, lbtext)
  566. buffer.text(x + (math.max(math.floor((35 / 2) - (unicode.len(pntext) / 2)), 0)), y+2, 0x727272, pntext)
  567. end
  568. buffer.text(x+1,y+4,0xFFFFFF,"О персонаже")
  569.  if showTargetInfo then
  570.  sTargetInfo(x+1,y+5)
  571.  end
  572. end
  573.  
  574. local function fSkillBar(x,y)
  575. buffer.square(x, y, 30, 5, 0x9B9B9B, 0xFFFFFF, " ")
  576. local sarray = {
  577. {c = 0x614251, t = "/2"},
  578. {c = 0x0000FF, t = "*3"},
  579. {c = 0x008500, t = "@4"},
  580. {c = 0x8600A0, t = "&5"},
  581. {c = 0xEE0000, t = "!6"},
  582. }
  583.  for f = 1, #sarray do
  584.  buffer.square(x+4+(f*5-5), y+1, 2, 1, sarray[f].c, 0xFFFFFF, " ")
  585.  buffer.text(x+4+(f*5-5), y+1, 0xFFFFFF, sarray[f].t)
  586.  buffer.text(x+4+(f*5-5), y+2, 0xFFFFFF, tostring(cUskills[f+1][2]))
  587.  end
  588. end
  589.  
  590. local function drawDialog(x,y)
  591. local sColor
  592. local massiv = cDialog
  593.  for f = 1, #massiv do
  594.   if massiv[#massiv-f+1]["action"] == "getquest" and gameQuestsData[cDialog[#massiv-f+1]["do"]]["comp"] == true then
  595.   table.remove(massiv[#massiv-f+1])
  596.   end
  597.  end
  598. buffer.square(x, y, 50, 24, 0x9B9B9B, 0xFFFFFF, " ")
  599. buffer.square(x, y, 50, 1, 0x606060, 0xFFFFFF, " ")
  600. buffer.square(x+1, y+1, 48, 12, 0x7A7A7A, 0xFFFFFF, " ")
  601. buffer.square(x+1, y+14, 48, 9, 0x7A7A7A, 0xFFFFFF, " ")
  602. buffer.text(x+49,y,0xFFFFFF,"X")
  603. local text1 = cGUData[cTarget]["name"]
  604. buffer.text(x+(math.max(math.floor((50 / 2) - (unicode.len(text1) / 2)), 0)), y, 0xFFFFFF, text1)
  605.  for f = 1, math.ceil(#cDialog["text"]/46) do
  606.  buffer.text(x+2,y+1+f,0xFFFFFF,unicode.sub(cDialog["text"],1+f*46-46,f*46))
  607.  end
  608.  for f = 1, #massiv do
  609.  sColor = 0xFFFFFF
  610.  if massiv[f]["action"] == getquest and gameQuestsData[massiv[f]["do"]]["comp"] == false then sColor = 0x555555 end
  611.  buffer.text(x+2,y+14+f,sColor,massiv[f]["text"])
  612.  end
  613. end
  614.  
  615. local function itemSubtypeToRus(subtype)
  616. local massiv = {
  617. ["helmet"] = "Шлем",
  618. ["bodywear"] = "Броня",
  619. ["pants"] = "Штаны",
  620. ["footwear"] = "Сапоги",
  621. ["pendant"] = "Кулон",
  622. ["sword"] = "Меч",
  623. }
  624. return massiv[subtype]
  625. end
  626.  
  627. local function getItemInfoWColor(id)
  628. local info = {}
  629. local function giiwcAdd(t,c) table.insert(info,{tostring(t),c}) end
  630. local itemtype = gameItemData[id]["type"]
  631. giiwcAdd(gameItemData[id]["name"], gameItemData[id]["ncolor"])
  632.  if itemtype == "armor" or itemtype == "weapon" then
  633.  giiwcAdd(itemSubtypeToRus(gameItemData[id]["subtype"]), 0xBCBCBC)
  634.  giiwcAdd("Уровень "..tostring(gameItemData[id]["level"]), 0xFFFFFF)
  635.  end
  636.  if itemtype == "armor" then
  637.  if gameItemData[id]["props"]["phisdef"] ~= 0 then giiwcAdd("Защита +"..tostring(gameItemData[id]["props"]["phisdef"]), 0xFFFFFF) end
  638.  if gameItemData[id]["props"]["magdef"] ~= 0 then giiwcAdd("Магическая защита +"..tostring(gameItemData[id]["props"]["magdef"]), 0xFFFFFF) end
  639.  elseif itemtype == "weapon" then
  640.  if gameItemData[id]["props"]["phisat"] ~= 0 then giiwcAdd("Физическая атака "..tostring(gameItemData[id]["props"]["phisat"]), 0xFFFFFF) end
  641.  if gameItemData[id]["props"]["magat"] ~= 0 then giiwcAdd("Магическая атака "..tostring(gameItemData[id]["props"]["magat"]), 0xFFFFFF) end
  642.  end
  643.  if itemtype == "armor" or itemtype == "weapon" or itemtype == "potion" then
  644.   if gameItemData[id]["reqlvl"] > cGUData[1]["level"] then
  645.   giiwcAdd("Требуемый уровень: "..gameItemData[id]["reqlvl"], 0xFF0000)
  646.   else
  647.   giiwcAdd("Требуемый уровень: "..gameItemData[id]["reqlvl"], 0xFFFFFF)
  648.   end
  649.  end
  650.  if gameItemData[id]["description"] ~= "" then
  651.   for f = 1, math.ceil(unicode.len(gameItemData[id]["description"])/35) do
  652.   giiwcAdd(unicode.sub(gameItemData[id]["description"],1+f*35-35,f*35), 0xBCBCBC)
  653.   end
  654.  end
  655. giiwcAdd("Цена "..tostring(gameItemData[id]["cost"]), 0xFFFFFF)
  656. return info
  657. end
  658.  
  659. local invcTargetItem, showItemData = 0, false
  660. local invIdx, invIdy = 1, 1
  661.  
  662. local function drawInventory(x,y)
  663. buffer.square(x, y, 160, 50, 0x9B9B9B, 0xFFFFFF, " ")
  664. buffer.square(x, y, 160, 1, 0x525252, 0xFFFFFF, " ")
  665. buffer.square(x, y+49, 160, 1, 0x525252, 0xFFFFFF, " ")
  666. buffer.square(x, y+1, 105, 45, 0x767676, 0xFFFFFF, " ")
  667.  for f = 1, 5 do
  668.  buffer.square(x, y+1+(f*11-11), 105, 1, 0x4A4A4A, 0xFFFFFF, " ")
  669.  end
  670.   for f = 1, 6 do
  671.  buffer.square(x+(f*21-21), y+1, 1, 45, 0x4A4A4A, 0xFFFFFF, " ")
  672.  end
  673. buffer.image(106, 2, image.load(cpath.."image/gGrid.pic"))
  674. buffer.text(x+75,y,0xFFFFFF,"Инвентарь")
  675. buffer.text(x+152,y,0xFFFFFF,"Закрыть")
  676. local xps, yps
  677.  for f = 1, 4 do
  678.   for i = 1, 5 do
  679.   xps, yps = x+1+i*21-21, y+2+f*11-11
  680.   local formula = (f-1)*5+i
  681.    if inventory["bag"][formula][1] ~= 0 and inventory["bag"][formula][2] ~= 0 then
  682.    buffer.image(xps, yps, image.load(cpath.."itempic/"..aItemIconsSpr[gameItemData[inventory["bag"][formula][1]]["icon"]]..".pic"))
  683.     if inventory["bag"][formula][2] > 1 then
  684.     buffer.square(xps, yps+9, #tostring(inventory["bag"][formula][2]), 1, 0x4A4A4A, 0xFFFFFF, " ")
  685.     buffer.text(xps,yps+9,0xFFFFFF,tostring(inventory["bag"][formula][2]))
  686.     end
  687.    end
  688.   end
  689.  end
  690. local wItemTypes = {
  691.     "helmet",
  692.     "bodywear",
  693.     "pants",
  694.     "weapon",
  695.     "footwear",
  696.     "pendant",
  697. }
  698.  for f = 1, 3 do
  699.   for i = 1, 2 do
  700.    xps, yps = 107+i*21-21, 3+f*11-11
  701.    if inventory["weared"][wItemTypes[(f-1)*2+i]] ~= 0 then
  702.    buffer.image(xps, yps, image.load(cpath.."itempic/"..aItemIconsSpr[gameItemData[inventory["weared"][wItemTypes[(f-1)*2+i]]]["icon"]]..".pic"))
  703.    end
  704.   end
  705.  end
  706.  if showItemData and invcTargetItem ~= 0 then
  707.  local itemInfo = getItemInfoWColor(invcTargetItem)
  708.  local hn, w, h = 0, 0, #itemInfo
  709.   for f = 1, #itemInfo do
  710.   if unicode.len(itemInfo[f][1]) > w then w = unicode.len(itemInfo[f][1]) end
  711.   end
  712.  buffer.square(math.min(invIdx,160-w), math.min(invIdy,50-h), w, h, 0x7E7E7E, 0xFFFFFF, " ")
  713.   for f = 1, #itemInfo do
  714.   buffer.text(math.min(invIdx,160-w),math.min(invIdy+f-1,50-h),itemInfo[f][2],itemInfo[f][1])
  715.   end
  716.  end
  717. end
  718.  
  719. local cCnsScroll = 1
  720.  
  721. local function gameConsole(x,y)
  722. buffer.square(x, y, 60, 35, 0xABABAB, 0xFFFFFF, " ")
  723. buffer.square(x, y, 60, 1, 0x525252, 0xFFFFFF, " ")
  724. buffer.square(x+1, y+1, 58, 31, 0x1A1A1A, 0xFFFFFF, " ")
  725. buffer.square(x+1, y+33, 58, 1, 0x1A1A1A, 0xFFFFFF, " ")
  726. local bColor, bSub
  727. local text1 = "Консоль v0.14"
  728. buffer.text(x+(math.max(math.floor((60 / 2) - (unicode.len(text1) / 2)), 0)), y, 0xFFFFFF, text1)
  729. buffer.text(x+59,y,0xFFFFFF,"X")
  730.  for f = 1, math.min(#consDataR,28) do
  731.   if consDataR[f+(cCnsScroll*4-4)] then
  732.    if unicode.sub(consDataR[f+(cCnsScroll*4-4)],1,2) == "!/" then
  733.    bColor = 0xFF0000
  734.    bSub = 3
  735.    else
  736.    bColor = 0xFFFFFF
  737.    bSub = 1
  738.    end
  739.   buffer.text(x+2,y+2+f,bColor,unicode.sub(consDataR[f+(cCnsScroll*4-4)],bSub,56))
  740.   end
  741.  end
  742. end
  743.  
  744. local targetQuest = 0
  745.  
  746. local function questsList(x,y)
  747. buffer.square(x, y, 100, 25, 0xABABAB, 0xFFFFFF, " ")
  748. buffer.square(x, y, 100, 1, 0x525252, 0xFFFFFF, " ")
  749. buffer.text(x+45,y,0xFFFFFF,"Задания")
  750. buffer.text(x+92,y,0xFFFFFF,"Закрыть")
  751. buffer.square(x+2, y+2, 29, 22, 0x7A7A7A, 0xFFFFFF, " ")
  752. buffer.square(x+32, y+2, 66, 22, 0x7A7A7A, 0xFFFFFF, " ")
  753.  for f = 1, math.min(#cUquests,20) do
  754.  buffer.text(x+3,y+3+f,0xFFFFFF,unicode.sub(gameQuestsData[cUquests[f][1]]["name"],1,28))
  755.  end
  756.  if targetQuest > 0 and cUquests[targetQuest] ~= nil then
  757.  local qInfoList = {
  758.     "Награда:",
  759.     "Монеты "..tostring(gameQuestsData[cUquests[targetQuest][1]]["qreward"]["coins"]),
  760.     "Опыт "..tostring(gameQuestsData[cUquests[targetQuest][1]]["qreward"]["xp"]),
  761.     }
  762.   if gameQuestsData[cUquests[targetQuest][1]]["type"] == "k" then
  763.   table.insert(qInfoList,1,"Уничтожить: "..gameUnitData[gameQuestsData[cUquests[targetQuest][1]]["targ"]]["name"].." ("..cUquests[targetQuest][2].."/"..gameQuestsData[cUquests[targetQuest][1]]["num"]..")")
  764.   end
  765.   if gameQuestsData[cUquests[targetQuest][1]]["qreward"]["item"] ~= nil then
  766.   table.insert(qInfoList,"Предмет: "..unicode.sub(gameItemData[gameQuestsData[cUquests[targetQuest][1]]["qreward"]["item"][1]]["name"],1,45).." ("..tostring(gameQuestsData[cUquests[targetQuest][1]]["qreward"]["item"][2])..")")
  767.   end
  768.  buffer.text(x+33,y+3,0xFFFFFF,unicode.sub(gameQuestsData[cUquests[targetQuest][1]]["name"],1,60))
  769.   for f = 1, #qInfoList do
  770.   buffer.text(x+33,y+3+f,0xFFFFFF,qInfoList[f])
  771.   end
  772.  end
  773. end
  774.  
  775. local function killUnitWithoutAnyLoot(id)
  776. cGUData[id]["living"] = false
  777. cGUData[id]["resptime"] = gameUnitData[cGUData[id]["id"]]["vresp"]
  778. end
  779.  
  780. local function makeDamage(id, damage)
  781.  if cGUData[id]["chp"] > damage then
  782.  cGUData[id]["chp"] = cGUData[id]["chp"] - damage
  783.  console.debug("Урон нанесен персонажу",cGUData[id]["name"],tostring(damage):sub(1,5))
  784.  elseif cGUData[id]["chp"] <= damage then
  785.  cGUData[id]["chp"] = 0
  786.  cGUData[id]["living"] = false
  787.  cGUData[id]["resptime"] = gameUnitData[cGUData[id]["id"]]["vresp"]
  788.  addXP(gameUnitData[cGUData[id]["id"]]["loot"]["exp"])
  789.   for f = 1, #cUquests do
  790.    if gameUnitData[id]["id"] == gameQuestsData[cUquests[f][1]]["targ"] and cUquests[f][3] == false then
  791.     if cUquests[f][2] < gameQuestsData[cUquests[f][1]]["num"] then
  792.     cUquests[f][2] = cUquests[f][2] + 1
  793.     else
  794.     cUquests[f][3] = true
  795.     end
  796.    end
  797.   end
  798.  cGUData[id]["resptime"] = gameUnitData[cGUData[id]["id"]]["vresp"]
  799.  if id == cTarget then cTarget = 0 end
  800.  showTargetInfo = false
  801.  end
  802. end
  803.  
  804. local function useSkill(skill)
  805. playerRefreshVar()
  806. local et = true
  807. local cskill = cUskills[skill][1]
  808. local damage = 0
  809.  if gameSkillsData[cskill]["type"] == "attack" and cGUData[cTarget]["rtype"] ~= "p" and et then
  810.  local physDefRedu = cGUData[cTarget]["phisdef"]/(cGUData[cTarget]["phisdef"]+cGUData[1]["level"]*85)
  811.  local magDefRedu = cGUData[cTarget]["magdef"]/(cGUData[cTarget]["magdef"]+cGUData[1]["level"]*85)
  812.   if gameSkillsData[cskill]["typedm"] == "p" then
  813.   damage = math.max((cGUData[1]["phisatck"]+math.random(gameSkillsData[cskill]["mindamage"][cUskills[skill][3]],gameSkillsData[cskill]["maxdamage"][cUskills[skill][3]]))*(1-physDefRedu),0.1)
  814.   elseif gameSkillsData[cskill]["typedm"] == "m" then
  815.   damage = math.max((cGUData[1]["magatck"]+math.random(gameSkillsData[cskill]["mindamage"][cUskills[skill][3]],gameSkillsData[cskill]["maxdamage"][cUskills[skill][3]]))*(1-magDefRedu),0.1)
  816.   end
  817.   if cmp >= gameSkillsData[cskill]["manacost"][cUskills[skill][3]] and cUskills[skill][2] == 0 and getDistanceToId(1,cTarget) <= gameSkillsData[cskill]["distance"] then
  818.   cmp = cmp - gameSkillsData[cskill]["manacost"][cUskills[skill][3]]
  819.   makeDamage(cTarget, damage)
  820.   cUskills[skill][2] = gameSkillsData[cskill]["reloading"]
  821.   end
  822.  end
  823. end
  824.  
  825. local function dmain()
  826.  if cWindowTrd ~= "inventory" then
  827.  buffer.square(1, 1, 160, 50, 0x00AAFF, 0xFFFFFF, " ")
  828.  buffer.square(1, 48, 160, 3, 0x755340, 0xFFFFFF, " ")
  829.   if cGUData[1]["spos"] == "r" then buffer.image(75, 32, image.load(cpath.."sprpic/player.pic"))
  830.   else buffer.image(75, 32, image.flipHorizontal(image.load(cpath.."sprpic/player.pic")))
  831.   end
  832.  drawCDataUnit()
  833.  playerCInfoBar(1,1)
  834.  if cTarget ~= 0 then targetCInfoBar(60,1) end
  835.  fSkillBar(110,1)
  836.  buffer.text(156,2,0xFFFFFF,"█ █")
  837.  buffer.text(156,3,0xFFFFFF,"█ █")
  838.  end
  839. if cWindowTrd == "pause" then
  840. fPause()
  841. elseif cWindowTrd == "inventory" then
  842. drawInventory(1,1)
  843. elseif cWindowTrd == "dialog" then
  844. drawDialog(12,11)
  845. elseif cWindowTrd == "quests" then
  846. questsList(30,15)
  847. elseif cWindowTrd == "console" then
  848. gameConsole(50,10)
  849. end
  850. buffer.text(1,50,0xFFFFFF,"fps: "..tostring(cfps))
  851. buffer.draw()
  852. end
  853.  
  854. local fPauseMenuAction = {
  855. [1]=function()
  856. cWindowTrd = nil
  857. paused = false
  858. dmain()
  859. end,
  860. [2]=function()
  861. cWindowTrd = "inventory"
  862. dmain()
  863. end,
  864. [3]=function()
  865.  
  866. end,
  867. [4]=function()
  868.  
  869. end,
  870. [5]=function()
  871. cWindowTrd = "quests"
  872. dmain()
  873. end,
  874. [6]=function()
  875. ingame = false
  876. end,
  877. }
  878.  
  879. playerRefreshVar()
  880. cGUData[1]["chp"] = cGUData[1]["mhp"]
  881. cmp = mmp
  882. dmain()
  883.  
  884. local healthReg, manaReg
  885.  
  886. local function functionPS()
  887.  while ingame do
  888.  cfps = gamefps
  889.  gamefps = 0
  890.   if not paused then
  891.   manaReg = math.min(0.1+(cGUData[1]["level"]-1)*0.022,2)
  892.   healthReg = math.min(0.08+(cGUData[1]["level"]-1)*0.014,1)
  893.    for f = 1, #cUskills do
  894.     if cUskills[f][1] > 0 and cUskills[f][2] > 0 then
  895.     cUskills[f][2] = cUskills[f][2] - 1
  896.     end
  897.    end
  898.    if cmp < mmp - manaReg and cGUData[1]["living"] then
  899.    cmp = cmp + manaReg
  900.    end
  901.   end
  902.  os.sleep(1)
  903.  end
  904. end
  905.  
  906. local function scrRef()
  907.  while ingame do
  908.  gamefps = gamefps + 1
  909.  dmain()
  910.  os.sleep(0.025)
  911.  end
  912. end
  913.  
  914. local someVar1
  915.  
  916. local function fInGame()
  917. while ingame do
  918. someVar1 = true
  919. local ev, p2, p3, p4, p5 = event.pull()
  920.  if ev == "key_down" then
  921.   if p4 == 44 then ingame = false end
  922.  
  923.   if p4 == 205 and not paused then -- right
  924.   cGUData[1]["x"] = cGUData[1]["x"] + 2
  925.   cGlobalx = cGlobalx + 2
  926.   cBackgroundPos = cBackgroundPos + 2
  927.   cGUData[1]["spos"] = "r"
  928.   elseif p4 == 203 and not paused then -- left
  929.   cGUData[1]["x"] = cGUData[1]["x"] - 2
  930.   cGlobalx = cGlobalx - 2
  931.   cBackgroundPos = cBackgroundPos - 2
  932.   cGUData[1]["spos"] = "l"
  933.   end
  934.   if cTarget ~= 0 and not paused then
  935.    for f = 1, 6 do
  936.     if p4 == 1+f and cUskills[f][1] ~= 0 then
  937.     useSkill(f)
  938.     end
  939.    end
  940.   end
  941.   if not paused and cTarget ~= 0 and cGUData[cTarget]["rtype"] == "f" and p4 == 18 and getDistanceToId(1,cTarget) <= 40 then
  942.   paused = true
  943.   cWindowTrd = "dialog"
  944.   cDialog = dialogs[cGUData[cTarget]["dialog"]]
  945.   end
  946.   if not paused and p4 == 46 then
  947.   paused = true
  948.   cCnsScroll = math.floor(#consDataR/4)
  949.   cWindowTrd = "console"
  950.   end
  951.  end
  952.  if ev == "touch" then
  953.  if cWindowTrd == nil and cTarget ~= 0 and p5 == 0 and clicked(p3,p4,60,5,71,5) then showTargetInfo = true
  954.  elseif cWindowTrd == nil and cTarget ~= 0 and p5 == 0 and not clicked(p3,p4,60,5,71,5) then showTargetInfo = false end
  955.  if p5 == 0 and clicked(p3,p4,1,1,25,5) and cWindowTrd == nil and not paused then cTarget = 1 end
  956.   if p5 == 0 and clicked(p3,p4,156,2,158,3) and cWindowTrd == nil then
  957.   cWindowTrd = "pause"
  958.   paused = true
  959.   elseif p5 == 0 and clicked(p3,p4,156,2,158,3) and cWindowTrd == "pause" then
  960.   cWindowTrd = nil
  961.   paused = false
  962.   end
  963.   if p5 == 0 and not paused then target(p3,p4) end
  964.   if p5 == 0 and cWindowTrd == "pause" then
  965.    for f = 1, #fPauselist do
  966.     if clicked(p3,p4,1,2+f*2,30,2+f*2) then
  967.     fPauseMenuAction[f]()
  968.     break
  969.     end
  970.    end
  971.   elseif cWindowTrd == "inventory" then
  972.    if clicked(p3,p4,152,1,159,1) then
  973.    cWindowTrd = "pause"
  974.    end
  975.   local fbParam = true
  976.   local nwitemuwr, xps, yps
  977.    for f = 1, 4 do
  978.     for i = 1, 5 do
  979.     xps, yps = 2+i*21-21, 3+f*11-11
  980.     local formula = (f-1)*5+i
  981.      if inventory["bag"][formula][1] ~= 0 and inventory["bag"][formula][2] ~= 0 then
  982.       if clicked(p3,p4,xps,yps,xps+19,yps+9) then
  983.        if p5 == 0 then
  984.        invcTargetItem = inventory["bag"][formula][1]
  985.        showItemData = true
  986.        invIdx, invIdy = p3, p4
  987.        fbParam = false
  988.        break
  989.        else
  990.         if gameItemData[inventory["bag"][formula][1]]["type"] == "armor" then
  991.          if inventory["weared"][gameItemData[inventory["bag"][formula][1]]["subtype"]] == 0 then
  992.          inventory["weared"][gameItemData[inventory["bag"][formula][1]]["subtype"]] = inventory["bag"][formula][1]
  993.          inventory["bag"][formula][1] = 0
  994.          inventory["bag"][formula][2] = 0
  995.          else
  996.          nwitemuwr = inventory["weared"][gameItemData[inventory["bag"][formula][1]]["subtype"]]
  997.          inventory["weared"][gameItemData[inventory["bag"][formula][1]]["subtype"]] = inventory["bag"][formula][1]
  998.          inventory["bag"][formula][1] = 0
  999.          inventory["bag"][formula][2] = 0
  1000.          addItem(nwitemuwr,1)
  1001.          end
  1002.         elseif gameItemData[inventory["bag"][formula][1]]["type"] == "weapon" then
  1003.          if inventory["weared"]["weapon"] == 0 then
  1004.          inventory["weared"]["weapon"] = inventory["bag"][formula][1]
  1005.          inventory["bag"][formula][1] = 0
  1006.          inventory["bag"][formula][2] = 0
  1007.          else
  1008.          nwitemuwr = inventory["weared"]["weapon"]
  1009.          inventory["weared"]["weapon"] = inventory["bag"][formula][1]
  1010.          inventory["bag"][formula][1] = 0
  1011.          inventory["bag"][formula][2] = 0
  1012.          addItem(nwitemuwr,1)
  1013.          end
  1014.         end
  1015.        nwitemuwr = nil
  1016.        break
  1017.        end
  1018.       end
  1019.      end
  1020.     end
  1021.    end
  1022.   local wItemTypes = {
  1023.       "helmet",
  1024.       "bodywear",
  1025.       "pants",
  1026.       "weapon",
  1027.       "footwear",
  1028.       "pendant",
  1029.   }
  1030.    for f = 1, 3 do
  1031.     for i = 1, 2 do
  1032.      xps, yps = 107+i*21-21, 3+f*11-11
  1033.      if inventory["weared"][wItemTypes[(f-1)*2+i]] ~= 0 then
  1034.       if clicked(p3,p4,xps,yps,xps+19,yps+9) then
  1035.        if p5 == 0 then
  1036.        invcTargetItem = inventory["weared"][wItemTypes[(f-1)*2+i]]
  1037.        showItemData = true
  1038.        invIdx, invIdy = p3, p4
  1039.        fbParam = false
  1040.        break
  1041.        else
  1042.        addItem(inventory["weared"][wItemTypes[(f-1)*2+i]],1)
  1043.        inventory["weared"][wItemTypes[(f-1)*2+i]] = 0
  1044.        end
  1045.       end
  1046.      end
  1047.     end
  1048.    end
  1049.    if fbParam then
  1050.    invcTargetItem = 0
  1051.    showItemData = false
  1052.    invIdx, invIdy = 1, 1  
  1053.    end
  1054.   playerRefreshVar()
  1055.   elseif cWindowTrd == "dialog" then
  1056.    for f = 1, #cDialog do
  1057.     if cDialog[f]["action"] == "getquest" and gameQuestsData[cDialog[f]["do"]]["comp"] == true then
  1058.     table.remove(cDialog[f])
  1059.     end
  1060.    end
  1061.    for f = 1, #cDialog do
  1062.     if p5 == 0 and clicked(p3,p4,14,25+f,58,25+f) then
  1063.      if cDialog[f]["action"] == "close" then
  1064.      cWindowTrd = nil
  1065.      cDialog = nil
  1066.      paused = false
  1067.      elseif cDialog[f]["action"] == "dialog" then
  1068.      cDialog = cDialog[f]["do"]
  1069.      elseif cDialog[f]["action"] == "getquest" and gameQuestsData[cDialog[f]["do"]]["comp"] == 0 then
  1070.      getQuest(cDialog[f]["do"])
  1071.      gameQuestsData[cDialog[f]["do"]]["comp"] = false
  1072.      cWindowTrd = nil
  1073.      cDialog = nil
  1074.      paused = false
  1075.      elseif cDialog[f]["action"] == "getquest" and gameQuestsData[cDialog[f]["do"]]["comp"] == false then
  1076.       for t = 1, #cUquests do
  1077.        if cUquests[t][1] == cDialog[f]["do"] and cUquests[t][3] then
  1078.        -- *награда за задание*
  1079.        
  1080.        gameQuestsData[cDialog[f]["do"]]["comp"] = true
  1081.        table.remove(cUquests,t)
  1082.        cWindowTrd = nil
  1083.        cDialog = nil
  1084.        paused = false
  1085.        break
  1086.        end
  1087.       end    
  1088.      end
  1089.     end
  1090.    end
  1091.   elseif cWindowTrd == "quests" then
  1092.    if p5 == 0 and clicked(p3,p4,122,15,129,15) then
  1093.    cWindowTrd = "pause"
  1094.    end
  1095.    for f = 1, #cUquests do
  1096.     if cUquests[f] ~= nil and clicked(p3,p4,32,18+f,60,18+f) then
  1097.     someVar1 = false
  1098.     targetQuest = f
  1099.     break
  1100.     end
  1101.    if not someVar1 then targetQuest = 0 end
  1102.    end
  1103.   elseif cWindowTrd == "console" then
  1104.    if p5 == 0 and clicked(p3,p4,109,10,109,10) then
  1105.    cWindowTrd = nil
  1106.    paused = false
  1107.    end
  1108.   end
  1109.  end
  1110.  if ev == "scroll" then
  1111.   if cWindowTrd == "console" then
  1112.    if clicked(p3,p4,50,10,109,42) and p5 == 1 and cCnsScroll > 1 then
  1113.    cCnsScroll = cCnsScroll - 1
  1114.    elseif clicked(p3,p4,50,10,109,42) and p5 == -1 and math.ceil(cCnsScroll*4) < #consDataR then
  1115.    cCnsScroll = cCnsScroll + 1
  1116.    end
  1117.   end
  1118.  end
  1119. end
  1120. end
  1121.  
  1122. thread.create(fInGame)
  1123. thread.create(scrRef)
  1124. thread.create(functionPS)
  1125.  
  1126. thread.waitForAll()
RAW Paste Data