wirthe16

lua

Jul 15th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 102.04 KB | None | 0 0
  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 term =      require "term"
  10. local event =     require "event"
  11. local image =     require "image"
  12. local thread =    require "thread"
  13. local fs =        require "filesystem"
  14. local unicode =   require "unicode"
  15. local computer =  require "computer"
  16. local keyboard =  require "keyboard"
  17. local component = require "component"
  18. local buffer =    require "doubleBuffering"
  19. local gpu = component.gpu
  20. local mxw, mxh = gpu.maxResolution()
  21. local TextVersion = "Версия 1.2(b) v14"
  22. local pScreenText = "(C) 2016 Wirthe16"
  23. local cScreenStat = "Загрузка..."
  24. local preduprejdenie = ""
  25. local vseNormalno = true
  26. local ESC = "pause"
  27. local LANGUAGE = "russian"
  28.  
  29. gpu.setResolution(mxw,mxh)
  30.  
  31. local startBckgColour = 0x222222
  32.  
  33. local limg = image.load("/games/testgame/image/slg.pic")
  34.  
  35. limg = image.brightness(limg,-10)
  36.  
  37. for f = 1, 6 do
  38. buffer.square(1,1,160,50,startBckgColour,0x000000," ")
  39. buffer.text(2,2,0xA7A7A7,cScreenStat)
  40. limg = image.brightness(limg,2*f)
  41. buffer.image(80-limg.width/2,25-limg.height/2,limg)
  42. buffer.draw()
  43. os.sleep()
  44. end
  45.  
  46. limg = nil
  47.  
  48. if mxw < 160 or mxh < 50 then
  49. vseNormalno = false
  50. preduprejdenie = 'Предупреждение: экран не поддерживает текущее разрешение'
  51. end
  52.  
  53. local dopInfo = {
  54. "Разрешение экрана только 160х50",
  55. "DoubleBuffering lib by IgorTimofeev",
  56. "Image lib by IgorTimofeev",
  57. "Thread lib by Zer0Galaxy",
  58. }
  59.  
  60. local function dmLoading()
  61. buffer.square(1,1,160,50,startBckgColour,0x000000," ")
  62. buffer.text(2,2,0xA7A7A7,cScreenStat)
  63. buffer.text(158-unicode.len(TextVersion),48,0xA1A1A1,TextVersion)
  64. buffer.text(158-unicode.len(pScreenText),49,0xB1B1B1,pScreenText)
  65.  for f = 1, #dopInfo do
  66.  buffer.text(2,48-#dopInfo+f,0xA7A7A7,dopInfo[f])
  67.  end
  68.  if not vseNormalno then
  69.  buffer.text(2,math.floor(mxh/2),0xD80000,preduprejdenie)
  70.  buffer.text(2,math.floor(mxh/2)+1,0xD80000,"Продолжить загрузку? Y/N")
  71.  buffer.draw()
  72.   while true do
  73.   local ev = table.pack(event.pull())
  74.    if ev[1] == "key_up" then
  75.     if ev[4] == 21 then
  76.     break
  77.     elseif ev[4] == 49 or ev[4] == 28 then
  78.     error("interrupted")
  79.     end  
  80.    end
  81.   end
  82.  end
  83. buffer.draw()
  84. end
  85.  
  86. local gamefps, cfps = 0, 0
  87.  
  88. thread.init()
  89.  
  90. local function readFromFile(path)
  91. local file = io.open(path, 'r')
  92. local array = {}
  93.  for line in file:lines() do
  94.   if line:sub(-1) == "\r" then
  95.   line = line:sub(1, -2)
  96.   end
  97.  table.insert(array, line)
  98.  end
  99. file:close()
  100. return array
  101. end
  102.  
  103. local function loadLanguage(wPath)
  104. if not fs.exists(wPath) then error("File not exists") end
  105. local ptable = {}
  106. local key, value, dmt1
  107. local len = 0
  108. local f = io.open(wPath, "r")
  109.  for line in f:lines() do
  110.  if not f then return nil end
  111.  len = len + 1
  112.  dmt1 = string.find(line, "@")
  113.  value1 = string.sub(line, 1, dmt1 - 2)
  114.  value2 = string.sub(line, dmt1 + 2, #line-1)
  115.  table.insert(ptable,{value1, value2})
  116.  end
  117. f:close()
  118. if len == 0 then return nil end
  119. return ptable
  120. end
  121.  
  122. local function convLang(ptable,value)
  123. local cLang = 2
  124. local newTable = {}
  125. if value == "russian" then cLang = 1 end
  126.  for f = 1, #ptable do
  127.  newTable[ptable[f][1]] = ptable[f][cLang]
  128.  end
  129. return newTable
  130. end
  131.  
  132. local rawlang = loadLanguage("/games/testgame/translate.lang")
  133. local nlang = convLang(rawlang, LANGUAGE)
  134. local function lang(string)
  135. if type(nlang[string]) == "string" then return nlang[string] end
  136. return string
  137. end
  138.  
  139. local aItemIconsSpr
  140. aItemIconsSpr = readFromFile("/games/testgame/itempic.data")
  141.  
  142. local dialogs = {
  143. [1]={["text"] = "",
  144.     {["text"] = lang("До встречи"),["action"] = "close", ["do"] = nil},
  145.     },
  146. [2]={["text"] = "",
  147.     {["text"] = lang("До встречи"),["action"] = "close", ["do"] = nil},
  148.     },
  149. [3]={["text"] = "",
  150.     {["text"] = lang("Товары и услуги"),["action"] = "trade", ["do"] = 1},
  151.     {["text"] = lang("До встречи"),["action"] = "close", ["do"] = nil},
  152.     },
  153. [4]={["text"] = "",
  154.     {["text"] = lang("Покинуть это место"), ["action"] = "dialog", ["do"] = {
  155.     ["text"] = "",
  156.     {["text"] = lang("Да, я хочу выйти"),["action"] = "setWorld", ["do"] = 2, ["reqlvl"] = 1},
  157.     {["text"] = lang("До встречи"),["action"] = "close", ["do"] = nil},
  158.     }},
  159.     {["text"] = lang("До встречи"),["action"] = "close", ["do"] = nil},
  160.     },
  161. [5]={["text"] = "",
  162.     {["text"] = lang("Пещера (тест)"), ["action"] = "dialog", ["do"] = {
  163.         ["text"] = "",
  164.         {["text"] = lang("В пещеру"),["action"] = "setWorld", ["do"] = 3, ["reqlvl"] = 5},
  165.         {["text"] = lang("До встречи"),["action"] = "close", ["do"] = nil},
  166.     }},
  167.     {["text"] = lang("Вернуться"), ["action"] = "dialog", ["do"] = {
  168.         ["text"] = "",
  169.         {["text"] = lang("Мне нужно поскорее вернуться"),["action"] = "setWorld", ["do"] = 1, ["reqlvl"] = 1},
  170.         {["text"] = lang("До встречи"),["action"] = "close", ["do"] = nil},
  171.     }},
  172.     {["text"] = lang("До встречи"),["action"] = "close", ["do"] = nil},
  173.     },
  174. [6]={["text"] = "",
  175.     {["text"] = lang("Вернуться"), ["action"] = "dialog", ["do"] = {
  176.         ["text"] = "Вернуться в локацию 'Зеленые луга'?",
  177.         {["text"] = lang("Да"),["action"] = "setWorld", ["do"] = 2, ["reqlvl"] = 1},
  178.         {["text"] = lang("Нет"),["action"] = "close", ["do"] = nil},
  179.     }},
  180.     {["text"] = lang("Не сейчас"),["action"] = "close", ["do"] = nil},
  181.     },
  182. [7]={["text"] = "",
  183.     {["text"] = lang("Войти в поселение"), ["action"] = "dialog", ["do"] = {
  184.         ["text"] = "Войти в поселение?",
  185.         {["text"] = lang("Да"),["action"] = "setWorld", ["do"] = 4, ["reqlvl"] = 1},
  186.         {["text"] = lang("Нет"),["action"] = "close", ["do"] = nil},
  187.     }},
  188.     {["text"] = lang("Не сейчас"),["action"] = "close", ["do"] = nil},
  189.     },
  190. [8]={["text"] = "Я еще не видел ничего подобного!",
  191.     {["text"] = lang("До встречи"),["action"] = "close", ["do"] = nil},
  192.     },
  193. }
  194.  
  195. local mSprites = {}
  196.  
  197. local vAttackDistance
  198.  
  199. local standartItemLoot1_4 = {
  200. {17,2.7},{18,2.7},{19,2.7},{20,2.7},{3,1.8},{4,1.8},{5,1.8},{6,1.8},{8,1.7},{28,1.2},{29,1.2},{30,1.1},{9,7.4},{10,7.4}
  201. }
  202. local standartItemLoot5_9 = {
  203. {17,2.7},{18,2.7},{19,2.7},{20,2.7},{31,1.8},{32,1.8},{33,1.8},{34,1.8},{35,1.7},{28,1.2},{29,1.2},{30,1.1},{11,7.4},{12,7.4}
  204. }
  205.  
  206. local gameUnitData = {
  207.     {["id"] = 1, ["name"] = "Игрок", ["wtype"] = "Управляемый персонаж", ["level"] = 6, ["atds"] = 10,
  208.     ["loot"] = {["exp"] = 0, ["coins"] = 0, ["items"] = {}}, ["vresp"] = 0, ["rtype"] = "p", ["image"] = "player"},
  209.     {["id"] = 2, ["name"] = "Зомби", ["wtype"] = "Ходячий труп",["level"] = 1, ["atds"] = 10, ["agr"] = true,
  210.     ["loot"] = {["exp"] = 2, ["coins"] = 3, ["items"] = standartItemLoot1_4},
  211.     ["vresp"] = 45, ["rtype"] = "e", ["image"] = "zombie1"},
  212.     {["id"] = 3, ["name"] = "Привидение", ["wtype"] = "Призрак",["level"] = 2, ["atds"] = 10,
  213.     ["loot"] = {["exp"] = 3, ["coins"] = 5, ["items"] = standartItemLoot1_4},
  214.     ["vresp"] = 45, ["rtype"] = "e", ["image"] = "ghost"},
  215.     {["id"] = 4, ["name"] = "Зеленый слизень", ["wtype"] = "Слизень", ["level"] = 2, ["atds"] = 10,
  216.     ["loot"] = {["exp"] = 3, ["coins"] = 4, ["items"] = standartItemLoot1_4},
  217.     ["vresp"] = 45, ["rtype"] = "e", ["image"] = "greenslug"},
  218.     {["id"] = 5, ["name"] = "Василий", ["wtype"] = "", ["level"] = 0, ["quests"] = {1,2,3},
  219.     ["vresp"] = 0, ["image"] = "vil1", ["rtype"] = "f",["dialog"] = 1},
  220.     {["id"] = 6, ["name"] = "Зеленый куст", ["wtype"] = "Дерево", ["level"] = 3, ["atds"] = 10,
  221.     ["loot"] = {["exp"] = 4, ["coins"] = 6, ["items"] = {
  222.     {30,1.1},{9,7.4},{10,7.4}
  223.     }}, ["vresp"] = 45, ["rtype"] = "e", ["image"] = "bush"},
  224.     {["id"] = 7, ["name"] = "Дух места", ["wtype"] = "Призрак", ["level"] = 3, ["atds"] = 10,
  225.     ["loot"] = {["exp"] = 4, ["coins"] = 6, ["items"] = {
  226.     {29,1.2},{30,1.1},{9,7.4},{10,7.4}
  227.     }}, ["vresp"] = 45, ["rtype"] = "e", ["image"] = "spiritofplace"},
  228.     {["id"] = 8, ["name"] = "Каменная черепаха", ["wtype"] = "Черепаха", ["level"] = 4, ["atds"] = 9,
  229.     ["loot"] = {["exp"] = 5, ["coins"] = 7, ["items"] = standartItemLoot1_4},
  230.     ["vresp"] = 45, ["rtype"] = "e", ["image"] = "stoneturtle"},
  231.     {["id"] = 9, ["name"] = "Гниющее дерево", ["wtype"] = "Дерево", ["level"] = 4, ["atds"] = 10,
  232.     ["loot"] = {["exp"] = 5, ["coins"] = 7, ["items"] = standartItemLoot1_4},
  233.     ["vresp"] = 45, ["rtype"] = "e", ["image"] = "swamptree"},
  234.     {["id"] = 10, ["name"] = "Анатолий", ["wtype"] = "Торговец снадобьями", ["level"] = 0, ["quests"] = {4},
  235.     ["vresp"] = 0, ["image"] = "vil2", ["rtype"] = "f",["dialog"] = 2},
  236.     {["id"] = 11, ["name"] = "Кинехет", ["wtype"] = "Кузнец", ["level"] = 0, ["quests"] = nil,
  237.     ["vresp"] = 0, ["image"] = "vil3", ["rtype"] = "f",["dialog"] = 3},
  238.     {["id"] = 12, ["name"] = "Стражник", ["wtype"] = "", ["level"] = 0, ["quests"] = nil,
  239.     ["vresp"] = 0, ["image"] = "guardian1", ["rtype"] = "f",["dialog"] = 4},
  240.     {["id"] = 13, ["name"] = "Стражник", ["wtype"] = "", ["level"] = 0, ["quests"] = nil,
  241.     ["vresp"] = 0, ["image"] = "guardian1", ["rtype"] = "f",["dialog"] = 5},
  242.     {["id"] = 14, ["name"] = "Болотный вурдалак", ["wtype"] = "Ходячий труп", ["level"] = 5, ["atds"] = 10, ["agr"] = true,
  243.     ["loot"] = {["exp"] = 6, ["coins"] = 9, ["items"] = standartItemLoot5_9}, ["vresp"] = 55, ["rtype"] = "e", ["image"] = "venomous_ghoul"},
  244.     {["id"] = 15, ["name"] = "Скелет", ["wtype"] = "Ходячий труп", ["level"] = 5, ["atds"] = 10, ["agr"] = true,
  245.     ["loot"] = {["exp"] = 6, ["coins"] = 9, ["items"] = standartItemLoot5_9}, ["vresp"] = 55, ["rtype"] = "e", ["image"] = "skelet1"},
  246.     {["id"] = 16, ["name"] = "Подземный вурдалак", ["wtype"] = "Ходячий труп", ["level"] = 5, ["atds"] = 10, ["agr"] = true,
  247.     ["loot"] = {["exp"] = 4, ["coins"] = 8, ["items"] = standartItemLoot5_9}, ["vresp"] = 85, ["rtype"] = "e", ["image"] = "venomous_ghoul"},
  248.     {["id"] = 17, ["name"] = "Привидение", ["wtype"] = "Призрак", ["level"] = 6, ["atds"] = 10, ["agr"] = true,
  249.     ["loot"] = {["exp"] = 7, ["coins"] = 11, ["items"] = standartItemLoot5_9}, ["vresp"] = 55, ["rtype"] = "e", ["image"] = "nv_ghost"},
  250.     {["id"] = 18, ["name"] = "Выход", ["wtype"] = "", ["level"] = 0, ["quests"] = nil,
  251.     ["vresp"] = 0, ["image"] = "tlp1", ["rtype"] = "f",["dialog"] = 6},
  252.     {["id"] = 19, ["name"] = "Каменная стена", ["wtype"] = "", ["level"] = 0, ["quests"] = nil,
  253.     ["vresp"] = 0, ["image"] = "stne_wall", ["rtype"] = "f",["dialog"] = 7},
  254.     {["id"] = 20, ["name"] = "Ученый из Лусофаега", ["wtype"] = "", ["level"] = 0, ["quests"] = nil,
  255.     ["vresp"] = 0, ["image"] = "vil4", ["rtype"] = "f",["dialog"] = 8},
  256.     {["id"] = 21, ["name"] = "Гравий", ["level"] = 0, ["reqlvl"] = 1, ["rtype"] = "r", ["image"] = "gravel", ["mnprs"] = 9, ["mxprs"] = 21, ["vresp"] = 750,
  257.     ["items"] = {{27,100},{27,1}}, ["coins"] = 0, ["exp"] = 0},
  258.     {["id"] = 22, ["name"] = "Залежи железа", ["level"] = 0, ["reqlvl"] = 1, ["rtype"] = "r", ["image"] = "iron_ore", ["mnprs"] = 9, ["mxprs"] = 21, ["vresp"] = 750,
  259.     ["items"] = {{25,100},{25,1}}, ["coins"] = 0, ["exp"] = 0},
  260.     {["id"] = 23, ["name"] = "Залежи меди", ["level"] = 0, ["reqlvl"] = 1, ["rtype"] = "r", ["image"] = "copper_ore", ["mnprs"] = 9, ["mxprs"] = 21, ["vresp"] = 750,
  261.     ["items"] = {{24,100},{24,1}}, ["coins"] = 0, ["exp"] = 0},
  262.     {["id"] = 24, ["name"] = "Старый пень", ["level"] = 0, ["reqlvl"] = 1, ["rtype"] = "r", ["image"] = "wooden", ["mnprs"] = 9, ["mxprs"] = 21, ["vresp"] = 750,
  263.     ["items"] = {{21,100},{21,1}}, ["coins"] = 0, ["exp"] = 0},
  264.     {["id"] = 25, ["name"] = "Залежи древесного угля", ["level"] = 0, ["reqlvl"] = 1, ["rtype"] = "r", ["image"] = "wcoal", ["mnprs"] = 9, ["mxprs"] = 21, ["vresp"] = 750,
  265.     ["items"] = {{26,100},{26,1}}, ["coins"] = 0, ["exp"] = 0}
  266. }
  267.  
  268. standartItemLoot1_4 = nil
  269. standartItemLoot5_9 = nil
  270.  
  271. for f = 1, #gameUnitData do
  272. gameUnitData[f]["name"] = lang(gameUnitData[f]["name"])
  273. gameUnitData[f]["wtype"] = lang(gameUnitData[f]["wtype"])
  274. end
  275.  
  276. local gameItemData = {
  277.     {["name"] = "Медный слиток", ["type"] = "item", ["subtype"] = "res", ["description"] = "Может быть использован для крафта",
  278.     ["stackable"] = true, ["maxstack"] = 99, ["level"] = 1, ["cost"] = 5, ["icon"] = 1, ["ncolor"] = 0xFFFFFF},
  279.     {["name"] = "Железный слиток", ["type"] = "item", ["subtype"] = "res", ["description"] = "Может быть использован для крафта",
  280.     ["stackable"] = true, ["maxstack"] = 99, ["level"] = 1, ["cost"] = 5, ["icon"] = 2, ["ncolor"] = 0xFFFFFF},
  281.     {["name"] = "Шлем новобранца", ["level"] = 1, ["type"] = "armor", ["subtype"] = "helmet", ["reqlvl"] = 1, ["description"] = "",
  282.     ["props"] = {}, ["stackable"] = false, ["cost"] = 5, ["icon"] = 5, ["ncolor"] = 0xFFFFFF},
  283.     {["name"] = "Доспех новобранца", ["level"] = 1, ["type"] = "armor", ["subtype"] = "bodywear", ["reqlvl"] = 1, ["description"] = "",
  284.     ["props"] = {}, ["stackable"] = false, ["cost"] = 5, ["icon"] = 3, ["ncolor"] = 0xFFFFFF},
  285.     {["name"] = "Брюки новобранца", ["level"] = 1, ["type"] = "armor", ["subtype"] = "pants", ["reqlvl"] = 1, ["description"] = "",
  286.     ["props"] = {}, ["stackable"] = false, ["cost"] = 5, ["icon"] = 4, ["ncolor"] = 0xFFFFFF},
  287.     {["name"] = "Сапоги новобранца", ["level"] = 1, ["type"] = "armor", ["subtype"] = "footwear", ["reqlvl"] = 1, ["description"] = "",
  288.     ["props"] = {}, ["stackable"] = false, ["cost"] = 5, ["icon"] = 6, ["ncolor"] = 0xFFFFFF},
  289.     {["name"] = "Деревянный меч", ["level"] = 1, ["type"] = "weapon", ["subtype"] = "sword", ["reqlvl"] = 1, ["description"] = "",
  290.     ["props"] = {["atds"] = 10, ["phisat"] = 2, ["magat"] = 0}, ["stackable"] = false, ["cost"] = 1, ["icon"] = 7, ["ncolor"] = 0xFFFF00},
  291.     {["name"] = "Ожерелье из кости", ["level"] = 1, ["type"] = "armor", ["subtype"] = "pendant", ["reqlvl"] = 1, ["description"] = "",
  292.     ["props"] = {}, ["stackable"] = false, ["cost"] = 6, ["icon"] = 8, ["ncolor"] = 0xFFFFFF},
  293.     {["name"] = "Малое исцеляющее зелье", ["type"] = "potion", ["subtype"] = "health", ["reqlvl"] = 1, ["description"] = "",
  294.     ["props"] = 1, ["stackable"] = true, ["maxstack"] = 99, ["level"] = 1, ["cost"] = 1, ["icon"] = 9, ["ncolor"] = 0xFFFFFF},
  295.     {["name"] = "Малое бодрящее зелье", ["type"] = "potion", ["subtype"] = "mana", ["reqlvl"] = 1, ["description"] = "",
  296.     ["props"] = 1, ["stackable"] = true, ["maxstack"] = 99, ["level"] = 1, ["cost"] = 1, ["icon"] = 10, ["ncolor"] = 0xFFFFFF},
  297.     {["name"] = "Среднее исцеляющее зелье", ["type"] = "potion", ["subtype"] = "health", ["reqlvl"] = 5, ["description"] = "",
  298.     ["props"] = 1, ["stackable"] = true, ["maxstack"] = 99, ["level"] = 2, ["cost"] = 2, ["icon"] = 11, ["ncolor"] = 0xFFFFFF},
  299.     {["name"] = "Среднее бодрящее зелье", ["type"] = "potion", ["subtype"] = "mana", ["reqlvl"] = 5, ["description"] = "",
  300.     ["props"] = 1, ["stackable"] = true, ["maxstack"] = 99, ["level"] = 2, ["cost"] = 2, ["icon"] = 12, ["ncolor"] = 0xFFFFFF},
  301.     {["name"] = "Большое исцеляющее зелье", ["type"] = "potion", ["subtype"] = "health", ["reqlvl"] = 10, ["description"] = "",
  302.     ["props"] = 1, ["stackable"] = true, ["maxstack"] = 99, ["level"] = 3, ["cost"] = 3, ["icon"] = 13, ["ncolor"] = 0xFFFFFF},
  303.     {["name"] = "Большое бодрящее зелье", ["type"] = "potion", ["subtype"] = "mana", ["reqlvl"] = 10, ["description"] = "",
  304.     ["props"] = 1, ["stackable"] = true, ["maxstack"] = 99, ["level"] = 3, ["cost"] = 3, ["icon"] = 14, ["ncolor"] = 0xFFFFFF},
  305.     {["name"] = "Концентрированное исцеляющее зелье", ["type"] = "potion", ["subtype"] = "health", ["reqlvl"] = 15, ["description"] = "",
  306.     ["props"] = 1, ["stackable"] = true, ["maxstack"] = 99, ["level"] = 4, ["cost"] = 4, ["icon"] = 15, ["ncolor"] = 0xFFFFFF},
  307.     {["name"] = "Концентрированное бодрящее зелье", ["type"] = "potion", ["subtype"] = "mana", ["reqlvl"] = 15, ["description"] = "",
  308.     ["props"] = 1, ["stackable"] = true, ["maxstack"] = 99, ["level"] = 4, ["cost"] = 4, ["icon"] = 16, ["ncolor"] = 0xFFFFFF},
  309.     {["name"] = "Грубая шкура животного", ["type"] = "item", ["subtype"] = "res", ["description"] = "Может быть использован для крафта",
  310.     ["stackable"] = true, ["maxstack"] = 99, ["level"] = 1, ["cost"] = 3, ["icon"] = 17, ["ncolor"] = 0xFFFFFF},
  311.     {["name"] = "Мягкий мех", ["type"] = "item", ["subtype"] = "res", ["description"] = "Может быть использован для крафта",
  312.     ["stackable"] = true, ["maxstack"] = 99, ["level"] = 1, ["cost"] = 5, ["icon"] = 18, ["ncolor"] = 0xFFFFFF},
  313.     {["name"] = "Грубая нить", ["type"] = "item", ["subtype"] = "res", ["description"] = "Может быть использован для крафта",
  314.     ["stackable"] = true, ["maxstack"] = 99, ["level"] = 1, ["cost"] = 5, ["icon"] = 19, ["ncolor"] = 0xFFFFFF},
  315.     {["name"] = "Необработанная кожа", ["type"] = "item", ["subtype"] = "res", ["description"] = "Может быть использован для крафта",
  316.     ["stackable"] = true, ["maxstack"] = 99, ["level"] = 1, ["cost"] = 6, ["icon"] = 20, ["ncolor"] = 0xFFFFFF},
  317.     {["name"] = "Необработанная древесина", ["type"] = "item", ["subtype"] = "res", ["description"] = "Может быть использован для крафта",
  318.     ["stackable"] = true, ["maxstack"] = 99, ["level"] = 1, ["cost"] = 4, ["icon"] = 21, ["ncolor"] = 0xFFFFFF},
  319.     {["name"] = "Коробка", ["type"] = "chest", ["subtype"] = "none", ["cost"] = 1, ["description"] = "Награда за задание",
  320.     ["props"] = {{9,5,14.2},{10,5,14.2},{3,1,14.2},{4,1,14.2},{5,1,14.2},{6,1,14.2},{8,1,14.2},{9,1,100}},
  321.     ["stackable"] = false, ["maxstack"] = 99, ["icon"] = 22, ["ncolor"] = 0xFFFFFF},
  322.     {["name"] = "Телепортирующая частица", ["type"] = "tlp", ["subtype"] = "none", ["description"] = "Телепортирует к началу",
  323.     ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 1, ["icon"] = 23, ["ncolor"] = 0x00C232},
  324.     {["name"] = "Медная руда", ["type"] = "item", ["subtype"] = "res", ["description"] = "Перерабатываемое сырье",
  325.     ["stackable"] = true, ["maxstack"] = 99, ["level"] = 1, ["cost"] = 2, ["icon"] = 24, ["ncolor"] = 0xFFFFFF},
  326.     {["name"] = "Железная руда", ["type"] = "item", ["subtype"] = "res", ["description"] = "Перерабатываемое сырье",
  327.     ["stackable"] = true, ["maxstack"] = 99, ["level"] = 1, ["cost"] = 2, ["icon"] = 25, ["ncolor"] = 0xFFFFFF},
  328.     {["name"] = "Древесный уголь", ["type"] = "item", ["subtype"] = "res", ["description"] = "Базовое топливо",
  329.     ["stackable"] = true, ["maxstack"] = 99, ["level"] = 1, ["cost"] = 3, ["icon"] = 26, ["ncolor"] = 0xFFFFFF},
  330.     {["name"] = "Гравий", ["type"] = "item", ["subtype"] = "res", ["description"] = "Сырье для работы с камнем",
  331.     ["stackable"] = true, ["maxstack"] = 99, ["level"] = 1, ["cost"] = 3, ["icon"] = 27, ["ncolor"] = 0xFFFFFF},
  332.     {["name"] = "Длинный меч", ["level"] = 1, ["type"] = "weapon", ["subtype"] = "sword", ["reqlvl"] = 2, ["description"] = "",
  333.     ["props"] = {["atds"] = 10, ["phisat"] = 5, ["magat"] = 0}, ["stackable"] = false, ["cost"] = 14, ["icon"] = 29, ["ncolor"] = 0xFFFFFF},
  334.     {["name"] = "Легкое копье", ["level"] = 1, ["type"] = "weapon", ["subtype"] = "spear", ["reqlvl"] = 2, ["description"] = "",
  335.     ["props"] = {["atds"] = 14, ["phisat"] = 4, ["magat"] = 0}, ["stackable"] = false, ["cost"] = 14, ["icon"] = 28, ["ncolor"] = 0xFFFFFF},
  336.     {["name"] = "Короткий каменный топор", ["level"] = 1, ["type"] = "weapon", ["subtype"] = "axe", ["reqlvl"] = 2, ["description"] = "",
  337.     ["props"] = {["atds"] = 10, ["phisat"] = 6, ["magat"] = 0}, ["stackable"] = false, ["cost"] = 14, ["icon"] = 30, ["ncolor"] = 0xFFFFFF},
  338.     {["name"] = "Легкий боевой шлем", ["level"] = 2, ["type"] = "armor", ["subtype"] = "helmet", ["reqlvl"] = 5, ["description"] = "",
  339.     ["props"] = {}, ["stackable"] = false, ["cost"] = 23, ["icon"] = 31, ["ncolor"] = 0xFFFFFF},
  340.     {["name"] = "Доспех из кожи", ["level"] = 2, ["type"] = "armor", ["subtype"] = "bodywear", ["reqlvl"] = 5, ["description"] = "",
  341.     ["props"] = {}, ["stackable"] = false, ["cost"] = 27, ["icon"] = 32, ["ncolor"] = 0xFFFFFF},
  342.     {["name"] = "Брюки из кожи", ["level"] = 2, ["type"] = "armor", ["subtype"] = "pants", ["reqlvl"] = 5, ["description"] = "",
  343.     ["props"] = {}, ["stackable"] = false, ["cost"] = 25, ["icon"] = 33, ["ncolor"] = 0xFFFFFF},
  344.     {["name"] = "Кожаные сапоги", ["level"] = 2, ["type"] = "armor", ["subtype"] = "footwear", ["reqlvl"] = 5, ["description"] = "",
  345.     ["props"] = {}, ["stackable"] = false, ["cost"] = 25, ["icon"] = 34, ["ncolor"] = 0xFFFFFF},   
  346.     {["name"] = "Волшебный кулон", ["level"] = 2, ["type"] = "armor", ["subtype"] = "pendant", ["reqlvl"] = 6, ["description"] = "",
  347.     ["props"] = {}, ["stackable"] = false, ["cost"] = 36, ["icon"] = 35, ["ncolor"] = 0xFFFFFF},
  348.    
  349.     -- Читерское
  350.     {["name"] = "Дохрена мощный топор", ["level"] = 16, ["type"] = "weapon", ["subtype"] = "axe", ["reqlvl"] = 1, ["description"] = "",
  351.     ["props"] = {["atds"] = 10, ["phisat"] = 6, ["magat"] = 0}, ["stackable"] = false, ["cost"] = 1, ["icon"] = 30, ["ncolor"] = 0x00C221},
  352. }
  353.  
  354. local itemPhysDefMlt = {["helmet"]=13.2,["bodywear"]=14.4,["pants"]=13.7,["footwear"]=12.2,["pendant"]=9.5}
  355. local itemMagDefMlt = {["helmet"]=1.5,["bodywear"]=5.3,["pants"]=4.8,["footwear"]=4.5,["pendant"]=11.7}
  356.  
  357. for f = 1, #gameItemData do
  358. gameItemData[f]["name"] = lang(gameItemData[f]["name"])
  359. gameItemData[f]["description"] = lang(gameItemData[f]["description"])
  360.  if gameItemData[f]["type"] == "armor" then
  361.   if gameItemData[f]["props"]["pdef"] == nil then
  362.   gameItemData[f]["props"]["pdef"] = math.ceil(21+gameItemData[f]["level"]*itemPhysDefMlt[gameItemData[f]["subtype"]])
  363.   end
  364.   if gameItemData[f]["props"]["magdef"] == nil then
  365.   gameItemData[f]["props"]["magdef"] = math.ceil(9+gameItemData[f]["level"]*itemMagDefMlt[gameItemData[f]["subtype"]])
  366.   end
  367.  end
  368. end
  369.  
  370. local gameQuestsData = {
  371.     {["name"] = "Зомби", ["type"] = "k", ["qstrec"] = 5, ["targ"] = 2, ["num"] = 1, ["minlvl"] = 1,
  372.     ["descr"] = "Избавьте людей от этой угрозы!",
  373.     ["comp"] = 0, ["qreward"] = {["coins"] = 10, ["xp"] = 10, ["item"] = {{9,5},{23,5}}}},
  374.     {["name"] = "Призраки", ["type"] = "k", ["qstrec"] = 5, ["targ"] = 3, ["num"] = 3, ["minlvl"] = 1,
  375.     ["descr"] = "Даже привидения могут представлять угрозу человеку.",
  376.     ["comp"] = 0, ["qreward"] = {["coins"] = 12, ["xp"] = 9, ["item"] = {{10,5}}}},
  377.     {["name"] = "Луговые слизни", ["type"] = "k", ["qstrec"] = 5, ["targ"] = 4, ["num"] = 7, ["minlvl"] = 2,
  378.     ["descr"] = "Никогда не было так много слизней в наших лугах! Зеленые луговые слизни очень быстро уничтожат все растения и, скорее всего, скоро будут здесь.",
  379.     ["comp"] = 0, ["qreward"] = {["coins"] = 20, ["xp"] = 15, ["item"] = {{22,1}}}},
  380.     {["name"] = "Необычные черепахи", ["type"] = "k", ["qstrec"] = 10, ["targ"] = 8, ["num"] = 3, ["minlvl"] = 3,
  381.     ["descr"] = " Анатолия очень заинтересовали каменные черепахи. Принесите ему 3 панциря каменных черепах.",
  382.     ["comp"] = 0, ["qreward"] = {["coins"] = 18, ["xp"] = 16, ["item"] = nil}},
  383. }
  384.  
  385. local gameSkillsData = {
  386.     {["name"] = "Физическая атака", ["distance"] = 0, ["type"] = "attack", ["typedm"] = "p", ["level"] = 1, ["reloading"] = 1,
  387.     ["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"] = nil},
  388.     {["name"] = "Глубокий порез", ["distance"] = 1, ["type"] = "attack", ["typedm"] = "p", ["level"] = 1, ["reloading"] = 3,
  389.     ["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"] = nil},
  390.     {["name"] = "Кровопускание", ["distance"] = 1, ["type"] = "attack", ["typedm"] = "p", ["level"] = 1, ["reloading"] = 7,
  391.     ["mindamage"] = {2,3,4,6,8,12,16}, ["maxdamage"] = {4,6,8,10,12,17,23}, ["manacost"] = {6,7,9,11,13,16,20}, ["eff"] = 3},
  392.     {["name"] = "Аура железа", ["type"] = "buff", ["level"] = 1, ["reloading"] = 25,
  393.     ["manacost"] = {8,11,14,18,25,34,47}, ["eff"] = 4},
  394. }
  395.  
  396. local gameEffectsData = {
  397.     {["name"]="Исцеляющее зелье",["type"]="hpi", ["descr"]="Восстановление здоровья",
  398.     ["dur"]={10,10,10,10,10,10},["val"]={12,22,35,47,60,85},["i"]={0xcc4940,"h",0xff9200,"p"}},
  399.     {["name"]="Бодрящее зелье",["type"]="mpi", ["descr"]="Восстановление маны",
  400.     ["dur"]={10,10,10,10,10,10},["val"]={12,22,35,47,60,85},["i"]={0x3349bf,"m",0xff9200,"p"}},
  401.     {["name"]="Кровоточащая рана",["type"]="hpd", ["descr"]="",
  402.     ["dur"]={8,8,8,8,8,8},["val"]={8,14,21,29,38,53},["i"]={0x434941,"b",0xe32114,"w"}},       
  403.     {["name"]="Аура железа",["type"]="pdfi%", ["descr"]="Физическая защита увеличена",
  404.     ["dur"]={60,90,120,180,240,300},["val"]={5,10,15,20,25,30,35},["i"]={0x81c181,"w",0x3872ae,"a"}},
  405.  
  406. }
  407.  
  408. local gameTradew = {
  409. [1]={
  410.         {   ["section_name"] = "Тест",
  411.             {["item"]=3,["chance"]=100,["cost"]=182},
  412.             {["item"]=4,["chance"]=100,["cost"]=181},
  413.             {["item"]=5,["chance"]=100,["cost"]=185},
  414.             {["item"]=6,["chance"]=100,["cost"]=183},
  415.             {["item"]=7,["chance"]=100,["cost"]=111},
  416.             {["item"]=8,["chance"]=100,["cost"]=666},
  417.             {["item"]=9,["chance"]=100,["cost"]=16},
  418.             {["item"]=10,["chance"]=100,["cost"]=31},
  419.             {["item"]=11,["chance"]=100,["cost"]=53},
  420.             {["item"]=12,["chance"]=100,["cost"]=321},
  421.             {["item"]=13,["chance"]=100,["cost"]=12},
  422.             {["item"]=14,["chance"]=100,["cost"]=10},
  423.             {["item"]=15,["chance"]=100,["cost"]=62},
  424.             {["item"]=16,["chance"]=100,["cost"]=27},
  425.             {["item"]=17,["chance"]=100,["cost"]=82},
  426.             {["item"]=18,["chance"]=100,["cost"]=63},
  427.         },
  428.         {   ["section_name"] = "Тест2",
  429.             {["item"]=21,["chance"]=100,["cost"]=22},
  430.         }
  431.     },
  432. }
  433.  
  434. for f = 1, #gameQuestsData do
  435. gameQuestsData[f]["name"] = lang(gameQuestsData[f]["name"])
  436. gameQuestsData[f]["comp"] = 0
  437. end
  438.  
  439. local cGUData = {} -- массив со всеми персонажами
  440.  
  441. local cPlayerSkills = {{2,0,1}}
  442. local cUskills = {{1,0,1},{2,0,1},{3,0,1},{0,0,1},{4,0,1},{0,0,1}}
  443. local cUquests = {} -- структура -- [1] (и т.д.) = {1(id),0(прогресс),false(не выполнено/выполнено)}
  444.  
  445. local inventory = {
  446. ["weared"] = {
  447. ["helmet"] = 0,
  448. ["bodywear"] = 0,
  449. ["pants"] = 0,
  450. ["weapon"] = 7,
  451. ["footwear"] = 0,
  452. ["pendant"] = 0},
  453. ["bag"] = {}
  454. }
  455. for f = 1, 20 do
  456. inventory["bag"][f] = {}
  457. inventory["bag"][f][1] = 0
  458. inventory["bag"][f][2] = 0
  459. end
  460.  
  461.  
  462. local cpath = "/games/testgame/"
  463. local cGlobalx, cBackgroundPos = 1, 1
  464. local playerSprPicPos = 75
  465. local cTarget = 0
  466. local paused = false
  467. local cWindowTrd = nil
  468. local showTargetInfo = false
  469. local pckTarget = 0
  470. local pickingUp = false
  471. local maxPckTime = 0
  472. local pckTime = 0
  473.  
  474. local stopDrawing = false
  475. local ingame = true
  476. local playerCanMove = true
  477. local cmp, mmp, cxp, mxp, cCoins = 0, 0, 0, 0, 0
  478. local cDialog
  479.  
  480. local charPoints = gameUnitData[1]["level"]-1
  481. local survivability = 1
  482. local strength = 1
  483. local intelligence = 1
  484.  
  485. local world = {
  486. current = 1,
  487. [1]={
  488.     name = "Деревня Зеленый Камень",
  489.     limitL = -160,
  490.     limitR = 105,
  491.     spawnList = {
  492.         {11,-68,1},
  493.         {10,-47,1},
  494.         {5,-25,1},
  495.         {12,45,1}
  496.         },
  497.     draw = function()
  498.     buffer.square(1, 1, 160, 50, 0x00AAFF, 0xFFFFFF, " ")
  499.     buffer.square(1, 48, 160, 1, 0x755340, 0xFFFFFF, " ")
  500.     buffer.square(1, 49, 160, 2, 0x339240, 0xFFFFFF, " ")
  501.     end,
  502.     },
  503. [2]={
  504.     name = "Зеленые луга",
  505.     limitL = -60,
  506.     limitR = 2115,
  507.     spawnList = {
  508.         {13,-27,1},
  509.         {2,95,1,5,42},
  510.         {3,361,2,5,95},
  511.         {4,328,1,6,95},
  512.         {6,856,1,5,95},
  513.         {7,823,1,4,95},
  514.         {8,1361,1,4,95},
  515.         {9,1328,1,3,95},
  516.         {14,1758,1,4,95},
  517.         {15,1737,1,4,95},
  518.         {19,2125,-2},
  519.         {21,math.random(100,1450),1,math.random(1,3),math.random(120,290)},
  520.         {22,math.random(100,1450),1,math.random(1,3),math.random(120,290)},
  521.         {23,math.random(100,1450),1,math.random(1,3),math.random(120,290)},
  522.         {24,math.random(100,1450),1,math.random(1,3),math.random(120,290)}
  523.         --{17,2125,1,4,55},
  524.         },
  525.     draw = function()
  526.     buffer.square(1, 1, 160, 50, 0x00AAFF, 0xFFFFFF, " ")
  527.     buffer.square(1, 48, 160, 1, 0x755340, 0xFFFFFF, " ")
  528.     buffer.square(1, 49, 160, 2, 0x339240, 0xFFFFFF, " ")
  529.     end,
  530.     },
  531. [3]={
  532.     name = "Пещера",
  533.     limitL = -60,
  534.     limitR = 500,
  535.     spawnList = {
  536.         {18,-25,1},
  537.         {16,68,1,4,44},
  538.         },
  539.     draw = function()
  540.     buffer.square(1, 1, 160, 50, 0x656565, 0xFFFFFF, " ")
  541.     buffer.square(1, 1, 160, 3, 0x616161, 0xFFFFFF, " ")
  542.     buffer.square(1, 48, 160, 1, 0x585858, 0xFFFFFF, " ")
  543.     buffer.square(1, 49, 160, 2, 0x434343, 0xFFFFFF, " ")
  544.     end,
  545.     },
  546. [4]={
  547.     name = "Поселение",
  548.     limitL = -160,
  549.     limitR = 105,
  550.     spawnList = {
  551.         {10,-68,1},
  552.         {11,-47,1},
  553.         {20,-25,1},
  554.         },
  555.     draw = function()
  556.     buffer.square(1, 1, 160, 50, 0x00AAFF, 0xFFFFFF, " ")
  557.     buffer.square(1, 48, 160, 1, 0x755340, 0xFFFFFF, " ")
  558.     buffer.square(1, 49, 160, 2, 0x339240, 0xFFFFFF, " ")
  559.     end,
  560.     },
  561. }
  562.  
  563. local function clicked(x,y,x1,y1,x2,y2)
  564.  if x >= x1 and x <= x2 and y >= y1 and y <= y2 then
  565.  return true
  566.  end    
  567.  return false
  568. end
  569.  
  570. local function toboolean(v)
  571.  if v == "true" then return true
  572.  else return false
  573.  end
  574. end
  575.  
  576. local function getDistance(from,x)
  577. local dist = 0
  578. local x1, x2 = cGUData[from]["x"], x
  579. if x1 < x2 then dist = x2-x1
  580. elseif x1 > x2 then dist = x1-x2
  581. end
  582. return dist
  583. end
  584.  
  585. local function getDistanceToId(from,to)
  586. local dist = 0
  587. local x1, x2 = cGUData[from]["x"], cGUData[to]["x"]
  588. if x1 < x2 then dist = x2-x1-cGUData[from]["width"]
  589. elseif x1 > x2+cGUData[to]["width"] then dist = x1-x2-cGUData[to]["width"]
  590. end
  591. return dist
  592. end
  593.  
  594. local sScreenTimerw = false
  595. local sScreenTimer1 = 0
  596. local sScreenXValue = 1
  597. local old_cgx, old_cbpos = cGlobalx, cBackgroundPos
  598.  
  599. local function setScreenXValue(x, time)
  600. cWindowTrd = "screen_save"
  601. old_cgx, old_cbpos = cGlobalx, cBackgroundPos
  602. sScreenTimerw = true
  603. sScreenTimer1 = time
  604. sScreenXValue = x
  605. end
  606.  
  607. local function setScreenPosition(x)
  608. local ncGlobalx, ncBackgroundPos = cGlobalx, cBackgroundPos
  609. cGlobalx = x
  610. cBackgroundPos = x
  611. playerSprPicPos = 75-getDistance(1,x)
  612. end
  613.  
  614. local function setScreenNormalPosition(ncGlobalx, ncBackgroundPos)
  615. playerSprPicPos = 75
  616. cGlobalx, cBackgroundPos = ncGlobalx, ncBackgroundPos
  617. sScreenTimerw = false
  618. cWindowTrd = nil
  619. end
  620.  
  621. local function setScreenNewPosition()
  622.  if sScreenTimerw and sScreenXValue ~= nil then
  623.   if sScreenTimer1 - 1 > 0 then
  624.   setScreenPosition(sScreenXValue)
  625.   else
  626.   sScreenTimer1 = 0
  627.   setScreenNormalPosition(old_cgx, old_cbpos)
  628.   end
  629.  end
  630. end
  631.  
  632. local function movetoward(id, x, distanceLimit, step)
  633.  if getDistance(id,x) < distanceLimit and x < cGUData[id]["x"] then
  634.  cGUData[id]["x"] = cGUData[id]["x"] - step
  635.  cGUData[id]["spos"] = "l"
  636.  elseif getDistance(id,x) < distanceLimit and x > cGUData[id]["x"] then
  637.  cGUData[id]["x"] = cGUData[id]["x"] + step
  638.  cGUData[id]["spos"] = "r"
  639.  end
  640. end
  641.  
  642. local function playerAutoMove(x, distanceLimit, step)
  643.  if getDistance(1,x) >= step and getDistance(1,x) < distanceLimit and x < cGUData[1]["x"] then
  644.  x = math.ceil((cGUData[1]["x"] - x)/3)*3
  645.  cGUData[1]["spos"] = "l"
  646.  cGUData[1]["x"] = cGUData[1]["x"] - step
  647.  cGlobalx = cGlobalx - step
  648.  cBackgroundPos = cBackgroundPos - step
  649.  elseif getDistance(1,x) >= step and getDistance(1,x) < distanceLimit and x > cGUData[1]["x"] then
  650.  x = math.ceil((cGUData[1]["x"] + x)/3)*3
  651.  cGUData[1]["spos"] = "r"
  652.  cGUData[1]["x"] = cGUData[1]["x"] + step
  653.  cGlobalx = cGlobalx + step
  654.  cBackgroundPos = cBackgroundPos + step
  655.  else
  656.  cGUData[1]["mx"] = cGUData[1]["x"]
  657.  end
  658. end
  659.  
  660. local function insertQuests(id,dialog)
  661. local newDialog = dialog
  662. local tvar
  663. local cQue = gameUnitData[cGUData[id]["id"]]["quests"]
  664. local insQuestDialog = true
  665.  if type(cQue) == "table" then
  666.   for n = 1, #dialog do
  667.    if dialog[n]["action"] == "dialog" and dialog[n]["text"] then
  668.    insQuestDialog = false
  669.    break
  670.    end
  671.   end
  672.   if insQuestDialog then
  673.   table.insert(newDialog,1,{["text"]=lang("Задания"),["action"]="dialog",["do"] ={["text"]="Выберите любые доступные задания"}})
  674.   end
  675.   for v = 0, #cQue-1 do
  676.    tvar = true
  677.    for sq = 1, #cUquests do
  678.     if cUquests[sq][1] == #cQue-v and cUquests[sq][3] then
  679.     tvar = false
  680.     break
  681.     end
  682.    end
  683.    if not tvar then break end
  684.    if cQue[#cQue-v] > 0 and cQue[#cQue-v] <= #gameQuestsData and cGUData[1]["level"] >= gameQuestsData[#cQue-v]["minlvl"] then
  685.    newDialog[1]["do"][v] = {["q"]=#cQue-v,["text"]=gameQuestsData[#cQue-v]["name"],["action"]="qdialog",
  686.    ["do"] = {
  687.    ["text"]="Выбрать задание '"..gameQuestsData[cQue[#cQue-v]]["name"].."'",
  688.     {["text"]="Я готов выполнить задание",["action"]="getquest",["do"]=cQue[#cQue-v]},
  689.    {["text"]="Не сейчас",["action"]="close",["do"]=nil}
  690.    }}
  691.    end
  692.   end
  693.   for v = 1, #cUquests do
  694.    if cUquests[v][3] and gameUnitData[cTarget]["id"] == gameQuestsData[cUquests[v][1]]["qstrec"] and not gameQuestsData[cUquests[v][1]]["comp"] then
  695.    table.insert(newDialog[1]["do"],{["text"]=gameQuestsData[cUquests[v][1]]["name"],["action"]="cmpquest",["do"]=cUquests[v][1]})
  696.    end
  697.   end
  698.  newDialog[1]["do"][#cQue] = {["text"]=lang("До встречи"),["action"]="close",["do"]=nil}
  699.  end
  700. return newDialog
  701. end
  702.  
  703. local sMSG1, smsg1time = {"",""}, 0
  704.  
  705. local function addsmsg1(msg)
  706. table.insert(sMSG1,msg)
  707. smsg1time = 8
  708. end
  709.  
  710. local sMSG2, smsg2time = {""}, 0
  711.  
  712. local function addsmsg2(msg)
  713. table.insert(sMSG2,msg)
  714. smsg2time = 5
  715. end
  716.  
  717. sMSG3 = ""
  718.  
  719. local function addsmsg3(msg)
  720. sMSG3 = msg
  721. end
  722.  
  723. local consDataR = {}
  724.  
  725. local function booleanToString(b)
  726.  if b then
  727.  return "true"
  728.  else
  729.  return "false"
  730.  end
  731. end
  732.  
  733. local console={}
  734. function console.debug(...)
  735. local args = table.pack(...)
  736. local msg, adt = "", ""
  737.  if #args > 0 then
  738.   for f = 1, #args do
  739.    if type(args[f]) == "string" then
  740.    adt = args[f]
  741.    elseif type(args[f]) == "number" then
  742.    adt = tostring(args[f])
  743.    elseif type(args[f]) == "boolean" then
  744.    adt = booleanToString(args[f])
  745.    else
  746.    adt = type(args[f])
  747.    end
  748.   msg = msg..adt.." "
  749.   end
  750.  end
  751. table.insert(consDataR,msg)
  752. end
  753.  
  754. function console.wError(e)
  755. if type(e) == "string" then table.insert(consDataR,"!/"..e) end
  756. end
  757.  
  758. local cnsCommands = {
  759.     ["clear"] = function() consDataR = {} end
  760. }
  761.  
  762. function console.execCommand(com)
  763.  if type(com) ~= "string" then
  764.  console.wError("Значение команды невозможно")
  765.  else
  766.   if type(cnsCommands[com]) == "string" then
  767.   cnsCommands[com]()
  768.   end
  769.  end
  770. end
  771.  
  772. local function addUnit(id,x,y)
  773. local cUSprite
  774. cGUData[#cGUData+1] = {}
  775. cGUData[#cGUData]["sx"] = x
  776. cGUData[#cGUData]["mx"] = x
  777. cGUData[#cGUData]["x"] = x
  778. cGUData[#cGUData]["y"] = y
  779. cGUData[#cGUData]["id"] = gameUnitData[id]["id"]
  780. cGUData[#cGUData]["level"] = gameUnitData[id]["level"]
  781. cGUData[#cGUData]["spos"] = "r"
  782. cGUData[#cGUData]["image"] = gameUnitData[id]["image"]
  783.  if cGUData[#cGUData]["image"] ~= nil then
  784.  cUSprite = image.load(cpath.."sprpic/"..gameUnitData[id]["image"]..".pic")
  785.  cGUData[#cGUData]["width"] = cUSprite.width
  786.  cGUData[#cGUData]["height"] = cUSprite.height
  787.  end
  788.  if gameUnitData[id]["mhp"] == nil then
  789.  cGUData[#cGUData]["mhp"] = math.ceil(12+(gameUnitData[id]["level"]-1)*gameUnitData[id]["level"]*2.25)
  790.  else
  791.  cGUData[#cGUData]["mhp"] = gameUnitData[id]["mhp"]
  792.  end
  793. cGUData[#cGUData]["chp"] = cGUData[#cGUData]["mhp"]
  794. cGUData[#cGUData]["phisatck"] = math.ceil(0.15+cGUData[#cGUData]["level"]*0.44)
  795. cGUData[#cGUData]["magatck"] = math.ceil(0.75+cGUData[#cGUData]["level"]*0.3)
  796. cGUData[#cGUData]["pdef"] = math.ceil(11.5+cGUData[#cGUData]["level"]*5.84)
  797. cGUData[#cGUData]["magdef"] = math.ceil(9+gameUnitData[id]["level"]*4.31)
  798. cGUData[#cGUData]["resptime"] = 0
  799. cGUData[#cGUData]["living"] = true
  800. cGUData[#cGUData]["rtype"] = gameUnitData[id]["rtype"]
  801. cGUData[#cGUData]["attackdistance"] = gameUnitData[id]["atds"]
  802. cGUData[#cGUData]["attPlayer"] = false
  803.  if gameUnitData[id]["rtype"] == "f" then
  804.  cGUData[#cGUData]["dialog"] = gameUnitData[id]["dialog"]
  805.  end
  806. cGUData[#cGUData]["effects"] = {}
  807.  if gameUnitData[id]["rtype"] == "m" then
  808.  cGUData[#cGUData]["mhp"] = gameUnitData[id]["mhp"]
  809.  cGUData[#cGUData]["chp"] = cGUData[#cGUData]["mhp"]
  810.  end
  811. console.debug("Spawn new unit","id:"..tostring(gameUnitData[id]["id"]),"name:"..gameUnitData[id]["name"],"x:"..tostring(x),"y:"..tostring(y),"Gid:"..#cGUData)
  812. end
  813.  
  814. console.wError(preduprejdenie)
  815.  
  816. console.debug("Загрузка ("..unicode.sub(os.date(), 1, -4)..")")
  817.  
  818. local function addItem(itemid,num)
  819. local vparInvEx = 0
  820.  for f = 1, #inventory["bag"] do
  821.   if inventory["bag"][f][1] == 0 and inventory["bag"][f][1] ~= itemid and not gameItemData[itemid]["stackable"] then
  822.   inventory["bag"][f][1] = itemid
  823.   inventory["bag"][f][2] = num
  824.   break
  825.   end
  826.  end
  827.  if gameItemData[itemid]["stackable"] and vparInvEx == 0 then
  828.   for i = 1, #inventory["bag"] do
  829.    if inventory["bag"][i][1] == itemid then
  830.    inventory["bag"][i][2] = inventory["bag"][i][2] + num
  831.    vparInvEx = 1
  832.    break
  833.    end
  834.   end
  835.   if vparInvEx == 0 then
  836.    for i = 1, #inventory["bag"] do
  837.     if inventory["bag"][i][1] == 0 then
  838.     inventory["bag"][i][1] = itemid
  839.     inventory["bag"][i][2] = num   
  840.     break
  841.     end
  842.    end
  843.   end
  844.  end
  845.  for f = 1, #inventory["bag"] do
  846.   if inventory["bag"][f][1] ~= 0 and not gameItemData[inventory["bag"][f][1]]["stackable"] and inventory["bag"][f][2] > 1 then
  847.   inventory["bag"][f][2] = 1
  848.   end
  849.  end
  850. end
  851.  
  852. -- создание новых предметов и заполнение ими массива gameItemData
  853. local function createNewItem(itemID)
  854. local adds = {}
  855. local newItemID = #gameItemData + 1
  856.  if gameItemData[itemID]["type"] == "armor" or gameItemData[itemID]["type"] == "weapon" then
  857.  gameItemData[newItemID] = {}
  858.  local list = {
  859.     "name",
  860.     "level",
  861.     "type",
  862.     "subtype",
  863.     "reqlvl",
  864.     "description",
  865.     "stackable",
  866.     "cost",
  867.     "icon",
  868.     "ncolor"
  869.  }
  870.  for e = 1, # list do
  871.  gameItemData[newItemID][list[e]] = gameItemData[itemID][list[e]]
  872.  end
  873. gameItemData[newItemID]["props"] = {}
  874.  for k, v in pairs(gameItemData[itemID]["props"]) do
  875.  gameItemData[newItemID]["props"][k] = gameItemData[itemID]["props"][k]
  876.  end
  877.  local function A() gameItemData[newItemID]["name"] = "♦"..gameItemData[newItemID]["name"] end
  878.  for f = 1, math.min(math.random(1,math.ceil(gameItemData[itemID]["level"]/2)),5) do adds[f] = math.random(1,6) end
  879.   for f = 1, #adds do
  880.    if adds[f] == 1 then
  881.    gameItemData[newItemID]["props"]["hp+"] = math.random(5+(gameItemData[itemID]["level"]-1)*2,5+(gameItemData[itemID]["level"]-1)*6)
  882.    A()
  883.    elseif adds[f] == 2 then
  884.    gameItemData[newItemID]["props"]["sur+"] = math.floor(math.random(gameItemData[itemID]["level"],gameItemData[itemID]["level"]*2))
  885.    A()
  886.    elseif adds[f] == 3 then
  887.    gameItemData[newItemID]["props"]["str+"] = math.floor(math.random(gameItemData[itemID]["level"],gameItemData[itemID]["level"]*2))
  888.    A()
  889.    elseif adds[f] == 4 then
  890.    gameItemData[newItemID]["props"]["int+"] = math.floor(math.random(gameItemData[itemID]["level"],gameItemData[itemID]["level"]*1.5))
  891.    A()
  892.    elseif adds[f] == 5 then
  893.    gameItemData[newItemID]["props"]["pdm+"] = math.floor(math.random((gameItemData[itemID]["level"]-1)*15.7,(gameItemData[itemID]["level"]-1)*28.3)/10)
  894.    A()
  895.    elseif adds[f] == 6 then
  896.    gameItemData[newItemID]["props"]["mdm+"] = math.floor(math.random((gameItemData[itemID]["level"]-1)*12.5,(gameItemData[itemID]["level"]-1)*22.5)/10)
  897.    A()
  898.    end
  899.   end
  900.   if #adds > 0 then gameItemData[newItemID]["ncolor"] = 0x0044FF end
  901.  else
  902.  return itemID
  903.  end
  904. return newItemID
  905. end
  906.  
  907. --[[
  908. addItem(1,1)
  909. ]]
  910.  
  911. addItem(createNewItem(#gameItemData),1)
  912. addItem(createNewItem(30),1)
  913. addItem(createNewItem(35),1)
  914. addItem(35,1)
  915.  
  916. local function addPlayerEffect(id,level)
  917. local addne = true
  918.  if type(id) == 'number' and type(level) == 'number' and id >= 1 and id <= #gameEffectsData then
  919.   for eff = 1, #cGUData[1]["effects"] do
  920.    if cGUData[1]["effects"][eff][1] == id then
  921.    cGUData[1]["effects"][eff][2] = cGUData[1]["effects"][eff][2] + gameEffectsData[id]["dur"][level]
  922.    addne = false
  923.    break
  924.    end
  925.   end
  926.  if addne then table.insert(cGUData[1]["effects"],{id,gameEffectsData[id]["dur"][level],level}) end
  927.  else
  928.  console.wError('addPlayerEffect: неверное значение id или level')
  929.  end
  930. end
  931.  
  932. local function addUnitEffect(uID,eID,level)
  933. local addne = true
  934.  if type(uID) == 'number' and type(eID) == 'number' and type(level) == 'number' and eID >= 1 and eID <= #gameEffectsData then
  935.   for eff = 1, #cGUData[uID]["effects"] do
  936.    if cGUData[uID]["effects"][eff][1] == eID then
  937.    cGUData[uID]["effects"][eff][2] = cGUData[uID]["effects"][eff][2] + gameEffectsData[eID]["dur"][level]
  938.    addne = false
  939.    break
  940.    end
  941.   end
  942.  if addne then table.insert(cGUData[uID]["effects"],{eID,gameEffectsData[eID]["dur"][level],level}) end
  943.  else
  944.  console.wError('addUnitEffect: неверное значение uID, eID или level')
  945.  end
  946. end
  947.  
  948. local function saveGame(savePath,filename)
  949.  if not fs.exists(savePath) then
  950.  fs.makeDirectory(savePath)
  951.  end
  952. local saveNum = #fs.list(savePath)()-4 or 0
  953. fs.copy(savePath.."/gsave",savePath.."/"..filename)
  954. local save = io.open(savePath.."/"..filename,"w")
  955. local function rudt(id,value,ctype) return value.." = "..tostring(cGUData[id][value]).." @ "..ctype end
  956. save:write("save","\n")
  957. save:write(os.date(),"\n")
  958. save:write("save_md_s","\n")
  959. save:write("gameunitdata_s","\n")
  960.  for f = 1, #cGUData do
  961.  save:write("{","\n")
  962.  save:write(rudt(f,"sx","n"),"\n")
  963.  save:write(rudt(f,"x","n"),"\n")
  964.  save:write(rudt(f,"y","n"),"\n")
  965.  save:write(rudt(f,"id","n"),"\n")
  966.  save:write(rudt(f,"spos","n"),"\n")
  967.  save:write(rudt(f,"mhp","n"),"\n")
  968.  save:write(rudt(f,"chp","n"),"\n")
  969.  save:write(rudt(f,"living","b"),"\n")
  970.  save:write(rudt(f,"resptime","n"),"\n")
  971.  save:write("}","\n")
  972.  end
  973. save:write("save_md_e","\n")
  974. save:close()
  975. end
  976.  
  977. local function strGetValue(string)
  978. local del1 = string.find(string,"=")
  979. local del2 = string.find(string,"@")
  980. if del1 ~= nil and del2 ~= nil then
  981. local key = string.sub(string,1,del1-2)
  982. local value = string.sub(string,del1+2,del2-2)
  983. local ctype = string.sub(string,del2+2,#string)
  984. else key = nil
  985. end
  986. return key, value, ctype
  987. end
  988.  
  989. local function loadGame(savePath,filename)
  990. local gkv, ndKey, ndValue, ndType = 1, "", "", ""
  991. local rdata = {}
  992. local aInfo = {}
  993. local gUnitData = {}
  994. local cReadMode = "S"
  995. if fs.exists(savePath.."/"..filename) then rdata = readFromFile(savePath.."/"..filename) end
  996.  for f = 1, #rdata do
  997.   if cReadMode == "Gv" and rdata == "}" then
  998.   cReadMode = "G"
  999.   gkv = gkv + 1
  1000.   end
  1001.   if rdata[f] == "save_md_e" then
  1002.   break
  1003.   end
  1004.   if cReadMode == "S" then
  1005.   table.insert(aInfo,rdata[f])
  1006.   elseif cReadMode == "M" then
  1007.  
  1008.   elseif cReadMode == "Gv" then
  1009.   ndKey, ndValue, ndType = strGetValue(rdata[f])
  1010.    if ndKey ~= nil then
  1011.     if ndType == "n" then ndValue = tonumber(ndValue)
  1012.     elseif ndType == "b" then ndValue = toboolean(ndValue)
  1013.     end
  1014.    gUnitData[gkv][ndKey] = ndValue
  1015.    end
  1016.   end
  1017.  if rdata[f] == "save_md_s" then
  1018.   cReadMode = "M"
  1019.   end
  1020.   if rdata[f] == "gameunitdata_s" then
  1021.   cReadMode = "G"
  1022.   end
  1023.   if cReadMode == "G" and rdata[f] == "{" then
  1024.   cReadMode = "Gv"
  1025.   table.insert(gUnitData,gkv,{})
  1026.   end
  1027.  end
  1028. return aInfo, gUnitData
  1029. end
  1030.  
  1031. -- local dd, cGUData = loadGame("/games/testgame/saves","save_1.save")
  1032.  
  1033. -- saveGame("/games/testgame/saves","save_1.save")
  1034.  
  1035. local vaddsPnts = {vSur=0,vStr=0,vInt=0,vPdm=0,vMdm=0}
  1036.  
  1037. local function playerRefreshVar()
  1038. local vAtds = 8
  1039. local vSur,vStr,vInt,vHpi,vPdm,vMdm,vPdf,vMdf = 0, 0, 0, 0, 0, 0, 0, 0
  1040. local vaPdm, vaMdm = 0, 0
  1041. cGUData[1]["mhp"], mmp, mxp, cGUData[1]["phisatck"], cGUData[1]["magatck"], cGUData[1]["pdef"], cGUData[1]["magdef"] = 0, 0, 0, 0, 0, 0, 0
  1042. local wItemTypes = {
  1043.     "helmet",
  1044.     "bodywear",
  1045.     "pants",
  1046.     "footwear",
  1047.     "pendant",
  1048. }
  1049. --
  1050.  for f = 1, 5 do
  1051.   if inventory["weared"][wItemTypes[f]] ~= 0 then
  1052.    if gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["sur+"] ~= nil then
  1053.    vSur = vSur + gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["sur+"]
  1054.    end  
  1055.    if gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["str+"] ~= nil then
  1056.    vStr = vStr + gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["str+"]
  1057.    end
  1058.    if gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["int+"] ~= nil then
  1059.    vInt = vInt + gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["int+"]
  1060.    end  
  1061.    if gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["hp+"] ~= nil then
  1062.    vHpi = vHpi + gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["hp+"]
  1063.    end
  1064.    if gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["pdm+"] ~= nil then
  1065.    vPdm, vaPdm = vPdm + gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["pdm+"], vaPdm + gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["pdm+"]
  1066.    end  
  1067.    if gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["mdm+"] ~= nil then
  1068.    vMdm, vaMdm = vMdm + gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["mdm+"], vaMdm + gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["mdm+"]
  1069.    end  
  1070.  
  1071.   vPdf = vPdf + gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["pdef"]
  1072.   vMdf = vMdf + gameItemData[inventory["weared"][wItemTypes[f]]]["props"]["magdef"]
  1073.   end
  1074.  end
  1075.  --
  1076.  if inventory["weared"]["weapon"] ~= 0 then
  1077.   if gameItemData[inventory["weared"]["weapon"]]["props"]["sur+"] ~= nil then
  1078.   vSur = vSur + gameItemData[inventory["weared"]["weapon"]]["props"]["sur+"]
  1079.   end
  1080.   if gameItemData[inventory["weared"]["weapon"]]["props"]["str+"] ~= nil then
  1081.   vStr = vStr + gameItemData[inventory["weared"]["weapon"]]["props"]["str+"]
  1082.   end
  1083.   if gameItemData[inventory["weared"]["weapon"]]["props"]["int+"] ~= nil then
  1084.   vInt = vInt + gameItemData[inventory["weared"]["weapon"]]["props"]["int+"]
  1085.   end
  1086.   if gameItemData[inventory["weared"]["weapon"]]["props"]["hp+"] ~= nil then
  1087.   vHpi = vHpi + gameItemData[inventory["weared"]["weapon"]]["props"]["hp+"]
  1088.   end
  1089.   if gameItemData[inventory["weared"]["weapon"]]["props"]["pdm+"] ~= nil then
  1090.   vPdm = vPdm + gameItemData[inventory["weared"]["weapon"]]["props"]["pdm+"]
  1091.   end
  1092.   if gameItemData[inventory["weared"]["weapon"]]["props"]["mdm+"] ~= nil then
  1093.   vMdm = vMdm + gameItemData[inventory["weared"]["weapon"]]["props"]["mdm+"]
  1094.   end
  1095.   if gameItemData[inventory["weared"]["weapon"]]["props"]["pdm+"] ~= nil then
  1096.   vPdm, vaPdm = vPdm + gameItemData[inventory["weared"]["weapon"]]["props"]["pdm+"], vaPdm + gameItemData[inventory["weared"]["weapon"]]["props"]["pdm+"]
  1097.   end  
  1098.   if gameItemData[inventory["weared"]["weapon"]]["props"]["mdm+"] ~= nil then
  1099.   vMdm, vaMdm = vMdm + gameItemData[inventory["weared"]["weapon"]]["props"]["mdm+"], vaMdm + gameItemData[inventory["weared"]["weapon"]]["props"]["mdm+"]
  1100.   end
  1101.  vPdm = cGUData[1]["phisatck"] + gameItemData[inventory["weared"]["weapon"]]["props"]["phisat"]
  1102.  vMdm = cGUData[1]["magatck"] + gameItemData[inventory["weared"]["weapon"]]["props"]["magat"]
  1103.  vAtds = gameItemData[inventory["weared"]["weapon"]]["props"]["atds"]
  1104.  end
  1105. vaddsPnts.vSur, vaddsPnts.vStr, vaddsPnts.vInt, vaddsPnts.vPdm, vaddsPnts.vMdm = vSur, vStr, vInt, vaPdm, vaMdm
  1106. cGUData[1]["mhp"] = math.ceil(4+(survivability+vSur)*11+(cGUData[1]["level"]-1)*7)+vHpi
  1107. mmp = math.ceil(4+(intelligence+vInt)*6+(cGUData[1]["level"]-1)*4)
  1108. mxp = math.ceil(28+(cGUData[1]["level"]-1)*34.7)
  1109. cGUData[1]["phisatck"] = math.floor(1+(strength+vStr-1)*0.9+(cGUData[1]["level"]-1)*0.1525)+vPdm
  1110. cGUData[1]["magatck"] = math.floor(1+(intelligence+vInt-1)*0.25+(cGUData[1]["level"]-1)*0.0125)+vMdm
  1111. cGUData[1]["pdef"] = math.ceil(5+(strength+vStr-1)*29.4+(cGUData[1]["level"]-1)*4.85)+vPdf
  1112. cGUData[1]["magdef"] = math.ceil(5+(intelligence+vInt-1)*22.8+(cGUData[1]["level"]-1)*1.5)+vMdf
  1113. vAttackDistance = vAtds
  1114. end
  1115.  
  1116. local function addXP(value)
  1117.  if mxp-cxp >= value then
  1118.  cxp = cxp + value
  1119.  else
  1120.  value = value - (mxp - cxp)
  1121.  charPoints = charPoints + 1
  1122.  cGUData[1]["level"] = cGUData[1]["level"] + 1
  1123.  playerRefreshVar()
  1124.  cxp = value
  1125.  cGUData[1]["chp"] = cGUData[1]["mhp"]
  1126.  cmp = mmp
  1127.  end
  1128. end
  1129.  
  1130. local function getQuest(quest)
  1131. table.insert(cUquests,{quest,0,false})
  1132. end
  1133.  
  1134. addUnit(1,1,1)
  1135.  
  1136. local function loadWorld(id)
  1137. stopDrawing = true
  1138. cWindowTrd = nil
  1139. cTarget = 0
  1140. cDialog = nil
  1141. paused = false
  1142. dmLoading()
  1143. cGUData[1]["x"], cGlobalx, cBackgroundPos = 1, 1, 1
  1144. local n = cGUData[1]
  1145. cGUData = {}
  1146. cGUData[1] = n
  1147. local cspawnl = world[id].spawnList
  1148.  for f = 1, #cspawnl do
  1149.   if cspawnl[f][4] == nil then
  1150.   addUnit(cspawnl[f][1],cspawnl[f][2],cspawnl[f][3])
  1151.   else
  1152.    for i = 1, cspawnl[f][4] do
  1153.    addUnit(cspawnl[f][1],cspawnl[f][2]+i*cspawnl[f][5]-cspawnl[f][5],cspawnl[f][3])
  1154.    os.sleep()
  1155.    end  
  1156.   end
  1157.  os.sleep()
  1158.  end
  1159. -- nenujnayaVar = 0
  1160. stopDrawing = false
  1161. addsmsg2(world[id].name)
  1162. end
  1163.  
  1164. local function pbar(x,y,size,percent,color1,color2, text, textcolor)
  1165. percent = 100 - percent
  1166. local fill = {}
  1167.  for f = 1, size do
  1168.  table.insert(fill,1)
  1169.  end
  1170.  for f = 1, size do
  1171.   if 100/size*f <= percent then
  1172.   fill[size-f+1] = 0
  1173.   end
  1174.  end
  1175. local color0 = 0x000000
  1176.  for f = 1, size do
  1177.   if fill[f] == 1 then color0 = color1
  1178.   else color0 = color2
  1179.   end
  1180.  buffer.set(x+f-1,y,color0, 0xFFFFFF, " ")
  1181.  buffer.text(x, y, textcolor, text)
  1182.  end
  1183. end
  1184.  
  1185. local function drawCDataUnit()
  1186.  for f = 2, #cGUData do
  1187.   if getDistanceToId(1,f) <= 170 and cGUData[f]["living"] then
  1188.    if cGUData[f]["image"] ~= nil and cGUData[f]["spos"] == "r" then
  1189.    buffer.image(cGUData[f]["x"]+75-cGlobalx,49-cGUData[f]["y"]-cGUData[f]["height"], image.load(cpath.."sprpic/"..cGUData[f]["image"]..".pic"))
  1190.    elseif cGUData[f]["spos"] == "l" then
  1191.    buffer.image(cGUData[f]["x"]+75-cGlobalx,49-cGUData[f]["y"]-cGUData[f]["height"], image.flipHorizontal(image.load(cpath.."sprpic/"..cGUData[f]["image"]..".pic")))
  1192.    end
  1193.    if ( cGUData[f]["rtype"] == "e" or cGUData[f]["rtype"] == "p" or cGUData[f]["rtype"] == "m" ) and cTarget == f then
  1194.    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)
  1195.    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"])))
  1196.    elseif pickingUp and cTarget ~= 0 and pckTarget == f and cGUData[f]["rtype"] == "r" then
  1197.    local vpercentr = math.ceil((maxPckTime-pckTime)*100/maxPckTime)
  1198.    pbar(cGUData[f]["x"]+75-cGlobalx,49-cGUData[f]["y"]-cGUData[f]["height"]-2,8,vpercentr,0x009945,0x444444,vpercentr.."% ",0xFFFFFF)
  1199.    end
  1200.   end
  1201.  end
  1202. end
  1203.  
  1204. local function target(x,y)
  1205. if cTarget ~= 1 and not showTargetInfo then
  1206. cTarget = 0
  1207. end
  1208.  for f = 2, #cGUData do
  1209.   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
  1210.    if cGUData[f]["living"] then
  1211.    cTarget = f
  1212.    console.debug("Выбрать цель","id:",tostring(cTarget),gameUnitData[cGUData[cTarget]["id"]]["name"])
  1213.    end
  1214.   end
  1215.  end
  1216. end
  1217.  
  1218. local fPauselist = {
  1219. "Продолжить игру",
  1220. "Инвентарь",
  1221. "Умения персонажа",
  1222. "Характеристика",
  1223. "Текущие задания",
  1224. "Выйти из игры"
  1225. }
  1226.  
  1227. local function fPause()
  1228. buffer.square(1, 1, 30, 50, 0x9D9D9D, 0xFFFFFF, " ")
  1229. buffer.text(13,2,0xFFFFFF,"Пауза")
  1230.  for f = 1, #fPauselist do
  1231.  buffer.square(1, 2+f*2, 30, 1, 0x838383, 0xFFFFFF, " ")
  1232.  buffer.text(math.max(math.floor((30/2)-(unicode.len(fPauselist[f])/2)),0),2+f*2,0xFFFFFF,fPauselist[f])
  1233.  end
  1234. end
  1235.  
  1236. local svxpbar = false
  1237.  
  1238. local vshowEffDescr, sEffdx, sEffdy = 0, 1, 1
  1239.  
  1240. local function playerCInfoBar(x,y)
  1241. local isTrue = false
  1242. buffer.square(x, y, 25, 5, 0x8C8C8C, 0xFFFFFF, " ")
  1243. local fxpdt = tostring(cxp).."/"..tostring(mxp)
  1244. local percent1 = math.floor(cGUData[1]["chp"]*100/cGUData[1]["mhp"])
  1245. local percent2 = math.floor(cmp*100/mmp)
  1246. local percent3 = math.floor(cxp*100/mxp*10)/10
  1247. buffer.text(x+1, y, 0xFFFFFF, "Уровень "..cGUData[1]["level"])
  1248. local tpbar1 = math.floor(cGUData[1]["chp"]).."/"..math.floor(cGUData[1]["mhp"])
  1249. local tpbar2 = math.floor(cmp).."/"..math.floor(mmp)
  1250. local tpbar3 = percent3.."% "
  1251. if percent3 == 0 then tpbar3 = percent3..".0% " end
  1252. pbar(x,y+1,25,percent1,0xFF0000,0x5B5B5B," ", 0xFFFFFF)
  1253. buffer.text(math.max(math.floor((25/2)-(#tpbar1/2)),0),y+1,0xFFFFFF,tpbar1)
  1254. pbar(x,y+2,25,percent2,0x0000FF,0x5B5B5B," ", 0xFFFFFF)
  1255. buffer.text(math.max(math.floor((25/2)-(#tpbar2/2)),0),y+2,0xFFFFFF,tpbar2)
  1256. pbar(x,y+3,25,percent3,0xFFFF00,0x5B5B5B," ", 0x333333)
  1257. buffer.text(math.max(math.floor((25/2)-(#tpbar3/2)),0),y+3,0x333333,tpbar3)
  1258. if svxpbar then buffer.text(x+25-#fxpdt, y+3, 0x4F4F4F, fxpdt) end
  1259.  for f = 1, math.min(#cGUData[1]["effects"],5) do
  1260.  buffer.square(x+f*3-3+1,y+5,1,1,gameEffectsData[cGUData[1]["effects"][f][1]]["i"][1],0xFFFFFF,gameEffectsData[cGUData[1]["effects"][f][1]]["i"][2])
  1261.  buffer.square(x+f*3-3+2,y+5,1,1,gameEffectsData[cGUData[1]["effects"][f][1]]["i"][3],0xFFFFFF,gameEffectsData[cGUData[1]["effects"][f][1]]["i"][4])
  1262.  end
  1263.  if vshowEffDescr ~= 0 then
  1264.   for g = 1, #cGUData[1]["effects"] do
  1265.    if cGUData[1]["effects"][g][1] == vshowEffDescr then
  1266.    isTrue = true
  1267.    break
  1268.    else
  1269.    isTrue = false
  1270.    vshowEffDescr = 0
  1271.    end
  1272.   end
  1273.   if isTrue then
  1274.   buffer.square(sEffdx,sEffdy,math.max(unicode.len(gameEffectsData[cGUData[1]["effects"][vshowEffDescr][1]]["name"]),unicode.len(gameEffectsData[cGUData[1]["effects"][vshowEffDescr][1]]["descr"])),2,0xA1A1A1,0xFFFFFF," ")
  1275.   buffer.text(sEffdx,sEffdy,0xEDEDED,gameEffectsData[cGUData[1]["effects"][vshowEffDescr][1]]["name"])
  1276.   buffer.text(sEffdx,sEffdy+1,0xCECECE,gameEffectsData[cGUData[1]["effects"][vshowEffDescr][1]]["descr"])
  1277.   end
  1278.  end
  1279. end
  1280.  
  1281. local function sTargetInfo(x,y)
  1282. local sTInfoArray1 = {
  1283.     gameUnitData[cGUData[cTarget]["id"]]["name"],
  1284.     "Тип: "..unicode.sub(gameUnitData[cGUData[cTarget]["id"]]["wtype"],1,22),
  1285.     "Respawn: "..tostring(gameUnitData[cGUData[cTarget]["id"]]["vresp"]).." секунд",
  1286.     "ID: "..tostring(cGUData[cTarget]["id"]),
  1287. }
  1288. local sTInfoArray2 = {
  1289.     "Физ.атака: "..tostring(cGUData[cTarget]["phisatck"]),
  1290.     "Маг.атака: "..tostring(cGUData[cTarget]["magatck"]),
  1291.     "Физ.защита: "..tostring(cGUData[cTarget]["pdef"]),
  1292.     "Маг.защита: "..tostring(cGUData[cTarget]["magdef"]),
  1293. }
  1294. buffer.square(x, y, 25, 9, 0xABABAB, 0xFFFFFF, " ")
  1295.  for f = 1, #sTInfoArray1 do
  1296.  buffer.text(x+1,y+f-1,0xFFFFFF,tostring(sTInfoArray1[f]))
  1297.  end
  1298.  if cGUData[cTarget]["rtype"] ~= "f" then
  1299.   for f = 1, #sTInfoArray2 do
  1300.   buffer.text(x+1,y+f-1+#sTInfoArray1,0xFFFFFF,tostring(sTInfoArray2[f]))
  1301.   end
  1302.  end
  1303. end
  1304.  
  1305. local function targetCInfoBar(x,y)
  1306. local bl = false
  1307. buffer.square(x, y, 35, 5, 0x9B9B9B, 0xFFFFFF, " ")
  1308. if cGUData[cTarget]["rtype"] == "e" or cGUData[cTarget]["rtype"] == "p" or cGUData[cTarget]["rtype"] == "m" then
  1309. local chp, mhp = cGUData[cTarget]["chp"], cGUData[cTarget]["mhp"]
  1310. local pbtext, lbtext = tostring(math.ceil(chp)).."/"..tostring(math.ceil(mhp)), "["..tostring(cGUData[cTarget]["level"]).."] "..gameUnitData[cGUData[cTarget]["id"]]["name"]
  1311. local percent = math.ceil(chp*100/mhp)
  1312. pbar(x,y+1,35,percent,0xFF0000,0x5B5B5B," ", 0xFFFFFF)
  1313. pbar(x,y+2,35,percent,0xFF0000,0x5B5B5B," ", 0xFFFFFF)
  1314. buffer.text(x + (math.max(math.floor((35 / 2) - (unicode.len(pbtext) / 2)), 0)),y+1,0xFFFFFF,pbtext)
  1315. buffer.text(x + (math.max(math.floor((35 / 2) - (unicode.len(lbtext) / 2)), 0)), y+2, 0xFFFFFF, lbtext)
  1316. bl = true
  1317. elseif cGUData[cTarget]["rtype"] == "f" then
  1318. local pntext, lbtext = gameUnitData[cGUData[cTarget]["id"]]["wtype"], gameUnitData[cGUData[cTarget]["id"]]["name"]
  1319. buffer.text(x,y,0x727272,"НИП")
  1320. buffer.text(x + (math.max(math.floor((35 / 2) - (unicode.len(lbtext) / 2)), 0)), y+1, 0xFFFFFF, lbtext)
  1321. buffer.text(x + (math.max(math.floor((35 / 2) - (unicode.len(pntext) / 2)), 0)), y+2, 0x727272, pntext)
  1322. bl = true
  1323. elseif cGUData[cTarget]["rtype"] == "r" then
  1324. buffer.text(x,y,0x727272,"Ресурс")
  1325. local pntext = "Нажмите 'E' чтобы собрать"
  1326. buffer.text(x + (math.max(math.floor((35 / 2) - (unicode.len(gameUnitData[cGUData[cTarget]["id"]]["name"]) / 2)), 0)), y+1, 0xFFFFFF, gameUnitData[cGUData[cTarget]["id"]]["name"])
  1327. buffer.text(x + (math.max(math.floor((35 / 2) - (unicode.len(pntext) / 2)), 0)), y+2, 0x727272, pntext)
  1328. bl = false
  1329. end
  1330. if bl then buffer.text(x+1,y+4,0xFFFFFF,"О персонаже") end
  1331.  for f = 1, math.min(#cGUData[cTarget]["effects"],10) do
  1332.  buffer.square(x+f*3-3+1,y+5,1,1,gameEffectsData[cGUData[cTarget]["effects"][f][1]]["i"][1],0xFFFFFF,gameEffectsData[cGUData[cTarget]["effects"][f][1]]["i"][2])
  1333.  buffer.square(x+f*3-3+2,y+5,1,1,gameEffectsData[cGUData[cTarget]["effects"][f][1]]["i"][3],0xFFFFFF,gameEffectsData[cGUData[cTarget]["effects"][f][1]]["i"][4])
  1334.  end
  1335.  if showTargetInfo then
  1336.  sTargetInfo(x+1,y+5)
  1337.  end
  1338. end
  1339.  
  1340. local vtskillUsingMsg, skillUsingMsg = 0, {}
  1341.  
  1342. local function fSkillBar(x,y)
  1343. buffer.square(x, y, 30, 5, 0x9B9B9B, 0xFFFFFF, " ")
  1344. local sarray = {
  1345. {c = 0x614251, t = "/2"},
  1346. {c = 0x0000FF, t = "*3"},
  1347. {c = 0x008500, t = "@4"},
  1348. {c = 0x8600A0, t = "&5"},
  1349. {c = 0xEE0000, t = "!6"},
  1350. }
  1351.  for f = 1, #sarray do
  1352.  buffer.square(x+4+(f*5-5), y+1, 2, 1, sarray[f].c, 0xFFFFFF, " ")
  1353.  buffer.text(x+4+(f*5-5), y+1, 0xFFFFFF, sarray[f].t)
  1354.  buffer.text(x+4+(f*5-5), y+2, 0xFFFFFF, tostring(cUskills[f+1][2]))
  1355.  end
  1356. if vtskillUsingMsg > 0 then buffer.text(x+1,y+4,0xC1C1C1,skillUsingMsg[#skillUsingMsg]) end
  1357. end
  1358.  
  1359. local function drawDialog(x,y)
  1360. local sColor
  1361. local isQnComp, isQcomp = false, false
  1362.  for f = 1, #cDialog do
  1363.   isQnComp = false
  1364.   if cDialog[#cDialog-f+1] ~= nil then
  1365.    if cDialog[#cDialog-f+1]["action"] == "qdialog" then
  1366.     for l = 1, #cUquests do
  1367.      if cUquests[l][1] == cDialog[#cDialog-f+1]["q"] and cUquests[l][3] == false then
  1368.      isQnComp = true
  1369.      break
  1370.      end
  1371.     end
  1372.    end
  1373.    if cDialog[#cDialog-f+1] ~= nil and cDialog[#cDialog-f+1]["action"] == "qdialog" then
  1374.     if isQnComp or gameQuestsData[cDialog[#cDialog-f+1]["q"]]["minlvl"] > cGUData[1]["level"] then
  1375.     table.remove(cDialog,#cDialog-f+1)
  1376.     end
  1377.    elseif cDialog[#cDialog-f+1]["action"] == "setWorld" and cGUData[1]["level"] < cDialog[#cDialog-f+1]["reqlvl"] then
  1378.    cDialog[#cDialog-f+1]["text"] = unicode.sub(cDialog[#cDialog-f+1]["text"],1,unicode.len(cDialog[#cDialog-f+1]["text"])-#tostring(cDialog[#cDialog-f+1]["reqlvl"])-2)
  1379.    cDialog[#cDialog-f+1]["text"] = cDialog[#cDialog-f+1]["text"].." "..cDialog[#cDialog-f+1]["reqlvl"].."+"
  1380.    end
  1381.   end
  1382.  end
  1383. buffer.square(x, y, 50, 24, 0x9B9B9B, 0xFFFFFF, " ")
  1384. buffer.square(x, y, 50, 1, 0x606060, 0xFFFFFF, " ")
  1385. buffer.square(x+1, y+1, 48, 12, 0x7A7A7A, 0xFFFFFF, " ")
  1386. buffer.square(x+1, y+14, 48, 9, 0x7A7A7A, 0xFFFFFF, " ")
  1387. buffer.text(x+49,y,0xFFFFFF,"X")
  1388. local text1 = gameUnitData[cGUData[cTarget]["id"]]["name"]
  1389. buffer.text(x+(math.max(math.floor((50 / 2) - (unicode.len(text1) / 2)), 0)), y, 0xFFFFFF, text1)
  1390.  for f = 1, math.ceil(#cDialog["text"]/46) do
  1391.  buffer.text(x+2,y+1+f,0xFFFFFF,unicode.sub(cDialog["text"],1+f*46-46,f*46))
  1392.  end
  1393.  for f = 1, #cDialog do
  1394.  sColor = 0xFFFFFF
  1395.  isQnComp, isQcomp = false, false
  1396.   for l = 1, #cUquests do
  1397.    if cDialog[f]["action"] == "qdialog" then
  1398.    if cUquests[l][1] == cDialog[f]["q"] and not cUquests[l][3] then isQnComp = true end
  1399.    elseif cDialog[f]["action"] == "cmpquest" then isQcomp = true
  1400.    end
  1401.   end  
  1402.   if isQnComp then
  1403.   sColor = 0x555555
  1404.   elseif isQcomp then
  1405.   sColor = 0x1AB235
  1406.   end
  1407.  buffer.text(x+2,y+14+f,sColor,cDialog[f]["text"])
  1408.  end
  1409. end
  1410.  
  1411. local function itemSubtypeToRus(subtype)
  1412. local massiv = {
  1413. ["helmet"] = "Шлем",
  1414. ["bodywear"] = "Броня",
  1415. ["pants"] = "Штаны",
  1416. ["footwear"] = "Сапоги",
  1417. ["pendant"] = "Кулон",
  1418. ["sword"] = "Меч",
  1419. ["spear"] = "Копье",
  1420. ["axe"] = "Короткая секира",
  1421. }
  1422. return massiv[subtype]
  1423. end
  1424.  
  1425. local invTItem = 0
  1426. local invcTItem, invcTargetItem, showItemData = 0, 0, false
  1427. local invIdx, invIdy = 1, 1
  1428.  
  1429. local function getItemInfoWColor(id)
  1430. local info = {}
  1431. local function giiwcAdd(t,c) table.insert(info,{tostring(t),c}) end
  1432. local itemtype, itemsubtype = gameItemData[id]["type"], gameItemData[id]["subtype"]
  1433. giiwcAdd(gameItemData[id]["name"], gameItemData[id]["ncolor"])
  1434.  if itemtype == "armor" or itemtype == "weapon" then
  1435.  giiwcAdd(lang(itemSubtypeToRus(itemsubtype)), 0xBCBCBC)
  1436.  giiwcAdd(lang("Уровень").." "..tostring(gameItemData[id]["level"]), 0xFFFFFF)
  1437.  end
  1438.  if itemtype == "weapon" then
  1439.  giiwcAdd(lang("Дальность атаки:").." "..gameItemData[id]["props"]["atds"], 0xEFEFEF)
  1440.  end
  1441.  if itemtype == "item" and itemsubtype == "res" then
  1442.  giiwcAdd(lang("Уровень материала").." "..tostring(gameItemData[id]["level"]), 0xFFFFFF)
  1443.  end
  1444.  if itemtype == "armor" then
  1445.  if gameItemData[id]["props"]["pdef"] ~= 0 then giiwcAdd("Защита +"..tostring(gameItemData[id]["props"]["pdef"]), 0xFFFFFF) end
  1446.  if gameItemData[id]["props"]["magdef"] ~= 0 then giiwcAdd("Магическая защита +"..tostring(gameItemData[id]["props"]["magdef"]), 0xFFFFFF) end
  1447.  elseif itemtype == "weapon" then
  1448.  if gameItemData[id]["props"]["phisat"] ~= 0 then giiwcAdd("Физическая атака "..tostring(gameItemData[id]["props"]["phisat"]), 0xFFFFFF) end
  1449.  if gameItemData[id]["props"]["magat"] ~= 0 then giiwcAdd("Магическая атака "..tostring(gameItemData[id]["props"]["magat"]), 0xFFFFFF) end
  1450.  end
  1451.  if itemtype == "armor" or itemtype == "weapon" or itemtype == "potion" then
  1452.   if gameItemData[id]["subtype"] == "health" then
  1453.   giiwcAdd("Восстановить "..tostring(gameEffectsData[1]["val"][gameItemData[id]["level"]]).." ед. здоровья за 10 секунд", 0xFFFFFF)
  1454.   elseif gameItemData[id]["subtype"] == "mana" then
  1455.   giiwcAdd("Восстановить "..tostring(gameEffectsData[2]["val"][gameItemData[id]["level"]]).." ед. маны за 10 секунд", 0xFFFFFF)
  1456.   end
  1457.   if gameItemData[id]["reqlvl"] > cGUData[1]["level"] then
  1458.   giiwcAdd(lang("Требуемый уровень:").." "..gameItemData[id]["reqlvl"], 0xFF0000)
  1459.   else
  1460.   giiwcAdd(lang("Требуемый уровень:").." "..gameItemData[id]["reqlvl"], 0xFFFFFF)
  1461.   end
  1462. if itemtype == "armor" or itemtype == "weapon" then
  1463. local spisok1 = {
  1464.     {"hp+","Здоровье"},
  1465.     {"sur+","Выживаемость"},
  1466.     {"str+","Сила"},
  1467.     {"int+","Интеллект"},
  1468.     {"pdm+","Атака"},
  1469.     {"mdm+","Магическая атака"},
  1470. }
  1471.    for e = 1, #spisok1 do
  1472.     if gameItemData[id]["props"][spisok1[e][1]] ~= nil and gameItemData[id]["props"][spisok1[e][1]] ~= 0 then
  1473.     giiwcAdd(lang(spisok1[e][2]).." + "..gameItemData[id]["props"][spisok1[e][1]], 0x0044ee)
  1474.     end  
  1475.    end
  1476. end
  1477.  end
  1478.  if gameItemData[id]["description"] ~= "" then
  1479.   for f = 1, math.ceil(unicode.len(gameItemData[id]["description"])/35) do
  1480.   giiwcAdd(unicode.sub(gameItemData[id]["description"],1+f*35-35,f*35), 0xBCBCBC)
  1481.   end
  1482.  end
  1483. local v = ""
  1484. if invTItem > 1 then v = " ("..tostring(gameItemData[id]["cost"]*invTItem)..")" end
  1485. giiwcAdd(lang("Цена").." "..tostring(gameItemData[id]["cost"])..v, 0xFFFFFF)
  1486. return info
  1487. end
  1488.  
  1489. local function drawInventory(x,y)
  1490. buffer.square(x, y, 160, 50, 0x9B9B9B, 0xFFFFFF, " ")
  1491. buffer.square(x, y, 160, 1, 0x525252, 0xFFFFFF, " ")
  1492. buffer.square(x, y+49, 160, 1, 0x525252, 0xFFFFFF, " ")
  1493. buffer.square(x, y+1, 105, 45, 0x767676, 0xFFFFFF, " ")
  1494.  for f = 1, 5 do
  1495.  buffer.square(x, y+1+(f*11-11), 105, 1, 0x4A4A4A, 0xFFFFFF, " ")
  1496.  end
  1497.   for f = 1, 6 do
  1498.  buffer.square(x+(f*21-21), y+1, 1, 45, 0x4A4A4A, 0xFFFFFF, " ")
  1499.  end
  1500. buffer.image(x+105, y+1, image.load(cpath.."image/gGrid.pic"))
  1501. buffer.text(x+1,y,0xC4C4C4,"Монеты:".." "..tostring(cCoins))
  1502. buffer.text(x+75,y,0xFFFFFF,"Инвентарь")
  1503. buffer.text(x+152,y,0xFFFFFF,"Закрыть")
  1504. local xps, yps
  1505.  for f = 1, 4 do
  1506.   for i = 1, 5 do
  1507.   xps, yps = x+1+i*21-21, y+2+f*11-11
  1508.   local formula = (f-1)*5+i
  1509.    if inventory["bag"][formula][1] ~= 0 and inventory["bag"][formula][2] ~= 0 then
  1510.    buffer.image(xps, yps, image.load(cpath.."itempic/"..aItemIconsSpr[gameItemData[inventory["bag"][formula][1]]["icon"]]..".pic"))
  1511.     if inventory["bag"][formula][2] > 1 then
  1512.     buffer.square(xps, yps+9, #tostring(inventory["bag"][formula][2]), 1, 0x4A4A4A, 0xFFFFFF, " ")
  1513.     buffer.text(xps,yps+9,0xFFFFFF,tostring(inventory["bag"][formula][2]))
  1514.     end
  1515.    end
  1516.   end
  1517.  end
  1518. local wItemTypes = {
  1519.     "helmet",
  1520.     "bodywear",
  1521.     "pants",
  1522.     "weapon",
  1523.     "footwear",
  1524.     "pendant",
  1525. }
  1526.  for f = 1, 3 do
  1527.   for i = 1, 2 do
  1528.    xps, yps = 107+i*21-21, 3+f*11-11
  1529.    if inventory["weared"][wItemTypes[(f-1)*2+i]] ~= 0 then
  1530.    buffer.image(xps, yps, image.load(cpath.."itempic/"..aItemIconsSpr[gameItemData[inventory["weared"][wItemTypes[(f-1)*2+i]]]["icon"]]..".pic"))
  1531.    end
  1532.   end
  1533.  end
  1534. buffer.text(2,48,0x444444,sMSG3)
  1535. local textRemoveItem = "Выбросить предмет(ы)"
  1536.  if showItemData and invcTItem ~= 0 then
  1537.  local itemInfo = getItemInfoWColor(invcTItem)
  1538.  local hn, w, h = 0, 0, #itemInfo
  1539.   for f = 1, #itemInfo do
  1540.   if unicode.len(itemInfo[f][1]) > w then w = unicode.len(itemInfo[f][1]) end
  1541.   end
  1542.  buffer.square(math.min(invIdx,160-w), math.min(invIdy,50-h), w, h, 0x7E7E7E, 0xFFFFFF, " ")
  1543.   for f = 1, #itemInfo do
  1544.   buffer.text(math.min(invIdx,160-w),math.min(invIdy+f-1,50-h+f),itemInfo[f][2],itemInfo[f][1])
  1545.   end
  1546.  buffer.square(x+1,y+46,unicode.len(textRemoveItem),1,0x3c539e, 0xFFFFFF," ")
  1547.  buffer.text(x+1,y+46,0xFEFEFE,textRemoveItem)
  1548.  end
  1549. end
  1550.  
  1551. local function unicodeframe(x,y,w,h,c)
  1552. buffer.text(x,y,c,"┌"..string.rep("─",w-2).."┐")
  1553.  for f = 1, h-2 do
  1554.  buffer.text(x,y+f,c,"│")
  1555.  buffer.text(x+w-1,y+f,c,"│")
  1556.  end
  1557. buffer.text(x,y+h-1,c,"└"..string.rep("─",w-2).."┘")
  1558. end
  1559.  
  1560. local tradew = {
  1561.     twindow = 0,
  1562.     titem = 0,
  1563.     titemcount = 1,
  1564.     sect = 1,
  1565.     tScrl = 1
  1566. }
  1567.  
  1568. local smw, smh = 50, 15
  1569.  
  1570. local function tradeWindow(x,y)
  1571. buffer.square(x, y, 160, 50, 0x9B9B9B, 0xFFFFFF, " ")
  1572. buffer.square(x, y, 160, 1, 0x525252, 0xFFFFFF, " ")
  1573. buffer.square(x, y+1, 160, 3, 0x747474, 0xFFFFFF, " ")
  1574. local hclr
  1575. local t = "Торговля"
  1576. buffer.text(math.max(80-(unicode.len(t)/2), 0), y, 0xFFFFFF, t)
  1577. buffer.text(x+1,y+3,0xC2C2C2,"Наименование")
  1578. buffer.text(x+65,y+3,0xC2C2C2,"Цена за единицу")
  1579. buffer.text(x+152,y,0xFFFFFF,"Закрыть")
  1580. buffer.text(x+1,y+2,0xFFFFFF,"Монеты "..cCoins)
  1581. local massiv = gameTradew[tradew.twindow][tradew.sect]
  1582. local t1
  1583.  for f = 1, #gameTradew[tradew.twindow] do
  1584.  t1 = unicode.sub(gameTradew[tradew.twindow][f]["section_name"],1,25)
  1585.  if tradew.sect == f then hclr = 0x525252 else hclr = 0x606060 end
  1586.  buffer.square(x+1+f*26-26, y+1, 25, 1, hclr, 0xFFFFFF, " ")
  1587.  buffer.text(x+1+f*26-26, y+1, 0xCCCCCC, t1)
  1588.  end
  1589.  for f = 1, math.min(#massiv, 24) do
  1590.  if f+4*tradew.tScrl-4 == tradew.titem then buffer.square(x+1,y+4+f*2-2, 160, 3, 0x818181, 0xFFFFFF, " ") end
  1591.  end
  1592.  for f = 1, math.min(#massiv+1, 24) do
  1593.  buffer.text(x+1,y+4+f*2-2,0xFFFFFF,string.rep("─",158))
  1594.  end
  1595.  for f = 1, math.min(#massiv, 24) do
  1596.  buffer.text(x+1,y+4+f*2-1,0xFFFFFF,gameItemData[massiv[f+4*tradew.tScrl-4]["item"]]["name"])
  1597.  buffer.text(x+65,y+4+f*2-1,0xFFFFFF,tostring(massiv[f+4*tradew.tScrl-4]["cost"]))
  1598.  end
  1599. local clr, smx, smy, tn = 0xCCCCCC
  1600. tn = "Купить"
  1601.  if tradew.titem ~= 0 then
  1602.  smx, smy = math.floor(80-smw/2), math.floor(25-smh/2)
  1603.  buffer.square(smx, smy, smw, smh, 0x828282, 0xFFFFFF, " ")
  1604.  unicodeframe(smx, smy, smw, smh, 0x4c4c4c)
  1605.  buffer.square(smx-23, smy, 22, 12, 0x828282, 0xFFFFFF, " ")
  1606.  buffer.image(smx-22, smy+1, image.load(cpath.."itempic/"..aItemIconsSpr[gameItemData[massiv[tradew.titem]["item"]]["icon"]]..".pic"))
  1607.  buffer.text(smx+smw-2, smy, 0x4c4c4c, "X")
  1608.  buffer.text(smx+(smw/2-unicode.len(gameItemData[massiv[tradew.titem]["item"]]["name"])/2), smy+1, clr, gameItemData[massiv[tradew.titem]["item"]]["name"])
  1609.  buffer.text(smx+1,smy+2, clr, "Покупка предмета")
  1610.  buffer.text(smx+1,smy+3, clr, "Количество:")
  1611.  buffer.square(smx+13, smy+3, #tostring(tradew.titemcount)+4, 1, 0x616161, 0xFFFFFF, " ")
  1612.  buffer.text(smx+13,smy+3, clr, "+ "..tradew.titemcount.." -")
  1613.  buffer.text(smx+1,smy+4, clr, "Цена: "..massiv[tradew.titem]["cost"])
  1614.  local td
  1615.  if tradew.titemcount*massiv[tradew.titem]["cost"] <= cCoins then td = clr else td = 0xb71202 end
  1616.  buffer.text(smx+1,smy+5, td, "Сумма: "..tostring(tradew.titemcount*massiv[tradew.titem]["cost"]))
  1617.  buffer.square(smx, smy+smh, smw, 3, 0x0054cb5, 0xFFFFFF, " ")
  1618.  buffer.text(smx+(smw/2-unicode.len(tn)/2), smy+smh+1, clr, tn)
  1619.  end
  1620. end
  1621.  
  1622. local cCnsScroll = 1
  1623.  
  1624. local function gameConsole(x,y)
  1625. buffer.square(x, y, 60, 35, 0xABABAB, 0xFFFFFF, " ")
  1626. buffer.square(x, y, 60, 1, 0x525252, 0xFFFFFF, " ")
  1627. buffer.square(x+1, y+1, 58, 31, 0x1A1A1A, 0xFFFFFF, " ")
  1628. buffer.square(x+1, y+33, 58, 1, 0x1A1A1A, 0xFFFFFF, " ")
  1629. local bColor, bSub
  1630. local text1 = "debug"
  1631. buffer.text(x+(math.max(math.floor((60 / 2) - (unicode.len(text1) / 2)), 0)), y, 0xFFFFFF, text1)
  1632. buffer.text(x+59,y,0xFFFFFF,"X")
  1633.  for f = 1, math.min(#consDataR,28) do
  1634.   if consDataR[f+(cCnsScroll*4-4)] then
  1635.    if unicode.sub(consDataR[f+(cCnsScroll*4-4)],1,2) == "!/" then
  1636.    bColor = 0xFF0000
  1637.    bSub = 3
  1638.    else
  1639.    bColor = 0xFFFFFF
  1640.    bSub = 1
  1641.    end
  1642.   buffer.text(x+2,y+2+f,bColor,unicode.sub(consDataR[f+(cCnsScroll*4-4)],bSub,56))
  1643.   end
  1644.  end
  1645. end
  1646.  
  1647. local function remFirstSmfromString(str,cs)
  1648. local s = unicode.sub(str,1,1)
  1649.  if s == cs then
  1650.  return unicode.sub(str,2,#str)
  1651.  end
  1652. return str
  1653. end
  1654.  
  1655. local targetQuest = 0
  1656.  
  1657. local function questsList(x,y)
  1658. buffer.square(x, y, 100, 25, 0xABABAB, 0xFFFFFF, " ")
  1659. buffer.square(x, y, 100, 1, 0x525252, 0xFFFFFF, " ")
  1660. buffer.text(x+45,y,0xFFFFFF,"Задания")
  1661. buffer.text(x+92,y,0xFFFFFF,"Закрыть")
  1662. buffer.square(x+2, y+2, 29, 22, 0x7A7A7A, 0xFFFFFF, " ")
  1663. buffer.square(x+32, y+2, 66, 22, 0x7A7A7A, 0xFFFFFF, " ")
  1664.  for f = 1, math.min(#cUquests,20) do
  1665.  if cUquests[f][3] then buffer.text(x+3,y+3+f,0x00C222,"→") end
  1666.  buffer.text(x+4,y+3+f,0xDDDDDD,unicode.sub(gameQuestsData[cUquests[f][1]]["name"],1,28))
  1667.  end
  1668.  if targetQuest > 0 and cUquests[targetQuest] ~= nil then
  1669.  local qDeskList = {}
  1670.  local dstr
  1671.   for i = 1, math.floor(#gameQuestsData[cUquests[targetQuest][1]]["descr"]/60) do
  1672.   dstr = remFirstSmfromString(remFirstSmfromString(unicode.sub(gameQuestsData[cUquests[targetQuest][1]]["descr"],1+(60*i-60),60*i),",")," ")
  1673.   table.insert(qDeskList, dstr)
  1674.   end
  1675.  local qInfoList = {
  1676.     "Награда:",
  1677.     "Монеты "..tostring(gameQuestsData[cUquests[targetQuest][1]]["qreward"]["coins"]),
  1678.     "Опыт "..tostring(gameQuestsData[cUquests[targetQuest][1]]["qreward"]["xp"]),
  1679.     }
  1680.   table.insert(qInfoList,1,"Описание:")
  1681.   for i = 1, #qDeskList do
  1682.   table.insert(qInfoList,i+1,qDeskList[i])
  1683.   end
  1684.   if gameQuestsData[cUquests[targetQuest][1]]["type"] == "k" then
  1685.   table.insert(qInfoList,1,"Уничтожить: "..gameUnitData[gameQuestsData[cUquests[targetQuest][1]]["targ"]]["name"].." ("..cUquests[targetQuest][2].."/"..gameQuestsData[cUquests[targetQuest][1]]["num"]..")")
  1686.   end
  1687.   if gameQuestsData[cUquests[targetQuest][1]]["qreward"]["item"] ~= nil then
  1688.   table.insert(qInfoList,"Предмет:")
  1689.    for o = 1, #gameQuestsData[cUquests[targetQuest][1]]["qreward"]["item"] do
  1690.    table.insert(qInfoList,unicode.sub(gameItemData[gameQuestsData[cUquests[targetQuest][1]]["qreward"]["item"][o][1]]["name"].." ("..tostring(gameQuestsData[cUquests[targetQuest][1]]["qreward"]["item"][o][2])..")",1,45))
  1691.    end
  1692.   end
  1693.  buffer.text(x+33,y+3,0xFFFFFF,unicode.sub(gameQuestsData[cUquests[targetQuest][1]]["name"],1,60))
  1694.   for f = 1, #qInfoList do
  1695.   buffer.text(x+33,y+3+f,0xFFFFFF,qInfoList[f])
  1696.   end
  1697.  end
  1698. end
  1699.  
  1700. local pstatspntrs={x=0,y=0}
  1701.  
  1702. local chPointsAss = {0,0,0,0} -- не надо менять этот массив, читеры!
  1703.  
  1704. local function playerStats(x,y)
  1705. buffer.square(x, y, 100, 35, 0xABABAB, 0xFFFFFF, " ")
  1706. buffer.square(x, y, 100, 1, 0x525252, 0xFFFFFF, " ")
  1707. local someText = "Персонаж"
  1708. buffer.text(x+(math.max(50-(unicode.len(someText)/2),0)),y,0xFFFFFF,someText)
  1709. buffer.text(x+92,y,0xFFFFFF,"Закрыть")
  1710. local info1 = {
  1711.     "Имя персонажа: "..gameUnitData[cGUData[1]["id"]]["name"],
  1712.     "Уровень: "..cGUData[1]["level"],
  1713.     "Здоровье: "..tostring(math.floor(cGUData[1]["chp"]*10)/10).."/"..math.floor(cGUData[1]["mhp"]),
  1714.     "Мана: "..tostring(math.floor(cmp*10)/10).."/"..math.floor(mmp),
  1715.     "Опыт: "..cxp.."/"..mxp.." ("..tostring(math.floor(cxp*100/mxp*10)/10).."%)",
  1716.     "Физическая атака: "..cGUData[1]["phisatck"]+vaddsPnts.vPdm,
  1717.     "Магическая атака: "..cGUData[1]["magatck"]+vaddsPnts.vMdm,
  1718.     "Физическая защита: "..cGUData[1]["pdef"],
  1719.     "Магическая защита: "..cGUData[1]["magdef"],   
  1720. }
  1721.  for f = 1, #info1 do
  1722.  buffer.text(x+3,y+1+f,0xFFFFFF,info1[f])
  1723.  end
  1724. pstatspntrs.x, pstatspntrs.y = x+3, y+14
  1725. buffer.square(x+3, y+14, 37, 4, 0x898989, 0xFFFFFF, " ")
  1726. buffer.text(x+4,y+14,0xFFFFFF,"Очков для распределния "..charPoints)
  1727. buffer.text(x+4,y+15,0xEEEEEE,"Интеллект")
  1728. buffer.text(x+17,y+15,0xCECECE,tostring(intelligence+chPointsAss[1]+vaddsPnts.vInt))
  1729. buffer.text(x+4,y+16,0xEEEEEE,"Сила")
  1730. buffer.text(x+17,y+16,0xCECECE,tostring(strength+chPointsAss[2]+vaddsPnts.vStr))
  1731. buffer.text(x+4,y+17,0xEEEEEE,"Выносливость")
  1732. buffer.text(x+17,y+17,0xCECECE,tostring(survivability+chPointsAss[3]+vaddsPnts.vSur))
  1733.  for f = 1, 3 do
  1734.  buffer.square(x+20, y+14+f, 3, 1, 0x727272, 0xFFFFFF, " ")
  1735.  buffer.text(x+21,y+14+f,0xEEEEEE,"+")
  1736.  buffer.square(x+24, y+14+f, 3, 1, 0x727272, 0xFFFFFF, " ")
  1737.  buffer.text(x+25,y+14+f,0xEEEEEE,"-")
  1738.  end
  1739.  buffer.square(x+28, y+15, 9, 1, 0x737373, 0xFFFFFF, " ")
  1740.  buffer.text(x+28,y+15,0xEEEEEE,"→Принять")
  1741.  buffer.square(x+28, y+17, 9, 1, 0x737373, 0xFFFFFF, " ")
  1742.  buffer.text(x+28,y+17,0xEEEEEE,"×отменить")
  1743. end
  1744.  
  1745. local function killUnitWithoutAnyLoot(id)
  1746. cGUData[id]["living"] = false
  1747. cGUData[id]["resptime"] = gameUnitData[cGUData[id]["id"]]["vresp"]
  1748. end
  1749.  
  1750. local function getRandSeq(massiv)
  1751. -- эта функция перемешивает значения переменной (костыль)
  1752. local new = {}
  1753.  for e = 1, #massiv do
  1754.  new[e] = "_n"
  1755.  end
  1756. local nrandom
  1757.  for f = 1, #massiv do
  1758.  nrandom = math.random(1,#massiv)
  1759.  table.insert(new,nrandom,massiv[f])
  1760.  end
  1761.  for e = 1, #new do if new[#new-e+1] == "_n" then table.remove(new,#new-e+1) end end
  1762. return new
  1763. end
  1764.  
  1765. local function makeDamage(id, damage)
  1766.  if cGUData[id]["chp"] > damage then
  1767.  cGUData[id]["attPlayer"] = true
  1768.  cGUData[id]["chp"] = cGUData[id]["chp"] - damage
  1769.  console.debug("Урон нанесен персонажу",gameUnitData[cGUData[id]["id"]]["name"],tostring(damage):sub(1,5))
  1770.  elseif cGUData[id]["chp"] <= damage then
  1771.  cGUData[id]["effects"] = {}
  1772.  cGUData[id]["attPlayer"] = false
  1773.  console.debug("Урон нанесен персонажу",gameUnitData[cGUData[id]["id"]]["name"],tostring(damage):sub(1,5))
  1774.  cGUData[id]["chp"] = 0
  1775.  cGUData[id]["living"] = false
  1776.  cGUData[id]["resptime"] = gameUnitData[cGUData[id]["id"]]["vresp"]
  1777.  local expr = math.ceil(gameUnitData[cGUData[id]["id"]]["loot"]["exp"]+math.random(-gameUnitData[cGUData[id]["id"]]["loot"]["exp"]*0.1,gameUnitData[cGUData[id]["id"]]["loot"]["exp"]*0.1))
  1778.  addXP(expr)
  1779.   for f = 1, #cUquests do
  1780.    if cGUData[id]["id"] == gameQuestsData[cUquests[f][1]]["targ"] and cUquests[f][3] == false then
  1781.     if cUquests[f][2] + 1 < gameQuestsData[cUquests[f][1]]["num"] then
  1782.     cUquests[f][2] = cUquests[f][2] + 1
  1783.     else
  1784.     gameQuestsData[cUquests[f][1]]["comp"] = true
  1785.     cUquests[f][2] = gameQuestsData[cUquests[f][1]]["num"]
  1786.     cUquests[f][3] = true
  1787.     addsmsg1("Задание "..gameQuestsData[cUquests[f][1]]["name"].." выполнено!")
  1788.     end
  1789.    end
  1790.   end
  1791.  local coinsLoot = gameUnitData[cGUData[id]["id"]]["loot"]["coins"]
  1792.  local giveCoins = math.ceil(math.random(coinsLoot-coinsLoot*0.5,coinsLoot+coinsLoot*0.1))
  1793.  cCoins = cCoins + giveCoins
  1794.  local itemLoot = getRandSeq(gameUnitData[cGUData[id]["id"]]["loot"]["items"])
  1795.  local nitemid
  1796.   for f = 1, #itemLoot do
  1797.    if itemLoot[f][1] ~= nil and 1000-itemLoot[f][2]*10 <= math.random(1,1000) then
  1798.    if math.random(1,15) == 5 then itemLoot[f][1] = createNewItem(itemLoot[f][1]) end
  1799.    addItem(itemLoot[f][1],1)
  1800.    console.debug("Получен предмет "..gameItemData[itemLoot[f][1]]["name"])
  1801.    addsmsg1("Получен предмет "..gameItemData[itemLoot[f][1]]["name"])
  1802.    break
  1803.    end
  1804.   end
  1805.  cGUData[id]["resptime"] = gameUnitData[cGUData[id]["id"]]["vresp"]
  1806.  console.debug("опыт +",expr,"монеты +",giveCoins)
  1807.  if id == cTarget then cTarget = 0 end
  1808.  showTargetInfo = false
  1809.  end
  1810. end
  1811.  
  1812. local function playerGetDamage(fromID)
  1813.  if cGUData[fromID]["x"] > cGUData[1]["x"] then
  1814.  cGUData[fromID]["spos"] = "l"
  1815.  else
  1816.  cGUData[fromID]["spos"] = "r"
  1817.  end
  1818. local patck = cGUData[fromID]["phisatck"]
  1819. local dmgRed = cGUData[1]["pdef"]/(cGUData[1]["pdef"]+cGUData[fromID]["level"]*85)
  1820. local damage = math.max(math.random(patck-patck*0.5,patck+patck*0.5)*(1-dmgRed),0.01)
  1821. if cTarget == 0 then cTarget = fromID end
  1822.  if damage < cGUData[1]["chp"] then
  1823.  cGUData[1]["chp"] = cGUData[1]["chp"] - damage
  1824.  else
  1825.  cGUData[1]["living"] = false
  1826.  end
  1827. return damage
  1828. end
  1829.  
  1830. local function useSkill(skill)
  1831. local cskill = cUskills[skill][1]
  1832. local damage = 0
  1833.  if gameSkillsData[cskill]["type"] == "attack" and cGUData[cTarget]["rtype"] ~= "p" and cGUData[cTarget]["rtype"] ~= "f" and cGUData[cTarget]["rtype"] ~= "r" then
  1834.   if cGUData[cTarget]["x"] > cGUData[1]["x"] then
  1835.   cGUData[1]["spos"] = "r"
  1836.   else
  1837.   cGUData[1]["spos"] = "l"
  1838.   end
  1839.  local physDefRedu = cGUData[cTarget]["pdef"]/(cGUData[cTarget]["pdef"]+cGUData[1]["level"]*85)
  1840.  local magDefRedu = cGUData[cTarget]["magdef"]/(cGUData[cTarget]["magdef"]+cGUData[1]["level"]*85)
  1841.   if gameSkillsData[cskill]["typedm"] == "p" then
  1842.   damage = math.max((cGUData[1]["phisatck"]+math.random(gameSkillsData[cskill]["mindamage"][cUskills[skill][3]],gameSkillsData[cskill]["maxdamage"][cUskills[skill][3]]))*(1-physDefRedu),0.1)
  1843.   elseif gameSkillsData[cskill]["typedm"] == "m" then
  1844.   damage = math.max((cGUData[1]["magatck"]+math.random(gameSkillsData[cskill]["mindamage"][cUskills[skill][3]],gameSkillsData[cskill]["maxdamage"][cUskills[skill][3]]))*(1-magDefRedu),0.1)
  1845.   end
  1846.   if cmp >= gameSkillsData[cskill]["manacost"][cUskills[skill][3]] and cUskills[skill][2] == 0 and getDistanceToId(1,cTarget) <= vAttackDistance+gameSkillsData[cskill]["distance"] then
  1847.   cmp = cmp - gameSkillsData[cskill]["manacost"][cUskills[skill][3]]
  1848.   makeDamage(cTarget, damage)
  1849.   if gameSkillsData[cskill]["eff"] ~= nil then addUnitEffect(cTarget,gameSkillsData[cskill]["eff"],cUskills[skill][3]) end
  1850.   cUskills[skill][2] = gameSkillsData[cskill]["reloading"]
  1851.   vtskillUsingMsg = 3
  1852.   table.insert(skillUsingMsg,gameSkillsData[cskill]["name"])
  1853.   end
  1854.  elseif gameSkillsData[cskill]["type"] == "buff" and cmp >= gameSkillsData[cskill]["manacost"][cUskills[skill][3]] and cUskills[skill][2] == 0 then
  1855.  cmp = cmp - gameSkillsData[cskill]["manacost"][cUskills[skill][3]]
  1856.  if gameSkillsData[cskill]["eff"] ~= nil then addUnitEffect(1,gameSkillsData[cskill]["eff"],cUskills[skill][3]) end
  1857.  end
  1858. end
  1859.  
  1860. local sram
  1861.  
  1862. local function dmain()
  1863.  if cWindowTrd ~= "inventory" and cWindowTrd ~= "tradeWindow" then
  1864.  world[world.current].draw()
  1865.   if cGUData[1]["spos"] == "r" then buffer.image(playerSprPicPos, 34, image.load(cpath.."sprpic/"..cGUData[1]["image"]..".pic"))
  1866.   else buffer.image(playerSprPicPos, 34, image.flipHorizontal(image.load(cpath.."sprpic/"..cGUData[1]["image"]..".pic")))
  1867.   end
  1868.  drawCDataUnit()
  1869.   if cWindowTrd ~= "screen_save" then
  1870.   playerCInfoBar(1,1)
  1871.   if cTarget ~= 0 then targetCInfoBar(60,1) end
  1872.   fSkillBar(110,1)
  1873.   buffer.text(156,2,0xFFFFFF,"█ █")
  1874.   buffer.text(156,3,0xFFFFFF,"█ █")
  1875.    if smsg1time > 0 then
  1876.    buffer.text(9,49,0x929292,">"..sMSG1[#sMSG1-1])
  1877.    buffer.text(9,50,0xC7C7C7,">"..sMSG1[#sMSG1])
  1878.    end
  1879.    if smsg2time > 0 then
  1880.    buffer.text(80-unicode.len(sMSG2[#sMSG2])/2,12,0xD3D3D3,sMSG2[#sMSG2])
  1881.    end
  1882.   end
  1883.  end
  1884. if cWindowTrd == "pause" then
  1885. fPause()
  1886. elseif cWindowTrd == "inventory" then
  1887. drawInventory(1,1)
  1888. elseif cWindowTrd == "dialog" then
  1889. drawDialog(12,11)
  1890. elseif cWindowTrd == "quests" then
  1891. questsList(30,15)
  1892. elseif cWindowTrd == "console" then
  1893. gameConsole(50,10)
  1894. elseif cWindowTrd == "pstats" then
  1895. playerStats(30,8)
  1896. elseif cWindowTrd == "tradeWindow" then
  1897. tradeWindow(1,1)
  1898. end
  1899. if #cUquests > 0 and cUquests[1][3] == true then buffer.text(50,50,0xFFFFFF,"#### quest 1 true") end
  1900. buffer.text(1,50,0xFFFFFF,"fps: "..tostring(cfps))
  1901. sram = tostring(math.floor((computer.totalMemory()-computer.freeMemory())/1024)).." KB/"..tostring(math.ceil(computer.totalMemory()/1048576*10)/10).." MB"
  1902. buffer.text(160-#sram,50,0xC7C7C7,sram)
  1903. buffer.draw()
  1904. end
  1905.  
  1906. local fPauseMenuAction = {
  1907. [1]=function()
  1908. cWindowTrd = nil
  1909. paused = false
  1910. end,
  1911. [2]=function()
  1912. cWindowTrd = "inventory"
  1913. end,
  1914. [3]=function()
  1915.  
  1916. end,
  1917. [4]=function()
  1918. cWindowTrd = "pstats"
  1919. end,
  1920. [5]=function()
  1921. cWindowTrd = "quests"
  1922. end,
  1923. [6]=function()
  1924. ingame = false
  1925. end,
  1926. }
  1927.  
  1928. loadWorld(world.current)
  1929. playerRefreshVar()
  1930. cGUData[1]["chp"] = cGUData[1]["mhp"]
  1931. cmp = mmp
  1932. dmain()
  1933.  
  1934. local uMoveRef = 1
  1935. local healthReg, manaReg
  1936.  
  1937. local function functionPS()
  1938. local value, duration, efftype
  1939. local itemLootarray
  1940.  while ingame do
  1941.  cfps = gamefps
  1942.  gamefps = 0
  1943.   if not paused then
  1944.   if cTarget ~= 0 and getDistanceToId(1,cTarget) > 99 then cTarget = 0 end
  1945.   playerRefreshVar()
  1946.   uMoveRef = uMoveRef - 1
  1947.   if vtskillUsingMsg > 0 then vtskillUsingMsg = vtskillUsingMsg - 1 end
  1948.   manaReg = math.min(0.26+(cGUData[1]["level"]-1)*0.015,2)
  1949.   healthReg = math.min(0.08+(cGUData[1]["level"]-1)*0.008,1)
  1950.    for f = 1, #cUskills do
  1951.     if cUskills[f][1] > 0 and cUskills[f][2] > 0 then
  1952.     cUskills[f][2] = cUskills[f][2] - 1
  1953.     end
  1954.    end
  1955.    
  1956.    if cGUData[1]["living"] then
  1957.     -- восстановление маны персонажа
  1958.     if cmp < mmp - manaReg then
  1959.     cmp = cmp + manaReg
  1960.     else
  1961.     cmp = mmp
  1962.     end
  1963.    
  1964.     -- восстановление здоровья персонажа
  1965.     if cGUData[1]["chp"] < cGUData[1]["mhp"] - healthReg then
  1966.     cGUData[1]["chp"] = cGUData[1]["chp"] + healthReg
  1967.     else
  1968.     cGUData[1]["chp"] = cGUData[1]["mhp"]
  1969.     end
  1970.    end
  1971.  
  1972.    for f = 2, #cGUData do
  1973.     -- респавн юнитов
  1974.     if not cGUData[f]["living"] and cGUData[f]["resptime"] > 0 then
  1975.     cGUData[f]["resptime"] = cGUData[f]["resptime"] - 1
  1976.     end
  1977.     if not cGUData[f]["living"] and cGUData[f]["resptime"] == 0 then
  1978.     cGUData[f]["chp"] = cGUData[f]["mhp"]
  1979.     cGUData[f]["x"] = cGUData[f]["sx"]
  1980.     cGUData[f]["living"] = true
  1981.     end
  1982.     -- рандомное движение мобов
  1983.     if getDistanceToId(1,f) <= 320 and cGUData[f]["rtype"] == "e" and cGUData[f]["living"] and math.random(1,3) == 3 and uMoveRef == 0 then
  1984.     cGUData[f]["mx"] = cGUData[f]["sx"] + math.random(-16, 16)
  1985.     end
  1986.     if getDistanceToId(1,f) <= 140 and cGUData[f]["x"] ~= cGUData[f]["mx"] then
  1987.     movetoward(f, cGUData[f]["mx"], 100, 1)
  1988.     end    
  1989.     -- теперь мобы могут бить вашего персонажа >:D
  1990.     if cGUData[f]["living"] and getDistanceToId(1,f) <= 60 and cGUData[f]["attPlayer"] == true then
  1991.      if getDistanceToId(1,f) > gameUnitData[cGUData[f]["id"]]["atds"] then
  1992.       if cGUData[f]["x"] > cGUData[1]["x"] then
  1993.       cGUData[f]["spos"] = "l"
  1994.       cGUData[f]["mx"] = cGUData[1]["x"]+cGUData[1]["width"]+gameUnitData[cGUData[f]["id"]]["atds"]
  1995.       else
  1996.       cGUData[f]["spos"] = "r"
  1997.       cGUData[f]["mx"] = cGUData[1]["x"]-gameUnitData[cGUData[f]["id"]]["atds"]
  1998.       end
  1999.      else
  2000.      cGUData[f]["mx"] = cGUData[f]["x"]
  2001.      playerGetDamage(f)
  2002.      end
  2003.     end
  2004.     if cGUData[f]["living"] and cGUData[f]["attPlayer"] == true and getDistanceToId(1,f) > 60  then
  2005.     cGUData[f]["attPlayer"] = false
  2006.     cGUData[f]["mx"] = cGUData[f]["sx"]
  2007.     end
  2008.     if not cGUData[f]["living"] and cGUData[f]["attPlayer"] and cGUData[f]["agr"] == true and getDistanceToId(1,f) <= cGUData[f]["atds"]*2 then
  2009.     cGUData[f]["attPlayer"] = true
  2010.     end  
  2011.    end
  2012.    -- обслуживание всех эффектов на всех объектах
  2013.    for f = 1, #cGUData do
  2014.     for eff = 1, #cGUData[f]["effects"] do
  2015.      if cGUData[f]["living"] and cGUData[f]["effects"][#cGUData[f]["effects"]-eff+1] ~= nil then
  2016.      value = gameEffectsData[cGUData[f]["effects"][#cGUData[f]["effects"]-eff+1][1]]["val"][cGUData[f]["effects"][#cGUData[f]["effects"]-eff+1][3]]
  2017.      duration = gameEffectsData[cGUData[f]["effects"][#cGUData[f]["effects"]-eff+1][1]]["dur"][cGUData[f]["effects"][#cGUData[f]["effects"]-eff+1][3]]
  2018.      efftype = gameEffectsData[cGUData[f]["effects"][#cGUData[f]["effects"]-eff+1][1]]["type"]
  2019.       if efftype == "hpi" then
  2020.        if cGUData[f]["chp"] + value/duration < cGUData[f]["mhp"] then
  2021.        cGUData[f]["chp"] = cGUData[f]["chp"] + value/duration
  2022.        else cGUData[f]["chp"] = cGUData[f]["mhp"]
  2023.        end
  2024.       elseif efftype == "mpi" then
  2025.        if cmp + value/duration < mmp then
  2026.        cmp = cmp + value/duration
  2027.        else cmp = mmp
  2028.        end
  2029.       elseif efftype == "hpd" then
  2030.       makeDamage(f,value/duration)
  2031.       elseif efftype == "pdfi%" then
  2032.       cGUData[1]["pdef"] = cGUData[1]["pdef"]+math.ceil(value/100*cGUData[1]["pdef"])
  2033.       end
  2034.       if cGUData[f]["effects"][#cGUData[f]["effects"]-eff+1] ~= nil then
  2035.       cGUData[f]["effects"][#cGUData[f]["effects"]-eff+1][2] = cGUData[f]["effects"][#cGUData[f]["effects"]-eff+1][2] - 1
  2036.       end
  2037.       if cGUData[f]["effects"][#cGUData[f]["effects"]-eff+1][2] == 0 then
  2038.       vshowEffDescr = 0
  2039.       table.remove(cGUData[f]["effects"],#cGUData[f]["effects"]-eff+1)
  2040.       end
  2041.      end
  2042.     end
  2043.    end
  2044.    ------------------------------------------------
  2045.    if smsg1time > 0 then
  2046.    smsg1time = smsg1time - 1
  2047.    end
  2048.    if smsg2time > 0 then
  2049.    smsg2time = smsg2time - 1
  2050.    end
  2051.    if pickingUp then
  2052.    cGUData[1]["mx"] = cGUData[1]["x"]
  2053.    pckTime = pckTime - 1
  2054.    end
  2055.    if pickingUp and pckTime == 0 then
  2056.    cGUData[1]["image"] = gameUnitData[1]["image"]
  2057.    pickingUp = false
  2058.    itemLootarray = getRandSeq(gameUnitData[cGUData[pckTarget]["id"]]["items"])
  2059.     for item = 1, #itemLootarray do
  2060.      if itemLootarray[item][1] ~= nil and 1000-itemLootarray[item][2]*10 <= math.random(1,1000) then
  2061.      if math.random(1,15) == 5 then itemLootarray[item][1] = createNewItem(itemLootarray[item][1]) end
  2062.      addItem(itemLootarray[item][1],1)
  2063.      console.debug("Получен предмет "..gameItemData[itemLootarray[item][1]]["name"])
  2064.      addsmsg1("Получен предмет "..gameItemData[itemLootarray[item][1]]["name"])
  2065.      break
  2066.      end
  2067.     end
  2068.    addXP(gameUnitData[cGUData[pckTarget]["id"]]["exp"])
  2069.    cCoins = cCoins + gameUnitData[cGUData[pckTarget]["id"]]["coins"]
  2070.    playerCanMove = true
  2071.    cGUData[pckTarget]["living"] = false
  2072.    cGUData[pckTarget]["resptime"] = gameUnitData[cGUData[pckTarget]["id"]]["vresp"]
  2073.    if pckTarget == cTarget then cTarget = 0 end
  2074.    end
  2075.   if uMoveRef <= 0 then uMoveRef = 8 end
  2076.  
  2077.  
  2078.   setScreenNewPosition() -- отображает часть мира независимо от координат игрока
  2079.   if sScreenTimer1 > 0 then sScreenTimer1 = sScreenTimer1 - 1 end
  2080.  
  2081.  
  2082.  
  2083.   end
  2084.  os.sleep(1)
  2085.  end
  2086. end
  2087.  
  2088. local function funcPrQfsec()
  2089.  while ingame do
  2090.   if not paused then
  2091.    if cGUData[1]["x"] ~= cGUData[1]["mx"] then
  2092.    playerAutoMove(cGUData[1]["mx"], 3555, 3)
  2093.    end
  2094.   end
  2095.  os.sleep(0.25)
  2096.  end
  2097. end
  2098.  
  2099. local function scrRef()
  2100.  while ingame do
  2101.   if not stopDrawing then
  2102.   gamefps = gamefps + 1
  2103.   dmain()
  2104.   end
  2105.  os.sleep(0.035)
  2106.  end
  2107. end
  2108.  
  2109. local someVar1
  2110. local plcmx
  2111.  
  2112. cCoins = 152
  2113.  
  2114. local function fInGame()
  2115. local vseffdescrig
  2116. local pItem
  2117. local mpcktime
  2118. while ingame do
  2119. vseffdescrig = false
  2120. someVar1 = true
  2121. local ev, p2, p3, p4, p5 = event.pull()
  2122.  if ev == "key_down" then
  2123.   if p4 == 44 then ingame = false end
  2124.  
  2125.   if p4 == 205 and not paused and cGUData[1]["x"] <= world[world.current].limitR and playerCanMove then -- right
  2126.    if keyboard.isAltDown() then
  2127.    cGUData[1]["mx"] = world[world.current].limitR
  2128.    else
  2129.    cGUData[1]["x"] = cGUData[1]["x"] + 2
  2130.    cGlobalx = cGlobalx + 2
  2131.    cBackgroundPos = cBackgroundPos + 2
  2132.    cGUData[1]["spos"] = "r"
  2133.    cGUData[1]["mx"] = cGUData[1]["x"]
  2134.    end
  2135.   elseif p4 == 203 and not paused and cGUData[1]["x"] >= world[world.current].limitL and playerCanMove then -- left
  2136.    if keyboard.isAltDown() then
  2137.    cGUData[1]["mx"] = world[world.current].limitL
  2138.    else
  2139.    cGUData[1]["x"] = cGUData[1]["x"] - 2
  2140.    cGlobalx = cGlobalx - 2
  2141.    cBackgroundPos = cBackgroundPos - 2
  2142.    cGUData[1]["spos"] = "l"
  2143.    cGUData[1]["mx"] = cGUData[1]["x"]
  2144.    end
  2145.   end
  2146.   if not paused then
  2147.    for f = 1, 6 do
  2148.     if cTarget ~= 0 and p4 == 1+f and cUskills[f][1] ~= 0 and gameSkillsData[cUskills[f][1]]["type"] ~= "buff" then
  2149.      if cGUData[cTarget]["mx"] > cGUData[1]["x"] then
  2150.      plcmx = cGUData[cTarget]["mx"] - (vAttackDistance+gameSkillsData[cUskills[f][1]]["distance"]) - cGUData[1]["width"]
  2151.      else
  2152.      plcmx = cGUData[cTarget]["mx"] + cGUData[cTarget]["width"] + (vAttackDistance+gameSkillsData[cUskills[f][1]]["distance"])
  2153.      end     
  2154.      if getDistanceToId(1,cTarget) > vAttackDistance+gameSkillsData[cUskills[f][1]]["distance"] then
  2155.      cGUData[1]["mx"] = plcmx
  2156.      plcmx = cGUData[1]["x"]
  2157.      elseif getDistanceToId(1,cTarget) <= vAttackDistance+gameSkillsData[cUskills[f][1]]["distance"] then
  2158.      useSkill(f)
  2159.      plcmx = cGUData[1]["x"]
  2160.      cGUData[1]["mx"] = cGUData[1]["x"]
  2161.      end
  2162.     elseif p4 == 1+f and cUskills[f][1] ~= 0 and gameSkillsData[cUskills[f][1]]["type"] == "buff" then
  2163.     useSkill(f)
  2164.     end
  2165.    end
  2166.   end
  2167.   if not paused and cTarget ~= 0 and cGUData[cTarget]["rtype"] == "f" and p4 == 18 and getDistanceToId(1,cTarget) <= 40 then
  2168.   cGUData[1]["mx"] = cGUData[1]["x"]
  2169.   paused = true
  2170.   cWindowTrd = "dialog"
  2171.   cDialog = dialogs[cGUData[cTarget]["dialog"]]
  2172.   cDialog = insertQuests(cTarget,cDialog)
  2173.   end
  2174.   if not pickingUp and not paused and cTarget ~= 0 and cGUData[cTarget]["rtype"] == "r" and p4 == 18 and getDistanceToId(1,cTarget) <= 11 then
  2175.   pckTarget = cTarget
  2176.   pickingUp = true
  2177.   mpcktime = math.random(gameUnitData[cGUData[cTarget]["id"]]["mnprs"],gameUnitData[cGUData[cTarget]["id"]]["mxprs"])
  2178.   pckTime, maxPckTime = mpcktime, mpcktime
  2179.   playerCanMove = false
  2180.   cGUData[1]["image"] = "player_pck"
  2181.   cGUData[1]["mx"] = cGUData[1]["x"]
  2182.   end
  2183.   if not paused and p4 == 46 then
  2184.   paused = true
  2185.   cCnsScroll = math.floor(#consDataR/4)
  2186.   cWindowTrd = "console"
  2187.   end
  2188.  end
  2189.   if p4 == 1 and cWindowTrd == nil and ESC == "pause" then
  2190.   cWindowTrd = "pause"
  2191.   paused = true  
  2192.   elseif p4 == 1 and cWindowTrd == "pause" and ESC == "pause" then
  2193.   cWindowTrd = nil
  2194.   paused = false
  2195.   end
  2196.  if ev == "touch" then
  2197.   if cWindowTrd == nil and not paused then
  2198.    if clicked(p3,p4,1,4,25,4) then
  2199.    svxpbar = true
  2200.    else
  2201.    svxpbar = false
  2202.    end
  2203.   end
  2204.  if cWindowTrd == nil and cTarget ~= 0 and p5 == 0 and gameUnitData[cGUData[cTarget]["id"]]["rtype"] ~= "r" and clicked(p3,p4,60,5,71,5) then showTargetInfo = true
  2205.  elseif cWindowTrd == nil and cTarget ~= 0 and p5 == 0 and not clicked(p3,p4,60,5,71,5) then showTargetInfo = false end
  2206.  if p5 == 0 and clicked(p3,p4,1,1,25,5) and cWindowTrd == nil and not paused then cTarget = 1 end
  2207.   if p5 == 0 and clicked(p3,p4,156,2,158,3) and cWindowTrd == nil then
  2208.   cWindowTrd = "pause"
  2209.   paused = true
  2210.   elseif p5 == 0 and clicked(p3,p4,156,2,158,3) and cWindowTrd == "pause" then
  2211.   cWindowTrd = nil
  2212.   paused = false
  2213.   end
  2214.  
  2215.   if p5 == 0 and not paused then target(p3,p4) end
  2216.  
  2217.   if p5 == 0 and not paused then
  2218.    for f = 1, math.min(#cGUData[1]["effects"],5) do
  2219.     if clicked(p3,p4,f*3-1,6,1+f*3,6) then
  2220.     vseffdescrig = true
  2221.     vshowEffDescr, sEffdx, sEffdy = f, p3, p4+1
  2222.     break
  2223.     end
  2224.    end
  2225.   end
  2226.   if not vseffdescrig then vshowEffDescr, sEffdx, sEffdy = 0, 1, 1 end
  2227.   if p5 == 0 and cWindowTrd == "pause" then
  2228.    for f = 1, #fPauselist do
  2229.     if clicked(p3,p4,1,2+f*2,30,2+f*2) then
  2230.     fPauseMenuAction[f]()
  2231.     p3, p4 = 0, 0
  2232.     break
  2233.     end
  2234.    end
  2235.   elseif cWindowTrd == "inventory" then
  2236.    if clicked(p3,p4,152,1,159,1) then
  2237.    cWindowTrd = "pause"
  2238.    end
  2239.    if showItemData and invcTargetItem ~= 0 and clicked(p3,p4,2,47,12,47) then
  2240.    inventory["bag"][invcTargetItem] = {0,0}
  2241.    showItemData, invcTargetItem = false, 0
  2242.    end
  2243.   local fbParam = true
  2244.   local nwitemuwr, xps, yps
  2245.    for f = 1, 4 do
  2246.     for i = 1, 5 do
  2247.     xps, yps = 2+i*21-21, 3+f*11-11
  2248.     local formula = (f-1)*5+i
  2249.      if inventory["bag"][formula][1] ~= 0 and inventory["bag"][formula][2] ~= 0 then
  2250.       if clicked(p3,p4,xps,yps,xps+19,yps+9) then
  2251.       pItem = gameItemData[inventory["bag"][formula][1]]
  2252.        if p5 == 0 then
  2253.        invcTItem = inventory["bag"][formula][1]
  2254.        invcTargetItem = formula
  2255.        invTItem = inventory["bag"][formula][2]
  2256.        showItemData = true
  2257.        invIdx, invIdy = p3, p4
  2258.        fbParam = false
  2259.        break
  2260.        else
  2261.         if pItem["type"] == "armor" and cGUData[1]["level"] >= pItem["reqlvl"] then
  2262.          if inventory["weared"][pItem["subtype"]] == 0 then
  2263.          inventory["weared"][pItem["subtype"]] = inventory["bag"][formula][1]
  2264.          inventory["bag"][formula][1] = 0
  2265.          inventory["bag"][formula][2] = 0
  2266.          else
  2267.          nwitemuwr = inventory["weared"][pItem["subtype"]]
  2268.          inventory["weared"][pItem["subtype"]] = inventory["bag"][formula][1]
  2269.          inventory["bag"][formula][1] = 0
  2270.          inventory["bag"][formula][2] = 0
  2271.          addItem(nwitemuwr,1)
  2272.          end
  2273.         elseif pItem["type"] == "weapon" and cGUData[1]["level"] >= pItem["reqlvl"] then
  2274.          if inventory["weared"]["weapon"] == 0 then
  2275.          inventory["weared"]["weapon"] = inventory["bag"][formula][1]
  2276.          inventory["bag"][formula][1] = 0
  2277.          inventory["bag"][formula][2] = 0
  2278.          else
  2279.          nwitemuwr = inventory["weared"]["weapon"]
  2280.          inventory["weared"]["weapon"] = inventory["bag"][formula][1]
  2281.          inventory["bag"][formula][1] = 0
  2282.          inventory["bag"][formula][2] = 0
  2283.          addItem(nwitemuwr,1)
  2284.          end
  2285.         elseif pItem["type"] == "chest" then
  2286.          for t = 1, #pItem["props"] do
  2287.           if 1000-pItem["props"][t][3]*10 <= math.random(1,1000) then
  2288.           addItem(pItem["props"][t][1],pItem["props"][t][2])
  2289.           break
  2290.           end
  2291.          end
  2292.         addsmsg3(unicode.sub(os.date(), #os.date()-7, #os.date()).." Использован предмет "..pItem["name"])
  2293.         inventory["bag"][formula][2] = inventory["bag"][formula][2] - 1
  2294.         elseif pItem["type"] == "tlp" then
  2295.         cGUData[1]["x"], cGlobalx, cBackgroundPos = 1, 1, 1
  2296.         addsmsg3(unicode.sub(os.date(), #os.date()-7, #os.date()).." Использован предмет "..pItem["name"])
  2297.         inventory["bag"][formula][2] = inventory["bag"][formula][2] - 1
  2298.         elseif pItem["type"] == "potion" and cGUData[1]["level"] >= pItem["reqlvl"] then
  2299.          if pItem["subtype"] == "health" then
  2300.          addPlayerEffect(1,pItem["level"])
  2301.          inventory["bag"][formula][2] = inventory["bag"][formula][2] - 1
  2302.          elseif pItem["subtype"] == "mana" then
  2303.          addPlayerEffect(2,pItem["level"])
  2304.          inventory["bag"][formula][2] = inventory["bag"][formula][2] - 1
  2305.          end
  2306.         addsmsg3(unicode.sub(os.date(), #os.date()-7, #os.date()).." Использован предмет "..pItem["name"])
  2307.         end
  2308.        nwitemuwr = nil
  2309.        break
  2310.        end
  2311.       end
  2312.      end
  2313.     end
  2314.    end
  2315.   local wItemTypes = {
  2316.       "helmet",
  2317.       "bodywear",
  2318.       "pants",
  2319.       "weapon",
  2320.       "footwear",
  2321.       "pendant",
  2322.   }
  2323.    for f = 1, 3 do
  2324.     for i = 1, 2 do
  2325.      xps, yps = 107+i*21-21, 3+f*11-11
  2326.      if inventory["weared"][wItemTypes[(f-1)*2+i]] ~= 0 then
  2327.       if clicked(p3,p4,xps,yps,xps+19,yps+9) then
  2328.        if p5 == 0 then
  2329.        invcTItem = inventory["weared"][wItemTypes[(f-1)*2+i]]
  2330.        invTItem = 1
  2331.        showItemData = true
  2332.        invIdx, invIdy = p3, p4
  2333.        fbParam = false
  2334.        break
  2335.        else
  2336.        addItem(inventory["weared"][wItemTypes[(f-1)*2+i]],1)
  2337.        inventory["weared"][wItemTypes[(f-1)*2+i]] = 0
  2338.        end
  2339.       end
  2340.      end
  2341.     end
  2342.    end
  2343.    if fbParam then
  2344.    invcTargetItem = 0
  2345.    invTItem = 0
  2346.    showItemData = false
  2347.    invIdx, invIdy = 1, 1
  2348.    end
  2349.  playerRefreshVar()
  2350.  elseif cWindowTrd == "dialog" then
  2351.    for f = 1, #cDialog do
  2352.     if cDialog[f]["action"] == "getquest" and gameQuestsData[cDialog[f]["do"]]["comp"] == true then
  2353.     table.remove(cDialog[f])
  2354.     end
  2355.    end
  2356.    for f = 1, #cDialog do
  2357.     if p5 == 0 and clicked(p3,p4,14,25+f,58,25+f) then
  2358.      if cDialog[f]["action"] == "close" then
  2359.      cWindowTrd = nil
  2360.      cDialog = nil
  2361.      paused = false
  2362.      elseif cDialog[f]["action"] == "trade" then
  2363.      tradew.twindow = cDialog[f]["do"]
  2364.      tradew.sect = 1
  2365.      cWindowTrd = "tradeWindow"
  2366.      elseif cDialog[f]["action"] == "dialog" or cDialog[f]["action"] == "qdialog" then
  2367.      cDialog = cDialog[f]["do"]
  2368.      elseif cDialog[f]["action"] == "getquest" and gameQuestsData[cDialog[f]["do"]]["comp"] == 0 then
  2369.      getQuest(cDialog[f]["do"])
  2370.      gameQuestsData[cDialog[f]["do"]]["comp"] = false
  2371.      cWindowTrd = nil
  2372.      cDialog = nil
  2373.      paused = false
  2374.      elseif cDialog[f]["action"] == "cmpquest" then
  2375.       for t = 1, #cUquests do
  2376.        if cUquests[t][1] == cDialog[f]["do"] and cUquests[t][3] then
  2377.        -- *награда за задание*
  2378.        addXP(gameQuestsData[cDialog[f]["do"]]["qreward"]["xp"])
  2379.        cCoins = cCoins + gameQuestsData[cDialog[f]["do"]]["qreward"]["coins"]
  2380.         if gameQuestsData[cDialog[f]["do"]]["qreward"]["item"] ~= 0 then
  2381.          for u = 1, #gameQuestsData[cDialog[f]["do"]]["qreward"]["item"] do
  2382.          addItem(gameQuestsData[cDialog[f]["do"]]["qreward"]["item"][u][1],gameQuestsData[cDialog[f]["do"]]["qreward"]["item"][u][2])
  2383.          end
  2384.         end
  2385.        gameQuestsData[cDialog[f]["do"]]["comp"] = true
  2386.        table.remove(cUquests,t)
  2387.        cWindowTrd = nil
  2388.        cDialog = nil
  2389.        paused = false
  2390.        break
  2391.        end
  2392.       end
  2393.      elseif cDialog[f]["action"] == "setWorld" and cGUData[1]["level"] >= cDialog[f]["reqlvl"] then
  2394.      world.current = cDialog[f]["do"]
  2395.      loadWorld(world.current)
  2396.      end
  2397.     end
  2398.    end
  2399.    if clicked(p3,p4,61,11,61,11) then
  2400.    cWindowTrd = nil
  2401.    cDialog = nil
  2402.    paused = false  
  2403.    end
  2404.   elseif cWindowTrd == "quests" then
  2405.    if p5 == 0 and clicked(p3,p4,122,15,129,15) then
  2406.    cWindowTrd = "pause"
  2407.    end
  2408.    for f = 1, #cUquests do
  2409.     if cUquests[f] ~= nil and clicked(p3,p4,32,18+f,60,18+f) then
  2410.     someVar1 = false
  2411.     targetQuest = f
  2412.     break
  2413.     end
  2414.    if not someVar1 then targetQuest = 0 end
  2415.    end
  2416.   elseif cWindowTrd == "console" then
  2417.    if p5 == 0 and clicked(p3,p4,109,10,109,10) then
  2418.    cWindowTrd = nil
  2419.    paused = false
  2420.    end
  2421.   elseif cWindowTrd == "pstats" then
  2422.   if p5 == 0 and clicked(p3,p4,122,8,129,8) then cWindowTrd = "pause" end
  2423.    for t = 1, 3 do
  2424.     if p5 == 0 and charPoints > 0 and clicked(p3,p4,pstatspntrs.x+17,pstatspntrs.y+t,pstatspntrs.x+20,pstatspntrs.y+t) then
  2425.     chPointsAss[t] = chPointsAss[t] + 1
  2426.     charPoints = charPoints - 1
  2427.     chPointsAss[4] = chPointsAss[4] + 1
  2428.     elseif p5 == 0 and charPoints > 0 and clicked(p3,p4,pstatspntrs.x+22,pstatspntrs.y+t,pstatspntrs.x+25,pstatspntrs.y+t) and chPointsAss[t] > 0 then
  2429.     chPointsAss[t] = chPointsAss[t] - 1
  2430.     charPoints = charPoints + 1
  2431.     chPointsAss[4] = chPointsAss[4] - 1
  2432.     end
  2433.    end
  2434.    if p5 == 0 and clicked(p3,p4,pstatspntrs.x+28,pstatspntrs.y+1,pstatspntrs.x+34,pstatspntrs.y+1) then
  2435.    intelligence = intelligence + chPointsAss[1]
  2436.    strength = strength + chPointsAss[2]
  2437.    survivability = survivability + chPointsAss[3]
  2438.    chPointsAss = {0,0,0,0}
  2439.    playerRefreshVar()
  2440.    elseif p5 == 0 and chPointsAss[4] > 0 and clicked(p3,p4,pstatspntrs.x+28,pstatspntrs.y+3,pstatspntrs.x+34,pstatspntrs.y+3) then
  2441.    charPoints = charPoints + chPointsAss[4]
  2442.    chPointsAss = {0,0,0,0}
  2443.    playerRefreshVar()
  2444.    end
  2445.   elseif cWindowTrd == "tradeWindow" then
  2446.    if p5 == 0 and clicked(p3,p4,152,1,159,1) then
  2447.     tradew = {
  2448.     twindow = 1,
  2449.     titem = 0,
  2450.     titemcount = 1,
  2451.     sect = 1,
  2452.     tScrl = 1
  2453.     }
  2454.    cWindowTrd = nil
  2455.    cDialog = nil
  2456.    paused = false
  2457.    end
  2458.    if tradew.titem == 0 then
  2459.     for f = 1, #gameTradew[tradew.twindow] do
  2460.      if p5 == 0 and clicked(p3,p4,2+f*26-26, 2, 2+f*25, 2) then
  2461.      tradew.sect = f
  2462.      end
  2463.     end
  2464.     for f = 1, math.min(#gameTradew[tradew.twindow][tradew.sect], 24) do
  2465.      if clicked(p3,p4,2,5+f*2-2,160,5+f*2) then
  2466.      tradew.titem = f+4*tradew.tScrl-4
  2467.      end
  2468.     end
  2469.    else
  2470.     if p5 == 0 and gameItemData[gameTradew[tradew.twindow][tradew.sect][tradew.titem]["item"]]["stackable"] and tradew.titemcount < 100 and clicked(p3,p4,math.floor(80-smw/2)+13, math.floor(25-smh/2)+3,math.floor(80-smw/2)+13, math.floor(25-smh/2)+3) then -- +
  2471.     tradew.titemcount = tradew.titemcount + 1
  2472.     elseif p5 == 0 and tradew.titemcount > 1 and clicked(p3,p4,math.floor(80-smw/2)+16+#tostring(tradew.titemcount), math.floor(25-smh/2)+3,math.floor(80-smw/2)+16+#tostring(tradew.titemcount), math.floor(25-smh/2)+3) then -- -
  2473.     tradew.titemcount = tradew.titemcount - 1
  2474.     end
  2475.     if clicked(p3,p4,math.floor(80-smw/2),math.floor(25-smh/2)+smh,math.floor(80-smw/2)+smw,math.floor(25-smh/2)+smh+3) and cCoins >= tradew.titemcount*gameTradew[tradew.twindow][tradew.sect][tradew.titem]["cost"] then
  2476.     cCoins = cCoins - tradew.titemcount*gameTradew[tradew.twindow][tradew.sect][tradew.titem]["cost"]
  2477.     addItem(gameTradew[tradew.twindow][tradew.sect][tradew.titem]["item"],tradew.titemcount)
  2478.     tradew.titem = 0
  2479.     tradew.titemcount = 1  
  2480.     end
  2481.     if clicked(p3,p4,math.floor(80-smw/2)+smw-2, math.floor(25-smh/2),math.floor(80-smw/2)+smw-2, math.floor(25-smh/2)) then
  2482.     tradew.titem = 0
  2483.     tradew.titemcount = 1
  2484.     end
  2485.    end
  2486.   end
  2487.  end
  2488.  if ev == "scroll" then
  2489.   if cWindowTrd == "console" then
  2490.    if clicked(p3,p4,50,10,109,42) and p5 == 1 and cCnsScroll > 1 then
  2491.    cCnsScroll = cCnsScroll - 1
  2492.    elseif clicked(p3,p4,50,10,109,42) and p5 == -1 and math.ceil(cCnsScroll*4) < #consDataR then
  2493.    cCnsScroll = cCnsScroll + 1
  2494.    end
  2495.   end
  2496.  end
  2497. end
  2498. end
  2499.  
  2500. thread.create(fInGame)
  2501. thread.create(scrRef)
  2502. thread.create(functionPS)
  2503. thread.create(funcPrQfsec)
  2504.  
  2505. thread.waitForAll()
  2506.  
  2507. gpu.setBackground(0x000000)
  2508. gpu.setForeground(0xFFFFFF)
  2509. term.clear()
  2510. term.setCursor(1,1)
  2511. io.write("Wirthe16 game "..TextVersion)
Add Comment
Please, Sign In to add comment