npc-aspect
Version:
Library for NPC aspect modelling.
3 lines (2 loc) • 8.5 kB
JavaScript
import{random as e,randomFromList as i}from"role-methods";var n,t,a,r,o,s,p,c;!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"}(n||(n={})),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"}(t||(t={})),function(e){e[e.Black=0]="Black",e[e.Brown=1]="Brown",e[e.Blue=2]="Blue",e[e.Green=3]="Green"}(a||(a={})),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"}(r||(r={})),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"}(o||(o={})),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"}(s||(s={})),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"}(c||(c={}));var h=[t.Athletic,t.Fat,t.Skinny,t.Strongman,t.Thin],u=[a.Black,a.Blue,a.Brown,a.Green],g=[r.Black,r.Blond,r.Blue,r.Brown,r.Red,r.White],l=[o.Bald,o.CurvyLong,o.Shaved,o.Short,o.StraightLong],d=[s.African,s.American,s.Arabic,s.Asian,s.European,s.Oceanic],M=[p.Androgynous,p.Female,p.Male],_=[c.Dwarf,c.Elf,c.Goblin,c.Human,c.Orc,c.Troll],m=[n.Kid,n.Midage,n.Old,n.Teenager,n.Young];function f(e){return e>=12&&e<=18?n.Teenager:e>=19&&e<=35?n.Young:e>=36&&e<=65?n.Midage:e>=66?n.Old:n.Kid}function y(e,i){(null==i||i>e.length)&&(i=e.length);for(var n=0,t=new Array(i);n<i;n++)t[n]=e[n];return t}function A(e,i){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,i){if(e){if("string"==typeof e)return y(e,i);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?y(e,i):void 0}}(e))||i&&e&&"number"==typeof e.length){n&&(e=n);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var v=/*#__PURE__*/function(){function f(e,i,n,h,u,g,l,d,M){void 0===e&&(e=p.Male),void 0===i&&(i=s.European),void 0===n&&(n=a.Black),void 0===h&&(h=r.Black),void 0===u&&(u=o.Shaved),void 0===g&&(g=t.Thin),void 0===l&&(l=c.Human),void 0===d&&(d=180),void 0===M&&(M=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=n,this._hair=h,this._haircut=u,this._complexion=g,this._height=d,this._age=M,this._specie=l}var y,A;return f.generateHuman=function(e,i,n,t,a,r,o,s){return new f(e,i,n,t,a,r,c.Human,o,s)},f.generateAgeKindHuman=function(e,i,n,t,a,r,o,s){return this.generateHuman(e,i,n,t,a,r,o,this.getRandomAgeByAgeKind(s))},f.generateRandomAgeKind=function(e){var n=i(_);return new f(i(M),i(d),i(u),i(g),i(l),i(h),n,this.getRandomHeightBySpecie(n),this.getRandomAgeByAgeKind(e))},f.generateOriginHuman=function(e){return this.generateOriginAndSexHuman(e,i(M))},f.generateRandomSpecie=function(e){return this.generateRandomSpecieAndSex(e,i(M))},f.generateOriginAndSexHuman=function(e,n){return this.generateOriginAgeAndSexHuman(e,i(m),n)},f.generateOriginAndAgeHuman=function(e,n){return this.generateOriginAgeAndSexHuman(e,n,i(M))},f.generateOriginAgeAndSexHuman=function(e,n,t){return new f(t,e,i(u),i(g),i(l),i(h),c.Human,this.getRandomHeightBySpecie(c.Human),this.getRandomAgeByAgeKind(n))},f.generateRandomSpecieAndSex=function(e,n){return this.generateRandomSpecieAgeAndSex(e,i(m),n)},f.generateRandomSpecieAndAge=function(e,n){return this.generateRandomSpecieAgeAndSex(e,n,i(M))},f.generateRandomSpecieAgeAndSex=function(e,n,t){return new f(t,i(d),i(u),i(g),i(l),i(h),e,this.getRandomHeightBySpecie(e),this.getRandomAgeByAgeKind(n))},f.prototype.copy=function(){return new f(this._sex,this._origin,this._eye,this._hair,this._haircut,this._complexion,this._specie,this._height,this._age)},f.getRandomAgeByAgeKind=function(i){switch(i){case n.Kid:return 5+e(6);case n.Teenager:return 12+e(6);case n.Young:return 19+e(16);case n.Midage:return 36+e(29);case n.Old:return 66+e(34)}},f.getRandomHeightBySpecie=function(i){var n=150,t=51;return i!=c.Dwarf&&i!=c.Goblin||(n=100,t=61),n+e(t)},y=f,(A=[{key:"sex",get:function(){return this._sex}},{key:"origin",get:function(){return this._origin}},{key:"eye",get:function(){return this._eye}},{key:"hair",get:function(){return this._hair}},{key:"haircut",get:function(){return this._haircut}},{key:"complexion",get:function(){return this._complexion}},{key:"specie",get:function(){return this._specie}},{key:"height",get:function(){return this._height}},{key:"age",get:function(){return this._age}}])&&function(e,i){for(var n=0;n<i.length;n++){var t=i[n];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}(y.prototype,A),Object.defineProperty(y,"prototype",{writable:!1}),f}(),S=/*#__PURE__*/function(){function i(){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()}i.likesSpecie=function(e){var n=new i;return this.minimizeAspectMap(n._specieMap),n._specieMap.set(e,100),n},i.likesSex=function(e){var n=new i;return this.minimizeAspectMap(n._sexMap),n._sexMap.set(e,100),n},i.likesSpecieAndSex=function(e,i){var n=this.likesSpecie(e);return this.minimizeAspectMap(n._sexMap),n._sexMap.set(i,100),n},i.likesConcreteHuman=function(e,i,n,t,a,r,o){return this.likesConcreteSpecie(c.Human,e,i,n,t,a,r,o)},i.likesConcreteSpecie=function(e,i,n,t,a,r,o,s){var p=this.likesSpecieAndSex(e,i);return p._originMap.set(n,100),p._eyeColorMap.set(t,100),p._hairColorMap.set(a,100),p._hairCutMap.set(r,100),p._complexionMap.set(o,100),p._ageMap.set(s,100),p},i.likesAspect=function(e){var n=new i;return n._specieMap.set(e.specie,100),n._sexMap.set(e.sex,100),n._originMap.set(e.origin,100),n._eyeColorMap.set(e.eye,100),n._hairColorMap.set(e.hair,100),n._hairCutMap.set(e.haircut,100),n._complexionMap.set(e.complexion,100),n._ageMap.set(f(e.age),100),n};var n=i.prototype;return n.Eval=function(e){var 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(f(e.age)),(i+=4*this._specieMap.get(e.specie))/14},n.initializeMaps=function(){this.initializeAspectMap(this._sexMap,M),this.initializeAspectMap(this._originMap,d),this.initializeAspectMap(this._eyeColorMap,u),this.initializeAspectMap(this._hairColorMap,g),this.initializeAspectMap(this._hairCutMap,l),this.initializeAspectMap(this._complexionMap,h),this.initializeAspectMap(this._specieMap,_),this.initializeAspectMap(this._ageMap,m)},n.initializeAspectMap=function(i,n){for(var t,a=A(n);!(t=a()).done;)i.set(t.value,e(100))},i.minimizeAspectMap=function(e){for(var i,n=A(e.keys());!(i=n()).done;)e.set(i.value,0)},n.copy=function(){var e=new i;return i.copyMap(this._sexMap,e._sexMap),i.copyMap(this._originMap,e._originMap),i.copyMap(this._eyeColorMap,e._eyeColorMap),i.copyMap(this._hairColorMap,e._hairColorMap),i.copyMap(this._hairCutMap,e._hairCutMap),i.copyMap(this._complexionMap,e._complexionMap),i.copyMap(this._specieMap,e._specieMap),i.copyMap(this._ageMap,e._ageMap),e},i.copyMap=function(e,i){for(var n,t=A(e.keys());!(n=t()).done;){var a=n.value;i.set(a,e.get(a))}},i}();export{n as AgeKind,m as Ages,v as Aspect,t as ComplexionKind,h as Complexions,a as EyeColor,u as Eyes,r as HairColor,g as HairColors,l as HairCuts,o as HaircutStyle,S as Likes,s as OriginKind,d as Origins,p as SexKind,M as Sexes,c as SpecieKind,_ as Species};
//# sourceMappingURL=index.mjs.map