Skip to content

Commit

Permalink
added catch percent settings to fishing. /npc fish --percent # or - f…
Browse files Browse the repository at this point in the history
…ish catchpercent:#
  • Loading branch information
Jeebiss committed Apr 29, 2013
1 parent 71d4319 commit 6577767
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/main/java/net/aufdemrand/denizen/CommandHandler.java
Expand Up @@ -501,6 +501,10 @@ public void startFishing(CommandContext args, CommandSender sender, NPC npc) thr
trait.setCatchFish(true);
}

if (args.hasValueFlag("percent")) {
trait.setCatchPercent(args.getFlagInteger("percent"));
}

if (args.hasValueFlag("location")) {
String[] argsArray = args.getFlag("location").split(",");
if (argsArray.length != 4) {
Expand Down
Expand Up @@ -39,6 +39,10 @@ public class FishingTrait extends Trait {
Location fishingSpot = null;
EntityFishingHook fishHook = null;
EntityItem fish = null;

@Persist("catch chance")
int catchPercent = 65;

int reelCount = 100;
int castCount = 0;

Expand Down Expand Up @@ -165,7 +169,7 @@ private void reel() {
fishHook.getBukkitEntity().remove();
} catch(Exception e){ }

if (chance>65 && fishHook != null && catchFish) {
if (chance>catchPercent && fishHook != null && catchFish) {
try{
fish.getBukkitEntity().remove();
} catch(Exception e) { }
Expand Down Expand Up @@ -241,6 +245,10 @@ public static Vector normalizeVector(Vector victor){

public void setCatchFish(Boolean catchFish) {
this.catchFish = catchFish;
}

public void setCatchPercent(int catchPercent) {
this.catchPercent = catchPercent;
}

}
Expand Up @@ -116,7 +116,7 @@ public void registerCoreMembers() {
"FINISH", "finish (script:name{attached script}) (player:player_name)", 0);

registerCoreMember(FishCommand.class,
"FISH", "fish (catchfish) (stop) (location:x,y,z,world)", 1);
"FISH", "fish (catchfish) (stop) (location:x,y,z,world) (catchpercent:#{65})", 1);

registerCoreMember(FlagCommand.class,
"FLAG", "flag ({player}|npc|global) [name([#])](:action)[:value] (duration:#)", 1);
Expand Down
Expand Up @@ -6,6 +6,7 @@
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.utilities.arguments.aH;
import net.aufdemrand.denizen.utilities.arguments.aH.ArgumentType;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;
import net.citizensnpcs.api.npc.NPC;
Expand All @@ -20,6 +21,7 @@ public void parseArgs(ScriptEntry scriptEntry)
Location location = null;
Boolean stopping = false;
Boolean catchFish = false;
int catchPercent = 65;

for (String arg : scriptEntry.getArguments()) {
if (aH.matchesLocation(arg)) {
Expand All @@ -33,19 +35,25 @@ public void parseArgs(ScriptEntry scriptEntry)
stopping = true;
dB.echoDebug("...stopping");
continue;
} else if (aH.matchesValueArg("CATCHPERCENT, PERCENT", arg, ArgumentType.Integer)) {
catchPercent = aH.getIntegerFrom(arg);
dB.echoDebug("...set catch percent: " + catchPercent);
} else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg);

}

scriptEntry.addObject("location", location)
.addObject("stopping", stopping)
.addObject("catchFish", catchFish);
.addObject("catchFish", catchFish)
.addObject("catchPercent", catchPercent);
}

@Override
public void execute(ScriptEntry scriptEntry)
throws CommandExecutionException {
Boolean stopping = (Boolean) scriptEntry.getObject("stopping");
Boolean catchFish = (Boolean) scriptEntry.getObject("catchFish");
int catchPercent = (Integer) scriptEntry.getObject("catchPercent");
NPC npc = scriptEntry.getNPC().getCitizen();
FishingTrait trait = new FishingTrait();

Expand All @@ -64,9 +72,9 @@ public void execute(ScriptEntry scriptEntry)
}

trait.startFishing(location);
if (catchFish) {
trait.setCatchFish(true);
}
trait.setCatchPercent(catchPercent);
if (catchFish) trait.setCatchFish(true);

return;

}
Expand Down

0 comments on commit 6577767

Please sign in to comment.