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-4a0572cd to 0.0.1-4baabe2b

dist/box.js

81

dist/attack.js

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

});
exports.attackReducer = exports.attack = exports.ATTACK = undefined;
exports.attackReducer = exports.attack = exports.ATTACK = void 0;

@@ -13,18 +13,30 @@ var _checkDeath = require("./check-death");

var _standardAction = require("./standard-action");
var _util = require("@cardcore/util");
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var ATTACK = exports.ATTACK = "ATTACK";
var attack = exports.attack = function attack(attackingUnitId, defendingUnitId) {
const ATTACK = "ATTACK";
exports.ATTACK = ATTACK;
const attack = (attackingUnitId, defendingUnitId) => {
return {
type: ATTACK,
attackingUnitId: attackingUnitId,
defendingUnitId: defendingUnitId
attackingUnitId,
defendingUnitId
};
};
var attackReducer = exports.attackReducer = function attackReducer(state, action) {
exports.attack = attack;
const attackReducer = (state, action) => {
if (action.type === _startGame.START_GAME) {
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
allowedActions: Object.assign({}, state.game.allowedActions, _defineProperty({}, ATTACK, true))
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
allowedActions: _objectSpread({}, state.game.allowedActions, {
[ATTACK]: true
})
})

@@ -35,28 +47,45 @@ });

if (action.type === ATTACK) {
var _Object$assign2;
var attackingUnitId = action.attackingUnitId,
defendingUnitId = action.defendingUnitId;
var attackingUnit = state.game.units[attackingUnitId];
var defendingUnit = state.game.units[defendingUnitId];
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
units: Object.assign({}, state.game.units, (_Object$assign2 = {}, _defineProperty(_Object$assign2, attackingUnitId, Object.assign({}, attackingUnit, {
health: attackingUnit.health - defendingUnit.attack,
canAttack: false
})), _defineProperty(_Object$assign2, defendingUnitId, Object.assign({}, defendingUnit, {
health: defendingUnit.health - attackingUnit.attack
})), _Object$assign2)),
const {
attackingUnitId,
defendingUnitId
} = action;
const attackingUnit = state.game.units[attackingUnitId];
const defendingUnit = state.game.units[defendingUnitId];
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
units: _objectSpread({}, state.game.units, {
[attackingUnitId]: _objectSpread({}, attackingUnit, {
health: attackingUnit.health - defendingUnit.attack,
canAttack: false
}),
[defendingUnitId]: _objectSpread({}, defendingUnit, {
health: defendingUnit.health - attackingUnit.attack
})
}),
nextActions: [{
playerId: action._sender,
playerId: action.agent,
action: {
type: _checkDeath.CHECK_DEATH
}
}]
}, {
playerId: action.agent,
action: {
type: _standardAction.STANDARD_ACTION
}
}, ...state.game.nextActions],
queue: [(0, _util.makeSchema)({
type: _checkDeath.CHECK_DEATH,
agent: action.agent
}), (0, _util.makeSchema)({
type: _standardAction.STANDARD_ACTION,
agent: action.agent
}), ...state.game.queue]
})
});
}
return state;
};
exports.attackReducer = attackReducer;
//# sourceMappingURL=attack.js.map

@@ -6,59 +6,43 @@ "use strict";

});
exports.bounceReducer = exports.bounceEncrypt = exports.BOUNCE_ENCRYPT = exports.bounce = exports.BOUNCE = undefined;
exports.bounceReducer = exports.bounceEncrypt = exports.BOUNCE_ENCRYPT = exports.bounce = exports.BOUNCE = void 0;
var _regenerator = require("babel-runtime/regenerator");
var _regenerator2 = _interopRequireDefault(_regenerator);
var _util = require("@cardcore/util");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
const BOUNCE = "BOUNCE";
exports.BOUNCE = BOUNCE;
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
const bounce = ({
target
}) => {
return {
type: BOUNCE,
target
};
};
var BOUNCE = exports.BOUNCE = "BOUNCE";
var bounce = exports.bounce = function bounce(_ref) {
var target = _ref.target;
exports.bounce = bounce;
const BOUNCE_ENCRYPT = "BOUNCE_ENCRYPT";
exports.BOUNCE_ENCRYPT = BOUNCE_ENCRYPT;
return { type: BOUNCE, target: target };
const bounceEncrypt = ({
unitId
}) => async (dispatch, getState) => {
return dispatch({
type: "BOUNCE_ENCRYPT",
unitId
});
};
var BOUNCE_ENCRYPT = exports.BOUNCE_ENCRYPT = "BOUNCE_ENCRYPT";
var bounceEncrypt = exports.bounceEncrypt = function bounceEncrypt(_ref2) {
var unitId = _ref2.unitId;
return function () {
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee(dispatch, getState) {
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
return _context.abrupt("return", dispatch({
type: "BOUNCE_ENCRYPT",
unitId: unitId
}));
exports.bounceEncrypt = bounceEncrypt;
case 1:
case "end":
return _context.stop();
}
}
}, _callee, undefined);
}));
return function (_x, _x2) {
return _ref3.apply(this, arguments);
};
}();
};
var bounceReducer = exports.bounceReducer = function bounceReducer(state, action) {
const bounceReducer = (state, action) => {
if (action.type === BOUNCE) {
var targets = (0, _util.targetArray)(state.game, action.target);
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
nextActions: [].concat(_toConsumableArray(targets.map(function (target) {
const targets = (0, _util.targetArray)(state.game, action.target);
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
nextActions: [...targets.map(target => {
return {

@@ -71,21 +55,30 @@ playerId: target.playerId,

};
})), _toConsumableArray(state.game.nextActions))
}), ...state.game.nextActions],
queue: [...targets.map(target => ({
action: BOUNCE_ENCRYPT,
agent: target.playerId,
unitId: target.unitId
})), ...state.game.queue]
})
});
}
if (action.type === BOUNCE_ENCRYPT) {
var player = state.game.players[action._sender];
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
players: Object.assign({}, state.game.players, _defineProperty({}, action._sender, Object.assign({}, player, {
hand: [].concat(_toConsumableArray(player.hand), [action.unitId]),
field: player.field.filter(function (unitId) {
return unitId !== action.unitId;
const player = state.game.players[action.agent];
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
players: _objectSpread({}, state.game.players, {
[action.agent]: _objectSpread({}, player, {
hand: [...player.hand, action.unitId],
field: player.field.filter(unitId => unitId !== action.unitId)
})
})))
})
})
});
}
return state;
};
exports.bounceReducer = bounceReducer;
//# sourceMappingURL=bounce.js.map

