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: API) -> Bool {
14         
15         return api.endpoint == .destroyItem2
16     }
17     
18     override func execute() {
19         
20         let store = ServerDataStore.oneTimeEditor()
21         
22         store.slotItems(in: parameter["api_slotitem_ids"].integerArray).forEach(store.delete)
23         
24         guard let material = 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         material.fuel += getMaterials[0]
35         material.bull += getMaterials[1]
36         material.steel += getMaterials[2]
37         material.bauxite += getMaterials[3]
38     }
39 }