diff --git a/scripts/gameobjects/cards.lua b/scripts/gameobjects/cards.lua index 89784b4..35c79fb 100644 --- a/scripts/gameobjects/cards.lua +++ b/scripts/gameobjects/cards.lua @@ -281,6 +281,66 @@ cards.loan = { is_creeper = true, } +cards.football_match = { + name = "Football match", + effects = { + { + type = "resource", + resource="happiness", + value = 30, + }, + }, + requirements = {{type="resource", property="happiness", relation="gt", value=30}}, + costs = {}, + autoadd=true, + is_creeper = true, +} + +cards.demonstration = { + name = "Demonstration", + effects = { + { + type = "resource", + resource="nuisance", + value = 30, + }, + }, + requirements = {{type="building_count", filter={"small_generator", "medium_generator"}, relation="gt", value=9}}, + costs = {}, + autoadd=true, + is_creeper = true, +} + +cards.vacancy = { + name = "Vacancy", + effects = { + { + type = "resource", + resource = "nuisance", + value = 30, + }, + }, + requirements = {{type="resource", property="excessHousing", relation="gt", value=20}}, + costs = {}, + autoadd=true, + is_creeper = true, +} + +cards.lack_of_work = { + name = "Lack of workers", + effects = { + { + type = "resource", + resource = "money", + value = -30, + }, + }, + requirements = {{type="resource", property="work", relation="lt", value=-15}}, + costs = {}, + autoadd = true, + is_creeper = true, +} + -- -- Additional functions -- @@ -303,12 +363,34 @@ local function verifyResourceRequirement(requirement, state) end end +local function verifyBuildingCountRequirement(requirement, state) + local S = scripts.helpers.gamerules.countBuildingTypes + if requirement.relation == "gt" then + return S(state, requirement.filter) > requirement.value + end + if requirement.relation == "lt" then + return S(state, requirement.filter) < requirement.value + end + if requirement.relation == "gte" then + return S(state, requirement.filter) >= requirement.value + end + if requirement.relation == "lte" then + return S(state, requirement.filter) <= requirement.value + end + if requirement.relation == "eq" then + return S(state, requirement.filter) == requirement.value + end +end + for _, card in pairs(cards) do function card:verifyRequirements(state) for _, requirement in ipairs(self.requirements) do if requirement.type == "resource" then if not verifyResourceRequirement(requirement, state) then return false end end + if requirement.type == "building_count" then + if not verifyBuildingCountRequirement(requirement, state) then return false end + end end return true end diff --git a/scripts/helpers/gamerules.lua b/scripts/helpers/gamerules.lua index 4cb56a3..b36212c 100644 --- a/scripts/helpers/gamerules.lua +++ b/scripts/helpers/gamerules.lua @@ -130,6 +130,16 @@ function gamerules.addCard(state, card) table.insert(state.discardPile, card) end +function gamerules.countBuildingTypes(state, types) + local i = 0 + for _, building in ipairs(state.buildings) do + if list_contains(types, building.building) then + i = i + 1 + end + end + return i +end + local beforeTurn = { housing = 0, happiness = 0, @@ -232,5 +242,6 @@ gamerules.resources.nuisance = gamerules.getNuisance gamerules.resources.money = function(state) return state.properties.money end +gamerules.resources.excessHousing = gamerules.getAvailableHousing return gamerules diff --git a/scripts/states/runCard.lua b/scripts/states/runCard.lua index 22f8139..4723636 100644 --- a/scripts/states/runCard.lua +++ b/scripts/states/runCard.lua @@ -80,9 +80,10 @@ effects.resource = { exec = function(card, index) local c = scripts.gameobjects.cards[menu.cardData] local effect = c.effects[index] - pprint(STATE.properties) - pprint(effect) - STATE.properties[effect.resource] = STATE.properties[effect.resource] + effect.value +-- pprint(STATE.properties) +-- pprint(effect) + table.insert(STATE.currentTurnEffects, effect) +-- STATE.properties[effect.resource] = STATE.properties[effect.resource] + effect.value end, draw = function(card, index, time) end,