@@ -6,15 +6,21 @@ "use strict";

});
exports.buffReducer = exports.CHANGE_HEALTH = exports.CHANGE_ATTACK = undefined;
exports.buffReducer = exports.CHANGE_HEALTH = exports.CHANGE_ATTACK = void 0;
var _util = require("@cardcore/util");
var CHANGE_ATTACK = exports.CHANGE_ATTACK = "CHANGE_ATTACK";
var CHANGE_HEALTH = exports.CHANGE_HEALTH = "CHANGE_HEALTH";
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
var buffReducer = exports.buffReducer = function buffReducer(state, action) {
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
const CHANGE_ATTACK = "CHANGE_ATTACK";
exports.CHANGE_ATTACK = CHANGE_ATTACK;
const CHANGE_HEALTH = "CHANGE_HEALTH";
exports.CHANGE_HEALTH = CHANGE_HEALTH;
const buffReducer = (state, action) => {
if (action.type === CHANGE_ATTACK) {
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
units: Object.assign({}, state.game.units, (0, _util.target)(state.game, action.target, function (unit) {
return Object.assign({}, unit, {
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
units: _objectSpread({}, state.game.units, (0, _util.target)(state, action.target, unit => {
return _objectSpread({}, unit, {
attack: action.value

@@ -28,6 +34,6 @@ });

if (action.type === CHANGE_HEALTH) {
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
units: Object.assign({}, state.game.units, (0, _util.target)(state.game, action.target, function (unit) {
return Object.assign({}, unit, {
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
units: _objectSpread({}, state.game.units, (0, _util.target)(state, action.target, unit => {
return _objectSpread({}, unit, {
health: action.value

@@ -42,2 +48,4 @@ });

};
exports.buffReducer = buffReducer;
//# sourceMappingURL=buff.js.map

@@ -6,60 +6,34 @@ "use strict";

});
exports.checkDeathReducer = exports.checkDeath = exports.CHECK_DEATH = undefined;
exports.checkDeathReducer = exports.checkDeath = exports.CHECK_DEATH = void 0;
var _regenerator = require("babel-runtime/regenerator");
var _util = require("@cardcore/util");
var _regenerator2 = _interopRequireDefault(_regenerator);
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const CHECK_DEATH = "CHECK_DEATH";
exports.CHECK_DEATH = CHECK_DEATH;
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
const checkDeath = () => async dispatch => {
await dispatch({
type: CHECK_DEATH
});
};
var CHECK_DEATH = exports.CHECK_DEATH = "CHECK_DEATH";
var checkDeath = exports.checkDeath = function checkDeath() {
return function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee(dispatch) {
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return dispatch({
type: CHECK_DEATH
});
exports.checkDeath = checkDeath;
case 2:
case "end":
return _context.stop();
}
}
}, _callee, undefined);
}));
return function (_x) {
return _ref.apply(this, arguments);
};
}();
};
var checkDeathReducer = exports.checkDeathReducer = function checkDeathReducer(state, action) {
const checkDeathReducer = (state, action) => {
if (action.type === CHECK_DEATH) {
var newPlayers = {};
Object.entries(state.game.players).forEach(function (_ref2) {
var _ref3 = _slicedToArray(_ref2, 2),
playerId = _ref3[0],
player = _ref3[1];
const traverse = boxId => _util.Box.traverse(state, boxId);
newPlayers[playerId] = Object.assign({}, player, {
field: player.field.filter(function (unitId) {
return state.game.units[unitId].health > 0;
}),
graveyard: player.field.concat(player.field.filter(function (unitId) {
return state.game.units[unitId].health <= 0;
}))
const newPlayers = {};
Object.entries(state.game.players).forEach(([playerId, player]) => {
newPlayers[playerId] = _objectSpread({}, player, {
field: player.field.filter(boxId => state.game.units[traverse(boxId)].health > 0),
graveyard: player.field.concat(player.field.filter(boxId => state.game.units[traverse(boxId)].health <= 0))
});
});
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
players: newPlayers

@@ -72,2 +46,4 @@ })

};
exports.checkDeathReducer = checkDeathReducer;
//# sourceMappingURL=check-death.js.map

@@ -6,14 +6,19 @@ "use strict";

});
exports.damageReducer = exports.DAMAGE = undefined;
exports.damageReducer = exports.DAMAGE = void 0;
var _util = require("@cardcore/util");
var DAMAGE = exports.DAMAGE = "DAMAGE";
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
var damageReducer = exports.damageReducer = function damageReducer(state, action) {
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
const DAMAGE = "DAMAGE";
exports.DAMAGE = DAMAGE;
const damageReducer = (state, action) => {
if (action.type === DAMAGE) {
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
units: Object.assign({}, state.game.units, (0, _util.target)(state.game, action.target, function (unit) {
return Object.assign({}, unit, {
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
units: _objectSpread({}, state.game.units, (0, _util.target)(state, action.target, unit => {
return _objectSpread({}, unit, {
health: unit.health - action.value

@@ -25,4 +30,7 @@ });

}
return state;
};
exports.damageReducer = damageReducer;
//# sourceMappingURL=damage.js.map

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

});
var DESYNC = exports.DESYNC = "DESYNC";
exports.desync = exports.DESYNC = void 0;
const DESYNC = "DESYNC";
/**

@@ -12,3 +13,6 @@ * In the event of a desync, we give up on doing anything else and just have clients report their

*/
var desync = exports.desync = function desync(user, state) {
exports.DESYNC = DESYNC;
const desync = (user, state) => {
return {

@@ -20,2 +24,4 @@ type: DESYNC,

};
exports.desync = desync;
//# sourceMappingURL=desync.js.map

@@ -6,22 +6,24 @@ "use strict";

});
exports.DRAW_CARD = undefined;
exports.drawCardReducer = drawCardReducer;
exports.DRAW_CARD = void 0;
var _shuffleDeck = require("./shuffle-deck");
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
var _util = require("@cardcore/util");
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var DRAW_CARD = exports.DRAW_CARD = "DRAW_CARD";
const DRAW_CARD = "DRAW_CARD";
exports.DRAW_CARD = DRAW_CARD;
function drawCardReducer(state, action) {
if (action.type === DRAW_CARD) {
var players = state.game.playerOrder;
let players = state.game.playerOrder;
if (action.target.player === "self") {
players = [state.game.turn];
} else if (action.target.player === "enemy") {
players = state.game.playerOrder.filter(function (x) {
return x !== state.game.turn;
});
players = state.game.playerOrder.filter(x => x !== state.game.turn);
} else if (action.target.player) {

@@ -32,55 +34,52 @@ players = [action.target.player];

}
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = players[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var playerId = _step.value;
for (const playerId of players) {
const player = state.game.players[playerId];
const boxId = player.deck[0];
var player = state.game.players[playerId];
var boxId = player.deck[0];
if (!boxId) {
// fatigue
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
units: Object.assign({}, state.game.units, _defineProperty({}, player.unitId, Object.assign({}, state.game.units[player.unitId], {
if (!boxId) {
// fatigue
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
units: _objectSpread({}, state.game.units, {
[player.unitId]: _objectSpread({}, state.game.units[player.unitId], {
health: state.game.units[player.unitId].health - player.fatigue
}))),
players: Object.assign({}, state.game.players, _defineProperty({}, playerId, Object.assign({}, player, {
})
}),
players: _objectSpread({}, state.game.players, {
[playerId]: _objectSpread({}, player, {
fatigue: player.fatigue + 1
})))
})
})
});
}
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
players: Object.assign({}, state.game.players, _defineProperty({}, playerId, Object.assign({}, player, {
hand: [boxId].concat(_toConsumableArray(player.hand)),
deck: player.deck.slice(1)
}))),
nextActions: [{
playerId: Object.keys(state.game.boxes[boxId].keys).sort()[0],
action: {
type: _shuffleDeck.SHUFFLE_DECK_DECRYPT,
playerId: playerId,
boxId: boxId
}
}].concat(_toConsumableArray(state.game.nextActions))
})
});
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
players: _objectSpread({}, state.game.players, {
[playerId]: _objectSpread({}, player, {
hand: [boxId, ...player.hand],
deck: player.deck.slice(1)
})
}),
nextActions: [{
playerId: Object.keys(state.game.boxes[boxId].keys).sort()[0],
action: {
type: _shuffleDeck.SHUFFLE_DECK_DECRYPT,
playerId: playerId,
boxId: boxId
}
}, ...state.game.nextActions],
queue: [(0, _util.makeSchema)({
type: _shuffleDeck.SHUFFLE_DECK_DECRYPT,
agent: Object.keys(state.game.boxes[boxId].keys).sort()[0],
boxId: boxId,
playerId,
key: {
type: "string"
}
}), ...state.game.queue]
})
});
}

@@ -87,0 +86,0 @@

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

});
exports.gameReducer = undefined;
var _exportNames = {
gameReducer: true
};
exports.gameReducer = void 0;

@@ -13,5 +16,6 @@ var _attack = require("./attack");

if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
get: function () {
return _attack[key];

@@ -26,5 +30,6 @@ }

if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
get: function () {
return _bounce[key];

@@ -35,2 +40,15 @@ }

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

@@ -40,5 +58,6 @@

if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
get: function () {
return _buff[key];

@@ -53,5 +72,6 @@ }

if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
get: function () {
return _checkDeath[key];

@@ -66,5 +86,6 @@ }

if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
get: function () {
return _damage[key];

@@ -79,5 +100,6 @@ }

if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
get: function () {
return _desync[key];

@@ -92,5 +114,6 @@ }

if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
get: function () {
return _drawCard[key];

@@ -105,5 +128,6 @@ }

if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
get: function () {
return _playCard[key];

@@ -118,5 +142,6 @@ }

if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
get: function () {
return _playCreature[key];

@@ -131,5 +156,6 @@ }

if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
get: function () {
return _seedRng[key];

@@ -144,5 +170,6 @@ }

if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
get: function () {
return _shuffleDeck[key];

@@ -153,2 +180,15 @@ }

var _standardAction = require("./standard-action");
Object.keys(_standardAction).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _standardAction[key];
}
});
});
var _startGame = require("./start-game");

@@ -158,5 +198,6 @@

if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
get: function () {
return _startGame[key];

@@ -171,5 +212,6 @@ }

if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
get: function () {
return _summonCreature[key];

@@ -184,5 +226,6 @@ }

if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
get: function () {
return _turns[key];

@@ -193,35 +236,10 @@ }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var gameReducer = exports.gameReducer = function gameReducer(state, action) {
// initialization
// On this one, clear out both the nextActions queue and the players list... this is the first
// person joining. Everyone else joins with JOIN_GAME
if (action.type === _startGame.CREATE_GAME) {
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
startTime: action.startTime,
nextActions: [{
action: { type: _startGame.JOIN_GAME },
// lol lol lol hack hack hack
notPlayerId: action._sender
}],
allowedActions: {},
playerOrder: [],
params: {
startDraw: 3
},
started: false,
players: _defineProperty({}, action._sender, {}),
units: {},
randoSeeds: {},
prev: null,
boxes: {}
})
});
}
const gameReducer = (state, action) => {
if (action.prev) {
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
prev: action.prev

@@ -234,2 +252,4 @@ })

};
exports.gameReducer = gameReducer;
//# sourceMappingURL=index.js.map

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

});
exports.playCardReducer = exports.revealCard = exports.REVEAL_CARD = exports.playCard = exports.PLAY_CARD = undefined;
exports.playCardReducer = exports.revealCard = exports.REVEAL_CARD = exports.PLAY_CARD_DONE = exports.playCard = exports.PLAY_CARD = void 0;

@@ -15,37 +15,46 @@ var _util = require("@cardcore/util");

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
var _standardAction = require("./standard-action");
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var PLAY_CARD = exports.PLAY_CARD = "PLAY_CARD";
var playCard = exports.playCard = function playCard(_ref) {
var boxId = _ref.boxId;
return {
type: "PLAY_CARD",
boxId: boxId
};
};
const PLAY_CARD = "PLAY_CARD";
exports.PLAY_CARD = PLAY_CARD;
var REVEAL_CARD = exports.REVEAL_CARD = "REVEAL_CARD";
var revealCard = exports.revealCard = function revealCard(_ref2) {
var boxId = _ref2.boxId;
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);
dispatch({
type: "REVEAL_CARD",
boxId: boxId,
privateKey: privateKey
});
};
};
const playCard = ({
boxId
}) => ({
type: "PLAY_CARD",
boxId
});
// TODO: are you adding not-creatures? go here!
var playCardReducer = exports.playCardReducer = function playCardReducer(state, action) {
exports.playCard = playCard;
const PLAY_CARD_DONE = "PLAY_CARD_DONE";
exports.PLAY_CARD_DONE = PLAY_CARD_DONE;
const REVEAL_CARD = "REVEAL_CARD";
exports.REVEAL_CARD = REVEAL_CARD;
const revealCard = ({
boxId
}) => (dispatch, getState) => {
const privateKey = _util.Box.getPrivate(getState(), boxId);
dispatch({
type: "REVEAL_CARD",
boxId,
privateKey
});
}; // TODO: are you adding not-creatures? go here!
exports.revealCard = revealCard;
const playCardReducer = (state, action) => {
if (action.type === _startGame.START_GAME) {
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
allowedActions: Object.assign({}, state.game.allowedActions, _defineProperty({}, PLAY_CARD, true))
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
allowedActions: _objectSpread({}, state.game.allowedActions, {
[PLAY_CARD]: true
})
})

@@ -56,12 +65,26 @@ });

