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: String) -> Bool {
15 if api == "/kcsapi/api_req_air_corps/supply" { return true }
20 override func execute() {
22 let store = ServerDataStore.oneTimeEditor()
24 guard let areaId = parameter["api_area_id"].int else { return }
25 guard let rId = parameter["api_base_id"].int else { return }
26 guard let squadronIdsString = parameter["api_squadron_id"].string else { return }
27 guard let airBase = store.airBase(area: areaId, base: rId) else { return }
29 let planeInfos = data["api_plane_info"]
30 let planes = airBase.planeInfo
31 let squadronIds = squadronIdsString
32 .components(separatedBy: ",")
35 squadronIds.enumerated().forEach {
37 guard planes.count >= $0.element else { return }
38 guard planeInfos.count > $0.offset else { return }
39 guard let plane = planes[$0.element - 1] as? AirBasePlaneInfo else { return }
41 let planeInfo = planeInfos[$0.offset]
43 if let v = planeInfo["api_cond"].int { plane.cond = v }
44 if let v = planeInfo["api_slotid"].int { plane.slotid = v }
45 if let v = planeInfo["api_state"].int { plane.state = v }
46 if let v = planeInfo["api_count"].int { plane.count = v }
47 if let v = planeInfo["api_max_count"].int { plane.max_count = v }
50 if let v = data["api_distance"].int { airBase.distance = v }
52 guard let material = store.material() else { return }
54 if let v = data["api_after_bauxite"].int { material.bauxite = v }
55 if let v = data["api_after_fuel"].int { material.fuel = v }