(body, buildList, type = true)
| 929 | |
| 930 | // 升级建筑 |
| 931 | async function getBuildInfo(body, buildList, type = true) { |
| 932 | let twobody = body |
| 933 | return new Promise(async (resolve) => { |
| 934 | $.get(taskUrl(`user/GetBuildInfo`, body), async (err, resp, data) => { |
| 935 | try { |
| 936 | if (err) { |
| 937 | console.log(`${JSON.stringify(err)}`) |
| 938 | console.log(`${$.name} GetBuildInfo API请求失败,请检查网路重试`) |
| 939 | } else { |
| 940 | data = JSON.parse(data.replace(/\n/g, "").match(new RegExp(/jsonpCBK.?\((.*);*\)/))[1]); |
| 941 | if (type) { |
| 942 | let buildNmae; |
| 943 | switch(buildList.strBuildIndex) { |
| 944 | case 'food': |
| 945 | buildNmae = '京喜美食城' |
| 946 | break |
| 947 | case 'sea': |
| 948 | buildNmae = '京喜旅馆' |
| 949 | break |
| 950 | case 'shop': |
| 951 | buildNmae = '京喜商店' |
| 952 | break |
| 953 | case 'fun': |
| 954 | buildNmae = '京喜游乐场' |
| 955 | default: |
| 956 | break |
| 957 | } |
| 958 | if (data.dwBuildLvl === 0) { |
| 959 | console.log(`创建建筑`) |
| 960 | console.log(`【${buildNmae}】当前建筑还未创建,开始创建`) |
| 961 | await createbuilding(`strBuildIndex=${data.strBuildIndex}`, buildNmae) |
| 962 | await $.wait(3000) |
| 963 | data = await getBuildInfo(twobody, buildList, false) |
| 964 | await $.wait(3000) |
| 965 | } |
| 966 | console.log(`收金币`) |
| 967 | const body = `strBuildIndex=${data.strBuildIndex}&dwType=1` |
| 968 | let collectCoinRes = await collectCoin(body) |
| 969 | console.log(`【${buildNmae}】收集${collectCoinRes.ddwCoin}金币`) |
| 970 | await $.wait(3000) |
| 971 | await getUserInfo(false) |
| 972 | console.log(`升级建筑`) |
| 973 | console.log(`【${buildNmae}】当前等级:${buildList.dwLvl}`) |
| 974 | console.log(`【${buildNmae}】升级需要${data.ddwNextLvlCostCoin}金币,保留升级需要的3倍${data.ddwNextLvlCostCoin * 3}金币,当前拥有${$.info.ddwCoinBalance}金币`) |
| 975 | if(data.dwCanLvlUp > 0 && $.info.ddwCoinBalance >= (data.ddwNextLvlCostCoin * 3)) { |
| 976 | console.log(`【${buildNmae}】满足升级条件,开始升级`) |
| 977 | const body = `strBuildIndex=${data.strBuildIndex}&ddwCostCoin=${data.ddwNextLvlCostCoin}` |
| 978 | await $.wait(3000) |
| 979 | let buildLvlUpRes = await buildLvlUp(body) |
| 980 | if (buildLvlUpRes.iRet === 0) { |
| 981 | console.log(`【${buildNmae}】升级成功:获得${data.ddwLvlRich}财富\n`) |
| 982 | } else { |
| 983 | console.log(`【${buildNmae}】升级失败:${buildLvlUpRes.sErrMsg}\n`) |
| 984 | } |
| 985 | } else { |
| 986 | console.log(`【${buildNmae}】不满足升级条件,跳过升级\n`) |
| 987 | } |
| 988 | } |
no test coverage detected