Exemplo n.º 1
0
 public Phenomenon(int targetOwnerID, int targetObjectID, subobject targetSubObject, behaviour targetBehaviour, parameters targetParameters)
 {
     _ownerID    = targetOwnerID;
     _objectID   = targetObjectID;
     _subobject  = targetSubObject;
     _behaviour  = targetBehaviour;
     _parameters = targetParameters;
 }
Exemplo n.º 2
0
    public behaviour estado;             //variable que guarda los estados de los npc.

    public IEnumerator MovimientoEnemy() //Corrutina que controla el estado y la dierccion del movimiento de los npc.
    {
        yield return(new WaitForSeconds(2));

        estado = (behaviour)Random.Range(0, 2);
        dir    = Random.Range(0, 4);
        Moving();
        StartCoroutine(MovimientoEnemy());
    }
Exemplo n.º 3
0
 void assignPlayers()
 {
     for (int i = 0; i < states.Length; i++)
     {
         behaviour b = states[i].GetComponent <behaviour>();
         int       r = Random.Range(0, 5);
         b.owner = r;
         b.updateColourOfProvinceRing(r);
     }
 }
Exemplo n.º 4
0
 void FixedUpdate()
 {
     // Calculate movement
     if (life == 0)
     {
         return;
     }
     shootTimer  -= Time.deltaTime;
     behaviourRet = ChooseBehaviour(behaviourRet);
     handler.SetNPCBehavior(gameObject, behaviourRet.type);
     if (Vector3.Distance(gameObject.transform.position, _target) < avoidTargetRadius)
     {
         _target = _pathfinder.getPosition(gameObject.transform.position, behaviourRet.target);
     }
     updateBehaviour();
     if (bushes.Count > 0)
     {
         if (bushTimer <= 0)
         {
             bushes.Dequeue();
             bushTimer = 5;
         }
         else
         {
             bushTimer -= Time.deltaTime;
         }
     }
     if (playerSeen)
     {
         playerSeenTimer += Time.deltaTime;
         if (playerSeenTimer >= 10)
         {
             playerSeenTimer = 0;
             playerSeen      = false;
         }
     }
     _animator.SetBool("walk", walk);
     _animator.SetBool("run", run);
     _animator.SetBool("shoot", shoot);
     _animator.SetInteger("hp", life);
     if (!float.IsNaN(_rotation.y) && !float.IsInfinity(_rotation.y))
     {
         transform.eulerAngles += _rotation * Time.deltaTime;
         transform.eulerAngles  = new Vector3(0, transform.eulerAngles.y, 0);
     }
     if (behaviourRet.type != BehaviourType.Attack)
     {
         transform.position = CheckBorder(transform.position + _vel * Time.deltaTime);
     }
     if (behaviourRet.type == BehaviourType.Bush && gameObject.transform.position == behaviourRet.target)
     {
         bushes.Enqueue(behaviourRet.target);
     }
 }
Exemplo n.º 5
0
        private void Hunting()
        {
            Player target = GetClosest();

            //If you're the only player dont look for more then teleport.
            if (Game.players.Count == 1)
            {
                currentBehaviour = behaviour.hiding;
                return;
            }

            //fuckoff
            if (target == null)
            {
                return;
            }

            if (Math.Abs((target.x - x)) > Math.Abs((target.y - y)))
            {
                if (target.x > x)
                {
                    x++;
                }
                else
                {
                    x--;
                }
            }
            //Moving along the Y axis
            else
            {
                if (target.y > y)
                {
                    if (y < 24)
                    {
                        y++;
                    }
                }
                else
                {
                    if (y > 1)
                    {
                        y--;
                    }
                }
            }

            //Kill the target
            if (x == target.x && y == target.y)
            {
                Events.TwoPersonEventsAttacker(this, target);
                Fight(target);
            }
        }
Exemplo n.º 6
0
    void OnMouseDown()
    {
        Ray        rayDown = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hitDown;

        if (Physics.Raycast(rayDown, out hitDown) && hitDown.transform.gameObject.name == "hitbox")
        {
            GameObject go   = hitDown.transform.gameObject;
            behaviour  temp = go.GetComponentInParent <behaviour>();
            lolv = temp.getLocals();
        }
    }
