#import "HMKCMasterShipObject.h"
#import "HMKCSlotItemObject+Extensions.h"
#import "HMKCMasterSlotItemObject.h"
+#import "HMKCMasterSType.h"
@interface HMAnchorageRepairManager ()
@property (strong) HMKCDeck* fleet;
@property (strong) NSNumber *deckID;
-@property (strong) NSArray *members;
+@property (strong) NSArray<HMKCShipObject *> *members;
@property (strong) NSObjectController *fleetController;
@property (strong) NSArrayController *memberController;
[self buildMembers];
-// [self resetRepairTime];
-
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
selector:@selector(didRecivePortAPINotification:)
name:HMPortAPIRecieveNotification
object:nil];
+
+
+ _memberController = [[NSArrayController alloc] initWithContent:nil];
+ [_memberController bind:NSContentArrayBinding
+ toObject:self
+ withKeyPath:@"members"
+ options:nil];
+ [self.memberController addObserver:self
+ forKeyPath:@"arrangedObjects.equippedItem"
+ options:0
+ context:@"members"];
}
return self;
}
[_fleetController removeObserver:self
forKeyPath:[NSString stringWithFormat:@"selection.%@", key]];
}
+
+ [_memberController removeObserver:self forKeyPath:@"arrangedObjects.equippedItem"];
+ [_memberController unbind:@"members"];
}
- (NSDate *)repairTime
- (void)buildMembers
{
- NSString *observeKeyPath = @"arrangedObjects.equippedItem";
-
- [self.memberController removeObserver:self forKeyPath:observeKeyPath];
-
- NSArray *shipKeys = @[@"ship_0", @"ship_1", @"ship_2", @"ship_3", @"ship_4", @"ship_5"];
- HMServerDataStore *store = [HMServerDataStore defaultManager];
- NSMutableArray *array = [NSMutableArray new];
- [shipKeys enumerateObjectsUsingBlock:^(NSString *key, NSUInteger idx, BOOL *stop) {
- id shipID = [_fleet valueForKey:key];
- NSError *error = nil;
- NSArray *ships = [store objectsWithEntityName:@"Ship"
- error:&error
- predicateFormat:@"id = %ld", [shipID integerValue]];
- if(error) {
- NSLog(@"%s error: %@", __PRETTY_FUNCTION__, error);
- }
- if(ships.count != 0) {
- [array addObject:ships[0]];
- }
- }];
- _members = array;
- _memberController = [[NSArrayController alloc] initWithContent:array];
- [self.memberController addObserver:self
- forKeyPath:observeKeyPath
- options:0
- context:@"members"];
+ NSMutableArray<HMKCShipObject *> *array = [NSMutableArray array];
+ for(NSInteger i = 0; i < 6; i++) {
+ HMKCShipObject *ship = self.fleet[i];
+ if(ship) [array addObject:ship];
+ }
+ self.members = array;
}
- (void)didRecivePortAPINotification:(NSNotification *)notification
}
}
+- (HMKCShipObject *)flagShip
+{
+ if(self.members.count == 0) return nil;
+ return self.members[0];
+}
+
- (NSArray *)repairShipIds
{
return @[@(19)];
}
- (BOOL)repairable
{
- HMKCShipObject *flagShip = self.fleet[0];
+ HMKCShipObject *flagShip = self.flagShip;
HMKCMasterShipObject *flagShipMaster = flagShip.master_ship;
- id stype = flagShipMaster.stype;
- id stypeId = [stype valueForKey:@"id"];
+ HMKCMasterSType *stype = flagShipMaster.stype;
+ NSNumber *stypeId = stype.id;
BOOL result = [self.repairShipIds containsObject:stypeId];
if(!result && [sRepairableDeckIDs containsObject:self.deckID]) {
[sRepairableDeckIDs removeObject:self.deckID];
if(![self repairable]) return @0;
NSUInteger count = 2;
- HMKCShipObject *flagShip = self.fleet[0];
+ HMKCShipObject *flagShip = self.flagShip;
for(HMKCSlotItemObject *item in flagShip.equippedItem) {
if([self.repairSlotItemIds containsObject:item.master_slotItem.type_2]) {
count++;