Skip to content

Commit b4b8f60

Browse files
Merge pull request #9 from AzisabaNetwork/issues-8
Issues 8 - コマンドによって報酬を配布する際、確率を指定して抽選を行えるようにする
2 parents 6b4e8cf + 67e6abb commit b4b8f60

File tree

18 files changed

+488
-178
lines changed

18 files changed

+488
-178
lines changed

multiserverreward/pom.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.aburaagetarou</groupId>
88
<artifactId>MultiServerReward</artifactId>
9-
<version>1.0.2</version>
9+
<version>1.1.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>MultiServerReward</name>
@@ -25,6 +25,9 @@
2525
<configuration>
2626
<source>${java.version}</source>
2727
<target>${java.version}</target>
28+
<compilerArgs>
29+
<arg>-parameters</arg>
30+
</compilerArgs>
2831
</configuration>
2932
</plugin>
3033
<plugin>

multiserverreward/src/main/java/com/github/aburaagetarou/command/MSRCommand.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package com.github.aburaagetarou.command;
22

3+
import java.security.SecureRandom;
34
import java.util.ArrayList;
45
import java.util.List;
56
import java.util.Map;
7+
import java.util.Random;
68

79
import org.bukkit.command.CommandSender;
810
import org.bukkit.entity.Player;
911
import org.bukkit.plugin.Plugin;
1012

13+
import com.github.aburaagetarou.MultiServerReward;
1114
import com.github.aburaagetarou.config.ConfigManager;
1215
import com.github.aburaagetarou.config.MSRConfig;
1316
import com.github.aburaagetarou.reward.config.category.killstreak.KillStreakLevelReward;
@@ -17,6 +20,7 @@
1720
import com.github.aburaagetarou.reward.config.category.match.MatchWinReward;
1821
import com.github.aburaagetarou.reward.config.type.IReward;
1922
import com.github.aburaagetarou.reward.config.type.RewardCommand;
23+
import com.github.aburaagetarou.reward.config.universal.UniversalRewardManager;
2024
import com.github.aburaagetarou.reward.manage.RewardManager;
2125
import com.github.aburaagetarou.util.MessageUtils;
2226

@@ -27,8 +31,10 @@
2731
import co.aikar.commands.annotation.Default;
2832
import co.aikar.commands.annotation.Dependency;
2933
import co.aikar.commands.annotation.Description;
34+
import co.aikar.commands.annotation.Flags;
3035
import co.aikar.commands.annotation.HelpCommand;
3136
import co.aikar.commands.annotation.Subcommand;
37+
import co.aikar.commands.bukkit.contexts.OnlinePlayer;
3238

3339
@CommandAlias("msr")
3440
@Description("MultiServerRewardのコマンド")
@@ -225,6 +231,65 @@ public void onMatchLose(Player player) {
225231
}
226232
}
227233

