示例#1
0
    public static bool CheckFaction(int EntityID, EntityAlive entity)
    {
        bool        result   = false;
        EntityAlive myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAlive;

        if (myEntity == null)
        {
            return(result);
        }

        // same faction
        if (myEntity.factionId == entity.factionId)
        {
            return(true);
        }

        FactionManager.Relationship myRelationship = FactionManager.Instance.GetRelationshipTier(myEntity, entity);
        DisplayLog(" CheckFactionForEnemy: " + myRelationship.ToString());
        if (myRelationship == FactionManager.Relationship.Hate)
        {
            DisplayLog(" I hate this entity: " + entity.ToString());
            return(false);
        }
        else
        {
            DisplayLog(" My relationship with this " + entity.ToString() + " is: " + myRelationship.ToString());
            result = true;
        }
        return(false);
    }
        public static bool Postfix(bool __result, EAISetAsTargetIfHurt __instance)
        {
            EntityAlive targetEntity = null;

            if (__result)
            {
                // Do extra processing to see if your revenge target is your leader, or even part of the same faction as you are.
                if (__instance.theEntity.GetRevengeTarget() != null)
                {
                    targetEntity = __instance.theEntity.GetRevengeTarget();
                    Entity myLeader = EntityUtilities.GetLeaderOrOwner(__instance.theEntity.entityId);
                    if (myLeader)
                    {
                        if (targetEntity.entityId == myLeader.entityId)
                        {
                            __result = false;
                        }
                    }

                    // If the relationship is really positive, then forgive them for the attack.
                    FactionManager.Relationship myRelationship = FactionManager.Instance.GetRelationshipTier(__instance.theEntity, targetEntity);
                    if (myRelationship == FactionManager.Relationship.Love)
                    {
                        __result = false;
                    }
                }
            }

            return(__result);
        }
    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);
    }
示例#4
0
    public bool CheckFactionForEnemy(EntityAlive Entity)
    {
        FactionManager.Relationship myRelationship = FactionManager.Instance.GetRelationshipTier(this.theEntity, Entity);
        switch (myRelationship)
        {
        case FactionManager.Relationship.Hate:
            this.fleeDistance = 40;
            break;

        case FactionManager.Relationship.Dislike:
            this.fleeDistance = 20;
            break;

        case FactionManager.Relationship.Neutral:
            //this.fleeDistance = 10;
            //break;
            return(false);

        case FactionManager.Relationship.Like:
            return(false);

        case FactionManager.Relationship.Love:
            return(false);
        }

        return(true);
    }
示例#5
0
        public static bool Postfix(bool __result, EAITarget __instance, EntityAlive _e)
        {
            if (!EntityUtilities.IsHuman(__instance.theEntity.entityId))
            {
                return(__result);
            }

            if (__instance.theEntity.IsSleeping)
            {
                return(__result);
            }

            //  Debug.Log("Entity: " + __instance.theEntity.entityId + " Target: " + _e.entityId +  " + Result: " + __result);
            // The base class sees this as a valid target.
            if (__result)
            {
                // same faction
                if (__instance.theEntity.factionId == _e.factionId)
                {
                    return(false);
                }

                // if the attack cool down is applied, don't set a new target for 30 seconds.
                if (__instance.theEntity.Buffs.HasBuff("buffAttackCoolDown"))
                {
                    return(false);
                }

                // We have some complicated checks here, since this method gets called by 3 different target methods.
                FactionManager.Relationship myRelationship = FactionManager.Instance.GetRelationshipTier(__instance.theEntity, _e);
                // Debug.Log("Checking Relationship: " + myRelationship.ToString());
                switch (myRelationship)
                {
                case FactionManager.Relationship.Hate:
                    return(true);

                case FactionManager.Relationship.Dislike:
                case FactionManager.Relationship.Neutral:
                    // If you don't like them, or are more or less neutral to them,
                    // know the difference between an aggressive hit, or just a regular scan of entities.
                    if (__instance is EAISetNearestEntityAsTarget)
                    {
                        return(false);    // they aren't an enemy to kill right off
                    }
                    if (__instance is EAISetAsTargetIfHurt)
                    {
                        return(true);     // They suck! They hurt you. Get them!
                    }
                    return(false);

                default:
                    return(false);
                }
            }
            return(__result);
        }
        public static bool Postfix(bool __result, EAISetNearestEntityAsTarget __instance)
        {
            // If it's a zombie, don't do anything extra
            if (!EntityUtilities.IsHuman(__instance.theEntity.entityId))
            {
                return(__result);
            }


            // Check if we have any target in mind.
            EntityAlive targetEntity = __instance.targetEntity;

            if (targetEntity == null)
            {
                DisplayLog("No Target Entity", __instance.theEntity);
                return(__result);
            }

            DisplayLog("Postfix for CanExecute()", __instance.theEntity);
            // If we have a target, check if they are our leader, so we can forgive them.
            if (__result)
            {
                DisplayLog("Checking for Leader", __instance.theEntity);
                // If the Revenge Target is your leader, then forgive them?
                Entity myLeader = EntityUtilities.GetLeaderOrOwner(__instance.theEntity.entityId);
                if (myLeader)
                {
                    DisplayLog("Leader Found " + myLeader.entityId + ", checking ID", __instance.theEntity);
                    if (targetEntity.entityId == myLeader.entityId)
                    {
                        __result = false;
                    }
                }
            }

            // If we are still intent on attacking this target, check its faction, and see if we can forgive them.
            // If they don't really like them, it doesn't mean they want to kill them.
            if (__result)
            {
                DisplayLog("Checking Relationship with " + targetEntity.entityId, __instance.theEntity);
                FactionManager.Relationship myRelationship = FactionManager.Instance.GetRelationshipTier(__instance.theEntity, targetEntity);
                if (myRelationship != FactionManager.Relationship.Hate)
                {
                    __result = false;
                }
                DisplayLog("\tMRelationship with " + targetEntity.entityId + " is " + myRelationship.ToString(), __instance.theEntity);
            }

            DisplayLog("CanExecute(): " + __result, __instance.theEntity);
            return(__result);
        }
