Bodypart.ts 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /// <reference path="../Thing.ts" />
  2. interface BodypartValueResult {
  3. value : number;
  4. weight : number;
  5. }
  6. class Bodypart extends Thing {
  7. public static WEIGHT_LOWEST = 1;
  8. public static WEIGHT_LOW = 3;
  9. public static WEIGHT_MEDIUM = 5;
  10. public static WEIGHT_HIGH = 7;
  11. public static WEIGHT_HIGHEST = 9;
  12. public static SLUTTINESS_LOWEST_SAINTLY = 0;
  13. public static SLUTTINESS_LOW_PRUDE = 25;
  14. public static SLUTTINESS_MEDIUM_AVERAGE = 50;
  15. public static SLUTTINESS_HIGH_SLUT = 75;
  16. public static SLUTTINESS_HIGHEST_WHORE = 100;
  17. public static GENDER_LOWEST_MANLIEST = 0;
  18. public static GENDER_LOW_MANLY = 25;
  19. public static GENDER_MEDIUM_ANDROGYNE = 50;
  20. public static GENDER_HIGH_FEMININE = 75;
  21. public static GENDER_HIGHEST_FEMININEST = 100;
  22. // The higher this number, the more the bodypart will be worth for health.
  23. // For instance, HEAD should be worth more than FINGERNAIL.
  24. public sorenessWeight : number = 1;
  25. // 0 to 10
  26. // says how fucked up the bodypart is
  27. public soreness : number = 0;
  28. // How much soreness is healed every turn
  29. public sorenessPerTurn : number = 0.05;
  30. // Last turn soreness got updated
  31. public lastSorenessUpdate : number = 0;
  32. public constructor (options? : ThingOptions) {
  33. super(options);
  34. this.addGetAlterations((bp : Bodypart) => {
  35. return {
  36. Soreness : bp.soreness,
  37. GenderValue : bp.genderValue,
  38. Sluttiness : bp.getSluttiness()
  39. }
  40. });
  41. this.addSetAlterations((bp : Bodypart, changes) => {
  42. this.soreness = changes.Soreness;
  43. this.genderValue = changes.GenderValue;
  44. this.sluttiness = changes.Sluttiness;
  45. });
  46. }
  47. public updateSoreness () {
  48. let cTurn = WorldState.getCurrentTurn();
  49. if (cTurn > this.lastSorenessUpdate) {
  50. if (this.soreness > 0) {
  51. this.soreness -= (this.sorenessPerTurn * (cTurn - this.lastSorenessUpdate));
  52. if (this.soreness < 0) {
  53. this.soreness = 0;
  54. }
  55. }
  56. this.lastSorenessUpdate = cTurn;
  57. }
  58. }
  59. public changeSoreness (soreness : number) {
  60. this.updateSoreness();
  61. this.soreness += soreness;
  62. if (this.soreness < 0) {
  63. this.soreness = 0;
  64. }
  65. }
  66. public getSoreness () {
  67. this.updateSoreness();
  68. return this.soreness;
  69. }
  70. public getWeightedSoreness() {
  71. return this.getSoreness() * this.sorenessWeight;
  72. }
  73. public getSorenessWeight () {
  74. return this.sorenessWeight;
  75. }
  76. // These are the slots the bodypart is visible on
  77. // Should use Humanoid.SLOT_* !
  78. public slots : Array<number> = [];
  79. public visibleSlots : Array<number> = [];
  80. // GenderValue is how masculine/feminine this bodypart is.
  81. // At 0 = the most masculine possible, at 100 = the most feminine eveter
  82. // 50 would be completely androgynous
  83. public genderValue : number = Bodypart.GENDER_MEDIUM_ANDROGYNE;
  84. // Like with health, the weight makes this bodypart matter more for deciding gender.
  85. // Gender presentation is not about prettiness, so, for instance, having huge breasts will
  86. // strongly push you to the "is a woman" side, even if you're manly as fuck everywhere else.
  87. // If you're too manly everywhere else, though, you'll probably end up closer on the spectrum to male
  88. // or at least androgynous, which might result in not passing.
  89. public genderWeight : number = 1;
  90. /**
  91. * Sluttiness goes from 0 to 100.
  92. * A bodypart's sluttiness is dependent on it being seen.
  93. * @type {number}
  94. */
  95. public sluttiness : number = 10;
  96. public sluttinessWeight : number = Bodypart.WEIGHT_LOWEST;
  97. public getGenderWeight () {
  98. if (this.slots.length == 0) {
  99. return 0;
  100. }
  101. return this.genderWeight * (this.visibleSlots.length / this.slots.length);
  102. }
  103. public getGenderValue () {
  104. return this.genderValue;
  105. }
  106. public getWeightedGenderValue () {
  107. return this.getGenderValue() * this.getGenderWeight();
  108. }
  109. public getSluttiness() {
  110. return this.sluttiness;
  111. }
  112. public getSluttinessWeight () {
  113. if (this.slots.length == 0) {
  114. return 0;
  115. }
  116. return this.sluttinessWeight * (this.visibleSlots.length / this.slots.length);
  117. }
  118. public getWeightedSluttinessValue () {
  119. return this.getSluttiness() * this.getSluttinessWeight();
  120. }
  121. public updateVisibility () {
  122. this.visibleSlots = this.slots.slice(0);
  123. let parent = Thing.PartRelation.getLeft(this);
  124. if (parent != undefined) {
  125. let clothing = <Array<Clothing>>Thing.WearRelation.getRight(parent);
  126. for (let i = 0; i < clothing.length; i++) {
  127. let covering = clothing[i].getCoveringSlots();
  128. for (let k = 0; k < covering.length; k++) {
  129. let idx = this.visibleSlots.indexOf(covering[k]);
  130. if (idx >= 0) {
  131. this.visibleSlots.splice(idx, 1);
  132. }
  133. }
  134. if (this.visibleSlots.length == 0) break;
  135. }
  136. }
  137. }
  138. public isUncovered () {
  139. this.updateVisibility();
  140. return this.visibleSlots.length == this.slots.length && this.slots.length > 0;
  141. }
  142. public updateStatus () {
  143. this.updateVisibility();
  144. }
  145. public static getSoreness (thing : Thing) {
  146. let bodyparts = Thing.PartRelation.getRightType(thing, Bodypart);
  147. let soreness = 0;
  148. bodyparts.forEach((bodypart : Bodypart) => {
  149. soreness += bodypart.getWeightedSoreness();
  150. });
  151. return soreness;
  152. }
  153. public static getGenderValueOn (thing : Thing) : BodypartValueResult {
  154. let weight = 0;
  155. let value = 0;
  156. let bodyparts = Thing.PartRelation.getRightType(thing, Bodypart);
  157. bodyparts.forEach((bodypart : Bodypart) => {
  158. weight += bodypart.getGenderWeight();
  159. value += bodypart.getWeightedGenderValue();
  160. });
  161. return {
  162. weight : weight,
  163. value : value
  164. };
  165. }
  166. public static getSluttinessValueOn (thing : Thing) : BodypartValueResult {
  167. let weight = 0;
  168. let value = 0;
  169. let bodyparts = Thing.PartRelation.getRightType(thing, Bodypart);
  170. bodyparts.forEach((bodypart : Bodypart) => {
  171. weight += bodypart.getSluttinessWeight();
  172. value += bodypart.getWeightedSluttinessValue();
  173. });
  174. return {
  175. weight : weight,
  176. value : value
  177. };
  178. }
  179. /**
  180. * Changes the bodypart so that it matches the desired genderValue.
  181. * This needs to be implemented in all classes inheriting from Bodypart, as not all bodyparts have a simple "genderValue" to assign.
  182. * @param {number} genderValue
  183. */
  184. public arrangeGenderValue (genderValue : number) {
  185. this.genderValue = genderValue;
  186. (<Humanoid> this.getPartOne()).invalidateCaches();
  187. }
  188. /**
  189. * Attempts to increase Femininity by 5 * amount. Will read Current Gender Value and try to reassign it.
  190. * @param {number} amount
  191. */
  192. public increaseFemininity (amount : number) {
  193. let currentGV = this.getGenderValue();
  194. this.arrangeGenderValue(currentGV + (5 * amount));
  195. }
  196. /**
  197. * Attempts to increase Masculinity by 5 * amount. Will read Current Gender Value and try to reassign it.
  198. * @param {number} amount
  199. */
  200. public increaseMasculinity (amount : number) {
  201. let currentGV = this.getGenderValue();
  202. this.arrangeGenderValue(currentGV - (5 * amount));
  203. }
  204. }