Rebase with upstream

This commit is contained in:
verinia 2019-05-28 22:15:17 -08:00
commit 101b8314c9
2889 changed files with 481914 additions and 0 deletions

View file

@ -0,0 +1,123 @@
package plugin.random;
import org.crandor.cache.def.impl.ItemDefinition;
import org.crandor.game.interaction.OptionHandler;
import org.crandor.game.node.Node;
import org.crandor.game.node.entity.npc.drop.DropFrequency;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.item.ChanceItem;
import org.crandor.game.node.item.Item;
import org.crandor.game.world.repository.Repository;
import org.crandor.plugin.Plugin;
import org.crandor.tools.RandomFunction;
import org.crandor.plugin.InitializablePlugin;
import org.crandor.tools.StringUtils;
/**
* Handles the mystery box item.
* @author Vexia
* @author Splinter
*/
@InitializablePlugin
public final class MysteryBoxPlugin extends OptionHandler {
/**
* The rewards recieved from a mystery box.
*/
private static final ChanceItem[] REWARDS = new ChanceItem[] {
new ChanceItem(8008, 2, 5, DropFrequency.COMMON),//lumbridge tab
new ChanceItem(8007, 2, 5, DropFrequency.COMMON),//varrock tab
new ChanceItem(8009, 2, 5, DropFrequency.COMMON),//falador tab
new ChanceItem(8010, 2, 5, DropFrequency.COMMON),//camelot tab
new ChanceItem(555, 100, 120, DropFrequency.COMMON),//water rune
new ChanceItem(557, 100, 300, DropFrequency.COMMON),//earth rune
new ChanceItem(556, 100, 380, DropFrequency.COMMON),//air rune
new ChanceItem(7937, 76, 150, DropFrequency.COMMON),//noted pure ess
new ChanceItem(232, 26, 50, DropFrequency.COMMON),//snape grass noted
new ChanceItem(8779, 27, 35, DropFrequency.COMMON),//oak planks
new ChanceItem(10476, 15, 25, DropFrequency.COMMON),//purple sweets
new ChanceItem(226, 5, 9, DropFrequency.COMMON),//limpwurt root
new ChanceItem(1776, 19, 35, DropFrequency.COMMON),//molten glass
new ChanceItem(12158, 10, 18, DropFrequency.UNCOMMON),//green charm
new ChanceItem(12160, 10, 18, DropFrequency.UNCOMMON),//crimson charm
new ChanceItem(565, 100, 120, DropFrequency.UNCOMMON),//blood rune
new ChanceItem(5302, 9, 18, DropFrequency.UNCOMMON),//lantadyme seed
new ChanceItem(5300, 6, 12, DropFrequency.UNCOMMON),//snap seed
new ChanceItem(390, 18, 26, DropFrequency.UNCOMMON),//raw manta ray
new ChanceItem(396, 20, 28, DropFrequency.UNCOMMON),//raw sea turtle
new ChanceItem(5297, 4, 11, DropFrequency.UNCOMMON),//irit seed
new ChanceItem(12183, 2000, 9999, DropFrequency.UNCOMMON),//spirit shard
new ChanceItem(11255, 1, 3, DropFrequency.UNCOMMON),//ninja impling jar
new ChanceItem(2358, 15, 28, DropFrequency.UNCOMMON),//noted gold bar
new ChanceItem(450, 16, 27, DropFrequency.UNCOMMON),//addy ore
new ChanceItem(8781, 48, 75, DropFrequency.UNCOMMON),//teak plank
new ChanceItem(8427, 1, 1, DropFrequency.UNCOMMON),//bagged yew tree
new ChanceItem(6688, 8, 17, DropFrequency.UNCOMMON),//sara brew(3)
new ChanceItem(4153, 1, 1, DropFrequency.RARE),//granite maul
new ChanceItem(985, 1, 1, DropFrequency.RARE),//half key
new ChanceItem(987, 1, 1, DropFrequency.RARE),//half key
new ChanceItem(989, 1, 1, DropFrequency.RARE),//full key
new ChanceItem(1333, 1, 1, DropFrequency.RARE),//rune scimitar
new ChanceItem(9194, 9, 18, DropFrequency.RARE),//onyx bolt tips
new ChanceItem(6809, 1, 1, DropFrequency.RARE),//granite legs
new ChanceItem(3122, 1, 1, DropFrequency.RARE),//granite shield
new ChanceItem(4131, 1, 1, DropFrequency.RARE),//rune booties
new ChanceItem(1359, 1, 1, DropFrequency.RARE),//rune axe
new ChanceItem(2363, 9, 17, DropFrequency.RARE),//rune bar
new ChanceItem(12922, 1, 1, DropFrequency.RARE),//rune spikeshield
new ChanceItem(12929, 1, 1, DropFrequency.RARE),//rune berserker shield
new ChanceItem(1149, 1, 1, DropFrequency.RARE),//dragon med helm
new ChanceItem(1319, 1, 1, DropFrequency.RARE),//rune 2h
new ChanceItem(5315, 1, 2, DropFrequency.RARE),//yew seed
new ChanceItem(8787, 1, 2, DropFrequency.RARE),//marble block
new ChanceItem(12163, 12, 21, DropFrequency.RARE),//blue charm
new ChanceItem(8429, 1, 1, DropFrequency.RARE),//bagged magic tree
new ChanceItem(1631, 1, 1, DropFrequency.RARE),//uncut dstone
new ChanceItem(1127, 1, 1, DropFrequency.RARE),//rune pl8
new ChanceItem(5316, 1, 2, DropFrequency.VERY_RARE),//magic seed
new ChanceItem(2366, 1, 1, DropFrequency.VERY_RARE),//shield left half
new ChanceItem(1305, 1, 1, DropFrequency.VERY_RARE),//dragon longsword
new ChanceItem(3204, 1, 1, DropFrequency.VERY_RARE),//dragon halberd
new ChanceItem(10394, 1, 1, DropFrequency.VERY_RARE),//flared trousers
new ChanceItem(11256, 2, 4, DropFrequency.VERY_RARE),//dragon impling jar
new ChanceItem(10508, 1, 1, DropFrequency.VERY_RARE),//wintumber tree
new ChanceItem(11902, 1, 1, DropFrequency.VERY_RARE),//enchanted robe set
new ChanceItem(13107, 1, 1, DropFrequency.VERY_RARE),//sheep mask
new ChanceItem(10398, 1, 1, DropFrequency.VERY_RARE),//sleeping cap
new ChanceItem(2577, 1, 1, DropFrequency.VERY_RARE),//ranger boots
};
@Override
public Plugin<Object> newInstance(Object arg) throws Throwable {
ItemDefinition.forId(6199).getConfigurations().put("option:open", this);
return this;
}
@Override
public boolean handle(Player player, Node node, String option) {
final ChanceItem item = RandomFunction.getChanceItem(REWARDS);
final String name = item.getName().toLowerCase();
final Item box = (Item) node;
if (player.getInventory().remove(box, box.getSlot(), true)) {
player.lock(1);
player.getInventory().add(new Item(item.getId(), RandomFunction.random(item.getMinimumAmount(), item.getMaximumAmount())));
player.sendMessage("Inside the box you find " + (item.getId() == 995 ? "some" : (StringUtils.isPlusN(name) ? "an" : "a")) + " " + name + "!");
if(item.getChanceRate() <= 10){
Repository.sendNews(player.getUsername()+" has just recieved "+item.getAmount()+" x "+item.getName()+" from a Mystery box.");
}
}
return true;
}
@Override
public boolean isWalk() {
return false;
}
}

View file

@ -0,0 +1,113 @@
package plugin.random.drilldemon;
import java.nio.ByteBuffer;
import org.crandor.game.content.ame.AntiMacroEvent;
import org.crandor.game.interaction.Option;
import org.crandor.game.node.Node;
import org.crandor.game.node.entity.Entity;
import org.crandor.game.node.entity.npc.NPC;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.system.task.Pulse;
import org.crandor.game.world.GameWorld;
import org.crandor.game.world.map.Location;
import org.crandor.game.world.map.RegionManager;
import org.crandor.game.world.update.flag.context.Graphics;
import org.crandor.plugin.PluginManager;
/**
* Handles the drill demon event.
* @author Vexia
*/
public final class DrillDemonEvent extends AntiMacroEvent {
/**
* Constructs a new {@code DrillDemonEvent} {@code Object}.
*/
public DrillDemonEvent() {
this(null);
}
/**
* Constructs a new {@code DrillDemonEvent} {@code Object}.
*/
public DrillDemonEvent(Player player) {
super("drill demon", false, false);
this.player = player;
}
@Override
public void save(ByteBuffer buffer) {
}
@Override
public void parse(ByteBuffer buffer) {
}
@Override
public boolean start(Player player, boolean login, Object... args) {
if (login) {
return true;
}
final NPC sergeant = NPC.create(2790, player.getLocation());
if (!initSergeant(sergeant)) {
return false;
}
player.lock(4);
sergeant.lock(4);
sergeant.face(player);
player.graphics(Graphics.create(86), 3);
sergeant.sendChat("Private " + player.getUsername() + "! Get yourself to the parade ground ASAP!");
GameWorld.submit(new Pulse(3, player, sergeant) {
@Override
public boolean pulse() {
return true;
}
});
return true;
}
@Override
public AntiMacroEvent create(Player player) {
return new DrillDemonEvent(player);
}
@Override
public boolean interact(Entity e, Node target, Option option) {
return super.interact(e, target, option);
}
/**
* Initializes the sergeant (temporary).
* @param sergeant the sergeant.
* @return {@code True} if so.
*/
private boolean initSergeant(NPC sergeant) {
final Location start = RegionManager.getSpawnLocation(player, sergeant);
if (start == null) {
terminate();
return false;
}
sergeant.setLocation(start);
sergeant.init();
return true;
}
@Override
public void register() {
PluginManager.definePlugin(new SergeantDamienNPC());
}
@Override
public Location getSpawnLocation() {
return null;
}
@Override
public void configure() {
}
}

View file

@ -0,0 +1,67 @@
package plugin.random.drilldemon;
import org.crandor.game.node.entity.npc.AbstractNPC;
import org.crandor.game.world.map.Location;
import org.crandor.plugin.Plugin;
/**
* Handles the sergeant damien npc.
* @author Vexia
*/
public final class SergeantDamienNPC extends AbstractNPC {
/**
* The default spawn.
*/
private static final Location DEFAULT_SPAWN = Location.create(3163, 4818, 0);
/**
* The movement path.
*/
private static final Location[] MOVEMENT_PATH = new Location[] { Location.create(3163, 4818, 0), Location.create(3162, 4818, 0), Location.create(3161, 4818, 0), Location.create(3160, 4818, 0), Location.create(3159, 4818, 0), Location.create(3159, 4819, 0), Location.create(3159, 4820, 0), Location.create(3159, 4821, 0), Location.create(3159, 4822, 0), Location.create(3160, 4822, 0), Location.create(3161, 4822, 0), Location.create(3162, 4822, 0), Location.create(3163, 4822, 0), Location.create(3164, 4822, 0), Location.create(3165, 4822, 0), Location.create(3166, 4822, 0), Location.create(3167, 4822, 0), Location.create(3167, 4821, 0), Location.create(3167, 4820, 0), Location.create(3167, 4819, 0), Location.create(3167, 4818, 0), Location.create(3166, 4818, 0), Location.create(3165, 4818, 0), Location.create(3164, 4818, 0) };
/**
* Constructs a new {@code SergeantDamienNPC} {@code Object}.
*/
public SergeantDamienNPC() {
super(2790, DEFAULT_SPAWN);
}
/**
* Constructs a new {@code SergeantDamienNPC} {@code Object}.
* @param id the id.
* @param location the location.
*/
public SergeantDamienNPC(int id, Location location) {
super(id, location);
}
@Override
public void configure() {
super.configure();
setWalks(true);
if (isWalks()) {
configureMovementPath(MOVEMENT_PATH);
}
}
@Override
public void setNextWalk() {
}
@Override
public AbstractNPC construct(int id, Location location, Object... objects) {
return new SergeantDamienNPC(id, location);
}
@Override
public Plugin<Object> newInstance(Object arg) throws Throwable {
init();
return super.newInstance(arg);
}
@Override
public int[] getIds() {
return new int[] { 2790 };
}
}

View file

@ -0,0 +1,127 @@
package plugin.random.drunkdwarf;
import java.nio.ByteBuffer;
import org.crandor.game.content.ame.AntiMacroDialogue;
import org.crandor.game.content.ame.AntiMacroEvent;
import org.crandor.game.content.dialogue.DialoguePlugin;
import org.crandor.game.content.dialogue.FacialExpression;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.item.Item;
import org.crandor.game.world.map.Location;
import org.crandor.game.world.update.flag.context.Animation;
import org.crandor.plugin.InitializablePlugin;
import org.crandor.plugin.PluginManager;
/**
* Handles the drunken dward anti macro event.
* @author Vexia
*/
@InitializablePlugin
public final class DrunkDwarfEvent extends AntiMacroEvent {
/**
* The name of the drunken dwarf event.
*/
public static final String NAME = "drunk dwarf";
/**
* Constructs a new {@code DrunkDwarfEvent} {@code Object}.
*/
public DrunkDwarfEvent() {
super(NAME, true, false);
}
@Override
public void save(ByteBuffer buffer) {
}
@Override
public void parse(ByteBuffer buffer) {
}
@Override
public boolean start(Player player, boolean login, Object... args) {
final DrunkenDwarfNPC dwarf = new DrunkenDwarfNPC(956, player.getLocation(), this, player);
dwarf.init();
super.init(player);
return true;
}
@Override
public AntiMacroEvent create(Player player) {
DrunkDwarfEvent event = new DrunkDwarfEvent();
event.player = player;
return event;
}
@Override
public void register() {
PluginManager.definePlugin(new DrunkDwarfDialogue());
}
@Override
public Location getSpawnLocation() {
return null;
}
@Override
public void configure() {
}
/**
* Handles the drunk dwarf dialogue.
* @author Vexia
*/
public final class DrunkDwarfDialogue extends AntiMacroDialogue {
/**
* Constructs a new {@code DrunkDwarfDialogue} {@code Object}.
*/
public DrunkDwarfDialogue() {
/**
* empty.
*/
}
/**
* Constructs a new {@code DrunkDwarfDialogue} {@code Object}.
* @param player the player.
*/
public DrunkDwarfDialogue(Player player) {
super(player);
}
@Override
public DialoguePlugin newInstance(Player player) {
return new DrunkDwarfDialogue(player);
}
@Override
public boolean open(Object... args) {
if (super.open(args)) {
player.getDialogueInterpreter().sendDialogues(npc, FacialExpression.OSRS_NORMAL, "I 'new it were you matey! 'Ere, have some ob the good", "stuff!");
} else {
return true;
}
return true;
}
@Override
public boolean handle(int interfaceId, int buttonId) {
wave(Animation.create(105));
player.getInventory().add(new Item(1917), player);
player.getInventory().add(new Item(1971), player);
return true;
}
@Override
public int[] getIds() {
return new int[] { 956 };
}
}
}

View file

@ -0,0 +1,67 @@
package plugin.random.drunkdwarf;
import org.crandor.game.content.ame.AntiMacroEvent;
import org.crandor.game.content.ame.AntiMacroNPC;
import org.crandor.game.node.entity.Entity;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.entity.player.link.audio.Audio;
import org.crandor.game.world.map.Location;
/**
* Handles the drunken dwarf npc.
* @author Vexia
*/
public final class DrunkenDwarfNPC extends AntiMacroNPC {
/**
* The quotes that the dwarf will say.
*/
private static final String[] QUOTES = new String[] { "'Ere, matey, 'ave some 'o the good stuff.", "Dun ignore your matey!", "I hates you @name!", "Aww comeon, talk to ikle me @name!" };
/**
* Constructs a new {@code DrunkenDwarfNPC} {@code Object}.
* @param id the id.
* @param location the location.
* @param event
* @param player
*/
public DrunkenDwarfNPC(int id, Location location, AntiMacroEvent event, Player player) {
super(id, location, event, player, QUOTES);
}
@Override
public void init() {
super.init();
player.getAudioManager().send(new Audio(344));
}
@Override
public void handleTickActions() {
super.handleTickActions();
if (timeUp && getDialoguePlayer() == null) {
if (!getProperties().getCombatPulse().isAttacking()) {
getProperties().getCombatPulse().attack(player);
}
}
}
@Override
public void handleTimeUp() {
}
@Override
public boolean isIgnoreAttackRestrictions(Entity victim) {
return true;
}
@Override
public boolean isIgnoreMultiBoundaries(Entity victim) {
return victim == player;
}
@Override
public int[] getIds() {
return new int[] { 956 };
}
}

View file

@ -0,0 +1,140 @@
package plugin.random.evilchicken;
import org.crandor.game.node.entity.Entity;
import org.crandor.game.node.entity.combat.BattleState;
import org.crandor.game.node.entity.combat.CombatStyle;
import org.crandor.game.node.entity.combat.CombatSwingHandler;
import org.crandor.game.node.entity.combat.handlers.MagicSwingHandler;
import org.crandor.game.node.entity.npc.AbstractNPC;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.item.GroundItem;
import org.crandor.game.node.item.GroundItemManager;
import org.crandor.game.node.item.Item;
import org.crandor.game.world.map.Location;
import org.crandor.game.world.update.flag.context.Graphics;
import org.crandor.tools.RandomFunction;
/**
* Handles the evil chicken NPC.
* @author Emperor
*/
public final class EvilChickenNPC extends AbstractNPC {
/**
* The messages the evil chicken can use.
*/
private static final String[] MESSAGES = { "Bwuk", "Bwuk bwuk bwuk", "Bwaaaaaauk bwuk bwuk", "How dare you invade my lair?", "MUAHAHAHAHAAA!", "Flee from me, @name@!", "Begone, @name@!" };
/**
* The player.
*/
protected Player player;
/**
* The random event instance.
*/
public EvilChickenRandomEvent event;
/**
* The combat swing handler.
*/
private static final CombatSwingHandler HANDLER = new MagicSwingHandler() {
@Override
public int swing(Entity entity, Entity victim, BattleState state) {
entity.sendChat(RandomFunction.getRandomElement(MESSAGES).replace("@name@", victim.getUsername()));
return super.swing(entity, victim, state);
}
};
/**
* Constructs a new {@code EvilChickenNPC} {@code Object}.
*/
public EvilChickenNPC() {
this(2463, null);
}
@Override
public void finalizeDeath(Entity killer) {
super.finalizeDeath(killer);
if (killer instanceof Player) {
GroundItemManager.create(new GroundItem(new Item(526), getLocation(), killer.asPlayer()));
GroundItemManager.create(new GroundItem(new Item(2138), getLocation(), killer.asPlayer()));
GroundItemManager.create(new GroundItem(new Item(314, RandomFunction.random(32, 750)), getLocation(), killer.asPlayer()));
}
}
/**
* Constructs a new {@code EvilChickenNPC} {@code Object}.
* @param id The NPC id.
* @param location The location.
*/
public EvilChickenNPC(int id, Location location) {
super(id, location);
}
@Override
public void init() {
super.init();
setRespawn(false);
graphics(Graphics.create(86));
getProperties().getCombatPulse().attack(player);
}
@Override
public void handleTickActions() {
if (player == null) {
return;
}
if (!getProperties().getCombatPulse().isAttacking()) {
getProperties().getCombatPulse().attack(player);
}
if (!player.isActive() || !getLocation().withinDistance(player.getLocation(), 10)) {
clear();
}
}
@Override
public CombatSwingHandler getSwingHandler(boolean swing) {
return HANDLER;
}
@Override
public boolean isAttackable(Entity entity, CombatStyle style) {
if (entity instanceof Player && entity != player) {
((Player) entity).getPacketDispatch().sendMessage("It's not after you.");
return false;
}
return super.isAttackable(entity, style);
}
@Override
public boolean isIgnoreMultiBoundaries(Entity victim) {
return victim == player;
}
@Override
public void onRegionInactivity() {
super.onRegionInactivity();
clear();
}
@Override
public void clear() {
super.clear();
if (event != null) {
event.terminate();
}
}
@Override
public AbstractNPC construct(int id, Location location, Object... objects) {
return new EvilChickenNPC(id, location);
}
@Override
public int[] getIds() {
return new int[] { 2463, 2464, 2465, 2466, 2467, 2468 };
}
}

View file

@ -0,0 +1,89 @@
package plugin.random.evilchicken;
import java.nio.ByteBuffer;
import org.crandor.game.content.ame.AntiMacroEvent;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.entity.player.link.HintIconManager;
import org.crandor.game.world.map.Location;
import org.crandor.plugin.InitializablePlugin;
import org.crandor.plugin.PluginManager;
/**
* Handles the evil chicken random event.
* @author Emperor
*/
@InitializablePlugin
public final class EvilChickenRandomEvent extends AntiMacroEvent {
/**
* Constructs a new {@code EvilChickenRandomEvent} {@code Object}.
*/
public EvilChickenRandomEvent() {
super("chicken", true, false);
}
@Override
public boolean start(Player player, boolean login, Object... args) {
super.init(player);
int level = player.getProperties().getCurrentCombatLevel();
int npcId = 2468;
if (level < 11) {
npcId = 2463;
} else if (level < 21) {
npcId = 2464;
} else if (level < 41) {
npcId = 2465;
} else if (level < 61) {
npcId = 2466;
} else if (level < 91) {
npcId = 2467;
}
Location location = Location.getRandomLocation(player.getLocation(), 6, true);
EvilChickenNPC npc = new EvilChickenNPC(npcId, location);
npc.player = player;
npc.event = this;
npc.init();
if (location == player.getLocation()) {
npc.moveStep();
}
HintIconManager.registerHintIcon(player, npc);
return true;
}
@Override
public void terminate() {
super.terminate();
if (player != null) {
player.getHintIconManager().clear();
}
}
@Override
public AntiMacroEvent create(Player player) {
EvilChickenRandomEvent event = new EvilChickenRandomEvent();
event.player = player;
return event;
}
@Override
public Location getSpawnLocation() {
return null;
}
@Override
public void configure() {
PluginManager.definePlugin(new EvilChickenNPC());
}
@Override
public void save(ByteBuffer buffer) {
}
@Override
public void parse(ByteBuffer buffer) {
}
}

View file

