Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CosmeticItem {
- static SLOTS_ENUM: any = {
- HAT: 0,
- HAIR: 1,
- EYES: 2
- };
- protected slotId: number = 0;
- public getSlotId() {
- return this.slotId;
- }
- }
- class CosmeticSlots {
- slots: CosmeticItem[] = [];
- hatSlot: CosmeticItem = null;
- hairSlot: CosmeticItem = null;
- eyesSlot: CosmeticItem = null;
- _addItemToSlot(slotId: number, item: CosmeticItem) {
- if (slotId == CosmeticItem.SLOTS_ENUM.HAT) {
- this.hatSlot = item;
- }
- else if (slotId == CosmeticItem.SLOTS_ENUM.HAIR) {
- this.hairSlot = item;
- }
- else if (slotId == CosmeticItem.SLOTS_ENUM.EYES) {
- this.eyesSlot = item;
- }
- this.slots.push(item);
- }
- //removeItemFromSlot
- addItem(item: CosmeticItem) {
- this._addItemToSlot(item.getSlotId(), item);
- }
- //removeItem
- getItems(): CosmeticItem[] {
- return this.slots;
- }
- getSlot(slotId: number) {
- if (slotId == CosmeticItem.SLOTS_ENUM.HAT) {
- return this.hatSlot;
- }
- else if (slotId == CosmeticItem.SLOTS_ENUM.HAIR) {
- return this.hairSlot;
- }
- else if (slotId == CosmeticItem.SLOTS_ENUM.EYES) {
- return this.eyesSlot;
- }
- return null;
- }
- }
- class CosmeticHat extends CosmeticItem {
- name: string = "";
- someHatSpecificThing: number = 9999;
- constructor(name: string = "") {
- super();
- this.slotId = CosmeticItem.SLOTS_ENUM.HAT;
- this.name = name;
- }
- }
- var mySlots: CosmeticSlots = new CosmeticSlots();
- var myHat: CosmeticHat = new CosmeticHat("super duper hat of ownage");
- mySlots.addItem(myHat);
- mySlots.getSlot(CosmeticItem.SLOTS_ENUM.HAT); //returns the hat
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement