Advertisement
ReDestroyDeR

Untitled

Nov 5th, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.21 KB | None | 0 0
  1. --------------------------------------
  2.  
  3. -- Импорты
  4.  
  5. local com = require("component")
  6. local ss = require("term")
  7. local st = require("serialization")
  8. local tt = require("text")
  9. local fs = require("filesystem")
  10. local event = require("event")
  11. local cl = require("gpuColors")
  12. local getUUID = require("uuid").next()
  13.  
  14. -- ОМГ ОМГ ЭТО ЖЕ АХУЕТЬ КАКОЙ ВАЖНЫЙ КОМПОНЕНТ
  15. -- ( да )
  16.  
  17. local mdm = com.modem
  18. local gpu = com.gpu
  19.  
  20. -------------------------------------------------
  21.  
  22. --СТАНДАРТНЫЕ ФУНКЦИИ ДЛЯ МОДЕМА
  23.  
  24. local function openP(port)
  25.  
  26. return mdm.open(port)
  27.  
  28. end
  29.  
  30. local function closeP(port)
  31.  
  32. return mdm.close(port)
  33.  
  34. end
  35.  
  36. local function send(ip,port,message)
  37.  
  38. return mdm.send(ip,port,message)
  39.  
  40. end
  41.  
  42. local function broadcast(port,message)
  43.  
  44. return mdm.broadcast(port,message)
  45.  
  46. end
  47.  
  48. local function getMDM(port)
  49.  
  50. open(port)
  51.  
  52. local function getMessage()
  53.  
  54. while true do
  55.  
  56. local e = {event.pull()}
  57.  
  58. if e[1] == "modem_message" then
  59.  
  60. return e[6]
  61.  
  62. end
  63.  
  64. end
  65.  
  66. end
  67.  
  68. local function getIP()
  69.  
  70. while true do
  71.  
  72. local e = {event.pull()}
  73.  
  74. if e[1] == "modem_message" then
  75.  
  76. return e[2]
  77.  
  78. end
  79.  
  80. end
  81.  
  82. end
  83.  
  84. end
  85.  
  86. ----------------------------------------------------------------------------------
  87.  
  88. --Номера строк что бы работала память компа, а не моя. Ну а хуле нам, програмистам
  89.  
  90. --MainFile
  91.  
  92. local m_ln_playername = 1
  93. local m_ln_uuid = 2
  94. local m_ln_currentweaponid = 3
  95. local m_ln_startdate = 4
  96. local m_ln_rank = 5
  97. local m_ln_localmodemadress = 6
  98. local m_ln_currentmana = 7
  99. local m_ln_curernthp = 8
  100. local m_ln_maxhp = 9
  101. local m_ln_maxmana = 10
  102. local m_ln_level = 11
  103. local m_ln_exp = 12
  104. local m_ln_money = 13
  105.  
  106. --FORSAVE
  107. --name,uuid,weaponid,startingdate,rank,localmodemadress,currentmana,currenthp,maxhp,manxmana,lvl
  108.  
  109. --WeaponInfoFile
  110.  
  111. local w_ln_weaponname = 1
  112. local w_ln_customweaponname = 2
  113. local w_ln_damage = 3
  114. local w_ln_critchance = 4
  115. local w_ln_critpr = 5
  116. local w_ln_hpbonus = 6
  117. local w_ln_combochance = 7
  118. local w_ln_marketprice = 8
  119. local w_ln_id = 9
  120.  
  121. --FORSAVE
  122. --name,customname,damage,critchance,crit%,hpbonus,combochance,price,id
  123.  
  124. --EnemyInfoFile
  125.  
  126. local e_ln_name = 1
  127. local e_ln_hp = 2
  128. local e_ln_damage = 3
  129. local e_ln_id = 4
  130. local e_ln_expr = 5
  131. local e_ln_goldr = 6
  132.  
  133. --FORSAVE
  134. --name,hp,damage,id,expReward,goldReward
  135.  
  136. --TODO
  137. --ServerInfoFile
  138. --AbilityInfoFile
  139.  
  140. ------------------------------
  141.  
  142. --FileNames
  143.  
  144. local fn_mainfile = "rpg/mainfile.DGIF"
  145.  
  146. --Directories
  147.  
  148. local dir_enemies = "rpg/enemies/"
  149. local dir_weapons = "rpg/weapons/"
  150. local dir_ips = "rpg/net/ips/"
  151. local dir_ports = "rpg/net/ports/"
  152.  
  153. --------------------------------------
  154. ------------Some Random Stuff---------
  155. --------------------------------------
  156.  
  157. local function yn(str)
  158.  
  159. print(str.." Y/N")
  160.  
  161. local ynv = io.read()
  162.  
  163. if ynv == "y" then
  164.  
  165. return true
  166.  
  167. elseif ynv == "n" then
  168.  
  169. return false
  170.  
  171. else
  172.  
  173. yn(str)
  174.  
  175. end
  176.  
  177. end
  178.  
  179. --------------------------------------
  180. ------------------FS------------------
  181. --------------------------------------
  182.  
  183. local function save(path,toSavev)
  184.  
  185. local file = io.open(path,"a")
  186. local toSave = st.serialize(toSavev)
  187. file:write(toSave)
  188. file:close()
  189. return true
  190.  
  191. end
  192.  
  193. local function get(path,lineNumber)
  194.  
  195. local file = io.open(path,"r")
  196. local v = st.unserialize(file)
  197. if v[lineNumber] == nil then
  198. return 0
  199. else
  200. return v[lineNumber]
  201. end
  202.  
  203. end
  204.  
  205. local function getInDirNumber(path)
  206.  
  207. local toReturn = 0
  208.  
  209. local v = fs.list(path)
  210.  
  211. for file in v do
  212.  
  213. toReturn = toReturn + 1
  214.  
  215. end
  216.  
  217. return toReturn
  218.  
  219. end
  220.  
  221. --------------------------------------
  222. --------------РЕГИСТРАЦИЯ-------------
  223. --------------------------------------
  224.  
  225. local function registerPlayer()
  226.  
  227. --name,uuid,weaponid,startingdate,rank,localmodemadress,currentmana,currenthp,maxhp,manxmana,lvl,exp,money
  228. print("Добро пожаловать в OSF - THE RPG!\nВы зашли в игру впервые, поэтому Вам следует пройти регистрацию!\nВведите имя Вашего персонажа...")
  229. local name = io.read()
  230. local uuid = getUUID
  231. print("Ваш уникальный UUID номер - "..uuid)
  232. print("Введите текущую дату (ДД/ММ/ГГГГ)")
  233. local date = io.read()
  234. local toTransfer = {name,uuid,1,date,_,_,_,_,20,0,1,_,_}
  235. save(fn_mainfile,toTransfer)
  236. print("Запись информации...")
  237. os.sleep(2)
  238. gpu.setForeground(cl.salad())
  239. print("Запись прошла успешно!")
  240. gpu.setForeground(cl.white())
  241. print("Вы успешно зарегестрировались!")
  242. return true
  243.  
  244. end
  245.  
  246. --------------------------------------
  247. ------------СИСТЕМА УРОНА-------------
  248. --------------------------------------
  249.  
  250. local function getCurrentWeapon()
  251.  
  252. return get(dir_weapons..get(fn_mainfile,m_ln_currentweaponid))..".DWIF"
  253.  
  254. end
  255.  
  256. local function getDmg(x)
  257.  
  258. return math.random(x/100*75,x)
  259.  
  260. end
  261.  
  262. local function getCrit(procent,chance)
  263.  
  264. if math.random(1,100) <= chance then
  265.  
  266. procent = math.random(procent-5,procent+5)
  267. return procent+100
  268.  
  269. else
  270.  
  271. return 100
  272.  
  273. end
  274.  
  275. end
  276.  
  277. local function finalDamage()
  278.  
  279. local x = getDmg(getCurrentWeapon(),w_ln_damage())
  280. local y = getCrit(w_ln_critpr,w_ln_critchance)
  281. local z = false
  282.  
  283. if not y == 100 then
  284.  
  285. z = true
  286.  
  287. end
  288.  
  289. print("Damage","Crit","CritTF?")
  290. print(x,y,z)
  291.  
  292. return math.ceil(x/100*y),z
  293.  
  294. end
  295.  
  296. ---------------------------------------------------
  297. -----------------СОЗДАНИЕ ОРУЖИЯ-------------------
  298. ---------------------------------------------------
  299.  
  300. local function createNewWeapon(name,damage,critC,critP)
  301.  
  302. local ls = {name,_,damage,critC,critP,_,_,_,id}
  303. id = getInDirNumber(dir_weapons)+1
  304. print("Installed weapon - "..name..". Weapon ID: "..id)
  305. return save(dir_weapons..id..".DWIF",ls)
  306.  
  307. end
  308.  
  309. ---------------------------------------------------
  310. ------------------CОЗДАНИЕ ВРАГА-------------------
  311. ---------------------------------------------------
  312.  
  313. local function createBaseEnemy(name,damage,hp,er,gr)
  314.  
  315. --name,hp,damage,id,expReward,goldReward
  316. local ls = {name,hp,damage,id,er,gr}
  317. id = getInDirNumber(dir_enemies)+1
  318. print("Installed enemy - "..name)
  319. return save(dir_enemies..id..".DEIF",ls)
  320.  
  321. end
  322.  
  323. ---------------------------------------------------
  324. ------------------------PvE------------------------
  325. ---------------------------------------------------
  326.  
  327. ---------PVE BATTLES IS ONLY TURN BASED
  328. --It's Basic Fight. Level 1-10
  329.  
  330. local function PvEBattle(enemyID)
  331.  
  332. --Start
  333.  
  334. local fN = dir_enemies..enemyID..".DEIF"
  335. print("*Вжух* И Вы наткнулись на врага!\nОсторожно, перед Вами - "..get(fN,e_ln_name))
  336.  
  337. --Объявление текущих состояний
  338. --name,uuid,weaponid,startingdate,rank,localmodemadress,currentmana,currenthp,maxhp,manxmana,lvl
  339.  
  340. local pHP = get(fn_mainfile,m_ln_curernthp)
  341. if pHP == 0 then local ts = {_,_,_,_,_,_,_,get(fn_mainfile,m_ln_maxhp),_,_,_,_,_} save(ts) pHP = ts[8] end
  342. local eHP = get(dir_enemies..enemyID..".DEIF",e_ln_hp)
  343. local eHPM = eHP
  344. local eBLOCK = false
  345.  
  346. local function turnStart()
  347.  
  348. local turnNumber = 1
  349. print("Ваше здоровье - "..pHP.."\nЗдоровье Врага - "..eHP)
  350.  
  351. --Your Turn
  352.  
  353. local function yourTurn()
  354.  
  355. print("1. Атаковать\n2. Использовать предмет\n3. Бежать")
  356. local selection = io.read()
  357.  
  358. if selection > 0 and selection < 4 and selection.type() == "integer" then
  359.  
  360. if selection == 1 then
  361.  
  362. local attackDamage = {finalDamage()}
  363.  
  364. if not attackDamage[2] == true then
  365.  
  366. print("Вы нанесли "..attackDamage[1].." урона!")
  367. return true
  368.  
  369. elseif attackDamage[2] == true then
  370.  
  371. print("Сработал крит! Вы нанесли "..attackDamage[1].." урона!")
  372.  
  373. end
  374.  
  375. if eBLOCK == true then
  376.  
  377. print("У Врага стоял 'БЛОК'! Ваш урон был урезан на 50%")
  378. attackDamage[1] = attackDamage[1]/2
  379.  
  380. end
  381.  
  382. eHP = eHP - attackDamage[1]
  383. print("Здоровье врага: "..eHP)
  384. return true
  385.  
  386.  
  387. elseif selection == 2 then
  388.  
  389. --TODO Система предметов
  390. return true
  391.  
  392. elseif selection == 3 then
  393.  
  394. --TODO
  395. print("Вы попытались убежать...")
  396. os.sleep(2)
  397. ss.clear()
  398. print("Запуск деинсталяции системы...")
  399. print("...")
  400. --fs.remove(*)
  401. return false
  402.  
  403. end
  404.  
  405. end
  406.  
  407. --TODO Сделать Перемещение через кнопки на клавиатуре
  408.  
  409. end
  410.  
  411. --Enemy Turn
  412.  
  413. local function enemyTurn()
  414.  
  415. --Alpha of OC AI
  416.  
  417. local function AI_attack()
  418.  
  419. local eDMG = getDmg(get(fN,e_ln_damage))
  420. pHP = pHP - eDMG
  421. print("Вам нанесли "..eDMG.." урона!")
  422. print("Ваше текущее здоровье: "..pHP)
  423. return true
  424.  
  425. end
  426.  
  427. local function AI_block()
  428.  
  429. eBLOCK = true
  430. print("Враг поставил блок!")
  431. return true
  432.  
  433. end
  434.  
  435. if turnNumber == 3 then
  436.  
  437. AI_block()
  438. turnNumber = 1
  439.  
  440. else
  441.  
  442. AI_attack()
  443.  
  444. end
  445.  
  446. end
  447.  
  448. while pHP > 0 or eHP > 0 do
  449.  
  450. print("Ваш ход.")
  451. yourTurn()
  452. print("Ход противника.")
  453. enemyTurn()
  454.  
  455. end
  456.  
  457. if pHP <= 0 then
  458.  
  459. return false
  460.  
  461. elseif eHP <= 0 then
  462.  
  463. return true
  464.  
  465. end
  466.  
  467. end
  468.  
  469. print(turnStart())
  470.  
  471. end
  472.  
  473. ---------------------------------------------------------------------------------------------------------------------------------------------------------
  474.  
  475. --Установка собсна
  476.  
  477. local function installGame(whatto)
  478.  
  479. local function installWeapons()
  480.  
  481. --name,damage,critC,critP
  482. createNewWeapon("Stick",2,_,_)
  483. createNewWeapon("Kitchen Knife",4,10,10)
  484. createNewWeapon("Axe",7,5,10)
  485. createNewWeapon("Small Sword",10,_,_)
  486. createNewWeapon("Big Sword",25,15,15)
  487.  
  488. end
  489.  
  490. local function installEnemies()
  491.  
  492. --name,hp,damage,expReward,goldReward
  493. createBaseEnemy("Rabbit",5,2,1,4)
  494. createBaseEnemy("Wolf",20,7,10,15)
  495.  
  496. end
  497.  
  498. local function all()
  499.  
  500. installWeapons()
  501. installEnemies()
  502.  
  503. end
  504.  
  505. if whatto == "installWeapons" then installWeapons() elseif whatto == "installEnemies" then installEnemies() elseif whatto == "all" then all() else print("FATAL ERROR!") end
  506.  
  507. end
  508.  
  509. --Бетка отдельной проги
  510.  
  511. local function uninstallGame()
  512.  
  513. if not fs.exists("rpg/") then
  514.  
  515. print("Whoops... Game isn't installed!")
  516. print("Returning to shell...")
  517. return false
  518.  
  519. end
  520.  
  521. print("Unistalling...")
  522. fs.remove("rpg/")
  523. if fs.exists("rpg/") then
  524.  
  525. print("UNISTALLATION FAILED!")
  526. if yn("RETRY?") == true then
  527.  
  528. uninstallGame()
  529.  
  530. else
  531.  
  532. print("Retrying canceled...")
  533. return false
  534.  
  535. end
  536.  
  537. else
  538.  
  539. print("Unisntallation Successfully...\nThank's for using BETA version of OC_UISNT")
  540. return true
  541.  
  542. end
  543.  
  544. end
  545.  
  546.  
  547. --Че тестим пацаны
  548. installGame("all")
  549. registerPlayer()
  550. PvEBattle(math.random(getInDirNumber(dir_enemies)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement