From e3209cbf6a4d465b90dea6092cd8d90e70537491 Mon Sep 17 00:00:00 2001 From: Timothy Date: Mon, 7 Nov 2016 22:17:36 -0600 Subject: [PATCH 1/3] Changed dice to newest version --- code/item/class.lua | 2 +- code/item/use/activate.lua | 14 +- code/libs/dice.lua | 228 ++++++++++++++++++ code/libs/rl-dice/dice.lua | 170 ------------- code/libs/rl-dice/odds.lua | 116 --------- .../building/barrier/barricade/class.lua | 6 +- code/location/building/buildDesc.lua | 9 +- code/location/tile/class.lua | 3 +- code/player/action/outcome.lua | 6 +- code/player/armor/class.lua | 4 +- code/player/armor/item_class.lua | 1 - code/player/armor/organic_class.lua | 1 - code/player/carcass.lua | 6 +- code/player/combat.lua | 8 +- code/player/condition/burn.lua | 8 +- code/player/condition/decay.lua | 1 - code/player/condition/infection.lua | 1 - code/player/condition/poison.lua | 10 +- code/player/condition/tracking.lua | 6 +- 19 files changed, 267 insertions(+), 333 deletions(-) create mode 100644 code/libs/dice.lua delete mode 100644 code/libs/rl-dice/dice.lua delete mode 100644 code/libs/rl-dice/odds.lua diff --git a/code/item/class.lua b/code/item/class.lua index 55d6d56..6f3581f 100644 --- a/code/item/class.lua +++ b/code/item/class.lua @@ -9,7 +9,7 @@ local order = require('code.item.order') local bit = require('plugin.bit') local lshift, rshift, bor = bit.lshift, bit.rshift, bit.bor local check = require('code.item.use.check') -local dice = require('code.libs.rl-dice.dice') +local dice = require('code.libs.dice') local item = class('item') diff --git a/code/item/use/activate.lua b/code/item/use/activate.lua index 6bc52ed..3e8ee4f 100644 --- a/code/item/use/activate.lua +++ b/code/item/use/activate.lua @@ -1,4 +1,4 @@ -local dice = require('code.libs.rl-dice.dice') +local dice = require('code.libs.dice') local lookupMedical = require('code.item.medical.search') local flags = require('code.player.skills.flags') @@ -28,8 +28,7 @@ function activate.FAK(player, condition, target) FAK_dice = FAK_dice..'^^' end - local heal_rolls, hp_gained = dice.roll(FAK_dice), 0 - for _, heal in ipairs(heal_rolls) do hp_gained = hp_gained + heal end + local hp_gained = FAK_dice:roll() target:updateHP(hp_gained) -- target:event trigger print('You heal with '..FAK:getName()..' for '..hp_gained..' hp.') @@ -50,8 +49,7 @@ function activate.bandage(player, condition, target) end end - local heal_rolls, hp_gained = dice.roll(bandage_dice), 0 - for _, heal in ipairs(heal_rolls) do hp_gained = hp_gained + heal end + local hp_gained = bandage_dice:roll() target:updateHP(hp_gained) -- target:event trigger print('You heal with '..bandage:getName()..' for '..hp_gained..' hp.') @@ -62,7 +60,7 @@ function activate.antidote(player, condition, target) local cure_chance = antidote:getAccuracy() -- modify chance based on skills? - local cure_success = dice.chance(cure_chance) + local cure_success = cure_chance >= math.random() -- target:updateStatusEffects? -- target:event trigger if cure_success then @@ -77,7 +75,7 @@ function activate.syringe(player, condition, target) local inject_chance = syringe:getAccuracy() -- modify chance based on skills? - local inject_success = dice.chance(inject_chance) + local inject_success = inject_chance >= math.random() target:killed('syringe') -- target:event trigger end @@ -164,7 +162,7 @@ function activate.book(player, condition) local book_dice = dice:new(xp_dice_str) if player.skills:check(flags.bookworm) then book_dice = book_dice^1 end if player:isStaged('inside') and player:getSpotCondition() == 'powered' then book_dice = book_dice/2 end - local gained_xp = book_dice:rollAndTotal() + local gained_xp = book_dice:roll() player:updateXP(gained_xp) end diff --git a/code/libs/dice.lua b/code/libs/dice.lua new file mode 100644 index 0000000..566109f --- /dev/null +++ b/code/libs/dice.lua @@ -0,0 +1,228 @@ +--- A library used to roll and manipulate roguelike based dice +-- @classmod dice +-- @author Timothy Torres +-- @copyright 2013 +-- @license MIT/X11 + +local dice = { + _AUTHOR = 'Timothy Torres', + _URL = 'https://github.com/timothymtorres/RL-Dice', + _DESCRIPTION = 'A robust module to roll and manipulate roguelike dice.', + _LICENSE = [[ + MIT LICENSE + Copyright (c) 2013 Timothy Torres + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + ]] +} +dice.minimum = 1 -- class default lowest possible roll is 1 (can set to nil to allow negative rolls) +local random, max, abs, sort, match, format = math.random, math.max, math.abs, table.sort, string.match, string.format + +--- Creates a new dice instance +-- @tparam ?int|string dice_notation Can be either a dice string, or int +-- @tparam[opt] int minimum Sets dice instance roll's minimum result boundaries +-- @treturn dice +function dice:new(dice_notation, minimum) + -- If dice_notation is a number, we must convert it into the proper dice string format + if type(dice_notation) == 'number' then dice_notation = '1d'..dice_notation end + + local dice_pattern = '[(]?%d+[d]%d+[+-]?[+-]?%d*[%^]?[+-]?[+-]?%d*[)]?[x]?%d*' + assert(dice_notation == match(dice_notation, dice_pattern), "Dice string incorrectly formatted.") + + local dice_INST = {} + + dice_INST.num = tonumber(match(dice_notation, '%d+')) + dice_INST.faces = tonumber(match(dice_notation, '[d](%d+)')) + + local double_bonus = match(dice_notation, '[^%^+-]([+-]?[+-])%d+') + local bonus = match(dice_notation, '[^%^+-][+-]?([+-]%d+)') + dice_INST.is_bonus_plural = double_bonus == '++' or double_bonus == '--' + dice_INST.bonus = tonumber(bonus) or 0 + + + local double_reroll = match(dice_notation, '[%^]([+-]?[+-])%d+') + local reroll = match(dice_notation, '[%^][+-]?([+-]%d+)') + dice_INST.is_reroll_plural = double_reroll == '++' or double_reroll == '--' + dice_INST.rerolls = tonumber(reroll) or 0 + + dice_INST.sets = tonumber(match(dice_notation, '[x](%d+)')) or 1 + + dice_INST.minimum = minimum + + self.__index = self + return setmetatable(dice_INST, self) +end + +--- Sets class global for dice minimum +--@tparam[opt] int value Sets dice class minimum result boundaries (if nil, no minimum result) +function dice:setMin(value) self.minimum = value end + +--- Number of total dice +-- @treturn int +function dice:getNum() return self.num end + +--- Number of total faces on a dice +-- @treturn int +function dice:getFaces() return self.faces end + +--- Bonus to be added to the dice total +-- @treturn int +function dice:getBonus() return self.bonus end + +--- Rerolls to be added to the dice +-- @treturn int +function dice:getRerolls() return self.rerolls end + +--- Number of total dice sets +-- @treturn int +function dice:getSets() return self.sets end + +--- Bonus to be added to all dice (if double bonus enabled) otherwise regular bonus +-- @treturn int +function dice:getTotalBonus() return (self.is_bonus_plural and self.bonus*self.num) or self.bonus end + +--- Rerolls to be added to all dice (if double reroll enabled) otherwise regular reroll +-- @treturn int +function dice:getTotalRerolls() return (self.is_reroll_plural and self.rerolls*self.num) or self.rerolls end + +--- Determines if all dice are to be rerolled together or individually +-- @treturn bool +function dice:isDoubleReroll() return self.is_reroll_plural end + +--- Determines if all dice are to apply a bonus together or individually +-- @treturn bool +function dice:isDoubleBonus() return self.is_bonus_plural end + +--- Modifies bonus +-- @tparam int value +-- @treturn dice dice +function dice:__add(value) self.bonus = self.bonus + value return self end + +--- Modifies bonus +-- @tparam int value +-- @treturn dice +function dice:__sub(value) self.bonus = self.bonus - value return self end + +--- Modifies number of dice +-- @tparam int value +-- @treturn dice +function dice:__mul(value) self.num = self.num + value return self end + +--- Modifies amount of dice faces +-- @tparam int value +-- @treturn dice +function dice:__div(value) self.faces = self.faces + value return self end + +--- Modifies rerolls +-- @tparam int value +-- @treturn dice +function dice:__pow(value) self.rerolls = self.rerolls + value return self end + +--- Modifies dice sets +-- @tparam int value +-- @treturn dice +function dice:__mod(value) self.sets = self.sets + value return self end + +--- Gets a formatted dice string in roguelike notation +-- @treturn string +function dice:__tostring() + local num_dice, dice_faces, bonus, is_bonus_plural, rerolls, is_reroll_plural, sets = self.num, self.faces, self.bonus, self.is_bonus_plural, self.rerolls, self.is_reroll_plural, self.sets + + -- num_dice & dice_faces default to 1 if negative or 0! + sets, num_dice, dice_faces = max(sets, 1), max(num_dice, 1), max(dice_faces, 1) + + local double_bonus = is_bonus_plural and (bonus >= 0 and '+' or '-') or '' + bonus = (bonus ~= 0 and double_bonus..format('%+d', bonus)) or '' + + local double_reroll = is_reroll_plural and (rerolls >= 0 and '+' or '-') or '' + rerolls = (rerolls ~= 0 and '^'..double_reroll..format('%+d', rerolls)) or '' + + if sets > 1 then return '('..num_dice..'d'..dice_faces..bonus..rerolls..')x'..sets + else return num_dice..'d'..dice_faces..bonus..rerolls + end +end + +--- Modifies whether reroll or bonus applies to individual dice or all of them +-- @tparam str pluralism_notation String must be one of the following operators `- + ^` The operator may be double signed to indicate pluralism. +-- @treturn dice +function dice:__concat(pluralism_notation) + local str_b = match(pluralism_notation, '[+-][+-]?') or '' + local bonus = ((str_b == '++' or str_b == '--') and 'double') or ((str_b == '+' or str_b == '-') and 'single') or nil + + local str_r = match(pluralism_notation, '[%^][%^]?') or '' + local reroll = (str_r == '^^' and 'double') or (str_r == '^' and 'single') or nil + + if bonus == 'double' then self.is_bonus_plural = true + elseif bonus == 'single' then self.is_bonus_plural = false end + + if reroll == 'double' then self.is_reroll_plural = true + elseif reroll == 'single' then self.is_reroll_plural = false end + return self +end + +--- Rolls the dice +-- @tparam ?int|dice|str self +-- @tparam[opt] int minimum +function dice.roll(self, minimum) + if type(self) ~= 'table' then self = dice:new(self, minimum) end + local num_dice, dice_faces = self.num, self.faces + local bonus, rerolls = self.bonus, self.rerolls + local is_bonus_plural, is_reroll_plural = self.is_bonus_plural, self.is_reroll_plural + local sets, minimum = self.sets, self.minimum + + sets = max(sets, 1) -- Minimum of 1 needed + local set_rolls = {} + + local bonus_all = is_bonus_plural and bonus or 0 + rerolls = is_reroll_plural and rerolls*num_dice or rerolls + + -- num_dice & dice_faces CANNOT be negative! + num_dice, dice_faces = max(num_dice, 1), max(dice_faces, 1) + + for i=1, sets do + local rolls = {} + for ii=1, num_dice + abs(rerolls) do + rolls[ii] = random(1, dice_faces) + bonus_all -- if is_bonus_plural then bonus_all gets added to every roll, otherwise bonus_all = 0 + end + + if rerolls ~= 0 then + -- sort and if reroll is + then remove lowest rolls, if reroll is - then remove highest rolls + if rerolls > 0 then sort(rolls, function(a,b) return a>b end) else sort(rolls) end + for index=num_dice + 1, #rolls do rolls[index] = nil end + end + + -- bonus gets added to the last roll if it is not plural + if not is_bonus_plural then rolls[#rolls] = rolls[#rolls] + bonus end + + local total = 0 + for _, number in ipairs(rolls) do total = total + number end + set_rolls[i] = total + end + + -- if minimum is empty then use dice class default min + if minimum == nil then minimum = dice.minimum end + + if minimum then + for i=1, sets do + set_rolls[i] = max(set_rolls[i], minimum) + end + end + + return unpack(set_rolls) +end + +return dice \ No newline at end of file diff --git a/code/libs/rl-dice/dice.lua b/code/libs/rl-dice/dice.lua deleted file mode 100644 index dadc913..0000000 --- a/code/libs/rl-dice/dice.lua +++ /dev/null @@ -1,170 +0,0 @@ -local dice = {} -dice.__index = dice - ---[[-- DICE INDEX ----- -{x}d{y}+{s}{z}^+{s}{r} - x - number of dice being rolled - y - faces of the dice - z - a value to be added to the result (can be negative) - r - rerolls, if + then remove lowest rolls, if - then remove highest rolls - s - if double sign (++ or --) adds {z} value to all dice rolls (default is last roll) or {r} rerolls to all dice rolls - - Examples: - - 1d6 = Roll 1 six sided die - 3d4 = Roll 3 dice with four sides - 2d4+1 = Roll 2 dice with four sides, add +1 to last roll - 3d3++1 = Roll 3 dice with three sides, add +1 to all rolls - 3d3--1 = Roll 3 dice with three sides, add -1 to all rolls - 2d6^+2 = Roll 4 dice with six sides, remove the two lowest rolls - 2d4^++1 = Roll 4 dice with four sides, remove the two lowest rolls - 3d4-2^-1 = Roll 3 dice with four sides, remove the highest roll, add -1 to last roll ------- FINISH --]]-- - -local function shuffle(tab) - local len = #tab - local r - for i = 1, len do - r = math.random(i, len) - tab[i], tab[r] = tab[r], tab[i] - end -end - -local function determine(num_dice, dice_faces, bonus, double_sign_bonus, rerolls, double_sign_rerolls) - local rolls = {} - local rerolls_temp = rerolls or 0 - local bonus_all = double_sign_bonus and bonus or 0 - local rerolls = double_sign_rerolls and rerolls_temp*num_dice or rerolls_temp - - -- num_dice & dice_faces CANNOT be negative! - local num_dice, dice_faces = math.max(num_dice, 1), math.max(dice_faces, 1) - - for i=1, num_dice + math.abs(rerolls) do - rolls[i] = math.random(1, dice_faces) + bonus_all - end - - if rerolls ~= 0 then - -- sort and if reroll is + then remove lowest rolls, if reroll is - then remove highest rolls - if rerolls > 0 then table.sort(rolls, function(a,b) return a>b end) else table.sort(rolls) end - for i=num_dice + 1, #rolls do rolls[i] = nil end - shuffle(rolls) -- to make the rolls random and out of order - end - - -- adds bonus to last roll by default - if not double_sign_bonus and bonus then rolls[#rolls] = rolls[#rolls] + bonus end - - return unpack(rolls) -end - ---[[ - dice = { - num = (+)number, - faces = (+)number, - bonus = (+ or -)number, -- optional - double_b = binary, -- optional (requires bonus) - rerolls = (+ or -)number -- optional - double_r = binary, -- optional (requires rerolls) - } ---]] - -function dice:new(roll) - roll = (type(roll) == 'table' and roll) or (type(roll) == 'string' and dice.getDice(roll)) or (type(roll) == 'number' and dice.getDice('1d'..roll)) - self.__index = self - return setmetatable(roll, self) -end - -function dice:getNum() return self.num end -function dice:getFaces() return self.faces end -function dice:getBonus() return self.bonus end -function dice:getRerolls() return self.rerolls end -function dice:getTotalBonus() return (self.double_b and self.bonus*self.num) or self.bonus end -function dice:getTotalRerolls() return (self.double_r and self.rerolls*self.num) or self.rerolls end -function dice:isDoubleReroll() return self.double_r end -function dice:isDoubleBonus() return self.double_b end - -function dice.__add(roll, value) roll.bonus = roll:getBonus() + value return dice:new(roll) end - -function dice.__mul(roll, value) roll.num = roll:getNum() + value return dice:new(roll) end - -function dice.__div(roll, value) roll.faces = roll:getFaces() + value return dice:new(roll) end - -function dice.__pow(roll, value) roll.rerolls = roll:getRerolls() + value return dice:new(roll) end - -function dice.__tostring(self) return self:getString() end - -function dice.__concat(roll, str) - local str_b = str:match('[+-][+-]?') or '' - local bonus = ((str_b == '++' or str_b == '--') and 'double') or ((str_b == '+' or str_b == '-') and 'single') or nil - - local str_r = str:match('[%^][%^]?') or '' - local reroll = (str_r == '^^' and 'double') or (str_r == '^' and 'single') or nil - - if bonus == 'double' then roll.double_b = true - elseif bonus == 'single' then roll.double_b = false end - - if reroll == 'double' then roll.double_r = true - elseif reroll == 'single' then roll.double_r = false end - return dice:new(roll) -end - -function dice:roll() - if type(self) == 'string' then - local roll = dice.getDice(self) - return {determine(roll.num, roll.faces, roll.bonus, roll.double_b, roll.rerolls, roll.double_r)} - elseif type(self) == 'number' then - return {math.random(1, self)} - elseif type(self) == 'table' then - return {determine(self.num, self.faces, self.bonus, self.double_b, self.rerolls, self.double_r)} - end -end - -local function getRollTotal(roll_result) - local total = 0 - for _, number in ipairs(roll_result) do total = total + number end - return total -end - -function dice:rollAndTotal() return getRollTotal(dice.roll(self)) end - --- percent must be a decimal (ie. .75 = 75%) -function dice.chance(percent) return percent >= math.random() end - -function dice.getDice(str) - if not str:match('%d+[d]%d+') then return error("Dice string incorrectly formatted.") end - local dice = {} - dice.num = tonumber(str:match('%d+')) or 0 - if not (dice.num > 0) then return error('No dice to roll?') end -- if no dice then exit - - local str_f = str:match('[d]%d+') - dice.faces = tonumber(str_f:sub(2)) or 0 - - local str_b = str:match('[^%^+-][+-][+-]?%d+') or '' - dice.double_b = str_b:sub(2,3) == '++' or str_b:sub(2,3) == '--' or false -- if ++ or --, then bonus to all dice - dice.bonus = tonumber(str_b:match('[+-]%d+')) or 0 - - local str_r = str:match('[%^][+-][+-]?%d+') or '' - dice.double_r = str_r:sub(2,3) == '++' or str_r:sub(2,3) == '--' or false -- if ++ or --, then reroll all dice - - dice.rerolls = tonumber(str_r:match('[+-]%d+')) or 0 - return dice -end - -function dice:getString() - local num_dice, dice_faces, bonus, double_sign_bonus, rerolls, double_sign_reroll = self.num, self.faces, self.bonus, self.double_b, self.rerolls, self.double_r - - -- num_dice & dice_faces CANNOT be negative! - local num_dice, dice_faces = math.max(num_dice, 1), math.max(dice_faces, 1) - - if not num_dice or not dice_faces then return error('Dice string incorrectly formatted. Missing num_dice or dice_faces.') - elseif double_sign_bonus and not bonus then return error('Dice string incorrectly formatted. Double_sign exists but missing bonus.') end - - local double_b = double_sign_bonus and (bonus >= 0 and '+' or '-') or '' - bonus = (bonus ~= 0 and double_b..string.format('%+d', bonus)) or '' - - local double_r = double_sign_reroll and (rerolls >= 0 and '+' or '-') or '' - rerolls = (rerolls ~= 0 and '^'..double_r..string.format('%+d', rerolls)) or '' - - return num_dice..'d'..dice_faces..bonus..rerolls -end - -return dice diff --git a/code/libs/rl-dice/odds.lua b/code/libs/rl-dice/odds.lua deleted file mode 100644 index 8da873d..0000000 --- a/code/libs/rl-dice/odds.lua +++ /dev/null @@ -1,116 +0,0 @@ -local dice = require('libs.rl-dice.dice') -local total_dice, total_rerolls, total_bonus -local dice_num, dice_faces - -local function conversion(roll) - if type(roll) == 'string' then - roll = dice:new(roll) - elseif type(roll) == 'number' then - roll = dice:new('1d'..roll) - elseif type(roll) == 'table' then - -- already table format - end - return roll -end - -local function table_copy(t) - local t2 = {} - for k,v in pairs(t) do t2[k] = v end - return t2 -end - -local function trimReroll(roll_set) - local sort_pattern = total_rerolls>0 and (function(a,b) return a>b end) or (function(a,b) return a= total_dice then - roll_outcomes[#roll_outcomes+1] = set - return - end - - sequence = sequence + 1 - for i=1, dice_faces do - if sequence == #set then set[#set] = i - else set[#set+1] = i end - local next_set = table_copy(set) - diceLoop(roll_outcomes, next_set, sequence) - end - - if sequence == 1 then return roll_outcomes end -end - -local function tallyDice(dice, odds_range) - local list, set, sequence = {}, {}, 0 - local roll_list = diceLoop(list, set, sequence) - - if total_rerolls ~= 0 then roll_list = trimReroll(roll_list) end - roll_list = tallyTotal(roll_list, odds_range) - return roll_list -end - -local function roundOdds(odds, denominator) - for i=odds.low, odds.high do odds[i] = odds[i]/denominator end - return odds -end - -local function getAverage(odds) - local average = 0 - for i=odds.low, odds.high do average = average + i*odds[i] end - return average -end - -local function determine_odds(roll) - local roll = conversion(roll) - - dice_num, dice_faces = roll:getNum(), roll:getFaces() - total_rerolls, total_bonus = roll:getTotalRerolls(), roll:getTotalBonus() - total_dice = dice_num + math.abs(total_rerolls) - - local max, min = dice_num*dice_faces + total_bonus, dice_num + total_bonus - - local total_combinations = dice_faces^total_dice - local number_range = setupResults(min, max) - local odds = tallyDice(roll, number_range) - - odds.low, odds.high = min, max - odds = roundOdds(odds, total_combinations) - odds.average = getAverage(odds) - return odds -end - -local function printOdds(odds) - local min, max, average = odds.low, odds.high, odds.average - - print() - print('Dice Odds:') - for i=min, max do - print('['..i..'] = '..odds[i]..'%') - end - - print( 'min='..min..' ('..odds[min]..'%)', 'max='..max..' ('..odds[max]..'%)', 'average='..average) -end - -return determine_odds diff --git a/code/location/building/barrier/barricade/class.lua b/code/location/building/barrier/barricade/class.lua index 1dd0179..8968532 100644 --- a/code/location/building/barrier/barricade/class.lua +++ b/code/location/building/barrier/barricade/class.lua @@ -1,5 +1,5 @@ local class = require('code.libs.middleclass') -local dice = require('code.libs.rl-dice.dice') +local dice = require('code.libs.dice') local barrier = require('code.location.building.barrier.class') local barricade = class('barricade', barrier) @@ -107,7 +107,7 @@ function barricade:reinforce() end local reinforce_dice = dice:new(dice_str, 0) - local roll_result = reinforce_dice.roll() + local roll_result = reinforce_dice:roll() if roll_result > 0 then self.potential_hp = math.min(self.potential_hp + roll_result, MAX_HP) self:updateDesc() @@ -163,7 +163,7 @@ function barricade:fortify(player, cade_condition) if player.skills:check('barricade') then barricade_dice = barricade_dice / 1 end if player.skills:check('barricade_adv') then barricade_dice = barricade_dice ^ 1 end - self:updateHP(barricade_dice.roll()) + self:updateHP(barricade_dice:roll()) end return barricade \ No newline at end of file diff --git a/code/location/building/buildDesc.lua b/code/location/building/buildDesc.lua index 85cd612..5105a2c 100644 --- a/code/location/building/buildDesc.lua +++ b/code/location/building/buildDesc.lua @@ -1,5 +1,4 @@ local b_list = require('code.location.building.list') -local dice = require('code.libs.rl-dice.dice') local function buildDesc(building_class) local external_desc, internal_desc, powered_desc @@ -9,11 +8,11 @@ local function buildDesc(building_class) local material = e_desc.material[math.random(1, #e_desc.material)] external_desc = { - adjective = dice.chance(odds.adjective) and e_desc.adjective[math.random(1, #e_desc.adjective)] or false, - color = e_desc.colored_material[material] and dice.chance(odds.color) and e_desc.color[math.random(1, #e_desc.color)] or false, + adjective = odds.adjective >= math.random() and e_desc.adjective[math.random(1, #e_desc.adjective)] or false, + color = e_desc.colored_material[material] and odds.color >= math.random() and e_desc.color[math.random(1, #e_desc.color)] or false, material = material, - details = dice.chance(odds.details) and e_desc.details[math.random(1, #e_desc.details)] or false, - surroundings = dice.chance(odds.surroundings) and e_desc.surroundings[math.random(1, #e_desc.surroundings)] or false, + details = odds.details >= math.random() and e_desc.details[math.random(1, #e_desc.details)] or false, + surroundings = odds.surroundings >= math.random() and e_desc.surroundings[math.random(1, #e_desc.surroundings)] or false, } local i_desc = b_list[building_class].internal_desc diff --git a/code/location/tile/class.lua b/code/location/tile/class.lua index faa3fc8..abc0115 100644 --- a/code/location/tile/class.lua +++ b/code/location/tile/class.lua @@ -4,7 +4,6 @@ local b_list = require('code.location.building.list') --local building = require('code.location.building.class') local item = require('code.item.class') local lookupItem = require('code.item.search') -local dice = require('code.libs.rl-dice.dice') local tile = class('tile') --local building = class(building, tile) @@ -170,7 +169,7 @@ function tile:search(player, setting) local location_state = self:getState() local odds = self:getSearchOdds(player, setting, location_state) - local search_success = dice.chance(odds) + local search_success = odds >= math.random() if not search_success then return false end diff --git a/code/player/action/outcome.lua b/code/player/action/outcome.lua index 61ef7c0..baef392 100644 --- a/code/player/action/outcome.lua +++ b/code/player/action/outcome.lua @@ -9,7 +9,7 @@ local itemActivate = require('code.item.use.activate') local equipmentActivate = require('code.location.building.equipment.operation.activate') local skillActivate = require('code.player.skills.activate') local enzyme_list = require('code.player.enzyme_list') -local dice = require('code.libs.rl-dice.dice') +local dice = require('code.libs.dice') Outcome = {} @@ -73,7 +73,7 @@ function Outcome.attack(player, target, weapon, inv_ID) local retailation_damage = target.armor:getProtection('damage_melee_attacker') local is_melee_attack = weapon:getStyle() == 'melee' if is_melee_attack and retailation_damage > 0 then - local retailation_hp_loss = -1*dice:rollAndTotal(retailation_damage) + local retailation_hp_loss = -1*dice.roll(retailation_damage) player:updateStat('hp', retailation_hp_loss) -- insert some type of event? end @@ -194,7 +194,7 @@ function Outcome.feed(player) decay_loss = corpse_effects.decay[nutrition_lvl] end - xp_gained, decay_loss = dice.rollAndTotal(xp_gained), dice.rollAndTotal(decay_loss) + xp_gained, decay_loss = dice.roll(xp_gained), dice.roll(decay_loss) player:updateStat('xp', xp_gained) player.condition.decay:add(-1*decay_loss) diff --git a/code/player/armor/class.lua b/code/player/armor/class.lua index fa3f41d..d50a800 100644 --- a/code/player/armor/class.lua +++ b/code/player/armor/class.lua @@ -1,4 +1,4 @@ -local dice = require('code.libs.rl-dice.dice') +local dice = require('code.libs.dice') local class = require('code.libs.middleclass') local armor = class('armor') @@ -7,7 +7,7 @@ function armor:initialize(player) self.player = player end -function armor:failDurabilityCheck(degrade_chance) return dice.roll(self.durability) <= degrade_chance end +function armor:failDurabilityCheck(degrade_chance) return dice.roll(self.durability) <= degrade_chance end function armor:getProtection(damage_type) return self.protection[damage_type] or 0 end diff --git a/code/player/armor/item_class.lua b/code/player/armor/item_class.lua index 40a5c9e..401934d 100644 --- a/code/player/armor/item_class.lua +++ b/code/player/armor/item_class.lua @@ -1,5 +1,4 @@ local class = require('code.libs.middleclass') -local dice = require('code.libs.rl-dice.dice') local item_armor_list = require('code.item.list.armor') local armor = require('code.player.armor.class') diff --git a/code/player/armor/organic_class.lua b/code/player/armor/organic_class.lua index 732f193..72c72cd 100644 --- a/code/player/armor/organic_class.lua +++ b/code/player/armor/organic_class.lua @@ -1,5 +1,4 @@ local class = require('code.libs.middleclass') -local dice = require('code.libs.rl-dice.dice') local organic_armor_list = require('code.player.armor.organic_list') local armor = require('code.player.armor.class') diff --git a/code/player/carcass.lua b/code/player/carcass.lua index 3e6d209..c88017c 100644 --- a/code/player/carcass.lua +++ b/code/player/carcass.lua @@ -1,5 +1,5 @@ local class = require('code.libs.middleclass') -local dice = require('code.libs.rl-dice.dice') +local dice = require('code.libs.dice') local carcass = class('carcass') -- carcass description (very fresh|fresh|old meat) @@ -33,7 +33,7 @@ function carcass:devour(player) self.carnivour_list[player] = true local infestation = player.skills:check('digestion') and INFESTATION_DIGESTION_AMT or INFESTATION_DEVOUR_AMT - self:infest(dice.rollAndTotal(infestation)) + self:infest(dice.roll(infestation)) if #self.carnivour_list == MAX_FEEDINGS then self.infestation = MAX_INFESTATION @@ -53,7 +53,7 @@ end local INFESTATION_TICK_AMT = '1d5' -- this should be a server wide (single) roll function carcass:elapse() - self:infest(dice.rollAndTotal(INFESTATION_TICK_AMT)) + self:infest(dice.roll(INFESTATION_TICK_AMT)) end function carcass:reanimate() diff --git a/code/player/combat.lua b/code/player/combat.lua index 1b8fb25..326e734 100644 --- a/code/player/combat.lua +++ b/code/player/combat.lua @@ -1,15 +1,15 @@ local chanceToHit = require('code.item.weapon.chanceToHit') -local dice = require('code.libs.rl-dice.dice') +local dice = require('code.libs.dice') local function combat(player, target, weapon) - local attack = dice.chance(chanceToHit(player, target, weapon)) + local attack = chanceToHit(player, target, weapon) >= math.random() local damage, critical if attack then -- successful! if target:getClassName() == 'player' then local weapon_dice = weapon:getDice(player) - damage = dice.rollAndTotal(weapon_dice) - critical = dice.chance(weapon:getCrit()) + damage = dice.roll(weapon_dice) + critical = weapon:getCrit() >= math.random() if critical then damage = damage*2 end elseif target:getClassName() == 'equipment' then damage = weapon:getObjectDamage('equipment') diff --git a/code/player/condition/burn.lua b/code/player/condition/burn.lua index 0b890dc..06e64f7 100644 --- a/code/player/condition/burn.lua +++ b/code/player/condition/burn.lua @@ -1,5 +1,5 @@ local class = require('code.libs.middleclass') -local dice = require('code.libs.rl-dice.dice') +local dice = require('code.libs.dice') local burn = class('burn') @@ -22,7 +22,7 @@ function burn:isActive() end function burn:add(fuel, combustion_source) - fuel = dice.rollAndTotal(fuel) + fuel = dice.roll(fuel) self.units = math.min(self.units + fuel, MAX_UNITS) self.on_fire = combustion_source or false end @@ -49,7 +49,7 @@ function burn:damage() for burn_LV, burn_amount in ipairs(burn_data) do if self.units <= burn_amount then local damage_roll = burn_data.dice.damage[burn_LV] - return dice.rollAndTotal(damage_roll) + return dice.roll(damage_roll) end end end @@ -58,7 +58,7 @@ function burn:consumeFuel() local absorption_roll for burn_LV, burn_amount in ipairs(burn_data) do if self.units <= burn_amount then - absorption_roll = dice.rollAndTotal(burn_data.dice.absorption[burn_LV]) + absorption_roll = dice.roll(burn_data.dice.absorption[burn_LV]) break end end diff --git a/code/player/condition/decay.lua b/code/player/condition/decay.lua index 4ab628a..a38dbe2 100644 --- a/code/player/condition/decay.lua +++ b/code/player/condition/decay.lua @@ -1,5 +1,4 @@ local class = require('code.libs.middleclass') -local dice = require('code.libs.rl-dice.dice') local decay = class('decay') diff --git a/code/player/condition/infection.lua b/code/player/condition/infection.lua index a479408..70eb1fe 100644 --- a/code/player/condition/infection.lua +++ b/code/player/condition/infection.lua @@ -1,5 +1,4 @@ local class = require('code.libs.middleclass') -local dice = require('code.libs.rl-dice.dice') local infection = class('infection') diff --git a/code/player/condition/poison.lua b/code/player/condition/poison.lua index f232bb3..a909c59 100644 --- a/code/player/condition/poison.lua +++ b/code/player/condition/poison.lua @@ -1,5 +1,5 @@ local class = require('code.libs.middleclass') -local dice = require('code.libs.rl-dice.dice') +local dice = require('code.libs.dice') local poison = class('poison') @@ -26,7 +26,7 @@ function poison:isActive() end function poison:add(duration, amount) - duration, amount = dice.rollAndTotal(duration), dice.rollAndTotal(amount) + duration, amount = dice.roll(duration), dice.roll(amount) self.units = math.min(self.units + amount, MAX_UNITS) self.duration_remaining = duration end @@ -66,13 +66,13 @@ function poison:damage() for poison_LV, poison_amount in ipairs(poison_data) do if self.units <= poison_amount then local damage_roll = poison_data.dice.damage[poison_LV] - return dice.rollAndTotal(damage_roll) + return dice.roll(damage_roll) end end end function poison:rollDamageFrequency() - local frequency_roll = dice.rollAndTotal('1d'..(self.duration_count+1)..'-1') + local frequency_roll = dice.roll('1d'..(self.duration_count+1)..'-1') return frequency_roll end @@ -80,7 +80,7 @@ function poison:absorbIntoBloodstream() local absorption_roll for poison_LV, poison_amount in ipairs(poison_data) do if self.units <= poison_amount then - absorption_roll = dice.rollAndTotal(poison_data.dice.absorption[poison_LV]) + absorption_roll = dice.roll(poison_data.dice.absorption[poison_LV]) break end end diff --git a/code/player/condition/tracking.lua b/code/player/condition/tracking.lua index 72839e7..bb6c114 100644 --- a/code/player/condition/tracking.lua +++ b/code/player/condition/tracking.lua @@ -1,5 +1,5 @@ local class = require('code.libs.middleclass') -local dice = require('code.libs.rl-dice.dice') +local dice = require('code.libs.dice') local tracking = class('tracking') local TRACKING_TARGET_LIMIT, TRACKING_ADV_TARGET_LIMIT = 5, 8 @@ -23,13 +23,13 @@ function tracking:addScent(target) -- check if target is already on our list for i, scent in ipairs(self.list) do if scent.prey == target then -- update target to most recent - self.list[#self.list+1] = {prey = target, ticks = math.max(dice.rollAndTotal(scent_time), scent.ticks)} + self.list[#self.list+1] = {prey = target, ticks = math.max(dice.roll(scent_time), scent.ticks)} table.remove(self.list, i) return -- no need for other stuff end end - self.list[#self.list+1] = {prey = target, ticks = dice.rollAndTotal(scent_time)} + self.list[#self.list+1] = {prey = target, ticks = dice.roll(scent_time)} target.condition.tracking:addTracker(self.player) local target_limit = has_advanced_tracking and TRACKING_ADV_TARGET_LIMIT or TRACKING_TARGET_LIMIT From 5fe5a46e4261d55226970d245eacc16c5a002356 Mon Sep 17 00:00:00 2001 From: Timothy Date: Mon, 7 Nov 2016 22:54:37 -0600 Subject: [PATCH 2/3] Deleted old unused code and files --- code/backup/skills_with_cost_slots/class.lua | 87 ------------ code/backup/skills_with_cost_slots/flags.lua | 79 ----------- code/backup/skills_with_cost_slots/list.lua | 141 ------------------- code/item/medical/search.lua | 26 ---- code/item/search.lua | 14 -- code/item/use/activate.lua | 12 +- code/item/weapon/class.lua | 2 +- code/item/weapon/search.lua | 28 ---- code/location/building/equipment/search.lua | 30 ---- code/location/map/class.lua | 6 +- code/location/search.lua | 40 ------ code/location/tile/class.lua | 7 - 12 files changed, 8 insertions(+), 464 deletions(-) delete mode 100644 code/backup/skills_with_cost_slots/class.lua delete mode 100644 code/backup/skills_with_cost_slots/flags.lua delete mode 100644 code/backup/skills_with_cost_slots/list.lua delete mode 100644 code/item/medical/search.lua delete mode 100644 code/item/search.lua delete mode 100644 code/item/weapon/search.lua delete mode 100644 code/location/building/equipment/search.lua delete mode 100644 code/location/search.lua diff --git a/code/backup/skills_with_cost_slots/class.lua b/code/backup/skills_with_cost_slots/class.lua deleted file mode 100644 index 2403a8a..0000000 --- a/code/backup/skills_with_cost_slots/class.lua +++ /dev/null @@ -1,87 +0,0 @@ -local class = require('libs/middleclass') -local bit = require('bit') -local band, bor, bxor, bnot = bit.band, bit.bor, bit.bxor, bit.bnot -local flags = require('player/skills/flags') -local s_list = require('player/skills/list') - -local skills = class('skills') -local default_slots = 12 - -function skills:initialize() - self.flags = 0 - self.slots = default_slots -end - -function skills:getFlags() return self.flags end - -function skills:isSlotAvailable() return self.slots > 0 end - -function skills:updateSlots(num) self.slots = self.slots + num end - --- class prices, 100, 200, 350, 550 --- skill buy formula (y = .2*(x)^2 + .25*(x) + 50) -function skills:buy(player, skill) - local player_mob_type = player:getMobType() - local slot_open = player.skills:isSlotAvailable() - local xp = player:getXP() - - local cost = s_list:getCost(skill) - local required_flags = s_list:getRequiredFlags(skill) - local skill_mob_type = s_list:getMobType(skill) - local innate = s_list:isInnate(skill) - local memory = s_list:getMemory(skill) ---print('[skills:buy]', 'player.xp='..xp, 'skill['..skill..'] cost='..cost) - - -- should return error msgs? - if xp < cost then return error('not enough xp') end - if skill_mob_type ~= player_mob_type then return false end - if not player:isStanding() then return false end - ---[[ -if required_flags ~= 0 then -print('required_flags='..required_flags) -print('skills:check - ', player.skills:check(required_flags)) -end ---]] - - if required_flags ~= 0 and not player.skills:check(required_flags) then return false end - - - if not innate and not slot_open then return false end - - player:updateXP( (-1)*cost) - - if innate then - player.skills:add(skill) - if memory then player.skills:updateSlots(memory) end - else - player.skills:add(skill) - player.skills:updateSlots(-1) - end -end - -local function lookupFlags(skills) - local array = {} - for i, skill in ipairs(skills) do -print('[player/skills/class lookupFlags] - '..skill, flags[skill]) - if not flags[skill] then return error('Skill does not exist') end - array[i] = flags[skill] end - return array -end - -local function combineFlags(requirements) - local list = lookupFlags(requirements) - return bor(unpack(list)) -end - -function skills:check(skill_flag) ---print('self.flags='..self.flags, 'skill_flag='..skill_flag) - return band(self:getFlags(), skill_flag) > 0 end - - function skills:add(skill) ---print('self.flags - ', self.flags,'flags[skill]', flags[skill]) - self.flags = bor(self.flags, flags[skill]) end - -function skills:remove(skill) self.flags = band(self.flags, bnot(flags[skill])) end - -return skills \ No newline at end of file diff --git a/code/backup/skills_with_cost_slots/flags.lua b/code/backup/skills_with_cost_slots/flags.lua deleted file mode 100644 index 55062bf..0000000 --- a/code/backup/skills_with_cost_slots/flags.lua +++ /dev/null @@ -1,79 +0,0 @@ --- 64 skills max (4 are classes/4 are slots) - --- 56 skills 5 cataegories (16 general skills, 10 in each skill tree [4x10 = 40] ) ---start,300,350,400,500xp --- 12, 14, 12, 10, 8 - -local skill_flags = { - military = 1, - medical = 2, - science = 4, - engineering = 8, - - brute = 1, - sentient = 2, - hunter = 4, - hive = 8, - - slot26 = 16, - slot38 = 32, - slot48 = 64, - slot56 = 128, -} -- The numbers start to get REALLY big soooo time to *2 our bitflags - ---[[ ---- HUMAN ---]] - --- General -skill_flags.roof_travel = skill_flags.slot56*2 -skill_flags.melee = skill_flags.roof_travel*2 -skill_flags.stabbing = skill_flags.melee*2 -skill_flags.swinging = skill_flags.stabbing*2 -skill_flags.ranged = skill_flags.swinging*2 - --- Military -skill_flags.melee_adv = skill_flags.ranged*2 -skill_flags.stabbing_adv = skill_flags.melee_adv*2 -skill_flags.swinging_adv = skill_flags.stabbing_adv*2 -skill_flags.ranged_adv = skill_flags.swinging_adv*2 -skill_flags.weapon_expert = skill_flags.ranged_adv*2 - --- Medical -skill_flags.diagnosis = skill_flags.weapon_expert*2 -skill_flags.diagnosis_adv = skill_flags.diagnosis*2 -skill_flags.first_aid = skill_flags.diagnosis_adv*2 -skill_flags.surgery = skill_flags.first_aid*2 - --- Science -skill_flags.lab_tech = skill_flags.surgery*2 -skill_flags.researcher = skill_flags.lab_tech*2 - --- Engineering -skill_flags.repairs = skill_flags.researcher*2 -skill_flags.repairs_adv = skill_flags.repairs*2 - ---[[ ---- ZOMBIE ---]] - --- General - -skill_flags.groan = skill_flags.slot56*2 - --- Brute - --- Hunter - --- Sentient - --- Hive - ---[[ -print() -print('SKILL_FLAGS LIST') -print() -for k,v in pairs(skill_flags) do print(k,v) end ---]] - -return skill_flags \ No newline at end of file diff --git a/code/backup/skills_with_cost_slots/list.lua b/code/backup/skills_with_cost_slots/list.lua deleted file mode 100644 index 2bf9f38..0000000 --- a/code/backup/skills_with_cost_slots/list.lua +++ /dev/null @@ -1,141 +0,0 @@ -local skill_flags = require('player/skills/flags') -local skill_list = {} -local bit = require('bit') -local band, bor, bxor, bnot = bit.band, bit.bor, bit.bxor, bit.bnot - ---[[ - skill = {name='string', desc='string', innate=true/nil, requires={'skill_name1', 'skill_name2', etc.}/nil} ---]] - -local skill_info = { - zombie = { - general = {}, - brute = {}, - sentient = {}, - hunter = {}, - hive = {}, - }, - human = { - general = { - engineering = {name='engineering', desc='Unlock Engineering skills', innate=true,}, - military = {name='military', desc='Unlock Military skills', innate=true,}, - science = {name='science', desc='Unlock Science skills', innate=true,}, - medical = {name='medical', desc='Unlock Medical skills', innate=true,}, - - melee = {name='melee', desc='Melee weapons +5% to-hit'}, - cutting = {name='cutting', desc='Blade weapons +10% to-hit', requires={'melee'},}, - swinging = {name='swinging', desc='Blunt weapons +10% to-hit', requires={'melee'},}, - smacking = {name='smacking', desc='Light blunt weapons +15 to-hit', requires={'swinging'},}, - martial_arts = {name='martial arts', desc='Hand-to-hand combat +15 to-hit', requires={'melee'}, }, - ranged = {name='ranged', desc='Ranged weapons +5% to-hit'}, - roof_travel = {name='roof travel', desc='Travel through buildings'}, - hp_bonus = {name='hp bonus', desc='Bonus +10 hp',}, - ip_bonus = {name='ip bonus', desc='Bonus +10 ip', requires={'hp_bonus'},}, - looting = {name='looting', desc='bonus for searching',}, - }, - - military = { - ranged_adv = {name='ranged advanced', desc='Ranged weapons +10% to-hit'}, - guns = {}, - shotguns = {}, - handguns = {}, - rifles = {}, - archery = {}, - bows = {}, - melee_adv = {name='melee advanced', desc='Melee weapons +10% to-hit'}, - chopping = {}, - slicing = {}, - smashing = {}, - --stabbing_adv = {name='slice & dice', desc='Blade weapons +15% to-hit', requires={'melee_adv'},}, - --swinging_adv = {name='melee master', desc='Blunt weapons +15% to-hit', requires={'melee_adv'},}, - explosives = {name='explosives', desc='Scorch weapons +10% to-hit'}, - }, - medical = { - diagnosis = {name='check up', desc='Determine VAGUE health status'}, - diagnosis_adv = {name='diagnosis', desc='Determine PRECISE health status', requires={'diagnosis'},}, - first_aid = {name='first aid', desc='First Aid Kits give +10 hp',}, - surgery = {name='surgery', desc='First Aid Kits give +15 hp in powered hospital', requires={'first_aid'},}, - }, - science = { - lab_tech = {name='lab tech', desc='Gain ability to use science equipment',}, - researcher = {name='researcher', desc='Gain ability to tag zombies and track via terminals',}, - computer_tech = {}, -- terminals installed/repaired/use at less ap - }, - engineering = { - construction = {}, - repairs = {name='basic repairs', desc='Gain ability to repair equipment',}, - repairs_adv= {name='advanced repairs',desc='Gain ability to repair ruined buildings',}, - renovate = {} -- repair ruins - barricade = {}, -- barricade past very strongly? - barricade_adv= {name='pack rat', desc='Build better barricades',}, -- +1 to all barricades - reinforce = {}, -- extend max barricade limit more easier - tech = {}, - power_tech = {}, -- generators installed/repaired at less ap - radio_tech = {}, - computer_tech = {}, - - reserve = {} -- toolbox durability increased - }, - }, -} - --- 64 skills max (4 are classes) --- 60 skills 5 cataegories (12 general skills, 12 in each skill tree) - ---[[ -print() -print('SKILL_FLAGS LIST') -print() -for k,v in pairs(skill_flags) do print(k,v) end ---]] - -local function lookupFlags(skills) - local array = {} - for i, skill in ipairs(skills) do array[i] = skill_flags[skill] end - return array -end - -local function combineFlags(requirements) - local list = lookupFlags(requirements) - return bor(unpack(list)) -end - -local function fillList(list) - for mob_type in pairs(skill_info) do - for skill_tree in pairs(skill_info[mob_type]) do - for skill, data in pairs(skill_info[mob_type][skill_tree]) do - list[skill] = data - list[skill].mob_type = mob_type - list[skill].category = skill_tree - - list[skill].requires = list[skill].requires or {} - list[skill].requires[#list[skill].requires+1] = (skill_tree ~= 'general' and skill_tree) or nil ---print('skill - '..skill, 'skill_tree - '..skill_tree) - local requirements = list[skill].requires - list[skill].required_flags = next(requirements) and combineFlags(requirements) or 0 ---print('skill - '..skill, 'flags - '..list[skill].flags) - end - end - end - return list -end - -do -- combine zombie/human skills into one list - skill_list = fillList(skill_list) -end - -function skill_list:getCost(skill) return skill_list[skill].cost end - -function skill_list:getRequirement(skill) return skill_list[skill].requires end - -function skill_list:getRequiredFlags(skill) return skill_list[skill].required_flags end - -function skill_list:getMobType(skill) return skill_list[skill].mob_type end - -function skill_list:getMemory(skill) return skill_list[skill].memory end - -function skill_list:isInnate(skill) return skill_list[skill].innate end - -function skill_list:isMemory(skill) return skill_list[skill].memory and true or false end - -return skill_list \ No newline at end of file diff --git a/code/item/medical/search.lua b/code/item/medical/search.lua deleted file mode 100644 index 3167333..0000000 --- a/code/item/medical/search.lua +++ /dev/null @@ -1,26 +0,0 @@ -local medical = require('code.item.medical.class') - -local medical_list = {medical.FAK, medical.bandage, medical.antidote} - -for ID, obj in ipairs(medical_list) do - medical_list[obj:getName()] = ID - obj.medical_ID = ID -end - -local function lookupMedical(obj) - local med - if type(obj) == 'string' then - local ID = medical_list[obj] - med = medical_list[ID] - elseif type(obj) == 'number' then - local ID = obj - med = medical_list[ID] - else - error('item medical_lookup invalid') - end - return med -end - ---for i,v in ipairs(medical_list) do print(k,v) end - -return lookupMedical \ No newline at end of file diff --git a/code/item/search.lua b/code/item/search.lua deleted file mode 100644 index 5d2cf3d..0000000 --- a/code/item/search.lua +++ /dev/null @@ -1,14 +0,0 @@ -local item_CL = require('code.item.class') -local order = require('code.item.order') - -local item_list = order - -for ID, name in ipairs(item_list) do - item_list[name] = ID -- do we need this? maybe...? - item_CL[name].ID = ID -end - --- ID can be a num or str -local function lookup(ID) return item_CL[ID] end - -return lookup \ No newline at end of file diff --git a/code/item/use/activate.lua b/code/item/use/activate.lua index 3e8ee4f..67f9a62 100644 --- a/code/item/use/activate.lua +++ b/code/item/use/activate.lua @@ -1,6 +1,6 @@ local dice = require('code.libs.dice') -local lookupMedical = require('code.item.medical.search') local flags = require('code.player.skills.flags') +local medical = require('code.item.medical.class') local activate = {} @@ -9,8 +9,7 @@ local activate = {} --]] function activate.FAK(player, condition, target) - local FAK = lookupMedical('FAK') - local FAK_dice = dice:new(FAK:getDice()) + local FAK_dice = dice:new(medical.FAK:getDice()) local tile = player:getTile() if player.skills:check(flags.recovery) and tile:isBuilding() and tile:isPowered() and player:isStaged('inside') then @@ -35,8 +34,7 @@ function activate.FAK(player, condition, target) end function activate.bandage(player, condition, target) - local bandage = lookupMedical('bandage') - local bandage_dice = dice:new(bandage:getDice()) + local bandage_dice = dice:new(medical.bandage:getDice()) if player.skills:check(flags.recovery) then bandage_dice = bandage_dice+1 @@ -56,7 +54,7 @@ function activate.bandage(player, condition, target) end function activate.antidote(player, condition, target) - local antidote = lookupMedical('antidote') + local antidote = medical.antidote local cure_chance = antidote:getAccuracy() -- modify chance based on skills? @@ -71,7 +69,7 @@ function activate.antidote(player, condition, target) end function activate.syringe(player, condition, target) - local syringe = lookupMedical('syringe') + local syringe = medical.syringe local inject_chance = syringe:getAccuracy() -- modify chance based on skills? diff --git a/code/item/weapon/class.lua b/code/item/weapon/class.lua index 7669b88..a0d2e25 100644 --- a/code/item/weapon/class.lua +++ b/code/item/weapon/class.lua @@ -3,7 +3,7 @@ local item = require('code.item.class') local chanceToHit = require('code.item.weapon.chanceToHit') local w_list = require('code.item.weapon.list') local entangle = require('code.player.condition.entangle') -local dice = require('code.libs.rl-dice.dice') +local dice = require('code.libs.dice') local weapon = class('weapon', item) diff --git a/code/item/weapon/search.lua b/code/item/weapon/search.lua deleted file mode 100644 index 38f00fb..0000000 --- a/code/item/weapon/search.lua +++ /dev/null @@ -1,28 +0,0 @@ ---[[ -local weapon = require('code.item.weapon.class') - -local weapon_list = {weapon.fist, weapon.bite, weapon.claw, weapon.crowbar, weapon.sledge, weapon.knife, weapon.katanna, weapon.pistol, weapon.shotgun} - -for ID, obj in ipairs(weapon_list) do - weapon_list[obj:getName()] = ID - obj.weapon_ID = ID -end - -local function lookupWeapon(obj) - local weap - if type(obj) == 'string' then - local ID = weapon_list[obj] - weap = weapon_list[ID] - elseif type(obj) == 'number' then - local ID = obj - weap = weapon_list[ID] - else - error('item weapon_lookup invalid') - end - return weap -end - ---for i,v in ipairs(weapon_list) do print(k,v) end - -return lookupWeapon ---]] \ No newline at end of file diff --git a/code/location/building/equipment/search.lua b/code/location/building/equipment/search.lua deleted file mode 100644 index 7da7e21..0000000 --- a/code/location/building/equipment/search.lua +++ /dev/null @@ -1,30 +0,0 @@ -local building = require('code.location.building.class') -local tile = require('code.location.tile.class') - -local generator = require('code.location.building.equipment.generator.class') -local transmitter = require('code.location.building.equipment.transmitter.class') -local terminal = require('code.location.building.equipment.terminal.class') - -local equipment_list = {generator, transmitter, terminal} - -for ID, equipment in ipairs(equipment_list) do ---print(equipment:getName(), ID) - equipment_list[equipment:getName()] = ID - equipment.ID = ID -end - -local function lookup(equipment) ---print(equipment) - if type(equipment) == 'string' then - local ID = equipment_list[equipment] - equipment = equipment_list[ID] - elseif type(equipment) == 'number' then - local ID = equipment - equipment = equipment_list[ID] - else - error('equipment lookup invalid') - end - return equipment -end - -return lookup \ No newline at end of file diff --git a/code/location/map/class.lua b/code/location/map/class.lua index 2ca07c1..adb4dbc 100644 --- a/code/location/map/class.lua +++ b/code/location/map/class.lua @@ -3,7 +3,6 @@ local class = require('code.libs.middleclass') local tile = require('code.location.tile.class') local building = require('code.location.building.class') local b_list = require('code.location.building.list') -local lookupArea = require('code.location.search') local map = class('map') @@ -20,9 +19,8 @@ function map:initialize(size) for y=1, size do self[y] = {} for x=1, size do - - local location = lookupArea(tile_type) - self[y][x] = location:new(self, y, x, '[insert name]') + + self[y][x] = building[tile_type]:new(self, y, x, '[insert name]') end end end diff --git a/code/location/search.lua b/code/location/search.lua deleted file mode 100644 index 0df8685..0000000 --- a/code/location/search.lua +++ /dev/null @@ -1,40 +0,0 @@ -local building = require('code.location.building.class') -local tile = require('code.location.tile.class') - -local area_list = { - -- TILES - tile.street, tile.cemetary, tile.monument, tile.park, tile.wasteland, - tile.stadium, tile.junkyard, tile.carpark, - -- BUILDINGS - building.PD, building.FD, building.warehouse, building.factory, building.sport, - building.hotel, building.hospital, building.apartment, building.warehouse, building.factory, - building.school, building.library, building.mall, building.bar, building.bank, - building.museum, building.power, building.lab, building.ISP, building.toolshop, - building.theatre, building.church, building.nightclub, building.gas, building.vacant, - building.power, building.food, -} - -for ID, area in ipairs(area_list) do ---print(area:getName(), ID) ---print(area) ---for k,v in pairs(area) do print(k,v) end ---print() - area_list[area:getName()] = ID - area.ID = ID -end - -local function lookup(area) ---print(area) - if type(area) == 'string' then - local ID = area_list[area] - area = area_list[ID] - elseif type(area) == 'number' then - local ID = area - area = area_list[ID] - else - error('area lookup invalid') - end - return area -end - -return lookup \ No newline at end of file diff --git a/code/location/tile/class.lua b/code/location/tile/class.lua index abc0115..3c6bc22 100644 --- a/code/location/tile/class.lua +++ b/code/location/tile/class.lua @@ -1,12 +1,9 @@ local class = require('code.libs.middleclass') local t_list = require('code.location.tile.list') local b_list = require('code.location.building.list') ---local building = require('code.location.building.class') local item = require('code.item.class') -local lookupItem = require('code.item.search') local tile = class('tile') ---local building = class(building, tile) function tile:initialize(map, y, x, name) self.y, self.x = y, x @@ -182,10 +179,6 @@ print('location_state - ', location_state) if self:getClassName() == 'junkyard' then location_state = 'powered' end local item_INST = item[item_type]:new(location_state) - --- DO WE NEED THIS?! ---local item = lookupItem(item_name) -- do we need item[#ID] or item class? - return item_INST end From 2efa9ceb0cefcad23ac297bf1f000a33ef80c486 Mon Sep 17 00:00:00 2001 From: Timothy Date: Sun, 13 Nov 2016 10:39:32 -0600 Subject: [PATCH 3/3] Removed old code --- code/item/medical/class.lua | 14 -------------- code/location/building/class.lua | 1 - code/location/tile/class.lua | 2 -- 3 files changed, 17 deletions(-) diff --git a/code/item/medical/class.lua b/code/item/medical/class.lua index 414f058..070f7be 100644 --- a/code/item/medical/class.lua +++ b/code/item/medical/class.lua @@ -22,20 +22,6 @@ function medical:getDice() return self.dice end function medical:getGroup() return self.group end ---function medical:getWeaponID() return self.weapon_ID end - ---[[ -for obj in pairs(w_list) do - medical[obj] = class(obj, medical) - medical[obj].initialize = function(self) - medical.initialize(self) - end - - for field, data in pairs(w_list[obj]) do medical[obj][field] = data end -end ---]] - - function medical:dataToClass(...) -- this should be a middleclass function (fix later) local combined_lists = {...} for _, list in ipairs(combined_lists) do diff --git a/code/location/building/class.lua b/code/location/building/class.lua index 43cbd66..3676ffc 100644 --- a/code/location/building/class.lua +++ b/code/location/building/class.lua @@ -1,6 +1,5 @@ local class = require('code.libs.middleclass') local b_list = require('code.location.building.list') ---local lookupItem = require('code.search.item') local tile = require('code.location.tile.class') local equipment = require('code.location.building.equipment.class') local generator = require('code.location.building.equipment.generator.class') diff --git a/code/location/tile/class.lua b/code/location/tile/class.lua index 3c6bc22..7db52c6 100644 --- a/code/location/tile/class.lua +++ b/code/location/tile/class.lua @@ -122,8 +122,6 @@ function tile:getDesc(setting) return str end ---function tile:getTileType() return self.tile_type end - function tile:getPlayers(setting) local players if setting == 'inside' then