Browse Source

Unused and duplicate variable removed.

master
MagicBot 1 year ago
parent
commit
3883963225
  1. 6
      src/engine/db/handlers/dbMobHandler.java
  2. 49
      src/engine/mobileAI/MobAI.java
  3. 3
      src/engine/mobileAI/Threads/MobRespawnThread.java
  4. 23
      src/engine/net/client/handlers/MinionTrainingMsgHandler.java
  5. 33
      src/engine/objects/Mob.java

6
src/engine/db/handlers/dbMobHandler.java

@ -12,7 +12,6 @@ package engine.db.handlers;
import engine.gameManager.DbManager; import engine.gameManager.DbManager;
import engine.objects.Mob; import engine.objects.Mob;
import engine.objects.Zone; import engine.objects.Zone;
import engine.server.MBServerStatics;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
@ -122,10 +121,9 @@ public class dbMobHandler extends dbHandlerBase {
if (toCreate == null) if (toCreate == null)
return; return;
if (toCreate != null) { if (toCreate != null)
toCreate.setTimeToSpawnSiege(System.currentTimeMillis() + MBServerStatics.FIFTEEN_MINUTES);
toCreate.setDeathTime(System.currentTimeMillis()); toCreate.setDeathTime(System.currentTimeMillis());
}
} }
} catch (SQLException e) { } catch (SQLException e) {

49
src/engine/mobileAI/MobAI.java

@ -50,15 +50,18 @@ public class MobAI {
} }
if (target.getObjectType() == Enum.GameObjectType.PlayerCharacter && canCast(mob)) { if (target.getObjectType() == Enum.GameObjectType.PlayerCharacter && canCast(mob)) {
if (mob.isPlayerGuard() == false && MobCast(mob)) { if (mob.isPlayerGuard() == false && MobCast(mob)) {
mob.updateLocation(); mob.updateLocation();
return; return;
} }
if (mob.isPlayerGuard() == true && GuardCast(mob)) { if (mob.isPlayerGuard() == true && GuardCast(mob)) {
mob.updateLocation(); mob.updateLocation();
return; return;
} }
} }
if (!CombatUtilities.inRangeToAttack(mob, target)) if (!CombatUtilities.inRangeToAttack(mob, target))
return; return;
@ -258,7 +261,9 @@ public class MobAI {
//guard captains inherit barracks patrol points dynamically //guard captains inherit barracks patrol points dynamically
if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal()) { if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal()) {
Building barracks = mob.building; Building barracks = mob.building;
if (barracks != null && barracks.patrolPoints != null && !barracks.getPatrolPoints().isEmpty()) { if (barracks != null && barracks.patrolPoints != null && !barracks.getPatrolPoints().isEmpty()) {
mob.patrolPoints = barracks.patrolPoints; mob.patrolPoints = barracks.patrolPoints;
} else { } else {
@ -275,8 +280,8 @@ public class MobAI {
MovementUtilities.aiMove(mob, mob.destination, true); MovementUtilities.aiMove(mob, mob.destination, true);
if (mob.BehaviourType.equals(Enum.MobBehaviourType.GuardCaptain)) { if (mob.BehaviourType.equals(Enum.MobBehaviourType.GuardCaptain))
for (Entry<Mob, Integer> minion : mob.siegeMinionMap.entrySet()) { for (Entry<Mob, Integer> minion : mob.siegeMinionMap.entrySet())
//make sure mob is out of combat stance //make sure mob is out of combat stance
@ -288,8 +293,6 @@ public class MobAI {
MovementUtilities.aiMove(minion.getKey(), formationPatrolPoint, true); MovementUtilities.aiMove(minion.getKey(), formationPatrolPoint, true);
} }
} }
}
}
} catch (Exception e) { } catch (Exception e) {
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: AttackTarget" + " " + e.getMessage()); Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: AttackTarget" + " " + e.getMessage());
} }
@ -306,11 +309,14 @@ public class MobAI {
return false; return false;
if(mob.isPlayerGuard == true){ if(mob.isPlayerGuard == true){
int contractID; int contractID;
if(mob.BehaviourType.equals(Enum.MobBehaviourType.GuardMinion)) if(mob.BehaviourType.equals(Enum.MobBehaviourType.GuardMinion))
contractID = mob.npcOwner.contract.getContractID(); contractID = mob.npcOwner.contract.getContractID();
else else
contractID = mob.contract.getContractID(); contractID = mob.contract.getContractID();
if(Enum.MinionType.ContractToMinionMap.get(contractID).isMage() == false) if(Enum.MinionType.ContractToMinionMap.get(contractID).isMage() == false)
return false; return false;
} }
@ -384,24 +390,20 @@ public class MobAI {
//check for hit-roll //check for hit-roll
if (mobPower.requiresHitRoll) { if (mobPower.requiresHitRoll)
if (CombatUtilities.triggerDefense(mob, mob.getCombatTarget())) if (CombatUtilities.triggerDefense(mob, mob.getCombatTarget()))
return false; return false;
}
// Cast the spell // Cast the spell
if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mobPower.getRange())) { if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mobPower.getRange())) {
PerformActionMsg msg; PerformActionMsg msg;
if (!mobPower.isHarmful() || mobPower.targetSelf) { if (!mobPower.isHarmful() || mobPower.targetSelf) {
PowersManager.useMobPower(mob, mob, mobPower, powerRank); PowersManager.useMobPower(mob, mob, mobPower, powerRank);
msg = PowersManager.createPowerMsg(mobPower, powerRank, mob, mob); msg = PowersManager.createPowerMsg(mobPower, powerRank, mob, mob);
} } else {
else {
PowersManager.useMobPower(mob, target, mobPower, powerRank); PowersManager.useMobPower(mob, target, mobPower, powerRank);
msg = PowersManager.createPowerMsg(mobPower, powerRank, mob, target); msg = PowersManager.createPowerMsg(mobPower, powerRank, mob, target);
} }
@ -410,6 +412,7 @@ public class MobAI {
PowersManager.finishUseMobPower(msg, mob, 0, 0); PowersManager.finishUseMobPower(msg, mob, 0, 0);
long randomCooldown = (long)((ThreadLocalRandom.current().nextInt(10,15) * 1000) * MobAIThread.AI_CAST_FREQUENCY); long randomCooldown = (long)((ThreadLocalRandom.current().nextInt(10,15) * 1000) * MobAIThread.AI_CAST_FREQUENCY);
mob.nextCastTime = System.currentTimeMillis() + randomCooldown; mob.nextCastTime = System.currentTimeMillis() + randomCooldown;
return true; return true;
} }
@ -642,10 +645,12 @@ public class MobAI {
mob.setCombatTarget(null); mob.setCombatTarget(null);
return; return;
} }
if (mob.BehaviourType.ordinal() != Enum.MobBehaviourType.Pet1.ordinal()) if (mob.BehaviourType.ordinal() != Enum.MobBehaviourType.Pet1.ordinal())
CheckToSendMobHome(mob); CheckToSendMobHome(mob);
if (mob.getCombatTarget() != null) { if (mob.getCombatTarget() != null) {
if (mob.getCombatTarget().isAlive() == false) { if (mob.getCombatTarget().isAlive() == false) {
mob.setCombatTarget(null); mob.setCombatTarget(null);
return; return;
@ -753,7 +758,7 @@ public class MobAI {
for (AbstractWorldObject awoMob : awoList) { for (AbstractWorldObject awoMob : awoList) {
//dont scan self. // exclude self.
if (aiAgent.equals(awoMob)) if (aiAgent.equals(awoMob))
continue; continue;
@ -867,7 +872,7 @@ public class MobAI {
} }
} }
} else if (System.currentTimeMillis() > (aiAgent.deathTime + (aiAgent.spawnTime * 1000))) { } else if (System.currentTimeMillis() > (aiAgent.deathTime + (aiAgent.spawnTime * 1000))) {
//aiAgent.respawn();
if (Zone.respawnQue.contains(aiAgent) == false) { if (Zone.respawnQue.contains(aiAgent) == false) {
Zone.respawnQue.add(aiAgent); Zone.respawnQue.add(aiAgent);
} }
@ -957,6 +962,7 @@ public class MobAI {
float rangeSquared = mob.getRange() * mob.getRange(); float rangeSquared = mob.getRange() * mob.getRange();
float distanceSquared = mob.getLoc().distanceSquared2D(mob.getCombatTarget().getLoc()); float distanceSquared = mob.getLoc().distanceSquared2D(mob.getCombatTarget().getLoc());
if(mob.isMoving() == true && distanceSquared < rangeSquared - 50) { if(mob.isMoving() == true && distanceSquared < rangeSquared - 50) {
mob.destination = mob.getLoc(); mob.destination = mob.getLoc();
MovementUtilities.moveToLocation(mob, mob.destination, 0); MovementUtilities.moveToLocation(mob, mob.destination, 0);
@ -1002,12 +1008,14 @@ public class MobAI {
Mob aggroMob = (Mob) awoMob; Mob aggroMob = (Mob) awoMob;
//dont attack other guards //don't attack other guards
if (aggroMob.isGuard()) if (aggroMob.isGuard())
continue; continue;
if(aggroMob.BehaviourType.equals(Enum.MobBehaviourType.Pet1)) if(aggroMob.BehaviourType.equals(Enum.MobBehaviourType.Pet1))
continue; continue;
if (mob.getLoc().distanceSquared2D(aggroMob.getLoc()) > sqr(50)) if (mob.getLoc().distanceSquared2D(aggroMob.getLoc()) > sqr(50))
continue; continue;
@ -1048,9 +1056,9 @@ public class MobAI {
try { try {
if (!mob.npcOwner.isAlive()) { if (!mob.npcOwner.isAlive()) {
if(mob.getCombatTarget() == null) { if (mob.getCombatTarget() == null) {
CheckForPlayerGuardAggro(mob); CheckForPlayerGuardAggro(mob);
}else { } else {
AbstractWorldObject newTarget = ChangeTargetFromHateValue(mob); AbstractWorldObject newTarget = ChangeTargetFromHateValue(mob);
@ -1095,10 +1103,10 @@ public class MobAI {
private static void PetLogic(Mob mob) { private static void PetLogic(Mob mob) {
try { try {
if (mob.getOwner() == null && mob.isNecroPet() == false && mob.isSiege() == false) {
if (mob.getOwner() == null && mob.isNecroPet() == false && mob.isSiege() == false)
if (ZoneManager.getSeaFloor().zoneMobSet.contains(mob)) if (ZoneManager.getSeaFloor().zoneMobSet.contains(mob))
mob.killCharacter("no owner"); mob.killCharacter("no owner");
}
if (MovementUtilities.canMove(mob) && mob.BehaviourType.canRoam) if (MovementUtilities.canMove(mob) && mob.BehaviourType.canRoam)
CheckMobMovement(mob); CheckMobMovement(mob);
@ -1110,17 +1118,16 @@ public class MobAI {
if (mob.getTimestamps().containsKey("HEALTHRECOVERED") == false) if (mob.getTimestamps().containsKey("HEALTHRECOVERED") == false)
mob.getTimestamps().put("HEALTHRECOVERED", System.currentTimeMillis()); mob.getTimestamps().put("HEALTHRECOVERED", System.currentTimeMillis());
if (mob.isSit() && mob.getTimeStamp("HEALTHRECOVERED") < System.currentTimeMillis() + 3000) { if (mob.isSit() && mob.getTimeStamp("HEALTHRECOVERED") < System.currentTimeMillis() + 3000)
if (mob.getHealth() < mob.getHealthMax()) { if (mob.getHealth() < mob.getHealthMax()) {
float recoveredHealth = mob.getHealthMax() * ((1 + mob.getBonuses().getFloatPercentAll(Enum.ModType.HealthRecoverRate, Enum.SourceType.None)) * 0.01f); float recoveredHealth = mob.getHealthMax() * ((1 + mob.getBonuses().getFloatPercentAll(Enum.ModType.HealthRecoverRate, Enum.SourceType.None)) * 0.01f);
mob.setHealth(mob.getHealth() + recoveredHealth); mob.setHealth(mob.getHealth() + recoveredHealth);
mob.getTimestamps().put("HEALTHRECOVERED", System.currentTimeMillis()); mob.getTimestamps().put("HEALTHRECOVERED", System.currentTimeMillis());
if (mob.getHealth() > mob.getHealthMax()) { if (mob.getHealth() > mob.getHealthMax())
mob.setHealth(mob.getHealthMax()); mob.setHealth(mob.getHealthMax());
}
} }
}
} catch (Exception e) { } catch (Exception e) {
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: PetLogic" + " " + e.getMessage()); Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: PetLogic" + " " + e.getMessage());
} }

3
src/engine/mobileAI/Threads/MobRespawnThread.java

@ -25,9 +25,6 @@ import org.pmw.tinylog.Logger;
public class MobRespawnThread implements Runnable { public class MobRespawnThread implements Runnable {
// Instance variables
// Thread constructor
public MobRespawnThread() { public MobRespawnThread() {
Logger.info(" MobRespawnThread thread has started!"); Logger.info(" MobRespawnThread thread has started!");

23
src/engine/net/client/handlers/MinionTrainingMsgHandler.java

@ -14,7 +14,6 @@ import engine.net.DispatchMessage;
import engine.net.client.ClientConnection; import engine.net.client.ClientConnection;
import engine.net.client.msg.*; import engine.net.client.msg.*;
import engine.objects.*; import engine.objects.*;
import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.util.ArrayList; import java.util.ArrayList;
@ -69,7 +68,6 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler {
npc.getSiegeMinionMap().remove(toRemove); npc.getSiegeMinionMap().remove(toRemove);
//toRemove.disableIntelligence();
WorldGrid.RemoveWorldObject(toRemove); WorldGrid.RemoveWorldObject(toRemove);
if (toRemove.getParentZone() != null) if (toRemove.getParentZone() != null)
@ -199,9 +197,9 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler {
if (npc == null) if (npc == null)
return true; return true;
Building b = BuildingManager.getBuildingFromCache(minionMsg.getBuildingID()); Building building = BuildingManager.getBuildingFromCache(minionMsg.getBuildingID());
if (b == null) if (building == null)
return true; return true;
//clear minion //clear minion
@ -211,6 +209,7 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler {
if (minionMsg.getType() == 2) { if (minionMsg.getType() == 2) {
Mob toRemove = Mob.getFromCache(minionMsg.getUUID()); Mob toRemove = Mob.getFromCache(minionMsg.getUUID());
if (!npc.getSiegeMinionMap().containsKey(toRemove)) if (!npc.getSiegeMinionMap().containsKey(toRemove))
return true; return true;
@ -219,7 +218,6 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler {
npc.getSiegeMinionMap().remove(toRemove); npc.getSiegeMinionMap().remove(toRemove);
//toRemove.disableIntelligence();
WorldGrid.RemoveWorldObject(toRemove); WorldGrid.RemoveWorldObject(toRemove);
if (toRemove.getParentZone() != null) if (toRemove.getParentZone() != null)
@ -236,21 +234,18 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler {
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
} }
// we Found the move to remove, lets break the for loop so it doesnt look for more. ManageCityAssetsMsg mca1 = new ManageCityAssetsMsg(player, building);
ManageCityAssetsMsg mca1 = new ManageCityAssetsMsg(player, b);
mca1.actionType = 3; mca1.actionType = 3;
mca1.setTargetType(b.getObjectType().ordinal()); mca1.setTargetType(building.getObjectType().ordinal());
mca1.setTargetID(b.getObjectUUID()); mca1.setTargetID(building.getObjectUUID());
mca1.setTargetType3(npc.getObjectType().ordinal()); mca1.setTargetType3(npc.getObjectType().ordinal());
mca1.setTargetID3(npc.getObjectUUID()); mca1.setTargetID3(npc.getObjectUUID());
mca1.setAssetName1(b.getName()); mca1.setAssetName1(building.getName());
mca1.setUnknown54(1); mca1.setUnknown54(1);
Dispatch dispatch = Dispatch.borrow(player, mca1); Dispatch dispatch = Dispatch.borrow(player, mca1);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
;
ManageNPCMsg mnm = new ManageNPCMsg(npc); ManageNPCMsg mnm = new ManageNPCMsg(npc);
dispatch = Dispatch.borrow(player, mnm); dispatch = Dispatch.borrow(player, mnm);
@ -302,14 +297,14 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler {
if (!DbManager.MobQueries.ADD_TO_GUARDS(npc.getObjectUUID(), mobBase, pirateName, npc.getSiegeMinionMap().size() + 1)) if (!DbManager.MobQueries.ADD_TO_GUARDS(npc.getObjectUUID(), mobBase, pirateName, npc.getSiegeMinionMap().size() + 1))
return true; return true;
Mob toCreate = Mob.createGuardMob(npc, npc.getGuild(), zone, b.getLoc(), npc.getLevel(), pirateName); Mob toCreate = Mob.createGuardMob(npc, npc.getGuild(), zone, building.getLoc(), npc.getLevel(), pirateName);
if (toCreate == null) if (toCreate == null)
return true; return true;
// toCreate.despawn(); // toCreate.despawn();
if (toCreate != null) { if (toCreate != null) {
toCreate.setTimeToSpawnSiege(System.currentTimeMillis() + MBServerStatics.FIFTEEN_MINUTES);
toCreate.setDeathTime(System.currentTimeMillis()); toCreate.setDeathTime(System.currentTimeMillis());
toCreate.parentZone.zoneMobSet.add(toCreate); toCreate.parentZone.zoneMobSet.add(toCreate);
} }

33
src/engine/objects/Mob.java

@ -95,7 +95,6 @@ public class Mob extends AbstractIntelligenceAgent {
private AbstractWorldObject fearedObject = null; private AbstractWorldObject fearedObject = null;
private int buildingID; private int buildingID;
private boolean isSiege = false; private boolean isSiege = false;
private long timeToSpawnSiege;
private long lastAttackTime = 0; private long lastAttackTime = 0;
private int lastMobPowerToken = 0; private int lastMobPowerToken = 0;
private HashMap<Integer, MobEquipment> equip = null; private HashMap<Integer, MobEquipment> equip = null;
@ -103,6 +102,7 @@ public class Mob extends AbstractIntelligenceAgent {
private DateTime upgradeDateTime = null; private DateTime upgradeDateTime = null;
private boolean lootSync = false; private boolean lootSync = false;
/** /**
* No Id Constructor * No Id Constructor
*/ */
@ -1309,10 +1309,9 @@ public class Mob extends AbstractIntelligenceAgent {
this.hasLoot = false; this.hasLoot = false;
this.playerAgroMap.clear(); this.playerAgroMap.clear();
this.timeToSpawnSiege = System.currentTimeMillis() + 60 * 15 * 1000; if (this.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardMinion.ordinal())
if (this.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardMinion.ordinal()) {
this.spawnTime = (int) (-2.500 * ((Mob) this.npcOwner).building.getRank() + 22.5) * 60; this.spawnTime = (int) (-2.500 * ((Mob) this.npcOwner).building.getRank() + 22.5) * 60;
}
if (this.isPet()) { if (this.isPet()) {
PlayerCharacter petOwner = this.getOwner(); PlayerCharacter petOwner = this.getOwner();
@ -1333,10 +1332,8 @@ public class Mob extends AbstractIntelligenceAgent {
this.hasLoot = false; this.hasLoot = false;
//if (this.parentZone != null) //if (this.parentZone != null)
//this.parentZone.zoneMobSet.remove(this); //this.parentZone.zoneMobSet.remove(this);
if(ZoneManager.getSeaFloor().zoneMobSet.contains(this)) { ZoneManager.getSeaFloor().zoneMobSet.remove(this);
ZoneManager.getSeaFloor().zoneMobSet.remove(this);
}
try { try {
this.clearEffects(); this.clearEffects();
} catch (Exception e) { } catch (Exception e) {
@ -1382,9 +1379,8 @@ public class Mob extends AbstractIntelligenceAgent {
} }
public void respawn() { public void respawn() {
//Commenting out Mob ID rotation.
this.despawned = false; this.despawned = false;
//this.playerAgroMap.clear();
this.setCombatTarget(null); this.setCombatTarget(null);
this.setHealth(this.healthMax); this.setHealth(this.healthMax);
this.stamina.set(this.staminaMax); this.stamina.set(this.staminaMax);
@ -1397,17 +1393,22 @@ public class Mob extends AbstractIntelligenceAgent {
this.lastBindLoc = this.bindLoc; this.lastBindLoc = this.bindLoc;
this.setLoc(this.lastBindLoc); this.setLoc(this.lastBindLoc);
this.stopMovement(this.lastBindLoc); this.stopMovement(this.lastBindLoc);
NPCManager.applyRuneSetEffects(this); NPCManager.applyRuneSetEffects(this);
this.recalculateStats(); this.recalculateStats();
this.setHealth(this.healthMax); this.setHealth(this.healthMax);
if (this.building == null && this.npcOwner != null && ((Mob) this.npcOwner).BehaviourType.ordinal() == MobBehaviourType.GuardCaptain.ordinal()) {
if (this.building == null && this.npcOwner != null && ((Mob) this.npcOwner).BehaviourType.ordinal() == MobBehaviourType.GuardCaptain.ordinal())
this.building = ((Mob) this.npcOwner).building; this.building = ((Mob) this.npcOwner).building;
} else if (this.building != null) { else if (this.building != null)
this.region = BuildingManager.GetRegion(this.building, bindLoc.x, bindLoc.y, bindLoc.z); this.region = BuildingManager.GetRegion(this.building, bindLoc.x, bindLoc.y, bindLoc.z);
}
//MovementManager.translocate(this, this.bindLoc, this.region); //MovementManager.translocate(this, this.bindLoc, this.region);
if (!this.isSiege && !this.isPlayerGuard && contract == null) if (!this.isSiege && !this.isPlayerGuard && contract == null)
loadInventory(); loadInventory();
this.updateLocation(); this.updateLocation();
} }
@ -1488,7 +1489,7 @@ public class Mob extends AbstractIntelligenceAgent {
float s; float s;
h = this.mobBase.getHealthMax(); h = this.mobBase.getHealthMax();
if(this.isPet()){ if (this.isPet()) {
h = this.level * 0.5f * 120; h = this.level * 0.5f * 120;
} }
m = this.statSpiCurrent; m = this.statSpiCurrent;
@ -2059,10 +2060,6 @@ public class Mob extends AbstractIntelligenceAgent {
this.isSiege = isSiege; this.isSiege = isSiege;
} }
public void setTimeToSpawnSiege(long timeToSpawnSiege) {
this.timeToSpawnSiege = timeToSpawnSiege;
}
public void setNpcOwner(AbstractCharacter npcOwner) { public void setNpcOwner(AbstractCharacter npcOwner) {
this.npcOwner = npcOwner; this.npcOwner = npcOwner;
} }

Loading…
Cancel
Save