Fix dodgy scaling

This commit is contained in:
Sam 2018-06-26 23:49:20 +01:00 committed by Alexander Meech
parent 191364e352
commit 83733c8793
9 changed files with 62 additions and 83 deletions

View File

@ -11,27 +11,25 @@ public class MissionContext<T> implements Mission<T>
private final String _name; private final String _name;
private final String _description; private final String _description;
private final GameDisplay[] _games; private final GameDisplay[] _games;
private final int _requiredProgress;
private final MissionTrackerType _trackerType; private final MissionTrackerType _trackerType;
private final T _data; private final T _data;
private final LevelReward[] _rewards; private final LevelReward[] _rewards;
private final boolean _eventMission; private final boolean _eventMission;
private final int _minWeeklyScale, _maxWeeklyScale; private final int _minX, _maxX;
private final int _minY, _maxY; private final int _minY, _maxY;
private MissionContext(int id, String name, String description, GameDisplay[] games, int requiredProgress, MissionTrackerType trackerType, T data, LevelReward[] rewards, int minWeeklyScale, int maxWeeklyScale, int minY, int maxY, boolean eventMission) private MissionContext(int id, String name, String description, GameDisplay[] games, MissionTrackerType trackerType, T data, LevelReward[] rewards, int minX, int maxX, int minY, int maxY, boolean eventMission)
{ {
_id = id; _id = id;
_name = name; _name = name;
_description = description; _description = description;
_games = games; _games = games;
_requiredProgress = requiredProgress;
_trackerType = trackerType; _trackerType = trackerType;
_data = data; _data = data;
_rewards = rewards; _rewards = rewards;
_minWeeklyScale = minWeeklyScale; _minX = minX;
_maxWeeklyScale = maxWeeklyScale; _maxX = maxX;
_minY = minY; _minY = minY;
_maxY = maxY; _maxY = maxY;
_eventMission = eventMission; _eventMission = eventMission;
@ -64,7 +62,7 @@ public class MissionContext<T> implements Mission<T>
@Override @Override
public int getRequiredProgress() public int getRequiredProgress()
{ {
return _requiredProgress; return 0;
} }
@Override @Override
@ -85,9 +83,9 @@ public class MissionContext<T> implements Mission<T>
return _rewards; return _rewards;
} }
public int getRandomWeeklyScale() public int getRandomX()
{ {
return _minWeeklyScale == _maxWeeklyScale ? _minWeeklyScale : UtilMath.rRange(_minWeeklyScale, _maxWeeklyScale); return _minX == _maxX ? _minX : UtilMath.rRange(_minX, _maxX);
} }
public int getRandomY() public int getRandomY()
@ -114,12 +112,11 @@ public class MissionContext<T> implements Mission<T>
private String _name; private String _name;
private String _description; private String _description;
private GameDisplay[] _games; private GameDisplay[] _games;
private int _requiredProgress;
private MissionTrackerType _trackerType; private MissionTrackerType _trackerType;
private T _data; private T _data;
private LevelReward[] _rewards; private LevelReward[] _rewards;
private int _minWeeklyScale, _maxWeeklyScale; private int _minX, _maxX;
private int _minY, _maxY; private int _minY, _maxY;
private boolean _eventMission; private boolean _eventMission;
@ -149,12 +146,6 @@ public class MissionContext<T> implements Mission<T>
return this; return this;
} }
public MissionBuilder<T> requiredProgress(int requiredProgress)
{
_requiredProgress = requiredProgress;
return this;
}
public MissionBuilder<T> tracker(MissionTrackerType tracker) public MissionBuilder<T> tracker(MissionTrackerType tracker)
{ {
_trackerType = tracker; _trackerType = tracker;
@ -173,10 +164,10 @@ public class MissionContext<T> implements Mission<T>
return this; return this;
} }
public MissionBuilder<T> weeklyScale(int min, int max) public MissionBuilder<T> xRange(int min, int max)
{ {
_minWeeklyScale = min; _minX = min;
_maxWeeklyScale = max; _maxX = max;
return this; return this;
} }
@ -197,7 +188,7 @@ public class MissionContext<T> implements Mission<T>
{ {
if (_eventMission) if (_eventMission)
{ {
_minWeeklyScale = _maxWeeklyScale = _minY = _maxY = 0; _minX = _maxX = _minY = _maxY = 0;
} }
if (_name == null || _name.isEmpty()) if (_name == null || _name.isEmpty())
@ -212,10 +203,6 @@ public class MissionContext<T> implements Mission<T>
{ {
_games = new GameDisplay[0]; _games = new GameDisplay[0];
} }
else if (_requiredProgress <= 0)
{
throw new IllegalStateException("The required progress must be greater than 0! Mission [" + _id + "]");
}
else if (_trackerType == null) else if (_trackerType == null)
{ {
throw new IllegalStateException("The tracker type cannot be null! Mission [" + _id + "]"); throw new IllegalStateException("The tracker type cannot be null! Mission [" + _id + "]");
@ -224,12 +211,12 @@ public class MissionContext<T> implements Mission<T>
{ {
throw new IllegalStateException("The rewards cannot be null or empty! Mission [" + _id + "]"); throw new IllegalStateException("The rewards cannot be null or empty! Mission [" + _id + "]");
} }
else if (_minWeeklyScale < 0 || _maxWeeklyScale < 0 || _minY < 0 || _maxY < 0 || _minWeeklyScale > _maxWeeklyScale || _minY > _maxY) else if (_minX < 0 || _maxX < 0 || _minY < 0 || _maxY < 0 || _minX > _maxX || _minY > _maxY)
{ {
throw new IllegalStateException("The scales or y values are invalid! Mission [" + _id + "]"); throw new IllegalStateException("The scales or y values are invalid! Mission [" + _id + "]");
} }
_manager.addMission(new MissionContext<>(_id, _name, _description, _games, _requiredProgress, _trackerType, _data, _rewards, _minWeeklyScale, _maxWeeklyScale, _minY, _maxY, _eventMission)); _manager.addMission(new MissionContext<>(_id, _name, _description, _games, _trackerType, _data, _rewards, _minX, _maxX, _minY, _maxY, _eventMission));
} }
} }
} }

