2 // SetPlaneCommand.swift
5 // Created by Hori,Masaki on 2017/01/14.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 final class SetPlaneCommand: JSONCommand {
13 override class func canExecuteAPI(_ api: String) -> Bool {
15 if api == "/kcsapi/api_req_air_corps/set_plane" { return true }
20 override func execute() {
22 guard let areaId = parameter["api_area_id"].int,
23 let rId = parameter["api_base_id"].int,
24 let squadronId = parameter["api_squadron_id"].int else {
26 print("SetPlaneCommand: Argument is wrong")
29 guard let distance = data["api_distance"].int else {
31 print("SetPlaneCommand: JSON is wrong")
35 let planInfo = data["api_plane_info"][0]
37 guard let slotid = planInfo["api_slotid"].int,
38 let state = planInfo["api_state"].int else {
40 print("api_plane_info is wrong")
44 let store = ServerDataStore.oneTimeEditor()
46 guard let airbase = store.airBase(area: areaId, base: rId) else {
48 print("AirBase is not found")
52 let planes = airbase.planeInfo
54 guard planes.count >= squadronId,
55 let plane = planes[squadronId - 1] as? AirBasePlaneInfo else {
57 print("AirBase is wrong")
61 // TODO: state が 2 の時のみ cond, count, max_count がnilであることを許すようにする
62 plane.cond = planInfo["api_cond"].int ?? 0
65 plane.count = planInfo["api_count"].int ?? 0
66 plane.max_count = planInfo["api_max_count"].int ?? 0
68 airbase.distance = distance
70 data["api_after_bauxite"].int.map { store.material()?.bauxite = $0 }