|
|
|
import { initialWeapon, initialArmor, initialNeck, initialRing, i18n, archive_name } from '@/config';
|
|
|
|
import { conisOfsell, getAssets } from '@/tool';
|
|
|
|
import { Base64 } from 'js-base64';
|
|
|
|
|
|
|
|
const backgound = new Audio('/audio/backgound.mp3');
|
|
|
|
backgound.loop = true;
|
|
|
|
backgound.volume = 0.2;
|
|
|
|
const battle = new Audio('/audio/battle.mp3');
|
|
|
|
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];
|
|
|
|
console.log(item);
|
|
|
|
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 }) => {
|
|
|
|
const data = {
|
|
|
|
equips: [state.playerAttribute.weapon, state.playerAttribute.armor, state.playerAttribute.ring, state.playerAttribute.neck],
|
|
|
|
endlessLv: state.endlessLv,
|
|
|
|
lv: state.playerAttribute.lv,
|
|
|
|
coins: state.playerAttribute.coins,
|
|
|
|
backpack: state.grid,
|
|
|
|
autoSell: state.autoSell,
|
|
|
|
shop: state.shop,
|
|
|
|
reborn: state.rebornPoints,
|
|
|
|
};
|
|
|
|
var saveData = Base64.encode(Base64.encode(JSON.stringify(data)));
|
|
|
|
localStorage.setItem(archive_name, saveData);
|
|
|
|
commit('set_sys_info', { msg: t('saveGame.2'), type: 'win' });
|
|
|
|
};
|
|
|
|
|
|
|
|
export const loadGame = ({ commit }, data?) => {
|
|
|
|
if (!data) {
|
|
|
|
try {
|
|
|
|
const archive = localStorage.getItem(archive_name) || '';
|
|
|
|
data = JSON.parse(Base64.decode(Base64.decode(archive)));
|
|
|
|
} catch (error) {}
|
|
|
|
}
|
|
|
|
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_endless_lv', data.endlessLv || 1);
|
|
|
|
commit('set_player_coins', data.coins || 0);
|
|
|
|
commit('set_backpack', data.backpack);
|
|
|
|
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');
|
|
|
|
};
|