Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------------------------
- -- Импорты
- local com = require("component")
- local ss = require("term")
- local st = require("serialization")
- local tt = require("text")
- local fs = require("filesystem")
- local event = require("event")
- local cl = require("gpuColors")
- local getUUID = require("uuid").next()
- -- ОМГ ОМГ ЭТО ЖЕ АХУЕТЬ КАКОЙ ВАЖНЫЙ КОМПОНЕНТ
- -- ( да )
- local mdm = com.modem
- local gpu = com.gpu
- -------------------------------------------------
- --СТАНДАРТНЫЕ ФУНКЦИИ ДЛЯ МОДЕМА
- local function openP(port)
- return mdm.open(port)
- end
- local function closeP(port)
- return mdm.close(port)
- end
- local function send(ip,port,message)
- return mdm.send(ip,port,message)
- end
- local function broadcast(port,message)
- return mdm.broadcast(port,message)
- end
- local function getMDM(port)
- open(port)
- local function getMessage()
- while true do
- local e = {event.pull()}
- if e[1] == "modem_message" then
- return e[6]
- end
- end
- end
- local function getIP()
- while true do
- local e = {event.pull()}
- if e[1] == "modem_message" then
- return e[2]
- end
- end
- end
- end
- ----------------------------------------------------------------------------------
- --Номера строк что бы работала память компа, а не моя. Ну а хуле нам, програмистам
- --MainFile
- local m_ln_playername = 1
- local m_ln_uuid = 2
- local m_ln_currentweaponid = 3
- local m_ln_startdate = 4
- local m_ln_rank = 5
- local m_ln_localmodemadress = 6
- local m_ln_currentmana = 7
- local m_ln_curernthp = 8
- local m_ln_maxhp = 9
- local m_ln_maxmana = 10
- local m_ln_level = 11
- local m_ln_exp = 12
- local m_ln_money = 13
- --FORSAVE
- --name,uuid,weaponid,startingdate,rank,localmodemadress,currentmana,currenthp,maxhp,manxmana,lvl
- --WeaponInfoFile
- local w_ln_weaponname = 1
- local w_ln_customweaponname = 2
- local w_ln_damage = 3
- local w_ln_critchance = 4
- local w_ln_critpr = 5
- local w_ln_hpbonus = 6
- local w_ln_combochance = 7
- local w_ln_marketprice = 8
- local w_ln_id = 9
- --FORSAVE
- --name,customname,damage,critchance,crit%,hpbonus,combochance,price,id
- --EnemyInfoFile
- local e_ln_name = 1
- local e_ln_hp = 2
- local e_ln_damage = 3
- local e_ln_id = 4
- local e_ln_expr = 5
- local e_ln_goldr = 6
- --FORSAVE
- --name,hp,damage,id,expReward,goldReward
- --TODO
- --ServerInfoFile
- --AbilityInfoFile
- ------------------------------
- --FileNames
- local fn_mainfile = "rpg/mainfile.DGIF"
- --Directories
- local dir_enemies = "rpg/enemies/"
- local dir_weapons = "rpg/weapons/"
- local dir_ips = "rpg/net/ips/"
- local dir_ports = "rpg/net/ports/"
- --------------------------------------
- ------------Some Random Stuff---------
- --------------------------------------
- local function yn(str)
- print(str.." Y/N")
- local ynv = io.read()
- if ynv == "y" then
- return true
- elseif ynv == "n" then
- return false
- else
- yn(str)
- end
- end
- --------------------------------------
- ------------------FS------------------
- --------------------------------------
- local function save(path,toSavev)
- local file = io.open(path,"a")
- local toSave = st.serialize(toSavev)
- file:write(toSave)
- file:close()
- return true
- end
- local function get(path,lineNumber)
- local file = io.open(path,"r")
- local v = st.unserialize(file)
- if v[lineNumber] == nil then
- return 0
- else
- return v[lineNumber]
- end
- end
- local function getInDirNumber(path)
- local toReturn = 0
- local v = fs.list(path)
- for file in v do
- toReturn = toReturn + 1
- end
- return toReturn
- end
- --------------------------------------
- --------------РЕГИСТРАЦИЯ-------------
- --------------------------------------
- local function registerPlayer()
- --name,uuid,weaponid,startingdate,rank,localmodemadress,currentmana,currenthp,maxhp,manxmana,lvl,exp,money
- print("Добро пожаловать в OSF - THE RPG!\nВы зашли в игру впервые, поэтому Вам следует пройти регистрацию!\nВведите имя Вашего персонажа...")
- local name = io.read()
- local uuid = getUUID
- print("Ваш уникальный UUID номер - "..uuid)
- print("Введите текущую дату (ДД/ММ/ГГГГ)")
- local date = io.read()
- local toTransfer = {name,uuid,1,date,_,_,_,_,20,0,1,_,_}
- save(fn_mainfile,toTransfer)
- print("Запись информации...")
- os.sleep(2)
- gpu.setForeground(cl.salad())
- print("Запись прошла успешно!")
- gpu.setForeground(cl.white())
- print("Вы успешно зарегестрировались!")
- return true
- end
- --------------------------------------
- ------------СИСТЕМА УРОНА-------------
- --------------------------------------
- local function getCurrentWeapon()
- return get(dir_weapons..get(fn_mainfile,m_ln_currentweaponid))..".DWIF"
- end
- local function getDmg(x)
- return math.random(x/100*75,x)
- end
- local function getCrit(procent,chance)
- if math.random(1,100) <= chance then
- procent = math.random(procent-5,procent+5)
- return procent+100
- else
- return 100
- end
- end
- local function finalDamage()
- local x = getDmg(getCurrentWeapon(),w_ln_damage())
- local y = getCrit(w_ln_critpr,w_ln_critchance)
- local z = false
- if not y == 100 then
- z = true
- end
- print("Damage","Crit","CritTF?")
- print(x,y,z)
- return math.ceil(x/100*y),z
- end
- ---------------------------------------------------
- -----------------СОЗДАНИЕ ОРУЖИЯ-------------------
- ---------------------------------------------------
- local function createNewWeapon(name,damage,critC,critP)
- local ls = {name,_,damage,critC,critP,_,_,_,id}
- id = getInDirNumber(dir_weapons)+1
- print("Installed weapon - "..name..". Weapon ID: "..id)
- return save(dir_weapons..id..".DWIF",ls)
- end
- ---------------------------------------------------
- ------------------CОЗДАНИЕ ВРАГА-------------------
- ---------------------------------------------------
- local function createBaseEnemy(name,damage,hp,er,gr)
- --name,hp,damage,id,expReward,goldReward
- local ls = {name,hp,damage,id,er,gr}
- id = getInDirNumber(dir_enemies)+1
- print("Installed enemy - "..name)
- return save(dir_enemies..id..".DEIF",ls)
- end
- ---------------------------------------------------
- ------------------------PvE------------------------
- ---------------------------------------------------
- ---------PVE BATTLES IS ONLY TURN BASED
- --It's Basic Fight. Level 1-10
- local function PvEBattle(enemyID)
- --Start
- local fN = dir_enemies..enemyID..".DEIF"
- print("*Вжух* И Вы наткнулись на врага!\nОсторожно, перед Вами - "..get(fN,e_ln_name))
- --Объявление текущих состояний
- --name,uuid,weaponid,startingdate,rank,localmodemadress,currentmana,currenthp,maxhp,manxmana,lvl
- local pHP = get(fn_mainfile,m_ln_curernthp)
- if pHP == 0 then local ts = {_,_,_,_,_,_,_,get(fn_mainfile,m_ln_maxhp),_,_,_,_,_} save(ts) pHP = ts[8] end
- local eHP = get(dir_enemies..enemyID..".DEIF",e_ln_hp)
- local eHPM = eHP
- local eBLOCK = false
- local function turnStart()
- local turnNumber = 1
- print("Ваше здоровье - "..pHP.."\nЗдоровье Врага - "..eHP)
- --Your Turn
- local function yourTurn()
- print("1. Атаковать\n2. Использовать предмет\n3. Бежать")
- local selection = io.read()
- if selection > 0 and selection < 4 and selection.type() == "integer" then
- if selection == 1 then
- local attackDamage = {finalDamage()}
- if not attackDamage[2] == true then
- print("Вы нанесли "..attackDamage[1].." урона!")
- return true
- elseif attackDamage[2] == true then
- print("Сработал крит! Вы нанесли "..attackDamage[1].." урона!")
- end
- if eBLOCK == true then
- print("У Врага стоял 'БЛОК'! Ваш урон был урезан на 50%")
- attackDamage[1] = attackDamage[1]/2
- end
- eHP = eHP - attackDamage[1]
- print("Здоровье врага: "..eHP)
- return true
- elseif selection == 2 then
- --TODO Система предметов
- return true
- elseif selection == 3 then
- --TODO
- print("Вы попытались убежать...")
- os.sleep(2)
- ss.clear()
- print("Запуск деинсталяции системы...")
- print("...")
- --fs.remove(*)
- return false
- end
- end
- --TODO Сделать Перемещение через кнопки на клавиатуре
- end
- --Enemy Turn
- local function enemyTurn()
- --Alpha of OC AI
- local function AI_attack()
- local eDMG = getDmg(get(fN,e_ln_damage))
- pHP = pHP - eDMG
- print("Вам нанесли "..eDMG.." урона!")
- print("Ваше текущее здоровье: "..pHP)
- return true
- end
- local function AI_block()
- eBLOCK = true
- print("Враг поставил блок!")
- return true
- end
- if turnNumber == 3 then
- AI_block()
- turnNumber = 1
- else
- AI_attack()
- end
- end
- while pHP > 0 or eHP > 0 do
- print("Ваш ход.")
- yourTurn()
- print("Ход противника.")
- enemyTurn()
- end
- if pHP <= 0 then
- return false
- elseif eHP <= 0 then
- return true
- end
- end
- print(turnStart())
- end
- ---------------------------------------------------------------------------------------------------------------------------------------------------------
- --Установка собсна
- local function installGame(whatto)
- local function installWeapons()
- --name,damage,critC,critP
- createNewWeapon("Stick",2,_,_)
- createNewWeapon("Kitchen Knife",4,10,10)
- createNewWeapon("Axe",7,5,10)
- createNewWeapon("Small Sword",10,_,_)
- createNewWeapon("Big Sword",25,15,15)
- end
- local function installEnemies()
- --name,hp,damage,expReward,goldReward
- createBaseEnemy("Rabbit",5,2,1,4)
- createBaseEnemy("Wolf",20,7,10,15)
- end
- local function all()
- installWeapons()
- installEnemies()
- end
- if whatto == "installWeapons" then installWeapons() elseif whatto == "installEnemies" then installEnemies() elseif whatto == "all" then all() else print("FATAL ERROR!") end
- end
- --Бетка отдельной проги
- local function uninstallGame()
- if not fs.exists("rpg/") then
- print("Whoops... Game isn't installed!")
- print("Returning to shell...")
- return false
- end
- print("Unistalling...")
- fs.remove("rpg/")
- if fs.exists("rpg/") then
- print("UNISTALLATION FAILED!")
- if yn("RETRY?") == true then
- uninstallGame()
- else
- print("Retrying canceled...")
- return false
- end
- else
- print("Unisntallation Successfully...\nThank's for using BETA version of OC_UISNT")
- return true
- end
- end
- --Че тестим пацаны
- installGame("all")
- registerPlayer()
- PvEBattle(math.random(getInDirNumber(dir_enemies)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement