//Run every frame we are in the idle state. private void Idle_SuperUpdate() { //If Jump. if (warriorInputController.allowedInput && warriorController.Jump()) { currentState = WarriorState.Jump; warriorState = WarriorState.Jump; return; } //In air. if (!MaintainingGround()) { currentState = WarriorState.Fall; warriorState = WarriorState.Fall; return; } if (warriorInputController.HasMoveInput() && canMove) { currentState = WarriorState.Move; warriorState = WarriorState.Move; return; } //Apply friction to slow to a halt. currentVelocity = Vector3.MoveTowards(currentVelocity, Vector3.zero, groundFriction * superCharacterController.deltaTime); }
//fight functions public WarriorState TakeDamage(Warrior attacker, DamageMethod method, int value) { var beginValue = value; WarriorState warriorState = WarriorState.ALIVE; if (Armour > 0) { var armourRemaining = Armour; Armour -= value; if (Armour <= 0) { value -= armourRemaining;//deal damage to armour, take all armour and next deal damage to hitpoints warriorState = WarriorState.NO_ARMOUR; } else { value = 0; } } if (value > 0) { Hitpoints -= value; if (Hitpoints <= 0) { warriorState = WarriorState.DEAD; } } Console.WriteLine($"{attacker.Name} deals {beginValue} damage to {Name} leaving {Armour} armour,{Hitpoints} hitpoints left"); State = warriorState; return(warriorState); }
void Update() { switch (_state) { case WarriorState.Idle: _state = WarriorState.FindTarget; break; case WarriorState.FindTarget: var target = FindEnemy(); if (target) { _target.SetTarget(target.gameObject); _state = WarriorState.MovingToTarget; _goTo.enabled = true; } break; case WarriorState.MovingToTarget: if (!_target.HasTarget()) { _goTo.enabled = false; _state = WarriorState.Idle; } break; } }
public void Reset(Vector2Int initCoordinate) { if (m_actionCoroutine != null) { StopCoroutine(m_actionCoroutine); m_actionCoroutine = null; } if (m_moveTween != null) { m_moveTween.Kill(); } var targetPos = BoardManager.instance.GetGridPos(initCoordinate); transform.position = targetPos; Coordinate = initCoordinate; m_image.sprite = m_ghostSprite; m_image.SetNativeSize(); transform.rotation = (GameManager.instance.CurStage.FaceToRight) ? Quaternion.Euler(new Vector3(0, 180, 0)) : Quaternion.Euler(new Vector3(0, 0, 0)); CurState = WarriorState.Move; }
public void Die() { m_image.sprite = m_deadSprite; m_image.SetNativeSize(); CurState = WarriorState.Dead; SoundManager.instance.PlaySound(SoundType.Killed); }
// POST api/<controller> public WarriorState Post([FromBody] string value) { WarriorState state = new WarriorState(); state = BattleFieldSingleton.BattleField.GetWarriorByName(value).MyInfo(); return(state); }
private void Awake() { instance = this; CurState = WarriorState.Move; m_image = GetComponent <Image>(); }
private void Move_SuperUpdate() { //If Jump. if (warriorInputController.allowedInput && warriorController.Jump()) { currentState = WarriorState.Jump; warriorState = WarriorState.Jump; return; } //Fallling. if (!MaintainingGround()) { currentState = WarriorState.Fall; warriorState = WarriorState.Fall; return; } //Set speed determined by movement type. if (warriorInputController.HasMoveInput() && canMove) { //Keep strafing animations from playing. animator.SetFloat("Velocity X", 0F); //Run. currentVelocity = Vector3.MoveTowards(currentVelocity, warriorInputController.moveInput * runSpeed, movementAcceleration * superCharacterController.deltaTime); } else { currentState = WarriorState.Idle; warriorState = WarriorState.Idle; } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.TryGetComponent <King>(out King king)) { _currentState = WarriorState.Attack; _move = false; } }
private void Fall_SuperUpdate() { if (AcquiringGround()) { currentVelocity = Math3d.ProjectVectorOnPlane(superCharacterController.up, currentVelocity); currentState = WarriorState.Idle; warriorState = WarriorState.Idle; return; } //Normal gravity. currentVelocity -= superCharacterController.up * gravity * superCharacterController.deltaTime; }
private void HandleIdle() { var observations = _entity.observations; observations.Sort(new GameObjectDistanceSortComparer(this.transform.position)); var count = observations.Count; for (int i = 0; i < count; i++) { var obs = observations[i]; var otherUnit = obs.GetComponent <UnitBase>(); if (otherUnit != null) { if (_entity.IsAllied(otherUnit)) { // don't attack allied units continue; } _attackTarget = otherUnit; _currentState = WarriorState.Attacking; return; } var nest = obs.GetComponent <NestStructure>(); if (nest != null) { if (_entity.IsAllied(nest)) { // don't attack own nest continue; } _attackTarget = nest; _currentState = WarriorState.Attacking; return; } } // nothing interesting in memory, do some random wandering if (!_entity.isMoving) { _entity.RandomWander(); } }
private void Jump_SuperUpdate() { Vector3 planarMoveDirection = Math3d.ProjectVectorOnPlane(superCharacterController.up, currentVelocity); Vector3 verticalMoveDirection = currentVelocity - planarMoveDirection; //Falling. if (currentVelocity.y < 0) { currentVelocity = planarMoveDirection; currentState = WarriorState.Fall; warriorState = WarriorState.Fall; return; } planarMoveDirection = Vector3.MoveTowards(planarMoveDirection, warriorInputController.moveInput * inAirSpeed, jumpAcceleration * superCharacterController.deltaTime); verticalMoveDirection -= superCharacterController.up * gravity * superCharacterController.deltaTime; currentVelocity = planarMoveDirection + verticalMoveDirection; }
private void Start() { superCharacterController = GetComponent <SuperCharacterController>(); warriorController = GetComponent <WarriorControllerFREE>(); warriorInputController = GetComponent <WarriorInputControllerFREE>(); animator = GetComponentInChildren <Animator>(); rb = GetComponent <Rigidbody>(); if (rb != null) { //Set restraints on startup if using Rigidbody. rb.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ; } //Set currentState to idle on startup. currentState = WarriorState.Idle; warriorState = WarriorState.Idle; SwitchCollisionOn(); }
private void HandleAttacking() { if (_attackTarget == null || _attackTarget.isDead) { _attackTarget = null; _currentState = WarriorState.Idle; return; } if ((_attackTarget.transform.position - _entity.transform.position).sqrMagnitude > (_entity.attackRadius * _entity.attackRadius)) { // attack target outside of range if (!_entity.isMoving) { _entity.MoveTo(_attackTarget.transform.position); } return; } // attack target within range _entity.Attack(); }
public void Sleep(int miliseconds, WarriorState state, IResetable resetable) { }
public Warrior(WarriorState state) { State = state; }
public static void CheckLogging(WarriorState outcome) { Logger.Info("You checked your enemy, its life is " + outcome.Life + ", state is " + outcome.State); }