F42680121943E92D00B2C27F /* HMKCShipObject+Extensions.m in Sources */ = {isa = PBXBuildFile; fileRef = F42680111943E92D00B2C27F /* HMKCShipObject+Extensions.m */; };
F426802B194D0F4800B2C27F /* HMMemberShip2Command.m in Sources */ = {isa = PBXBuildFile; fileRef = F426802A194D0F4800B2C27F /* HMMemberShip2Command.m */; };
F426802E194D0FFD00B2C27F /* HMMemberShip3Command.m in Sources */ = {isa = PBXBuildFile; fileRef = F426802D194D0FFD00B2C27F /* HMMemberShip3Command.m */; };
- F4268031194D1B1A00B2C27F /* HMChangeHenseiCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4268030194D1B1A00B2C27F /* HMChangeHenseiCommand.m */; };
F4268034195332A000B2C27F /* HMPowerUpCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4268033195332A000B2C27F /* HMPowerUpCommand.m */; };
F431E9761DF3AC1C00FB56AE /* HMSetActionCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F431E9751DF3AC1C00FB56AE /* HMSetActionCommand.m */; };
F43769DE1AE1248800DE6204 /* HMAirBattleCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F43769DD1AE1248800DE6204 /* HMAirBattleCommand.m */; };
F44BC6E51E23082B004644E3 /* HMCombinedCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC6E41E23082B004644E3 /* HMCombinedCommand.swift */; };
F44BC6E71E231534004644E3 /* HMSlotResetCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC6E61E231534004644E3 /* HMSlotResetCommand.swift */; };
F44BC6E91E232B15004644E3 /* HMKaisouLockCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC6E81E232B15004644E3 /* HMKaisouLockCommand.swift */; };
+ F44BC6EB1E234531004644E3 /* HMChangeHenseiCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC6EA1E234531004644E3 /* HMChangeHenseiCommand.swift */; };
F4513EDD18B619B600073552 /* HMCoreDataManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F4513EDC18B619B600073552 /* HMCoreDataManager.m */; };
F4513EE818B77A5300073552 /* HMMemberKDockCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4513EE718B77A5300073552 /* HMMemberKDockCommand.m */; };
F4513EEB18B7900A00073552 /* HMMemberDeckCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4513EEA18B7900A00073552 /* HMMemberDeckCommand.m */; };
F4F9F89B1C6CB7D400D0EE76 /* HMFleet.m in Sources */ = {isa = PBXBuildFile; fileRef = F4F9F89A1C6CB7D400D0EE76 /* HMFleet.m */; };
F4F9F8A31C70AFB600D0EE76 /* HMFleetManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F4F9F8A21C70AFB600D0EE76 /* HMFleetManager.m */; };
F4F9F8A61C78596900D0EE76 /* HMAnchorageRepairManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F4F9F8A51C78596900D0EE76 /* HMAnchorageRepairManager.m */; };
- F4F9F8A91C796C2E00D0EE76 /* HMChangeHenseiNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = F4F9F8A81C796C2E00D0EE76 /* HMChangeHenseiNotification.m */; };
F4FCFD44191F4C1D000640A1 /* HMKenzoMarkCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4FCFD43191F4C1D000640A1 /* HMKenzoMarkCommand.m */; };
/* End PBXBuildFile section */
F426802A194D0F4800B2C27F /* HMMemberShip2Command.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMMemberShip2Command.m; sourceTree = "<group>"; };
F426802C194D0FFD00B2C27F /* HMMemberShip3Command.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMMemberShip3Command.h; sourceTree = "<group>"; };
F426802D194D0FFD00B2C27F /* HMMemberShip3Command.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMMemberShip3Command.m; sourceTree = "<group>"; };
- F426802F194D1B1A00B2C27F /* HMChangeHenseiCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMChangeHenseiCommand.h; sourceTree = "<group>"; };
- F4268030194D1B1A00B2C27F /* HMChangeHenseiCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMChangeHenseiCommand.m; sourceTree = "<group>"; };
F4268032195332A000B2C27F /* HMPowerUpCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMPowerUpCommand.h; sourceTree = "<group>"; };
F4268033195332A000B2C27F /* HMPowerUpCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMPowerUpCommand.m; sourceTree = "<group>"; };
F42CBB201D1ED41D004C2AE2 /* LocalData 3.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "LocalData 3.xcdatamodel"; sourceTree = "<group>"; };
F44BC6E41E23082B004644E3 /* HMCombinedCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMCombinedCommand.swift; sourceTree = "<group>"; };
F44BC6E61E231534004644E3 /* HMSlotResetCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMSlotResetCommand.swift; sourceTree = "<group>"; };
F44BC6E81E232B15004644E3 /* HMKaisouLockCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMKaisouLockCommand.swift; sourceTree = "<group>"; };
+ F44BC6EA1E234531004644E3 /* HMChangeHenseiCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMChangeHenseiCommand.swift; sourceTree = "<group>"; };
F4513EDB18B619B600073552 /* HMCoreDataManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMCoreDataManager.h; sourceTree = "<group>"; };
F4513EDC18B619B600073552 /* HMCoreDataManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMCoreDataManager.m; sourceTree = "<group>"; };
F4513EE618B77A5300073552 /* HMMemberKDockCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMMemberKDockCommand.h; sourceTree = "<group>"; };
F4F9F8A21C70AFB600D0EE76 /* HMFleetManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMFleetManager.m; sourceTree = "<group>"; };
F4F9F8A41C78596900D0EE76 /* HMAnchorageRepairManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMAnchorageRepairManager.h; sourceTree = "<group>"; };
F4F9F8A51C78596900D0EE76 /* HMAnchorageRepairManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMAnchorageRepairManager.m; sourceTree = "<group>"; };
- F4F9F8A71C796C2E00D0EE76 /* HMChangeHenseiNotification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMChangeHenseiNotification.h; sourceTree = "<group>"; };
- F4F9F8A81C796C2E00D0EE76 /* HMChangeHenseiNotification.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMChangeHenseiNotification.m; sourceTree = "<group>"; };
F4FCFD42191F4C1D000640A1 /* HMKenzoMarkCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMKenzoMarkCommand.h; sourceTree = "<group>"; };
F4FCFD43191F4C1D000640A1 /* HMKenzoMarkCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMKenzoMarkCommand.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
children = (
F4BEEFD91B0A219E004702B8 /* HMShipDeckCommand.h */,
F4BEEFDA1B0A219E004702B8 /* HMShipDeckCommand.m */,
- F426802F194D1B1A00B2C27F /* HMChangeHenseiCommand.h */,
- F4268030194D1B1A00B2C27F /* HMChangeHenseiCommand.m */,
+ F44BC6EA1E234531004644E3 /* HMChangeHenseiCommand.swift */,
F44BC6E81E232B15004644E3 /* HMKaisouLockCommand.swift */,
F44BC6E61E231534004644E3 /* HMSlotResetCommand.swift */,
F44BC6E41E23082B004644E3 /* HMCombinedCommand.swift */,
F49546291B14CBA600E0D8D0 /* HMBookmarkManager.h */,
F495462A1B14CBA600E0D8D0 /* HMBookmarkManager.m */,
F45771221E1BCC7C008A9215 /* HMPeriodicNotifier.swift */,
- F4F9F8A71C796C2E00D0EE76 /* HMChangeHenseiNotification.h */,
- F4F9F8A81C796C2E00D0EE76 /* HMChangeHenseiNotification.m */,
F4F9F8A41C78596900D0EE76 /* HMAnchorageRepairManager.h */,
F4F9F8A51C78596900D0EE76 /* HMAnchorageRepairManager.m */,
F448F9901B6FBF80004901AD /* HMResourceHistoryManager.h */,
F4F9F8901C6B6ACA00D0EE76 /* HMKCNyukyoDock.m in Sources */,
F44AB24119E8252600F217AF /* HMKCSlotItemObject+Extensions.m in Sources */,
F4D05BE11E0FAB8E00688D66 /* HMShipViewController.swift in Sources */,
+ F44BC6EB1E234531004644E3 /* HMChangeHenseiCommand.swift in Sources */,
F4E5FF041E1518200026868C /* HMScreenshotDetailViewController.swift in Sources */,
F472159E1E1E6EE70083D3BC /* HMShipMasterDetailWindowController.swift in Sources */,
F44BC6D71E226CB1004644E3 /* HMHokyuChargeCommand.swift in Sources */,
F4AA59421E1E2854001667AF /* HMOrderedSetToArrayTransformer.swift in Sources */,
F494DC5F18C30AE100AE97E4 /* HMMissionStatus.m in Sources */,
F43F3D4C1A34AC8000D6DAF7 /* HMKCMasterShipObject.m in Sources */,
- F4268031194D1B1A00B2C27F /* HMChangeHenseiCommand.m in Sources */,
F4BEEFE11B0B6326004702B8 /* HMDummyShipCommand.m in Sources */,
F4AA59441E1E300B001667AF /* HMActinKindTransformer.swift in Sources */,
F4D05BCC1E0D274100688D66 /* HMBookmarkEditorViewController.swift in Sources */,
F494DC6D18CC054800AE97E4 /* HMNyukyoDockStatus.m in Sources */,
F4666C641B25CA3E001840DB /* HMKCQuest+Extensions.m in Sources */,
- F4F9F8A91C796C2E00D0EE76 /* HMChangeHenseiNotification.m in Sources */,
F43BA4A1197BE22200CFF788 /* HMDestroyShipCommand.m in Sources */,
F4B414EF18B0BF1A00468DAF /* HMMasterMapInfoCommand.m in Sources */,
F4B3DC1B18DEAB5E0011B4FC /* HMKaihatuHistory.m in Sources */,
#import "HMUserDefaults.h"
#import "HMAppDelegate.h"
-#import "HMChangeHenseiNotification.h"
-
@interface HMAnchorageRepairManager ()
@property (strong) HMFleetManager *fleetManager;
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(henseiDidChangeNotification:)
- name:HMChangeHenseiNotification
+ name:HMChangeHenseiCommand.notificationName
object:nil];
[nc addObserver:self
selector:@selector(didReturnToBaseNotification:)
return ship.master_ship.stype.id;
}
-- (BOOL)needsResetWithInfo:(HMChangeHenseiNotificationUserInfo *)userInfo
+- (BOOL)needsResetWithInfo:(HenseiDidChangeUserInfo *)userInfo
{
// 変更のあった艦隊の旗艦は工作艦か?
- NSNumber *flagShipShipTypeID = [self shipTypeIDWithFleetNumber:userInfo.fleetNumber position:@0];
+ NSNumber *flagShipShipTypeID = [self shipTypeIDWithFleetNumber:@(userInfo.fleetNumber) position:@0];
if([self.repairShipTypeIds containsObject:flagShipShipTypeID]) {
return YES;
}
- if(userInfo.type == kHMChangeHenseiReplace) {
- flagShipShipTypeID = [self shipTypeIDWithFleetNumber:userInfo.replaceFleetNumber position:@0];
+ if(userInfo.objcType == 1 /* replace */) {
+ flagShipShipTypeID = [self shipTypeIDWithFleetNumber:userInfo.objcReplaceFleetNumbner position:@0];
if([self.repairShipTypeIds containsObject:flagShipShipTypeID]) {
return YES;
}
// 変更のあった艦娘は工作艦か?
// 旗艦から外れたか?
- if(userInfo.type == kHMChangeHenseiRemove || userInfo.type == kHMChangeHenseiAppend) {
- NSNumber *shipTypeID = [self shipTypeIDWithShipID:userInfo.shipID];
+ if(userInfo.objcType == 2 /* remove */|| userInfo.objcType == 0 /* append */) {
+ NSNumber *shipTypeID = [self shipTypeIDWithShipID:@(userInfo.shipID)];
if([self.repairShipTypeIds containsObject:shipTypeID]) {
- return [userInfo.position isEqual:@0];
+ return userInfo.position == 0;
}
}
- if(userInfo.type == kHMChangeHenseiReplace) {
- NSNumber *shipTypeID = [self shipTypeIDWithShipID:userInfo.replaceShipID];
+ if(userInfo.objcType == 1 /* replace */) {
+ NSNumber *shipTypeID = [self shipTypeIDWithShipID:userInfo.objcReplaceShipID];
if([self.repairShipTypeIds containsObject:shipTypeID]) {
- return [userInfo.replacePosition isEqual:@0];
+ return [userInfo.objcReplacePosition isEqual:@0];
}
}
NSDictionary *userInfo = notification.userInfo;
if(!userInfo) return;
- HMChangeHenseiNotificationUserInfo *info = userInfo[HMChangeHenseiUserInfoKey];
+ HenseiDidChangeUserInfo *info = userInfo[HMChangeHenseiCommand.userInfoKey];
- switch(info.type) {
- case kHMChangeHenseiAppend:
- case kHMChangeHenseiReplace:
- case kHMChangeHenseiRemove:
+ switch(info.objcType) {
+ case 0: /* append */
+ case 1: /* replace */
+ case 2: /*remove */
if([self needsResetWithInfo:info]) {
[self reset];
}
break;
- case kHMChangeHenseiRemoveAllWithoutFlagship:
+ case 3: /* removeAllWithoutFlagship */
// do nothing
break;
default:
+++ /dev/null
-//
-// HMChangeHenseiCommand.h
-// KCD
-//
-// Created by Hori,Masaki on 2014/06/15.
-// Copyright (c) 2014年 Hori,Masaki. All rights reserved.
-//
-
-#import "HMJSONCommand.h"
-
-@interface HMChangeHenseiCommand : HMJSONCommand
-
-@end
+++ /dev/null
-//
-// HMChangeHenseiCommand.m
-// KCD
-//
-// Created by Hori,Masaki on 2014/06/15.
-// Copyright (c) 2014年 Hori,Masaki. All rights reserved.
-//
-
-#import "HMChangeHenseiCommand.h"
-
-#import "KCD-Swift.h"
-
-#import "HMKCDeck+Extension.h"
-
-#import "HMChangeHenseiNotification.h"
-
-
-@interface HMChangeHenseiCommand ()
-@property (nonatomic, strong) HMServerDataStore *store;
-@end
-
-@implementation HMChangeHenseiCommand
-//+ (void)load
-//{
-// static dispatch_once_t onceToken;
-// dispatch_once(&onceToken, ^{
-// [HMJSONCommand registerClass:self];
-// });
-//}
-
-+ (BOOL)canExcuteAPI:(NSString *)api
-{
- return [api isEqualToString:@"/kcsapi/api_req_hensei/change"];
-}
-
-- (HMServerDataStore *)store
-{
- if(_store) return _store;
-
- _store = [HMServerDataStore oneTimeEditor];
- return _store;
-}
-
-- (void)printFleet
-{
- NSError *error = nil;
- NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"id" ascending:YES];
- NSArray<HMKCDeck *> *decks = [self.store objectsWithEntityName:@"Deck"
- sortDescriptors:@[sortDescriptor]
- predicate:nil
- error:&error];
- // TODO: error handling
-
- NSMutableArray *ships = [NSMutableArray new];
- for(HMKCDeck *deck in decks) {
- for(NSUInteger i = 0; i < 6; i++) {
- [ships addObject:[deck valueForKey:[NSString stringWithFormat:@"ship_%ld", i]]];
- }
- }
-
- for(int i = 0; i < 4; i++) {
- fprintf(stderr, "Fleet %d\n", i+1);
- for(int j = 0; j < 6; j++) {
- fprintf(stderr, "%d -> %ld\n", j+1, [ships[i*6+j] integerValue]);
- }
- }
- fprintf(stderr, "\n");
-}
-
-- (void)packFleet
-{
- NSError *error = nil;
- NSArray<HMKCDeck *> *decks = [self.store objectsWithEntityName:@"Deck"
- predicate:nil
- error:&error];
- // TODO: error handling
-
- for(HMKCDeck *deck in decks) {
- BOOL needsPack = NO;
- for(NSInteger i = 0; i < 6; i++) {
- NSInteger shipId = [[deck valueForKey:[NSString stringWithFormat:@"ship_%ld", i]] integerValue];
- if(!needsPack && shipId == -1) {
- needsPack = YES;
- continue;
- }
- if(needsPack) {
- [deck setValue:@(shipId) forKey:[NSString stringWithFormat:@"ship_%ld", i - 1]];
-
- if(i == 5) {
- [deck setValue:@(-1) forKey:@"ship_5"];
- }
- }
- }
- }
-}
-
-- (void)excludeShipsWithoutFlag
-{
- NSInteger deckNumber = [[self.arguments valueForKey:@"api_id"] integerValue];
-
- NSError *error = nil;
- NSArray<HMKCDeck *> *decks = [self.store objectsWithEntityName:@"Deck"
- error:&error
- predicateFormat:@"id = %ld", deckNumber];
- // TODO: error handling
- HMKCDeck *deck = decks[0];
-
- for(NSInteger i = 1; i < 6; i++) {
- [deck setValue:@(-1) forKey:[NSString stringWithFormat:@"ship_%ld", i]];
- }
-}
-
-// api_ship_id の値
-// ship_id > 0 : 艦娘のID append or replace
-// ship_id == -1 : remove.
-// ship_id == -2 : remove all without flag ship.
-- (void)execute
-{
- NSInteger deckNumber = [[self.arguments valueForKey:@"api_id"] integerValue];
- NSInteger shipId = [[self.arguments valueForKey:@"api_ship_id"] integerValue];
- NSInteger shipIndex = [[self.arguments valueForKey:@"api_ship_idx"] integerValue];
-
- if(shipId < -1) {
- [self excludeShipsWithoutFlag];
- self.store = nil;
-
- [self notifyWithType:kHMChangeHenseiRemoveAllWithoutFlagship
- fleetNumber:@(deckNumber)
- position:nil
- shipID:nil
- replaceFleetNumber:nil
- replacePosition:nil
- replaceShipID:nil];
- return;
- }
-
- NSError *error = nil;
- NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"id" ascending:YES];
- NSArray<HMKCDeck *> *decks = [self.store objectsWithEntityName:@"Deck"
- sortDescriptors:@[sortDescriptor]
- predicate:nil
- error:&error];
- // TODO: error handling
-
- NSMutableArray *ships = [NSMutableArray new];
- for(HMKCDeck *deck in decks) {
- for(NSUInteger i = 0; i < 6; i++) {
- [ships addObject:[deck valueForKey:[NSString stringWithFormat:@"ship_%ld", i]]];
- }
- }
-
- // すでに編成されているか? どこに?
- BOOL alreadyInFleet = [ships containsObject:@(shipId)];
- NSInteger shipDeckNumber = -1;
- NSInteger shipDeckIndex = -1;
- if(alreadyInFleet) {
- NSInteger index = [ships indexOfObject:@(shipId)];
- shipDeckNumber = index / 6;
- shipDeckIndex = index % 6;
- }
-
- // 配置しようとする位置に今配置されている艦娘
- NSInteger replaceShipId = [ships[(deckNumber - 1) * 6 + shipIndex] integerValue];
-
- // 艦隊に配備
- HMKCDeck *deck = decks[deckNumber - 1];
- [deck setValue:@(shipId) forKey:[NSString stringWithFormat:@"ship_%ld", shipIndex]];
-
- // 入れ替え
- if(alreadyInFleet && shipId != -1) {
- HMKCDeck *deck = decks[shipDeckNumber];
- [deck setValue:@(replaceShipId) forKey:[NSString stringWithFormat:@"ship_%ld", shipDeckIndex]];
- }
-
- [self packFleet];
- self.store = nil;
-
- //
- if(alreadyInFleet && shipId == -1) {
- [self notifyWithType:kHMChangeHenseiRemove
- fleetNumber:@(deckNumber)
- position:@(shipIndex)
- shipID:@(replaceShipId)
- replaceFleetNumber:nil
- replacePosition:nil
- replaceShipID:nil];
- } else if(alreadyInFleet) {
- [self notifyWithType:kHMChangeHenseiReplace
- fleetNumber:@(deckNumber)
- position:@(shipIndex)
- shipID:@(shipId)
- replaceFleetNumber:@(shipDeckNumber + 1)
- replacePosition:@(shipDeckIndex)
- replaceShipID:@(replaceShipId)];
- } else {
- [self notifyWithType:kHMChangeHenseiAppend
- fleetNumber:@(deckNumber)
- position:@(shipIndex)
- shipID:@(shipId)
- replaceFleetNumber:nil
- replacePosition:nil
- replaceShipID:nil];
- }
-}
-
-- (void)notifyWithType:(HMChangeHenseiType)type
- fleetNumber:(NSNumber *)fleetNumber
- position:(NSNumber *)position
- shipID:(NSNumber *)shipID
- replaceFleetNumber:(NSNumber *)replaceFleetNumber
- replacePosition:(NSNumber *)replacePosition
- replaceShipID:(NSNumber *)replaceShipID
-{
- HMChangeHenseiNotificationUserInfo *info = [HMChangeHenseiNotificationUserInfo new];
- info.type = type;
- info.fleetNumber = fleetNumber;
- info.position = position;
- info.shipID = shipID;
- info.replaceFleetNumber = replaceFleetNumber;
- info.replacePosition = replacePosition;
- info.replaceShipID = replaceShipID;
-
- [[NSNotificationCenter defaultCenter] postNotificationName:HMChangeHenseiNotification
- object:self
- userInfo:@{HMChangeHenseiUserInfoKey: info}];
-}
-@end
--- /dev/null
+//
+// HMChangeHenseiCommand.swift
+// KCD
+//
+// Created by Hori,Masaki on 2017/01/09.
+// Copyright © 2017年 Hori,Masaki. All rights reserved.
+//
+
+import Cocoa
+
+enum ChangeHenseiType: Int {
+ case append
+ case replace
+ case remove
+ case removeAllWithoutFlagship
+}
+
+extension Notification.Name {
+ static let HenseiDidChange = Notification.Name("com.masakih.KCD.Notification.HenseiDidChange")
+}
+let HenseiDidChangeUserInfoKey = "HenseiDidChangeUserInfoKey"
+
+class HenseiDidChangeUserInfo: NSObject {
+ let type: ChangeHenseiType
+
+ let fleetNumber: Int
+ let position: Int
+ let shipID: Int
+
+ let replaceFleetNumber: Int?
+ let replacePosition: Int?
+ let replaceShipID: Int?
+
+ var objcType: Int { return type.rawValue }
+ var objcReplaceFleetNumbner: NSNumber? { return replaceFleetNumber as NSNumber?? ?? nil }
+ var objcReplacePosition: NSNumber? { return replacePosition as NSNumber?? ?? nil }
+ var objcReplaceShipID: NSNumber? { return replaceShipID as NSNumber?? ?? nil }
+
+ required init(type: ChangeHenseiType, fleetNumber: Int, position: Int, shipID: Int, replaceFleetNumber: Int? = nil, replacePosition: Int? = nil, replaceShipID: Int? = nil) {
+ self.type = type
+ self.fleetNumber = fleetNumber
+ self.position = position
+ self.shipID = shipID
+ self.replaceFleetNumber = replaceFleetNumber
+ self.replacePosition = replacePosition
+ self.replaceShipID = replaceShipID
+ super.init()
+ }
+}
+
+class HMChangeHenseiCommand: HMJSONCommand {
+ override class func canExcuteAPI(_ api: String) -> Bool {
+ if api == "/kcsapi/api_req_hensei/change" { return true }
+ return false
+ }
+
+ static let notificationName = Notification.Name.HenseiDidChange.rawValue
+ static let userInfoKey = HenseiDidChangeUserInfoKey
+
+ // api_ship_id の値
+ // ship_id > 0 : 艦娘のID append or replace
+ // ship_id == -1 : remove.
+ // ship_id == -2 : remove all without flag ship.
+ override func execute() {
+ guard let dec = arguments["api_id"] as? String,
+ let deckNumber = Int(dec),
+ let si = arguments["api_ship_id"] as? String,
+ let shipId = Int(si),
+ let spi = arguments["api_ship_idx"] as? String,
+ let shipIndex = Int(spi)
+ else { return print("parameter is wrong") }
+ if shipId == -2 {
+ excludeShipsWithoutFlagShip(deckNumber: deckNumber)
+ notify(type: .removeAllWithoutFlagship)
+ return
+ }
+ let store = HMServerDataStore.oneTimeEditor()
+ let sortDec = NSSortDescriptor(key: "id", ascending: true)
+ guard let d = try? store?.objects(withEntityName: "Deck", sortDescriptors: [sortDec], predicate: nil),
+ let decks = d as? [HMKCDeck]
+ else { return print("Deck not found") }
+ let shipIds = decks.flatMap { (deck) -> [Int] in
+ return (0..<6).map {
+ if let res = deck.value(forKey: "ship_\($0)") as? Int {
+ return res
+ }
+ return -1
+ }
+ }
+
+ // すでに編成されているか? どこに?
+ let alreadyInFleet = shipIds.contains(shipId)
+ let index = alreadyInFleet ? shipIds.index(of: shipId)! : -1
+ let shipDeckNumber = alreadyInFleet ? index / 6 : -1
+ let shipDeckIndex = alreadyInFleet ? index % 6 : -1
+
+ // 配置しようとする位置に今配置されている艦娘
+ let replaceShipId = shipIds[(deckNumber - 1) * 6 + shipIndex]
+
+ // 艦隊に配備
+ let deck = decks[deckNumber - 1]
+ deck.setValue(shipId as NSNumber, forKey: "ship_\(shipIndex)")
+
+ // 入れ替え
+ if alreadyInFleet && shipId != -1 {
+ let aDeck = decks[shipDeckNumber]
+ aDeck.setValue(replaceShipId, forKey: "ship_\(shipDeckIndex)")
+ }
+
+ packFleet(store: store!)
+
+ // Notify
+ if alreadyInFleet && shipId == -1 {
+ notify(type: .remove,
+ fleetNumber: deckNumber,
+ position: shipIndex,
+ shipID: replaceShipId)
+ }
+ else if alreadyInFleet {
+ notify(type: .replace,
+ fleetNumber: deckNumber,
+ position: shipIndex,
+ shipID: shipId,
+ replaceFleetNumber: shipDeckNumber + 1,
+ replacePosition: shipDeckIndex,
+ replaceShipID: replaceShipId)
+ }
+ else {
+ notify(type: .append,
+ fleetNumber: deckNumber,
+ position: shipIndex,
+ shipID: shipId)
+ }
+ }
+
+ private func excludeShipsWithoutFlagShip(deckNumber: Int) {
+ let store = HMServerDataStore.oneTimeEditor()
+ let p = NSPredicate(format: "id = %ld", deckNumber)
+ guard let d = try? store?.objects(withEntityName: "Deck", predicate: p),
+ let decks = d as? [HMKCDeck],
+ let deck = decks.first
+ else { return print("Deck not found") }
+ (1..<6).forEach {
+ deck.setValue(-1 as NSNumber, forKey: "ship_\($0)")
+ }
+ }
+
+ private func packFleet(store: HMCoreDataManager) {
+ guard let d = try? store.objects(withEntityName: "Deck", predicate: nil),
+ let decks = d as? [HMKCDeck]
+ else { return }
+ decks.forEach { (deck) in
+ var needsPack = false
+ (0..<6).forEach {
+ let shipId = deck.value(forKey: "ship_\($0)") as? Int
+ if (shipId == nil || shipId! == -1) && !needsPack {
+ needsPack = true
+ return
+ }
+ if needsPack {
+ deck.setValue(shipId! as NSNumber, forKey: "ship_\($0 - 1)")
+ if shipId! == 5 {
+ deck.setValue(-1 as NSNumber, forKey: "ship_5")
+ }
+ }
+ }
+ }
+ }
+
+ private func notify(type: ChangeHenseiType, fleetNumber: Int = 0, position: Int = 0, shipID: Int = 0, replaceFleetNumber: Int? = nil, replacePosition: Int? = nil, replaceShipID: Int? = nil) {
+ let userInfo = HenseiDidChangeUserInfo(type: type, fleetNumber: fleetNumber, position: position, shipID: shipID, replaceFleetNumber: replaceFleetNumber, replacePosition: replacePosition, replaceShipID: replaceShipID)
+ NotificationCenter.default
+ .post(name: .HenseiDidChange, object: self, userInfo: [HenseiDidChangeUserInfoKey:userInfo])
+ }
+}
+++ /dev/null
-//
-// HMChangeHenseiNotification.h
-// KCD
-//
-// Created by Hori,Masaki on 2016/02/21.
-// Copyright © 2016年 Hori,Masaki. All rights reserved.
-//
-
-#import <Foundation/Foundation.h>
-
-typedef NS_ENUM(NSUInteger, HMChangeHenseiType) {
- kHMChangeHenseiAppend,
- kHMChangeHenseiReplace,
- kHMChangeHenseiRemove,
-
- kHMChangeHenseiRemoveAllWithoutFlagship,
-};
-
-@interface HMChangeHenseiNotificationUserInfo : NSObject
-
-@property HMChangeHenseiType type;
-
-@property (nonatomic, strong) NSNumber *fleetNumber;
-@property (nonatomic, strong) NSNumber *position;
-@property (nonatomic, strong) NSNumber *shipID;
-
-@property (nonatomic, strong) NSNumber *replaceFleetNumber;
-@property (nonatomic, strong) NSNumber *replacePosition;
-@property (nonatomic, strong) NSNumber *replaceShipID;
-
-@end
-
-
-extern NSString *HMChangeHenseiNotification;
-extern NSString *HMChangeHenseiUserInfoKey;
+++ /dev/null
-//
-// HMChangeHenseiNotification.m
-// KCD
-//
-// Created by Hori,Masaki on 2016/02/21.
-// Copyright © 2016年 Hori,Masaki. All rights reserved.
-//
-
-#import "HMChangeHenseiNotification.h"
-
-
-NSString *HMChangeHenseiNotification = @"HMChangeHenseiNotification";
-NSString *HMChangeHenseiUserInfoKey = @"HMChangeHenseiUserInfoKey";
-
-
-@implementation HMChangeHenseiNotificationUserInfo
-
-- (id)description
-{
- NSString *format = @"HMChangeHenseiNotificationUserInfo<%p> = {\n"
- @"type = %ld\n"
- @"fleetNumber = %@\n"
- @"position = %@\n"
- @"shipID = %@\n"
- @"replaceFleetNumber = %@\n"
- @"replacePosition = %@\n"
- @"replaceShipID = %@ }";
-
- return [NSString stringWithFormat:format,
- self,
- _type,
- _fleetNumber,
- _position,
- _shipID,
- _replaceFleetNumber,
- _replacePosition,
- _replaceShipID];
-}
-
-@end
#import "HMPowerUpCommand.h"
#import "HMRemodelSlotCommand.h"
#import "HMShipDeckCommand.h"
-#import "HMChangeHenseiCommand.h"
#import "HMResetSortieCommand.h"
#import "HMDropShipHistoryCommand.h"
#import "HMDummyShipCommand.h"