|
|
@@ -67,18 +67,66 @@ async function tryCompound() {
|
|
|
cacheActivitData(activityId, activityData);
|
|
|
}
|
|
|
if(activityData){
|
|
|
+ let collection = activityData.collection;
|
|
|
+ // 固定材料
|
|
|
+ let enough = true;
|
|
|
+ let needList = collection.need;
|
|
|
+ for(let i=0; i < needList.length; i++){
|
|
|
+ let iData = needList[i];
|
|
|
+ if(iData.count_num < iData.need_num){
|
|
|
+ enough = false;
|
|
|
+ magicJS.notification.appendNotifyInfo(`❌缺少材料[${iData.title}](${iData.count_num}/${iData.need_num})!`);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!enough){
|
|
|
+ return;
|
|
|
+ }
|
|
|
let randomList = activityData.randomcollection;
|
|
|
let randomJson = [];
|
|
|
let randomId = [];
|
|
|
if(randomList.length > 0){
|
|
|
-
|
|
|
+ for(let i=0; i < randomList.length; i++){
|
|
|
+ let groupList = randomList[i];
|
|
|
+ let collectionGroup = i;
|
|
|
+ let collectionId = groupList[0].id;
|
|
|
+ let totalOwnNum = 0;
|
|
|
+ groupList.forEach(function(one){
|
|
|
+ totalOwnNum+=one.count_num;
|
|
|
+ });
|
|
|
+ if(totalOwnNum < groupList[0].nums){
|
|
|
+ enough = false;
|
|
|
+ magicJS.notification.appendNotifyInfo(`❌缺少材料[${groupList[0].id}](${totalOwnNum}/${groupList[0].nums})!`);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ let myCollectionList = await getMyCollectionList(collectionId);
|
|
|
+ if(myCollectionList.length >= totalOwnNum){
|
|
|
+ let groupCost = {
|
|
|
+ collection_id: collectionId,
|
|
|
+ collection_group: collectionGroup,
|
|
|
+ num: groupList[0].nums,
|
|
|
+ };
|
|
|
+ randomJson.push(groupCost);
|
|
|
+ for (let j = 0; j < totalOwnNum; j++) {
|
|
|
+ randomId.push(myCollectionList[i].collection_id);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ magicJS.notification.appendNotifyInfo(`❌缺少材料[${groupList[0].id}](${totalOwnNum}/${groupList[0].nums})!`);
|
|
|
+ enough = false;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!enough){
|
|
|
+ return;
|
|
|
}
|
|
|
- let result = await startCompound(activityId, '', JSON.stringify(randomJson), randomId);
|
|
|
+ let result = await startCompound(activityId, '', JSON.stringify(randomJson), JSON.stringify(randomId));
|
|
|
if(result){
|
|
|
magicJS.notification.appendNotifyInfo(`🎉合成活动[${activityId}]合成成功!`);
|
|
|
} else {
|
|
|
|
|
|
}
|
|
|
+ return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -99,6 +147,15 @@ async function getCompoundData(id){
|
|
|
return result.data;
|
|
|
}
|
|
|
|
|
|
+async function getMyCollectionList(collectionId, page=1, limit=999){
|
|
|
+ let reqData = {collection_id: collectionId, page: page, limit: limit};
|
|
|
+ let result = await hbRequest({API: '/api/collection/indexdetail', METHOD: 'get'}, reqData);
|
|
|
+ if(result.code != 1000){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return result.data;
|
|
|
+}
|
|
|
+
|
|
|
async function startCompound(id, token, randomJson, randomId){
|
|
|
let reqData = {id: `${id}`, token: token, random_json: randomJson, random_id: randomId};
|
|
|
let result = await hbRequest({API: '/api/randomcompound/compound', METHOD: 'post'}, reqData);
|