Merge pull request #12130 from Cyborger1/contract-overlay-fix-12124

Check diseased and dead states on the Farming Contract Indicator
This commit is contained in:
Jordan
2020-10-12 13:07:17 -07:00
committed by GitHub
3 changed files with 646 additions and 16 deletions

View File

@@ -82,9 +82,23 @@ class FarmingContractInfoBox extends InfoBox
contractColor = ColorScheme.PROGRESS_ERROR_COLOR;
break;
case IN_PROGRESS:
contractDescription = "Ready " + TabContentPanel.getFormattedEstimate(manager.getCompletionTime() - Instant.now().getEpochSecond(),
config.timeFormatMode());
contractColor = Color.GRAY;
CropState cropState = manager.getContractCropState();
switch (cropState)
{
case DISEASED:
contractDescription = "Diseased";
contractColor = cropState.getColor();
break;
case DEAD:
contractDescription = "Dead";
contractColor = cropState.getColor();
break;
default:
contractDescription = "Ready " + TabContentPanel.getFormattedEstimate(manager.getCompletionTime() - Instant.now().getEpochSecond(),
config.timeFormatMode());
contractColor = Color.GRAY;
break;
}
break;
case EMPTY:
case UNKNOWN:

View File

@@ -58,6 +58,9 @@ public class FarmingContractManager
@Getter
private SummaryState summary = SummaryState.UNKNOWN;
@Getter
private CropState contractCropState;
@Inject
private Client client;
@@ -229,7 +232,10 @@ public class FarmingContractManager
PatchImplementation patchImplementation = contract.getPatchImplementation();
boolean hasEmptyPatch = false;
boolean hasDiseasedPatch = false;
boolean hasDeadPatch = false;
completionTime = Long.MAX_VALUE;
contractCropState = null;
for (FarmingPatch patch : farmingWorld.getFarmingGuildRegion().getPatches())
{
if (patch.getImplementation() != patchImplementation)
@@ -244,43 +250,76 @@ public class FarmingContractManager
}
Produce produce = prediction.getProduce();
CropState state = prediction.getCropState();
if (completionTime == Long.MAX_VALUE)
{
if (produce == null || produce == Produce.WEEDS)
{
summary = SummaryState.EMPTY;
// Don't report the empty state if there's a dead or diseased one
if (!(hasDiseasedPatch || hasDeadPatch))
{
summary = SummaryState.EMPTY;
}
hasEmptyPatch = true;
continue;
}
if ((contract.requiresHealthCheck() && prediction.getCropState() == CropState.HARVESTABLE)
&& !hasEmptyPatch)
if ((contract.requiresHealthCheck() && state == CropState.HARVESTABLE)
&& !(hasEmptyPatch || hasDiseasedPatch || hasDeadPatch))
{
summary = SummaryState.OCCUPIED;
// Don't let this run into the "Completed" section!
continue;
}
}
if (produce != contract)
// Herbs always turn into ANYHERB when dead, so let them through.
if (produce != contract && produce != Produce.ANYHERB)
{
if (!hasEmptyPatch && completionTime == Long.MAX_VALUE)
if (!(hasEmptyPatch || hasDiseasedPatch || hasDeadPatch) && completionTime == Long.MAX_VALUE)
{
summary = SummaryState.OCCUPIED;
}
}
else
{
long estimatedTime = Math.min(prediction.getDoneEstimate(), completionTime);
if (estimatedTime <= Instant.now().getEpochSecond())
// Ignore if crop is dead but there's another one in progress (either normal or diseased)
if (state == CropState.DEAD && (hasDiseasedPatch || completionTime != Long.MAX_VALUE))
{
summary = SummaryState.COMPLETED;
completionTime = 0;
break;
continue;
}
// Ignore if crop is diseased but there's another patch in progress
if (state == CropState.DISEASED && completionTime != Long.MAX_VALUE)
{
continue;
}
contractCropState = state;
if (contractCropState == CropState.DISEASED)
{
hasDiseasedPatch = true;
summary = SummaryState.IN_PROGRESS;
}
else if (contractCropState == CropState.DEAD)
{
hasDeadPatch = true;
summary = SummaryState.IN_PROGRESS;
}
else
{
summary = SummaryState.IN_PROGRESS;
completionTime = estimatedTime;
long estimatedTime = Math.min(prediction.getDoneEstimate(), completionTime);
if (estimatedTime <= Instant.now().getEpochSecond())
{
summary = SummaryState.COMPLETED;
completionTime = 0;
break;
}
else
{
summary = SummaryState.IN_PROGRESS;
completionTime = estimatedTime;
}
}
}
}