diff --git a/src/engine/net/client/msg/ManageCityAssetsMsg.java b/src/engine/net/client/msg/ManageCityAssetsMsg.java index 44112d42..f02a1cb9 100644 --- a/src/engine/net/client/msg/ManageCityAssetsMsg.java +++ b/src/engine/net/client/msg/ManageCityAssetsMsg.java @@ -744,8 +744,9 @@ public class ManageCityAssetsMsg extends ClientNetMsg { if (!npcHire.isAlive()){ writer.put((byte) 1); // 1 SHOWs respawning - writer.putInt(10); // Seconds in respawn. - writer.putInt(20); + int respawnRemaining = (int)(((Mob)npcHire).deathTime + ((Mob)npcHire).spawnTime * 1000 - System.currentTimeMillis()) / 1000; + writer.putInt(respawnRemaining); // Seconds in respawn remaining. + writer.putInt(((Mob)npcHire).spawnTime); // max seconds for respawn } else writer.put((byte)0); diff --git a/src/engine/net/client/msg/ManageNPCMsg.java b/src/engine/net/client/msg/ManageNPCMsg.java index 95c1e7ed..571dead5 100644 --- a/src/engine/net/client/msg/ManageNPCMsg.java +++ b/src/engine/net/client/msg/ManageNPCMsg.java @@ -248,542 +248,560 @@ public class ManageNPCMsg extends ClientNetMsg { Period upgradePeriod; int upgradePeriodInSeconds; - try{ - - - writer.putInt(messageType); //1 - if (messageType == 5) { - writer.putInt(unknown20);//0 - writer.putInt(targetType); - writer.putInt(targetID); - - writer.putInt(GameObjectType.Building.ordinal()); - writer.putInt(buildingID); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - - } else if (messageType == 1) { - NPC npc = null; - Mob mobA = null; - - if (this.targetType == GameObjectType.NPC.ordinal()){ - - npc = NPC.getFromCache(this.targetID); - - if (npc == null) { - Logger.error("Missing NPC of ID " + this.targetID); - return; - } - - Contract contract = null; - contract = npc.getContract(); + try { - if (contract == null) { - Logger.error("Missing contract for NPC " + this.targetID); - return; - } - writer.putInt(0); //anything other than 0 seems to mess up the client + writer.putInt(messageType); //1 + if (messageType == 5) { + writer.putInt(unknown20);//0 writer.putInt(targetType); writer.putInt(targetID); - writer.putInt(0); //static.... - writer.putInt(0);//static.... - writer.putInt(Blueprint.getNpcMaintCost(npc.getRank())); // salary - - writer.putInt(npc.getUpgradeCost()); - if (npc.isRanking() && npc.getUpgradeDateTime().isAfter(DateTime.now())) - upgradePeriod = new Period(DateTime.now(), npc.getUpgradeDateTime()); - else - upgradePeriod = new Period(0); + writer.putInt(GameObjectType.Building.ordinal()); + writer.putInt(buildingID); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); - writer.put((byte) upgradePeriod.getDays()); //for timer - writer.put((byte) unknown26);//unknown - writer.putInt(100); //unknown + } else if (messageType == 1) { + NPC npc = null; + Mob mobA = null; - writer.put((byte) upgradePeriod.getHours()); //for timer - writer.put((byte) upgradePeriod.getMinutes()); //for timer - writer.put((byte) upgradePeriod.getSeconds()); //for timer + if (this.targetType == GameObjectType.NPC.ordinal()) { - if (npc.isRanking() && npc.getUpgradeDateTime().isAfter(DateTime.now())) - upgradePeriodInSeconds = Seconds.secondsBetween(DateTime.now(), npc.getUpgradeDateTime()).getSeconds(); - else - upgradePeriodInSeconds = 0; + npc = NPC.getFromCache(this.targetID); - writer.putInt(upgradePeriodInSeconds); + if (npc == null) { + Logger.error("Missing NPC of ID " + this.targetID); + return; + } - writer.put((byte) 0); - writer.put((byte) (npc.getRank() == 7 ? 0 : 1)); //0 will make the upgrade field show "N/A" - writer.put((byte) 0); - writer.put((byte) 0); - writer.putInt(0); - writer.putInt(10000); //no idea... - writer.put((byte) 0); - writer.put((byte) 0); - writer.put((byte) 0); - writer.putInt(0); + Contract contract = null; + contract = npc.getContract(); - NPCProfits profit = NPC.GetNPCProfits(npc); - - if (profit == null) - profit = NPCProfits.defaultProfits; - //adding .000000001 to match client. - int buyNormal = (int) ((profit.buyNormal + .000001f) * 100); - int buyGuild = (int) ((profit.buyGuild + .000001f) *100); - int buyNation = (int) ((profit.buyNation + .000001f) * 100); - - int sellNormal = (int) ((profit.sellNormal + .000001f) * 100); - int sellGuild = (int) ((profit.sellGuild + .000001f) * 100); - int sellNation = (int) ((profit.sellNation + .000001f) * 100); - - writer.putInt(buyNormal); - writer.putInt(buyGuild); - writer.putInt(buyNation); - writer.putInt(sellNormal); - writer.putInt(sellGuild); - writer.putInt(sellNation); - - if (contract.isRuneMaster()) { - writer.putInt(0); //vendor slots - writer.putInt(0); //artillery slots - - //figure out number of protection slots based on building rank - int runemasterSlots = (2 * npc.getRank()) + 6; - - writer.putInt( runemasterSlots); - - for (int i = 0; i < 13; i++) { - writer.putInt(0); //statics + if (contract == null) { + Logger.error("Missing contract for NPC " + this.targetID); + return; } - //some unknown list - writer.putInt(4); //list count - writer.putInt(17); - writer.putInt(2); - writer.putInt(12); - writer.putInt(23); - writer.putInt(0); //static - writer.putInt(0); //static + writer.putInt(0); //anything other than 0 seems to mess up the client + writer.putInt(targetType); + writer.putInt(targetID); + writer.putInt(0); //static.... + writer.putInt(0);//static.... + writer.putInt(Blueprint.getNpcMaintCost(npc.getRank())); // salary - //TODO add runemaster list here + writer.putInt(npc.getUpgradeCost()); - ArrayList buildingList = npc.getProtectedBuildings(); + if (npc.isRanking() && npc.getUpgradeDateTime().isAfter(DateTime.now())) + upgradePeriod = new Period(DateTime.now(), npc.getUpgradeDateTime()); + else + upgradePeriod = new Period(0); - writer.putInt(buildingList.size()); + writer.put((byte) upgradePeriod.getDays()); //for timer + writer.put((byte) unknown26);//unknown + writer.putInt(100); //unknown - for (Building b : buildingList) { - writer.putInt(3); - writer.putInt(b.getObjectType().ordinal()); - writer.putInt(b.getObjectUUID()); + writer.put((byte) upgradePeriod.getHours()); //for timer + writer.put((byte) upgradePeriod.getMinutes()); //for timer + writer.put((byte) upgradePeriod.getSeconds()); //for timer - writer.putInt(npc.getParentZone().getObjectType().ordinal()); - writer.putInt(npc.getParentZone().getObjectUUID()); + if (npc.isRanking() && npc.getUpgradeDateTime().isAfter(DateTime.now())) + upgradePeriodInSeconds = Seconds.secondsBetween(DateTime.now(), npc.getUpgradeDateTime()).getSeconds(); + else + upgradePeriodInSeconds = 0; - writer.putLong(0); //TODO Identify what Comp this is suppose to be. - if (b.getProtectionState() == ProtectionState.PENDING) - writer.put((byte)1); - else - writer.put((byte)0); - writer.put((byte)0); - writer.putString(b.getName()); - writer.putInt(1);//what? - writer.putInt(1);//what? - //taxType = b.getTaxType() - switch(b.taxType){ - case NONE: - writer.putInt(0); - writer.putInt(0); - break; - case WEEKLY: - writer.putInt(b.taxAmount); - writer.putInt(0); - break; - case PROFIT: - writer.putInt(0); - writer.putInt(b.taxAmount); - break; + writer.putInt(upgradePeriodInSeconds); - } - writer.put(b.enforceKOS ? (byte)1:0); //ENFORCE KOS - writer.put((byte)0); //?? - writer.putInt(1); - } + writer.put((byte) 0); + writer.put((byte) (npc.getRank() == 7 ? 0 : 1)); //0 will make the upgrade field show "N/A" + writer.put((byte) 0); + writer.put((byte) 0); + writer.putInt(0); + writer.putInt(10000); //no idea... + writer.put((byte) 0); + writer.put((byte) 0); + writer.put((byte) 0); + writer.putInt(0); - writer.putInt(0); //artillery captain list + NPCProfits profit = NPC.GetNPCProfits(npc); - } else if (contract.isArtilleryCaptain()) { - int slots = 1; - if (contract.getContractID() == 839) - slots = 3; + if (profit == null) + profit = NPCProfits.defaultProfits; + //adding .000000001 to match client. + int buyNormal = (int) ((profit.buyNormal + .000001f) * 100); + int buyGuild = (int) ((profit.buyGuild + .000001f) * 100); + int buyNation = (int) ((profit.buyNation + .000001f) * 100); + int sellNormal = (int) ((profit.sellNormal + .000001f) * 100); + int sellGuild = (int) ((profit.sellGuild + .000001f) * 100); + int sellNation = (int) ((profit.sellNation + .000001f) * 100); - writer.putInt(0); //vendor slots - writer.putInt(slots); //artillery slots - writer.putInt(0); //runemaster slots + writer.putInt(buyNormal); + writer.putInt(buyGuild); + writer.putInt(buyNation); + writer.putInt(sellNormal); + writer.putInt(sellGuild); + writer.putInt(sellNation); - for (int i = 0; i < 13; i++) { - writer.putInt(0); //statics - } - //some unknown list - writer.putInt(1); //list count - writer.putInt(16); - - writer.putInt(0); //static - writer.putInt(0); //static - writer.putInt(0); //runemaster list - - //artillery captain list - ConcurrentHashMap siegeMinions = npc.getSiegeMinionMap(); - writer.putInt(1 + siegeMinions.size()); - serializeBulwarkList(writer, 1); //Trebuchet - //serializeBulwarkList(writer, 2); //Ballista - - if (siegeMinions != null && siegeMinions.size() > 0) - - for (Mob mob : siegeMinions.keySet()) { - this.unknown83 = mob.getObjectUUID(); - writer.putInt(2); - writer.putInt(mob.getObjectType().ordinal()); - writer.putInt(this.unknown83); - writer.putInt(0); - writer.putInt(10); - writer.putInt(0); - writer.putInt(1); - writer.putInt(1); - writer.put((byte) 0); - long curTime = System.currentTimeMillis() / 1000; - long upgradeTime = mob.getTimeToSpawnSiege() / 1000; - long timeLife = upgradeTime - curTime; + if (contract.isRuneMaster()) { + writer.putInt(0); //vendor slots + writer.putInt(0); //artillery slots - writer.putInt(900); - writer.putInt(900); - writer.putInt((int) timeLife); //time remaining? - writer.putInt(0); - writer.put((byte)0); - writer.putString(mob.getName()); - writer.put((byte) 0); + //figure out number of protection slots based on building rank + int runemasterSlots = (2 * npc.getRank()) + 6; + + writer.putInt(runemasterSlots); + + for (int i = 0; i < 13; i++) { + writer.putInt(0); //statics } - return; + //some unknown list + writer.putInt(4); //list count + writer.putInt(17); + writer.putInt(2); + writer.putInt(12); + writer.putInt(23); - }else{ + writer.putInt(0); //static + writer.putInt(0); //static - if (Contract.NoSlots(npc.getContract())) - writer.putInt(0); - else - writer.putInt(npc.getRank()); //vendor slots - writer.putInt(0); //artilerist slots - writer.putInt(0); //runemaster slots + //TODO add runemaster list here - writer.putInt(1); //is this static? - for (int i = 0; i < 4; i++) { - writer.putInt(0); //statics - } - //Begin Item list for creation. - writer.putInt(npc.getCanRoll().size()); + ArrayList buildingList = npc.getProtectedBuildings(); - for (Integer ib : npc.getCanRoll()) { - ItemBase item = ItemBase.getItemBase(ib); - writer.put((byte) 1); - writer.putInt(0); - writer.putInt(ib); //itemID - writer.putInt(item.getBaseValue()); - writer.putInt(600); - writer.put((byte) 1); - writer.put((byte) item.getModTable()); - writer.put((byte) item.getModTable()); - writer.put((byte) item.getModTable()); - writer.put((byte) item.getModTable());//EffectItemType - } - ArrayList itemList = npc.getRolling(); + writer.putInt(buildingList.size()); - if (itemList.isEmpty()) - writer.putInt(0); - else { - if (itemList.size() < npc.getRank()) - writer.putInt(itemList.size()); - else - writer.putInt(npc.getRank()); - for (Item i : itemList) { - if (itemList.indexOf(i) >= npc.getRank()) - break; - ItemBase ib = i.getItemBase(); - writer.put((byte) 0); // ? Unknown45 - writer.putInt(i.getObjectType().ordinal()); - writer.putInt(i.getObjectUUID()); + for (Building b : buildingList) { + writer.putInt(3); + writer.putInt(b.getObjectType().ordinal()); + writer.putInt(b.getObjectUUID()); - writer.putInt(0); - writer.putInt(i.getItemBaseID()); - writer.putInt(ib.getBaseValue()); - long curTime = System.currentTimeMillis() / 1000; - long upgradeTime = i.getDateToUpgrade() / 1000; - long timeLife = i.getDateToUpgrade() - System.currentTimeMillis(); - - timeLife /= 1000; - writer.putInt((int) timeLife); - writer.putInt(npc.getRollingTimeInSeconds(i.getItemBaseID())); - writer.putInt(1); - if (i.isComplete()) + writer.putInt(npc.getParentZone().getObjectType().ordinal()); + writer.putInt(npc.getParentZone().getObjectUUID()); + + writer.putLong(0); //TODO Identify what Comp this is suppose to be. + if (b.getProtectionState() == ProtectionState.PENDING) writer.put((byte) 1); else writer.put((byte) 0); + writer.put((byte) 0); + writer.putString(b.getName()); + writer.putInt(1);//what? + writer.putInt(1);//what? + //taxType = b.getTaxType() + switch (b.taxType) { + case NONE: + writer.putInt(0); + writer.putInt(0); + break; + case WEEKLY: + writer.putInt(b.taxAmount); + writer.putInt(0); + break; + case PROFIT: + writer.putInt(0); + writer.putInt(b.taxAmount); + break; - ArrayList effectsList = i.getEffectNames(); - EffectsBase prefix = null; - EffectsBase suffix = null; + } + writer.put(b.enforceKOS ? (byte) 1 : 0); //ENFORCE KOS + writer.put((byte) 0); //?? + writer.putInt(1); + } - for (String effectName: effectsList){ - if (effectName.contains("PRE")) - prefix = PowersManager.getEffectByIDString(effectName); - if (effectName.contains("SUF")) - suffix = PowersManager.getEffectByIDString(effectName); + writer.putInt(0); //artillery captain list - } + } else if (contract.isArtilleryCaptain()) { + int slots = 1; + if (contract.getContractID() == 839) + slots = 3; - if ((prefix == null && suffix == null)) - writer.putInt(0); - else - writer.putInt(-1497023830); - if ((prefix != null && !i.isRandom()) || (prefix != null && i.isComplete())) - writer.putInt(prefix.getToken()); - else + + writer.putInt(0); //vendor slots + writer.putInt(slots); //artillery slots + writer.putInt(0); //runemaster slots + + for (int i = 0; i < 13; i++) { + writer.putInt(0); //statics + } + //some unknown list + writer.putInt(1); //list count + writer.putInt(16); + + writer.putInt(0); //static + writer.putInt(0); //static + writer.putInt(0); //runemaster list + + //artillery captain list + ConcurrentHashMap siegeMinions = npc.getSiegeMinionMap(); + writer.putInt(1 + siegeMinions.size()); + serializeBulwarkList(writer, 1); //Trebuchet + //serializeBulwarkList(writer, 2); //Ballista + + if (siegeMinions != null && siegeMinions.size() > 0) + + for (Mob mob : siegeMinions.keySet()) { + this.unknown83 = mob.getObjectUUID(); + writer.putInt(2); + writer.putInt(mob.getObjectType().ordinal()); + writer.putInt(this.unknown83); writer.putInt(0); - if ((suffix != null && !i.isRandom()) || (suffix != null && i.isComplete())) - writer.putInt(suffix.getToken()); - else + writer.putInt(10); writer.putInt(0); - writer.putString(i.getCustomName()); - } - } + writer.putInt(1); + writer.putInt(1); + writer.put((byte) 0); + long curTime = System.currentTimeMillis() / 1000; + long upgradeTime = mob.getTimeToSpawnSiege() / 1000; + long timeLife = upgradeTime - curTime; - writer.putInt(0); - writer.putInt(0); - writer.putInt(1); - writer.putInt(0); - writer.putInt(3); - writer.putInt(3); - writer.putInt(0); - writer.putString("Repair items"); - writer.putString("percent"); - writer.putInt(npc.getRepairCost()); //cost for repair - writer.putInt(0); - //ArrayList modSuffixList = - ArrayList modPrefixList = npc.getModTypeTable(); - Integer mod = modPrefixList.get(0); + writer.putInt(900); + writer.putInt(900); + writer.putInt((int) timeLife); //time remaining? + writer.putInt(0); + writer.put((byte) 0); + writer.putString(mob.getName()); + writer.put((byte) 0); + } + return; - if (mod != 0) { - writer.putInt(npc.getModTypeTable().size()); //Effects size - for (Integer mtp : npc.getModTypeTable()) { + } else { - Integer imt = modPrefixList.indexOf(mtp); - writer.putInt(npc.getItemModTable().get(imt)); //? + if (Contract.NoSlots(npc.getContract())) writer.putInt(0); + else + writer.putInt(npc.getRank()); //vendor slots + writer.putInt(0); //artilerist slots + writer.putInt(0); //runemaster slots + + writer.putInt(1); //is this static? + for (int i = 0; i < 4; i++) { + writer.putInt(0); //statics + } + //Begin Item list for creation. + writer.putInt(npc.getCanRoll().size()); + + for (Integer ib : npc.getCanRoll()) { + ItemBase item = ItemBase.getItemBase(ib); + writer.put((byte) 1); writer.putInt(0); - writer.putFloat(2); - writer.putInt(0); - writer.putInt(1); - writer.putInt(2); + writer.putInt(ib); //itemID + writer.putInt(item.getBaseValue()); + writer.putInt(600); + writer.put((byte) 1); + writer.put((byte) item.getModTable()); + writer.put((byte) item.getModTable()); + writer.put((byte) item.getModTable()); + writer.put((byte) item.getModTable());//EffectItemType + } + ArrayList itemList = npc.getRolling(); + + if (itemList.isEmpty()) writer.putInt(0); - writer.putInt(1); - writer.put(npc.getItemModTable().get(imt)); - writer.put(npc.getItemModTable().get(imt)); - writer.put(npc.getItemModTable().get(imt)); - writer.put(npc.getItemModTable().get(imt));//writer.putInt(-916801465); effectItemType - writer.putInt(mtp); //prefix - Integer mts = modPrefixList.indexOf(mtp); - writer.putInt(npc.getModSuffixTable().get(mts)); //suffix + else { + if (itemList.size() < npc.getRank()) + writer.putInt(itemList.size()); + else + writer.putInt(npc.getRank()); + for (Item i : itemList) { + if (itemList.indexOf(i) >= npc.getRank()) + break; + ItemBase ib = i.getItemBase(); + writer.put((byte) 0); // ? Unknown45 + writer.putInt(i.getObjectType().ordinal()); + writer.putInt(i.getObjectUUID()); + + writer.putInt(0); + writer.putInt(i.getItemBaseID()); + writer.putInt(ib.getBaseValue()); + long curTime = System.currentTimeMillis() / 1000; + long upgradeTime = i.getDateToUpgrade() / 1000; + long timeLife = i.getDateToUpgrade() - System.currentTimeMillis(); + + timeLife /= 1000; + writer.putInt((int) timeLife); + writer.putInt(npc.getRollingTimeInSeconds(i.getItemBaseID())); + writer.putInt(1); + if (i.isComplete()) + writer.put((byte) 1); + else + writer.put((byte) 0); + + ArrayList effectsList = i.getEffectNames(); + EffectsBase prefix = null; + EffectsBase suffix = null; + + for (String effectName : effectsList) { + if (effectName.contains("PRE")) + prefix = PowersManager.getEffectByIDString(effectName); + if (effectName.contains("SUF")) + suffix = PowersManager.getEffectByIDString(effectName); + + } + + if ((prefix == null && suffix == null)) + writer.putInt(0); + else + writer.putInt(-1497023830); + if ((prefix != null && !i.isRandom()) || (prefix != null && i.isComplete())) + writer.putInt(prefix.getToken()); + else + writer.putInt(0); + if ((suffix != null && !i.isRandom()) || (suffix != null && i.isComplete())) + writer.putInt(suffix.getToken()); + else + writer.putInt(0); + writer.putString(i.getCustomName()); + } } - } else + writer.putInt(0); - ArrayList inventory = npc.getInventory(); + writer.putInt(0); + writer.putInt(1); + writer.putInt(0); + writer.putInt(3); + writer.putInt(3); + writer.putInt(0); + writer.putString("Repair items"); + writer.putString("percent"); + writer.putInt(npc.getRepairCost()); //cost for repair + writer.putInt(0); + //ArrayList modSuffixList = + ArrayList modPrefixList = npc.getModTypeTable(); + Integer mod = modPrefixList.get(0); + if (mod != 0) { + writer.putInt(npc.getModTypeTable().size()); //Effects size + for (Integer mtp : npc.getModTypeTable()) { - writer.putInt(inventory.size()); //placeholder for item cnt + Integer imt = modPrefixList.indexOf(mtp); + writer.putInt(npc.getItemModTable().get(imt)); //? + writer.putInt(0); + writer.putInt(0); + writer.putFloat(2); + writer.putInt(0); + writer.putInt(1); + writer.putInt(2); + writer.putInt(0); + writer.putInt(1); + writer.put(npc.getItemModTable().get(imt)); + writer.put(npc.getItemModTable().get(imt)); + writer.put(npc.getItemModTable().get(imt)); + writer.put(npc.getItemModTable().get(imt));//writer.putInt(-916801465); effectItemType + writer.putInt(mtp); //prefix + Integer mts = modPrefixList.indexOf(mtp); + writer.putInt(npc.getModSuffixTable().get(mts)); //suffix + } + } else + writer.putInt(0); + ArrayList inventory = npc.getInventory(); + writer.putInt(inventory.size()); //placeholder for item cnt - for (Item i : inventory) { - Item.serializeForClientMsgWithoutSlot(i,writer); - } + for (Item i : inventory) { + Item.serializeForClientMsgWithoutSlot(i, writer); + } - writer.putInt(0); - writer.putInt(5); - writer.putInt(1); - writer.putInt(2); - writer.putInt(15); - writer.putInt(3); - writer.putInt(18); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - } + writer.putInt(0); + writer.putInt(5); + writer.putInt(1); + writer.putInt(2); + writer.putInt(15); + writer.putInt(3); + writer.putInt(18); - }else if (this.targetType == GameObjectType.Mob.ordinal()){ + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + } - mobA = Mob.getFromCacheDBID(this.targetID); - if (mobA == null) { - Logger.error("Missing Mob of ID " + this.targetID); - return; - } + } else if (this.targetType == GameObjectType.Mob.ordinal()) { - if (mobA != null){ - Contract con = mobA.getContract(); - if (con == null) { - Logger.error("Missing contract for NPC " + this.targetID); + mobA = Mob.getFromCacheDBID(this.targetID); + if (mobA == null) { + Logger.error("Missing Mob of ID " + this.targetID); return; } - int maxSlots = 1; - - switch (mobA.getRank()){ - case 1: - case 2: - maxSlots = 1; - break; - case 3: - maxSlots = 2; - break; - case 4: - case 5: - maxSlots = 3; - break; - case 6: - maxSlots = 4; - break; - case 7: - maxSlots = 5; - break; - default: - maxSlots = 1; - - } - if(NPC.ISGuardCaptain(mobA.getContract().getContractID()) == false){ - maxSlots =0; - } - writer.putInt(0); //anything other than 0 seems to mess up the client - writer.putInt(targetType); - writer.putInt(targetID); - writer.putInt(0); //static.... - writer.putInt(0);//static.... - writer.putInt(Blueprint.getNpcMaintCost(mobA.getRank())); // salary + if (mobA != null) { + Contract con = mobA.getContract(); + if (con == null) { + Logger.error("Missing contract for NPC " + this.targetID); + return; + } - writer.putInt(Mob.getUpgradeCost(mobA)); + int maxSlots = 1; - if (mobA.isRanking() && mobA.getUpgradeDateTime().isAfter(DateTime.now())) - upgradePeriod = new Period(DateTime.now(), mobA.getUpgradeDateTime()); - else - upgradePeriod = new Period(0); + switch (mobA.getRank()) { + case 1: + case 2: + maxSlots = 1; + break; + case 3: + maxSlots = 2; + break; + case 4: + case 5: + maxSlots = 3; + break; + case 6: + maxSlots = 4; + break; + case 7: + maxSlots = 5; + break; + default: + maxSlots = 1; - writer.put((byte) upgradePeriod.getDays()); //for timer - writer.put((byte) unknown26);//unknown - writer.putInt(100); //unknown + } + if (NPC.ISGuardCaptain(mobA.getContract().getContractID()) == false) { + maxSlots = 0; + } + writer.putInt(0); //anything other than 0 seems to mess up the client + writer.putInt(targetType); + writer.putInt(targetID); + writer.putInt(0); //static.... + writer.putInt(0);//static.... + writer.putInt(Blueprint.getNpcMaintCost(mobA.getRank())); // salary - writer.put((byte) upgradePeriod.getHours()); //for timer - writer.put((byte) upgradePeriod.getMinutes()); //for timer - writer.put((byte) upgradePeriod.getSeconds()); //for timer + writer.putInt(Mob.getUpgradeCost(mobA)); - if (mobA.isRanking() && mobA.getUpgradeDateTime().isAfter(DateTime.now())) - upgradePeriodInSeconds = Seconds.secondsBetween(DateTime.now(), mobA.getUpgradeDateTime()).getSeconds(); - else - upgradePeriodInSeconds = 0; + if (mobA.isRanking() && mobA.getUpgradeDateTime().isAfter(DateTime.now())) + upgradePeriod = new Period(DateTime.now(), mobA.getUpgradeDateTime()); + else + upgradePeriod = new Period(0); - writer.putInt(upgradePeriodInSeconds); + writer.put((byte) upgradePeriod.getDays()); //for timer + writer.put((byte) unknown26);//unknown + writer.putInt(100); //unknown + writer.put((byte) upgradePeriod.getHours()); //for timer + writer.put((byte) upgradePeriod.getMinutes()); //for timer + writer.put((byte) upgradePeriod.getSeconds()); //for timer - writer.put((byte) 0); - writer.put((byte) (mobA.getRank() == 7 ? 0 : 1)); //0 will make the upgrade field show "N/A" - writer.put((byte) 0); - writer.put((byte) 0); - writer.putInt(0); - writer.putInt(10000); //no idea... - writer.put((byte) 0); - writer.put((byte) 0); - writer.put((byte) 0); - writer.putInt(0); + if (mobA.isRanking() && mobA.getUpgradeDateTime().isAfter(DateTime.now())) + upgradePeriodInSeconds = Seconds.secondsBetween(DateTime.now(), mobA.getUpgradeDateTime()).getSeconds(); + else + upgradePeriodInSeconds = 0; + writer.putInt(upgradePeriodInSeconds); - NPCProfits profit = NPCProfits.defaultProfits; - - writer.putInt((int) (profit.buyNormal * 100)); - writer.putInt((int) (profit.buyGuild * 100)); - writer.putInt((int) (profit.buyNation * 100)); - writer.putInt((int) (profit.sellNormal * 100)); - writer.putInt((int) (profit.sellGuild * 100)); - writer.putInt((int) (profit.sellNation * 100)); - writer.putInt(0); //vendor slots - writer.putInt(maxSlots); //artillery slots - writer.putInt(0); //runemaster slots + writer.put((byte) 0); + writer.put((byte) (mobA.getRank() == 7 ? 0 : 1)); //0 will make the upgrade field show "N/A" + writer.put((byte) 0); + writer.put((byte) 0); + writer.putInt(0); + writer.putInt(10000); //no idea... + writer.put((byte) 0); + writer.put((byte) 0); + writer.put((byte) 0); + writer.putInt(0); - for (int i = 0; i < 13; i++) { - writer.putInt(0); //statics - } - //some unknown list - writer.putInt(1); //list count - writer.putInt(16); - writer.putInt(0); //static - writer.putInt(0); //static - writer.putInt(0); //runemaster list + NPCProfits profit = NPCProfits.defaultProfits; - //artillery captain list - ConcurrentHashMap siegeMinions = mobA.getSiegeMinionMap(); + writer.putInt((int) (profit.buyNormal * 100)); + writer.putInt((int) (profit.buyGuild * 100)); + writer.putInt((int) (profit.buyNation * 100)); + writer.putInt((int) (profit.sellNormal * 100)); + writer.putInt((int) (profit.sellGuild * 100)); + writer.putInt((int) (profit.sellNation * 100)); - - writer.putInt(siegeMinions.size() + 1); - serializeGuardList(writer, mobA.getContract().getContractID()); //Guard - - if (siegeMinions != null && siegeMinions.size() > 0) - - for (Mob mob : siegeMinions.keySet()) { - this.unknown83 = mob.getObjectUUID(); - writer.putInt(2); - writer.putInt(mob.getObjectType().ordinal()); - writer.putInt(this.unknown83); - writer.putInt(0); - writer.putInt(10); - writer.putInt(0); - writer.putInt(1); - writer.putInt(1); - writer.put((byte) 0); - long curTime = System.currentTimeMillis() / 1000; - long upgradeTime = mob.getTimeToSpawnSiege() / 1000; - long timeLife = upgradeTime - curTime; + writer.putInt(0); //vendor slots + writer.putInt(maxSlots); //artillery slots + writer.putInt(0); //runemaster slots - writer.putInt(900); - writer.putInt(900); - writer.putInt((int) timeLife); //time remaining? - writer.putInt(0); - writer.put((byte)0); - writer.putString(mob.getNameOverride().isEmpty() ? mob.getName() : mob.getNameOverride()); - writer.put((byte) 0); + for (int i = 0; i < 13; i++) { + writer.putInt(0); //statics } + //some unknown list + writer.putInt(1); //list count + writer.putInt(16); - } + writer.putInt(0); //static + writer.putInt(0); //static + writer.putInt(0); //runemaster list + //artillery captain list + ConcurrentHashMap siegeMinions = mobA.getSiegeMinionMap(); - } - } - + writer.putInt(siegeMinions.size() + 1); + serializeGuardList(writer, mobA.getContract().getContractID()); //Guard + + if (siegeMinions != null && siegeMinions.size() > 0) + + for (Mob mob : siegeMinions.keySet()) { + this.unknown83 = mob.getObjectUUID(); + writer.putInt(2); + writer.putInt(mob.getObjectType().ordinal()); + writer.putInt(this.unknown83); + writer.putInt(0); + writer.putInt(10); + writer.putInt(0); + writer.putInt(1); + writer.putInt(1); + + long curTime = System.currentTimeMillis() / 1000; + long upgradeTime = (mob.deathTime + (mob.spawnTime * 1000)) / 1000; + long timeLife = upgradeTime - curTime; + if (upgradeTime * 1000 > System.currentTimeMillis()) { + if(mob.npcOwner.isAlive()) { + writer.put((byte) 0);//shows respawning timer + writer.putInt(mob.spawnTime); + writer.putInt(mob.spawnTime); + writer.putInt((int) timeLife); //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{ + 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){ e.printStackTrace(); }