Example #1
0
        public static void SetPlayerSquadFromImportedJson(string name, JSONObject squadJson, PlayerNo playerNo, Action callBack)
        {
            ClearShipsOfPlayer(playerNo);

            try
            {
                SquadList squadList = GetSquadList(playerNo);

                if (squadJson.HasField("name"))
                {
                    squadList.Name = squadJson["name"].str;
                }

                string  factionNameXws = squadJson["faction"].str;
                Faction faction        = XWSToFaction(factionNameXws);
                squadList.SquadFaction = faction;

                squadList.Points = (int)squadJson["points"].i;

                if (squadJson.HasField("pilots"))
                {
                    JSONObject pilotJsons = squadJson["pilots"];
                    foreach (JSONObject pilotJson in pilotJsons.list)
                    {
                        string shipNameXws     = pilotJson["ship"].str;
                        string shipNameGeneral = AllShips.Find(n => n.ShipNameCanonical == shipNameXws).ShipName;

                        string pilotNameXws = pilotJson["name"].str;
                        if (!AllPilots.Any(n => n.PilotNameCanonical == pilotNameXws))
                        {
                            Debug.Log("Cannot find pilot: " + pilotNameXws);
                            Console.Write("Cannot find pilot: " + pilotNameXws, LogTypes.Errors, true, "red");
                        }
                        string pilotNameGeneral = AllPilots.Find(n => n.PilotNameCanonical == pilotNameXws).PilotName;

                        PilotRecord pilotRecord     = AllPilots.Find(n => n.PilotName == pilotNameGeneral && n.PilotShip.ShipName == shipNameGeneral && n.PilotFaction == faction);
                        GenericShip newShipInstance = (GenericShip)Activator.CreateInstance(Type.GetType(pilotRecord.PilotTypeName));
                        Edition.Current.AdaptShipToRules(newShipInstance);
                        SquadBuilderShip newShip = AddPilotToSquad(newShipInstance, playerNo);

                        List <string> upgradesThatCannotBeInstalled = new List <string>();

                        JSONObject upgradeJsons = pilotJson["upgrades"];
                        foreach (string upgradeType in upgradeJsons.keys)
                        {
                            JSONObject upgradeNames = upgradeJsons[upgradeType];
                            foreach (JSONObject upgradeRecord in upgradeNames.list)
                            {
                                if (!AllUpgrades.Any(n => n.UpgradeNameCanonical == upgradeRecord.str))
                                {
                                    Debug.Log("Cannot find upgrade: " + upgradeRecord.str);
                                    Console.Write("Cannot find upgrade: " + upgradeRecord.str, LogTypes.Errors, true, "red");
                                }
                                string upgradeName = AllUpgrades.Find(n => n.UpgradeNameCanonical == upgradeRecord.str).UpgradeName;
                                bool   upgradeInstalledSucessfully = InstallUpgrade(newShip, upgradeName);
                                if (!upgradeInstalledSucessfully)
                                {
                                    upgradesThatCannotBeInstalled.Add(upgradeName);
                                }
                            }
                        }

                        while (upgradeJsons.Count != 0)
                        {
                            List <string> upgradesThatCannotBeInstalledCopy = new List <string>(upgradesThatCannotBeInstalled);

                            bool wasSuccess = false;
                            foreach (var upgradeName in upgradesThatCannotBeInstalledCopy)
                            {
                                bool upgradeInstalledSucessfully = InstallUpgrade(newShip, upgradeName);
                                if (upgradeInstalledSucessfully)
                                {
                                    wasSuccess = true;
                                    upgradesThatCannotBeInstalled.Remove(upgradeName);
                                }
                            }

                            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("No pilots");
                }

                callBack();
            }
            catch (Exception)
            {
                Messages.ShowError("Error during creation of squadron '" + name + "'");
                ClearShipsOfPlayer(playerNo);
                //throw;
            }
        }
Example #2
0
 public void RemoveShip(SquadBuilderShip ship)
 {
     Ships.Remove(ship);
 }
Example #3
0
 private static List <UpgradeSlot> FindFreeSlots(SquadBuilderShip shipHolder, List <UpgradeType> upgradeTypes)
 {
     return(shipHolder.Instance.UpgradeBar.GetFreeSlots(upgradeTypes));
 }
Example #4
0
 private static void SetSkinForShip(SquadBuilderShip ship, string skinName)
 {
     ship.Instance.ModelInfo.SkinName = skinName;
 }
Example #5
0
 private static string GetSkinName(SquadBuilderShip shipHolder)
 {
     return(shipHolder.Instance.ModelInfo.SkinName);
 }
Example #6
0
 public ShipWithUpgradesPanel(SquadBuilderShip ship, GameObject panel)
 {
     Ship  = ship;
     Panel = panel;
 }