if (action.type === PLAY_CARD) {
var nextActions = [].concat(_toConsumableArray(state.game.nextActions), [{
playerId: action._sender,
let nextActions = [...state.game.nextActions, {
playerId: action.agent,
action: {
type: _playCreature.PLAY_CREATURE,
type: PLAY_CARD_DONE,
boxId: action.boxId
}
}]);
}, {
playerId: action.agent,
action: {
type: _standardAction.STANDARD_ACTION
}
}];
let queue = [...state.game.queue, (0, _util.makeSchema)({
type: PLAY_CARD_DONE,
agent: action.agent,
boxId: action.boxId
}), (0, _util.makeSchema)({
type: _standardAction.STANDARD_ACTION,
agent: action.agent
})];
if (!state.game.units[action.boxId]) {
nextActions = [{
playerId: (0, _util.getLeftPlayer)(action._sender, state.game.playerOrder),
playerId: (0, _util.getLeftPlayer)(action.agent, state.game.playerOrder),
action: {

@@ -71,7 +94,17 @@ type: REVEAL_CARD,

}
}].concat(_toConsumableArray(nextActions));
}, ...nextActions];
queue = [(0, _util.makeSchema)({
type: REVEAL_CARD,
agent: (0, _util.getLeftPlayer)(action.agent, state.game.playerOrder),
boxId: action.boxId,
privateKey: {
type: "string"
}
}), ...queue];
}
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
nextActions: nextActions
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
nextActions: nextActions,
queue: queue
})

@@ -81,13 +114,79 @@ });

if (action.type === PLAY_CARD_DONE) {
// If we get here, we should know the contents...
const cardId = _util.Box.traverse(state, action.boxId);
const card = state.game.units[cardId];
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
nextActions: [{
playerId: action.agent,
action: {
type: _playCreature.PLAY_CREATURE,
boxId: action.boxId
}
}, ...state.game.nextActions],
queue: [(0, _util.makeSchema)({
type: _playCreature.PLAY_CREATURE,
agent: action.agent,
boxId: action.boxId,
targets: {
type: "array",
minItems: card.onSummon.length,
maxItems: card.onSummon.length,
items: card.onSummon.map(onSummon => {
if (onSummon.target.count === undefined) {
return {
enum: [null]
};
}
if (onSummon.target.random) {
return {
enum: [null]
};
}
const targets = Object.keys((0, _util.target)(state, onSummon.target)).sort();
if (targets.length > 0) {
return {
enum: targets
};
}
return {
enum: [null]
};
})
}
}), ...state.game.queue]
})
});
}
if (action.type === REVEAL_CARD) {
var box = state.game.boxes[action.boxId];
var newBox = Object.assign({}, box, {
const box = state.game.boxes[action.boxId];
const newBox = _objectSpread({}, box, {
privateKey: action.privateKey
});
var contents = _util.Box.open(action.boxId, newBox, null);
// if there's another box in here, pass to the player on our left
var _nextActions = state.game.nextActions;
state = _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
boxes: _objectSpread({}, state.game.boxes, {
[action.boxId]: newBox
})
})
});
const contents = _util.Box.open(state, action.boxId); // if there's another box in here, pass to the player on our left
let nextActions = state.game.nextActions;
let queue = state.game.queue;
if (state.game.boxes[contents]) {
_nextActions = [{
playerId: (0, _util.getLeftPlayer)(action._sender, state.game.playerOrder),
nextActions = [{
playerId: (0, _util.getLeftPlayer)(action.agent, state.game.playerOrder),
action: {

@@ -97,15 +196,27 @@ type: REVEAL_CARD,

}
}].concat(_toConsumableArray(_nextActions));
}, ...nextActions];
queue = [(0, _util.makeSchema)({
type: REVEAL_CARD,
agent: (0, _util.getLeftPlayer)(action.agent, state.game.playerOrder),
boxId: contents,
privateKey: {
type: "string"
}
}), ...queue];
} else if (!state.game.units[contents]) {
throw new Error("invalid card: " + contents);
throw new Error(`invalid card: ${contents}`);
}
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
boxes: Object.assign({}, state.game.boxes, _defineProperty({}, action.boxId, newBox)),
nextActions: _nextActions
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
nextActions: nextActions,
queue: queue
})
});
}
return state;
};
exports.playCardReducer = playCardReducer;
//# sourceMappingURL=play-card.js.map

@@ -6,8 +6,4 @@ "use strict";

});
exports.playCreatureReducer = exports.playCreature = exports.PLAY_CREATURE = undefined;
exports.playCreatureReducer = exports.playCreature = exports.PLAY_CREATURE = void 0;
var _regenerator = require("babel-runtime/regenerator");
var _regenerator2 = _interopRequireDefault(_regenerator);
var _seedRng = require("./seed-rng");

@@ -21,79 +17,109 @@

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
const PLAY_CREATURE = "PLAY_CREATURE";
exports.PLAY_CREATURE = PLAY_CREATURE;
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
const playCreature = ({
boxId
}) => async (dispatch, getState) => {
const {
targets
} = getState().client;
dispatch({
type: PLAY_CREATURE,
boxId,
targets
});
};
var PLAY_CREATURE = exports.PLAY_CREATURE = "PLAY_CREATURE";
var playCreature = exports.playCreature = function playCreature(_ref) {
var boxId = _ref.boxId;
return function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee(dispatch, getState) {
var targets;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
targets = getState().client.targets;
exports.playCreature = playCreature;
dispatch({
type: PLAY_CREATURE,
boxId: boxId,
targets: targets
});
const playCreatureReducer = (state, action) => {
if (action.type === PLAY_CREATURE) {
const player = state.game.players[action.agent];
const boxId = action.boxId;
case 2:
case "end":
return _context.stop();
}
}
}, _callee, undefined);
}));
const unitId = _util.Box.traverse(state, boxId);
return function (_x, _x2) {
return _ref2.apply(this, arguments);
};
}();
};
var playCreatureReducer = exports.playCreatureReducer = function playCreatureReducer(state, action) {
if (action.type === PLAY_CREATURE) {
var player = state.game.players[action._sender];
var boxId = action.boxId;
var unitId = _util.Box.traverse(boxId, state.game.boxes, state.client.keys);
var unit = state.game.units[unitId];
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
players: Object.assign({}, state.game.players, _defineProperty({}, action._sender, Object.assign({}, player, {
availableMana: player.availableMana - unit.cost,
hand: player.hand.filter(function (c) {
return c !== boxId;
}),
field: [unitId].concat(_toConsumableArray(player.field))
}))),
units: Object.assign({}, state.game.units, _defineProperty({}, unitId, Object.assign({}, unit, { canAttack: false }))),
const unit = state.game.units[unitId];
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
players: _objectSpread({}, state.game.players, {
[action.agent]: _objectSpread({}, player, {
availableMana: player.availableMana - unit.cost,
hand: player.hand.filter(c => c !== boxId),
field: [boxId, ...player.field]
})
}),
units: _objectSpread({}, state.game.units, {
[unitId]: _objectSpread({}, unit, {
canAttack: false
})
}),
nextActions: [{
playerId: action._sender,
playerId: action.agent,
action: {
type: _seedRng.SEED_RNG
}
}].concat(_toConsumableArray(unit.onSummon.filter(function (onSummon, i) {
if (Object.keys((0, _util.target)(state.game, onSummon.target)).length === 0) {
}, ...unit.onSummon.filter((onSummon, i) => {
if (Object.keys((0, _util.target)(state, onSummon.target)).length === 0) {
return false;
}
return true;
}).map(function (onSummon, i) {
}).map((onSummon, i) => {
return {
playerId: action._sender,
action: Object.assign({}, onSummon, {
target: Object.assign({}, onSummon.target, {
playerId: action.agent,
action: _objectSpread({}, onSummon, {
target: JSON.parse(JSON.stringify(_objectSpread({}, onSummon.target, {
unitId: onSummon.target.random ? undefined : action.targets[i]
}),
unitId: unitId
}))) // unitId: unitId
})
};
})), [{ playerId: action._sender, action: { type: _checkDeath.CHECK_DEATH } }], _toConsumableArray(state.game.nextActions))
}), {
playerId: action.agent,
action: {
type: _checkDeath.CHECK_DEATH
}
}, ...state.game.nextActions],
queue: [(0, _util.makeSchema)({
type: _seedRng.SEED_RNG,
agent: action.agent
}), ...unit.onSummon.filter((onSummon, i) => Object.keys((0, _util.target)(state, onSummon.target)).length !== 0).map((onSummon, i) => {
return (0, _util.makeSchema)(Object.keys(onSummon).reduce((schema, fieldName) => {
if (["type", "target"].includes(fieldName)) {
return schema;
}
return _objectSpread({}, schema, {
[fieldName]: {
enum: [onSummon[fieldName]]
}
});
}, {
type: onSummon.type,
agent: action.agent,
target: {
type: "object",
additionalProperties: false,
properties: Object.keys(onSummon.target).reduce((props, field) => _objectSpread({}, props, {
[field]: {
enum: [onSummon.target[field]]
}
}), // it's late, leave me alone
JSON.parse(JSON.stringify({
unitId: onSummon.target.random ? undefined : {
enum: [action.targets[i]]
}
})))
}
}));
}), (0, _util.makeSchema)({
type: _checkDeath.CHECK_DEATH,
agent: action.agent
}), ...state.game.queue]
})

@@ -105,2 +131,4 @@ });

};
exports.playCreatureReducer = playCreatureReducer;
//# sourceMappingURL=play-creature.js.map

