1
This commit is contained in:
parent
4349bba5f0
commit
5088112256
@ -1,8 +1,45 @@
|
||||
const utils = require('j7/utils');
|
||||
const bcutils = require('j7/bcutils');
|
||||
const basewrap = require('./basewrap');
|
||||
|
||||
const HERO_TYPE = 3;
|
||||
const GUN_TYPE = 7;
|
||||
const MATERIAL_TYPE = 10;
|
||||
|
||||
const MATERIAL_CHIP_SUBTYPE = 3;
|
||||
|
||||
class Item extends basewrap.BaseWrap {
|
||||
|
||||
getNftType() {
|
||||
switch (this['type']) {
|
||||
case HERO_TYPE:
|
||||
{
|
||||
return bcutils.HERO_TYPE;
|
||||
}
|
||||
break;
|
||||
case GUN_TYPE:
|
||||
{
|
||||
return bcutils.EQUIP_TYPE;
|
||||
}
|
||||
break;
|
||||
case MATERIAL_TYPE:
|
||||
{
|
||||
if (this['sub_type'] == MATERIAL_CHIP_SUBTYPE) {
|
||||
return bcutils.CHIP_TYPE;
|
||||
} else {
|
||||
return bcutils.NONE_TYPE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
return bcutils.NONE_TYPE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return bcutils.NONE_TYPE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = Item;
|
||||
|
@ -1,24 +1,54 @@
|
||||
const utils = require('j7/utils');
|
||||
const bcutils = require('j7/bcutils');
|
||||
const basewrap = require('./basewrap');
|
||||
const metaFactory = require('./factory');
|
||||
|
||||
class Present extends basewrap.BaseWrap {
|
||||
|
||||
_init0 () {
|
||||
const items = this['items'].split('|');
|
||||
let totalSpace = 0;
|
||||
this._items = [];
|
||||
items.forEach((tmpStr) => {
|
||||
const item = tmpStr.split(':');
|
||||
totalSpace += item[1];
|
||||
const itemMeta = metaFactory.getMetaByKey('Item', item[0]);
|
||||
if (!itemMeta) {
|
||||
throw 'itemMeta is null' + this;
|
||||
}
|
||||
const nftType = itemMeta.getNftType();
|
||||
if (nftType == bcutils.NONE_TYPE) {
|
||||
throw 'itemMeta nft type is null' + this;
|
||||
}
|
||||
this._items.push({
|
||||
'space': totalSpace,
|
||||
'itemId': item[0],
|
||||
'tokenType': nftType
|
||||
});
|
||||
});
|
||||
if (!(totalSpace > 0)) {
|
||||
throw 'total not > 0' + this
|
||||
}
|
||||
this._totalSpace = totalSpace;
|
||||
}
|
||||
|
||||
randItem() {
|
||||
let item = null;
|
||||
item = {
|
||||
itemId: 3100,
|
||||
tokenType: bcutils.HERO_TYPE
|
||||
};
|
||||
return item;
|
||||
const rand = utils.randRange(0, this._totalSpace);
|
||||
for (let i in this._items) {
|
||||
const item = this_items[i];
|
||||
if (rand >= item['space']) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
getCount() {
|
||||
return 1;
|
||||
return this['quantity'];
|
||||
}
|
||||
|
||||
getTags() {
|
||||
return '1';
|
||||
return this['tags'];
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user