234+
@Subcommand("give")
235+
@CommandPermission("msr.give")
236+
@Description("指定テーブルの汎用報酬を配布します")
237+
public void onGive(Player player, String key, @Flags("target") OnlinePlayer target, @Default("100") double argChance, @Default("true") boolean isOverLottery) {
238+
239+
// 登録されていないテーブルの場合は警告
240+
if(!UniversalRewardManager.exists(key)) {
241+
MultiServerReward.getInstance().getLogger().warning("コマンドで未定義の報酬テーブル[" + key + "]が指定されました。");
242+
return;
243+
}
244+
245+
// 報酬を取得
246+
List<IReward> rewards = UniversalRewardManager.getReward(key).getRewards();
247+
248+
// 抽選
249+
Random lottery = new SecureRandom();
250+
double chance = (!isOverLottery ? Math.min(argChance, 100.0d) : argChance);
251+
while(chance > 0.0d) {
252+
double random = lottery.nextDouble() * 100.0d;
253+
if(random <= chance) {
254+
RewardManager.getManager(target.player).addRewards(rewards);
255+
}
256+
chance -= 100.0d;
257+
}
258+
}
259+
260+
@Subcommand("debug")
261+
@CommandPermission("msr.debug")
262+
@Description("開発者向け機能")
263+
public class Debug extends BaseCommand {
264+
265+
@Subcommand("give")
266+
@CommandPermission("msr.debug.give")
267+
@Description("指定テーブルの汎用報酬を配布します")
268+
public void onGive(Player player, String key, @Flags("target") OnlinePlayer target, @Default("100") double argChance, @Default("true") boolean isOverLottery) {
269+
270+
// 登録されていないテーブルの場合は警告
271+
if(!UniversalRewardManager.exists(key)) {
272+
MessageUtils.sendColoredMessage(player, "&c未定義の報酬テーブルです。");
273+
return;
274+
}
275+
276+
// 報酬を取得
277+
List<IReward> rewards = UniversalRewardManager.getReward(key).getRewards();
278+
279+
// 抽選
280+
Random lottery = new SecureRandom();
281+
double chance = (!isOverLottery ? Math.min(argChance, 100.0d) : argChance);
282+
while(chance > 0.0d) {
283+
double random = lottery.nextDouble() * 100.0d;
284+
MessageUtils.sendColoredMessage(player, "random: " + random + " <= chance: " + chance);
285+
if(random <= chance) {
286+
RewardManager.getManager(target.player).addRewards(rewards);
287+
}
288+
chance -= 100.0d;
289+
}
290+
}
291+
}
292+
228293
@Subcommand("reward")
229294
//@CommandPermission("msr.reward")
230295
@Description("報酬を受け取ります")

multiserverreward/src/main/java/com/github/aburaagetarou/config/ConfigManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.github.aburaagetarou.reward.config.category.match.MatchEndReward;
1414
import com.github.aburaagetarou.reward.config.category.match.MatchLoseReward;
1515
import com.github.aburaagetarou.reward.config.category.match.MatchWinReward;
16+
import com.github.aburaagetarou.reward.config.universal.UniversalRewardManager;
1617
import com.github.aburaagetarou.util.MessageUtils;
1718

