//
//  MMORoom.m
//  SFS2X
//
//  Created by Lapo on 29/11/13.
//  Copyright (c) 2013 A51 Integrated | http://a51integrated.com. All rights reserved.
//

#import "MMORoom.h"
#import "ArrayUtil.h"

@implementation MMORoom
{
    // Dict<NSNumber, IMMOItem>
    
    @protected
    NSMutableDictionary* itemsById;
}

@synthesize defaultAOI = _defaultAOI;
@synthesize lowerMapLimit = _lowerMapLimit;
@synthesize higherMapLimit = _higherMapLimit;

- (id) initWithId:(NSInteger)id name:(NSString *)name groupId:(NSString *)groupId
{
    self = [super initWithId:id name:name groupId:groupId];
    if (self)
    {
        itemsById = [[NSMutableDictionary alloc] init];
    }
    
    return self;
}

- (id<IMMOItem>) getMMOItem:(NSInteger)itemId
{
    return [itemsById objectForKey:[NSNumber numberWithInt: (int)itemId]];
}

- (NSArray*) getMMOItems
{
    return [ArrayUtil objToArray:itemsById];
}

// Custom Setters

-(void)setDefaultAOI:(Vec3D *)defaultAOI
{
    if (_defaultAOI != nil)
        @throw [NSException exceptionWithName:NSInvalidArgumentException
                                       reason:@"Property is already set"
                                     userInfo:nil];
    
    // Proceed
    _defaultAOI = defaultAOI;
}

-(void)setLowerMapLimit:(Vec3D *)lowerMapLimit
{
    if (_lowerMapLimit != nil)
        @throw [NSException exceptionWithName:NSInvalidArgumentException
                                       reason:@"Property is already set"
                                     userInfo:nil];
    
    // Proceed
    _lowerMapLimit = lowerMapLimit;
}

-(void)setHigherMapLimit:(Vec3D *)higherMapLimit
{
    if (_higherMapLimit != nil)
        @throw [NSException exceptionWithName:NSInvalidArgumentException
                                       reason:@"Property is already set"
                                     userInfo:nil];
    
    // Proceed
    _higherMapLimit = higherMapLimit;
}


- (void) addMMOItem:(id<IMMOItem>)item
{
    // Int is converted to --> NSNumber
    [itemsById setObject:item forKey:[NSNumber numberWithInt: (int) item.id]];
}

- (void) removeMMOItem:(NSInteger) itemId
{
    [itemsById removeObjectForKey:[NSNumber numberWithInt: (int) itemId]];
}

@end