@@ -6,106 +6,87 @@ "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 = void 0;
var _regenerator = require("babel-runtime/regenerator");
var _ssbKeys = _interopRequireDefault(require("@streamplace/ssb-keys"));
var _regenerator2 = _interopRequireDefault(_regenerator);
var _util = require("@cardcore/util");
var _ssbKeys = require("@streamplace/ssb-keys");
var _box = require("./box");
var _ssbKeys2 = _interopRequireDefault(_ssbKeys);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _client = require("@cardcore/client");
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
var _util = require("@cardcore/util");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
const SEED_RNG = "SEED_RNG";
exports.SEED_RNG = SEED_RNG;
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
var SEED_RNG = exports.SEED_RNG = "SEED_RNG";
var seedRng = exports.seedRng = function seedRng(action) {
const seedRng = action => {
return action;
};
var SEED_RNG_ENCRYPT = exports.SEED_RNG_ENCRYPT = "SEED_RNG_ENCRYPT";
var seedRngEncrypt = exports.seedRngEncrypt = function seedRngEncrypt() {
return function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee(dispatch, getState) {
var _ref2, keys, randoSecret, boxed;
exports.seedRng = seedRng;
const SEED_RNG_ENCRYPT = "SEED_RNG_ENCRYPT";
exports.SEED_RNG_ENCRYPT = SEED_RNG_ENCRYPT;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return dispatch((0, _client.clientGenerateKey)());
const seedRngEncrypt = () => async (dispatch, getState) => {
const me = getState().client.keys; // idk just hash a key, good enough
case 2:
_ref2 = _context.sent;
keys = _ref2.keys;
const randoSecret = _ssbKeys.default.hash(_ssbKeys.default.generate().id);
// idk just hash a key
randoSecret = _ssbKeys2.default.hash(_ssbKeys2.default.generate().id);
boxed = _ssbKeys2.default.box(randoSecret, [keys]);
return _context.abrupt("return", dispatch({
type: SEED_RNG_ENCRYPT,
id: keys.id,
box: boxed
}));
const {
boxId,
box
} = _util.Box.new(randoSecret, me.id);
case 7:
case "end":
return _context.stop();
}
}
}, _callee, undefined);
}));
return function (_x, _x2) {
return _ref.apply(this, arguments);
};
}();
return dispatch({
type: SEED_RNG_ENCRYPT,
boxId,
box
});
};
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
}));
exports.seedRngEncrypt = seedRngEncrypt;
const SEED_RNG_COMBINE = "SEED_RNG_COMBINE"; // these actions should all happen in lexical order rather than playerOrder because they're used to // seed the RNG prior to playerOrder existing
case 4:
case "end":
return _context2.stop();
}
}
}, _callee2, undefined);
}));
exports.SEED_RNG_COMBINE = SEED_RNG_COMBINE;
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
var seedRngReducer = exports.seedRngReducer = function seedRngReducer(state, action) {
const seedRngReducer = (state, action) => {
if (action.type === SEED_RNG) {
var orderedPlayers = Object.keys(state.game.players).sort();
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
const orderedPlayers = Object.keys(state.game.players).sort();
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
queue: [(0, _util.makeSchema)({
type: {
enum: [SEED_RNG_ENCRYPT]
},
agent: {
enum: [orderedPlayers[0]]
},
boxId: {
type: "string"
},
box: {
type: "object",
additionalProperties: false,
required: ["contents", "keys"],
properties: {
contents: {
type: "string"
},
keys: {
[orderedPlayers[0]]: {
type: "string"
}
}
}
}
}), (0, _util.makeSchema)({
type: {
enum: [SEED_RNG_COMBINE]
},
agent: {
enum: [action.agent]
}
}), ...state.game.queue],
nextActions: [{

@@ -116,3 +97,8 @@ playerId: orderedPlayers[0],

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

@@ -123,39 +109,78 @@ });

if (action.type === SEED_RNG_ENCRYPT) {
var _orderedPlayers = Object.keys(state.game.players).sort();
state = Object.assign({}, state, {
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
}))
const orderedPlayers = Object.keys(state.game.players).sort();
state = _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
boxes: _objectSpread({}, state.game.boxes, {
[action.boxId]: action.box
}),
randoSeeds: _objectSpread({}, state.game.randoSeeds, {
[action.agent]: action.boxId
})
})
});
// if we're done, do all the decrypts
var seedCount = Object.keys(state.game.randoSeeds).length;
if (seedCount === _orderedPlayers.length) {
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
nextActions: [].concat(_toConsumableArray(_orderedPlayers.map(function (playerId) {
return {
playerId: playerId,
action: {
type: SEED_RNG_DECRYPT
}
};
})), _toConsumableArray(state.game.nextActions))
}); // if we're done, do all the decrypts
const seedCount = Object.keys(state.game.randoSeeds).length;
if (seedCount === orderedPlayers.length) {
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
nextActions: [...orderedPlayers.map(playerId => ({
playerId: playerId,
action: {
type: _box.BOX_OPEN,
boxId: state.game.randoSeeds[playerId]
}
})), ...state.game.nextActions],
queue: [...orderedPlayers.map(playerId => (0, _util.makeSchema)({
type: {
enum: [_box.BOX_OPEN]
},
agent: {
enum: [playerId]
},
boxId: {
enum: [state.game.randoSeeds[playerId]]
},
privateKey: {
type: "string"
}
})), ...state.game.queue]
})
});
}
// otherwise do the next encrypt
} // otherwise do the next encrypt
else {
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
nextActions: [{
playerId: _orderedPlayers[seedCount],
playerId: orderedPlayers[seedCount],
action: {
type: SEED_RNG_ENCRYPT
}
}].concat(_toConsumableArray(state.game.nextActions))
}, ...state.game.nextActions],
queue: [(0, _util.makeSchema)({
type: {
enum: [SEED_RNG_ENCRYPT]
},
agent: {
enum: [orderedPlayers[seedCount]]
},
boxId: {
type: "string"
},
box: {
type: "object",
additionalProperties: false,
required: ["contents", "keys"],
properties: {
contents: {
type: "string"
},
keys: {
[orderedPlayers[seedCount]]: {
type: "string"
}
}
}
}
}), ...state.game.queue]
})

@@ -166,27 +191,12 @@ });

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(""));
if (action.type === SEED_RNG_COMBINE) {
let finalSeed = Object.keys(state.game.players).sort().map(playerId => {
return _util.Box.traverse(state, state.game.randoSeeds[playerId]);
}).join("");
finalSeed = _ssbKeys.default.hash(finalSeed);
_util.rando.setSeed(finalSeed);
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
randoSeeds: {},

@@ -200,2 +210,4 @@ randoSeed: finalSeed

};
exports.seedRngReducer = seedRngReducer;
//# sourceMappingURL=seed-rng.js.map

@@ -6,129 +6,79 @@ "use strict";

});
exports.shuffleDeckReducer = exports.shuffleDeckDecrypt = exports.SHUFFLE_DECK_DECRYPT = exports.shuffleDeckEncrypt = exports.SHUFFLE_DECK_ENCRYPT = exports.SHUFFLE_DECK = undefined;
exports.shuffleDeckReducer = exports.shuffleDeckDecrypt = exports.SHUFFLE_DECK_DECRYPT = exports.shuffleDeckEncrypt = exports.SHUFFLE_DECK_ENCRYPT = exports.SHUFFLE_DECK = void 0;
var _regenerator = require("babel-runtime/regenerator");
var _util = require("@cardcore/util");
var _regenerator2 = _interopRequireDefault(_regenerator);
var _ssbKeys = _interopRequireDefault(require("@streamplace/ssb-keys"));
var _util = require("@cardcore/util");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
var SHUFFLE_DECK = exports.SHUFFLE_DECK = "SHUFFLE_DECK";
// export const shuffleDeck = action => (dispatch, getState) => {
const SHUFFLE_DECK = "SHUFFLE_DECK"; // export const shuffleDeck = action => (dispatch, getState) => {
// dispatch(action);
// };
var SHUFFLE_DECK_ENCRYPT = exports.SHUFFLE_DECK_ENCRYPT = "SHUFFLE_DECK_ENCRYPT";
var shuffleDeckEncrypt = exports.shuffleDeckEncrypt = function shuffleDeckEncrypt(_ref) {
var playerId = _ref.playerId;
return function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee(dispatch, getState) {
var state, encryptedDeck, boxes, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, card, _Box$new, boxId, box;
exports.SHUFFLE_DECK = SHUFFLE_DECK;
const SHUFFLE_DECK_ENCRYPT = "SHUFFLE_DECK_ENCRYPT";
exports.SHUFFLE_DECK_ENCRYPT = SHUFFLE_DECK_ENCRYPT;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
state = getState();
encryptedDeck = [];
boxes = {};
_iteratorNormalCompletion = true;
_didIteratorError = false;
_iteratorError = undefined;
_context.prev = 6;
const shuffleDeckEncrypt = ({
playerId
}) => async (dispatch, getState) => {
const state = getState();
for (_iterator = state.game.players[playerId].deck[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
card = _step.value;
_Box$new = _util.Box.new(card, state.client.keys.id), boxId = _Box$new.boxId, box = _Box$new.box;
const seed = _ssbKeys.default.generate().public;
encryptedDeck.push(boxId);
boxes[boxId] = box;
}
_context.next = 14;
break;
const boxes = {};
case 10:
_context.prev = 10;
_context.t0 = _context["catch"](6);
_didIteratorError = true;
_iteratorError = _context.t0;
for (const card of state.game.players[playerId].deck) {
const {
boxId,
box
} = _util.Box.new(card, state.client.keys.id);
case 14:
_context.prev = 14;
_context.prev = 15;
boxes[boxId] = box;
}
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
return dispatch({
type: SHUFFLE_DECK_ENCRYPT,
seed,
boxes,
playerId
});
}; // for now this operates on the first card in someone's hand... maybe that's okay.
case 17:
_context.prev = 17;
if (!_didIteratorError) {
_context.next = 20;
break;
}
exports.shuffleDeckEncrypt = shuffleDeckEncrypt;
const SHUFFLE_DECK_DECRYPT = "SHUFFLE_DECK_DECRYPT";
exports.SHUFFLE_DECK_DECRYPT = SHUFFLE_DECK_DECRYPT;
throw _iteratorError;
const shuffleDeckDecrypt = ({
playerId,
boxId
}) => (dispatch, getState) => {
const state = getState();
case 20:
return _context.finish(17);
const key = _util.Box.addKey(state, boxId, playerId);
case 21:
return _context.finish(14);
case 22:
return _context.abrupt("return", dispatch({
type: SHUFFLE_DECK_ENCRYPT,
deck: (0, _util.shuffle)(encryptedDeck),
boxes: boxes,
playerId: playerId
}));
case 23:
case "end":
return _context.stop();
}
}
}, _callee, undefined, [[6, 10, 14, 22], [15,, 17, 21]]);
}));
return function (_x, _x2) {
return _ref2.apply(this, arguments);
};
}();
dispatch({
type: SHUFFLE_DECK_DECRYPT,
boxId,
playerId,
key
});
};
// for now this operates on the first card in someone's hand... maybe that's okay.
var SHUFFLE_DECK_DECRYPT = exports.SHUFFLE_DECK_DECRYPT = "SHUFFLE_DECK_DECRYPT";
var shuffleDeckDecrypt = exports.shuffleDeckDecrypt = function shuffleDeckDecrypt(_ref3) {
var playerId = _ref3.playerId,
boxId = _ref3.boxId;
return function (dispatch, getState) {
var state = getState();
var key = _util.Box.addKey(state.game.boxes[boxId], state.client.keys, playerId);
dispatch({
type: SHUFFLE_DECK_DECRYPT,
boxId: boxId,
playerId: playerId,
key: key
});
};
};
exports.shuffleDeckDecrypt = shuffleDeckDecrypt;
var shuffleDeckReducer = exports.shuffleDeckReducer = function shuffleDeckReducer(state, action) {
const shuffleDeckReducer = (state, action) => {
if (action.type === SHUFFLE_DECK) {
var encryptOrder = (0, _util.rotateArray)(state.game.playerOrder, action.playerId);
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
nextActions: [].concat(_toConsumableArray(encryptOrder.map(function (playerId) {
const encryptOrder = (0, _util.rotateArray)(state.game.playerOrder, action.playerId);
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
nextActions: [...encryptOrder.map(playerId => {
return {
playerId: playerId,
playerId,
action: {

@@ -139,3 +89,29 @@ type: SHUFFLE_DECK_ENCRYPT,

};
})), _toConsumableArray(state.game.nextActions))
}), ...state.game.nextActions],
queue: [...encryptOrder.map(playerId => (0, _util.makeSchema)({
type: SHUFFLE_DECK_ENCRYPT,
agent: playerId,
playerId: action.playerId,
seed: {
type: "string"
},
boxes: {
type: "object",
minProperties: state.game.players[action.playerId].deck.length,
maxProperties: state.game.players[action.playerId].deck.length,
additionalProperties: {
type: "object",
properties: {
contents: {
type: "string"
},
keys: {
[playerId]: {
type: "string"
}
}
}
}
}
})), ...state.game.queue]
})

@@ -146,13 +122,18 @@ });

