Example #1
0
    public static void BackupHelper(int EntityID, Vector3 awayFrom, int distance)
    {
        EntityAlive myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAlive;

        if (myEntity == null)
        {
            return;
        }

        if (myEntity.moveHelper == null)
        {
            return;
        }

        Vector3 dirV   = myEntity.position - awayFrom;
        Vector3 vector = Vector3.zero;

        vector = myEntity.position + -new Vector3(awayFrom.x, 0f, awayFrom.z) * distance;

        // If you are blocked, try to go to another side.
        //vector = RandomPositionGenerator.CalcAway(myEntity, distance, distance,distance, awayFrom);
        myEntity.moveHelper.SetMoveTo(vector, false);

        // Move away at a hard coded speed of -4 to make them go backwards
        //  myEntity.speedForward = -4f;// Mathf.SmoothStep(myEntity.speedForward, -0.25f, 2 * Time.deltaTime);

        // Keep them facing the spot
        myEntity.SetLookPosition(awayFrom);
        myEntity.RotateTo(awayFrom.x, awayFrom.y, awayFrom.z, 30f, 30f);
    }
        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;
                    }
                }
            }
        }