-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheventCard.lua
More file actions
73 lines (65 loc) · 2.36 KB
/
eventCard.lua
File metadata and controls
73 lines (65 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
USEFUL = require("useful")
EVENTS = require("events")
-- awkward sizing but it keeps it consistend with calculated space
local width = eventspace.w / 3
local height = eventspace.h / 2.3
local padding = 10 --unused?
-- defining attributes of an eventCard, which will be currentEvent in main.lua
eventCard = {
width = width,
height = height,
x = (eventspace.w - width) / 2,
y = (eventspace.h - height) / 2,
option1x = (eventspace.w - width) / 2 - width,
option1y = (eventspace.h - height) / 2,
option2x = (eventspace.w - width) / 2,
option2y = (eventspace.h - height) / 2,
option3x = (eventspace.w - width) / 2 + width,
option3y = (eventspace.h - height) / 2,
expanded = false,
loadNext = false,
shuffling = false,
timeToShuffle = 2,
timeSpentShuffling = 0,
backupColour = USEFUL.RGB255ToRGB1({ r = 235, g = 162, b = 89 }),
event = {}
}
function eventCard:get()
return eventCard
end
function eventCard:updateEvent(e)
-- Update all options using variableCost table
if e == nil then
return
end
local newEvent = e
for i = 1, 3 do
local option = newEvent["option" .. i]
if option.variableCost then
for requirement, percentage in pairs(option.variableCost) do
local currentAmount = hand:getNumResource(requirement)
local calculatedAmount = math.ceil(currentAmount * percentage)
option.requirements[requirement] = calculatedAmount
end
end
end
-- random requirements such as "greed"
local resourceCount = Hand:cardsInHand()
for i = 1, 3 do
local option = newEvent["option" .. i]
if option.randomrequirements ~= 0 then
-- Reset all resource requirements to 0 before recalculating
for resourceName, _ in pairs(option.requirements) do
option.requirements[resourceName] = 0
end
for _ = 1, option.randomrequirements do
local resouceName = resourceCount[math.random(#resourceCount)]
option.requirements[resouceName] = option.requirements[resouceName] + 1
end
end
end
-- logic to be placed here for reading the necronomicon 1
-- this uses a cultist value of 840 to say "this option is only available if theres no cultists"
self.event = newEvent
end
return eventCard