Exemplo n.º 1
0
        public Grass1(TeamType team, string region, Vector2 location, ContentManager content, GraphicsDevice graphics) : base(team, content, graphics)
        {
            nHitsToDestory = 2;
            msRespawn      = GameOptions.GameDayLengthMs / 2;
            string objKey = "grass1";

            List <Tuple <string, int> > itemDrops = RandomEvents.RandomNPDrops(objKey, 2);

            drops = ItemUtility.CreateNPInventory(itemDrops, team, region, location, content, graphics);

            Texture2D textureGrass1   = content.Load <Texture2D>("RevisedGrass1");
            Texture2D textureGrass1BB = null;

            if (Gusto.GameOptions.ShowBoundingBox)
            {
                textureGrass1BB = new Texture2D(graphics, textureGrass1.Width, textureGrass1.Height);
            }
            Asset Grass1Asset = new Asset(textureGrass1, textureGrass1BB, 2, 1, 0.6f, objKey, region);

            SetSpriteAsset(Grass1Asset, location);
        }
Exemplo n.º 2
0
    IEnumerator PlayRoundCoroutine()
    {
        GameState state = GameManager.instance.state;

        yield return(new WaitForSeconds(.5f));

        m_feedControl.Pay();
        UpdateFoodCount();
        UpdateHappinessCount();

        Alert("Feeding the empire...");
        yield return(new WaitForSeconds(ALERT_TIME));

        m_investControl.Pay();
        UpdateMoneyCount();
        UpdateHappinessCount();

        Alert("Managing investments...");
        yield return(new WaitForSeconds(ALERT_TIME));

        int taxes = m_MapManager.CollectTaxes();

        state.m_Money += taxes;
        UpdateMoneyCount();

        Alert("Collecting taxes...");
        yield return(new WaitForSeconds(ALERT_TIME));

        int harvest = m_MapManager.HarvestFarms();

        if (harvest > 0)
        {
            state.m_Food += harvest;
            UpdateFoodCount();

            Alert("Harvesting farms...");
            yield return(new WaitForSeconds(ALERT_TIME));
        }

        int mined = m_MapManager.Mine();

        if (mined > 0)
        {
            state.m_Money += mined;
            UpdateMoneyCount();

            Alert("Carving jade...");
            yield return(new WaitForSeconds(ALERT_TIME));
        }

        yield return(StartCoroutine(TileController.ExpandTiles()));

        if (state.enemyFactions.Count > 0)
        {
            foreach (Faction faction in state.enemyFactions)
            {
                int count = Random.Range(1, 3);
                for (int i = 0; i < count; i++)
                {
                    if (faction != Faction.None)
                    {
                        faction.AddSoldier();
                    }
                }
            }
            Alert("The enemies have expanded their forces!");
            yield return(new WaitForSeconds(ALERT_TIME));

            foreach (Faction faction in state.enemyFactions)
            {
                bool expand = Random.value < Constants.CHANCE_TO_EXPAND;
                if (expand)
                {
                    // -1 = unable to siege, 0 = basic expansion, 1 = successful siege to player, 2 = successful siege to nonplayer, 3 = failed siege
                    int result = faction.MaybeSiege();
                    switch (result)
                    {
                    case 0:
                        Alert("The enemy has expanded their territory!", SIEGE_ALERT_TIME);
                        break;

                    case 1:
                        Alert("The enemy has taken some of your land!", SIEGE_ALERT_TIME);
                        state.m_Happiness += Constants.FAILED_INVADE_HAPPINESS;
                        state.m_Happiness  = Mathf.Min(state.m_Happiness, 100);
                        UpdateHappinessCount();
                        break;

                    case 2:
                        Alert("The enemies fought each other!", SIEGE_ALERT_TIME);
                        break;

                    case 3:
                        Alert("The enemies failed to expand their land...", SIEGE_ALERT_TIME);
                        break;
                    }
                    if (result != -1)
                    {
                        yield return(new WaitForSeconds(SIEGE_ALERT_TIME));
                    }
                }
            }
        }

        //Random Events
        if (Random.value < Constants.CHANCE_RANDOM_EVENT)
        {
            RandomEvents.RandomEvent randomEvent = RandomEvents.GetEvent();
            yield return(StartCoroutine(EventPopup(randomEvent.message)));

            randomEvent.eventFunc();
            Alert(randomEvent.alert);
            yield return(new WaitForSeconds(ALERT_TIME));
        }

        if (Faction.GetPlayer().TerritoryCount() == 0)
        {
            GameManager.instance.LoadLose();
        }
        else if (GameManager.instance.state.m_Happiness <= 0)
        {
            StartRebellion();
        }
        else if (GameManager.instance.state.m_Happiness == 100)
        {
            GameManager.instance.LoadWin();
        }

        NextRound();
    }
