Methods moved to better class.

This commit is contained in:
2024-03-13 14:11:53 -04:00
parent 0b68ae3960
commit b665d46dc3
3 changed files with 235 additions and 234 deletions
+181
View File
@@ -11,11 +11,15 @@ package engine.objects;
import engine.Enum;
import engine.InterestManagement.RealmMap;
import engine.InterestManagement.WorldGrid;
import engine.db.archive.DataWarehouse;
import engine.db.archive.RealmRecord;
import engine.gameManager.BuildingManager;
import engine.gameManager.DbManager;
import engine.gameManager.GuildManager;
import engine.gameManager.PowersManager;
import engine.net.ByteBufferWriter;
import engine.net.client.msg.ErrorPopupMsg;
import engine.powers.PowersBase;
import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger;
@@ -168,6 +172,183 @@ public class Realm {
}
public static boolean claimRealm(PlayerCharacter player, int charterUUID) {
Guild guild;
Realm realm;
City city;
Building tol;
float hPMod;
Warehouse warehouse;
boolean hasResources = true;
int resourceValue;
if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false) {
ErrorPopupMsg.sendErrorPopup(player, 176); // Only guild leaders can claim a territory
return false;
}
guild = player.getGuild();
city = guild.getOwnedCity();
if (city == null) {
ErrorPopupMsg.sendErrorPopup(player, 179); // Only landed guilds may claim a territory
return false;
}
if (city.isLocationOnCityGrid(player.getLoc()) == false) {
ErrorPopupMsg.sendErrorPopup(player, 186); // Your tree is not inside a territory!
return false;
}
tol = city.getTOL();
if (tol.getRank() != 7) {
ErrorPopupMsg.sendErrorPopup(player, 181); // Your tree must be rank 7 before claiming a territory
return false;
}
realm = RealmMap.getRealmForCity(city);
if (realm.getCanBeClaimed() == false) {
ErrorPopupMsg.sendErrorPopup(player, 180); // This territory cannot be ruled by anyone
return false;
}
if (realm.isRuled() == true) {
ErrorPopupMsg.sendErrorPopup(player, 178); // This territory is already claimed
return false;
}
if (!HasAllBlessings(player)) {
ErrorPopupMsg.sendErrorPopup(player, 185); // You must seek the blessing of the three sages before you can rule
return false;
}
// Must have the required resources in warehouse to claim realm
warehouse = city.getWarehouse();
if (warehouse == null) {
ErrorPopupMsg.sendErrorPopup(player, 188); // You must have a warehouse to become a capital
return false;
}
resourceValue = warehouse.resources.get(ItemBase.getItemBase(7));
if (resourceValue < 5000000)
hasResources = false;
resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580000));
if (resourceValue < 8000)
hasResources = false;
resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580004));
if (resourceValue < 8000)
hasResources = false;
resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580017));
if (resourceValue < 15)
hasResources = false;
resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580018));
if (resourceValue < 15)
hasResources = false;
if (hasResources == false) {
ErrorPopupMsg.sendErrorPopup(player, 184); // Insufficient gold or resources to upgrade to capital
return false;
}
// Remove resources from warehouse before claiming realm
resourceValue = warehouse.resources.get(ItemBase.getItemBase(7));
if (DbManager.WarehouseQueries.updateGold(warehouse, resourceValue - 5000000) == true) {
warehouse.resources.put(ItemBase.getItemBase(7), resourceValue - 5000000);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.GOLD, 5000000);
} else {
Logger.error("gold update failed for warehouse of UUID:" + warehouse.getObjectUUID());
return false;
}
resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580000));
if (DbManager.WarehouseQueries.updateStone(warehouse, resourceValue - 8000) == true) {
warehouse.resources.put(ItemBase.getItemBase(1580000), resourceValue - 8000);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.STONE, 8000);
} else {
Logger.error("stone update failed for warehouse of UUID:" + warehouse.getObjectUUID());
return false;
}
resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580004));
if (DbManager.WarehouseQueries.updateLumber(warehouse, resourceValue - 8000) == true) {
warehouse.resources.put(ItemBase.getItemBase(1580004), resourceValue - 8000);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.LUMBER, 8000);
} else {
Logger.error("lumber update failed for warehouse of UUID:" + warehouse.getObjectUUID());
return false;
}
resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580017));
if (DbManager.WarehouseQueries.updateGalvor(warehouse, resourceValue - 15) == true) {
warehouse.resources.put(ItemBase.getItemBase(1580017), resourceValue - 15);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.GALVOR, 15);
} else {
Logger.error("galvor update failed for warehouse of UUID:" + warehouse.getObjectUUID());
return false;
}
resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580018));
if (DbManager.WarehouseQueries.updateWormwood(warehouse, resourceValue - 15) == true) {
warehouse.resources.put(ItemBase.getItemBase(1580018), resourceValue - 15);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.WORMWOOD, 15);
} else {
Logger.error("wormwood update failed for warehouse of UUID:" + warehouse.getObjectUUID());
return false;
}
realm.claimRealmForCity(city, charterUUID);
BuildingManager.setRank(tol, 8);
WorldGrid.updateObject(tol);
for (Building building : city.getParent().zoneBuildingSet) {
if (building.getBlueprintUUID() != 0) {
// TOL Health set through regular linear equation
if (building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.TOL) {
continue;
}
hPMod = (building.getMaxHitPoints() * getRealmHealthMod(city));
building.setMaxHitPoints(building.getMaxHitPoints() + hPMod);
}
}
if (!guild.getNation().equals(guild)) {
guild.getNation().setRealmsOwned(guild.getNation().getRealmsOwned() + 1);
GuildManager.updateAllGuildTags(guild.getNation());
}
guild.setRealmsOwned(guild.getRealmsOwned() + 1);
GuildManager.updateAllGuildTags(guild);
AbstractCharacter.removeAllBlessings(player);
return true;
}
/*
* Getters
*/