Example #1
0
        private void ShowAvailablePilot(PilotRecord pilotRecord)
        {
            GameObject prefab           = (GameObject)Resources.Load("Prefabs/SquadBuilder/PilotPanel", typeof(GameObject));
            Transform  contentTransform = GameObject.Find("UI/Panels/SelectPilotPanel/Panel/Scroll View/Viewport/Content").transform;
            GameObject newPilotPanel    = MonoBehaviour.Instantiate(prefab, contentTransform);

            GenericShip newShip = (GenericShip)Activator.CreateInstance(Type.GetType(pilotRecord.PilotTypeName));

            Edition.Current.AdaptShipToRules(newShip);
            Edition.Current.AdaptPilotToRules(newShip);

            PilotPanelSquadBuilder script = newPilotPanel.GetComponent <PilotPanelSquadBuilder>();

            script.Initialize(newShip, PilotSelectedIsClicked, true);
        }
Example #2
0
        private static void ShowAvailablePilot(PilotRecord pilotRecord)
        {
            GameObject prefab           = (GameObject)Resources.Load("Prefabs/SquadBuilder/PilotPanel", typeof(GameObject));
            Transform  contentTransform = GameObject.Find("UI/Panels/SelectPilotPanel/Panel/Scroll View/Viewport/Content").transform;
            GameObject newPilotPanel    = MonoBehaviour.Instantiate(prefab, contentTransform);

            GenericShip newShip = (GenericShip)Activator.CreateInstance(Type.GetType(pilotRecord.PilotTypeName));

            PilotPanelSquadBuilder script = newPilotPanel.GetComponent <PilotPanelSquadBuilder>();

            script.Initialize(newShip, PilotSelectedIsClicked, true);

            int column = availablePilotsCounter;

            newPilotPanel.transform.localPosition = new Vector3(DISTANCE_MEDIUM + (PILOT_CARD_WIDTH + DISTANCE_MEDIUM) * column, PILOT_CARD_HEIGHT / 2, 0);

            availablePilotsCounter++;
        }
Example #3
0
        private void GetPilotsList(ShipRecord ship)
        {
            List <Type> pilotTypes = Assembly.GetExecutingAssembly().GetTypes()
                                     .Where(t => String.Equals(t.Namespace, ship.ShipNamespace, StringComparison.Ordinal))
                                     .ToList();

            foreach (var pilotType in pilotTypes)
            {
                if (pilotType.MemberType == MemberTypes.NestedType)
                {
                    continue;
                }

                PilotRecord pilotRecord = new PilotRecord(ship, pilotType);
                if (pilotRecord.IsAllowedForSquadBuilder)
                {
                    AllPilots.Add(pilotRecord);
                }
            }
        }
Example #4
0
        public static void SetPlayerSquadFromImportedJson(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));
                        RuleSet.Instance.AdaptShipToRules(newShipInstance);
                        RuleSet.Instance.AdaptPilotToRules(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.SkinName = myVendorData["skin"].str;
                                }
                            }
                        }
                    }
                }
                else
                {
                    Messages.ShowError("No pilots");
                }

                callBack();
            }
            catch (Exception)
            {
                Messages.ShowError("Error during creation of squadron");
                ClearShipsOfPlayer(playerNo);
                //throw;
            }
        }
Example #5
0
        public static void SetPlayerSquadFromImportedJson(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;
                        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));
                        SquadBuilderShip newShip         = AddPilotToSquad(newShipInstance, playerNo);

                        JSONObject upgradeJsons = pilotJson["upgrades"];
                        foreach (string upgradeType in upgradeJsons.keys)
                        {
                            JSONObject upgradeNames = upgradeJsons[upgradeType];
                            foreach (JSONObject upgradeRecord in upgradeNames.list)
                            {
                                string upgradeName = AllUpgrades.Find(n => n.UpgradeNameCanonical == upgradeRecord.str).UpgradeName;
                                InstallUpgrade(newShip, upgradeName);
                            }
                        }

                        if (pilotJson.HasField("vendor"))
                        {
                            JSONObject vendorData = pilotJson["vendor"];
                            if (vendorData.HasField("Sandrem.FlyCasual"))
                            {
                                JSONObject myVendorData = vendorData["Sandrem.FlyCasual"];
                                if (myVendorData.HasField("skin"))
                                {
                                    newShip.Instance.SkinName = myVendorData["skin"].str;
                                }
                            }
                        }
                    }
                }
                else
                {
                    Messages.ShowError("No pilots");
                }

                callBack();
            }
            catch (Exception)
            {
                Messages.ShowError("Error during creation of squadron");
                ClearShipsOfPlayer(playerNo);
                //throw;
            }
        }
Example #6
0
        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();
            }
        }