상속: MonoBehaviour
예제 #1
0
    public override void Act(NPCAI npc, Scannable target)
    {
        NavMeshAgent agent = npc.GetComponent <NavMeshAgent>();

        //Debug.Log("isStopped" + agent.isStopped);
        IsMoving = !agent.isStopped;
    }
    [SerializeField] TargetFilter[] filters; //Filter criteria, all of which must be met for a target to be considered valid.

    /// <summary>
    /// Filter out any invalid targets, and then, if there are any valid targets, return one based on the selection criteria.
    /// </summary>
    /// <param name="targets"></param>
    /// <returns></returns>
    public Scannable FilterAndSelect(ICollection <Scannable> targets, NPCAI npc)
    {
        //Filter targets based on given filter.
        List <Scannable> validTargets = new List <Scannable>();

        foreach (Scannable target in targets)
        {
            //The target must pass all filters to be considered valid.
            bool targetValid = true;
            foreach (TargetFilter filter in filters)
            {
                if (!filter.IsValidTarget(target, npc))
                {
                    //As soon as a target fails a filter, there is no point in continuing.
                    targetValid = false;
                    break;
                }
            }

            if (targetValid)
            {
                validTargets.Add(target);
            }
        }


        if (validTargets.Count == 0)
        {
            return(null);
        }
        else
        {
            return(SelectTarget(validTargets, npc));
        }
    }
    public override void Act(NPCAI npc, Scannable target)
    {
        //Move towrds the target on the x and z axes, but not the y axis.
        Vector3 targetPosition = new Vector3(target.transform.position.x, npc.transform.position.y, target.transform.position.z);

        MoveNPCTowardsPosition(npc, targetPosition, movementSpeed, turnSpeed);
    }
예제 #4
0
            void Awake()
            {
                RustAI = GetComponent <NPCAI>();
                RustAI.ServerDestroy();
                RustMetabolism = GetComponent <NPCMetabolism>();
                Base           = GetComponent <BaseNPC>();

                lastTick    = Time.time;
                targetpoint = Vector3.zero;
                action      = Act.None;

                hungerLose  = RustMetabolism.calories.max * 2 / 12000;
                thristyLose = RustMetabolism.hydration.max * 3 / 12000;
                sleepLose   = RustMetabolism.sleep.max / 12000;

                inventory = new ItemContainer();
                inventory.ServerInitialize(null, 6);

                Base.enableSaving = false;
                BaseEntity.saveList.Remove(Base);
                Base.InitializeHealth(Base.health * HealthModificator, Base.MaxHealth() * HealthModificator);
                Base.locomotion.gallopSpeed  *= SpeedModificator;
                Base.locomotion.trotSpeed    *= SpeedModificator;
                Base.locomotion.acceleration *= SpeedModificator;
            }
예제 #5
0
        public void ShootInPlayer_InViewScope_Success()
        {
            //Arrange
            var player = new PlayerBody(new ShapeCircle(2, new Point(10, 10)),
                                        new Vector(0, 0), null, null, 0, 0, "Bob", 100, 1);

            var viewPort = Substitute.For <IActiveBodyEyesight>();

            viewPort.GetFrame(Arg.Any <Guid>(), Arg.Any <IMapTile>()).Returns(v =>
                                                                              new ViewFrame()
            {
                Bodies = new List <Body> {
                    player
                }
            });

            var mechanicEngine = Substitute.For <IMechanicEngine>();

            mechanicEngine.ViewPort.Returns(v => viewPort);

            var weapon = Substitute.For <WeaponBase>(10, 100, mechanicEngine, "Gun");

            var npc = new NPCAI(new ShapeCircle(2, new Point(20, 20)), mechanicEngine, 10, 10, 100, 1);

            npc.AddWeapon(weapon);

            //Act
            npc.UpdateState();

            //Assert
            weapon.Received().Shoot(Arg.Any <Point>(), Arg.Any <Vector>(), npc.Id);
        }
예제 #6
0
    IEnumerator SetupBattle()
    {
        //set up enemy and enemy AI
        // GameObject enemyGO = Instantiate(enemyPrefab);
        GameObject enemyGO = enemyPrefab;

        enemy   = enemyGO.GetComponent <NPC>();
        enemyAI = enemyGO.GetComponent <NPCAI>();

        //display starting message
        dialogueBox.gameObject.SetActive(true);
        dialogueText.text = "A monster approaches.";

        //set HUDs
        enemyHUD.SetEnemyHUD(enemy);
        playerHUD.SetPlayerHUD();

        yield return(new WaitForSeconds(2f));

        dialogueText.text = "What will you do?";

        yield return(new WaitForSeconds(2f));

        dialogueBox.gameObject.SetActive(false);

        //start the battle, move to player turn
        state = BattleState.PLAYERTURN;
        PlayerTurn();
    }
