diff --git a/code/item/class.lua b/code/item/class.lua index 0f1a906..f03b274 100644 --- a/code/item/class.lua +++ b/code/item/class.lua @@ -29,11 +29,11 @@ local condition_spawn_odds = { -- used when spawning new item powered = {[1] = 0.10, [2] = 0.25, [3] = 0.40, [4] = 0.25}, } -function item:initialize(location_status) ---print(condition_spawn_odds, location_status) ---print(condition_spawn_odds[location_status]) - self.condition = selectFrom(condition_spawn_odds[location_status]) ---print('self.condition - ', self.condition) +function item:initialize(condition_setting) + if type(condition_setting) == 'string' then self.condition = selectFrom(condition_spawn_odds[condition_setting]) + elseif type(condition_setting) == 'number' and condition_setting > 0 and condition_setting <= 4 then self.condition = condition_setting + else error('Item initialization has a malformed condition setting') + end end --[[ THESE ARE SERVER/DATABASE FUNCTIONS diff --git a/code/item/list/armor.lua b/code/item/list/armor.lua index b2c342e..c0b18ca 100644 --- a/code/item/list/armor.lua +++ b/code/item/list/armor.lua @@ -2,32 +2,15 @@ local armor = {} --[[ full_name = 'insert name' - durability = num (average # of attacks it takes to wear armor out) - resistance = { - condition = {protection=num}, - } - - ** As condition becomes worse armor starts to lose resistance (with the exception of a few armors) + durability = 0 (all armor is one_use) --]] armor.leather = {} armor.leather.full_name = 'leather jacket' -armor.leather.durability = 32 -armor.leather.resistance = { - [0] = {blunt=1}, - [1] = {blunt=1}, - [2] = {blunt=1}, - [3] = {blunt=1}, -} +armor.leather.durability = 0 armor.firesuit = {} armor.firesuit.full_name = 'firesuit' -armor.firesuit.durability = 4 -armor.firesuit.resistance = { - [0] = {acid=1}, - [1] = {acid=2}, - [2] = {acid=3}, - [3] = {acid=4}, -} +armor.firesuit.durability = 0 return armor \ No newline at end of file diff --git a/code/item/use/activate.lua b/code/item/use/activate.lua index 6b198b9..dcb970f 100644 --- a/code/item/use/activate.lua +++ b/code/item/use/activate.lua @@ -205,4 +205,16 @@ function activate.bottle(player, condition) player:updateHP(1) end +--[[ +--- ARMOR +--]] + +function activate.leather(player, condition) + player.armor:equip('leather', condition) +end + +function activate.firesuit(player, condition) + player.armor:equip('firesuit', condition) +end + return activate \ No newline at end of file diff --git a/code/item/use/check.lua b/code/item/use/check.lua index abf4151..24c4647 100644 --- a/code/item/use/check.lua +++ b/code/item/use/check.lua @@ -103,4 +103,12 @@ function check.barricade(player) assert(playerInsideBuilding(player), 'Must be inside building to use barricade') end +--[[ +--- ARMOR +--]] + +function check.leather(player) end + +function check.firesuit(player) end + return check \ No newline at end of file diff --git a/code/item/use/criteria.lua b/code/item/use/criteria.lua index a63b116..1897553 100644 --- a/code/item/use/criteria.lua +++ b/code/item/use/criteria.lua @@ -170,4 +170,12 @@ function criteria.newspaper(player) end -- need light? function criteria.bottle(player) end +--[[ +--- ARMOR +--]] + +function criteria.leather(player) end -- make sure there is inventory room when unequiping armor? + +function criteria.firesuit(player) end + return criteria \ No newline at end of file diff --git a/code/player/action/list.lua b/code/player/action/list.lua index aa3853a..ba0082d 100644 --- a/code/player/action/list.lua +++ b/code/player/action/list.lua @@ -65,6 +65,8 @@ local action_list = { antidote = {name='antidote', cost=1}, antibodies= {name='antibodies', cost=1}, syringe = {name='syringe', cost=1}, + leather = {name='leather', cost=1}, + firesuit = {name='firesuit', cost=1}, }, equipment = { broadcast = {cost=3, modifier={tech = -1, radio_tech = -1},}, diff --git a/code/player/action/zone.lua b/code/player/action/zone.lua index dfb1029..73ca550 100644 --- a/code/player/action/zone.lua +++ b/code/player/action/zone.lua @@ -79,6 +79,10 @@ function setupZone.syringe(player, inv_ID, target) zone.target = target end +function setupZone.leather(player, inv_ID) + zone.type = 'self' +end + --------------------------------------- --------------------------------------- -- ZOMBIE -- diff --git a/code/player/armor/class.lua b/code/player/armor/class.lua index d50a800..2f03b5a 100644 --- a/code/player/armor/class.lua +++ b/code/player/armor/class.lua @@ -1,4 +1,5 @@ local dice = require('code.libs.dice') +local item_armor_list = require('code.player.armor.item_list') local class = require('code.libs.middleclass') local armor = class('armor') @@ -7,10 +8,29 @@ function armor:initialize(player) self.player = player end -function armor:failDurabilityCheck(degrade_chance) return dice.roll(self.durability) <= degrade_chance end +-- Possibly consider redoing armor for the zombies? Make it similiar to human armor or less complex... if it's made to be similiar to human armor, it will shrink +-- down the code in this file quite a bit, no need to differenate between human/zombie mobtypes -function armor:getProtection(damage_type) return self.protection[damage_type] or 0 end +function armor:failDurabilityCheck(degrade_chance) + local player, protection = self.player + + if player:isMobType('human') then return dice.roll(item_armor_list[self.name].durability) <= degrade_chance + elseif player:isMobType('zombie') then return dice.roll(self.durability) <= degrade_chance + end +end -function armor:isPresent() return self.protection and true or false end +function armor:getProtection(damage_type) + local player, protection = self.player + + if player:isMobType('human') then return item_armor_list[self.name].resistance[self.condition][damage_type] or 0 + elseif player:isMobType('zombie') then return self.protection[damage_type] or 0 + end +end + +function armor:isPresent() + if player:isMobType('human') then return self.name and true or false + elseif player:isMobType('zombie') then return self.protection and true or false + end +end return armor \ No newline at end of file diff --git a/code/player/armor/item_class.lua b/code/player/armor/item_class.lua index 42a8126..8e74737 100644 --- a/code/player/armor/item_class.lua +++ b/code/player/armor/item_class.lua @@ -1,6 +1,7 @@ -local class = require('code.libs.middleclass') +local class = require('code.libs.middleclass') local item_armor_list = require('code.item.list.armor') -local armor = require('code.player.armor.class') +local item = require('code.item.class') +local armor = require('code.player.armor.class') local item_armor = class('item_armor', armor) @@ -8,23 +9,25 @@ function item_armor:initialize(player) armor.initialize(self, player) end -function item_armor:equip(name, condition, inv_ID) - self.protection = item_armor_list[name].resistance[condition] - self.name, self.inv_ID, self.condition = name, inv_ID, condition - self.durability = item_armor_list[name].durability +function item_armor:equip(name, condition) + if self:isPresent() then self:remove() end -- unequips the old armor and puts it back into the inventory + self.name, self.condition = name, condition end -function item_armor:degrade(player) - local item_INST = player.inventory:lookup(self.inv_ID) - item_INST:updateCondition(-1, player, self.inv_ID) +function item_armor:remove() + local player, armor_type, condition = self.player, self.name, self.condition + local armor_INST = item[armor_type]:new(condition) + player.inventory:insert(armor_INST) + self.name, self.condition = nil, nil +end + +function item_armor:degrade(player) self.condition = self.condition - 1 if 0 > self.condition then -- armor is destroyed - local player = self.player - player.armor = item_armor:new(player) + self.name, self.condition = nil, nil return -- something to tell that armor is destroyed? end - self.protection = item_armor_list[self.name].resistance[self.condition] end return item_armor \ No newline at end of file diff --git a/code/player/armor/item_list.lua b/code/player/armor/item_list.lua new file mode 100644 index 0000000..40c3fbe --- /dev/null +++ b/code/player/armor/item_list.lua @@ -0,0 +1,31 @@ +local armor = {} + +--[[ + full_name = 'insert name' + durability = num (average # of attacks it takes to wear armor out) + resistance = { + condition = {protection=num}, + } + + ** As condition becomes worse armor starts to lose resistance (with the exception of a few armors) +--]] + +armor.leather = {} +armor.leather.durability = 32 +armor.leather.resistance = { + [1] = {blunt=1}, + [2] = {blunt=1}, + [3] = {blunt=1}, + [4] = {blunt=1}, +} + +armor.firesuit = {} +armor.firesuit.durability = 4 +armor.firesuit.resistance = { + [1] = {acid=1}, + [2] = {acid=2}, + [3] = {acid=3}, + [4] = {acid=4}, +} + +return armor \ No newline at end of file diff --git a/code/player/log/getMessage.lua b/code/player/log/getMessage.lua index 1d267cd..7f45922 100644 --- a/code/player/log/getMessage.lua +++ b/code/player/log/getMessage.lua @@ -88,6 +88,16 @@ function description.syringe(player, inv_ID, target, inject_success, target_weak end end +function description.leather(player, inv_ID) + local armor_INST = player.inventory:lookup(inv_ID) + msg[1] = 'You equip '..armor_INST:getClassName()..' armor.' +end + +function description.firesuit() + local armor_INST = player.inventory:lookup(inv_ID) + msg[1] = 'You equip '..armor_INST:getClassName()..' armor.' +end + --------------------------------------- --------------------------------------- -- ZOMBIE -- diff --git a/main.lua b/main.lua index eec2895..7f5df64 100644 --- a/main.lua +++ b/main.lua @@ -51,7 +51,7 @@ end local firesuit_INST = item.firesuit:new('ruined') alt_player.inventory:insert(firesuit_INST) -alt_player.armor:equip('firesuit', firesuit_INST:getCondition(), #alt_player.inventory) +alt_player.armor:equip('firesuit', firesuit_INST:getCondition()) --[[ print('---------') diff --git a/settings.lua b/settings.lua index 1b6d4fa..2a72fbc 100644 --- a/settings.lua +++ b/settings.lua @@ -1,5 +1,5 @@ local settings = { - _VERSION = 'ZomboTropolis v0.4.0', + _VERSION = 'ZomboTropolis v0.4.1', _AUTHOR = 'Timothy Torres', _URL = 'https://github.com/timothymtorres/ZomboTropolis-Roguelike', _DESCRIPTION = 'A zombie survival roguelike MMORPG.',