Exemple #1
0
    public BaseEntity CreateConstruction(Construction.Target target, bool bNeedsValidPlacement = false)
    {
        GameObject gameObject = GameManager.server.CreatePrefab(this.fullName, Vector3.zero, Quaternion.identity, false);
        bool       flag       = this.UpdatePlacement(gameObject.transform, this, ref target);
        BaseEntity baseEntity = gameObject.ToBaseEntity();

        if (bNeedsValidPlacement && !flag)
        {
            if (!baseEntity.IsValid())
            {
                GameManager.Destroy(gameObject, 0f);
            }
            else
            {
                baseEntity.Kill(BaseNetworkable.DestroyMode.None);
            }
            return(null);
        }
        DecayEntity decayEntity = baseEntity as DecayEntity;

        if (decayEntity)
        {
            decayEntity.AttachToBuilding(target.entity as DecayEntity);
        }
        return(baseEntity);
    }
 public void Remove(DecayEntity ent)
 {
     if (ent.buildingID == 0U)
     {
         this.decayEntities.Remove(ent);
     }
     else
     {
         BuildingManager.Building building = this.GetBuilding(ent.buildingID);
         if (building == null)
         {
             return;
         }
         building.Remove(ent);
         if (building.IsEmpty())
         {
             this.buildingDictionary.Remove(ent.buildingID);
             this.DisposeBuilding(ref building);
         }
         else
         {
             building.Dirty();
         }
     }
 }
    private void Split(BuildingManager.Building building)
    {
        while (building.HasBuildingBlocks())
        {
            BuildingBlock          buildingBlock = building.buildingBlocks.get_Item(0);
            uint                   newID         = BuildingManager.server.NewBuildingID();
            Action <BuildingBlock> action        = (Action <BuildingBlock>)(b => b.AttachToBuilding(newID));
            buildingBlock.EntityLinkBroadcast <BuildingBlock>(action);
        }
        while (building.HasBuildingPrivileges())
        {
            BuildingPrivlidge buildingPrivlidge   = building.buildingPrivileges.get_Item(0);
            BuildingBlock     nearbyBuildingBlock = buildingPrivlidge.GetNearbyBuildingBlock();
            buildingPrivlidge.AttachToBuilding(Object.op_Implicit((Object)nearbyBuildingBlock) ? nearbyBuildingBlock.buildingID : 0U);
        }
        while (building.HasDecayEntities())
        {
            DecayEntity   decayEntity         = building.decayEntities.get_Item(0);
            BuildingBlock nearbyBuildingBlock = decayEntity.GetNearbyBuildingBlock();
            decayEntity.AttachToBuilding(Object.op_Implicit((Object)nearbyBuildingBlock) ? nearbyBuildingBlock.buildingID : 0U);
        }
        if (!ConVar.AI.nav_carve_use_building_optimization)
        {
            return;
        }
        building.isNavMeshCarvingDirty = true;
        int ticks = 2;

        this.UpdateNavMeshCarver(building, ref ticks, 0);
    }
Exemple #4
0
    public BaseEntity CreateConstruction(Target target, bool bNeedsValidPlacement = false)
    {
        GameObject gameObject = GameManager.server.CreatePrefab(fullName, Vector3.zero, Quaternion.identity, false);
        bool       flag       = UpdatePlacement(gameObject.transform, this, ref target);
        BaseEntity baseEntity = GameObjectEx.ToBaseEntity(gameObject);

        if (bNeedsValidPlacement && !flag)
        {
            if (BaseEntityEx.IsValid(baseEntity))
            {
                baseEntity.Kill();
            }
            else
            {
                GameManager.Destroy(gameObject);
            }
            return(null);
        }
        DecayEntity decayEntity = baseEntity as DecayEntity;

        if ((bool)decayEntity)
        {
            decayEntity.AttachToBuilding(target.entity as DecayEntity);
        }
        return(baseEntity);
    }
