diff --git a/src/engine/objects/City.java b/src/engine/objects/City.java index 157e31ad..f163b498 100644 --- a/src/engine/objects/City.java +++ b/src/engine/objects/City.java @@ -74,7 +74,7 @@ public class City extends AbstractWorldObject { private boolean forceRename = false; private boolean noTeleport = false; //used by npc cities private boolean noRepledge = false; //used by npc cities - private boolean isOpen = false; + private final boolean isOpen = false; private int treeOfLifeID; private Vector3fImmutable location = Vector3fImmutable.ZERO; @@ -191,7 +191,6 @@ public class City extends AbstractWorldObject { Logger.error("NULL TOL FOR " + city.cityName); } - // Assign city owner if (city.getTOL() != null) @@ -209,7 +208,8 @@ public class City extends AbstractWorldObject { rulingNation = rulingGuild.getNation(); - // Begin Serialzing soverign guild data + // Begin Serializing sovereign guild data + writer.putInt(city.getObjectType().ordinal()); writer.putInt(city.getObjectUUID()); writer.putString(city.cityName); @@ -264,7 +264,6 @@ public class City extends AbstractWorldObject { writer.putInt(rulingNation.getObjectUUID()); } - // Serialize nation name if (rulingNation.isEmptyGuild()) @@ -286,16 +285,8 @@ public class City extends AbstractWorldObject { else writer.putString(Guild.GetGL(rulingNation).getFirstName() + ' ' + Guild.GetGL(rulingNation).getLastName()); - writer.putLocalDateTime(city.established); -// writer.put((byte) city.established.getDayOfMonth()); -// writer.put((byte) city.established.minusMonths(1).getMonth().getValue()); -// writer.putInt((int) years); -// writer.put((byte) hours); -// writer.put((byte) minutes); -// writer.put((byte) seconds); - writer.putFloat(city.location.x); writer.putFloat(city.location.y); writer.putFloat(city.location.z); @@ -334,6 +325,7 @@ public class City extends AbstractWorldObject { ConcurrentHashMap worldCities = DbManager.getMap(Enum.GameObjectType.City); //add npc cities + for (AbstractGameObject ago : worldCities.values()) { if (ago.getObjectType().equals(GameObjectType.City)) { @@ -350,6 +342,7 @@ public class City extends AbstractWorldObject { //list Player cities //open city, just list + if (city.open && city.getTOL() != null && city.getTOL().getRank() > 4) { if (!BuildingManager.IsPlayerHostile(city.getTOL(), pc)) @@ -359,7 +352,9 @@ public class City extends AbstractWorldObject { } else if (city.isNpc == 1) { + //list NPC cities + Guild g = city.getGuild(); if (g == null) { if (city.isNpc == 1) @@ -369,32 +364,34 @@ public class City extends AbstractWorldObject { } else if (pc.getLevel() > 9) cities.add(city); - } else if (pc.getLevel() >= g.getTeleportMin() && pc.getLevel() <= g.getTeleportMax()) { - - + } else if (pc.getLevel() >= g.getTeleportMin() && pc.getLevel() <= g.getTeleportMax()) cities.add(city); - } } - } } return cities; } - public static ArrayList getCitiesToRepledgeTo(PlayerCharacter pc) { + public static ArrayList getCitiesToRepledgeTo(PlayerCharacter playerCharacter) { + ArrayList cities = new ArrayList<>(); - if (pc == null) + + if (playerCharacter == null) return cities; - Guild pcG = pc.getGuild(); + + Guild pcG = playerCharacter.getGuild(); ConcurrentHashMap worldCities = DbManager.getMap(Enum.GameObjectType.City); //add npc cities + for (AbstractGameObject ago : worldCities.values()) { if (ago.getObjectType().equals(GameObjectType.City)) { + City city = (City) ago; + if (city.noRepledge) continue; @@ -402,11 +399,12 @@ public class City extends AbstractWorldObject { //list Player cities //open city, just list - if (pc.getAccount().status.equals(AccountStatus.ADMIN)) { + + if (playerCharacter.getAccount().status.equals(AccountStatus.ADMIN)) { cities.add(city); } else if (city.open && city.getTOL() != null && city.getTOL().getRank() > 4) { - if (!BuildingManager.IsPlayerHostile(city.getTOL(), pc)) + if (!BuildingManager.IsPlayerHostile(city.getTOL(), playerCharacter)) cities.add(city); //verify nation or guild is same } else if (Guild.sameNationExcludeErrant(city.getGuild(), pcG)) cities.add(city); @@ -414,15 +412,16 @@ public class City extends AbstractWorldObject { } else if (city.isNpc == 1) { //list NPC cities - Guild g = city.getGuild(); - if (g == null) { + Guild guild = city.getGuild(); + + if (guild == null) { if (city.isNpc == 1) if (city.isNoobIsle == 1) { - if (pc.getLevel() < 21) + if (playerCharacter.getLevel() < 21) cities.add(city); - } else if (pc.getLevel() > 9) + } else if (playerCharacter.getLevel() > 9) cities.add(city); - } else if (pc.getLevel() >= g.getRepledgeMin() && pc.getLevel() <= g.getRepledgeMax()) { + } else if (playerCharacter.getLevel() >= guild.getRepledgeMin() && playerCharacter.getLevel() <= guild.getRepledgeMax()) { cities.add(city); } @@ -438,6 +437,7 @@ public class City extends AbstractWorldObject { return null; City city = (City) DbManager.getFromCache(Enum.GameObjectType.City, cityId); + if (city != null) return city; @@ -454,8 +454,10 @@ public class City extends AbstractWorldObject { } public boolean renameCity(String cityName) { + if (!DbManager.CityQueries.renameCity(this, cityName)) return false; + if (!DbManager.CityQueries.updateforceRename(this, false)) return false; @@ -465,17 +467,22 @@ public class City extends AbstractWorldObject { } public boolean updateTOL(Building tol) { + if (tol == null) return false; + if (!DbManager.CityQueries.updateTOL(this, tol.getObjectUUID())) return false; + this.treeOfLifeID = tol.getObjectUUID(); return true; } public boolean renameCityForNewPlant(String cityName) { + if (!DbManager.CityQueries.renameCity(this, cityName)) return false; + if (!DbManager.CityQueries.updateforceRename(this, true)) return false; @@ -498,19 +505,11 @@ public class City extends AbstractWorldObject { } public Building getTOL() { + if (this.treeOfLifeID == 0) return null; return BuildingManager.getBuildingFromCache(this.treeOfLifeID); - - } - - public int getIsNoobIsle() { - return isNoobIsle; - } - - public int getPopulation() { - return population; } /** @@ -540,14 +539,6 @@ public class City extends AbstractWorldObject { Logger.error("Error when writing to database for cityUUID: " + this.getObjectUUID()); } - public float getLatitude() { - return this.location.x; - } - - public float getLongitude() { - return this.location.z; - } - public float getAltitude() { return this.location.y; } @@ -557,34 +548,10 @@ public class City extends AbstractWorldObject { return this.location; } - public byte getIsNpcOwned() { - return isNpc; - } - - public byte getIsSafeHold() { - return this.isSafeHold; - } - public boolean isSafeHold() { return (this.isSafeHold == (byte) 1); } - public byte getIsCapital() { - return isCapital; - } - - public void setIsCapital(boolean state) { - this.isCapital = (state) ? (byte) 1 : (byte) 0; - } - - public int getRadiusType() { - return this.radiusType; - } - - public float getBindRadius() { - return this.bindRadius; - } - public int getRank() { return (this.getTOL() == null) ? 0 : this.getTOL().getRank(); } @@ -650,13 +617,13 @@ public class City extends AbstractWorldObject { if (this.getTOL() == null) return null; - if (this.isNpc == 1) { if (this.getTOL().getOwner() == null) return null; return this.getTOL().getOwner().getGuild(); } else { + if (this.getTOL().getOwner() == null) return null; return this.getTOL().getOwner().getGuild(); @@ -664,13 +631,16 @@ public class City extends AbstractWorldObject { } public boolean openCity(boolean open) { + if (!DbManager.CityQueries.updateOpenCity(this, open)) return false; + this.open = open; return true; } public Vector3fImmutable getBindLoc() { + Vector3fImmutable treeLoc = null; if (this.getTOL() != null && this.getTOL().getRank() == 8) @@ -680,7 +650,9 @@ public class City extends AbstractWorldObject { return treeLoc; if (this.radiusType == 1 && this.bindRadius > 0f) { + //square radius + float x = this.bindLoc.getX(); float z = this.bindLoc.getZ(); float offset = ((ThreadLocalRandom.current().nextFloat() * 2) - 1) * this.bindRadius; @@ -801,7 +773,6 @@ public class City extends AbstractWorldObject { try { this.getTOL().addEffectBit((1 << 16)); this.getBane().getStone().addEffectBit((1 << 19)); - ; } catch (Exception e) { Logger.info("Failed ao add bane effects on city." + e.getMessage()); } @@ -826,6 +797,7 @@ public class City extends AbstractWorldObject { if (playerObject == null) continue; + if (!this.isLocationWithinSiegeBounds(playerObject.getLoc())) continue; @@ -842,8 +814,7 @@ public class City extends AbstractWorldObject { // Remove the city effect from the ago's internal collection - if (this.getEffects().containsKey(Integer.toString(effectBase.getUUID()))) - this.getEffects().remove(Integer.toString(effectBase.getUUID())); + this.getEffects().remove(Integer.toString(effectBase.getUUID())); // Any players currently in the zone will not be processed by the heartbeat // so we do it here manually @@ -852,6 +823,7 @@ public class City extends AbstractWorldObject { for (Integer playerID : this._playerMemory) { player = PlayerCharacter.getFromCache(playerID); + if (player == null) continue; @@ -867,8 +839,10 @@ public class City extends AbstractWorldObject { } public Warehouse getWarehouse() { + if (this.warehouseBuildingID == 0) return null; + return Warehouse.warehouseByBuildingUUID.get(this.warehouseBuildingID); } @@ -1040,8 +1014,7 @@ public class City extends AbstractWorldObject { _playerMemory.removeAll(toRemove); for (Integer removalUUID : toRemove) { - if (this.cityOutlaws.contains(removalUUID)) - this.cityOutlaws.remove(removalUUID); + this.cityOutlaws.remove(removalUUID); } } @@ -1142,6 +1115,7 @@ public class City extends AbstractWorldObject { // All protection contracts are void upon transfer of a city //Dont forget to not Flip protection on Banestones and siege Equipment... Noob. + if (cityBuilding.getBlueprint() != null && !cityBuilding.getBlueprint().isSiegeEquip() && cityBuilding.getBlueprint().getBuildingGroup() != BuildingGroup.BANESTONE) cityBuilding.setProtectionState(ProtectionState.NONE); @@ -1173,7 +1147,6 @@ public class City extends AbstractWorldObject { Zone cityZone; sourceGuild = sourcePlayer.getGuild(); - if (sourceGuild == null) return false; @@ -1229,14 +1202,6 @@ public class City extends AbstractWorldObject { this.forceRename = forceRename; } - public boolean isReverseKOS() { - return reverseKOS; - } - - public void setReverseKOS(boolean reverseKOS) { - this.reverseKOS = reverseKOS; - } - public String getHash() { return hash; } @@ -1264,26 +1229,6 @@ public class City extends AbstractWorldObject { } - //TODO use this for taxing later. -// public boolean isAfterTaxPeriod(LocalDateTime dateTime,PlayerCharacter player){ -// if (dateTime.isBefore(realmTaxDate)){ -// String wait = ""; -// float hours = 1000*60*60; -// float seconds = 1000; -// float hoursUntil = realmTaxDate.minus(dateTime.get).getMillis() /hours; -// int secondsUntil = (int) (realmTaxDate.minus(dateTime.getMillis()).getMillis() /seconds); -// if (hoursUntil < 1) -// wait = "You must wait " + secondsUntil + " seconds before taxing this city again!"; -// else -// wait = "You must wait " + hoursUntil + " hours before taxing this city again!"; -// ErrorPopupMsg.sendErrorMsg(player, wait); -// return false; -// } -// -// return true; -// } - - public synchronized boolean TaxWarehouse(TaxResourcesMsg msg, PlayerCharacter player) { // Member variable declaration @@ -1296,12 +1241,12 @@ public class City extends AbstractWorldObject { } City city = building.getCity(); + if (city == null) { ErrorPopupMsg.sendErrorMsg(player, "This building does not belong to a city."); return true; } - if (playerGuild == null || playerGuild.isEmptyGuild()) { ErrorPopupMsg.sendErrorMsg(player, "You must belong to a guild to do that!"); return true; @@ -1326,6 +1271,7 @@ public class City extends AbstractWorldObject { ErrorPopupMsg.sendErrorMsg(player, "Cannot find realm for your city!"); return true; } + Realm targetRealm = RealmMap.getRealmForCity(city); if (targetRealm == null) { @@ -1354,31 +1300,32 @@ public class City extends AbstractWorldObject { return true; } - if (this.realmTaxDate.isAfter(LocalDateTime.now())) return true; + if (msg.getResources().size() == 0) return true; if (city.getWarehouse() == null) return true; + Warehouse ruledWarehouse = playerGuild.getOwnedCity().getWarehouse(); + if (ruledWarehouse == null) return true; - ItemBase.getItemHashIDMap(); ArrayList resources = new ArrayList<>(); float taxPercent = msg.getTaxPercent(); + if (taxPercent > 20) taxPercent = .20f; for (int resourceHash : msg.getResources().keySet()) { if (ItemBase.getItemHashIDMap().get(resourceHash) != null) resources.add(ItemBase.getItemHashIDMap().get(resourceHash)); - } for (Integer itemBaseID : resources) { @@ -1396,6 +1343,7 @@ public class City extends AbstractWorldObject { ErrorPopupMsg.sendErrorMsg(player, "Failed to Update next Tax Date due to internal Error. City was not charged taxes this time."); return false; } + try { city.getWarehouse().transferResources(player, msg, resources, taxPercent, ruledWarehouse); } catch (Exception e) { @@ -1413,6 +1361,5 @@ public class City extends AbstractWorldObject { dispatch = Dispatch.borrow(player, msg); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); return true; - } }