Пример #1
0
    public bool OpenDoor()
    {
        if (nextCheck < Time.time)
        {
            nextCheck = Time.time + CheckDelay;
            Vector3i blockPosition       = GetBlockPosition();
            Vector3i TargetBlockPosition = new Vector3i();

            int MaxDistance = 2;
            for (var x = blockPosition.x - MaxDistance; x <= blockPosition.x + MaxDistance; x++)
            {
                for (var z = blockPosition.z - MaxDistance; z <= blockPosition.z + MaxDistance; z++)
                {
                    TargetBlockPosition.x = x;
                    TargetBlockPosition.y = Utils.Fastfloor(position.y);
                    TargetBlockPosition.z = z;

                    // DisplayLog(" Target Block: " + TargetBlockPosition + " Block: " + this.world.GetBlock(TargetBlockPosition).Block.GetBlockName() + " My Position: " + this.GetBlockPosition());
                    BlockValue blockValue = world.GetBlock(TargetBlockPosition);
                    if (Block.list[blockValue.type].HasTag(BlockTags.Door) && !Block.list[blockValue.type].HasTag(BlockTags.Window))
                    {
                        DisplayLog(" I found a door.");

                        lastDoorOpen = TargetBlockPosition;
                        BlockDoor targetDoor = (Block.list[blockValue.type] as BlockDoor);


                        bool isDoorOpen = BlockDoor.IsDoorOpen(blockValue.meta);
                        if (isDoorOpen)
                        {
                            lastDoorOpen = Vector3i.zero;
                        }
                        else
                        {
                            lastDoorOpen = TargetBlockPosition;
                        }

                        emodel.avatarController.SetTrigger("OpenDoor");
                        DisplayLog(" Is Door Open? " + BlockDoor.IsDoorOpen(blockValue.meta));

                        Chunk chunk = (Chunk)world.GetChunkFromWorldPos(TargetBlockPosition);
                        TileEntitySecureDoor tileEntitySecureDoor = (TileEntitySecureDoor)world.GetTileEntity(0, TargetBlockPosition);
                        if (tileEntitySecureDoor == null)
                        {
                            DisplayLog(" Not a door.");
                            return(false);
                        }
                        if (tileEntitySecureDoor.IsLocked())
                        {
                            DisplayLog(" The Door is locked.");
                            return(false);
                        }
                        targetDoor.OnBlockActivated(world, 0, TargetBlockPosition, blockValue, null);
                        return(true);
                    }
                }
            }
        }
        return(false);
    }
Пример #2
0
 public BCMTileEntitySecureDoor(Vector3i pos, [NotNull] TileEntitySecureDoor te) : base(pos, te)
 {
     Owner       = te.GetOwner();
     Users       = te.GetUsers();
     HasPassword = te.HasPassword();
     IsLocked    = te.IsLocked();
 }
