Exemplo n.º 1
0
        public void ImpactStat(CityStatImpact cityStatImpact)
        {
            var impactedStat = Stats.FirstOrDefault(s => s.Name == cityStatImpact.ParameterName);

            if (impactedStat != null && impactedStat.StatType != CityStatType.SumOfBuildings)
            {
                impactedStat.Value += cityStatImpact.WeeklyImpact;
            }
        }
Exemplo n.º 2
0
        // TODO priority:lower the efficiency of this can be largely improved
        public void EndOfWeek()
        {
            foreach (var cityBuilding in Buildings)
            {
                var building          = cityBuilding;
                var buildingPrototype =
                    PrototypeManager.Instance.Buildings.FirstOrDefault(b => b.Name == building.BuildingName);

                foreach (var cityStatImpact in buildingPrototype.CityStatImpacts)
                {
                    ImpactStat(cityStatImpact);
                }
            }

            foreach (var cityStat in Stats)
            {
                if (cityStat.StatType == CityStatType.SumOfBuildings)
                {
                    // TODO priority:high refactor this as use of First is unsafe, adding a reference to the CityBuilding to a Building prototype upon creation will help a lot
                    // TODO priority:bug this doesn't seems to work
                    CityStat stat = cityStat;
                    cityStat.Value =
                        Buildings.SelectMany(
                            bd =>
                            PrototypeManager.Instance.Buildings.First(b => b.Name == bd.BuildingName)
                            .CityStatImpacts)
                        .Where(s => s.ParameterName == stat.Name)
                        .Sum(i => i.WeeklyImpact);
                }
            }

            var cashImpact = new CityStatImpact {
                ParameterName = "Cash"
            };

            foreach (var activeTrade in ActiveTrades)
            {
                cashImpact.WeeklyImpact = activeTrade.WeeklyProfit;
                ImpactStat(cashImpact);
            }

            Date.Week++;
        }
Exemplo n.º 3
0
        public void Build(Building building, Vector2 worldMousePosition)
        {
            var cityBuilding = new CityBuilding
            {
                BuildingName = building.Name,
                Id           = Buildings.Max(b => b.Id) + 1,
                X            = worldMousePosition.x,
                Y            = worldMousePosition.y,
            };

            Buildings.Add(cityBuilding);

            var cashImpact = new CityStatImpact {
                ParameterName = "Cash"
            };

            ImpactStat(cashImpact);
            BuildingDisplayController.Instance.Refresh();
        }