Advertisement
ReDestroyDeR

Untitled

Nov 5th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.23 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. print(file)
  215.  
  216. end
  217.  
  218. return toReturn
  219.  
  220. end
  221.  
  222. --------------------------------------
  223. --------------РЕГИСТРАЦИЯ-------------
  224. --------------------------------------
  225.  
  226. local function registerPlayer()
  227.  
  228. --name,uuid,weaponid,startingdate,rank,localmodemadress,currentmana,currenthp,maxhp,manxmana,lvl,exp,money
  229. print("Добро пожаловать в OSF - THE RPG!\nВы зашли в игру впервые, поэтому Вам следует пройти регистрацию!\nВведите имя Вашего персонажа...")
  230. local name = io.read()
  231. local uuid = getUUID
  232. print("Ваш уникальный UUID номер - "..uuid)
  233. print("Введите текущую дату (ДД/ММ/ГГГГ)")
  234. local date = io.read()
  235. local toTransfer = {name,uuid,1,date,_,_,_,_,20,0,1,_,_}
  236. save(fn_mainfile,toTransfer)
  237. print("Запись информации...")
  238. os.sleep(2)
  239. --gpu.setForeground(cl.salad())
  240. print("Запись прошла успешно!")
  241. --gpu.setForeground(cl.white())
  242. print("Вы успешно зарегестрировались!")
  243. return true
  244.  
  245. end
  246.  
  247. --------------------------------------
  248. ------------СИСТЕМА УРОНА-------------
  249. --------------------------------------
  250.  
  251. local function getCurrentWeapon()
  252.  
  253. return get(dir_weapons..get(fn_mainfile,m_ln_currentweaponid))..".DWIF"
  254.  
  255. end
  256.  
  257. local function getDmg(x)
  258.  
  259. return math.random(x/100*75,x)
  260.  
  261. end
  262.  
  263. local function getCrit(procent,chance)
  264.  
  265. if math.random(1,100) <= chance then
  266.  
  267. procent = math.random(procent-5,procent+5)
  268. return procent+100
  269.  
  270. else
  271.  
  272. return 100
  273.  
  274. end
  275.  
  276. end
  277.  
  278. local function finalDamage()
  279.  
  280. local x = getDmg(getCurrentWeapon(),w_ln_damage())
  281. local y = getCrit(w_ln_critpr,w_ln_critchance)
  282. local z = false
  283.  
  284. if not y == 100 then
  285.  
  286. z = true
  287.  
  288. end
  289.  
  290. print("Damage","Crit","CritTF?")
  291. print(x,y,z)
  292.  
  293. return math.ceil(x/100*y),z
  294.  
  295. end
  296.  
  297. ---------------------------------------------------
  298. -----------------СОЗДАНИЕ ОРУЖИЯ-------------------
  299. ---------------------------------------------------
  300.  
  301. local function createNewWeapon(name,damage,critC,critP)
  302.  
  303. local ls = {name,_,damage,critC,critP,_,_,_,id}
  304. id = getInDirNumber(dir_weapons)+1
  305. print("Installed weapon - "..name..". Weapon ID: "..id)
  306. return save(dir_weapons..id..".DWIF",ls)
  307.  
  308. end
  309.  
  310. ---------------------------------------------------
  311. ------------------CОЗДАНИЕ ВРАГА-------------------
  312. ---------------------------------------------------
  313.  
  314. local function createBaseEnemy(name,damage,hp,er,gr)
  315.  
  316. --name,hp,damage,id,expReward,goldReward
  317. local ls = {name,hp,damage,id,er,gr}
  318. id = getInDirNumber(dir_enemies)+1
  319. print("Installed enemy - "..name)
  320. return save(dir_enemies..id..".DEIF",ls)
  321.  
  322. end
  323.  
  324. ---------------------------------------------------
  325. ------------------------PvE------------------------
  326. ---------------------------------------------------
  327.  
  328. ---------PVE BATTLES IS ONLY TURN BASED
  329. --It's Basic Fight. Level 1-10
  330.  
  331. local function PvEBattle(enemyID)
  332.  
  333. --Start
  334.  
  335. local fN = dir_enemies..enemyID..".DEIF"
  336. print("*Вжух* И Вы наткнулись на врага!\nОсторожно, перед Вами - "..get(fN,e_ln_name))
  337.  
  338. --Объявление текущих состояний
  339. --name,uuid,weaponid,startingdate,rank,localmodemadress,currentmana,currenthp,maxhp,manxmana,lvl
  340.  
  341. local pHP = get(fn_mainfile,m_ln_curernthp)
  342. if pHP == 0 then local ts = {_,_,_,_,_,_,_,get(fn_mainfile,m_ln_maxhp),_,_,_,_,_} save(ts) pHP = ts[8] end
  343. local eHP = get(dir_enemies..enemyID..".DEIF",e_ln_hp)
  344. local eHPM = eHP
  345. local eBLOCK = false
  346.  
  347. local function turnStart()
  348.  
  349. local turnNumber = 1
  350. print("Ваше здоровье - "..pHP.."\nЗдоровье Врага - "..eHP)
  351.  
  352. --Your Turn
  353.  
  354. local function yourTurn()
  355.  
  356. print("1. Атаковать\n2. Использовать предмет\n3. Бежать")
  357. local selection = io.read()
  358.  
  359. if selection > 0 and selection < 4 and selection.type() == "integer" then
  360.  
  361. if selection == 1 then
  362.  
  363. local attackDamage = {finalDamage()}
  364.  
  365. if not attackDamage[2] == true then
  366.  
  367. print("Вы нанесли "..attackDamage[1].." урона!")
  368. return true
  369.  
  370. elseif attackDamage[2] == true then
  371.  
  372. print("Сработал крит! Вы нанесли "..attackDamage[1].." урона!")
  373.  
  374. end
  375.  
  376. if eBLOCK == true then
  377.  
  378. print("У Врага стоял 'БЛОК'! Ваш урон был урезан на 50%")
  379. attackDamage[1] = attackDamage[1]/2
  380.  
  381. end
  382.  
  383. eHP = eHP - attackDamage[1]
  384. print("Здоровье врага: "..eHP)
  385. return true
  386.  
  387.  
  388. elseif selection == 2 then
  389.  
  390. --TODO Система предметов
  391. return true
  392.  
  393. elseif selection == 3 then
  394.  
  395. --TODO
  396. print("Вы попытались убежать...")
  397. os.sleep(2)
  398. ss.clear()
  399. print("Запуск деинсталяции системы...")
  400. print("...")
  401. --fs.remove(*)
  402. return false
  403.  
  404. end
  405.  
  406. end
  407.  
  408. --TODO Сделать Перемещение через кнопки на клавиатуре
  409.  
  410. end
  411.  
  412. --Enemy Turn
  413.  
  414. local function enemyTurn()
  415.  
  416. --Alpha of OC AI
  417.  
  418. local function AI_attack()
  419.  
  420. local eDMG = getDmg(get(fN,e_ln_damage))
  421. pHP = pHP - eDMG
  422. print("Вам нанесли "..eDMG.." урона!")
  423. print("Ваше текущее здоровье: "..pHP)
  424. return true
  425.  
  426. end
  427.  
  428. local function AI_block()
  429.  
  430. eBLOCK = true
  431. print("Враг поставил блок!")
  432. return true
  433.  
  434. end
  435.  
  436. if turnNumber == 3 then
  437.  
  438. AI_block()
  439. turnNumber = 1
  440.  
  441. else
  442.  
  443. AI_attack()
  444.  
  445. end
  446.  
  447. end
  448.  
  449. while pHP > 0 or eHP > 0 do
  450.  
  451. print("Ваш ход.")
  452. yourTurn()
  453. print("Ход противника.")
  454. enemyTurn()
  455.  
  456. end
  457.  
  458. if pHP <= 0 then
  459.  
  460. return false
  461.  
  462. elseif eHP <= 0 then
  463.  
  464. return true
  465.  
  466. end
  467.  
  468. end
  469.  
  470. print(turnStart())
  471.  
  472. end
  473.  
  474. ---------------------------------------------------------------------------------------------------------------------------------------------------------
  475.  
  476. --Установка собсна
  477.  
  478. local function installGame(whatto)
  479.  
  480. local function installWeapons()
  481.  
  482. --name,damage,critC,critP
  483. createNewWeapon("Stick",2,_,_)
  484. createNewWeapon("Kitchen Knife",4,10,10)
  485. createNewWeapon("Axe",7,5,10)
  486. createNewWeapon("Small Sword",10,_,_)
  487. createNewWeapon("Big Sword",25,15,15)
  488.  
  489. end
  490.  
  491. local function installEnemies()
  492.  
  493. --name,hp,damage,expReward,goldReward
  494. createBaseEnemy("Rabbit",5,2,1,4)
  495. createBaseEnemy("Wolf",20,7,10,15)
  496.  
  497. end
  498.  
  499. local function all()
  500.  
  501. installWeapons()
  502. installEnemies()
  503.  
  504. end
  505.  
  506. if whatto == "installWeapons" then installWeapons() elseif whatto == "installEnemies" then installEnemies() elseif whatto == "all" then all() else print("FATAL ERROR!") end
  507.  
  508. end
  509.  
  510. --Бетка отдельной проги
  511.  
  512. local function uninstallGame()
  513.  
  514. if not fs.exists("rpg/") then
  515.  
  516. print("Whoops... Game isn't installed!")
  517. print("Returning to shell...")
  518. return false
  519.  
  520. end
  521.  
  522. print("Unistalling...")
  523. fs.remove("rpg/")
  524. if fs.exists("rpg/") then
  525.  
  526. print("UNISTALLATION FAILED!")
  527. if yn("RETRY?") == true then
  528.  
  529. uninstallGame()
  530.  
  531. else
  532.  
  533. print("Retrying canceled...")
  534. return false
  535.  
  536. end
  537.  
  538. else
  539.  
  540. print("Unisntallation Successfully...\nThank's for using BETA version of OC_UISNT")
  541. return true
  542.  
  543. end
  544.  
  545. end
  546.  
  547.  
  548. --Че тестим пацаны
  549. installGame("all")
  550. registerPlayer()
  551. PvEBattle(math.random(getInDirNumber(dir_enemies)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement