public bool ApplyUserEvent()
        {
            bool success = true;

            _incentive = new CityEventXmlIncentive()
            {
                _name                  = _name.Text,
                _description           = _description.Text,
                _activeWhenRandomEvent = _activeWhenRandomEvent.IsChecked.HasValue ? _activeWhenRandomEvent.IsChecked.Value : false
            };

            success = success && SafelyConvert.SafelyParseWithError(_costBuy.Text, ref _incentive._cost, "cost to buy");
            success = success && SafelyConvert.SafelyParseWithError(_costSell.Text, ref _incentive._returnCost, "cost to sell");
            success = success && SafelyConvert.SafelyParseWithError(_positiveEffect.Text, ref _incentive._positiveEffect, "percentage increase");
            success = success && SafelyConvert.SafelyParseWithError(_negativeEffect.Text, ref _incentive._negativeEffect, "percentage decrease");

            return(success);
        }
Example #2
0
        public bool ApplyXmlEvent()
        {
            bool success = true;

            _container = new CityEventXmlContainer()
            {
                _name                   = _eventName.Text,
                _userEventName          = _readableName.Text,
                _eventBuildingClassName = _buildingName.Text,

                _supportsRandomEvents = _randomEvents.IsChecked.HasValue ? _randomEvents.IsChecked.Value : false,
                _supportUserEvents    = _playerEvents.IsChecked.HasValue ? _playerEvents.IsChecked.Value : false,
                _canBeWatchedOnTV     = _watchedOnTv.IsChecked.HasValue ? _watchedOnTv.IsChecked.Value : false,
                _initialisedMessages  = TearDownText(_initialisedMessages),
                _beginMessages        = TearDownText(_startedMessages),
                _endedMessages        = TearDownText(_endedMessages),

                _chances = new CityEventXmlChances()
                {
                    _children = (int)(Math.Round(_children.Value)),
                    _teens    = (int)(Math.Round(_teens.Value)),
                    _adults   = (int)(Math.Round(_adults.Value)),
                    _seniors  = (int)(Math.Round(_seniors.Value)),

                    _lowWealth    = (int)(Math.Round(_lowWealth.Value)),
                    _mediumWealth = (int)(Math.Round(_mediumWealth.Value)),
                    _highWealth   = (int)(Math.Round(_highWealth.Value)),

                    _uneducated   = (int)(Math.Round(_uneducated.Value)),
                    _oneSchool    = (int)(Math.Round(_oneSchool.Value)),
                    _twoSchools   = (int)(Math.Round(_twoSchools.Value)),
                    _threeSchools = (int)(Math.Round(_threeSchools.Value)),

                    _badHappiness       = (int)(Math.Round(_badHappiness.Value)),
                    _poorHappiness      = (int)(Math.Round(_poorHappiness.Value)),
                    _goodHappiness      = (int)(Math.Round(_goodHappiness.Value)),
                    _excellentHappiness = (int)(Math.Round(_excellentHappiness.Value)),
                    _superbHappiness    = (int)(Math.Round(_superbHappiness.Value)),

                    _veryUnhappyWellbeing = (int)(Math.Round(_veryUnhappy.Value)),
                    _unhappyWellbeing     = (int)(Math.Round(_unhappy.Value)),
                    _satisfiedWellbeing   = (int)(Math.Round(_satisfied.Value)),
                    _happyWellbeing       = (int)(Math.Round(_happy.Value)),
                    _veryHappyWellbeing   = (int)(Math.Round(_veryHappy.Value)),
                },

                _costs = new CityEventXmlCosts()
                {
                },

                _incentives = new CityEventXmlIncentive[]
                {
                }
            };

            success = success && SafelyConvert.SafelyParseWithError(_capacity.Text, ref _container._eventCapacity, "capacity");
            success = success && SafelyConvert.SafelyParseWithError(_length.Text, ref _container._eventLength, "event length");

            success = success && SafelyConvert.SafelyParseWithError(_creationCost.Text, ref _container._costs._creation, "creation cost");
            success = success && SafelyConvert.SafelyParseWithError(_perHeadCost.Text, ref _container._costs._perHead, "cost per citizen");
            success = success && SafelyConvert.SafelyParseWithError(_advertSignCost.Text, ref _container._costs._advertisingSigns, "advertising sign cost");
            success = success && SafelyConvert.SafelyParseWithError(_advertTVCost.Text, ref _container._costs._advertisingTV, "advertising TV cost");
            success = success && SafelyConvert.SafelyParseWithError(_entryCost.Text, ref _container._costs._entry, "ticket cost");

            List <CityEventXmlIncentive> incentiveList = new List <CityEventXmlIncentive>();

            foreach (TabItem tab in _incentiveTabs.Items)
            {
                IncentiveEditorPanel editor = tab.Content as IncentiveEditorPanel;

                if (editor != null)
                {
                    success = success && editor.ApplyUserEvent();

                    if (success)
                    {
                        incentiveList.Add(editor._incentive);
                    }
                }
            }

            _container._incentives = incentiveList.ToArray();

            return(success);
        }