Build time modifiers

This commit is contained in:
Shaun Bennett 2016-01-23 02:43:41 -05:00
parent 5dc773032b
commit f82a408f30
2 changed files with 81 additions and 10 deletions

View File

@ -104,6 +104,7 @@ public class SpeedBuilders extends SoloGame
private int _buildCountStage; private int _buildCountStage;
private int _viewCountStage; private int _viewCountStage;
private int _buildTimeTracker = 40;
private int _buildTime = 40; private int _buildTime = 40;
private int _viewTime = 8; private int _viewTime = 8;
@ -474,6 +475,7 @@ public class SpeedBuilders extends SoloGame
_currentBuild = UtilAlg.Random(_buildData, _usedBuilds); _currentBuild = UtilAlg.Random(_buildData, _usedBuilds);
_usedBuilds.add(_currentBuild); _usedBuilds.add(_currentBuild);
_buildTime = _currentBuild.getBuildTime(_buildTimeTracker);
HashSet<Location> usedBuildLocs = new HashSet<Location>(); HashSet<Location> usedBuildLocs = new HashSet<Location>();
@ -869,6 +871,7 @@ public class SpeedBuilders extends SoloGame
_currentBuild = UtilAlg.Random(_buildData, _usedBuilds); _currentBuild = UtilAlg.Random(_buildData, _usedBuilds);
_usedBuilds.add(_currentBuild); _usedBuilds.add(_currentBuild);
_buildTime = _currentBuild.getBuildTime(_buildTimeTracker);
for (Player player : GetTeamList().get(0).GetPlayers(true)) for (Player player : GetTeamList().get(0).GetPlayers(true))
{ {
@ -924,8 +927,8 @@ public class SpeedBuilders extends SoloGame
_roundsPlayed++; _roundsPlayed++;
if (_buildTime > 1) if (_buildTimeTracker > 1)
_buildTime--; _buildTimeTracker--;
_viewCountStage = 0; _viewCountStage = 0;

View File

@ -21,7 +21,6 @@ import org.bukkit.material.Stairs;
public class BuildData public class BuildData
{ {
public SpeedBuilders Game; public SpeedBuilders Game;
public Location BuildMin; public Location BuildMin;
@ -36,6 +35,11 @@ public class BuildData
public ArrayList<MobData> Mobs = new ArrayList<MobData>(); public ArrayList<MobData> Mobs = new ArrayList<MobData>();
private int _timeAdd = 0;
private int _timeSubtract = 0;
private int _timeEqual = -1;
private double _timeMultiplier = 1.0;
public BuildData(Location loc, String buildText, SpeedBuilders game) public BuildData(Location loc, String buildText, SpeedBuilders game)
{ {
Build = new BlockState[game.BuildSize][game.BuildSize][game.BuildSize]; Build = new BlockState[game.BuildSize][game.BuildSize][game.BuildSize];
@ -43,8 +47,6 @@ public class BuildData
StairShapes = new EnumStairShape[game.BuildSize][game.BuildSize][game.BuildSize]; StairShapes = new EnumStairShape[game.BuildSize][game.BuildSize][game.BuildSize];
BuildText = buildText;
Game = game; Game = game;
Location groundMin = loc.clone().subtract(game.BuildSizeDiv2, -3, game.BuildSizeDiv2); Location groundMin = loc.clone().subtract(game.BuildSizeDiv2, -3, game.BuildSizeDiv2);
@ -57,6 +59,8 @@ public class BuildData
} }
} }
parseText(buildText);
Location buildMin = loc.clone().subtract(game.BuildSizeDiv2, -4, game.BuildSizeDiv2); Location buildMin = loc.clone().subtract(game.BuildSizeDiv2, -4, game.BuildSizeDiv2);
BuildMin = buildMin; BuildMin = buildMin;
@ -108,6 +112,70 @@ public class BuildData
} }
} }
private void parseText(String buildText)
{
StringBuilder sb = new StringBuilder();
for (String part : buildText.split(" "))
{
if (part.matches("^time[\\Q+-=\\E][0-9]+$"))
{
// + - = add subtract or set seconds
try
{
int num = Integer.parseInt(part.substring(5));
switch (part.charAt(4))
{
case '-':
_timeSubtract = num;
break;
case '=':
_timeEqual = num;
break;
default:
_timeAdd = num;
}
}
catch (NumberFormatException e)
{
System.out.println("Failed parsing data for customloc: " + buildText);
e.printStackTrace();
}
}
else if (part.matches("^time\\*[0-9]*\\.?[0-9]+$"))
{
// * multiply by a number
try
{
double num = Double.parseDouble(part.substring(5));
_timeMultiplier = num;
}
catch (NumberFormatException e)
{
System.out.println("Failed parsing data for customloc: " + buildText);
e.printStackTrace();
}
}
else
{
sb.append(part + " ");
}
}
BuildText = sb.toString().trim();
}
public int getBuildTime(int unmodified)
{
int newTime = unmodified;
newTime += _timeAdd;
newTime -= _timeSubtract;
newTime = (int) (_timeMultiplier * newTime);
if (_timeEqual != -1) newTime = _timeEqual;
// limit to range of 5-60 seconds
return Math.min(Math.max(newTime, 5), 60);
}
public int getPerfectScore() public int getPerfectScore()
{ {
return Game.BuildSizePow3 + Mobs.size(); return Game.BuildSizePow3 + Mobs.size();