OSDN Git Service

HTTPパラメータを表すstructを作成、使用するようにした
[kcd/KCD.git] / KCD / DestroyItem2Command.swift
1 //
2 //  DestroyItem2Command.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/01/10.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10
11 class DestroyItem2Command: JSONCommand {
12     override class func canExecuteAPI(_ api: String) -> Bool {
13         if api == "/kcsapi/api_req_kousyou/destroyitem2" { return true }
14         return false
15     }
16     
17     override func execute() {
18         guard let itemIds = arguments["api_slotitem_ids"]
19             .string?
20             .components(separatedBy: ",")
21             .flatMap({ Int($0) })
22             else { return print("api_slotitem_ids is wrong") }
23         let store = ServerDataStore.oneTimeEditor()
24         store.slotItems(in: itemIds)
25             .forEach { store.delete($0) }
26         
27         guard let material = store.material()
28             else { return print("Material is not found") }
29         guard let gm = data["api_get_material"].arrayObject as? [Int]
30             else { return print("api_get_material is wrong") }
31         let resouces = ["fuel", "bull", "steel", "bauxite"]
32         zip(gm, resouces).forEach {
33             if let current = material.value(forKey: $0.1) as? Int {
34                 material.setValue((current + $0.0) as NSNumber, forKey: $0.1)
35             }
36         }
37     }
38 }