Example #1
0
 private void UpdateHireables(Location location)
 {
     if (hireableList != null)
     {
         hireableList.Content.Children.ToList().ForEach(c => hireableList.RemoveChild(c));
         var hireableCharacters = location.GetHireableCharacters();
         if (hireableCharacters.None())
         {
             new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), hireableList.Content.RectTransform), TextManager.Get("HireUnavailable"), textAlignment: Alignment.Center)
             {
                 CanBeFocused = false
             };
         }
         else
         {
             foreach (CharacterInfo c in hireableCharacters)
             {
                 if (c == null)
                 {
                     continue;
                 }
                 CreateCharacterFrame(c, hireableList);
             }
         }
         sortingDropDown.SelectItem(SortingMethod.JobAsc);
         hireableList.UpdateScrollBarSize();
     }
 }
        public void ServerReadCrew(IReadMessage msg, Client sender)
        {
            int[] pendingHires = null;

            bool updatePending = msg.ReadBoolean();

            if (updatePending)
            {
                ushort pendingHireLength = msg.ReadUInt16();
                pendingHires = new int[pendingHireLength];
                for (int i = 0; i < pendingHireLength; i++)
                {
                    pendingHires[i] = msg.ReadInt32();
                }
            }

            bool validateHires = msg.ReadBoolean();

            bool   renameCharacter    = msg.ReadBoolean();
            int    renamedIdentifier  = -1;
            string newName            = null;
            bool   existingCrewMember = false;

            if (renameCharacter)
            {
                renamedIdentifier  = msg.ReadInt32();
                newName            = msg.ReadString();
                existingCrewMember = msg.ReadBoolean();
            }

            bool fireCharacter   = msg.ReadBoolean();
            int  firedIdentifier = -1;

            if (fireCharacter)
            {
                firedIdentifier = msg.ReadInt32();
            }

            Location             location        = map?.CurrentLocation;
            List <CharacterInfo> hiredCharacters = new List <CharacterInfo>();
            CharacterInfo        firedCharacter  = null;

            if (location != null && AllowedToManageCampaign(sender))
            {
                if (fireCharacter)
                {
                    firedCharacter = CrewManager.CharacterInfos.FirstOrDefault(info => info.GetIdentifier() == firedIdentifier);
                    if (firedCharacter != null && (firedCharacter.Character?.IsBot ?? true))
                    {
                        CrewManager.FireCharacter(firedCharacter);
                    }
                    else
                    {
                        DebugConsole.ThrowError($"Tried to fire an invalid character ({firedIdentifier})");
                    }
                }

                if (renameCharacter)
                {
                    CharacterInfo characterInfo = null;
                    if (existingCrewMember && CrewManager != null)
                    {
                        characterInfo = CrewManager.CharacterInfos.FirstOrDefault(info => info.GetIdentifierUsingOriginalName() == renamedIdentifier);
                    }
                    else if (!existingCrewMember && location.HireManager != null)
                    {
                        characterInfo = location.HireManager.AvailableCharacters.FirstOrDefault(info => info.GetIdentifierUsingOriginalName() == renamedIdentifier);
                    }

                    if (characterInfo != null && (characterInfo.Character?.IsBot ?? true))
                    {
                        if (existingCrewMember)
                        {
                            CrewManager.RenameCharacter(characterInfo, newName);
                        }
                        else
                        {
                            location.HireManager.RenameCharacter(characterInfo, newName);
                        }
                    }
                    else
                    {
                        DebugConsole.ThrowError($"Tried to rename an invalid character ({renamedIdentifier})");
                    }
                }

                if (location.HireManager != null)
                {
                    if (validateHires)
                    {
                        foreach (CharacterInfo hireInfo in location.HireManager.PendingHires)
                        {
                            if (TryHireCharacter(location, hireInfo))
                            {
                                hiredCharacters.Add(hireInfo);
                            }
                            ;
                        }
                    }

                    if (updatePending)
                    {
                        List <CharacterInfo> pendingHireInfos = new List <CharacterInfo>();
                        foreach (int identifier in pendingHires)
                        {
                            CharacterInfo match = location.GetHireableCharacters().FirstOrDefault(info => info.GetIdentifierUsingOriginalName() == identifier);
                            if (match == null)
                            {
                                DebugConsole.ThrowError($"Tried to add a character that doesn't exist ({identifier}) to pending hires");
                                continue;
                            }

                            pendingHireInfos.Add(match);
                            if (pendingHireInfos.Count + CrewManager.CharacterInfos.Count() >= CrewManager.MaxCrewSize)
                            {
                                break;
                            }
                        }
                        location.HireManager.PendingHires = pendingHireInfos;
                    }

                    location.HireManager.AvailableCharacters.ForEachMod(info =>
                    {
                        if (!location.HireManager.PendingHires.Contains(info))
                        {
                            location.HireManager.RenameCharacter(info, info.OriginalName);
                        }
                    });
                }
            }

            // bounce back
            if (renameCharacter && existingCrewMember)
            {
                SendCrewState(hiredCharacters, (renamedIdentifier, newName), firedCharacter);
            }
            else
            {
                SendCrewState(hiredCharacters, default, firedCharacter);
Example #3
0
        private void UpdateLocationView(Location location)
        {
            if (location == null)
            {
                string errorMsg = "Failed to update CampaignUI location view (location was null)\n" + Environment.StackTrace;
                DebugConsole.ThrowError(errorMsg);
                GameAnalyticsManager.AddErrorEventOnce("CampaignUI.UpdateLocationView:LocationNull", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg);
                return;
            }

            if (characterPreviewFrame != null)
            {
                characterPreviewFrame.Parent?.RemoveChild(characterPreviewFrame);
                characterPreviewFrame = null;
            }

            if (characterList != null)
            {
                if (Campaign is SinglePlayerCampaign)
                {
                    var hireableCharacters = location.GetHireableCharacters();
                    foreach (GUIComponent child in characterList.Content.Children.ToList())
                    {
                        if (child.UserData is CharacterInfo character)
                        {
                            if (GameMain.GameSession.CrewManager != null)
                            {
                                if (GameMain.GameSession.CrewManager.GetCharacterInfos().Contains(character))
                                {
                                    continue;
                                }
                            }
                        }
                        else if (child.UserData as string == "mycrew" || child.UserData as string == "hire")
                        {
                            continue;
                        }
                        characterList.RemoveChild(child);
                    }
                    if (!hireableCharacters.Any())
                    {
                        new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), characterList.Content.RectTransform), TextManager.Get("HireUnavailable"), textAlignment: Alignment.Center)
                        {
                            CanBeFocused = false
                        };
                    }
                    else
                    {
                        foreach (CharacterInfo c in hireableCharacters)
                        {
                            var frame = c.CreateCharacterFrame(characterList.Content, c.Name + " (" + c.Job.Name + ")", c);
                            new GUITextBlock(new RectTransform(Vector2.One, frame.RectTransform, Anchor.TopRight), c.Salary.ToString(), textAlignment: Alignment.CenterRight);
                        }
                    }
                }
                characterList.UpdateScrollBarSize();
            }

            RefreshMyItems();

            bool purchaseableItemsFound = false;

            foreach (MapEntityPrefab mapEntityPrefab in MapEntityPrefab.List)
            {
                if (!(mapEntityPrefab is ItemPrefab itemPrefab))
                {
                    continue;
                }

                PriceInfo priceInfo = itemPrefab.GetPrice(Campaign.Map.CurrentLocation);
                if (priceInfo != null)
                {
                    purchaseableItemsFound = true; break;
                }
            }

            //disable store tab if there's nothing to buy
            tabButtons.Find(btn => (Tab)btn.UserData == Tab.Store).Enabled = purchaseableItemsFound;

            if (selectedTab == Tab.Store && !purchaseableItemsFound)
            {
                //switch out from store tab if there's nothing to buy
                SelectTab(Tab.Map);
            }
            else
            {
                //refresh store view
                FillStoreItemList();

                MapEntityCategory?category = null;
                //only select a specific category if the search box is empty
                //(items from all categories are shown when searching)
                if (string.IsNullOrEmpty(searchBox.Text))
                {
                    category = selectedItemCategory;
                }
                FilterStoreItems(category, searchBox.Text);
            }
        }
