()
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public void run() { |
| 45 | //投币最多操作数 解决csrf校验失败时死循环的问题 |
| 46 | int addCoinOperateCount = 0; |
| 47 | //安全检查,最多投币数 |
| 48 | final int maxNumberOfCoins = 5; |
| 49 | //获取自定义配置投币数 配置写在src/main/resources/taskConfig.json中 |
| 50 | int setCoin = ConfigLoader.helperConfig.getTaskConfig().getNumberOfCoins(); |
| 51 | // 预留硬币数 |
| 52 | int reserveCoins = ConfigLoader.helperConfig.getTaskConfig().getReserveCoins(); |
| 53 | |
| 54 | //已投的硬币 |
| 55 | int useCoin = TaskInfoHolder.expConfirm(); |
| 56 | //投币策略 |
| 57 | int coinAddPriority = ConfigLoader.helperConfig.getTaskConfig().getCoinAddPriority(); |
| 58 | |
| 59 | if (setCoin > maxNumberOfCoins) { |
| 60 | log.info("自定义投币数为: {}枚,为保护你的资产,自定义投币数重置为: " + maxNumberOfCoins + "枚", setCoin); |
| 61 | setCoin = maxNumberOfCoins; |
| 62 | } |
| 63 | |
| 64 | log.info("自定义投币数为: {}枚,程序执行前已投: {}枚", setCoin, useCoin); |
| 65 | |
| 66 | //调整投币数 设置投币数-已经投过的硬币数 |
| 67 | int needCoins = setCoin - useCoin; |
| 68 | |
| 69 | //投币前硬币余额 |
| 70 | Double beforeAddCoinBalance = OftenApi.getCoinBalance(); |
| 71 | int coinBalance = (int) Math.floor(beforeAddCoinBalance); |
| 72 | |
| 73 | |
| 74 | if (needCoins <= 0) { |
| 75 | log.info("已完成设定的投币任务,今日无需再投币了"); |
| 76 | return; |
| 77 | } else { |
| 78 | log.info("投币数调整为: {}枚", needCoins); |
| 79 | //投币数大于余额时,按余额投 |
| 80 | if (needCoins > coinBalance) { |
| 81 | log.info("完成今日设定投币任务还需要投: {}枚硬币,但是余额只有: {}", needCoins, beforeAddCoinBalance); |
| 82 | log.info("投币数调整为: {}", coinBalance); |
| 83 | needCoins = coinBalance; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | if (coinBalance < reserveCoins) { |
| 88 | log.info("剩余硬币数为{},低于预留硬币数{},今日不再投币", beforeAddCoinBalance, reserveCoins); |
| 89 | log.info("tips: 当硬币余额少于你配置的预留硬币数时,则会暂停当日投币任务"); |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | log.info("投币前余额为 : {}", beforeAddCoinBalance); |
| 94 | /* |
| 95 | * 请勿修改 max_numberOfCoins 这里多判断一次保证投币数超过5时 不执行投币操作. |
| 96 | * 最后一道安全判断,保证即使前面的判断逻辑错了,也不至于发生投币事故. |
| 97 | */ |
| 98 | while (needCoins > 0 && needCoins <= maxNumberOfCoins) { |
| 99 | String bvid; |
| 100 | if (coinAddPriority == 1 && addCoinOperateCount < 7) { |
nothing calls this directly
no test coverage detected