예제 #7
0
 public WorkDesire(NPCAI pAI, NPC pNPC)
 {
     base.currentDegree = 60f;
     base.maxDegree     = 100f;
     base.owner         = pAI;
     myMaster           = pNPC;
 }
예제 #8
0
        public static void FightRoutine(NPCProto npc)
        {
            //Draw Weapon:


            NPCAI    ai    = npc.getAI();
            NPCProto enemy = ai.EnemyList.First.Value;

            npc.readyBestWeapon(enemy);



            if (enemy.HP == 0)
            {
                ai.EnemyList.Remove(enemy);
                npc.standAnim();
                npc.unreadyWeapon();
                return;
            }
            else if ((enemy.Position - npc.Position).Length > 3000)//Stop running!
            {
                ai.EnemyList.Remove(enemy);
                npc.standAnim();
                npc.unreadyWeapon();
                return;
            }

            if (npc.getAI().FightStates.First != null)
            {
                npc.getAI().FightStates.First.Value.update();
                return;
            }


            npc.turnToPosition(enemy.Position);
            if (rand.NextDouble() > 0.5)
            {
                npc.getAI().FightStates.AddLast(new AnimState(npc, "T_FISTPARADEJUMPB"));
                npc.getAI().FightStates.AddLast(new WaitState(npc, 10000 * 100));
            }

            if (npc.Position.getDistance(enemy.Position) > npc.getAttackRange())
            {
                npc.getAI().FightStates.AddLast(new GotoState(npc, enemy, npc.getAttackRange()));
            }
            else
            {
                npc.getAI().FightStates.AddLast(new AnimState(npc, npc.getFightRunAnimation()));
                npc.getAI().FightStates.AddLast(new DamageState(npc, enemy));
                npc.getAI().FightStates.AddLast(new WaitState(npc, 10000 * 200));
            }


            //if (npc.gotoPosition(enemy.Position, 200))
            //{
            //    npc.standAnim();
            //    npc.playAnimation(npc.getFightAnimation());
            //}
        }
    public static void MoveNPCTowardsPosition(NPCAI npc, Vector3 targetPosition, float movementSpeed, float turnSpeed)
    {
        //Move the npc a step towards the target.
        npc.transform.position = Vector3.MoveTowards(npc.transform.position, targetPosition, movementSpeed * Time.deltaTime);

        //Turn the npc towards the target.
        TurnTowards.Turn(targetPosition, npc.transform, turnSpeed);
    }
예제 #10
0
    public override void Plan(NPCAI npc, Scannable target)
    {
        //  Find the furtherest point you can get to for adjustmentDirections evenly distributed directions around a circle, if you try to travel
        //target distance in that direction.
        Vector3[] points     = new Vector3[adjustmentDirections];
        float     angleSteps = 360f / adjustmentDirections;

        for (int i = 0; i < points.Length; i++)
        {
            //Raycast in each direction around the circle.
            Vector3 currentDirection = Quaternion.Euler(0, angleSteps * i, 0) * Vector3.forward;

            Ray          ray  = new Ray(npc.transform.position, currentDirection);
            RaycastHit[] hits = Physics.RaycastAll(ray, targetDistance);

            //Find closest hit for each direction.
            if (hits.Length <= 0)
            {
                //If there were no hits, the NPC can move target distance in the current direction.
                points[i] = ray.GetPoint(targetDistance);
                continue;
            }
            else
            {
                //If there were hits, find the closest.
                Vector3 closestHitPoint = hits[0].point;
                for (int j = 1; j < hits.Length; j++)
                {
                    float distanceToClosestPoint = Vector3.Distance(closestHitPoint, npc.transform.position);
                    float distanceToCurrentPoint = Vector3.Distance(hits[j].point, npc.transform.position);

                    if (distanceToCurrentPoint < distanceToClosestPoint)
                    {
                        closestHitPoint = hits[j].point;
                    }
                }

                points[i] = closestHitPoint;
            }
        }

        //Find furthest point from target - that is the target point.
        Vector3 furtherestPointFromTarget = points[0];

        for (int i = 1; i < points.Length; i++)
        {
            float distanceBetweenFurthestPointAndTarget = Vector3.Distance(furtherestPointFromTarget, target.transform.position);
            float distanceBetweenCurrentPointAndTarget  = Vector3.Distance(points[i], target.transform.position);

            if (distanceBetweenCurrentPointAndTarget > distanceBetweenFurthestPointAndTarget)
            {
                furtherestPointFromTarget = points[i];
            }
        }

        targetPosition = furtherestPointFromTarget;
    }