Exemple #5
0
 public void AddDecayEntity(DecayEntity ent)
 {
     if (!(ent == null) && !decayEntities.Contains(ent))
     {
         decayEntities.Add(ent);
     }
 }
    public void PurchaseUpkeepTime(float deltaTime)
    {
        BuildingManager.Building building = this.GetBuilding();
        if (building == null || !building.HasDecayEntities())
        {
            return;
        }
        float num = Mathf.Min(this.GetProtectedMinutes(true) * 60f, deltaTime);

        if ((double)num <= 0.0)
        {
            return;
        }
        using (IEnumerator <DecayEntity> enumerator = building.decayEntities.GetEnumerator())
        {
            while (enumerator.MoveNext())
            {
                DecayEntity current          = enumerator.Current;
                float       protectedSeconds = current.GetProtectedSeconds();
                if ((double)num > (double)protectedSeconds)
                {
                    float time = this.PurchaseUpkeepTime(current, num - protectedSeconds);
                    current.AddUpkeepTime(time);
                    if (this.IsDebugging())
                    {
                        Debug.Log((object)(((object)this).ToString() + " purchased upkeep time for " + ((object)current).ToString() + ": " + (object)protectedSeconds + " + " + (object)time + " = " + (object)current.GetProtectedSeconds()));
                    }
                }
            }
        }
    }
Exemple #7
0
        void OnEntitySpawned(BaseNetworkable entity)
        {
            if (!init)
            {
                return;
            }
            if (entity?.net?.ID == null)
            {
                return;
            }
            if (IsDecayEntity(entity) && !decayEntities.Contains((BaseCombatEntity)entity))
            {
                decayEntities.Add((BaseCombatEntity)entity);
            }
            BuildingPrivlidge privlidge = entity as BuildingPrivlidge;

            if (privlidge != null)
            {
                cupboards.Add(privlidge.net.ID);
            }
            NextTick(() =>
            {
                DecayEntity decEnt = entity as DecayEntity;
                if (decEnt != null)
                {
                    decEnt.CancelInvoke("RunDecay");
                }
            });
        }
        void OnHammerHit(BasePlayer player, HitInfo info)
        {
            if (player == null || info == null || !_players.Contains(player.userID) || !permission.UserHasPermission(player.UserIDString, _usePerm))
            {
                return;
            }

            if (!player.serverInput.IsDown(BUTTON.SPRINT))
            {
                player.ChatMessage(Lang("NoKeyPress", player.UserIDString));
                return;
            }

            BuildingBlock block = info?.HitEntity as BuildingBlock;

            if (block == null)
            {
                player.ChatMessage(Lang("NoBuildingBlock", player.UserIDString));
                return;
            }

            DecayEntity decayEntity = block as DecayEntity;

            if (decayEntity == null)
            {
                player.ChatMessage(Lang("NoDecayEntity", player.UserIDString));
                return;
            }

            BuildingDecay(decayEntity.buildingID);

            player.ChatMessage(Lang("DecayStarted", player.UserIDString));
        }
    public void CheckMerge(DecayEntity ent)
    {
        if (ent.buildingID == 0U)
        {
            return;
        }
        BuildingManager.Building building = ent.GetBuilding();
        if (building == null)
        {
            return;
        }
        ent.EntityLinkMessage <BuildingBlock>((Action <BuildingBlock>)(b =>
        {
            if ((int)b.buildingID == (int)building.ID)
            {
                return;
            }
            BuildingManager.Building building1 = b.GetBuilding();
            if (building1 == null)
            {
                return;
            }
            this.Merge(building, building1);
        }));
        if (!ConVar.AI.nav_carve_use_building_optimization)
        {
            return;
        }
        building.isNavMeshCarvingDirty = true;
        int ticks = 2;

        this.UpdateNavMeshCarver(building, ref ticks, 0);
    }
