Browse Source

City realm id lookup not db load

combat-2
MagicBot 8 months ago
parent
commit
916a12a434
  1. 2
      src/engine/InterestManagement/RealmMap.java
  2. 5
      src/engine/net/client/handlers/TaxCityMsgHandler.java
  3. 2
      src/engine/objects/Building.java
  4. 21
      src/engine/objects/City.java
  5. 7
      src/engine/objects/Guild.java
  6. 18
      src/engine/objects/PlayerCharacter.java
  7. 2
      src/engine/objects/Realm.java
  8. 6
      src/engine/workthreads/DestroyCityThread.java

2
src/engine/InterestManagement/RealmMap.java

@ -68,7 +68,7 @@ public enum RealmMap {
public static Realm getRealmForCity(City city) { public static Realm getRealmForCity(City city) {
Realm outRealm = null; Realm outRealm = null;
outRealm = city.getRealm(); outRealm = city.realm;
return outRealm; return outRealm;
} }

5
src/engine/net/client/handlers/TaxCityMsgHandler.java

@ -1,9 +1,9 @@
package engine.net.client.handlers; package engine.net.client.handlers;
import engine.mbEnums;
import engine.InterestManagement.RealmMap; import engine.InterestManagement.RealmMap;
import engine.exception.MsgSendException; import engine.exception.MsgSendException;
import engine.gameManager.BuildingManager; import engine.gameManager.BuildingManager;
import engine.mbEnums;
import engine.net.Dispatch; import engine.net.Dispatch;
import engine.net.DispatchMessage; import engine.net.DispatchMessage;
import engine.net.client.ClientConnection; import engine.net.client.ClientConnection;
@ -72,7 +72,8 @@ public class TaxCityMsgHandler extends AbstractClientMsgHandler {
// return true; // return true;
// } // }
if (playerGuild.getOwnedCity().getRealm() == null) { City city1 = playerGuild.getOwnedCity();
if (city1.realm == null) {
ErrorPopupMsg.sendErrorMsg(player, "Cannot find realm for your city!"); ErrorPopupMsg.sendErrorMsg(player, "Cannot find realm for your city!");
return true; return true;
} }

2
src/engine/objects/Building.java

@ -561,7 +561,7 @@ public class Building extends AbstractWorldObject {
if (this.rank == 8) { if (this.rank == 8) {
cityRealm = city.getRealm(); cityRealm = city.realm;
if (cityRealm != null) if (cityRealm != null)
cityRealm.abandonRealm(); cityRealm.abandonRealm();

21
src/engine/objects/City.java

@ -63,7 +63,6 @@ public class City extends AbstractWorldObject {
private int isNoobIsle; //1: noob, 0: not noob: -1: not noob, no teleport private int isNoobIsle; //1: noob, 0: not noob: -1: not noob, no teleport
private int population = 0; private int population = 0;
private int siegesWithstood = 0; private int siegesWithstood = 0;
private int realmID;
private int radiusType; private int radiusType;
private float bindRadius; private float bindRadius;
private float bindX; private float bindX;
@ -81,6 +80,7 @@ public class City extends AbstractWorldObject {
private boolean open = false; private boolean open = false;
private String hash; private String hash;
public Warehouse warehouse; public Warehouse warehouse;
public Realm realm;
/** /**
* ResultSet Constructor * ResultSet Constructor
@ -138,8 +138,6 @@ public class City extends AbstractWorldObject {
this.hash = rs.getString("hash"); this.hash = rs.getString("hash");
this.realmID = rs.getInt("realmID");
} catch (Exception e) { } catch (Exception e) {
Logger.error(e); Logger.error(e);
} }
@ -734,12 +732,12 @@ public class City extends AbstractWorldObject {
if ((ConfigManager.serverType.equals(ServerType.WORLDSERVER)) if ((ConfigManager.serverType.equals(ServerType.WORLDSERVER))
&& (this.isNpc == (byte) 0)) { && (this.isNpc == (byte) 0)) {
Realm wsr = Realm.getRealm(this.realmID); this.realm = RealmMap.getRealmAtLocation(this.getLoc());
if (wsr != null) if (realm != null)
wsr.addCity(this.getObjectUUID()); realm.addCity(this.getObjectUUID());
else else
Logger.error("Unable to find realm of ID " + realmID + " for city " + this.getObjectUUID()); Logger.error("Unable to find realm for city " + this.getObjectUUID());
} }
// Set city motto to current guild motto // Set city motto to current guild motto
@ -893,12 +891,6 @@ public class City extends AbstractWorldObject {
} }
} }
public Realm getRealm() {
return Realm.getRealm(this.realmID);
}
public boolean isLocationOnCityGrid(Vector3fImmutable insideLoc) { public boolean isLocationOnCityGrid(Vector3fImmutable insideLoc) {
Bounds newBounds = Bounds.borrow(); Bounds newBounds = Bounds.borrow();
@ -1300,7 +1292,7 @@ public class City extends AbstractWorldObject {
return true; return true;
} }
if (playerGuild.getOwnedCity().getRealm() == null) { if (RealmMap.getRealmIDAtLocation(playerGuild.getOwnedCity().getLoc()) == 0) {
ErrorPopupMsg.sendErrorMsg(player, "Cannot find realm for your city!"); ErrorPopupMsg.sendErrorMsg(player, "Cannot find realm for your city!");
return true; return true;
} }
@ -1388,4 +1380,5 @@ public class City extends AbstractWorldObject {
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
return true; return true;
} }
} }

7
src/engine/objects/Guild.java

@ -9,12 +9,12 @@
package engine.objects; package engine.objects;
import engine.mbEnums;
import engine.mbEnums.*;
import engine.db.archive.DataWarehouse; import engine.db.archive.DataWarehouse;
import engine.db.archive.GuildRecord; import engine.db.archive.GuildRecord;
import engine.db.handlers.dbGuildHandler; import engine.db.handlers.dbGuildHandler;
import engine.gameManager.*; import engine.gameManager.*;
import engine.mbEnums;
import engine.mbEnums.*;
import engine.net.ByteBufferWriter; import engine.net.ByteBufferWriter;
import engine.net.Dispatch; import engine.net.Dispatch;
import engine.net.DispatchMessage; import engine.net.DispatchMessage;
@ -250,7 +250,8 @@ public class Guild extends AbstractWorldObject {
City ownedCity = guild.getOwnedCity(); City ownedCity = guild.getOwnedCity();
if (ownedCity != null) { if (ownedCity != null) {
Realm realm = guild.getOwnedCity().getRealm(); City city = guild.getOwnedCity();
Realm realm = city.realm;
if (realm != null && realm.getRulingCity() != null) { if (realm != null && realm.getRulingCity() != null) {
if (realm.getRulingCity().equals(ownedCity)) { if (realm.getRulingCity().equals(ownedCity)) {
writer.putInt(realm.getCharterType()); writer.putInt(realm.getCharterType());

18
src/engine/objects/PlayerCharacter.java

@ -1434,12 +1434,15 @@ public class PlayerCharacter extends AbstractCharacter {
return 0; return 0;
if (player.getGuild().getOwnedCity() == null) if (player.getGuild().getOwnedCity() == null)
return 10; return 10;
if (player.getGuild().getOwnedCity().getRealm() == null) City city5 = player.getGuild().getOwnedCity();
if (city5.realm == null)
return 10; return 10;
if (player.getGuild().getOwnedCity().getRealm().getRulingCity() == null) City city4 = player.getGuild().getOwnedCity();
if (city4.realm.getRulingCity() == null)
return 10; return 10;
if (player.getGuild().getOwnedCity().getRealm().getRulingCity().getObjectUUID() != player.getGuild().getOwnedCity().getObjectUUID()) City city3 = player.getGuild().getOwnedCity();
if (city3.realm.getRulingCity().getObjectUUID() != player.getGuild().getOwnedCity().getObjectUUID())
return 10; return 10;
int realmTitle = 1; int realmTitle = 1;
if (player.getGuild().getSubGuildList() == null || player.getGuild().getSubGuildList().isEmpty()) if (player.getGuild().getSubGuildList() == null || player.getGuild().getSubGuildList().isEmpty())
@ -1447,11 +1450,14 @@ public class PlayerCharacter extends AbstractCharacter {
for (Guild subGuild : player.getGuild().getSubGuildList()) { for (Guild subGuild : player.getGuild().getSubGuildList()) {
if (subGuild.getOwnedCity() == null) if (subGuild.getOwnedCity() == null)
continue; continue;
if (subGuild.getOwnedCity().getRealm() == null) City city2 = subGuild.getOwnedCity();
if (city2.realm == null)
continue; continue;
if (subGuild.getOwnedCity().getRealm().getRulingCity() == null) City city1 = subGuild.getOwnedCity();
if (city1.realm.getRulingCity() == null)
continue; continue;
if (subGuild.getOwnedCity().getRealm().getRulingCity().getObjectUUID() != subGuild.getOwnedCity().getObjectUUID()) City city = subGuild.getOwnedCity();
if (city.realm.getRulingCity().getObjectUUID() != subGuild.getOwnedCity().getObjectUUID())
continue; continue;
realmTitle++; realmTitle++;
} }

2
src/engine/objects/Realm.java

@ -160,7 +160,7 @@ public class Realm {
Realm serverRealm; Realm serverRealm;
CharterType charterType; CharterType charterType;
serverRealm = city.getRealm(); serverRealm = city.realm;
charterType = CharterType.getCharterTypeByID(serverRealm.charterType); charterType = CharterType.getCharterTypeByID(serverRealm.charterType);
return charterType.getMeshID(); return charterType.getMeshID();

6
src/engine/workthreads/DestroyCityThread.java

@ -18,12 +18,12 @@ package engine.workthreads;
* next reboot. * next reboot.
*/ */
import engine.mbEnums;
import engine.gameManager.BuildingManager; import engine.gameManager.BuildingManager;
import engine.gameManager.DbManager; import engine.gameManager.DbManager;
import engine.gameManager.GuildManager; import engine.gameManager.GuildManager;
import engine.gameManager.ZoneManager; import engine.gameManager.ZoneManager;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
import engine.mbEnums;
import engine.objects.Building; import engine.objects.Building;
import engine.objects.City; import engine.objects.City;
import engine.objects.Guild; import engine.objects.Guild;
@ -144,8 +144,8 @@ public class DestroyCityThread implements Runnable {
if (tol != null) if (tol != null)
BuildingManager.setRank(tol, -1); BuildingManager.setRank(tol, -1);
if (city.getRealm() != null) if (city.realm != null)
city.getRealm().removeCity(city.getObjectUUID()); city.realm.removeCity(city.getObjectUUID());
// It's now safe to delete the city zone from the database // It's now safe to delete the city zone from the database
// which will cause a cascade delete of everything else // which will cause a cascade delete of everything else

Loading…
Cancel
Save