public BCMTileEntitySecureDoor(Vector3i pos, TileEntitySecureDoor te) : base(pos, te)
 {
     Owner       = te.GetOwner();
     Users       = te.GetUsers();
     HasPassword = te.HasPassword();
     IsLocked    = te.IsLocked();
 }
    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;
                    }
                }
            }
        }
    }
Exemple #3
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();
    }
Exemple #4
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;
                    }
                }
            }
        }
    }