Esempio n. 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);
    }
Esempio n. 2
0
 private void Start()
 {
     rg2d      = gameObject.GetComponent <Rigidbody2D>();
     anim      = gameObject.GetComponent <Animator>();
     enemyBoss = gameObject.GetComponentInParent <EnemyBoss>();
     door      = GameObject.FindGameObjectWithTag("BlockDoor").GetComponent <BlockDoor>();
 }
Esempio n. 3
0
    public static void CloseDoor(int EntityID, Vector3i blockPos)
    {
        EntityAlive myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAlive;

        if (myEntity)
        {
            BlockValue block = myEntity.world.GetBlock(blockPos);
            if (Block.list[block.type].HasTag(BlockTags.Door) && BlockDoor.IsDoorOpen(block.meta))
            {
                Chunk chunk = myEntity.world.GetChunkFromWorldPos(blockPos) as Chunk;
                block.Block.OnBlockActivated(myEntity.world, chunk.ClrIdx, blockPos, block, myEntity);
            }
        }
    }
    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;
                    }
                }
            }
        }
    }
Esempio n. 5
0
 private void Start()
 {
     col  = gameObject.GetComponent <Collider2D>();
     door = GameObject.FindGameObjectWithTag("BlockDoor").GetComponent <BlockDoor>();
 }
Esempio n. 6
0
        public static void IsInsideBlocks(ClientInfo _cInfo, EntityPlayer _player)
        {
            if (!_player.IsCrouching)
            {
                CameraPosition = new Vector3(_player.position.x, _player.position.y + 1.6f, _player.position.z);
            }
            else
            {
                CameraPosition = new Vector3(_player.position.x, _player.position.y + 1f, _player.position.z);
            }
            World      world         = GameManager.Instance.World;
            Vector3i   blockPosition = World.worldToBlockPos(CameraPosition);
            BlockValue blockValue    = world.GetBlock(blockPosition);

            if (blockValue.type != AirType)
            {
                Block block = blockValue.Block;
                if (block.IsCollideMovement)
                {
                    if (block.shape.IsTerrain())
                    {
                        if (blockValue.damage < block.MaxDamage * 0.75)
                        {
                            if (!_player.IsCrouching)
                            {
                                blockPosition.y--;
                                if (world.GetBlock(blockPosition).Block.IsCollideMovement)
                                {
                                    Detected(_cInfo);
                                    return;
                                }
                            }
                            else
                            {
                                Detected(_cInfo);
                                return;
                            }
                        }
                    }
                    else if (block is BlockDrawBridge)
                    {
                        Vector3i parentPos = block.multiBlockPos.GetParentPos(blockPosition, blockValue);
                        if (BlockDoor.IsDoorOpen(world.GetBlock(parentPos).meta) && blockPosition.y == parentPos.y)
                        {
                            Detected(_cInfo);
                            return;
                        }
                    }
                    else
                    {
                        string shape = block.shape.GetName().ToLower();
                        //Log.Out(string.Format("[SERVERTOOLS] Shape: {0}", shape));
                        if (shape == "cube" || shape == "cube_frame")
                        {
                            if (!_player.IsCrouching)
                            {
                                blockPosition.y--;
                                if (world.GetBlock(blockPosition).Block.IsCollideMovement)
                                {
                                    Detected(_cInfo);
                                    return;
                                }
                            }
                            else
                            {
                                Detected(_cInfo);
                                return;
                            }
                        }
                    }
                }
            }
            if (BlackScreen.Contains(_cInfo.entityId))
            {
                BlackScreen.Remove(_cInfo.entityId);
                _cInfo.SendPackage(new NetPackageConsoleCmdClient().Setup("ScreenEffect FadeToBlack 0 1", true));
            }
        }
Esempio n. 7
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();
    }
Esempio n. 8
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;
                    }
                }
            }
        }
    }