-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added F (fortune) trigger; resolves #105
- Loading branch information
1 parent
cd0fe34
commit 2389d54
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
src/main/java/io/github/dre2n/dungeonsxl/trigger/FortuneTrigger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters