2 // SetPlaneCommand.swift
5 // Created by Hori,Masaki on 2017/01/14.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 class SetPlaneCommand: JSONCommand {
12 override class func canExecuteAPI(_ api: String) -> Bool {
13 if api == "/kcsapi/api_req_air_corps/set_plane" { return true }
17 override func execute() {
18 guard let areaId = parameter["api_area_id"].int,
19 let rId = parameter["api_base_id"].int,
20 let squadronId = parameter["api_squadron_id"].int
21 else { return print("Argument is wrong") }
22 guard let distance = data["api_distance"].int,
23 let bauxite = data["api_after_bauxite"].int
24 else { return print("JSON is wrong") }
25 let planInfo = data["api_plane_info"][0]
26 guard let cond = planInfo["api_cond"].int,
27 let slotid = planInfo["api_slotid"].int,
28 let state = planInfo["api_state"].int,
29 let count = planInfo["api_count"].int,
30 let maxCount = planInfo["api_max_count"].int
31 else { return print("api_plane_info is wrong") }
33 let store = ServerDataStore.oneTimeEditor()
34 guard let airbase = store.airBase(area: areaId, base: rId)
35 else { return print("AirBase is not found") }
36 let planes = airbase.planeInfo
37 guard planes.count >= squadronId,
38 let plane = planes[squadronId - 1] as? AirBasePlaneInfo
39 else { return print("AirBase is wrong") }
44 plane.max_count = maxCount
46 airbase.distance = distance
48 store.material()?.bauxite = bauxite