Exemplo n.º 7
0
        public Player()
        {
            name  = "Jeff";
            karma = 5;
            icon  = '@';

            attack      = 5;
            defense     = 5;
            aggression  = 4;
            desperation = 0;

            currentBehaviour = behaviour.hiding;
        }
Exemplo n.º 8
0
    // has the game been won? returns true if yes, false if no.
    public bool isWin()
    {
        behaviour temp1 = states[0].GetComponent <behaviour>();

        for (int i = 1; i < states.Length - 1; i++)
        {
            behaviour temp2 = states[i].GetComponent <behaviour>();
            if (temp1.owner != temp2.owner)
            {
                return(false);
            }
        }
        return(true);
    }
Exemplo n.º 9
0
    public List <GameObject> stateOf(int i)
    {
        List <GameObject> statesOfSpecified = new List <GameObject>();

        foreach (GameObject state in states)
        {
            behaviour stateCode = state.GetComponent <behaviour>();
            if (stateCode.owner == i)
            {
                statesOfSpecified.Add(state);
            }
        }
        return(statesOfSpecified);
    }
Exemplo n.º 10
0
 void Awake()
 {
     rgbd         = GetComponent <Rigidbody> ();
     _animator    = GetComponent <Animator>();
     behaviourRet = Behaviour();
     playerSeen   = false;
     ground       = GameObject.Find("Plane").GetComponent <MeshRenderer>();
     run          = false;
     attack       = false;
     stamina      = maxStamina;
     handler      = GameObject.FindGameObjectWithTag("GameController").GetComponent <NPCHandler>();
     _pathfinder  = pathfinder.GetComponent <PathFinding>();
     _target      = gameObject.transform.position;
 }
Exemplo n.º 11
0
    // Use this for initialization
    void Start()
    {
        time_col = 1f;
        colided  = false;
        changed  = false;
        float rand_behaviour = Random.Range(0, 9);

        if (rand_behaviour <= 3)
        {
            atual = behaviour.ONLY_DOWN;
        }
        else if (rand_behaviour <= 6)
        {
            atual = behaviour.DIAG;
        }
        else
        {
            atual = behaviour.ZIG;
        }
        float rand_dir = Random.Range(0, 10);

        if (rand_dir < 5)
        {
            atual_diag = diag.LEFT;
        }
        else
        {
            atual_diag = diag.RIGHT;
        }
        Destroy(gameObject, destroy_time);
        zig_time_elapsed = 0;
        float rand_zig = Random.Range(init_zig, end_zig);

        zig_time = rand_zig;
        damaged  = false;
    }
Exemplo n.º 12
0
        public void insertPhenomenon(int targetOwnerID, int targetObjectTypeID, subobject targetSubObject, behaviour targetBehaviour, parameters targetParameters)
        {
            //Consts.writeEnteringMethodToDebugLog(System.Reflection.MethodBase.GetCurrentMethod().ReflectedType + "." + System.Reflection.MethodBase.GetCurrentMethod().Name);
            Phenomenon targetPhenomenon = new Phenomenon(targetOwnerID, targetObjectTypeID, targetSubObject, targetBehaviour, targetParameters);

            listOfPhenomenons.AddLast(targetPhenomenon);

            ActionsToDo toDo = analyzePhenomenon(targetPhenomenon);

            if (toDo != null)
            {
                listOfActionsToDo.insertItemIntoQueue(toDo);
            }            //only if there is something to do.
                         //Consts.writeExitingMethodToDebugLog(System.Reflection.MethodBase.GetCurrentMethod().ReflectedType + "." + System.Reflection.MethodBase.GetCurrentMethod().Name);
        }