示例#7
0
 public bool CheckFactionForEnemy(EntityAlive Entity)
 {
     FactionManager.Relationship myRelationship = FactionManager.Instance.GetRelationshipTier(this.theEntity, Entity);
     if (myRelationship == FactionManager.Relationship.Hate)
     {
         DisplayLog(" I hate this entity: " + Entity.ToString());
         return(true);
     }
     else
     {
         DisplayLog(" My relationship with this " + Entity.ToString() + " is: " + myRelationship.ToString());
     }
     return(false);
 }
示例#8
0
        public static void Postfix(EntityAlive __instance)
        {
            // If it's a zombie, don't do anything extra
            if (__instance.HasAnyTags(FastTags.CombineTags(FastTags.Parse("zombie"), FastTags.Parse("hostile"))))
            {
                return;
            }

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

            // Scan the area around the Entity
            List <global::Entity> entitiesInBounds = GameManager.Instance.World.GetEntitiesInBounds(__instance, new Bounds(__instance.position, Vector3.one * 4f));

            if (entitiesInBounds.Count > 0)
            {
                for (int i = 0; i < entitiesInBounds.Count; i++)
                {
                    if (entitiesInBounds[i] is EntityPlayer)
                    {
                        // Check your faction relation. If you hate each other, don't stop and talk.
                        FactionManager.Relationship myRelationship = FactionManager.Instance.GetRelationshipTier(__instance, entitiesInBounds[i] as EntityAlive);
                        if (myRelationship == FactionManager.Relationship.Hate)
                        {
                            break;
                        }

                        // Give the player some space if NPC is too close.
                        if (__instance.GetDistance(entitiesInBounds[i]) < 1)
                        {
                            // Give the NPC a chance to move into position before facing the player.
                            __instance.moveHelper.SetMoveTo((entitiesInBounds[i] as EntityPlayer).GetLookVector(), false);
                            break;
                        }

                        // Turn to face the player, and stop the movement.
                        __instance.SetLookPosition(entitiesInBounds[i].getHeadPosition());
                        __instance.RotateTo(entitiesInBounds[i], 30f, 30f);
                        __instance.navigator.clearPath();
                        __instance.moveHelper.Stop();
                        break;
                    }
                }
            }
        }
示例#9
0
    //  <requirement type="Faction, Mods" requirementtype="Hide" value="neutral" />

    public override bool CheckRequirement(EntityPlayer player)
    {
        int entityID = 0;

        if (player.Buffs.HasCustomVar("CurrentNPC"))
        {
            entityID = (int)player.Buffs.GetCustomVar("CurrentNPC");
        }

        EntityAlive myEntity = player.world.GetEntity(entityID) as EntityAlive;

        if (myEntity != null)
        {
            FactionManager.Relationship myRelationship = FactionManager.Instance.GetRelationshipTier(myEntity, player);
            if (myRelationship.ToString().ToLower() == ID.ToLower())
            {
                return(true);
            }
        }
        return(false);
    }
示例#10
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;
                    }
                }
            }
        }
    }
示例#11
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;
                    }
                }
            }
        }
    }