一个全随机的刷装备小游戏
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

125 lines
3.8 KiB

import { callPlayerAttribute, conisOfsell, getArrayEmptyIdx, callEuqipTipsLocation } from '@/tool';
import { i18n, piont_arrts, point_coefficients } from '@/config';
const { t } = i18n;
export const call_player_attribute = (state) => {
callPlayerAttribute(state.playerAttribute, state.baseAttribute);
};
export const set_player_equips = (state, equips) => {
if (equips && equips.length > 0) {
equips.forEach((equip) => {
if (equip) {
const type = equip.type;
state.playerAttribute[type] = equip;
}
});
call_player_attribute(state);
}
};
export const takeOffEquip = (state, type) => {
const idx = getArrayEmptyIdx(state.grid);
if (idx != -1) {
state.grid[idx] = state.playerAttribute[type];
state.playerAttribute[type] = null;
call_player_attribute(state);
}
};
export const set_sys_info = (state, data) => {
state.sysInfo.push(data);
var time = +new Date();
var date = new Date(time + 8 * 3600 * 1000); // 增加8小时
state.sysInfo[state.sysInfo.length - 1].time = date.toJSON().substr(11, 8).replace('T', ' ');
if (state.sysInfo.length > 300) {
state.sysInfo.shift();
}
};
export const show_equip_tip = (state, data) => {
state.equipTip.equip = data.equip;
state.equipTip.compare = data.compare || false;
const styles = callEuqipTipsLocation(data.e, state.mobile);
state.equipTip.tipsStyle = styles[0];
state.equipTip.tipsStyle2 = styles[1];
state.equipTip.tipsShow = true;
};
export const close_equip_tip = (state) => {
state.equipTip.tipsShow = false;
};
export const clear_sys_info = (state, data) => {
state.sysInfo.splice(1, state.sysInfo.length);
};
export const add_player_coins = (state, coins) => {
state.playerAttribute.coins += parseInt(coins);
};
export const set_player_coins = (state, coins) => {
state.playerAttribute.coins = parseInt(coins);
};
export const set_backpack = (state, grid) => {
state.grid = grid;
};
export const set_auto_sell = (state, conf) => {
state.autoSell = conf;
};
export const add_bootys = (state, bootys) => {
const coins = bootys.coins;
add_player_coins(state, coins);
const equips = bootys.equips;
set_sys_info(state, { msg: t('getCoins') + coins, type: 'booty', equips: equips });
equips.forEach((equip) => {
const idx = getArrayEmptyIdx(state.grid);
if (state.autoSell.includes(equip.quality.quality) || idx == -1) {
const coins = conisOfsell(equip);
add_player_coins(state, coins);
set_sys_info(state, { msg: t('autoSell.2') + t('getCoins') + coins, type: 'booty' });
return;
} else {
state.grid[idx] = equip;
}
});
};
export const set_shop = (state, shop) => {
state.shop = shop;
};
export const set_player_lv = (state, data) => {
data = parseInt(data) || 1;
data = data < 1 ? 1 : data;
state.playerAttribute.lv = data;
state.playerAttribute.attribute.lv = data;
const total = state.points.total;
if (total < data) {
const add = data - total;
add_point(state, add);
}
};
export const set_player_layer = (state, data) => {
data = parseInt(data);
data = data < 1 ? 1 : data;
state.playerAttribute.layer = data;
};
export const add_point = (state, add) => {
const total = state.points.total;
if (total >= 2000) {
return;
}
if (total + add > 2000) {
add = 2000 - total;
}
state.points.total += add;
state.points.has += add;
};
export const set_points = (state, points) => {
state.points = points;
const baseAttribute = {};
piont_arrts.forEach((attr) => {
baseAttribute[attr] = points[attr] * point_coefficients[attr];
});
state.baseAttribute = baseAttribute;
call_player_attribute(state);
};
export const add_player_curhp = (state, hp) => {
hp = Math.ceil(hp);
const attr = state.playerAttribute.attribute;
let curHp = attr.curHp + hp;
curHp > attr.hp && (curHp = attr.hp);
curHp < 0 && (curHp = 0);
state.playerAttribute.attribute.curHp = curHp;
};