Jump to content
Existing user? Sign In

Sign In



Sign Up

[Ruse] Genie Random


Flub

Recommended Posts

Hey guys, whipped this up quickly. Make sure to add my previous snippets too.

Genie.java

package com.janus.world.content.randomevents;

import com.janus.engine.task.Task;
import com.janus.engine.task.TaskManager;
import com.janus.model.Animation;
import com.janus.model.Graphic;
import com.janus.model.Item;
import com.janus.model.container.impl.Inventory;
import com.janus.world.World;
import com.janus.world.entity.impl.npc.NPC;
import com.janus.world.entity.impl.player.Player;
import lombok.Getter;
import lombok.Setter;

public class Genie {

    @Getter
    @Setter
    private Player spawnedFor;
    @Getter
    @Setter
    private boolean claimed;

    public Genie(Player spawnedFor, boolean claimed) {
        this.spawnedFor = spawnedFor;
        this.claimed = claimed;
    }

    public static final int genieID = 409;

    private static final int lampID = 18782;

    private static final Item reward = new Item(lampID, 1);

    private static final Animation wave = new Animation(863);

    private static final Graphic smoke = new Graphic(188);

    public static void spawn(Player player) {
        String userName = player.getUsername();
        Genie genie = player.getGenie();
        genie.setClaimed(false);
        NPC genieNpc = new NPC(409, player.getPosition());
        genieNpc.setSpawnedFor(player);
        World.register(genieNpc);
        genieNpc.setResetMovementQueue(true);
        genieNpc.performGraphic(smoke);
        genieNpc.getMovementQueue().setFollowCharacter(player);
        genieNpc.performAnimation(wave);
        genieNpc.forceChat(userName + " I have a reward for you!");

        TaskManager.submit(new Task(60, false) {
            @Override
            protected void execute() {
                despawn(genieNpc);
            }
        });
    }

    public static void handleInteraction(NPC genieNpc, Player player, int click) {
        String userName = player.getUsername();
        Inventory invent = player.getInventory();
        boolean freeSlot = invent.getFreeSlots() >= 1;
        Genie playerGenie = player.getGenie();

        if (genieNpc.getSpawnedFor() == player
                && !player.getGenie().isClaimed()
                && playerGenie.getSpawnedFor() == player) {

            if (!freeSlot) {
                genieNpc.forceChat("You need to have at least one inventory slot free!");
                return;
            }

            switch (click) {
                case 1:
                    invent.add(reward);
                    playerGenie.setClaimed(true);
                    genieNpc.forceChat("Enjoy your reward " + userName + "!");
                    break;
                case 2:
                    player.getPacketSender().sendMessage("You dismiss the Genie!");
                    genieNpc.forceChat("Okay, bye for now " + userName + "!");
                    break;
            }
            despawn(genieNpc);
        } else if (playerGenie.isClaimed()){
            player.getPacketSender().sendMessage("You've already claimed your reward!");
        } else {
            player.getPacketSender().sendMessage("This Genie isn't here for you!");
        }
    }

    public static void despawn(NPC genieNpc) {
        if (genieNpc != null) {
            genieNpc.performAnimation(wave);
            genieNpc.performGraphic(smoke);

            TaskManager.submit(new Task(2, false) {
                @Override
                protected void execute() {
                    World.deregister(genieNpc);
                }
            });
        }
    }
}

Player.java

@Getter
    @Setter
    private Genie genie = new Genie(this, false);

NPCOptionPacketListener.java

First Click:

case Genie.genieID:
	Genie.handleInteraction(npc, player, 1);
break;

Second Click:

case Genie.genieID:
	Genie.handleInteraction(npc, player, 2);
break;

SkillManager.java

Anywhere in the addExperience method:

if (Misc.percentageChance(10.0)) { //Change the value. This is a 10% change of a spawn - Way too high.
	Genie.spawn(player);
}

 

Link to comment
Share on other sites

  • 4 weeks later...
  • 2 months later...
  • 2 weeks later...
  • 2 months later...
  • 1 month later...
  • 4 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Contact

[email protected]

astra.security

What is a RSPS?

A RSPS, also known as RuneScape private server, is an online game based on RuneScape, and controlled by independent individuals.

Popular RSPS Servers

Runewild Ikov RedemptionRSPS

Disclaimer

Runesuite is not affiliated with runescape, jagex in any way & exists solely for educational purposes.

×
×
  • Create New...