コード例 #1
0
        private static void SetupGame()
        {
            MultiplayerWorldComp comp = new MultiplayerWorldComp(Find.World);
            Faction dummyFaction      = Find.FactionManager.AllFactions.FirstOrDefault(f => f.loadID == -1);

            if (dummyFaction == null)
            {
                dummyFaction = new Faction()
                {
                    loadID = -1, def = Multiplayer.DummyFactionDef
                };

                foreach (Faction other in Find.FactionManager.AllFactionsListForReading)
                {
                    dummyFaction.TryMakeInitialRelationsWith(other);
                }

                Find.FactionManager.Add(dummyFaction);

                comp.factionData[dummyFaction.loadID] = FactionWorldData.New(dummyFaction.loadID);
            }

            dummyFaction.Name = "Multiplayer dummy faction";
            dummyFaction.def  = Multiplayer.DummyFactionDef;

            Faction.OfPlayer.Name = $"{Multiplayer.username}'s faction";
            comp.factionData[Faction.OfPlayer.loadID] = FactionWorldData.FromCurrent();

            Multiplayer.game = new MultiplayerGame
            {
                dummyFaction = dummyFaction,
                worldComp    = comp
            };

            comp.globalIdBlock = new IdBlock(GetMaxUniqueId(), 1_000_000_000);

            foreach (FactionWorldData data in comp.factionData.Values)
            {
                foreach (DrugPolicy p in data.drugPolicyDatabase.policies)
                {
                    p.uniqueId = Multiplayer.GlobalIdBlock.NextId();
                }

                foreach (Outfit o in data.outfitDatabase.outfits)
                {
                    o.uniqueId = Multiplayer.GlobalIdBlock.NextId();
                }

                foreach (FoodRestriction o in data.foodRestrictionDatabase.foodRestrictions)
                {
                    o.id = Multiplayer.GlobalIdBlock.NextId();
                }
            }

            foreach (Map map in Find.Maps)
            {
                //mapComp.mapIdBlock = localServer.NextIdBlock();

                BeforeMapGeneration.SetupMap(map);

                MapAsyncTimeComp async = map.AsyncTime();
                async.mapTicks  = Find.TickManager.TicksGame;
                async.TimeSpeed = Find.TickManager.CurTimeSpeed;
            }
            Multiplayer.WorldComp.UpdateTimeSpeed();
        }