Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More β†’
Socket
Sign inDemoInstall
Socket

@cardcore/game

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cardcore/game - npm Package Compare versions

Comparing version 0.0.1-a2227030 to 0.0.1-a6367903

dist/actions.js

4

dist/buff.js

@@ -17,3 +17,3 @@ "use strict";

game: Object.assign({}, state.game, {
units: Object.assign({}, state.game.units, (0, _util.target)(state.game, action.target, function (unit) {
units: Object.assign({}, state.game.units, (0, _util.target)(state, action.target, function (unit) {
return Object.assign({}, unit, {

@@ -30,3 +30,3 @@ attack: action.value

game: Object.assign({}, state.game, {
units: Object.assign({}, state.game.units, (0, _util.target)(state.game, action.target, function (unit) {
units: Object.assign({}, state.game.units, (0, _util.target)(state, action.target, function (unit) {
return Object.assign({}, unit, {

@@ -33,0 +33,0 @@ health: action.value

@@ -14,2 +14,4 @@ "use strict";

var _util = require("@cardcore/util");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -48,2 +50,5 @@

if (action.type === CHECK_DEATH) {
var traverse = function traverse(boxId) {
return _util.Box.traverse(state, boxId);
};
var newPlayers = {};

@@ -56,7 +61,7 @@ Object.entries(state.game.players).forEach(function (_ref2) {

newPlayers[playerId] = Object.assign({}, player, {
field: player.field.filter(function (unitId) {
return state.game.units[unitId].health > 0;
field: player.field.filter(function (boxId) {
return state.game.units[traverse(boxId)].health > 0;
}),
graveyard: player.field.concat(player.field.filter(function (unitId) {
return state.game.units[unitId].health <= 0;
graveyard: player.field.concat(player.field.filter(function (boxId) {
return state.game.units[traverse(boxId)].health <= 0;
}))

@@ -63,0 +68,0 @@ });

@@ -16,3 +16,3 @@ "use strict";

game: Object.assign({}, state.game, {
units: Object.assign({}, state.game.units, (0, _util.target)(state.game, action.target, function (unit) {
units: Object.assign({}, state.game.units, (0, _util.target)(state, action.target, function (unit) {
return Object.assign({}, unit, {

@@ -19,0 +19,0 @@ health: unit.health - action.value

@@ -32,2 +32,14 @@ "use strict";

var _box = require("./box");
Object.keys(_box).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _box[key];
}
});
});
var _buff = require("./buff");

@@ -185,3 +197,3 @@

return Object.assign({}, state, {
game: {
game: Object.assign({}, state.game, {
startTime: action.startTime,

@@ -204,3 +216,3 @@ nextActions: [{

boxes: {}
}
})
});

@@ -207,0 +219,0 @@ }

@@ -31,6 +31,3 @@ "use strict";

return function (dispatch, getState) {
var state = getState();
var me = state.client.keys;
var box = state.game.boxes[boxId];
var privateKey = _util.Box.getPrivate(box, me);
var privateKey = _util.Box.getPrivate(getState(), boxId);
dispatch({

@@ -83,3 +80,8 @@ type: "REVEAL_CARD",

});
var contents = _util.Box.open(action.boxId, newBox, null);
state = Object.assign({}, state, {
game: Object.assign({}, state.game, {
boxes: Object.assign({}, state.game.boxes, _defineProperty({}, action.boxId, newBox))
})
});
var contents = _util.Box.open(state, action.boxId);
// if there's another box in here, pass to the player on our left

@@ -100,3 +102,2 @@ var _nextActions = state.game.nextActions;

game: Object.assign({}, state.game, {
boxes: Object.assign({}, state.game.boxes, _defineProperty({}, action.boxId, newBox)),
nextActions: _nextActions

@@ -103,0 +104,0 @@ })

@@ -64,3 +64,3 @@ "use strict";

var boxId = action.boxId;
var unitId = _util.Box.traverse(boxId, state.game.boxes, state.client.keys);
var unitId = _util.Box.traverse(state, boxId);
var unit = state.game.units[unitId];

@@ -74,3 +74,3 @@ return Object.assign({}, state, {

}),
field: [unitId].concat(_toConsumableArray(player.field))
field: [boxId].concat(_toConsumableArray(player.field))
}))),

@@ -84,3 +84,3 @@ units: Object.assign({}, state.game.units, _defineProperty({}, unitId, Object.assign({}, unit, { canAttack: false }))),

}].concat(_toConsumableArray(unit.onSummon.filter(function (onSummon, i) {
if (Object.keys((0, _util.target)(state.game, onSummon.target)).length === 0) {
if (Object.keys((0, _util.target)(state, onSummon.target)).length === 0) {
return false;

@@ -87,0 +87,0 @@ }

@@ -6,3 +6,3 @@ "use strict";

});
exports.seedRngReducer = exports.seedRngDecrypt = exports.SEED_RNG_DECRYPT = exports.seedRngEncrypt = exports.SEED_RNG_ENCRYPT = exports.seedRng = exports.SEED_RNG = undefined;
exports.seedRngReducer = exports.SEED_RNG_COMBINE = exports.seedRngEncrypt = exports.SEED_RNG_ENCRYPT = exports.seedRng = exports.SEED_RNG = undefined;

@@ -17,6 +17,6 @@ var _regenerator = require("babel-runtime/regenerator");

var _client = require("@cardcore/client");
var _util = require("@cardcore/util");
var _box = require("./box");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -39,3 +39,3 @@

var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee(dispatch, getState) {
var _ref2, keys, randoSecret, boxed;
var me, randoSecret, _Box$new, boxId, box;

@@ -46,19 +46,14 @@ return _regenerator2.default.wrap(function _callee$(_context) {

case 0:
_context.next = 2;
return dispatch((0, _client.clientGenerateKey)());
me = getState().client.keys;
// idk just hash a key, good enough
case 2:
_ref2 = _context.sent;
keys = _ref2.keys;
// idk just hash a key
randoSecret = _ssbKeys2.default.hash(_ssbKeys2.default.generate().id);
boxed = _ssbKeys2.default.box(randoSecret, [keys]);
_Box$new = _util.Box.new(randoSecret, me.id), boxId = _Box$new.boxId, box = _Box$new.box;
return _context.abrupt("return", dispatch({
type: SEED_RNG_ENCRYPT,
id: keys.id,
box: boxed
boxId: boxId,
box: box
}));
case 7:
case 4:
case "end":

@@ -77,33 +72,4 @@ return _context.stop();

var SEED_RNG_DECRYPT = exports.SEED_RNG_DECRYPT = "SEED_RNG_DECRYPT";
var seedRngDecrypt = exports.seedRngDecrypt = function seedRngDecrypt() {
return function () {
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee2(dispatch, getState) {
var state, mySeed, privateKey;
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
state = getState();
mySeed = state.game.randoSeeds[state.client.keys.id];
privateKey = state.secret[mySeed.id].private;
return _context2.abrupt("return", dispatch({
type: SEED_RNG_DECRYPT,
privateKey: privateKey
}));
var SEED_RNG_COMBINE = exports.SEED_RNG_COMBINE = "SEED_RNG_COMBINE";
case 4:
case "end":
return _context2.stop();
}
}
}, _callee2, undefined);
}));
return function (_x3, _x4) {
return _ref3.apply(this, arguments);
};
}();
};
// these actions should all happen in lexical order rather than playerOrder because they're used to // seed the RNG prior to playerOrder existing

@@ -120,2 +86,7 @@ var seedRngReducer = exports.seedRngReducer = function seedRngReducer(state, action) {

}
}, {
playerId: action._sender,
action: {
type: SEED_RNG_COMBINE
}
}].concat(_toConsumableArray(state.game.nextActions))

@@ -130,8 +101,4 @@ })

game: Object.assign({}, state.game, {
randoSeeds: Object.assign({}, state.game.randoSeeds, _defineProperty({}, action._sender, {
secret: true,
id: action.id,
box: action.box,
playerId: action._sender
}))
boxes: Object.assign({}, state.game.boxes, _defineProperty({}, action.boxId, action.box)),
randoSeeds: Object.assign({}, state.game.randoSeeds, _defineProperty({}, action._sender, action.boxId))
})

@@ -148,3 +115,4 @@ });

action: {
type: SEED_RNG_DECRYPT
type: _box.BOX_OPEN,
boxId: state.game.randoSeeds[playerId]
}

@@ -171,25 +139,7 @@ };

if (action.type === SEED_RNG_DECRYPT) {
var _orderedPlayers2 = Object.keys(state.game.players).sort();
var randoSeed = state.game.randoSeeds[action._sender];
var newSecret = state.secret;
if (state.secret[randoSeed.id]) {
newSecret = Object.assign({}, state.secret);
delete newSecret[randoSeed.id];
}
state = Object.assign({}, state, {
game: Object.assign({}, state.game, {
randoSeeds: Object.assign({}, state.game.randoSeeds, _defineProperty({}, action._sender, _ssbKeys2.default.unbox(state.game.randoSeeds[action._sender].box, { private: action.privateKey })))
})
});
// if we're done, clear out randoSeeds
if (!Object.values(state.game.randoSeeds).every(function (val) {
return typeof val === "string";
})) {
return state;
}
var finalSeed = _ssbKeys2.default.hash(_orderedPlayers2.map(function (playerId) {
return state.game.randoSeeds[playerId];
}).concat(""));
_util.rando.setSeed(finalSeed);
if (action.type === SEED_RNG_COMBINE) {
var finalSeed = Object.keys(state.game.players).sort().map(function (playerId) {
return _util.Box.traverse(state, state.game.randoSeeds[playerId]);
}).join("");
finalSeed = _ssbKeys2.default.hash(finalSeed);
return Object.assign({}, state, {

@@ -196,0 +146,0 @@ game: Object.assign({}, state.game, {

@@ -115,3 +115,3 @@ "use strict";

var state = getState();
var key = _util.Box.addKey(state.game.boxes[boxId], state.client.keys, playerId);
var key = _util.Box.addKey(state, boxId, playerId);
dispatch({

@@ -118,0 +118,0 @@ type: SHUFFLE_DECK_DECRYPT,

@@ -23,3 +23,3 @@ "use strict";

name: "Standard " + cost + "-" + cost,
text: "",
text: [],
onSummon: [],

@@ -37,3 +37,3 @@ onDeath: [],

name: "Summon Dude",
text: "onSummon: summon a 1/1 creature",
text: ["onSummon: summon a 1/1 creature"],
onSummon: [{

@@ -49,3 +49,3 @@ type: "SUMMON_CREATURE",

name: "Bouncer",
text: "onSummon: choose a friendly creature to return to your hand",
text: ["onSummon: choose a friendly creature to return to your hand"],
onSummon: [{

@@ -64,3 +64,3 @@ type: "BOUNCE",

name: "Three Master",
text: "onSummon: Set all other creatures' Attack and Health to 3",
text: ["onSummon: Set all other creatures' Attack and Health to 3"],
onSummon: [{

@@ -86,3 +86,3 @@ type: "CHANGE_ATTACK",

name: "Card Drawer",
text: "onSummon: draw a card",
text: ["onSummon: draw a card"],
onSummon: [{

@@ -101,3 +101,3 @@ type: "DRAW_CARD",

name: "Owner Damager",
text: "onSummon: Deal 3 damage to your hero",
text: ["onSummon: Deal 3 damage to your hero"],
onSummon: [{

@@ -118,3 +118,3 @@ type: "DAMAGE",

name: "Creature Damager",
text: "onSummon: deal 1 damage to three target creatures",
text: ["onSummon: deal 1 damage to three target creatures"],
onSummon: [{

@@ -138,3 +138,3 @@ type: "DAMAGE",

name: "Random Creature Damager",
text: "onSummon: deal 1 random damage to three target creatures",
text: ["onSummon: deal 1 random damage to three target creatures"],
onSummon: [{

@@ -141,0 +141,0 @@ type: "DAMAGE",

@@ -18,2 +18,4 @@ "use strict";

var _util = require("@cardcore/util");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -96,3 +98,4 @@

var newUnits = {};
player.field.forEach(function (unitId) {
player.field.forEach(function (boxId) {
var unitId = _util.Box.traverse(state, boxId);
newUnits[unitId] = Object.assign({}, state.game.units[unitId], {

@@ -99,0 +102,0 @@ canAttack: true

{
"name": "@cardcore/game",
"version": "0.0.1-a2227030",
"version": "0.0.1-a6367903",
"description": "base rules for the Streamplace card game",

@@ -14,5 +14,7 @@ "main": "dist/index.js",

"dependencies": {
"@streamplace/ssb-keys": "^7.0.16"
"@cardcore/util": "0.0.1-a6367903",
"@streamplace/ssb-keys": "7.0.21",
"babel-runtime": "^6.26.0"
},
"gitHead": "a2227030a725c42f1d30ec19c0e97232bd467345"
"gitHead": "a63679039961e2cdd42258062acbfa0c4c0766a0"
}

@@ -14,3 +14,3 @@ import { target } from "@cardcore/util";

...state.game.units,
...target(state.game, action.target, unit => {
...target(state, action.target, unit => {
return {

@@ -33,3 +33,3 @@ ...unit,

...state.game.units,
...target(state.game, action.target, unit => {
...target(state, action.target, unit => {
return {

@@ -36,0 +36,0 @@ ...unit,

@@ -0,1 +1,3 @@

import { Box } from "@cardcore/util";
export const CHECK_DEATH = "CHECK_DEATH";

@@ -10,2 +12,3 @@ export const checkDeath = () => async dispatch => {

if (action.type === CHECK_DEATH) {
const traverse = boxId => Box.traverse(state, boxId);
const newPlayers = {};

@@ -16,6 +19,8 @@ Object.entries(state.game.players).forEach(([playerId, player]) => {

field: player.field.filter(
unitId => state.game.units[unitId].health > 0
boxId => state.game.units[traverse(boxId)].health > 0
),
graveyard: player.field.concat(
player.field.filter(unitId => state.game.units[unitId].health <= 0)
player.field.filter(
boxId => state.game.units[traverse(boxId)].health <= 0
)
)

@@ -22,0 +27,0 @@ };

@@ -13,3 +13,3 @@ import { target } from "@cardcore/util";

...state.game.units,
...target(state.game, action.target, unit => {
...target(state, action.target, unit => {
return {

@@ -16,0 +16,0 @@ ...unit,

export * from "./attack";
export * from "./bounce";
export * from "./box";
export * from "./buff";

@@ -26,2 +27,3 @@ export * from "./check-death";

game: {
...state.game,
startTime: action.startTime,

@@ -28,0 +30,0 @@ nextActions: [

@@ -13,6 +13,3 @@ import { Box, getLeftPlayer } from "@cardcore/util";

export const revealCard = ({ boxId }) => (dispatch, getState) => {
const state = getState();
const me = state.client.keys;
const box = state.game.boxes[boxId];
const privateKey = Box.getPrivate(box, me);
const privateKey = Box.getPrivate(getState(), boxId);
dispatch({

@@ -78,3 +75,13 @@ type: "REVEAL_CARD",

};
const contents = Box.open(action.boxId, newBox, null);
state = {
...state,
game: {
...state.game,
boxes: {
...state.game.boxes,
[action.boxId]: newBox
}
}
};
const contents = Box.open(state, action.boxId);
// if there's another box in here, pass to the player on our left

@@ -100,6 +107,2 @@ let nextActions = state.game.nextActions;

...state.game,
boxes: {
...state.game.boxes,
[action.boxId]: newBox
},
nextActions: nextActions

@@ -106,0 +109,0 @@ }

@@ -20,3 +20,3 @@ import { SEED_RNG } from "./seed-rng";

const boxId = action.boxId;
const unitId = Box.traverse(boxId, state.game.boxes, state.client.keys);
const unitId = Box.traverse(state, boxId);
const unit = state.game.units[unitId];

@@ -33,3 +33,3 @@ return {

hand: player.hand.filter(c => c !== boxId),
field: [unitId, ...player.field]
field: [boxId, ...player.field]
}

@@ -47,5 +47,3 @@ },

.filter((onSummon, i) => {
if (
Object.keys(target(state.game, onSummon.target)).length === 0
) {
if (Object.keys(target(state, onSummon.target)).length === 0) {
return false;

@@ -52,0 +50,0 @@ }

import ssbKeys from "@streamplace/ssb-keys";
import { clientGenerateKey } from "@cardcore/client";
import { rando } from "@cardcore/util";
import { rando, Box } from "@cardcore/util";
import { BOX_OPEN } from "./box";

@@ -12,23 +12,14 @@ export const SEED_RNG = "SEED_RNG";

export const seedRngEncrypt = () => async (dispatch, getState) => {
const { keys } = await dispatch(clientGenerateKey());
// idk just hash a key
const me = getState().client.keys;
// idk just hash a key, good enough
const randoSecret = ssbKeys.hash(ssbKeys.generate().id);
const boxed = ssbKeys.box(randoSecret, [keys]);
const { boxId, box } = Box.new(randoSecret, me.id);
return dispatch({
type: SEED_RNG_ENCRYPT,
id: keys.id,
box: boxed
boxId,
box
});
};
export const SEED_RNG_DECRYPT = "SEED_RNG_DECRYPT";
export const seedRngDecrypt = () => async (dispatch, getState) => {
const state = getState();
const mySeed = state.game.randoSeeds[state.client.keys.id];
const privateKey = state.secret[mySeed.id].private;
return dispatch({
type: SEED_RNG_DECRYPT,
privateKey: privateKey
});
};
export const SEED_RNG_COMBINE = "SEED_RNG_COMBINE";

@@ -50,2 +41,8 @@ // these actions should all happen in lexical order rather than playerOrder because they're used to // seed the RNG prior to playerOrder existing

},
{
playerId: action._sender,
action: {
type: SEED_RNG_COMBINE
}
},
...state.game.nextActions

@@ -63,10 +60,9 @@ ]

...state.game,
boxes: {
...state.game.boxes,
[action.boxId]: action.box
},
randoSeeds: {
...state.game.randoSeeds,
[action._sender]: {
secret: true,
id: action.id,
box: action.box,
playerId: action._sender
}
[action._sender]: action.boxId
}

@@ -86,3 +82,4 @@ }

action: {
type: SEED_RNG_DECRYPT
type: BOX_OPEN,
boxId: state.game.randoSeeds[playerId]
}

@@ -115,35 +112,10 @@ })),

if (action.type === SEED_RNG_DECRYPT) {
const orderedPlayers = Object.keys(state.game.players).sort();
const randoSeed = state.game.randoSeeds[action._sender];
let newSecret = state.secret;
if (state.secret[randoSeed.id]) {
newSecret = { ...state.secret };
delete newSecret[randoSeed.id];
}
state = {
...state,
game: {
...state.game,
randoSeeds: {
...state.game.randoSeeds,
[action._sender]: ssbKeys.unbox(
state.game.randoSeeds[action._sender].box,
{ private: action.privateKey }
)
}
}
};
// if we're done, clear out randoSeeds
if (
!Object.values(state.game.randoSeeds).every(
val => typeof val === "string"
)
) {
return state;
}
const finalSeed = ssbKeys.hash(
orderedPlayers.map(playerId => state.game.randoSeeds[playerId]).concat("")
);
rando.setSeed(finalSeed);
if (action.type === SEED_RNG_COMBINE) {
let finalSeed = Object.keys(state.game.players)
.sort()
.map(playerId => {
return Box.traverse(state, state.game.randoSeeds[playerId]);
})
.join("");
finalSeed = ssbKeys.hash(finalSeed);
return {

@@ -150,0 +122,0 @@ ...state,

@@ -37,3 +37,3 @@ import { rotateArray, shuffle } from "@cardcore/util";

const state = getState();
const key = Box.addKey(state.game.boxes[boxId], state.client.keys, playerId);
const key = Box.addKey(state, boxId, playerId);
dispatch({

@@ -40,0 +40,0 @@ type: SHUFFLE_DECK_DECRYPT,

@@ -12,3 +12,3 @@ // emoji, attack, health, name, text, onSummon

name: `Standard ${cost}-${cost}`,
text: "",
text: [],
onSummon: [],

@@ -27,3 +27,3 @@ onDeath: [],

name: "Summon Dude",
text: "onSummon: summon a 1/1 creature",
text: ["onSummon: summon a 1/1 creature"],
onSummon: [

@@ -42,3 +42,3 @@ {

name: "Bouncer",
text: "onSummon: choose a friendly creature to return to your hand",
text: ["onSummon: choose a friendly creature to return to your hand"],
onSummon: [

@@ -59,3 +59,3 @@ {

name: "Three Master",
text: `onSummon: Set all other creatures' Attack and Health to 3`,
text: [`onSummon: Set all other creatures' Attack and Health to 3`],
onSummon: [

@@ -84,3 +84,3 @@ {

name: "Card Drawer",
text: `onSummon: draw a card`,
text: [`onSummon: draw a card`],
onSummon: [

@@ -102,3 +102,3 @@ {

name: "Owner Damager",
text: `onSummon: Deal 3 damage to your hero`,
text: [`onSummon: Deal 3 damage to your hero`],
onSummon: [

@@ -121,3 +121,3 @@ {

name: "Creature Damager",
text: `onSummon: deal 1 damage to three target creatures`,
text: [`onSummon: deal 1 damage to three target creatures`],
onSummon: [

@@ -146,3 +146,3 @@ {

name: "Random Creature Damager",
text: `onSummon: deal 1 random damage to three target creatures`,
text: [`onSummon: deal 1 random damage to three target creatures`],
onSummon: [

@@ -149,0 +149,0 @@ {

import { DRAW_CARD } from "./draw-card";
import { START_GAME } from "./start-game";
import { Box } from "@cardcore/util";

@@ -38,3 +39,4 @@ export const START_TURN = "START_TURN";

const newUnits = {};
player.field.forEach(unitId => {
player.field.forEach(boxId => {
const unitId = Box.traverse(state, boxId);
newUnits[unitId] = {

@@ -41,0 +43,0 @@ ...state.game.units[unitId],

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc