2 // StoreCreateSlotItemHistoryCommand.swift
5 // Created by Hori,Masaki on 2017/01/11.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
12 final class StoreCreateSlotItemHistoryCommand: JSONCommand {
14 override func execute() {
16 guard let fuel = parameter["api_item1"].int,
17 let bull = parameter["api_item2"].int,
18 let steel = parameter["api_item3"].int,
19 let bauxite = parameter["api_item4"].int else {
21 return Logger.shared.log("Parameter is Wrong")
24 let success = data["api_create_flag"].int ?? 0
25 let name = masterSlotItemName(sccess: success, data: data)
26 let numberOfUsedKaihatuSizai = (success != 0 ? 1 : 0)
28 let store = ServerDataStore.default
30 guard let flagShip = store.deck(by: 1)?[0] else {
32 return Logger.shared.log("Flagship is not found")
35 guard let basic = store.basic() else { return print("Basic is wrong") }
37 let localStore = LocalDataStore.oneTimeEditor()
39 guard let newHistory = localStore.createKaihatuHistory() else {
41 return Logger.shared.log("Can not create new KaihatuHistory entry")
44 newHistory.name = name
45 newHistory.fuel = fuel
46 newHistory.bull = bull
47 newHistory.steel = steel
48 newHistory.bauxite = bauxite
49 newHistory.kaihatusizai = numberOfUsedKaihatuSizai
50 newHistory.flagShipLv = flagShip.lv
51 newHistory.flagShipName = flagShip.name
52 newHistory.commanderLv = basic.level
53 newHistory.date = Date()
56 private func masterSlotItemName(sccess: Int, data: JSON) -> String {
60 return LocalizedStrings.failDevelop.string
63 guard let slotItemId = data["api_slot_item"]["api_slotitem_id"].int else {
65 return Logger.shared.log("api_slotitem_id is wrong", value: "")
68 return ServerDataStore.default.masterSlotItem(by: slotItemId)?.name ?? ""