Пример #3
0
        public static bool Prefix(ref Block __instance, int _indexInBlockActivationCommands, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player)
        {
            // Check if this feature is enabled.
            if (!Configuration.CheckFeatureStatus(AdvFeatureClass, Feature))
            {
                return(true);
            }

            if (_blockValue.ischild)
            {
                return(true);
            }
            TileEntitySecureDoor tileEntitySecureDoor = (TileEntitySecureDoor)_world.GetTileEntity(_cIdx, _blockPos);

            if (tileEntitySecureDoor == null)
            {
                return(true);
            }


            if (!tileEntitySecureDoor.IsLocked() || tileEntitySecureDoor.IsUserAllowed(GamePrefs.GetString(EnumGamePrefs.PlayerId)))
            {
                return(true);
            }


            if (tileEntitySecureDoor.IsLocked())
            {
                // 1 == try to open locked door.
                if (_indexInBlockActivationCommands == 1)
                {
                    // Check if the player has lock picks.
                    LocalPlayerUI        playerUI        = (_player as EntityPlayerLocal).PlayerUI;
                    XUiM_PlayerInventory playerInventory = playerUI.xui.PlayerInventory;
                    ItemValue            item            = ItemClass.GetItem("resourceLockPick", false);
                    if (playerInventory.GetItemCount(item) == 0)
                    {
                        playerUI.xui.CollectedItemList.AddItemStack(new ItemStack(item, 0), true);
                        GameManager.ShowTooltip(_player as EntityPlayerLocal, Localization.Get("ttLockpickMissing"));
                        return(false);
                    }

                    tileEntitySecureDoor.SetLocked(true);
                    XUiC_PickLocking.Open(playerUI, tileEntitySecureDoor, _blockValue, _blockPos);
                    return(false);
                }
            }
            return(true);
        }
        public override void Execute(List <string> _params, CommandSenderInfo _senderInfo)
        {
            try
            {
                if (_params.Count != 1)
                {
                    SingletonMonoBehaviour <SdtdConsole> .Instance.Output(string.Format("[SERVERTOOLS] Wrong number of arguments, expected 1, found '{0}'", _params.Count));

                    return;
                }
                if (!string.IsNullOrEmpty(_senderInfo.RemoteClientInfo.CrossplatformId.CombinedString))
                {
                    LinkedList <Chunk> chunkArray = new LinkedList <Chunk>();
                    DictionaryList <Vector3i, TileEntity> tiles = new DictionaryList <Vector3i, TileEntity>();
                    ChunkClusterList chunklist = GameManager.Instance.World.ChunkClusters;
                    for (int i = 0; i < chunklist.Count; i++)
                    {
                        ChunkCluster chunk = chunklist[i];
                        chunkArray = chunk.GetChunkArray();
                        foreach (Chunk _c in chunkArray)
                        {
                            tiles = _c.GetTileEntities();
                            foreach (TileEntity tile in tiles.dict.Values)
                            {
                                TileEntityType type = tile.GetTileEntityType();
                                if (type.ToString().Equals("SecureDoor"))
                                {
                                    TileEntitySecureDoor SecureDoor = (TileEntitySecureDoor)tile;
                                    if (!SecureDoor.IsUserAllowed(_senderInfo.RemoteClientInfo.CrossplatformId))
                                    {
                                        List <PlatformUserIdentifierAbs> _users = SecureDoor.GetUsers();
                                        _users.Add(_senderInfo.RemoteClientInfo.CrossplatformId);
                                        SecureDoor.SetModified();
                                    }
                                }
                            }
                        }
                    }
                }
                SingletonMonoBehaviour <SdtdConsole> .Instance.Output(string.Format("[SERVERTOOLS] Door access set for '{0}'", _senderInfo.RemoteClientInfo.CrossplatformId.CombinedString));
            }
            catch (Exception e)
            {
                Log.Out(string.Format("[SERVERTOOLS] Error in SecureDoorAccess.Execute: {0}", e.Message));
            }
        }
