@cardcore/game
Advanced tools
Comparing version 0.0.1-3ec581c3 to 0.0.1-84ee245d
@@ -14,4 +14,2 @@ "use strict"; | ||
var _client = require("@cardcore/client"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -37,4 +35,2 @@ | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee(dispatch, getState) { | ||
var _ref4, keys, card; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
@@ -44,20 +40,8 @@ while (1) { | ||
case 0: | ||
_context.next = 2; | ||
return dispatch((0, _client.clientGenerateKey)()); | ||
case 2: | ||
_ref4 = _context.sent; | ||
keys = _ref4.keys; | ||
_context.next = 6; | ||
return dispatch((0, _client.clientBox)(unitId, keys)); | ||
case 6: | ||
card = _context.sent; | ||
return _context.abrupt("return", dispatch({ | ||
type: "BOUNCE_ENCRYPT", | ||
unitId: unitId, | ||
card: card | ||
unitId: unitId | ||
})); | ||
case 8: | ||
case 1: | ||
case "end": | ||
@@ -98,3 +82,3 @@ return _context.stop(); | ||
players: Object.assign({}, state.game.players, _defineProperty({}, action._sender, Object.assign({}, player, { | ||
hand: [].concat(_toConsumableArray(player.hand), [action.card]), | ||
hand: [].concat(_toConsumableArray(player.hand), [action.unitId]), | ||
field: player.field.filter(function (unitId) { | ||
@@ -101,0 +85,0 @@ return unitId !== action.unitId; |
@@ -40,6 +40,6 @@ "use strict"; | ||
var player = state.game.players[playerId]; | ||
var unitId = player.deck[0]; | ||
if (!unitId) { | ||
var boxId = player.deck[0]; | ||
if (!boxId) { | ||
// fatigue | ||
state = Object.assign({}, state, { | ||
return Object.assign({}, state, { | ||
game: Object.assign({}, state.game, { | ||
@@ -54,26 +54,19 @@ units: Object.assign({}, state.game.units, _defineProperty({}, player.unitId, Object.assign({}, state.game.units[player.unitId], { | ||
}); | ||
} else { | ||
var newActions = []; | ||
if (unitId.secret && unitId.playerId !== playerId) { | ||
// card is encrypted by someone else, ask them to decrypt | ||
newActions.push({ | ||
playerId: unitId.playerId, | ||
} | ||
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 | ||
playerId: playerId, | ||
boxId: boxId | ||
} | ||
}); | ||
} else { | ||
throw new Error("who the butt encrypted this"); | ||
} | ||
state = Object.assign({}, state, { | ||
game: Object.assign({}, state.game, { | ||
players: Object.assign({}, state.game.players, _defineProperty({}, playerId, Object.assign({}, player, { | ||
hand: [unitId].concat(_toConsumableArray(player.hand)), | ||
deck: player.deck.slice(1) | ||
}))), | ||
nextActions: [].concat(newActions, _toConsumableArray(state.game.nextActions)) | ||
}) | ||
}); | ||
} | ||
}].concat(_toConsumableArray(state.game.nextActions)) | ||
}) | ||
}); | ||
} | ||
@@ -80,0 +73,0 @@ } catch (err) { |
@@ -92,2 +92,14 @@ "use strict"; | ||
var _playCard = require("./play-card"); | ||
Object.keys(_playCard).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _playCard[key]; | ||
} | ||
}); | ||
}); | ||
var _playCreature = require("./play-creature"); | ||
@@ -189,3 +201,4 @@ | ||
randoSeeds: {}, | ||
prev: null | ||
prev: null, | ||
boxes: {} | ||
} | ||
@@ -192,0 +205,0 @@ }); |
@@ -12,6 +12,2 @@ "use strict"; | ||
var _ssbKeys = require("@streamplace/ssb-keys"); | ||
var _ssbKeys2 = _interopRequireDefault(_ssbKeys); | ||
var _seedRng = require("./seed-rng"); | ||
@@ -27,6 +23,6 @@ | ||
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 _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"); }); }; } | ||
@@ -36,8 +32,6 @@ | ||
var playCreature = exports.playCreature = function playCreature(_ref) { | ||
var id = _ref.id, | ||
privateKey = _ref.privateKey, | ||
_ref$targets = _ref.targets, | ||
targets = _ref$targets === undefined ? [] : _ref$targets; | ||
var boxId = _ref.boxId; | ||
return function () { | ||
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee(dispatch) { | ||
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee(dispatch, getState) { | ||
var targets; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
@@ -47,7 +41,7 @@ while (1) { | ||
case 0: | ||
_context.next = 2; | ||
return dispatch({ | ||
targets = getState().client.targets; | ||
dispatch({ | ||
type: PLAY_CREATURE, | ||
id: id, | ||
privateKey: privateKey, | ||
boxId: boxId, | ||
targets: targets | ||
@@ -64,3 +58,3 @@ }); | ||
return function (_x) { | ||
return function (_x, _x2) { | ||
return _ref2.apply(this, arguments); | ||
@@ -72,16 +66,6 @@ }; | ||
var playCreatureReducer = exports.playCreatureReducer = function playCreatureReducer(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_CREATURE, true)) | ||
}) | ||
}); | ||
} | ||
if (action.type === PLAY_CREATURE) { | ||
var player = state.game.players[action._sender]; | ||
var card = player.hand.filter(function (card) { | ||
return card.id === action.id; | ||
})[0]; | ||
var unitId = _ssbKeys2.default.unbox(card.box, { private: action.privateKey }); | ||
var boxId = action.boxId; | ||
var unitId = _util.Box.traverse(boxId, state.game.boxes, state.client.keys); | ||
var unit = state.game.units[unitId]; | ||
@@ -93,3 +77,3 @@ return Object.assign({}, state, { | ||
hand: player.hand.filter(function (c) { | ||
return c !== card; | ||
return c !== boxId; | ||
}), | ||
@@ -96,0 +80,0 @@ field: [unitId].concat(_toConsumableArray(player.field)) |
@@ -14,8 +14,2 @@ "use strict"; | ||
var _client = require("@cardcore/client"); | ||
var _ssbKeys = require("@streamplace/ssb-keys"); | ||
var _ssbKeys2 = _interopRequireDefault(_ssbKeys); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -39,3 +33,3 @@ | ||
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee(dispatch, getState) { | ||
var encryptedDeck, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, card, _ref3, keys; | ||
var state, encryptedDeck, boxes, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, card, _Box$new, boxId, box; | ||
@@ -46,49 +40,29 @@ return _regenerator2.default.wrap(function _callee$(_context) { | ||
case 0: | ||
state = getState(); | ||
encryptedDeck = []; | ||
boxes = {}; | ||
_iteratorNormalCompletion = true; | ||
_didIteratorError = false; | ||
_iteratorError = undefined; | ||
_context.prev = 4; | ||
_iterator = getState().game.players[playerId].deck[Symbol.iterator](); | ||
_context.prev = 6; | ||
case 6: | ||
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) { | ||
_context.next = 20; | ||
break; | ||
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; | ||
encryptedDeck.push(boxId); | ||
boxes[boxId] = box; | ||
} | ||
_context.next = 14; | ||
break; | ||
card = _step.value; | ||
_context.next = 10; | ||
return dispatch((0, _client.clientGenerateKey)()); | ||
case 10: | ||
_ref3 = _context.sent; | ||
keys = _ref3.keys; | ||
_context.t0 = encryptedDeck; | ||
_context.next = 15; | ||
return dispatch((0, _client.clientBox)(card, keys)); | ||
case 15: | ||
_context.t1 = _context.sent; | ||
_context.t0.push.call(_context.t0, _context.t1); | ||
case 17: | ||
_iteratorNormalCompletion = true; | ||
_context.next = 6; | ||
break; | ||
case 20: | ||
_context.next = 26; | ||
break; | ||
case 22: | ||
_context.prev = 22; | ||
_context.t2 = _context["catch"](4); | ||
_context.prev = 10; | ||
_context.t0 = _context["catch"](6); | ||
_didIteratorError = true; | ||
_iteratorError = _context.t2; | ||
_iteratorError = _context.t0; | ||
case 26: | ||
_context.prev = 26; | ||
_context.prev = 27; | ||
case 14: | ||
_context.prev = 14; | ||
_context.prev = 15; | ||
@@ -99,7 +73,7 @@ if (!_iteratorNormalCompletion && _iterator.return) { | ||
case 29: | ||
_context.prev = 29; | ||
case 17: | ||
_context.prev = 17; | ||
if (!_didIteratorError) { | ||
_context.next = 32; | ||
_context.next = 20; | ||
break; | ||
@@ -110,16 +84,17 @@ } | ||
case 32: | ||
return _context.finish(29); | ||
case 20: | ||
return _context.finish(17); | ||
case 33: | ||
return _context.finish(26); | ||
case 21: | ||
return _context.finish(14); | ||
case 34: | ||
case 22: | ||
return _context.abrupt("return", dispatch({ | ||
type: SHUFFLE_DECK_ENCRYPT, | ||
deck: (0, _util.shuffle)(encryptedDeck), | ||
boxes: boxes, | ||
playerId: playerId | ||
})); | ||
case 35: | ||
case 23: | ||
case "end": | ||
@@ -129,3 +104,3 @@ return _context.stop(); | ||
} | ||
}, _callee, undefined, [[4, 22, 26, 34], [27,, 29, 33]]); | ||
}, _callee, undefined, [[6, 10, 14, 22], [15,, 17, 21]]); | ||
})); | ||
@@ -141,12 +116,13 @@ | ||
var SHUFFLE_DECK_DECRYPT = exports.SHUFFLE_DECK_DECRYPT = "SHUFFLE_DECK_DECRYPT"; | ||
var shuffleDeckDecrypt = exports.shuffleDeckDecrypt = function shuffleDeckDecrypt(_ref4) { | ||
var playerId = _ref4.playerId; | ||
var shuffleDeckDecrypt = exports.shuffleDeckDecrypt = function shuffleDeckDecrypt(_ref3) { | ||
var playerId = _ref3.playerId, | ||
boxId = _ref3.boxId; | ||
return function (dispatch, getState) { | ||
var state = getState(); | ||
var encryptedCard = state.game.players[playerId].hand[0]; | ||
var keys = state.secret[encryptedCard.id]; | ||
var key = _util.Box.addKey(state.game.boxes[boxId], state.client.keys, playerId); | ||
dispatch({ | ||
type: SHUFFLE_DECK_DECRYPT, | ||
privateKey: keys.private, | ||
playerId: playerId | ||
boxId: boxId, | ||
playerId: playerId, | ||
key: key | ||
}); | ||
@@ -179,3 +155,9 @@ }; | ||
deck: action.deck | ||
}))) | ||
}))), | ||
boxes: action.deck.reduce(function (boxes, boxId) { | ||
return Object.assign({}, boxes, _defineProperty({}, boxId, { | ||
contents: action.boxes[boxId].contents, | ||
keys: _defineProperty({}, action._sender, action.boxes[boxId].keys[action._sender]) | ||
})); | ||
}, state.game.boxes) | ||
}) | ||
@@ -186,8 +168,7 @@ }); | ||
if (action.type === SHUFFLE_DECK_DECRYPT) { | ||
var box = state.game.boxes[action.boxId]; | ||
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], { | ||
hand: [_ssbKeys2.default.unbox(state.game.players[action.playerId].hand[0].box, { | ||
private: action.privateKey | ||
})].concat(_toConsumableArray(state.game.players[action.playerId].hand.slice(1))) | ||
boxes: Object.assign({}, state.game.boxes, _defineProperty({}, action.boxId, Object.assign({}, box, { | ||
keys: Object.assign({}, box.keys, _defineProperty({}, action.playerId, action.key)) | ||
}))) | ||
@@ -194,0 +175,0 @@ }) |
{ | ||
"name": "@cardcore/game", | ||
"version": "0.0.1-3ec581c3", | ||
"version": "0.0.1-84ee245d", | ||
"description": "base rules for the Streamplace card game", | ||
@@ -16,3 +16,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "3ec581c3f6f424e67d96dac06f7bcf5f3eb6f200" | ||
"gitHead": "84ee245dbb3f377431457889357c0132ddcbf93c" | ||
} |
import { targetArray } from "@cardcore/util"; | ||
import { clientGenerateKey, clientBox } from "@cardcore/client"; | ||
@@ -11,8 +10,5 @@ export const BOUNCE = "BOUNCE"; | ||
export const bounceEncrypt = ({ unitId }) => async (dispatch, getState) => { | ||
const { keys } = await dispatch(clientGenerateKey()); | ||
const card = await dispatch(clientBox(unitId, keys)); | ||
return dispatch({ | ||
type: "BOUNCE_ENCRYPT", | ||
unitId, | ||
card | ||
unitId | ||
}); | ||
@@ -53,3 +49,3 @@ }; | ||
...player, | ||
hand: [...player.hand, action.card], | ||
hand: [...player.hand, action.unitId], | ||
field: player.field.filter(unitId => unitId !== action.unitId) | ||
@@ -56,0 +52,0 @@ } |
@@ -18,6 +18,6 @@ import { SHUFFLE_DECK_DECRYPT } from "./shuffle-deck"; | ||
const player = state.game.players[playerId]; | ||
const unitId = player.deck[0]; | ||
if (!unitId) { | ||
const boxId = player.deck[0]; | ||
if (!boxId) { | ||
// fatigue | ||
state = { | ||
return { | ||
...state, | ||
@@ -42,32 +42,28 @@ game: { | ||
}; | ||
} else { | ||
let newActions = []; | ||
if (unitId.secret && unitId.playerId !== playerId) { | ||
// card is encrypted by someone else, ask them to decrypt | ||
newActions.push({ | ||
playerId: unitId.playerId, | ||
action: { | ||
type: SHUFFLE_DECK_DECRYPT, | ||
playerId: playerId | ||
} | ||
return { | ||
...state, | ||
game: { | ||
...state.game, | ||
players: { | ||
...state.game.players, | ||
[playerId]: { | ||
...player, | ||
hand: [boxId, ...player.hand], | ||
deck: player.deck.slice(1) | ||
} | ||
}); | ||
} else { | ||
throw new Error("who the butt encrypted this"); | ||
} | ||
state = { | ||
...state, | ||
game: { | ||
...state.game, | ||
players: { | ||
...state.game.players, | ||
[playerId]: { | ||
...player, | ||
hand: [unitId, ...player.hand], | ||
deck: player.deck.slice(1) | ||
}, | ||
nextActions: [ | ||
{ | ||
playerId: Object.keys(state.game.boxes[boxId].keys).sort()[0], | ||
action: { | ||
type: SHUFFLE_DECK_DECRYPT, | ||
playerId: playerId, | ||
boxId: boxId | ||
} | ||
}, | ||
nextActions: [...newActions, ...state.game.nextActions] | ||
} | ||
}; | ||
} | ||
...state.game.nextActions | ||
] | ||
} | ||
}; | ||
} | ||
@@ -74,0 +70,0 @@ return state; |
@@ -8,2 +8,3 @@ export * from "./attack"; | ||
export * from "./draw-card"; | ||
export * from "./play-card"; | ||
export * from "./play-creature"; | ||
@@ -45,3 +46,4 @@ export * from "./seed-rng"; | ||
randoSeeds: {}, | ||
prev: null | ||
prev: null, | ||
boxes: {} | ||
} | ||
@@ -48,0 +50,0 @@ }; |
@@ -1,17 +0,12 @@ | ||
import ssbKeys from "@streamplace/ssb-keys"; | ||
import { SEED_RNG } from "./seed-rng"; | ||
import { CHECK_DEATH } from "./check-death"; | ||
import { target } from "@cardcore/util"; | ||
import { target, Box } from "@cardcore/util"; | ||
import { START_GAME } from "./start-game"; | ||
export const PLAY_CREATURE = "PLAY_CREATURE"; | ||
export const playCreature = ({ | ||
id, | ||
privateKey, | ||
targets = [] | ||
}) => async dispatch => { | ||
await dispatch({ | ||
export const playCreature = ({ boxId }) => async (dispatch, getState) => { | ||
const { targets } = getState().client; | ||
dispatch({ | ||
type: PLAY_CREATURE, | ||
id, | ||
privateKey, | ||
boxId, | ||
targets | ||
@@ -22,19 +17,6 @@ }); | ||
export const playCreatureReducer = (state, action) => { | ||
if (action.type === START_GAME) { | ||
return { | ||
...state, | ||
game: { | ||
...state.game, | ||
allowedActions: { | ||
...state.game.allowedActions, | ||
[PLAY_CREATURE]: true | ||
} | ||
} | ||
}; | ||
} | ||
if (action.type === PLAY_CREATURE) { | ||
const player = state.game.players[action._sender]; | ||
const card = player.hand.filter(card => card.id === action.id)[0]; | ||
const unitId = ssbKeys.unbox(card.box, { private: action.privateKey }); | ||
const boxId = action.boxId; | ||
const unitId = Box.traverse(boxId, state.game.boxes, state.client.keys); | ||
const unit = state.game.units[unitId]; | ||
@@ -50,3 +32,3 @@ return { | ||
availableMana: player.availableMana - unit.cost, | ||
hand: player.hand.filter(c => c !== card), | ||
hand: player.hand.filter(c => c !== boxId), | ||
field: [unitId, ...player.field] | ||
@@ -53,0 +35,0 @@ } |
import { rotateArray, shuffle } from "@cardcore/util"; | ||
import { clientGenerateKey, clientBox } from "@cardcore/client"; | ||
import ssbKeys from "@streamplace/ssb-keys"; | ||
import { Box } from "@cardcore/util"; | ||
@@ -15,6 +14,9 @@ export const SHUFFLE_DECK = "SHUFFLE_DECK"; | ||
) => { | ||
const state = getState(); | ||
let encryptedDeck = []; | ||
for (const card of getState().game.players[playerId].deck) { | ||
const { keys } = await dispatch(clientGenerateKey()); | ||
encryptedDeck.push(await dispatch(clientBox(card, keys))); | ||
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; | ||
} | ||
@@ -24,2 +26,3 @@ return dispatch({ | ||
deck: shuffle(encryptedDeck), | ||
boxes, | ||
playerId | ||
@@ -31,10 +34,13 @@ }); | ||
export const SHUFFLE_DECK_DECRYPT = "SHUFFLE_DECK_DECRYPT"; | ||
export const shuffleDeckDecrypt = ({ playerId }) => (dispatch, getState) => { | ||
export const shuffleDeckDecrypt = ({ playerId, boxId }) => ( | ||
dispatch, | ||
getState | ||
) => { | ||
const state = getState(); | ||
const encryptedCard = state.game.players[playerId].hand[0]; | ||
const keys = state.secret[encryptedCard.id]; | ||
const key = Box.addKey(state.game.boxes[boxId], state.client.keys, playerId); | ||
dispatch({ | ||
type: SHUFFLE_DECK_DECRYPT, | ||
privateKey: keys.private, | ||
playerId | ||
boxId, | ||
playerId, | ||
key | ||
}); | ||
@@ -77,3 +83,15 @@ }; | ||
} | ||
} | ||
}, | ||
boxes: action.deck.reduce( | ||
(boxes, boxId) => ({ | ||
...boxes, | ||
[boxId]: { | ||
contents: action.boxes[boxId].contents, | ||
keys: { | ||
[action._sender]: action.boxes[boxId].keys[action._sender] | ||
} | ||
} | ||
}), | ||
state.game.boxes | ||
) | ||
} | ||
@@ -84,2 +102,3 @@ }; | ||
if (action.type === SHUFFLE_DECK_DECRYPT) { | ||
const box = state.game.boxes[action.boxId]; | ||
return { | ||
@@ -89,12 +108,10 @@ ...state, | ||
...state.game, | ||
players: { | ||
...state.game.players, | ||
[action.playerId]: { | ||
...state.game.players[action.playerId], | ||
hand: [ | ||
ssbKeys.unbox(state.game.players[action.playerId].hand[0].box, { | ||
private: action.privateKey | ||
}), | ||
...state.game.players[action.playerId].hand.slice(1) | ||
] | ||
boxes: { | ||
...state.game.boxes, | ||
[action.boxId]: { | ||
...box, | ||
keys: { | ||
...box.keys, | ||
[action.playerId]: action.key | ||
} | ||
} | ||
@@ -101,0 +118,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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
149072
49
2620