Exemplo n.º 3
0
 private bool willKillHost()
 {
     return(RandomEvents.virusWillKillHostByAgeAndHealthIdx(
                this.host.age, this.host.healthIndex));
 }
Exemplo n.º 4
0
 private void defineWhenImmunityWillSettle()
 {
     this.whenImmunityWillSettleInSecs = God.secondsSinceEpoch +
                                         RandomEvents.howManySecsSpreadingWillLastByAgeAndHealthIdx(
         this.host.age, this.host.healthIndex);
 }
Exemplo n.º 5
0
        public BaseShip(TeamType team, string region, Vector2 location, ContentManager content, GraphicsDevice graphics) : base(team, content, graphics)
        {
            timeSinceLastTurn     = 0;
            millisecondsPerTurn   = 500; // turn speed
            timeSinceStartAnchor  = 0;
            millisecondsToAnchor  = 1000;
            msToRepair            = 5000;
            millisecondsNewShot   = 2000;
            movementSpeed         = 0.2f;
            timeSinceStartSinking = 0;
            millisecondToSink     = 10000;
            nSails            = 1;
            fullHealth        = 40;
            health            = fullHealth;
            stopRange         = 260f;
            maxInventorySlots = 5;

            string objKey = "baseShip";

            //MapModelMovementVectorValues();
            Texture2D textureBaseShip   = content.Load <Texture2D>("BaseShip");
            Texture2D textureBaseShipBB = null;

            if (Gusto.GameOptions.ShowBoundingBox)
            {
                textureBaseShipBB = new Texture2D(graphics, textureBaseShip.Width, textureBaseShip.Height);
            }
            Asset baseShipAsset = new Asset(textureBaseShip, textureBaseShipBB, 1, 8, 0.6f, objKey, region);

            // inventory
            List <Sprite> interiorObjs = null;

            if (team != TeamType.Player)
            {
                List <Tuple <string, int> > itemDrops = RandomEvents.RandomNPDrops(objKey, 5);
                interiorObjs  = ItemUtility.CreateInteriorItems(itemDrops, team, region, location, content, graphics);
                mountedOnShip = new BaseCannon(teamType, regionKey, GetBoundingBox().Center.ToVector2(), content, graphics);
            }

            actionInventory = Enumerable.Repeat <InventoryItem>(null, maxInventorySlots).ToList();

            // TEMPORARY -- hardcode basesail to baseship (later on we want base ship to start without a sail)
            shipSail = new BaseSail(team, region, location, content, graphics);
            shipSail.millisecondsPerFrame = 500; // match turn speed for sail

            shipInterior = new Interior("baseShip", this, content, graphics);

            // set the random drops as interior objects
            if (interiorObjs != null)
            {
                foreach (var obj in interiorObjs)
                {
                    shipInterior.interiorObjects.Add(obj);

                    // need to do this for containers so they drop items within ship
                    if (obj is IContainer)
                    {
                        Container c = (Container)obj;
                        c.inInteriorId = shipInterior.interiorId;
                    }
                }
            }

            // set wake
            wake.MaxParticle      = 5;
            wake.WakeDisplacement = 13;

            SetSpriteAsset(baseShipAsset, location);
        }
Exemplo n.º 6
0
 // Start is called before the first frame update
 void Start()
 {
     randomEventsList = new RandomEvents();
     events           = randomEventsList.Events;
 }
