2 // HMKenzoMarkCommand.m
5 // Created by Hori,Masaki on 2014/05/11.
6 // Copyright (c) 2014年 Hori,Masaki. All rights reserved.
9 #import "HMKenzoMarkCommand.h"
11 #import "HMServerDataStore.h"
12 #import "HMLocalDataStore.h"
13 #import "HMKenzoHistory.h"
18 @implementation HMKenzoMarkCommand
21 HMServerDataStore *serverDataStore = [HMServerDataStore oneTimeEditor];
22 NSArray *array = [serverDataStore objectsWithEntityName:@"KenzoDock"
24 predicateFormat:@"id = %@", @([[self.arguments valueForKey:@"api_kdock_id"] integerValue])];
25 if([array count] == 0) {
26 NSLog(@"KenzoDock data is invalid.");
31 NSNumber *item1 = [kdock valueForKey:@"item1"];
34 array = [serverDataStore objectsWithEntityName:@"MasterShip" error:NULL predicateFormat:@"id = %@", [kdock valueForKey:@"created_ship_id"]];
35 if([array count] == 0) {
36 NSLog(@"MasterShip data is invalid or ship_id is invalid.");
42 NSNumber *flagShipLv = nil;
43 NSString *flafShipName = nil;
44 NSNumber *commanderLv = nil;
45 HMLocalDataStore *localDataStore = [HMLocalDataStore oneTimeEditor];
46 array = [localDataStore objectsWithEntityName:@"KenzoMark"
48 predicateFormat:@"fuel = %@ AND bull = %@ AND steel = %@ AND bauxite = %@ AND kaihatusizai = %@ AND kDockId = %@ AND created_ship_id = %@",
49 item1, [kdock valueForKey:@"item2"], [kdock valueForKey:@"item3"], [kdock valueForKey:@"item4"], [kdock valueForKey:@"item5"],
50 @([[self.arguments valueForKey:@"api_kdock_id"] integerValue]), [kdock valueForKey:@"created_ship_id"]
52 if([array count] != 0) {
53 flagShipLv = [array[0] valueForKey:@"flagShipLv"];
54 flafShipName = [array[0] valueForKey:@"flagShipName"];
55 commanderLv = [array[0] valueForKey:@"commanderLv"];
58 HMLocalDataStore *lds = [HMLocalDataStore oneTimeEditor];
59 NSManagedObjectContext *localStoreContext = [lds managedObjectContext];
60 HMKenzoHistory *newObejct = [NSEntityDescription insertNewObjectForEntityForName:@"KenzoHistory"
61 inManagedObjectContext:localStoreContext];
62 newObejct.name = [ship valueForKey:@"name"];
63 newObejct.sTypeId = [ship valueForKeyPath:@"stype.id"];
64 newObejct.fuel = item1;
65 newObejct.bull = [kdock valueForKey:@"item2"];
66 newObejct.steel = [kdock valueForKey:@"item3"];
67 newObejct.bauxite = [kdock valueForKey:@"item4"];
68 newObejct.kaihatusizai = [kdock valueForKey:@"item5"];
69 newObejct.flagShipLv = flagShipLv;
70 newObejct.flagShipName = flafShipName;
71 newObejct.commanderLv = commanderLv;
72 newObejct.date = [NSDate dateWithTimeIntervalSinceNow:0];