Exemplo n.º 1
0
        private void OnTick()
        {
            var now = DateTime.Now;

            if (nextStatsTime < now)
            {
                nextStatsTime = now.AddMilliseconds(statsInterval);
                lastStats     = currentStats;
                currentStats  = new Stats();
            }
            // Never use more than half the available tick time
            // but always process at least one queued block.
            var maxTime = (1000 / ConVar.Server.tickrate) / 2;
            var n       = 0;

            while (stabilityQueue.Count > 0 && (n == 0 || (DateTime.Now - now).TotalMilliseconds < maxTime))
            {
                var block = stabilityQueue[0];
                stabilityQueue.RemoveAt(0);
                if (!BuildingBlockHelpers.IsValidBlock(block))
                {
                    continue;
                }
                UpdateStability(block);
                ++n;
            }
            // Always delay queued updates until the next tick.
            // This also gives us a nice bottom up effect.
            while (stabilityQueueDelayed.Count > 0)
            {
                stabilityQueue.Add(stabilityQueueDelayed[0]);
                stabilityQueueDelayed.RemoveAt(0);
            }
        }
Exemplo n.º 2
0
        private void OnEntityBuilt(Planner planner, GameObject obj)
        {
            if (obj == null)
            {
                return;
            }
            var block = obj.GetComponent <BuildingBlock>();

            if (!BuildingBlockHelpers.IsValidBlock(block))
            {
                return;
            }
#if DEBUG
            Log("Placing block " + block.blockDefinition.hierachyName);
#endif
            ++currentStats.blocksBuilt;
            try {
                var defaultGrade = block.blockDefinition.defaultGrade;
                if (!UpdateStability(block, false))
                {
                    ++currentStats.blocksFailedBuilding;
                    // If this isn't stable, refund.
                    var player = planner.ownerPlayer;
                    foreach (var cost in defaultGrade.costToBuild)
                    {
                        var item = ItemManager.CreateByItemID(cost.itemid, (int)cost.amount, false);
                        player.GiveItem(item, BaseEntity.GiveItemReason.Generic);
                    }
                    player.ChatMessage(_(buildingFailedMessages[rng.Next(0, buildingFailedMessages.Length)]));
                    return;
                }
            } catch (Exception ex) {
                Error("OnEntityBuilt failed", ex);
            }
        }
Exemplo n.º 3
0
 private void OnBuildingBlockDemolish(BuildingBlock block, BasePlayer player)
 {
     if (!BuildingBlockHelpers.IsValidBlock(block))
     {
         return;
     }
     OnDemolish(block);
 }
Exemplo n.º 4
0
        private void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
            var block = entity as BuildingBlock;

            if (!BuildingBlockHelpers.IsValidBlock(block))
            {
                return;
            }
            OnDemolish(block);
        }
Exemplo n.º 5
0
        void cmdConsoleUpdateAll(ConsoleSystem.Arg arg)
        {
            if (arg.connection != null && arg.connection.authLevel < 2)
            {
                return;
            }
            var allBlocks = UnityEngine.Object.FindObjectsOfType <BuildingBlock>();

            foreach (var block in allBlocks)
            {
                if (!BuildingBlockHelpers.IsValidBlock(block))
                {
                    continue;
                }
                UpdateStability(block, true);
            }
            SendReply(arg, "Updating stability on ALL " + allBlocks.Length + " blocks in the background now, this will take a while.");
        }