Exemple #10
0
    public BaseEntity CreateConstruction(
        Construction.Target target,
        bool bNeedsValidPlacement = false)
    {
        GameObject prefab     = GameManager.server.CreatePrefab(this.fullName, Vector3.get_zero(), Quaternion.get_identity(), false);
        bool       flag       = this.UpdatePlacement(prefab.get_transform(), this, ref target);
        BaseEntity baseEntity = prefab.ToBaseEntity();

        if (bNeedsValidPlacement && !flag)
        {
            if (baseEntity.IsValid())
            {
                baseEntity.Kill(BaseNetworkable.DestroyMode.None);
            }
            else
            {
                GameManager.Destroy(prefab, 0.0f);
            }
            return((BaseEntity)null);
        }
        DecayEntity decayEntity = baseEntity as DecayEntity;

        if (Object.op_Implicit((Object)decayEntity))
        {
            decayEntity.AttachToBuilding(target.entity as DecayEntity);
        }
        return(baseEntity);
    }
 public void CheckMerge(DecayEntity ent)
 {
     if (ent.buildingID == 0)
     {
         return;
     }
     BuildingManager.Building building1 = ent.GetBuilding();
     if (building1 == null)
     {
         return;
     }
     ent.EntityLinkMessage <BuildingBlock>((BuildingBlock b) => {
         if (b.buildingID != building1.ID)
         {
             BuildingManager.Building building = b.GetBuilding();
             if (building != null)
             {
                 this.Merge(building1, building);
             }
         }
     });
     if (AI.nav_carve_use_building_optimization)
     {
         building1.isNavMeshCarvingDirty = true;
         int num = 2;
         this.UpdateNavMeshCarver(building1, ref num, 0);
     }
 }
Exemple #12
0
 public void RemoveDecayEntity(DecayEntity ent)
 {
     if (!(ent == null))
     {
         decayEntities.Remove(ent);
     }
 }
Exemple #13
0
        void InitDecayEntities()
        {
            var ents = UnityEngine.Object.FindObjectsOfType <BaseCombatEntity>();

            decayEntities = new List <BaseCombatEntity>(ents.Length);

            Parallel.For(0, ents.Length, (i) =>
            {
                var ent = ents[i];
                if (ent == null)
                {
                    return;
                }
                DecayEntity decEnt = ent as DecayEntity;
                NextTick(() =>
                {
                    if (decEnt != null)
                    {
                        decEnt.CancelInvoke("RunDecay");
                    }
                    if (IsDecayEntity(ent))
                    {
                        decayEntities.Add(ent);
                    }
                });
            });
            Puts($"Загрузка объектов прошла успешно! Count: {ents.Length}");
            init = true;
        }
 public void RemoveDecayEntity(DecayEntity ent)
 {
     if (Object.op_Equality((Object)ent, (Object)null))
     {
         return;
     }
     this.decayEntities.Remove(ent);
 }
 public void AddDecayEntity(DecayEntity ent)
 {
     if (Object.op_Equality((Object)ent, (Object)null) || this.decayEntities.Contains(ent))
     {
         return;
     }
     this.decayEntities.Add(ent);
 }
Exemple #16
0
 public void RemoveDecayEntity(DecayEntity ent)
 {
     if (ent == null)
     {
         return;
     }
     this.decayEntities.Remove(ent);
 }
        private static bool CheckBuilding(ChristmasTree tree)
        {
            DecayEntity decay = tree.GetComponent <DecayEntity>();

            if (decay == null)
            {
                return(false);
            }
            return(decay.GetBuilding() != null);
        }
Exemple #18
0
 public void AddDecayEntity(DecayEntity ent)
 {
     if (ent == null)
     {
         return;
     }
     if (!this.decayEntities.Contains(ent))
     {
         this.decayEntities.Add(ent);
     }
 }