@ -0,0 +1,507 @@
package plugin.random.eviltwin;
import java.nio.ByteBuffer;
import org.crandor.ServerConstants;
import org.crandor.game.component.CloseEvent;
import org.crandor.game.component.Component;
import org.crandor.game.content.ame.AntiMacroEvent;
import org.crandor.game.content.global.action.DoorActionHandler;
import org.crandor.game.interaction.Option;
import org.crandor.game.node.Node;
import org.crandor.game.node.entity.Entity;
import org.crandor.game.node.entity.npc.NPC;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.object.GameObject;
import org.crandor.game.node.object.ObjectBuilder;
import org.crandor.game.system.task.Pulse;
import org.crandor.game.world.GameWorld;
import org.crandor.game.world.map.Direction;
import org.crandor.game.world.map.Location;
import org.crandor.game.world.map.build.DynamicRegion;
import org.crandor.game.world.update.flag.context.Animation;
import org.crandor.game.world.update.flag.context.Graphics;
import org.crandor.net.packet.PacketRepository;
import org.crandor.net.packet.context.CameraContext;
import org.crandor.net.packet.context.CameraContext.CameraType;
import org.crandor.net.packet.out.CameraViewPacket;
import org.crandor.plugin.PluginManager;
import org.crandor.tools.RandomFunction;
/**
* Handles the evil twin random event.
* @author Emperor
*/
public final class EvilTwinRandomEvent extends AntiMacroEvent {
/**
* The x-offset.
*/
private int offsetX = 0;
/**
* The y-offset.
*/
private int offsetY = 0;
/**
* The Molly NPC.
*/
private NPC molly;
/**
* The current crane object.
*/
private GameObject currentCrane;
/**
* The amount of tries left.
*/
private int tries = 3;
/**
* If the event has been completed.
*/
private boolean success;
/**
* The crane NPC.
*/
private NPC craneNPC;
/**
* Constructs a new {@code EvilTwinRandomEvent} {@code Object}.
*/
public EvilTwinRandomEvent() {
this(null);
}
/**
* Constructs a new {@code EvilTwinRandomEvent} {@code Object}.
* @param player The player.
*/
public EvilTwinRandomEvent(Player player) {
super("Evil twin", true, true);
super.player = player;
}
@Override
public void register() {
PluginManager.definePlugin(new MollyDialogue());
}
@Override
public boolean start(final Player player, boolean login, Object... args) {
region = DynamicRegion.create(7504);
region.setMusicId(612);
registerRegion(region.getId());
currentCrane = new GameObject(14976, region.getBaseLocation().transform(14, 12, 0), 10, 0);
if (login) {
int hash = player.getAttribute("ame:evil_twin", 0);
molly = NPC.create(getMollyId(hash), region.getBaseLocation().transform(4, 15, 0));
molly.init();
spawnSuspects(hash);
toggleVisibleNPCs(player.getLocation().getLocalX() < 9);
player.getProperties().setTeleportLocation(region.getBaseLocation().transform(offsetX, offsetY, 0));
return true;
}
TwinClothColor color = RandomFunction.getRandomElement(TwinClothColor.values());
int model = RandomFunction.random(5);
final int hash = color.ordinal() | (model << 16);
player.setAttribute("ame:evil_twin", hash);
int npcId = getMollyId(hash);
molly = NPC.create(npcId, Location.getRandomLocation(player.getLocation(), 2, true));
molly.init();
molly.graphics(Graphics.create(86, 96));
molly.sendChat("I need your help, " + player.getUsername() + ".");
molly.face(player);
player.lock(4);
player.setAttribute("ame:location", player.getLocation());
GameWorld.submit(new Pulse(3) {
@Override
public boolean pulse() {
teleport(player, molly, hash);
return true;
}
});
return true;
}
@Override
public boolean enter(Entity entity) {
if (entity instanceof Player) {
((Player) entity).getInterfaceManager().hideTabs(0, 1, 2, 3, 4, 5, 6, 7, 11, 12);
}
return super.enter(entity);
}
@Override
public boolean leave(Entity e, boolean logout) {
if (e == player) {
if (!logout) {
terminate();
}
player.removeAttribute("ame:evil_twin:ccx");
player.removeAttribute("ame:evil_twin:ccy");
}
return super.leave(e, logout);
}
@Override
public void terminate() {
super.terminate();
craneNPC = null;
if (player != null) {
player.getInterfaceManager().restoreTabs();
player.removeAttribute("ame:location");
player.removeAttribute("ame:evil_twin_info");
PacketRepository.send(CameraViewPacket.class, new CameraContext(player, CameraType.RESET, 0, 0, 0, 0, 0));
}
}
@Override
public boolean interact(Entity e, Node target, Option option) {
if (target instanceof GameObject) {
GameObject object = (GameObject) target;
switch (object.getId()) {
case 14982:
if (e.getLocation().getLocalX() < 9 && !e.getAttribute("ame:evil_twin_info", false)) {
player.getDialogueInterpreter().open("ame:molly", molly, 3);
return true;
}
DoorActionHandler.handleAutowalkDoor(e, object);
return true;
case 14978:
if (success) {
player.getPacketDispatch().sendMessage("You already caught the evil twin.");
return true;
}
player.getInterfaceManager().openSingleTab(new Component(240).setCloseEvent(new CloseEvent() {
@Override
public boolean close(Player player, Component c) {
ObjectBuilder.remove(currentCrane);
ObjectBuilder.add(new GameObject(66, currentCrane.getLocation(), 22, 0));
currentCrane = currentCrane.transform(currentCrane.getId(), currentCrane.getRotation(), region.getBaseLocation().transform(14, 12, 0));
ObjectBuilder.add(new GameObject(14977, currentCrane.getLocation(), 22, 0));
ObjectBuilder.add(currentCrane);
PacketRepository.send(CameraViewPacket.class, new CameraContext(player, CameraType.RESET, 0, 0, 0, 0, 0));
return true;
}
}));
player.getPacketDispatch().sendString("Tries: " + tries, 240, 27);
updateCraneCam(14, 12);
return true;
}
} else if (target instanceof NPC) {
NPC npc = (NPC) target;
if ((tries < 1 || success) && npc.getId() >= 3892 && npc.getId() <= 3911) {
player.getDialogueInterpreter().open("ame:molly", npc, success ? 2 : 1);
return true;
}
}
return false;
}
@Override
public boolean actionButton(final Player player, int interfaceId, int buttonId, int slot, int itemId, int opcode) {
if (success) {
return false;
}
switch (interfaceId) {
case 240:
switch (buttonId) {
case 28:
player.lock(5);
player.getLocks().lockComponent(5);
success = false;
for (final NPC npc : region.getPlanes()[0].getNpcs()) {
if (npc.getLocation().equals(currentCrane.getLocation())) {
final boolean evilTwin = isEvilTwin(npc, player.getAttribute("ame:evil_twin", 0));
if (evilTwin) {
success = true;
player.getPacketDispatch().sendMessage("You caught the Evil twin!");
} else {
player.getPacketDispatch().sendMessage("You caught an innocent civilian!");
}
npc.animate(Animation.create(4001));
npc.lock(10);
player.lock(10);
player.getLocks().lockComponent(15);
updateCraneCam(10, 4);
GameWorld.submit(new Pulse(5, player) {
int cycle = 0;
@Override
public boolean pulse() {
switch (cycle++) {
case 0:
ObjectBuilder.remove(currentCrane);
ObjectBuilder.add(new GameObject(66, currentCrane.getLocation(), 22, 0));
npc.transform(npc.getId() + 20);
npc.lock(20);
npc.getWalkingQueue().reset();
npc.getWalkingQueue().addPath(region.getBaseLocation().getX() + 10, region.getBaseLocation().getY() + 4);
setDelay(npc.getWalkingQueue().getQueue().size() + 1);
craneNPC = npc;
break;
case 1:
craneNPC = null;
npc.animate(Animation.create(4003));
setDelay(3);
break;
case 2:
npc.reTransform();
npc.faceLocation(player.getLocation());
if (evilTwin) {
removeSuspects();
npc.getAnimator().forceAnimation(Animation.create(859));
} else {
npc.sendChat("You're putting me in prison?!");
}
currentCrane = currentCrane.transform(currentCrane.getId(), currentCrane.getRotation(), region.getBaseLocation().transform(14, 12, 0));
ObjectBuilder.add(new GameObject(14977, currentCrane.getLocation(), 22, 0));
ObjectBuilder.add(currentCrane);
break;
case 3:
updateCraneCam(14, 12);
if (evilTwin) {
player.getInterfaceManager().closeSingleTab();
player.getDialogueInterpreter().open("ame:molly", molly, 0);
} else {
decreaseTries();
}
return true;
}
return false;
}
});
player.getPacketDispatch().sendObjectAnimation(currentCrane, Animation.create(4000));
return true;
}
}
decreaseTries();
player.getPacketDispatch().sendObjectAnimation(currentCrane, Animation.create(4000));
return true;
case 29:
moveCrane(Direction.SOUTH);
return true;
case 30:
moveCrane(Direction.NORTH);
return true;
case 31:
moveCrane(Direction.EAST);
return true;
case 32:
moveCrane(Direction.WEST);
return true;
case 34:
player.getInterfaceManager().closeSingleTab();
return true;
}
break;
}
return false;
}
/**
* Decreases the tries amount.
*/
public void decreaseTries() {
tries--;
player.getPacketDispatch().sendString("Tries: " + tries, 240, 27);
if (tries < 1) {
player.lock(20);
player.getInterfaceManager().closeSingleTab();
player.getDialogueInterpreter().open("ame:molly", molly, 1);
}
}
@Override
public void locationUpdate(Entity e, Location last) {
if (e == craneNPC && e.getWalkingQueue().getQueue().size() > 1 && player.getInterfaceManager().getSingleTab() != null) {
Location l = e.getLocation();
PacketRepository.send(CameraViewPacket.class, new CameraContext(player, CameraType.POSITION, l.getX() + 2, l.getY() + 3, 650, 1, 5));
PacketRepository.send(CameraViewPacket.class, new CameraContext(player, CameraType.ROTATION, l.getX() - 3, l.getY() - 3, 420, 1, 5));
} else if (e == player) {
if (molly.isInvisible() && e.getLocation().getLocalX() < 9) {
toggleVisibleNPCs(true);
} else if (!molly.isInvisible() && e.getLocation().getLocalX() > 8) {
toggleVisibleNPCs(false);
}
}
super.locationUpdate(e, last);
}
/**
* Toggles the visibility of the NPCs.
* @param showMolly If molly should be shown.
*/
public void toggleVisibleNPCs(boolean showMolly) {
for (NPC npc : region.getPlanes()[0].getNpcs()) {
if (npc.getId() >= 3852 && npc.getId() <= 3891) {
npc.setInvisible(showMolly);
}
}
molly.setInvisible(!showMolly);
}
/**
* Method used to handle the camera.
* @param x the x offset.
* @param y the y offset.
* @param xRot the xRotation.
* @param yRot the yRotation.
* @Param height the height.
*/
private void updateCraneCam(int x, int y) {
if (player.getInterfaceManager().getSingleTab() != null) {
Location loc = region.getBaseLocation().transform(14, 20, 0);
PacketRepository.send(CameraViewPacket.class, new CameraContext(player, CameraType.POSITION, loc.getX(), loc.getY(), 650, 1, 100));
loc = region.getBaseLocation().transform(x, 4 + y - (x < 14 || x > 14 ? (y / 4) : 0), 0);
PacketRepository.send(CameraViewPacket.class, new CameraContext(player, CameraType.ROTATION, loc.getX(), loc.getY(), 420, 1, 100));
}
player.setAttribute("ame:evil_twin:ccx", x);
player.setAttribute("ame:evil_twin:ccy", y);
}
/**
* Removes the suspects.
*/
public void removeSuspects() {
int hash = player.getAttribute("ame:evil_twin", 0);
for (final NPC npc : region.getPlanes()[0].getNpcs()) {
if (npc.getId() >= 3852 && npc.getId() <= 3891 && !isEvilTwin(npc, hash)) {
Graphics.send(Graphics.create(86), npc.getLocation());
npc.clear();
}
}
}
/**
* Checks if the NPC is the evil twin NPC.
* @param npc The NPC.
* @return {@code True} if so.
*/
private boolean isEvilTwin(NPC npc, int hash) {
int npcId = npc.getId() - 3852;
int type = npcId / TwinClothColor.values().length;
int color = npcId - (type * TwinClothColor.values().length);
return hash == (color | (type << 16));
}
/**
* Moves the crane.
* @param direction The current direction.
*/
private void moveCrane(final Direction direction) {
GameWorld.submit(new Pulse(1, player) {
@Override
public boolean pulse() {
if (!direction.canMove(currentCrane.getLocation().transform(direction))) {
return true;
}
int craneX = player.getAttribute("ame:evil_twin:ccx", 14) + direction.getStepX();
int craneY = player.getAttribute("ame:evil_twin:ccy", 12) + direction.getStepY();
updateCraneCam(craneX, craneY);
ObjectBuilder.remove(currentCrane);
ObjectBuilder.add(new GameObject(66, currentCrane.getLocation(), 22, 0));
currentCrane = currentCrane.transform(currentCrane.getId(), currentCrane.getRotation(), region.getBaseLocation().transform(craneX, craneY, 0));
ObjectBuilder.add(new GameObject(14977, currentCrane.getLocation(), 22, 0));
ObjectBuilder.add(currentCrane);
return true;
}
});
}
@Override
public boolean teleport(Entity e, int type, Node node) {
if (type != -1) {
if (e instanceof Player) {
((Player) e).getPacketDispatch().sendMessage("You can't teleport away from here.");
}
return false;
}
return true;
}
/**
* Spawns the suspects.
* @param hash The color & type.
*/
public void spawnSuspects(int hash) {
if (region.getPlanes()[0].getNpcs().size() > 3) {
return;
}
int npcId = 3852 + (hash & 0xFF);
for (int i = 0; i < 5; i++) {
Location location = region.getBaseLocation().transform(11 + RandomFunction.random(8), 6 + RandomFunction.random(6), 0);
NPC suspect = NPC.create(npcId + (i * TwinClothColor.values().length), location);
suspect.setWalks(true);
suspect.setWalkRadius(6);
suspect.init();
}
}
/**
* Teleports the player and Molly to the random event region.
* @param player The player.
* @param npc The NPC.
*/
public void teleport(Player player, NPC npc, int hash) {
npc.getProperties().setTeleportLocation(region.getBaseLocation().transform(4, 15, 0));
player.getProperties().setTeleportLocation(region.getBaseLocation().transform(4, 16, 0));
player.getDialogueInterpreter().open(npc.getId(), npc);
spawnSuspects(hash);
toggleVisibleNPCs(true);
}
/**
* Gets the current NPC id for Molly.
* @param color The clothing color.
* @param type The type (looks).
* @return The NPC id.
*/
public static int getMollyId(int hash) {
return 3892 + (hash & 0xFF) + (((hash >> 16) & 0xFF) * TwinClothColor.values().length);
}
@Override
public void save(ByteBuffer buffer) {
int offset = player.getAttribute("ame:evil_twin", 0);
buffer.put((byte) (offset & 0xFF));
buffer.put((byte) ((offset >> 16) & 0xFF));
buffer.put((byte) (player.getLocation().getX() - region.getBaseLocation().getX()));
buffer.put((byte) (player.getLocation().getY() - region.getBaseLocation().getY()));
buffer.put((byte) tries);
Location loc = player.getAttribute("ame:location", ServerConstants.HOME_LOCATION);
buffer.putShort((short) loc.getX());
buffer.putShort((short) loc.getY());
buffer.put((byte) loc.getZ());
buffer.put((byte) (success ? 1 : 0));
}
@Override
public void parse(ByteBuffer buffer) {
player.setAttribute("ame:evil_twin", (buffer.get() & 0xFF) | ((buffer.get() & 0xFF) << 16));
offsetX = buffer.get() & 0xFF;
offsetY = buffer.get() & 0xFF;
tries = buffer.get() & 0xFF;
player.setAttribute("ame:location", Location.create(buffer.getShort(), buffer.getShort(), buffer.get()));
success = (buffer.get() & 0xFF) == 1;
}
@Override
public AntiMacroEvent create(Player player) {
return new EvilTwinRandomEvent(player);
}
@Override
public Location getSpawnLocation() {
return null;
}
@Override
public void configure() {
}
}

