Ejemplo n.º 1
0
	public void setPawn( Vector3 newPos, int newOwner)
	{
		this.rootTransform.position = newPos;
		idolPos = newPos;
		ownership = newOwner;
		pawnState = PawnState.idle;
	}
Ejemplo n.º 2
0
    void FixedUpdate()
    {
        switch(state){
            case PawnState.Stand:

            break;
            case Move:
                if(_MoveTo()){
                    state=PawnState.Stand;
                }
            break;
            case Follow:
                if(_Follow()){
                    state=PawnState.Stand;
                }
            break;
            case Attack:
                if(_Follow(pawn.MaxAttackDistance())){
                    if(_AttackTarget()){
                        state=PawnState.Stand;
                    }
                }
            break;
        }
    }
Ejemplo n.º 3
0
        public void SetState(PawnState nextState)
        {
            PawnState prevState = m_PawnState;

            m_PawnState = nextState;
            OnStateChange(prevState, nextState);
        }
    public Transition generateTransit(BoardState a, BoardState b)
    {
        Transition output  = new Transition();
        PawnState  current = a.pawns[a.initiative];
        //difference in initiatives should be 1 but could be 0 if the initiative got shoved back due to a pawn dying.
        //in that case init will be set to -1
        int init = b.initiative - 1;

        if (init >= b.pawns.Count)
        {
            init = 0;
        }
        if (init < 0)
        {
            init = b.pawns.Count - 1;
        }
        PawnState future = b.pawns[init];

        output.id = current.id;
        output.fx = current.x;
        output.fy = current.y;
        output.fz = current.z;
        output.x  = future.x;
        output.y  = future.y;
        output.z  = future.z;
        return(output);
    }
Ejemplo n.º 5
0
    private void StopCurrentState()
    {
        if (currentPawnState == null)
        {
            return;
        }
        if (currentPawnState.invincibleDuringState)
        {
            SetInvincible(false);
        }
        if (currentStateCoroutine != null)
        {
            currentStateCoroutine.Stop();
            if (currentStateStartCoroutine != null)
            {
                StopCoroutine(currentStateStartCoroutine);
            }
        }

        if (currentStateCoroutine != null)
        {
            currentStateStopCoroutine.StartCoroutine();
        }
        currentPawnState = null;
    }
Ejemplo n.º 6
0
 public void SetNormalHitState()
 {
     if (IsInState(m_AnimStateNameNormalHit))
     {
         return;
     }
     m_State = PawnState.NormalHit;
     TriggerAnimState(m_TriggerNormalHitState);
 }
Ejemplo n.º 7
0
 public void SetStateReactionSlow()
 {
     if (IsInState(m_AnimStateReactionToSlow))
     {
         return;
     }
     m_State = PawnState.NormalHit;
     TriggerAnimState(m_TriggerReactionToSlow);
 }
Ejemplo n.º 8
0
Archivo: Pawn.cs Proyecto: Arumenn/Ur
    /*private void OnTriggerEnter(Collider other) {
     *  Square square = other.gameObject.GetComponent<Square>();
     *  if (square) {
     *      Debug.Log(name + " entering " + square.position);
     *      if ((currentSquare != square)) {
     *          currentSquare = square;
     *          Debug.Log(name + " is hovering over " + square.position);
     *          //square.currentPawn = this;
     *          //Debug.Log(square.position + " is free so we set " + name + " as pawn");
     *      }
     *  }
     * }*/

    /*private void OnTriggerExit(Collider other) {
     *  Square square = other.gameObject.GetComponent<Square>();
     *  if (square) {
     *      Debug.Log(name + " leaving " + square.position);
     *      if (currentSquare == square) {
     *          currentSquare = null;
     *          other.gameObject.GetComponent<Square>().currentPawn = null;
     *      }
     *  }
     * }*/

    public void pushOut()
    {
        Debug.Log(name + " is dead");
        pawnState = PawnState.waiting;
        currentSquare.currentPawn = null;
        currentSquare             = null;
        transform.position        = originalPosition;
        lastPosition = 0;
    }