if (action.type === SHUFFLE_DECK_ENCRYPT) {
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
players: Object.assign({}, state.game.players, _defineProperty({}, action.playerId, Object.assign({}, state.game.players[action.playerId], {
deck: action.deck
}))),
boxes: action.deck.reduce(function (boxes, boxId) {
return Object.assign({}, boxes, _defineProperty({}, boxId, {
const localRando = new _util.RandomUtil(action.seed);
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
players: _objectSpread({}, state.game.players, {
[action.playerId]: _objectSpread({}, state.game.players[action.playerId], {
deck: localRando.shuffle(Object.keys(action.boxes))
})
}),
boxes: Object.keys(action.boxes).reduce((boxes, boxId) => _objectSpread({}, boxes, {
[boxId]: {
contents: action.boxes[boxId].contents,
keys: _defineProperty({}, action._sender, action.boxes[boxId].keys[action._sender])
}));
}, state.game.boxes)
keys: {
[action.agent]: action.boxes[boxId].keys[action.agent]
}
}
}), state.game.boxes)
})

@@ -163,8 +144,12 @@ });

if (action.type === SHUFFLE_DECK_DECRYPT) {
var box = state.game.boxes[action.boxId];
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
boxes: Object.assign({}, state.game.boxes, _defineProperty({}, action.boxId, Object.assign({}, box, {
keys: Object.assign({}, box.keys, _defineProperty({}, action.playerId, action.key))
})))
const box = state.game.boxes[action.boxId];
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
boxes: _objectSpread({}, state.game.boxes, {
[action.boxId]: _objectSpread({}, box, {
keys: _objectSpread({}, box.keys, {
[action.playerId]: action.key
})
})
})
})

@@ -176,2 +161,4 @@ });

};
exports.shuffleDeckReducer = shuffleDeckReducer;
//# sourceMappingURL=shuffle-deck.js.map

@@ -12,6 +12,15 @@ "use strict";

