1
This commit is contained in:
parent
1c7b728d27
commit
6a78f31a13
@ -1,97 +0,0 @@
|
||||
const assert = require('assert');
|
||||
const utils = require('j7/utils');
|
||||
const bcutils = require('j7/bcutils');
|
||||
const basewrap = require('./basewrap');
|
||||
const factory = require('./factory');
|
||||
|
||||
const HERO_TYPE = 3;
|
||||
const GUN_TYPE = 7;
|
||||
const MATERIAL_TYPE = 10;
|
||||
const BLIND_BOX_TYPE = 12;
|
||||
|
||||
const CHIP_TYPE = 13;
|
||||
|
||||
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;
|
||||
case CHIP_TYPE:
|
||||
{
|
||||
return bcutils.CHIP_TYPE;
|
||||
}
|
||||
break;
|
||||
case BLIND_BOX_TYPE:
|
||||
{
|
||||
return bcutils.BLIND_BOX_TYPE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
return bcutils.NONE_TYPE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return bcutils.NONE_TYPE;
|
||||
}
|
||||
|
||||
static randHero(transId) {
|
||||
const val = Math.abs(utils.crc32Str(transId));
|
||||
const heros = [
|
||||
30100,
|
||||
30200,
|
||||
30300,
|
||||
30400,
|
||||
30500,
|
||||
30600,
|
||||
30700,
|
||||
30800,
|
||||
30900,
|
||||
31000
|
||||
];
|
||||
return heros[val % heros.length];
|
||||
}
|
||||
|
||||
static randGun(transId) {
|
||||
const val = Math.abs(utils.crc32Str(transId));
|
||||
const guns = [
|
||||
70001,
|
||||
70002,
|
||||
70003,
|
||||
70004,
|
||||
70005,
|
||||
70006,
|
||||
70007
|
||||
];
|
||||
return guns[val % guns.length];
|
||||
}
|
||||
|
||||
randLuckBox(tokenType) {
|
||||
const itemId = factory.callMetaStatic('LuckyBox', 'randLuckBox', this['id'], tokenType);
|
||||
assert(itemId > 0);
|
||||
return itemId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = Item;
|
@ -1,52 +0,0 @@
|
||||
const assert = require('assert');
|
||||
const utils = require('j7/utils');
|
||||
const bcutils = require('j7/bcutils');
|
||||
const basewrap = require('./basewrap');
|
||||
|
||||
class LuckyBox extends basewrap.BaseWrap {
|
||||
|
||||
static idTypeHash = {
|
||||
|
||||
}
|
||||
|
||||
_init0(factory) {
|
||||
const key = this['box_id'] + '_' + this['type'];
|
||||
if (!utils.hasKey(LuckyBox.idTypeHash, key)) {
|
||||
LuckyBox.idTypeHash[key] = {
|
||||
'total_space': 0,
|
||||
'items': []
|
||||
};
|
||||
}
|
||||
assert(this['weight'] > 0);
|
||||
LuckyBox.idTypeHash[key]['total_space'] += this['weight'];
|
||||
LuckyBox.idTypeHash[key]['items'].push({
|
||||
'space': LuckyBox.idTypeHash[key]['total_space'],
|
||||
'meta': this
|
||||
});
|
||||
const itemMeta = factory.getMetaByKey('Item', this['item_id']);
|
||||
assert(itemMeta);
|
||||
assert(itemMeta.getNftType() != bcutils.NONE_TYPE);
|
||||
assert(itemMeta.getNftType() == this['type']);
|
||||
}
|
||||
|
||||
static randLuckBox(boxId, tokenType) {
|
||||
const key = boxId + '_' + tokenType;
|
||||
if (!utils.hasKey(LuckyBox.idTypeHash, key)) {
|
||||
console.log(1111, key);
|
||||
return 0;
|
||||
}
|
||||
const data = LuckyBox.idTypeHash[key];
|
||||
assert(data['total_space'] > 0);
|
||||
const rand = utils.randRange(0, data['total_space'] - 1);
|
||||
for (let i in data['items']) {
|
||||
const item = data['items'][i];
|
||||
if (rand < item['space']) {
|
||||
return item['meta']['item_id'];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = LuckyBox;
|
@ -1,57 +0,0 @@
|
||||
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(':');
|
||||
item[1] = parseInt(item[1]);
|
||||
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() {
|
||||
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 this['quantity'];
|
||||
}
|
||||
|
||||
getTags() {
|
||||
return this['tags'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = Present;
|
@ -1,8 +0,0 @@
|
||||
const utils = require('j7/utils');
|
||||
const basewrap = require('./basewrap');
|
||||
|
||||
class PresentList extends basewrap.BaseWrap {
|
||||
|
||||
}
|
||||
|
||||
module.exports = PresentList;
|
@ -113,20 +113,6 @@ function init() {
|
||||
'',
|
||||
'GameDb'
|
||||
);
|
||||
registerMetaClass(configDir + 'present_list.json',
|
||||
'',
|
||||
'PresentList'
|
||||
);
|
||||
|
||||
registerMetaClass(resDir + 'item@item.json',
|
||||
'id',
|
||||
'Item'
|
||||
);
|
||||
registerMetaClass(resDir + 'luckyBox@luckyBox.json',
|
||||
'id',
|
||||
'LuckyBox'
|
||||
);
|
||||
|
||||
load();
|
||||
{
|
||||
const classList = [];
|
||||
|
Loading…
x
Reference in New Issue
Block a user