Exemplo n.º 1
0
        private void UpdateBindings()
        {
            bool         flag1         = false;
            ushort       extractorID   = GetFishExtractorID();
            ushort       fishFarmID    = BuildingExtension.GetFishFarm(extractorID);
            BuildingInfo extractorInfo = BuildingManager.instance.m_buildings.m_buffer[extractorID].Info;
            BuildingInfo fishFarmInfo  = BuildingManager.instance.m_buildings.m_buffer[fishFarmID].Info;

            ItemClass.Service service = fishFarmInfo.GetService();
            BuildingExtension.FishItemClass fishfarm = new BuildingExtension.FishItemClass(service);
            if (!FishFarmUtil.IsValidFishFarm(fishFarmID))
            {
                flag1 = true;
            }
            if (flag1 || _updateFishFarms[fishfarm])
            {
                PopulateFishFarmDropDown(extractorInfo, fishFarmInfo);
                _updateFishFarms[fishfarm] = false;
            }
            if (_fishFarmDropDown.Items.Length == 0)
            {
                _fishFarmDropDown.Text = "No fish farm found.";
            }
            else
            {
                _fishFarmDropDown.SelectedItem = fishFarmID;
            }
            Vector3[] extractor_pos_arr = new Vector3[BuildingExtension._extractorData.Length];
            BuildingExtension._extractorData.ForEach <BuildingExtension.ExtractorData>(item => {
                extractor_pos_arr = extractor_pos_arr.Concat <Vector3>(new Vector3[] { item.Position }).ToArray();
            });
            m_extractionPositions = extractor_pos_arr;
        }
        public static ushort[] GetFishFarms(BuildingInfo extractorInfo, BuildingInfo fishFarmInfo)
        {
            if (fishFarmInfo == null)
            {
                return(new ushort[0]);
            }
            var FarmNames      = fishFarmInfo.name.Split('_');
            var FarmType       = FarmNames[0];
            var ExtractorNames = extractorInfo.name.Split('_');
            var ExtractorType  = ExtractorNames[0];

            return(_fishFarmMap.TryGetValue(new FishItemClass(fishFarmInfo.GetService()), out HashSet <ushort> source)
                ? source.Where(d => FishFarmUtil.IsValidFishFarm(d)).Where(d => FarmType == ExtractorType).ToArray()
                : new ushort [0]);
        }
        private static void ObserveForInfo(ushort buildingId, BuildingInfo fishFarmInfo)
        {
            if (fishFarmInfo == null || !FishFarmUtil.IsValidFishFarm(buildingId))
            {
                return;
            }
            var fishItemClass = new FishItemClass(fishFarmInfo.GetService());

            if (!_fishFarmMap.TryGetValue(fishItemClass, out HashSet <ushort> fishFarms))
            {
                fishFarms = new HashSet <ushort>();
                _fishFarmMap.Add(fishItemClass, fishFarms);
            }
            if (fishFarms.Contains(buildingId))
            {
                return;
            }
            fishFarms.Add(buildingId);
            OnFishFarmAdded?.Invoke(fishItemClass.Service);
        }