exports.getStandardEmoji = getStandardEmoji;
exports.onSummonRandomDamage = exports.onSummonDamageOwnHero = exports.onSummonBounce = exports.onSummonSummon = void 0;
var _util = require("@cardcore/util");
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
// emoji, attack, health, name, text, onSummon
var emojis = ["πŸ˜€", "πŸ˜ƒ", "πŸ˜„", "😁", "πŸ˜†", "πŸ˜…", "πŸ˜‚", "🀣", "☺️", "😊"];
const emojis = ["πŸ˜€", "πŸ˜ƒ", "πŸ˜„", "😁", "πŸ˜†", "πŸ˜…", "πŸ˜‚", "🀣", "☺️", "😊"];
function standard(cost) {
var emoji = emojis[cost] || emojis[emojis.length - 1];
const emoji = emojis[cost] || emojis[emojis.length - 1];
return {

@@ -23,33 +32,40 @@ cost: cost,

type: "creature",
name: "Standard " + cost + "-" + cost,
text: "",
onSummon: [],
onDeath: [],
onEndOfTurn: [],
onStartOfTurn: [],
onSpellCast: [],
onCreatureEntersField: []
name: `Standard ${cost}-${cost}`,
text: [],
onSummon: []
};
}
var onSummonSummon = exports.onSummonSummon = Object.assign({}, standard(2), {
const onSummonSummon = _objectSpread({}, standard(2), {
emoji: "",
name: "Summon Dude",
text: "onSummon: summon a 1/1 creature",
text: ["onSummon: summon a 1/1 creature"],
onSummon: [{
type: "SUMMON_CREATURE",
unit: standard(1),
target: { playerId: "SELF" }
target: {
playerId: "SELF"
}
}]
});
var onSummonBounce = exports.onSummonBounce = Object.assign({}, standard(1), {
exports.onSummonSummon = onSummonSummon;
const onSummonBounce = _objectSpread({}, standard(1), {
emoji: "",
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: [{
type: "BOUNCE",
target: { type: "creature", count: 1, location: "field", player: "self" }
target: {
type: "creature",
count: 1,
location: "field",
player: "self"
}
}]
});
exports.onSummonBounce = onSummonBounce;
function threeMaster(cost) {

@@ -63,11 +79,17 @@ return {

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: [{
type: "CHANGE_ATTACK",
value: 3,
target: { type: "creature", location: "field" }
target: {
type: "creature",
location: "field"
}
}, {
type: "CHANGE_HEALTH",
value: 3,
target: { type: "creature", location: "field" }
target: {
type: "creature",
location: "field"
}
}]

@@ -85,7 +107,9 @@ };

name: "Card Drawer",
text: "onSummon: draw a card",
text: [`onSummon: draw a card`],
onSummon: [{
type: "DRAW_CARD",
value: 1,
target: { player: "self" }
target: {
player: "self"
}
}]

@@ -95,3 +119,3 @@ };

var onSummonDamageOwnHero = exports.onSummonDamageOwnHero = Object.assign({}, standard(1), {
const onSummonDamageOwnHero = _objectSpread({}, standard(1), {
emoji: "",

@@ -101,10 +125,15 @@ attack: 3,

name: "Owner Damager",
text: "onSummon: Deal 3 damage to your hero",
text: [`onSummon: Deal 3 damage to your hero`],
onSummon: [{
type: "DAMAGE",
value: 3,
target: { type: "face", player: "self" }
target: {
type: "face",
player: "self"
}
}]
});
exports.onSummonDamageOwnHero = onSummonDamageOwnHero;
function damageCreature(cost) {

@@ -118,15 +147,27 @@ return {

name: "Creature Damager",
text: "onSummon: deal 1 damage to three target creatures",
text: [`onSummon: deal 1 damage to three target creatures`],
onSummon: [{
type: "DAMAGE",
value: 1,
target: { type: "creature", count: 1, location: "field" }
target: {
type: "creature",
count: 1,
location: "field"
}
}, {
type: "DAMAGE",
value: 1,
target: { type: "creature", count: 1, location: "field" }
target: {
type: "creature",
count: 1,
location: "field"
}
}, {
type: "DAMAGE",
value: 1,
target: { type: "creature", count: 1, location: "field" }
target: {
type: "creature",
count: 1,
location: "field"
}
}]

@@ -136,20 +177,37 @@ };

var onSummonRandomDamage = exports.onSummonRandomDamage = Object.assign({}, standard(2), {
const onSummonRandomDamage = _objectSpread({}, standard(2), {
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: [{
type: "DAMAGE",
value: 1,
target: { type: "creature", count: 1, location: "field", random: true }
target: {
type: "creature",
count: 1,
location: "field",
random: true
}
}, {
type: "DAMAGE",
value: 1,
target: { type: "creature", count: 1, location: "field", random: true }
target: {
type: "creature",
count: 1,
location: "field",
random: true
}
}, {
type: "DAMAGE",
value: 1,
target: { type: "creature", count: 1, location: "field", random: true }
target: {
type: "creature",
count: 1,
location: "field",
random: true
}
}]
});
exports.onSummonRandomDamage = onSummonRandomDamage;
function getStandardDeck() {

@@ -156,0 +214,0 @@ return [standard(1), standard(2), standard(3), threeMaster(3), cardDraw(2), damageCreature(4), onSummonSummon, onSummonBounce, onSummonRandomDamage, onSummonDamageOwnHero];

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

});
exports.createGame = exports.CREATE_GAME = exports.START_GAME = exports.ORDER_PLAYERS = exports.JOIN_GAME = undefined;
exports.startGameReducer = startGameReducer;
exports.createGame = exports.CREATE_GAME = exports.START_GAME = exports.ORDER_PLAYERS = exports.JOIN_GAME = void 0;

@@ -22,11 +22,16 @@ var _seedRng = require("./seed-rng");

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
const JOIN_GAME = "JOIN_GAME";
exports.JOIN_GAME = JOIN_GAME;
const ORDER_PLAYERS = "ORDER_PLAYERS";
exports.ORDER_PLAYERS = ORDER_PLAYERS;
const START_GAME = "START_GAME";
exports.START_GAME = START_GAME;
const CREATE_GAME = "CREATE_GAME";
exports.CREATE_GAME = CREATE_GAME;
var JOIN_GAME = exports.JOIN_GAME = "JOIN_GAME";
var ORDER_PLAYERS = exports.ORDER_PLAYERS = "ORDER_PLAYERS";
var START_GAME = exports.START_GAME = "START_GAME";
var CREATE_GAME = exports.CREATE_GAME = "CREATE_GAME";
var createGame = exports.createGame = function createGame() {
const createGame = () => {
return {

@@ -38,3 +43,4 @@ type: CREATE_GAME,

var INITIAL_PLAYER = {
exports.createGame = createGame;
const INITIAL_PLAYER = {
mana: 0,

@@ -49,7 +55,66 @@ availableMana: 0,

function startGameReducer(state, action) {
// initialization
// On this one, clear out both the nextActions queue and the players list... this is the first
// person joining. Everyone else joins with JOIN_GAME
if (action.type === CREATE_GAME) {
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
startTime: action.startTime,
queue: [(0, _util.makeSchema)({
type: {
enum: [JOIN_GAME]
},
agent: {
type: "string",
not: {
enum: [action.agent]
}
}
})],
nextActions: [{
action: {
type: JOIN_GAME
},
// lol lol lol hack hack hack
notPlayerId: action.agent
}],
allowedActions: {},
playerOrder: [],
params: {
startDraw: 3
},
started: false,
players: {
[action.agent]: {}
},
units: {},
randoSeeds: {},
prev: null,
boxes: {}
})
});
}
if (action.type === JOIN_GAME) {
var lexicalPlayers = [].concat(_toConsumableArray(Object.keys(state.game.players)), [action._sender]).sort();
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
players: Object.assign({}, state.game.players, _defineProperty({}, action._sender, {})),
let lexicalPlayers = [...Object.keys(state.game.players), action.agent].sort();
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
players: _objectSpread({}, state.game.players, {
[action.agent]: {}
}),
queue: [...state.game.queue, (0, _util.makeSchema)({
type: {
enum: [_seedRng.SEED_RNG]
},
agent: {
enum: [lexicalPlayers[0]]
}
}), (0, _util.makeSchema)({
type: {
enum: [ORDER_PLAYERS]
},
agent: {
enum: [lexicalPlayers[0]]
}
})],
nextActions: [{

@@ -71,13 +136,14 @@ playerId: lexicalPlayers[0],

if (action.type === ORDER_PLAYERS) {
var playerOrder = _util.rando.shuffle(Object.keys(state.game.players).sort());
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
const playerOrder = _util.rando.shuffle(Object.keys(state.game.players).sort());
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
playerOrder: playerOrder,
turn: playerOrder[0],
nextActions: [].concat(_toConsumableArray(playerOrder.map(function (playerId) {
return {
playerId: playerId,
action: { type: START_GAME }
};
})), [{
nextActions: [...playerOrder.map(playerId => ({
playerId,
action: {
type: START_GAME
}
})), {
playerId: playerOrder[0],

@@ -87,3 +153,18 @@ action: {

}
}], _toConsumableArray(state.game.nextActions))
}, ...state.game.nextActions],
queue: [...playerOrder.map(playerId => (0, _util.makeSchema)({
type: {
enum: [START_GAME]
},
agent: {
enum: [playerId]
}
})), (0, _util.makeSchema)({
type: {
enum: [_turns.START_TURN]
},
agent: {
enum: [playerOrder[0]]
}
}), ...state.game.queue]
})

@@ -94,8 +175,8 @@ });

if (action.type === START_GAME) {
var _playerOrder = state.game.playerOrder;
var newUnits = {};
var playerUnitId = (0, _util.uid)();
var deck = [];
const playerOrder = state.game.playerOrder;
const newUnits = {};
const playerUnitId = (0, _util.uid)();
const deck = [];
newUnits[playerUnitId] = {
emoji: (0, _standard.getStandardEmoji)()[_playerOrder.indexOf(action._sender)],
emoji: (0, _standard.getStandardEmoji)()[playerOrder.indexOf(action.agent)],
health: 30,

@@ -105,53 +186,51 @@ attack: 0,

};
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = (0, _standard.getStandardDeck)()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var card = _step.value;
var id = (0, _util.uid)();
newUnits[id] = Object.assign({}, card);
deck.push(id);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
for (const card of (0, _standard.getStandardDeck)()) {
const id = (0, _util.uid)();
newUnits[id] = _objectSpread({}, card);
deck.push(id);
}
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
units: Object.assign({}, state.game.units, newUnits),
players: Object.assign({}, state.game.players, _defineProperty({}, action._sender, Object.assign({}, INITIAL_PLAYER, {
unitId: playerUnitId,
deck: deck
}))),
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
units: _objectSpread({}, state.game.units, newUnits),
players: _objectSpread({}, state.game.players, {
[action.agent]: _objectSpread({}, INITIAL_PLAYER, {
unitId: playerUnitId,
deck
})
}),
nextActions: [{
playerId: action._sender,
playerId: action.agent,
action: {
type: _shuffleDeck.SHUFFLE_DECK,
playerId: action._sender
playerId: action.agent
}
}].concat(_toConsumableArray((0, _util.range)(state.game.params.startDraw).map(function () {
return {
playerId: action._sender,
action: {
type: _drawCard.DRAW_CARD,
target: {
player: action._sender
}, ...(0, _util.range)(state.game.params.startDraw).map(() => ({
playerId: action.agent,
action: {
type: _drawCard.DRAW_CARD,
target: {
player: action.agent
}
}
})), ...state.game.nextActions],
queue: [(0, _util.makeSchema)({
type: _shuffleDeck.SHUFFLE_DECK,
agent: action.agent,
playerId: action.agent
}), ...(0, _util.range)(state.game.params.startDraw).map(() => (0, _util.makeSchema)({
type: _drawCard.DRAW_CARD,
agent: action.agent,
target: {
type: "object",
additionalProperties: false,
required: ["player"],
properties: {
player: {
enum: [action.agent]
}
}
};
})), _toConsumableArray(state.game.nextActions))
}
})), ...state.game.queue]
})

@@ -158,0 +237,0 @@ });

@@ -6,29 +6,35 @@ "use strict";

});
exports.summonCreatureReducer = exports.SUMMON_CREATURE = undefined;
exports.summonCreatureReducer = exports.SUMMON_CREATURE = void 0;
var _util = require("@cardcore/util");
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
const SUMMON_CREATURE = "SUMMON_CREATURE";
exports.SUMMON_CREATURE = SUMMON_CREATURE;
var SUMMON_CREATURE = exports.SUMMON_CREATURE = "SUMMON_CREATURE";
var summonCreatureReducer = exports.summonCreatureReducer = function summonCreatureReducer(state, action) {
const summonCreatureReducer = (state, action) => {
if (action.type === SUMMON_CREATURE) {
var playerUnitId = (0, _util.uid)();
var newUnit = {};
var player = state.game.players[state.game.turn];
newUnit[playerUnitId] = Object.assign({}, action.unit);
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
players: Object.assign({}, state.game.players, _defineProperty({}, state.game.turn, Object.assign({}, player, {
field: [].concat(_toConsumableArray(player.field), [playerUnitId])
}))),
units: Object.assign({}, state.game.units, newUnit)
const playerUnitId = (0, _util.uid)();
const newUnit = {};
const player = state.game.players[state.game.turn];
newUnit[playerUnitId] = _objectSpread({}, action.unit);
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
players: _objectSpread({}, state.game.players, {
[state.game.turn]: _objectSpread({}, player, {
field: [...player.field, playerUnitId]
})
}),
units: _objectSpread({}, state.game.units, newUnit)
})
});
}
return state;
};
exports.summonCreatureReducer = summonCreatureReducer;
//# sourceMappingURL=summon-creature.js.map

@@ -6,10 +6,7 @@ "use strict";

});
exports.endTurn = exports.END_TURN = exports.startTurn = exports.START_TURN = undefined;
exports.turnReducer = turnReducer;
exports.endTurn = exports.END_TURN = exports.startTurn = exports.START_TURN = void 0;
var _regenerator = require("babel-runtime/regenerator");
var _util = require("@cardcore/util");
var _regenerator2 = _interopRequireDefault(_regenerator);
exports.turnReducer = turnReducer;
var _drawCard = require("./draw-card");

@@ -19,67 +16,36 @@

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _standardAction = require("./standard-action");
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
const START_TURN = "START_TURN";
exports.START_TURN = START_TURN;
var START_TURN = exports.START_TURN = "START_TURN";
var startTurn = exports.startTurn = function startTurn() {
return function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee(dispatch) {
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return dispatch({ type: START_TURN });
const startTurn = () => async dispatch => {
await dispatch({
type: START_TURN
});
};
case 2:
case "end":
return _context.stop();
}
}
}, _callee, undefined);
}));
exports.startTurn = startTurn;
const END_TURN = "END_TURN";
exports.END_TURN = END_TURN;
return function (_x) {
return _ref.apply(this, arguments);
};
}();
const endTurn = () => async dispatch => {
await dispatch({
type: END_TURN
});
};
var END_TURN = exports.END_TURN = "END_TURN";
var endTurn = exports.endTurn = function endTurn() {
return function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee2(dispatch) {
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return dispatch({
type: END_TURN
});
exports.endTurn = endTurn;
case 2:
case "end":
return _context2.stop();
}
}
}, _callee2, undefined);
}));
return function (_x2) {
return _ref2.apply(this, arguments);
};
}();
};
function turnReducer(state, action) {
if (action.type === _startGame.START_GAME) {
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
allowedActions: Object.assign({}, state.game.allowedActions, _defineProperty({}, END_TURN, true))
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
allowedActions: _objectSpread({}, state.game.allowedActions, {
[END_TURN]: true
})
})

@@ -90,4 +56,4 @@ });

if (action.type === START_TURN) {
var player = state.game.players[state.game.turn];
var newMana = player.mana + 1;
const player = state.game.players[state.game.turn];
let newMana = player.mana + 1;

@@ -97,19 +63,51 @@ if (newMana > 10) {

}
var newUnits = {};
player.field.forEach(function (unitId) {
newUnits[unitId] = Object.assign({}, state.game.units[unitId], {
const newUnits = {};
player.field.forEach(boxId => {
const unitId = _util.Box.traverse(state, boxId);
newUnits[unitId] = _objectSpread({}, state.game.units[unitId], {
canAttack: true
});
});
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
units: Object.assign({}, state.game.units, newUnits),
players: Object.assign({}, state.game.players, _defineProperty({}, state.game.turn, Object.assign({}, player, {
mana: newMana,
availableMana: newMana
}))),
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
units: _objectSpread({}, state.game.units, newUnits),
players: _objectSpread({}, state.game.players, {
[state.game.turn]: _objectSpread({}, player, {
mana: newMana,
availableMana: newMana
})
}),
nextActions: [{
playerId: state.game.turn,
action: { type: _drawCard.DRAW_CARD, target: { player: state.game.turn } }
}].concat(_toConsumableArray(state.game.nextActions))
action: {
type: _drawCard.DRAW_CARD,
target: {
player: state.game.turn
}
}
}, {
playerId: state.game.turn,
action: {
type: _standardAction.STANDARD_ACTION
}
}, ...state.game.nextActions],
queue: [(0, _util.makeSchema)({
type: _drawCard.DRAW_CARD,
agent: state.game.turn,
target: {
type: "object",
additionalProperties: false,
required: ["player"],
properties: {
player: {
enum: [state.game.turn]
}
}
}
}), (0, _util.makeSchema)({
type: _standardAction.STANDARD_ACTION,
agent: state.game.turn
}), ...state.game.queue]
})

@@ -120,13 +118,17 @@ });

