/// <summary> /// Initializes defense, or ticks defense forward by one frame. Called when the current AD state is defending. /// </summary> /// <returns>A callback to change the movement properties of the defending character.</returns> /// /// After /// /// <example>A typical move will disable the character's movement for a certain number of frames. /// An unusual move may cause the character to be launched upwards on the fifth frame.</example> public Action <MovementController> Tick() { switch (this.state) { case DefenseState.PreHit: return(this.BeginHit()); case DefenseState.PreBlock: return(this.BeginBlock()); case DefenseState.Hit: var(defenseStateHit, movementCallbackHit) = this.move.TickDefenderHit(); this.state = defenseStateHit; return(movementCallbackHit); case DefenseState.Blocking: var(defenseStateBlock, movementCallbackBlock) = this.move.TickDefenderBlock(); this.state = defenseStateBlock; return(movementCallbackBlock); default: return(_ => { }); } }
private Action <MovementController> BeginBlock() { this.move = Instantiate(collidedMove.defenseObject, this.transform).GetComponent <DefenseMove>(); this.collidedMove = null; var(defenseState, movementCallback) = this.move.InitializeDefenderBlock(); this.state = defenseState; return(movementCallback); }
public bool ChangeState() { if (canBeChanged) { StopCoroutine("RunAway"); currentState = DefenseState.None; bossAnimController.SetBool("isWalking", false); bossAgent.isStopped = true; return(canBeChanged); } return(false); }
IEnumerator Strafe() { int rnd = Random.Range(1, 3); int strafeAmount = 0; bossAnimController.SetBool("isWalking", true); Vector3 direction = transform.position; bossAgent.isStopped = false; if (abilityID == 1) { strafeAmount = 4; } else { strafeAmount = 8; } if (abilityID == 1 && distance > 9) { direction = direction + player.transform.forward * 3; bossAgent.SetDestination(direction); } else { if (rnd == 1) { direction = direction + player.transform.right * strafeAmount; bossAgent.SetDestination(direction); } else if (rnd == 2) { direction = direction + (-player.transform.right) * strafeAmount; bossAgent.SetDestination(direction); } } while (bossAgent.remainingDistance >= bossAgent.stoppingDistance) { yield return(null); } bossAgent.isStopped = true; bossAnimController.SetBool("isWalking", false); currentState = DefenseState.None; canBeChanged = true; }
private void ResolveCollisions(MovementState movementState) { if (this.collidedMove == null) { return; } switch (this.collidedMove.height) { case MoveHeight.High: if (movementState == MovementState.Reversing) { this.state = DefenseState.PreBlock; } else { this.state = DefenseState.PreHit; } break; case MoveHeight.Mid: if (movementState == MovementState.Reversing || movementState == MovementState.CrouchingBlock) { this.state = DefenseState.PreBlock; } else { this.state = DefenseState.PreHit; } break; case MoveHeight.Low: if (movementState == MovementState.CrouchingBlock) { this.state = DefenseState.PreBlock; } else { this.state = DefenseState.PreHit; } break; default: this.state = DefenseState.None; break; } }
void Start() { personCtrl = this.GetComponent <HeroCtrl>(); heroStateActVer = new IdleStateActVer(this.gameObject); heroStateMoveVer = new IdleStateMoveVer(this.gameObject); inputArgs = new InputEventArgs("", "", ""); hero_act_state[0] = new IdleStateActVer(this.gameObject); hero_act_state[1] = new ActState(this.gameObject); hero_act_state[2] = new DefenseState(this.gameObject); hero_move_state[0] = new IdleStateMoveVer(this.gameObject); hero_move_state[1] = new MoveState(this.gameObject); hero_move_state[2] = new JumpState(this.gameObject); InputTran += new InputEventHandler(heroStateActVer.handleInput); InputTran += new InputEventHandler(heroStateMoveVer.handleInput); }
public override void Process() { Goal child = GetActiveGoal(); if (child != null && child.IsInactive) { child.Activate(); } IReadOnlyCollection <DataCreature> creatures = owner.Memory.Creatures.Read(); Agent aggresor = null; float distanceToAggresor = Mathf.Infinity; foreach (DataCreature data in creatures) { if (!data.creature) { continue; } Agent agent = data.creature.agentCreature; if (!agent.gameObject.activeSelf || data.RegistrationDate < Time.time - 1f) { continue; } bool isHostil = GoalEvade.CreatureIsHostil(owner, agent.Creature); if (!isHostil) { continue; } //bool attackSpecies = agent.Steering.Target && agent.Steering.Target.Creature.SpecieID == owner.Creature.SpecieID; //if(!attackSpecies) continue; float distanceToAgent = Vector3.Distance(owner.transform.position, agent.transform.position); if (agent != owner && agent.Creature.SpecieID != owner.Creature.SpecieID && distanceToAgent < distanceToAggresor) { aggresor = agent; distanceToAggresor = distanceToAgent; } } switch (defenseState) { case DefenseState.LookAt: if (aggresor == null) { if (child != null) { child.Abort(); } } else if (owner.Steering.Behavior != eSteeringBehavior.LookAt) { AddSubgoal(new GoalLookAt(owner, aggresor)); } /*else if(aggresor.Steering.Target != owner){ * if(child != null) child.Abort(); * AddSubgoal(new GoalPursuit(owner, aggresor)); * defenseState = DefenseState.Pursuit; * }*/ else if (distanceToAggresor < 2) { if (child != null) { child.Abort(); } AddSubgoal(new GoalAttack(owner, aggresor.Creature)); defenseState = DefenseState.Attack; } else { IReadOnlyCollection <DataCreature> friends = owner.Memory.Creatures.Read(); bool friendAggresed = false; foreach (DataCreature data in friends) { if (!data.creature) { continue; } Agent agent = data.creature.agentCreature; if (!agent.gameObject.activeSelf || data.RegistrationDate < Time.time - 1f) { continue; } if (aggresor.Steering.Target == agent) { friendAggresed = true; break; } } if (friendAggresed) { if (child != null) { child.Abort(); } AddSubgoal(new GoalPursuit(owner, aggresor)); if (Random.value > 0.5f) { owner.Creature.AudioBox.PlayOneShot(SoundOneShot.CreatureDefense); } defenseState = DefenseState.Pursuit; } } break; case DefenseState.Pursuit: if (child.IsComplete) { AddSubgoal(new GoalAttack(owner, owner.Steering.Target.Creature)); defenseState = DefenseState.Attack; } else if (child.HasFailed) { defenseState = DefenseState.LookAt; } else if (aggresor != null) { if ((owner.Steering.Behavior == eSteeringBehavior.Pursuit || owner.Steering.Behavior == eSteeringBehavior.Seek) && aggresor != owner.Steering.Target && Vector3.Distance(owner.transform.position, aggresor.transform.position) + 5f < Vector3.Distance(owner.transform.position, owner.Steering.Destination)) { child.Abort(); AddSubgoal(new GoalPursuit(owner, aggresor)); } } break; case DefenseState.Attack: if (aggresor == null) { break; } if (child.IsComplete || child.HasFailed) { IReadOnlyCollection <DataCreature> friends = owner.Memory.Creatures.Read(); bool friendAggresed = false; foreach (DataCreature data in friends) { if (!data.creature) { continue; } Agent agent = data.creature.agentCreature; if (!agent.gameObject.activeSelf || data.RegistrationDate < Time.time - 1f) { continue; } if (aggresor.Steering.Target == agent) { friendAggresed = true; break; } } if (friendAggresed) { if (child != null) { child.Abort(); } AddSubgoal(new GoalPursuit(owner, aggresor)); defenseState = DefenseState.Pursuit; } else { AddSubgoal(new GoalLookAt(owner, aggresor)); defenseState = DefenseState.LookAt; } /*if(aggresor.Steering.Target != owner){ * AddSubgoal(new GoalPursuit(owner, aggresor)); * defenseState = DefenseState.Pursuit; * }else{ * AddSubgoal(new GoalLookAt(owner, aggresor)); * defenseState = DefenseState.LookAt; * }*/ } break; } base.ProcessSubgoals(); }
// Update is called once per frame void Update() { if (!defenseMode) { return; } if (Input.GetKeyDown(KeyCode.Space)) { StartCoroutine("Strafe"); } if (playerAbilityDetected) { if (abilityID == 2) { return; } canBeChanged = false; UseDefenseWeight = 0; if (abilityID == 1) { UseDefenseWeight += 10; if (distance >= 10) { UseDefenseWeight += 10; } else if (BossBrain.instance.bossAbility.ultimateAbilityActivated) { if (!BossBrain.instance.hasUltimateAvail) { UseDefenseWeight += 10; } if (abilityDamageRank > bossResources.GetHealth()) { UseDefenseWeight += 20; } } int rand = Random.Range(0, 101); if (rand >= bossResources.GetHealthPercentage()) { UseDefenseWeight += 20; } } else if (abilityID == 3) { UseDefenseWeight += 20; if (distance >= 15) { UseDefenseWeight += 5; if (abilityDamageRank > bossResources.GetHealth()) { if (Random.Range(0, 100) > bossResources.GetHealthPercentage()) { UseDefenseWeight += 10; } } } else { UseDefenseWeight += 15; } } if (UseDefenseWeight >= 30 && defenceAbilityAvailable) { bossAnimController.SetBool("isWalking", false); bossAnimController.SetBool("isDefend", true); currentState = DefenseState.Ability; if (!state.text.Equals(previousState.text)) { previousState.text = state.text; } state.text = "Defense"; } else if (UseDefenseWeight <= 30 && !defenceAbilityActive) { currentState = DefenseState.Strafe; StartCoroutine("Strafe"); if (!state.text.Equals(previousState.text)) { previousState.text = state.text; } state.text = "Strafe"; } playerAbilityDetected = false; } else { if (currentState == DefenseState.None) { currentState = DefenseState.Run; bossAnimController.SetBool("isWalking", true); StartCoroutine("RunAway"); if (!state.text.Equals(state.text)) { previousState.text = state.text; state.text = "RunAway"; } } } }
public void EndDefenceAnim() { currentState = DefenseState.None; bossAnimController.SetBool("isDefend", false); canBeChanged = true; }
public override void Process() { DesirabilitiesConfig desirabilitiesConfig = GameManager.Instance.DesirabilitiesConfig; float vigilanceConsideration = desirabilitiesConfig.DefensePlayerConsiderationMinVigilance; float vigilance = (desirabilitiesConfig.DefensePlayerDesirabilityByAggressivity.Evaluate(owner.Creature.Traits.Vigilance.Value) - vigilanceConsideration) * (1 / (1 - vigilanceConsideration)); vigilance *= (Player.Instance.PlayerController.Velocity.magnitude * desirabilitiesConfig.DefensePlayerPlayerSpeedThreatWeight); float distToAttack = Mathf.Lerp(minDistToAttack, maxDistToAttack, vigilance); float distToPursuit = Mathf.Lerp(minDistToPursuit, maxDistToPursuit, vigilance); Vector3 playerPos = Player.Instance.transform.position; float distanceToPlayer = Vector3.Distance(owner.transform.position, playerPos); Goal child = GetActiveGoal(); if (child != null && child.IsInactive) { child.Activate(); } switch (defenseState) { case DefenseState.LookAt: if (owner.Steering.Behavior != eSteeringBehavior.LookAtPlayer) { AddSubgoal(new GoalLookAtPlayer(owner)); } else if (distanceToPlayer < 2) { if (child != null) { child.Abort(); } AddSubgoal(new GoalAttackPlayer(owner)); defenseState = DefenseState.Attack; timeStart = Time.time; } else if (Time.time - timeStart >= desirabilitiesConfig.DefensePlayerMaxTimeSpend) { status = GoalStatus.Completed; } else { IReadOnlyCollection <DataCreature> friends = owner.Memory.Creatures.Read(); bool friendAggresed = false; Agent friend = null; foreach (DataCreature data in friends) { if (!data.creature) { continue; } Agent agent = data.creature.agentCreature; if (!agent.gameObject.activeSelf || data.RegistrationDate < Time.time - 1f) { continue; } if (Vector3.Distance(agent.transform.position, playerPos) < distToAttack) { friendAggresed = true; friend = agent; break; } } if (!friendAggresed) { friendAggresed = Vector3.Distance(owner.transform.position, playerPos) < distToAttack; friend = owner; } if (friendAggresed) { if (child != null) { child.Abort(); } AddSubgoal(new GoalPursuitPlayer(owner)); defenseState = DefenseState.Pursuit; if (Random.value > 0.5f) { owner.Creature.AudioBox.PlayOneShot(SoundOneShot.CreatureDefense); } timeStart = Time.time; } } break; case DefenseState.Pursuit: if (child.IsComplete) { AddSubgoal(new GoalAttackPlayer(owner)); defenseState = DefenseState.Attack; } else if (child.HasFailed) { defenseState = DefenseState.LookAt; } else if (Vector3.Distance(owner.transform.position, playerPos) > distToPursuit) { child.Abort(); defenseState = DefenseState.LookAt; } break; case DefenseState.Attack: if (child.IsComplete || child.HasFailed) { IReadOnlyCollection <DataCreature> friends = owner.Memory.Creatures.Read(); bool friendAggresed = false; Agent friend = null; foreach (DataCreature data in friends) { if (!data.creature) { continue; } Agent agent = data.creature.agentCreature; if (!agent.gameObject.activeSelf || data.RegistrationDate < Time.time - 1f) { continue; } if (Vector3.Distance(agent.transform.position, playerPos) < distToAttack) { friendAggresed = true; friend = agent; break; } } if (!friendAggresed) { friendAggresed = Vector3.Distance(owner.transform.position, playerPos) < distToAttack; friend = owner; } if (friendAggresed) { if (child != null) { child.Abort(); } AddSubgoal(new GoalPursuitPlayer(owner)); defenseState = DefenseState.Pursuit; } else { AddSubgoal(new GoalLookAtPlayer(owner)); defenseState = DefenseState.LookAt; } } break; } base.ProcessSubgoals(); }
void Start() { personCtrl = this.GetComponent<HeroCtrl>(); heroStateActVer = new IdleStateActVer(this.gameObject); heroStateMoveVer = new IdleStateMoveVer(this.gameObject); inputArgs = new InputEventArgs("", "", ""); hero_act_state[0] = new IdleStateActVer(this.gameObject); hero_act_state[1] = new ActState(this.gameObject); hero_act_state[2] = new DefenseState(this.gameObject); hero_move_state[0] = new IdleStateMoveVer(this.gameObject); hero_move_state[1] = new MoveState(this.gameObject); hero_move_state[2] = new JumpState(this.gameObject); InputTran += new InputEventHandler(heroStateActVer.handleInput); InputTran += new InputEventHandler(heroStateMoveVer.handleInput); }
void Start() { PlayerAutomate = false; AutomateSpeed = 0.01f; AnswerCount = 0; DebugScript = GameObject.Find("DebugObject").GetComponent<GameDebugScript>(); Basic = GameObject.Find("Basic"); Strong = GameObject.Find("Strong"); Special = GameObject.Find("Special"); NoCombatState = new NoCombatState(this); AttackState = new AttackState(this); DefenseState = new DefenseState(this); AnswerState = new AnswerState(this); AnimatingState = new AnimatingState(this); Camera = new CameraController(GameObject.Find("Main Camera")); Waypoint = new Waypoint(); Waypoint.CurrentPosition = new Vector3(-1.65f, 0.9f, -1.0f); Waypoint.WaypointPosition = new Vector3(0.9f, 0.9f, -1.0f); MonsterWaypoint = new Vector3(3.1f, 1.05f, -1.0f); Camera.WaypointPosition = Waypoint.WaypointPosition + new Vector3(1.1f, 0f, -10.0f); WaypointCounter = 0; UIView = GameObject.Find("GameController").GetComponent<UIView>(); PlayerFactory = new PlayerFactory(); EnemyFactory = new EnemyFactory(); // Player Factory Player = PlayerFactory.CreatePlayer("Wizard", Application.loadedLevel, GameObject.Find("Player")); Player.WaypointPosition = Waypoint.WaypointPosition; State = NoCombatState; }
void Start() { playerModelDefaultRotation = playerModel.transform.localRotation; playerModelClimbRotation = Quaternion.identity; playerModelTauntRotation.SetLookRotation(new Vector3(0, 0, -1), new Vector3(0, 1, 0)); attackCollider.enabled = false; lightningGenerator.SetActive(false); // temp dashAttackCollider.enabled = false; shieldCollider.enabled = false; ShowShield(false); ShowHorn(false); playerAnimator = GetComponent <Animator>(); GameObject.FindGameObjectWithTag("GameSession").GetComponent <SavePlayerState>().RecoverPlayerStatusValues(this); staminaRecovery = 0.0f; fullStaminaRecovery = false; GameObject guiObject = GameObject.Find("GUI"); if (guiObject) { guiManager = guiObject.GetComponent <GUIManager>(); } activeRespawnPoint = initialPosition; cameraFade = GameObject.Find("PlayerCamera").GetComponent <CameraFade>(); attack = new AttackState(CalculateFramesFromTime(attackDuration)); cast = new CastState(CalculateFramesFromTime(castDuration)); climb = new ClimbState(); dash = new DashState(CalculateFramesFromTime(dashDuration)); dead = new DeadState(CalculateFramesFromTime(deadDuration)); defense = new DefenseState(); drink = new DrinkState(CalculateFramesFromTime(drinkDuration)); fall = new FallState(); fallcloud = new FallCloudState(CalculateFramesFromTime(fallCloudDuration)); hit = new HitState(CalculateFramesFromTime(hitDuration)); idle = new IdleState(); jump = new JumpState(CalculateFramesFromTime(GetComponent <PlayerMove>().timeToJumpApex)); refill = new RefillState(CalculateFramesFromTime(refillDuration)); taunt = new TauntState(CalculateFramesFromTime(tauntDuration)); walk = new WalkState(); SetState(idle); facingRight = true; jumpAvailable = true; climbLadderAvailable = false; beerRefillAvailable = false; justHit = false; jumpFrames = 0; framesInDelayCount = 0; camFollow = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <CameraFollow>(); colliderSize = GetComponent <BoxCollider>().size; godMode = false; }