|
|
|
import { initialWeapon, initialArmor, initialNeck, initialRing, i18n, audio_mp3 } from '@/config';
|
|
|
|
import { conisOfsell, saveArchive, getArchive, getFromStore } from '@/tool';
|
|
|
|
|
|
|
|
const backgound = new Audio(audio_mp3.background);
|
|
|
|
backgound.loop = true;
|
|
|
|
backgound.volume = 0.2;
|
|
|
|
const battle = new Audio(audio_mp3.battle);
|
|
|
|
battle.loop = true;
|
|
|
|
battle.volume = 0.2;
|
|
|
|
const music = {
|
|
|
|
backgound: backgound,
|
|
|
|
battle: battle,
|
|
|
|
};
|
|
|
|
|
|
|
|
const { t } = i18n;
|
|
|
|
|
|
|
|
export const play_music = (store, type) => {
|
|
|
|
Object.keys(music).forEach((key) => {
|
|
|
|
const audio = music[key];
|
|
|
|
if (key == type) {
|
|
|
|
audio.play();
|
|
|
|
} else {
|
|
|
|
audio.pause();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const set_music_muted = (store, muted) => {
|
|
|
|
Object.keys(music).forEach((key) => {
|
|
|
|
music[key].muted = muted;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const set_music_volume = (store, volume) => {
|
|
|
|
Object.keys(music).forEach((key) => {
|
|
|
|
music[key].volume = volume;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const reset_player_equi = ({ commit }) => {
|
|
|
|
const equips = [initialWeapon(), initialArmor(), initialNeck(), initialRing()];
|
|
|
|
commit('set_player_equips', equips);
|
|
|
|
commit('set_player_lv', 1);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const sell_equip = ({ state, commit }, index) => {
|
|
|
|
const item = state.grid[index];
|
|
|
|
if (item.locked) {
|
|
|
|
commit('set_sys_info', { msg: t('sellLocked'), type: 'warning' });
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const coins = conisOfsell(item);
|
|
|
|
const tmp = state.grid;
|
|
|
|
tmp[index] = null;
|
|
|
|
commit('add_player_coins', coins);
|
|
|
|
commit('set_backpack', tmp);
|
|
|
|
commit('set_sys_info', { msg: `${t('sellEquip')}${coins}`, type: 'booty' });
|
|
|
|
};
|
|
|
|
|
|
|
|
export const useEquip = ({ state, commit }, index) => {
|
|
|
|
const grid = state.grid;
|
|
|
|
const tmp = grid[index];
|
|
|
|
const type = tmp.type;
|
|
|
|
grid[index] = state.playerAttribute[type];
|
|
|
|
commit('set_player_equips', [tmp]);
|
|
|
|
commit('set_backpack', grid);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const saveGame = ({ state, commit }) => {
|
|
|
|
saveArchive(state);
|
|
|
|
commit('set_sys_info', { msg: t('saveGame.2'), type: 'win' });
|
|
|
|
};
|
|
|
|
|
|
|
|
export const loadGame = ({ commit }, data?) => {
|
|
|
|
if (data) {
|
|
|
|
loadArchive(commit, data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
getArchive().then((rsp: any) => {
|
|
|
|
loadArchive(commit, rsp);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
const loadArchive = (commit, data) => {
|
|
|
|
if (!data) {
|
|
|
|
commit('set_sys_info', { msg: t('loadEmpty'), type: 'warning' });
|
|
|
|
} else if (data == 'undfind') {
|
|
|
|
commit('set_sys_info', { msg: t('loadError'), type: 'warning' });
|
|
|
|
} else {
|
|
|
|
commit('set_player_equips', data.equips);
|
|
|
|
commit('set_player_lv', data.lv || 1);
|
|
|
|
commit('set_player_layer', data.layer || 1);
|
|
|
|
commit('set_player_coins', data.coins || 0);
|
|
|
|
commit('set_backpack', data.grid);
|
|
|
|
commit('set_auto_sell', data.autoSell);
|
|
|
|
commit('set_shop', data.shop);
|
|
|
|
commit('set_reborn_points', data.reborn);
|
|
|
|
commit('set_sys_info', { msg: t('loadSuccess'), type: 'win' });
|
|
|
|
}
|
|
|
|
commit('call_player_attribute');
|
|
|
|
};
|