123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import { socketService } from '../../../main';
- export default function AnyPlayer() {
- const initPlayerState = {
- // Username of this player
- name: '',
- // Color of this player (blue or red)
- color: '',
- // Faction chosen (will stay empty if not faction mode)
- faction: '',
- // Will contain the IDs of the heroes selectable for draft mode
- draftHeroesIds: [],
- // the 12 heroes the player is playing with
- // Player will fill it himself if mode is draft or tournament
- // contains object : {id:heroId , position:'pile' , possibleActions :[]}
- twelveHeroes: [],
- foodInCamp: 0,
- // Can see already we might have issues with left/right depending from where we look :)
- 'foodInBattle/left': 0,
- 'foodInBattle/center': 0,
- 'foodInBattle/right': 0,
- // During military phase it will contain actions made by player to be replayed by other
- actionsPerformed: []
- };
- const state = Object.assign({}, initPlayerState);
- const getters = {
- color: state => {
- return state.color;
- },
- draftIds: state => {
- return state.draftHeroesIds;
- },
- twelveHeroes: state => {
- return state.twelveHeroes;
- }
- };
- const mutations = {
- SET_FULL_PLAYER_STATE: (state, payload) => {
- Object.assign(state, payload);
- },
- INIT_PLAYER_STATE: state => {
- Object.assign(state, initPlayerState);
- }
- };
- const actions = {
- submitFaction: ({ commit, state }, payload) => {
- commit(
- 'game/SET_WAITING_FOR',
- { color: state.color, value: false },
- { root: true }
- );
- socketService
- .endTurn({ color: state.color, faction: payload })
- .catch(err => {
- console.log('Error sending data : ', err);
- //Unvalid submit
- commit(
- 'game/SET_WAITING_FOR',
- { color: state.color, value: true },
- { root: true }
- );
- });
- }
- };
- return {
- namespace: true,
- state,
- getters,
- mutations,
- actions
- };
- }
|