Merge branch 'master' of git.kingsome.cn:node/card_info_svr

This commit is contained in:
zhl 2021-01-22 11:44:32 +08:00
commit a64781da95
3 changed files with 26 additions and 20 deletions

View File

@ -29,7 +29,7 @@ let ItemMan = {
let lst: CIC[] = []; let lst: CIC[] = [];
let reslst:ItemInfo[] = []; let reslst:ItemInfo[] = [];
return reslst; // return reslst;
this._useItem(obj, itemcount, false, lst); this._useItem(obj, itemcount, false, lst);
@ -112,7 +112,7 @@ let ItemMan = {
} }
if(pkg._randsubitems){ if(pkg._randsubitems){
for(let i = 0; i < count; i++){ for(let i = 0; i < count; i++){
let n = calcWeight(pkg._randsubitems, pkg._randsubtotalwh); let n = calcWeight(pkg._randsubitems);
let info = pkg._randsubitems[n]; let info = pkg._randsubitems[n];
if(!info){ if(!info){
//todo: //todo:
@ -213,8 +213,6 @@ let ItemMan = {
v._randsubitems.length = 0; v._randsubitems.length = 0;
} }
v._randsubtotalwh = 0;
let lst = []; let lst = [];
if(v._randsubtype == COMMON_ITEM_TYPE.CARD && v._randsubgrade){ if(v._randsubtype == COMMON_ITEM_TYPE.CARD && v._randsubgrade){
console.log('is card random:', v._randsubtype, v._randsubgrade); console.log('is card random:', v._randsubtype, v._randsubgrade);
@ -227,7 +225,6 @@ let ItemMan = {
lst && lst.forEach((element: CommonItem) => { lst && lst.forEach((element: CommonItem) => {
v._randsubitems.push(new ItemInfo(element._id, 1, element._weight)); v._randsubitems.push(new ItemInfo(element._id, 1, element._weight));
v._randsubtotalwh += element._weight;
}); });
v._randexitems && v._randexitems.forEach((item: ItemInfo) =>{ v._randexitems && v._randexitems.forEach((item: ItemInfo) =>{
@ -238,7 +235,6 @@ let ItemMan = {
obj.weight += item.weight; obj.weight += item.weight;
}else{ }else{
v._randsubitems.push(item); v._randsubitems.push(item);
v._randsubtotalwh += item.weight;
} }
}); });
} }

View File

@ -72,8 +72,6 @@ export class CommonItem{
public _randsubtype: number = 0; public _randsubtype: number = 0;
public _randsubgrade: number = 0; public _randsubgrade: number = 0;
public _randsubtotalwh: number = 0;
public _solidsubitems: ItemInfo[]; public _solidsubitems: ItemInfo[];
public _randexitems: ItemInfo[]; public _randexitems: ItemInfo[];
@ -137,15 +135,20 @@ export class CommonItem{
} }
}); });
lst = aitem.additionalcandidates.split('|'); if(aitem.additionalcandidates){
lst.forEach((v: string) => { lst = aitem.additionalcandidates.split('|');
let item = new ItemInfo(parseInt(v)); lst.forEach((v: string) => {
if(!this._randexitems){ let n = parseInt(v);
this._randexitems = [item]; if(n > 0){
}else{ let item = new ItemInfo(n);
this._randexitems.push(item); if(!this._randexitems){
} this._randexitems = [item];
}); }else{
this._randexitems.push(item);
}
}
});
}
}; };
isPackage(){ isPackage(){
@ -165,5 +168,6 @@ export class CIC{
constructor(aitem: CommonItem, acount: number = 1){ constructor(aitem: CommonItem, acount: number = 1){
this.item = aitem; this.item = aitem;
this.info = new ItemInfo(aitem? aitem._id: 0, acount, aitem? aitem._weight: 0); this.info = new ItemInfo(aitem? aitem._id: 0, acount, aitem? aitem._weight: 0);
this.info.type = aitem? aitem._type: 0;
}; };
} }

View File

@ -4,15 +4,21 @@
* @param {[array]} obj_vec [weight] * @param {[array]} obj_vec [weight]
* @return {[number]} [obj_vec数组索引] * @return {[number]} [obj_vec数组索引]
*/ */
export function calcWeight(obj_vec: any[], all_weight: number) { export function calcWeight(obj_vec: any[]) {
let all_weight = 0;
let wvec = [];
for (let obj of obj_vec) {
all_weight += Math.max(0, obj.weight);
wvec.push(all_weight);
}
if (all_weight <= 0) { if (all_weight <= 0) {
return 0; return 0;
} }
let ret = 0; let ret = 0;
let rand = Math.random() * all_weight; let rand = Math.random() * all_weight;
for (let i = 0; i < obj_vec.length; i++) { for (let i = 0; i < wvec.length; i++) {
if (rand < obj_vec[i].weight) { if (rand < wvec[i]) {
ret = i; ret = i;
break; break;
} }