View file

@ -0,0 +1,156 @@
package plugin.random.eviltwin;
import org.crandor.game.content.ame.AntiMacroEvent;
import org.crandor.game.content.dialogue.DialogueInterpreter;
import org.crandor.game.content.dialogue.DialoguePlugin;
import org.crandor.game.node.entity.npc.NPC;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.entity.player.link.TeleportManager.TeleportType;
import org.crandor.game.node.item.GroundItemManager;
import org.crandor.game.node.item.Item;
import org.crandor.game.system.script.ScriptContext;
import org.crandor.game.system.script.ScriptManager;
import org.crandor.game.world.map.Location;
import org.crandor.tools.RandomFunction;
/**
* Handles Molly's dialogue.
* @author Emperor
*/
public final class MollyDialogue extends DialoguePlugin {
/**
* The possible rewards.
*/
private static final Item[] REWARDS = { new Item(1618, 2), new Item(1620, 3), new Item(1622, 3), new Item(1624, 4), };
/**
* If the player successfully caught the evil twin.
*/
private int type;
/**
* Constructs a new {@code MollyDialogue} {@code Object}.
*/
public MollyDialogue() {
super();
}
/**
* Constructs a new {@code MollyDialogue} {@code Object}.
* @param player The player.
*/
public MollyDialogue(Player player) {
super(player);
}
@Override
public DialoguePlugin newInstance(Player player) {
return new MollyDialogue(player);
}
@Override
public boolean open(Object... args) {
npc = (NPC) args[0];
type = (Integer) args[1];
if (type == 0) {
player.getPacketDispatch().sendMessage("Congratulations! You caught the evil twin!");
npc("Well done! You managed to catch my sister!");
} else if (type == 1) {
npc("Such incompetence! I should never have asked a", "baboon like you to do a complex task like this!", "Get out of my sight!");
} else if (type == 2) {
player("Well, I've managed to get her into the cage.");
} else if (type == 3) {
npc("Wait! Do you know what you're doing here?");
}
return true;
}
@Override
public boolean handle(int interfaceId, int buttonId) {
switch (stage++) {
case 0:
switch (type) {
case 0:
npc("Come next door and talk to me.");
return true;
case 1:
player("Err, sorry. I seem to have messed it up a little.");
return true;
case 2:
npc("Fantastic! For so many years I've had to put up with", "her and now she's locked up for good.");
return true;
case 3:
options("Yes, I know.", "Erm, no I don't actually.");
return true;
}
break;
case 1:
switch (type) {
case 0:
end();
return true;
case 1:
player.getTeleporter().send(AntiMacroEvent.getRandomLocation(), TeleportType.NORMAL, -1);
end();
return true;
case 2:
npc("Thank you for all your help. Take this as a reward.");
return true;
case 3:
switch (buttonId) {
case 1:
player.setAttribute("/save:ame:evil_twin_info", true);
player("Yes, I know, I've been here before.");
stage = 10;
return true;
case 2:
stage = 20;
player("Erm, no I don't actually.");
return true;
}
break;
}
break;
case 2:
switch (type) {
case 2:
end();
Location destination = player.getAttribute("ame:location");
if (destination != null) {
Item item = RandomFunction.getRandomElement(REWARDS);
if (player.getInventory().hasSpaceFor(item)) {
player.getInventory().add(item);
} else {
GroundItemManager.create(item, destination, player);
}
player.getDialogueInterpreter().sendItemMessage(item, "Molly's given you " + item.getAmount() + " " + item.getName().toLowerCase() + "s.");
player.getProperties().setTeleportLocation(destination);
player.removeAttribute("ame:location");
}
return true;
}
break;
case 10:
npc("Good luck!");
break;
case 11:
end();
break;
case 20:
end();
ScriptContext script = DialogueInterpreter.getScript(npc.getId());
if (script != null && (script = ScriptManager.getMethod(script, "event_info")) != null) {
player.getDialogueInterpreter().startScript(npc.getId(), script, player, npc);
}
break;
}
return false;
}
@Override
public int[] getIds() {
return new int[] { DialogueInterpreter.getDialogueKey("ame:molly") };
}
}

View file

@ -0,0 +1,10 @@
package plugin.random.eviltwin;
/**
* The clothing colors.
* @author Emperor
*/
public enum TwinClothColor {
RED, GREEN, BLUE, YELLOW;
}

View file

@ -0,0 +1,48 @@
package plugin.random.genie;
import org.crandor.game.content.ame.AntiMacroNPC;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.world.map.Location;
import org.crandor.game.world.update.flag.context.Graphics;
/**
* Handles the random event genie npc.
* @author Vexia
*/
public final class GenieNPC extends AntiMacroNPC {
/**
* The force chats to pronounce.
*/
private static final String[] CHATS = new String[] { "Greetings, @gL @name!", "Ehem... @gender @name?", "Are you there, @gL @name?", "No one ignores me!" };
/**
* Constructs a new {@code GenieNPC} {@code Object}.
* @param id the id.
* @param location the location.
* @param event the event.
* @param player the player.
*/
public GenieNPC(int id, Location location, GenieRandomEvent event, Player player) {
super(id, location, event, player, CHATS);
}
/**
* Constructs a new {@code GenieNPC} {@code Object}.
*/
public GenieNPC() {
super(0, null, null, null);
}
@Override
public void init() {
super.init();
graphics(new Graphics(86));
}
@Override
public int[] getIds() {
return new int[] { 409 };
}
}

View file

@ -0,0 +1,135 @@
package plugin.random.genie;
import java.nio.ByteBuffer;
import org.crandor.game.content.ame.AntiMacroDialogue;
import org.crandor.game.content.ame.AntiMacroEvent;
import org.crandor.game.content.dialogue.DialoguePlugin;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.item.Item;
import org.crandor.game.world.map.Location;
import org.crandor.plugin.InitializablePlugin;
import org.crandor.plugin.PluginManager;
/**
* Handles the genie random event.
* @author Vexia
*/
@InitializablePlugin
public final class GenieRandomEvent extends AntiMacroEvent {
/**
* The lamp item.
*/
private static final Item LAMP = new Item(2528);
/**
* Constructs a new {@code GenieRandomEvent} {@code Object}.
*/
public GenieRandomEvent() {
super("Genie", true, false);
}
@Override
public void save(ByteBuffer buffer) {
}
@Override
public void parse(ByteBuffer buffer) {
}
@Override
public boolean start(Player player, boolean login, Object... args) {
if (player.hasItem(new Item(2528))) {
return false;
}
super.init(player);
final GenieNPC npc = new GenieNPC(409, player.getLocation(), this, player);
npc.init();
return true;
}
@Override
public AntiMacroEvent create(Player player) {
final GenieRandomEvent event = new GenieRandomEvent();
event.player = player;
return event;
}
@Override
public Location getSpawnLocation() {
return null;
}
@Override
public void configure() {
}
@Override
public void register() {
PluginManager.definePlugin(new GenieDialogue());
}
@Override
public String getGenderPrefix(boolean male) {
return male ? "Master" : "Mistress";
}
/**
* Handles the dialogue used for the genie npc.
* @author Vexia
*/
public final class GenieDialogue extends AntiMacroDialogue {
/**
* Constructs a new {@code GenieDialogue} {@code Object}.
*/
public GenieDialogue() {
/**
* empty.
*/
}
/**
* Constructs a new {@code GenieDialogue} {@code Object}.
* @param player the player.
*/
public GenieDialogue(Player player) {
super(player);
}
@Override
public DialoguePlugin newInstance(Player player) {
return new GenieDialogue(player);
}
@Override
public boolean open(Object... args) {
if (super.open(args)) {
npc("Ah, so you are there " + player.getAntiMacroHandler().getEvent().getGenderPrefix().toLowerCase() + ". I'm so glad you", "summoned me. Please take this lamp and make your", "wish!");
}
return true;
}
@Override
public boolean handle(int interfaceId, int buttonId) {
switch (stage) {
case 0:
npc("I hope you're happy with your wish. I must be leaving", "now, though.");
stage++;
break;
case 1:
wave();
player.getInventory().add(LAMP, player);
break;
}
return true;
}
@Override
public int[] getIds() {
return new int[] { 409 };
}
}
}

