private void UpdateInit(IUpdateEventArgs args) { _targetting = new RadiusExitTargetting(args.Sim.Map, _host.Tile, 1, 1); _targetting.OwnTeam = _host.Stats.Team; _state = TowerBehaviourState.Searching; }
private void UpdateAiming(float ticks) { // find rotation angle from us to target var targetDirection = CalcTargetDirection(); // update our direction according to our rotation rate _rotationVel = RotationRate * TargettingBase.ShortestRotationDirection(_currentDirection, targetDirection); _currentDirection = _currentDirection.Wrap(_rotationVel * ticks, 0.0f, Twopi); // see if we've arrived nearly enough, and snap if (Math.Abs(_currentDirection.Wrap(-targetDirection, 0.0f, Twopi)) <= RotationRate * ticks) { _currentDirection = targetDirection; _state = TowerBehaviourState.Attacking; } _host.Rotation = _currentDirection; }
private void UpdateSearching() { // see if anything has changed in our targetting range if (_targetting.GetAgentVersionDelta() == 0) { return; } // if so, select a target _targetTile = _targetting.GetBestTargetTile(); _targetMob = _targetting.GetBestTargetMob(_targetTile); if (_targetMob == null) { // no target found, continue searching } else { // target found; start aiming _state = TowerBehaviourState.Aiming; } }
private void UpdateAttacking() { // check if a better target has appeared if (_targetting.GetAgentVersionDelta() > 0) { var potentialTile = _targetting.GetBestTargetTile(); var potentialMob = _targetting.GetBestTargetMob(potentialTile); if (ReferenceEquals(potentialMob, _targetMob)) { // stay on target } else if (potentialMob == null) { // no targets available _state = TowerBehaviourState.Searching; return; } else { // a better target has appeared _targetTile = potentialTile; _targetMob = potentialMob; _state = TowerBehaviourState.Aiming; return; } } // continue to point at the target _currentDirection = CalcTargetDirection(); _host.Rotation = _currentDirection; // TODO fire at enemy var attack = _host.CreateAttack(_targetMob); _targetMob.OnHit(attack); }
public void OnRemove(IExtendedAgent agent) { _state = TowerBehaviourState.Removed; }