"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Inventory = void 0;
const JSONTemplate_1 = require("modloader64_api/JSONTemplate");
const Z64API = __importStar(require("../../API/imports"));
const Z64CORE = __importStar(require("../importsZ64"));
class Inventory extends JSONTemplate_1.JSONTemplate {
    emulator;
    instance = Z64CORE.Z64.Z64_SAVE;
    inventory_addr = this.instance + 0x0074;
    inventory_ammo_addr = this.instance + 0x008c;
    inventory_upgrades_addr = this.instance + 0x00a0;
    log;
    jsonFields = [
        'dekuSticks',
        'dekuNuts',
        'bombs',
        'bombchus',
        'magicBeans',
        'magicBeansCount',
        'fairySlingshot',
        'fairyBow',
        'fireArrows',
        'iceArrows',
        'lightArrows',
        'dinsFire',
        'faroresWind',
        'nayrusLove',
        'ocarina',
        'hookshot',
        'boomerang',
        'lensOfTruth',
        'megatonHammer',
        'bottle_1',
        'bottle_2',
        'bottle_3',
        'bottle_4',
        'childTradeItem',
        'adultTradeItem',
        'wallet',
        'quiver',
        'bulletBag',
        'bombBag',
        'dekuNutsCapacity',
        'dekuSticksCapacity',
        'swimming',
        'strength',
    ];
    constructor(emu, log) {
        super();
        this.emulator = emu;
        this.log = log;
    }
    set strength(bb) {
        let buf = this.emulator.rdramReadBits8(this.inventory_upgrades_addr + 0x3);
        switch (bb) {
            case 0 /* Z64API.OoT.Strength.NONE */:
                buf[0x0] = 0x00;
                buf[0x1] = 0x00;
                break;
            case 1 /* Z64API.OoT.Strength.GORON_BRACELET */:
                buf[0x0] = 0x00;
                buf[0x1] = 0x01;
                break;
            case 2 /* Z64API.OoT.Strength.SILVER_GAUNTLETS */:
                buf[0x0] = 0x01;
                buf[0x1] = 0x00;
                break;
            case 3 /* Z64API.OoT.Strength.GOLDEN_GAUNTLETS */:
                buf[0x0] = 0x01;
                buf[0x1] = 0x01;
                break;
        }
        this.emulator.rdramWriteBits8(this.inventory_upgrades_addr + 0x3, buf);
    }
    get strength() {
        let buf = this.emulator.rdramReadBits8(this.inventory_upgrades_addr + 0x3);
        let str = buf.slice(0, 2).toString('hex');
        switch (str) {
            case '0000':
                return 0 /* Z64API.OoT.Strength.NONE */;
            case '0001':
                return 1 /* Z64API.OoT.Strength.GORON_BRACELET */;
            case '0100':
                return 2 /* Z64API.OoT.Strength.SILVER_GAUNTLETS */;
            case '0101':
                return 3 /* Z64API.OoT.Strength.GOLDEN_GAUNTLETS */;
        }
        return 0 /* Z64API.OoT.Strength.NONE */;
    }
    set swimming(bb) {
        let buf = this.emulator.rdramReadBits8(this.inventory_upgrades_addr + 0x2);
        switch (bb) {
            case 0 /* Z64API.OoT.ZoraScale.NONE */:
                buf[0x5] = 0x00;
                buf[0x6] = 0x00;
                break;
            case 1 /* Z64API.OoT.ZoraScale.SILVER */:
                buf[0x5] = 0x00;
                buf[0x6] = 0x01;
                break;
            case 2 /* Z64API.OoT.ZoraScale.GOLDEN */:
                buf[0x5] = 0x01;
                buf[0x6] = 0x00;
                break;
        }
        this.emulator.rdramWriteBits8(this.inventory_upgrades_addr + 0x2, buf);
    }
    get swimming() {
        let buf = this.emulator.rdramReadBits8(this.inventory_upgrades_addr + 0x2);
        let str = buf.slice(5, 7).toString('hex');
        switch (str) {
            case '0000':
                return 0 /* Z64API.OoT.ZoraScale.NONE */;
            case '0001':
                return 1 /* Z64API.OoT.ZoraScale.SILVER */;
            case '0100':
                return 2 /* Z64API.OoT.ZoraScale.GOLDEN */;
        }
        return 0 /* Z64API.OoT.ZoraScale.NONE */;
    }
    set dekuSticksCapacity(bb) {
        let buf = this.emulator.rdramReadBits8(this.inventory_upgrades_addr + 0x1);
        switch (bb) {
            case 0 /* Z64API.Z64.AmmoUpgrade.NONE */:
                buf[0x5] = 0x00;
                buf[0x6] = 0x00;
                break;
            case 1 /* Z64API.Z64.AmmoUpgrade.BASE */:
                buf[0x5] = 0x00;
                buf[0x6] = 0x01;
                break;
            case 2 /* Z64API.Z64.AmmoUpgrade.UPGRADED */:
                buf[0x5] = 0x01;
                buf[0x6] = 0x00;
                break;
            case 3 /* Z64API.Z64.AmmoUpgrade.MAX */:
                buf[0x5] = 0x01;
                buf[0x6] = 0x01;
                break;
        }
        this.emulator.rdramWriteBits8(this.inventory_upgrades_addr + 0x1, buf);
    }
    get dekuSticksCapacity() {
        let buf = this.emulator.rdramReadBits8(this.inventory_upgrades_addr + 0x1);
        let str = buf.slice(5, 7).toString('hex');
        switch (str) {
            case '0000':
                return 0 /* Z64API.Z64.AmmoUpgrade.NONE */;
            case '0001':
                return 1 /* Z64API.Z64.AmmoUpgrade.BASE */;
            case '0100':
                return 2 /* Z64API.Z64.AmmoUpgrade.UPGRADED */;
            case '0101':
                return 3 /* Z64API.Z64.AmmoUpgrade.MAX */;
        }
        return 0 /* Z64API.Z64.AmmoUpgrade.NONE */;
    }
    set dekuNutsCapacity(bb) {
        let buf = this.emulator.rdramReadBits8(this.inventory_upgrades_addr + 0x1);
        switch (bb) {
            case 0 /* Z64API.Z64.AmmoUpgrade.NONE */:
                buf[0x2] = 0x00;
                buf[0x3] = 0x00;
                break;
            case 1 /* Z64API.Z64.AmmoUpgrade.BASE */:
                buf[0x2] = 0x00;
                buf[0x3] = 0x01;
                break;
            case 2 /* Z64API.Z64.AmmoUpgrade.UPGRADED */:
                buf[0x2] = 0x01;
                buf[0x3] = 0x00;
                break;
            case 3 /* Z64API.Z64.AmmoUpgrade.MAX */:
                buf[0x2] = 0x01;
                buf[0x3] = 0x01;
                break;
        }
        this.emulator.rdramWriteBits8(this.inventory_upgrades_addr + 0x1, buf);
    }
    get dekuNutsCapacity() {
        let buf = this.emulator.rdramReadBits8(this.inventory_upgrades_addr + 0x1);
        let str = buf.slice(2, 4).toString('hex');
        switch (str) {
            case '0000':
                return 0 /* Z64API.Z64.AmmoUpgrade.NONE */;
            case '0001':
                return 1 /* Z64API.Z64.AmmoUpgrade.BASE */;
            case '0100':
                return 2 /* Z64API.Z64.AmmoUpgrade.UPGRADED */;
            case '0101':
                return 3 /* Z64API.Z64.AmmoUpgrade.MAX */;
        }
        return 0 /* Z64API.Z64.AmmoUpgrade.NONE */;
    }
    set bombBag(bb) {
        let buf = this.emulator.rdramReadBits8(this.inventory_upgrades_addr + 0x3);
        switch (bb) {
            case 0 /* Z64API.Z64.AmmoUpgrade.NONE */:
                buf[0x3] = 0x00;
                buf[0x4] = 0x00;
                break;
            case 1 /* Z64API.Z64.AmmoUpgrade.BASE */:
                buf[0x3] = 0x00;
                buf[0x4] = 0x01;
                break;
            case 2 /* Z64API.Z64.AmmoUpgrade.UPGRADED */:
                buf[0x3] = 0x01;
                buf[0x4] = 0x00;
                break;
            case 3 /* Z64API.Z64.AmmoUpgrade.MAX */:
                buf[0x3] = 0x01;
                buf[0x4] = 0x01;
                break;
        }
        this.emulator.rdramWriteBits8(this.inventory_upgrades_addr + 0x3, buf);
    }
    get bombBag() {
        let buf = this.emulator.rdramReadBits8(this.inventory_upgrades_addr + 0x3);
        let str = buf.slice(3, 5).toString('hex');
        switch (str) {
            case '0000':
                return 0 /* Z64API.Z64.AmmoUpgrade.NONE */;
            case '0001':
                return 1 /* Z64API.Z64.AmmoUpgrade.BASE */;
            case '0100':
                return 2 /* Z64API.Z64.AmmoUpgrade.UPGRADED */;
            case '0101':
                return 3 /* Z64API.Z64.AmmoUpgrade.MAX */;
        }
        return 0 /* Z64API.Z64.AmmoUpgrade.NONE */;
    }
    get bulletBag() {
        let buf = this.emulator.rdramReadBits8(this.inventory_upgrades_addr + 0x2);
        let str = buf.slice(0, 2).toString('hex');
        switch (str) {
            case '0000':
                return 0 /* Z64API.Z64.AmmoUpgrade.NONE */;
            case '0001':
                return 1 /* Z64API.Z64.AmmoUpgrade.BASE */;
            case '0100':
                return 2 /* Z64API.Z64.AmmoUpgrade.UPGRADED */;
            case '0101':
                return 3 /* Z64API.Z64.AmmoUpgrade.MAX */;
        }
        return 0 /* Z64API.Z64.AmmoUpgrade.NONE */;
    }
    set bulletBag(bb) {
        let buf = this.emulator.rdramReadBits8(this.inventory_upgrades_addr + 0x2);
        switch (bb) {
            case 0 /* Z64API.Z64.AmmoUpgrade.NONE */:
                buf[0x0] = 0x00;
                buf[0x1] = 0x00;
                break;
            case 1 /* Z64API.Z64.AmmoUpgrade.BASE */:
                buf[0x0] = 0x00;
                buf[0x1] = 0x01;
                break;
            case 2 /* Z64API.Z64.AmmoUpgrade.UPGRADED */:
                buf[0x0] = 0x01;
                buf[0x1] = 0x00;
                break;
            case 3 /* Z64API.Z64.AmmoUpgrade.MAX */:
                buf[0x0] = 0x01;
                buf[0x1] = 0x01;
                break;
        }
        this.emulator.rdramWriteBits8(this.inventory_upgrades_addr + 0x2, buf);
    }
    get quiver() {
        let buf = this.emulator.rdramReadBits8(this.inventory_upgrades_addr + 0x3);
        let str = buf.slice(6, 8).toString('hex');
        switch (str) {
            case '0000':
                return 0 /* Z64API.Z64.AmmoUpgrade.NONE */;
            case '0001':
                return 1 /* Z64API.Z64.AmmoUpgrade.BASE */;
            case '0100':
                return 2 /* Z64API.Z64.AmmoUpgrade.UPGRADED */;
            case '0101':
                return 3 /* Z64API.Z64.AmmoUpgrade.MAX */;
        }
        return 0 /* Z64API.Z64.AmmoUpgrade.NONE */;
    }
    set quiver(q) {
        let buf = this.emulator.rdramReadBits8(this.inventory_upgrades_addr + 0x3);
        switch (q) {
            case 0 /* Z64API.Z64.AmmoUpgrade.NONE */:
                buf[0x6] = 0x00;
                buf[0x7] = 0x00;
                break;
            case 1 /* Z64API.Z64.AmmoUpgrade.BASE */:
                buf[0x6] = 0x00;
                buf[0x7] = 0x01;
                break;
            case 2 /* Z64API.Z64.AmmoUpgrade.UPGRADED */:
                buf[0x6] = 0x01;
                buf[0x7] = 0x00;
                break;
            case 3 /* Z64API.Z64.AmmoUpgrade.MAX */:
                buf[0x6] = 0x01;
                buf[0x7] = 0x01;
                break;
        }
        this.emulator.rdramWriteBits8(this.inventory_upgrades_addr + 0x3, buf);
    }
    get wallet() {
        let buf = this.emulator.rdramReadBits8(this.inventory_upgrades_addr + 0x2);
        let str = buf.slice(2, 4).toString('hex');
        switch (str) {
            case '0000':
                return Z64API.Z64.Wallet.CHILD;
            case '0001':
                return Z64API.Z64.Wallet.ADULT;
            case '0100':
                return Z64API.Z64.Wallet.GIANT;
            case '0101':
                return Z64API.Z64.Wallet.TYCOON;
        }
        return Z64API.Z64.Wallet.CHILD;
    }
    set wallet(w) {
        let buf = this.emulator.rdramReadBits8(this.inventory_upgrades_addr + 0x2);
        switch (w) {
            case Z64API.Z64.Wallet.CHILD:
                buf[0x2] = 0x00;
                buf[0x3] = 0x00;
                break;
            case Z64API.Z64.Wallet.ADULT:
                buf[0x2] = 0x00;
                buf[0x3] = 0x01;
                break;
            case Z64API.Z64.Wallet.GIANT:
                buf[0x2] = 0x10;
                buf[0x3] = 0x00;
                break;
            case Z64API.Z64.Wallet.TYCOON:
                buf[0x2] = 0x01;
                buf[0x3] = 0x01;
        }
        this.emulator.rdramWriteBits8(this.inventory_upgrades_addr + 0x2, buf);
    }
    getMaxRupeeCount() {
        let addr = 0x800F8CEC;
        let capacities = [];
        for (let i = 0; i < 8; i += 2) {
            capacities.push(this.emulator.rdramRead16(addr + i));
        }
        return capacities[this.wallet];
    }
    get dekuSticks() {
        let val = this.getItemInSlot(0 /* Z64API.OoT.InventorySlots.DEKU_STICKS */);
        return !(val === 255 /* Z64API.OoT.InventoryItem.NONE */);
    }
    set dekuSticks(bool) {
        let value = bool ? 0 /* Z64API.OoT.InventoryItem.DEKU_STICK */ : 255 /* Z64API.OoT.InventoryItem.NONE */;
        this.setItemInSlot(value, 0 /* Z64API.OoT.InventorySlots.DEKU_STICKS */);
    }
    get dekuSticksCount() {
        return this.getAmmoForSlot(0 /* Z64API.OoT.InventorySlots.DEKU_STICKS */);
    }
    set dekuSticksCount(count) {
        this.setAmmoInSlot(0 /* Z64API.OoT.InventorySlots.DEKU_STICKS */, count);
    }
    get dekuNuts() {
        let val = this.getItemInSlot(1 /* Z64API.OoT.InventorySlots.DEKU_NUTS */);
        return !(val === 255 /* Z64API.OoT.InventoryItem.NONE */);
    }
    set dekuNuts(bool) {
        let value = bool ? 1 /* Z64API.OoT.InventoryItem.DEKU_NUT */ : 255 /* Z64API.OoT.InventoryItem.NONE */;
        this.setItemInSlot(value, 1 /* Z64API.OoT.InventorySlots.DEKU_NUTS */);
    }
    get dekuNutsCount() {
        return this.getAmmoForSlot(1 /* Z64API.OoT.InventorySlots.DEKU_NUTS */);
    }
    set dekuNutsCount(count) {
        this.setAmmoInSlot(1 /* Z64API.OoT.InventorySlots.DEKU_NUTS */, count);
    }
    get bombs() {
        let val = this.getItemInSlot(2 /* Z64API.OoT.InventorySlots.BOMBS */);
        return !(val === 255 /* Z64API.OoT.InventoryItem.NONE */);
    }
    set bombs(bool) {
        let value = bool ? 2 /* Z64API.OoT.InventoryItem.BOMB */ : 255 /* Z64API.OoT.InventoryItem.NONE */;
        this.setItemInSlot(value, 2 /* Z64API.OoT.InventorySlots.BOMBS */);
    }
    get bombsCount() {
        return this.getAmmoForSlot(2 /* Z64API.OoT.InventorySlots.BOMBS */);
    }
    set bombsCount(count) {
        this.setAmmoInSlot(2 /* Z64API.OoT.InventorySlots.BOMBS */, count);
    }
    get bombchus() {
        let val = this.getItemInSlot(8 /* Z64API.OoT.InventorySlots.BOMBCHUS */);
        return !(val === 255 /* Z64API.OoT.InventoryItem.NONE */);
    }
    set bombchus(bool) {
        let value = bool ? 9 /* Z64API.OoT.InventoryItem.BOMBCHU */ : 255 /* Z64API.OoT.InventoryItem.NONE */;
        this.setItemInSlot(value, 8 /* Z64API.OoT.InventorySlots.BOMBCHUS */);
    }
    get bombchuCount() {
        return this.getAmmoForSlot(8 /* Z64API.OoT.InventorySlots.BOMBCHUS */);
    }
    set bombchuCount(count) {
        this.setAmmoInSlot(8 /* Z64API.OoT.InventorySlots.BOMBCHUS */, count);
    }
    get magicBeans() {
        let val = this.getItemInSlot(14 /* Z64API.OoT.InventorySlots.MAGIC_BEANS */);
        return !(val === 255 /* Z64API.OoT.InventoryItem.NONE */);
    }
    set magicBeans(bool) {
        let value = bool ? 16 /* Z64API.OoT.InventoryItem.MAGIC_BEAN */ : 255 /* Z64API.OoT.InventoryItem.NONE */;
        this.setItemInSlot(value, 14 /* Z64API.OoT.InventorySlots.MAGIC_BEANS */);
    }
    get magicBeansCount() {
        return this.getAmmoForSlot(14 /* Z64API.OoT.InventorySlots.MAGIC_BEANS */);
    }
    set magicBeansCount(count) {
        this.setAmmoInSlot(14 /* Z64API.OoT.InventorySlots.MAGIC_BEANS */, count);
    }
    get fairySlingshot() {
        let val = this.getItemInSlot(6 /* Z64API.OoT.InventorySlots.FAIRY_SLINGSHOT */);
        return !(val === 255 /* Z64API.OoT.InventoryItem.NONE */);
    }
    set fairySlingshot(bool) {
        let value = bool ? 6 /* Z64API.OoT.InventoryItem.FAIRY_SLINGSHOT */ : 255 /* Z64API.OoT.InventoryItem.NONE */;
        this.setItemInSlot(value, 6 /* Z64API.OoT.InventorySlots.FAIRY_SLINGSHOT */);
    }
    get dekuSeeds() {
        return this.getAmmoForSlot(6 /* Z64API.OoT.InventorySlots.FAIRY_SLINGSHOT */);
    }
    set dekuSeeds(count) {
        this.setAmmoInSlot(6 /* Z64API.OoT.InventorySlots.FAIRY_SLINGSHOT */, count);
    }
    get fairyBow() {
        let val = this.getItemInSlot(3 /* Z64API.OoT.InventorySlots.FAIRY_BOW */);
        return !(val === 255 /* Z64API.OoT.InventoryItem.NONE */);
    }
    set fairyBow(bool) {
        let value = bool ? 3 /* Z64API.OoT.InventoryItem.FAIRY_BOW */ : 255 /* Z64API.OoT.InventoryItem.NONE */;
        this.setItemInSlot(value, 3 /* Z64API.OoT.InventorySlots.FAIRY_BOW */);
    }
    get arrows() {
        return this.getAmmoForSlot(3 /* Z64API.OoT.InventorySlots.FAIRY_BOW */);
    }
    set arrows(count) {
        this.setAmmoInSlot(3 /* Z64API.OoT.InventorySlots.FAIRY_BOW */, count);
    }
    get fireArrows() {
        let val = this.getItemInSlot(4 /* Z64API.OoT.InventorySlots.FIRE_ARROWS */);
        return !(val === 255 /* Z64API.OoT.InventoryItem.NONE */);
    }
    set fireArrows(bool) {
        let value = bool ? 4 /* Z64API.OoT.InventoryItem.FIRE_ARROW */ : 255 /* Z64API.OoT.InventoryItem.NONE */;
        this.setItemInSlot(value, 4 /* Z64API.OoT.InventorySlots.FIRE_ARROWS */);
    }
    get iceArrows() {
        let val = this.getItemInSlot(10 /* Z64API.OoT.InventorySlots.ICE_ARROWS */);
        return !(val === 255 /* Z64API.OoT.InventoryItem.NONE */);
    }
    set iceArrows(bool) {
        let value = bool ? 12 /* Z64API.OoT.InventoryItem.ICE_ARROW */ : 255 /* Z64API.OoT.InventoryItem.NONE */;
        this.setItemInSlot(value, 10 /* Z64API.OoT.InventorySlots.ICE_ARROWS */);
    }
    get lightArrows() {
        let val = this.getItemInSlot(16 /* Z64API.OoT.InventorySlots.LIGHT_ARROWS */);
        return !(val === 255 /* Z64API.OoT.InventoryItem.NONE */);
    }
    set lightArrows(bool) {
        let value = bool ? 18 /* Z64API.OoT.InventoryItem.LIGHT_ARROW */ : 255 /* Z64API.OoT.InventoryItem.NONE */;
        this.setItemInSlot(value, 16 /* Z64API.OoT.InventorySlots.LIGHT_ARROWS */);
    }
    get dinsFire() {
        let val = this.getItemInSlot(5 /* Z64API.OoT.InventorySlots.DINS_FIRE */);
        return !(val === 255 /* Z64API.OoT.InventoryItem.NONE */);
    }
    set dinsFire(bool) {
        let value = bool ? 5 /* Z64API.OoT.InventoryItem.DINS_FIRE */ : 255 /* Z64API.OoT.InventoryItem.NONE */;
        this.setItemInSlot(value, 5 /* Z64API.OoT.InventorySlots.DINS_FIRE */);
    }
    get faroresWind() {
        let val = this.getItemInSlot(11 /* Z64API.OoT.InventorySlots.FARORES_WIND */);
        return !(val === 255 /* Z64API.OoT.InventoryItem.NONE */);
    }
    set faroresWind(bool) {
        let value = bool ? 13 /* Z64API.OoT.InventoryItem.FARORES_WIND */ : 255 /* Z64API.OoT.InventoryItem.NONE */;
        this.setItemInSlot(value, 11 /* Z64API.OoT.InventorySlots.FARORES_WIND */);
    }
    get nayrusLove() {
        let val = this.getItemInSlot(17 /* Z64API.OoT.InventorySlots.NAYRUS_LOVE */);
        return !(val === 255 /* Z64API.OoT.InventoryItem.NONE */);
    }
    set nayrusLove(bool) {
        let value = bool ? 19 /* Z64API.OoT.InventoryItem.NAYRUS_LOVE */ : 255 /* Z64API.OoT.InventoryItem.NONE */;
        this.setItemInSlot(value, 17 /* Z64API.OoT.InventorySlots.NAYRUS_LOVE */);
    }
    get ocarina() {
        let val = this.getItemInSlot(7 /* Z64API.OoT.InventorySlots.OCARINA */);
        switch (val) {
            case 7 /* Z64API.OoT.InventoryItem.FAIRY_OCARINA */:
                return 1 /* Z64API.Z64.Ocarina.FAIRY_OCARINA */;
            case 8 /* Z64API.OoT.InventoryItem.OCARINA_OF_TIME */:
                return 2 /* Z64API.Z64.Ocarina.OCARINA_OF_TIME */;
            default:
                return 0 /* Z64API.Z64.Ocarina.NONE */;
        }
    }
    set ocarina(item) {
        if (item === this.ocarina)
            return;
        switch (item) {
            case 0 /* Z64API.Z64.Ocarina.NONE */:
                this.setItemInSlot(255 /* Z64API.OoT.InventoryItem.NONE */, 7 /* Z64API.OoT.InventorySlots.OCARINA */);
                break;
            case 1 /* Z64API.Z64.Ocarina.FAIRY_OCARINA */:
                this.setItemInSlot(7 /* Z64API.OoT.InventoryItem.FAIRY_OCARINA */, 7 /* Z64API.OoT.InventorySlots.OCARINA */);
                break;
            case 2 /* Z64API.Z64.Ocarina.OCARINA_OF_TIME */:
                this.setItemInSlot(8 /* Z64API.OoT.InventoryItem.OCARINA_OF_TIME */, 7 /* Z64API.OoT.InventorySlots.OCARINA */);
                break;
        }
    }
    get hookshot() {
        let val = this.getItemInSlot(9 /* Z64API.OoT.InventorySlots.HOOKSHOT */);
        switch (val) {
            case 10 /* Z64API.OoT.InventoryItem.HOOKSHOT */:
                return 1 /* Z64API.OoT.Hookshot.HOOKSHOT */;
            case 11 /* Z64API.OoT.InventoryItem.LONGSHOT */:
                return 2 /* Z64API.OoT.Hookshot.LONGSHOT */;
            default:
                return 0 /* Z64API.OoT.Hookshot.NONE */;
        }
    }
    set hookshot(item) {
        if (item === this.hookshot)
            return;
        switch (item) {
            case 0 /* Z64API.OoT.Hookshot.NONE */:
                this.setItemInSlot(255 /* Z64API.OoT.InventoryItem.NONE */, 9 /* Z64API.OoT.InventorySlots.HOOKSHOT */);
                break;
            case 1 /* Z64API.OoT.Hookshot.HOOKSHOT */:
                this.setItemInSlot(10 /* Z64API.OoT.InventoryItem.HOOKSHOT */, 9 /* Z64API.OoT.InventorySlots.HOOKSHOT */);
                break;
            case 2 /* Z64API.OoT.Hookshot.LONGSHOT */:
                this.setItemInSlot(11 /* Z64API.OoT.InventoryItem.LONGSHOT */, 9 /* Z64API.OoT.InventorySlots.HOOKSHOT */);
                break;
        }
    }
    get boomerang() {
        let val = this.getItemInSlot(12 /* Z64API.OoT.InventorySlots.BOOMERANG */);
        return !(val === 255 /* Z64API.OoT.InventoryItem.NONE */);
    }
    set boomerang(bool) {
        let value = bool ? 14 /* Z64API.OoT.InventoryItem.BOOMERANG */ : 255 /* Z64API.OoT.InventoryItem.NONE */;
        this.setItemInSlot(value, 12 /* Z64API.OoT.InventorySlots.BOOMERANG */);
    }
    get lensOfTruth() {
        let val = this.getItemInSlot(13 /* Z64API.OoT.InventorySlots.LENS_OF_TRUTH */);
        return !(val === 255 /* Z64API.OoT.InventoryItem.NONE */);
    }
    set lensOfTruth(bool) {
        let value = bool ? 15 /* Z64API.OoT.InventoryItem.LENS_OF_TRUTH */ : 255 /* Z64API.OoT.InventoryItem.NONE */;
        this.setItemInSlot(value, 13 /* Z64API.OoT.InventorySlots.LENS_OF_TRUTH */);
    }
    get megatonHammer() {
        let val = this.getItemInSlot(15 /* Z64API.OoT.InventorySlots.MEGATON_HAMMER */);
        return !(val === 255 /* Z64API.OoT.InventoryItem.NONE */);
    }
    set megatonHammer(bool) {
        let value = bool ? 17 /* Z64API.OoT.InventoryItem.MEGATON_HAMMER */ : 255 /* Z64API.OoT.InventoryItem.NONE */;
        this.setItemInSlot(value, 15 /* Z64API.OoT.InventorySlots.MEGATON_HAMMER */);
    }
    get bottle_1() {
        return this.getItemInSlot(18 /* Z64API.OoT.InventorySlots.BOTTLE1 */);
    }
    set bottle_1(content) {
        this.setItemInSlot(content, 18 /* Z64API.OoT.InventorySlots.BOTTLE1 */);
    }
    get bottle_2() {
        return this.getItemInSlot(19 /* Z64API.OoT.InventorySlots.BOTTLE2 */);
    }
    set bottle_2(content) {
        this.setItemInSlot(content, 19 /* Z64API.OoT.InventorySlots.BOTTLE2 */);
    }
    get bottle_3() {
        return this.getItemInSlot(20 /* Z64API.OoT.InventorySlots.BOTTLE3 */);
    }
    set bottle_3(content) {
        this.setItemInSlot(content, 20 /* Z64API.OoT.InventorySlots.BOTTLE3 */);
    }
    get bottle_4() {
        return this.getItemInSlot(21 /* Z64API.OoT.InventorySlots.BOTTLE4 */);
    }
    set bottle_4(content) {
        this.setItemInSlot(content, 21 /* Z64API.OoT.InventorySlots.BOTTLE4 */);
    }
    hasBottle() {
        for (let i = 18 /* Z64API.OoT.InventorySlots.BOTTLE1 */; i <= 21 /* Z64API.OoT.InventorySlots.BOTTLE4 */; i++) {
            let item = this.getItemInSlot(i);
            if (item >= 20 /* Z64API.OoT.InventoryItem.EMPTY_BOTTLE */ &&
                item <= 32 /* Z64API.OoT.InventoryItem.BOTTLED_POE */) {
                return true;
            }
        }
        return false;
    }
    getBottleCount() {
        let bottles = 0;
        for (let i = 18 /* Z64API.OoT.InventorySlots.BOTTLE1 */; i <= 21 /* Z64API.OoT.InventorySlots.BOTTLE4 */; i++) {
            let item = this.getItemInSlot(i);
            if (item >= 20 /* Z64API.OoT.InventoryItem.EMPTY_BOTTLE */ &&
                item <= 32 /* Z64API.OoT.InventoryItem.BOTTLED_POE */) {
                bottles++;
            }
        }
        return bottles;
    }
    getBottledItems() {
        let bottles = new Array();
        for (let i = 18 /* Z64API.OoT.InventorySlots.BOTTLE1 */; i <= 21 /* Z64API.OoT.InventorySlots.BOTTLE4 */; i++) {
            let item = this.getItemInSlot(i);
            if (item >= 20 /* Z64API.OoT.InventoryItem.EMPTY_BOTTLE */ &&
                item <= 32 /* Z64API.OoT.InventoryItem.BOTTLED_POE */) {
                bottles.push(item);
            }
        }
        return bottles;
    }
    get childTradeItem() {
        return this.getItemInSlot(23 /* Z64API.OoT.InventorySlots.CHILD_TRADE_ITEM */);
    }
    set childTradeItem(item) {
        this.setItemInSlot(item, 23 /* Z64API.OoT.InventorySlots.CHILD_TRADE_ITEM */);
    }
    get adultTradeItem() {
        return this.getItemInSlot(22 /* Z64API.OoT.InventorySlots.ADULT_TRADE_ITEM */);
    }
    set adultTradeItem(item) {
        this.setItemInSlot(item, 22 /* Z64API.OoT.InventorySlots.ADULT_TRADE_ITEM */);
    }
    isChildTradeFinished() {
        // This is going to require more complex flag checks
        return true;
    }
    isAdultTradeFinished() {
        // This should be done with flags also
        return true;
    }
    getItemInSlot(slotId) {
        if (slotId < 0 || slotId > 23 /* Z64API.OoT.InventorySlots.CHILD_TRADE_ITEM */) {
            return 255 /* Z64API.OoT.InventoryItem.NONE */;
        }
        let itemId = this.emulator.rdramRead8(this.inventory_addr + slotId);
        return itemId;
    }
    getSlotForItem(item) {
        for (let i = 0; i <= 23 /* Z64API.OoT.InventorySlots.CHILD_TRADE_ITEM */; i++) {
            if (this.getItemInSlot(i) == item) {
                return i;
            }
        }
        return -1;
    }
    getSlotsForItem(item) {
        let slots = new Array();
        for (let i = 0; i <= 23 /* Z64API.OoT.InventorySlots.CHILD_TRADE_ITEM */; i++) {
            if (this.getItemInSlot(i) == item) {
                slots.push(i);
            }
        }
        return slots;
    }
    hasItem(item) {
        return this.getSlotForItem(item) != -1;
    }
    getAmmoForItem(item) {
        if (!this.hasAmmo(item))
            return 0;
        let ammo = 0;
        let slots = this.getSlotsForItem(item);
        for (let i = 0; i < slots.length; i++) {
            ammo += this.getAmmoForSlot(slots[i]);
        }
        return ammo;
    }
    hasAmmo(item) {
        switch (item) {
            case 0 /* Z64API.OoT.InventoryItem.DEKU_STICK */:
            case 1 /* Z64API.OoT.InventoryItem.DEKU_NUT */:
            case 6 /* Z64API.OoT.InventoryItem.FAIRY_SLINGSHOT */:
            case 3 /* Z64API.OoT.InventoryItem.FAIRY_BOW */:
            case 2 /* Z64API.OoT.InventoryItem.BOMB */:
            case 9 /* Z64API.OoT.InventoryItem.BOMBCHU */:
            case 16 /* Z64API.OoT.InventoryItem.MAGIC_BEAN */:
                return true;
        }
        return false;
    }
    getAmmoForSlot(slotId) {
        if (slotId < 0 || slotId > 0xf)
            return 0;
        return this.emulator.rdramRead8(this.inventory_ammo_addr + slotId);
    }
    setAmmoInSlot(slot, amount) {
        if (slot < 0 || slot >= 0xf)
            return;
        this.emulator.rdramWrite8(this.inventory_ammo_addr + slot, amount);
    }
    setItemInSlot(item, slot) {
        if (slot < 0 || slot > 23 /* Z64API.OoT.InventorySlots.CHILD_TRADE_ITEM */) {
            return;
        }
        this.emulator.rdramWrite8(this.inventory_addr + slot, item.valueOf());
    }
    giveItem(item, desiredSlot) {
        if (this.getItemInSlot(desiredSlot) == 255 /* Z64API.OoT.InventoryItem.NONE */ ||
            this.getItemInSlot(desiredSlot) == item) {
            this.setItemInSlot(item, desiredSlot);
        }
    }
    removeItem(item) {
        let slots = this.getSlotsForItem(item);
        for (let i = 0; i < slots.length; i++) {
            this.setItemInSlot(255 /* Z64API.OoT.InventoryItem.NONE */, i);
        }
    }
    getEmptySlots() {
        let slots = new Array();
        for (let i = 0; i <= 23 /* Z64API.OoT.InventorySlots.CHILD_TRADE_ITEM */; i++) {
            if (this.getItemInSlot(i) == 255 /* Z64API.OoT.InventoryItem.NONE */) {
                slots.push(i);
            }
        }
        return slots;
    }
}
exports.Inventory = Inventory;
//# sourceMappingURL=Inventory.js.map