Browse Source

optimized

lakebane-master
FatBoy-DOTC 7 months ago
parent
commit
40078df067
  1. 556
      src/engine/gameManager/LootManager.java
  2. 132
      src/engine/gameManager/ZergManager.java
  3. 224
      src/engine/objects/Warehouse.java
  4. 138
      src/engine/workthreads/ZergMechanicThread.java

556
src/engine/gameManager/LootManager.java

@ -73,38 +73,38 @@ public enum LootManager {
} }
public static void GenerateMobLoot(Mob mob) { public static void GenerateMobLoot(Mob mob) {
int mobBootySet = mob.getMobBase().bootySet;
if (mobBootySet != 0) {
RunBootySetIfPresent(mobBootySet, mob);
}
//iterate the booty sets mobBootySet = mob.bootySet;
if (mobBootySet != 0) {
if (mob.getMobBase().bootySet != 0 && _bootySetMap.containsKey(mob.getMobBase().bootySet) == true) RunBootySetIfPresent(mobBootySet, mob);
RunBootySet(_bootySetMap.get(mob.getMobBase().bootySet), mob); }
if (mob.bootySet != 0 && _bootySetMap.containsKey(mob.bootySet) == true)
RunBootySet(_bootySetMap.get(mob.bootySet), mob);
//lastly, check mobs inventory for godly or disc runes to send a server announcement
for (Item it : mob.getInventory()) {
ItemBase ib = it.getItemBase(); // Check mob's inventory for godly or disc runes to send a server announcement
if(ib == null) for (Item item : mob.getInventory()) {
break; ItemBase itemBase = item.getItemBase();
if (ib.getName().toLowerCase().contains("of the gods")) { if (itemBase != null && itemBase.getName().toLowerCase().contains("of the gods")) {
ChatSystemMsg chatMsg = new ChatSystemMsg(null, mob.getName() + " in " + mob.getParentZone().getName() + " has found the " + ib.getName() + ". Are you tough enough to take it?"); ChatSystemMsg chatMsg = new ChatSystemMsg(
null,
mob.getName() + " in " + mob.getParentZone().getName() + " has found the " + itemBase.getName() + ". Are you tough enough to take it?"
);
chatMsg.setMessageType(10); chatMsg.setMessageType(10);
chatMsg.setChannel(Enum.ChatChannelType.SYSTEM.getChannelID()); chatMsg.setChannel(Enum.ChatChannelType.SYSTEM.getChannelID());
DispatchMessage.dispatchMsgToAll(chatMsg); DispatchMessage.dispatchMsgToAll(chatMsg);
} }
} }
} }
private static void RunBootySet(ArrayList<BootySetEntry> entries, Mob mob) { private static void RunBootySet(ArrayList<BootySetEntry> entries, Mob mob) {
float dropRate = NORMAL_DROP_RATE; float dropRate = NORMAL_DROP_RATE;
//roll the geenric world drop table boolean isSafeZone = mob.parentZone.getSafeZone() == 0;
if(mob.parentZone.getSafeZone() == 0) {
if (isSafeZone) {
GenerateLootDrop(mob, 1300); GenerateLootDrop(mob, 1300);
if(ThreadLocalRandom.current().nextInt(1, 10000) == 5000) { if (ThreadLocalRandom.current().nextInt(1, 10000) == 5000) {
MobLoot extraLoot = rollForGlass(mob); MobLoot extraLoot = rollForGlass(mob);
if (extraLoot != null) { if (extraLoot != null) {
mob.getCharItemManager().addItemToInventory(extraLoot); mob.getCharItemManager().addItemToInventory(extraLoot);
@ -112,7 +112,6 @@ public enum LootManager {
} }
} }
// Iterate all entries in this bootySet and process accordingly
boolean hasExtraRolled = false; boolean hasExtraRolled = false;
for (BootySetEntry bse : entries) { for (BootySetEntry bse : entries) {
switch (bse.bootyType) { switch (bse.bootyType) {
@ -120,17 +119,13 @@ public enum LootManager {
GenerateGoldDrop(mob, bse); GenerateGoldDrop(mob, bse);
break; break;
case "LOOT": case "LOOT":
if (ThreadLocalRandom.current().nextInt(1, 100 + 1) < (bse.dropChance * dropRate)) if (ThreadLocalRandom.current().nextInt(1, 101) < (bse.dropChance * dropRate)) {
GenerateLootDrop(mob, bse.genTable); //generate normal loot drop GenerateLootDrop(mob, bse.genTable);
if (mob.parentZone.getSafeZone() == 0 && hasExtraRolled == false && ThreadLocalRandom.current().nextInt(1, 5000) < 15 * dropRate) {
int roll = ThreadLocalRandom.current().nextInt(1, 101);
MobLoot extraLoot = null;
if (roll <= 50) {
extraLoot = rollForContract(bse.genTable, mob);
}
if (roll >= 51) {
extraLoot = rollForRune(bse.genTable, mob);
} }
if (isSafeZone && !hasExtraRolled && ThreadLocalRandom.current().nextInt(1, 5000) < 15 * dropRate) {
MobLoot extraLoot = (ThreadLocalRandom.current().nextInt(1, 101) <= 50)
? rollForContract(bse.genTable, mob)
: rollForRune(bse.genTable, mob);
if (extraLoot != null) { if (extraLoot != null) {
mob.getCharItemManager().addItemToInventory(extraLoot); mob.getCharItemManager().addItemToInventory(extraLoot);
} }
@ -142,45 +137,60 @@ public enum LootManager {
break; break;
} }
} }
MobLoot specialDrop = getSpecialDropForMob(mob);
if (specialDrop != null) {
enhanceMob(mob, specialDrop);
}
}
private static void RunBootySetIfPresent(int bootySet, Mob mob) {
if (_bootySetMap.containsKey(bootySet)) {
RunBootySet(_bootySetMap.get(bootySet), mob);
}
}
private static MobLoot getSpecialDropForMob(Mob mob) {
MobLoot specialDrop = null; MobLoot specialDrop = null;
switch(mob.getObjectUUID()) { int mobUUID = mob.getObjectUUID();
case 22595://elf 1 switch (mobUUID) {
specialDrop = new MobLoot(mob,ItemBase.getItemBase(252134),true); case 22595:
mob.setFirstName("Melandrach The Blood-Mage"); specialDrop = createSpecialDrop(mob, 252134, "Melandrach The Blood-Mage");
break; break;
case 22432: //elf 2 case 22432:
specialDrop = new MobLoot(mob,ItemBase.getItemBase(252135),true); specialDrop = createSpecialDrop(mob, 252135, "Kyrtaar The Blood-Mage");
mob.setFirstName("Kyrtaar The Blood-Mage");
break; break;
case 22537: //elf 3 case 22537:
specialDrop = new MobLoot(mob,ItemBase.getItemBase(252136),true); specialDrop = createSpecialDrop(mob, 252136, "Vamir The Blood-Mage");
mob.setFirstName("Vamir The Blood-Mage");
break; break;
case 16387: //human 4 DONE case 16387:
specialDrop = new MobLoot(mob,ItemBase.getItemBase(252129),true); specialDrop = createSpecialDrop(mob, 252129, "Alatar The Blood-Mage");
mob.setFirstName("Alatar The Blood-Mage");
break; break;
case 32724:// human 5 GOOD case 32724:
specialDrop = new MobLoot(mob,ItemBase.getItemBase(252130),true); specialDrop = createSpecialDrop(mob, 252130, "Elphaba The Blood-Mage");
mob.setFirstName("Elphaba The Blood-Mage");
break; break;
case 23379: //human 1 GOOD case 23379:
specialDrop = new MobLoot(mob,ItemBase.getItemBase(252131),true); specialDrop = createSpecialDrop(mob, 252131, "Bavmorda The Blood-Mage");
mob.setFirstName("Bavmorda The Blood-Mage");
break; break;
case 10826: //human 2 REDO case 10826:
specialDrop = new MobLoot(mob,ItemBase.getItemBase(252132),true); specialDrop = createSpecialDrop(mob, 252132, "Draco The Blood-Mage");
mob.setFirstName("Draco The Blood-Mage");
break; break;
case 15929: //human 3 GOOD case 15929:
specialDrop = new MobLoot(mob,ItemBase.getItemBase(252133),true); specialDrop = createSpecialDrop(mob, 252133, "Atlantes The Blood-Mage");
mob.setFirstName("Atlantes The Blood-Mage");
break; break;
} }
if(specialDrop != null) { return specialDrop;
}
private static MobLoot createSpecialDrop(Mob mob, int itemBaseId, String name) {
mob.setFirstName(name);
return new MobLoot(mob, ItemBase.getItemBase(itemBaseId), true);
}
private static void enhanceMob(Mob mob, MobLoot specialDrop) {
mob.setLevel((short) 65); mob.setLevel((short) 65);
mob.setSpawnTime(10800); mob.setSpawnTime(10800);
mob.healthMax = (7500); mob.healthMax = 7500;
mob.setHealth(7500); mob.setHealth(7500);
ChatSystemMsg chatMsg = new ChatSystemMsg(null, mob.getName() + " in " + mob.getParentZone().getName() + " has found the " + specialDrop.getName() + ". Are you tough enough to take it?"); ChatSystemMsg chatMsg = new ChatSystemMsg(null, mob.getName() + " in " + mob.getParentZone().getName() + " has found the " + specialDrop.getName() + ". Are you tough enough to take it?");
chatMsg.setMessageType(10); chatMsg.setMessageType(10);
@ -189,100 +199,81 @@ public enum LootManager {
mob.getCharItemManager().addItemToInventory(specialDrop); mob.getCharItemManager().addItemToInventory(specialDrop);
mob.setResists(new Resists("Dropper")); mob.setResists(new Resists("Dropper"));
} }
}
public static MobLoot getGenTableItem(int genTableID, AbstractCharacter mob) { public static MobLoot getGenTableItem(int genTableID, AbstractCharacter mob) {
if (mob == null || !_genTables.containsKey(genTableID)) {
if (mob == null || _genTables.containsKey(genTableID) == false)
return null; return null;
}
MobLoot outItem; int genRoll = ThreadLocalRandom.current().nextInt(1, 95);
int genRoll = ThreadLocalRandom.current().nextInt(1,94 + 1);
GenTableEntry selectedRow = GenTableEntry.rollTable(genTableID, genRoll, 1.0f); GenTableEntry selectedRow = GenTableEntry.rollTable(genTableID, genRoll, 1.0f);
if (selectedRow == null) if (selectedRow == null || !_itemTables.containsKey(selectedRow.itemTableID)) {
return null; return null;
}
int itemTableId = selectedRow.itemTableID; int itemTableRoll = (mob.getObjectType().ordinal() == 52) ?
ThreadLocalRandom.current().nextInt(1, 321) :
TableRoll(mob.level);
if (_itemTables.containsKey(itemTableId) == false) ItemTableEntry tableRow = ItemTableEntry.rollTable(selectedRow.itemTableID, itemTableRoll);
return null;
//gets the 1-320 roll for this mob if (tableRow == null || tableRow.cacheID == 0) {
int itemTableRoll = 0;
int objectType = mob.getObjectType().ordinal();
if(mob.getObjectType().ordinal() == 52) { //52 = player character
itemTableRoll = ThreadLocalRandom.current().nextInt(1,320 + 1);
} else{
itemTableRoll = TableRoll(mob.level);
}
ItemTableEntry tableRow = ItemTableEntry.rollTable(itemTableId, itemTableRoll);
if (tableRow == null)
return null; return null;
}
int itemUUID = tableRow.cacheID; ItemBase itemBase = ItemBase.getItemBase(tableRow.cacheID);
if (itemBase == null) {
if (itemUUID == 0)
return null; return null;
}
if (ItemBase.getItemBase(itemUUID).getType().ordinal() == Enum.ItemType.RESOURCE.ordinal()) { if (itemBase.getType() == Enum.ItemType.RESOURCE) {
int chance = ThreadLocalRandom.current().nextInt(1,101); if (ThreadLocalRandom.current().nextInt(1, 101) > 10) {
if(chance > 10)
return null; return null;
int amount = ThreadLocalRandom.current().nextInt((int)(tableRow.minSpawn * 0.5f), (int)((tableRow.maxSpawn + 1) * 0.5f)); }
return new MobLoot(mob, ItemBase.getItemBase(itemUUID), amount, false); int amount = ThreadLocalRandom.current().nextInt((int) (tableRow.minSpawn * 0.5f),
(int) ((tableRow.maxSpawn + 1) * 0.5f));
return new MobLoot(mob, itemBase, amount, false);
} }
outItem = new MobLoot(mob, ItemBase.getItemBase(itemUUID), false); MobLoot outItem = new MobLoot(mob, itemBase, false);
Enum.ItemType outType = outItem.getItemBase().getType();
if(selectedRow.pModTable != 0){
try { try {
if (selectedRow.pModTable != 0) {
outItem = GeneratePrefix(mob, outItem, genTableID, genRoll); outItem = GeneratePrefix(mob, outItem, genTableID, genRoll);
outItem.setIsID(false); outItem.setIsID(false);
} catch (Exception e) {
Logger.error("Failed to GeneratePrefix for item: " + outItem.getName());
} }
} if (selectedRow.sModTable != 0) {
if(selectedRow.sModTable != 0){
try {
outItem = GenerateSuffix(mob, outItem, genTableID, genRoll); outItem = GenerateSuffix(mob, outItem, genTableID, genRoll);
outItem.setIsID(false); outItem.setIsID(false);
} catch (Exception e) {
Logger.error("Failed to GenerateSuffix for item: " + outItem.getName());
} }
} catch (Exception e) {
Logger.error("Failed to generate mod for item: " + outItem.getName(), e);
} }
return outItem; return outItem;
} }
private static MobLoot GeneratePrefix(AbstractCharacter mob, MobLoot inItem, int genTableID, int genRoll) { private static MobLoot GeneratePrefix(AbstractCharacter mob, MobLoot inItem, int genTableID, int genRoll) {
GenTableEntry selectedRow = GenTableEntry.rollTable(genTableID, genRoll, 1.0f); GenTableEntry selectedRow = GenTableEntry.rollTable(genTableID, genRoll, 1.0f);
if (selectedRow == null) {
if (selectedRow == null)
return inItem; return inItem;
}
int prefixroll = ThreadLocalRandom.current().nextInt(1, 100 + 1); ModTypeTableEntry prefixTable = ModTypeTableEntry.rollTable(selectedRow.pModTable, ThreadLocalRandom.current().nextInt(1, 101));
if (prefixTable == null) {
ModTypeTableEntry prefixTable = ModTypeTableEntry.rollTable(selectedRow.pModTable, prefixroll);
if (prefixTable == null)
return inItem; return inItem;
int prefixTableRoll = 0;
if(mob.getObjectType().ordinal() == 52) {
prefixTableRoll = ThreadLocalRandom.current().nextInt(1,320 + 1);
} else{
prefixTableRoll = TableRoll(mob.level);
} }
ModTableEntry prefixMod = ModTableEntry.rollTable(prefixTable.modTableID, prefixTableRoll);
if (prefixMod == null) int prefixTableRoll = (mob.getObjectType().ordinal() == 52) ?
ThreadLocalRandom.current().nextInt(1, 321) :
TableRoll(mob.level);
ModTableEntry prefixMod = ModTableEntry.rollTable(prefixTable.modTableID, prefixTableRoll);
if (prefixMod == null) {
return inItem; return inItem;
}
if (prefixMod.action.length() > 0) { if (!prefixMod.action.isEmpty()) {
inItem.setPrefix(prefixMod.action); inItem.setPrefix(prefixMod.action);
inItem.addPermanentEnchantment(prefixMod.action, 0, prefixMod.level, true); inItem.addPermanentEnchantment(prefixMod.action, 0, prefixMod.level, true);
} }
@ -291,30 +282,26 @@ public enum LootManager {
} }
private static MobLoot GenerateSuffix(AbstractCharacter mob, MobLoot inItem, int genTableID, int genRoll) { private static MobLoot GenerateSuffix(AbstractCharacter mob, MobLoot inItem, int genTableID, int genRoll) {
GenTableEntry selectedRow = GenTableEntry.rollTable(genTableID, genRoll, 1.0f); GenTableEntry selectedRow = GenTableEntry.rollTable(genTableID, genRoll, 1.0f);
if (selectedRow == null) {
if (selectedRow == null)
return inItem; return inItem;
}
int suffixRoll = ThreadLocalRandom.current().nextInt(1, 100 + 1); ModTypeTableEntry suffixTable = ModTypeTableEntry.rollTable(selectedRow.sModTable, ThreadLocalRandom.current().nextInt(1, 101));
if (suffixTable == null) {
ModTypeTableEntry suffixTable = ModTypeTableEntry.rollTable(selectedRow.sModTable, suffixRoll);
if (suffixTable == null)
return inItem; return inItem;
int suffixTableRoll = 0;
if(mob.getObjectType().ordinal() == 52) {
suffixTableRoll = ThreadLocalRandom.current().nextInt(1,320 + 1);
} else{
suffixTableRoll = TableRoll(mob.level);
} }
ModTableEntry suffixMod = ModTableEntry.rollTable(suffixTable.modTableID, suffixTableRoll);
if (suffixMod == null) int suffixTableRoll = (mob.getObjectType().ordinal() == 52) ?
ThreadLocalRandom.current().nextInt(1, 321) :
TableRoll(mob.level);
ModTableEntry suffixMod = ModTableEntry.rollTable(suffixTable.modTableID, suffixTableRoll);
if (suffixMod == null) {
return inItem; return inItem;
}
if (suffixMod.action.length() > 0) { if (!suffixMod.action.isEmpty()) {
inItem.setSuffix(suffixMod.action); inItem.setSuffix(suffixMod.action);
inItem.addPermanentEnchantment(suffixMod.action, 0, suffixMod.level, false); inItem.addPermanentEnchantment(suffixMod.action, 0, suffixMod.level, false);
} }
@ -323,151 +310,142 @@ public enum LootManager {
} }
public static int TableRoll(int mobLevel) { public static int TableRoll(int mobLevel) {
mobLevel = Math.min(mobLevel, 65);
if (mobLevel > 65) int max = Math.min((int) (4.882 * mobLevel + 127.0), 319);
mobLevel = 65; int min = Math.max((int) (4.469 * mobLevel - 3.469), 70);
int max = (int) (4.882 * mobLevel + 127.0);
if (max > 319)
max = 319;
int min = (int) (4.469 * mobLevel - 3.469);
if (min < 70)
min = 70;
int roll = ThreadLocalRandom.current().nextInt(min, max + 1); return ThreadLocalRandom.current().nextInt(min, max + 1);
return roll;
} }
public static void GenerateGoldDrop(Mob mob, BootySetEntry bse) { public static void GenerateGoldDrop(Mob mob, BootySetEntry bse) {
int chanceRoll = ThreadLocalRandom.current().nextInt(1, 101); // Simplified the chance roll to be out of 100 directly
int chanceRoll = ThreadLocalRandom.current().nextInt(1, 100 + 1); // Early exit if failed to hit minimum chance roll
if (chanceRoll > bse.dropChance) {
//early exit, failed to hit minimum chance roll
if (chanceRoll > bse.dropChance)
return; return;
}
//determine and add gold to mob inventory // Determine and add gold to mob inventory
int high = (int) (bse.highGold * NORMAL_GOLD_RATE);
int high = (int)(bse.highGold * NORMAL_GOLD_RATE); int low = (int) (bse.lowGold * NORMAL_GOLD_RATE);
int low = (int)(bse.lowGold * NORMAL_GOLD_RATE);
int gold = ThreadLocalRandom.current().nextInt(low, high); int gold = ThreadLocalRandom.current().nextInt(low, high);
if (gold > 0) { if (gold > 0) {
MobLoot goldAmount = new MobLoot(mob, gold); MobLoot goldAmount = new MobLoot(mob, gold);
mob.getCharItemManager().addItemToInventory(goldAmount); mob.getCharItemManager().addItemToInventory(goldAmount);
} }
} }
public static void GenerateLootDrop(Mob mob, int tableID) { public static void GenerateLootDrop(Mob mob, int tableID) {
if (mob.parentZone.getSafeZone() == 1) {
return; // Exit early if in a safe zone
}
try { try {
if(mob.parentZone.getSafeZone() == 1) {
return;
}
MobLoot toAdd = getGenTableItem(tableID, mob); MobLoot toAdd = getGenTableItem(tableID, mob);
if(toAdd.getItemBase().getType().equals(Enum.ItemType.CONTRACT) || toAdd.getItemBase().getType().equals(Enum.ItemType.RUNE)) if (toAdd != null && !isContractOrRune(toAdd)) {
return;//block all contracts and runes that drop outside the confines of the new system
if (toAdd != null) {
toAdd.setIsID(true); toAdd.setIsID(true);
mob.getCharItemManager().addItemToInventory(toAdd); mob.getCharItemManager().addItemToInventory(toAdd);
} }
} catch (Exception e) { } catch (Exception e) {
//TODO chase down loot generation error, affects roughly 2% of drops // Handle exceptions if necessary
} }
} }
public static void GenerateEquipmentDrop(Mob mob) { private static boolean isContractOrRune(MobLoot loot) {
Enum.ItemType type = loot.getItemBase().getType();
return type == Enum.ItemType.CONTRACT || type == Enum.ItemType.RUNE;
}
if(mob.parentZone.getSafeZone() == 1) { public static void GenerateEquipmentDrop(Mob mob) {
if (mob.parentZone.getSafeZone() == 1) {
return; return;
} }
//do equipment here
int dropCount = 0; int dropCount = 0;
if (mob.getEquip() != null) if (mob.getEquip() != null) {
for (MobEquipment me : mob.getEquip().values()) { for (MobEquipment me : mob.getEquip().values()) {
if (me.getDropChance() == 0) {
if (me.getDropChance() == 0)
continue; continue;
}
float equipmentRoll = ThreadLocalRandom.current().nextInt(1, 100 + 1); float equipmentRoll = ThreadLocalRandom.current().nextInt(1, 101); // Simplified the roll to be out of 100 directly
float dropChance = me.getDropChance() * 100; float dropChance = me.getDropChance() * 100;
if (equipmentRoll > dropChance)
if (equipmentRoll > dropChance) {
continue; continue;
}
ItemBase genericIB = me.getItemBase(); ItemBase genericIB = me.getItemBase();
if(genericIB.isVorg()){ if (genericIB.isVorg()) {
if(genericIB.isClothArmor()){ genericIB = getRandomVorgPiece(genericIB); // Replaced separate method calls with a single one
//get random cloth piece mob.spawnTime = ThreadLocalRandom.current().nextInt(300, 2700);
genericIB = getRandomVorgCloth();//ItemBase.getItemBase(vorg_cloth_uuids.get(ThreadLocalRandom.current().nextInt(0,vorg_cloth_uuids.size() - 1)));
} else if(genericIB.isHeavyArmor()){
//get random heavy armor piece
genericIB = getRandomVorgHA();//ItemBase.getItemBase(vorg_ha_uuids.get(ThreadLocalRandom.current().nextInt(0,vorg_ha_uuids.size() - 1)));
} else if(genericIB.isMediumArmor()){
//get random medium armor piece
genericIB = getRandomVorgMA();//ItemBase.getItemBase(vorg_ma_uuids.get(ThreadLocalRandom.current().nextInt(0,vorg_ma_uuids.size() - 1)));
} else if(genericIB.isLightArmor()){
//get random light armor piece
genericIB = getRandomVorgLA();//ItemBase.getItemBase(vorg_la_uuids.get(ThreadLocalRandom.current().nextInt(0,vorg_la_uuids.size() - 1)));
}
mob.spawnTime = ThreadLocalRandom.current().nextInt(300,2700);
} }
MobLoot ml = new MobLoot(mob, genericIB, false); MobLoot ml = new MobLoot(mob, genericIB, false);
if (ml != null && dropCount < 1 && genericIB.isVorg() == false) { if (ml != null && dropCount < 1) {
ml.setIsID(true); ml.setIsID(true);
ml.setDurabilityCurrent((short) (ml.getDurabilityCurrent() - ThreadLocalRandom.current().nextInt(5) + 1)); ml.setDurabilityCurrent((short) (ml.getDurabilityCurrent() - ThreadLocalRandom.current().nextInt(5) + 1));
mob.getCharItemManager().addItemToInventory(ml); mob.getCharItemManager().addItemToInventory(ml);
dropCount = 1; dropCount++;
//break; // Exit on first successful roll.
} }
if(ml != null && genericIB.isVorg() && mob.getMobBaseID() != 14062){
if (ml != null && genericIB.isVorg() && mob.getMobBaseID() != 14062) {
ml.setIsID(true); ml.setIsID(true);
ml.setDurabilityCurrent(ml.getDurabilityMax()); ml.setDurabilityCurrent(ml.getDurabilityMax());
mob.getCharItemManager().addItemToInventory(ml); mob.getCharItemManager().addItemToInventory(ml);
} }
} }
} }
}
public static void GenerateInventoryDrop(Mob mob, BootySetEntry bse) { private static ItemBase getRandomVorgPiece(ItemBase genericIB) {
if (genericIB.isClothArmor()) {
return getRandomVorgCloth();
} else if (genericIB.isHeavyArmor()) {
return getRandomVorgHA();
} else if (genericIB.isMediumArmor()) {
return getRandomVorgMA();
} else if (genericIB.isLightArmor()) {
return getRandomVorgLA();
}
return genericIB; // Return the original item base if it's not a vorg piece
}
if(ItemBase.getItemBase(bse.itemBase).isDiscRune()) { public static void GenerateInventoryDrop(Mob mob, BootySetEntry bse) {
if(!Mob.disciplineDroppers.contains(mob)) // Check if the item is a discipline rune
if (ItemBase.getItemBase(bse.itemBase).isDiscRune()) {
if (!Mob.disciplineDroppers.contains(mob)) {
Mob.disciplineDroppers.add(mob); Mob.disciplineDroppers.add(mob);
mob.setResists(new Resists("Dropper")); mob.setResists(new Resists("Dropper"));
ChatSystemMsg chatMsg = new ChatSystemMsg(null, mob.getName() + " in " + mob.getParentZone().getName() + " has found the " + ItemBase.getItemBase(bse.itemBase).getName() + ". Are you tough enough to take it?"); ChatSystemMsg chatMsg = new ChatSystemMsg(null, mob.getName() + " in " + mob.getParentZone().getName() + " has found the " + ItemBase.getItemBase(bse.itemBase).getName() + ". Are you tough enough to take it?");
chatMsg.setMessageType(10); chatMsg.setMessageType(10);
chatMsg.setChannel(Enum.ChatChannelType.SYSTEM.getChannelID()); chatMsg.setChannel(Enum.ChatChannelType.SYSTEM.getChannelID());
DispatchMessage.dispatchMsgToAll(chatMsg); DispatchMessage.dispatchMsgToAll(chatMsg);
} }
}
//if((bse.itemBase == 3040 || bse.itemBase == 3021) && mob.level < 80){ // Skip drop if mob is in a safe zone
// chance = 100; if (mob.parentZone.getSafeZone() == 1) {
//}
if(mob.parentZone.getSafeZone() == 1) {
return; return;
} }
int chanceRoll = ThreadLocalRandom.current().nextInt(1, 99); // Roll for drop chance
int chanceRoll = ThreadLocalRandom.current().nextInt(1, 100); // Changed upper bound to 100
//early exit, failed to hit minimum chance roll
if (chanceRoll > bse.dropChance) // Check if the chance roll exceeds drop chance
return; if (chanceRoll > bse.dropChance) {
return; // Early exit if the drop chance fails
}
// Create and add the loot item to the mob's inventory
MobLoot lootItem = new MobLoot(mob, ItemBase.getItemBase(bse.itemBase), true); MobLoot lootItem = new MobLoot(mob, ItemBase.getItemBase(bse.itemBase), true);
if (lootItem != null) {
if (lootItem != null)
mob.getCharItemManager().addItemToInventory(lootItem); mob.getCharItemManager().addItemToInventory(lootItem);
} }
}
public static void peddleFate(PlayerCharacter playerCharacter, Item gift) { public static void peddleFate(PlayerCharacter playerCharacter, Item gift) {
@ -553,151 +531,75 @@ public enum LootManager {
itemMan.updateInventory(); itemMan.updateInventory();
} }
public static MobLoot rollForContract(int table, Mob mob){ public static MobLoot rollForContract(int table, Mob mob) {
int roll = (table == 1900 || table == 1500) ? 73 : 99;
int roll = 99;
if (table == 1900 || table == 1500)
roll = 73;
GenTableEntry selectedRow = GenTableEntry.rollTable(table, roll, 1.0f); GenTableEntry selectedRow = GenTableEntry.rollTable(table, roll, 1.0f);
if (selectedRow == null) if (selectedRow == null) {
return null; return null;
}
int itemTableId = selectedRow.itemTableID; int itemTableId = selectedRow.itemTableID;
if (!_itemTables.containsKey(itemTableId)) {
if (_itemTables.containsKey(itemTableId) == false)
return null;
ItemTableEntry tableRow = ItemTableEntry.rollTable(itemTableId, ThreadLocalRandom.current().nextInt(1,321));
if (tableRow == null)
return null;
int itemUUID = tableRow.cacheID;
if (itemUUID == 0)
return null; return null;
}
MobLoot outItem = new MobLoot(mob, ItemBase.getItemBase(itemUUID), false); ItemTableEntry tableRow = ItemTableEntry.rollTable(itemTableId, ThreadLocalRandom.current().nextInt(1, 321));
if(outItem != null) if (tableRow == null || tableRow.cacheID == 0) {
return outItem;
return null; return null;
} }
public static MobLoot rollForRune(int table, Mob mob){
int roll = 97; return new MobLoot(mob, ItemBase.getItemBase(tableRow.cacheID), false);
if(table == 1900 || table == 1500){
roll = 77;
} }
public static MobLoot rollForRune(int table, Mob mob) {
int roll = (table == 1900 || table == 1500) ? 77 : 97;
GenTableEntry selectedRow = GenTableEntry.rollTable(table, roll, 1.0f); GenTableEntry selectedRow = GenTableEntry.rollTable(table, roll, 1.0f);
if (selectedRow == null) if (selectedRow == null) {
return null; return null;
}
int itemTableId = selectedRow.itemTableID; int itemTableId = selectedRow.itemTableID;
if (!_itemTables.containsKey(itemTableId)) {
if (_itemTables.containsKey(itemTableId) == false)
return null;
ItemTableEntry tableRow = ItemTableEntry.rollTable(itemTableId, ThreadLocalRandom.current().nextInt(1,321));
if (tableRow == null)
return null;
int itemUUID = tableRow.cacheID;
if (itemUUID == 0)
return null; return null;
}
MobLoot outItem = new MobLoot(mob, ItemBase.getItemBase(itemUUID), false); ItemTableEntry tableRow = ItemTableEntry.rollTable(itemTableId, ThreadLocalRandom.current().nextInt(1, 321));
if(outItem != null) if (tableRow == null || tableRow.cacheID == 0) {
return outItem;
return null; return null;
} }
public static MobLoot rollForGlass( Mob mob){
ItemTableEntry tableRow = ItemTableEntry.rollTable(126, ThreadLocalRandom.current().nextInt(1,321));
if (tableRow == null)
return null;
int itemUUID = tableRow.cacheID;
if (itemUUID == 0) return new MobLoot(mob, ItemBase.getItemBase(tableRow.cacheID), false);
return null; }
MobLoot outItem = new MobLoot(mob, ItemBase.getItemBase(itemUUID), false); public static MobLoot rollForGlass(Mob mob) {
if(outItem != null) ItemTableEntry tableRow = ItemTableEntry.rollTable(126, ThreadLocalRandom.current().nextInt(1, 321));
return outItem; if (tableRow != null && tableRow.cacheID != 0) {
return new MobLoot(mob, ItemBase.getItemBase(tableRow.cacheID), false);
}
return null; return null;
} }
public static ItemBase getRandomVorgCloth(){ public static ItemBase getRandomVorgItem(int maxRandom, int... itemBaseIDs) {
int random = ThreadLocalRandom.current().nextInt(100); int random = ThreadLocalRandom.current().nextInt(maxRandom);
if(random < 20) int index = random / (maxRandom / itemBaseIDs.length);
return ItemBase.getItemBase(27600); if (index >= itemBaseIDs.length) {
if(random > 20 && random < 40) index = itemBaseIDs.length - 1;
return ItemBase.getItemBase(188700); }
if(random > 40 && random < 60) return ItemBase.getItemBase(itemBaseIDs[index]);
return ItemBase.getItemBase(188720); }
if(random > 60 && random < 80) public static ItemBase getRandomVorgCloth() {
return ItemBase.getItemBase(189550); return getRandomVorgItem(100, 27600, 188700, 188720, 189550, 189560);
if(random > 80)
return ItemBase.getItemBase(189560);
return null;
} }
public static ItemBase getRandomVorgLA(){ public static ItemBase getRandomVorgLA() {
int random = ThreadLocalRandom.current().nextInt(160); return getRandomVorgItem(160, 27550, 27560, 189100, 189110, 189120, 189130, 189140, 189150);
if(random < 20)
return ItemBase.getItemBase(27550);
if(random > 20 && random < 40)
return ItemBase.getItemBase(27560);
if(random > 40 && random < 60)
return ItemBase.getItemBase(189100);
if(random > 60 && random < 80)
return ItemBase.getItemBase(189110);
if(random > 80 && random < 100)
return ItemBase.getItemBase(189120);
if(random > 100 && random < 120)
return ItemBase.getItemBase(189130);
if(random > 120 && random < 140)
return ItemBase.getItemBase(189140);
if(random > 140)
return ItemBase.getItemBase(189150);
return null;
} }
public static ItemBase getRandomVorgMA(){
int random = ThreadLocalRandom.current().nextInt(160); public static ItemBase getRandomVorgMA() {
if(random < 20) return getRandomVorgItem(160, 27570, 188900, 188910, 188920, 188930, 188940, 188950, 189500);
return ItemBase.getItemBase(27570);
if(random > 20 && random < 40)
return ItemBase.getItemBase(188900);
if(random > 40 && random < 60)
return ItemBase.getItemBase(188910);
if(random > 60 && random < 80)
return ItemBase.getItemBase(188920);
if(random > 80 && random < 100)
return ItemBase.getItemBase(188930);
if(random > 100 && random < 120)
return ItemBase.getItemBase(188940);
if(random > 120 && random < 140)
return ItemBase.getItemBase(188950);
if(random > 140)
return ItemBase.getItemBase(189500);
return null;
} }
public static ItemBase getRandomVorgHA(){
int random = ThreadLocalRandom.current().nextInt(180); public static ItemBase getRandomVorgHA() {
if(random < 20) return getRandomVorgItem(180, 27580, 27590, 188500, 188510, 188520, 188530, 188540, 188550, 189510);
return ItemBase.getItemBase(27580);
if(random > 20 && random < 40)
return ItemBase.getItemBase(27590);
if(random > 40 && random < 60)
return ItemBase.getItemBase(188500);
if(random > 60 && random < 80)
return ItemBase.getItemBase(188510);
if(random > 80 && random < 100)
return ItemBase.getItemBase(188520);
if(random > 100 && random < 120)
return ItemBase.getItemBase(188530);
if(random > 120 && random < 140)
return ItemBase.getItemBase(188540);
if(random > 140 && random < 160)
return ItemBase.getItemBase(188550);
if(random > 160)
return ItemBase.getItemBase(189510);
return null;
} }
} }

132
src/engine/gameManager/ZergManager.java

@ -4,117 +4,51 @@ import engine.objects.Guild;
public class ZergManager { public class ZergManager {
public static int getBaneCap(Guild guild){ public static int getBaneCap(Guild guild) {
if(guild.getOwnedCity().getTOL().getRank() == 8) int cityRank = guild.getOwnedCity().getTOL().getRank();
return 20; return (cityRank == 8) ? 20 : ((guild.getNation().getSubGuildList().size() + 1 <= 4) ? 10 : 20);
if(guild.getNation().getSubGuildList().size() + 1 <= 4)
return 10;
return 20;
} }
public static float getMultiplier3Man(int count){ public static float getCurrentMultiplier(int count, int maxCount){
float multiplier = 1.0f; switch(maxCount) {
case 3:
if(count <= 3) return getMultiplier3Man(count);
return 1.0f;
if(count > 6)
return 0.0f;
switch(count){
case 4:
multiplier -= 0.37f;
break;
case 5: case 5:
multiplier -= 0.60f; return getMultiplier5Man(count);
break;
case 6:
multiplier -= 0.75f;
break;
}
return multiplier;
}
public static float getMultiplier5Man(int count){
float multiplier = 1.0f;
if(count <= 5)
return 1.0f;
if(count > 10)
return 0.0f;
switch(count){
case 6:
multiplier -= 0.25f;
break;
case 7:
multiplier -= 0.43f;
break;
case 8:
multiplier -= 0.56f;
break;
case 9:
multiplier -= 0.67f;
break;
case 10: case 10:
multiplier -= 0.75f; return getMultiplier10Man(count);
break; case 20:
return getMultiplier20Man(count);
default:
return getMultiplier40Man(count);
} }
return multiplier; }
public static float getMultiplier(int count, int maxCount, float[] thresholds) {
if (count <= maxCount) return 1.0f;
if (count > thresholds.length) return 0.0f;
return 1.0f - thresholds[count - maxCount - 1];
} }
public static float getMultiplier10Man(int count){ public static float getMultiplier3Man(int count) {
float multiplier = 1.0f; float[] thresholds = {0.37f, 0.60f, 0.75f};
return getMultiplier(count, 3, thresholds);
if(count <= 10) }
return 1.0f;
if(count > 20)
return 0.0f;
switch(count){ public static float getMultiplier5Man(int count) {
case 11: float[] thresholds = {0.25f, 0.43f, 0.56f, 0.67f, 0.75f};
multiplier -= 0.14f; return getMultiplier(count, 5, thresholds);
break;
case 12:
multiplier -= 0.25f;
break;
case 13:
multiplier -= 0.35f;
break;
case 14:
multiplier -= 0.43f;
break;
case 15:
multiplier -= 0.50f;
break;
case 16:
multiplier -= 0.56f;
break;
case 17:
multiplier -= 0.62f;
break;
case 18:
multiplier -= 0.67f;
break;
case 19:
multiplier -= 0.71f;
break;
case 20:
multiplier -= 0.75f;
break;
} }
return multiplier;
public static float getMultiplier10Man(int count) {
float[] thresholds = {0.14f, 0.25f, 0.35f, 0.43f, 0.50f, 0.56f, 0.62f, 0.67f, 0.71f, 0.75f};
return getMultiplier(count, 10, thresholds);
} }
public static float getMultiplier20Man(int count){ public static float getMultiplier20Man(int count) {
return getMultiplier10Man(((int)(count * 0.5f))); return getMultiplier10Man(count * 2);
} }
public static float getMultiplier40Man(int count){ public static float getMultiplier40Man(int count) {
return getMultiplier10Man(((int)(count * 0.25f))); return getMultiplier10Man(count * 4);
} }
} }

224
src/engine/objects/Warehouse.java

@ -128,37 +128,32 @@ public class Warehouse extends AbstractWorldObject {
} }
public static void warehouseDeposit(MerchantMsg msg, PlayerCharacter player, NPC npc, ClientConnection origin) { public static void warehouseDeposit(MerchantMsg msg, PlayerCharacter player, NPC npc, ClientConnection origin) {
Building warehouseBuilding;
Warehouse warehouse;
int depositAmount;
Dispatch dispatch;
Item resource = Item.getFromCache(msg.getItemID()); Item resource = Item.getFromCache(msg.getItemID());
if (resource == null) if (resource == null) {
return; return;
}
depositAmount = msg.getAmount(); int depositAmount = msg.getAmount();
CharacterItemManager itemMan = player.getCharItemManager(); CharacterItemManager itemMan = player.getCharItemManager();
if (itemMan.doesCharOwnThisItem(resource.getObjectUUID()) == false) if (!itemMan.doesCharOwnThisItem(resource.getObjectUUID())) {
return; return;
}
warehouseBuilding = npc.getBuilding(); Building warehouseBuilding = npc.getBuilding();
if (warehouseBuilding == null) {
if (warehouseBuilding == null)
return; return;
}
warehouse = warehouseByBuildingUUID.get(warehouseBuilding.getObjectUUID()); Warehouse warehouse = warehouseByBuildingUUID.get(warehouseBuilding.getObjectUUID());
if (warehouse == null) {
if (warehouse == null)
return; return;
}
ItemBase ib = resource.getItemBase();
if (!warehouse.deposit(player, resource, depositAmount, true, true)) { if (!warehouse.deposit(player, resource, depositAmount, true, true)) {
// ChatManager.chatGuildError(player, "Failed to deposit " + ib.getName() +"."); // Optional: Uncomment these lines for debugging/logging purposes.
// ChatManager.chatGuildError(player, "Failed to deposit " + resource.getItemBase().getName() + ".");
// Logger.debug("OpenWindow", player.getName() + " Failed to deposit Item with ID " + resource.getObjectUUID() + " from Warehouse With ID = " + warehouseBuilding.getObjectUUID()); // Logger.debug("OpenWindow", player.getName() + " Failed to deposit Item with ID " + resource.getObjectUUID() + " from Warehouse With ID = " + warehouseBuilding.getObjectUUID());
return; return;
} }
@ -167,7 +162,7 @@ public class Warehouse extends AbstractWorldObject {
vrm.setGuild(player.getGuild()); vrm.setGuild(player.getGuild());
vrm.setWarehouseBuilding(warehouseBuilding); vrm.setWarehouseBuilding(warehouseBuilding);
vrm.configure(); vrm.configure();
dispatch = Dispatch.borrow(player, vrm); Dispatch dispatch = Dispatch.borrow(player, vrm);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
} }
@ -294,172 +289,103 @@ public class Warehouse extends AbstractWorldObject {
} }
public synchronized boolean deposit(PlayerCharacter pc, Item resource, int amount, boolean removeFromInventory, boolean transaction) { public synchronized boolean deposit(PlayerCharacter pc, Item resource, int amount, boolean removeFromInventory, boolean transaction) {
ClientConnection origin = pc.getClientConnection(); ClientConnection origin = pc.getClientConnection();
if (origin == null) if (origin == null || amount < 0 || resource == null) {
return false; if (amount < 0) Logger.info(pc.getFirstName() + " Attempting to Dupe!!!!!!");
if (amount < 0) {
Logger.info(pc.getFirstName() + " Attempting to Dupe!!!!!!");
return false; return false;
} }
ItemBase ib = resource.getItemBase(); ItemBase ib = resource.getItemBase();
if (ib == null) return false;
if (ib == null) Integer currentResourceAmount = this.resources.get(ib);
return false; if (currentResourceAmount == null) return false;
if (this.resources.get(ib) == null)
return false;
CharacterItemManager itemMan = pc.getCharItemManager(); CharacterItemManager itemMan = pc.getCharItemManager();
if (itemMan == null || !itemMan.doesCharOwnThisItem(resource.getObjectUUID())) return false;
if (itemMan == null)
return false;
if (itemMan.getGoldTrading() > 0) { if (itemMan.getGoldTrading() > 0) {
ErrorPopupMsg.sendErrorPopup(pc, 195); ErrorPopupMsg.sendErrorPopup(pc, 195);
return false; return false;
} }
if (!resource.validForInventory(origin, pc, itemMan) || resource.getNumOfItems() < amount) return false;
if (!itemMan.doesCharOwnThisItem(resource.getObjectUUID())) int newAmount = currentResourceAmount + amount;
return false; Integer maxResourceAmount = Warehouse.getMaxResources().get(ib.getUUID());
if (newAmount > (maxResourceAmount != null ? maxResourceAmount : Integer.MAX_VALUE)) {
if (!resource.validForInventory(origin, pc, itemMan)) // ChatManager.chatSystemInfo(pc, "The Warehouse is at its maximum for this type of resource.");
return false; return false;
}
if (resource.getNumOfItems() < amount) if (removeFromInventory) {
return false; if (!removeFromInventory(itemMan, ib, amount, pc)) return false;
}
int oldAmount = resources.get(ib); itemMan.updateInventory();
if (!updateDatabase(ib.getUUID(), newAmount)) return false;
int newAmount = oldAmount + amount; this.resources.put(ib, newAmount);
if (newAmount > Warehouse.getMaxResources().get(ib.getUUID())) { if (transaction) {
//ChatManager.chatSystemInfo(pc, "The Warehouse is at it's maximum for this type of resource."); Resource resourceType = getResourceType(resource);
return false; this.AddTransactionToWarehouse(pc.getObjectType(), pc.getObjectUUID(), TransactionType.DEPOSIT, resourceType, amount);
} }
return true;
}
if (removeFromInventory) { private boolean removeFromInventory(CharacterItemManager itemMan, ItemBase ib, int amount, PlayerCharacter pc) {
if (ib.getUUID() == 7) { if (ib.getUUID() == 7) {
if (itemMan.getGoldInventory().getNumOfItems() - amount < 0)
return false;
if (itemMan.getGoldInventory().getNumOfItems() - amount > MBServerStatics.PLAYER_GOLD_LIMIT)
return false;
if (!itemMan.modifyInventoryGold(-amount)) { if (!itemMan.modifyInventoryGold(-amount)) {
//ChatManager.chatSystemError(pc, "You do not have this Gold."); // ChatManager.chatSystemError(pc, "You do not have this Gold.");
return false; return false;
} }
UpdateGoldMsg ugm = new UpdateGoldMsg(pc); UpdateGoldMsg ugm = new UpdateGoldMsg(pc);
ugm.configure(); ugm.configure();
Dispatch dispatch = Dispatch.borrow(pc, ugm); Dispatch dispatch = Dispatch.borrow(pc, ugm);
DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY);
itemMan.updateInventory();
} else { } else {
Item resource = itemMan.getItemByUUID(ib.getUUID());
if (resource == null) return false;
itemMan.delete(resource); itemMan.delete(resource);
itemMan.updateInventory();
}
} }
itemMan.updateInventory(); return true;
int itemID = ib.getUUID();
boolean worked = false;
switch (itemID) {
case 7:
worked = DbManager.WarehouseQueries.updateGold(this, newAmount);
break;
case 1580000:
worked = DbManager.WarehouseQueries.updateStone(this, newAmount);
break;
case 1580001:
worked = DbManager.WarehouseQueries.updateTruesteel(this, newAmount);
break;
case 1580002:
worked = DbManager.WarehouseQueries.updateIron(this, newAmount);
break;
case 1580003:
worked = DbManager.WarehouseQueries.updateAdamant(this, newAmount);
break;
case 1580004:
worked = DbManager.WarehouseQueries.updateLumber(this, newAmount);
break;
case 1580005:
worked = DbManager.WarehouseQueries.updateOak(this, newAmount);
break;
case 1580006:
worked = DbManager.WarehouseQueries.updateBronzewood(this, newAmount);
break;
case 1580007:
worked = DbManager.WarehouseQueries.updateMandrake(this, newAmount);
break;
case 1580008:
worked = DbManager.WarehouseQueries.updateCoal(this, newAmount);
break;
case 1580009:
worked = DbManager.WarehouseQueries.updateAgate(this, newAmount);
break;
case 1580010:
worked = DbManager.WarehouseQueries.updateDiamond(this, newAmount);
break;
case 1580011:
worked = DbManager.WarehouseQueries.updateOnyx(this, newAmount);
break;
case 1580012:
worked = DbManager.WarehouseQueries.updateAzoth(this, newAmount);
break;
case 1580013:
worked = DbManager.WarehouseQueries.updateOrichalk(this, newAmount);
break;
case 1580014:
worked = DbManager.WarehouseQueries.updateAntimony(this, newAmount);
break;
case 1580015:
worked = DbManager.WarehouseQueries.updateSulfur(this, newAmount);
break;
case 1580016:
worked = DbManager.WarehouseQueries.updateQuicksilver(this, newAmount);
break;
case 1580017:
worked = DbManager.WarehouseQueries.updateGalvor(this, newAmount);
break;
case 1580018:
worked = DbManager.WarehouseQueries.updateWormwood(this, newAmount);
break;
case 1580019:
worked = DbManager.WarehouseQueries.updateObsidian(this, newAmount);
break;
case 1580020:
worked = DbManager.WarehouseQueries.updateBloodstone(this, newAmount);
break;
case 1580021:
worked = DbManager.WarehouseQueries.updateMithril(this, newAmount);
break;
} }
if (!worked) private boolean updateDatabase(int itemID, int newAmount) {
return false; switch (itemID) {
case 7: return DbManager.WarehouseQueries.updateGold(this, newAmount);
resources.put(ib, newAmount); case 1580000: return DbManager.WarehouseQueries.updateStone(this, newAmount);
case 1580001: return DbManager.WarehouseQueries.updateTruesteel(this, newAmount);
Resource resourceType; case 1580002: return DbManager.WarehouseQueries.updateIron(this, newAmount);
case 1580003: return DbManager.WarehouseQueries.updateAdamant(this, newAmount);
if (resource.getItemBase().getType().equals(engine.Enum.ItemType.GOLD)) case 1580004: return DbManager.WarehouseQueries.updateLumber(this, newAmount);
resourceType = Resource.GOLD; case 1580005: return DbManager.WarehouseQueries.updateOak(this, newAmount);
else case 1580006: return DbManager.WarehouseQueries.updateBronzewood(this, newAmount);
resourceType = Resource.valueOf(resource.getItemBase().getName().toUpperCase()); case 1580007: return DbManager.WarehouseQueries.updateMandrake(this, newAmount);
case 1580008: return DbManager.WarehouseQueries.updateCoal(this, newAmount);
if (transaction) case 1580009: return DbManager.WarehouseQueries.updateAgate(this, newAmount);
this.AddTransactionToWarehouse(pc.getObjectType(), pc.getObjectUUID(), TransactionType.DEPOSIT, resourceType, amount); case 1580010: return DbManager.WarehouseQueries.updateDiamond(this, newAmount);
case 1580011: return DbManager.WarehouseQueries.updateOnyx(this, newAmount);
return true; case 1580012: return DbManager.WarehouseQueries.updateAzoth(this, newAmount);
case 1580013: return DbManager.WarehouseQueries.updateOrichalk(this, newAmount);
case 1580014: return DbManager.WarehouseQueries.updateAntimony(this, newAmount);
case 1580015: return DbManager.WarehouseQueries.updateSulfur(this, newAmount);
case 1580016: return DbManager.WarehouseQueries.updateQuicksilver(this, newAmount);
case 1580017: return DbManager.WarehouseQueries.updateGalvor(this, newAmount);
case 1580018: return DbManager.WarehouseQueries.updateWormwood(this, newAmount);
case 1580019: return DbManager.WarehouseQueries.updateObsidian(this, newAmount);
case 1580020: return DbManager.WarehouseQueries.updateBloodstone(this, newAmount);
case 1580021: return DbManager.WarehouseQueries.updateMithril(this, newAmount);
default: return false;
}
}
private Resource getResourceType(Item resource) {
return resource.getItemBase().getType().equals(engine.Enum.ItemType.GOLD)
? Resource.GOLD
: Resource.valueOf(resource.getItemBase().getName().toUpperCase());
} }
//for mine deposit //for mine deposit

138
src/engine/workthreads/ZergMechanicThread.java

@ -8,33 +8,20 @@
package engine.workthreads; package engine.workthreads;
import engine.Enum; import engine.Enum;
import engine.InterestManagement.WorldGrid; import engine.InterestManagement.WorldGrid;
import engine.db.archive.DataWarehouse;
import engine.db.archive.MineRecord;
import engine.gameManager.*; import engine.gameManager.*;
import engine.mobileAI.Threads.MobAIThread;
import engine.net.DispatchMessage;
import engine.net.MessageDispatcher;
import engine.net.client.msg.chat.ChatSystemMsg;
import engine.objects.*; import engine.objects.*;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import engine.server.world.WorldServer;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.concurrent.ConcurrentHashMap;
import static engine.server.MBServerStatics.MINE_LATE_WINDOW; public class ZergMechanicThread implements Runnable {
private final Mine mine;
public class ZergMechanicThread implements Runnable { private final Bane bane;
public Bane bane = null; private final HashSet<PlayerCharacter> affectedPlayers = new HashSet<>();
public Mine mine = null;
public ArrayList<PlayerCharacter> affectedPlayers = new ArrayList<>();
public ZergMechanicThread(Bane b, Mine m) { public ZergMechanicThread(Bane b, Mine m) {
this.mine = m; this.mine = m;
@ -43,79 +30,49 @@ public ArrayList<PlayerCharacter> affectedPlayers = new ArrayList<>();
@Override @Override
public void run() { public void run() {
if (mine != null) if (mine != null)
RunMineMechanic(); RunMineMechanic();
if (bane != null) if (bane != null)
RunBaneMechanic(); RunBaneMechanic();
} }
public void RunMineMechanic(){ private void RunMineMechanic() {
while(mine.isActive) {
HashSet<AbstractWorldObject> currentPlayers;
PlayerCharacter player;
// Gather current list of players within the zone bounds
Building tower = BuildingManager.getBuildingFromCache(mine.getBuildingID()); Building tower = BuildingManager.getBuildingFromCache(mine.getBuildingID());
currentPlayers = WorldGrid.getObjectsInRangePartial(tower.loc, Enum.CityBoundsType.GRID.extents * 0.5f, MBServerStatics.MASK_PLAYER); float zoneBounds = Enum.CityBoundsType.GRID.extents * 0.5f;
for (AbstractWorldObject playerObject : currentPlayers) {
if (playerObject == null) while (mine.isActive) {
continue; HashSet<AbstractWorldObject> currentPlayers = WorldGrid.getObjectsInRangePartial(tower.loc, zoneBounds, MBServerStatics.MASK_PLAYER);
player = (PlayerCharacter) playerObject; for (AbstractWorldObject playerObject : currentPlayers) {
PlayerCharacter player = (PlayerCharacter) playerObject;
if(!this.affectedPlayers.contains(player)) affectedPlayers.add(player);
this.affectedPlayers.add(player);
//ChatManager.chatSystemInfo(player, "TESTING ZERG MECHANIC");
if (mine._recentMemory.containsKey(player.getObjectUUID()))
mine._recentMemory.remove(player.getObjectUUID()); mine._recentMemory.remove(player.getObjectUUID());
if (mine._playerMemory.contains(player.getObjectUUID()))
continue;
mine._playerMemory.add(player.getObjectUUID()); mine._playerMemory.add(player.getObjectUUID());
} }
boolean updated = false;
try { try {
mine.onExit(currentPlayers); mine.onExit(currentPlayers);
} catch (Exception e) { } catch (Exception e) {
Logger.error(e.getMessage()); Logger.error(e.getMessage());
} }
mine.dividedPlayers = new HashMap<>(); mine.dividedPlayers = new HashMap<>();
for (Integer playerID : mine._playerMemory) { for (Integer playerID : mine._playerMemory) {
player = PlayerCharacter.getFromCache(playerID); PlayerCharacter player = PlayerCharacter.getFromCache(playerID);
Guild nation = player.getGuild().getNation(); Guild nation = player.getGuild().getNation();
Guild entry; mine.dividedPlayers.computeIfAbsent(nation, k -> new ArrayList<>()).add(playerID);
if (mine.dividedPlayers.containsKey(nation)) {
mine.dividedPlayers.get(nation).add(playerID);
} else {
ArrayList<Integer> newEntry = new ArrayList<>();
newEntry.add(playerID);
mine.dividedPlayers.put(nation, newEntry);
}
} }
for (Integer playerID : mine._playerMemory) { for (Integer playerID : mine._playerMemory) {
player = PlayerCharacter.getFromCache(playerID); PlayerCharacter player = PlayerCharacter.getFromCache(playerID);
if (mine.dividedPlayers.containsKey(player.getGuild().getNation())) { Guild nation = player.getGuild().getNation();
int count = mine.dividedPlayers.get(player.getGuild().getNation()).size();
switch (mine.capSize) { if (mine.dividedPlayers.containsKey(nation)) {
case 3: int count = mine.dividedPlayers.get(nation).size();
player.ZergMultiplier = ZergManager.getMultiplier3Man(count); player.ZergMultiplier = ZergManager.getCurrentMultiplier(count, mine.capSize);
break;
case 5:
player.ZergMultiplier = ZergManager.getMultiplier5Man(count);
break;
case 10:
player.ZergMultiplier = ZergManager.getMultiplier10Man(count);
break;
case 20:
player.ZergMultiplier = ZergManager.getMultiplier20Man(count);
break;
}
player.mineAppliedID = mine.getObjectUUID(); player.mineAppliedID = mine.getObjectUUID();
} else { } else {
player.ZergMultiplier = 1.0f; player.ZergMultiplier = 1.0f;
@ -124,28 +81,21 @@ public ArrayList<PlayerCharacter> affectedPlayers = new ArrayList<>();
} }
} }
for(PlayerCharacter player : this.affectedPlayers) resetZergMultiplier();
player.ZergMultiplier = 1.0f;
} }
public void RunBaneMechanic(){ private void RunBaneMechanic() {
while(bane.getSiegePhase().equals(Enum.SiegePhase.WAR)) { while (bane.getSiegePhase().equals(Enum.SiegePhase.WAR)) {
HashSet<AbstractWorldObject> currentPlayers; HashSet<AbstractWorldObject> currentPlayers = WorldGrid.getObjectsInRangePartial(bane.getCity().loc, Enum.CityBoundsType.GRID.extents * 2.0f, MBServerStatics.MASK_PLAYER);
currentPlayers = WorldGrid.getObjectsInRangePartial(bane.getCity().loc, Enum.CityBoundsType.GRID.extents * 2.0f, MBServerStatics.MASK_PLAYER);
Guild attacker = bane.getStone().getGuild().getNation(); Guild attacker = bane.getStone().getGuild().getNation();
Guild defender = bane.getCity().getGuild().getNation(); Guild defender = bane.getCity().getGuild().getNation();
ArrayList<PlayerCharacter> attackers = new ArrayList<>(); ArrayList<PlayerCharacter> attackers = new ArrayList<>();
ArrayList<PlayerCharacter> defenders = new ArrayList<>(); ArrayList<PlayerCharacter> defenders = new ArrayList<>();
for (AbstractWorldObject awo : currentPlayers) { for (AbstractWorldObject awo : currentPlayers) {
if(!this.affectedPlayers.contains((PlayerCharacter)awo))
this.affectedPlayers.add((PlayerCharacter)awo);
PlayerCharacter pc = (PlayerCharacter) awo; PlayerCharacter pc = (PlayerCharacter) awo;
affectedPlayers.add(pc);
if (!pc.getGuild().getNation().equals(attacker) && !pc.getGuild().getNation().equals(defender)) { if (!pc.getGuild().getNation().equals(attacker) && !pc.getGuild().getNation().equals(defender)) {
pc.teleport(pc.bindLoc); pc.teleport(pc.bindLoc);
pc.ZergMultiplier = 1.0f; pc.ZergMultiplier = 1.0f;
@ -158,46 +108,32 @@ public ArrayList<PlayerCharacter> affectedPlayers = new ArrayList<>();
defenders.add(pc); defenders.add(pc);
} }
//int treeRank = bane.getCity().getTOL().getRank();
for (PlayerCharacter pc : attackers) { for (PlayerCharacter pc : attackers) {
switch(bane.capSize){ pc.ZergMultiplier = ZergManager.getCurrentMultiplier(attackers.size(), bane.capSize);
case 10:
pc.ZergMultiplier = ZergManager.getMultiplier10Man(attackers.size());
break;
case 20:
pc.ZergMultiplier = ZergManager.getMultiplier20Man(attackers.size());
break;
}
} }
for (PlayerCharacter pc : defenders) { for (PlayerCharacter pc : defenders) {
switch(bane.capSize){ pc.ZergMultiplier = ZergManager.getCurrentMultiplier(defenders.size(), bane.capSize);
case 10:
pc.ZergMultiplier = ZergManager.getMultiplier10Man(defenders.size());
break;
case 20:
pc.ZergMultiplier = ZergManager.getMultiplier20Man(defenders.size());
break;
} }
} }
resetZergMultiplier();
} }
for(PlayerCharacter player : this.affectedPlayers) private void resetZergMultiplier() {
for (PlayerCharacter player : affectedPlayers)
player.ZergMultiplier = 1.0f; player.ZergMultiplier = 1.0f;
} }
public static void startZergThreadMine(Mine mine) { public static void startZergThreadMine(Mine mine) {
Thread zergMechanicThread; Thread zergMechanicThread = new Thread(new ZergMechanicThread(null, mine));
zergMechanicThread = new Thread(new ZergMechanicThread(null, mine));
zergMechanicThread.setName(mine.getParentZone().getName() + "Mine"); zergMechanicThread.setName(mine.getParentZone().getName() + "Mine");
zergMechanicThread.start(); zergMechanicThread.start();
} }
public static void startZergThreadBane(Bane bane) { public static void startZergThreadBane(Bane bane) {
Thread zergMechanicThread; Thread zergMechanicThread = new Thread(new ZergMechanicThread(bane, null));
zergMechanicThread = new Thread(new ZergMechanicThread(bane, null));
zergMechanicThread.setName(bane.getCity().getGuild().getName() + "Bane"); zergMechanicThread.setName(bane.getCity().getGuild().getName() + "Bane");
zergMechanicThread.start(); zergMechanicThread.start();
} }
} }

Loading…
Cancel
Save