Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class CosmeticItem {
  2.     static SLOTS_ENUM: any = {
  3.         HAT: 0,
  4.         HAIR: 1,
  5.         EYES: 2
  6.     };
  7.  
  8.     protected slotId: number = 0;
  9.  
  10.     public getSlotId() {
  11.         return this.slotId;
  12.     }
  13. }
  14.  
  15.  
  16. class CosmeticSlots {
  17.  
  18.     slots: CosmeticItem[] = [];
  19.  
  20.     hatSlot: CosmeticItem = null;
  21.     hairSlot: CosmeticItem = null;
  22.     eyesSlot: CosmeticItem = null;
  23.  
  24.  
  25.     _addItemToSlot(slotId: number, item: CosmeticItem) {
  26.         if (slotId == CosmeticItem.SLOTS_ENUM.HAT) {
  27.             this.hatSlot = item;
  28.         }
  29.         else if (slotId == CosmeticItem.SLOTS_ENUM.HAIR) {
  30.             this.hairSlot = item;
  31.         }
  32.         else if (slotId == CosmeticItem.SLOTS_ENUM.EYES) {
  33.             this.eyesSlot = item;
  34.         }
  35.         this.slots.push(item);
  36.     }
  37.  
  38.     //removeItemFromSlot
  39.  
  40.     addItem(item: CosmeticItem) {
  41.         this._addItemToSlot(item.getSlotId(), item);
  42.     }
  43.  
  44.     //removeItem
  45.  
  46.     getItems(): CosmeticItem[] {
  47.         return this.slots;
  48.     }
  49.  
  50.     getSlot(slotId: number) {
  51.         if (slotId == CosmeticItem.SLOTS_ENUM.HAT) {
  52.             return this.hatSlot;
  53.         }
  54.         else if (slotId == CosmeticItem.SLOTS_ENUM.HAIR) {
  55.             return this.hairSlot;
  56.         }
  57.         else if (slotId == CosmeticItem.SLOTS_ENUM.EYES) {
  58.             return this.eyesSlot;
  59.         }
  60.         return null;
  61.     }
  62. }
  63.  
  64.  
  65. class CosmeticHat extends CosmeticItem {
  66.     name: string = "";
  67.     someHatSpecificThing: number = 9999;
  68.  
  69.     constructor(name: string = "") {
  70.         super();
  71.         this.slotId = CosmeticItem.SLOTS_ENUM.HAT;
  72.         this.name = name;
  73.     }
  74. }
  75.  
  76.  
  77. var mySlots: CosmeticSlots = new CosmeticSlots();
  78.  
  79. var myHat: CosmeticHat = new CosmeticHat("super duper hat of ownage");
  80.  
  81. mySlots.addItem(myHat);
  82.  
  83. mySlots.getSlot(CosmeticItem.SLOTS_ENUM.HAT); //returns the hat
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement