Rename ./fillwarehouse to ./fill and require a selected warehouse
The command now acts on the selected building and refuses anything whose blueprint is not a warehouse, or a warehouse that is not its city's active one, instead of using the city the player stands in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c616afa33b
commit
077dcc071d
2 files changed
+23
-15
No files matched your search
@@ -0,0 +1,105 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2026
|
||||
// https://www.magicbane.com
|
||||
|
||||
|
||||
package engine.devcmd.cmds;
|
||||
|
||||
import engine.devcmd.AbstractDevCmd;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.mbEnums;
|
||||
import engine.objects.AbstractGameObject;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.City;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.objects.Warehouse;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class FillCmd extends AbstractDevCmd {
|
||||
|
||||
public FillCmd() {
|
||||
super("fill");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _doCmd(PlayerCharacter pc, String[] words,
|
||||
AbstractGameObject target) {
|
||||
|
||||
Building building;
|
||||
City city;
|
||||
Warehouse warehouse;
|
||||
int amount = Integer.MAX_VALUE;
|
||||
HashMap<mbEnums.ResourceType, Integer> oldResources;
|
||||
|
||||
if (words.length > 1) {
|
||||
this.sendUsage(pc);
|
||||
return;
|
||||
}
|
||||
|
||||
if (words.length == 1 && !words[0].isEmpty()) {
|
||||
try {
|
||||
amount = Integer.parseInt(words[0]);
|
||||
} catch (NumberFormatException e) {
|
||||
throwbackError(pc, "Amount must be a number, " + words[0] + " is invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
if (amount < 0) {
|
||||
throwbackError(pc, "Amount must be 0 or more");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(target instanceof Building)) {
|
||||
throwbackError(pc, "Select a warehouse");
|
||||
return;
|
||||
}
|
||||
|
||||
building = (Building) target;
|
||||
|
||||
if (building.getBlueprint() == null || building.getBlueprint().getBuildingGroup() != mbEnums.BuildingGroup.WAREHOUSE) {
|
||||
throwbackError(pc, "Selected building is not a warehouse");
|
||||
return;
|
||||
}
|
||||
|
||||
city = building.getCity();
|
||||
|
||||
if (city == null || city.warehouse == null || city.warehouse.building != building) {
|
||||
throwbackError(pc, "Selected warehouse is not the active warehouse of a city");
|
||||
return;
|
||||
}
|
||||
|
||||
warehouse = city.warehouse;
|
||||
|
||||
oldResources = new HashMap<>(warehouse.resources);
|
||||
|
||||
for (mbEnums.ResourceType resourceType : mbEnums.ResourceType.values())
|
||||
warehouse.resources.put(resourceType, Math.min(amount, resourceType.deposit_limit));
|
||||
|
||||
if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
|
||||
warehouse.resources.putAll(oldResources);
|
||||
throwbackError(pc, "Failed to update the warehouse in the database");
|
||||
return;
|
||||
}
|
||||
|
||||
ChatManager.chatSayInfo(pc, "Filled the " + city.getCityName() + " warehouse"
|
||||
+ (amount == Integer.MAX_VALUE ? " to each deposit limit" : " with " + amount + " of each resource (capped at the deposit limit)"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getHelpString() {
|
||||
return "Sets every resource in the selected warehouse";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getUsageString() {
|
||||
return "' ./fill [amount]' with a warehouse selected (no amount fills each resource to its deposit limit)";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user