-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecks.lua
More file actions
112 lines (94 loc) · 3.47 KB
/
decks.lua
File metadata and controls
112 lines (94 loc) · 3.47 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
--[[
Creation and management of the deck object,
containing all 3 decks deck, discard, permaDiscrd
]]
local EVENTS = require("events")
local USEFUL = require("useful")
local events = EVENTS
-- events:initializeCustom()
local decks = {
deck = {}, -- the deck being actively used
discarded = {}, -- where the discarded cards to be reused or inserted next shuffle are stored
permaDiscarded = {} -- where the permanently discarded cards are stored
}
function decks:initiateDecks(gods)
-- full initiation, used at the start of the run
self:insertGods()
self:insertCommonEvents()
self:insertBlessings(gods)
self:shuffle()
end
function decks:initiateTutoralDecks()
-- basically just load the EVENTS.tutorial{} in the correct order into self.deck
-- bit of smoke and mirrors here
self.deck = USEFUL.deepcopy(events.tutorialUnkeyed)
end
function decks:insertGods()
--local wantedTitles = { "Rumors of Darkness", "A Fishing Trip", "The Call of Uhl'uht'c", "A Mysterious Egg", "Start a Tea Shop" }
--self:insert(events.godSummon.rumorsOfDarkness)
--self:insert(events.godSummon.aFishingTrip)
--self:insert(events.godSummon.theCallOfUhlUhtC)
--self:insert(events.godSummon.aMysteriousEgg)
--self:insert(events.godSummon.startATeaShop)
for idx, card in pairs(events.godSummon) do
self:insert(card)
end
-- something needs to be done to make this more accessible for modding - probably a config folder.
end
function decks:insertCommonEvents()
-- Get all keys from events.common
local keyset = {}
for k in pairs(events.common) do
table.insert(keyset, k)
end
USEFUL.fisherYates(keyset)
-- Take the first 10 items
-- normally its a bit more variable than this but wiki and fan site
-- just say "some random events are randomly selected and added"
-- this is an efficient way to make sure each card is unique
local numToSelect = math.min(10, #keyset)
for i = 1, numToSelect do
local selectedKey = keyset[i]
local selectedEvent = events.common[selectedKey]
self:insert(selectedEvent)
end
end
function decks:insertBlessings(gods)
local lgods = gods or {} -- ensuring that lgods is a table and exists
for _, god in ipairs(lgods) do
local god_lower = string.lower(god)
for _, event in pairs(events.blessings[god_lower]) do
self:insert(event)
end
end
end
function decks:insert(e)
-- inserts into the discarded deck as this deck gets shuffled next loop
table.insert(self.discarded, e)
end
function decks:insertPunishment(punishment)
-- seperate function for punishment so its obviously defined when this happens
-- and the key can be put directly in event.punishments
table.insert(self.deck, 1, events.punishments[punishment])
end
function decks:shuffle()
-- shuffle using the weights provided in events
local shuffledDiscard = Useful.weightedShuffle(self.discarded)
self.deck = shuffledDiscard
self.discarded = {}
end
function decks:discard(eid, recurring)
-- discards the id from the deck into the discarded deck
if recurring == 1 then
-- if ite recurring then it goes into discarded
self:insert(self.deck[eid])
else
-- if its not recurring then it goes into permanent discarded
table.insert(self.permaDiscarded, self.deck[eid])
end
table.remove(self.deck, eid)
end
function decks:printDecks()
USEFUL.printTable(self.deck)
end
return decks