Jobs minigame

Core implemented, all that needs to be done now is the rest of the NPCs table base and thats all.

Also will most likely merge all gathering tasks into one class, as they are the same for all NPCs and will have a seperate slaying one, to be done later though.
This commit is contained in:
jamix77 2020-03-11 13:45:14 +00:00
parent 4fb3a19177
commit b7043e3b0b
8 changed files with 396 additions and 5 deletions

View file

@ -0,0 +1,56 @@
/**
*
*/
package org.crandor.game.content.global.jobs;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.item.Item;
/**
* Represents a gathering job, eg fishing woodcutting and such.
* @author jamix77
*
*/
public class GatheringJob extends Job {
private int itemId;
private int amount;
/**
* Constructs a new @{Code GatheringJob} object.
*/
public GatheringJob(int employer, Player player,int amount, int itemId) {
super(employer,player);
this.itemId = itemId;
this.setAmount(amount);
}
@Override
public
boolean reward() {
if (getPlayer().getInventory().getAmount(itemId) >= getAmount()) {
getPlayer().getInventory().remove(new Item(itemId,getAmount()));
setAmount(0);
return true;
} else {
setAmount(getAmount() - getPlayer().getInventory().getAmount(itemId));
getPlayer().getInventory().remove(new Item(itemId,getPlayer().getInventory().getAmount(itemId)));
getPlayer().sendMessage("You have " + getAmount() + " left to get.");
}
return false;
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
public int getItemId() {
return itemId;
}
}

View file

@ -0,0 +1,41 @@
package org.crandor.game.content.global.jobs;
import org.crandor.game.node.entity.player.Player;
/**
* Represents the job of a player
* @author jamix77
*
*/
public abstract class Job {
private final int employer;
private final Player player;
/**
* Constructs a new @{Code Job} object.
* @param employer
*/
protected Job(int employer, Player player) {
this.employer = employer;
this.player = player;
}
/**
* The reward for the player after the player has completed their job.
*/
public abstract boolean reward();
/**
* The employer of the job.
* @return
*/
public int getEmployer() {
return employer;
}
public Player getPlayer() {
return player;
}
}

View file

@ -0,0 +1,14 @@
package org.crandor.game.content.global.jobs;
/**
*
* @author jamix77
*
*/
public enum JobType {
GATHERING,
BONE_BURYING,
KILLING;
}

View file

@ -0,0 +1,63 @@
package org.crandor.game.content.global.jobs;
import java.nio.ByteBuffer;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.entity.player.info.login.SavingModule;
/**
* Handles the jobs of a player
* @author jamix77
*/
public final class JobsMinigameManager implements SavingModule {
/**
* The current job of the player.
*/
private Job job;
/**
* The player.
*/
private final Player player;
/**
* Constructs a new {@Code TreasureTrailManager} {@Code
* Object}
* @param player the player.
*/
public JobsMinigameManager(Player player) {
this.player = player;
}
@Override
public void save(ByteBuffer buffer) {
}
@Override
public void parse(ByteBuffer buffer) {
}
/**
* Gets the player.
* @return the player
*/
public Player getPlayer() {
return player;
}
public Job getJob() {
return job;
}
public void setJob(Job job) {
this.job = job;
}
public static final int WILFRED_ID = 4906;
}

View file

@ -0,0 +1,63 @@
package org.crandor.game.content.global.jobs.impl;
import org.crandor.game.content.global.jobs.JobType;
import org.crandor.game.content.skill.Skills;
import org.crandor.tools.RandomFunction;
/**
* Represents the jobs that Mikasi can give.
* @author jamix77
*
*/
public enum MikasiJobs {
LOG(20,28, 1, 1511,JobType.GATHERING, Skills.WOODCUTTING),
COWHIDES(20,28,1, 1739,JobType.GATHERING,0),
OAK(22,28,15, 1521,JobType.GATHERING,Skills.WOODCUTTING),
WATER_RUNE(20,28,5, 555,JobType.GATHERING,Skills.RUNECRAFTING),
EARTH_RUNE(20,28,9, 557,JobType.GATHERING,Skills.RUNECRAFTING),
FIRE_RUNE(20,28,14, 554,JobType.GATHERING,Skills.RUNECRAFTING),
AIR_RUNE(20,28,1, 556,JobType.GATHERING,Skills.RUNECRAFTING),
RUNE_ESS(20,28,1, 1436,JobType.GATHERING,Skills.MINING),
BALL_OF_WOOL(20,28,1, 1759,JobType.GATHERING,Skills.CRAFTING),
LEATHER_GLOVE(20,28,1, 1059,JobType.GATHERING,Skills.CRAFTING),
WILLOW(22,28,30, 1519,JobType.GATHERING,Skills.WOODCUTTING),
LEATHER_BOOT(24,24,1, 1061,JobType.GATHERING,Skills.CRAFTING);
private final int id;
private final int upperBound;
private final int lowerBound;
private final int lvlReq;
private final JobType jobType;
private final int skillId;
private MikasiJobs(int lowerBound,int upperBound, int lvlReq, int id, JobType jobType, int skillId) {
this.lowerBound = lowerBound;
this.upperBound = upperBound;
this.id = id;
this.lvlReq = lvlReq;
this.jobType = jobType;
this.skillId = skillId;
}
public int getLvlReq() {
return lvlReq;
}
public int getid() {
return id;
}
public int getAmount() {
return RandomFunction.random(lowerBound, upperBound);
}
public JobType getJobType() {
return jobType;
}
public int getSkillId() {
return skillId;
}
}

View file

@ -0,0 +1,54 @@
package org.crandor.game.content.global.jobs.impl;
import org.crandor.game.content.global.jobs.JobType;
import org.crandor.game.content.skill.Skills;
import org.crandor.tools.RandomFunction;
/**
* Represents the jobs that Wilfred can give.
* @author jamix77
*
*/
public enum WilfredJobs {
LOG(22,28, 1, 1511,JobType.GATHERING, Skills.WOODCUTTING),
OAK(22,28,15, 1521,JobType.GATHERING,Skills.WOODCUTTING),
WILLOW(22,28,30, 1519,JobType.GATHERING,Skills.WOODCUTTING);
private final int itemId;
private final int upperBound;
private final int lowerBound;
private final int lvlReq;
private final JobType jobType;
private final int skillId;
private WilfredJobs(int lowerBound,int upperBound, int lvlReq, int itemId, JobType jobType, int skillId) {
this.lowerBound = lowerBound;
this.upperBound = upperBound;
this.itemId = itemId;
this.lvlReq = lvlReq;
this.jobType = jobType;
this.skillId = skillId;
}
public int getLvlReq() {
return lvlReq;
}
public int getItemId() {
return itemId;
}
public int getAmount() {
return RandomFunction.random(lowerBound, upperBound);
}
public JobType getJobType() {
return jobType;
}
public int getSkillId() {
return skillId;
}
}

View file

@ -1,5 +1,8 @@
package org.crandor.game.node.entity.player;
import java.util.ArrayList;
import java.util.List;
import org.crandor.ServerConstants;
import org.crandor.game.component.Component;
import org.crandor.game.container.Container;
@ -9,6 +12,7 @@ import org.crandor.game.container.impl.InventoryListener;
import org.crandor.game.content.ame.AntiMacroHandler;
import org.crandor.game.content.dialogue.DialogueInterpreter;
import org.crandor.game.content.eco.ge.GrandExchange;
import org.crandor.game.content.global.jobs.JobsMinigameManager;
import org.crandor.game.content.global.ttrail.TreasureTrailManager;
import org.crandor.game.content.skill.Skills;
import org.crandor.game.content.skill.member.construction.HouseManager;
@ -36,7 +40,20 @@ import org.crandor.game.node.entity.player.info.UIDInfo;
import org.crandor.game.node.entity.player.info.login.LoginConfiguration;
import org.crandor.game.node.entity.player.info.portal.DonatorType;
import org.crandor.game.node.entity.player.info.portal.Perks;
import org.crandor.game.node.entity.player.link.*;
import org.crandor.game.node.entity.player.link.BankPinManager;
import org.crandor.game.node.entity.player.link.BarcrawlManager;
import org.crandor.game.node.entity.player.link.ConfigurationManager;
import org.crandor.game.node.entity.player.link.GlobalData;
import org.crandor.game.node.entity.player.link.HintIconManager;
import org.crandor.game.node.entity.player.link.InterfaceManager;
import org.crandor.game.node.entity.player.link.IronmanManager;
import org.crandor.game.node.entity.player.link.IronmanMode;
import org.crandor.game.node.entity.player.link.PacketDispatch;
import org.crandor.game.node.entity.player.link.SavedData;
import org.crandor.game.node.entity.player.link.Settings;
import org.crandor.game.node.entity.player.link.SkullManager;
import org.crandor.game.node.entity.player.link.SpellBookManager;
import org.crandor.game.node.entity.player.link.WarningMessages;
import org.crandor.game.node.entity.player.link.appearance.Appearance;
import org.crandor.game.node.entity.player.link.audio.AudioManager;
import org.crandor.game.node.entity.player.link.diary.AchievementDiaryManager;
@ -55,7 +72,12 @@ import org.crandor.game.system.communication.CommunicationInfo;
import org.crandor.game.system.monitor.PlayerMonitor;
import org.crandor.game.system.task.LogoutTask;
import org.crandor.game.world.GameWorld;
import org.crandor.game.world.map.*;
import org.crandor.game.world.map.Direction;
import org.crandor.game.world.map.Location;
import org.crandor.game.world.map.Region;
import org.crandor.game.world.map.RegionChunk;
import org.crandor.game.world.map.RegionManager;
import org.crandor.game.world.map.Viewport;
import org.crandor.game.world.map.build.DynamicRegion;
import org.crandor.game.world.map.zone.ZoneType;
import org.crandor.game.world.repository.Repository;
@ -78,9 +100,6 @@ import org.crandor.net.packet.out.UpdateSceneGraph;
import org.crandor.plugin.Plugin;
import org.crandor.tools.StringUtils;
import java.util.ArrayList;
import java.util.List;
/**
* Represents a player entity.
* @author Emperor
@ -272,6 +291,11 @@ public class Player extends Entity {
* The Ironman manager.
*/
private final IronmanManager ironmanManager = new IronmanManager(this);
/**
* The jobs minigame manager.
*/
private final JobsMinigameManager jobsManager = new JobsMinigameManager(this);
/**
* The logout plugins.
@ -1304,4 +1328,8 @@ public class Player extends Entity {
public void setArcheryTotal(int archeryTotal) {
this.archeryTotal = archeryTotal;
}
public JobsMinigameManager getJobsManager() {
return jobsManager;
}
}

View file

@ -0,0 +1,72 @@
package plugin.activity.jobs;
import org.crandor.cache.def.impl.NPCDefinition;
import org.crandor.game.content.global.jobs.GatheringJob;
import org.crandor.game.content.global.jobs.JobType;
import org.crandor.game.content.global.jobs.impl.MikasiJobs;
import org.crandor.game.content.global.jobs.impl.WilfredJobs;
import org.crandor.game.interaction.OptionHandler;
import org.crandor.game.node.Node;
import org.crandor.game.node.entity.npc.NPC;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.item.Item;
import org.crandor.plugin.InitializablePlugin;
import org.crandor.plugin.Plugin;
import org.crandor.tools.RandomFunction;
/**
* Handles the work-for actions for the NPCs
* @author ceik
*/
@InitializablePlugin
public final class WorkForOptionHandler extends OptionHandler {
@Override
public Plugin<Object> newInstance(Object arg) throws Throwable {
NPCDefinition.forId(4906).getConfigurations().put("option:work-for",this);
return this;
}
@Override
public boolean handle(Player player, Node node, String option) {
if (player.getJobsManager().getJob() != null) {
if (player.getJobsManager().getJob().reward()) {
player.sendMessage("You completed the job");
player.getJobsManager().setJob(null);
return true;
}
} else {
switch (((NPC)node).getId()) {
case 4906://wilfred, woodcutting
while (true) {
int gen = RandomFunction.random(0, WilfredJobs.values().length -1);
if (WilfredJobs.values()[gen].getLvlReq() <= player.getSkills().getLevel(player.getSkills().WOODCUTTING)) {
if (WilfredJobs.values()[gen].getJobType() == JobType.GATHERING) {
player.getJobsManager().setJob(new GatheringJob( ((NPC)node).getId(), player, WilfredJobs.values()[gen].getAmount(), WilfredJobs.values()[gen].getItemId()));
}
break;
}
}
break;
case 4707:
while (true) {
int gen = RandomFunction.random(0, MikasiJobs.values().length -1);
if (WilfredJobs.values()[gen].getLvlReq() <= player.getSkills().getLevel(player.getSkills().WOODCUTTING)) {
player.getJobsManager().setJob(new GatheringJob( ((NPC)node).getId(), player, WilfredJobs.values()[gen].getAmount(), WilfredJobs.values()[gen].getItemId()));
break;
}
}
break;
}
if (player.getJobsManager().getJob() instanceof GatheringJob) {
player.getDialogueInterpreter().sendItemMessage(((GatheringJob)player.getJobsManager().getJob()).getItemId(), "Gather " + ((GatheringJob)player.getJobsManager().getJob()).getAmount() + " " + new Item(((GatheringJob)player.getJobsManager().getJob()).getItemId()).getName() + " for " + ((NPC)node).getName() );
}
}
return true;
}
}