if (action.type === END_TURN) {
var playerIdx = (state.game.playerOrder.indexOf(state.game.turn) + 1) % state.game.playerOrder.length;
var playerId = state.game.playerOrder[playerIdx];
return Object.assign({}, state, {
game: Object.assign({}, state.game, {
const playerIdx = (state.game.playerOrder.indexOf(state.game.turn) + 1) % state.game.playerOrder.length;
const playerId = state.game.playerOrder[playerIdx];
return _objectSpread({}, state, {
game: _objectSpread({}, state.game, {
turn: playerId,
nextActions: [{
playerId: playerId,
playerId,
action: {
type: START_TURN
}
}]
}],
queue: [(0, _util.makeSchema)({
type: START_TURN,
agent: playerId
})]
})

@@ -133,0 +135,0 @@ });

{
"name": "@cardcore/game",
"version": "0.0.1-4a0572cd",
"version": "0.0.1-4baabe2b",
"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-4baabe2b",
"@streamplace/ssb-keys": "7.0.21",
"babel-runtime": "^6.26.0"
},
"gitHead": "4a0572cd286ae86d011a80c5b81ac8fcfe50072b"
"gitHead": "4baabe2b946b8f0ee3d12e4c114241cc1cade664"
}
import { CHECK_DEATH } from "./check-death";
import { START_GAME } from "./start-game";
import { STANDARD_ACTION } from "./standard-action";
import { makeSchema } from "@cardcore/util";

@@ -49,7 +51,25 @@ export const ATTACK = "ATTACK";

{
playerId: action._sender,
playerId: action.agent,
action: {
type: CHECK_DEATH
}
}
},
{
playerId: action.agent,
action: {
type: STANDARD_ACTION
}
},
...state.game.nextActions
],
queue: [
makeSchema({
type: CHECK_DEATH,
agent: action.agent
}),
makeSchema({
type: STANDARD_ACTION,
agent: action.agent
}),
...state.game.queue
]

@@ -56,0 +76,0 @@ }

@@ -34,2 +34,10 @@ import { targetArray } from "@cardcore/util";

...state.game.nextActions
],
queue: [
...targets.map(target => ({
action: BOUNCE_ENCRYPT,
agent: target.playerId,
unitId: target.unitId
})),
...state.game.queue
]

@@ -40,3 +48,3 @@ }

if (action.type === BOUNCE_ENCRYPT) {
const player = state.game.players[action._sender];
const player = state.game.players[action.agent];
return {

@@ -48,3 +56,3 @@ ...state,

...state.game.players,
[action._sender]: {
[action.agent]: {
...player,

@@ -51,0 +59,0 @@ hand: [...player.hand, action.unitId],

@@ -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,

import { SHUFFLE_DECK_DECRYPT } from "./shuffle-deck";
import { makeSchema } from "@cardcore/util";
export const DRAW_CARD = "DRAW_CARD";

@@ -64,2 +65,14 @@

...state.game.nextActions
],
queue: [
makeSchema({
type: SHUFFLE_DECK_DECRYPT,
agent: Object.keys(state.game.boxes[boxId].keys).sort()[0],
boxId: boxId,
playerId,
key: {
type: "string"
}
}),
...state.game.queue
]

@@ -66,0 +79,0 @@ }

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

@@ -12,2 +13,3 @@ export * from "./check-death";

export * from "./shuffle-deck";
export * from "./standard-action";
export * from "./start-game";

@@ -17,38 +19,3 @@ export * from "./summon-creature";

import { CREATE_GAME, JOIN_GAME } from "./start-game";
export const gameReducer = (state, action) => {
// initialization
// On this one, clear out both the nextActions queue and the players list... this is the first
// person joining. Everyone else joins with JOIN_GAME
if (action.type === CREATE_GAME) {
return {
...state,
game: {
...state.game,
startTime: action.startTime,
nextActions: [
{
action: { type: JOIN_GAME },
// lol lol lol hack hack hack
notPlayerId: action._sender
}
],
allowedActions: {},
playerOrder: [],
params: {
startDraw: 3
},
started: false,
players: {
[action._sender]: {}
},
units: {},
randoSeeds: {},
prev: null,
boxes: {}
}
};
}
if (action.prev) {

@@ -55,0 +22,0 @@ return {

@@ -1,4 +0,5 @@

import { Box, getLeftPlayer } from "@cardcore/util";
import { Box, getLeftPlayer, makeSchema, target } from "@cardcore/util";
import { PLAY_CREATURE } from "./play-creature";
import { START_GAME } from "./start-game";
import { STANDARD_ACTION } from "./standard-action";

@@ -11,8 +12,7 @@ export const PLAY_CARD = "PLAY_CARD";

export const PLAY_CARD_DONE = "PLAY_CARD_DONE";
export const REVEAL_CARD = "REVEAL_CARD";
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({

@@ -44,13 +44,31 @@ type: "REVEAL_CARD",

{
playerId: action._sender,
playerId: action.agent,
action: {
type: PLAY_CREATURE,
type: PLAY_CARD_DONE,
boxId: action.boxId
}
},
{
playerId: action.agent,
action: {
type: STANDARD_ACTION
}
}
];
let queue = [
...state.game.queue,
makeSchema({
type: PLAY_CARD_DONE,
agent: action.agent,
boxId: action.boxId
}),
makeSchema({
type: STANDARD_ACTION,
agent: action.agent
})
];
if (!state.game.units[action.boxId]) {
nextActions = [
{
playerId: getLeftPlayer(action._sender, state.game.playerOrder),
playerId: getLeftPlayer(action.agent, state.game.playerOrder),
action: {

@@ -63,2 +81,13 @@ type: REVEAL_CARD,

];
queue = [
makeSchema({
type: REVEAL_CARD,
agent: getLeftPlayer(action.agent, state.game.playerOrder),
boxId: action.boxId,
privateKey: {
type: "string"
}
}),
...queue
];
}

@@ -69,3 +98,4 @@ return {

...state.game,
nextActions: nextActions
nextActions: nextActions,
queue: queue
}

@@ -75,2 +105,52 @@ };

if (action.type === PLAY_CARD_DONE) {
// If we get here, we should know the contents...
const cardId = Box.traverse(state, action.boxId);
const card = state.game.units[cardId];
return {
...state,
game: {
...state.game,
nextActions: [
{
playerId: action.agent,
action: {
type: PLAY_CREATURE,
boxId: action.boxId
}
},
...state.game.nextActions
],
queue: [
makeSchema({
type: PLAY_CREATURE,
agent: action.agent,
boxId: action.boxId,
targets: {
type: "array",
minItems: card.onSummon.length,
maxItems: card.onSummon.length,
items: card.onSummon.map(onSummon => {
if (onSummon.target.count === undefined) {
return { enum: [null] };
}
if (onSummon.target.random) {
return { enum: [null] };
}
const targets = Object.keys(
target(state, onSummon.target)
).sort();
if (targets.length > 0) {
return { enum: targets };
}
return { enum: [null] };
})
}
}),
...state.game.queue
]
}
};
}
if (action.type === REVEAL_CARD) {

@@ -82,9 +162,20 @@ const box = state.game.boxes[action.boxId];

};
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
let nextActions = state.game.nextActions;
let queue = state.game.queue;
if (state.game.boxes[contents]) {
nextActions = [
{
playerId: getLeftPlayer(action._sender, state.game.playerOrder),
playerId: getLeftPlayer(action.agent, state.game.playerOrder),
action: {

@@ -97,2 +188,13 @@ type: REVEAL_CARD,

];
queue = [
makeSchema({
type: REVEAL_CARD,
agent: getLeftPlayer(action.agent, state.game.playerOrder),
boxId: contents,
privateKey: {
type: "string"
}
}),
...queue
];
} else if (!state.game.units[contents]) {

@@ -105,7 +207,4 @@ throw new Error(`invalid card: ${contents}`);

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

@@ -112,0 +211,0 @@ };

import { SEED_RNG } from "./seed-rng";
import { CHECK_DEATH } from "./check-death";
import { target, Box } from "@cardcore/util";
import { target, Box, makeSchema } from "@cardcore/util";
import { START_GAME } from "./start-game";

@@ -18,5 +18,5 @@

if (action.type === PLAY_CREATURE) {
const player = state.game.players[action._sender];
const player = state.game.players[action.agent];
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];

@@ -29,7 +29,7 @@ return {

...state.game.players,
[action._sender]: {
[action.agent]: {
...player,
availableMana: player.availableMana - unit.cost,
hand: player.hand.filter(c => c !== boxId),
field: [unitId, ...player.field]
field: [boxId, ...player.field]
}

@@ -40,3 +40,3 @@ },

{
playerId: action._sender,
playerId: action.agent,
action: {

@@ -48,5 +48,3 @@ type: SEED_RNG

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

@@ -58,17 +56,76 @@ }

return {
playerId: action._sender,
playerId: action.agent,
action: {
...onSummon,
target: {
...onSummon.target,
unitId: onSummon.target.random
? undefined
: action.targets[i]
},
unitId: unitId
target: JSON.parse(
JSON.stringify({
...onSummon.target,
unitId: onSummon.target.random
? undefined
: action.targets[i]
})
)
// unitId: unitId
}
};
}),
{ playerId: action._sender, action: { type: CHECK_DEATH } },
{ playerId: action.agent, action: { type: CHECK_DEATH } },
...state.game.nextActions
],
queue: [
makeSchema({
type: SEED_RNG,
agent: action.agent
}),
...unit.onSummon
.filter(
(onSummon, i) =>
Object.keys(target(state, onSummon.target)).length !== 0
)
.map((onSummon, i) => {
return makeSchema(
Object.keys(onSummon).reduce(
(schema, fieldName) => {
if (["type", "target"].includes(fieldName)) {
return schema;
}
return {
...schema,
[fieldName]: {
enum: [onSummon[fieldName]]
}
};
},
{
type: onSummon.type,
agent: action.agent,
target: {
type: "object",
additionalProperties: false,
properties: Object.keys(onSummon.target).reduce(
(props, field) => ({
...props,
[field]: {
enum: [onSummon.target[field]]
}
}),
// it's late, leave me alone
JSON.parse(
JSON.stringify({
unitId: onSummon.target.random
? undefined
: { enum: [action.targets[i]] }
})
)
)
}
}
)
);
}),
makeSchema({
type: CHECK_DEATH,
agent: action.agent
}),
...state.game.queue
]

@@ -75,0 +132,0 @@ }

import ssbKeys from "@streamplace/ssb-keys";
import { clientGenerateKey } from "@cardcore/client";
import { rando } from "@cardcore/util";
import { rando, Box, makeSchema } 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";

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

...state.game,
queue: [
makeSchema({
type: {
enum: [SEED_RNG_ENCRYPT]
},
agent: {
enum: [orderedPlayers[0]]
},
boxId: {
type: "string"
},
box: {
type: "object",
additionalProperties: false,
required: ["contents", "keys"],
properties: {
contents: {
type: "string"
},
keys: {
[orderedPlayers[0]]: {
type: "string"
}
}
}
}
}),
makeSchema({
type: {
enum: [SEED_RNG_COMBINE]
},
agent: {
enum: [action.agent]
}
}),
...state.game.queue
],
nextActions: [

@@ -51,2 +79,8 @@ {

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

@@ -64,10 +98,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.agent]: action.boxId
}

@@ -87,6 +120,26 @@ }

action: {
type: SEED_RNG_DECRYPT
type: BOX_OPEN,
boxId: state.game.randoSeeds[playerId]
}
})),
...state.game.nextActions
],
queue: [
...orderedPlayers.map(playerId =>
makeSchema({
type: {
enum: [BOX_OPEN]
},
agent: {
enum: [playerId]
},
boxId: {
enum: [state.game.randoSeeds[playerId]]
},
privateKey: {
type: "string"
}
})
),
...state.game.queue
]

@@ -109,3 +162,33 @@ }

},
...state.game.nextActions
],
queue: [
makeSchema({
type: {
enum: [SEED_RNG_ENCRYPT]
},
agent: {
enum: [orderedPlayers[seedCount]]
},
boxId: {
type: "string"
},
box: {
type: "object",
additionalProperties: false,
required: ["contents", "keys"],
properties: {
contents: {
type: "string"
},
keys: {
[orderedPlayers[seedCount]]: {
type: "string"
}
}
}
}
}),
...state.game.queue
]