Exemplo n.º 7
0
    void Start()
    {
        //Erdem's manager assignment
        myBlinkScript = myManager.GetComponent<blinkScript>();

        //Cursor.visible = false;

        SunCenter = GameObject.Find("Center");
        Sun = GameObject.Find("Sun");

        myCombatClass = GameObject.Find("GameManager").GetComponent<Combat>();

        resource = GameObject.Find("GameManager").GetComponent<Resource>();
        randomEvents = GameObject.Find("GameManager").GetComponent<RandomEvents>();

        BlinkScript = GameObject.Find("GameManager").GetComponent<blinkScript>();

        HelpUILeft = GameObject.Find("HelpUILeft").GetComponent<Text>();
        HelpUIRight = GameObject.Find("HelpUIRight").GetComponent<Text>();

        Tips = GameObject.Find("Tips");

        MainCamera = GameObject.Find("Main Camera");
        UnfocusPos = MainCamera.transform.position;
        UnfocusRot = MainCamera.transform.rotation;
        FocusPos = GameObject.Find("FocusPoint").transform.position;
        FocusRot = GameObject.Find("FocusPoint").transform.rotation;
        currentUI = UIChoice.MainMenu;
        MainMenu = GameObject.Find("MainMenu");
        MenuPosition = GameObject.Find("MenuPlaceHolder").transform.position;
        MenuRotation = GameObject.Find("MenuPlaceHolder").transform.rotation;

        MulitaryUI = GameObject.Find("MulitaryUI");
        MulitaryPos = MulitaryUI.transform.position;
        MulitaryRot = MulitaryUI.transform.rotation;

        StockUI = GameObject.Find("StockUI");
        StockPos = StockUI.transform.position;
            StockRot = StockUI.transform.rotation;

            AssignUI = GameObject.Find("AssignUI");
            AssignPos = AssignUI.transform.position;
            AssignRot = AssignUI.transform.rotation;

            TurnReport = GameObject.Find("TurnReport");
            ReportPosition = TurnReport.transform.position;
            ReportRotation = TurnReport.transform.rotation;
            FocusLocationPos = GameObject.Find("FocusLocation").transform.position;
            FocusLocationRot = GameObject.Find("FocusLocation").transform.rotation;
            CurrentUI = MainMenu;
            LeftPage = GameObject.Find("MainMenuLeftPage");
            RightPage = GameObject.Find("MainMenuRightPage");

            SoldierNum = resource.popSoldier;
            //MulitaryStatusChoice(0);
    }
        //saves a game
        public static void SaveGame(string name)
        {
            //Pause the game so we can save without the clock running :)
            GameObjectWorker.GetInstance().pause();

            string fileName = AppSettings.getCommonApplicationDataPath() + "\\saves\\" + name + ".sav";

            Stopwatch sw = new Stopwatch();

            sw.Start();

            SaveObject so = new SaveObject();

            Parallel.Invoke(() =>
            {
                so.airportsList = new List <Airport>();
                so.airportsList.AddRange(Airports.GetAllAirports());
            }, () =>
            {
                so.airlinesList = new List <Airline>();
                so.airlinesList.AddRange(Airlines.GetAllAirlines());
            }, () =>
            {
                so.airlinersList = new List <Airliner>();
                so.airlinersList.AddRange(Airliners.GetAllAirliners());
            }, () =>
            {
                so.calendaritemsList = new List <CalendarItem>();
                so.calendaritemsList.AddRange(CalendarItems.GetCalendarItems());
            }, () =>
            {
                so.configurationList = new List <Configuration>();
                so.configurationList.AddRange(Configurations.GetConfigurations());
            }, () =>
            {
                so.eventsList = new List <RandomEvent>();
                so.eventsList.AddRange(RandomEvents.GetEvents());
            }, () =>
            {
                so.allianceList = new List <Alliance>();
                so.allianceList.AddRange(Alliances.GetAlliances());
            }, () =>
            {
                so.Airportfacilitieslist = new List <AirportFacility>();
                so.Airportfacilitieslist.AddRange(AirportFacilities.GetFacilities());
            }, () =>
            {
                so.instance = GameObject.GetInstance();
            });


            DataContractSerializer serializer = new DataContractSerializer(typeof(SaveObject), null,
                                                                           Int32.MaxValue,
                                                                           false,
                                                                           true,
                                                                           null);

            using (Stream stream = new FileStream(fileName, FileMode.Create))
            {
                using (DeflateStream compress = new DeflateStream(stream, CompressionMode.Compress))
                {
                    serializer.WriteObject(compress, so);
                }
            }

            sw.Stop();
        }
        //loads a game
        public static void LoadGame(string file)
        {
            string fileName = AppSettings.getCommonApplicationDataPath() + "\\saves\\" + file + ".sav";

            DataContractSerializer serializer = new DataContractSerializer(typeof(SaveObject));
            SaveObject             deserializedSaveObject;

            using (FileStream stream = new FileStream(fileName, FileMode.Open))
            {
                using (DeflateStream decompress = new DeflateStream(stream, CompressionMode.Decompress))
                {
                    deserializedSaveObject =
                        (SaveObject)serializer.ReadObject(decompress);
                }
            }

            //Parrarel for loading the game
            Parallel.Invoke(() =>
            {
                Airlines.Clear();

                foreach (Airline airline in deserializedSaveObject.airlinesList)
                {
                    Airlines.AddAirline(airline);
                }
            },
                            () =>
            {
                Airports.Clear();

                foreach (Airport airport in deserializedSaveObject.airportsList)
                {
                    airport.Statics = new AirportStatics(airport);
                    Airports.AddAirport(airport);
                }
            },
                            () =>
            {
                Airliners.Clear();

                foreach (Airliner airliner in deserializedSaveObject.airlinersList)
                {
                    Airliners.AddAirliner(airliner);
                }
            },
                            () =>
            {
                CalendarItems.Clear();

                foreach (CalendarItem item in deserializedSaveObject.calendaritemsList)
                {
                    CalendarItems.AddCalendarItem(item);
                }

                Configurations.Clear();

                foreach (Configuration configuration in deserializedSaveObject.configurationList)
                {
                    Configurations.AddConfiguration(configuration);
                }
            },
                            () =>
            {
                RandomEvents.Clear();

                foreach (RandomEvent e in deserializedSaveObject.eventsList)
                {
                    RandomEvents.AddEvent(e);
                }
            },
                            () =>
            {
                Alliances.Clear();

                foreach (Alliance alliance in deserializedSaveObject.allianceList)
                {
                    Alliances.AddAlliance(alliance);
                }
            },
                            () =>
            {
                AirportFacilities.Clear();

                foreach (AirportFacility facility in deserializedSaveObject.Airportfacilitieslist)
                {
                    AirportFacilities.AddFacility(facility);
                }
            },
                            () =>
            {
                GameObject.SetInstance(deserializedSaveObject.instance);
            });  //close parallel.invoke

            //Maybe this helps? But i doubt this is the best way
            Action action = () =>
            {
                Stopwatch swPax = new Stopwatch();
                swPax.Start();

                PassengerHelpers.CreateDestinationDemand();

                //Console.WriteLine("Demand have been created in {0} ms.", swPax.ElapsedMilliseconds);
                swPax.Stop();
            };

            //Create some pilots for the game
            int pilotsPool = 100 * Airlines.GetAllAirlines().Count;

            GeneralHelpers.CreatePilots(pilotsPool);
            int instructorsPool = 75 * Airlines.GetAllAirlines().Count;

            GeneralHelpers.CreateInstructors(instructorsPool);

            //Start the game paused
            GameObjectWorker.GetInstance().startPaused();

            //Task is needed this unlocks the game agian.
            Task.Factory.StartNew(action);
        }
Exemplo n.º 10
0
        //saves a game
        public static void SaveGame(string name)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            SaveObject so = new SaveObject();

            Parallel.Invoke(() =>
            {
                so.airportsList           = new List <Airport>();
                so.airportsfromstringList = new List <string>();

                var airportsInUse = Airports.GetAllAirports().Where(a => Airlines.GetAllAirlines().Exists(al => al.Airports.Contains(a)) || a.hasAirlineFacility());
                so.airportsList.AddRange(airportsInUse);

                foreach (Airport airport in Airports.GetAirports(a => !airportsInUse.Contains(a)))
                {
                    so.airportsfromstringList.Add(airport.Profile.IATACode);
                }
            }, () =>
            {
                so.airlinesList = new List <Airline>();
                so.airlinesList.AddRange(Airlines.GetAllAirlines());
            }, () =>
            {
                so.airlinersList = new List <Airliner>();
                so.airlinersList.AddRange(Airliners.GetAllAirliners().Where(a => a.Airline != null));
            }, () =>
            {
                so.calendaritemsList = new List <CalendarItem>();
                so.calendaritemsList.AddRange(CalendarItems.GetCalendarItems());
            }, () =>
            {
                so.configurationList = new List <Configuration>();
                so.configurationList.AddRange(Configurations.GetConfigurations());
            }, () =>
            {
                so.eventsList = new List <RandomEvent>();
                so.eventsList.AddRange(RandomEvents.GetEvents());
            }, () =>
            {
                so.allianceList = new List <Alliance>();
                so.allianceList.AddRange(Alliances.GetAlliances());
            }, () =>
            {
                so.Airportfacilitieslist = new List <AirportFacility>();
                so.Airportfacilitieslist.AddRange(AirportFacilities.GetFacilities());
            }, () =>
            {
                so.feeTypeslist = new List <FeeType>();
                so.feeTypeslist.AddRange(FeeTypes.GetTypes());
            }, () =>
            {
                so.advertisementTypeslist = new List <AdvertisementType>();
                so.advertisementTypeslist.AddRange(AdvertisementTypes.GetTypes());
            }, () =>
            {
                so.airlinerfacilitieslist = new List <AirlinerFacility>();
                so.airlinerfacilitieslist.AddRange(AirlinerFacilities.GetAllFacilities());
            }, () =>
            {
                so.routefacilitieslist = new List <RouteFacility>();
                so.routefacilitieslist.AddRange(RouteFacilities.GetAllFacilities());
            }, () =>
            {
                so.instance = GameObject.GetInstance();
                so.settings = Settings.GetInstance();
            }, () =>
            {
                so.airlinefacilitieslist = new List <AirlineFacility>();
                so.airlinefacilitieslist.AddRange(AirlineFacilities.GetFacilities());
            });

            string fileName = AppSettings.getCommonApplicationDataPath() + "\\saves\\" + name + ".sav";

            FileSerializer.Serialize(fileName, so);

            sw.Stop();
            Console.WriteLine("Saving: {0} ms", sw.ElapsedMilliseconds);



            //Clearing stats because there is no need for saving those.
            if (name != "autosave")
            {
                Airports.GetAllAirports().ForEach(a => a.clearDestinationPassengerStatistics());
                Airports.GetAllAirports().ForEach(a => a.clearDestinationCargoStatistics());
                AirlineHelpers.ClearRoutesStatistics();
                AirlineHelpers.ClearAirlinesStatistics();
                AirportHelpers.ClearAirportStatistics();
            }

            /*
             * SaveObject so = new SaveObject();
             * Parallel.Invoke(() =>
             * {
             *  so.airportsList = new List<Airport>();
             *  so.airportsList.AddRange(Airports.GetAllAirports());
             * }, () =>
             * {
             *  so.airlinesList = new List<Airline>();
             *  so.airlinesList.AddRange(Airlines.GetAllAirlines());
             * }, () =>
             * {
             *  so.airlinersList = new List<Airliner>();
             *  so.airlinersList.AddRange(Airliners.GetAllAirliners());
             * }, () =>
             * {
             *  so.calendaritemsList = new List<CalendarItem>();
             *  so.calendaritemsList.AddRange(CalendarItems.GetCalendarItems());
             * }, () =>
             * {
             *  so.configurationList = new List<Configuration>();
             *  so.configurationList.AddRange(Configurations.GetConfigurations());
             * }, () =>
             * {
             *  so.eventsList = new List<RandomEvent>();
             *  so.eventsList.AddRange(RandomEvents.GetEvents());
             * }, () =>
             * {
             *  so.allianceList = new List<Alliance>();
             *  so.allianceList.AddRange(Alliances.GetAlliances());
             * }, () =>
             * {
             *  so.Airportfacilitieslist = new List<AirportFacility>();
             *  so.Airportfacilitieslist.AddRange(AirportFacilities.GetFacilities());
             * }, () =>
             * {
             *  so.feeTypeslist = new List<FeeType>();
             *  so.feeTypeslist.AddRange(FeeTypes.GetTypes());
             * }, () =>
             * {
             *  so.advertisementTypeslist = new List<AdvertisementType>();
             *  so.advertisementTypeslist.AddRange(AdvertisementTypes.GetTypes());
             * }, () =>
             * {
             *  so.airlinerfacilitieslist = new List<AirlinerFacility>();
             *  so.airlinerfacilitieslist.AddRange(AirlinerFacilities.GetAllFacilities());
             * }, () =>
             * {
             *  so.routefacilitieslist = new List<RouteFacility>();
             *  so.routefacilitieslist.AddRange(RouteFacilities.GetAllFacilities());
             * }, () =>
             * {
             *  so.instance = GameObject.GetInstance();
             *  so.settings = Settings.GetInstance();
             *  so.savetype = "039";
             *  so.saveversionnumber = 1;
             * });
             */
            /*
             * DataContractSerializer serializer = new DataContractSerializer(typeof(SaveObject), null, Int32.MaxValue, false, true, null);
             *
             * using (Stream stream = new FileStream(fileName, FileMode.Create))
             * {
             *  using (DeflateStream compress = new DeflateStream(stream, CompressionLevel.Fastest))
             *  {
             *      serializer.WriteObject(compress, so);
             *  }
             * }
             */
        }
