Browse Source

Consolidating handling of different session.

master
MagicBot 2 years ago
parent
commit
837c2fa1f9
  1. 57
      src/engine/objects/Mine.java
  2. 11
      src/engine/powers/poweractions/ClaimMinePowerAction.java

57
src/engine/objects/Mine.java

@ -53,8 +53,9 @@ public class Mine extends AbstractGameObject {
private float longitude; private float longitude;
private float altitude; private float altitude;
private Guild owningGuild; private Guild owningGuild;
private int lastClaimerID; private PlayerCharacter lastClaimer;
private SessionID lastClaimerSessionID; private SessionID lastClaimerSessionID;
private int flags; private int flags;
private int buildingID; private int buildingID;
private Zone parentZone; private Zone parentZone;
@ -106,8 +107,6 @@ public class Mine extends AbstractGameObject {
this.altitude = 0; this.altitude = 0;
this.zoneName = "Unknown Mine"; this.zoneName = "Unknown Mine";
} }
this.owningGuild = Guild.getGuild(ownerUID); this.owningGuild = Guild.getGuild(ownerUID);
Guild nation = null; Guild nation = null;
@ -122,19 +121,17 @@ public class Mine extends AbstractGameObject {
this.owningGuild = Guild.getErrantGuild(); this.owningGuild = Guild.getErrantGuild();
} }
if(!nation.isErrant()) { if(!nation.isErrant()) {
this.nationName = nation.getName(); this.nationName = nation.getName();
this.nationTag = nation.getGuildTag(); this.nationTag = nation.getGuildTag();
} else { } else {
this.nationName = ""; this.nationName = "";
this.nationTag = GuildTag.ERRANT; this.nationTag = GuildTag.ERRANT;
} }
this.setActive(false); this.setActive(false);
this.production = Resource.valueOf(rs.getString("mine_resource")); this.production = Resource.valueOf(rs.getString("mine_resource"));
this.lastClaimerID = 0;
this.lastClaimerSessionID = null; this.lastClaimerSessionID = null;
} }
@ -371,13 +368,6 @@ try{
public void handleStartMineWindow() { public void handleStartMineWindow() {
// Do not open errant mines until after woo
// if ((this.getOwningGuild() == null) &&
// (this.getOpenDate().isAfter(DateTime.now())))
// return;
this.lastClaimerID = 0;
this.setActive(true); this.setActive(true);
ChatManager.chatSystemChannel(this.zoneName + "'s Mine is now Active!"); ChatManager.chatSystemChannel(this.zoneName + "'s Mine is now Active!");
Logger.info(this.zoneName + "'s Mine is now Active!"); Logger.info(this.zoneName + "'s Mine is now Active!");
@ -490,24 +480,13 @@ try{
if (mineBuilding.getRank() > 0) { if (mineBuilding.getRank() > 0) {
//never knocked down, let's just move on. //never knocked down, let's just move on.
//hasn't been claimed since server start. //hasn't been claimed since server start.
if (this.lastClaimerID == 0 && (this.owningGuild == null || this.owningGuild.isErrant()))
return false;
this.setActive(false); this.setActive(false);
return true; return true;
} }
PlayerCharacter claimer = PlayerCharacter.getFromCache(this.lastClaimerID); if (!validClaimer(this.lastClaimer))
if (!validClaimer(claimer))
return false; return false;
// //verify the player hasn't logged out since claim
// if (SessionManager.getSession(claimer) == null)
// return false;
// if (!SessionManager.getSession(claimer).getSessionID().equals(this.lastClaimerSessionID))
// return false;
if (this.owningGuild == null || this.owningGuild.isErrant() || this.owningGuild.getNation().isErrant()) if (this.owningGuild == null || this.owningGuild.isErrant() || this.owningGuild.getNation().isErrant())
return false; return false;
@ -523,19 +502,19 @@ try{
if (mineBuilding.getRank() < 1){ if (mineBuilding.getRank() < 1){
if (claimer == null){ if (this.lastClaimer == null){
this.lastClaimerID = 0; this.lastClaimerSessionID = null;
updateGuildOwner(null); updateGuildOwner(null);
return false; return false;
} }
mineBuilding.rebuildMine(); mineBuilding.rebuildMine();
WorldGrid.updateObject(mineBuilding); WorldGrid.updateObject(mineBuilding);
ChatManager.chatSystemChannel(claimer.getName() + " has claimed the mine in " + this.parentZone.getParent().getName() + " for " + this.owningGuild.getName() + ". The mine is no longer active."); ChatManager.chatSystemChannel(this.lastClaimer.getName() + " has claimed the mine in " + this.parentZone.getParent().getName() + " for " + this.owningGuild.getName() + ". The mine is no longer active.");
// Warehouse this claim event // Warehouse this claim event
MineRecord mineRecord = MineRecord.borrow(this, claimer, Enum.RecordEventType.CAPTURE); MineRecord mineRecord = MineRecord.borrow(this, this.lastClaimer, Enum.RecordEventType.CAPTURE);
DataWarehouse.pushToWarehouse(mineRecord); DataWarehouse.pushToWarehouse(mineRecord);
}else{ }else{
@ -546,7 +525,7 @@ try{
return true; return true;
} }
public boolean claimMine(PlayerCharacter claimer){ public boolean claimMine(PlayerCharacter claimer) {
if (claimer == null) if (claimer == null)
return false; return false;
@ -562,10 +541,24 @@ try{
if (!updateGuildOwner(claimer)) if (!updateGuildOwner(claimer))
return false; return false;
this.lastClaimerID = claimer.getObjectUUID(); // Not the Same session for this character?
Mine.setLastChange(System.currentTimeMillis()); // Claimers may not relog or they lose claim.
if (this.lastClaimer != null) {
if (SessionManager.getSession(lastClaimer).getSessionID() !=
this.lastClaimerSessionID) {
this.lastClaimer = null;
this.lastClaimerSessionID = null;
Mine.setLastChange(System.currentTimeMillis());
return false;
}
}
// Successful claim
return true; return true;
} }
public boolean depositMineResources(){ public boolean depositMineResources(){
if (this.owningGuild == null) if (this.owningGuild == null)

11
src/engine/powers/poweractions/ClaimMinePowerAction.java

@ -36,16 +36,17 @@ public class ClaimMinePowerAction extends AbstractPowerAction {
if (!(awo.getObjectType().equals(Enum.GameObjectType.Building))) if (!(awo.getObjectType().equals(Enum.GameObjectType.Building)))
return; return;
Building b = (Building)awo; Building mineBuilding = (Building)awo;
if (b.getRank() > 0) if (mineBuilding.getRank() > 0)
return; return;
Mine m = Mine.getMineFromTower(b.getObjectUUID()); Mine mine = Mine.getMineFromTower(mineBuilding.getObjectUUID());
if (m == null)
if (mine == null)
return; return;
m.claimMine((PlayerCharacter) source); mine.claimMine((PlayerCharacter) source);
} }
@Override @Override

Loading…
Cancel
Save