267 lines
8.3 KiB
JavaScript
267 lines
8.3 KiB
JavaScript
import Bag from "../ts/bag/Bag";
|
|
import GameModel from "../ts/core/GameModel";
|
|
import ItemUtil from "../ts/core/ItemUtil";
|
|
import MsgAlert from "../ts/game/msg/MsgAlert";
|
|
cc.Class({
|
|
extends: cc.Component,
|
|
|
|
properties: {
|
|
bagContent: cc.Node,
|
|
lockerContent: cc.Node,
|
|
shigongLab: cc.Label,
|
|
yinliangLab: cc.Label,
|
|
xianyuLab: cc.Label,
|
|
lockerItem: cc.Prefab,
|
|
lastTime: 0
|
|
},
|
|
|
|
onLoad() {
|
|
this.bagSelected = -1;
|
|
GameModel.send('c2s_get_lockeritem', { roleid: GameModel.player.roleid });
|
|
this.bagList = {};
|
|
this.lockerList = {};
|
|
this.bagEquip = [];
|
|
this.lockerEquip = [];
|
|
this.shigongLab.string = '0';
|
|
this.yinliangLab.string = GameModel.player.gameData.money;
|
|
this.yinliangLab.node.color = GameModel.getColor(GameModel.player.gameData.money);
|
|
this.xianyuLab.string = GameModel.player.gameData.jade;
|
|
this.xianyuLab.node.color = GameModel.getColor(GameModel.player.gameData.jade);
|
|
|
|
this.readyBagContent()
|
|
this.readylockerContent()
|
|
},
|
|
readyBagContent() {
|
|
this.bagContent.destroyAllChildren();
|
|
let maxLength = GameModel.player.bagKindNum;
|
|
this.bagContent.height = Math.ceil(maxLength / 5) * 66;
|
|
for (let i = 0; i < maxLength; i++) {
|
|
this.addItem(i, this.bagContent)
|
|
}
|
|
},
|
|
readylockerContent() {
|
|
this.lockerContent.destroyAllChildren();
|
|
let maxLength = GameModel.player.lockerKindNum;
|
|
this.lockerContent.height = Math.ceil(maxLength / 5) * 66;
|
|
for (let i = 0; i < maxLength; i++) {
|
|
this.addItem(i, this.lockerContent)
|
|
}
|
|
},
|
|
loadInfo(baginfo, lockerinfo, equipinfo) {
|
|
this.bagList = baginfo;
|
|
this.lockerList = lockerinfo;
|
|
this.bagEquip = equipinfo.list;
|
|
this.lockerEquip = equipinfo.locker;
|
|
this.loadBagList();
|
|
this.loadLockerList();
|
|
},
|
|
|
|
addItem(index, parent) {
|
|
let item = cc.instantiate(this.lockerItem);
|
|
item.x = -132 + (index % 5) * 66;
|
|
item.y = -33 - Math.floor(index / 5) * 66;
|
|
item.parent = parent;
|
|
},
|
|
|
|
getItem(index, parent) {
|
|
return parent.children[index]
|
|
},
|
|
loadBagList() {
|
|
let keys = Object.getOwnPropertyNames(this.bagList);
|
|
let maxLength = GameModel.player.bagKindNum;
|
|
let curIndex = 0;
|
|
// 先添加裝備
|
|
for (const info of this.bagEquip) {
|
|
let item = this.getItem(curIndex++, this.bagContent);
|
|
item.getComponent('LockerItem').panelLogic = this;
|
|
item.getComponent('LockerItem').type = 1;
|
|
item.getComponent('LockerItem').isequip = true;
|
|
item.getComponent('LockerItem').loadEquipInfo(info);
|
|
}
|
|
|
|
var tempMax = maxLength - this.bagEquip.length;
|
|
for (let index = 0; index < tempMax; index++) {
|
|
let item = this.getItem(curIndex++, this.bagContent);
|
|
if (this.bagList[keys[index]] == 0) {
|
|
item.getComponent('LockerItem').loadInfo(null, 0)
|
|
item.getComponent('LockerItem').isequip = false;
|
|
continue;
|
|
}
|
|
var info = ItemUtil.getItemData(keys[index])
|
|
if (info && info.type == 15 || (keys[index] >= 1003010 && keys[index] <= 1003100) || (keys[index] >= 100320 && keys[index] <= 100323)) {
|
|
item.getComponent('LockerItem').loadInfo(null, 0)
|
|
item.getComponent('LockerItem').isequip = false;
|
|
continue;
|
|
}
|
|
if (info && info.type == 18) {
|
|
item.getComponent('LockerItem').loadInfo(null, 0)
|
|
item.getComponent('LockerItem').isequip = false;
|
|
continue
|
|
}
|
|
if (index < keys.length) {
|
|
item.getComponent('LockerItem').panelLogic = this;
|
|
item.getComponent('LockerItem').type = 1;
|
|
item.getComponent('LockerItem').isequip = false;
|
|
item.getComponent('LockerItem').loadInfo(keys[index], this.bagList[keys[index]]);
|
|
} else {
|
|
item.getComponent('LockerItem').isequip = false;
|
|
item.getComponent('LockerItem').loadInfo(null, 0)
|
|
}
|
|
}
|
|
},
|
|
|
|
loadLockerList() {
|
|
let keys = Object.getOwnPropertyNames(this.lockerList);
|
|
let maxLength = GameModel.player.lockerKindNum;
|
|
let curIndex = 0;
|
|
for (const info of this.lockerEquip) {
|
|
let item = this.getItem(curIndex++, this.lockerContent);
|
|
item.getComponent('LockerItem').panelLogic = this;
|
|
item.getComponent('LockerItem').type = 0;
|
|
item.getComponent('LockerItem').isequip = true;
|
|
item.getComponent('LockerItem').loadEquipInfo(info);
|
|
}
|
|
for (let index = 0; index < maxLength - this.lockerEquip.length; index++) {
|
|
let item = this.getItem(curIndex++, this.lockerContent);
|
|
if (this.lockerList[keys[index]] == 0) {
|
|
item.getComponent('LockerItem').loadInfo(null, 0)
|
|
item.getComponent('LockerItem').isequip = false;
|
|
continue;
|
|
}
|
|
var info = ItemUtil.getItemData(keys[index])
|
|
if (info && info.type == 15 || (keys[index] >= 1003010 && keys[index] <= 1003100) || (keys[index] >= 100320 && keys[index] <= 100323)) {
|
|
item.getComponent('LockerItem').loadInfo(null, 0)
|
|
item.getComponent('LockerItem').isequip = false;
|
|
continue;
|
|
}
|
|
if (index < keys.length) {
|
|
item.getComponent('LockerItem').panelLogic = this;
|
|
item.getComponent('LockerItem').type = 0;
|
|
item.getComponent('LockerItem').isequip = false;
|
|
item.getComponent('LockerItem').loadInfo(keys[index], this.lockerList[keys[index]]);
|
|
} else {
|
|
item.getComponent('LockerItem').isequip = false;
|
|
item.getComponent('LockerItem').loadInfo(null, 0)
|
|
}
|
|
}
|
|
},
|
|
|
|
changeItemType(type, itemid) {
|
|
if (this.stopFastTap()) return
|
|
if (type == 0) {
|
|
let keys = Object.getOwnPropertyNames(this.bagList);
|
|
var transProp = this.countTransPorpNum(this.bagList)
|
|
if (keys.length + this.bagEquip.length - transProp >= GameModel.player.bagKindNum) {
|
|
MsgAlert.addMsg(`背包已滿`);
|
|
return
|
|
}
|
|
if (this.bagList[itemid] == null) this.bagList[itemid] = 0;
|
|
this.bagList[itemid] += this.lockerList[itemid];
|
|
delete this.lockerList[itemid];
|
|
}
|
|
else {
|
|
let keys = Object.getOwnPropertyNames(this.lockerList);
|
|
var transProp = this.countTransPorpNum(this.lockerList)
|
|
if (keys.length + this.lockerEquip.length - transProp >= GameModel.player.lockerKindNum) {
|
|
MsgAlert.addMsg(`倉庫已滿`);
|
|
return
|
|
}
|
|
if (this.lockerList[itemid] == null) this.lockerList[itemid] = 0;
|
|
this.lockerList[itemid] += this.bagList[itemid];
|
|
delete this.bagList[itemid];
|
|
}
|
|
this.loadBagList();
|
|
this.loadLockerList();
|
|
this.sendChange(0, type, itemid);
|
|
},
|
|
|
|
changeEquipType(type, info) {
|
|
if (this.stopFastTap()) return
|
|
if (type == 0) {
|
|
let keys = Object.getOwnPropertyNames(this.bagList);
|
|
var transProp = this.countTransPorpNum(this.bagList)
|
|
if (keys.length + this.bagEquip.length - transProp >= GameModel.player.bagKindNum) {
|
|
MsgAlert.addMsg(`背包已滿`);
|
|
return
|
|
}
|
|
let lockerindex = this.lockerEquip.indexOf(info);
|
|
let listindex = this.bagEquip.indexOf(info);
|
|
if (lockerindex != -1) {
|
|
this.lockerEquip.splice(lockerindex, 1);
|
|
}
|
|
if (listindex == -1) {
|
|
this.bagEquip.push(info);
|
|
}
|
|
}
|
|
else {
|
|
let keys = Object.getOwnPropertyNames(this.lockerList);
|
|
var transProp = this.countTransPorpNum(this.lockerList)
|
|
if (keys.length + this.lockerEquip.length - transProp >= GameModel.player.lockerKindNum) {
|
|
MsgAlert.addMsg(`倉庫已滿`);
|
|
return
|
|
}
|
|
let lockerindex = this.lockerEquip.indexOf(info);
|
|
let listindex = this.bagEquip.indexOf(info);
|
|
if (lockerindex == -1) {
|
|
this.lockerEquip.push(info);
|
|
}
|
|
if (listindex != -1) {
|
|
this.bagEquip.splice(listindex, 1);
|
|
}
|
|
}
|
|
this.loadBagList();
|
|
this.loadLockerList();
|
|
this.sendChange(1, type, info.EquipID);
|
|
},
|
|
stopFastTap() {
|
|
var time = new Date().getTime();
|
|
if (time - this.lastTime <= 400) {
|
|
MsgAlert.addMsg("您點擊太快啦")
|
|
return true
|
|
}
|
|
this.lastTime = time;
|
|
return false
|
|
},
|
|
sendChange(type, operation, operateid) {
|
|
GameModel.send('c2s_update_lockeritem', {
|
|
roleid: GameModel.player.roleid,
|
|
type: type,
|
|
operation: operation,
|
|
operateid: operateid.toString(),
|
|
});
|
|
},
|
|
|
|
onCloseBtnClicked(e, d) {
|
|
// let equipInfo = {};
|
|
// equipInfo.locker = [];
|
|
// equipInfo.list = [];
|
|
// for (const info of this.bagEquip) {
|
|
// equipInfo.list.push(info.EquipID);
|
|
// }
|
|
// for (const info of this.lockerEquip) {
|
|
// equipInfo.locker.push(info.EquipID);
|
|
// }
|
|
// GameModel.send('c2s_update_lockeritem', {
|
|
// roleid: GameModel.player.roleid,
|
|
// bag: JSON.stringify(this.bagList),
|
|
// locker: JSON.stringify(this.lockerList),
|
|
// equip: JSON.stringify(equipInfo),
|
|
// });
|
|
this.node.destroy();
|
|
Bag.Instance.showBagPanel();
|
|
},
|
|
|
|
/**
|
|
* 統計變身道具數量
|
|
*/
|
|
countTransPorpNum(list) {
|
|
let keys = Object.getOwnPropertyNames(list);
|
|
var count = 0
|
|
for (let i in keys) {
|
|
if ((keys[i] >= 500001 && keys[i] <= 500199) || (keys[i] >= 1003010 && keys[i] <= 1003100))
|
|
count++;
|
|
}
|
|
return count;
|
|
}
|
|
});
|