Example #1
0
        private static void ShowAvailablePilots(Faction faction, string shipName)
        {
            availablePilotsCounter = 0;

            ShipRecord shipRecord = AllShips.Find(n => n.ShipName == shipName);

            List <PilotRecord> AllPilotsFiltered = AllPilots
                                                   .Where(n =>
                                                          n.PilotShip == shipRecord &&
                                                          n.PilotFaction == faction &&
                                                          n.Instance.GetType().ToString().Contains(Edition.Current.NameShort)
                                                          )
                                                   .OrderByDescending(n => n.PilotSkill).
                                                   OrderByDescending(n => n.Instance.PilotInfo.Cost).
                                                   ToList();
            int pilotsCount = AllPilotsFiltered.Count();

            Transform contentTransform = GameObject.Find("UI/Panels/SelectPilotPanel/Panel/Scroll View/Viewport/Content").transform;

            DestroyChildren(contentTransform);
            contentTransform.localPosition = new Vector3(0, contentTransform.localPosition.y, contentTransform.localPosition.z);
            contentTransform.GetComponent <RectTransform>().sizeDelta = new Vector2(pilotsCount * (PILOT_CARD_WIDTH + DISTANCE_MEDIUM) + 2 * DISTANCE_MEDIUM, 0);

            foreach (PilotRecord pilot in AllPilotsFiltered)
            {
                ShowAvailablePilot(pilot);
            }
        }
Example #2
0
        private static void ShowAvailableShip(ShipRecord ship, Faction faction)
        {
            string     prefabPath   = (IsSmallFaction(faction)) ? "Prefabs/SquadBuilder/ShipPanelBig" : "Prefabs/SquadBuilder/ShipPanel";
            GameObject prefab       = (GameObject)Resources.Load(prefabPath, typeof(GameObject));
            GameObject newShipPanel = MonoBehaviour.Instantiate(prefab, GameObject.Find("UI/Panels/SelectShipPanel/Panel").transform);

            ShipPanelSquadBuilder script = newShipPanel.GetComponent <ShipPanelSquadBuilder>();

            script.ImageUrl = GetImageOfIconicPilot(ship);
            script.ShipName = ship.Instance.ShipInfo.ShipName;
            script.FullType = ship.Instance.ShipInfo.ShipName;

            int rowsCount = (IsSmallFaction(faction)) ? SHIP_COLUMN_COUNT_SMALLFACTION : SHIP_COLUMN_COUNT;
            int row       = availableShipsCounter / rowsCount;
            int column    = availableShipsCounter - (row * rowsCount);

            if (IsSmallFaction(faction))
            {
                newShipPanel.transform.localPosition = new Vector3(210 + column * PILOT_CARD_WIDTH * 2 + 50 * (column), -(DISTANCE_MEDIUM + row * 368 + DISTANCE_MEDIUM * 2 * (row)), 0);
            }
            else
            {
                newShipPanel.transform.localPosition = new Vector3(25 + column * PILOT_CARD_WIDTH + 25 * (column), -(DISTANCE_MEDIUM + row * 184 + DISTANCE_MEDIUM * (row)), 0);
            }

            availableShipsCounter++;
        }
Example #3
0
        public PilotRecord(ShipRecord ship, Type type)
        {
            Ship = ship;

            Instance = (GenericShip)System.Activator.CreateInstance(type);
            Edition.Current.AdaptPilotToRules(Instance);
        }
Example #4
0
        private void GetShipRecord(string shipNameSpace)
        {
            ShipRecord shipRecord = new ShipRecord(shipNameSpace);

            if (!AllShips.Any(n => n.ShipName == shipRecord.ShipName))
            {
                AllShips.Add(shipRecord);
                GetPilotsList(shipRecord);
            }
        }
