OSDN Git Service

Doutaku を 1.0 にアップデート
[kcd/KCD.git] / KCD / AirCorpsSupplyCommand.swift
1 //
2 //  AirCorpsSupplyCommand.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/01/08.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10
11 final class AirCorpsSupplyCommand: JSONCommand {
12     
13     override class func canExecuteAPI(_ api: API) -> Bool {
14         
15         return api.endpoint == .airCorpsSupply
16     }
17     
18     override func execute() {
19         
20         let store = ServerDataStore.oneTimeEditor()
21         store.async {
22             
23             guard let areaId = self.parameter["api_area_id"].int else {
24                 
25                 return
26             }
27             guard let rId = self.parameter["api_base_id"].int else {
28                 
29                 return
30             }
31             guard let airBase = store.airBase(area: areaId, base: rId) else {
32                 
33                 return
34             }
35             
36             let planeInfos = self.data["api_plane_info"]
37             let planes = airBase.planeInfo
38             
39             self.parameter["api_squadron_id"]
40                 .integerArray
41                 .enumerated()
42                 .forEach {
43                     
44                     guard planes.count >= $0.element else {
45                         
46                         return
47                     }
48                     guard planeInfos.count > $0.offset else {
49                         
50                         return
51                     }
52                     guard let plane = planes[$0.element - 1] as? AirBasePlaneInfo else {
53                         
54                         return
55                     }
56                     
57                     let planeInfo = planeInfos[$0.offset]
58                     
59                     if let v = planeInfo["api_cond"].int {
60                         
61                         plane.cond = v
62                     }
63                     if let v = planeInfo["api_slotid"].int {
64                         
65                         plane.slotid = v
66                     }
67                     if let v = planeInfo["api_state"].int {
68                         
69                         plane.state = v
70                     }
71                     if let v = planeInfo["api_count"].int {
72                         
73                         plane.count = v
74                     }
75                     if let v = planeInfo["api_max_count"].int {
76                         
77                         plane.max_count = v
78                     }
79             }
80             
81             if let v = self.data["api_distance"].int {
82                 
83                 airBase.distance = v
84             }
85             
86             guard let material = store.material() else {
87                 
88                 return
89             }
90             
91             if let v = self.data["api_after_bauxite"].int {
92                 
93                 material.bauxite = v
94             }
95             if let v = self.data["api_after_fuel"].int {
96                 
97                 material.fuel = v
98             }
99         }
100     }
101 }