Пример #5
0
    public override void OnUpdateLive()
    {
        // Wake them up if they are sleeping, since the trigger sleeper makes them go idle again.
        if (!this.sleepingOrWakingUp && isAlwaysAwake)
        {
            this.IsSleeping = true;
            ConditionalTriggerSleeperWakeUp();
        }

        emodel.avatarController.SetBool("IsBusy", false);

        Buffs.RemoveBuff("buffnewbiecoat", false);
        Stats.Health.MaxModifier = Stats.Health.Max;

        // Set CanFall and IsOnGround
        if (this.emodel != null && this.emodel.avatarController != null)
        {
            this.emodel.avatarController.SetBool("CanFall", !this.emodel.IsRagdollActive && this.bodyDamage.CurrentStun == EnumEntityStunType.None && !this.isSwimming);
            this.emodel.avatarController.SetBool("IsOnGround", this.onGround || this.isSwimming);
        }

        if (SingletonMonoBehaviour <ConnectionManager> .Instance.IsServer)
        {
            //If blocked, check to see if its a door.
            if (moveHelper.IsBlocked)
            {
                Vector3i   blockPos = moveHelper.HitInfo.hit.blockPos;
                BlockValue block    = world.GetBlock(blockPos);
                if (Block.list[block.type].HasTag(BlockTags.Door) && !BlockDoor.IsDoorOpen(block.meta))
                {
                    bool canOpenDoor = true;
                    TileEntitySecureDoor tileEntitySecureDoor = GameManager.Instance.World.GetTileEntity(0, blockPos) as TileEntitySecureDoor;
                    if (tileEntitySecureDoor != null)
                    {
                        if (tileEntitySecureDoor.IsLocked() && tileEntitySecureDoor.GetOwner() == "")
                        {
                            canOpenDoor = false;
                        }
                    }
                    //TileEntityPowered poweredDoor = GameManager.Instance.World.GetTileEntity(0, blockPos) as TileEntityPowered;
                    //if (poweredDoor != null)
                    //{
                    //    if (poweredDoor.IsLocked() && poweredDoor.GetOwner() == "")
                    //        canOpenDoor = false;

                    //}
                    if (canOpenDoor)
                    {
                        DisplayLog("I am blocked by a door. Trying to open...");
                        SphereCache.AddDoor(entityId, blockPos);
                        EntityUtilities.OpenDoor(entityId, blockPos);
                        //  We were blocked, so let's clear it.
                        moveHelper.ClearBlocked();
                    }
                }
            }
        }

        // Check to see if we've opened a door, and close it behind you.
        Vector3i doorPos = SphereCache.GetDoor(entityId);

        if (doorPos != Vector3i.zero)
        {
            DisplayLog("I've opened a door recently. I'll see if I can close it.");
            BlockValue block = world.GetBlock(doorPos);
            if (Block.list[block.type].HasTag(BlockTags.Door) && BlockDoor.IsDoorOpen(block.meta))
            {
                float CloseDistance = 3;
                // If it's a multidim, increase tha radius a bit
                if (Block.list[block.type].isMultiBlock)
                {
                    Vector3i vector3i = StringParsers.ParseVector3i(Block.list[block.type].Properties.Values["MultiBlockDim"], 0, -1, false);
                    if (CloseDistance > vector3i.x)
                    {
                        CloseDistance = vector3i.x + 1;
                    }
                }
                if ((GetDistanceSq(doorPos.ToVector3()) > CloseDistance))
                {
                    DisplayLog("I am going to close the door now.");
                    EntityUtilities.CloseDoor(entityId, doorPos);
                    SphereCache.RemoveDoor(entityId, doorPos);
                }
            }
        }

        // Makes the NPC always face its attack or revent target.
        EntityAlive target = EntityUtilities.GetAttackOrReventTarget(entityId) as EntityAlive;

        if (target != null)
        {
            // makes the npc look at its attack target
            if (this.emodel != null && this.emodel.avatarController != null)
            {
                this.emodel.SetLookAt(target.getHeadPosition());
            }

            SetLookPosition(target.getHeadPosition());
            RotateTo(target, 45, 45);

            if (EntityUtilities.HasTask(this.entityId, "Ranged"))
            {
                if (EntityUtilities.CheckAIRange(this.entityId, target.entityId))
                {
                    EntityUtilities.ChangeHandholdItem(this.entityId, EntityUtilities.Need.Ranged);
                }
                else
                {
                    EntityUtilities.ChangeHandholdItem(this.entityId, EntityUtilities.Need.Melee);
                }
            }
            else
            {
                EntityUtilities.ChangeHandholdItem(this.entityId, EntityUtilities.Need.Melee);
            }
        }


        // Non-player entities don't fire all the buffs or stats, so we'll manually fire the water tick,
//        Stats.Water.Tick(0.5f, 0, false);

        // then fire the updatestats over time, which is protected from a IsPlayer check in the base onUpdateLive().
        //Stats.UpdateStatsOverTime(0.5f);


        updateTime = Time.time + 2f;
        base.OnUpdateLive();

        // Allow EntityAliveSDX to get buffs from blocks
        if (!this.isEntityRemote)
        {
            updateBlockRadiusEffects();
        }

        // No NPC info, don't continue
        if (NPCInfo == null)
        {
            return;
        }

        // If the Tile Entity Trader isn't set, set it now. Sometimes this fails, and won't allow interaction.
        if (TileEntityTrader == null)
        {
            TileEntityTrader                     = new TileEntityTrader(null);
            TileEntityTrader.entityId            = entityId;
            TileEntityTrader.TraderData.TraderID = NPCInfo.TraderID;
        }

        // If there is no attack target, don't bother checking this.
        if (target == null)
        {
            if (this is EntityAliveFarmingAnimalSDX)
            {
                return;
            }

            List <global::Entity> entitiesInBounds = GameManager.Instance.World.GetEntitiesInBounds(this, new Bounds(position, Vector3.one * 5f));
            if (entitiesInBounds.Count > 0)
            {
                for (int i = 0; i < entitiesInBounds.Count; i++)
                {
                    if (entitiesInBounds[i] is EntityPlayerLocal || entitiesInBounds[i] is EntityPlayer)
                    {
                        // Check your faction relation. If you hate each other, don't stop and talk.
                        FactionManager.Relationship myRelationship = FactionManager.Instance.GetRelationshipTier(this, entitiesInBounds[i] as EntityPlayerLocal);
                        if (myRelationship == FactionManager.Relationship.Hate)
                        {
                            break;
                        }

                        if (GetDistance(entitiesInBounds[i]) < 1 && this.moveHelper != null)
                        {
                            DisplayLog("The entity is too close to me. Moving away: " + entitiesInBounds[i].ToString());
                            EntityUtilities.BackupHelper(entityId, entitiesInBounds[i].position, 3);
                            break;
                        }

                        // Turn to face the player, and stop the movement.
                        emodel.avatarController.SetBool("IsBusy", true);
                        SetLookPosition(entitiesInBounds[i].getHeadPosition());
                        RotateTo(entitiesInBounds[i], 90f, 90f);
                        EntityUtilities.Stop(this.entityId);
                        break;
                    }
                }
            }
        }
    }
