2018-10-30 06:15:08 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Baritone.
|
|
|
|
*
|
|
|
|
* Baritone is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Baritone is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-10-31 01:30:44 +00:00
|
|
|
package tenor.game;
|
|
|
|
|
|
|
|
import tenor.*;
|
2018-10-30 06:15:08 +00:00
|
|
|
|
2018-10-31 20:30:37 +00:00
|
|
|
public class AquireCraftingItems extends QuantizedTaskNode implements IClaimProvider, ISingleParentQuantizedPriorityAllocator {
|
2018-10-30 20:51:19 +00:00
|
|
|
|
2018-10-30 22:05:17 +00:00
|
|
|
final CraftingTask parent;
|
2018-10-30 18:51:49 +00:00
|
|
|
|
2018-10-30 22:05:17 +00:00
|
|
|
public AquireCraftingItems(CraftingTask parent) {
|
2018-10-30 18:51:49 +00:00
|
|
|
super(DependencyType.PARALLEL_ALL);
|
2018-10-30 22:05:17 +00:00
|
|
|
this.parent = parent;
|
2018-10-30 22:31:00 +00:00
|
|
|
addParent(parent);
|
2018-10-30 18:51:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double priorityAllocatedTo(IQuantizedParentTaskRelationship child, int quantity) {
|
|
|
|
AquireItemTask resource = (AquireItemTask) child.childTask(); // all our dependents are aquire item tasks
|
2018-10-30 22:05:17 +00:00
|
|
|
int amount = parent.inputSizeFor(resource);
|
2018-10-30 18:51:49 +00:00
|
|
|
|
|
|
|
// they could provide us with quantity
|
|
|
|
int actualQuantity = (int) Math.ceil(quantity * 1.0D / amount);
|
|
|
|
// so we could do the crafting recipe this many times
|
2018-10-31 00:42:58 +00:00
|
|
|
// how good would that be?
|
2018-10-30 18:51:49 +00:00
|
|
|
return priority().value(actualQuantity);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-10-30 20:51:19 +00:00
|
|
|
public IQuantityRelationship cost() {
|
2018-10-30 22:05:17 +00:00
|
|
|
return x -> {
|
|
|
|
// cost to get x copies of these items
|
|
|
|
double sum = 0;
|
2018-10-30 22:44:52 +00:00
|
|
|
for (IQuantizedParentTaskRelationship resource : childTasks()) {
|
2018-10-30 22:05:17 +00:00
|
|
|
int amountPerCraft = parent.inputSizeFor((AquireItemTask) resource.childTask());
|
|
|
|
int totalAmountNeeded = x * amountPerCraft;
|
|
|
|
|
2018-10-30 22:44:52 +00:00
|
|
|
int amountForUs = ((IQuantizedChildTaskRelationship) resource).quantityCompleted();
|
2018-10-30 22:05:17 +00:00
|
|
|
totalAmountNeeded -= amountForUs;
|
|
|
|
|
|
|
|
if (totalAmountNeeded <= 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
sum += resource.cost().value(totalAmountNeeded);
|
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
};
|
2018-10-30 18:51:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int quantityCompletedForParent(IQuantizedChildTaskRelationship relationship) {
|
2018-10-30 22:31:00 +00:00
|
|
|
if (relationship != parentTasks().get(0)) {
|
2018-10-30 22:05:17 +00:00
|
|
|
throw new IllegalStateException();
|
|
|
|
}
|
2018-10-30 18:51:49 +00:00
|
|
|
// our only parent is the crafting task
|
|
|
|
int minCompletion = Integer.MAX_VALUE;
|
2018-10-30 22:44:52 +00:00
|
|
|
for (IQuantizedParentTaskRelationship resource : childTasks()) {
|
|
|
|
int amountForUs = ((IQuantizedChildTaskRelationship) resource).quantityCompleted();
|
2018-10-30 18:51:49 +00:00
|
|
|
|
2018-10-30 22:05:17 +00:00
|
|
|
int amountPerCraft = parent.inputSizeFor((AquireItemTask) resource.childTask());
|
2018-10-30 18:51:49 +00:00
|
|
|
|
|
|
|
int actualQuantity = (int) Math.ceil(amountForUs * 1.0D / amountPerCraft);
|
|
|
|
|
|
|
|
if (actualQuantity < minCompletion || minCompletion == Integer.MAX_VALUE) {
|
|
|
|
minCompletion = actualQuantity; // any missing ingredient and we aren't really done
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return minCompletion;
|
|
|
|
}
|
2018-10-30 06:15:08 +00:00
|
|
|
}
|