import * as Utils from "../utils" ; import Names from "../names" ; import NameData from "../names/names.json" ; import NPCData from "./npcs.json" ; import { INPCGenerateProps , INameDomainObject , IRace , INPCDomainObject , ISeed } from "../interfaces" ; const RelationshipKeyWords = [ "mother" , "father" , "son" , "daughter" , "brother" , "sister" ] ; const generate = ( props = { } ) : INPCDomainObject => { let { seed , race , gender , shouldGenerateRelations = true } = props ; seed = seed || Utils . FantasyContentGeneratorSeed || Utils . generateUUID ( ) ; return Utils . withSeed ( seed , ( ) => { race = race ? race : Utils . pick ( Object . keys ( NameData ) ) ; gender = gender ? gender : Utils . randomGender ( ) ; const nameObject = Names . generate ( { race , gender } ) ; const traits = Utils . pickMany ( NPCData . traits , 2 ) . map ( Utils . parseTemplate ) ; const desires = Utils . pickMany ( NPCData . desires , 1 ) . map ( Utils . parseTemplate ) ; let relations = [ ] ; if ( shouldGenerateRelations ) { relations = generateRelationships ( { originalNpcNameObject : nameObject , race , desires , seed } ) ; } return { seed , nameObject , gender , race , traits , desires , formattedData : { name : nameObject . name , firstName : nameObject . firstName , lastName : nameObject . lastName , gender : Utils . titleCase ( gender ) , race : Utils . formatRace ( race ) , traits , desires , relations } , relations } ; } ) ; } ; const generateRelationships = ( { originalNpcNameObject , race , desires , seed } ) => { const relationTitles = getRelationTitlesFromDesires ( desires ) ; return relationTitles . map ( relationTitle => { switch ( relationTitle ) { case "father" : case "mother" : case "brother" : case "sister" : case "son" : case "daughter" : return { relationTitle , npc : generateFamilyMember ( { originalNpcNameObject , race , relationTitle , seed : `${ relationTitle }-${ seed }` } ) } ; } } ) ; } ; const getRelationTitlesFromDesires = ( desires ) => { const concatonatedDesires = desires . join ( ":" ) ; return RelationshipKeyWords . filter ( relationKeyword => concatonatedDesires . includes ( " " + relationKeyword ) ) ; } ; const generateFamilyMember = ( { originalNpcNameObject , race , relationTitle , seed } ) => { let gender = null ; switch ( relationTitle ) { case "father" : case "brother" : case "son" : gender = "male" ; break ; case "mother" : case "sister" : case "daughter" : gender = "female" ; break ; } const generatedRelation = generate ( { race , gender , shouldGenerateRelations : false , seed } ) ; if ( originalNpcNameObject . formattedData . lastName != null && generatedRelation . formattedData . lastName != null ) { generatedRelation . nameObject . name = generatedRelation . nameObject . name . replace ( generatedRelation . formattedData . lastName , originalNpcNameObject . formattedData . lastName ) ; generatedRelation . nameObject . lastName = originalNpcNameObject . lastName ; generatedRelation . formattedData . name = generatedRelation . formattedData . name . replace ( generatedRelation . formattedData . lastName , originalNpcNameObject . formattedData . lastName ) ; generatedRelation . formattedData . lastName = originalNpcNameObject . lastName ; } return generatedRelation ; } ; const generateTrait = ( ) : string => Utils . parseTemplate ( Utils . pick ( NPCData . traits ) ) ; const generateDesire = ( ) : string => Utils . parseTemplate ( Utils . pick ( NPCData . desires ) ) ; const functions = { generate , trait : generateTrait , desire : generateDesire } ; export default functions ;