Exemplo n.º 11
0
        //loads a game
        public static void LoadGame(string file)
        {
            string fileName = AppSettings.getCommonApplicationDataPath() + "\\saves\\" + file + ".sav";

            SaveObject deserializedSaveObject = FileSerializer.Deserialize <SaveObject>(fileName);

            /*
             *
             * DataContractSerializer serializer = new DataContractSerializer(typeof(SaveObject));
             * SaveObject deserializedSaveObject;
             * string loading;
             * int version;
             *
             * using (FileStream stream = new FileStream(fileName, FileMode.Open))
             * {
             * using (DeflateStream decompress = new DeflateStream(stream, CompressionMode.Decompress))
             * {
             *     deserializedSaveObject = (SaveObject)serializer.ReadObject(decompress);
             * }
             * }
             *
             * loading = deserializedSaveObject.savetype;
             * version = deserializedSaveObject.saveversionnumber;
             */
            //Parrarel for loading the game
            Parallel.Invoke(() =>
            {
                Airlines.Clear();

                foreach (Airline airline in deserializedSaveObject.airlinesList)
                {
                    Airlines.AddAirline(airline);
                }
            },
                            () =>
            {
                Setup.LoadAirports();

                var airports = Airports.GetAllAirports();

                Airports.Clear();

                foreach (Airport airport in deserializedSaveObject.airportsList)
                {
                    airport.Statics = new AirportStatics(airport);
                    Airports.AddAirport(airport);
                }

                foreach (string iata in deserializedSaveObject.airportsfromstringList)
                {
                    Airport airport = airports.FirstOrDefault(a => a.Profile.IATACode == iata);

                    if (airport != null)
                    {
                        Airports.AddAirport(airport);
                    }
                }
            },
                            () =>
            {
                Airliners.Clear();

                foreach (Airliner airliner in deserializedSaveObject.airlinersList)
                {
                    Airliners.AddAirliner(airliner);
                }
            },
                            () =>
            {
                CalendarItems.Clear();

                foreach (CalendarItem item in deserializedSaveObject.calendaritemsList)
                {
                    CalendarItems.AddCalendarItem(item);
                }
            },
                            () =>
            {
                Configurations.Clear();

                foreach (Configuration configuration in deserializedSaveObject.configurationList)
                {
                    Configurations.AddConfiguration(configuration);
                }
            },
                            () =>
            {
                RandomEvents.Clear();

                foreach (RandomEvent e in deserializedSaveObject.eventsList)
                {
                    RandomEvents.AddEvent(e);
                }
            },
                            () =>
            {
                Alliances.Clear();

                foreach (Alliance alliance in deserializedSaveObject.allianceList)
                {
                    Alliances.AddAlliance(alliance);
                }
            },
                            () =>
            {
                AirportFacilities.Clear();

                foreach (AirportFacility facility in deserializedSaveObject.Airportfacilitieslist)
                {
                    AirportFacilities.AddFacility(facility);
                }
            },
                            () =>
            {
                FeeTypes.Clear();

                foreach (FeeType type in deserializedSaveObject.feeTypeslist)
                {
                    FeeTypes.AddType(type);
                }
            },
                            () =>
            {
                AdvertisementTypes.Clear();

                foreach (AdvertisementType addtype in deserializedSaveObject.advertisementTypeslist)
                {
                    AdvertisementTypes.AddAdvertisementType(addtype);
                }
            },
                            () =>
            {
                AirlinerFacilities.Clear();

                foreach (AirlinerFacility airlinerfas in deserializedSaveObject.airlinerfacilitieslist)
                {
                    AirlinerFacilities.AddFacility(airlinerfas);
                }
            },
                            () =>
            {
                RouteFacilities.Clear();

                foreach (RouteFacility routefas in deserializedSaveObject.routefacilitieslist)
                {
                    RouteFacilities.AddFacility(routefas);
                }
            },
                            () =>
            {
                GameObject.SetInstance(deserializedSaveObject.instance);
                Settings.SetInstance(deserializedSaveObject.settings);
            },
                            () =>
            {
                if (deserializedSaveObject.airlinefacilitieslist != null)
                {
                    AirlineFacilities.Clear();

                    foreach (AirlineFacility airlinefac in deserializedSaveObject.airlinefacilitieslist)
                    {
                        AirlineFacilities.AddFacility(airlinefac);
                    }
                }
            }); //close parallel.invoke

            //for 0.3.9.2 and the issue with no saved facilities on a route classes
            var emptyRouteClassesFacilities = Configurations.GetConfigurations(Configuration.ConfigurationType.Routeclasses).SelectMany(c => ((RouteClassesConfiguration)c).Classes.Where(cl => cl.Facilities == null));

            foreach (RouteClassConfiguration rClassConfiguration in emptyRouteClassesFacilities)
            {
                rClassConfiguration.Facilities = new List <RouteFacility>();
            }

            Setup.SetupLoadedGame();
            //Maybe this helps? But i doubt this is the best way
            Action action = () =>
            {
                Stopwatch swPax = new Stopwatch();
                swPax.Start();

                PassengerHelpers.CreateDestinationDemand();

                //Console.WriteLine("Demand have been created in {0} ms.", swPax.ElapsedMilliseconds);
                swPax.Stop();
            };

            //create some pilots for the game
            int pilotsPool = 100 * Airlines.GetAllAirlines().Count;

            GeneralHelpers.CreatePilots(pilotsPool);
            int instructorsPool = 75 * Airlines.GetAllAirlines().Count;

            GeneralHelpers.CreateInstructors(instructorsPool);

            //creates some airliners for the game
            AirlinerHelpers.CreateStartUpAirliners();

            //Start the game paused
            GameObjectWorker.GetInstance().startPaused();

            //Task is needed this unlocks the game agian.
            Task.Factory.StartNew(action);
        }
