예제 #1
0
        internal void Stage1() // Methods highly inlined due to keen's mod profiler
        {
            Session.StallReporter.Start("FragmentsNeedingEntities", 32);
            if (Session.FragmentsNeedingEntities.Count > 0)
            {
                PrepFragmentEntities();
            }
            Session.StallReporter.End();

            if (!Session.DedicatedServer)
            {
                DeferedAvStateUpdates(Session);
            }

            Session.StallReporter.Start("Clean&Spawn", 32);
            Clean();
            SpawnFragments();

            ActiveProjetiles.ApplyChanges();
            Session.StallReporter.End();

            if (AddTargets.Count > 0)
            {
                AddProjectileTargets();
            }

            Session.StallReporter.Start("UpdateState", 32);
            UpdateState();
            Session.StallReporter.End();

            Session.StallReporter.Start("CheckHits", 32);
            Session.PTask = MyAPIGateway.Parallel.Start(CheckHits, Session.CoreWorkOpt);
            Session.StallReporter.End();
        }
예제 #2
0
        public override void UpdateAfterSimulation()
        {
            try
            {
                UpdateObjects.ApplyChanges();

                foreach (IUpdatable obj in UpdateObjects)
                {
                    obj.Update();
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
예제 #3
0
        internal void Update() // Methods highly inlined due to keen's mod profiler
        {
            if (!Session.DedicatedServer)
            {
                DeferedAvStateUpdates(Session);
            }

            Clean();
            SpawnFragments();

            ActiveProjetiles.ApplyChanges();

            UpdateState();
            CheckHits();
            if (!Session.DedicatedServer)
            {
                UpdateAv();
            }
        }
        private void Update()
        {
            if (!MyMultiplayerModApi.Static.IsServer)
            {
                return;
            }
            if (MyMultiplayerModApi.Static.Players.Count == 0)
            {
                if (_weatherEnabled.HasValue)
                {
                    _weather.Enabled   = _weatherEnabled.Value;
                    _weather.DayOffset = _weather.DayOffset; // force sync
                }
                _weatherEnabled = null;
                return;
            }

            if (_dirty)
            {
                _slots.ApplyChanges();
                var required = (int)(MyMultiplayerModApi.Static.Players.Count / 2f) + 1;
                var has      = 0;
                var next     = _nextSleeping;
                next.Clear();
                foreach (var s in _slots)
                {
                    if (s.Controllable.Entity != null && s.Controllable.Entity.InScene && s.AttachedCharacter != null)
                    {
                        var player = MyAPIGateway.Players?.GetPlayerControllingEntity(s.AttachedCharacter);
                        if (player == null)
                        {
                            continue;
                        }
                        has++;
                        StateData stateData;
                        if (!_currentlySleeping.TryGetValue(s, out stateData))
                        {
                            stateData = new StateData(s.AttachedCharacter, null);
                            _currentlySleeping.Add(s, stateData);
                            BroadcastNotification($"{stateData.Player.DisplayName} is now sleeping.  ({has}/{required})");
                        }

                        next.Add(s, stateData);
                    }
                }

                _advanceTime = has >= required;
                foreach (var k in _currentlySleeping)
                {
                    if (!next.ContainsKey(k.Key))
                    {
                        BroadcastNotification($"{k.Value.Player.DisplayName} woke up.");
                    }
                }
                var current = _currentlySleeping;
                _currentlySleeping = next;
                current.Clear();
                _nextSleeping = current;
            }

            _wakeUpTimer--;
            if (_wakeUpTimer <= 0)
            {
                CheckWakeup();
                _wakeUpTimer = 30;
            }

            // ReSharper disable once InvertIf
            if (_advanceTime)
            {
                if (!_weatherEnabled.HasValue)
                {
                    _weatherEnabled = _weather.Enabled;
                }

                var nextOffset = _weather.DayOffset + TimeSpan.FromSeconds(SecondsPerSecond * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS);
                _weather.Enabled   = true;
                _weather.DayOffset = TimeSpan.FromMinutes(nextOffset.TotalMinutes % _weather.DayDurationInMinutes);
            }
            else
            {
                if (_weatherEnabled.HasValue)
                {
                    _weather.Enabled   = _weatherEnabled.Value;
                    _weather.DayOffset = _weather.DayOffset; // force sync
                }
                _weatherEnabled = null;
            }
        }
        public static void GenerateLuckyContent(this MyInventoryBase inventory, MyLootTableDefinition lootTableDefinition,
                                                LootContext context, HashSet <MyStringHash> blacklistedLootTables = null)
        {
            var cachingHashSet = new CachingHashSet <MyLootTableDefinition.Row>();

            foreach (var item in lootTableDefinition.LootTable)
            {
                cachingHashSet.Add(item);
            }
            cachingHashSet.ApplyChanges();
            var num = 0f;

            if (blacklistedLootTables == null)
            {
                blacklistedLootTables = new HashSet <MyStringHash>();
            }
            blacklistedLootTables.Add(lootTableDefinition.Id.SubtypeId);
            foreach (var row in cachingHashSet)
            {
                if (row.AlwaysDrops && row.ItemDefinition != null)
                {
                    if (row.ItemDefinition.Value.TypeId == typeof(MyObjectBuilder_LootTableDefinition))
                    {
                        var nestedTable = MyDefinitionManager.Get <MyLootTableDefinition>(row.ItemDefinition.Value);
                        if (nestedTable != null && !blacklistedLootTables.Contains(nestedTable.Id.SubtypeId))
                        {
                            inventory.GenerateLuckyContent(nestedTable, context, blacklistedLootTables);
                        }
                    }
                    else
                    {
                        AddItemsFuzzy(inventory, row.ItemDefinition.Value, row.Amount);
                    }

                    if (row.IsUnique)
                    {
                        cachingHashSet.Remove(row, false);
                        continue;
                    }
                }

                num += row.Weight;
            }

            var rollLucky = Math.Round(lootTableDefinition.Rolls * context.RollMultiplier + context.RollAdditive);

            for (var j = 0; j < rollLucky; j++)
            {
                var num2 = MyRandom.Instance.NextFloat(0f, num);
                cachingHashSet.ApplyChanges();
                foreach (var row2 in cachingHashSet)
                {
                    num2 -= row2.Weight;
                    if (num2 > 0f || row2.ItemDefinition == null)
                    {
                        continue;
                    }
                    if (row2.ItemDefinition.Value.TypeId == typeof(MyObjectBuilder_LootTableDefinition))
                    {
                        var nestedTable = MyDefinitionManager.Get <MyLootTableDefinition>(row2.ItemDefinition.Value);
                        if (nestedTable != null)
                        {
                            inventory.GenerateLuckyContent(nestedTable, context);
                        }
                    }
                    else
                    {
                        AddItemsFuzzy(inventory, row2.ItemDefinition.Value, row2.Amount);
                    }

                    if (row2.IsUnique)
                    {
                        cachingHashSet.Remove(row2, false);
                        num -= row2.Weight;
                    }

                    break;
                }
            }

            blacklistedLootTables.Remove(lootTableDefinition.Id.SubtypeId);
        }