Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mod.sin.wyvern.bounty;
- import java.util.logging.*;
- import mod.piddagoras.duskombat.*;
- import java.text.*;
- import java.util.*;
- import com.wurmonline.shared.exceptions.*;
- import mod.sin.items.caches.*;
- import com.wurmonline.server.items.*;
- import com.wurmonline.mesh.*;
- import com.wurmonline.server.villages.*;
- import mod.sin.items.*;
- import com.wurmonline.server.creatures.*;
- import mod.sin.wyvern.util.*;
- import com.wurmonline.server.*;
- import mod.sin.creatures.*;
- import mod.sin.wyvern.*;
- public class LootBounty
- {
- public static final Logger logger;
- protected static final Random random;
- public static void displayLootAssistance(final Creature mob) {
- if (DamageEngine.dealtDamage.containsKey(mob.getWurmId())) {
- LootBounty.logger.info("Found the damageDealt entry, parsing...");
- final ArrayList<String> names = new ArrayList<String>();
- final ArrayList<Double> damages = new ArrayList<Double>();
- for (final long creatureId : DamageEngine.dealtDamage.get(mob.getWurmId()).keySet()) {
- if (Players.getInstance().getPlayerOrNull(creatureId) != null) {
- names.add(Players.getInstance().getPlayerOrNull(creatureId).getName());
- damages.add(DamageEngine.dealtDamage.get(mob.getWurmId()).get(creatureId));
- }
- else {
- if (Creatures.getInstance().getCreatureOrNull(creatureId) == null) {
- continue;
- }
- LootBounty.logger.info("Skipping creature " + Creatures.getInstance().getCreatureOrNull(creatureId).getName() + " in loot assistance.");
- }
- }
- LootBounty.logger.info("Names have been added: " + names);
- String strBuilder = "Loot Assistance <Damagers> (" + mob.getName() + "): ";
- final DecimalFormat formatter = new DecimalFormat("#,###,###");
- while (names.size() > 0) {
- final int index = Server.rand.nextInt(names.size());
- strBuilder += names.get(index);
- strBuilder = strBuilder + " [" + formatter.format(Math.round(damages.get(index))) + "]";
- names.remove(index);
- damages.remove(index);
- if (names.size() > 0) {
- strBuilder += ", ";
- }
- }
- MiscChanges.sendServerTabMessage("event", strBuilder, 0, 128, 255);
- LootBounty.logger.info("Broadcast loot assistance message success [Damage].");
- }
- else {
- LootBounty.logger.warning("Powerful creature " + mob.getName() + " died, but no players were credited to its death [Damage].");
- }
- }
- public static int doRollingCrystalReward(final Creature mob, final Item corpse, final double cretStr, final int templateId, final int chance, final double reductionPerRoll) {
- try {
- double rollingCounter = cretStr;
- int addedCrystals = 0;
- while (rollingCounter > 0.0) {
- if (LootBounty.random.nextInt(chance + addedCrystals) == 0) {
- final Item chaosCrystal = ItemFactory.createItem(templateId, (float)(LootBounty.random.nextFloat() * Math.min(100.0, Math.cbrt(rollingCounter))), "");
- if (LootBounty.random.nextInt(40) == 0) {
- chaosCrystal.setRarity((byte)1);
- }
- else if (mob.isUnique() && LootBounty.random.nextInt(5) == 0) {
- if (LootBounty.random.nextInt(5) == 0) {
- chaosCrystal.setRarity((byte)2);
- }
- else {
- chaosCrystal.setRarity((byte)1);
- }
- }
- corpse.insertItem(chaosCrystal);
- ++addedCrystals;
- }
- rollingCounter -= reductionPerRoll;
- }
- return addedCrystals;
- }
- catch (FailedException | NoSuchTemplateException ex2) {
- final WurmServerException ex;
- final WurmServerException e = ex;
- e.printStackTrace();
- return 0;
- }
- }
- public static void insertUniqueLoot(final Creature mob, final Item corpse) {
- try {
- final Item affinityOrb = ItemFactory.createItem(AffinityOrb.templateId, 90.0f + 10.0f * LootBounty.random.nextFloat(), "");
- corpse.insertItem(affinityOrb);
- final int[] cacheIds = { ArtifactCache.templateId, CrystalCache.templateId, CrystalCache.templateId, DragonCache.templateId, DragonCache.templateId, MoonCache.templateId, MoonCache.templateId, RiftCache.templateId, TreasureMapCache.templateId };
- for (int i = 1 + Server.rand.nextInt(3); i > 0; --i) {
- final Item cache = ItemFactory.createItem(cacheIds[Server.rand.nextInt(cacheIds.length)], 50.0f + 30.0f * LootBounty.random.nextFloat(), "");
- if (Server.rand.nextInt(5) == 0) {
- cache.setRarity((byte)1);
- }
- corpse.insertItem(cache);
- }
- if (mob.isDragon()) {
- final int mTemplate = mob.getTemplate().getTemplateId();
- int lootTemplate = 371;
- if (mTemplate == 89 || mTemplate == 91 || mTemplate == 90 || mTemplate == 16 || mTemplate == 92) {
- lootTemplate = 372;
- }
- LootBounty.logger.info("Generating extra hide & scale to insert on the corpse of " + mob.getName() + ".");
- final ItemTemplate itemTemplate = ItemTemplateFactory.getInstance().getTemplate(lootTemplate);
- for (int i = 0; i < 2; ++i) {
- final Item loot = ItemFactory.createItem(lootTemplate, 80.0f + 15.0f * LootBounty.random.nextFloat(), "");
- final String creatureName = mob.getTemplate().getName().toLowerCase();
- if (!loot.getName().contains(creatureName)) {
- loot.setName(creatureName.toLowerCase() + " " + itemTemplate.getName());
- }
- loot.setData2(mTemplate);
- final int weightGrams = itemTemplate.getWeightGrams() * ((lootTemplate == 371) ? 3 : 1);
- loot.setWeight((int)(weightGrams * 0.02f + weightGrams * 0.02f * LootBounty.random.nextFloat()), true);
- corpse.insertItem(loot);
- }
- }
- }
- catch (FailedException | NoSuchTemplateException ex2) {
- final WurmServerException ex;
- final WurmServerException e = ex;
- e.printStackTrace();
- }
- }
- public static void blessWorldWithMoonVeins(final Creature mob) {
- for (int i = 8 + Server.rand.nextInt(5); i > 0; --i) {
- final int x = LootBounty.random.nextInt(Server.surfaceMesh.getSize());
- final int y = LootBounty.random.nextInt(Server.surfaceMesh.getSize());
- final short height = Tiles.decodeHeight(Server.surfaceMesh.getTile(x, y));
- final int type = Tiles.decodeType(Server.caveMesh.getTile(x, y));
- if (height >= 100 && (type == Tiles.Tile.TILE_CAVE_WALL.id || type == Tiles.Tile.TILE_CAVE.id)) {
- final Tiles.Tile tileType = LootBounty.random.nextBoolean() ? Tiles.Tile.TILE_CAVE_WALL_ORE_ADAMANTINE : Tiles.Tile.TILE_CAVE_WALL_ORE_GLIMMERSTEEL;
- Server.caveMesh.setTile(x, y, Tiles.encode(Tiles.decodeHeight(Server.caveMesh.getTile(x, y)), tileType.id, Tiles.decodeData(Server.caveMesh.getTile(x, y))));
- Players.getInstance().sendChangedTile(x, y, false, true);
- Server.setCaveResource(x, y, 400 + LootBounty.random.nextInt(600));
- Village v = Villages.getVillage(x, y, true);
- if (v == null) {
- for (int vx = -20; vx < 20; vx += 5) {
- for (int vy = -20; vy < 20 && (v = Villages.getVillage(x + vx, y + vy, true)) == null; vy += 5) {}
- if (v != null) {
- break;
- }
- }
- }
- if (v != null) {
- HistoryManager.addHistory(mob.getTemplate().getName(), "blesses the world with a " + tileType.getName() + " near " + v.getName() + "!");
- MiscChanges.sendServerTabMessage("rumors", mob.getTemplate().getName() + " blesses the world with a " + tileType.getName() + " near " + v.getName() + "!", 255, 255, 255);
- }
- LootBounty.logger.info("Placed a " + tileType.getName() + " at " + x + ", " + y + " - " + height + " height");
- }
- }
- Server.getInstance().broadCastAlert("The death of the " + mob.getTemplate().getName() + " has blessed the world with valuable ores!");
- }
- public static void spawnFriyanTablets() {
- for (int i = 5 + LootBounty.random.nextInt(5); i > 0; --i) {
- final int x = LootBounty.random.nextInt(Server.surfaceMesh.getSize());
- final int y = LootBounty.random.nextInt(Server.surfaceMesh.getSize());
- final short height = Tiles.decodeHeight(Server.surfaceMesh.getTile(x, y));
- if (height > 0 && height < 1000 && Creature.getTileSteepness(x, y, true)[1] < 30) {
- try {
- 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");
- LootBounty.logger.info("Created a Tablet of Friyan at " + x + ", " + y + ".");
- }
- catch (NoSuchTemplateException | FailedException ex2) {
- final WurmServerException ex;
- final WurmServerException e = ex;
- e.printStackTrace();
- }
- }
- }
- }
- public static void handleDragonLoot(final Creature mob, final Item corpse) {
- try {
- final int mTemplate = mob.getTemplate().getTemplateId();
- int lootTemplate = 371;
- byte ctype;
- if (mTemplate == 89 || mTemplate == 91 || mTemplate == 90 || mTemplate == 16 || mTemplate == 92) {
- ctype = 99;
- lootTemplate = 372;
- }
- else {
- ctype = (byte)Math.max(0, Server.rand.nextInt(17) - 5);
- }
- final float x = mob.getPosX();
- final float y = mob.getPosY();
- final CreatureTemplate template = CreatureTemplateFactory.getInstance().getTemplate(SpectralDrake.templateId);
- 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));
- Server.getInstance().broadCastAction("The spirit of the " + mob.getTemplate().getName() + " is released into the world!", mob, 20);
- Server.getInstance().broadCastAlert(spectralDrake.getName() + " is released from the soul of the " + mob.getTemplate().getName() + ", seeking vengeance for its physical form!");
- LootBounty.logger.info("Generating extra hide & scale to insert on the corpse of " + mob.getName() + ".");
- final ItemTemplate itemTemplate = ItemTemplateFactory.getInstance().getTemplate(lootTemplate);
- for (int i = 0; i < 2; ++i) {
- final Item loot = ItemFactory.createItem(lootTemplate, 80.0f + 15.0f * LootBounty.random.nextFloat(), "");
- final String creatureName = mob.getTemplate().getName().toLowerCase();
- if (!loot.getName().contains(creatureName)) {
- loot.setName(creatureName.toLowerCase() + " " + itemTemplate.getName());
- }
- loot.setData2(mTemplate);
- final int weightGrams = itemTemplate.getWeightGrams() * ((lootTemplate == 371) ? 3 : 1);
- loot.setWeight((int)(weightGrams * 0.1f + weightGrams * 0.1f * LootBounty.random.nextFloat()), true);
- corpse.insertItem(loot);
- }
- for (int i = 0; i < 4; ++i) {
- final Item loot = ItemFactory.createItem(lootTemplate, 80.0f + 15.0f * LootBounty.random.nextFloat(), "");
- final String creatureName = mob.getTemplate().getName().toLowerCase();
- if (!loot.getName().contains(creatureName)) {
- loot.setName(creatureName.toLowerCase() + " " + itemTemplate.getName());
- }
- loot.setData2(mTemplate);
- final int weightGrams = itemTemplate.getWeightGrams() * ((lootTemplate == 371) ? 3 : 1);
- loot.setWeight((int)(weightGrams * 0.05f + weightGrams * 0.05f * LootBounty.random.nextFloat()), true);
- spectralDrake.getInventory().insertItem(loot);
- }
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static void handleChampionLoot(final Item corpse) {
- try {
- final Item tool = ItemUtil.createRandomLootTool();
- if (tool != null) {
- corpse.insertItem(tool, true);
- }
- if (LootBounty.random.nextInt(100) < 75) {
- corpse.insertItem(ItemFactory.createItem(LootBounty.random.nextBoolean() ? 694 : 698, 30.0f + 30.0f * LootBounty.random.nextFloat(), ""));
- }
- if (LootBounty.random.nextInt(100) < 5) {
- final int[] maskTemplates = { 973, 974, 975, 976, 977, 978, 1099 };
- corpse.insertItem(ItemFactory.createItem(maskTemplates[LootBounty.random.nextInt(maskTemplates.length)], 90.0f + 9.0f * LootBounty.random.nextFloat(), ""));
- }
- if (LootBounty.random.nextInt(100) < 1) {
- final Item bone = ItemFactory.createItem(867, 90.0f + 10.0f * LootBounty.random.nextFloat(), "");
- bone.setRarity((byte)1);
- if (LootBounty.random.nextInt(100) < 1) {
- bone.setRarity((byte)2);
- }
- corpse.insertItem(bone);
- }
- }
- catch (FailedException | NoSuchTemplateException ex2) {
- final WurmServerException ex;
- final WurmServerException e = ex;
- e.printStackTrace();
- }
- }
- public static void checkLootTable(final Creature mob, final Item corpse) {
- if (mob.isReborn() || mob.isBred()) {
- return;
- }
- final double cretStr = Bounty.getCreatureStrength(mob);
- final int numCrystals = 0;
- boolean sendLootHelp = false;
- final int templateId = mob.getTemplate().getTemplateId();
- if (Servers.localServer.PVPSERVER && mob.isPlayer()) {
- if (mob.isDeathProtected()) {
- LootBounty.logger.info("Death protection was active for " + mob.getName() + ". Inserting silver coin reward.");
- try {
- final Item silver = ItemFactory.createItem(52, 99.0f, (String)null);
- corpse.insertItem(silver, true);
- }
- catch (FailedException | NoSuchTemplateException ex3) {
- final WurmServerException ex;
- final WurmServerException e = ex;
- e.printStackTrace();
- }
- }
- final Item[] allItems;
- final Item[] items = allItems = mob.getAllItems();
- for (final Item item : allItems) {
- if (item.isRepairable()) {
- item.setDamage(Math.min(99.0f, item.getDamage() + Math.max(10.0f + Server.rand.nextFloat() * 5.0f, 10.0f * item.getDamageModifier(false))));
- }
- }
- }
- if (templateId == Reaper.templateId || templateId == SpectralDrake.templateId) {
- Server.getInstance().broadCastAlert("The " + mob.getName() + " has been slain. A new creature shall enter the realm shortly.");
- sendLootHelp = true;
- }
- else if (Titans.isTitan(mob)) {
- Server.getInstance().broadCastAlert("The Titan " + mob.getName() + " has been defeated!");
- MiscChanges.sendGlobalFreedomChat(mob, "The Titan " + mob.getName() + " has been defeated!", 255, 105, 180);
- MiscChanges.sendServerTabMessage("titan", "The Titan " + mob.getName() + " has been defeated!", 255, 105, 180);
- final Item armour = ItemUtil.createRandomPlateChain(50.0f, 80.0f, (byte)67, mob.getName());
- if (armour != null) {
- ItemUtil.applyEnchant(armour, (byte)110, 80.0f + Server.rand.nextInt(40));
- corpse.insertItem(armour, true);
- }
- Titans.removeTitan(mob);
- sendLootHelp = true;
- }
- if (mob.getTemplate().getTemplateId() == 23) {
- try {
- final int[] lumpIds = { 694, 221, 223, 47, 698, 44, 46, 49, 45, 205, 48 };
- final Item randomLump = ItemFactory.createItem(lumpIds[LootBounty.random.nextInt(lumpIds.length)], 20.0f + 60.0f * LootBounty.random.nextFloat(), "");
- corpse.insertItem(randomLump);
- }
- catch (FailedException | NoSuchTemplateException ex4) {
- final WurmServerException ex2;
- final WurmServerException e = ex2;
- e.printStackTrace();
- }
- }
- if (mob.isUnique()) {
- blessWorldWithMoonVeins(mob);
- spawnFriyanTablets();
- insertUniqueLoot(mob, corpse);
- sendLootHelp = true;
- }
- if (mob.getStatus().isChampion()) {
- handleChampionLoot(corpse);
- }
- if (sendLootHelp) {
- LootBounty.logger.info("Beginning loot assistance message generation...");
- displayLootAssistance(mob);
- }
- if (numCrystals > 0) {
- Server.getInstance().broadCastAction(mob.getName() + " had something of interest...", mob, 5);
- }
- }
- static {
- logger = Logger.getLogger(LootBounty.class.getName());
- random = new Random();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement