OSDN Git Service

新しく追加したコアデータエンティティクラスを使用するように変更
authormasakih <masakih@users.sourceforge.jp>
Wed, 10 Feb 2016 13:55:18 +0000 (22:55 +0900)
committermasakih <masakih@users.sourceforge.jp>
Wed, 10 Feb 2016 13:55:18 +0000 (22:55 +0900)
19 files changed:
KCD/HMApplySuppliesCommand.m
KCD/HMCalculateDamageCommand.m
KCD/HMChangeHenseiCommand.m
KCD/HMCreateShipCommand.m
KCD/HMDestroyItem2Command.m
KCD/HMDropShipHistoryCommand.m
KCD/HMDummyShipCommand.m
KCD/HMGuardShelterCommand.m
KCD/HMKaisouLockCommand.m
KCD/HMKenzoMarkCommand.m
KCD/HMNyukyoSpeedChangeCommand.m
KCD/HMNyukyoStartCommand.m
KCD/HMRealDestroyShipCommand.m
KCD/HMRealPowerUpCommand.m
KCD/HMRemodelSlotItemCommand.m
KCD/HMResetSortieCommand.m
KCD/HMSlotResetCommand.m
KCD/HMStoreCreateSlotItemHistoryCommand.m
KCD/HMUpdateSlotItemCommand.m

index d4a4c9d..eae9ff0 100644 (file)
        
        for(NSDictionary *updataInfo in shipInfos) {
                NSError *error = nil;
-               NSArray *array = [store objectsWithEntityName:@"Ship"
-                                                                                               error:&error
-                                                                         predicateFormat:@"id = %@", @([updataInfo[@"api_id"] integerValue])];
-               if(array.count == 0) {
+               NSArray<HMKCShipObject *> *ships = [store objectsWithEntityName:@"Ship"
+                                                                                                                                 error:&error
+                                                                                                               predicateFormat:@"id = %@", @([updataInfo[@"api_id"] integerValue])];
+               if(ships.count == 0) {
                        if(error) {
                                NSLog(@"Error: at %@ : %@", NSStringFromClass([self class]), error);
                        }
                        continue;
                }
                
-               HMKCShipObject *ship = array[0];
-               ship.bull = updataInfo[@"api_bull"];
-               ship.fuel = updataInfo[@"api_fuel"];
+               ships[0].bull = updataInfo[@"api_bull"];
+               ships[0].fuel = updataInfo[@"api_fuel"];
                NSArray *onslots = updataInfo[@"api_onslot"];
-               ship.onslot_0 = onslots[0];
-               ship.onslot_1 = onslots[1];
-               ship.onslot_2 = onslots[2];
-               ship.onslot_3 = onslots[3];
-               ship.onslot_4 = onslots[4];
+               ships[0].onslot_0 = onslots[0];
+               ships[0].onslot_1 = onslots[1];
+               ships[0].onslot_2 = onslots[2];
+               ships[0].onslot_3 = onslots[3];
+               ships[0].onslot_4 = onslots[4];
        }
 }
 @end
index 956a1a9..83dbd0e 100644 (file)
 #import "HMTemporaryDataStore.h"
 #import "HMServerDataStore.h"
 
+#import "HMKCDamage.h"
+#import "HMKCBattle.h"
 #import "HMKCShipObject+Extensions.h"
-#import "HMKCSlotItemObject+Extensions.h"
-
+#import "HMKCSlotItemObject.h"
+#import "HMKCDeck+Extension.h"
 
 #define DAMAGE_CHECK 0
 
@@ -44,14 +46,14 @@ typedef NS_ENUM(NSUInteger, HMBattleType) {
        NSManagedObjectContext *moc = self.store.managedObjectContext;
        
        NSError *error = nil;
-       NSArray *array = [self.store objectsWithEntityName:@"Battle"
-                                                                               predicate:nil
-                                                                                       error:&error];
+       NSArray<HMKCBattle *> *array = [self.store objectsWithEntityName:@"Battle"
+                                                                                                                  predicate:nil
+                                                                                                                          error:&error];
        if(error) {
                [self log:@"%s error: %@", __PRETTY_FUNCTION__, error];
                return;
        }
-       for(id object in array) {
+       for(HMKCBattle *object in array) {
                [moc deleteObject:object];
        }
                
@@ -63,17 +65,17 @@ typedef NS_ENUM(NSUInteger, HMBattleType) {
        NSManagedObjectContext *moc = self.store.managedObjectContext;
        
        NSError *error = nil;
-       NSArray *array = [self.store objectsWithEntityName:@"Damage"
-                                                          predicate:nil
-                                                                  error:&error];
+       NSArray<HMKCDamage *> *array = [self.store objectsWithEntityName:@"Damage"
+                                                                                                                  predicate:nil
+                                                                                                                          error:&error];
        if(error) {
                [self log:@"%s error: %@", __PRETTY_FUNCTION__, error];
                return;
        }
-       for(id object in array) {
+       for(HMKCDamage *object in array) {
                [moc deleteObject:object];
        }
-               
+       
        [self.store saveAction:nil];
 }
 
@@ -82,13 +84,13 @@ typedef NS_ENUM(NSUInteger, HMBattleType) {
        NSManagedObjectContext *moc = self.store.managedObjectContext;
        
        // Battleエンティティ作成
-       id battle = [NSEntityDescription insertNewObjectForEntityForName:@"Battle"
-                                                                                         inManagedObjectContext:moc];
+       HMKCBattle *battle = [NSEntityDescription insertNewObjectForEntityForName:@"Battle"
+                                                                                                          inManagedObjectContext:moc];
        
-       [battle setValue:@([[self.arguments valueForKey:@"api_deck_id"] integerValue]) forKeyPath:@"deckId"];
-       [battle setValue:@([[self.arguments valueForKey:@"api_maparea_id"] integerValue]) forKeyPath:@"mapArea"];
-       [battle setValue:@([[self.arguments valueForKey:@"api_mapinfo_no"] integerValue]) forKeyPath:@"mapInfo"];
-       [battle setValue:@([[self.json valueForKeyPath:@"api_data.api_no"] integerValue]) forKeyPath:@"no"];
+       battle.deckId = @([[self.arguments valueForKey:@"api_deck_id"] integerValue]);
+       battle.mapArea = @([[self.arguments valueForKey:@"api_maparea_id"] integerValue]);
+       battle.mapInfo = @([[self.arguments valueForKey:@"api_mapinfo_no"] integerValue]);
+       battle.no = @([[self.json valueForKeyPath:@"api_data.api_no"] integerValue]);
        
        [self.store saveAction:nil];
 }
@@ -96,9 +98,9 @@ typedef NS_ENUM(NSUInteger, HMBattleType) {
 - (void)updateBattleCell
 {
        NSError *error = nil;
-       NSArray *battles = [self.store objectsWithEntityName:@"Battle"
-                                                                                          predicate:nil
-                                                                                                  error:&error];
+       NSArray<HMKCBattle *> *battles = [self.store objectsWithEntityName:@"Battle"
+                                                                                                                        predicate:nil
+                                                                                                                                error:&error];
        if(error) {
                [self log:@"%s error: %@", __PRETTY_FUNCTION__, error];
        }
@@ -106,24 +108,23 @@ typedef NS_ENUM(NSUInteger, HMBattleType) {
                NSLog(@"Battle is invalid.");
                return;
        }
-       id battle = battles[0];
        
-       id battleCell = [battle valueForKey:@"no"];
-       if([battleCell integerValue] == 0) {
+       NSNumber *battleCell = battles[0].no;
+       if(battleCell.integerValue == 0) {
                battleCell = nil;
        }
        if([self.api hasSuffix:@"next"]) {
                battleCell = nil;
        }
-       [battle setValue:battleCell forKeyPath:@"battleCell"];
+       battles[0].battleCell = battleCell;
 }
 
 - (void)nextCell
 {
        NSError *error = nil;
-       NSArray *battles = [self.store objectsWithEntityName:@"Battle"
-                                                                                          predicate:nil
-                                                                                                  error:&error];
+       NSArray<HMKCBattle *> *battles = [self.store objectsWithEntityName:@"Battle"
+                                                                                                                        predicate:nil
+                                                                                                                                error:&error];
        if(error) {
                [self log:@"%s error: %@", __PRETTY_FUNCTION__, error];
        }
@@ -131,27 +132,26 @@ typedef NS_ENUM(NSUInteger, HMBattleType) {
                NSLog(@"Battle is invalid.");
                return;
        }
-       id battle = battles[0];
        id cellNumber = [self.json valueForKeyPath:@"api_data.api_no"];
        id eventIDNumber = [self.json valueForKeyPath:@"api_data.api_event_id"];
        BOOL isBossCell = [eventIDNumber integerValue] == 5;
        
-       [battle setValue:@([cellNumber integerValue]) forKeyPath:@"no"];
-       [battle setValue:@(isBossCell) forKeyPath:@"isBossCell"];
+       battles[0].no = @([cellNumber integerValue]);
+       battles[0].isBossCell = @(isBossCell);
        
        [self.store saveAction:nil];
 }
 
-- (NSMutableArray *)damages
+- (NSArray<HMKCDamage *> *)damages
 {
        NSManagedObjectContext *moc = self.store.managedObjectContext;
        
        NSError *error = nil;
        NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"id" ascending:YES];
-       NSArray *array = [self.store objectsWithEntityName:@"Damage"
-                                                                          sortDescriptors:@[sortDescriptor]
-                                                                                        predicate:nil
-                                                                                                error:&error];
+       NSArray<HMKCDamage *> *array = [self.store objectsWithEntityName:@"Damage"
+                                                                                                        sortDescriptors:@[sortDescriptor]
+                                                                                                                  predicate:nil
+                                                                                                                          error:&error];
        if(error) {
                [self log:@"%s error: %@", __PRETTY_FUNCTION__, error];
        }
@@ -161,9 +161,9 @@ typedef NS_ENUM(NSUInteger, HMBattleType) {
        if(array.count != frendShipCount) {
                // Battleエンティティ取得
                error = nil;
-               NSArray *battles = [self.store objectsWithEntityName:@"Battle"
-                                                                                                  predicate:nil
-                                                                                                          error:&error];
+               NSArray<HMKCBattle *> *battles = [self.store objectsWithEntityName:@"Battle"
+                                                                                                                                predicate:nil
+                                                                                                                                        error:&error];
                if(error) {
                        [self log:@"%s error: %@", __PRETTY_FUNCTION__, error];
                }
@@ -171,24 +171,23 @@ typedef NS_ENUM(NSUInteger, HMBattleType) {
                        NSLog(@"Battle is invalid.");
                        return [NSMutableArray new];
                }
-               id battle = battles[0];
                
                // Damage エンティティ作成6個
-               NSMutableArray *damages = [NSMutableArray new];
+               NSMutableArray<HMKCDamage *> *damages = [NSMutableArray new];
                for(NSInteger i = 0; i < frendShipCount; i++) {
-                       id damage = [NSEntityDescription insertNewObjectForEntityForName:@"Damage"
-                                                                                                         inManagedObjectContext:moc];
-                       [damage setValue:battle forKeyPath:@"battle"];
-                       [damage setValue:@(i) forKeyPath:@"id"];
+                       HMKCDamage *damage = [NSEntityDescription insertNewObjectForEntityForName:@"Damage"
+                                                                                                                          inManagedObjectContext:moc];
+                       damage.battle = battles[0];
+                       damage.id = @(i);
                        [damages addObject:damage];
                }
                array = damages;
        }
        
-       return [NSMutableArray arrayWithArray:array];
+       return [NSArray arrayWithArray:array];
 }
 
-- (void)calculateHougeki:(NSMutableArray *)damages targetsKeyPath:(NSString *)targetKeyPath damageKeyPath:(NSString *)damageKeyPath
+- (void)calculateHougeki:(NSArray<HMKCDamage *> *)damages targetsKeyPath:(NSString *)targetKeyPath damageKeyPath:(NSString *)damageKeyPath
 {
 #if DAMAGE_CHECK
        NSLog(@"Start Hougeki %@", targetKeyPath);
@@ -196,7 +195,7 @@ typedef NS_ENUM(NSUInteger, HMBattleType) {
        id targetShips = [self.json valueForKeyPath:targetKeyPath];
        if(!targetShips || [targetShips isKindOfClass:[NSNull class]]) return;
        
-       id hougeki1Damages = [self.json valueForKeyPath:damageKeyPath];
+       NSArray<NSArray *> *hougeki1Damages = [self.json valueForKeyPath:damageKeyPath];
        NSInteger i = 0;
        NSInteger offset = self.calcSecondFleet ? 6 : 0;
        for(NSArray *array in targetShips) {
@@ -216,10 +215,10 @@ typedef NS_ENUM(NSUInteger, HMBattleType) {
                                continue;
                        }
                        
-                       id damageObject = [damages objectAtIndex:target - 1 + offset];
-                       NSInteger damage = [[[hougeki1Damages objectAtIndex:i] objectAtIndex:j] integerValue];
-                       damage += [[damageObject valueForKey:@"damage"] integerValue];
-                       [damageObject setValue:@(damage) forKeyPath:@"damage"];
+                       HMKCDamage *damageObject = damages[target - 1 + offset];
+                       NSInteger damage = [hougeki1Damages[i][j] integerValue];
+                       damage += damageObject.damage.integerValue;
+                       damageObject.damage = @(damage);
                        
 #if DAMAGE_CHECK
                        NSLog(@"Hougeki %ld -> %ld", target + offset, damage);
@@ -231,7 +230,7 @@ typedef NS_ENUM(NSUInteger, HMBattleType) {
        }
 }
 
-- (void)calculateFDam:(NSMutableArray *)damages fdamKeyPath:(NSString *)fdamKeyPath
+- (void)calculateFDam:(NSArray<HMKCDamage *> *)damages fdamKeyPath:(NSString *)fdamKeyPath
 {
 #if DAMAGE_CHECK
        NSLog(@"Start FDam %@", fdamKeyPath);
@@ -241,10 +240,10 @@ typedef NS_ENUM(NSUInteger, HMBattleType) {
        
        NSInteger offset = self.calcSecondFleet ? 6 : 0;
        for(NSInteger i = 1; i <= 6; i++) {
-               id damageObject = [damages objectAtIndex:i - 1 + offset];
-               NSInteger damage = [[koukuDamage objectAtIndex:i] integerValue];
-               damage += [[damageObject valueForKey:@"damage"] integerValue];
-               [damageObject setValue:@(damage) forKeyPath:@"damage"];
+               HMKCDamage *damageObject = damages[i - 1 + offset];
+               NSInteger damage = [koukuDamage[i] integerValue];
+               damage += damageObject.damage.integerValue;
+               damageObject.damage = @(damage);
                
 #if DAMAGE_CHECK
                NSLog(@"FDam %ld -> %ld", i + offset, damage);
@@ -264,7 +263,7 @@ typedef NS_ENUM(NSUInteger, HMBattleType) {
        // 艦隊のチェック
        
        // Damage エンティティ作成6個
-       NSMutableArray *damages = [self damages];
+       NSArray<HMKCDamage *> *damages = [self damages];
        
        // koukuu
        [self calculateFDam:damages
@@ -324,7 +323,7 @@ typedef NS_ENUM(NSUInteger, HMBattleType) {
        [self updateBattleCell];
        
        // Damage 取得
-       NSMutableArray *damages = [self damages];
+       NSArray<HMKCDamage *> *damages = [self damages];
        
        // hougeki
        self.calcSecondFleet = self.isCombinedBattle;
@@ -363,7 +362,7 @@ NSInteger damageControlIfPossible(NSInteger nowhp, HMKCShipObject *ship)
 - (void)applyDamage
 {
        // Damage 取得
-       NSArray *damages = nil;
+       NSArray<HMKCDamage *> *damages = nil;
        
        NSError *error = nil;
        NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"id" ascending:YES];
@@ -382,9 +381,9 @@ NSInteger damageControlIfPossible(NSInteger nowhp, HMKCShipObject *ship)
        }
        
        error = nil;
-       NSArray *array = [self.store objectsWithEntityName:@"Battle"
-                                                                               predicate:nil
-                                                                                       error:&error];
+       NSArray<HMKCBattle *> *array = [self.store objectsWithEntityName:@"Battle"
+                                                                                                                  predicate:nil
+                                                                                                                          error:&error];
        if(error) {
                [self log:@"%s error: %@", __PRETTY_FUNCTION__, error];
                return;
@@ -395,14 +394,14 @@ NSInteger damageControlIfPossible(NSInteger nowhp, HMKCShipObject *ship)
        }
        
        HMServerDataStore *serverStore = [HMServerDataStore oneTimeEditor];
-       NSPredicate *predicate = [NSPredicate predicateWithFormat:@"id = %@", [array[0] valueForKey:@"deckId"]];
+       NSPredicate *predicate = [NSPredicate predicateWithFormat:@"id = %@", array[0].deckId];
        BOOL firstRun = YES;
        for(NSInteger i = 0; i < 2; i++) {
                // 艦隊メンバーを取得
                error = nil;
-               NSArray *decks = [serverStore objectsWithEntityName:@"Deck"
-                                                                                                 predicate:predicate
-                                                                                                         error:&error];
+               NSArray<HMKCDeck *> *decks = [serverStore objectsWithEntityName:@"Deck"
+                                                                                                                         predicate:predicate
+                                                                                                                                 error:&error];
                if(error) {
                        [self log:@"%s error: %@", __PRETTY_FUNCTION__, error];
                        return;
@@ -412,21 +411,15 @@ NSInteger damageControlIfPossible(NSInteger nowhp, HMKCShipObject *ship)
                        [self log:@"Deck is invalid. %s", __PRETTY_FUNCTION__];
                        return;
                }
-               id deck = decks[0];
-               NSMutableArray *shipIds = [NSMutableArray new];
-               [shipIds addObject:[deck valueForKey:@"ship_0"]];
-               [shipIds addObject:[deck valueForKey:@"ship_1"]];
-               [shipIds addObject:[deck valueForKey:@"ship_2"]];
-               [shipIds addObject:[deck valueForKey:@"ship_3"]];
-               [shipIds addObject:[deck valueForKey:@"ship_4"]];
-               [shipIds addObject:[deck valueForKey:@"ship_5"]];
+               HMKCDeck *deck = decks[0];
+               NSArray *shipIds = @[deck.ship_0, deck.ship_1, deck.ship_2, deck.ship_3, deck.ship_4, deck.ship_5];
                
-               NSMutableArray *ships = [NSMutableArray new];
+               NSMutableArray<HMKCShipObject *> *ships = [NSMutableArray new];
                for(id shipId in shipIds) {
                        error = nil;
-                       NSArray *ship = [serverStore objectsWithEntityName:@"Ship"
-                                                                                                                error:&error
-                                                                                          predicateFormat:@"id = %@", @([shipId integerValue])];
+                       NSArray<HMKCShipObject *> *ship = [serverStore objectsWithEntityName:@"Ship"
+                                                                                                                                                  error:&error
+                                                                                                                                predicateFormat:@"id = %@", @([shipId integerValue])];
                        if(error) {
                                [self log:@"%s error: %@", __PRETTY_FUNCTION__, error];
                        }
@@ -438,15 +431,13 @@ NSInteger damageControlIfPossible(NSInteger nowhp, HMKCShipObject *ship)
                NSUInteger shipCount = ships.count;
                NSUInteger offset = (self.isCombinedBattle && !firstRun) ? 6 : 0;
                for(NSInteger i = 0; i < shipCount; i++) {
-                       HMKCShipObject *ship = ships[i];
-                       NSInteger damage = [[damages[i + offset] valueForKey:@"damage"] integerValue];
-                       NSInteger nowhp = [[ship valueForKey:@"nowhp"] integerValue];
+                       NSInteger damage = damages[i + offset].damage.integerValue;
+                       NSInteger nowhp = ships[i].nowhp.integerValue;
                        nowhp -= damage;
-                       [ship setValue:@(nowhp) forKeyPath:@"nowhp"];
                        if(nowhp <= 0) {
-                               nowhp = damageControlIfPossible(nowhp, ship);
+                               nowhp = damageControlIfPossible(nowhp, ships[i]);
                        }
-                       ship.nowhp = @(nowhp);
+                       ships[i].nowhp = @(nowhp);
                }
                
                predicate = [NSPredicate predicateWithFormat:@"id = %@", @2];
index e756781..52ca1c8 100644 (file)
@@ -9,6 +9,7 @@
 #import "HMChangeHenseiCommand.h"
 
 #import "HMServerDataStore.h"
+#import "HMKCDeck+Extension.h"
 
 @interface HMChangeHenseiCommand ()
 @property (nonatomic, strong) HMServerDataStore *store;
 {
        NSError *error = nil;
        NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"id" ascending:YES];
-       NSArray *decks = [self.store objectsWithEntityName:@"Deck"
-                                                                          sortDescriptors:@[sortDescriptor]
-                                                                                        predicate:nil
-                                                                                                error:&error];
+       NSArray<HMKCDeck *> *decks = [self.store objectsWithEntityName:@"Deck"
+                                                                                                  sortDescriptors:@[sortDescriptor]
+                                                                                                                predicate:nil
+                                                                                                                        error:&error];
        // TODO: error handling
        
        NSMutableArray *ships = [NSMutableArray new];
-       for(id deck in decks) {
+       for(HMKCDeck *deck in decks) {
                for(NSUInteger i = 0; i < 6; i++) {
                        [ships addObject:[deck valueForKey:[NSString stringWithFormat:@"ship_%ld", i]]];
                }
 - (void)packFleet
 {
        NSError *error = nil;
-       NSArray *decks = [self.store objectsWithEntityName:@"Deck"
-                                                                                        predicate:nil
-                                                                                                error:&error];
+       NSArray<HMKCDeck *> *decks = [self.store objectsWithEntityName:@"Deck"
+                                                                                                                predicate:nil
+                                                                                                                        error:&error];
        // TODO: error handling
        
-       for(id deck in decks) {
+       for(HMKCDeck *deck in decks) {
                BOOL needsPack = NO;
                for(NSInteger i = 0; i < 6; i++) {
                        NSInteger shipId = [[deck valueForKey:[NSString stringWithFormat:@"ship_%ld", i]] integerValue];
        NSInteger deckNumber = [[self.arguments valueForKey:@"api_id"] integerValue];
        
        NSError *error = nil;
-       NSArray *decks = [self.store objectsWithEntityName:@"Deck"
-                                                                                                error:&error
-                                                                          predicateFormat:@"id = %ld", deckNumber];
+       NSArray<HMKCDeck *> *decks = [self.store objectsWithEntityName:@"Deck"
+                                                                                                                        error:&error
+                                                                                                  predicateFormat:@"id = %ld", deckNumber];
        // TODO: error handling
-       id deck = decks[0];
+       HMKCDeck *deck = decks[0];
        
        for(NSInteger i = 1; i < 6; i++) {
                [deck setValue:@(-1) forKey:[NSString stringWithFormat:@"ship_%ld", i]];
        
        NSError *error = nil;
        NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"id" ascending:YES];
-       NSArray *decks = [self.store objectsWithEntityName:@"Deck"
-                                                                          sortDescriptors:@[sortDescriptor]
-                                                                                        predicate:nil
-                                                                                                error:&error];
+       NSArray<HMKCDeck *> *decks = [self.store objectsWithEntityName:@"Deck"
+                                                                                                  sortDescriptors:@[sortDescriptor]
+                                                                                                                predicate:nil
+                                                                                                                        error:&error];
        // TODO: error handling
        
        NSMutableArray *ships = [NSMutableArray new];
-       for(id deck in decks) {
+       for(HMKCDeck *deck in decks) {
                for(NSUInteger i = 0; i < 6; i++) {
                        [ships addObject:[deck valueForKey:[NSString stringWithFormat:@"ship_%ld", i]]];
                }
        NSInteger replaceShipId = [ships[(deckNumber - 1) * 6 + shipIndex] integerValue];
        
        // 艦隊に配備
-       id deck = decks[deckNumber - 1];
+       HMKCDeck *deck = decks[deckNumber - 1];
        [deck setValue:@(shipId) forKey:[NSString stringWithFormat:@"ship_%ld", shipIndex]];
        
        // 入れ替え
        if(alreadyInFleet && shipId != -1) {
-               id deck = decks[shipDeckNumber];
+               HMKCDeck *deck = decks[shipDeckNumber];
                [deck setValue:@(replaceShipId) forKey:[NSString stringWithFormat:@"ship_%ld", shipDeckIndex]];
        }
        
index 34d88cd..2cefc71 100644 (file)
 #import "HMServerDataStore.h"
 #import "HMLocalDataStore.h"
 #import "HMKenzoMark.h"
+#import "HMKCKenzoDock.h"
+#import "HMKCDeck+Extension.h"
+#import "HMKCMasterShipObject.h"
+#import "HMKCShipObject+Extensions.h"
+#import "HMKCBasic.h"
+
 
 /**
  *  建造履歴に残すために秘書艦と司令部レベルを保存する
 {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                HMServerDataStore *serverDataStore = [HMServerDataStore oneTimeEditor];
-               NSArray *array = [serverDataStore objectsWithEntityName:@"KenzoDock"
-                                                                                                                 error:NULL
-                                                                                               predicateFormat:@"id = %@", @([[self.arguments valueForKey:@"api_kdock_id"] integerValue])];
-               if([array count] == 0) {
+               NSArray<HMKCKenzoDock *> *kenzoDocks = [serverDataStore objectsWithEntityName:@"KenzoDock"
+                                                                                                                                                               error:NULL
+                                                                                                                                         predicateFormat:@"id = %@", @([[self.arguments valueForKey:@"api_kdock_id"] integerValue])];
+               if([kenzoDocks count] == 0) {
                        NSLog(@"KenzoDock data is invalid.");
                        return;
                }
                
-               id kdock = array[0];
-               NSNumber *item1 = [kdock valueForKey:@"item1"];
+               HMKCKenzoDock *kdock = kenzoDocks[0];
+               NSNumber *item1 = kdock.item1;
                
                // Deck -> FlagShip
-               array = [serverDataStore objectsWithEntityName:@"Deck" error:NULL predicateFormat:@"id = 1"];
-               if([array count] == 0) {
+               NSArray<HMKCDeck *> *decks = [serverDataStore objectsWithEntityName:@"Deck" error:NULL predicateFormat:@"id = 1"];
+               if([decks count] == 0) {
                        NSLog(@"Deck data is invalid.");
                        return;
                }
-               id deck = array[0];
-               id flagShipID = [deck valueForKey:@"ship_0"];
-               array = [serverDataStore objectsWithEntityName:@"Ship" error:NULL predicateFormat:@"id = %@", flagShipID];
-               if([array count] == 0) {
+               HMKCDeck *deck = decks[0];
+               NSNumber *flagShipID = deck.ship_0;
+               NSArray<HMKCShipObject *> *ships = [serverDataStore objectsWithEntityName:@"Ship" error:NULL predicateFormat:@"id = %@", flagShipID];
+               if([ships count] == 0) {
                        NSLog(@"Ship data is invalid or ship_0 is invalid.");
                        return;
                }
-               id flagShip = array[0];
-               NSNumber *flagShipLv = [flagShip valueForKey:@"lv"];
-               NSString *flagShipName = [flagShip valueForKeyPath:@"master_ship.name"];
+               HMKCShipObject *flagShip = ships[0];
+               NSNumber *flagShipLv = flagShip.lv;
+               NSString *flagShipName = flagShip.master_ship.name;
                
                // Basic -> level
-               array = [serverDataStore objectsWithEntityName:@"Basic" predicate:nil error:NULL];
-               if([array count] == 0) {
+               NSArray<HMKCBasic *> *basics = [serverDataStore objectsWithEntityName:@"Basic" predicate:nil error:NULL];
+               if([basics count] == 0) {
                        NSLog(@"Basic data is invalid.");
                        return;
                }
-               id basic = array[0];
+               HMKCBasic *basic = basics[0];
                
                //
                HMLocalDataStore *lds = [HMLocalDataStore oneTimeEditor];
                HMKenzoMark *newObejct = nil;
-               array = [lds objectsWithEntityName:@"KenzoMark"
-                                                                        error:NULL
-                                                  predicateFormat:@"kDockId = %@", @([[self.arguments valueForKey:@"api_kdock_id"] integerValue])];
-               if([array count] == 0) {
+               NSArray<HMKenzoMark *> *kenzomarks = [lds objectsWithEntityName:@"KenzoMark"
+                                                                                                                                 error:NULL
+                                                                                                               predicateFormat:@"kDockId = %@", @([[self.arguments valueForKey:@"api_kdock_id"] integerValue])];
+               if([kenzomarks count] == 0) {
                        newObejct = [NSEntityDescription insertNewObjectForEntityForName:@"KenzoMark"
                                                                                                          inManagedObjectContext:[lds managedObjectContext]];
                } else {
-                       newObejct = array[0];
+                       newObejct = kenzomarks[0];
                }
                
                newObejct.fuel = item1;
-               newObejct.bull = [kdock valueForKey:@"item2"];
-               newObejct.steel = [kdock valueForKey:@"item3"];
-               newObejct.bauxite = [kdock valueForKey:@"item4"];
-               newObejct.kaihatusizai = [kdock valueForKey:@"item5"];
-               newObejct.created_ship_id = [kdock valueForKey:@"created_ship_id"];
+               newObejct.bull = kdock.item2;
+               newObejct.steel = kdock.item3;
+               newObejct.bauxite = kdock.item4;
+               newObejct.kaihatusizai = kdock.item5;
+               newObejct.created_ship_id = kdock.created_ship_id;
                newObejct.flagShipLv = flagShipLv;
                newObejct.flagShipName = flagShipName;
-               newObejct.commanderLv = [basic  valueForKey:@"level"];
+               newObejct.commanderLv = basic.level;
                newObejct.kDockId = @([[self.arguments valueForKey:@"api_kdock_id"] integerValue]);
        });
 }
index 004bff1..9e83a25 100644 (file)
@@ -9,6 +9,8 @@
 #import "HMDestroyItem2Command.h"
 
 #import "HMServerDataStore.h"
+#import "HMKCSlotItemObject+Extensions.h"
+#import "HMKCMaterial.h"
 
 
 @implementation HMDestroyItem2Command
        }
        
        NSError *error = nil;
-       NSArray *array = [store objectsWithEntityName:@"SlotItem"
-                                                                                  error:&error
-                                                                predicateFormat:@"id IN %@", items];
-       if([array count] == 0) {
+       NSArray<HMKCSlotItemObject *> *slotItems = [store objectsWithEntityName:@"SlotItem"
+                                                                                                                                         error:&error
+                                                                                                                       predicateFormat:@"id IN %@", items];
+       if(slotItems.count == 0) {
                NSLog(@"SlotItem is invalid.");
                return;
        }
        
-       for(id obj in array) {
+       for(id obj in slotItems) {
                [moc deleteObject:obj];
        }
        
        //
        error = nil;
-       array = [store objectsWithEntityName:@"Material" predicate:nil error:&error];
+       NSArray<HMKCMaterial *> *materials = [store objectsWithEntityName:@"Material" predicate:nil error:&error];
        if(error) {
                [self log:@"Fetch error: %@", error];
                return;
        }
-       if([array count] == 0) {
+       if(materials.count == 0) {
                NSLog(@"SlotItem is invalid.");
                return;
        }
        
-       id material = array[0];
        NSArray *keys = @[@"fuel", @"bull", @"steel", @"bauxite", @"kousokukenzo", @"kousokushuhuku", @"kaihatusizai", @"screw"];
        
-       NSArray *materials = [self.json valueForKeyPath:@"api_data.api_get_material"];
+       NSArray *gotMaterials = [self.json valueForKeyPath:@"api_data.api_get_material"];
        for(NSInteger i = 0; i < 4; i++) {
-               NSInteger current = [[material valueForKey:keys[i]] integerValue];
-               NSInteger increase = [materials[i] integerValue];
-               [material setValue:@(current + increase) forKey:keys[i]];
+               NSInteger current = [[materials[0] valueForKey:keys[i]] integerValue];
+               NSInteger increase = [gotMaterials[i] integerValue];
+               [materials[0] setValue:@(current + increase) forKey:keys[i]];
        }
 }
 @end
index 477df42..c42ab31 100644 (file)
 #import "HMLocalDataStore.h"
 #import "HMTemporaryDataStore.h"
 #import "HMDropShipHistory.h"
+#import "HMKCBattle.h"
+#import "HMKCMasterMapInfo.h"
+#import "HMKCMasterMapArea.h"
 
 @implementation HMDropShipHistoryCommand
 
-- (NSManagedObject *)battle
+- (HMKCBattle *)battle
 {
        HMTemporaryDataStore *store = [HMTemporaryDataStore defaultManager];
        NSError *error = nil;
-       NSArray *array  = [store objectsWithEntityName:@"Battle" predicate:nil error:&error];
+       NSArray<HMKCBattle *> *battles  = [store objectsWithEntityName:@"Battle" predicate:nil error:&error];
        if(error) {
                NSLog(@"%s error: %@", __PRETTY_FUNCTION__, error);
        }
-       return array.count > 0 ? array[0] : nil;
+       return battles.count > 0 ? battles[0] : nil;
 }
 - (void)execute
 {
        id getShip = [data valueForKey:@"api_get_ship"];
        if(!getShip || [getShip isKindOfClass:[NSNull class]]) return;
        
-       id battle = [self battle];
+       HMKCBattle *battle = [self battle];
        if(!battle) {
                NSLog(@"Can not get battle object");
                return;
        }
        
-       id mapAreaId = [battle valueForKey:@"mapArea"];
-       id mapInfoId = [battle valueForKey:@"mapInfo"];
-       id mapCellNo = [battle valueForKey:@"no"];
+       NSNumber *mapAreaId = battle.mapArea;
+       NSNumber *mapInfoId = battle.mapInfo;
+       NSNumber *mapCellNo = battle.no;
        
        HMServerDataStore *store = [HMServerDataStore defaultManager];
        NSError *error = nil;
-       NSArray *array = [store objectsWithEntityName:@"MasterMapInfo"
-                                                                                       error:&error
-                                                                 predicateFormat:@"maparea_id = %@ AND %K = %@", mapAreaId, @"no", mapInfoId];
+       NSArray<HMKCMasterMapInfo *> *mapInfos = [store objectsWithEntityName:@"MasterMapInfo"
+                                                                                                                                       error:&error
+                                                                                                                 predicateFormat:@"maparea_id = %@ AND %K = %@", mapAreaId, @"no", mapInfoId];
        if(error) {
                NSLog(@"%s error: %@", __PRETTY_FUNCTION__, error);
        }
-       if(array.count == 0) {
+       if(mapInfos.count == 0) {
                NSLog(@"%s error: Can not get mapInfo", __PRETTY_FUNCTION__);
                return;
        }
-       id mapInfoName = [array[0] valueForKey:@"name"];
+       NSString *mapInfoName = mapInfos[0].name;
        
        error = nil;
-       array = [store objectsWithEntityName:@"MasterMapArea"
-                                                                  error:&error
-                                                predicateFormat:@"id = %@", mapAreaId];
+       NSArray<HMKCMasterMapArea *> *mapAreas = [store objectsWithEntityName:@"MasterMapArea"
+                                                                                                                                error:&error
+                                                                                                          predicateFormat:@"id = %@", mapAreaId];
        if(error) {
                NSLog(@"%s error: %@", __PRETTY_FUNCTION__, error);
        }
-       if(array.count == 0) {
+       if(mapAreas.count == 0) {
                NSLog(@"%s error: Can not get mapArea", __PRETTY_FUNCTION__);
                return;
        }
-       id mapAreaName = [array[0] valueForKey:@"name"];
+       NSString *mapAreaName = mapAreas[0].name;
        
        HMLocalDataStore *lds = [HMLocalDataStore oneTimeEditor];
        HMDropShipHistory *newObejct = [NSEntityDescription insertNewObjectForEntityForName:@"HiddenDropShipHistory"
 {
        HMLocalDataStore *lds = [HMLocalDataStore oneTimeEditor];
        NSError *error = nil;
-       NSArray *array = [lds objectsWithEntityName:@"HiddenDropShipHistory"
-                                                                         predicate:nil
-                                                                                 error:&error];
+       NSArray<HMDropShipHistory *> *dropShipHistories = [lds objectsWithEntityName:@"HiddenDropShipHistory"
+                                                                                                                                          predicate:nil
+                                                                                                                                                  error:&error];
        if(error) {
                NSLog(@"%s error: %@", __PRETTY_FUNCTION__, error);
        }
        NSManagedObjectContext *context = lds.managedObjectContext;
-       for(HMDropShipHistory *history in array) {
+       for(HMDropShipHistory *history in dropShipHistories) {
                HMDropShipHistory *newObejct = [NSEntityDescription insertNewObjectForEntityForName:@"DropShipHistory"
                                                                                                                                         inManagedObjectContext:[lds managedObjectContext]];
                
index 060f5ad..c3acc92 100644 (file)
@@ -44,10 +44,10 @@ static BOOL getShipFlag = 0;
        NSError *error = nil;
        HMServerDataStore *serverDataStore = [HMServerDataStore oneTimeEditor];
        NSManagedObjectContext *managedObjectContext = [serverDataStore managedObjectContext];
-       NSArray *dummys = [serverDataStore objectsWithEntityName:@"Ship"
-                                                                                                          error:&error
-                                                                                        predicateFormat:@"id = %@", @(-2)];
-       for(NSManagedObject *dummy in dummys) {
+       NSArray<HMKCShipObject *> *dummys = [serverDataStore objectsWithEntityName:@"Ship"
+                                                                                                                                                error:&error
+                                                                                                                          predicateFormat:@"id = %@", @(-2)];
+       for(HMKCShipObject *dummy in dummys) {
                [managedObjectContext deleteObject:dummy];
        }
 }
index 1320b86..dad96a2 100644 (file)
@@ -13,6 +13,7 @@
 #import "HMServerDataStore.h"
 
 #import "HMKCDeck.h"
+#import "HMKCGuardEscaped.h"
 
 
 NSString *HMGuardShelterCommandDidUpdateGuardExcapeNotification = @"HMGuardShelterCommandDidUpdateGuardExcapeNotification";
@@ -56,9 +57,9 @@ NSString *HMGuardShelterCommandDidUpdateGuardExcapeNotification = @"HMGuardShelt
        NSError *error = nil;
        HMServerDataStore *serverStore = [HMServerDataStore defaultManager];
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"id = %@", feetID];
-       NSArray *decks = [serverStore objectsWithEntityName:@"Deck"
-                                                                                         predicate:predicate
-                                                                                                 error:&error];
+       NSArray<HMKCDeck *> *decks = [serverStore objectsWithEntityName:@"Deck"
+                                                                                                                 predicate:predicate
+                                                                                                                         error:&error];
        if(error) {
                [self log:@"%s error: %@", __PRETTY_FUNCTION__, error];
                return nil;
@@ -68,14 +69,13 @@ NSString *HMGuardShelterCommandDidUpdateGuardExcapeNotification = @"HMGuardShelt
                [self log:@"Deck is invalid. %s", __PRETTY_FUNCTION__];
                return nil;
        }
-       HMKCDeck *deck = decks[0];
        NSArray *shipIds = @[
-                                                deck.ship_0,
-                                                deck.ship_1,
-                                                deck.ship_2,
-                                                deck.ship_3,
-                                                deck.ship_4,
-                                                deck.ship_5,
+                                                decks[0].ship_0,
+                                                decks[0].ship_1,
+                                                decks[0].ship_2,
+                                                decks[0].ship_3,
+                                                decks[0].ship_4,
+                                                decks[0].ship_5,
                                                 ];
        
        return shipIds;
@@ -108,33 +108,33 @@ NSString *HMGuardShelterCommandDidUpdateGuardExcapeNotification = @"HMGuardShelt
        
        
        HMTemporaryDataStore *store = [HMTemporaryDataStore oneTimeEditor];
-       NSManagedObject *object = [NSEntityDescription insertNewObjectForEntityForName:@"GuardEscaped"
-                                                                                                                  inManagedObjectContext:store.managedObjectContext];
-       [object setValue:guardianID forKey:@"shipID"];
-       [object setValue:@NO forKey:@"ensured"];
+       HMKCGuardEscaped *guardian = [NSEntityDescription insertNewObjectForEntityForName:@"GuardEscaped"
+                                                                                                                          inManagedObjectContext:store.managedObjectContext];
+       guardian.shipID = guardianID;
+       guardian.ensured = @NO;
        
-       object = [NSEntityDescription insertNewObjectForEntityForName:@"GuardEscaped"
+       HMKCGuardEscaped *damaged = [NSEntityDescription insertNewObjectForEntityForName:@"GuardEscaped"
                                                                                   inManagedObjectContext:store.managedObjectContext];
-       [object setValue:damagedShipID forKey:@"shipID"];
-       [object setValue:@NO forKey:@"ensured"];
+       damaged.shipID = damagedShipID;
+       damaged.ensured = @NO;
        
 }
 - (void)removeInvalidEntry
 {
        HMTemporaryDataStore *store = [HMTemporaryDataStore oneTimeEditor];
        NSError *error = nil;
-       NSArray *array = [store objectsWithEntityName:@"GuardEscaped"
-                                                                                       error:&error
-                                                                 predicateFormat:@"ensured = FALSE"];
+       NSArray<HMKCGuardEscaped *> *escapeds = [store objectsWithEntityName:@"GuardEscaped"
+                                                                                                                                  error:&error
+                                                                                                         predicateFormat:@"ensured = FALSE"];
        if(error) {
                NSLog(@"GuardEscaped is invalid. -> %@", error);
                return;
        }
-       if(!array) {
+       if(!escapeds) {
                NSLog(@"GuardEscaped is invalid. -> %@", error);
                return;
        }
-       for(NSManagedObject *object in array) {
+       for(NSManagedObject *object in escapeds) {
                [store.managedObjectContext deleteObject:object];
        }
        [store saveAction:nil];
@@ -146,18 +146,18 @@ NSString *HMGuardShelterCommandDidUpdateGuardExcapeNotification = @"HMGuardShelt
 {
        HMTemporaryDataStore *store = [HMTemporaryDataStore oneTimeEditor];
        NSError *error = nil;
-       NSArray *array = [store objectsWithEntityName:@"GuardEscaped"
-                                                                                       error:&error
-                                                                 predicateFormat:nil];
+       NSArray<HMKCGuardEscaped *> *escapeds = [store objectsWithEntityName:@"GuardEscaped"
+                                                                                                                                  error:&error
+                                                                                                                predicateFormat:nil];
        if(error) {
                NSLog(@"GuardEscaped is invalid. -> %@", error);
                return;
        }
-       if(!array) {
+       if(!escapeds) {
                NSLog(@"GuardEscaped is invalid. -> %@", error);
                return;
        }
-       for(NSManagedObject *object in array) {
+       for(NSManagedObject *object in escapeds) {
                [store.managedObjectContext deleteObject:object];
        }
        [store saveAction:nil];
@@ -169,9 +169,9 @@ NSString *HMGuardShelterCommandDidUpdateGuardExcapeNotification = @"HMGuardShelt
 {
        HMTemporaryDataStore *store = [HMTemporaryDataStore oneTimeEditor];
        NSError *error = nil;
-       NSArray *shelters = [store objectsWithEntityName:@"GuardEscaped"
-                                                                                          error:&error
-                                                                        predicateFormat:nil];
+       NSArray<HMKCGuardEscaped *> *shelters = [store objectsWithEntityName:@"GuardEscaped"
+                                                                                                                                  error:&error
+                                                                                                                predicateFormat:nil];
        if(error) {
                NSLog(@"GuardEscaped is invalid. -> %@", error);
                return;
@@ -180,8 +180,8 @@ NSString *HMGuardShelterCommandDidUpdateGuardExcapeNotification = @"HMGuardShelt
                NSLog(@"GuardEscaped is invalid. -> %@", error);
                return;
        }
-       for(NSManagedObject *object in shelters) {
-               [object setValue:@YES forKey:@"ensured"];
+       for(HMKCGuardEscaped *object in shelters) {
+               object.ensured = @YES;
        }
        [store saveAction:nil];
        [NSThread sleepForTimeInterval:0.1];
index 558d1ef..03c70a8 100644 (file)
@@ -9,6 +9,7 @@
 #import "HMKaisouLockCommand.h"
 
 #import "HMServerDataStore.h"
+#import "HMKCSlotItemObject+Extensions.h"
 
 @implementation HMKaisouLockCommand
 + (void)load
        
        HMServerDataStore *serverDataStore = [HMServerDataStore oneTimeEditor]; 
        NSError *error = nil;
-       NSArray *result = [serverDataStore objectsWithEntityName:@"SlotItem"
-                                                                                                error:&error
-                                                                          predicateFormat:@"id = %ld", [slotitemId integerValue]];
+       NSArray<HMKCSlotItemObject *> *slotItems = [serverDataStore objectsWithEntityName:@"SlotItem"
+                                                                                                                                                        error:&error
+                                                                                                                                  predicateFormat:@"id = %ld", [slotitemId integerValue]];
        if(error) {
                [self log:@"Fetch error: %@", error];
                return;
        }
-       if(result.count == 0) {
+       if(slotItems.count == 0) {
                [self log:@"Could not find SlotItem number %@", slotitemId];
                return;
        }
        
        BOOL locked = [api_data[@"api_locked"] boolValue];
-       [result[0] setValue:@(locked) forKey:@"locked"];
+       slotItems[0].locked = @(locked);
 }
 
 @end
index 4c519f4..226e526 100644 (file)
 #import "HMServerDataStore.h"
 #import "HMLocalDataStore.h"
 #import "HMKenzoHistory.h"
+#import "HMKenzoMark.h"
+#import "HMKCKenzoDock.h"
+#import "HMKCMasterShipObject.h"
+#import "HMKCMasterSType.h"
+
 
 /**
  *  建造履歴を残す
 - (void)execute
 {
        HMServerDataStore *serverDataStore = [HMServerDataStore oneTimeEditor];
-       NSArray *array = [serverDataStore objectsWithEntityName:@"KenzoDock"
-                                                                                                         error:NULL
-                                                                                       predicateFormat:@"id = %@", @([[self.arguments valueForKey:@"api_kdock_id"] integerValue])];
-       if([array count] == 0) {
+       NSArray<HMKCKenzoDock *> *kenzoDocks = [serverDataStore objectsWithEntityName:@"KenzoDock"
+                                                                                                                                          error:NULL
+                                                                                                                        predicateFormat:@"id = %@", @([[self.arguments valueForKey:@"api_kdock_id"] integerValue])];
+       if([kenzoDocks count] == 0) {
                NSLog(@"KenzoDock data is invalid.");
                return;
        }
-       
-       id kdock = array[0];
-       NSNumber *item1 = [kdock valueForKey:@"item1"];
+       NSNumber *item1 = kenzoDocks[0].item1;
        
        //
-       array = [serverDataStore objectsWithEntityName:@"MasterShip" error:NULL predicateFormat:@"id = %@", [kdock valueForKey:@"created_ship_id"]];
-       if([array count] == 0) {
+       NSArray<HMKCMasterShipObject *> *ships = [serverDataStore objectsWithEntityName:@"MasterShip"
+                                                                                                                                                         error:NULL
+                                                                                                                         predicateFormat:@"id = %@", kenzoDocks[0].created_ship_id];
+       if([ships count] == 0) {
                NSLog(@"MasterShip data is invalid or ship_id is invalid.");
                return;
        }
-       id ship = array[0];
        
        //
        NSNumber *flagShipLv = nil;
        NSString *flafShipName = nil;
        NSNumber *commanderLv = nil;
        HMLocalDataStore *localDataStore = [HMLocalDataStore oneTimeEditor];
-       array = [localDataStore objectsWithEntityName:@"KenzoMark"
-                                                                                       error:NULL
-                                                                 predicateFormat:@"fuel = %@ AND bull = %@ AND steel = %@ AND bauxite = %@ AND kaihatusizai = %@ AND kDockId = %@ AND created_ship_id = %@",
-                        item1, [kdock valueForKey:@"item2"], [kdock valueForKey:@"item3"], [kdock valueForKey:@"item4"], [kdock valueForKey:@"item5"],
-                        @([[self.arguments valueForKey:@"api_kdock_id"] integerValue]), [kdock valueForKey:@"created_ship_id"]
-                        ];
-       if([array count] != 0) {
-               flagShipLv = [array[0] valueForKey:@"flagShipLv"];
-               flafShipName = [array[0] valueForKey:@"flagShipName"];
-               commanderLv = [array[0] valueForKey:@"commanderLv"];
+       NSArray<HMKenzoMark *> *kenzoMarks = [localDataStore objectsWithEntityName:@"KenzoMark"
+                                                                                                                                                error:NULL
+                                                                                                                          predicateFormat:
+                                                                                 @"fuel = %@ AND bull = %@ AND steel = %@ AND bauxite = %@ AND kaihatusizai = %@ AND kDockId = %@ AND created_ship_id = %@",
+                                                                                 item1, kenzoDocks[0].item2, kenzoDocks[0].item3, kenzoDocks[0].item4, kenzoDocks[0].item5,
+                                                                                 @([[self.arguments valueForKey:@"api_kdock_id"] integerValue]), kenzoDocks[0].created_ship_id
+                                                                                 ];
+       if([kenzoMarks count] != 0) {
+               flagShipLv = kenzoMarks[0].flagShipLv;
+               flafShipName = kenzoMarks[0].flagShipName;
+               commanderLv = kenzoMarks[0].commanderLv;
        }
        
        HMLocalDataStore *lds = [HMLocalDataStore oneTimeEditor];
        NSManagedObjectContext *localStoreContext = [lds managedObjectContext];
        HMKenzoHistory *newObejct = [NSEntityDescription insertNewObjectForEntityForName:@"KenzoHistory"
                                                                                                                          inManagedObjectContext:localStoreContext];
-       newObejct.name = [ship valueForKey:@"name"];
-       newObejct.sTypeId = [ship valueForKeyPath:@"stype.id"];
+       newObejct.name = ships[0].name;
+       newObejct.sTypeId = ships[0].stype.id;
        newObejct.fuel = item1;
-       newObejct.bull = [kdock valueForKey:@"item2"];
-       newObejct.steel = [kdock valueForKey:@"item3"];
-       newObejct.bauxite = [kdock valueForKey:@"item4"];
-       newObejct.kaihatusizai = [kdock valueForKey:@"item5"];
+       newObejct.bull = kenzoDocks[0].item2;
+       newObejct.steel = kenzoDocks[0].item3;
+       newObejct.bauxite = kenzoDocks[0].item4;
+       newObejct.kaihatusizai = kenzoDocks[0].item5;
        newObejct.flagShipLv = flagShipLv;
        newObejct.flagShipName = flafShipName;
        newObejct.commanderLv = commanderLv;
index 37b5cfd..2434629 100644 (file)
@@ -9,6 +9,8 @@
 #import "HMNyukyoSpeedChangeCommand.h"
 
 #import "HMServerDataStore.h"
+#import "HMKCNyukyoDock.h"
+#import "HMKCShipObject+Extensions.h"
 
 
 @implementation HMNyukyoSpeedChangeCommand
        NSString *ndockId = self.arguments[@"api_ndock_id"];
        
        NSError *error = nil;
-       NSArray *array = [store objectsWithEntityName:@"NyukyoDock"
-                                                                                       error:&error
-                                                                 predicateFormat:@"id = %@", @([ndockId integerValue])];
-       if(array.count == 0) {
+       NSArray<HMKCNyukyoDock *> *nyukyoDocks = [store objectsWithEntityName:@"NyukyoDock"
+                                                                                                                         error:&error
+                                                                                                                 predicateFormat:@"id = %@", @([ndockId integerValue])];
+       if(nyukyoDocks.count == 0) {
                if(error) {
                        NSLog(@"Error: at %@ : %@", NSStringFromClass([self class]), error);
                }
                return;
        }
        
-       id dock = array[0];
-       
-       NSString *shipId = [dock valueForKey:@"ship_id"];
-       
-       [dock setValue:nil forKey:@"ship_id"];
-       [dock setValue:@(0) forKey:@"state"];
+       NSNumber *shipId = nyukyoDocks[0].ship_id;
        
+       nyukyoDocks[0].ship_id = nil;
+       nyukyoDocks[0].state = @(0);
        
        // 艦隊リスト更新用
        error = nil;
-       array = [store objectsWithEntityName:@"Ship"
-                                                                  error:&error
-                                                predicateFormat:@"id = %@", @([shipId integerValue])];
-       if(array.count == 0) {
+       NSArray<HMKCShipObject *> *ships = [store objectsWithEntityName:@"Ship"
+                                                                                                                         error:&error
+                                                                                                       predicateFormat:@"id = %@", @([shipId integerValue])];
+       if(ships.count == 0) {
                if(error) {
                        NSLog(@"Error: at %@ : %@", NSStringFromClass([self class]), error);
                }
                return;
        }
        
-       id ship = array[0];
-       [ship setValue:[ship valueForKey:@"maxhp"] forKey:@"nowhp"];
+       ships[0].nowhp = ships[0].maxhp;
 }
 @end
index 268670b..f43c5ba 100644 (file)
@@ -9,6 +9,7 @@
 #import "HMNyukyoStartCommand.h"
 
 #import "HMServerDataStore.h"
+#import "HMKCShipObject+Extensions.h"
 
 
 @implementation HMNyukyoStartCommand
        NSString *shipId = self.arguments[@"api_ship_id"];
        
        NSError *error = nil;
-       NSArray *array = [store objectsWithEntityName:@"Ship"
-                                                                                       error:&error
-                                                                 predicateFormat:@"id = %@", @([shipId integerValue])];
-       if(array.count == 0) {
+       NSArray<HMKCShipObject *> *ships = [store objectsWithEntityName:@"Ship"
+                                                                                                                         error:&error
+                                                                                                       predicateFormat:@"id = %@", @([shipId integerValue])];
+       if(ships.count == 0) {
                if(error) {
                        NSLog(@"Error: at %@ : %@", NSStringFromClass([self class]), error);
                }
                return;
        }
        
-       id ship = array[0];
-       [ship setValue:[ship valueForKey:@"maxhp"] forKey:@"nowhp"];
+       ships[0].nowhp = ships[0].maxhp;
 }
 @end
index 926e3e7..c910f23 100644 (file)
@@ -19,9 +19,9 @@
        NSString *destroyedShipId = [self.arguments objectForKey:@"api_ship_id"];
        
        NSError *error = nil;
-       NSArray *ships = [store objectsWithEntityName:@"Ship"
-                                                                                       error:&error
-                                                                 predicateFormat:@"id = %@", @([destroyedShipId integerValue])];
+       NSArray<NSManagedObject *> *ships = [store objectsWithEntityName:@"Ship"
+                                                                                                                          error:&error
+                                                                                                        predicateFormat:@"id = %@", @([destroyedShipId integerValue])];
        if(ships.count == 0) {
                return;
        }
index bf74e10..c71c431 100644 (file)
@@ -9,6 +9,7 @@
 #import "HMRealPowerUpCommand.h"
 
 #import "HMServerDataStore.h"
+#import "HMKCShipObject+Extensions.h"
 
 
 @implementation HMRealPowerUpCommand
@@ -22,9 +23,9 @@
        
        for(NSString *shipId in usedShipStringArray) {
                NSError *error = nil;
-               NSArray *ships = [store objectsWithEntityName:@"Ship"
-                                                                                               error:&error
-                                                                         predicateFormat:@"id = %@", @([shipId integerValue])];
+               NSArray<HMKCShipObject *> *ships = [store objectsWithEntityName:@"Ship"
+                                                                                                                                 error:&error
+                                                                                                               predicateFormat:@"id = %@", @([shipId integerValue])];
                if(ships.count == 0) {
                        continue;
                }
index 5b44343..9a12042 100644 (file)
@@ -9,6 +9,7 @@
 #import "HMRemodelSlotItemCommand.h"
 
 #import "HMServerDataStore.h"
+#import "HMKCSlotItemObject+Extensions.h"
 
 
 @implementation HMRemodelSlotItemCommand
        
        HMServerDataStore *serverDataStore = [HMServerDataStore oneTimeEditor];
        NSError *error = nil;
-       NSArray *result = [serverDataStore objectsWithEntityName:@"SlotItem"
-                                                                                                          error:&error
-                                                                                        predicateFormat:@"id = %ld", [slotitemId integerValue]];
+       NSArray<HMKCSlotItemObject *> *slotItems = [serverDataStore objectsWithEntityName:@"SlotItem"
+                                                                                                                                                               error:&error
+                                                                                                                                         predicateFormat:@"id = %ld", [slotitemId integerValue]];
        if(error) {
                [self log:@"Fetch error: %@", error];
                return;
        }
-       if(result.count == 0) {
+       if(slotItems.count == 0) {
                [self log:@"Could not find SlotItem number %@", slotitemId];
                return;
        }
        api_data = api_data[@"api_after_slot"];
        
        BOOL locked = [api_data[@"api_locked"] boolValue];
-       [result[0] setValue:@(locked) forKey:@"locked"];
+       slotItems[0].locked = @(locked);
        
        NSNumber *masterSoltItemId = api_data[@"api_slotitem_id"];
-       if([masterSoltItemId compare:[result[0] valueForKey:@"slotitem_id"]] != NSOrderedSame) {
-               [self setMasterSlotItemForItemID:masterSoltItemId object:result[0] store:serverDataStore];
+       if([masterSoltItemId compare:slotItems[0].slotitem_id] != NSOrderedSame) {
+               [self setMasterSlotItemForItemID:masterSoltItemId object:slotItems[0] store:serverDataStore];
        }
        
        NSNumber *level = api_data[@"api_level"];
-       [result[0] setValue:level forKey:@"level"];
+       slotItems[0].level = level;
 }
 
 - (void)setMasterSlotItemForItemID:(NSNumber *)slotItemId object:(id)object store:(HMServerDataStore *)serverDataStore
 {
        NSError *error = nil;
-       NSArray *result = [serverDataStore objectsWithEntityName:@"MasterSlotItem"
-                                                                                                          error:&error
-                                                                                        predicateFormat:@"id = %ld", [slotItemId integerValue]];
+       NSArray<HMKCSlotItemObject *> *slotItems = [serverDataStore objectsWithEntityName:@"MasterSlotItem"
+                                                                                                                                                               error:&error
+                                                                                                                                         predicateFormat:@"id = %ld", [slotItemId integerValue]];
        if(error) {
                [self log:@"Fetch error: %@", error];
                return;
        }
-       if(result.count == 0) {
+       if(slotItems.count == 0) {
                [self log:@"Could not find MasterSlotItem number %@", slotItemId];
                return;
        }
-       id item = result[0];
-       [self setValueIfNeeded:item toObject:object forKey:@"master_slotItem"];
+       [self setValueIfNeeded:slotItems[0] toObject:object forKey:@"master_slotItem"];
        [self setValueIfNeeded:slotItemId toObject:object forKey:@"slotitem_id"];
 }
 
index 4a70d60..08e1d69 100644 (file)
@@ -9,6 +9,7 @@
 #import "HMResetSortieCommand.h"
 
 #import "HMTemporaryDataStore.h"
+#import "HMKCBattle.h"
 
 
 @implementation HMResetSortieCommand
        NSManagedObjectContext *moc = store.managedObjectContext;
        
        NSError *error = nil;
-       NSArray *array = [store objectsWithEntityName:@"Battle"
-                                                                               predicate:nil
-                                                                                       error:NULL];
+       NSArray<HMKCBattle *> *battles = [store objectsWithEntityName:@"Battle"
+                                                                                                               predicate:nil
+                                                                                                                       error:NULL];
        if(error) {
                [self log:@"%s error: %@", __PRETTY_FUNCTION__, error];
                return;
        }
-       for(id object in array) {
+       for(HMKCBattle *object in battles) {
                [moc deleteObject:object];
        }
 }
index 2494dd2..f2b1b7f 100644 (file)
@@ -9,6 +9,7 @@
 #import "HMSlotResetCommand.h"
 
 #import "HMServerDataStore.h"
+#import "HMKCShipObject+Extensions.h"
 
 
 @interface HMSlotResetCommand ()
        NSString *destroyedShipId = [self.arguments objectForKey:@"api_id"];
        
        NSError *error = nil;
-       NSArray *ships = [store objectsWithEntityName:@"Ship"
-                                                                                       error:&error
-                                                                 predicateFormat:@"id = %@", @([destroyedShipId integerValue])];
+       NSArray<HMKCShipObject *> *ships = [store objectsWithEntityName:@"Ship"
+                                                                                                                         error:&error
+                                                                                                       predicateFormat:@"id = %@", @([destroyedShipId integerValue])];
        if(ships.count == 0) {
                return;
        }
        
-       id ship = ships[0];
+       HMKCShipObject *ship = ships[0];
        
        NSArray *slotItems = [self.json valueForKeyPath:@"api_data.api_slot"];
        for(NSUInteger i = 0; i < slotItems.count; i++) {
index 7fc7f8b..f1916b2 100644 (file)
 #import "HMServerDataStore.h"
 #import "HMLocalDataStore.h"
 #import "HMKaihatuHistory.h"
+#import "HMKCMasterSlotItemObject.h"
+#import "HMKCDeck+Extension.h"
+#import "HMKCShipObject+Extensions.h"
+#import "HMKCMasterShipObject.h"
+#import "HMKCBasic.h"
 
 @implementation HMStoreCreateSlotItemHistoryCommand
 
        
        if(created) {
                NSNumber *slotItemID = [data valueForKeyPath:@"api_slot_item.api_slotitem_id"];
-               NSArray *array = [serverDataStore objectsWithEntityName:@"MasterSlotItem"
-                                                                                                                 error:NULL
-                                                                                               predicateFormat:@"id = %@", slotItemID];
-               if([array count] == 0) {
+               NSArray<HMKCMasterSlotItemObject *> *masterSlotItems = [serverDataStore objectsWithEntityName:@"MasterSlotItem"
+                                                                                                                                                                                               error:NULL
+                                                                                                                                                                         predicateFormat:@"id = %@", slotItemID];
+               if([masterSlotItems count] == 0) {
                        NSLog(@"MasterSlotItem data is invalid or api_slotitem_id is invalid.");
                        return;
                }
-               name = [array[0] valueForKey:@"name"];
+               name = masterSlotItems[0].name;
                numberOfUsedKaihatuSizai = @1;
        } else {
                name = NSLocalizedString(@"fail to develop", @"");
        }
        
        // Deck -> FlagShip
-       NSArray *array = [serverDataStore objectsWithEntityName:@"Deck" error:NULL predicateFormat:@"id = 1"];
-       if([array count] == 0) {
+       NSArray<HMKCDeck *> *decks = [serverDataStore objectsWithEntityName:@"Deck" error:NULL predicateFormat:@"id = 1"];
+       if([decks count] == 0) {
                NSLog(@"Deck data is invalid.");
                return;
        }
-       id deck = array[0];
-       id flagShipID = [deck valueForKey:@"ship_0"];
-       array = [serverDataStore objectsWithEntityName:@"Ship" error:NULL predicateFormat:@"id = %@", flagShipID];
-       if([array count] == 0) {
+       HMKCDeck *deck = decks[0];
+       NSNumber *flagShipID = deck.ship_0;
+       NSArray<HMKCShipObject *> *ships = [serverDataStore objectsWithEntityName:@"Ship" error:NULL predicateFormat:@"id = %@", flagShipID];
+       if([ships count] == 0) {
                NSLog(@"Ship data is invalid or ship_0 is invalid.");
                return;
        }
-       id flagShip = array[0];
-       NSNumber *flagShipLv = [flagShip valueForKey:@"lv"];
-       NSString *flagShipName = [flagShip valueForKeyPath:@"master_ship.name"];
+       HMKCShipObject *flagShip = ships[0];
+       NSNumber *flagShipLv = flagShip.lv;
+       NSString *flagShipName = flagShip.master_ship.name;
        
        // Basic -> level
-       array = [serverDataStore objectsWithEntityName:@"Basic" predicate:nil error:NULL];
-       if([array count] == 0) {
+       NSArray<HMKCBasic *> *basics = [serverDataStore objectsWithEntityName:@"Basic" predicate:nil error:NULL];
+       if([basics count] == 0) {
                NSLog(@"Basic data is invalid.");
                return;
        }
-       id basic = array[0];
+       HMKCBasic *basic = basics[0];
        
        HMLocalDataStore *lds = [HMLocalDataStore oneTimeEditor];
        HMKaihatuHistory *newObejct = [NSEntityDescription insertNewObjectForEntityForName:@"KaihatuHistory"
@@ -75,7 +80,7 @@
        newObejct.kaihatusizai = numberOfUsedKaihatuSizai;
        newObejct.flagShipLv = flagShipLv;
        newObejct.flagShipName = flagShipName;
-       newObejct.commanderLv = [basic valueForKey:@"level"];
+       newObejct.commanderLv = basic.level;
        newObejct.date = [NSDate dateWithTimeIntervalSinceNow:0];
        
        [lds saveAction:nil];
index 82d4b03..b91d1a4 100644 (file)
@@ -9,6 +9,8 @@
 #import "HMUpdateSlotItemCommand.h"
 
 #import "HMServerDataStore.h"
+#import "HMKCMasterSlotItemObject.h"
+#import "HMKCSlotItemObject+Extensions.h"
 
 @implementation HMUpdateSlotItemCommand
 - (NSString *)dataKey
        NSManagedObjectContext *moc = store.managedObjectContext;
        
        NSError *error = nil;
-       NSArray *array = [store objectsWithEntityName:@"MasterSlotItem"
-                                                                  error:&error
-                                                predicateFormat:@"id = %@", data[@"api_slotitem_id"]];
-       if([array count] == 0) {
+       NSArray<HMKCMasterSlotItemObject *> *masterSlotItems = [store objectsWithEntityName:@"MasterSlotItem"
+                                                                                                                                                                 error:&error
+                                                                                                                                               predicateFormat:@"id = %@", data[@"api_slotitem_id"]];
+       if(masterSlotItems.count == 0) {
                NSLog(@"MasterSlotItem is invalid");
                return;
        }
        
-       id object = [NSEntityDescription insertNewObjectForEntityForName:@"SlotItem"
-                                                                                         inManagedObjectContext:moc];
-       [object setValue:data[@"api_id"] forKey:@"id"];
-       [object setValue:array[0] forKey:@"master_slotItem"];
+       HMKCSlotItemObject *newSlotItem = [NSEntityDescription insertNewObjectForEntityForName:@"SlotItem"
+                                                                                                                                       inManagedObjectContext:moc];
+       newSlotItem.id =  data[@"api_id"];
+       newSlotItem.master_slotItem = masterSlotItems[0];
 }
 
 @end