• R/O
  • HTTP
  • SSH
  • HTTPS

KCD: Commit

main code repository.


Commit MetaInfo

Revisiona1ef53858caf910c6f6e74759a23cf8eacd92c72 (tree)
Time2018-08-05 14:32:11
Authormasakih <masakih@user...>
Commitermasakih

Log Message

被ダメージ計算を多少分かりやすくした

Change Summary

Incremental Difference

--- a/KCD/DamageCalculator.swift
+++ b/KCD/DamageCalculator.swift
@@ -16,6 +16,39 @@ enum BattleFleet {
1616 case secondOnly
1717 }
1818
19+private struct PositionedDamage {
20+
21+ let position: Int
22+ let damage: Int
23+
24+ static let zero = PositionedDamage(position: 0, damage: 0)
25+}
26+
27+extension PositionedDamage: Equatable {
28+
29+ static func == (lhs: PositionedDamage, rhs: PositionedDamage) -> Bool {
30+
31+ return lhs.position == rhs.position && lhs.damage == rhs.damage
32+ }
33+}
34+
35+private struct HogekiBattleData {
36+
37+ let targetPositionList: [Int]
38+ let damageList: [Int]
39+ let enemyFlags: Bool
40+}
41+
42+private func friendDamage(_ data: HogekiBattleData) -> PositionedDamage {
43+
44+ guard !data.enemyFlags else { return .zero }
45+
46+ guard let pos = data.targetPositionList.first else { return .zero }
47+
48+ return PositionedDamage(position: pos,
49+ damage: data.damageList.filter({ $0 > 0 }).reduce(0, +))
50+}
51+
1952 final class DamageCalculator {
2053
2154 private let store = TemporaryDataStore.oneTimeEditor()
@@ -384,17 +417,7 @@ extension DamageCalculator {
384417 calculateHogeki(baseKeyPath: baseKeyPath, battleFleet: bf())
385418 }
386419
387- private func omitEnemyDamage(targetPosLists: [[Int]], damageLists: [[Int]], eFlags: [Int]?) -> [([Int], [Int])] {
388-
389- guard let eFlags = eFlags else {
390-
391- return zip(targetPosLists, damageLists).map { $0 }
392- }
393-
394- return zip(zip(targetPosLists, damageLists), eFlags).filter { $0.1 == 1 }.map { $0.0 }
395- }
396-
397- private func calculateHogeki(baseKeyPath: String, battleFleet: BattleFleet = .normal) {
420+ private func buildBattleData(baseKeyPath: String) -> [HogekiBattleData] {
398421
399422 let baseValue = json[baseKeyPath.components(separatedBy: ".")]
400423
@@ -403,47 +426,56 @@ extension DamageCalculator {
403426
404427 Debug.print("Cound not find api_df_list or api_damage for \(baseKeyPath)", level: .full)
405428
406- return
429+ return []
407430 }
408431
409432 guard targetPosLists.count == damageLists.count else {
410433
411434 Logger.shared.log("api_damage is wrong.")
412435
413- return
436+ return []
414437 }
415438
416- Debug.print("Start Hougeki \(baseKeyPath)", level: .debug)
439+ guard let eFlags = enemyFlags(baseValue["api_at_eflag"]) else {
440+
441+ return zip(targetPosLists, damageLists).map { HogekiBattleData(targetPositionList: $0.0, damageList: $0.1, enemyFlags: false) }
442+ }
417443
418- omitEnemyDamage(targetPosLists: targetPosLists, damageLists: damageLists, eFlags: enemyFlags(baseValue["api_at_eflag"]))
419- .map { (targetPosList, damageList) -> (Int, Int) in
444+ return zip(zip(targetPosLists, damageLists), eFlags)
445+ .map { arg -> HogekiBattleData in
420446
421- guard let pos = targetPosList.first else {
422-
423- return (0, 0)
424- }
447+ let ((targetPosList, damageList), eflag) = arg
425448
426- return (pos, damageList.filter { $0 > 0 }.reduce(0, +))
427- }
428- .forEach { (targetPos, damage) in
449+ return HogekiBattleData(targetPositionList: targetPosList, damageList: damageList, enemyFlags: eflag != 1)
450+ }
451+ }
452+
453+ private func calculateHogeki(baseKeyPath: String, battleFleet: BattleFleet = .normal) {
454+
455+ Debug.print("Start Hougeki \(baseKeyPath)", level: .debug)
456+
457+ buildBattleData(baseKeyPath: baseKeyPath)
458+ .map(friendDamage)
459+ .filter { $0 != .zero }
460+ .forEach { posDamage in
429461
430- guard validTargetPos(targetPos, in: battleFleet) else {
462+ guard validTargetPos(posDamage.position, in: battleFleet) else {
431463
432- Logger.shared.log("invalid position \(targetPos)")
464+ Logger.shared.log("invalid position \(posDamage.position)")
433465
434466 return
435467 }
436468
437- guard let damagePos = position(targetPos, in: battleFleet) else {
469+ guard let damagePos = position(posDamage.position, in: battleFleet) else {
438470
439471 Logger.shared.log("damage pos is larger than damage count")
440472
441473 return
442474 }
443475
444- calcHP(damage: damages[damagePos], receive: damage)
476+ calcHP(damage: damages[damagePos], receive: posDamage.damage)
445477
446- Debug.print("Hougeki \(targetPos) -> \(damage)", level: .debug)
478+ Debug.print("Hougeki \(posDamage.position) -> \(posDamage.damage)", level: .debug)
447479 }
448480 }
449481
Show on old repository browser