123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- import { Framework } from "../../framework/Framework";
- import { ItemEnum } from "../common/InterfaceAddEnum";
- import { LoginMgr } from "../common/LoginManager";
- import { EquipConf } from "../config/EquipConf";
- import { EquipstrengthenConf } from "../config/EquipstrengthenConf";
- import { Equip, EquipData } from "../data/EquipData";
- import { GameEvent } from "../data/GameEvent";
- export class EquipManager {
- /**
- * 根据参数获取装备(或奖励装备)
- * @param id 装备id_经验exp_星级star
- * @param count 数量
- * @param isWear 是否穿戴
- */
- static getEquipById(id: string, count: number, isWear: boolean) {
- let conf = EquipConf.data;
- let arr = id.split('_');
- let eConf = conf[arr[0]];
- if (eConf) {
- let lvAdd = this.getEquipLevelByExp(Number(arr[1]));
- let attrAdd = eConf.Stat1.split(':')
- let equipData: Equip = {
- id: id,
- count: count,
- exp: Number(arr[1]),
- star: Number(arr[2]),
- wear: isWear,
- type: ItemEnum.equip,
- fightForce: (1 + lvAdd.atkMod) * attrAdd[1],
- conf: eConf
- }
- return equipData;
- }
- return null;
- }
- /**
- * 根据参数获取装备(或奖励装备)
- * @param id 装备id
- * @param exp 经验
- */
- static getEquipLevelByExp(exp: number) {
- let strengConf = EquipstrengthenConf.data;
- let data = [];
- for (const key in strengConf) {
- if (Object.prototype.hasOwnProperty.call(strengConf, key)) {
- const element = strengConf[key];
- data.push(element);
- }
- }
- data.sort((a, b) => {
- return Number(a.id) < Number(b.id) ? -1 : 1;
- });
- let nowConf = null
- for (let index = 0; index < data.length; index++) {
- const element = data[index];
- if (exp < element.NeedExp) {
- nowConf = element;
- break;
- }
- }
- return nowConf;
- }
- static getEquipNextLevel(exp: number) {
- let strengConf = EquipstrengthenConf.data;
- let data = [];
- for (const key in strengConf) {
- if (Object.prototype.hasOwnProperty.call(strengConf, key)) {
- const element = strengConf[key];
- data.push(element);
- }
- }
- data.sort((a, b) => {
- return Number(a.id) < Number(b.id) ? -1 : 1;
- });
- let nowConf = null
- for (let index = 0; index < data.length; index++) {
- const element = data[index];
- if (exp < element.NeedExp) {
- nowConf = element;
- break;
- }
- }
- return strengConf[String(nowConf.Id + 1)];
- }
- //获取阵营穿戴装备
- static getEquipWearRaceGroup() {
- let equips = {};
- for (let x = 1; x <= 4; x++) {
- for (let y = 1; y <= 4; y++) {
- equips[x] = {};
- equips[x][y] = 0;
- }
- }
- let data = EquipData.getData();
- for (const key in data) {
- if (Object.prototype.hasOwnProperty.call(data, key)) {
- const element = data[key];
- if (element.wear) {
- equips[element.conf['Race']][element.conf['Slot']] = element;
- }
- }
- }
- return equips;
- }
- //获取阵营装备(分类)
- static getEquipRaceSlotGroup(race) {
- let equips = { 1: [], 2: [], 3: [], 4: [] };
- let data = EquipData.getData();
- for (const key in data) {
- if (Object.prototype.hasOwnProperty.call(data, key)) {
- const element = data[key];
- if (!element.wear && element.conf['Race'] == race) {
- equips[element.conf['Slot']].push(element);
- }
- }
- }
- return equips;
- }
- //获取阵营装备(全)
- static getEquipRaceSlotAllGroup(race) {
- let equips = []
- let data = EquipData.getData();
- for (const key in data) {
- if (Object.prototype.hasOwnProperty.call(data, key)) {
- const element = data[key];
- if (!element.wear && element.conf['Race'] == race) {
- equips.push(element);
- }
- }
- }
- return equips;
- }
- static updateEquips(race, slot) {
- }
- //消息-穿戴装备
- static sendWearMsg(args: { eid: string, slot: number, race: number }, callback) {
- LoginMgr.sendPost('equip', 'wear', (data) => {
- console.log(data);
- let wearData = this.getEquipWearRaceGroup()[args.race][args.slot];
- if (wearData && wearData.id) {
- EquipData.removeDataByKey(wearData.id + '_' + args.slot);
- }
- if (data.race_equip) {
- for (const slot in data.race_equip) {
- if (Object.prototype.hasOwnProperty.call(data.race_equip, slot)) {
- if (Number(slot) == args.slot) {
- const eid = data.race_equip[slot];
- if (eid != 0) {
- let equip = this.getEquipById(eid, 1, true);
- if (equip) {
- EquipData.addDataByKey(eid + '_' + args.race, equip);
- }
- }
- }
- }
- }
- }
- if (data.equip) {
- EquipData.parseDataByServer(data.equip);
- }
- Framework.event.fireEvent(GameEvent.EquipWearChange, args.race);
- callback();
- }, args)
- }
- //消息-升级装备
- static sendUpdateMsg(args: { eat_eids: {}, slot: number, race: number }, callback) {
- LoginMgr.sendPost('equip', 'strengthen', (data) => {
- console.log(data);
- let wearData = this.getEquipWearRaceGroup()[args.race][args.slot];
- if (wearData && wearData.id) {
- EquipData.removeDataByKey(wearData.id + '_' + args.slot);
- }
- if (data.race_equip) {
- for (const slot in data.race_equip) {
- if (Object.prototype.hasOwnProperty.call(data.race_equip, slot)) {
- if (Number(slot) == args.slot) {
- const eid = data.race_equip[slot];
- if (eid != 0) {
- let equip = this.getEquipById(eid, 1, true);
- if (equip) {
- EquipData.addDataByKey(eid + '_' + args.race, equip);
- }
- }
- }
- }
- }
- }
- if (data.equip) {
- EquipData.parseDataByServer(data.equip);
- }
- Framework.event.fireEvent(GameEvent.EquipWearChange, args.race);
- callback();
- }, args)
- }
- static setData(bagData, equipData) {
- EquipData.equipData = {};
- EquipData.bagData = {};
- for (const key in bagData) {
- if (Object.prototype.hasOwnProperty.call(bagData, key)) {
- const element = bagData[key];
- let equip = EquipManager.getEquipById(key, element, false);
- if (equip) {
- EquipData.bagData[key] = equip;
- }
- }
- }
- let conf = EquipConf.data;
- for (const race in equipData) {
- if (Object.prototype.hasOwnProperty.call(equipData, race)) {
- const element = equipData[race];
- for (const key in element) {
- if (Object.prototype.hasOwnProperty.call(element, key)) {
- const eid = element[key];
- if (eid != 0) {
- let equip = EquipManager.getEquipById(eid, 1, true);
- if (equip) {
- EquipData.bagData[key + '_' + race] = equip;
- }
- }
- }
- }
- }
- }
- }
- }
|