예제 #11
0
 void Awake()
 {
     Options      = GameObject.Find("Options").GetComponent <PanelScript>();
     Speech       = GameObject.Find("DialoguePanel").GetComponent <PanelScript>();
     NameText     = GameObject.Find("Name").GetComponent <Text>();
     DialogueText = GameObject.Find("Dialogue").GetComponent <Text>();
     nPCAI        = GameObject.Find("NPC").GetComponent <NPCAI>();
     playerNav    = GameObject.Find("PlayerNav").GetComponent <Image>();
 }
예제 #12
0
 // Start is called before the first frame update
 void Awake()
 {
     nameText     = GameObject.Find("Name").GetComponent <Text>();
     dialogueText = GameObject.Find("Dialogue").GetComponent <Text>();
     //options = GameObject.Find("Options").GetComponent<PanelScript>();
     display = GameObject.Find("DialoguePanel").GetComponent <PanelScript>();
     nPCAI   = GameObject.Find("NPC").GetComponent <NPCAI>();
     //playerNav = GameObject.Find("PlayerNav").GetComponent<Image>();
     player = GameObject.Find("PlayerController").GetComponent <SMPlayerStats>();
 }
예제 #13
0
 void Awake()
 {
     AI               = GetComponent <NPCAI>();
     NPC              = GetComponent <BaseNPC>();
     Metabolism       = GetComponent <NPCMetabolism>();
     isAttacking      = false;
     Target           = null;
     NPC.state        = BaseNPC.State.Normal;
     NPC.enableSaving = false;
     BaseEntity.saveList.Remove(NPC);
 }
예제 #14
0
    public override void Cease(NPCAI npc, Scannable target)
    {
        NavMeshAgent agent = npc.GetComponent <NavMeshAgent>();

        if (agent == null)
        {
            throw new System.Exception(npc.name + " is trying to use the NavigateTowards behavour without having a NavMeshAgent");
        }

        agent.ResetPath();
    }
예제 #15
0
    private void Start()
    {
        movement = GetComponent <NPCMovement>();
        combat   = GetComponent <EnemyCombat>();
        ai       = GetComponent <NPCAI>();

        // spawnPoint = transform.position;
        spawnPoint = transform.localPosition;

        curState = EnemyStates.Wandering;
    }
예제 #16
0
    private void SetAttackTarget(NPCAI npc, GameObject target)
    {
        AttackAnimationEventHandler handler = npc.GetComponent <AttackAnimationEventHandler>();

        if (handler == null)
        {
            throw new System.Exception("The npc " + npc.name + " does not have an AttackAnimationEventHandler attatched.");
        }

        handler.target = target;
    }
예제 #17
0
    /// <summary>
    /// Sets the NavMeshAgent destination to the position of the target, if it exists.
    /// </summary>
    /// <param name="npc"></param>
    /// <param name="target"></param>
    private void NaviagteTowardsTarget(NPCAI npc, Scannable target)
    {
        NavMeshAgent agent = npc.GetComponent <NavMeshAgent>();

        if (agent == null)
        {
            throw new System.Exception(npc.name + " is trying to use the NavigateTowards behavour without having a NavMeshAgent");
        }

        agent.speed = moveSpeed;
        agent.SetDestination(target.transform.position);
    }
