示例#1
0
        /// <param name="recycler">The recycler entity we're "overwriting".</param>
        public Crafter(Recycler recycler)
        {
            CreationTime = DateTime.UtcNow;

            Recycler = recycler;

            CreateOutputContainer();

            // Reset despawn timer on loot bag once per minute.
            resetDespawnTimer = Utility.Timer.Every(60, () =>
            {
                if (!outputContainer.IsDestroyed)
                {
                    outputContainer.ResetRemovalTime();
                }
            });

            recycler.gameObject.AddComponent <GroundWatch>();
            recycler.gameObject.AddComponent <DestroyOnGroundMissing>();

            recycler.repair.enabled    = true;
            recycler.repair.itemTarget = ItemManager.FindItemDefinition("wall.frame.shopfront.metal");

            // Set health to 1000
            Recycler._maxHealth = 1000;
            Recycler.health     = recycler.MaxHealth();

            // Set up damage protection
            Recycler.baseProtection.density = 4;

            for (int i = 0; i < Recycler.baseProtection.amounts.Length; ++i)
            {
                Recycler.baseProtection.amounts[i] = Utility.Config.CrafterProtectionProperties[i];
            }

            // Set up decay
            var researchPrefab = GameManager.server.FindPrefab(Constants.DeployedResearchTablePrefab);             // Copying decay settings from research table

            if (researchPrefab == null)
            {
                Utility.LogWarning("Could not find research table prefab, skipping decay setup");
            }
            else
            {
                uint prefabID    = researchPrefab.GetComponent <BaseEntity>().prefabID;
                var  decay       = PrefabAttribute.server.Find <Decay>(prefabID);
                var  decayPoints = PrefabAttribute.server.FindAll <DecayPoint>(prefabID);

                typeof(DecayEntity).GetField("decay", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(Recycler, decay);
                typeof(DecayEntity).GetField("decayPoints", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(Recycler, decayPoints);
                BuildingManager.DecayEntities.Add(Recycler);
            }
        }