Ejemplo n.º 9
0
    // Use this for initialization
    void Start()
    {
        pawnState = PawnState.AwaitingInput;

        if (playerCamera == null)
        {
            Debug.LogError("PlayerPawn got no Camera", this);
        }
    }
Ejemplo n.º 10
0
 internal void load(PawnState ps)
 {
     x          = ps.x;
     y          = ps.y;
     z          = ps.z;
     id         = ps.id;
     initiative = ps.initiative;
     color      = ps.color;
     Start();
 }
Ejemplo n.º 11
0
        public void SetIdleState()
        {
            if (IsInState(m_AnimStateNameIdle))
            {
                return;
            }

            m_State = PawnState.Idle;
            TriggerAnimState(m_TriggerIdleState);
        }
Ejemplo n.º 12
0
        public void SetDeadState()
        {
            if (IsInState(m_AnimStateNameDying))
            {
                return;
            }

            m_State = PawnState.Dead;
            TriggerAnimState(m_TriggerDyingState);
        }
Ejemplo n.º 13
0
        public void SetNothingState()
        {
            if (IsInState(m_AnimStateNameNothing))
            {
                return;
            }

            m_State = PawnState.Nothing;
            TriggerAnimState(m_TriggerNothingState);
        }
Ejemplo n.º 14
0
    private void Animation(PawnState animatonState, bool value, float speed = 1.0f)
    {
        if (GetComponent <PawnModel>().animator == null)
        {
            Debug.LogError("BotAnimation Animation: animator not set!");
            return;
        }

        GetComponent <PawnModel>().animator.SetBool(ExtensionMethods.ToStringEnums(animatonState), value);
        GetComponent <PawnModel>().animator.SetFloat("speed", speed);
    }
