OSDN Git Service

Doutakuを導入
[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 { return }
24             guard let rId = self.parameter["api_base_id"].int else { return }
25             guard let airBase = store.airBase(area: areaId, base: rId) else { return }
26             
27             let planeInfos = self.data["api_plane_info"]
28             let planes = airBase.planeInfo
29             
30             self.parameter["api_squadron_id"]
31                 .integerArray
32                 .enumerated()
33                 .forEach {
34                     
35                     guard planes.count >= $0.element else { return }
36                     guard planeInfos.count > $0.offset else { return }
37                     guard let plane = planes[$0.element - 1] as? AirBasePlaneInfo else { return }
38                     
39                     let planeInfo = planeInfos[$0.offset]
40                     
41                     if let v = planeInfo["api_cond"].int { plane.cond = v }
42                     if let v = planeInfo["api_slotid"].int { plane.slotid = v }
43                     if let v = planeInfo["api_state"].int { plane.state = v }
44                     if let v = planeInfo["api_count"].int { plane.count = v }
45                     if let v = planeInfo["api_max_count"].int { plane.max_count = v }
46             }
47             
48             if let v = self.data["api_distance"].int { airBase.distance = v }
49             
50             guard let material = store.material() else { return }
51             
52             if let v = self.data["api_after_bauxite"].int { material.bauxite = v }
53             if let v = self.data["api_after_fuel"].int { material.fuel = v }
54         }
55     }
56 }