Exemplo n.º 12
0
    IEnumerator FinishDay()
    {
        Debug.Log("Finishing day!");

        GameStatics.Loading = true;

        // Play sound
        MajorClick.Play();

        Player.Navigate(new List <Vector3> {
            new Vector3(6, 2, 1)
        }, playSelectSound: false);                                                          // Return to spawn loc

        // Show black screen
        NextDayScreen.gameObject.SetActive(true);
        StartCoroutine(NextDayScreen.ShowScreen(++Days));

        yield return(new WaitUntil(() => NextDayScreen.time >= 1));

        DiscordRichPresenceManager.UpdateActivity("Playing", Days); // Discord Rich Presence

        // Manage Debt
        if (Player.Money < 0)
        {
            if (InDebt)
            {
                Debug.Log("You are in debt");
                // Try to sell flowerbeds first to cover debt
                var shopItems = Shop.ShopItems.FindAll(shopItem => shopItem.IsDowngradable && shopItem.Level > 0);
                shopItems.Sort((shopItem1, shopItem2) => shopItem1.Price.CompareTo(shopItem2.Price));
                if (shopItems.Count == 0)
                {
                    // Display message
                    PopupManager.ShowWindowPopup("You've lost everything...", "Sadly, you've ended up with less money than you've started with. Luckily for you, your parents were nice enough to pay for your debts and give you a fresh start.", goodAlert: false);

                    // Reset values
                    Player.Money = 100;
                }
                else
                {
                    int shopItemIndex = 0;
                    while (shopItems[shopItemIndex].Price + Player.Money < 0 && shopItemIndex < shopItems.Count)
                    {
                        shopItemIndex++;
                    }

                    // Display message
                    PopupManager.ShowWindowPopup($"You sold your {shopItems[shopItemIndex].Name}", $"Since you were still in debt, you were forced to sell some things to help you get back on your feet.", goodAlert: false);

                    Player.Money += shopItems[shopItemIndex].Price; // Return money
                    int newLevel = --shopItems[shopItemIndex].Level;

                    if (shopItems[shopItemIndex].Name == "Flower Beds")            // flower bed edge case
                    {
                        FlowerBedManager.SendMessage("RemoveFlowerBed", newLevel); // Sell flowerbed
                    }
                    Shop.UpdateBuyButtonVisual(shopItems[shopItemIndex]);          // Update visuals
                }
            }
            else
            {
                InDebt = true;
                PopupManager.ShowWindowPopup("You're in debt!", "You are in debt! Get out of debt or you'll soon need to start selling your things!", goodAlert: false);
            }
        }
        else
        {
            InDebt = false;

            Player.Money -= FamilyPayment;                 // Pay family
            Player.Money -= BorrowMoney.TotalDailyPayment; // Pay loans
            BorrowMoney.UpdateDailyPayments();
        }

        // Game won?
        if (!finishedGame && Player.Money > 5000 && Shop.IsMaxedOut)
        {
            Debug.Log($"You've made a lot of money, your family is proud of you. The end! :) ({Days} days to complete game)");
            StorylineManager.ShowStoryline("The End");
            finishedGame = true;
        }


        // PLAYER
        Player.InHand = Player.Items.Nothing; // Empty hands

        // STORYLINE
        StorylineManager.CheckForNewStoryline(Days);

        // FLOWER BEDS
        // Get Flower Beds States
        var FlowerBedScripts = FlowerBeds.GetComponentsInChildren <FlowerBed>();


        // WEATHER
        Debug.Log(weather);

        // Apply logic to flower beds

        // Get chances for weather
        if (!WeatherLogicData.TryGetValue(weather, out var flowerbedStateChances))
        {
            WeatherLogicData.TryGetValue(Weather.Sunny, out flowerbedStateChances);
        }

        // Go through flowerbeds
        foreach (FlowerBed flowerBed in FlowerBedScripts)
        {
            if (!flowerbedStateChances.TryGetValue(flowerBed.state, out var chances))
            {
                continue;
            }
            float randomChance = Random.value;

            foreach (var possibleChance in chances)
            {
                if (possibleChance.Value > randomChance)
                {
                    flowerBed.UpdateFlowerbedState(possibleChance.Key);
                    break;
                }

                randomChance -= possibleChance.Value;
            }
        }

        RandomEvents.Run(); // Random events

        // Create new weather for tomorrow
        GenerateWeather();

        GameFunctions.SaveGame(true, "finish_day_backup").Wait(); // Save data everyday while making backup copies just in case

        GameStatics.Loading = false;
    }
Exemplo n.º 13
0
 /*
 RandEvent(string titl, string tex, string o1, string o2, string o3){
     title = titl;
     text = tex;
     option1 = o1;
     option2 = o2;
     option3 = o3;
 }
 */
 public RandEvent(GameObject obj)
 {
     myResourceClass = GameObject.Find("GameManager").GetComponent<Resource>();
     myEventClass = GameObject.Find("GameManager").GetComponent<RandomEvents>();
 }