Browse Source

NPCs in buildings show correct spawn times and progress

master
FatBoy-DOTC 2 years ago
parent
commit
76f3d2599b
  1. 5
      src/engine/net/client/msg/ManageCityAssetsMsg.java
  2. 82
      src/engine/net/client/msg/ManageNPCMsg.java

5
src/engine/net/client/msg/ManageCityAssetsMsg.java

@ -744,8 +744,9 @@ public class ManageCityAssetsMsg extends ClientNetMsg {
if (!npcHire.isAlive()){ if (!npcHire.isAlive()){
writer.put((byte) 1); // 1 SHOWs respawning writer.put((byte) 1); // 1 SHOWs respawning
writer.putInt(10); // Seconds in respawn. int respawnRemaining = (int)(((Mob)npcHire).deathTime + ((Mob)npcHire).spawnTime * 1000 - System.currentTimeMillis()) / 1000;
writer.putInt(20); writer.putInt(respawnRemaining); // Seconds in respawn remaining.
writer.putInt(((Mob)npcHire).spawnTime); // max seconds for respawn
} }
else else
writer.put((byte)0); writer.put((byte)0);

82
src/engine/net/client/msg/ManageNPCMsg.java

@ -248,7 +248,7 @@ public class ManageNPCMsg extends ClientNetMsg {
Period upgradePeriod; Period upgradePeriod;
int upgradePeriodInSeconds; int upgradePeriodInSeconds;
try{ try {
writer.putInt(messageType); //1 writer.putInt(messageType); //1
@ -281,7 +281,7 @@ public class ManageNPCMsg extends ClientNetMsg {
NPC npc = null; NPC npc = null;
Mob mobA = null; Mob mobA = null;
if (this.targetType == GameObjectType.NPC.ordinal()){ if (this.targetType == GameObjectType.NPC.ordinal()) {
npc = NPC.getFromCache(this.targetID); npc = NPC.getFromCache(this.targetID);
@ -344,7 +344,7 @@ public class ManageNPCMsg extends ClientNetMsg {
profit = NPCProfits.defaultProfits; profit = NPCProfits.defaultProfits;
//adding .000000001 to match client. //adding .000000001 to match client.
int buyNormal = (int) ((profit.buyNormal + .000001f) * 100); int buyNormal = (int) ((profit.buyNormal + .000001f) * 100);
int buyGuild = (int) ((profit.buyGuild + .000001f) *100); int buyGuild = (int) ((profit.buyGuild + .000001f) * 100);
int buyNation = (int) ((profit.buyNation + .000001f) * 100); int buyNation = (int) ((profit.buyNation + .000001f) * 100);
int sellNormal = (int) ((profit.sellNormal + .000001f) * 100); int sellNormal = (int) ((profit.sellNormal + .000001f) * 100);
@ -365,7 +365,7 @@ public class ManageNPCMsg extends ClientNetMsg {
//figure out number of protection slots based on building rank //figure out number of protection slots based on building rank
int runemasterSlots = (2 * npc.getRank()) + 6; int runemasterSlots = (2 * npc.getRank()) + 6;
writer.putInt( runemasterSlots); writer.putInt(runemasterSlots);
for (int i = 0; i < 13; i++) { for (int i = 0; i < 13; i++) {
writer.putInt(0); //statics writer.putInt(0); //statics
@ -396,15 +396,15 @@ public class ManageNPCMsg extends ClientNetMsg {
writer.putLong(0); //TODO Identify what Comp this is suppose to be. writer.putLong(0); //TODO Identify what Comp this is suppose to be.
if (b.getProtectionState() == ProtectionState.PENDING) if (b.getProtectionState() == ProtectionState.PENDING)
writer.put((byte)1); writer.put((byte) 1);
else else
writer.put((byte)0); writer.put((byte) 0);
writer.put((byte)0); writer.put((byte) 0);
writer.putString(b.getName()); writer.putString(b.getName());
writer.putInt(1);//what? writer.putInt(1);//what?
writer.putInt(1);//what? writer.putInt(1);//what?
//taxType = b.getTaxType() //taxType = b.getTaxType()
switch(b.taxType){ switch (b.taxType) {
case NONE: case NONE:
writer.putInt(0); writer.putInt(0);
writer.putInt(0); writer.putInt(0);
@ -419,8 +419,8 @@ public class ManageNPCMsg extends ClientNetMsg {
break; break;
} }
writer.put(b.enforceKOS ? (byte)1:0); //ENFORCE KOS writer.put(b.enforceKOS ? (byte) 1 : 0); //ENFORCE KOS
writer.put((byte)0); //?? writer.put((byte) 0); //??
writer.putInt(1); writer.putInt(1);
} }
@ -474,13 +474,13 @@ public class ManageNPCMsg extends ClientNetMsg {
writer.putInt(900); writer.putInt(900);
writer.putInt((int) timeLife); //time remaining? writer.putInt((int) timeLife); //time remaining?
writer.putInt(0); writer.putInt(0);
writer.put((byte)0); writer.put((byte) 0);
writer.putString(mob.getName()); writer.putString(mob.getName());
writer.put((byte) 0); writer.put((byte) 0);
} }
return; return;
}else{ } else {
if (Contract.NoSlots(npc.getContract())) if (Contract.NoSlots(npc.getContract()))
writer.putInt(0); writer.putInt(0);
@ -546,7 +546,7 @@ public class ManageNPCMsg extends ClientNetMsg {
EffectsBase prefix = null; EffectsBase prefix = null;
EffectsBase suffix = null; EffectsBase suffix = null;
for (String effectName: effectsList){ for (String effectName : effectsList) {
if (effectName.contains("PRE")) if (effectName.contains("PRE"))
prefix = PowersManager.getEffectByIDString(effectName); prefix = PowersManager.getEffectByIDString(effectName);
if (effectName.contains("SUF")) if (effectName.contains("SUF"))
@ -615,10 +615,9 @@ public class ManageNPCMsg extends ClientNetMsg {
writer.putInt(inventory.size()); //placeholder for item cnt writer.putInt(inventory.size()); //placeholder for item cnt
for (Item i : inventory) { for (Item i : inventory) {
Item.serializeForClientMsgWithoutSlot(i,writer); Item.serializeForClientMsgWithoutSlot(i, writer);
} }
@ -636,7 +635,7 @@ public class ManageNPCMsg extends ClientNetMsg {
writer.putInt(0); writer.putInt(0);
} }
}else if (this.targetType == GameObjectType.Mob.ordinal()){ } else if (this.targetType == GameObjectType.Mob.ordinal()) {
mobA = Mob.getFromCacheDBID(this.targetID); mobA = Mob.getFromCacheDBID(this.targetID);
if (mobA == null) { if (mobA == null) {
@ -644,7 +643,7 @@ public class ManageNPCMsg extends ClientNetMsg {
return; return;
} }
if (mobA != null){ if (mobA != null) {
Contract con = mobA.getContract(); Contract con = mobA.getContract();
if (con == null) { if (con == null) {
Logger.error("Missing contract for NPC " + this.targetID); Logger.error("Missing contract for NPC " + this.targetID);
@ -653,7 +652,7 @@ public class ManageNPCMsg extends ClientNetMsg {
int maxSlots = 1; int maxSlots = 1;
switch (mobA.getRank()){ switch (mobA.getRank()) {
case 1: case 1:
case 2: case 2:
maxSlots = 1; maxSlots = 1;
@ -675,8 +674,8 @@ public class ManageNPCMsg extends ClientNetMsg {
maxSlots = 1; maxSlots = 1;
} }
if(NPC.ISGuardCaptain(mobA.getContract().getContractID()) == false){ if (NPC.ISGuardCaptain(mobA.getContract().getContractID()) == false) {
maxSlots =0; maxSlots = 0;
} }
writer.putInt(0); //anything other than 0 seems to mess up the client writer.putInt(0); //anything other than 0 seems to mess up the client
writer.putInt(targetType); writer.putInt(targetType);
@ -763,27 +762,46 @@ public class ManageNPCMsg extends ClientNetMsg {
writer.putInt(0); writer.putInt(0);
writer.putInt(1); writer.putInt(1);
writer.putInt(1); writer.putInt(1);
writer.put((byte) 0);
long curTime = System.currentTimeMillis() / 1000; long curTime = System.currentTimeMillis() / 1000;
long upgradeTime = mob.getTimeToSpawnSiege() / 1000; long upgradeTime = (mob.deathTime + (mob.spawnTime * 1000)) / 1000;
long timeLife = upgradeTime - curTime; long timeLife = upgradeTime - curTime;
if (upgradeTime * 1000 > System.currentTimeMillis()) {
writer.putInt(900); if(mob.npcOwner.isAlive()) {
writer.putInt(900); writer.put((byte) 0);//shows respawning timer
writer.putInt((int) timeLife); //time remaining? writer.putInt(mob.spawnTime);
writer.putInt(mob.spawnTime);
writer.putInt((int) timeLife); //time remaining for mob that is dead
writer.putInt(0); writer.putInt(0);
writer.put((byte)0); writer.put((byte) 0);
writer.putString(mob.getNameOverride().isEmpty() ? mob.getName() : mob.getNameOverride()); writer.putString(mob.getNameOverride().isEmpty() ? mob.getName() : mob.getNameOverride());
writer.put((byte) 0); writer.put((byte) 0);
} }
else{
writer.put((byte) 0);//shows respawning timer
writer.putInt(0);
writer.putInt(0);
writer.putInt(0); //time remaining for mob that is dead
writer.putInt(0);
writer.put((byte) 0);
writer.putString(mob.getNameOverride().isEmpty() ? mob.getName() : mob.getNameOverride());
writer.put((byte) 0);
}
} else {
//nothing required for countdown for a mob that is alive
writer.put((byte) 1);//shows "Standing By"
writer.putInt(0);
writer.putInt(0);
writer.putInt(0);
writer.putInt(0);
writer.put((byte) 0);
writer.putString(mob.getNameOverride().isEmpty() ? mob.getName() : mob.getNameOverride());
writer.put((byte) 0);
}
}
} }
} }
} }
}catch(Exception e){ }catch(Exception e){
e.printStackTrace(); e.printStackTrace();
} }

Loading…
Cancel
Save