OSDN Git Service

Doutakuを導入
[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: API) -> Bool {
14         
15         return api.endpoint == .destroyItem2
16     }
17     
18     override func execute() {
19         
20         let store = ServerDataStore.oneTimeEditor()
21         
22         store.sync { store.slotItems(in: self.parameter["api_slotitem_ids"].integerArray).forEach(store.delete) }
23         
24         guard let material = store.sync(execute: { store.material() }) else {
25             
26             return Logger.shared.log("Material is not found")
27         }
28         guard let getMaterials = data["api_get_material"].arrayObject as? [Int],
29             getMaterials.count >= 4 else {
30             
31             return Logger.shared.log("api_get_material is wrong")
32         }
33         
34         store.sync {
35             
36             material.fuel += getMaterials[0]
37             material.bull += getMaterials[1]
38             material.steel += getMaterials[2]
39             material.bauxite += getMaterials[3]
40         }
41     }
42 }