Exemple #19
0
    private bool OnGround()
    {
        BaseEntity component = GetComponent <BaseEntity>();

        if ((bool)component)
        {
            Construction construction = PrefabAttribute.server.Find <Construction>(component.prefabID);
            if ((bool)construction)
            {
                Socket_Base[] allSockets = construction.allSockets;
                for (int i = 0; i < allSockets.Length; i++)
                {
                    SocketMod[] socketMods = allSockets[i].socketMods;
                    for (int j = 0; j < socketMods.Length; j++)
                    {
                        SocketMod_AreaCheck socketMod_AreaCheck = socketMods[j] as SocketMod_AreaCheck;
                        if ((bool)socketMod_AreaCheck && socketMod_AreaCheck.wantsInside && !socketMod_AreaCheck.DoCheck(component.transform.position, component.transform.rotation))
                        {
                            if (ConVar.Physics.groundwatchdebug)
                            {
                                Debug.Log("GroundWatch failed: " + socketMod_AreaCheck.hierachyName);
                            }
                            return(false);
                        }
                    }
                }
            }
        }
        List <Collider> obj = Facepunch.Pool.GetList <Collider>();

        Vis.Colliders(base.transform.TransformPoint(groundPosition), radius, obj, layers);
        foreach (Collider item in obj)
        {
            BaseEntity baseEntity = GameObjectEx.ToBaseEntity(item.gameObject);
            if (!baseEntity || (!(baseEntity == component) && !baseEntity.IsDestroyed && !baseEntity.isClient))
            {
                DecayEntity decayEntity  = component as DecayEntity;
                DecayEntity decayEntity2 = baseEntity as DecayEntity;
                if (!decayEntity || decayEntity.buildingID == 0 || !decayEntity2 || decayEntity2.buildingID == 0 || decayEntity.buildingID == decayEntity2.buildingID)
                {
                    Facepunch.Pool.FreeList(ref obj);
                    return(true);
                }
            }
        }
        if (ConVar.Physics.groundwatchdebug)
        {
            Debug.Log("GroundWatch failed: Legacy radius check");
        }
        Facepunch.Pool.FreeList(ref obj);
        return(false);
    }
 public void CheckSplit(DecayEntity ent)
 {
     if (ent.buildingID == 0U)
     {
         return;
     }
     BuildingManager.Building building = ent.GetBuilding();
     if (building == null || !this.ShouldSplit(building))
     {
         return;
     }
     this.Split(building);
 }
        private object OnHammerHit(BasePlayer player, HitInfo info)
        {
            BaseCombatEntity entity = info?.HitEntity as BaseCombatEntity;

            if (entity == null || entity.IsDestroyed)
            {
                return(null);
            }

            DecayEntity decay = entity as DecayEntity;

            if (decay != null && decay.buildingID == 0)
            {
                return(null);
            }

            if (!_storedData.RepairEnabled.ContainsKey(player.userID) && _pluginConfig.DefaultEnabled)
            {
                _storedData.RepairEnabled[player.userID] = true;
            }

            if (!_storedData.RepairEnabled[player.userID])
            {
                return(null);
            }

            if (IsNoEscapeBlocked(player))
            {
                Chat(player, Lang(LangKeys.NoEscape, player));
                return(null);
            }

            if (_repairingPlayers.Contains(player.userID))
            {
                Chat(player, Lang(LangKeys.RepairInProcess, player));
                return(null);
            }

            BuildingPrivlidge priv = player.GetBuildingPrivilege();

            if (priv == null || !priv.IsAuthed(player))
            {
                return(null);
            }

            PlayerRepairStats stats = new PlayerRepairStats();

            BuildingManager.Building building = priv.GetBuilding();
            ServerMgr.Instance.StartCoroutine(DoBuildingRepair(player, building, stats));
            return(true);
        }
