2 // AirCorpsSupplyCommand.swift
5 // Created by Hori,Masaki on 2017/01/08.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 final class AirCorpsSupplyCommand: JSONCommand {
13 override class func canExecuteAPI(_ api: API) -> Bool {
15 return api.endpoint == .airCorpsSupply
18 override func execute() {
20 let store = ServerDataStore.oneTimeEditor()
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 }
27 let planeInfos = self.data["api_plane_info"]
28 let planes = airBase.planeInfo
30 self.parameter["api_squadron_id"]
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 }
39 let planeInfo = planeInfos[$0.offset]
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 }
48 if let v = self.data["api_distance"].int { airBase.distance = v }
50 guard let material = store.material() else { return }
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 }