Example #5
0
        public static void ShowListOfArchetypes()
        {
            GameObject prefab          = (GameObject)Resources.Load("Prefabs/UI/ArchetypePanel", typeof(GameObject));
            GameObject archetypesPanel = GameObject.Find("UI/Panels").transform.Find("BrowsePopularSquadsPanel").Find("Scroll View/Viewport/Content").gameObject;

            RectTransform archetypesPanelRectTransform = archetypesPanel.GetComponent <RectTransform>();

            foreach (Transform transform in archetypesPanel.transform)
            {
                GameObject.Destroy(transform.gameObject);
            }

            archetypesPanelRectTransform.sizeDelta = new Vector2(archetypesPanelRectTransform.sizeDelta.x, 0);
            GameObject.Find("UI/Panels").transform.Find("BrowsePopularSquadsPanel").Find("Scroll View").GetComponentInChildren <ScrollRect>().verticalNormalizedPosition = 0f;

            foreach (JSONObject archetype in Data.list)
            {
                GameObject archetypeRecord;

                archetypeRecord      = MonoBehaviour.Instantiate(prefab, archetypesPanel.transform);
                archetypeRecord.name = archetype["name"].str;

                archetypeRecord.transform.Find("Name").GetComponent <Text>().text = archetype["name"].str;

                archetypesPanelRectTransform.sizeDelta = new Vector2(archetypesPanelRectTransform.sizeDelta.x, archetypesPanelRectTransform.sizeDelta.y + 120f + FREE_SPACE);

                string factionText = FactionToChar(archetype["faction"].str.ToLower()).ToString();
                archetypeRecord.transform.Find("Faction").GetComponent <Text>().text = factionText;

                string shipIcons = "";
                foreach (JSONObject ship in archetype["ships"].list)
                {
                    ShipRecord shipRecord = SquadBuilder.AllShips.FirstOrDefault(n => n.ShipName == ship.str);
                    if (shipRecord != null)
                    {
                        shipIcons += shipRecord.Instance.ShipIconLetter;
                    }
                }
                if (shipIcons.Length > 5)
                {
                    shipIcons = shipIcons.Insert((shipIcons.Length - shipIcons.Length % 2) / 2, "\n");
                    archetypeRecord.transform.Find("Ships").GetComponent <Text>().fontSize = 90; // 150 for 1 row
                }
                archetypeRecord.transform.Find("Ships").GetComponent <Text>().text = shipIcons;

                archetypeRecord.transform.Find("LoadButton").GetComponent <Button>().onClick.AddListener
                (
                    () =>
                {
                    SelectedSquadId = int.Parse(archetype["id"].str);
                    MainMenu.CurrentMainMenu.ChangePanel("BrowsePopularSquadsVariantsPanel");
                }
                );;
            }
        }
Example #6
0
        private static string GetImageOfIconicPilot(ShipRecord ship)
        {
            string image = null;

            if (ship.Instance.IconicPilots != null)
            {
                image = AllPilots.Find(n => n.PilotTypeName == ship.Instance.IconicPilots[CurrentSquadList.SquadFaction].ToString()).Instance.ImageUrl;
            }

            return(image);
        }
Example #7
0
        private string GetImageOfIconicPilot(ShipRecord ship)
        {
            string image = null;

            if (ship.Instance.IconicPilots != null)
            {
                image = Global.SquadBuilder.Database.AllPilots.Find(n => n.PilotTypeName == ship.Instance.IconicPilots[Global.SquadBuilder.CurrentSquad.SquadFaction].ToString()).Instance.ImageUrl;
            }

            return(image);
        }
Example #8
0
        private static void ShowAvailableShip(ShipRecord ship)
        {
            GameObject prefab       = (GameObject)Resources.Load("Prefabs/SquadBuilder/ShipPanel", typeof(GameObject));
            GameObject newShipPanel = MonoBehaviour.Instantiate(prefab, GameObject.Find("UI/Panels/SelectShipPanel/Panel").transform);

            ShipPanelSquadBuilder script = newShipPanel.GetComponent <ShipPanelSquadBuilder>();

            script.ImageUrl = GetImageOfIconicPilot(ship);
            script.ShipName = ship.ShipName;

            int row    = availableShipsCounter / SHIP_COLUMN_COUNT;
            int column = availableShipsCounter - (row * SHIP_COLUMN_COUNT);

            newShipPanel.transform.localPosition = new Vector3(25 + column * PILOT_CARD_WIDTH + 25 * (column), -(DISTANCE_MEDIUM + row * 184 + DISTANCE_MEDIUM * (row)), 0);

            availableShipsCounter++;
        }
Example #9
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 #10
0
 private bool HasPilots(ShipRecord ship, Faction faction)
 {
     return(Global.SquadBuilder.Database.AllPilots.Any(n => n.Ship == ship && n.PilotFaction == faction));
 }
Example #11
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();
            }
        }