View file

@ -0,0 +1,211 @@
package plugin.random.lostandfound;
import java.nio.ByteBuffer;
import org.crandor.ServerConstants;
import org.crandor.cache.def.impl.ObjectDefinition;
import org.crandor.game.content.ame.AntiMacroEvent;
import org.crandor.game.interaction.Option;
import org.crandor.game.interaction.OptionHandler;
import org.crandor.game.node.Node;
import org.crandor.game.node.entity.Entity;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.entity.player.link.TeleportManager;
import org.crandor.game.node.item.Item;
import org.crandor.game.node.object.GameObject;
import org.crandor.game.system.task.Pulse;
import org.crandor.game.world.GameWorld;
import org.crandor.game.world.map.Location;
import org.crandor.net.packet.PacketRepository;
import org.crandor.net.packet.context.MinimapStateContext;
import org.crandor.net.packet.out.MinimapState;
import org.crandor.plugin.Plugin;
import org.crandor.plugin.PluginManager;
import org.crandor.tools.RandomFunction;
/**
* Handles the "Lost and found" random event.
* @author Emperor
*/
public final class LostFoundRandomEvent extends AntiMacroEvent {
/**
* Constructs a new {@code LostFoundRandomEvent} {@code Object}.
*/
public LostFoundRandomEvent() {
this(null);
}
/**
* Constructs a new {@code LostFoundRandomEvent} {@code Object}.
* @param player The player.
*/
public LostFoundRandomEvent(Player player) {
super("landf", false, true, -1);
super.player = player;
}
@Override
public boolean start(Player player, boolean login, Object... args) {
player.getProperties().setTeleportLocation(Location.create(2338, 4747, 0));
if (player.getAttribute("l&f_dest") == null) {
player.setAttribute("l&f_dest", args.length > 0 ? args[0] : player.getLocation());
}
player.sendChat("Uh? Help!");
return true;
}
@Override
public boolean enter(Entity entity) {
if (entity instanceof Player) {
Player player = (Player) entity;
setRandomAppendage(player);
PacketRepository.send(MinimapState.class, new MinimapStateContext(player, 2));
player.getDialogueInterpreter().sendPlainMessage(false, "There has been a fault in the teleportation matrix. Please operate the", "odd appendage out to be forwarded to your destination.");
}
return super.enter(entity);
}
@Override
public boolean leave(Entity entity, boolean logout) {
if (entity instanceof Player && !logout) {
Player player = (Player) entity;
PacketRepository.send(MinimapState.class, new MinimapStateContext(player, 0));
player.removeAttribute("l&f_dest");
player.removeAttribute("teleport:items");
player.getLocks().unlock();
player.getAntiMacroHandler().setEvent(null);
}
return super.leave(entity, logout);
}
@Override
public boolean interact(Entity e, Node target, Option option) {
if (!(target instanceof GameObject)) {
return true;
}
return false;
}
@Override
public boolean actionButton(Player player, int interfaceId, int buttonId, int slot, int itemId, int opcode) {
return false;
}
@Override
public boolean teleport(Entity e, int type, Node node) {
if (type != -1) {
if (e instanceof Player) {
((Player) e).getPacketDispatch().sendMessage("You have to operate the appendage before you can teleport again.");
}
return false;
}
return true;
}
@Override
public AntiMacroEvent create(Player player) {
return new LostFoundRandomEvent(player);
}
@Override
public Location getSpawnLocation() {
return null;
}
/**
* Sets a random odd appendage.
* @param player The player.
*/
private static void setRandomAppendage(Player player) {
int value = 0;
int odd = RandomFunction.random(4);
int mod = RandomFunction.RANDOM.nextBoolean() ? 0 : 1;
int offset = RandomFunction.random(4) * 2;
for (int i = 0; i < 4; i++) {
if (i == odd) {
value |= (offset + (1 - mod)) << (i * 5);
} else {
value |= (offset + mod) << (i * 5);
}
}
player.getConfigManager().set(531, value);
}
@Override
public void configure() {
registerRegion(9290);
PluginManager.definePlugin(new OptionHandler() {
@Override
public Plugin<Object> newInstance(Object arg) throws Throwable {
for (int id = 8998; id < 9006; id++) {
ObjectDefinition.forId(id).getConfigurations().put("option:operate", this);
}
return this;
}
@Override
public boolean handle(final Player player, Node node, String option) {
GameObject object = (GameObject) node;
player.lock(2);
if (isOddAppendage(player, object)) {
GameWorld.submit(new Pulse(4) {
@Override
public boolean pulse() {
player.getDialogueInterpreter().sendPlainMessage(false, "The Abyssal Services Department apologises for the inconvenience.");
return true;
}
});
player.getInventory().add(player.getAttribute("teleport:items", new Item[0]));
player.getTeleporter().send(player.getAttribute("l&f_dest", ServerConstants.HOME_LOCATION), TeleportManager.getType(player), -1);
} else {
setRandomAppendage(player);
player.getPacketDispatch().sendMessage("That was not the correct appendage!");
}
return true;
}
/**
* Checks if the object was the player's odd appendage.
* @param player The player.
* @param objectId The object id.
* @return {@code True} if the odd appendage was operated.
*/
private boolean isOddAppendage(Player player, GameObject object) {
int index = object.getWrapper().getId() - 8994;
int current = object.getWrapper().getChild(player).getId();
for (int i = 0; i < 4; i++) {
if (index != i && ObjectDefinition.forId(8994 + i).getChildObject(player).getId() == current) {
return false;
}
}
return true;
}
});
}
@Override
public void save(ByteBuffer buffer) {
Location l = player.getAttribute("l&f_dest", player.getLocation());
buffer.putShort((short) l.getX()).putShort((short) l.getY()).put((byte) l.getZ());
Item[] runes = player.getAttribute("teleport:items", new Item[0]);
buffer.put((byte) runes.length);
for (int i = 0; i < runes.length; i++) {
buffer.putShort((short) runes[i].getId());
buffer.put((byte) runes[i].getAmount());
}
}
@Override
public void parse(ByteBuffer buffer) {
player.setAttribute("l&f_dest", Location.create(buffer.getShort(), buffer.getShort(), buffer.get()));
Item[] runes = new Item[buffer.get() & 0xFF];
for (int i = 0; i < runes.length; i++) {
runes[i] = new Item(buffer.getShort() & 0xFFFF, buffer.get() & 0xFF);
}
if (runes.length > 0) {
player.setAttribute("teleport:items", runes);
}
}
}

View file

@ -0,0 +1,138 @@
package plugin.random.lostpirate;
import java.nio.ByteBuffer;
import org.crandor.game.content.ame.AntiMacroDialogue;
import org.crandor.game.content.ame.AntiMacroEvent;
import org.crandor.game.content.dialogue.DialoguePlugin;
import org.crandor.game.node.entity.npc.drop.DropFrequency;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.item.ChanceItem;
import org.crandor.game.node.item.Item;
import org.crandor.game.world.map.Location;
import org.crandor.plugin.PluginManager;
import org.crandor.plugin.InitializablePlugin;
import org.crandor.tools.RandomFunction;
/**
* Handles the capn hand anti macro event.
* @author Vexia
*/
@InitializablePlugin
public final class CapnHandEvent extends AntiMacroEvent {
/**
* The name of the event.
*/
public static final String NAME = "capn hand";
/**
* Constructs a new {@code CapnHandEvent} {@code Object}.
*/
public CapnHandEvent() {
super(NAME, true, false);
}
@Override
public void save(ByteBuffer buffer) {
}
@Override
public void parse(ByteBuffer buffer) {
}
@Override
public boolean start(Player player, boolean login, Object... args) {
final CapnHandNPC capn = new CapnHandNPC(2539, player.getLocation(), this, player);
capn.init();
super.init(player);
return true;
}
@Override
public AntiMacroEvent create(Player player) {
CapnHandEvent event = new CapnHandEvent();
event.player = player;
return event;
}
@Override
public void register() {
PluginManager.definePlugin(new CapnHandDialogue());
}
@Override
public Location getSpawnLocation() {
return null;
}
@Override
public void configure() {
}
@Override
public String getGenderPrefix(boolean male) {
return male ? "mister" : "miss";
}
/**
* Handles the rick turpnetine dialogue.
* @author Vexia
*/
public static final class CapnHandDialogue extends AntiMacroDialogue {
/**
* The random items recieved.
*/
private static final ChanceItem[] ITEMS = new ChanceItem[] { new ChanceItem(995, 1, 640, DropFrequency.COMMON), new ChanceItem(1969, 1, 1, DropFrequency.COMMON), new ChanceItem(1971, 1, 1, DropFrequency.COMMON), new ChanceItem(1623, 1, 1, DropFrequency.UNCOMMON), new ChanceItem(1621, 1, 1, DropFrequency.UNCOMMON), new ChanceItem(1619, 1, 1, DropFrequency.UNCOMMON), new ChanceItem(1617, 1, 1, DropFrequency.UNCOMMON), new ChanceItem(1454, 1, 1, DropFrequency.UNCOMMON), new ChanceItem(985, 1, 1, DropFrequency.RARE) };
/**
* Constructs a new {@code CapnHandDialogue} {@code Object}.
*/
public CapnHandDialogue() {
/**
* empty.
*/
}
/**
* Constructs a new {@code CapnHandDialogue} {@code Object}.
* @param player the player.
*/
public CapnHandDialogue(Player player) {
super(player);
}
@Override
public DialoguePlugin newInstance(Player player) {
return new CapnHandDialogue(player);
}
@Override
public boolean open(Object... args) {
if (super.open(args)) {
npc("My mistake " + event.getGenderPrefix() + ", I was thinking yer be some other", "fella!", "Take this swag, and we'll be saying no more about it!", "Yarrr!");
} else {
return true;
}
return true;
}
@Override
public boolean handle(int interfaceId, int buttonId) {
final Item item = RandomFunction.getChanceItem(ITEMS).getRandomItem();
player.getInventory().add(item, player);
wave(null);
return true;
}
@Override
public int[] getIds() {
return new int[] { 2539 };
}
}
}

View file

@ -0,0 +1,60 @@
package plugin.random.lostpirate;
import org.crandor.game.content.ame.AntiMacroEvent;
import org.crandor.game.content.ame.AntiMacroNPC;
import org.crandor.game.node.entity.Entity;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.world.map.Location;
/**
* Handles the capn hand npc.
* @author Vexia
*/
public final class CapnHandNPC extends AntiMacroNPC {
/**
* The quotes to say.
*/
private static final String[] QUOTES = new String[] { "Heave to, @gender @name!", "That be an order, @gender @name!" };
/**
* Constructs a new {@code CapnHandNPC} {@code Object}.
* @param id the id.
* @param location the loc.
* @param event the event.
* @param player the player.
*/
public CapnHandNPC(int id, Location location, AntiMacroEvent event, Player player) {
super(id, location, event, player, QUOTES);
}
@Override
public void handleTickActions() {
super.handleTickActions();
if (timeUp && getDialoguePlayer() == null) {
if (!getProperties().getCombatPulse().isAttacking()) {
getProperties().getCombatPulse().attack(player);
}
}
}
@Override
public void handleTimeUp() {
}
@Override
public boolean isIgnoreAttackRestrictions(Entity victim) {
return true;
}
@Override
public boolean isIgnoreMultiBoundaries(Entity victim) {
return victim == player;
}
@Override
public int[] getIds() {
return new int[] { 2539 };
}
}

