OSDN Git Service

新しく追加したコアデータエンティティクラスを使用するように変更
[kcd/KCD.git] / KCD / HMApplySuppliesCommand.m
1 //
2 //  HMApplySuppliesCommand.m
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2014/09/24.
6 //  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
7 //
8
9 #import "HMApplySuppliesCommand.h"
10
11 #import "HMKCShipObject+Extensions.h"
12 #import "HMServerDataStore.h"
13
14
15 @implementation HMApplySuppliesCommand
16 - (void)execute
17 {
18         HMServerDataStore *store = [HMServerDataStore oneTimeEditor];
19         
20         NSDictionary *data = self.json[@"api_data"];
21         NSArray *shipInfos = data[@"api_ship"];
22         
23         for(NSDictionary *updataInfo in shipInfos) {
24                 NSError *error = nil;
25                 NSArray<HMKCShipObject *> *ships = [store objectsWithEntityName:@"Ship"
26                                                                                                                                   error:&error
27                                                                                                                 predicateFormat:@"id = %@", @([updataInfo[@"api_id"] integerValue])];
28                 if(ships.count == 0) {
29                         if(error) {
30                                 NSLog(@"Error: at %@ : %@", NSStringFromClass([self class]), error);
31                         }
32                         continue;
33                 }
34                 
35                 ships[0].bull = updataInfo[@"api_bull"];
36                 ships[0].fuel = updataInfo[@"api_fuel"];
37                 NSArray *onslots = updataInfo[@"api_onslot"];
38                 ships[0].onslot_0 = onslots[0];
39                 ships[0].onslot_1 = onslots[1];
40                 ships[0].onslot_2 = onslots[2];
41                 ships[0].onslot_3 = onslots[3];
42                 ships[0].onslot_4 = onslots[4];
43         }
44 }
45 @end