Skip to content

Commit

Permalink
Merge pull request #124 from pyrrhicPachyderm/card-gain-hook
Browse files Browse the repository at this point in the history
Add a hook to modify the number of cards gained.
  • Loading branch information
iakona authored Oct 19, 2023
2 parents a34bff6 + b774219 commit 43e3c43
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 55 deletions.
8 changes: 8 additions & 0 deletions CUSTOM.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,11 @@ This section is meant for users who are familiar with both the tts mod and progr
- `isGain`: **bool** - true if the operation is a gain, false if it's a pay
- `isUndo`: **bool** - true if the operation is being undone (right click), false otherwise
- `amount`: **number** - amount of energy gained/paid (before bargain deductions); positive for gain or pay
- Trigger to modify the number of cards gained
- Create object and tag with "Modify Card Gain"
- `modifyCardGain(params)`
- `params`: **table** - contains data about the player and the cards played
- `color`: **string** - is the color of the player whose card cost is being calculated
- `major`: **boolean** - true if gaining majors, false if gaining minors
- `count`: **number** - the number of cards being gained
- return **number** - the number of cards to gain
16 changes: 2 additions & 14 deletions objects/0e627b/contained/fddf31/script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,15 @@ function doSetup(params)
Player[color].broadcast("Don't forget to gain 1 Time", "Blue")
end

local playtestPowers = Global.getVar("playtestMinorPowers")
local playtestCount = playtestPowers
if playtestPowers == 1 then
playtestCount = math.floor(count / 3)
elseif playtestPowers == 2 then
playtestCount = math.floor(count / 2)
end
local playtestCount = Global.call("getPlaytestCount", {count = count, major = false})
local minorPowerDeck = getObjectFromGUID(Global.getVar("minorPowerZone")).getObjects()[1]
minorPowerDeck.deal(count - playtestCount, color, 3)
if playtestCount > 0 then
minorPowerDeck = getObjectFromGUID(Global.getVar("playtestMinorPowerZone")).getObjects()[1]
minorPowerDeck.deal(playtestCount, color, 3)
end

