Clothing.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /// <reference path="../Thing.ts" />
  2. interface ClothingOptions extends ThingOptions {
  3. topDescription? : Say;
  4. bottomDescription? : Say;
  5. feetDescription? : Say;
  6. slots? : Array<number>;
  7. layer? : number;
  8. }
  9. interface ClothingWearerValue {
  10. weight : number;
  11. value : number;
  12. }
  13. class Clothing extends Thing {
  14. public slots : Array<number> = [];
  15. public transparentSlots : Array<number> = [];
  16. public layer : number = Clothing.LAYER_MEDIUM;
  17. public isVisible = false;
  18. public visibleOn : Array<number> = [];
  19. // Padding: gets added to current size. Can be negative
  20. // max: If current size > max, current size = max. On -1 this is not considered.
  21. // tight: If current size > tight, person becomes tight. On -1 this is not considered.
  22. // loose: if current size < loose, person becomes loose - can be overriden by covering clothes
  23. // If something is not used, leave as undefined
  24. // Would be fun to make them burst if too much over max, but that's not going to be used right now
  25. public breastPadding : number = 0;
  26. public maxBreastSize : number = -1;
  27. public tightBreastSize : number = -1;
  28. public looseBreastSize : number = 0;
  29. // Padding: gets added to current size. Can be negative
  30. // max: If current size > max, current size = max. On -1 this is not considered.
  31. // tight: If current size > tight, person becomes tight. On -1 this is not considered.
  32. // loose: if current size < loose, person becomes loose - can be overriden by covering clothes
  33. // If something is not used, leave as undefined
  34. // Would be fun to make them burst if too much over max, but that's not going to be used right now
  35. public crotchPadding : number = 0;
  36. public maxCrotchSize : number = -1;
  37. public tightCrotchSize : number = -1;
  38. public looseCrotchSize : number = 0;
  39. // Padding: gets added to current size. Can be negative
  40. // max: If current size > max, current size = max. On -1 this is not considered.
  41. // tight: If current size > tight, person becomes tight. On -1 this is not considered.
  42. // loose: if current size < loose, person becomes loose - can be overriden by covering clothes
  43. // If something is not used, leave as undefined
  44. // Would be fun to make them burst if too much over max, but that's not going to be used right now
  45. public buttPadding : number = 0;
  46. public maxButtSize : number = -1;
  47. public tightButtSize : number = -1;
  48. public looseButtSize : number = 0;
  49. constructor (t : ClothingOptions) {
  50. super(t);
  51. this.layer = t.layer == undefined ? Clothing.LAYER_MEDIUM : t.layer;
  52. this.slots = t.slots == undefined ? [] : [...t.slots];
  53. }
  54. /**
  55. * This function must be called any time anything could change clothing on a person.
  56. * Ripped a clothing? Update all clothes.
  57. * Changed breast size? Update all clothes.
  58. */
  59. public updateStatus () {
  60. this.visibleOn = [];
  61. this.visibleOn.push(...this.slots);
  62. let wearer = Thing.WearRelation.getLeft(this);
  63. if (wearer == undefined) return;
  64. let cloths = Thing.WearRelation.getRight(wearer);
  65. let coveredSlots = [];
  66. for (let i = 0; i < cloths.length; i++) {
  67. let worn = cloths[i];
  68. if ((worn != this) && worn.layer > this.layer) {
  69. coveredSlots.push(...worn.getCoveringSlots());
  70. }
  71. }
  72. this.visibleOn = this.visibleOn.filter(visible => {
  73. return coveredSlots.indexOf(visible) == -1;
  74. });
  75. this.isVisible = this.visibleOn.length > 0;
  76. }
  77. public getCoveringSlots () {
  78. if (this.transparentSlots.length == 0) {
  79. return this.slots.slice(0);
  80. }
  81. return this.slots.filter((value, index, array) => {
  82. return this.transparentSlots.indexOf(value) == -1;
  83. });
  84. }
  85. public static LAYER_LOWEST = 0;
  86. public static LAYER_LOW = 5;
  87. public static LAYER_MEDIUM = 10;
  88. public static LAYER_HIGH = 15;
  89. public static LAYER_HIGHEST = 20;
  90. public genderValue : number = 50;
  91. public sluttinessValue : number = 40;
  92. public getGenderWeight () {
  93. return this.visibleOn.length;
  94. }
  95. public getGenderValue () {
  96. return this.genderValue;
  97. }
  98. public getSluttinessWeight () {
  99. return this.visibleOn.length;
  100. }
  101. public getSluttinessValue () {
  102. return this.sluttinessValue;
  103. }
  104. public static getGenderValueOn (p : Thing) : ClothingWearerValue {
  105. let weight = 0;
  106. let value = 0;
  107. let clothes = Thing.WearRelation.getRight(p);
  108. for (let i = 0; i < clothes.length; i++) {
  109. weight += clothes[i].getGenderWeight();
  110. value += clothes[i].getGenderWeight() * clothes[i].getGenderValue();
  111. }
  112. return {
  113. weight : weight,
  114. value : value
  115. };
  116. }
  117. public static getSluttinessValueOn (p : Thing) : ClothingWearerValue {
  118. let weight = 0;
  119. let value = 0;
  120. let clothes = Thing.WearRelation.getRight(p);
  121. for (let i = 0; i < clothes.length; i++) {
  122. weight += clothes[i].getSluttinessWeight();
  123. value += clothes[i].getSluttinessWeight() * clothes[i].getSluttinessValue();
  124. }
  125. return {
  126. weight : weight,
  127. value : value
  128. };
  129. }
  130. }