Skip to content

Commit

Permalink
Pulling in monster count branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Asmor committed Apr 24, 2019
2 parents 3c92800 + b16cd92 commit 56c16ed
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 11,466 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
31 changes: 0 additions & 31 deletions build/index.html

This file was deleted.

Loading

0 comments on commit 56c16ed

Please sign in to comment.