@ -12,7 +12,7 @@ function handleIframeLoad(frameName)
if ( frame != null )
{
result = frame . document . getElementsByTagName ( "pre" ) [ 0 ] . innerHTML ;
// The form's onload handler gets called when the main page is first loaded as well.
// We detect this condition by checking if the iframes contents are not empty.
if ( result . length > 0 ) {
@ -32,7 +32,7 @@ function handleIframeLoad(frameName)
scope . loadCurrentCharacterFromStruct ( charStruct ) ;
}
) ;
}
}
catch ( e ) {
console . log ( "Loading character failed: " + e ) ;
scope . $apply (
@ -72,7 +72,7 @@ burningModule.run(function($rootScope, $location, $anchorScroll, $routeParams) {
$rootScope . $on ( '$routeChangeSuccess' , function ( newRoute , oldRoute ) {
if ( $routeParams . scrollTo ) {
$location . hash ( $routeParams . scrollTo ) ;
$anchorScroll ( ) ;
$anchorScroll ( ) ;
}
} ) ;
} ) ;
@ -92,7 +92,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
selected item at that level .
index : The starting level in the hierarchy for which we should recalculate the lower levels
of the lists .
* /
* /
$scope . calculateHierarchyListForSelectN = function ( listForSelect , currentItem , index ) {
if ( index < 1 )
return ;
@ -100,7 +100,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
while ( index < 3 ) {
if ( ! currentItem [ index - 1 ] || ! currentItem [ index - 1 ] . resources ) {
listForSelect [ index ] = [ ] ;
listForSelect [ index ] = [ ] ;
currentItem [ index ] = { } ;
}
else {
@ -118,7 +118,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
$scope . enforcePointLimits = settings . enforcePointLimits
/* A list of DisplayLifepath. */
$scope . selectedLifepaths = [ ] ;
$scope . selectedLifepaths = [ ] ;
$scope . statNames = [ "Will" , "Perception" , "Power" , "Forte" , "Agility" , "Speed" ] ;
$scope . stats = [ ] ;
@ -195,7 +195,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
$scope . reputations = { } ;
// Hash containing total stat points categorized by
// Hash containing total stat points categorized by
// type (physical, mental, either)
$scope . totalStatPoints = { "physical" : 0 , "mental" : 0 , "either" : 0 }
$scope . unspentStatPoints = { "physical" : 0 , "mental" : 0 , "either" : 0 }
@ -206,12 +206,6 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
// Character name
$scope . name = "" ;
// Character stock. One of man, dwarf, orc, elf
// if ( ! isValidStock(stock) ){
// console.log("Invalid stock '"+stock+"' passed to BurningCtrl.initialize. Defaulting to man");
// stock = "man";
// }
$scope . stock = stock ;
// Character id (server side id)
@ -247,7 +241,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
/* Traits that are on the character's lifepaths, but not necessarily taken */
$scope . lifepathTraits = { } ;
/ * M o d i f i e r s t o a t t r i b u t e s b a s e d o n t h e a n s w e r s t o q u e s t i o n s . T h i s a p p l i e s t o G r e e d , S t e e l , e t c .
/ * M o d i f i e r s t o a t t r i b u t e s b a s e d o n t h e a n s w e r s t o q u e s t i o n s . T h i s a p p l i e s t o G r e e d , S t e e l , e t c .
The hash is keyed by attribute name , and the value is a list of yes / no questions , their answers ,
and the modifier applied for a yes answer .
* /
@ -255,11 +249,11 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
$scope . attributeBonuses = { } ;
/ * U s e d t o k e e p t r a c k o f w h e t h e r t h e u s e r s h a d e - s h i f t e d a n a t t r i b u t e , f o r t h o s e a t t r i b u t e s t h a t
/ * U s e d t o k e e p t r a c k o f w h e t h e r t h e u s e r s h a d e - s h i f t e d a n a t t r i b u t e , f o r t h o s e a t t r i b u t e s t h a t
allow shade shifting * /
$scope . attributeShade = { 'Steel' : 'B' , 'Grief' : 'B' , 'Greed' : 'B' , 'Hatred' : 'B' , 'Spite' : 'B' } ;
$scope . ptgs = new PTGS ( ) ;
$scope . ptgs = new PTGS ( ) ;
/* List of traits to show in the Choose Special Trait dropdown */
$scope . specialTraitsForDisplay = [ ] ;
@ -287,19 +281,19 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
} ;
$scope . characterStorage = characterStorage
$scope . resourceAdderToShow = 'gear' ;
// If this is true, then the user had added a lifepath to an Orc character that added a
// If this is true, then the user had added a lifepath to an Orc character that added a
// brutal life trait, and then the character removed that lifepath. According to the rules
// they can never gain more lifepaths after this action.
$scope . brutalLifeWithdrawn = false ;
calculateGearSelectionLists ( $scope , burningData ) ;
calculatePropertySelectionLists ( $scope , burningData ) ;
$scope . serverSettings = serverSettings ;
}
$scope . initialize ( ) ;
@ -354,7 +348,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
}
return result ;
}
$scope . onGenderChange = function ( ) {
if ( $scope . name . length == 0 ) {
@ -365,7 +359,18 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
$scope . onStockChange = function ( ) {
if ( ! $scope . stock ) return ;
if ( ! $scope . stockSelected ) {
$scope . stocks . shift ( ) ;
$scope . stockSelected = true ;
}
var oldName = $scope . name ;
if ( ! burningData . lifepaths [ $scope . stock ] ) {
burningData . loadLifepathsForStock ( $scope . stock ) ;
}
if ( ! burningData . resources [ $scope . stock ] ) {
burningData . loadResourcesForStock ( $scope . stock ) ;
}
// TODO: technically a bug — only want this registered once per stock...
burningData . registerStockEvent ( $scope . stock , "lifepathsLoaded" , function ( ) {
// Make a blank character sheet
$scope . initialize ( $scope . stock ) ;
@ -379,14 +384,6 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
calculateCurrentSettingLifepathNames ( $scope , burningData ) ;
calculateSpecialTraitsForDisplay ( $scope , burningData ) ;
} ) ;
if ( ! burningData . lifepaths [ $scope . stock ] ) {
burningData . loadLifepathsForStock ( $scope . stock ) ;
}
if ( ! burningData . resources [ $scope . stock ] ) {
burningData . loadResourcesForStock ( $scope . stock ) ;
}
}
$scope . onSettingChange = function ( ) {
@ -412,13 +409,11 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
calculateUnspentSkillPoints ( $scope ) ;
}
// burningData.registerOnAllDatasetsLoaded(function(){
// onLifepathsLoad($scope, burningData);
// });
burningData . registerEvent ( "stocksLoaded" , function ( ) {
$scope . stocks = [ { name : "Select a stock" } ]
$scope . stocks = $scope . stocks . concat ( Object . values ( burningData . stocks ) ) ;
$scope . stockSelected = false ;
} ) ;
$scope . $on ( '$locationChangeStart' , function ( event , nextUrl , currentUrl ) {
@ -440,11 +435,11 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
$scope . onAddLifepathClick = function ( ) {
// Find the current lifepath info in the lifepaths
var setting = burningData . lifepaths [ $scope . stock ] [ $scope . currentSetting ] ;
if ( ! setting )
if ( ! setting )
return ;
var lifepath = setting [ $scope . currentSettingLifepath ] ;
if ( ! lifepath )
if ( ! lifepath )
return ;
displayLp = new DisplayLifepath ( $scope . currentSetting , $scope . currentSettingLifepath , lifepath ) ;
@ -463,7 +458,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
$scope . chooseStatPenalties ( displayLp , - penalty ) ;
}
// If the lifepath contains 'Appropriate Weapons', ask the
// If the lifepath contains 'Appropriate Weapons', ask the
// user to choose those weapons.
if ( appropriateWeapons . hasAppropriateWeapons ( displayLp ) ) {
var appropriate = appropriateWeapons . appropriateWeapons [ displayLp . name ] ;
@ -480,7 +475,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
}
}
// If the lifepath contains 'Weapon Of Choice', ask the
// If the lifepath contains 'Weapon Of Choice', ask the
// user to choose the weapon.
if ( weaponOfChoice . hasWeaponOfChoice ( displayLp ) ) {
weaponOfChoice . selectWeaponOfChoice ( displayLp , function ( ) {
@ -501,7 +496,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
displayLp . calculateResourcePoints ( prevLifepath ) ;
displayLp . calculateGeneralSkillPoints ( prevLifepath ) ;
displayLp . modifyForDiminishingReturns ( $scope . selectedLifepaths ) ;
displayLp . modifyForDiminishingReturns ( $scope . selectedLifepaths ) ;
if ( $scope . stock == "orc" ) {
displayLp . applyBrutalLife ( $scope . selectedLifepaths ) ;
}
@ -565,7 +560,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
calculateUnspentResourcePoints ( $scope ) ;
applyBonusesFromTraits ( $scope ) ;
}
$scope . incrementStat = function ( stat ) {
// Man stock has max 8 pts in any stat
@ -592,7 +587,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
if ( specificStatPoints <= 0 && eitherStatPoints <= 0 && $scope . enforcePointLimits )
return ;
if ( specificStatPoints > 0 ) {
specificStatPoints -= 1 ;
stat . setSpecificPointsSpent ( stat . specificPointsSpent ( ) + 1 ) ;
@ -605,10 +600,10 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
$scope . unspentStatPoints . either = eitherStatPoints ;
if ( "m" == stat . type ) {
$scope . unspentStatPoints . mental = specificStatPoints ;
}
}
else if ( "p" == stat . type ) {
$scope . unspentStatPoints . physical = specificStatPoints ;
}
}
calculatePTGS ( $scope ) ;
}
@ -625,15 +620,15 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
}
else {
var specificStatPoints = 0 ;
stat . setSpecificPointsSpent ( stat . specificPointsSpent ( ) - 1 ) ;
if ( "m" == stat . type ) {
$scope . unspentStatPoints . mental += 1 ;
}
}
else if ( "p" == stat . type ) {
$scope . unspentStatPoints . physical += 1 ;
}
}
else {
console . log ( "Error: Unknown stat type " + stat . type + " passed to decrementStat for stat " + stat . name ) ;
// Undo the decrement
@ -686,10 +681,10 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
$scope . unspentStatPoints . either = eitherStatPoints ;
if ( "m" == stat . type ) {
$scope . unspentStatPoints . mental = specificStatPoints ;
}
}
else if ( "p" == stat . type ) {
$scope . unspentStatPoints . physical = specificStatPoints ;
}
}
}
var toBlack = function ( stat ) {
@ -704,7 +699,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
else {
console . log ( "Error: Unknown stat type " + stat . type + " passed to incrementStat for stat " + stat . name ) ;
return ;
}
}
var cost = 5 ;
@ -787,7 +782,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
cost -= toTake ;
}
if ( cost > 0 && ( $scope . unspentSkillPoints [ "general" ] > 0 || ! $scope . enforcePointLimits ) )
{
$scope . unspentSkillPoints [ "general" ] -= cost ;
@ -803,11 +798,11 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
// If this skill is required to be open, do not allow
// unchecking
var required = skillsRequiredToBeOpened ( $scope . selectedLifepaths )
if ( skill . name in required ) {
if ( skill . name in required ) {
checkbox . checked = true ;
return ;
}
if ( skill . generalPointsSpent > 0 ) {
$scope . unspentSkillPoints . general += skill . generalPointsSpent ;
skill . generalPointsSpent = 0 ;
@ -903,7 +898,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
if ( endsWith ( wiseName , "-wise" ) ) {
wiseName = wiseName . substring ( 0 , wiseName . length - 5 ) ;
}
wiseName = capitalizeEachWord ( wiseName ) + "-wise" ;
$scope . generalSkills [ wiseName ] = new DisplaySkill ( wiseName , burningData . skills ) ;
@ -913,7 +908,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
general skills selected by the user * /
$scope . isGeneralSkill = function ( displaySkill ) {
return ( displaySkill . name in $scope . generalSkills ) ;
}
/* Given the passed display skill, remove it from the list of general skills */
@ -922,7 +917,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
calculateUnspentSkillPoints ( $scope ) ;
}
// Return a hash containing all skills
// Return a hash containing all skills
$scope . allSelectedSkills = function ( ) {
var result = { }
for ( var key in $scope . lifepathSkills ) {
@ -935,8 +930,8 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
}
// Return a list of skill names that the character can choose
// from to add a general skill. This is all skills less the
// skills the character already has, and less the skills that
// from to add a general skill. This is all skills less the
// skills the character already has, and less the skills that
// are not allowed for the character's stock.
$scope . selectableGeneralSkills = function ( ) {
var result = [ ] ;
@ -1038,7 +1033,8 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
return { "shade" : "" , "exp" : 10 - $scope . statsByName [ "Will" ] . exp ( ) + bonus } ;
}
else if ( "Stride" == name ) {
var stride = burningData . stocks [ $scope . stock ] . stride ;
// This is a hack: if stock is unselected, use 0 for stride to not throw error; it shouldn't be displayed anyway
var stride = $scope . stock ? burningData . stocks [ $scope . stock ] . stride : 0 ;
stride += bonus ;
return { "shade" : "" , "exp" : stride } ;
}
@ -1056,13 +1052,13 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
for ( var i = 0 ; i < property . length ; i ++ ) {
sum += property [ i ] . cost ;
}
if ( sum >= 50 ) {
v += 1 ;
}
v += bonus ;
return { "shade" : "B" , "exp" : v } ;
}
else if ( "Resources" == name ) {
@ -1142,7 +1138,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
// Divide physical between each physical stat
var physicalBuckets = divideIntoBuckets ( $scope . totalStatPoints . physical , 4 ) ;
var physicalEitherBuckets = divideIntoBuckets ( eitherBuckets [ 1 ] , 4 ) ;
$scope . statsByName . Will . mentalPointsSpent = mentalBuckets [ 0 ] ;
$scope . statsByName . Will . eitherPointsSpent = mentalEitherBuckets [ 1 ] ;
$scope . statsByName . Perception . mentalPointsSpent = mentalBuckets [ 1 ] ;
@ -1164,7 +1160,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
}
if ( sum != $scope . totalStatPoints . either + $scope . totalStatPoints . mental + $scope . totalStatPoints . physical ) {
console . log ( "Error: Calculation in distributeStats is incorrect." ) ;
for ( var i = 0 ; i < $scope . stats . length ; i ++ ) {
$scope . stats [ i ] . physicalPointsSpent = 0 ;
$scope . stats [ i ] . mentalPointsSpent = 0 ;
@ -1192,15 +1188,15 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
return list ;
}
/ *
$scope . specialTraitsForDisplay = function ( ) {
var list = [ ] ;
for ( var traitName in burningData . traits ) {
var trait = burningData . traits [ traitName ] ;
if ( 'restrict' in trait ) {
if ( trait . restrict . indexOf ( validStockToRestrictionStock ( $scope . stock ) ) >= 0 &&
if ( trait . restrict . indexOf ( validStockToRestrictionStock ( $scope . stock ) ) >= 0 &&
( trait . restrict . indexOf ( "special" ) >= 0 || trait . restrict . indexOf ( "character" ) >= 0 ) ) {
list . push ( new DisplayTrait ( traitName , burningData . traits ) ) ;
}
@ -1213,7 +1209,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
}
return list ;
}
}
* /
$scope . addLifepathTrait = function ( traitName ) {
@ -1405,7 +1401,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
} ) ;
}
// Launch a download for the current character. Since Javascript can't really
// Launch a download for the current character. Since Javascript can't really
// launch a download using data from javascript, we need to pass the current character
// to the server which sends a filename back to a hidden iframe which then launches the download.
$scope . downloadCurrentCharacter = function ( ) {
@ -1536,7 +1532,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
}
$scope . addResource = function ( type ) {
var resource = null ;
var resourceHash = null ;
if ( type == 'relationship' ) {
@ -1605,7 +1601,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
calculateUnspentResourcePoints ( $scope ) ;
}
$scope . addSelectListGear = function ( ) {
var name = "" ;
var cost = 0 ;
@ -1625,7 +1621,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
}
}
}
$scope . currentGearDesc = name ;
$scope . currentGearCost = cost ;
$scope . addResource ( 'gear' ) ;
@ -1650,7 +1646,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
}
}
}
$scope . currentPropertyDesc = name ;
$scope . currentPropertyCost = cost ;
$scope . addResource ( 'property' ) ;
@ -1715,7 +1711,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
}
$scope . answerEmotionalAttributeQuestions = function ( attributeName ) {
// If the character already has some or all of the questions answered, pass those in.
// Otherwise generate new ones.
@ -1740,9 +1736,9 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
displayEmotionalMath : function ( ) {
return serverSettings . displayAttrMath ;
} ,
}
}
} ) ;
modalInstance . result . then ( function ( selected ) {
$scope . attributeModifierQuestionResults [ attributeName ] = selected ;
} , function ( ) {
@ -1840,12 +1836,12 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
}
$scope . showUploadCharacterModal = function ( ) {
var modalInstance = $modal . open ( {
templateUrl : '/upload_character_partial' ,
controller : UploadCharacterModalCtrl
} ) ;
modalInstance . result . then ( function ( ) {
console . log ( "Modal: Uploaded character" ) ;
} , function ( ) {
@ -1955,7 +1951,7 @@ function calculateAge($scope){
function calculateSettingNames ( $scope , burningData ) {
var settingNames = null ;
var lastCurrentSetting = $scope . currentSetting ;
var lastCurrentSetting = $scope . currentSetting ;
if ( ! $scope . enforceLifepathReqts ) {
// Display all settings and subsettings
@ -2032,8 +2028,8 @@ function calculateCurrentSettingLifepathNames($scope, burningData){
var currentSettingLifepathNames = null ;
if ( $scope . enforceLifepathReqts ) {
//console.log("calculateCurrentSettingLifepathNames: enforce lifepath requirements is enabled");
currentSettingLifepathNames = [ ] ;
//console.log("calculateCurrentSettingLifepathNames: enforce lifepath requirements is enabled");
currentSettingLifepathNames = [ ] ;
var all = Object . keys ( burningData . lifepaths [ $scope . stock ] [ $scope . currentSetting ] )
// Filter out the names that are not allowed based on the character's lifepaths.
if ( $scope . selectedLifepaths . length == 0 ) {
@ -2058,11 +2054,11 @@ function calculateCurrentSettingLifepathNames($scope, burningData){
//console.log(settingName + ":" + lifepathName + " allowed: " + (result[0] ? "yes" : "no"));
//console.log("rexpr: " + rexpr);
if ( result [ 0 ] ) {
//console.log("calculateCurrentSettingLifepathNames: added because lifepath has reqts, which are met: " + lifepathName);
//console.log("calculateCurrentSettingLifepathNames: added because lifepath has reqts, which are met: " + lifepathName);
currentSettingLifepathNames . push ( lifepathName ) ;
}
else {
//console.log("calculateCurrentSettingLifepathNames: not added because lifepath has reqts, which not are met: " + lifepathName);
//console.log("calculateCurrentSettingLifepathNames: not added because lifepath has reqts, which not are met: " + lifepathName);
}
}
else {
@ -2071,7 +2067,7 @@ function calculateCurrentSettingLifepathNames($scope, burningData){
}
}
}
}
else {
currentSettingLifepathNames = Object . keys ( burningData . lifepaths [ $scope . stock ] [ $scope . currentSetting ] ) ;
}
@ -2094,7 +2090,7 @@ function calculateCurrentSettingLifepathNames($scope, burningData){
}
function calculateTotalStatPoints ( $scope , burningData ) {
var totalStatPoints = { "physical" : 0 , "mental" : 0 , "either" : 0 } ;
$scope . totalStatPoints = { "physical" : 0 , "mental" : 0 , "either" : 0 } ;
@ -2125,10 +2121,10 @@ function calculateTotalStatPoints($scope, burningData){
Preconditions : totalStatPoints is up to date .
* /
function calculateUnspentStatPoints ( $scope ) {
var unspentStatPoints = {
"physical" : $scope . totalStatPoints . physical ,
"mental" : $scope . totalStatPoints . mental ,
"physical" : $scope . totalStatPoints . physical ,
"mental" : $scope . totalStatPoints . mental ,
"either" : $scope . totalStatPoints . either
}
@ -2151,7 +2147,7 @@ function calculateLifepathSkills($scope, burningData, appropriateWeapons){
for ( var i = 0 ; i < $scope . selectedLifepaths . length ; i ++ ) {
var displayLp = $scope . selectedLifepaths [ i ] ;
appropriateWeapons . replaceAppropriateWeaponsUsingSaved ( displayLp ) ;
displayLp . replaceWeaponOfChoice ( ) ;
@ -2160,7 +2156,7 @@ function calculateLifepathSkills($scope, burningData, appropriateWeapons){
if ( name != "General" ) {
lifepathSkills [ name ] = new DisplaySkill ( name , burningData . skills ) ;
}
}
}
}
$scope . lifepathSkills = lifepathSkills ;
@ -2180,20 +2176,20 @@ function calculateTotalSkillPoints($scope){
function calculateUnspentSkillPoints ( $scope ) {
var unspentSkillPoints = {
"lifepath" : $scope . totalSkillPoints . lifepath ,
"lifepath" : $scope . totalSkillPoints . lifepath ,
"general" : $scope . totalSkillPoints . general
}
for ( var key in $scope . lifepathSkills ) {
var skill = $scope . lifepathSkills [ key ]
unspentSkillPoints . lifepath -= skill . lifepathPointsSpent ;
unspentSkillPoints . general -= skill . generalPointsSpent ;
}
for ( var key in $scope . generalSkills ) {
var skill = $scope . generalSkills [ key ]
unspentSkillPoints . lifepath -= skill . lifepathPointsSpent ;
unspentSkillPoints . general -= skill . generalPointsSpent ;
}
@ -2205,7 +2201,7 @@ function openRequiredSkills($scope){
var required = skillsRequiredToBeOpened ( $scope . selectedLifepaths ) ;
var unspentSkillPoints = {
"lifepath" : $scope . unspentSkillPoints . lifepath ,
"lifepath" : $scope . unspentSkillPoints . lifepath ,
"general" : $scope . unspentSkillPoints . general
}
@ -2243,13 +2239,13 @@ function skillsRequiredToBeOpened(lifepaths){
break ;
}
}
}
}
return skillHash ;
}
/ *
When a lifepath is removed , the stat points spent may be more than the available ,
When a lifepath is removed , the stat points spent may be more than the available ,
leading to a negative amount available . This method attempts to correct the situation
by lowering the spent points .
* /
@ -2260,10 +2256,10 @@ function correctStatPoints($scope){
}
/ *
Helper function used by correctStatPoints . This function tries to correct the deficit in
Helper function used by correctStatPoints . This function tries to correct the deficit in
$scope . unspentStatPoints for the specified 'unspentStatField' ( one of physical , mental , or either )
by unspending points from the stats , using the field 'displayStatField'
( one of physicalPointsSpent , mentalPointsSpent , eitherPointsSpent )
by unspending points from the stats , using the field 'displayStatField'
( one of physicalPointsSpent , mentalPointsSpent , eitherPointsSpent )
* /
function correctStatPointsHelperLowerPointsOfType ( $scope , unspentStatField , displayStatField ) {
if ( $scope . unspentStatPoints [ unspentStatField ] < 0 ) {
@ -2286,7 +2282,7 @@ function correctStatPointsHelperLowerPointsOfType($scope, unspentStatField, disp
}
}
}
}
/ * I f t h e u s e r a d d s s o m e g e n e r a l s k i l l s t o t h e c h a r a c t e r a n d t h e n a d d s a l i f e p a t h t h a t h a s t h o s e s k i l l s ,
@ -2309,14 +2305,14 @@ function calculateLifepathTraits($scope, burningData){
for ( var i = 0 ; i < $scope . selectedLifepaths . length ; i ++ ) {
var displayLp = $scope . selectedLifepaths [ i ] ;
totalTraitPoints += displayLp . traitPts ;
for ( var j = 0 ; j < displayLp . traits . length ; j ++ ) {
var name = displayLp . traits [ j ] ;
lifepathTraits [ name ] = new DisplayTrait ( name , burningData . traits ) ;
}
}
}
$scope . lifepathTraits = lifepathTraits ;
@ -2379,7 +2375,7 @@ function traitsRequiredToBeOpened(lifepaths){
break ;
}
}
}
}
return traitHash ;
}
@ -2406,17 +2402,17 @@ function calculateUnspentTraitPoints($scope){
/ *
rexpr are the requires _expr . Returns a two - element list .
The first element is true if the requirements are satisifed , false
otherwise . The second element are any extra conditions if the first
rexpr are the requires _expr . Returns a two - element list .
The first element is true if the requirements are satisifed , false
otherwise . The second element are any extra conditions if the first
element is true . These extra conditions semantically descibe extra conditions
that must _later _ be met , for example " the requirements are satisfied as long as
that must _later _ be met , for example " the requirements are satisfied as long as
the character takes the trait 'your grace' "
The extra conditions supported so far are only a list of trait names .
* /
function areLifepathRequirementsSatisfied ( $scope , rexpr ) {
// make lookup tables
var selectedLifepathsByName = { }
for ( var i = 0 ; i < $scope . selectedLifepaths . length ; i ++ ) {
@ -2426,7 +2422,7 @@ function areLifepathRequirementsSatisfied($scope, rexpr){
for ( var i = 0 ; i < $scope . selectedLifepaths . length ; i ++ ) {
selectedLifepathsBySettingAndName [ $scope . selectedLifepaths [ i ] . setting . toLowerCase ( ) + ":" + $scope . selectedLifepaths [ i ] . name . toLowerCase ( ) ] = true ;
}
var checkHasLifepathIn = function ( rexpr ) {
// This is a [+has_lifepath_in, lp1, lp2, ...] OR [lifepath, lifepath] array.
@ -2511,7 +2507,7 @@ function areLifepathRequirementsSatisfied($scope, rexpr){
console . log ( "Error in areLifepathRequirementsSatisfied when evaluating expression: age_less_than predicate is length < 2 when it must be 2" ) ;
return [ false , [ ] ] ;
}
return [ $scope . age < rexpr [ 1 ] , [ ] ] ;
}
@ -2520,7 +2516,7 @@ function areLifepathRequirementsSatisfied($scope, rexpr){
console . log ( "Error in areLifepathRequirementsSatisfied when evaluating expression: age_greater_than predicate is length < 2 when it must be 2" ) ;
return [ false , [ ] ] ;
}
return [ $scope . age > rexpr [ 1 ] , [ ] ] ;
}
@ -2588,7 +2584,7 @@ function areLifepathRequirementsSatisfied($scope, rexpr){
console . log ( "Error in areLifepathRequirementsSatisfied when evaluating expression: '" + type + "' expression is length " + rexpr . length + " when it must exactly 2" ) ;
return [ false , [ ] ] ;
}
var evalResult = areLifepathRequirementsSatisfied ( $scope , rexpr [ 1 ] ) ;
return [ ! evalResult [ 0 ] , evalResult [ 1 ] ] ;
@ -2666,7 +2662,7 @@ function characterStructValid(charStruct){
}
function calculateTraitWarnings ( $scope , burningData ) {
// Make lookup maps of traits using lower-case trait names
var allTakenTraitNames = { } ;
for ( var key in $scope . purchasedTraits ) {
@ -2688,7 +2684,7 @@ function calculateTraitWarnings($scope, burningData){
var result = areLifepathRequirementsSatisfied ( $scope , rexpr ) ;
for ( var k = 0 ; k < result [ 1 ] . length ; k ++ ) {
var trait = result [ 1 ] [ k ] ;
if ( ! ( trait in allTakenTraitNames ) ) {
traitWarnings . push ( "You must take the '" + trait + "' trait to satisfy the '" + selectedLifepath . name + "' lifepath requirements." ) ;
}
@ -2706,12 +2702,12 @@ function applyBonusesFromTraits($scope) {
for ( var key in $scope . purchasedTraits ) {
var displayTrait = $scope . purchasedTraits [ key ] ;
traitBonuses . addTrait ( key , displayTrait ) ;
}
}
for ( var key in $scope . requiredTraits ) {
var displayTrait = $scope . requiredTraits [ key ] ;
traitBonuses . addTrait ( key , displayTrait ) ;
}
}
for ( var key in $scope . commonTraits ) {
var displayTrait = $scope . commonTraits [ key ] ;
@ -2727,13 +2723,13 @@ function applyBonusesFromTraits($scope) {
var displaySkill = $scope . lifepathSkills [ key ] ;
displaySkill . bonus = traitBonuses . getAddBonusesForSkill ( key ) ;
displaySkill . roundUp = traitBonuses . getRoundUpBonusForSkill ( displaySkill ) ;
}
}
for ( var key in $scope . generalSkills ) {
var displaySkill = $scope . generalSkills [ key ] ;
displaySkill . bonus = traitBonuses . getAddBonusesForSkill ( key ) ;
displaySkill . roundUp = traitBonuses . getRoundUpBonusForSkill ( displaySkill ) ;
}
}
//** Attributes
@ -2752,7 +2748,7 @@ function applyBonusesFromTraits($scope) {
}
/ *
Compute which traits the user can add as special traits . This value depends on character stock so
Compute which traits the user can add as special traits . This value depends on character stock so
this function should be called when stock changes .
* /
function calculateSpecialTraitsForDisplay ( $scope , burningData ) {
@ -2762,7 +2758,7 @@ function calculateSpecialTraitsForDisplay($scope, burningData){
var trait = burningData . traits [ traitName ] ;
if ( 'restrict' in trait ) {
if ( trait . restrict . indexOf ( validStockToRestrictionStock ( $scope . stock ) ) >= 0 &&
if ( trait . restrict . indexOf ( validStockToRestrictionStock ( $scope . stock ) ) >= 0 &&
( trait . restrict . indexOf ( "special" ) >= 0 || trait . restrict . indexOf ( "character" ) >= 0 ) ) {
list . push ( new DisplayTrait ( traitName , burningData . traits ) ) ;
}
@ -2851,7 +2847,7 @@ function validStockToRestrictionStock(stock){
}
function attributeModifyingQuestions ( $scope , attribute )
{
{
var result = [ ] ;
var ageMod = function ( age ) {
@ -2921,8 +2917,8 @@ function attributeModifyingQuestions($scope, attribute)
{ question : "+1 Greed if the character is over 200 years old." , computed : true , compute : ageMod ( 200 ) } ,
{ question : "+1 Greed if the character is over 400 years old." , computed : true , compute : ageMod ( 400 ) } ,
{ question : "Each romantic relationship is -1 Greed. Each hateful relationship is +1 Greed. A hateful immediate family member is +2 Greed." , computed : true , compute : relMod }
) ;
}
) ;
}
else if ( attribute == "Health" )
{
var stockMod = function ( ) {
@ -2946,7 +2942,7 @@ function attributeModifyingQuestions($scope, attribute)
// "herald":1, "bannerman":1, "scout":1, "sergeant":1, "veteran":1, "cavalryman":1, "captain":1, "military order":1}
var steelyLps = { "conscript" : 1 , "squire" : 1 , "knight" : 1 , "bandit" : 1 , "pirate" : 1 , "military order" : 1 , "sword singer" : 1 } ;
var steelySettings = { "professional soldier subsetting" : 1 , "black legion subsetting" : 1 , "dwarven host subsetting" : 1 , "protector subsetting" : 1 } ;
var steel = 0 ;
for ( var i = 0 ; i < $scope . selectedLifepaths . length ; i ++ ) {
if ( $scope . selectedLifepaths [ i ] . name . toLowerCase ( ) in steelyLps || $scope . selectedLifepaths [ i ] . setting . toLowerCase ( ) in steelySettings ) {
@ -3053,23 +3049,23 @@ function attributeModifyingQuestions($scope, attribute)
var lpMod1 = function ( ) {
var lps = { "lancer" : 1 , "lieutenant" : 1 , "captain" : 1 } ;
var lps2 = { "lord protector" : 1 , "soother" : 1 } ;
var grief1 = 0 ;
var grief2 = 0 ;
for ( var i = 0 ; i < $scope . selectedLifepaths . length ; i ++ ) {
if ( $scope . selectedLifepaths [ i ] . name . toLowerCase ( ) in lps )
{
grief1 = 1 ;
if ( grief2 > 0 )
if ( grief2 > 0 )
break ;
}
if ( $scope . selectedLifepaths [ i ] . name . toLowerCase ( ) in lps2 )
{
grief2 = 1 ;
if ( grief1 > 0 )
if ( grief1 > 0 )
break ;
}
}
}
return grief1 + grief2 ;
}
@ -3086,11 +3082,11 @@ function attributeModifyingQuestions($scope, attribute)
var lpMod2 = function ( ) {
var lps = { "loremaster" : 1 , "adjutant" : 1 , "althing" : 1 } ;
for ( var i = 0 ; i < $scope . selectedLifepaths . length ; i ++ ) {
if ( $scope . selectedLifepaths [ i ] . name . toLowerCase ( ) in lps )
return 1 ;
}
}
return 0 ;
}
@ -3130,7 +3126,7 @@ function attributeModifyingQuestions($scope, attribute)
var percMod = function ( ) {
return ( $scope . statsByName [ 'Perception' ] . exp ( ) > 5 ? 1 : 0 ) ;
}
result . push (
{ question : "+1 Grief if the character has taken any Protector lifepath." , computed : true , compute : protectMod } ,
{ question : "+1 Grief if the character has been a Lancer, Lieutenant or Captain; Additional +1 if the character has been a Lord Protector or Soother" , computed : true , compute : lpMod1 } ,
@ -3237,7 +3233,7 @@ function attributeModifyingQuestions($scope, attribute)
var brutalMod = function ( ) {
var count = 0 ;
for ( var i = 0 ; i < $scope . selectedLifepaths . length ; i ++ ) {
if ( $scope . selectedLifepaths [ i ] . brutalLifeTraitName ) {
if ( $scope . selectedLifepaths [ i ] . brutalLifeTraitName ) {
count ++ ;
}
}
@ -3356,7 +3352,7 @@ function convertAttributeModifierQuestionResultsForSave($scope){
// Save only the non-computed questions that were answered.
var result = { } ;
for ( key in $scope . attributeModifierQuestionResults ) {
var list = [ ] ;
@ -3386,7 +3382,7 @@ function convertAttributeModifierQuestionResultsForCharsheet($scope){
var attribute = attributeNames [ j ] ;
var fullQuestions = attributeModifyingQuestions ( $scope , attribute )
if ( ! fullQuestions ) {
// Not an attribute with questions
continue ;
@ -3425,7 +3421,7 @@ function loadAttributeModifierQuestionResultsFromSave($scope, questions)
{
var result = { } ;
// For each attribute for which questions were saved, generate the
// For each attribute for which questions were saved, generate the
// full set of questions, then add in the answers from the save.
// The reason we do this rather than save all questions and answers
// is 1) to save space, and 2) because we can't save the compute function
@ -3454,7 +3450,7 @@ function loadAttributeModifierQuestionResultsFromSave($scope, questions)
/ * *
A number of skills are not defined because they are a specific instance of a general skill ; for example
ancient history is a type of history , and has the same roots . This function returns the parent skill for
ancient history is a type of history , and has the same roots . This function returns the parent skill for
a specific skill .
* /
function getGeneralSkillNameFor ( skillName ) {
@ -3512,7 +3508,7 @@ var computeStatAverage = function(statsByName, statNames, roundUp){
if ( getShade ( stats [ i ] ) == 'G' && ! allGray ) {
sum += 2 ;
}
sum += stats [ i ] . exp ( ) ;
}
@ -3559,11 +3555,11 @@ function calculateGearSelectionLists($scope, burningData) {
$scope . gearListForSelect = [ ] ;
for ( var i = 0 ; i < 3 ; i ++ )
$scope . currentSelectListGear . push ( { } ) ;
$scope . gearListForSelect [ 0 ] = calculateHierarchyListForSelect ( $scope , burningData , 'gear' ) ;
if ( $scope . gearListForSelect [ 0 ] . length > 0 )
$scope . currentSelectListGear [ 0 ] = $scope . gearListForSelect [ 0 ] [ 0 ] ;
$scope . calculateHierarchyListForSelectN ( $scope . gearListForSelect , $scope . currentSelectListGear , 1 ) ;
}
@ -3572,11 +3568,11 @@ function calculatePropertySelectionLists($scope, burningData) {
$scope . propertyListForSelect = [ ] ;
for ( var i = 0 ; i < 3 ; i ++ )
$scope . currentSelectListProperty . push ( { } ) ;
$scope . propertyListForSelect [ 0 ] = calculateHierarchyListForSelect ( $scope , burningData , 'property' ) ;
if ( $scope . propertyListForSelect [ 0 ] . length > 0 )
$scope . currentSelectListProperty [ 0 ] = $scope . propertyListForSelect [ 0 ] [ 0 ] ;
$scope . calculateHierarchyListForSelectN ( $scope . propertyListForSelect , $scope . currentSelectListProperty , 1 ) ;
}