public SquadListShip AddPilotToSquad(GenericShip ship, bool isFromUi = false) { SquadListShip squadBuilderShip = AddShip(ship); if (isFromUi) { foreach (var upgradeType in ship.DefaultUpgrades) { GenericUpgrade upgrade = (GenericUpgrade)Activator.CreateInstance(upgradeType); Edition.Current.AdaptUpgradeToRules(upgrade); if (upgrade is IVariableCost && Edition.Current is SecondEdition) { (upgrade as IVariableCost).UpdateCost(ship); if (upgrade.UpgradeInfo.Cost == int.MaxValue) { upgrade.IsHidden = true; } } squadBuilderShip.TryInstallUpgade(upgrade); } } return(squadBuilderShip); }
public SquadListShip AddShip(GenericShip ship) { SquadListShip newShip = new SquadListShip(ship, this); Ships.Add(newShip); return(newShip); }
public ShipWithUpgradesPanelInfo(SquadListShip ship) { Ship = ship; CreateHolderPanel(ship); ShowPilot(ship); ShowUpgradesOfPilot(ship); SetSize(); }
private void ShowPilot(SquadListShip ship) { GameObject prefab = (GameObject)Resources.Load("Prefabs/SquadBuilder/PilotPanel", typeof(GameObject)); PilotPanel = MonoBehaviour.Instantiate(prefab, Panel.transform); PilotPanel.transform.localPosition = Vector3.zero; PilotPanelSquadBuilder script = PilotPanel.GetComponent <PilotPanelSquadBuilder>(); script.Initialize(ship.Instance, Global.SquadBuilder.View.OpenShipInfo); }
private void CreateHolderPanel(SquadListShip ship) { GameObject prefab = (GameObject)Resources.Load("Prefabs/SquadBuilder/ShipWithUpgradesPanel", typeof(GameObject)); Panel = MonoBehaviour.Instantiate(prefab, GameObject.Find("UI/Panels").transform.Find("SquadBuilderPanel").Find("Panel").Find("SquadListPanel").transform); RectTransform contentRect = Panel.transform.GetComponent <RectTransform>(); int installedUpgradesCount = ship.Instance.UpgradeBar.GetUpgradesAll().Count; contentRect.sizeDelta = new Vector2(SquadBuilderView.PILOT_CARD_WIDTH + (Edition.Current.UpgradeCardCompactSize.x + SquadBuilderView.DISTANCE_SMALL) * installedUpgradesCount, contentRect.sizeDelta.y); }
private int GetShipCost(SquadListShip shipHolder) { int result = 0; result += shipHolder.Instance.PilotInfo.Cost; foreach (var upgradeSlot in shipHolder.Instance.UpgradeBar.GetUpgradeSlots()) { if (!upgradeSlot.IsEmpty) { result += ReduceUpgradeCost(upgradeSlot.InstalledUpgrade.UpgradeInfo.Cost, upgradeSlot.CostDecrease); } } return(result); }
public void CopyShip(SquadListShip shipToCopy) { if (UniquePilotsLimitIsNotExceeded(shipToCopy.Instance)) { GenericShip newShip = (GenericShip)Activator.CreateInstance(Type.GetType(shipToCopy.Instance.GetType().ToString())); Edition.Current.AdaptShipToRules(newShip); Edition.Current.AdaptPilotToRules(newShip); SquadListShip squadBuilderShip = AddShip(newShip); List <GenericUpgrade> copyUpgradesList = new List <GenericUpgrade>(shipToCopy.Instance.UpgradeBar.GetUpgradesAll()); CopyUpgradesRecursive(squadBuilderShip, copyUpgradesList); } else { Messages.ShowInfo(shipToCopy.Instance.PilotInfo.PilotName + " is not copied due to unique cards limit"); } }
private void CopyUpgradesRecursive(SquadListShip targetShip, List <GenericUpgrade> upgradeList) { if (upgradeList.Count > 0) { if (UniqueUpgradesLimitIsNotExceeded(upgradeList.First())) { targetShip.InstallUpgrade(upgradeList.First().NameCanonical, upgradeList.First().UpgradeInfo.UpgradeTypes.First()); } else { Messages.ShowInfo(upgradeList.First().UpgradeInfo.Name + " is not copied due to unique cards limit"); } upgradeList.Remove(upgradeList.First()); CopyUpgradesRecursive(targetShip, upgradeList); } }
private void ShowUpgradeOfPilot(GenericUpgrade upgrade, SquadListShip ship) { GameObject prefab = (GameObject)Resources.Load("Prefabs/SquadBuilder/UpgradePanel", typeof(GameObject)); GameObject newUpgradePanel = MonoBehaviour.Instantiate(prefab, Panel.transform); float configurationOffset = (HasConfigurationInstalled) ? Edition.Current.UpgradeCardCompactSize.x : 0; newUpgradePanel.transform.localPosition = new Vector2( configurationOffset + SquadBuilderView.PILOT_CARD_WIDTH + (Edition.Current.UpgradeCardCompactSize.x * AvailableUpgradesCounter), 0 ); UpgradePanelSquadBuilder script = newUpgradePanel.GetComponent <UpgradePanelSquadBuilder>(); script.Initialize(upgrade.UpgradeInfo.Name, null, upgrade, compact: true); AvailableUpgradesCounter++; }
private void ShowUpgradesOfPilot(SquadListShip ship) { AvailableUpgradesCounter = 0; UpgradePanelSquadBuilder.WaitingToLoad = 0; List <GenericUpgrade> shipUpgrades = ship.Instance.UpgradeBar.GetUpgradesAll().OrderBy(s => s.UpgradeInfo.UpgradeTypes[0]).ToList(); if (shipUpgrades.Any(n => n.HasType(UpgradeType.Configuration))) { HasConfigurationInstalled = true; ShowConfigurationUpgrade(); } foreach (GenericUpgrade upgrade in shipUpgrades) { if (!upgrade.HasType(UpgradeType.Configuration)) { ShowUpgradeOfPilot(upgrade, ship); } } }
private static JSONObject GenerateSquadPilot(SquadListShip shipHolder) { JSONObject pilotJson = new JSONObject(); pilotJson.AddField("id", shipHolder.Instance.PilotNameCanonical); //TODO: Restore //pilotJson.AddField("points", GetShipCost(shipHolder)); pilotJson.AddField("ship", shipHolder.Instance.ShipTypeCanonical); Dictionary <string, JSONObject> upgradesDict = new Dictionary <string, JSONObject>(); foreach (var installedUpgrade in shipHolder.Instance.UpgradeBar.GetUpgradesAll()) { string slotName = Edition.Current.UpgradeTypeToXws(installedUpgrade.UpgradeInfo.UpgradeTypes[0]); if (!upgradesDict.ContainsKey(slotName)) { JSONObject upgrade = new JSONObject(); upgrade.Add(installedUpgrade.NameCanonical); upgradesDict.Add(slotName, upgrade); } else { upgradesDict[slotName].Add(installedUpgrade.NameCanonical); } } JSONObject upgradesDictJson = new JSONObject(upgradesDict); pilotJson.AddField("upgrades", upgradesDictJson); JSONObject vendorJson = new JSONObject(); JSONObject skinJson = new JSONObject(); skinJson.AddField("skin", shipHolder.Instance.ModelInfo.SkinName); vendorJson.AddField("Sandrem.FlyCasual", skinJson); pilotJson.AddField("vendor", vendorJson); return(pilotJson); }
public void RemoveShip(SquadListShip ship) { Ships.Remove(ship); }
private void SetSkinForShip(SquadListShip ship, string skinName) { ship.Instance.ModelInfo.SkinName = skinName; }
private void AddShipWithUpgradesPanel(SquadListShip ship) { ShipWithUpgradesPanelInfo shipWithUpgradesPanel = new ShipWithUpgradesPanelInfo(ship); ShipWithUpgradesPanels.Add(shipWithUpgradesPanel); }
public static void SetPlayerSquadFromImportedJson(SquadList squad, JSONObject squadJson) { if (squadJson.HasField("name")) { squad.Name = squadJson["name"].str; } string factionNameXws = squadJson["faction"].str; Faction faction = Edition.Current.XwsToFaction(factionNameXws); squad.SquadFaction = faction; if (squadJson.HasField("pilots")) { JSONObject pilotJsons = squadJson["pilots"]; foreach (JSONObject pilotJson in pilotJsons.list) { string shipNameXws = pilotJson["ship"].str; string shipNameGeneral = ""; ShipRecord shipRecord = SquadBuilder.Instance.Database.AllShips.FirstOrDefault(n => n.ShipNameCanonical == shipNameXws); if (shipRecord == null) { Messages.ShowError("Cannot find ship: " + shipNameXws); continue; } shipNameGeneral = shipRecord.ShipName; string pilotNameXws = pilotJson["id"].str; PilotRecord pilotRecord = SquadBuilder.Instance.Database.AllPilots.FirstOrDefault(n => n.PilotNameCanonical == pilotNameXws && n.Ship.ShipName == shipNameGeneral && n.PilotFaction == faction); if (pilotRecord == null) { Messages.ShowError("Cannot find pilot: " + pilotNameXws); continue; } GenericShip newShipInstance = (GenericShip)Activator.CreateInstance(Type.GetType(pilotRecord.PilotTypeName)); Edition.Current.AdaptShipToRules(newShipInstance); SquadListShip newShip = squad.AddPilotToSquad(newShipInstance); Dictionary <string, string> upgradesThatCannotBeInstalled = new Dictionary <string, string>(); if (pilotJson.HasField("upgrades")) { JSONObject upgradeJsons = pilotJson["upgrades"]; if (upgradeJsons.keys != null) { foreach (string upgradeType in upgradeJsons.keys) { JSONObject upgradeNames = upgradeJsons[upgradeType]; foreach (JSONObject upgradeRecord in upgradeNames.list) { UpgradeRecord newUpgradeRecord = SquadBuilder.Instance.Database.AllUpgrades.FirstOrDefault(n => n.UpgradeNameCanonical == upgradeRecord.str); if (newUpgradeRecord == null) { Messages.ShowError("Cannot find upgrade: " + upgradeRecord.str); } bool upgradeInstalledSucessfully = newShip.InstallUpgrade(upgradeRecord.str, Edition.Current.XwsToUpgradeType(upgradeType)); if (!upgradeInstalledSucessfully && !upgradesThatCannotBeInstalled.ContainsKey(upgradeRecord.str)) { upgradesThatCannotBeInstalled.Add(upgradeRecord.str, upgradeType); } } } while (upgradeJsons.Count != 0) { Dictionary <string, string> upgradesThatCannotBeInstalledCopy = new Dictionary <string, string>(upgradesThatCannotBeInstalled); bool wasSuccess = false; foreach (var upgrade in upgradesThatCannotBeInstalledCopy) { bool upgradeInstalledSucessfully = newShip.InstallUpgrade(upgrade.Key, Edition.Current.XwsToUpgradeType(upgrade.Value)); if (upgradeInstalledSucessfully) { wasSuccess = true; upgradesThatCannotBeInstalled.Remove(upgrade.Key); } } if (!wasSuccess) { break; } } } } if (pilotJson.HasField("vendor")) { JSONObject vendorData = pilotJson["vendor"]; if (vendorData.HasField("Sandrem.FlyCasual")) { JSONObject myVendorData = vendorData["Sandrem.FlyCasual"]; if (myVendorData.HasField("skin")) { newShip.Instance.ModelInfo.SkinName = myVendorData["skin"].str; } } } } } else { Messages.ShowError("The squad has no pilots"); } if (squadJson.HasField("obstacles")) { squad.ChosenObstacles.AddRange( new List <GenericObstacle>() { ObstaclesManager.GetPossibleObstacle(squadJson["obstacles"][0].str), ObstaclesManager.GetPossibleObstacle(squadJson["obstacles"][1].str), ObstaclesManager.GetPossibleObstacle(squadJson["obstacles"][2].str) } ); } else { squad.SetDefaultObstacles(); } }