UNPKG

npc-aspect

Version:

Library for NPC aspect modelling.

3 lines (2 loc) 6.8 kB
import{randomFromList as e,random as i}from"role-methods";var t,a,n,s,r,o,p,h;!function(e){e[e.Kid=0]="Kid",e[e.Teenager=1]="Teenager",e[e.Young=2]="Young",e[e.Midage=3]="Midage",e[e.Old=4]="Old"}(t||(t={})),function(e){e[e.Skinny=0]="Skinny",e[e.Thin=1]="Thin",e[e.Fat=2]="Fat",e[e.Athletic=3]="Athletic",e[e.Strongman=4]="Strongman"}(a||(a={})),function(e){e[e.Black=0]="Black",e[e.Brown=1]="Brown",e[e.Blue=2]="Blue",e[e.Green=3]="Green"}(n||(n={})),function(e){e[e.White=0]="White",e[e.Black=1]="Black",e[e.Brown=2]="Brown",e[e.Red=3]="Red",e[e.Blond=4]="Blond",e[e.Blue=5]="Blue"}(s||(s={})),function(e){e[e.Shaved=0]="Shaved",e[e.Short=1]="Short",e[e.StraightLong=2]="StraightLong",e[e.CurvyLong=3]="CurvyLong",e[e.Bald=4]="Bald"}(r||(r={})),function(e){e[e.European=0]="European",e[e.African=1]="African",e[e.Asian=2]="Asian",e[e.American=3]="American",e[e.Arabic=4]="Arabic",e[e.Oceanic=5]="Oceanic"}(o||(o={})),function(e){e[e.Male=0]="Male",e[e.Female=1]="Female",e[e.Androgynous=2]="Androgynous"}(p||(p={})),function(e){e[e.Human=0]="Human",e[e.Dwarf=1]="Dwarf",e[e.Elf=2]="Elf",e[e.Goblin=3]="Goblin",e[e.Orc=4]="Orc",e[e.Troll=5]="Troll"}(h||(h={}));const c=[a.Athletic,a.Fat,a.Skinny,a.Strongman,a.Thin],g=[n.Black,n.Blue,n.Brown,n.Green],l=[s.Black,s.Blond,s.Blue,s.Brown,s.Red,s.White],M=[r.Bald,r.CurvyLong,r.Shaved,r.Short,r.StraightLong],_=[o.African,o.American,o.Arabic,o.Asian,o.European,o.Oceanic],u=[p.Androgynous,p.Female,p.Male],d=[h.Dwarf,h.Elf,h.Goblin,h.Human,h.Orc,h.Troll],m=[t.Kid,t.Midage,t.Old,t.Teenager,t.Young];function A(e){return e>=12&&e<=18?t.Teenager:e>=19&&e<=35?t.Young:e>=36&&e<=65?t.Midage:e>=66?t.Old:t.Kid}class x{constructor(e=p.Male,i=o.European,t=n.Black,c=s.Black,g=r.Shaved,l=a.Thin,M=h.Human,_=180,u=30){this._sex=void 0,this._origin=void 0,this._eye=void 0,this._hair=void 0,this._haircut=void 0,this._complexion=void 0,this._specie=void 0,this._height=void 0,this._age=void 0,this._sex=e,this._origin=i,this._eye=t,this._hair=c,this._haircut=g,this._complexion=l,this._height=_,this._age=u,this._specie=M}get sex(){return this._sex}get origin(){return this._origin}get eye(){return this._eye}get hair(){return this._hair}get haircut(){return this._haircut}get complexion(){return this._complexion}get specie(){return this._specie}get height(){return this._height}get age(){return this._age}static generateHuman(e,i,t,a,n,s,r,o){return new x(e,i,t,a,n,s,h.Human,r,o)}static generateAgeKindHuman(e,i,t,a,n,s,r,o){return this.generateHuman(e,i,t,a,n,s,r,this.getRandomAgeByAgeKind(o))}static generateRandomAgeKind(i){let t=e(d);return new x(e(u),e(_),e(g),e(l),e(M),e(c),t,this.getRandomHeightBySpecie(t),this.getRandomAgeByAgeKind(i))}static generateOriginHuman(i){return this.generateOriginAndSexHuman(i,e(u))}static generateRandomSpecie(i){return this.generateRandomSpecieAndSex(i,e(u))}static generateOriginAndSexHuman(i,t){return this.generateOriginAgeAndSexHuman(i,e(m),t)}static generateOriginAndAgeHuman(i,t){return this.generateOriginAgeAndSexHuman(i,t,e(u))}static generateOriginAgeAndSexHuman(i,t,a){return new x(a,i,e(g),e(l),e(M),e(c),h.Human,this.getRandomHeightBySpecie(h.Human),this.getRandomAgeByAgeKind(t))}static generateRandomSpecieAndSex(i,t){return this.generateRandomSpecieAgeAndSex(i,e(m),t)}static generateRandomSpecieAndAge(i,t){return this.generateRandomSpecieAgeAndSex(i,t,e(u))}static generateRandomSpecieAgeAndSex(i,t,a){return new x(a,e(_),e(g),e(l),e(M),e(c),i,this.getRandomHeightBySpecie(i),this.getRandomAgeByAgeKind(t))}copy(){return new x(this._sex,this._origin,this._eye,this._hair,this._haircut,this._complexion,this._specie,this._height,this._age)}static getRandomAgeByAgeKind(e){switch(e){case t.Kid:return 5+i(6);case t.Teenager:return 12+i(6);case t.Young:return 19+i(16);case t.Midage:return 36+i(29);case t.Old:return 66+i(34)}}static getRandomHeightBySpecie(e){let t=150,a=51;return e!=h.Dwarf&&e!=h.Goblin||(t=100,a=61),t+i(a)}}class y{constructor(){this._sexMap=void 0,this._originMap=void 0,this._eyeColorMap=void 0,this._hairColorMap=void 0,this._hairCutMap=void 0,this._complexionMap=void 0,this._specieMap=void 0,this._ageMap=void 0,this._sexMap=new Map,this._originMap=new Map,this._eyeColorMap=new Map,this._hairColorMap=new Map,this._hairCutMap=new Map,this._complexionMap=new Map,this._specieMap=new Map,this._ageMap=new Map,this.initializeMaps()}static likesSpecie(e){let i=new y;return this.minimizeAspectMap(i._specieMap),i._specieMap.set(e,100),i}static likesSex(e){let i=new y;return this.minimizeAspectMap(i._sexMap),i._sexMap.set(e,100),i}static likesSpecieAndSex(e,i){let t=this.likesSpecie(e);return this.minimizeAspectMap(t._sexMap),t._sexMap.set(i,100),t}static likesConcreteHuman(e,i,t,a,n,s,r){return this.likesConcreteSpecie(h.Human,e,i,t,a,n,s,r)}static likesConcreteSpecie(e,i,t,a,n,s,r,o){let p=this.likesSpecieAndSex(e,i);return p._originMap.set(t,100),p._eyeColorMap.set(a,100),p._hairColorMap.set(n,100),p._hairCutMap.set(s,100),p._complexionMap.set(r,100),p._ageMap.set(o,100),p}static likesAspect(e){let i=new y;return i._specieMap.set(e.specie,100),i._sexMap.set(e.sex,100),i._originMap.set(e.origin,100),i._eyeColorMap.set(e.eye,100),i._hairColorMap.set(e.hair,100),i._hairCutMap.set(e.haircut,100),i._complexionMap.set(e.complexion,100),i._ageMap.set(A(e.age),100),i}Eval(e){let i=4*this._sexMap.get(e.sex);return i+=this._originMap.get(e.origin),i+=this._eyeColorMap.get(e.eye),i+=this._hairColorMap.get(e.hair),i+=this._hairCutMap.get(e.haircut),i+=this._complexionMap.get(e.complexion),i+=this._ageMap.get(A(e.age)),i+=4*this._specieMap.get(e.specie),i/14}initializeMaps(){this.initializeAspectMap(this._sexMap,u),this.initializeAspectMap(this._originMap,_),this.initializeAspectMap(this._eyeColorMap,g),this.initializeAspectMap(this._hairColorMap,l),this.initializeAspectMap(this._hairCutMap,M),this.initializeAspectMap(this._complexionMap,c),this.initializeAspectMap(this._specieMap,d),this.initializeAspectMap(this._ageMap,m)}initializeAspectMap(e,t){for(let a of t)e.set(a,i(100))}static minimizeAspectMap(e){for(let i of e.keys())e.set(i,0)}copy(){let e=new y;return y.copyMap(this._sexMap,e._sexMap),y.copyMap(this._originMap,e._originMap),y.copyMap(this._eyeColorMap,e._eyeColorMap),y.copyMap(this._hairColorMap,e._hairColorMap),y.copyMap(this._hairCutMap,e._hairCutMap),y.copyMap(this._complexionMap,e._complexionMap),y.copyMap(this._specieMap,e._specieMap),y.copyMap(this._ageMap,e._ageMap),e}static copyMap(e,i){for(let t of e.keys())i.set(t,e.get(t))}}export{t as AgeKind,m as Ages,x as Aspect,a as ComplexionKind,c as Complexions,n as EyeColor,g as Eyes,s as HairColor,l as HairColors,M as HairCuts,r as HaircutStyle,y as Likes,o as OriginKind,_ as Origins,p as SexKind,u as Sexes,h as SpecieKind,d as Species}; //# sourceMappingURL=index.modern.js.map