OSDN Git Service

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