Exemple #22
0
        private Item OnFindBurnable(BaseOven oven)
        {
            if (oven.fuelType == null)
            {
                return(null);
            }
            if (!activeShortNames.Contains(oven.ShortPrefabName))
            {
                return(null);
            }
            if (HasFuel(oven))
            {
                return(null);
            }
            DecayEntity decayEnt = oven.GetComponent <DecayEntity>();

            if (decayEnt == null)
            {
                return(null);
            }
            AutomaticRefuel refuel = decayEnt.GetComponent <AutomaticRefuel>();

            if (!refuel)
            {
                decayEnt.gameObject.AddComponent <AutomaticRefuel>();
            }
            if (refuel.cupboard == null)
            {
                refuel.SearchForCupboard();
                if (refuel.cupboard == null)
                {
                    return(null);
                }
            }

            if (dontRequireFuel)
            {
                return(ItemManager.CreateByName(oven.fuelType.shortname, 1));
            }
            Item fuelItem = refuel.GetFuel();

            if (fuelItem == null)
            {
                return(null);
            }
            RemoveItemThink(fuelItem);
            ItemManager.CreateByName(oven.fuelType.shortname, 1)?.MoveToContainer(oven.inventory);
            return(null);
        }
        private BaseEntity SpawnSmallShelves(Vector3 pos, Quaternion rot, DecayEntity floor)
        {
            BaseEntity    ent       = GameManager.server.CreateEntity("assets/scripts/entity/misc/visualstoragecontainer/visualshelvestest.prefab", pos, rot);
            LootContainer container = ent.GetComponent <LootContainer>();

            container.destroyOnEmpty   = false;
            container.initialLootSpawn = false;
            ent.GetComponent <DecayEntity>().AttachToBuilding(floor);
            DestroyOnGroundMissing des   = ent.gameObject.AddComponent <DestroyOnGroundMissing>();
            GroundWatch            watch = ent.gameObject.AddComponent <GroundWatch>();

            watch.InvokeRepeating("OnPhysicsNeighbourChanged", 0f, 0.15f);
            ent.Spawn();
            return(ent);
        }
 object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo)
 {
     if (hitInfo.damageTypes.GetMajorityDamageType().ToString().Contains("Decay"))
     {
         var ownerid = entity.OwnerID;
         if (HasPermission(ownerid, "vipnodecay.vip"))
         {
             DecayEntity decayEntity = entity.GetComponent <DecayEntity>();
             //First resets the decay timer for entity who's owner is a vip
             decayEntity.DecayTouch();
             //Then blocks this currrent damage to entity
             return(false);
         }
     }
     return(null);
 }
    private void Split(BuildingManager.Building building)
    {
        uint num;
        uint num1;

        while (building.HasBuildingBlocks())
        {
            BuildingBlock item = building.buildingBlocks[0];
            uint          num2 = BuildingManager.server.NewBuildingID();
            item.EntityLinkBroadcast <BuildingBlock>((BuildingBlock b) => b.AttachToBuilding(num2));
        }
        while (building.HasBuildingPrivileges())
        {
            BuildingPrivlidge buildingPrivlidge   = building.buildingPrivileges[0];
            BuildingBlock     nearbyBuildingBlock = buildingPrivlidge.GetNearbyBuildingBlock();
            if (nearbyBuildingBlock)
            {
                num = nearbyBuildingBlock.buildingID;
            }
            else
            {
                num = 0;
            }
            buildingPrivlidge.AttachToBuilding(num);
        }
        while (building.HasDecayEntities())
        {
            DecayEntity   decayEntity   = building.decayEntities[0];
            BuildingBlock buildingBlock = decayEntity.GetNearbyBuildingBlock();
            if (buildingBlock)
            {
                num1 = buildingBlock.buildingID;
            }
            else
            {
                num1 = 0;
            }
            decayEntity.AttachToBuilding(num1);
        }
        if (AI.nav_carve_use_building_optimization)
        {
            building.isNavMeshCarvingDirty = true;
            int num3 = 2;
            this.UpdateNavMeshCarver(building, ref num3, 0);
        }
    }