View File

@ -11,35 +11,30 @@ import mineplex.core.common.util.UtilText;
public enum MissionLength public enum MissionLength
{ {
DAY("Daily", UtilText.splitLineToArray(C.cGray + "Here you will find missions that you can only participate in only for today. Each day you get a handful of brand new missions.", LineFormat.LORE), ChatColor.WHITE, 0, Calendar.DAY_OF_WEEK), DAY("Daily", UtilText.splitLineToArray(C.cGray + "Here you will find missions that you can only participate in only for today. Each day you get a handful of brand new missions.", LineFormat.LORE), ChatColor.WHITE, 0, 1, Calendar.DAY_OF_WEEK),
WEEK("Weekly", UtilText.splitLineToArray(C.cGray + "These missions wil rotate out every Monday. They will be daily missions that have an increased objective and rewards.", LineFormat.LORE), ChatColor.GREEN, 7, Calendar.WEEK_OF_YEAR) WEEK("Weekly", UtilText.splitLineToArray(C.cGray + "These missions wil rotate out every Monday. They will be daily missions that have an increased objective and rewards.", LineFormat.LORE), ChatColor.GREEN, 7, 7, Calendar.WEEK_OF_YEAR),
{ EVENT("Event", UtilText.splitLineToArray(C.cGray + "These super special missions will only show up every once in a while and come with a super special reward!", LineFormat.LORE), ChatColor.LIGHT_PURPLE, 10, 1, -1);
@Override
public <T> PlayerMission<T> createFromContext(MissionContext<T> context)
{
return new PlayerMission<>(context, context.getRandomWeeklyScale(), context.getRandomY(), 0);
}
},
EVENT("Event", UtilText.splitLineToArray(C.cGray + "These super special missions will only show up every once in a while and come with a super special reward!", LineFormat.LORE), ChatColor.LIGHT_PURPLE, 10, -1);
private final String _name; private final String _name;
private final String[] _resetInfo; private final String[] _resetInfo;
private final ChatColor _chatColour; private final ChatColor _chatColour;
private final byte _colourData; private final byte _colourData;
private final int _xScale;
private final int _calendarField; private final int _calendarField;
MissionLength(String name, String[] resetInfo, ChatColor chatColour, int colourData, int calendarField) MissionLength(String name, String[] resetInfo, ChatColor chatColour, int colourData, int xScale, int calendarField)
{ {
_name = name; _name = name;
_resetInfo = resetInfo; _resetInfo = resetInfo;
_chatColour = chatColour; _chatColour = chatColour;
_colourData = (byte) colourData; _colourData = (byte) colourData;
_xScale = xScale;
_calendarField = calendarField; _calendarField = calendarField;
} }
public <T> PlayerMission<T> createFromContext(MissionContext<T> context) public <T> PlayerMission<T> createFromContext(MissionContext<T> context)
{ {
return new PlayerMission<>(context, 1, context.getRandomY(), 0); return new PlayerMission<>(context, this, context.getRandomX(), context.getRandomY(), 0);
} }
public String getName() public String getName()
@ -62,6 +57,11 @@ public enum MissionLength
return _colourData; return _colourData;
} }
public int getxScale()
{
return _xScale;
}
public int getCalendarField() public int getCalendarField()
{ {
return _calendarField; return _calendarField;

View File

@ -141,10 +141,11 @@ public class MissionManager extends MiniDbClientPlugin<MissionClient>
} }
int progress = resultSet.getInt("progress"); int progress = resultSet.getInt("progress");
int weeklyScale = resultSet.getInt("weeklyScale"); int length = resultSet.getInt("length");
int x = resultSet.getInt("x");
int y = resultSet.getInt("y"); int y = resultSet.getInt("y");
long startTime = resultSet.getLong("startTime"); long startTime = resultSet.getLong("startTime");
PlayerMission mission = new PlayerMission<>(context, weeklyScale, y, progress); PlayerMission mission = new PlayerMission<>(context, MissionLength.values()[length], x, y, progress);
Calendar start = Calendar.getInstance(utc); Calendar start = Calendar.getInstance(utc);
start.setTimeInMillis(startTime); start.setTimeInMillis(startTime);
@ -180,7 +181,7 @@ public class MissionManager extends MiniDbClientPlugin<MissionClient>
runAsync(() -> runAsync(() ->
{ {
if (!_repository.startMission(ClientManager.getAccountId(player), mission.getId(), mission.getWeeklyScale(), mission.getY())) if (!_repository.startMission(ClientManager.getAccountId(player), mission.getId(), mission.getLength().ordinal(), mission.getRequiredProgress(), mission.getY()))
{ {
client.getMissions().remove(mission); client.getMissions().remove(mission);
player.sendMessage(F.main(getName(), "Something went wrong when trying to start " + F.name(mission.getName()) + ".")); player.sendMessage(F.main(getName(), "Something went wrong when trying to start " + F.name(mission.getName()) + "."));

View File

@ -6,9 +6,11 @@ import mineplex.core.achievement.leveling.rewards.LevelChestReward;
import mineplex.core.achievement.leveling.rewards.LevelCurrencyReward; import mineplex.core.achievement.leveling.rewards.LevelCurrencyReward;
import mineplex.core.achievement.leveling.rewards.LevelExperienceReward; import mineplex.core.achievement.leveling.rewards.LevelExperienceReward;
import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.currency.GlobalCurrency;
import mineplex.core.game.GameDisplay;
import mineplex.core.treasure.types.TreasureType; import mineplex.core.treasure.types.TreasureType;
import static mineplex.core.game.GameDisplay.*;
import static mineplex.core.mission.MissionTrackerType.*;
public class MissionPopulator public class MissionPopulator
{ {
@ -17,10 +19,9 @@ public class MissionPopulator
MissionContext.<Material>newBuilder(manager, 1) MissionContext.<Material>newBuilder(manager, 1)
.name("Gold Finger") .name("Gold Finger")
.description("Get %s kills with a Golden Pickaxe") .description("Get %s kills with a Golden Pickaxe")
.requiredProgress(3) .xRange(4, 8)
.weeklyScale(4, 8) .games(CakeWars4, CakeWarsDuos)
.games(GameDisplay.CakeWars4, GameDisplay.CakeWarsDuos) .tracker(GAME_KILL)
.tracker(MissionTrackerType.GAME_KILL)
.trackerData(Material.GOLD_PICKAXE) .trackerData(Material.GOLD_PICKAXE)
.rewards( .rewards(
new LevelCurrencyReward(GlobalCurrency.GEM, 2000), new LevelCurrencyReward(GlobalCurrency.GEM, 2000),
@ -31,10 +32,9 @@ public class MissionPopulator
MissionContext.<GameDisplay>newBuilder(manager, 2) MissionContext.<GameDisplay>newBuilder(manager, 2)
.name("Cake Winner") .name("Cake Winner")
.description("Win %s games of Cake Wars Standard") .description("Win %s games of Cake Wars Standard")
.requiredProgress(2) .xRange(2, 4)
.weeklyScale(2, 4) .games(CakeWars4)
.games(GameDisplay.CakeWars4) .tracker(GAME_WIN)
.tracker(MissionTrackerType.GAME_WIN)
.rewards( .rewards(
new LevelCurrencyReward(GlobalCurrency.GEM, 2000), new LevelCurrencyReward(GlobalCurrency.GEM, 2000),
new LevelChestReward(TreasureType.ANCIENT, 1) new LevelChestReward(TreasureType.ANCIENT, 1)

View File

@ -6,16 +6,17 @@ import java.util.stream.Collectors;
import mineplex.serverdata.database.DBPool; import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase; import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.column.ColumnByte;
import mineplex.serverdata.database.column.ColumnInt; import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnLong; import mineplex.serverdata.database.column.ColumnLong;
public class MissionRepository extends RepositoryBase public class MissionRepository extends RepositoryBase
{ {
private static final String START_QUEST = "INSERT INTO accountMissions (accountId, missionId, weeklyScale, y, startTime) VALUES (?,?,?,?,?);"; private static final String START_QUEST = "INSERT INTO accountMissions (accountId, missionId, length, x, y, startTime) VALUES (?,?,?,?,?,?);";
private static final String INCREMENT_PROGRESS = "UPDATE accountMissions SET progress=progress+{0} WHERE accountId={1} AND missionId={2};"; private static final String INCREMENT_PROGRESS = "UPDATE accountMissions SET progress=progress+{0} WHERE accountId={1} AND missionId={2};";
private static final String COMPLETE_QUEST = "UPDATE accountMissions SET complete=1 WHERE accountId=? AND missionId=?;"; private static final String COMPLETE_QUEST = "UPDATE accountMissions SET complete=1 WHERE accountId=? AND missionId=?;";
private static final String CLEAR_PROGRESS = "DELETE FROM accountMissions WHERE accountId=? AND missionId=?"; private static final String CLEAR_PROGRESS = "DELETE FROM accountMissions WHERE accountId=? AND missionId=?;";
private final List<MissionQuery> _queries; private final List<MissionQuery> _queries;
@ -26,12 +27,13 @@ public class MissionRepository extends RepositoryBase
_queries = new ArrayList<>(); _queries = new ArrayList<>();
} }
public boolean startMission(int accountId, int missionId, int weeklyScale, int y) public boolean startMission(int accountId, int missionId, int lengthId, int x, int y)
{ {
return accountId != -1 && executeInsert(START_QUEST, null, return accountId != -1 && executeInsert(START_QUEST, null,
new ColumnInt("accountId", accountId), new ColumnInt("accountId", accountId),
new ColumnInt("missionId", missionId), new ColumnInt("missionId", missionId),
new ColumnInt("weeklyScale", weeklyScale), new ColumnByte("length", (byte) lengthId),
new ColumnInt("x", x),
new ColumnInt("y", y), new ColumnInt("y", y),
new ColumnLong("startTime", System.currentTimeMillis()) new ColumnLong("startTime", System.currentTimeMillis())
) > 0; ) > 0;

View File

@ -11,37 +11,24 @@ public class PlayerMission<T> implements Mission<T>
private final String _description; private final String _description;
private final MissionLength _length; private final MissionLength _length;
private final int _requiredProgress; private final int _x;
private final int _weeklyScale;
private final int _y; private final int _y;
private final LevelReward[] _rewards; private final LevelReward[] _rewards;
private int _currentProgress, _unsavedProgress; private int _currentProgress, _unsavedProgress;
private boolean _rewarded; private boolean _rewarded;
PlayerMission(MissionContext<T> context, int weeklyScale, int y, int currentProgress) PlayerMission(MissionContext<T> context, MissionLength length, int x, int y, int currentProgress)
{ {
_context = context; _context = context;
_requiredProgress = context.getRequiredProgress() * weeklyScale; _length = length;
_description = String.format(context.getDescription(), _requiredProgress, y);
if (context.isEventMission()) _x = x * length.getxScale();
{
_length = MissionLength.EVENT;
}
else if (weeklyScale > 1)
{
_length = MissionLength.WEEK;
}
else
{
_length = MissionLength.DAY;
}
_weeklyScale = weeklyScale;
_y = y; _y = y;
if (weeklyScale > 1) _description = String.format(context.getDescription(), _x, y);
if (_x != 1)
{ {
_rewards = new LevelReward[context.getRewards().length]; _rewards = new LevelReward[context.getRewards().length];
@ -51,7 +38,7 @@ public class PlayerMission<T> implements Mission<T>
if (reward instanceof ScalableLevelReward) if (reward instanceof ScalableLevelReward)
{ {
_rewards[i] = ((ScalableLevelReward) reward).cloneScalable(weeklyScale); _rewards[i] = ((ScalableLevelReward) reward).cloneScalable(x);
} }
else else
{ {
@ -105,12 +92,7 @@ public class PlayerMission<T> implements Mission<T>
@Override @Override
public int getRequiredProgress() public int getRequiredProgress()
{ {
return _requiredProgress; return _x;
}
public int getWeeklyScale()
{
return _weeklyScale;
} }
public int getY() public int getY()

View File

@ -432,6 +432,11 @@ public abstract class LobbyManager implements Listener
writeGameLine("waiting for players", 3, 159, (byte) 13); writeGameLine("waiting for players", 3, 159, (byte) 13);
} }
public void displayVoting()
{
writeGameLine("voting", 3, Material.STAINED_CLAY.getId(), (byte) 13);
}
public void ScoreboardDisplay(UpdateEvent event) public void ScoreboardDisplay(UpdateEvent event)
{ {
if (event.getType() != UpdateType.FAST) if (event.getType() != UpdateType.FAST)

View File

@ -73,6 +73,8 @@ public class VotingManager extends ListenerComponent implements Lifetimed
player.getInventory().setItem(0, _currentVote.getItemStack()); player.getInventory().setItem(0, _currentVote.getItemStack());
} }
_manager.GetLobby().displayVoting();
activate(); activate();
_lifetime.start(); _lifetime.start();
} }

View File

@ -67,7 +67,7 @@ public class VotingPage<T extends Voteable> extends ShopPageBase<ArcadeManager,
{ {
_vote.vote(player, voteable); _vote.vote(player, voteable);
playAcceptSound(player); playAcceptSound(player);
player.sendMessage(F.main("Game", "You voted for " + F.name(fName) + ".")); player.sendMessage(F.main("Game", "You voted for the next " + lowerName + ", " + F.name(fName) + "."));
}); });
} }
} }