Пример #1
0
    public override bool OnEntityActivated(int _indexInBlockActivationCommands, Vector3i _tePos, EntityAlive _entityFocusing)
    {
        // Don't allow interaction with a Hated entity
        FactionManager.Relationship myRelationship = FactionManager.Instance.GetRelationshipTier(this, _entityFocusing);
        if (myRelationship == FactionManager.Relationship.Hate)
        {
            return(false);
        }

        // If they have attack targets, don't interrupt them.
        if (GetAttackTarget() != null || GetRevengeTarget() != null)
        {
            return(false);
        }

        // set the IsBusy flag, so it won't wander away when you are talking to it.
        emodel.avatarController.SetBool("IsBusy", true);

        // Look at the entity that is talking to you.
        SetLookPosition(_entityFocusing.getHeadPosition());

        // This is used by various dialog boxes to know which EntityID the player is talking too.
        _entityFocusing.Buffs.SetCustomVar("CurrentNPC", entityId, true);

        base.OnEntityActivated(_indexInBlockActivationCommands, _tePos, _entityFocusing);


        SetSpawnerSource(EnumSpawnerSource.StaticSpawner);

        return(true);
    }
Пример #2
0
    public override bool OnEntityActivated(int _indexInBlockActivationCommands, Vector3i _tePos, EntityAlive _entityFocusing)
    {
        // set the IsBusy flag, so it won't wander away when you are talking to it.
        emodel.avatarController.SetBool("IsBusy", true);
        // Look at the entity that is talking to you.
        SetLookPosition(_entityFocusing.getHeadPosition());

        _entityFocusing.Buffs.SetCustomVar("CurrentNPC", entityId, true);
        base.OnEntityActivated(_indexInBlockActivationCommands, _tePos, _entityFocusing);

        return(true);
    }
Пример #3
0
    public override bool OnEntityActivated(int _indexInBlockActivationCommands, Vector3i _tePos, EntityAlive _entityFocusing)
    {
        // set the IsBusy flag, so it won't wander away when you are talking to it.
        this.emodel.avatarController.SetBool("IsBusy", true);

        // Look at the entity that is talking to you.
        this.SetLookPosition(_entityFocusing.getHeadPosition());

        // Add a reference for the dialog otherEntitySDX to the UI, since the respondent doesn't always carry forward
        LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(_entityFocusing as EntityPlayerLocal);

        uiforPlayer.xui.Dialog.otherEntitySDX = this;
        base.OnEntityActivated(_indexInBlockActivationCommands, _tePos, _entityFocusing);


        return(true);
    }
Пример #4
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;
                    }
                }
            }
        }
    }
Пример #5
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();
    }