Advertisement
Guest User

line 282

a guest
Apr 18th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 18.25 KB | None | 0 0
  1. package mod.sin.wyvern.bounty;
  2.  
  3. import java.util.logging.*;
  4. import mod.piddagoras.duskombat.*;
  5. import java.text.*;
  6. import java.util.*;
  7. import com.wurmonline.shared.exceptions.*;
  8. import mod.sin.items.caches.*;
  9. import com.wurmonline.server.items.*;
  10. import com.wurmonline.mesh.*;
  11. import com.wurmonline.server.villages.*;
  12. import mod.sin.items.*;
  13. import com.wurmonline.server.creatures.*;
  14. import mod.sin.wyvern.util.*;
  15. import com.wurmonline.server.*;
  16. import mod.sin.creatures.*;
  17. import mod.sin.wyvern.*;
  18.  
  19. public class LootBounty
  20. {
  21.     public static final Logger logger;
  22.     protected static final Random random;
  23.    
  24.     public static void displayLootAssistance(final Creature mob) {
  25.         if (DamageEngine.dealtDamage.containsKey(mob.getWurmId())) {
  26.             LootBounty.logger.info("Found the damageDealt entry, parsing...");
  27.             final ArrayList<String> names = new ArrayList<String>();
  28.             final ArrayList<Double> damages = new ArrayList<Double>();
  29.             for (final long creatureId : DamageEngine.dealtDamage.get(mob.getWurmId()).keySet()) {
  30.                 if (Players.getInstance().getPlayerOrNull(creatureId) != null) {
  31.                     names.add(Players.getInstance().getPlayerOrNull(creatureId).getName());
  32.                     damages.add(DamageEngine.dealtDamage.get(mob.getWurmId()).get(creatureId));
  33.                 }
  34.                 else {
  35.                     if (Creatures.getInstance().getCreatureOrNull(creatureId) == null) {
  36.                         continue;
  37.                     }
  38.                     LootBounty.logger.info("Skipping creature " + Creatures.getInstance().getCreatureOrNull(creatureId).getName() + " in loot assistance.");
  39.                 }
  40.             }
  41.             LootBounty.logger.info("Names have been added: " + names);
  42.             String strBuilder = "Loot Assistance <Damagers> (" + mob.getName() + "): ";
  43.             final DecimalFormat formatter = new DecimalFormat("#,###,###");
  44.             while (names.size() > 0) {
  45.                 final int index = Server.rand.nextInt(names.size());
  46.                 strBuilder += names.get(index);
  47.                 strBuilder = strBuilder + " [" + formatter.format(Math.round(damages.get(index))) + "]";
  48.                 names.remove(index);
  49.                 damages.remove(index);
  50.                 if (names.size() > 0) {
  51.                     strBuilder += ", ";
  52.                 }
  53.             }
  54.             MiscChanges.sendServerTabMessage("event", strBuilder, 0, 128, 255);
  55.             LootBounty.logger.info("Broadcast loot assistance message success [Damage].");
  56.         }
  57.         else {
  58.             LootBounty.logger.warning("Powerful creature " + mob.getName() + " died, but no players were credited to its death [Damage].");
  59.         }
  60.     }
  61.    
  62.     public static int doRollingCrystalReward(final Creature mob, final Item corpse, final double cretStr, final int templateId, final int chance, final double reductionPerRoll) {
  63.         try {
  64.             double rollingCounter = cretStr;
  65.             int addedCrystals = 0;
  66.             while (rollingCounter > 0.0) {
  67.                 if (LootBounty.random.nextInt(chance + addedCrystals) == 0) {
  68.                     final Item chaosCrystal = ItemFactory.createItem(templateId, (float)(LootBounty.random.nextFloat() * Math.min(100.0, Math.cbrt(rollingCounter))), "");
  69.                     if (LootBounty.random.nextInt(40) == 0) {
  70.                         chaosCrystal.setRarity((byte)1);
  71.                     }
  72.                     else if (mob.isUnique() && LootBounty.random.nextInt(5) == 0) {
  73.                         if (LootBounty.random.nextInt(5) == 0) {
  74.                             chaosCrystal.setRarity((byte)2);
  75.                         }
  76.                         else {
  77.                             chaosCrystal.setRarity((byte)1);
  78.                         }
  79.                     }
  80.                     corpse.insertItem(chaosCrystal);
  81.                     ++addedCrystals;
  82.                 }
  83.                 rollingCounter -= reductionPerRoll;
  84.             }
  85.             return addedCrystals;
  86.         }
  87.         catch (FailedException | NoSuchTemplateException ex2) {
  88.             final WurmServerException ex;
  89.             final WurmServerException e = ex;
  90.             e.printStackTrace();
  91.             return 0;
  92.         }
  93.     }
  94.    
  95.     public static void insertUniqueLoot(final Creature mob, final Item corpse) {
  96.         try {
  97.             final Item affinityOrb = ItemFactory.createItem(AffinityOrb.templateId, 90.0f + 10.0f * LootBounty.random.nextFloat(), "");
  98.             corpse.insertItem(affinityOrb);
  99.             final int[] cacheIds = { ArtifactCache.templateId, CrystalCache.templateId, CrystalCache.templateId, DragonCache.templateId, DragonCache.templateId, MoonCache.templateId, MoonCache.templateId, RiftCache.templateId, TreasureMapCache.templateId };
  100.             for (int i = 1 + Server.rand.nextInt(3); i > 0; --i) {
  101.                 final Item cache = ItemFactory.createItem(cacheIds[Server.rand.nextInt(cacheIds.length)], 50.0f + 30.0f * LootBounty.random.nextFloat(), "");
  102.                 if (Server.rand.nextInt(5) == 0) {
  103.                     cache.setRarity((byte)1);
  104.                 }
  105.                 corpse.insertItem(cache);
  106.             }
  107.             if (mob.isDragon()) {
  108.                 final int mTemplate = mob.getTemplate().getTemplateId();
  109.                 int lootTemplate = 371;
  110.                 if (mTemplate == 89 || mTemplate == 91 || mTemplate == 90 || mTemplate == 16 || mTemplate == 92) {
  111.                     lootTemplate = 372;
  112.                 }
  113.                 LootBounty.logger.info("Generating extra hide & scale to insert on the corpse of " + mob.getName() + ".");
  114.                 final ItemTemplate itemTemplate = ItemTemplateFactory.getInstance().getTemplate(lootTemplate);
  115.                 for (int i = 0; i < 2; ++i) {
  116.                     final Item loot = ItemFactory.createItem(lootTemplate, 80.0f + 15.0f * LootBounty.random.nextFloat(), "");
  117.                     final String creatureName = mob.getTemplate().getName().toLowerCase();
  118.                     if (!loot.getName().contains(creatureName)) {
  119.                         loot.setName(creatureName.toLowerCase() + " " + itemTemplate.getName());
  120.                     }
  121.                     loot.setData2(mTemplate);
  122.                     final int weightGrams = itemTemplate.getWeightGrams() * ((lootTemplate == 371) ? 3 : 1);
  123.                     loot.setWeight((int)(weightGrams * 0.02f + weightGrams * 0.02f * LootBounty.random.nextFloat()), true);
  124.                     corpse.insertItem(loot);
  125.                 }
  126.             }
  127.         }
  128.         catch (FailedException | NoSuchTemplateException ex2) {
  129.             final WurmServerException ex;
  130.             final WurmServerException e = ex;
  131.             e.printStackTrace();
  132.         }
  133.     }
  134.    
  135.     public static void blessWorldWithMoonVeins(final Creature mob) {
  136.         for (int i = 8 + Server.rand.nextInt(5); i > 0; --i) {
  137.             final int x = LootBounty.random.nextInt(Server.surfaceMesh.getSize());
  138.             final int y = LootBounty.random.nextInt(Server.surfaceMesh.getSize());
  139.             final short height = Tiles.decodeHeight(Server.surfaceMesh.getTile(x, y));
  140.             final int type = Tiles.decodeType(Server.caveMesh.getTile(x, y));
  141.             if (height >= 100 && (type == Tiles.Tile.TILE_CAVE_WALL.id || type == Tiles.Tile.TILE_CAVE.id)) {
  142.                 final Tiles.Tile tileType = LootBounty.random.nextBoolean() ? Tiles.Tile.TILE_CAVE_WALL_ORE_ADAMANTINE : Tiles.Tile.TILE_CAVE_WALL_ORE_GLIMMERSTEEL;
  143.                 Server.caveMesh.setTile(x, y, Tiles.encode(Tiles.decodeHeight(Server.caveMesh.getTile(x, y)), tileType.id, Tiles.decodeData(Server.caveMesh.getTile(x, y))));
  144.                 Players.getInstance().sendChangedTile(x, y, false, true);
  145.                 Server.setCaveResource(x, y, 400 + LootBounty.random.nextInt(600));
  146.                 Village v = Villages.getVillage(x, y, true);
  147.                 if (v == null) {
  148.                     for (int vx = -20; vx < 20; vx += 5) {
  149.                         for (int vy = -20; vy < 20 && (v = Villages.getVillage(x + vx, y + vy, true)) == null; vy += 5) {}
  150.                         if (v != null) {
  151.                             break;
  152.                         }
  153.                     }
  154.                 }
  155.                 if (v != null) {
  156.                     HistoryManager.addHistory(mob.getTemplate().getName(), "blesses the world with a " + tileType.getName() + " near " + v.getName() + "!");
  157.                     MiscChanges.sendServerTabMessage("rumors", mob.getTemplate().getName() + " blesses the world with a " + tileType.getName() + " near " + v.getName() + "!", 255, 255, 255);
  158.                 }
  159.                 LootBounty.logger.info("Placed a " + tileType.getName() + " at " + x + ", " + y + " - " + height + " height");
  160.             }
  161.         }
  162.         Server.getInstance().broadCastAlert("The death of the " + mob.getTemplate().getName() + " has blessed the world with valuable ores!");
  163.     }
  164.    
  165.     public static void spawnFriyanTablets() {
  166.         for (int i = 5 + LootBounty.random.nextInt(5); i > 0; --i) {
  167.             final int x = LootBounty.random.nextInt(Server.surfaceMesh.getSize());
  168.             final int y = LootBounty.random.nextInt(Server.surfaceMesh.getSize());
  169.             final short height = Tiles.decodeHeight(Server.surfaceMesh.getTile(x, y));
  170.             if (height > 0 && height < 1000 && Creature.getTileSteepness(x, y, true)[1] < 30) {
  171.                 try {
  172.                     ItemFactory.createItem(FriyanTablet.templateId, 80.0f + LootBounty.random.nextInt(20), x * 4.0f, y * 4.0f, LootBounty.random.nextFloat() * 360.0f, true, (byte)0, -10L, "Friyanouce");
  173.                     LootBounty.logger.info("Created a Tablet of Friyan at " + x + ", " + y + ".");
  174.                 }
  175.                 catch (NoSuchTemplateException | FailedException ex2) {
  176.                     final WurmServerException ex;
  177.                     final WurmServerException e = ex;
  178.                     e.printStackTrace();
  179.                 }
  180.             }
  181.         }
  182.     }
  183.    
  184.     public static void handleDragonLoot(final Creature mob, final Item corpse) {
  185.         try {
  186.             final int mTemplate = mob.getTemplate().getTemplateId();
  187.             int lootTemplate = 371;
  188.             byte ctype;
  189.             if (mTemplate == 89 || mTemplate == 91 || mTemplate == 90 || mTemplate == 16 || mTemplate == 92) {
  190.                 ctype = 99;
  191.                 lootTemplate = 372;
  192.             }
  193.             else {
  194.                 ctype = (byte)Math.max(0, Server.rand.nextInt(17) - 5);
  195.             }
  196.             final float x = mob.getPosX();
  197.             final float y = mob.getPosY();
  198.             final CreatureTemplate template = CreatureTemplateFactory.getInstance().getTemplate(SpectralDrake.templateId);
  199.             final Creature spectralDrake = Creature.doNew(template.getTemplateId(), true, x, y, LootBounty.random.nextFloat() * 360.0f, mob.getLayer(), template.getName(), (byte)0, mob.getKingdomId(), ctype, false, (byte)(-106));
  200.             Server.getInstance().broadCastAction("The spirit of the " + mob.getTemplate().getName() + " is released into the world!", mob, 20);
  201.             Server.getInstance().broadCastAlert(spectralDrake.getName() + " is released from the soul of the " + mob.getTemplate().getName() + ", seeking vengeance for its physical form!");
  202.             LootBounty.logger.info("Generating extra hide & scale to insert on the corpse of " + mob.getName() + ".");
  203.             final ItemTemplate itemTemplate = ItemTemplateFactory.getInstance().getTemplate(lootTemplate);
  204.             for (int i = 0; i < 2; ++i) {
  205.                 final Item loot = ItemFactory.createItem(lootTemplate, 80.0f + 15.0f * LootBounty.random.nextFloat(), "");
  206.                 final String creatureName = mob.getTemplate().getName().toLowerCase();
  207.                 if (!loot.getName().contains(creatureName)) {
  208.                     loot.setName(creatureName.toLowerCase() + " " + itemTemplate.getName());
  209.                 }
  210.                 loot.setData2(mTemplate);
  211.                 final int weightGrams = itemTemplate.getWeightGrams() * ((lootTemplate == 371) ? 3 : 1);
  212.                 loot.setWeight((int)(weightGrams * 0.1f + weightGrams * 0.1f * LootBounty.random.nextFloat()), true);
  213.                 corpse.insertItem(loot);
  214.             }
  215.             for (int i = 0; i < 4; ++i) {
  216.                 final Item loot = ItemFactory.createItem(lootTemplate, 80.0f + 15.0f * LootBounty.random.nextFloat(), "");
  217.                 final String creatureName = mob.getTemplate().getName().toLowerCase();
  218.                 if (!loot.getName().contains(creatureName)) {
  219.                     loot.setName(creatureName.toLowerCase() + " " + itemTemplate.getName());
  220.                 }
  221.                 loot.setData2(mTemplate);
  222.                 final int weightGrams = itemTemplate.getWeightGrams() * ((lootTemplate == 371) ? 3 : 1);
  223.                 loot.setWeight((int)(weightGrams * 0.05f + weightGrams * 0.05f * LootBounty.random.nextFloat()), true);
  224.                 spectralDrake.getInventory().insertItem(loot);
  225.             }
  226.         }
  227.         catch (Exception e) {
  228.             e.printStackTrace();
  229.         }
  230.     }
  231.    
  232.     public static void handleChampionLoot(final Item corpse) {
  233.         try {
  234.             final Item tool = ItemUtil.createRandomLootTool();
  235.             if (tool != null) {
  236.                 corpse.insertItem(tool, true);
  237.             }
  238.             if (LootBounty.random.nextInt(100) < 75) {
  239.                 corpse.insertItem(ItemFactory.createItem(LootBounty.random.nextBoolean() ? 694 : 698, 30.0f + 30.0f * LootBounty.random.nextFloat(), ""));
  240.             }
  241.             if (LootBounty.random.nextInt(100) < 5) {
  242.                 final int[] maskTemplates = { 973, 974, 975, 976, 977, 978, 1099 };
  243.                 corpse.insertItem(ItemFactory.createItem(maskTemplates[LootBounty.random.nextInt(maskTemplates.length)], 90.0f + 9.0f * LootBounty.random.nextFloat(), ""));
  244.             }
  245.             if (LootBounty.random.nextInt(100) < 1) {
  246.                 final Item bone = ItemFactory.createItem(867, 90.0f + 10.0f * LootBounty.random.nextFloat(), "");
  247.                 bone.setRarity((byte)1);
  248.                 if (LootBounty.random.nextInt(100) < 1) {
  249.                     bone.setRarity((byte)2);
  250.                 }
  251.                 corpse.insertItem(bone);
  252.             }
  253.         }
  254.         catch (FailedException | NoSuchTemplateException ex2) {
  255.             final WurmServerException ex;
  256.             final WurmServerException e = ex;
  257.             e.printStackTrace();
  258.         }
  259.     }
  260.    
  261.     public static void checkLootTable(final Creature mob, final Item corpse) {
  262.         if (mob.isReborn() || mob.isBred()) {
  263.             return;
  264.         }
  265.         final double cretStr = Bounty.getCreatureStrength(mob);
  266.         final int numCrystals = 0;
  267.         boolean sendLootHelp = false;
  268.         final int templateId = mob.getTemplate().getTemplateId();
  269.         if (Servers.localServer.PVPSERVER && mob.isPlayer()) {
  270.             if (mob.isDeathProtected()) {
  271.                 LootBounty.logger.info("Death protection was active for " + mob.getName() + ". Inserting silver coin reward.");
  272.                 try {
  273.                     final Item silver = ItemFactory.createItem(52, 99.0f, (String)null);
  274.                     corpse.insertItem(silver, true);
  275.                 }
  276.                 catch (FailedException | NoSuchTemplateException ex3) {
  277.                     final WurmServerException ex;
  278.                     final WurmServerException e = ex;
  279.                     e.printStackTrace();
  280.                 }
  281.             }
  282.             final Item[] allItems;
  283.             final Item[] items = allItems = mob.getAllItems();
  284.             for (final Item item : allItems) {
  285.                 if (item.isRepairable()) {
  286.                     item.setDamage(Math.min(99.0f, item.getDamage() + Math.max(10.0f + Server.rand.nextFloat() * 5.0f, 10.0f * item.getDamageModifier(false))));
  287.                 }
  288.             }
  289.         }
  290.         if (templateId == Reaper.templateId || templateId == SpectralDrake.templateId) {
  291.             Server.getInstance().broadCastAlert("The " + mob.getName() + " has been slain. A new creature shall enter the realm shortly.");
  292.             sendLootHelp = true;
  293.         }
  294.         else if (Titans.isTitan(mob)) {
  295.             Server.getInstance().broadCastAlert("The Titan " + mob.getName() + " has been defeated!");
  296.             MiscChanges.sendGlobalFreedomChat(mob, "The Titan " + mob.getName() + " has been defeated!", 255, 105, 180);
  297.             MiscChanges.sendServerTabMessage("titan", "The Titan " + mob.getName() + " has been defeated!", 255, 105, 180);
  298.             final Item armour = ItemUtil.createRandomPlateChain(50.0f, 80.0f, (byte)67, mob.getName());
  299.             if (armour != null) {
  300.                 ItemUtil.applyEnchant(armour, (byte)110, 80.0f + Server.rand.nextInt(40));
  301.                 corpse.insertItem(armour, true);
  302.             }
  303.             Titans.removeTitan(mob);
  304.             sendLootHelp = true;
  305.         }
  306.         if (mob.getTemplate().getTemplateId() == 23) {
  307.             try {
  308.                 final int[] lumpIds = { 694, 221, 223, 47, 698, 44, 46, 49, 45, 205, 48 };
  309.                 final Item randomLump = ItemFactory.createItem(lumpIds[LootBounty.random.nextInt(lumpIds.length)], 20.0f + 60.0f * LootBounty.random.nextFloat(), "");
  310.                 corpse.insertItem(randomLump);
  311.             }
  312.             catch (FailedException | NoSuchTemplateException ex4) {
  313.                 final WurmServerException ex2;
  314.                 final WurmServerException e = ex2;
  315.                 e.printStackTrace();
  316.             }
  317.         }
  318.         if (mob.isUnique()) {
  319.             blessWorldWithMoonVeins(mob);
  320.             spawnFriyanTablets();
  321.             insertUniqueLoot(mob, corpse);
  322.             sendLootHelp = true;
  323.         }
  324.         if (mob.getStatus().isChampion()) {
  325.             handleChampionLoot(corpse);
  326.         }
  327.         if (sendLootHelp) {
  328.             LootBounty.logger.info("Beginning loot assistance message generation...");
  329.             displayLootAssistance(mob);
  330.         }
  331.         if (numCrystals > 0) {
  332.             Server.getInstance().broadCastAction(mob.getName() + " had something of interest...", mob, 5);
  333.         }
  334.     }
  335.    
  336.     static {
  337.         logger = Logger.getLogger(LootBounty.class.getName());
  338.         random = new Random();
  339.     }
  340. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement