Skip to content

Commit

Permalink
增加部分功能,修复文字信息变更导致施肥失败的问题。配置文件恢复支持两种模式。
Browse files Browse the repository at this point in the history
  • Loading branch information
constanline committed Jun 20, 2024
1 parent 4ec8b83 commit c46c3f6
Show file tree
Hide file tree
Showing 12 changed files with 196 additions and 23 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
minSdk 21
//noinspection ExpiredTargetSdkVersion
targetSdk 29
versionCode 71
versionName "1.2.3-beta18"
versionCode 73
versionName "1.2.4"
}
buildTypes {
release {
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/pansong291/xposed/quickenergy/AntFarm.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ public void run() {
if (Config.sendBackAnimal())
sendBackAnimal();

Log.farm("小鸡animalInteractStatus" + ownerAnimal.animalInteractStatus);
Log.farm("小鸡locationType" + ownerAnimal.locationType);
if (!AnimalInteractStatus.HOME.name().equals(ownerAnimal.animalInteractStatus)) {
if ("ORCHARD".equals(ownerAnimal.locationType)) {
Log.farm("小鸡到好友家除草了" );
Expand Down
91 changes: 90 additions & 1 deletion app/src/main/java/pansong291/xposed/quickenergy/AntForest.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,15 @@ public void run() {
if (Config.userPatrol()) {
UserPatrol();
}
if (Config.ExchangeEnergyDoubleClick() && Statistics.canExchangeDoubleCardToday()) {
if (Config.exchangeEnergyDoubleClick() && Statistics.canExchangeDoubleCardToday()) {
int exchangeCount = Config.getExchangeEnergyDoubleClickCount();
exchangeEnergyDoubleClick(exchangeCount);
}
if (Config.exchangeEnergyShield()) {
exchangeEnergyShield();
}
sendEnergyByAction("GREEN_LIFE");
sendEnergyByAction("ANTFOREST");
}

PluginUtils.invoke(AntForest.class, PluginUtils.PluginAction.STOP);
Expand Down Expand Up @@ -1829,6 +1834,90 @@ private static void combineAnimalPiece(int animalId) {
}
}

private static void sendEnergyByAction(String sourceType) {
try {
JSONObject jo = new JSONObject(AntForestRpcCall.consultForSendEnergyByAction(sourceType));
if (jo.getBoolean("success")) {
JSONObject data = jo.getJSONObject("data");
if (data.optBoolean("canSendEnergy", false)) {
jo = new JSONObject(AntForestRpcCall.sendEnergyByAction(sourceType));
if (jo.getBoolean("success")) {
data = jo.getJSONObject("data");
if (data.optBoolean("canSendEnergy", false)) {
int receivedEnergyAmount = data.getInt("receivedEnergyAmount");
Log.forest("集市逛街👀[能量" + receivedEnergyAmount + "g]");
}
}
}
} else {
Log.i(TAG, jo.getJSONObject("data").getString("resultCode"));
}
} catch (Throwable t) {
Log.i(TAG, "sendEnergyByAction err:");
Log.printStackTrace(TAG, t);
}
}

private static void exchangeEnergyShield() {
try {
String s = AntForestRpcCall.itemList("SC_ASSETS");
JSONObject jo = new JSONObject(s);
String skuId = null;
String spuId = null;
double price = 0d;
if (jo.getBoolean("success")) {
JSONArray itemInfoVOList = jo.optJSONArray("itemInfoVOList");
if (itemInfoVOList != null && itemInfoVOList.length() > 0) {
for (int i = 0; i < itemInfoVOList.length(); i++) {
jo = itemInfoVOList.getJSONObject(i);
if ("能量保护罩".equals(jo.getString("spuName"))) {
spuId = jo.getString("spuId");
jo = new JSONObject(AntForestRpcCall.itemDetail(spuId));
if (jo.getBoolean("success")) {
JSONObject spuItemInfoVO = jo.getJSONObject("spuItemInfoVO");
JSONArray skuModelList = spuItemInfoVO.getJSONArray("skuModelList");
for (int j = 0; j < skuModelList.length(); j++) {
jo = skuModelList.getJSONObject(j);
if ("VITALITY_ENERGY_SHIELD_NO_EXPIRE_2023"
.equals(jo.getString("rightsConfigId"))) {
if (!jo.has("skuRuleResult")) {
skuId = jo.getString("skuId");
price = jo.getJSONObject("price").getDouble("amount");
}
break;
}
}
}
break;
}
}
}
if (skuId != null && spuId != null) {
jo = new JSONObject(AntForestRpcCall.queryVitalityStoreIndex());
if ("SUCCESS".equals(jo.getString("resultCode"))) {
int totalVitalityAmount = jo.getJSONObject("userVitalityInfoVO")
.getInt("totalVitalityAmount");
if (totalVitalityAmount > price) {
jo = new JSONObject(AntForestRpcCall.exchangeBenefit(spuId, skuId));
if ("SUCCESS".equals(jo.getString("resultCode"))) {
Log.forest("活力兑换🎐[永久保护罩]");
} else {
Log.recordLog(jo.getString("resultDesc"), jo.toString());
}
} else {
Log.recordLog("活力值不足,停止兑换!", "");
}
}
}
} else {
Log.recordLog(jo.getString("desc"), s);
}
} catch (Throwable t) {
Log.i(TAG, "exchangeEnergyShield err:");
Log.printStackTrace(TAG, t);
}
}

/**
* Execute.
*
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/java/pansong291/xposed/quickenergy/AntOrchard.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,16 @@ private static String getWua() {
return "null";
}

private static boolean canSpreadManureContinue(String stageBefore, String stageAfter) {
Double bef = Double.parseDouble(StringUtil.getSubString(stageBefore, "施肥", "%"));
Double aft = Double.parseDouble(StringUtil.getSubString(stageAfter, "施肥", "%"));
if (bef - aft != 0.01)
private static boolean canSpreadManureContinue(int stageBefore, int stageAfter) {
if (stageAfter - stageBefore > 1) {
return true;
}
Log.recordLog("施肥只加0.01%进度今日停止施肥!");
return false;
}

private static void orchardSpreadManure() {
try {
try {
JSONObject jo = new JSONObject(AntOrchardRpcCall.orchardIndex());
if ("100".equals(jo.getString("resultCode"))) {
if (jo.has("spreadManureActivity")) {
Expand All @@ -126,7 +125,7 @@ private static void orchardSpreadManure() {
return;
}
JSONObject seedStage = plantInfo.getJSONObject("seedStage");
String stageBefore = seedStage.getString("stageText");
int totalValueBefore = seedStage.getInt("totalValue");
treeLevel = Integer.toString(seedStage.getInt("stageLevel"));
JSONObject accountInfo = jo.getJSONObject("gameInfo").getJSONObject("accountInfo");
int happyPoint = Integer.parseInt(accountInfo.getString("happyPoint"));
Expand All @@ -138,9 +137,10 @@ private static void orchardSpreadManure() {
if ("100".equals(jo.getString("resultCode"))) {
taobaoData = jo.getString("taobaoData");
jo = new JSONObject(taobaoData);
String stageAfter = jo.getJSONObject("currentStage").getString("stageText");
Log.farm("农场施肥💩[" + stageAfter + "]");
if (!canSpreadManureContinue(stageBefore, stageAfter)) {
String stageText = jo.getJSONObject("currentStage").getString("stageText");
int totalValueAfter = jo.getJSONObject("currentStage").getInt("totalValue");
Log.farm("农场施肥💩[" + stageText + "]");
if (!canSpreadManureContinue(totalValueBefore, totalValueAfter)) {
Statistics.spreadManureToday(userId);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,13 @@ public static String collectFriendGiftBox(String targetId, String targetUserId)
"[{\"source\":\"chInfo_ch_appcenter__chsub_9patch\",\"targetId\":\"" + targetId
+ "\",\"targetUserId\":\"" + targetUserId + "\"}]");
}
public static String consultForSendEnergyByAction(String sourceType) {
return RpcUtil.request("alipay.bizfmcg.greenlife.consultForSendEnergyByAction",
"[{\"sourceType\":\"" + sourceType + "\"}]");
}

public static String sendEnergyByAction(String sourceType) {
return RpcUtil.request("alipay.bizfmcg.greenlife.sendEnergyByAction",
"[{\"actionType\":\"GOODS_BROWSE\",\"requestId\":\"" + RandomUtils.getRandom(8) + "\",\"sourceType\":\"" + sourceType + "\"}]");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
Expand All @@ -14,8 +13,6 @@
import android.widget.TabHost;
import android.widget.Toast;

import java.util.Locale;

import pansong291.xposed.quickenergy.R;
import pansong291.xposed.quickenergy.entity.*;
import pansong291.xposed.quickenergy.util.*;
Expand Down Expand Up @@ -47,7 +44,7 @@ public class SettingsActivity extends Activity {
sw_enableStall, sw_stallAutoClose, sw_stallAutoOpen, sw_stallAutoTask, sw_stallReceiveAward,
sw_stallOpenType, sw_stallDonate, sw_chickenDiary, sw_collectGiftBox, sw_stallInviteRegister,
sw_stallThrowManure, sw_greenFinance, sw_totalCertCount, sw_batchRobEnergy, sw_antBookRead, sw_consumeGold,
sw_omegakoiTown, sw_language_simplified_chinese, sw_special_food;
sw_omegakoiTown, sw_language_simplified_chinese, sw_special_food, sw_ExchangeEnergyShield;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -207,6 +204,7 @@ private void initSwitch() {
sw_limitCollect = findViewById(R.id.sw_limitCollect);
sw_doubleCard = findViewById(R.id.sw_doubleCard);
sw_ExchangeEnergyDoubleClick = findViewById(R.id.sw_ExchangeEnergyDoubleClick);
sw_ExchangeEnergyShield = findViewById(R.id.sw_ExchangeEnergyShield);
sw_ecoLifeTick = findViewById(R.id.sw_ecoLifeTick);
sw_tiyubiz = findViewById(R.id.sw_tiyubiz);
sw_insBlueBeanExchange = findViewById(R.id.sw_insBlueBeanExchange);
Expand Down Expand Up @@ -286,7 +284,8 @@ protected void onResume() {
sw_kbSignIn.setChecked(Config.kbSginIn());
sw_limitCollect.setChecked(Config.isLimitCollect());
sw_doubleCard.setChecked(Config.doubleCard());
sw_ExchangeEnergyDoubleClick.setChecked(Config.ExchangeEnergyDoubleClick());
sw_ExchangeEnergyDoubleClick.setChecked(Config.exchangeEnergyDoubleClick());
sw_ExchangeEnergyShield.setChecked(Config.exchangeEnergyShield());
sw_ecoLifeTick.setChecked(Config.ecoLifeTick());
sw_tiyubiz.setChecked(Config.tiyubiz());
sw_insBlueBeanExchange.setChecked(Config.insBlueBeanExchange());
Expand Down Expand Up @@ -407,6 +406,10 @@ public void onClick(View v) {
Config.setExchangeEnergyDoubleClick(sw.isChecked());
break;

case R.id.sw_ExchangeEnergyShield:
Config.setExchangeEnergyShield(sw.isChecked());
break;

case R.id.sw_reserve:
Config.setReserve(sw.isChecked());
break;
Expand Down
34 changes: 33 additions & 1 deletion app/src/main/java/pansong291/xposed/quickenergy/util/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ public CharSequence nickName() {

private boolean exchangeEnergyDoubleClick;
private int exchangeEnergyDoubleClickCount;
private boolean exchangeEnergyShield;
private int exchangeEnergyShieldCount;
private boolean antdodoCollect;
private boolean antOcean;
private boolean userPatrol;
Expand Down Expand Up @@ -705,7 +707,7 @@ public static boolean energyRain() {
return getConfig().energyRain;
}

public static boolean ExchangeEnergyDoubleClick() {
public static boolean exchangeEnergyDoubleClick() {
return getConfig().exchangeEnergyDoubleClick;
}

Expand All @@ -723,6 +725,24 @@ public static void setExchangeEnergyDoubleClickCount(int i) {
hasChanged = true;
}


public static boolean exchangeEnergyShield() {
return getConfig().exchangeEnergyShield;
}

public static void setExchangeEnergyShield(boolean b) {
getConfig().exchangeEnergyShield = b;
hasChanged = true;
}

public static int getExchangeEnergyShieldCount() {
return getConfig().exchangeEnergyShieldCount;
}

public static void setExchangeEnergyShieldCount(int i) {
getConfig().exchangeEnergyShieldCount = i;
hasChanged = true;
}
public static void setAncientTreeOnlyWeek(boolean b) {
getConfig().ancientTreeOnlyWeek = b;
hasChanged = true;
Expand Down Expand Up @@ -1445,6 +1465,8 @@ public static Config defInit() {
c.giveEnergyRainList = new ArrayList<>();
c.exchangeEnergyDoubleClick = false;
c.exchangeEnergyDoubleClickCount = 6;
c.exchangeEnergyShield = false;
c.exchangeEnergyShieldCount = 6;
c.ancientTreeOnlyWeek = true;
c.antdodoCollect = true;
c.antOcean = true;
Expand Down Expand Up @@ -1765,6 +1787,12 @@ public static Config json2Config(String json) {
config.exchangeEnergyDoubleClickCount = jo.optInt("exchangeEnergyDoubleClickCount", 6);
Log.i(TAG, "exchangeEnergyDoubleClickCount" + ":" + config.exchangeEnergyDoubleClickCount);

config.exchangeEnergyShield = jo.optBoolean("exchangeEnergyShield", false);
Log.i(TAG, "exchangeEnergyShield" + ":" + config.exchangeEnergyShield);

config.exchangeEnergyShieldCount = jo.optInt("exchangeEnergyShieldCount", 6);
Log.i(TAG, "exchangeEnergyShieldCount" + ":" + config.exchangeEnergyShieldCount);

config.ancientTreeOnlyWeek = jo.optBoolean(jn_ancientTreeOnlyWeek, true);
//Log.i(TAG, jn_ancientTreeOnlyWeek + ":" + config.ancientTreeOnlyWeek);

Expand Down Expand Up @@ -2201,6 +2229,10 @@ public static String config2Json(Config config) {

jo.put("exchangeEnergyDoubleClickCount", config.exchangeEnergyDoubleClickCount);

jo.put("exchangeEnergyShield", config.exchangeEnergyShield);

jo.put("exchangeEnergyShieldCount", config.exchangeEnergyShieldCount);

jo.put(jn_ancientTreeOnlyWeek, config.ancientTreeOnlyWeek);

jo.put(jn_antdodoCollect, config.antdodoCollect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ public static File getMainDirectoryFile() {
if (!storageDir.exists()) {
storageDir.mkdirs();
}
String storageDirStr = Environment.getExternalStorageDirectory() + File.separator + "Android" +
File.separator + "media" + File.separator + ClassMember.PACKAGE_NAME;
storageDir = new File(storageDirStr);
File useMedia = new File(storageDir, "useMedia");
if (useMedia.exists()) {
String storageDirStr = Environment.getExternalStorageDirectory() + File.separator + "Android" +
File.separator + "media" + File.separator + ClassMember.PACKAGE_NAME;
storageDir = new File(storageDirStr);
}

mainDirectory = new File(storageDir, "xqe");
if (!mainDirectory.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ public StallHelpedCountLog(String id) {
private ArrayList<String> protectBubbleList;
private int exchangeDoubleCard = 0;
private int exchangeTimes = 0;
private int exchangeShieldCard = 0;
private int exchangeShieldTimes = 0;
private int doubleTimes = 0;

// farm
Expand Down Expand Up @@ -664,6 +666,13 @@ public static boolean canExchangeDoubleCardToday() {
} else return stat.exchangeTimes < Config.getExchangeEnergyDoubleClickCount();
}

public static boolean canExchangeShieldCardToday() {
Statistics stat = getStatistics();
if (stat.exchangeShieldCard < stat.day.time) {
return true;
} else return stat.exchangeShieldTimes < Config.getExchangeEnergyShieldCount();
}

public static void exchangeDoubleCardToday(boolean isSuccess) {
Statistics stat = getStatistics();
if (stat.exchangeDoubleCard != stat.day.time) {
Expand All @@ -677,11 +686,29 @@ public static void exchangeDoubleCardToday(boolean isSuccess) {
save();
}

public static void exchangeShieldToday(boolean isSuccess) {
Statistics stat = getStatistics();
if (stat.exchangeShieldCard != stat.day.time) {
stat.exchangeShieldCard = stat.day.time;
}
if (isSuccess) {
stat.exchangeShieldTimes += 1;
} else {
stat.exchangeShieldTimes = Config.getExchangeEnergyShieldCount();
}
save();
}

public static int getExchangeTimes() {
Statistics stat = getStatistics();
return stat.exchangeTimes;
}

public static int getExchangeShieldTimes() {
Statistics stat = getStatistics();
return stat.exchangeShieldTimes;
}

public static boolean canDoubleToday() {
Statistics stat = getStatistics();
return stat.doubleTimes < Config.getDoubleCountLimit();
Expand Down
Loading

0 comments on commit c46c3f6

Please sign in to comment.