使用物品接口完成
This commit is contained in:
parent
7d79d7b2b6
commit
ee917d08b4
@ -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;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -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{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(aitem.additionalcandidates){
|
||||||
lst = aitem.additionalcandidates.split('|');
|
lst = aitem.additionalcandidates.split('|');
|
||||||
lst.forEach((v: string) => {
|
lst.forEach((v: string) => {
|
||||||
let item = new ItemInfo(parseInt(v));
|
let n = parseInt(v);
|
||||||
|
if(n > 0){
|
||||||
|
let item = new ItemInfo(n);
|
||||||
if(!this._randexitems){
|
if(!this._randexitems){
|
||||||
this._randexitems = [item];
|
this._randexitems = [item];
|
||||||
}else{
|
}else{
|
||||||
this._randexitems.push(item);
|
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;
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user