예제 #18
0
    void Start()
    {
        root = gameObject.transform.parent.gameObject;

        /*if (root.GetComponent<AntAI>())
         * {
         *  AntScript = root.GetComponent<AntAI>();
         *  whichScript = 1;
         * }
         * else if (root.GetComponent<DemigodAI>())
         * {
         *  DemigodScript = root.GetComponent<DemigodAI>();
         *  whichScript = 2;
         * }
         * else if (root.GetComponent<MinotaurAI>())
         * {
         *  MinotaurScript = root.GetComponent<MinotaurAI>();
         *  whichScript = 3;
         * }
         * else if (root.GetComponent<MedusaAI>())
         * {
         *  MedusaScript = root.GetComponent<MedusaAI>();
         *  whichScript = 4;
         * }
         * else if (root.GetComponent<PlayerHealth>())
         * {
         *  PlayerScript = root.GetComponent<PlayerHealth>();
         *  whichScript = 5;
         * }
         * else if (root.GetComponent<ChimeraAI>())
         * {
         *  ChimeraScript = root.GetComponent<ChimeraAI>();
         *  whichScript = 6;
         * }
         * else if (root.GetComponent<CTFCamperAI>())
         * {
         *  CTFScript = root.GetComponent<CTFCamperAI>();
         *  whichScript = 7;
         * }*/
        if (root.GetComponent <NPCAI>())
        {
            AIScript = root.GetComponent <NPCAI>();//Means this script is attached to an NPC instead of the player
            onPlayer = false;
        }

        else if (root.GetComponent <PlayerHealth>())
        {
            PlayerScript = root.GetComponent <PlayerHealth>();//This script is attached to a player
            onPlayer     = true;
        }
    }
예제 #19
0
 // Update is called once per frame
 void Update()
 {
     if (activeNPC != null)
     {
         if (activeAI == null)
         {
             activeAI = activeNPC.GetComponent <NPCAI>();
         }
         Debug.Log(activeAI.getDisplay(state));
         if (Input.GetKeyDown(KeyCode.Alpha1))
         {
             state += 1;
         }
     }
 }
    public override void Plan(NPCAI npc, Scannable target)
    {
        float distance = Vector3.Distance(npc.transform.position, target.transform.position);

        //if scary thing is within avoid set new path directly away from scary thing
        if (distance < avoidDistance)
        {
            Vector3 dirToScare = npc.transform.position - target.transform.position;

            agent = npc.GetComponent <NavMeshAgent>();

            agent.speed = moveSpeed;
            agent.SetDestination(npc.transform.position + dirToScare);
        }
    }
예제 #21
0
        public static void OnDamage(NPCProto npc, NPCProto victim, NPCProto attacker, int damage, bool dropUnconscious, bool dropDead)
        {
            NPCAI ai = victim.getAI();

            if (victim.HP == 0)
            {
                victim.standAnim();
                victim.playAnimation("S_DEADB");
                return;
            }

            if (attacker == null)
            {
                return;
            }
            ai.addEnemy(attacker);
        }
    public IEnumerator MoveToTarget(LivingEntity target, NPCAI npc)
    {
        while (true)
        {
            float targetDistance = Vector2.Distance(transform.position, target.transform.position);
            if (targetDistance <= npc.ProperRange)
            {
                break;
            }
            float directionX = Mathf.Sign((target.transform.position - transform.position).x);

            input = new Vector2(directionX, 0);
            yield return(null);
        }

        input = Vector2.zero;
    }
예제 #23
0
    void NPC01Init()
    {
        NPCAI ai = NPC01.GetComponent <NPCAI>();

        ai.addNPCState(); //add empty state 0
        ai.setNPCState(0, 0, "This is the forst state.", null, .5f);
        ai.setNPCState(0, 1, "This is the first target state.", null, .5f);
        ai.setNPCState(0, 2, "This is the Second target state.", null, .5f);
        ai.setNPCState(0, 3, "This is the third target state.", null, .5f);
        ai.setNPCState(0, 4, "This is the fourth target state.", null, .5f);

        ai.addNPCState(); //add empty state 1
        ai.setNPCState(1, 0, "his is the first target state.", null, .5f);
        ai.setNPCState(1, 1, "This is the first target state.", null, .5f);
        ai.setNPCState(1, 2, "This is the Second target state.", null, .5f);
        ai.setNPCState(1, 3, "This is the third target state.", null, .5f);
        ai.setNPCState(1, 4, "This is the fourth target state.", null, .5f);
    }
    public override bool IsValidTarget(Scannable target, NPCAI npc)
    {
        //Find where the target and NPC are on the NavMesh.
        NavMeshHit npcPosition;
        NavMeshHit targetPosition;

        NavMesh.SamplePosition(npc.transform.position, out npcPosition, POINT_TOLERANCE, NavMesh.AllAreas);
        NavMesh.SamplePosition(target.transform.position, out targetPosition, POINT_TOLERANCE, NavMesh.AllAreas);

        if (targetPosition.position.Equals(new Vector3(Mathf.Infinity, Mathf.Infinity, Mathf.Infinity)))
        {
            return(false);
        }

        //Try to find a path between the two points and return whether is is successful.
        NavMeshPath path = new NavMeshPath();

        NavMesh.CalculatePath(npcPosition.position, targetPosition.position, NavMesh.AllAreas, path);
        return(path.status == NavMeshPathStatus.PathComplete);
    }