@@ -117,34 +200,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("")
);
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);
rando.setSeed(finalSeed);

@@ -151,0 +210,0 @@ return {

import { rotateArray, shuffle } from "@cardcore/util";
import { Box } from "@cardcore/util";
import { Box, makeSchema, RandomUtil } from "@cardcore/util";
import ssbKeys from "@streamplace/ssb-keys";

@@ -15,7 +16,6 @@ export const SHUFFLE_DECK = "SHUFFLE_DECK";

const state = getState();
let encryptedDeck = [];
const seed = ssbKeys.generate().public;
const boxes = {};
for (const card of state.game.players[playerId].deck) {
const { boxId, box } = Box.new(card, state.client.keys.id);
encryptedDeck.push(boxId);
boxes[boxId] = box;

@@ -25,3 +25,3 @@ }

type: SHUFFLE_DECK_ENCRYPT,
deck: shuffle(encryptedDeck),
seed,
boxes,

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

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

@@ -67,2 +67,33 @@ type: SHUFFLE_DECK_DECRYPT,

...state.game.nextActions
],
queue: [
...encryptOrder.map(playerId =>
makeSchema({
type: SHUFFLE_DECK_ENCRYPT,
agent: playerId,
playerId: action.playerId,
seed: {
type: "string"
},
boxes: {
type: "object",
minProperties: state.game.players[action.playerId].deck.length,
maxProperties: state.game.players[action.playerId].deck.length,
additionalProperties: {
type: "object",
properties: {
contents: {
type: "string"
},
keys: {
[playerId]: {
type: "string"
}
}
}
}
}
})
),
...state.game.queue
]

@@ -74,2 +105,3 @@ }

if (action.type === SHUFFLE_DECK_ENCRYPT) {
const localRando = new RandomUtil(action.seed);
return {

@@ -83,6 +115,6 @@ ...state,

...state.game.players[action.playerId],
deck: action.deck
deck: localRando.shuffle(Object.keys(action.boxes))
}
},
boxes: action.deck.reduce(
boxes: Object.keys(action.boxes).reduce(
(boxes, boxId) => ({

@@ -93,3 +125,3 @@ ...boxes,

keys: {
[action._sender]: action.boxes[boxId].keys[action._sender]
[action.agent]: action.boxes[boxId].keys[action.agent]
}

@@ -96,0 +128,0 @@ }

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

import { makeSchema } from "@cardcore/util";
// emoji, attack, health, name, text, onSummon

@@ -12,9 +14,4 @@ const emojis = ["πŸ˜€", "πŸ˜ƒ", "πŸ˜„", "😁", "πŸ˜†", "πŸ˜…", "πŸ˜‚", "🀣", "☺️", "😊"];

name: `Standard ${cost}-${cost}`,
text: "",
onSummon: [],
onDeath: [],
onEndOfTurn: [],
onStartOfTurn: [],
onSpellCast: [],
onCreatureEntersField: []
text: [],
onSummon: []
};

@@ -27,3 +24,3 @@ }

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

@@ -42,3 +39,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 +56,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 +81,3 @@ {

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

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

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

@@ -121,3 +118,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 +143,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 +146,0 @@ {

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

import { getStandardDeck, getStandardEmoji } from "./standard";
import { rando, range, uid } from "@cardcore/util";
import { rando, range, uid, makeSchema } from "@cardcore/util";

@@ -30,6 +30,52 @@ export const JOIN_GAME = "JOIN_GAME";

export function startGameReducer(state, action) {
// initialization
// On this one, clear out both the nextActions queue and the players list... this is the first
// person joining. Everyone else joins with JOIN_GAME
if (action.type === CREATE_GAME) {
return {
...state,
game: {
...state.game,
startTime: action.startTime,
queue: [
makeSchema({
type: {
enum: [JOIN_GAME]
},
agent: {
type: "string",
not: {
enum: [action.agent]
}
}
})
],
nextActions: [
{
action: { type: JOIN_GAME },
// lol lol lol hack hack hack
notPlayerId: action.agent
}
],
allowedActions: {},
playerOrder: [],
params: {
startDraw: 3
},
started: false,
players: {
[action.agent]: {}
},
units: {},
randoSeeds: {},
prev: null,
boxes: {}
}
};
}
if (action.type === JOIN_GAME) {
let lexicalPlayers = [
...Object.keys(state.game.players),
action._sender
action.agent
].sort();

@@ -42,4 +88,23 @@ return {

...state.game.players,
[action._sender]: {}
[action.agent]: {}
},
queue: [
...state.game.queue,
makeSchema({
type: {
enum: [SEED_RNG]
},
agent: {
enum: [lexicalPlayers[0]]
}
}),
makeSchema({
type: {
enum: [ORDER_PLAYERS]
},
agent: {
enum: [lexicalPlayers[0]]
}
})
],
nextActions: [

@@ -83,2 +148,23 @@ {

...state.game.nextActions
],
queue: [
...playerOrder.map(playerId =>
makeSchema({
type: {
enum: [START_GAME]
},
agent: {
enum: [playerId]
}
})
),
makeSchema({
type: {
enum: [START_TURN]
},
agent: {
enum: [playerOrder[0]]
}
}),
...state.game.queue
]

@@ -95,3 +181,3 @@ }

newUnits[playerUnitId] = {
emoji: getStandardEmoji()[playerOrder.indexOf(action._sender)],
emoji: getStandardEmoji()[playerOrder.indexOf(action.agent)],
health: 30,

@@ -116,3 +202,3 @@ attack: 0,

...state.game.players,
[action._sender]: {
[action.agent]: {
...INITIAL_PLAYER,

@@ -125,14 +211,14 @@ unitId: playerUnitId,

{
playerId: action._sender,
playerId: action.agent,
action: {
type: SHUFFLE_DECK,
playerId: action._sender
playerId: action.agent
}
},
...range(state.game.params.startDraw).map(() => ({
playerId: action._sender,
playerId: action.agent,
action: {
type: DRAW_CARD,
target: {
player: action._sender
player: action.agent
}

@@ -142,2 +228,26 @@ }

...state.game.nextActions
],
queue: [
makeSchema({
type: SHUFFLE_DECK,
agent: action.agent,
playerId: action.agent
}),
...range(state.game.params.startDraw).map(() =>
makeSchema({
type: DRAW_CARD,
agent: action.agent,
target: {
type: "object",
additionalProperties: false,
required: ["player"],
properties: {
player: {
enum: [action.agent]
}
}
}
})
),
...state.game.queue
]

@@ -144,0 +254,0 @@ }

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

import { Box, makeSchema } from "@cardcore/util";
import { DRAW_CARD } from "./draw-card";
import { START_GAME } from "./start-game";
import { STANDARD_ACTION } from "./standard-action";

@@ -38,3 +40,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] = {

@@ -66,3 +69,28 @@ ...state.game.units[unitId],

},
{
playerId: state.game.turn,
action: { type: STANDARD_ACTION }
},
...state.game.nextActions
],
queue: [
makeSchema({
type: DRAW_CARD,
agent: state.game.turn,
target: {
type: "object",
additionalProperties: false,
required: ["player"],
properties: {
player: {
enum: [state.game.turn]
}
}
}
}),
makeSchema({
type: STANDARD_ACTION,
agent: state.game.turn
}),
...state.game.queue
]

@@ -90,2 +118,8 @@ }

}
],
queue: [
makeSchema({
type: START_TURN,
agent: playerId
})
]

@@ -92,0 +126,0 @@ }

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

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