Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
shdwp committed Jun 23, 2020
1 parent 8956df4 commit abf5f44
Show file tree
Hide file tree
Showing 18 changed files with 137 additions and 43 deletions.
5 changes: 3 additions & 2 deletions app/controller/Scripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ void Scripting::registerClasses() {
.beginClass<Card>("Card")
.TYPE_PROP(Card)
.addConstructor<void(*) (int, luabridge::LuaRef)>()
.addProperty("uid", &Card::uid)
.addProperty("uid", &Card::uid, false)
.addProperty("faceup", &Card::faceup)
.addProperty("variant", &Card::variant)
.addProperty("meta", &Card::meta)
.addProperty("slotid", std::function([](const Card *ptr) {return ptr->slotid;}))
.addProperty("meta", &Card::meta, false)
.endClass();
}

Expand Down
2 changes: 2 additions & 0 deletions app/model/board/GameBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class GameBoard {

auto card_view = stack_widget->addChild(V::For(ptr));
card_view->slotid = slotid;
ptr->slotid = slotid;
UILayer::registerSceneEntity(card_view);
}

Expand All @@ -76,6 +77,7 @@ class GameBoard {
template <class T>
int erase(const string &slotid, luabridge::RefCountedPtr<T> item) {
auto vec = &(*cards_)[slotid];
item->slotid = "";

for (auto i = vec->begin(); i != vec->end(); i++) {
if (i->get() == item.get()) {
Expand Down
4 changes: 4 additions & 0 deletions app/model/card/Card.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@

class Item {
public:
string slotid = "";

virtual ~Item() = default;
};

class Card: public Item {
public:
int uid = 0;
int variant = 0;

bool faceup = true;
bool highlighted = false;

luabridge::LuaRef meta = nullptr;

Card(int uid, luabridge::LuaRef meta):
Expand Down
5 changes: 3 additions & 2 deletions app/model/card/Deck.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ class Deck: public Item {
return *this;
}

void insert(const Card &card, int idx) {
void insert(Card &card, int idx) {
if (idx == -1) {
idx = cards->size();
}

card.slotid = this->slotid;
cards->insert(cards->begin() + idx, new Card(card));
}

void append(const Card &card) {
void append(Card &card) {
insert(card, -1);
}

Expand Down
9 changes: 6 additions & 3 deletions app/scripts/Side.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ function Side:newTurn()
end

--- @param card Card
--- @param from string
function Side:actionDiscard(card, from)
board:cardPop(from, card)
function Side:actionDiscard(card)
board:cardPop(card.slotid, card)

local deck = board:deckGet(sideDiscardSlot(self.id), 0)
card.faceup = false
deck:append(card)
end

function Side:actionDrawCard()
Expand Down
9 changes: 5 additions & 4 deletions app/scripts/cardspec/CardMeta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ end

--- @return boolean
function CardMeta:isCardIcebreaker()
return self.info.type_code == "icebreaker"
return self:keywordsInclude({"Icebreaker"})
end

--- @return boolean
Expand Down Expand Up @@ -102,13 +102,14 @@ end
function CardMeta:keywordsInclude(kws)
local str = self.info.keywords
for _, kw in pairs(kws) do
if string.find(str, kw) then
print(str, string.find(str, kw))
if string.find(str, kw) ~= nil then
return true
end

local result = false
for t in self:modificationsIter() do
if string.find(t.additional_keywords, kw) then
if t.additional_keywords and string.find(t.additional_keywords, kw) ~= nil then
result = true
end
end
Expand Down Expand Up @@ -246,7 +247,7 @@ function CardMeta:onRunEnd()
self.until_run_end = {}
end

function CardMeta:onIceEncounterEnd()
function CardMeta:onEncounterEnd()
self.until_encounter_end = {}

if self.info.onIceEncounterEnd then return self.info.onIceEncounterEnd(self:_ctx()) end
Expand Down
6 changes: 5 additions & 1 deletion app/scripts/cardspec/Db.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ end
--- @param uid number
--- @return Card
function Db:card(uid)
if type(uid) == "string" then
uid = self.card_titles[uid]
end

local info = self.cards[uid]
if not info then
error("Failed to find card %d", uid)
error("Failed to find card %s", uid)
end

local card = Card(uid, CardMeta:New(info))
Expand Down
60 changes: 48 additions & 12 deletions app/scripts/cardspec/packs/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ Db.cards[1026] = {
if game.runner:spendCredits(2) then
ctx.meta.until_use.additional_strength = (ctx.meta.until_use.additional_strength or 0) + 1
end
end,

onInstall = function (ctx)
make_interaction:promptSlotSelect(SIDE_RUNNER, isSlotIce, 1, function (decision, card, slot)

end)
return true
end
}
Db.card_titles["Femme Fatale"] = 1026
Expand Down Expand Up @@ -170,10 +177,10 @@ Db.cards[1027] = {
end,

--- @param ctx Ctx
onBreakIce = function (ctx)
if game.runner:spendCredits(1) then
return ctx.meta:keywordsInclude({"Sentry"})
end
--- @param ice_meta CardMeta
--- @return boolean
onBreakIce = function (ctx, ice_meta)
return ice_meta:keywordsInclude({"Sentry"}) and game.runner:spendCredits(1)
end,
}
Db.card_titles["Ninja"] = 1027
Expand Down Expand Up @@ -366,7 +373,7 @@ Db.cards[1040] = {
onInstall = function (ctx)
make_interaction:promptSlotSelect(SIDE_RUNNER, SLOT_RUNNER_PROGRAMS, 1, function (decision, card, slot)
if card.meta:isCardIcebreaker() then
card.meta.until_forever.additional_strength = card.meta.until_forever.additional_strength + 1
card.meta.until_forever.additional_strength = (card.meta.until_forever.additional_strength or 0) + 1
return true
else
return false
Expand Down Expand Up @@ -434,13 +441,14 @@ Db.cards[1043] = {
uniqueness = false,

--- @param ctx Ctx
onBreakIce = function (ctx)
if game.runner:spendCredits(1) then
return ctx.meta:keywordsInclude({"Code Gate"})
end
--- @param ice_meta CardMeta
--- @return boolean
onBreakIce = function (ctx, ice_meta)
return ice_meta:keywordsInclude({"Code Gate"}) and game.runner:spendCredits(1)
end,

--- @param ctx Ctx
--- @return boolean
onPowerUp = function (ctx)
if game.runner:spendCredits(1) then
ctx.meta.until_run_end.additional_strength = (ctx.meta.until_run_end.additional_strength or 0) + 1
Expand Down Expand Up @@ -519,6 +527,33 @@ Db.cards[1049] = {
title = "Infiltration",
type_code = "event",
uniqueness = false,

--- @param ctx Ctx
onPlay = function (ctx)
local options = {
["credits"] = "Gain 2[credit]",
["expose"] = "Expose 1 card",
}

make_interaction:promptOptionSelect(SIDE_RUNNER, options, function (opt_id)
if opt_id == "credits" then
game.runner:alterCredits(2)
elseif opt_id == "expose" then
make_interaction:promptSlotSelect(SIDE_RUNNER, function () return true end, 1, function (decision, card, slot)
if not card.faceup then
make_interaction:displayFaceup(SIDE_RUNNER, card)
return true
end

return false
end)
else
return false
end

return true
end)
end,
}
Db.card_titles["Infiltration"] = 1049

Expand Down Expand Up @@ -579,8 +614,9 @@ Db.cards[1051] = {
end,

--- @param ctx Ctx
--- @param ice_meta CardMeta
--- @return boolean
onBreakIce = function (ctx)
onBreakIce = function (ctx, ice_meta)
if game.runner:spendCredits(1) then
ctx.meta.virus_tagged = true
return true
Expand All @@ -593,7 +629,7 @@ Db.cards[1051] = {
if (ctx.meta.virus_counter or 0) > 0 then
ctx.meta.virus_counter = ctx.meta.virus_counter - 1
else
ctx.meta.discard = true
game.runner:actionDiscard(ctx.meta.card)
end
end
end
Expand Down Expand Up @@ -888,7 +924,7 @@ Db.cards[1101] = {
make_interaction:promptSlotSelect(SIDE_CORP, SLOT_CORP_HAND, 1, function (decision, card, slot)
if card.meta:isCardAgenda() and game.corp:payPrice(ctx.meta) then
game.corp:rez(ctx.meta)
board:cardPop(slot, card)
game.corp:actionDiscard(card)
decision:handledTop()
return true
end
Expand Down
10 changes: 10 additions & 0 deletions app/scripts/const.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ function sideHandSlot(side)
end
end

function sideDiscardSlot(side)
if side == SIDE_CORP then
return SLOT_CORP_ARCHIVES
else
return SLOT_RUNNER_HEAP
end
end

function sideForId(id)
if id == SIDE_CORP then
return game.corp
Expand Down Expand Up @@ -76,11 +84,13 @@ SLOT_CORP_HQ = "corp_hq"
-- SLOT_CORP_ = "corp_"

SLOT_RUNNER_HAND = "runner_hand"
SLOT_RUNNER_ID = "runner_id"
SLOT_RUNNER_STACK = "runner_stack"
SLOT_RUNNER_CONSOLE = "runner_console"
SLOT_RUNNER_PROGRAMS = "runner_software"
SLOT_RUNNER_HARDWARE = "runner_hardware"
SLOT_RUNNER_RESOURCES = "runner_resources"
SLOT_RUNNER_HEAP = "runner_heap"

RUNNER_SLOTS = {
SLOT_RUNNER_HAND,
Expand Down
2 changes: 2 additions & 0 deletions app/scripts/controller/human/HumanController.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ function HumanController:interaction(type, descr)
result = comp:onPrimary(descr.card, descr.slot)
elseif type == INTERACTION_SECONDARY then
result = comp:onSecondary(descr.card, descr.slot)
elseif type == INTERACTION_TERTIARY then
result = comp:onTertiary(descr.card, descr.slot)
elseif type == INTERACTION_CANCEL then
result = comp:onCancel()
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
HCTurnEndDiscardComponent = class("HCTurnEndDiscardComponent", HumanControllerComponent)

function HCTurnEndDiscardComponent:onPrimary(card, slot)
self.side:actionDiscard(card, slot)
self.side:actionDiscard(card)
self.decision:discardedCard(card)

return true
Expand Down
14 changes: 11 additions & 3 deletions app/scripts/decision/make_interaction.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ end
--- @param amount number
--- @param cb fun(decision: SelectFromSlotDecision, card: Card, slot: string): boolean
--- @param forced boolean
--- @return boolean
function make_interaction:promptSlotSelect(side, slot, amount, cb, forced)
game.decision_stack:push(SelectFromSlotDecision:New(side, slot, amount, cb, forced))
game:cycle()
Expand All @@ -26,16 +25,25 @@ end
--- @param side string
--- @param card userdata Card
--- @param discount number
--- @return boolean
function make_interaction:promptDiscountedInstall(side, slot, card, discount)
game.decision_stack:push(DiscountedInstallDecision:New(side, slot, card, discount and discount or -99))
game:cycle()
end

--- @param side string
--- @param cb function returning bool
--- @return boolean
function make_interaction:promptFreeAdvance(side, cb)
game.decision_stack:push(FreeAdvanceDecision:New(side, cb))
game:cycle()
end

--- @param side string
--- @param options table<string, string>
--- @param cb fun(option: string): boolean
function make_interaction:promptOptionSelect(side, options, cb)
game.decision_stack:push(SelectFromOptionsDecision:New(side, options, cb))
game:cycle()
end

function make_interaction:displayFaceup(side, card)
end
15 changes: 15 additions & 0 deletions app/scripts/decision/phases/SelectFromOptionsDecision.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--- @class SelectFromOptionsDecision: Decision
--- @field options table<string, string>
--- @field cb fun(option: string): boolean
SelectFromOptionsDecision = class("SelectFromOptionsDecision", Decision, { Type = "select_from_options "})

--- @param side_id string
--- @param options table<string, string>
--- @param cb fun(option: string): boolean
function SelectFromOptionsDecision:New(side_id, options, cb)
return construct(self, Decision:New(self.Type, side_id), {
options = options,
cb = cb,
})
end

2 changes: 1 addition & 1 deletion app/scripts/decision/phases/run/RunEndDecision.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ end

function RunEndDecision:autoHandle()
for card in game:boardCardsIter() do
card.meta:onIceEncounterEnd()
card.meta:onEncounterEnd()
card.meta:onRunEnd()
end

Expand Down
2 changes: 1 addition & 1 deletion app/scripts/decision/phases/run/RunIceApproachDecision.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ end

function RunIceApproachDecision:autoHandle()
for card in game:boardCardsIter() do
card.meta:onIceEncounterEnd()
card.meta:onEncounterEnd()
end

return false
Expand Down
Loading

0 comments on commit abf5f44

Please sign in to comment.