void Update() { timer += Time.deltaTime; if (timer >= timeBetweenAttacks && enemyInRange) { Attack(); } if (targetHealth != null && targetHealth.IsDead()) { controller.FindNextTarget(); /* * if (target.tag == "Player") * { * anim.SetTrigger("PlayerDead"); * } * else * { * controller.FindNextTarget(); * } */ } }
private SmartEntity GetPrefferedBuilding(ShooterComponent shooterComp, PriorityList <SmartEntity> buildings, ref int maxWeight) { HashSet <string> hashSet = new HashSet <string>(); SmartEntity result = null; int i = 0; int count = buildings.Count; while (i < count) { ElementPriorityPair <SmartEntity> elementPriorityPair = buildings.Get(i); SmartEntity element = elementPriorityPair.Element; HealthComponent healthComp = element.HealthComp; if (healthComp != null && !healthComp.IsDead()) { BuildingComponent buildingComp = element.BuildingComp; if (buildingComp.BuildingType.Type != BuildingType.Blocker && (element.TrapComp == null || element.TrapComp.CurrentState == TrapState.Armed) && hashSet.Add(buildingComp.BuildingType.BuildingID)) { int num = this.CalculateWeight(shooterComp, null, healthComp.ArmorType, elementPriorityPair.Priority); if (num > maxWeight) { maxWeight = num; result = element; } } } i++; } return(result); }
private void OnCollisionEnter2D(Collision2D collision) { if (collision.collider.CompareTag("enemy")) { // TODO: do this too: but then also add a new trigger. // Physics2D.IgnoreCollision(myCollider, collision.collider); // take damage. HealthComponent otherHealthComp = collision.collider.GetComponent <HealthComponent>(); if (!otherHealthComp.IsDead()) { myHealth.TakeDamage(otherHealthComp.touchDamage); } } else if (collision.collider.CompareTag("ground")) { jumpsLeft = maxjumps; Debug.Log("jump reset by" + collision.collider); } else if (collision.collider.CompareTag("pickup")) { var pickupComp = collision.collider.GetComponent <PickupableItem>(); pickupComp.OnPickup(gameObject); } else if (collision.collider.CompareTag("platform")) { if (!crouch) { jumpsLeft = maxjumps; Debug.Log("jump reset by" + collision.collider); } } }
protected override void OnBeforeAttack(SmartEntity troop) { if (this.hitShieldCell == null) { return; } if (this.hitShieldCell.Obstacles != null) { int i = 0; int count = this.hitShieldCell.Obstacles.Count; while (i < count) { if (this.hitShieldCell.Obstacles[i] != null) { HealthComponent healthComp = ((SmartEntity)this.hitShieldCell.Obstacles[i]).HealthComp; if (healthComp != null && !healthComp.IsDead()) { SecondaryTargetsComponent secondaryTargetsComp = troop.SecondaryTargetsComp; secondaryTargetsComp.ObstacleTarget = this.hitShieldCell.Obstacles[i]; secondaryTargetsComp.ObstacleTargetPoint = new Point(this.hitShieldCell.X, this.hitShieldCell.Z); break; } } i++; } } }
// Update is called once per frame void Update() { if (!health.IsDead()) { FindNextTarget(); Vector3 realpos = this.transform.position + offset; int x, z; tileMap.nodeAtLocation(realpos, out x, out z); int pathx, pathz; tileMap.nodeAtLocation(pathToTarget[pathIndex], out pathx, out pathz); if (pathx == x && pathz == z) { if (pathIndex + 1 < pathToTarget.Length) { pathIndex++; movement.setTargetPosition(pathToTarget[pathIndex]); } else { movement.setTargetPosition(target.transform.position); } } } }
public void InformTurretsAboutTroop(List <EntityElementPriorityPair> turretsInRangeOf, SmartEntity entity, HashSet <ShooterComponent> resetReevaluateTargetSet) { int i = 0; int count = turretsInRangeOf.Count; while (i < count) { EntityElementPriorityPair entityElementPriorityPair = turretsInRangeOf[i]; SmartEntity smartEntity = (SmartEntity)entityElementPriorityPair.Element; HealthComponent healthComp = smartEntity.HealthComp; if (healthComp != null && !healthComp.IsDead()) { ShooterComponent shooterComp = smartEntity.ShooterComp; if (shooterComp != null) { TurretShooterComponent turretShooterComp = smartEntity.TurretShooterComp; if (turretShooterComp != null) { this.AddTurretTarget(shooterComp, turretShooterComp, entity, entityElementPriorityPair.Priority, resetReevaluateTargetSet); } } } i++; } }
private bool UpdateWallBreakingTroops(SmartEntity entity, TargetingController.OnTargetingDone onTroopTargetingDone) { if (!entity.TroopComp.UpdateWallAttackerTroop) { return(false); } entity.TroopComp.UpdateWallAttackerTroop = false; if (entity.ShooterComp.Target == null) { return(false); } HealthComponent healthComp = entity.ShooterComp.Target.HealthComp; if (healthComp == null || healthComp.IsDead()) { return(false); } if (entity.ShooterComp.AttackFSM.IsAttacking && entity.SecondaryTargetsComp.CurrentAlternateTarget != null && entity.SecondaryTargetsComp.ObstacleTarget == null) { entity.ShooterComp.AttackFSM.StopAttacking(true); bool flag = false; bool flag2 = Service.PathingManager.RestartPathing(entity, out flag, false); if (flag2 && flag) { SmartEntity primaryTarget = this.shooterController.GetPrimaryTarget(entity.ShooterComp); onTroopTargetingDone(entity); this.shooterController.StopSearch(entity.ShooterComp); this.OnPathingComplete(entity, entity.SecondaryTargetsComp, entity.StateComp, entity.ShooterComp, primaryTarget); } return(true); } return(false); }
private void EnsurePrimaryTarget(SmartEntity entity) { if (entity.ShooterComp.Target != null) { ShooterComponent shooterComp = entity.ShooterComp; HealthComponent healthComp = shooterComp.Target.HealthComp; if (healthComp == null || healthComp.IsDead()) { Service.TargetingController.InvalidateCurrentTarget(entity); } } }
private SmartEntity FindValidTargetFromTroopNodeList <T>(NodeList <T> troopNodeList, SmartEntity attackerEntity, ref int maxWeight, SmartEntity finalTarget) where T : Node <T>, new() { for (T t = troopNodeList.Tail; t != null; t = t.Previous) { SmartEntity smartEntity = (SmartEntity)t.Entity; HealthComponent healthComp = smartEntity.HealthComp; if (!healthComp.IsDead() && (long)GameUtils.GetSquaredDistanceToTarget(attackerEntity.ShooterComp, smartEntity) >= (long)((ulong)attackerEntity.ShooterComp.MinAttackRangeSquared) && this.CheckTarget(attackerEntity, smartEntity, ref maxWeight)) { finalTarget = smartEntity; } } return(finalTarget); }
public void UpdateLootOnHealthChange(Entity entity, HealthComponent healthComp, int delta) { if (delta == 0) { return; } LootComponent lootComponent = entity.Get <LootComponent>(); if (lootComponent == null || delta == 0) { return; } if (healthComp.IsDead()) { return; } this.EarnLootFromDamage(lootComponent, healthComp, delta); Service.EventManager.SendEvent(EventId.LootEarnedUpdated, lootComponent); }
private void OnDamageShieldBorder(Entity shieldGeneratorEntity, Bullet bullet) { if (shieldGeneratorEntity == null) { return; } HealthComponent healthComp = bullet.Target.HealthComp; if (healthComp == null || healthComp.IsDead()) { return; } Vector3 targetWorldLocation = bullet.TargetWorldLocation; if (bullet.GunLocator != null && bullet.Owner != null) { targetWorldLocation.y = bullet.GunLocator.transform.position.y; } this.effects.ApplyHitEffect(shieldGeneratorEntity, targetWorldLocation); }
protected bool IsTargetAliveAndInRange(SmartEntity entity, SmartEntity target) { if (target == null) { this.OnTargetIsNull(entity); return(false); } HealthComponent healthComp = target.HealthComp; if (healthComp == null || healthComp.IsDead()) { this.OnTargetIsDead(entity); return(false); } if (!this.IsTargetInRange(entity.ShooterComp, target)) { this.OnTargetIsOutOfRange(entity); return(false); } return(true); }
private SmartEntity GetPrefferedBuilding(ShooterComponent shooterComp, SmartEntityPriorityList buildings, ref int maxWeight) { HashSet <string> hashSet = new HashSet <string>(); SmartEntity result = null; int i = 0; int count = buildings.Count; while (i < count) { SmartEntityElementPriorityPair smartEntityElementPriorityPair = buildings.Get(i); SmartEntity element = smartEntityElementPriorityPair.Element; if (!shooterComp.ShooterVO.NewTargetOnReload || shooterComp.IsPotentialTargetNew(element.ID)) { HealthComponent healthComp = element.HealthComp; if (healthComp != null && !healthComp.IsDead()) { BuildingComponent buildingComp = element.BuildingComp; if (buildingComp.BuildingType.Type != BuildingType.Blocker) { if (element.TrapComp == null || element.TrapComp.CurrentState == TrapState.Armed) { if (hashSet.Add(buildingComp.BuildingType.BuildingID)) { int num = this.CalculateWeight(shooterComp, null, healthComp.ArmorType, smartEntityElementPriorityPair.Priority); if (num > maxWeight) { maxWeight = num; result = element; } } } } } } i++; } return(result); }
private void CheckHp() { if (!isTargetSet) { return; } if (target == null) { DispatchEvent(); return; } HealthComponent healthComponent = target.GetComponent <HealthComponent>(); bool matched = healthComponent == null || healthComponent.IsDead() || (float)healthComponent.Health / healthComponent.MaxHealth <= hpThreshold; if (matched) { DispatchEvent(); } }
public bool IsAttackerThenFlag(SmartEntity target, object self) { if (target == null) { return(false); } if (target.ShooterComp != null && target.ShooterComp.Target != null) { HealthComponent healthComp = target.ShooterComp.Target.HealthComp; if (healthComp == null || healthComp.IsDead()) { return(false); } } if (target.AttackerComp != null) { TroopComponent troopComp = target.TroopComp; if (troopComp != null && !troopComp.IsAbilityModeActive) { troopComp.UpdateWallAttackerTroop = true; } } return(false); }
public void OnDeath() { animator.SetBool("IsDead", healthComponent.IsDead()); }
public void UpdateTroop(SmartEntity troop) { this.EnsurePrimaryTarget(troop); this.UpdateTroopShield(troop); SmartEntity troopTarget = this.shooterController.GetTroopTarget(troop); for (SmartEntity troopWallCrushingTarget = this.shooterController.GetTroopWallCrushingTarget(troop); troopWallCrushingTarget != null; troopWallCrushingTarget = this.shooterController.GetTroopWallCrushingTarget(troop)) { if (!this.CanCrushNearTargetNow(troop, troopWallCrushingTarget)) { break; } this.OnTargetWallIsDestroyed(troop, troopWallCrushingTarget); } while (troopTarget != null) { HealthComponent healthComp = troopTarget.HealthComp; if (healthComp != null && !healthComp.IsDead()) { break; } this.OnTargetIsDead(troop); troopTarget = this.shooterController.GetTroopTarget(troop); } ShooterComponent shooterComp = troop.ShooterComp; bool flag = shooterComp.PrimaryTargetMoved(); PathingComponent pathingComp = troop.PathingComp; bool flag2 = pathingComp == null || pathingComp.CurrentPath == null || pathingComp.GetNextTile() == null; if (troopTarget == null) { this.OnTargetIsNull(troop); } else if (!this.IsTargetInRangeForAttack(troop, troopTarget, flag2) || (flag && shooterComp.Target != troopTarget)) { this.OnTargetIsOutOfRange(troop, flag); } else { if (troopTarget.TransformComp == null) { base.UpdateShooter(troop); return; } this.hitShieldCell = null; if (flag2) { this.UpdateShieldInLineOfShoot(troop, troopTarget); base.UpdateShooter(troop); return; } if (this.HasLineOfSight(troop, troopTarget)) { if (!TroopController.IsEntityHealer(troop) || flag2) { base.UpdateShooter(troop); } return; } this.OnTargetIsOutOfRange(troop, flag2 || flag); } }