Exemplo n.º 13
0
    behaviour ChooseBehaviour(behaviour b)
    {
        GetVision();
        int priority      = 0;
        int formationPrio = (int)handler.GetGeneralBehaviour();

        foreach (GameObject obj in visible)
        {
            switch (obj.name)
            {
            case "Player":
                if (Vector3.Distance(obj.gameObject.transform.position, gameObject.transform.position) > shootDistance)
                {
                    b.type = BehaviourType.Track;
                }
                else if (obj.GetComponent <Player>().life > 5 && Vector3.Distance(obj.gameObject.transform.position, gameObject.transform.position) < 5)
                {
                    b.type = BehaviourType.Flee;
                }
                else
                {
                    b.type = BehaviourType.Attack;
                }
                priority      = 3;
                b.target      = obj.gameObject.transform.position;
                playerLastPos = b.target;
                playerSeen    = true;
                return(b);

            case "bush":
                if (formationPrio >= 2 || priority >= 2 || b.target == obj.transform.position || bushes.Contains(obj.gameObject.transform.position))
                {
                    break;
                }
                b.type   = BehaviourType.Bush;
                b.target = obj.gameObject.transform.position;
                priority = 1;
                break;

            case "footprint":
                if (priority >= 3 || formationPrio >= 3)
                {
                    break;
                }
                b.type = BehaviourType.Track;
                if (priority == 2 &&
                    Vector3.Distance(b.target, gameObject.transform.position) > Vector3.Distance(b.target, obj.gameObject.transform.position))
                {
                    break;
                }
                priority   = 2;
                b.target   = obj.gameObject.transform.position;
                b.rotation = obj.gameObject.transform.localRotation;
                break;

            default:
                break;
            }
        }
        if (priority < 3 && playerSeen)
        {
            b.target = playerLastPos;
            b.type   = BehaviourType.Track;
        }
        else if ((b.type != BehaviourType.Formation || handler.GetGeneralBehaviour() == BehaviourType.Wander) && priority == 0 && wanderTimer <= 0)
        {
            wanderTimer = 1;
            b.type      = BehaviourType.Wander;
            b.target    = gameObject.transform.position;
            b.target.z += wanderDir;
            b.target.x += Random.Range(-15, 15);
        }
        else if (priority == 0)
        {
            wanderTimer -= Time.deltaTime;
        }
        shoot = false;
        walk  = false;
        return(b);
    }
Exemplo n.º 14
0
    IEnumerator runAI()
    {
        yield return(new WaitForSeconds(commandWait));

        int        r        = Random.Range(0, 38);
        GameObject curState = states[r];

        //grab the game engine object
        GameObject tempEngine = GameObject.FindGameObjectWithTag("Engine");
        //grab the script of the object
        Engine tempEngineScript = tempEngine.GetComponent <Engine>();

        for (int i = 2; i < 5; i++)
        {
            List <GameObject> statesUnderAttack = new List <GameObject>();

            List <GameObject> myStates = tempEngineScript.stateOf(i);
            //if the player has no states left, continue
            if (myStates.Count == 0)
            {
                continue;
            }
            //if the player has at least one state left
            if (myStates.Count != 0)
            {
                //determine if the need to defend is paramount
                for (int j = 0; j < tempEngineScript.stateOf(i).Count; j++)
                {
                    behaviour temp = myStates[j].GetComponent <behaviour>();
                    if (temp.totalVoters > temp.listOfLocallyOwnedLocalVoters().Count)
                    {
                        statesUnderAttack.Add(myStates[j]);
                    }
                }
                //if states are under attack, set other states to send help
                if (statesUnderAttack.Count == 1)
                {
                    //determine if we should attack a neighbour
                    for (int j = 0; j < tempEngineScript.stateOf(i).Count; j++)
                    {
                        //send all units to state which is under attack...
                    }
                    continue; //moves calculated, end turn
                }
                if (myStates.Count > (2 * statesUnderAttack.Count))
                {
                    //code for those states not under attack to go help those under attack
                    continue; //moves calculated, end turn
                }
                else
                {
                    //GIVE UP, under too much attack
                    continue; //moves calculated, end turn
                }

                //determine if we should attack a neighbour
                for (int j = 0; j < tempEngineScript.stateOf(i).Count; j++)
                {
                    behaviour temp = myStates[j].GetComponent <behaviour>();
                    if (temp.listOfLocallyOwnedLocalVoters().Count > temp.garrisonValue)
                    {
                        //attack neighbour based on probability?
                    }
                }
            }
        }
    }
Exemplo n.º 15
0
 public void HuntTime()
 {
     currentBehaviour = behaviour.hunting;
 }