public void setPawn( Vector3 newPos, int newOwner) { this.rootTransform.position = newPos; idolPos = newPos; ownership = newOwner; pawnState = PawnState.idle; }
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; } }
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); }
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; }
public void SetNormalHitState() { if (IsInState(m_AnimStateNameNormalHit)) { return; } m_State = PawnState.NormalHit; TriggerAnimState(m_TriggerNormalHitState); }
public void SetStateReactionSlow() { if (IsInState(m_AnimStateReactionToSlow)) { return; } m_State = PawnState.NormalHit; TriggerAnimState(m_TriggerReactionToSlow); }
/*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; }
// Use this for initialization void Start() { pawnState = PawnState.AwaitingInput; if (playerCamera == null) { Debug.LogError("PlayerPawn got no Camera", this); } }
internal void load(PawnState ps) { x = ps.x; y = ps.y; z = ps.z; id = ps.id; initiative = ps.initiative; color = ps.color; Start(); }
public void SetIdleState() { if (IsInState(m_AnimStateNameIdle)) { return; } m_State = PawnState.Idle; TriggerAnimState(m_TriggerIdleState); }
public void SetDeadState() { if (IsInState(m_AnimStateNameDying)) { return; } m_State = PawnState.Dead; TriggerAnimState(m_TriggerDyingState); }
public void SetNothingState() { if (IsInState(m_AnimStateNameNothing)) { return; } m_State = PawnState.Nothing; TriggerAnimState(m_TriggerNothingState); }
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); }
public bool IsStateOverriden(PawnState currentState, PawnState newState) { foreach (string s in newState.stateOverriden) { if (s == currentState.name) { return(true); } } return(false); }
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); }
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"); }
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); }
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; }
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; } }
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; }
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; }
/// <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; } }
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); * }*/ } } }
public void StandStill() { state=PawnState.Stand; }
private void OnStateChange(PawnState prev, PawnState next) { m_StateChangedTime = Time.time; }
public virtual void Start() { state = PawnState.Idle; animator = GetComponent <Animator>(); }
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); }
public void SetState(PawnState nextState) { m_PawnControl.SetState(nextState); }
public void FollowTarget(DamageableObject target) { movementTarget= target.transform; state=PawnState.Follow; }
public virtual void StartAnimation(PawnState animatonState, float speed = 1.0f) { Animation(animatonState, true, speed); MementoAnimationState = animatonState; }
public void MoveTo(Vector3 target) { position= target; agent.SetTarget(target); state=PawnState.Move; }
private void Start() { this.pawnState = PawnState.Idle; ptl = GetComponentInChildren <ParticleSystem>(); // sleep particle system }
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)); }