playtestPowers = Global.getVar("playtestMajorPowers")
playtestCount = playtestPowers
if playtestPowers == 1 then
playtestCount = math.floor(count / 3)
elseif playtestPowers == 2 then
playtestCount = math.floor(count / 2)
end
playtestCount = Global.call("getPlaytestCount", {count = count, major = true})
local majorPowerDeck = getObjectFromGUID(Global.getVar("majorPowerZone")).getObjects()[1]
majorPowerDeck.deal(count - playtestCount, color, 3)
if playtestCount > 0 then
Expand Down
4 changes: 4 additions & 0 deletions savegame.json
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@
{
"displayed": "Gain Pay",
"normalized": "gain_pay"
},
{
"displayed": "Modify Card Gain",
"normalized": "modify_card_gain"
}
]
},
Expand Down
94 changes: 53 additions & 41 deletions script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1838,6 +1838,20 @@ function addFearCard(params)
end
end
----- Minor/Major Power Section
function getPlaytestCount(params)
local count = params.count
local playtestPowers
if params.major then
playtestPowers = Global.getVar("playtestMajorPowers")
else
playtestPowers = Global.getVar("playtestMinorPowers")
end
if playtestPowers == 1 then
return math.max(1, math.floor(count / 3))
elseif playtestPowers == 2 then
return math.max(1, math.floor(count / 2))
end
end
function SetupPlaytestPowerDeck(deck, name, option, callback)
local stagingArea = {
["Minor Powers"] = getObjectFromGUID(playtestMinorPowerZone).getPosition(),
Expand Down Expand Up @@ -2020,7 +2034,7 @@ function MajorPowerC(obj, player_color, alt_click)
if alt_click then
cards = 2
end
startDealPowerCards(false, Player[player_color], cards)
startDealPowerCards({player = Player[player_color], major = true, count = cards})
end
function MajorPowerUI(player, button)
if player.color == "Grey" then return end
Expand All @@ -2029,14 +2043,14 @@ function MajorPowerUI(player, button)
if math.abs(button) > 1 then
cards = 2
end
startDealPowerCards(false, player, cards)
startDealPowerCards({player = player, major = true, count = cards})
end
function MinorPowerC(obj, player_color, alt_click)
local cards = 4
if alt_click then
cards = 6
end
startDealPowerCards(true, Player[player_color], cards)
startDealPowerCards({player = Player[player_color], major = false, count = cards})
end
function MinorPowerUI(player, button)
if player.color == "Grey" then return end
Expand All @@ -2045,44 +2059,53 @@ function MinorPowerUI(player, button)
if math.abs(button) > 1 then
cards = 6
end
startDealPowerCards(true, player, cards)
startDealPowerCards({player = player, major = false, count = cards})
end
function startDealPowerCards(minor, player, cardCount)
function modifyCardGain(params)
for _,obj in pairs(getObjectsWithTag("Modify Card Gain")) do
params.count = obj.call("modifyCardGain", params)
end
return params.count
end
function startDealPowerCards(params)
-- protection from double clicking
if scriptWorkingCardC then return end
scriptWorkingCardC = true

if minor then
params.count = modifyCardGain({color = params.player.color, major = params.major, count = params.count})
local playtestCount = getPlaytestCount({count = params.count, major = params.major})

if params.major then
_G["startDealPowerCardsCo"] = function()
DealPowerCards(
player,
cardCount,
getObjectFromGUID(minorPowerZone),
getObjectFromGUID(minorPowerDiscardZone),
getObjectFromGUID(playtestMinorPowerZone),
getObjectFromGUID(playtestMinorPowerDiscardZone),
playtestMinorPowers
params.player,
params.count,
getObjectFromGUID(majorPowerZone),
getObjectFromGUID(majorPowerDiscardZone),
getObjectFromGUID(playtestMajorPowerZone),
getObjectFromGUID(playtestMajorPowerDiscardZone),
playtestCount
)
return 1
end
else
_G["startDealPowerCardsCo"] = function()
DealPowerCards(
player,
cardCount,
getObjectFromGUID(majorPowerZone),
getObjectFromGUID(majorPowerDiscardZone),
getObjectFromGUID(playtestMajorPowerZone),
getObjectFromGUID(playtestMajorPowerDiscardZone),
playtestMajorPowers
params.player,
params.count,
getObjectFromGUID(minorPowerZone),
getObjectFromGUID(minorPowerDiscardZone),
getObjectFromGUID(playtestMinorPowerZone),
getObjectFromGUID(playtestMinorPowerDiscardZone),
playtestCount
)
return 1
end
end

startLuaCoroutine(Global, "startDealPowerCardsCo")
end
function DealPowerCards(player, cardCount, deckZone, discardZone, playtestDeckZone, playtestDiscardZone, playtestPowers)
function DealPowerCards(player, cardCount, deckZone, discardZone, playtestDeckZone, playtestDiscardZone, playtestCount)
-- clear the zone!
local hand = player.getHandTransform()
if hand == nil then
Expand All @@ -2099,14 +2122,15 @@ function DealPowerCards(player, cardCount, deckZone, discardZone, playtestDeckZo
if cardCount > 4 then
xPadding = 3.6
end
local cardPlaceOffset = {
Vector(-(2.5*xPadding)+2*xPadding,0,0),
Vector(-(2.5*xPadding)+3*xPadding,0,0),
Vector(-(2.5*xPadding)+1*xPadding,0,0),
Vector(-(2.5*xPadding)+4*xPadding,0,0),
Vector(-(2.5*xPadding)+0*xPadding,0,0),
Vector(-(2.5*xPadding)+5*xPadding,0,0),
}
if cardCount > 6 then
player.broadcast("Gaining more than 6 cards is not supported.", Color.Red)
scriptWorkingCardC = false
return
end
local cardPlaceOffset = {}
for i = -(cardCount-1)/2,(cardCount-1)/2,1 do
table.insert(cardPlaceOffset, Vector(i*xPadding,0,0))
end
local cardsAdded = 0
local cardsResting = 0
local powerDealCentre = handOffset + handPos
Expand Down Expand Up @@ -2163,18 +2187,6 @@ function DealPowerCards(player, cardCount, deckZone, discardZone, playtestDeckZo
end
end
end
local playtestCount = playtestPowers
if cardCount == 2 then
if playtestPowers > 0 then
playtestCount = 1
end
elseif cardCount == 6 then
if playtestPowers == 1 then
playtestCount = 2
elseif playtestPowers == 2 then
playtestCount = 3
end
end
dealPowerCards(deckZone, discardZone, cardCount - playtestCount, 0, false)
dealPowerCards(playtestDeckZone, playtestDiscardZone, playtestCount, cardCount - playtestCount, true)

Expand Down

0 comments on commit 43e3c43

Please sign in to comment.