Skip to content

Commit

Permalink
Rig support.
Browse files Browse the repository at this point in the history
  • Loading branch information
mamaral committed Oct 30, 2019
1 parent dc879ed commit 6d9552d
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 0 deletions.
4 changes: 4 additions & 0 deletions iOS/BattleBuddy.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
EFD03DD222B3FAAA00DE1874 /* BaseTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EFD03DD122B3FAAA00DE1874 /* BaseTabBarController.swift */; };
EFD03DD522B3FAEA00DE1874 /* LoadingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EFD03DD322B3FAEA00DE1874 /* LoadingViewController.swift */; };
EFD03DD622B3FAEA00DE1874 /* LoadingViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = EFD03DD422B3FAEA00DE1874 /* LoadingViewController.xib */; };
EFDB0747236A041B00B8EBE7 /* Rig.swift in Sources */ = {isa = PBXBuildFile; fileRef = EFDB0746236A041B00B8EBE7 /* Rig.swift */; };
EFDD387422C26BAF00B66E13 /* MoreMenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EFDD387322C26BAF00B66E13 /* MoreMenuViewController.swift */; };
EFF2FF4222D3BB2D00BED024 /* StaticGridCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = EFF2FF4122D3BB2C00BED024 /* StaticGridCollectionViewCell.swift */; };
EFF2FF4622D3C5A200BED024 /* FirebaseManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = EFF2FF4522D3C5A200BED024 /* FirebaseManager.swift */; };
Expand Down Expand Up @@ -428,6 +429,7 @@
EFD03DD122B3FAAA00DE1874 /* BaseTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseTabBarController.swift; sourceTree = "<group>"; };
EFD03DD322B3FAEA00DE1874 /* LoadingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingViewController.swift; sourceTree = "<group>"; };
EFD03DD422B3FAEA00DE1874 /* LoadingViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = LoadingViewController.xib; sourceTree = "<group>"; };
EFDB0746236A041B00B8EBE7 /* Rig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Rig.swift; sourceTree = "<group>"; };
EFDD387322C26BAF00B66E13 /* MoreMenuViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoreMenuViewController.swift; sourceTree = "<group>"; };
EFF2FF4122D3BB2C00BED024 /* StaticGridCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StaticGridCollectionViewCell.swift; sourceTree = "<group>"; };
EFF2FF4522D3C5A200BED024 /* FirebaseManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirebaseManager.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -620,6 +622,7 @@
276D916F23100FE600CD61E0 /* Firearm.swift */,
EF7AF36222C2A8D300DA1A18 /* Ammo.swift */,
EF7AF35E22C2A7F800DA1A18 /* Armor.swift */,
EFDB0746236A041B00B8EBE7 /* Rig.swift */,
EF831FE522DF78A300C6C138 /* Medical.swift */,
27A4A8FC22E69BCD00C5618E /* Throwable.swift */,
27BF991822C839EB003F01C5 /* MeleeWeapon.swift */,
Expand Down Expand Up @@ -1504,6 +1507,7 @@
EF7AF37A22C66B0C00DA1A18 /* StaticGridCollectionView.swift in Sources */,
27D2105D23194185005A538F /* WatchAdCell.swift in Sources */,
EF1945A823510FED007D8242 /* DependencyUtils.swift in Sources */,
EFDB0747236A041B00B8EBE7 /* Rig.swift in Sources */,
EF4F20072326A99800F20CF0 /* DeviceManagerImpl.swift in Sources */,
276D917E231033C200CD61E0 /* MedicalEnums.swift in Sources */,
27F09ADD22DF50A100552C35 /* MathUtils.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class FirebaseManager: NSObject {
private lazy var ammoImageRef = storageRef.child("ammo")
private lazy var medsImageRef = storageRef.child("meds")
private lazy var armorImageRef = storageRef.child("armor")
private lazy var rigsImageRef = storageRef.child("rigs")
private lazy var helmetImageRef = storageRef.child("armor")
private lazy var visorImageRef = storageRef.child("armor")
private lazy var tradersImageRef = storageRef.child("traders")
Expand Down Expand Up @@ -112,6 +113,7 @@ class FirebaseManager: NSObject {
case .ammo: return ammoImageRef.child(imageId)
case .medical: return medsImageRef.child(imageId)
case .armor: return armorImageRef.child(imageId)
case .rig: return rigImageRef.child(imageId)
case .helmet: return helmetImageRef.child(imageId)
case .visor: return visorImageRef.child(imageId)
case .throwable: return throwableImageRef.child(imageId)
Expand Down
2 changes: 2 additions & 0 deletions iOS/BattleBuddy/Source/Model/Question/Enums/ItemEnums.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum ItemType: String {
case melee = "melee"
case ammo = "ammunition"
case armor = "armor"
case rig = "tacticalrig"
case medical = "medical"
case throwable = "grenade"
case helmet = "helmet"
Expand All @@ -25,6 +26,7 @@ enum ItemType: String {
case .melee: return "main_menu_melee".local()
case .ammo: return "main_menu_ammo".local()
case .armor: return "main_menu_armor".local()
case .rig: return "main_menu_rig".local()
case .visor: return "main_menu_visors".local()
case .medical: return "main_menu_medical".local()
case .throwable: return "main_menu_throwables".local()
Expand Down
158 changes: 158 additions & 0 deletions iOS/BattleBuddy/Source/Model/Question/Rig.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
//
// Rig.swift
// BattleBuddy
//
// Created by Mike on 6/25/19.
// Copyright © 2019 Veritas. All rights reserved.
//

import Foundation
import BallisticsEngine

class Rig: BaseItem, Armored {
let json: [String : Any]
let type: ItemType
var maxDurability: Int
var currentDurability: Int
let material: ArmorMaterial
let armorType: ArmorType
let armorClass: ArmorClass
var richochetParams: RichochetParams { get { return RichochetParams(x: richochetX, y: richochetY, z: richochetZ) } }
var penalties: Penalties { get { return Penalties(ergonomics: ergoPenalty, turnSpeed: turnSpeedPenalty, movementSpeed: movementSpeedPenalty, hearing: hearingPenalty) } }
var armorZoneConfig: ArmorZonesConfig { get { return ArmorZonesConfig(topHead: protectsTopHead, eyes: protectsEyes, jaws: protectsJaws, ears: protectsEars, nape: protectsNape, chest: protectsChest, stomach: protectsStomach, leftArm: protectsLeftArm, rightArm: protectsRightArm, leftLeg: protectsLeftLeg, rightLeg: protectsRightLeg) } }

fileprivate var bluntThroughput: Float
fileprivate var ergoPenalty: Int
fileprivate var turnSpeedPenalty: Int
fileprivate var movementSpeedPenalty: Int
fileprivate var protectsTopHead: Bool
fileprivate var protectsEyes: Bool
fileprivate var protectsJaws: Bool
fileprivate var protectsEars: Bool
fileprivate var protectsNape: Bool
fileprivate var protectsChest: Bool
fileprivate var protectsStomach: Bool
fileprivate var protectsLeftArm: Bool
fileprivate var protectsRightArm: Bool
fileprivate var protectsLeftLeg: Bool
fileprivate var protectsRightLeg: Bool

init?(json: [String: Any]) {
self.json = json
self.type = .rig

guard BaseItemUtils.baseItemJsonValid(json),
let rawType = json["type"] as? String,
let resolvedType = ArmorType(rawValue: rawType),
let armorProperties = json["armor"] as? [String: Any],
let rawMaterial = armorProperties["material"] as? [String: Any],
let rawMaterialName = rawMaterial["name"] as? String,
let resolvedMaterial = ArmorMaterial(rawValue: rawMaterialName),
let rawDurability = armorProperties["durability"] as? NSNumber,
let rawClass = armorProperties["class"] as? NSNumber,
let resolvedArmorClass = ArmorClass(rawValue: rawClass.intValue),
let rawZones = armorProperties["zones"] as? [String],
let rawBluntTp = armorProperties["bluntThroughput"] as? NSNumber,
let penalties = json["penalties"] as? [String: Any] else {
print("ERROR: Armor missing required parameters in json: \(json)")
return nil
}

armorType = resolvedType
material = resolvedMaterial
armorClass = resolvedArmorClass
maxDurability = rawDurability.intValue
currentDurability = maxDurability
protectsTopHead = rawZones.contains("top")
protectsEyes = rawZones.contains("eyes")
protectsJaws = rawZones.contains("jaws")
protectsEars = rawZones.contains("ears")
protectsNape = rawZones.contains("nape")
protectsChest = rawZones.contains("chest")
protectsStomach = rawZones.contains("stomach")
protectsLeftArm = rawZones.contains("leftarm")
protectsRightArm = rawZones.contains("rightarm")
protectsLeftLeg = rawZones.contains("leftleg")
protectsRightLeg = rawZones.contains("rightleg")
bluntThroughput = rawBluntTp.floatValue

if let speedPen = penalties["speed"] as? NSNumber {
movementSpeedPenalty = speedPen.intValue
} else {
movementSpeedPenalty = 0
}

if let ergoPen = penalties["ergonomics"] as? NSNumber {
ergoPenalty = ergoPen.intValue
} else {
ergoPenalty = 0
}

if let mousePen = penalties["mouse"] as? NSNumber {
turnSpeedPenalty = mousePen.intValue
} else {
turnSpeedPenalty = 0
}
}

func localizedArmorZonesDisplayString() -> String {
var components: [String] = []

if protectsTopHead { components.append("armor_zone_top".local()) }
if protectsEyes { components.append("armor_zone_eyes".local()) }
if protectsJaws { components.append("armor_zone_jaws".local()) }
if protectsEars { components.append("armor_zone_ears".local()) }
if protectsNape { components.append("armor_zone_nape".local()) }
if protectsChest { components.append("armor_zone_chest".local()) }
if protectsStomach { components.append("armor_zone_stomach".local()) }
if protectsLeftArm { components.append("armor_zone_left_arm".local()) }
if protectsRightArm { components.append("armor_zone_right_arm".local()) }
if protectsLeftLeg { components.append("armor_zone_left_leg".local()) }
if protectsRightLeg { components.append("armor_zone_right_leg".local()) }

return components.joined(separator: ", ")
}
}

class SimulationArmor: Armored {
override init?(json: [String: Any]) {
super.init(json: json)
}
}

// MARK: Calculable Armor
extension SimulationArmor: CalculableArmor {
func copy(with zone: NSZone? = nil) -> Any {
return SimulationArmor(json: json)!
}

var resolvedArmorName: String { get { return displayName } }
var resolvedArmorClass: Int { get { return armorClass.rawValue } }
var resolvedCurrentDurability: Double {
get { return Double(currentDurability) }
set { currentDurability = Int(newValue) }
}
var resolvedMaxDurability: Double {
get { return Double(maxDurability) }
set { maxDurability = Int(newValue) }
}
var resolvedDestructibility: Double { get { return Double(material.destructibility()) } }
var resolvedBluntThroughput: Double { get { return Double(bluntThroughput) } }
var resolvedProtectionZones: [BallisticsEngine.BodyZoneType] {
var zones: [BallisticsEngine.BodyZoneType] = []

if protectsTopHead { if !zones.contains(.head) { zones.append(.head) } }
if protectsEyes { if !zones.contains(.head) { zones.append(.head) } }
if protectsJaws { if !zones.contains(.head) { zones.append(.head) } }
if protectsEars { if !zones.contains(.head) { zones.append(.head) } }
if protectsNape { if !zones.contains(.head) { zones.append(.head) } }
if protectsChest { zones.append(.thorax) }
if protectsStomach { zones.append(.stomach) }
if protectsLeftArm { zones.append(.leftArm) }
if protectsRightArm { zones.append(.rightArm) }
if protectsLeftLeg { zones.append(.leftLeg) }
if protectsRightLeg { zones.append(.rightLeg) }

return zones
}
}

0 comments on commit 6d9552d

Please sign in to comment.