Exemple #26
0
        private Item OnFindBurnable(BaseOven oven)
        {
            if (!permission.UserHasPermission(oven.OwnerID.ToString(), permissionName))
            {
                return(null);
            }
            if (oven.fuelType == null)
            {
                return(null);
            }
            if (!activeShortNames.Contains(oven.ShortPrefabName))
            {
                return(null);
            }
            if (HasFuel(oven))
            {
                return(null);
            }
            DecayEntity decayEnt = oven.GetComponent <DecayEntity>();

            if (decayEnt == null)
            {
                return(null);
            }
            BuildingPrivlidge priv = decayEnt.GetBuildingPrivilege();

            if (priv == null)
            {
                return(null);
            }
            else
            {
                if (dontRequireFuel)
                {
                    return(ItemManager.CreateByName(oven.fuelType.shortname, 1));
                }
                Item fuelItem = GetFuel(priv, oven);
                if (fuelItem == null)
                {
                    return(null);
                }
                RemoveItemThink(fuelItem);
                ItemManager.CreateByName(oven.fuelType.shortname, 1)?.MoveToContainer(oven.inventory);
                return(null);
            }
        }
    public float PurchaseUpkeepTime(DecayEntity entity, float deltaTime)
    {
        float             single  = this.CalculateUpkeepPeriodMinutes() * 60f;
        float             single1 = this.CalculateUpkeepCostFraction() * deltaTime / single;
        List <ItemAmount> list    = Facepunch.Pool.GetList <ItemAmount>();

        entity.CalculateUpkeepCostAmounts(list, single1);
        bool flag = this.CanAffordUpkeepPayment(list);

        this.QueueUpkeepPayment(list);
        Facepunch.Pool.FreeList <ItemAmount>(ref list);
        this.ApplyUpkeepPayment();
        if (!flag)
        {
            return(0f);
        }
        return(deltaTime);
    }
Exemple #28
0
 public void Add(DecayEntity ent)
 {
     if (ent.buildingID == 0)
     {
         if (!this.decayEntities.Contains(ent))
         {
             this.decayEntities.Add(ent);
         }
         return;
     }
     BuildingManager.Building building = this.GetBuilding(ent.buildingID);
     if (building == null)
     {
         building = this.CreateBuilding(ent.buildingID);
         this.buildingDictionary.Add(ent.buildingID, building);
     }
     building.Add(ent);
     building.Dirty();
 }
Exemple #29
0
    public float PurchaseUpkeepTime(DecayEntity entity, float deltaTime)
    {
        float             num        = CalculateUpkeepCostFraction();
        float             num2       = CalculateUpkeepPeriodMinutes() * 60f;
        float             multiplier = num * deltaTime / num2;
        List <ItemAmount> obj        = Facepunch.Pool.GetList <ItemAmount>();

        entity.CalculateUpkeepCostAmounts(obj, multiplier);
        bool num3 = CanAffordUpkeepPayment(obj);

        QueueUpkeepPayment(obj);
        Facepunch.Pool.FreeList(ref obj);
        ApplyUpkeepPayment();
        if (!num3)
        {
            return(0f);
        }
        return(deltaTime);
    }
    public static void BuildingDecayTouch(BuildingBlock buildingBlock)
    {
        if (ConVar.Decay.upkeep)
        {
            return;
        }
        List <DecayEntity> list = Facepunch.Pool.GetList <DecayEntity>();

        Vis.Entities <DecayEntity>(buildingBlock.transform.position, 40f, list, 2097408, QueryTriggerInteraction.Collide);
        for (int i = 0; i < list.Count; i++)
        {
            DecayEntity   item           = list[i];
            BuildingBlock buildingBlock1 = item as BuildingBlock;
            if (!buildingBlock1 || buildingBlock1.buildingID == buildingBlock.buildingID)
            {
                item.DecayTouch();
            }
        }
        Facepunch.Pool.FreeList <DecayEntity>(ref list);
    }