Пример #6
0
    public override void OnUpdateLive()
    {
        if (SingletonMonoBehaviour <ConnectionManager> .Instance.IsServer)
        {
            //If blocked, check to see if its a door.
            if (moveHelper.IsBlocked)
            {
                Vector3i   blockPos = moveHelper.HitInfo.hit.blockPos;
                BlockValue block    = world.GetBlock(blockPos);
                if (Block.list[block.type].HasTag(BlockTags.Door) && !BlockDoor.IsDoorOpen(block.meta))
                {
                    bool canOpenDoor = true;
                    TileEntitySecureDoor tileEntitySecureDoor = GameManager.Instance.World.GetTileEntity(0, blockPos) as TileEntitySecureDoor;
                    if (tileEntitySecureDoor != null)
                    {
                        if (tileEntitySecureDoor.IsLocked() && tileEntitySecureDoor.GetOwner() == "")
                        {
                            canOpenDoor = false;
                        }
                    }
                    //TileEntityPowered poweredDoor = GameManager.Instance.World.GetTileEntity(0, blockPos) as TileEntityPowered;
                    //if (poweredDoor != null)
                    //{
                    //    if (poweredDoor.IsLocked() && poweredDoor.GetOwner() == "")
                    //        canOpenDoor = false;

                    //}
                    if (canOpenDoor)
                    {
                        DisplayLog("I am blocked by a door. Trying to open...");
                        SphereCache.AddDoor(entityId, blockPos);
                        EntityUtilities.OpenDoor(entityId, blockPos);
                        //  We were blocked, so let's clear it.
                        moveHelper.ClearBlocked();
                    }
                }
            }
        }

        // Check to see if we've opened a door, and close it behind you.
        Vector3i doorPos = SphereCache.GetDoor(entityId);

        if (doorPos != Vector3i.zero)
        {
            DisplayLog("I've opened a door recently. I'll see if I can close it.");
            BlockValue block = world.GetBlock(doorPos);
            if (Block.list[block.type].HasTag(BlockTags.Door) && BlockDoor.IsDoorOpen(block.meta))
            {
                float CloseDistance = 3;
                // If it's a multidim, increase tha radius a bit
                if (Block.list[block.type].isMultiBlock)
                {
                    Vector3i vector3i = StringParsers.ParseVector3i(Block.list[block.type].Properties.Values["MultiBlockDim"], 0, -1, false);
                    if (CloseDistance > vector3i.x)
                    {
                        CloseDistance = vector3i.x + 1;
                    }
                }
                if ((GetDistanceSq(doorPos.ToVector3()) > CloseDistance))
                {
                    DisplayLog("I am going to close the door now.");
                    EntityUtilities.CloseDoor(entityId, doorPos);
                    SphereCache.RemoveDoor(entityId, doorPos);
                }
            }
        }

        // Makes the NPC always face its attack or revent target.
        EntityAlive target = EntityUtilities.GetAttackOrReventTarget(entityId) as EntityAlive;

        if (target != null)
        {
            // makes the npc look at its attack target
            if (this.emodel != null && this.emodel.avatarController != null)
            {
                this.emodel.SetLookAt(target.getHeadPosition());
            }

            SetLookPosition(target.getHeadPosition());
            RotateTo(target, 45, 45);
        }
        Buffs.RemoveBuff("buffnewbiecoat", false);
        Stats.Health.MaxModifier = Stats.Health.Max;

        // Set CanFall and IsOnGround
        if (this.emodel != null && this.emodel.avatarController != null)
        {
            this.emodel.avatarController.SetBool("CanFall", !this.emodel.IsRagdollActive && this.bodyDamage.CurrentStun == EnumEntityStunType.None && !this.isSwimming);
            this.emodel.avatarController.SetBool("IsOnGround", this.onGround || this.isSwimming);
        }


        // Non-player entities don't fire all the buffs or stats, so we'll manually fire the water tick,
        Stats.Water.Tick(0.5f, 0, false);

        // then fire the updatestats over time, which is protected from a IsPlayer check in the base onUpdateLive().
        Stats.UpdateStatsOverTime(0.5f);


        base.OnUpdateLive();
    }
