import * as Utils from "../utils" ; import MagicItemData from "./magic_items.json" ; import GenericData from "../genericData.json" ; import Names from "../names" ; import { IMagicItemGenerateProps } from "../interfaces" ; const _type = ( ) => Utils . pick ( MagicItemData . types ) ; const _powerLevel = ( ) => Utils . pick ( MagicItemData . power_levels ) ; const _schoolOfMagic = type => { if ( type === "weapon" ) { return Utils . pick ( Object . keys ( MagicItemData . school_weapon_effects_per_level ) ) ; } return Utils . pick ( MagicItemData . schools_of_magic ) ; } ; const _effects = ( schoolOfMagic , powerLevel ) => { const effectsCount = Utils . parseTemplate ( MagicItemData . item_effects_per_level [ powerLevel ] ) ; return Utils . pickMany ( MagicItemData . school_weapon_effects_per_level [ schoolOfMagic ] [ powerLevel ] , parseInt ( effectsCount ) ) . map ( Utils . parseTemplate ) ; } ; const _tagline = formattedData => { const taglineTemplate = Utils . pick ( MagicItemData . tagline_templates ) ; const generationContent = { } ; if ( taglineTemplate . includes ( "tagline_owned_word" ) ) { generationContent . tagline_owned_word = Utils . pick ( MagicItemData . tagline_owned_words ) ; } if ( taglineTemplate . includes ( "owner_first_name_possessive" ) ) { const ownerFirstName = formattedData . owner . split ( " " ) [ 0 ] ; generationContent . owner_first_name_possessive = ownerFirstName . substr ( - 1 ) === "s" ? `${ ownerFirstName }'` : `${ ownerFirstName }'s` ; } return Utils . parseTemplate ( taglineTemplate , generationContent ) ; } ; const generate = ( props = { } ) => { let { seed , type , powerLevel , schoolOfMagic , effects , subtype } = props ; seed = seed || Utils . FantasyContentGeneratorSeed || Utils . generateUUID ( ) ; return Utils . withSeed ( seed , ( ) => { type = type ? type : _type ( ) ; powerLevel = powerLevel ? powerLevel : _powerLevel ( ) ; schoolOfMagic = schoolOfMagic ? schoolOfMagic : _schoolOfMagic ( type ) ; effects = effects ? effects : _effects ( schoolOfMagic , powerLevel ) ; subtype = subtype ? subtype : Utils . pick ( GenericData [ type ] ) ; const formattedData = { } ; switch ( powerLevel ) { case "greater" : case "supreme" : formattedData . owner = Names . generate ( ) . name ; formattedData . tagline = _tagline ( formattedData ) ; break ; } formattedData . title = `${ subtype } of ${ Utils . titleCase ( powerLevel ) } ${ Utils . titleCase ( schoolOfMagic ) }` ; return { seed , type , subtype , powerLevel , schoolOfMagic , effects , formattedData } ; } ) ; } ; const functions = { generate } ; export default functions ;