farming: Fix contract status for plots with diseased/dead crops
This commit fixes the farming contract manager's behavior when encountering crops which have become diseased. Previously, it would not take this into account and incorrectly report the crop as IN_PROGRESS or READY.
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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,17 +250,22 @@ 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!
|
||||
@@ -262,27 +273,53 @@ public class FarmingContractManager
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user