public void TestCreepState() { var state = new CreepState(); state.SetVulnerabilityWithValue(TowerType.Ice, 1000f); Assert.AreEqual(Vulnerability.Sudden, state.GetVulnerability(TowerType.Ice)); }
private void Hold() { activeOrder = CreepState.Hold; targetPosition = myPosition.position; targetVictim = null; TryFindTarget(); }
private void Stop() { activeOrder = CreepState.Idle; legs.Stop(); targetVictim = null; TryFindTarget(); }
// // Приказы // private void Move(DTRMVector2 position) { activeOrder = CreepState.Move; targetPosition = position; legs.targetPosition = targetPosition; targetVictim = null; }
private void MoveAttack(DTRMVector2 position) { activeOrder = CreepState.MoveAttack; targetPosition = position; targetVictim = null; FindTargetOrCarryOn(); }
public override void Update(GameTime gameTime) { var elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; //Falls der Gegner noch in Bewegung ist, und auch noch Wegpunkte vor sich if ((creepState == CreepState.Running) && (WayPoints != null) && (WayPoints.Count > 0)) { //Falls er einen Wegpunkt erreicht hat if (AtDestination) { //Nächsten Wegpunkte zum aktuellen machen WayPoints.Dequeue(); //Und die Gridposition richtig setzen GridPosition.X = (float)Math.Round(GridPosition.X, 0, MidpointRounding.AwayFromZero); GridPosition.Y = (float)Math.Round(GridPosition.Y, 0, MidpointRounding.AwayFromZero); //Auch die Punkte müssen neu berechnet werden, da ein Creep kurz vor Ende seiner Reise mehr Punkte gibt Points = (int)Math.Round(InitialHealth * maxMoveSpeed / (WayPoints.Count + 1), MidpointRounding.AwayFromZero) + 1; } else { //Blablabla, einfach die aktuelle Geschwindikeit errechnen float previousMoveSpeed = moveSpeed; float desiredMoveSpeed = FindMaxMoveSpeed(WayPoints.Peek()); moveSpeed = MathHelper.Clamp(desiredMoveSpeed, previousMoveSpeed - MaxMoveSpeedDelta * elapsedTime, previousMoveSpeed + MaxMoveSpeedDelta * elapsedTime); //Hier wird der Creep noch in die richtige Richtung gedreht var facingDirection = (float)Math.Atan2(direction.Y, direction.X); facingDirection = TurnToFace(GridPosition, WayPoints.Peek(), facingDirection, MaxAngularVelocity * elapsedTime); direction = new Vector2((float)Math.Cos(facingDirection), (float)Math.Sin(facingDirection)); Rotation = (float)Math.Atan2(direction.Y, direction.X); //Und die Position aktualisiert GridPosition = GridPosition + (direction * moveSpeed * elapsedTime); } //Jetzt noch die "richtige" Position ausrechnen, also die, die zum Zeichnen benötigt wird Position = new Vector2( GridPosition.X * GameScreen.LevelManager.GridSize.X + GameScreen.LevelManager.GridSize.X / 2, GridPosition.Y * GameScreen.LevelManager.GridSize.Y + GameScreen.LevelManager.GridSize.Y / 2); } //SInd wir am Ende des levels? if (TargetReached) { creepState = CreepState.Out; GameScreen.CreepOut(this); } //Das CustomUpdate für die Türme... if (CustomUpdate != null) { CustomUpdate(this, gameTime); } HealthPosition = new Vector2(Position.X - HealthSize.X / 2, Position.Y - Size.Y); base.Update(gameTime); }
public void TestMeltState() { var creep = new Creep(CreepType.Cloth, Vector2D.Zero); var state = new CreepState(); state.Melt = true; state.UpdateStateAndTimers(creep); Assert.IsTrue(state.Melt); }
private void Patrol(DTRMVector2 position) { targetPosition = position; patrolPosition = myPosition.position; activeOrder = CreepState.Patrol; targetVictim = null; FindTargetOrCarryOn(); }
void Start() { state = CreepState.Running; if (GameMasterObject.playerUse != null) { player = GameMasterObject.playerUse.transform; } }
void UpdateTarget(Transform targ) { target = targ; opponent = targ.GetComponent <Pleb>(); if (Vector3.Distance(myTransform.position, targ.position) <= closeEnough) { state = CreepState.Fighting; } }
void Awake() { seeker = GetComponent <Seeker>(); controller = GetComponent <CharacterController>(); creepState = CreepState.Idle; //heading = Random.Range(0, 360); radius = 5; //controller.detectCollisions = false; animation.Play("idle"); //GetComponent<ShadowComponent>().CreateShadowPlane(); }
public void TestSlowImmuneState() { var creep = new Creep(CreepType.Cloth, Vector2D.Zero); var state = new CreepState(); state.Slow = true; state.UpdateStateAndTimers(creep); Assert.IsTrue(state.Slow); state.SlowImmune = true; state.UpdateStateAndTimers(creep); Assert.IsTrue(state.SlowImmune); }
public void TestFrozenState() { var creep = new Creep(CreepType.Cloth, Vector2D.Zero); var state = new CreepState(); state.Frozen = true; state.UpdateStateAndTimers(creep); Assert.IsTrue(state.Frozen); state.Unfreezable = true; state.UpdateStateAndTimers(creep); Assert.IsTrue(state.Unfreezable); }
private void Attack(Health target) { if (!attack.CheckTarget(target)) { return; } activeOrder = CreepState.Attack; targetVictim = target; attack.AppointTarget(targetVictim); legs.FollowTarget(target.myPosition); }
private void CreateStats(CreepType type, CreepPropertiesXml properties) { CreepData creepData = properties.Get(type); Name = creepData.Name; CreateStat("Hp", creepData.MaxHp); CreateStat("Speed", creepData.Speed); CreateStat("Resistance", creepData.Resistance); CreateStat("Gold", creepData.GoldReward); if (Player.Current != null) ApplyBuff(new BuffEffect(Player.Current.Avatar.GetType().Name + "GoldMultiplier")); State = new CreepState(); foreach (var modifier in creepData.TypeDamageModifier) State.SetVulnerabilityWithValue(modifier.Key, modifier.Value); }
// // IAttackListener // public void OnLostAppointedTarget() { targetVictim = null; switch (activeOrder) { case CreepState.Idle: if (!TryFindTarget()) { legs.Stop(); } break; case CreepState.Hold: FindTargetOrCarryOn(); break; case CreepState.Move: Debug.LogWarning("Unexpected lost appointed target event for move state!"); break; case CreepState.MoveAttack: FindTargetOrCarryOn(); break; case CreepState.Attack: activeOrder = CreepState.Idle; TryFindTarget(); break; case CreepState.Patrol: FindTargetOrCarryOn(); break; default: Debug.LogError("Unknown order!"); break; } }
void Update() { RaycastHit opponentHit; if (state == CreepState.Running) { } else { agent.isStopped = true; } if (opponent == null) { Ray middleMiddleRay = new Ray(myTransform.position, myTransform.forward); if (Physics.SphereCast(middleMiddleRay, sphereRadius, out opponentHit, lookRayDistance, lookLayerMask)) { state = CreepState.Idle; UpdateTarget(opponentHit.collider.transform); } } #region Switch statment To check states switch (state) { case CreepState.Idle: break; case CreepState.Searching: break; case CreepState.Running: break; case CreepState.Fighting: break; case CreepState.Dead: break; default: break; } #endregion }
public override void Initialize() { SpriteBatch = CurrGame.SpriteBatch; TextureDirectory = "Creep/"; OriginType = OriginType.Center; Size = new Vector2(GameScreen.LevelManager.GridSize.X * 1.5f, GameScreen.LevelManager.GridSize.Y); HealthSize = new Vector2(Size.X, 5); HealthPosition = new Vector2(Position.X - HealthSize.X / 2, Position.Y - Size.Y); spriteBatch = CurrGame.SpriteBatch; Position = new Vector2(GridPosition.X * GameScreen.LevelManager.GridSize.X + GameScreen.LevelManager.GridSize.X / 2, GridPosition.Y * GameScreen.LevelManager.GridSize.Y + GameScreen.LevelManager.GridSize.Y / 2); //Weg zum Ziel suchen GridChanged(null); Points = (int)Math.Round(InitialHealth * maxMoveSpeed / WayPoints.Count, MidpointRounding.AwayFromZero); creepState = CreepState.Running; base.Initialize(); }
protected override void RestartStatsAndState(float percentage, AgentData data) { var creepData = (CreepData)data; Stats.Clear(); CreateStat("Hp", creepData.MaxHp); var amountToSubtract = (1 - percentage) * creepData.MaxHp; AdjustStat(new StatAdjustment("Hp", "", -amountToSubtract)); CreateStat("Speed", creepData.Speed); CreateStat("Resistance", creepData.Resistance); CreateStat("Gold", creepData.GoldReward); State = new CreepState(); foreach (var modifier in creepData.TypeDamageModifier) { State.SetVulnerabilityWithValue(modifier.Key, modifier.Value); } }
private void CreateStats(CreepType type, CreepPropertiesXml properties) { CreepData creepData = properties.Get(type); Name = creepData.Name; CreateStat("Hp", creepData.MaxHp); CreateStat("Speed", creepData.Speed); CreateStat("Resistance", creepData.Resistance); CreateStat("Gold", creepData.GoldReward); if (Player.Current != null) { ApplyBuff(new BuffEffect(Player.Current.Avatar.GetType().Name + "GoldMultiplier")); } State = new CreepState(); foreach (var modifier in creepData.TypeDamageModifier) { State.SetVulnerabilityWithValue(modifier.Key, modifier.Value); } }
// // ILegsListener // public void OnTargetReach() { switch (activeOrder) { case CreepState.Idle: Debug.LogWarning("Unexpected target reach event for state Idle!"); break; case CreepState.Hold: // Вернулись на место, отдыхаем. break; case CreepState.Move: activeOrder = CreepState.Idle; break; case CreepState.MoveAttack: activeOrder = CreepState.Idle; break; case CreepState.Attack: Debug.LogWarning("Unexpected target reach event for state Attack!"); break; case CreepState.Patrol: DTRMVector2 exchangePosition = targetPosition; targetPosition = patrolPosition; patrolPosition = exchangePosition; legs.targetPosition = targetPosition; break; default: Debug.LogError("Unknown order!"); break; } }
// // ILegsListener // public void OnTargetReach() { switch(activeOrder) { case CreepState.Idle: Debug.LogWarning("Unexpected target reach event for state Idle!"); break; case CreepState.Hold: // Вернулись на место, отдыхаем. break; case CreepState.Move: activeOrder = CreepState.Idle; break; case CreepState.MoveAttack: activeOrder = CreepState.Idle; break; case CreepState.Attack: Debug.LogWarning("Unexpected target reach event for state Attack!"); break; case CreepState.Patrol: DTRMVector2 exchangePosition = targetPosition; targetPosition = patrolPosition; patrolPosition = exchangePosition; legs.targetPosition = targetPosition; break; default: Debug.LogError("Unknown order!"); break; } }
protected override void RestartStatsAndState(float percentage, AgentData data) { var creepData = (CreepData)data; Stats.Clear(); CreateStat("Hp", creepData.MaxHp); var amountToSubtract = (1 - percentage) * creepData.MaxHp; AdjustStat(new StatAdjustment("Hp", "", -amountToSubtract)); CreateStat("Speed", creepData.Speed); CreateStat("Resistance", creepData.Resistance); CreateStat("Gold", creepData.GoldReward); State = new CreepState(); foreach (var modifier in creepData.TypeDamageModifier) State.SetVulnerabilityWithValue(modifier.Key, modifier.Value); }
public void Kill() { creepState = CreepState.Killed; GameScreen.CreepOut(this); }
void Awake() { myTransform = transform; state = CreepState.Running; agent = GetComponent <NavMeshAgent>(); }
// // IAttackListener // public void OnLostAppointedTarget() { targetVictim = null; switch(activeOrder) { case CreepState.Idle: if (!TryFindTarget()) legs.Stop(); break; case CreepState.Hold: FindTargetOrCarryOn(); break; case CreepState.Move: Debug.LogWarning("Unexpected lost appointed target event for move state!"); break; case CreepState.MoveAttack: FindTargetOrCarryOn(); break; case CreepState.Attack: activeOrder = CreepState.Idle; TryFindTarget(); break; case CreepState.Patrol: FindTargetOrCarryOn(); break; default: Debug.LogError("Unknown order!"); break; } }
private void Attack(Health target) { if (!attack.CheckTarget(target)) return; activeOrder = CreepState.Attack; targetVictim = target; attack.AppointTarget(targetVictim); legs.FollowTarget(target.myPosition); }