View file

@ -0,0 +1,256 @@
package plugin.random.quizmaster;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.crandor.cache.def.impl.ItemDefinition;
import org.crandor.game.content.dialogue.DialoguePlugin;
import org.crandor.game.content.dialogue.FacialExpression;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.item.GroundItemManager;
import org.crandor.game.node.item.Item;
import org.crandor.game.world.GameWorld;
import org.crandor.game.world.map.Location;
import org.crandor.net.packet.PacketRepository;
import org.crandor.net.packet.context.DisplayModelContext;
import org.crandor.net.packet.context.DisplayModelContext.ModelType;
import org.crandor.net.packet.out.DisplayModel;
import org.crandor.tools.RandomFunction;
/**
* Handles the quiz master dialogue.
* @author Vexia
*/
public final class QuizMasterDialogue extends DialoguePlugin {
/**
* The correct dialogues.
*/
private static final String[][] CORRECT = new String[][] { { "Hey, you're good at this!", "CORRECT!", "Okay, next question!" }, { "Absolutely RIGHT!", "Keep going for the win!", "Okay, next question!" }, { "Wow, you're a smart one!", "You're absolutely right!", "Okay, next question!" }, { "COR-RECT!", "Okay, next question!" }, { "DING DING DING", "That's RIGHT! Good for you!", "Okay, next question!" }, { "YES!", "You're RIGHT!", "Okay, next question!" } };
/**
* The wrong dialogues.
*/
private static final String[][] WRONG = new String[][] { { "Huh...? Didn't you know that one?", "You're supposed to pick the ODD ONE OUT.", "Now, let's start again..." }, { "No. No, that's not right at all.", "You're supposed to pick the ODD ONE OUT.", "Now let's start again..." }, { "No, sorry, Try harder!", "You're supposed to pick the ODD ONE OUT.", "Now, let's start again..." }, { "Better luck next time!", "You're supposed to pick the ODD ONE OUT.", "Now, let's start again..." }, { "WRONG! That's just WRONG!", "You're supposed to pick the ODD ONE OUT.", "Now, let's start again..." }, { "WRONG WRONG WRONG!", "You're supposed to pick the ODD ONE OUT.", "Now, let's start again..." }, { "No, no, no... That's completely WRONG!", "You're supposed to pick the ODD ONE OUT.", "Now, let's start again..." }, { "Nope, that's not it.", "You're supposed to pick the ODD ONE OUT.", "Now, let's start again..." }, { "BZZZZZZZ! WRONG!", "You're supposed to pick the ODD ONE OUT.", "Now, let's start again..." } };
/**
* The coin reward.
*/
private static final Item COINS = new Item(995, 1000);
/**
* The mystery box reward.
*/
private static final Item MYSTERY_BOX = new Item(6199);
/**
* The quiz master event.
*/
private QuizMasterEvent event;
/**
* The wrong button id.
*/
private int wrongId;
/**
* Constructs a new {@code QuizMasterDialogue} {@code Object}.
*/
public QuizMasterDialogue() {
/**
* empty.
*/
}
/**
* Constructs a new {@code QuizMasterDialogue} {@code Object}.
* @param player the player.
*/
public QuizMasterDialogue(final Player player) {
super(player);
}
@Override
public DialoguePlugin newInstance(Player player) {
return new QuizMasterDialogue(player);
}
@Override
public boolean open(Object... args) {
event = (QuizMasterEvent) args[0];
if (!event.isStartedQuiz()) {
event.setStartedQuiz(true);
} else {
if (event.getScore() == 4) {
npc(BLUE + "CONGRATULATIONS!", "You are a " + RED + "WINNER</col>!", "Please choose your " + BLUE + "PRIZE</col>!");
stage = 4;
return true;
}
npc(event.getScore() == 0 ? ("Okay! First question!") : "Okay! Next question!");
stage = 2;
return true;
}
npc("WELCOME to the GREATEST QUIZ SHOW in the", "whole of " + GameWorld.getName() + ".", "<col=7f0000>O <col=6f000f>D <col=5f001f>D <col=4f002f>O <col=3f003f>N <col=2f004f>E <col=1f005f>O <col=0f006f>U <col=00007f>T");
return true;
}
@Override
public boolean handle(int interfaceId, int buttonId) {
switch (stage) {
case 0:
interpreter.sendDialogues(player, FacialExpression.ANNOYED, "I'm sure I didn't ask to take part in a quiz show...");
stage++;
break;
case 1:
npc("Please welcome our newest contestant:", RED + player.getUsername(), "Just pick the ODD ONE OUT", "Four questions right, and then you win!");
stage++;
break;
case 2:
display(QuizSet.getQuizSet());
player.getInterfaceManager().openChatbox(191);
stage++;
break;
case 3:
buttonId -= 4;
final boolean wrong = wrongId != buttonId;
if (wrong) {
event.resetScore();
} else {
event.incrementScore();
}
if (event.getScore() == 4) {
npc(BLUE + "CONGRATULATIONS!", "You are a " + RED + "WINNER</col>!", "Please choose your " + BLUE + "PRIZE</col>!");
stage = 4;
break;
}
npc(getDialogue(wrong ? WRONG : CORRECT));
stage = 2;
break;
case 4:
options("1000 Coins", "Mystery Box");
stage++;
break;
case 5:
reward(buttonId == 1 ? COINS : MYSTERY_BOX);
break;
default:
System.out.println("UNHANDLED QUIZ STAGE " + stage + ", " + buttonId + ", " + interfaceId);
break;
}
return true;
}
/**
* Rewards the player.
* @param item the item.
*/
private void reward(Item item) {
end();
event.terminate();
Location destination = player.getAttribute("ame:location");
if (destination != null) {
if (!player.getInventory().hasSpaceFor(item)) {
GroundItemManager.create(item, destination, player);
} else {
player.getInventory().add(item);
}
player.getProperties().setTeleportLocation(destination);
}
}
/**
* Displays a quiz.
* @param quiz the quiz.
*/
private void display(QuizSet[] quiz) {
QuizSet correct = quiz[0];
QuizSet wrong = quiz[1];
List<Integer> childs = new ArrayList<>();
childs.add(1);
childs.add(2);
childs.add(3);
Collections.shuffle(childs);
for (int i = 0; i < 2; i++) {
sendItem(correct.getModel(i), childs.get(i));
}
wrongId = childs.get(2);
sendItem(wrong.getModel(RandomFunction.random(wrong.ids.length)), wrongId);
}
/**
* Sends an item.
* @param model the model.
* @param index the index.
*/
private void sendItem(int model, int index) {
PacketRepository.send(DisplayModel.class, new DisplayModelContext(player, ModelType.MODEL, model, 190, 191, 4 + index));
}
/**
* Gets the dialogues of a 2d array.
* @param dialogues the dialogues.
* @return the dialogues.
*/
public String[] getDialogue(String[][] dialogues) {
return dialogues[RandomFunction.random(dialogues.length)];
}
@Override
public int[] getIds() {
return new int[] { 2477 };
}
/**
* Fish, 6189, 6190, Weapons - 6191, 6192, Armour - 6193, 6194, Craftings -
* 6195, 6196, Jewllery - 6197, 6198
*/
/**
* Represents a quiz set.
* @author Vexia
*/
public enum QuizSet {
FISH(6189, 6190), WEAPONRY(6191, 6192), ARMOUR(6193, 6194), TOOLS(6195, 6196), JEWELLERY(6197, 6198);
/**
* The item ids.
*/
private int[] ids;
/**
* Constructs a new {@code QuizSet} {@code Object}.
* @param ids the ids.
*/
private QuizSet(int... ids) {
this.ids = ids;
}
/**
* Gets the quiz set.
* @return the set.
*/
public static QuizSet[] getQuizSet() {
List<QuizSet> sets = new ArrayList<>();
for (QuizSet s : values()) {
sets.add(s);
}
Collections.shuffle(sets);
QuizSet[] set = new QuizSet[2];
set[0] = sets.get(0);
sets.remove(set[0]);
set[1] = sets.get(RandomFunction.random(sets.size()));
return set;
}
/**
* Gets the model id.
* @param index the index.
* @return the model.
*/
public int getModel(int index) {
return ItemDefinition.forId(ids[index]).getInterfaceModelId();
}
}
}

View file

