RoomRandomFodder.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /// <reference path="RoomRandom.ts" />
  2. /**
  3. * Fodder is exactly the same as a random room, except:
  4. * 1 - It must be created as needed by a RegionRandom as it attempts to place Tricky rooms.
  5. * 2 - It doesn't count towards a player's maximum remembered rooms
  6. */
  7. enum RandomLootType {
  8. DROPPED_ITEM,
  9. CHEST
  10. }
  11. interface FodderPossibility {
  12. name : string;
  13. description : Say | string;
  14. objects? : Array<Thing>; // Always has these objects
  15. randomLootChance? : number; // 0 to 100, chance of having loot on top of the objects
  16. randomLootType? : RandomLootType; // if randomLootChance succeeds, this will be the type of loot in the room
  17. chestType? : Array<Thing | typeof Thing>; // if randomLootType is chest, chest will be generated using this
  18. maxLootRarity? : number;
  19. minLootRarity? : number; // Level of the random loot generated, from 1 to 10
  20. }
  21. class RoomRandomFodder extends RoomRandom {
  22. public constructor (id? : string) {
  23. super(id, true);
  24. }
  25. public cloneInterface (pos : FodderPossibility) {
  26. this.name = pos.name;
  27. this.description = typeof pos.description == "string" ? new Say(pos.description) : pos.description;
  28. if (pos.objects != undefined) {
  29. for (let i = 0; i < pos.objects.length; i++) {
  30. let object = pos.objects[i];
  31. if (object instanceof Thing) {
  32. this.place(object);
  33. } else if (object == Thing || (<any>object).prototype instanceof Thing) {
  34. this.place(new (<any>object)());
  35. } else if (typeof object == "function") {
  36. object = (<Function> object)();
  37. if (object instanceof Thing) {
  38. this.place(object);
  39. }
  40. }
  41. }
  42. }
  43. if (pos.randomLootChance != undefined && (Math.random() * 100) <= pos.randomLootChance) {
  44. // TODO: Add the loot.
  45. }
  46. }
  47. }