Пример #7
0
    public override void OnUpdateLive()
    {
        //If blocked, check to see if its a door.
        if (moveHelper.IsBlocked)
        {
            Vector3i   blockPos = moveHelper.HitInfo.hit.blockPos;
            BlockValue block    = world.GetBlock(blockPos);
            if (Block.list[block.type].HasTag(BlockTags.Door) && !BlockDoor.IsDoorOpen(block.meta))
            {
                bool canOpenDoor = true;
                TileEntitySecureDoor tileEntitySecureDoor = GameManager.Instance.World.GetTileEntity(0, blockPos) as TileEntitySecureDoor;
                if (tileEntitySecureDoor != null)
                {
                    if (tileEntitySecureDoor.IsLocked() && tileEntitySecureDoor.GetOwner() == "")
                    {
                        canOpenDoor = false;
                    }
                }
                //TileEntityPowered poweredDoor = GameManager.Instance.World.GetTileEntity(0, blockPos) as TileEntityPowered;
                //if (poweredDoor != null)
                //{
                //    if (poweredDoor.IsLocked() && poweredDoor.GetOwner() == "")
                //        canOpenDoor = false;

                //}
                if (canOpenDoor)
                {
                    DisplayLog("I am blocked by a door. Trying to open...");
                    SphereCache.AddDoor(entityId, blockPos);
                    EntityUtilities.OpenDoor(entityId, blockPos);
                    //  We were blocked, so let's clear it.
                    moveHelper.ClearBlocked();
                }
            }
        }


        // Check to see if we've opened a door, and close it behind you.
        Vector3i doorPos = SphereCache.GetDoor(entityId);

        if (doorPos != Vector3i.zero)
        {
            DisplayLog("I've opened a door recently. I'll see if I can close it.");
            BlockValue block = world.GetBlock(doorPos);
            if (Block.list[block.type].HasTag(BlockTags.Door) && BlockDoor.IsDoorOpen(block.meta))
            {
                float CloseDistance = 3;
                // If it's a multidim, increase tha radius a bit
                if (Block.list[block.type].isMultiBlock)
                {
                    Vector3i vector3i = StringParsers.ParseVector3i(Block.list[block.type].Properties.Values["MultiBlockDim"], 0, -1, false);
                    if (CloseDistance > vector3i.x)
                    {
                        CloseDistance = vector3i.x + 1;
                    }
                }
                if ((GetDistanceSq(doorPos.ToVector3()) > CloseDistance))
                {
                    DisplayLog("I am going to close the door now.");
                    EntityUtilities.CloseDoor(entityId, doorPos);
                    SphereCache.RemoveDoor(entityId, doorPos);
                }
            }
        }

        // Makes the NPC always face its attack or revent target.
        EntityAlive target = EntityUtilities.GetAttackOrReventTarget(entityId) as EntityAlive;

        if (target != null)
        {
            SetLookPosition(attackTarget.position);
            RotateTo(attackTarget, 45, 45);
        }
        Buffs.RemoveBuff("buffnewbiecoat", false);
        Stats.Health.MaxModifier = Stats.Health.Max;


        // Non-player entities don't fire all the buffs or stats, so we'll manually fire the water tick,
        Stats.Water.Tick(0.5f, 0, false);

        // then fire the updatestats over time, which is protected from a IsPlayer check in the base onUpdateLive().
        Stats.UpdateStatsOverTime(0.5f);


        updateTime = Time.time - 2f;
        base.OnUpdateLive();

        // No NPC info, don't continue
        if (NPCInfo == null)
        {
            return;
        }

        // If the Tile Entity Trader isn't set, set it now. Sometimes this fails, and won't allow interaction.
        if (TileEntityTrader == null)
        {
            TileEntityTrader                     = new TileEntityTrader(null);
            TileEntityTrader.entityId            = entityId;
            TileEntityTrader.TraderData.TraderID = NPCInfo.TraderID;
        }

        // Check if there's a player within 10 meters of us. If not, resume wandering.
        emodel.avatarController.SetBool("IsBusy", false);

        if (!SingletonMonoBehaviour <ConnectionManager> .Instance.IsServer)
        {
            return;
        }

        if (target == null)
        {
            if (this is EntityAliveFarmingAnimalSDX)
            {
                return;
            }

            List <global::Entity> entitiesInBounds = GameManager.Instance.World.GetEntitiesInBounds(this, new Bounds(position, Vector3.one * 5f));
            if (entitiesInBounds.Count > 0)
            {
                for (int i = 0; i < entitiesInBounds.Count; i++)
                {
                    if (entitiesInBounds[i] is EntityPlayerLocal)
                    {
                        // Check your faction relation. If you hate each other, don't stop and talk.
                        FactionManager.Relationship myRelationship = FactionManager.Instance.GetRelationshipTier(this, entitiesInBounds[i] as EntityPlayerLocal);
                        if (myRelationship == FactionManager.Relationship.Hate)
                        {
                            break;
                        }

                        if (GetDistance(entitiesInBounds[i]) < 2)
                        {
                            DisplayLog("The entity is too close to me. Moving away: " + entitiesInBounds[i].ToString());
                            EntityUtilities.BackupHelper(entityId, entitiesInBounds[i].position, 5);
                            //moveHelper.SetMoveTo((entitiesInBounds[i] as EntityPlayerLocal).GetLookVector(), false);
                            break;
                        }


                        // Turn to face the player, and stop the movement.
                        emodel.avatarController.SetBool("IsBusy", true);

                        SetLookPosition(entitiesInBounds[i].getHeadPosition());
                        RotateTo(entitiesInBounds[i], 90f, 90f);
                        navigator.clearPath();
                        moveHelper.Stop();

                        // this stops the walking jitter
                        this.speedForward = 0;
                        break;
                    }
                }
            }
        }
    }