Skip to content

Commit

Permalink
Merge branch 'hotfix-v0.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
timothymtorres committed Aug 13, 2017
2 parents 68a749e + 3685a3b commit fc155d9
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 42 deletions.
10 changes: 5 additions & 5 deletions code/item/class.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 3 additions & 20 deletions code/item/list/armor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions code/item/use/activate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions code/item/use/check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions code/item/use/criteria.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions code/player/action/list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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},},
Expand Down
4 changes: 4 additions & 0 deletions code/player/action/zone.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 --
Expand Down
26 changes: 23 additions & 3 deletions code/player/armor/class.lua
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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
27 changes: 15 additions & 12 deletions code/player/armor/item_class.lua
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
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)

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
31 changes: 31 additions & 0 deletions code/player/armor/item_list.lua
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions code/player/log/getMessage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 --
Expand Down
2 changes: 1 addition & 1 deletion main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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('---------')
Expand Down
2 changes: 1 addition & 1 deletion settings.lua
Original file line number Diff line number Diff line change
@@ -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.',
Expand Down

0 comments on commit fc155d9

Please sign in to comment.