1819
/**
@@ -84,6 +85,7 @@ public static void reload(boolean observe) {
8485
MatchEndReward.loadAll();
8586
MatchWinReward.loadAll();
8687
MatchLoseReward.loadAll();
88+
UniversalRewardManager.loadAll();
8789

8890
MessageUtils.broadcastColoredMessage("&a&l設定の再読み込みが完了しました。");
8991
MessageUtils.broadcastColoredMessage("&a&lご協力ありがとうございました。");

multiserverreward/src/main/java/com/github/aburaagetarou/reward/config/category/RewardUtil.java

Lines changed: 0 additions & 155 deletions
This file was deleted.

multiserverreward/src/main/java/com/github/aburaagetarou/reward/config/category/killstreak/AssistStreakLevelReward.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import com.github.aburaagetarou.MultiServerReward;
1313
import com.github.aburaagetarou.config.MSRConfig;
1414
import com.github.aburaagetarou.reward.config.category.RewardTrigger;
15-
import com.github.aburaagetarou.reward.config.category.RewardUtil;
1615
import com.github.aburaagetarou.reward.config.type.IReward;
1716

1817
/**
@@ -99,14 +98,14 @@ public static void loadAll() {
9998

10099
// 通常報酬の読み込み
101100
AssistStreakLevelReward reward = new AssistStreakLevelReward();
102-
allRewards.add(RewardUtil.loadKillStreakReward(reward, yml, null));
101+
allRewards.add(KillStreakRewardBase.loadKillStreakReward(reward, yml, null));
103102

104103
// 期間限定報酬の読み込み
105104
ConfigurationSection section = yml.getConfigurationSection("limited-time-streak");
106105
if(section != null) {
107106
for(String key : section.getKeys(false)) {
108107
reward = new AssistStreakLevelReward();
109-
allRewards.add(RewardUtil.loadKillStreakReward(reward, yml, "limited-time-streak." + key));
108+
allRewards.add(KillStreakRewardBase.loadKillStreakReward(reward, yml, "limited-time-streak." + key));
110109
}
111110
}
112111
}

multiserverreward/src/main/java/com/github/aburaagetarou/reward/config/category/killstreak/AssistStreakReward.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import com.github.aburaagetarou.MultiServerReward;
1313
import com.github.aburaagetarou.config.MSRConfig;
1414
import com.github.aburaagetarou.reward.config.category.RewardTrigger;
15-
import com.github.aburaagetarou.reward.config.category.RewardUtil;
1615
import com.github.aburaagetarou.reward.config.type.IReward;
1716

1817
/**
@@ -88,14 +87,14 @@ public static void loadAll() {
8887

8988
// 通常報酬の読み込み
9089
AssistStreakReward reward = new AssistStreakReward();
91-
allRewards.add(RewardUtil.loadKillStreakReward(reward, yml, null));
90+
allRewards.add(KillStreakRewardBase.loadKillStreakReward(reward, yml, null));
9291

9392
// 期間限定報酬の読み込み
9493
ConfigurationSection section = yml.getConfigurationSection("limited-time-streak");
9594
if(section != null) {
9695
for(String key : section.getKeys(false)) {
9796
reward = new AssistStreakReward();
98-
allRewards.add(RewardUtil.loadKillStreakReward(reward, yml, "limited-time-streak." + key));
97+
allRewards.add(KillStreakRewardBase.loadKillStreakReward(reward, yml, "limited-time-streak." + key));
9998
}
10099
}
101100
}

multiserverreward/src/main/java/com/github/aburaagetarou/reward/config/category/killstreak/KillStreakLevelReward.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import com.github.aburaagetarou.MultiServerReward;
1313
import com.github.aburaagetarou.config.MSRConfig;
1414
import com.github.aburaagetarou.reward.config.category.RewardTrigger;
15-
import com.github.aburaagetarou.reward.config.category.RewardUtil;
1615
import com.github.aburaagetarou.reward.config.type.IReward;
1716

1817
/**
@@ -99,14 +98,14 @@ public static void loadAll() {
9998

10099
// 通常報酬の読み込み
101100
KillStreakLevelReward reward = new KillStreakLevelReward();
102-
allRewards.add(RewardUtil.loadKillStreakReward(reward, yml, null));
101+
allRewards.add(KillStreakRewardBase.loadKillStreakReward(reward, yml, null));
103102

104103
// 期間限定報酬の読み込み
105104
ConfigurationSection section = yml.getConfigurationSection("limited-time-streak");
106105
if(section != null) {
107106
for(String key : section.getKeys(false)) {
108107
reward = new KillStreakLevelReward();
109-
allRewards.add(RewardUtil.loadKillStreakReward(reward, yml, "limited-time-streak." + key));
108+
allRewards.add(KillStreakRewardBase.loadKillStreakReward(reward, yml, "limited-time-streak." + key));
110109
}
111110
}
112111
}

multiserverreward/src/main/java/com/github/aburaagetarou/reward/config/category/killstreak/KillStreakReward.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import com.github.aburaagetarou.MultiServerReward;
1313
import com.github.aburaagetarou.config.MSRConfig;
1414
import com.github.aburaagetarou.reward.config.category.RewardTrigger;
15-
import com.github.aburaagetarou.reward.config.category.RewardUtil;
1615
import com.github.aburaagetarou.reward.config.type.IReward;
1716

1817
/**
@@ -88,14 +87,14 @@ public static void loadAll() {
8887

8988
// 通常報酬の読み込み
9089
KillStreakReward reward = new KillStreakReward();
91-
allRewards.add(RewardUtil.loadKillStreakReward(reward, yml, null));
90+
allRewards.add(KillStreakRewardBase.loadKillStreakReward(reward, yml, null));
9291

9392
// 期間限定報酬の読み込み
9493
ConfigurationSection section = yml.getConfigurationSection("limited-time-streak");
9594
if(section != null) {
9695
for(String key : section.getKeys(false)) {
9796
reward = new KillStreakReward();
98-
allRewards.add(RewardUtil.loadKillStreakReward(reward, yml, "limited-time-streak." + key));
97+
allRewards.add(KillStreakRewardBase.loadKillStreakReward(reward, yml, "limited-time-streak." + key));
9998
}
10099
}
101100
}

0 commit comments

Comments
 (0)