OSDN Git Service

列挙子の名称変更
[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 final class DestroyItem2Command: JSONCommand {
12     
13     override class func canExecuteAPI(_ api: String) -> Bool {
14         
15         if api == "/kcsapi/api_req_kousyou/destroyitem2" { return true }
16         
17         return false
18     }
19     
20     override func execute() {
21         
22         guard let itemIds = parameter["api_slotitem_ids"]
23             .string?
24             .components(separatedBy: ",")
25             .flatMap({ Int($0) })
26             else { return print("api_slotitem_ids is wrong") }
27         
28         let store = ServerDataStore.oneTimeEditor()
29         
30         store.slotItems(in: itemIds)
31             .forEach { store.delete($0) }
32         
33         guard let material = store.material()
34             else { return print("Material is not found") }
35         
36         guard let gm = data["api_get_material"].arrayObject as? [Int]
37             else { return print("api_get_material is wrong") }
38         
39         let resouces = ["fuel", "bull", "steel", "bauxite"]
40         
41         zip(gm, resouces).forEach {
42             
43             if let current = material.value(forKey: $0.1) as? Int {
44                 
45                 material.setValue((current + $0.0) as NSNumber, forKey: $0.1)
46             }
47         }
48         
49     }
50 }