Exemplo n.º 1
0
 public override void OnLevelUnloading()
 {
     ServiceBuildingOptions.GetInstance().Clear();
     DistrictSelectionPanel.Uninstall();
     harmonyInstance.UnpatchAll(harmonyId);
     harmonyInstance = null;
 }
Exemplo n.º 2
0
        public override void OnSaveData()
        {
            base.OnSaveData();
#if RELEASE
            try {
#endif
            ServiceBuildingData[] dataArray = ServiceBuildingOptions.GetInstance().ToArray();
            if (dataArray == null || dataArray.Length == 0)
            {
                return;
            }

            byte[] bytes;
            using (var stream = new MemoryStream())
            {
                DataSerializer.SerializeArray(stream,
                                              DataSerializer.Mode.Memory,
                                              VERSION,
                                              dataArray);
                bytes = stream.ToArray();
            }

            serializableDataManager.SaveData(KEY, bytes);
            Utils.LogGeneral($"DSL data saved (Size in bytes: {bytes.Length})");
#if RELEASE
        }

        catch (Exception ignored) { }
#endif
        }
Exemplo n.º 3
0
        public override void OnLoadData()
        {
            base.OnLoadData();
#if RELEASE
            try {
#endif
            ServiceBuildingOptions.GetInstance().Clear();
            byte[] bytes = serializableDataManager.LoadData(KEY);
            if (bytes == null)
            {
                return;
            }

            ServiceBuildingData[] dataArray;
            using (var stream = new MemoryStream(bytes))
            {
                dataArray = DataSerializer.DeserializeArray <ServiceBuildingData>(stream, DataSerializer.Mode.Memory);
                foreach (ServiceBuildingData data in dataArray)
                {
                    ServiceBuildingOptions.GetInstance().SetData(data.buildingID, data);
                }
            }

            Utils.LogGeneral($"DSL data loaded (Size in bytes: {bytes.Length})");
#if RELEASE
        }

        catch (Exception ignored) { }
#endif
        }
Exemplo n.º 4
0
        public void Display(object data, bool isRowOdd)
        {
            ignoreEvents = true;

            if (isRowOdd)
            {
                background.backgroundSprite = null;
            }
            else
            {
                background.backgroundSprite = "UnlockingItemBackground";
                background.color            = new Color32(0, 0, 0, 50);
            }

            object[] info = (object[])data;
            districtID   = (byte)info[0];
            districtName = (string)info[1];
            buildingID   = DistrictSelectionPanel.Panel.lastBuildingID;

            checkbox.isChecked = districtName.Equals(DistrictSelectionPanel.ALL_DISTRICTS) ?
                                 ServiceBuildingOptions.GetInstance().AreAllDistrictsServed(buildingID) :
                                 ServiceBuildingOptions.GetInstance().IsAdditionalTarget(buildingID, districtID);
            checkbox.text = districtName;

            ignoreEvents = false;
        }
Exemplo n.º 5
0
        private void OnCheckChanged(UIComponent component, bool value)
        {
            if (ignoreEvents)
            {
                return;
            }

            if (districtName.Equals(DistrictSelectionPanel.ALL_DISTRICTS))
            {
                ServiceBuildingOptions.GetInstance().SetAllDistrictsServed(buildingID, value);
            }
            else
            {
                ServiceBuildingOptions.GetInstance().SetAdditionalTarget(buildingID, districtID, value);
            }
        }
Exemplo n.º 6
0
        private void Show(ushort selectedBuildingID)
        {
            if (!ServiceBuildingOptions.GetInstance().IsSupported(selectedBuildingID))
            {
                Hide();
                Utils.LogGeneral($"[DistrictSelectionPanel] Won't show panel: building {selectedBuildingID} not supported");
                return;
            }

            RefreshData(selectedBuildingID);

            if (fastList.rowsData.m_size == 0)
            {
                Hide();
                Utils.LogGeneral($"[DistrictSelectionPanel] Won't show panel: no data to display for building {selectedBuildingID}");
                return;
            }

            Show();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Eventual handler of all service requests
        /// </summary>
        private static bool IsTransferAllowed(Vector3 source, Vector3 destination, ushort buildingID, ushort destBuildingID, TransferManager.TransferReason reason, bool isResidentTransfer)
        {
            ServiceBuildingOptions opts            = ServiceBuildingOptions.GetInstance();
            DistrictManager        districtManager = Singleton <DistrictManager> .instance;
            byte srcDistrict = districtManager.GetDistrict(source);
            byte dstDistrict = districtManager.GetDistrict(destination);

            if (srcDistrict != 0 && !IsActive(srcDistrict))
            {
                Utils.LogGeneral($"IsTransferAllowed: srcDistrict {srcDistrict} not active, setting to zero!");
                srcDistrict = 0;
            }

            if (dstDistrict != 0 && !IsActive(dstDistrict))
            {
                Utils.LogGeneral($"IsTransferAllowed: dstDistrict {dstDistrict} not active, setting to zero!");
                dstDistrict = 0;
            }

            // check whether this transfer represents a resident going out to do something
            if (isResidentTransfer)
            {
                switch (reason)
                {
                // resident going to a hospital or clinic
                case TransferManager.TransferReason.Sick:
                case TransferManager.TransferReason.Sick2:
                    return(Settings.RestrictCitizenHealthAccess ?
                           (dstDistrict == 0 || srcDistrict == dstDistrict || opts.IsTargetCovered(destBuildingID, srcDistrict)) : true);

                // resident going to an educational building
                case TransferManager.TransferReason.Student1:
                case TransferManager.TransferReason.Student2:
                case TransferManager.TransferReason.Student3:
                    return(Settings.RestrictCitizenEducationalAccess ?
                           (dstDistrict == 0 || srcDistrict == dstDistrict || opts.IsTargetCovered(destBuildingID, srcDistrict)) : true);

                // resident going to a park
                case TransferManager.TransferReason.Entertainment:
                case TransferManager.TransferReason.EntertainmentB:
                case TransferManager.TransferReason.EntertainmentC:
                case TransferManager.TransferReason.EntertainmentD:
                    return(Settings.RestrictCitizenParkAccess ?
                           (dstDistrict == 0 || srcDistrict == dstDistrict || opts.IsTargetCovered(destBuildingID, srcDistrict)) : true);

                // resident going to a shop
                case TransferManager.TransferReason.Shopping:
                case TransferManager.TransferReason.ShoppingB:
                case TransferManager.TransferReason.ShoppingC:
                case TransferManager.TransferReason.ShoppingD:
                case TransferManager.TransferReason.ShoppingE:
                case TransferManager.TransferReason.ShoppingF:
                case TransferManager.TransferReason.ShoppingG:
                case TransferManager.TransferReason.ShoppingH:
                    return(Settings.RestrictCitizenShoppingAccess ?
                           (dstDistrict == 0 || srcDistrict == dstDistrict || opts.IsTargetCovered(destBuildingID, srcDistrict)) : true);

                // resident going to work
                case TransferManager.TransferReason.Worker0:
                case TransferManager.TransferReason.Worker1:
                case TransferManager.TransferReason.Worker2:
                case TransferManager.TransferReason.Worker3:
                    return(Settings.RestrictCitizenWorkAccess ?
                           (dstDistrict == 0 || srcDistrict == dstDistrict || opts.IsTargetCovered(destBuildingID, srcDistrict)) : true);

                default:
                    return(true);
                }
            }
            else
            {
                switch (reason)
                {
                // vehicle fetching something
                case TransferManager.TransferReason.Garbage:
                case TransferManager.TransferReason.Crime:
                case TransferManager.TransferReason.Sick:
                case TransferManager.TransferReason.Sick2:
                case TransferManager.TransferReason.Dead:
                case TransferManager.TransferReason.Fire:
                case TransferManager.TransferReason.Fire2:
                case TransferManager.TransferReason.Taxi:
                case TransferManager.TransferReason.Snow:
                case TransferManager.TransferReason.RoadMaintenance:
                    return(!Settings.RestrictServiceDispatching ? true :
                           (srcDistrict == 0 ||
                            srcDistrict == dstDistrict ||
                            opts.IsTargetCovered(buildingID, dstDistrict)));

                // vehicle freeing building capacity
                case TransferManager.TransferReason.DeadMove:
                case TransferManager.TransferReason.GarbageMove:
                case TransferManager.TransferReason.SnowMove:
                    return(!Settings.RestrictMaterialTransfer ? true :
                           (dstDistrict == 0 ||
                            srcDistrict == dstDistrict ||
                            opts.IsTargetCovered(destBuildingID, srcDistrict)));        //inverted logic: destination must cover source of move!

                // ignore prisons
                case TransferManager.TransferReason.CriminalMove:
                    return(true);

                default:
                    return(true);
                }
            }
        }
Exemplo n.º 8
0
 public override void OnBuildingReleased(ushort buildingID)
 {
     ServiceBuildingOptions.GetInstance().OnBuildingRemoved(buildingID);
 }