@ -0,0 +1,233 @@
package plugin.random.quizmaster;
import java.nio.ByteBuffer;
import org.crandor.ServerConstants;
import org.crandor.game.content.ame.AntiMacroEvent;
import org.crandor.game.node.entity.Entity;
import org.crandor.game.node.entity.npc.NPC;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.entity.player.link.SavedData;
import org.crandor.game.world.map.Location;
import org.crandor.net.packet.PacketRepository;
import org.crandor.net.packet.context.CameraContext;
import org.crandor.net.packet.context.CameraContext.CameraType;
import org.crandor.net.packet.out.CameraViewPacket;
import org.crandor.plugin.InitializablePlugin;
import org.crandor.plugin.PluginManager;
/**
* Handles the quiz master random event.
* @author Vexia
*/
@InitializablePlugin
public final class QuizMasterEvent extends AntiMacroEvent {
/**
* The quiz master random event.
*/
private NPC quizMaster;
/**
* The score of the quiz.
*/
private int score;
/**
* If the quiz was started.
*/
private boolean startedQuiz;
/**
* Constructs a new {@code QuizMasterEvent} {@code Object}.
*/
public QuizMasterEvent() {
super("quiz master", true, true);
}
@Override
public void save(ByteBuffer buffer) {
SavedData.save(buffer, score, 1);
SavedData.save(buffer, startedQuiz, 2);
buffer.put((byte) 3);
Location l = player.getAttribute("ame:location", ServerConstants.HOME_LOCATION);
l.save(buffer);
buffer.put((byte) 0);
}
@Override
public void parse(ByteBuffer buffer) {
int opcode;
while ((opcode = buffer.get()) != 0) {
switch (opcode) {
case 1:
score = buffer.get();
break;
case 2:
startedQuiz = SavedData.getBoolean(buffer.get());
break;
case 3:
player.setAttribute("ame:location", Location.parse(buffer));
break;
}
}
}
@Override
public boolean enter(Entity entity) {
/*
* if (player.getName().equals("vexia")) { return false; } if (entity
* instanceof Player) { ((Player)
* entity).getInterfaceManager().removeTabs(0, 1, 2, 3, 4, 5, 6, 7, 11,
* 12); } return super.enter(entity);
*/
return false;
}
@Override
public boolean start(Player player, boolean login, Object... args) {
return false;
/*
* if (player.getName().equals("vexia")) { return false; }
*/
/*
* setRegion(); if (login) { quizMaster = NPC.create(2477,
* getLocation(32, 32)); quizMaster.init(); teleport(); if (startedQuiz)
* { startQuiz(); } return true; } player.getPulseManager().clear();
* player.getInterfaceManager().close(); setQuizMaster(false); if
* (quizMaster == null) { return false; }
* player.setAttribute("ame:location", player.getLocation());
* player.lock(5); quizMaster.lock(5); quizMaster.face(player);
* quizMaster.graphics(Graphics.create(86));
* quizMaster.sendChat("It's your lucky day!");
* player.graphics(Graphics.create(86), 3); GameWorld.submit(new
* Pulse(4, player, quizMaster) {
* @Override public boolean pulse() { teleport(); setQuizMaster(true);
* return true; } }); super.init(player); return true;
*/
}
@Override
public boolean leave(Entity e, boolean logout) {
if (e == player) {
if (!logout) {
terminate();
} else {
if (quizMaster != null) {
quizMaster.clear();
}
region.flagInactive();
}
}
return super.leave(e, logout);
}
@Override
public void terminate() {
super.terminate();
quizMaster = null;
if (player != null) {
player.getAnimator().reset();
player.getAppearance().setDefaultAnimations();
player.getAppearance().sync();
player.getInterfaceManager().restoreTabs();
PacketRepository.send(CameraViewPacket.class, new CameraContext(player, CameraType.RESET, 0, 0, 0, 0, 0));
}
}
@Override
public AntiMacroEvent create(Player player) {
final QuizMasterEvent event = new QuizMasterEvent();
event.player = player;
return event;
}
/**
* Resets the score.
*/
public void resetScore() {
score = 0;
}
/**
* Increments the score.
*/
public void incrementScore() {
score++;
}
/**
* Gets the score.
* @return the score.
*/
public int getScore() {
return score;
}
/**
* Sets the region.
*/
/*
* private void setRegion() { region = DynamicRegion.create(7754);
* registerRegion(region.getId()); } /** Teleports the player to the quiz.
*/
/*
* private void teleport() {
* player.getAppearance().setAnimations(Animation.create(2378));
* player.getAppearance().sync(); player.faceLocation(getLocation(32, 32));
* player.getProperties().setTeleportLocation(getLocation(32, 28));
* startQuiz(); } /** Sets the quiz master.
*/
/*
* private void setQuizMaster(boolean teleport) { if (quizMaster == null) {
* quizMaster = new QuizMasterNPC(2477, player.getLocation(), this, player);
* quizMaster.init(); } if (teleport) {
* quizMaster.getProperties().setTeleportLocation(getLocation(32, 32)); } }
* /** Stars the quiz.
*/
/*
* private void startQuiz() { player.getDialogueInterpreter().open(2477,
* this); player.sendMessage(
* "Answer four questions correctly in a row to be teleported back where you came from."
* ); } /** Gets the startedQuiz.
* @return The startedQuiz.
*/
public boolean isStartedQuiz() {
return startedQuiz;
}
/**
* Sets the startedQuiz.
* @param startedQuiz The startedQuiz to set.
*/
public void setStartedQuiz(boolean startedQuiz) {
this.startedQuiz = startedQuiz;
}
/**
* Gets the transformed location.
* @param xOff the xOff.
* @param yOff the yOff.
* @return the location.
*/
/*
* private Location getLocation(int xOff, int yOff) { return
* region.getBaseLocation().transform(xOff, yOff, 1); }
*/
@Override
public void register() {
PluginManager.definePlugin(new QuizMasterDialogue());
}
@Override
public Location getSpawnLocation() {
return null;
}
@Override
public void configure() {
}
}

View file

@ -0,0 +1,53 @@
package plugin.random.quizmaster;
import org.crandor.game.content.ame.AntiMacroEvent;
import org.crandor.game.content.ame.AntiMacroNPC;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.world.map.Location;
import org.crandor.game.world.repository.Repository;
/**
* Handles the quiz master npc.
* @author Vexia
*/
public final class QuizMasterNPC extends AntiMacroNPC {
/**
* Constructs a new {@code QuizMasterNPC} {@code Object}.
* @param id the id.
* @param location the location.
* @param event the event.
* @param player the player.
*/
public QuizMasterNPC(int id, Location location, AntiMacroEvent event, Player player) {
super(id, location, event, player);
}
@Override
public void handleTickActions() {
if (!getLocks().isMovementLocked()) {
if (dialoguePlayer == null || !dialoguePlayer.isActive() || !dialoguePlayer.getInterfaceManager().hasChatbox()) {
dialoguePlayer = null;
}
}
if (!player.isActive()) {
clear();
}
if (!getPulseManager().hasPulseRunning()) {
startFollowing();
}
}
@Override
public void clear() {
Repository.removeRenderableNPC(this);
Repository.getNpcs().remove(this);
getViewport().setCurrentPlane(null);
}
@Override
public int[] getIds() {
return new int[] { 2477 };
}
}

View file

@ -0,0 +1,138 @@
package plugin.random.rickturpentine;
import java.nio.ByteBuffer;
import org.crandor.game.content.ame.AntiMacroDialogue;
import org.crandor.game.content.ame.AntiMacroEvent;
import org.crandor.game.content.dialogue.DialoguePlugin;
import org.crandor.game.node.entity.npc.drop.DropFrequency;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.item.ChanceItem;
import org.crandor.game.node.item.Item;
import org.crandor.game.world.map.Location;
import org.crandor.plugin.PluginManager;
import org.crandor.plugin.InitializablePlugin;
import org.crandor.tools.RandomFunction;
/**
* Handles the rick turpentine anti macro event.
* @author Vexia
*/
@InitializablePlugin
public final class RickTurpentineEvent extends AntiMacroEvent {
/**
* The name of the event.
*/
public static final String NAME = "rick turpentine";
/**
* Constructs a new {@code RickTurpentineEvent} {@code Object}.
*/
public RickTurpentineEvent() {
super(NAME, true, false);
}
@Override
public void save(ByteBuffer buffer) {
}
@Override
public void parse(ByteBuffer buffer) {
}
@Override
public boolean start(Player player, boolean login, Object... args) {
final RickTurpentineNPC dwarf = new RickTurpentineNPC(2476, player.getLocation(), this, player);
dwarf.init();
super.init(player);
return true;
}
@Override
public AntiMacroEvent create(Player player) {
RickTurpentineEvent event = new RickTurpentineEvent();
event.player = player;
return event;
}
@Override
public void register() {
PluginManager.definePlugin(new RickTurpentineDialogue());
}
@Override
public Location getSpawnLocation() {
return null;
}
@Override
public void configure() {
}
@Override
public String getGenderPrefix(boolean male) {
return male ? "milord" : "milady";
}
/**
* Handles the rick turpnetine dialogue.
* @author Vexia
*/
public static final class RickTurpentineDialogue extends AntiMacroDialogue {
/**
* The random items recieved from rick turpnetine.
*/
private static final ChanceItem[] ITEMS = new ChanceItem[] { new ChanceItem(995, 1, 640, DropFrequency.COMMON), new ChanceItem(1969, 1, 1, DropFrequency.COMMON), new ChanceItem(1971, 1, 1, DropFrequency.COMMON), new ChanceItem(1623, 1, 1, DropFrequency.UNCOMMON), new ChanceItem(1621, 1, 1, DropFrequency.UNCOMMON), new ChanceItem(1619, 1, 1, DropFrequency.UNCOMMON), new ChanceItem(1617, 1, 1, DropFrequency.UNCOMMON), new ChanceItem(1454, 1, 1, DropFrequency.UNCOMMON), new ChanceItem(985, 1, 1, DropFrequency.RARE) };
/**
* Constructs a new {@code RickTurpentineDialogue} {@code Object}.
*/
public RickTurpentineDialogue() {
/**
* empty.
*/
}
/**
* Constructs a new {@code RickTurpentineDialogue} {@code Object}.
* @param player the player.
*/
public RickTurpentineDialogue(Player player) {
super(player);
}
@Override
public DialoguePlugin newInstance(Player player) {
return new RickTurpentineDialogue(player);
}
@Override
public boolean open(Object... args) {
if (super.open(args)) {
npc("Today is your lucky day, sirrah!", "I am donating to the victims of crime to atone for my", "past actions!");
} else {
return true;
}
return true;
}
@Override
public boolean handle(int interfaceId, int buttonId) {
final Item item = RandomFunction.getChanceItem(ITEMS).getRandomItem();
player.getInventory().add(item, player);
wave(null);
return true;
}
@Override
public int[] getIds() {
return new int[] { 2476 };
}
}
}

View file

@ -0,0 +1,74 @@
package plugin.random.rickturpentine;
import org.crandor.game.content.ame.AntiMacroEvent;
import org.crandor.game.content.ame.AntiMacroNPC;
import org.crandor.game.node.entity.Entity;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.system.task.Pulse;
import org.crandor.game.world.GameWorld;
import org.crandor.game.world.map.Location;
/**
* Handles the drunken dwarf npc.
* @author Vexia
*/
public final class RickTurpentineNPC extends AntiMacroNPC {
/**
* The quotes that the dwarf will say.
*/
private static final String[] QUOTES = new String[] { "Greetings, @gender @name!", "Your money or your life, @name!" };
/**
* Constructs a new {@code RickTurpentineNPC} {@code Object}.
* @param id the id.
* @param location the loc.
* @param event the event.
* @param player the player.
*/
public RickTurpentineNPC(int id, Location location, AntiMacroEvent event, Player player) {
super(id, location, event, player, QUOTES);
}
@Override
public void handleTickActions() {
super.handleTickActions();
if (timeUp && getDialoguePlayer() == null) {
if (!getProperties().getCombatPulse().isAttacking()) {
getProperties().getCombatPulse().attack(player);
}
}
}
@Override
public void handlePlayerLeave() {
sendChat("What a dismal little spot this is");
GameWorld.submit(new Pulse(3) {
@Override
public boolean pulse() {
clear();
return true;
}
});
}
@Override
public void handleTimeUp() {
}
@Override
public boolean isIgnoreAttackRestrictions(Entity victim) {
return true;
}
@Override
public boolean isIgnoreMultiBoundaries(Entity victim) {
return victim == player;
}
@Override
public int[] getIds() {
return new int[] { 2476 };
}
}

View file

@ -0,0 +1,81 @@
package plugin.random.rivertroll;
import java.nio.ByteBuffer;
import org.crandor.game.content.ame.AntiMacroEvent;
import org.crandor.game.content.skill.Skills;
import org.crandor.game.node.entity.player.Player;
import org.crandor.plugin.InitializablePlugin;
import org.crandor.game.world.map.Location;
/**
* Handles the zombie event.
* @author Vexia
*/
@InitializablePlugin
public final class RiverTrollEvent extends AntiMacroEvent {
/**
* Constructs a new {@code ZombieEvent} {@code Object}.
*/
public RiverTrollEvent() {
super("river troll", true, false, Skills.FISHING);
}
@Override
public void save(ByteBuffer buffer) {
}
@Override
public void parse(ByteBuffer buffer) {
}
@Override
public boolean start(Player player, boolean login, Object... args) {
final RiverTrollNPC troll = new RiverTrollNPC(getId(player), player.getLocation(), this, player);
troll.init();
super.init(player);
return true;
}
@Override
public AntiMacroEvent create(Player player) {
RiverTrollEvent event = new RiverTrollEvent();
event.player = player;
return event;
}
/**
* Gets the id of the shade.
* @param player the player.
* @return the id.
*/
private int getId(Player player) {
int level = player.getProperties().getCurrentCombatLevel();
int npcId = 396;
if (level < 11) {
npcId = 391;
} else if (level < 21) {
npcId = 392;
} else if (level < 41) {
npcId = 393;
} else if (level < 61) {
npcId = 394;
} else if (level < 91) {
npcId = 395;
}
return npcId;
}
@Override
public Location getSpawnLocation() {
return null;
}
@Override
public void configure() {
}
}

View file

