mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-25 03:55:22 +01:00
Added F (fortune) trigger; resolves #105
This commit is contained in:
parent
cd0fe34bf4
commit
2389d54490
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.trigger;
|
||||
|
||||
import io.github.dre2n.commons.util.NumberUtil;
|
||||
import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent;
|
||||
import static io.github.dre2n.dungeonsxl.trigger.Trigger.plugin;
|
||||
import io.github.dre2n.dungeonsxl.world.DGameWorld;
|
||||
|
||||
/**
|
||||
* @author Frank Baumann, Daniel Saukel
|
||||
*/
|
||||
public class FortuneTrigger extends Trigger {
|
||||
|
||||
private TriggerType type = TriggerTypeDefault.FORTUNE;
|
||||
|
||||
private double chance = 0;
|
||||
|
||||
public FortuneTrigger(double chance) {
|
||||
this.chance = chance;
|
||||
}
|
||||
|
||||
/* Getters and setters */
|
||||
public double getChance() {
|
||||
return chance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param chance
|
||||
* the chance to set
|
||||
*/
|
||||
public void setChance(double chance) {
|
||||
this.chance = chance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TriggerType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
public void onTrigger() {
|
||||
int random = NumberUtil.generateRandomInt(0, 100);
|
||||
if (chance * 100 < random) {
|
||||
return;
|
||||
}
|
||||
|
||||
TriggerActionEvent event = new TriggerActionEvent(this);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setTriggered(true);
|
||||
updateDSigns();
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
public static FortuneTrigger getOrCreate(String chance, DGameWorld gameWorld) {
|
||||
return new FortuneTrigger(NumberUtil.parseDouble(chance));
|
||||
}
|
||||
|
||||
}
|
@ -138,6 +138,12 @@ public abstract class Trigger {
|
||||
trigger = new DistanceTrigger(dSign.getSign().getLocation());
|
||||
}
|
||||
|
||||
} else if (type == TriggerTypeDefault.FORTUNE) {
|
||||
|
||||
if (value != null) {
|
||||
trigger = new FortuneTrigger(NumberUtil.parseDouble(value));
|
||||
}
|
||||
|
||||
} else if (type == TriggerTypeDefault.SIGN) {
|
||||
|
||||
if (value != null) {
|
||||
|
@ -22,6 +22,7 @@ package io.github.dre2n.dungeonsxl.trigger;
|
||||
public enum TriggerTypeDefault implements TriggerType {
|
||||
|
||||
DISTANCE("D", DistanceTrigger.class),
|
||||
FORTUNE("F", FortuneTrigger.class),
|
||||
INTERACT("I", InteractTrigger.class),
|
||||
MOB("M", MobTrigger.class),
|
||||
PROGRESS("P", ProgressTrigger.class),
|
||||
|
@ -30,6 +30,7 @@ import io.github.dre2n.dungeonsxl.sign.DSignType;
|
||||
import io.github.dre2n.dungeonsxl.sign.DSignTypeDefault;
|
||||
import io.github.dre2n.dungeonsxl.sign.MobSign;
|
||||
import io.github.dre2n.dungeonsxl.sign.StartSign;
|
||||
import io.github.dre2n.dungeonsxl.trigger.FortuneTrigger;
|
||||
import io.github.dre2n.dungeonsxl.trigger.ProgressTrigger;
|
||||
import io.github.dre2n.dungeonsxl.trigger.RedstoneTrigger;
|
||||
import io.github.dre2n.dungeonsxl.trigger.Trigger;
|
||||
@ -375,6 +376,10 @@ public class DGameWorld extends DInstanceWorld {
|
||||
((RedstoneTrigger) trigger).onTrigger();
|
||||
}
|
||||
|
||||
for (Trigger trigger : getTriggers(TriggerTypeDefault.FORTUNE)) {
|
||||
((FortuneTrigger) trigger).onTrigger();
|
||||
}
|
||||
|
||||
for (DSign dSign : dSigns) {
|
||||
if (dSign != null) {
|
||||
if (!dSign.hasTriggers()) {
|
||||
|
Loading…
Reference in New Issue
Block a user