Browse Source

Methods moved to better class.

combat-2
MagicBot 8 months ago
parent
commit
b665d46dc3
  1. 236
      src/engine/net/client/handlers/ObjectActionMsgHandler.java
  2. 52
      src/engine/objects/AbstractCharacter.java
  3. 181
      src/engine/objects/Realm.java

236
src/engine/net/client/handlers/ObjectActionMsgHandler.java

@ -1,11 +1,7 @@
package engine.net.client.handlers; package engine.net.client.handlers;
import engine.Enum; import engine.Enum;
import engine.Enum.BuildingGroup;
import engine.Enum.DispatchChannel;
import engine.Enum.ItemType; import engine.Enum.ItemType;
import engine.InterestManagement.RealmMap;
import engine.InterestManagement.WorldGrid;
import engine.exception.MsgSendException; import engine.exception.MsgSendException;
import engine.gameManager.*; import engine.gameManager.*;
import engine.math.Bounds; import engine.math.Bounds;
@ -16,7 +12,6 @@ import engine.net.client.ClientConnection;
import engine.net.client.msg.*; import engine.net.client.msg.*;
import engine.objects.*; import engine.objects.*;
import engine.powers.PowersBase; import engine.powers.PowersBase;
import org.pmw.tinylog.Logger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
@ -35,233 +30,6 @@ public class ObjectActionMsgHandler extends AbstractClientMsgHandler {
public ObjectActionMsgHandler() { public ObjectActionMsgHandler() {
super(ObjectActionMsg.class); super(ObjectActionMsg.class);
} }
private 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 (!Realm.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, engine.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, engine.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, engine.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, engine.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, engine.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() == BuildingGroup.TOL) {
continue;
}
hPMod = (building.getMaxHitPoints() * Realm.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);
removeAllBlessings(player);
return true;
}
private static void removeAllBlessings(PlayerCharacter player) {
PowersBase[] powers = new PowersBase[3];
powers[0] = PowersManager.getPowerByIDString("BLS-POWER");
powers[1] = PowersManager.getPowerByIDString("BLS-FORTUNE");
powers[2] = PowersManager.getPowerByIDString("BLS-WISDOM");
for (PowersBase power : powers) {
PowersManager.removeEffect(player, power.getActions().get(0), true, false);
}
}
private static void removeRune(PlayerCharacter pc, ClientConnection origin, int runeID) {
if (pc == null || origin == null) {
return;
}
//remove only if rune is discipline
if (runeID < 3001 || runeID > 3048) {
return;
}
//see if pc has rune
ArrayList<CharacterRune> runes = pc.getRunes();
if (runes == null)
return;
CharacterRune found = pc.getRune(runeID);
if (found == null)
return;
//TODO see if player needs to refine skills or powers first
//attempt remove rune from player
if (!CharacterRune.removeRune(pc, runeID))
return;
//update client with removed rune.
ApplyRuneMsg arm = new ApplyRuneMsg(pc.getObjectType().ordinal(), pc.getObjectUUID(), runeID);
Dispatch dispatch = Dispatch.borrow(pc, arm);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
}
// Handle activation of tears of seadron: Removes rune from player.
@Override @Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
@ -389,7 +157,7 @@ public class ObjectActionMsgHandler extends AbstractClientMsgHandler {
charterType = -600065291; charterType = -600065291;
break; break;
} }
if (claimRealm(player, charterType) == true) { if (Realm.claimRealm(player, charterType) == true) {
itemMan.consume(item); itemMan.consume(item);
} }
break; break;
@ -485,7 +253,7 @@ public class ObjectActionMsgHandler extends AbstractClientMsgHandler {
break; break;
} else if (uuid == 910010) { //tears of saedron } else if (uuid == 910010) { //tears of saedron
if (comps.size() > 1) { if (comps.size() > 1) {
removeRune(player, origin, comps.get(1).intValue()); AbstractCharacter.removeRune(player, origin, comps.get(1).intValue());
} }
break; break;
} else if ((byte) item.chargesRemaining > 0) { } else if ((byte) item.chargesRemaining > 0) {

52
src/engine/objects/AbstractCharacter.java

@ -26,9 +26,13 @@ import engine.math.AtomicFloat;
import engine.math.Bounds; import engine.math.Bounds;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
import engine.net.ByteBufferWriter; import engine.net.ByteBufferWriter;
import engine.net.Dispatch;
import engine.net.DispatchMessage; import engine.net.DispatchMessage;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ApplyRuneMsg;
import engine.net.client.msg.UpdateStateMsg; import engine.net.client.msg.UpdateStateMsg;
import engine.powers.EffectsBase; import engine.powers.EffectsBase;
import engine.powers.PowersBase;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
@ -535,6 +539,54 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
} }
} }
public static void removeRune(PlayerCharacter pc, ClientConnection origin, int runeID) {
if (pc == null || origin == null) {
return;
}
//remove only if rune is discipline
if (runeID < 3001 || runeID > 3048) {
return;
}
//see if pc has rune
ArrayList<CharacterRune> runes = pc.getRunes();
if (runes == null)
return;
CharacterRune found = pc.getRune(runeID);
if (found == null)
return;
//TODO see if player needs to refine skills or powers first
//attempt remove rune from player
if (!CharacterRune.removeRune(pc, runeID))
return;
//update client with removed rune.
ApplyRuneMsg arm = new ApplyRuneMsg(pc.getObjectType().ordinal(), pc.getObjectUUID(), runeID);
Dispatch dispatch = Dispatch.borrow(pc, arm);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
}
public static void removeAllBlessings(PlayerCharacter player) {
PowersBase[] powers = new PowersBase[3];
powers[0] = PowersManager.getPowerByIDString("BLS-POWER");
powers[1] = PowersManager.getPowerByIDString("BLS-FORTUNE");
powers[2] = PowersManager.getPowerByIDString("BLS-WISDOM");
for (PowersBase power : powers) {
PowersManager.removeEffect(player, power.getActions().get(0), true, false);
}
}
private void initializeCharacter() { private void initializeCharacter() {
this.timers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); this.timers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
this.timestamps = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); this.timestamps = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);

181
src/engine/objects/Realm.java

@ -11,11 +11,15 @@ package engine.objects;
import engine.Enum; import engine.Enum;
import engine.InterestManagement.RealmMap; import engine.InterestManagement.RealmMap;
import engine.InterestManagement.WorldGrid;
import engine.db.archive.DataWarehouse; import engine.db.archive.DataWarehouse;
import engine.db.archive.RealmRecord; import engine.db.archive.RealmRecord;
import engine.gameManager.BuildingManager;
import engine.gameManager.DbManager; import engine.gameManager.DbManager;
import engine.gameManager.GuildManager;
import engine.gameManager.PowersManager; import engine.gameManager.PowersManager;
import engine.net.ByteBufferWriter; import engine.net.ByteBufferWriter;
import engine.net.client.msg.ErrorPopupMsg;
import engine.powers.PowersBase; import engine.powers.PowersBase;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger; 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 * Getters
*/ */

Loading…
Cancel
Save