예제 #25
0
 public override bool PreAI()
 {
     NPCs.NPCAI.ExtraNPCAction action = delegate()
     {
         if ((npc.velocity.Y == 0 && Math.Abs((float)(npc.position.X + (npc.width / 2) - (Main.player[npc.target].position.X + (Main.player[npc.target].width / 2)))) < 160 && Math.Abs((float)(npc.position.Y + (npc.height / 2) - (Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2)))) < 50.0 && (npc.direction > 0 && npc.velocity.X >= 1 || npc.direction < 0 && npc.velocity.X <= -1)))
         {
             npc.velocity.X = npc.velocity.X * 4f;
             if ((double)npc.velocity.X > 5)
             {
                 npc.velocity.X = 5f;
             }
             if ((double)npc.velocity.X < -5)
             {
                 npc.velocity.X = -5f;
             }
             npc.velocity.Y = -4f;
             npc.netUpdate  = true;
         }
     };
     NPCAI.FighterAI(npc.whoAmI, 5, 0.2F, null, action);
     return(false);
 }
예제 #26
0
        public static void OnAssessTarget(NPCProto npc, NPCProto target)
        {
            NPCAI ai = npc.getAI();

            //Check if target is Enemy and call AssessEnemy:
            if (npc.getAttitudeToGuild(target.getGuild()) == Enumeration.GuildsAttitude.HOSTILE &&
                target.HP != 0 &&
                !target.isUnconscious && ai.AssessEnemyRoutine != null)
            {
                if (ai.AssessWarnRoutine != null)
                {
                }
                else
                {
                    ai.AssessEnemyRoutine(npc, target);
                }
            }

            if (target.HP == 0 && ai.AssessBodyRoutine != null)
            {
                ai.AssessBodyRoutine(npc, target);
            }
        }
        public static void OnDamage(NPCProto npc, NPCProto victim, NPCProto attacker,
                                    int damage, bool dropUnconscious, bool dropDead)
        {
            NPCAI ai = npc.getAI();

            if (victim.HP != 0)
            {
                if (npc.getAttitudeToGuild(victim.getGuild()) == Enumeration.GuildsAttitude.FRIENDLY &&
                    npc.getAttitudeToGuild(attacker.getGuild()) != Enumeration.GuildsAttitude.FRIENDLY)
                {
                    ai.addEnemy(attacker);
                }
                else if (npc.getAttitudeToGuild(attacker.getGuild()) == Enumeration.GuildsAttitude.FRIENDLY &&
                         npc.getAttitudeToGuild(victim.getGuild()) != Enumeration.GuildsAttitude.FRIENDLY)
                {
                    ai.addEnemy(victim);
                }
            }
            else if (ai.AssessBodyRoutine != null)
            {
                ai.AssessBodyRoutine(npc, victim);
            }
        }
예제 #28
0
    public override Scannable SelectTarget(ICollection <Scannable> targets, NPCAI npc)
    {
        Scannable nearestScannable = null;

        foreach (Scannable target in targets)
        {
            //To begin with, set the nearest scannable to the first item in scannables.
            if (nearestScannable == null)
            {
                nearestScannable = target;
                continue;
            }

            float distanceToCurrent = Vector3.Distance(npc.transform.position, target.transform.position);
            float distanceToNearest = Vector3.Distance(npc.transform.position, nearestScannable.transform.position);

            if (distanceToCurrent < distanceToNearest)
            {
                nearestScannable = target;
            }
        }

        return(nearestScannable);
    }
예제 #29
0
 public override void Plan(NPCAI npc, Scannable target)
 {
 }
예제 #30
0
 public override void Cease(NPCAI npc, Scannable target)
 {
 }
예제 #31
0
 // Use this for initialization  
 void Start()
 {
     agent = GetComponent<NavMeshAgent>();
     npcai = GetComponent<NPCAI>();         
 }