예제 #1
0
        private static void CreateEventButton_eventClicked(UIComponent component, UIMouseEventParameter eventParam)
        {
            UIFastList eventSelection = component.parent.Find <UIFastList>("EventSelectionList");
            ushort     buildingID     = lastInstanceID.Value.Building;

            if (lastInstanceID != null && buildingID != 0)
            {
                BuildingManager _buildingManager = Singleton <BuildingManager> .instance;
                Building        _currentBuilding = _buildingManager.m_buildings.m_buffer[buildingID];

                if ((_currentBuilding.m_flags & Building.Flags.Active) != Building.Flags.None)
                {
                    List <CityEvent> userEvents = CityEventBuildings.instance.GetUserEventsForBuilding(ref _currentBuilding);

                    BuildDropdownList(component);

                    if (eventSelection.isVisible)
                    {
                        eventSelection.Hide();
                    }
                    else
                    {
                        eventSelection.selectedIndex = -1;
                        eventSelection.Show();
                        eventSelection.rowsData.Clear();

                        foreach (CityEvent userEvent in userEvents)
                        {
                            XmlEvent xmlUserEvent = userEvent as XmlEvent;

                            if (xmlUserEvent != null)
                            {
                                xmlUserEvent.SetUp(ref buildingID);
                                LabelOptionItem eventToInsert = new LabelOptionItem()
                                {
                                    linkedEvent = xmlUserEvent, readableLabel = xmlUserEvent.GetReadableName()
                                };
                                eventSelection.rowsData.Add(eventToInsert);

                                LoggingWrapper.Log(xmlUserEvent.GetReadableName());
                            }
                        }

                        eventSelection.DisplayAt(0);
                    }
                }
            }
        }
예제 #2
0
        public void CreateEvents()
        {
            SimulationManager _simulationManager = Singleton <SimulationManager> .instance;
            BuildingManager   _buildingManager   = Singleton <BuildingManager> .instance;

            PrintMonuments();

            if (m_forcedEvent != null)
            {
                m_nextEvents.Clear();
            }

            FastList <ushort> allBuildings = CityEventBuildings.instance.GetPotentialEventBuildings();

            if (allBuildings.m_size > 0)
            {
                if (m_forcedEvent != null)
                {
                    for (int index = 0; index < allBuildings.m_size; ++index)
                    {
                        ushort   buildingId = allBuildings[index];
                        Building monument   = _buildingManager.m_buildings.m_buffer[buildingId];

                        if (monument.Info.name == m_forcedEvent._eventBuildingClassName)
                        {
                            CityEvent xmlEvent = new XmlEvent(m_forcedEvent);
                            xmlEvent.SetUp(ref buildingId);
                            xmlEvent.m_eventData.m_eventStartTime  = CITY_TIME.AddHours(4d);
                            xmlEvent.m_eventData.m_eventFinishTime = xmlEvent.m_eventData.m_eventStartTime.AddHours(xmlEvent.GetEventLength());

                            AddEvent(xmlEvent);

                            LoggingWrapper.Log("Forced event created at " + monument.Info.name + " for " + xmlEvent.m_eventData.m_eventStartTime.ToShortTimeString() + ". Current date: " + CITY_TIME.ToShortTimeString());
                        }
                        else
                        {
                            LoggingWrapper.Log(monument.Info.name + " != " + m_forcedEvent._eventBuildingClassName);
                        }
                    }
                }
                else
                {
                    for (int count = 0; count < 10; ++count)
                    {
                        ushort randomMonumentId = allBuildings.m_buffer[_simulationManager.m_randomizer.UInt32((uint)allBuildings.m_size)];

                        if (randomMonumentId < _buildingManager.m_buildings.m_size)
                        {
                            Building  monument   = _buildingManager.m_buildings.m_buffer[randomMonumentId];
                            CityEvent foundEvent = CityEventBuildings.instance.GetEventForBuilding(ref monument);

                            if (foundEvent != null && (monument.m_flags & Building.Flags.Active) != Building.Flags.None)
                            {
                                foundEvent.SetUp(ref randomMonumentId);
                                AddEvent(foundEvent);
                                break;
                            }
                            else
                            {
                                Debug.Log("No event scheduled just yet. Checking again soon.");
                            }
                        }
                    }
                }
            }

            m_forcedEvent = null;

            if (!ExperimentsToggle.ForceEventToHappen)
            {
                m_nextEventCheck = CITY_TIME.AddHours(3);
            }
        }