Skip to content

Commit

Permalink
Merge branch 'stuartlangridge-add-monster-count'
Browse files Browse the repository at this point in the history
  • Loading branch information
Asmor committed Apr 24, 2019
2 parents 3c92800 + faa049c commit dd70f0e
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 19 deletions.
3 changes: 2 additions & 1 deletion app/encounter-builder/current-encounter.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
vm.isPool = vm.encounter.type == 'pool';
vm.newEncounter = newEncounter;
vm.partyInfo = partyInfo;
vm.totalMonsters = 10;

vm.launchImpInit = integration.launchImpInit;

var lastDifficulty = "medium";

function generateRandom(difficulty) {
difficulty = difficulty || lastDifficulty;
encounter.generateRandom(vm.filters, difficulty);
encounter.generateRandom(vm.filters, difficulty, vm.totalMonsters);
lastDifficulty = difficulty;
}

Expand Down
6 changes: 6 additions & 0 deletions app/encounter-builder/current-encounter.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ <h2>
</ul>
</div>
</h2>
<p>
No more than
<input class="current-encounter--total-monsters form-control input-sm"
type="number" ng-model="vm.totalMonsters">
monster<span ng-if="vm.totalMonsters != 1">s</span>
</p>
<p class="current-encounter--empty bg-info text-muted" ng-if="vm.encounter.qty == 0">
Create an encounter by clicking the Random encounter button or by adding monsters from the monsters table.
</p>
Expand Down
5 changes: 5 additions & 0 deletions app/encounter-builder/current-encounter.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
text-overflow: ellipsis;
}

&--total-monsters {
display: inline;
width: 4em;
}

&--btns {
margin-top: 0.5rem;
display: flex;
Expand Down
4 changes: 2 additions & 2 deletions app/services/encounter.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@
encounter.reference = null;
}

function generateRandom(filters, targetDifficulty) {
function generateRandom(filters, targetDifficulty, maxMonsters) {
targetDifficulty = targetDifficulty || 'medium';
var totalTargetExp = partyInfo.totalPartyExpLevels[targetDifficulty];
var monsters = randomEncounter.getRandomEncounter(partyInfo.totalPlayerCount, totalTargetExp, filters),
var monsters = randomEncounter.getRandomEncounter(partyInfo.totalPlayerCount, totalTargetExp, filters, maxMonsters),
i;

encounter.reset();
Expand Down
17 changes: 12 additions & 5 deletions app/services/randomencounter.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
// targetTotalExp: The experience target value. Takes into account player count, player level, and target difficulty already.
// filters: Any filters that should be applied when making the encounter
//
getRandomEncounter: function (playerCount, targetTotalExp, filters) {
getRandomEncounter: function (playerCount, targetTotalExp, filters, maxMonsters) {
var fudgeFactor = 1.1, // The algorithm is conservative in spending exp, so this tries to get it closer to the actual medium value
baseExpBudget = targetTotalExp * fudgeFactor,
encounterTemplate = getEncounterTemplate(),
encounterTemplate = getEncounterTemplate(maxMonsters),
multiplier = miscLib.getMultiplier(playerCount, encounterTemplate.total),
availableExp = baseExpBudget / multiplier,
monster,
Expand Down Expand Up @@ -54,9 +54,10 @@

return randomEncounter;

function getEncounterTemplate() {
function getEncounterTemplate(maxMonsters) {
var templates = [
[ 1 ],
[ 1, 1 ],
[ 1, 2 ],
[ 1, 5 ],
[ 1, 1, 1 ],
Expand All @@ -65,8 +66,14 @@
[ 2, 2 ],
[ 2, 4 ],
[ 8 ],
],
groups = JSON.parse(JSON.stringify(templates[Math.floor(Math.random() * templates.length)])),
];
if (maxMonsters) {
templates = templates.filter(function(t) {
let sum = t.reduce(function (a, b) { return a+b; });
return sum <= maxMonsters;
});
}
var groups = JSON.parse(JSON.stringify(templates[Math.floor(Math.random() * templates.length)])),
total = groups.reduce(function (a, b) { return a+b; });

// Silly hack to clone object
Expand Down
4 changes: 2 additions & 2 deletions build/index.html
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<link rel="icon" href="images/logo.png" sizes="600x600">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,500,600" rel="stylesheet">
<link rel="stylesheet" href="styles/styles-4508b73e9d.css">
<link rel="stylesheet" href="styles/styles-807680a86b.css">
</head>
<body>
<navbar></navbar>
Expand All @@ -26,6 +26,6 @@
<script src="thirdparty/dirPagination/dirPagination.js"></script>
<script src="thirdparty/angular-local-storage/angular-local-storage.js"></script>

<script src="js/app-8eea88e7b9.js"></script>
<script src="js/app-658bd5c77d.js"></script>
</body>
</html>
26 changes: 17 additions & 9 deletions build/js/app-8eea88e7b9.js → build/js/app-658bd5c77d.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7488,6 +7488,9 @@ button.close {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis; }
.current-encounter--total-monsters {
display: inline;
width: 4em; }
.current-encounter--btns {
margin-top: 0.5rem;
display: flex;
Expand Down
3 changes: 3 additions & 0 deletions styles/style.css
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -7488,6 +7488,9 @@ button.close {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis; }
.current-encounter--total-monsters {
display: inline;
width: 4em; }
.current-encounter--btns {
margin-top: 0.5rem;
display: flex;
Expand Down

0 comments on commit dd70f0e

Please sign in to comment.