Example #4
0
        public void ServerReadCrew(IReadMessage msg, Client sender)
        {
            int[] pendingHires = null;

            bool updatePending = msg.ReadBoolean();

            if (updatePending)
            {
                ushort pendingHireLength = msg.ReadUInt16();
                pendingHires = new int[pendingHireLength];
                for (int i = 0; i < pendingHireLength; i++)
                {
                    pendingHires[i] = msg.ReadInt32();
                }
            }

            bool validateHires = msg.ReadBoolean();
            bool fireCharacter = msg.ReadBoolean();

            int firedIdentifier = -1;

            if (fireCharacter)
            {
                firedIdentifier = msg.ReadInt32();
            }

            Location location = map?.CurrentLocation;

            CharacterInfo firedCharacter = null;

            if (location != null && AllowedToManageCampaign(sender))
            {
                if (fireCharacter)
                {
                    firedCharacter = CrewManager.CharacterInfos.FirstOrDefault(info => info.GetIdentifier() == firedIdentifier);
                    if (firedCharacter != null && (firedCharacter.Character?.IsBot ?? true))
                    {
                        CrewManager.FireCharacter(firedCharacter);
                    }
                    else
                    {
                        DebugConsole.ThrowError($"Tried to fire an invalid character ({firedIdentifier})");
                    }
                }

                if (location.HireManager != null)
                {
                    if (validateHires)
                    {
                        foreach (CharacterInfo hireInfo in location.HireManager.PendingHires)
                        {
                            TryHireCharacter(location, hireInfo);
                        }
                    }

                    if (updatePending)
                    {
                        List <CharacterInfo> pendingHireInfos = new List <CharacterInfo>();
                        foreach (int identifier in pendingHires)
                        {
                            CharacterInfo match = location.GetHireableCharacters().FirstOrDefault(info => info.GetIdentifier() == identifier);
                            if (match == null)
                            {
                                DebugConsole.ThrowError($"Tried to hire a character that doesn't exist ({identifier})");
                                continue;
                            }

                            pendingHireInfos.Add(match);
                        }
                        location.HireManager.PendingHires = pendingHireInfos;
                    }
                }
            }

            // bounce back
            SendCrewState(validateHires, firedCharacter);
        }