Fix dodgy scaling
This commit is contained in:
parent
191364e352
commit
83733c8793
@ -11,27 +11,25 @@ public class MissionContext<T> implements Mission<T>
|
||||
private final String _name;
|
||||
private final String _description;
|
||||
private final GameDisplay[] _games;
|
||||
private final int _requiredProgress;
|
||||
private final MissionTrackerType _trackerType;
|
||||
private final T _data;
|
||||
private final LevelReward[] _rewards;
|
||||
private final boolean _eventMission;
|
||||
|
||||
private final int _minWeeklyScale, _maxWeeklyScale;
|
||||
private final int _minX, _maxX;
|
||||
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;
|
||||
_name = name;
|
||||
_description = description;
|
||||
_games = games;
|
||||
_requiredProgress = requiredProgress;
|
||||
_trackerType = trackerType;
|
||||
_data = data;
|
||||
_rewards = rewards;
|
||||
_minWeeklyScale = minWeeklyScale;
|
||||
_maxWeeklyScale = maxWeeklyScale;
|
||||
_minX = minX;
|
||||
_maxX = maxX;
|
||||
_minY = minY;
|
||||
_maxY = maxY;
|
||||
_eventMission = eventMission;
|
||||
@ -64,7 +62,7 @@ public class MissionContext<T> implements Mission<T>
|
||||
@Override
|
||||
public int getRequiredProgress()
|
||||
{
|
||||
return _requiredProgress;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -85,9 +83,9 @@ public class MissionContext<T> implements Mission<T>
|
||||
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()
|
||||
@ -114,12 +112,11 @@ public class MissionContext<T> implements Mission<T>
|
||||
private String _name;
|
||||
private String _description;
|
||||
private GameDisplay[] _games;
|
||||
private int _requiredProgress;
|
||||
private MissionTrackerType _trackerType;
|
||||
private T _data;
|
||||
private LevelReward[] _rewards;
|
||||
|
||||
private int _minWeeklyScale, _maxWeeklyScale;
|
||||
private int _minX, _maxX;
|
||||
private int _minY, _maxY;
|
||||
|
||||
private boolean _eventMission;
|
||||
@ -149,12 +146,6 @@ public class MissionContext<T> implements Mission<T>
|
||||
return this;
|
||||
}
|
||||
|
||||
public MissionBuilder<T> requiredProgress(int requiredProgress)
|
||||
{
|
||||
_requiredProgress = requiredProgress;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MissionBuilder<T> tracker(MissionTrackerType tracker)
|
||||
{
|
||||
_trackerType = tracker;
|
||||
@ -173,10 +164,10 @@ public class MissionContext<T> implements Mission<T>
|
||||
return this;
|
||||
}
|
||||
|
||||
public MissionBuilder<T> weeklyScale(int min, int max)
|
||||
public MissionBuilder<T> xRange(int min, int max)
|
||||
{
|
||||
_minWeeklyScale = min;
|
||||
_maxWeeklyScale = max;
|
||||
_minX = min;
|
||||
_maxX = max;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -197,7 +188,7 @@ public class MissionContext<T> implements Mission<T>
|
||||
{
|
||||
if (_eventMission)
|
||||
{
|
||||
_minWeeklyScale = _maxWeeklyScale = _minY = _maxY = 0;
|
||||
_minX = _maxX = _minY = _maxY = 0;
|
||||
}
|
||||
|
||||
if (_name == null || _name.isEmpty())
|
||||
@ -212,10 +203,6 @@ public class MissionContext<T> implements Mission<T>
|
||||
{
|
||||
_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)
|
||||
{
|
||||
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 + "]");
|
||||
}
|
||||
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 + "]");
|
||||
}
|
||||
|
||||
_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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,35 +11,30 @@ import mineplex.core.common.util.UtilText;
|
||||
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),
|
||||
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)
|
||||
{
|
||||
@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);
|
||||
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, 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);
|
||||
|
||||
private final String _name;
|
||||
private final String[] _resetInfo;
|
||||
private final ChatColor _chatColour;
|
||||
private final byte _colourData;
|
||||
private final int _xScale;
|
||||
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;
|
||||
_resetInfo = resetInfo;
|
||||
_chatColour = chatColour;
|
||||
_colourData = (byte) colourData;
|
||||
_xScale = xScale;
|
||||
_calendarField = calendarField;
|
||||
}
|
||||
|
||||
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()
|
||||
@ -62,6 +57,11 @@ public enum MissionLength
|
||||
return _colourData;
|
||||
}
|
||||
|
||||
public int getxScale()
|
||||
{
|
||||
return _xScale;
|
||||
}
|
||||
|
||||
public int getCalendarField()
|
||||
{
|
||||
return _calendarField;
|
||||
|
@ -141,10 +141,11 @@ public class MissionManager extends MiniDbClientPlugin<MissionClient>
|
||||
}
|
||||
|
||||
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");
|
||||
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);
|
||||
start.setTimeInMillis(startTime);
|
||||
@ -180,7 +181,7 @@ public class MissionManager extends MiniDbClientPlugin<MissionClient>
|
||||
|
||||
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);
|
||||
player.sendMessage(F.main(getName(), "Something went wrong when trying to start " + F.name(mission.getName()) + "."));
|
||||
|
@ -6,9 +6,11 @@ import mineplex.core.achievement.leveling.rewards.LevelChestReward;
|
||||
import mineplex.core.achievement.leveling.rewards.LevelCurrencyReward;
|
||||
import mineplex.core.achievement.leveling.rewards.LevelExperienceReward;
|
||||
import mineplex.core.common.currency.GlobalCurrency;
|
||||
import mineplex.core.game.GameDisplay;
|
||||
import mineplex.core.treasure.types.TreasureType;
|
||||
|
||||
import static mineplex.core.game.GameDisplay.*;
|
||||
import static mineplex.core.mission.MissionTrackerType.*;
|
||||
|
||||
public class MissionPopulator
|
||||
{
|
||||
|
||||
@ -17,10 +19,9 @@ public class MissionPopulator
|
||||
MissionContext.<Material>newBuilder(manager, 1)
|
||||
.name("Gold Finger")
|
||||
.description("Get %s kills with a Golden Pickaxe")
|
||||
.requiredProgress(3)
|
||||
.weeklyScale(4, 8)
|
||||
.games(GameDisplay.CakeWars4, GameDisplay.CakeWarsDuos)
|
||||
.tracker(MissionTrackerType.GAME_KILL)
|
||||
.xRange(4, 8)
|
||||
.games(CakeWars4, CakeWarsDuos)
|
||||
.tracker(GAME_KILL)
|
||||
.trackerData(Material.GOLD_PICKAXE)
|
||||
.rewards(
|
||||
new LevelCurrencyReward(GlobalCurrency.GEM, 2000),
|
||||
@ -31,10 +32,9 @@ public class MissionPopulator
|
||||
MissionContext.<GameDisplay>newBuilder(manager, 2)
|
||||
.name("Cake Winner")
|
||||
.description("Win %s games of Cake Wars Standard")
|
||||
.requiredProgress(2)
|
||||
.weeklyScale(2, 4)
|
||||
.games(GameDisplay.CakeWars4)
|
||||
.tracker(MissionTrackerType.GAME_WIN)
|
||||
.xRange(2, 4)
|
||||
.games(CakeWars4)
|
||||
.tracker(GAME_WIN)
|
||||
.rewards(
|
||||
new LevelCurrencyReward(GlobalCurrency.GEM, 2000),
|
||||
new LevelChestReward(TreasureType.ANCIENT, 1)
|
||||
|
@ -6,16 +6,17 @@ import java.util.stream.Collectors;
|
||||
|
||||
import mineplex.serverdata.database.DBPool;
|
||||
import mineplex.serverdata.database.RepositoryBase;
|
||||
import mineplex.serverdata.database.column.ColumnByte;
|
||||
import mineplex.serverdata.database.column.ColumnInt;
|
||||
import mineplex.serverdata.database.column.ColumnLong;
|
||||
|
||||
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 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;
|
||||
|
||||
@ -26,12 +27,13 @@ public class MissionRepository extends RepositoryBase
|
||||
_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,
|
||||
new ColumnInt("accountId", accountId),
|
||||
new ColumnInt("missionId", missionId),
|
||||
new ColumnInt("weeklyScale", weeklyScale),
|
||||
new ColumnByte("length", (byte) lengthId),
|
||||
new ColumnInt("x", x),
|
||||
new ColumnInt("y", y),
|
||||
new ColumnLong("startTime", System.currentTimeMillis())
|
||||
) > 0;
|
||||
|
@ -11,37 +11,24 @@ public class PlayerMission<T> implements Mission<T>
|
||||
|
||||
private final String _description;
|
||||
private final MissionLength _length;
|
||||
private final int _requiredProgress;
|
||||
private final int _weeklyScale;
|
||||
private final int _x;
|
||||
private final int _y;
|
||||
private final LevelReward[] _rewards;
|
||||
|
||||
private int _currentProgress, _unsavedProgress;
|
||||
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;
|
||||
_requiredProgress = context.getRequiredProgress() * weeklyScale;
|
||||
_description = String.format(context.getDescription(), _requiredProgress, y);
|
||||
_length = length;
|
||||
|
||||
if (context.isEventMission())
|
||||
{
|
||||
_length = MissionLength.EVENT;
|
||||
}
|
||||
else if (weeklyScale > 1)
|
||||
{
|
||||
_length = MissionLength.WEEK;
|
||||
}
|
||||
else
|
||||
{
|
||||
_length = MissionLength.DAY;
|
||||
}
|
||||
|
||||
_weeklyScale = weeklyScale;
|
||||
_x = x * length.getxScale();
|
||||
_y = y;
|
||||
|
||||
if (weeklyScale > 1)
|
||||
_description = String.format(context.getDescription(), _x, y);
|
||||
|
||||
if (_x != 1)
|
||||
{
|
||||
_rewards = new LevelReward[context.getRewards().length];
|
||||
|
||||
@ -51,7 +38,7 @@ public class PlayerMission<T> implements Mission<T>
|
||||
|
||||
if (reward instanceof ScalableLevelReward)
|
||||
{
|
||||
_rewards[i] = ((ScalableLevelReward) reward).cloneScalable(weeklyScale);
|
||||
_rewards[i] = ((ScalableLevelReward) reward).cloneScalable(x);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -105,12 +92,7 @@ public class PlayerMission<T> implements Mission<T>
|
||||
@Override
|
||||
public int getRequiredProgress()
|
||||
{
|
||||
return _requiredProgress;
|
||||
}
|
||||
|
||||
public int getWeeklyScale()
|
||||
{
|
||||
return _weeklyScale;
|
||||
return _x;
|
||||
}
|
||||
|
||||
public int getY()
|
||||
|
@ -432,6 +432,11 @@ public abstract class LobbyManager implements Listener
|
||||
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)
|
||||
{
|
||||
if (event.getType() != UpdateType.FAST)
|
||||
|
@ -73,6 +73,8 @@ public class VotingManager extends ListenerComponent implements Lifetimed
|
||||
player.getInventory().setItem(0, _currentVote.getItemStack());
|
||||
}
|
||||
|
||||
_manager.GetLobby().displayVoting();
|
||||
|
||||
activate();
|
||||
_lifetime.start();
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ public class VotingPage<T extends Voteable> extends ShopPageBase<ArcadeManager,
|
||||
{
|
||||
_vote.vote(player, voteable);
|
||||
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) + "."));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user