一个全随机的刷装备小游戏
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.

131 lines
4.2 KiB

1 month ago
import { callPlayerAttribute, conisOfsell, getArrayEmptyIdx } from '@/tool';
import { reborn_point_coefficients, reborn_arrts, i18n } from '@/config';
const { t } = i18n;
export const call_player_attribute = (state) => {
const attribute = callPlayerAttribute(state.playerAttribute, state.rebornAttribute);
state.playerAttribute.attribute = attribute;
};
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 > 50) {
state.sysInfo.shift();
}
};
export const show_equip_tip = (state, data) => {
state.equipTip.equip = data.equip;
state.equipTip.compare = data.compare || false;
const x = data.e.pageX,
y = data.e.pageY,
maxH = window.innerHeight,
maxW = window.innerWidth;
const tipsStyle = state.equipTip.tipsStyle;
const tipsStyle2 = state.equipTip.tipsStyle2;
if (x < maxW / 2) {
delete tipsStyle.right;
tipsStyle.left = x + 'px';
delete tipsStyle2.right;
tipsStyle2.left = 'calc(' + x + 'px + 21rem)';
} else {
delete tipsStyle.left;
tipsStyle.right = maxW - x + 'px';
delete tipsStyle2.left;
tipsStyle.right2 = 'calc(' + tipsStyle.righ + ' - 21rem)';
}
if (y < maxH / 2) {
delete tipsStyle.bottom;
tipsStyle.top = y + 'px';
delete tipsStyle2.bottom;
tipsStyle2.top = y + 'px';
} else {
delete tipsStyle.top;
tipsStyle.bottom = maxH - y + 'px';
delete tipsStyle2.top;
tipsStyle2.bottom = maxH - y + 'px';
}
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_endless_lv = (state, data) => {
state.playerAttribute.endlessLv = parseInt(data) < 1 ? 1 : parseInt(data);
};
export const set_player_lv = (state, data) => {
data = data < 1 ? 1 : data;
state.playerAttribute.lv = parseInt(data || 1);
};
export const set_reborn_points = (state, rebornPoints) => {
state.rebornPoints = rebornPoints;
const rebornAttribute = {};
reborn_arrts.forEach((attr) => {
rebornAttribute[attr] = rebornPoints[attr] * reborn_point_coefficients[attr];
});
state.rebornAttribute = rebornAttribute;
call_player_attribute(state);
};
export const add_player_curhp = (state, 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;
};