Add member_quantity attribute to purchased ninja cards

This value is increased if the card was purchased in-game via any member-only purchase method.
This commit is contained in:
Ben 2020-02-14 21:49:37 +00:00
parent a95b237292
commit ef421dc957
3 changed files with 6 additions and 2 deletions

View File

@ -833,6 +833,7 @@ CREATE TABLE penguin_card (
penguin_id INT NOT NULL, penguin_id INT NOT NULL,
card_id INT NOT NULL, card_id INT NOT NULL,
quantity SMALLINT NOT NULL DEFAULT 1, quantity SMALLINT NOT NULL DEFAULT 1,
member_quantity SMALLINT NOT NULL DEFAULT 0,
PRIMARY KEY (penguin_id, card_id), PRIMARY KEY (penguin_id, card_id),
CONSTRAINT penguin_card_ibfk_1 FOREIGN KEY (penguin_id) REFERENCES penguin (id) ON DELETE RESTRICT ON UPDATE CASCADE, CONSTRAINT penguin_card_ibfk_1 FOREIGN KEY (penguin_id) REFERENCES penguin (id) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT penguin_card_ibfk_2 FOREIGN KEY (card_id) REFERENCES card (id) ON DELETE RESTRICT ON UPDATE CASCADE CONSTRAINT penguin_card_ibfk_2 FOREIGN KEY (card_id) REFERENCES card (id) ON DELETE RESTRICT ON UPDATE CASCADE
@ -845,6 +846,7 @@ COMMENT ON TABLE penguin_card IS 'Penguin Card Jitsu decks';
COMMENT ON COLUMN penguin_card.penguin_id IS 'Owner penguin ID'; COMMENT ON COLUMN penguin_card.penguin_id IS 'Owner penguin ID';
COMMENT ON COLUMN penguin_card.card_id IS 'Card type ID'; COMMENT ON COLUMN penguin_card.card_id IS 'Card type ID';
COMMENT ON COLUMN penguin_card.quantity IS 'Quantity owned'; COMMENT ON COLUMN penguin_card.quantity IS 'Quantity owned';
COMMENT ON COLUMN penguin_card.member_quantity IS 'Quantity owned as member';
DROP TABLE IF EXISTS penguin_furniture; DROP TABLE IF EXISTS penguin_furniture;
CREATE TABLE penguin_furniture ( CREATE TABLE penguin_furniture (

View File

@ -22,6 +22,7 @@ class PenguinCard(db.Model):
card_id = db.Column(db.ForeignKey('card.id', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True, card_id = db.Column(db.ForeignKey('card.id', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
nullable=False) nullable=False)
quantity = db.Column(db.SmallInteger, nullable=False, server_default=db.text("1")) quantity = db.Column(db.SmallInteger, nullable=False, server_default=db.text("1"))
member_quantity = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0"))
class CardCollection(AbstractDataCollection): class CardCollection(AbstractDataCollection):

View File

@ -175,12 +175,13 @@ class Penguin(Spheniscidae, penguin.Penguin):
return True return True
async def add_card(self, card, quantity=1): async def add_card(self, card, quantity=1, member_quantity=0):
if card.id in self.cards: if card.id in self.cards:
penguin_card = self.cards[card.id] penguin_card = self.cards[card.id]
await penguin_card.update( await penguin_card.update(
quantity=penguin_card.quantity + quantity).apply() quantity=penguin_card.quantity + quantity,
member_quantity=member_quantity).apply()
else: else:
await self.cards.insert(card_id=card.id) await self.cards.insert(card_id=card.id)