protected override void OnStateExit(RangedAIState state) { switch (state) { case RangedAIState.Idle: { Animator.SetTrigger("Combat"); } break; case RangedAIState.Strafe: { _strafeElapsedCooldown = 0f; _strafeElapsedTime = 0f; _attackRequestElapsedCooldown = 0f; } break; case RangedAIState.Attack: { AttackTarget.SendMessage("CompleteAttack", gameObject); } break; case RangedAIState.Hit: { RVOController.locked = false; } break; } }
protected override void Update() { base.Update(); ConductorSM hero = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetHero(); if (hero == null) { return; } CalculateIndicator(); if (!hero.IsDragging()) { StopDrag(false); } if (AttackTarget != null) { if (AttackTarget.CanNotInteract()) { AttackTarget = null; } } _attackingDenyPeriod -= Time.deltaTime; if (_attackingDenyPeriod <= 0) { IsAttackingAllowed = true; } if (AttackTarget != null) { float dist = AttackTargetDistance(); if (dist > AttackMaxDistance) { AttackTarget = null; } } }
public void EnemyAct() { Debug.Log(gameObject.name + "使用了技能1"); Debug.Log("名称:砍击"); m_Anim.SetTrigger("attack"); AttackTarget.GetComponent <RoleBase>().TakeDamage(attack); }
private AttackTarget searchForEnemy() { LayerMask mask = LayerMask.GetMask("Battle"); List <Collider2D> colliders = Physics2D.OverlapCircleAll(this.transform.position, searchRadius, mask) .Where(o => o.CompareTag("Enemy")) .OrderBy(o => (o.transform.position - this.transform.position).sqrMagnitude) .ToList(); if (colliders.Count > 0) { AttackTarget target = colliders[0].GetComponent <AttackTarget>(); if (this.transform.position.x > target.transform.position.x) { this.flipped = true; } else { this.flipped = false; } return(target); } return(null); }
public float DoAttack(AttackTarget target) { float damage = this.attackActor.GetDamagePower() - target.GetDamageReduction(); damage = (damage <= 0) ? 0 : damage; // In case of return(target.hitByTarget(this.attackActor, damage)); }
/* VIRTUAL FUNCTIONS */ //this function decides how the enemy detects the player, either scientist or swarm //sets public virtual void Awareness() { float mult = 1f; if (EnableLight && !Light.GetComponent <RoomLight>().turnedOn) { mult = sightDampen; } if (ScientistInSight(sightRange * mult, sightAngle)) { currTarget = AttackTarget.scientist; currTargetPos = getScientistCenterPos(); Debug.DrawRay(Scientist.S.transform.position, Vector3.up * 3f, Color.green); } else if (SwarmInSight(sightRange * mult, sightAngle)) { currTarget = AttackTarget.swarm; currTargetPos = Swarm.S.transform.position; Debug.DrawRay(Swarm.S.transform.position, Vector3.up * 3f, Color.green); } else { currTarget = AttackTarget.none; currTargetPos = Vector3.zero; } }
static public void clearState(AttackTarget stateID, uint state) { if ((uint)stateID < uint.MaxValue) { state &= (byte)(~((byte)(1 << ((int)stateID % 8)))); } }
private void Attack() { if (m_CurrentAttackCooldown > 0f) { m_CurrentAttackCooldown -= Time.deltaTime; AttackTarget = null; // we're not ready to attack, ignore the mouse hold or npc targeting from this frame } else if (AttackTargetIsInAttackRange()) { CharacterBehaviour characterBehaviour = AttackTarget.GetComponent <CharacterBehaviour>(); if (characterBehaviour != null && !characterBehaviour.Dead()) { m_CurrentAttackCooldown = AttackCooldown; m_Animator.ResetTrigger("Hit"); m_Animator.SetTrigger("Attack"); characterBehaviour.ApplyDamage(Damage); } AttackTarget = null; // we've executed the attack, require a new mouse hold/click or npc targeting } else if (InteractTargetIsInInteractRange()) { ItemPickup itemPickup = InteractTarget.GetComponent <ItemPickup>(); if (itemPickup != null) { GetComponent <CharacterInventory>().AddItem(itemPickup.ItemId); Destroy(InteractTarget); } InteractTarget = null; } }
protected override void Init() { colliderProximity = areaColliders[0]; colliderMidRange = areaColliders[1]; knifeAttack = GetComponent <EnemyKnifeAttack>(); grenadeAttack = GetComponent <AttackTarget>(); }
public void SetAttackTarget(AttackTarget Target) { this.Target = Target; Recalculate(); if (OnChanged != null) { OnChanged(this, EventArgs.Empty); } }
static public bool checkAttackState(AttackTarget stateID, uint state) { if ((uint)stateID < uint.MaxValue) { return((state & (uint)stateID) > 0); } return(false); }
public override AttackTarget ScanTargets(AttackTarget currentTarget) { if (!currentTarget || !currentTarget.isActiveAndEnabled) { RescanAttackTargets(); return(FocusTarget()); } return(null); }
public virtual void AttackRangeCheck() { Vector2 dist = AttackTarget.transform.position - transform.position; // Get distance between NPC and target if (dist.magnitude <= AttackRange) // Is target within attack range? { attacked = true; Attack(AttackTarget.GetComponent <Character>()); // Attack target! } }
/// <summary> /// Stops fighting. /// </summary> public void StopAttack() { RecoveryCounter = 0; if (AttackTarget != null) { // Attacker aus Angreiferliste entfernen AttackTarget.RemoveAttackerItem(this); AttackTarget = null; } }
// ------------------------------------------------------------------------ // General functions // ------------------------------------------------------------------------ public void attack() { if (this.isAttackColdownReady) { this.isFighting = true; this.attackColdownTimer = 0; Collider2D target = Physics2D.OverlapCircle(this.attackHitPoint.transform.position, this.meleeRange); AttackTarget t = target.GetComponent <AttackTarget>(); this.attackType.DoAttack(t); } }
protected void FixedUpdate() { HandleAnimation(); if (!Alive() || !GameManager.Instance.GameStarted || !navMeshAgent.isOnNavMesh) { return; } if (InArea && InArea.Visible() && MovementAudio && !MovementAudio.isPlaying) { MovementAudio.Play(); } else if (InArea && !InArea.Visible() && MovementAudio && MovementAudio.isPlaying) { MovementAudio.Stop(); } if (SPE.GetStatMax() < 1) { Debug.LogWarning("Speed is 0"); } navMeshAgent.speed = Walking ? Mathf.Min(WalkingSpeed, SPE.GetStatMax()) / 2f : SPE.GetStatMax() / 2f; DesiredVelocity = navMeshAgent.desiredVelocity.sqrMagnitude; AgentVelocity = navMeshAgent.velocity.sqrMagnitude; HasPath = navMeshAgent.hasPath; PathStale = navMeshAgent.isPathStale; IsOnNavMesh = navMeshAgent.isOnNavMesh; //if (IncoherentNavAgentSpeed() && agentStuckRoutine == null) // agentStuckRoutine = StartCoroutine(CheckForNavAgentStuck(0.25f)); //TODO: merge together with move's switch statement if (Attacking() && AttackTarget && AttackTarget.Alive() && InAttackRange() ) //has live enemy target and in attackrange { navMeshAgent.isStopped = true; if (_attackRoutine == null) { _attackRoutine = StartCoroutine(AttackRoutine()); } } else { navMeshAgent.isStopped = false; SelectAction(); } }
private void ChangeState(AttackUnitState toState) { if (currentRoutine != null) { StopCoroutine(currentRoutine); currentRoutine = null; } animator.SetBool("Attacking", false); target = null; state = toState; }
private void DoHurt() { var isCrit = Random.value <= 0.1; if (isCrit) { AttackTarget.Hurt((int)(AttackHurt * 1.2f), true); } else { AttackTarget.Hurt(AttackHurt, false); } }
private void OnEnable() { zombieStateMachine = GetComponent <ZombieStateMachine>(); agent = GetComponent <NavMeshAgent>(); rb = GetComponent <Rigidbody>(); attack_target = new AttackTarget(); rb.isKinematic = false; // Add the events zombieStateMachine.OnSeekPath.AddListener(SeekNavigationTargetAfterAttacking); zombieStateMachine.OnWalkingStart.AddListener(ResumeNavigation); zombieStateMachine.OnAttackStart.AddListener(StopNavigation); zombieStateMachine.OnDrinkingStart.AddListener(StopNavigation); zombieStateMachine.OnDyingStart.AddListener(StopNavigation); }
public AgentBehaviorTreeBuilder Action(ActionType type) { Action action = null; switch (type) { case ActionType.AssignTarget_Agent_ClosestInView: action = new AssignTarget(agent, TargetType.Agent, TargetCriteria.ClosestInView); break; case ActionType.AssignTarget_Food_ClosestInView: action = new AssignTarget(agent, TargetType.Food, TargetCriteria.ClosestInView); break; case ActionType.Eat: action = new Eat(agent); break; case ActionType.AttackTarget: action = new AttackTarget(agent); break; case ActionType.MoveToTarget: action = new MoveToTarget(agent); break; case ActionType.SteerToTarget: action = new SteerToTarget(agent); break; case ActionType.Wander: action = new Wander(agent); break; case ActionType.ChangeColor_Aggressive: action = new ChangeColorStatus(agent, ColorStatus.Aggressive); break; case ActionType.ChangeColor_Passive: action = new ChangeColorStatus(agent, ColorStatus.Passive); break; } base.Action(action); return(this); }
private void ColorCells(AttackTarget style, List <Cell> cells) { foreach (Cell cell in cells) { if (cell != null) { if (style == AttackTarget.beeline) { cell.DoBeelineColor(); } else if (style == AttackTarget.volley) { cell.DoVolleyColor(); } } } }
public void Update(GameTime gameTime) { if (controlledUnit == null) { return; } if (AttackTarget != null && AttackTarget.IsDead()) { AttackTarget = null; } fsm.Update(gameTime); if (steering != null) { steering.Steer((float)gameTime.ElapsedGameTime.TotalSeconds); } }
IEnumerator DefendingAttack(GameObject attackTarget) { target = attackTarget.GetComponent <AttackTarget>(); while (target.GetHealth() > 0) { Vector3 closestToTarget = GetComponent <Collider>().ClosestPoint(attackTarget.transform.position); Vector3 closestToThis = attackTarget.GetComponent <Collider>().ClosestPoint(transform.position); if (Vector3.Distance(closestToThis, closestToTarget) < 50 && Vector3.Distance(closestToThis, closestToTarget) > weapon.GetRange()) { animator.SetBool("Attacking", false); if (gameObject.GetComponent <IndividualMovement>().moving == false) { GetComponent <IndividualMovement>().MoveTo(new Destination(attackTarget), null, true); } yield return(new WaitForSeconds(0.05f)); } else if (Vector3.Distance(closestToThis, closestToTarget) > 50) { ChangeState(AttackUnitState.DEFENDING); } else { animator.SetBool("Attacking", true); target.TakeDamage(weapon.GetDamage()); Vector3 dir = (attackTarget.transform.position - transform.position).normalized; transform.rotation = Quaternion.LookRotation(new Vector3(dir.x, 0, dir.z), Vector3.up); if (target.GetHealth() <= 0) { ChangeState(AttackUnitState.DEFENDING); } yield return(new WaitForSeconds(1.0f / weapon.GetFiringRate())); } } ChangeState(AttackUnitState.DEFENDING); yield return(null); }
private IEnumerator AttackRoutine() { //Debug.Log(gameObject.name + " is Attacking " + AttackTarget.gameObject.name); State = CharacterState.Attacking; while (Attacking() && InAttackRange() && AttackTarget.Alive()) { (this as Goblin)?.Speak(SoundBank.GoblinSound.Attacking); //HIT TARGET var damage = Random.Range(1, DMG.GetStatMax()) * OutgoingDmgPct; if (AttackTarget.Surprised()) { damage = (int)(damage * AmbushModifier); } var target = AttackTarget; if (!(target.Team && GameManager.Instance.InvincibleMode)) { target.Health -= (int)Mathf.Round(damage * target.IncomingDmgPct); } if (target.Health <= 0) { //Debug.Log(name + " killed " + target.name); if (this as Goblin) { ((Goblin)this).Xp += GameManager.XpKill(); if (Team) { Team.OnTeamKill.Invoke(); } (this as Goblin)?.Speak(SoundBank.GoblinSound.Laugh); } break; } //Debug.Log(gameObject.name + " hit " + AttackTarget.gameObject.name +" for " + Damage + " damage"); //should be tied to animation maybe? yield return(new WaitForSeconds(AttackTime)); } _attackRoutine = null; }
new public void Update() { //base.Update(); if (hp <= 0) { //Удалить все эффекты fightController.enemies.Remove(this); DestroyHalo(halo); Death(); } HB.GetComponentInChildren <TextMeshProUGUI>().text = $"{Mathf.Ceil(hp)}/{Mathf.Ceil(maxhp)}"; if (time > 0) { time -= Time.deltaTime; } else { time = cooldown; float r = Random.Range(0, 2); switch (r) { case 0: SetTargetRandom(); StartCoroutine(AtakeAnim()); AttackTimeout = AttackCooldown; float dam = Random.Range(DamageMin, DamageMax) * (1 + power / 100); AttackTarget.TakeDamage(dam); TakeHeal(dam); StartCoroutine(AttackTarget.TakingDamageAnim()); break; case 1: foreach (var x in fightController.friends) { var st = Instantiate(vulnerability, x.transform); st.Name = "Уязвимость"; st.lifetime = 8; st.koef = Information.GetEffectStates("Уязвимость", 1, 0)[0]; st.character = x; x.TakeDamage(3); } break; } } }
public string AnimationName; //Name of animation used when attacking public AttackDetails(AttackDetailsInstance original) { AttackName = original.AttackName; Type = original.Type; Target = original.Target; Damage = original.Damage; Cooldown = original.Cooldown; BuffType = original.BuffType; BuffChance = original.BuffChance; BuffDuration = original.BuffDuration; BuffPotency = original.BuffPotency; Effect = original.Effect; EffectChance = original.EffectChance; EffectDuration = original.EffectDuration; EffectPotency = original.EffectPotency; Icon = original.Icon; AnimationName = original.AnimationName; }
void Update() { if (this.targetStrategy) { AttackTarget newAttackTarget = this.targetStrategy.ScanTargets(this.attackTarget); if (newAttackTarget) { this.attackTarget = newAttackTarget; if (this.movement) { this.movement.Init(this.attackTarget); } } } if (this.attackBehaviour) { this.attackBehaviour.TriggerAttack(); } }
protected override void OnStateEnter(MeleeAIState state) { switch (state) { case MeleeAIState.Idle: { } break; case MeleeAIState.Strafe: { _strafeDir = Random.value > 0.5f ? 1f : -1f; //Animator.SetFloat(AnimatorHash.VelocityX, 0f); //Animator.SetFloat(AnimatorHash.VelocityZ, 0f); } break; case MeleeAIState.Rush: { } break; case MeleeAIState.Attack: { Animator.SetTrigger(AnimatorHash.Attack); } break; case MeleeAIState.Hit: { AttackTarget.SendMessage("CompleteAttack", gameObject); RVOController.locked = true; if (IsDead) { CurrentState = MeleeAIState.Dead; } } break; } }
public override void Attack() { this.enemy = this.GetComponentInParent <Enemy>(); if (this.enemy) { this.attackTarget = enemy.attackTarget; } if (attackTarget) { float distance = Math.Abs(attackTarget.transform.position.x - this.firePoint.transform.position.x); if (fire && distance < 1.0f) { Transform obj = Instantiate(bullet, firePoint.position, firePoint.rotation).GetComponent <Transform>(); } fire = false; } }
private bool InAttackRange() { if (!AttackTarget || !AttackTarget.Alive()) { return(false); } var targetCol = AttackTarget.GetComponent <CapsuleCollider>(); if (!targetCol) { Debug.LogWarning(name + "'s target does not have a capsule collider"); return(false); } var boxCol = GetComponent <CapsuleCollider>(); return((boxCol.transform.position - (targetCol.transform.position)).magnitude <= boxCol.radius * boxCol.transform.lossyScale.x + targetCol.radius * targetCol.transform.lossyScale.x + AttackRange); }
void Start() { enemiesInRange = new List<EnemyHealth> (); weapon = GetComponent<AttackTarget> (); }
static public bool checkAttackState(AttackTarget stateID, uint state) { if ((uint)stateID < uint.MaxValue) { return ((state & (uint)stateID) > 0); } return false; }
/* VIRTUAL FUNCTIONS */ //this function decides how the enemy detects the player, either scientist or swarm //sets public virtual void Awareness() { float mult = 1f; if(EnableLight && !Light.GetComponent<RoomLight>().turnedOn) { mult = sightDampen; } if (ScientistInSight(sightRange * mult, sightAngle)) { currTarget = AttackTarget.scientist; currTargetPos = getScientistCenterPos(); Debug.DrawRay(Scientist.S.transform.position, Vector3.up * 3f, Color.green); } else if(SwarmInSight(sightRange * mult, sightAngle)) { currTarget = AttackTarget.swarm; currTargetPos = Swarm.S.transform.position; Debug.DrawRay(Swarm.S.transform.position, Vector3.up * 3f, Color.green); } else { currTarget = AttackTarget.none; currTargetPos = Vector3.zero; } }