Ejemplo n.º 15
0
 public bool IsStateOverriden(PawnState currentState, PawnState newState)
 {
     foreach (string s in newState.stateOverriden)
     {
         if (s == currentState.name)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 16
0
    internal void save(BoardState bs)
    {
        PawnState ps = new PawnState();

        ps.x          = x;
        ps.y          = y;
        ps.z          = z;
        ps.id         = id;
        ps.color      = color;
        ps.initiative = initiative;

        bs.pawns.Add(ps);
    }
Ejemplo n.º 17
0
Archivo: Pawn.cs Proyecto: Arumenn/Ur
 public void cancelMovement()
 {
     //restores last known infos
     if (lastSquare != null)
     {
         lastSquare.switchWith(this);
     }
     transform.position       = lastKnownTransform;
     pawnState                = lastPawnState;
     currentSquare            = lastSquare;
     lastPosition             = lastKnownPosition;
     gm.currentlySelectedPawn = null;
     Debug.Log("Cancelled movement");
 }
Ejemplo n.º 18
0
Archivo: Pawn.cs Proyecto: Arumenn/Ur
 private bool PlacePawn()
 {
     Debug.Log("Request to place pawn " + name + "...");
     if (currentSquare != null)
     {
         if ((currentSquare.squareTerritory == 0) || (currentSquare.squareTerritory == playerOwner))
         {
             if ((currentSquare.isOccupied))
             {
                 Debug.Log("Square " + currentSquare.position + " is occupied...");
                 if (currentSquare.currentPawn == this)
                 {
                     Debug.Log("by me.");
                     return(Snap());
                 }
                 else if (currentSquare.currentPawn.playerOwner != playerOwner)
                 {
                     Debug.Log("by an other player's pawn");
                     if (currentSquare.position == 8)
                     {
                         Debug.Log("Can't attack on a safe space");
                         return(false);
                     }
                     else
                     {
                         return(Snap());
                     }
                 }
             }
             else
             {
                 Debug.Log("Square " + currentSquare.position + " is free...");
                 pawnState = PawnState.waiting;
                 return(Snap());
             }
         }
         else
         {
             Debug.Log("Not your territory.");
             return(false);
         }
     }
     else
     {
         Debug.Log("No square to place on.");
     }
     return(false);
 }
Ejemplo n.º 19
0
    private IEnumerator StartStateCoroutine(IEnumerator _coroutine, PawnState _state)
    {
        if (_state.invincibleDuringState)
        {
            SetInvincible(true);
        }
        currentStateCoroutine = MonoBehaviourExtension.StartCoroutineEx(this, _coroutine);
        yield return(currentStateCoroutine.WaitFor());

        currentPawnState = null;
        yield return(null);

        if (_state.invincibleDuringState)
        {
            SetInvincible(false);
        }
        currentStateCoroutine = null;
    }
Ejemplo n.º 20
0
    public void ChangePawnState(string _newStateName, IEnumerator _coroutineToStart, IEnumerator _coroutineToCancel = null)     //Check "Pawn state: manual" on google drive for more informations
    {
        PawnState i_newState = pawnStates.GetPawnStateByName(_newStateName);
        bool      canOverrideState;

        if (currentPawnState != null)
        {
            if (pawnStates.IsStateOverriden(currentPawnState, i_newState) || currentStateCoroutine == null)
            {
                //Must cancel current state and replace by new state
                StopCurrentState();
                canOverrideState = true;
            }
            else
            {
                //Can't override current state, cancel action
                return;
            }
        }
        else
        {
            canOverrideState = true;
        }
        if (canOverrideState)
        {
            if (_coroutineToCancel != null)
            {
                currentStateStopCoroutine = _coroutineToCancel;
            }
            currentStateStartCoroutine = StartCoroutine(StartStateCoroutine(_coroutineToStart, i_newState));
            PawnState i_newStateInstance = new PawnState();
            i_newStateInstance.allowBallReception = i_newState.allowBallReception;
            i_newStateInstance.allowBallThrow     = i_newState.allowBallThrow;
            currentPawnState = i_newState;
        }
    }
Ejemplo n.º 21
0
    public virtual void Awake()
    {
        //Retrieve references
        rb             = GetComponent <Rigidbody>();
        animator       = GetComponentInChildren <Animator>();
        passController = GetComponent <PassController>();
        navMeshAgent   = GetComponent <NavMeshAgent>();
        pawnStates     = Resources.Load <PawnStates>("PawnStateDatas");
        if (navMeshAgent == null)
        {
            navMeshAgent = GetComponentInChildren <NavMeshAgent>();
        }
        if (navMeshAgent == null)
        {
            navMeshAgent = GetComponent <NavMeshAgent>();
        }
        pushDatas = PushDatas.GetDatas();

        //Init variables
        isInvincible = false;
        if (pawnMovementValues != null)
        {
            customGravity  = pawnMovementValues.onGroundGravityMultiplier * -9.81f;
            customDrag     = pawnMovementValues.idleDrag;
            effectiveSpeed = pawnMovementValues.moveSpeed;
        }
        currentHealth = maxHealth;
        targetable    = true;
        if (GetComponent <PlayerController>() != null)
        {
            isPlayer = true;
        }
        UpdateNavMeshAgent(navMeshAgent);
        moveState        = MoveState.Idle;
        currentPawnState = null;
    }
Ejemplo n.º 22
0
 public static bool IsAttackState( PawnState pawnState )
 {
     bool result = false;
     if( pawnState == PawnState.Attack ||
         pawnState == PawnState.AttackDizzy ||
         pawnState == PawnState.Counter ||
         pawnState == PawnState.MoveToAttack ||
         pawnState == PawnState.AttackSpecialA ||
         pawnState == PawnState.AttackSpecialB
        )
     {
         result = true;
     }
     return result;
 }
Ejemplo n.º 23
0
    /// <summary>
    /// Function that handles the physical parts of the player based upon given input
    /// </summary>
    protected void HandleGivenInput()
    {
        //Todo, these might be cut up in more sub methods for better overview later on
        switch (pawnState)
        {
        //What happens when the player can shoot the ball
        case PawnState.AwaitingInput:
            //Happens when player controller makes an interaction
            if (lastControllerState.hasInput)
            {
                //We create a Raycast from our camera to see if we hit our ball
                Ray        ray = playerCamera.ScreenPointToRay(lastControllerState.position);
                RaycastHit hitInfo;
                if (Physics.Raycast(ray, out hitInfo, 100))
                {
                    if (hitInfo.transform.GetComponent <Ball>() == playerBall)
                    {
                        //if we've hit our ball. We start tracking the players swipe
                        inputStartTime     = Time.time;
                        inputStartPosition = hitInfo.point;
                        pawnState          = PawnState.ActiveInput;
                    }
                }
            }
            break;

        //What happens when the player is actively swiping to shoot the ball
        case PawnState.ActiveInput:
            //Player is releasing the shot
            if (!lastControllerState.hasInput)
            {
                //We create another ray to get a better understanding of where the player is aiming
                Ray        ray = playerCamera.ScreenPointToRay(lastControllerState.position);
                RaycastHit hitInfo;
                Vector3    swipeEndPosition = new Vector3();
                if (Physics.Raycast(ray, out hitInfo, 100))
                {
                    swipeEndPosition = hitInfo.point;
                }
                else
                {
                    //When player is aiming at the sky. We pick a point in the air 30 units from where he is looking. This number came from playtesting
                    swipeEndPosition = ray.origin + ray.direction * 30;
                }


                float   swipeDuration  = Time.time - inputStartTime;
                Vector3 swipeDirection = swipeEndPosition - inputStartPosition;

                //we check to see if the shot was not just a quick accidental click
                if (swipeDirection.magnitude > 1)
                {
                    //Based upon the swiping start and end point, as well as it's quickness we calculate the forces we want to put on the Ball object
                    swipeDirection += Vector3.up * swipeDirection.magnitude / 10;
                    float force = swipeDirection.magnitude * 7 / swipeDuration;

                    playerBall.LaunchBall(swipeDirection, force);
                    pawnState = PawnState.PostInput;
                }
            }
            break;
        }
    }
Ejemplo n.º 24
0
Archivo: Pawn.cs Proyecto: Arumenn/Ur
    private void OnMouseDown()
    {
        if ((gm.currentPlayer != playerOwner) && (pawnState != PawnState.finished))
        {
            return;
        }

        if (Input.GetMouseButtonDown(0))
        {
            Debug.Log("Clicked " + name + " (currentSquare=" + currentSquare + "; State=" + pawnState + ")");
            if (gm.movesRemaining <= 0)
            {
                Debug.Log("No moves remaining");
                return;
            }
            if (gm.currentlySelectedPawn == null)
            {
                //are we near the end?
                if (currentSquare != null)
                {
                    int distanceToOutside = 15 - currentSquare.position; //15 is outside the 14 squares, so past the finish line
                    if ((distanceToOutside <= 4) && (gm.movesRemaining > distanceToOutside))
                    {
                        //an exact throw is needed to get a pawn home
                        Debug.LogWarning("You need an exact throw of " + distanceToOutside + " to move this pawn home");
                        return;
                    }
                }
                Debug.Log("Picked up " + name);
                //saves last known infos
                lastKnownTransform = transform.position;
                lastPawnState      = pawnState;
                lastSquare         = currentSquare;
                lastKnownPosition  = lastPosition;
                //sets to moving
                gm.currentlySelectedPawn = this;
                pawnState = PawnState.waiting;
            }
            else if (gm.currentlySelectedPawn == this)
            {
                if (checkValidMovement())
                {
                    if (PlacePawn())
                    {
                        gm.currentlySelectedPawn = null;
                        gm.consumeMoves(gm.movesRemaining, currentSquare.squareType);
                    }
                }
                else
                {
                    pawnState = PawnState.waiting;
                    Debug.Log("Invalid placement clicked for " + name);
                }

                /*if ((currentSquare != null) && (currentSquare.position >= lastPosition)) {
                 *  int moveCost = currentSquare.position - lastPosition;
                 *  if (moveCost > gm.movesRemaining) {
                 *      Debug.LogWarning("Not enough moves remaining");
                 *  } else if (moveCost < gm.movesRemaining) {
                 *      Debug.LogWarning("You have to use all the moves");
                 *  } else {
                 *      Debug.Log("Valid square clicked for " + name);
                 *
                 *  }
                 * } else {
                 *  pawnState = PawnState.waiting;
                 *  Debug.Log("Invalid placement clicked for " + name);
                 * }*/
            }
        }
    }
Ejemplo n.º 25
0
 public void StandStill()
 {
     state=PawnState.Stand;
 }
Ejemplo n.º 26
0
 private void OnStateChange(PawnState prev, PawnState next)
 {
     m_StateChangedTime = Time.time;
 }
Ejemplo n.º 27
0
 public virtual void Start()
 {
     state    = PawnState.Idle;
     animator = GetComponent <Animator>();
 }
Ejemplo n.º 28
0
 public override void StartAnimation(PawnState animatonState, float speed = 1)
 {
     base.StartAnimation(animatonState, speed);
 }
    void move(BoardState bs, List <BoardState> possibilities, int x, int y, int z)
    {
        int index = bs.initiative;

        if (index < 0)
        {
            index = bs.pawns.Count - 1;
        }
        if (index >= bs.pawns.Count)
        {
            index = 0;
        }
        PawnState current;

        try
        {
            current = bs.pawns[index];
        }
        catch (ArgumentOutOfRangeException e)
        {
            Debug.Log(index);
            foreach (PawnState ps in bs.pawns)
            {
                Debug.Log(ps);
            }
            throw e;
        }
        int offset = (int)Mathf.Pow(bs.grid.Length, 1 / 3f) / 2;

        int gridx = current.x + offset;
        int gridy = current.y + offset;
        int gridz = current.z + offset;

        if (exists(bs.grid, gridx + x, gridy + y, gridz + z))
        {
            BoardState bs1 = new BoardState();

            bs1.grid  = bs.grid;
            bs1.pawns = new List <PawnState>();
            bs1.pawns.AddRange(bs.pawns);
            bs1.pawns.Sort((a, b) => a.initiative - b.initiative);
            PawnState p     = new PawnState();
            int       found = bs1.pawns.FindIndex(pl =>
                                                  pl.x == current.x + x &&
                                                  pl.y == current.y + y &&
                                                  pl.z == current.z + z &&
                                                  pl.initiative != index);
            if (found > -1)
            {
                if (found < index)
                {
                    index--;
                }
                bs1.pawns.RemoveAt(found);
            }
            p.color          = current.color;
            p.x              = current.x + x;
            p.y              = current.y + y;
            p.z              = current.z + z;
            p.initiative     = index;
            bs1.pawns[index] = p;
            bs1.initiative   = index + 1;

            if (bs1.initiative >= bs1.pawns.Count)
            {
                bs1.initiative = 0;
            }
            bs1.grade = Grade(bs1);
            possibilities.Add(bs1);
        }
    }
 public bool neighbors(PawnState po, PawnState bo)
 {
     return(Math.Sqrt(Math.Pow(po.x - bo.x, 2) + Math.Pow(po.y - bo.y, 2) + Math.Pow(po.z - bo.z, 2)) < 2);
 }
Ejemplo n.º 31
0
 public void SetState(PawnState nextState)
 {
     m_PawnControl.SetState(nextState);
 }
Ejemplo n.º 32
0
 public void FollowTarget(DamageableObject  target)
 {
     movementTarget= target.transform;
     state=PawnState.Follow;
 }
Ejemplo n.º 33
0
 public virtual void StartAnimation(PawnState animatonState, float speed = 1.0f)
 {
     Animation(animatonState, true, speed);
     MementoAnimationState = animatonState;
 }
Ejemplo n.º 34
0
 public void MoveTo(Vector3  target)
 {
     position= target;
     agent.SetTarget(target);
     state=PawnState.Move;
 }
Ejemplo n.º 35
0
 private void Start()
 {
     this.pawnState = PawnState.Idle;
     ptl            = GetComponentInChildren <ParticleSystem>(); // sleep particle system
 }
Ejemplo n.º 36
0
 public static bool smethod_1(PawnState.StateType stateType_0, PawnState.StateType stateType_1)
 {
     return(PawnState.smethod_0(stateType_1) || stateType_1 == PawnState.StateType.LadderAttachTopWait || (stateType_0 == PawnState.StateType.LadderAttachTop && stateType_1 == PawnState.StateType.Fall));
 }