Merge branch 'master' of git.kingsome.cn:node/card_info_svr
This commit is contained in:
commit
a64781da95
@ -29,7 +29,7 @@ let ItemMan = {
|
||||
let lst: CIC[] = [];
|
||||
let reslst:ItemInfo[] = [];
|
||||
|
||||
return reslst;
|
||||
// return reslst;
|
||||
|
||||
this._useItem(obj, itemcount, false, lst);
|
||||
|
||||
@ -112,7 +112,7 @@ let ItemMan = {
|
||||
}
|
||||
if(pkg._randsubitems){
|
||||
for(let i = 0; i < count; i++){
|
||||
let n = calcWeight(pkg._randsubitems, pkg._randsubtotalwh);
|
||||
let n = calcWeight(pkg._randsubitems);
|
||||
let info = pkg._randsubitems[n];
|
||||
if(!info){
|
||||
//todo:
|
||||
@ -213,8 +213,6 @@ let ItemMan = {
|
||||
v._randsubitems.length = 0;
|
||||
}
|
||||
|
||||
v._randsubtotalwh = 0;
|
||||
|
||||
let lst = [];
|
||||
if(v._randsubtype == COMMON_ITEM_TYPE.CARD && v._randsubgrade){
|
||||
console.log('is card random:', v._randsubtype, v._randsubgrade);
|
||||
@ -227,7 +225,6 @@ let ItemMan = {
|
||||
|
||||
lst && lst.forEach((element: CommonItem) => {
|
||||
v._randsubitems.push(new ItemInfo(element._id, 1, element._weight));
|
||||
v._randsubtotalwh += element._weight;
|
||||
});
|
||||
|
||||
v._randexitems && v._randexitems.forEach((item: ItemInfo) =>{
|
||||
@ -238,7 +235,6 @@ let ItemMan = {
|
||||
obj.weight += item.weight;
|
||||
}else{
|
||||
v._randsubitems.push(item);
|
||||
v._randsubtotalwh += item.weight;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -72,8 +72,6 @@ export class CommonItem{
|
||||
public _randsubtype: number = 0;
|
||||
public _randsubgrade: number = 0;
|
||||
|
||||
public _randsubtotalwh: number = 0;
|
||||
|
||||
public _solidsubitems: ItemInfo[];
|
||||
|
||||
public _randexitems: ItemInfo[];
|
||||
@ -137,15 +135,20 @@ export class CommonItem{
|
||||
}
|
||||
});
|
||||
|
||||
lst = aitem.additionalcandidates.split('|');
|
||||
lst.forEach((v: string) => {
|
||||
let item = new ItemInfo(parseInt(v));
|
||||
if(!this._randexitems){
|
||||
this._randexitems = [item];
|
||||
}else{
|
||||
this._randexitems.push(item);
|
||||
}
|
||||
});
|
||||
if(aitem.additionalcandidates){
|
||||
lst = aitem.additionalcandidates.split('|');
|
||||
lst.forEach((v: string) => {
|
||||
let n = parseInt(v);
|
||||
if(n > 0){
|
||||
let item = new ItemInfo(n);
|
||||
if(!this._randexitems){
|
||||
this._randexitems = [item];
|
||||
}else{
|
||||
this._randexitems.push(item);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
isPackage(){
|
||||
@ -165,5 +168,6 @@ export class CIC{
|
||||
constructor(aitem: CommonItem, acount: number = 1){
|
||||
this.item = aitem;
|
||||
this.info = new ItemInfo(aitem? aitem._id: 0, acount, aitem? aitem._weight: 0);
|
||||
this.info.type = aitem? aitem._type: 0;
|
||||
};
|
||||
}
|
@ -4,15 +4,21 @@
|
||||
* @param {[array]} obj_vec [对象数组,对象中要有权重变量weight]
|
||||
* @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) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let ret = 0;
|
||||
let rand = Math.random() * all_weight;
|
||||
for (let i = 0; i < obj_vec.length; i++) {
|
||||
if (rand < obj_vec[i].weight) {
|
||||
for (let i = 0; i < wvec.length; i++) {
|
||||
if (rand < wvec[i]) {
|
||||
ret = i;
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user