@ -0,0 +1,71 @@
package plugin.random.rivertroll;
import org.crandor.cache.def.impl.NPCDefinition;
import org.crandor.game.content.ame.AntiMacroEvent;
import org.crandor.game.content.ame.AntiMacroNPC;
import org.crandor.game.node.entity.Entity;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.world.map.Location;
import org.crandor.game.world.update.flag.context.Animation;
import org.crandor.tools.RandomFunction;
/**
* Handles the river troll npc.
* @author Vexia
*/
public final class RiverTrollNPC extends AntiMacroNPC {
/**
* The river troll npc.
*/
private static final int[] IDS = new int[] { 391, 392, 393, 394, 395, 396 };
/**
* Constructs a new {@code RiverTrollNPC} {@code Object}.
* @param id the id.
* @param location the location.
* @param event the event.
* @param player the player.
* @param quotes the quotes.
*/
public RiverTrollNPC(int id, Location location, AntiMacroEvent event, Player player) {
super(id, location, event, player);
}
@Override
public void init() {
// Remove.
NPCDefinition def = NPCDefinition.forId(getId());
def.getConfigurations().put("attack_animation", new Animation(284));
def.getConfigurations().put("defence_animation", new Animation(285));
def.getConfigurations().put("death_animation", new Animation(287));
super.init();
setRespawn(false);
getProperties().getCombatPulse().attack(player);
sendChat("Fishies be mine! Leave dem fishies!");
}
@Override
public void handleTickActions() {
super.handleTickActions();
if (!getProperties().getCombatPulse().isAttacking()) {
getProperties().getCombatPulse().attack(player);
}
if (getProperties().getCombatPulse().isAttacking()) {
if (RandomFunction.random(20) < 3) {
sendChat("Fishies be mine! Leave dem fishies!");
}
}
}
@Override
public boolean isIgnoreMultiBoundaries(Entity victim) {
return victim == player;
}
@Override
public int[] getIds() {
return IDS;
}
}

View file

@ -0,0 +1,81 @@
package plugin.random.shade;
import java.nio.ByteBuffer;
import org.crandor.game.content.ame.AntiMacroEvent;
import org.crandor.game.content.skill.Skills;
import org.crandor.game.node.entity.player.Player;
import org.crandor.plugin.InitializablePlugin;
import org.crandor.game.world.map.Location;
/**
* Handles the shade event.
* @author Vexia
*/
@InitializablePlugin
public final class ShadeEvent extends AntiMacroEvent {
/**
* Constructs a new {@code ShadeEvent} {@code Object}.
*/
public ShadeEvent() {
super("shade", true, false, Skills.PRAYER);
}
@Override
public void save(ByteBuffer buffer) {
}
@Override
public void parse(ByteBuffer buffer) {
}
@Override
public boolean start(Player player, boolean login, Object... args) {
final ShadeNPC shade = new ShadeNPC(getId(player), player.getLocation(), this, player);
shade.init();
super.init(player);
return true;
}
@Override
public AntiMacroEvent create(Player player) {
ShadeEvent event = new ShadeEvent();
event.player = player;
return event;
}
/**
* Gets the id of the shade.
* @param player the player.
* @return the id.
*/
private int getId(Player player) {
int level = player.getProperties().getCurrentCombatLevel();
int npcId = 430;
if (level < 11) {
npcId = 425;
} else if (level < 21) {
npcId = 426;
} else if (level < 41) {
npcId = 427;
} else if (level < 61) {
npcId = 428;
} else if (level < 91) {
npcId = 429;
}
return npcId;
}
@Override
public Location getSpawnLocation() {
return null;
}
@Override
public void configure() {
}
}

View file

@ -0,0 +1,57 @@
package plugin.random.shade;
import org.crandor.game.content.ame.AntiMacroEvent;
import org.crandor.game.content.ame.AntiMacroNPC;
import org.crandor.game.node.entity.Entity;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.world.map.Location;
/**
* Handles the shade npc.
* @author Vexia
*/
public final class ShadeNPC extends AntiMacroNPC {
/**
* The shade npc ids.
*/
private static final int[] IDS = new int[] { 425, 426, 427, 428, 429, 430 };
/**
* Constructs a new {@code ShadeNPC} {@code Object}.
* @param id the id.
* @param location the location.
* @param event the event.
* @param player the player.
* @param quotes the quotes.
*/
public ShadeNPC(int id, Location location, AntiMacroEvent event, Player player) {
super(id, location, event, player);
}
@Override
public void init() {
super.init();
setRespawn(false);
getProperties().getCombatPulse().attack(player);
}
@Override
public void handleTickActions() {
super.handleTickActions();
if (!getProperties().getCombatPulse().isAttacking()) {
getProperties().getCombatPulse().attack(player);
}
}
@Override
public boolean isIgnoreMultiBoundaries(Entity victim) {
return victim == player;
}
@Override
public int[] getIds() {
return IDS;
}
}

View file

@ -0,0 +1,81 @@
package plugin.random.treespirit;
import java.nio.ByteBuffer;
import org.crandor.game.content.ame.AntiMacroEvent;
import org.crandor.game.content.skill.Skills;
import org.crandor.game.node.entity.player.Player;
import org.crandor.plugin.InitializablePlugin;
import org.crandor.game.world.map.Location;
/**
* Handles the Tree Spirit event whilst cutting trees.
* @author Splinter
*/
@InitializablePlugin
public final class TreeSpiritEvent extends AntiMacroEvent {
/**
* Constructs a new {@code TreeSpiritEvent} {@code Object}.
*/
public TreeSpiritEvent() {
super("tree spirit", true, false, Skills.WOODCUTTING);
}
@Override
public void save(ByteBuffer buffer) {
}
@Override
public void parse(ByteBuffer buffer) {
}
@Override
public boolean start(Player player, boolean login, Object... args) {
final TreeSpiritRandomNPC spirit = new TreeSpiritRandomNPC(getId(player), player.getLocation(), this, player);
spirit.init();
super.init(player);
return true;
}
@Override
public AntiMacroEvent create(Player player) {
TreeSpiritEvent event = new TreeSpiritEvent();
event.player = player;
return event;
}
/**
* Gets the id of the spirit.
* @param player the player.
* @return the id.
*/
private int getId(Player player) {
int level = player.getProperties().getCurrentCombatLevel();
int npcId = 443;
if (level < 11) {
npcId = 438;
} else if (level < 21) {
npcId = 439;
} else if (level < 41) {
npcId = 440;
} else if (level < 61) {
npcId = 441;
} else if (level < 91) {
npcId = 442;
}
return npcId;
}
@Override
public Location getSpawnLocation() {
return null;
}
@Override
public void configure() {
}
}

View file

@ -0,0 +1,70 @@
package plugin.random.treespirit;
import org.crandor.cache.def.impl.NPCDefinition;
import org.crandor.game.content.ame.AntiMacroEvent;
import org.crandor.game.content.ame.AntiMacroNPC;
import org.crandor.game.node.entity.Entity;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.world.map.Location;
import org.crandor.game.world.update.flag.context.Animation;
import org.crandor.tools.RandomFunction;
/**
* Handles the Tree Spirit NPCs
* @author Splinter
*/
public final class TreeSpiritRandomNPC extends AntiMacroNPC {
/**
* The tree spirit npc ids.
*/
private static final int[] IDS = new int[] { 438, 439, 440, 441, 442, 443 };
/**
* Constructs a new {@code TreeSpiritRandomNPC} {@code Object}.
* @param id the id.
* @param location the location.
* @param event the event.
* @param player the player.
* @param quotes the quotes.
*/
public TreeSpiritRandomNPC(int id, Location location, AntiMacroEvent event, Player player) {
super(id, location, event, player);
}
@Override
public void init() {
NPCDefinition def = NPCDefinition.forId(getId());
def.getConfigurations().put("attack_animation", new Animation(94));
def.getConfigurations().put("defence_animation", new Animation(95));
def.getConfigurations().put("death_animation", new Animation(96));
super.init();
setRespawn(false);
getProperties().getCombatPulse().attack(player);
sendChat("Leave these woods and never return!");
}
@Override
public void handleTickActions() {
super.handleTickActions();
if (!getProperties().getCombatPulse().isAttacking()) {
getProperties().getCombatPulse().attack(player);
}
if (getProperties().getCombatPulse().isAttacking()) {
if (RandomFunction.random(40) < 2) {
sendChat("Leave these woods and never return!");
}
}
}
@Override
public boolean isIgnoreMultiBoundaries(Entity victim) {
return victim == player;
}
@Override
public int[] getIds() {
return IDS;
}
}

View file

@ -0,0 +1,64 @@
package plugin.random.zombie;
import org.crandor.game.content.ame.AntiMacroEvent;
import org.crandor.game.content.ame.AntiMacroNPC;
import org.crandor.game.node.entity.Entity;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.world.map.Location;
import org.crandor.tools.RandomFunction;
/**
* Handles the zombie npc.
* @author Vexia
*/
public final class ZombieAmeNPC extends AntiMacroNPC {
/**
* The zombie npc.
*/
private static final int[] IDS = new int[] { 419, 420, 421, 422, 423, 424 };
/**
* Constructs a new {@code ZombieNPC} {@code Object}.
* @param id the id.
* @param location the location.
* @param event the event.
* @param player the player.
* @param quotes the quotes.
*/
public ZombieAmeNPC(int id, Location location, AntiMacroEvent event, Player player) {
super(id, location, event, player);
}
@Override
public void init() {
super.init();
setRespawn(false);
getProperties().getCombatPulse().attack(player);
sendChat("Braaiinnzzzzzzzzzz");
}
@Override
public void handleTickActions() {
super.handleTickActions();
if (!getProperties().getCombatPulse().isAttacking()) {
getProperties().getCombatPulse().attack(player);
}
if (getProperties().getCombatPulse().isAttacking()) {
if (RandomFunction.random(20) < 3) {
sendChat("Braaiinnzzzzzzzzzz");
}
}
}
@Override
public boolean isIgnoreMultiBoundaries(Entity victim) {
return victim == player;
}
@Override
public int[] getIds() {
return IDS;
}
}

View file

@ -0,0 +1,81 @@
package plugin.random.zombie;
import java.nio.ByteBuffer;
import org.crandor.game.content.ame.AntiMacroEvent;
import org.crandor.game.content.skill.Skills;
import org.crandor.game.node.entity.player.Player;
import org.crandor.plugin.InitializablePlugin;
import org.crandor.game.world.map.Location;
/**
* Handles the zombie event.
* @author Vexia
*/
@InitializablePlugin
public final class ZombieEvent extends AntiMacroEvent {
/**
* Constructs a new {@code ZombieEvent} {@code Object}.
*/
public ZombieEvent() {
super("zombie", true, false, Skills.PRAYER);
}
@Override
public void save(ByteBuffer buffer) {
}
@Override
public void parse(ByteBuffer buffer) {
}
@Override
public boolean start(Player player, boolean login, Object... args) {
final ZombieAmeNPC zombie = new ZombieAmeNPC(getId(player), player.getLocation(), this, player);
zombie.init();
super.init(player);
return true;
}
@Override
public AntiMacroEvent create(Player player) {
ZombieEvent event = new ZombieEvent();
event.player = player;
return event;
}
/**
* Gets the id of the shade.
* @param player the player.
* @return the id.
*/
private int getId(Player player) {
int level = player.getProperties().getCurrentCombatLevel();
int npcId = 424;
if (level < 11) {
npcId = 419;
} else if (level < 21) {
npcId = 420;
} else if (level < 41) {
npcId = 421;
} else if (level < 61) {
npcId = 422;
} else if (level < 91) {
npcId = 423;
}
return npcId;
}
@Override
public Location getSpawnLocation() {
return null;
}
@Override
public void configure() {
}
}