OSDN Git Service

UIを調整
[kcd/KCD.git] / KCD / HMNyukyoSpeedChangeCommand.m
1 //
2 //  HMNyukyoSpeedChangeCommand.m
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2014/07/21.
6 //  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
7 //
8
9 #import "HMNyukyoSpeedChangeCommand.h"
10
11 #import "HMServerDataStore.h"
12
13
14 @implementation HMNyukyoSpeedChangeCommand
15 + (void)load
16 {
17         static dispatch_once_t onceToken;
18         dispatch_once(&onceToken, ^{
19                 [HMJSONCommand registerClass:self];
20         });
21 }
22
23 + (BOOL)canExcuteAPI:(NSString *)api
24 {
25         if([api isEqualToString:@"/kcsapi/api_req_nyukyo/speedchange"]) return YES;
26         
27         return NO;
28 }
29 - (void)execute
30 {
31         HMServerDataStore *store = [HMServerDataStore oneTimeEditor];
32         
33         NSString *ndockId = self.arguments[@"api_ndock_id"];
34         
35         NSError *error = nil;
36         NSArray *array = [store objectsWithEntityName:@"NyukyoDock"
37                                                                                         error:&error
38                                                                   predicateFormat:@"id = %@", @([ndockId integerValue])];
39         if(array.count == 0) {
40                 if(error) {
41                         NSLog(@"Error: at %@ : %@", NSStringFromClass([self class]), error);
42                 }
43                 return;
44         }
45         
46         id dock = array[0];
47         
48         NSString *shipId = [dock valueForKey:@"ship_id"];
49         
50         [dock setValue:nil forKey:@"ship_id"];
51         [dock setValue:@(0) forKey:@"state"];
52         
53         
54         // 艦隊リスト更新用
55         error = nil;
56         array = [store objectsWithEntityName:@"Ship"
57                                                                    error:&error
58                                                  predicateFormat:@"id = %@", @([shipId integerValue])];
59         if(array.count == 0) {
60                 if(error) {
61                         NSLog(@"Error: at %@ : %@", NSStringFromClass([self class]), error);
62                 }
63                 return;
64         }
65         
66         id ship = array[0];
67         [ship setValue:[ship valueForKey:@"maxhp"] forKey:@"nowhp"];
68 }
69 @end