private void DisplayAttackBar() { // HealthBar Y position int posY = ResolutionHandler.GetResolution(1); // Line width int width = ResolutionHandler.GetResolution(0); // Get player's target information AMonster targetMonster = Program.Player.CurrentTarget; // Declare string builder StringBuilder attackBarBuilder = new StringBuilder(); if (targetMonster != default) { float monsterHealth = targetMonster.Health; string monsterName = (string)targetMonster.GetType().GetProperty("Name")?.GetValue(null); string targetText = $"{monsterName}: {targetMonster.Health}/{targetMonster.MaxHealth}"; // Calculate health position x int monsterHealthX = width / 2 - targetText.Length / 2; // Calculate monster health in procents var monsterHealthProcent = (int)Math.Floor((double)monsterHealth / targetMonster.MaxHealth * 100); // Push content to the builder for (var ma = 0; ma < width; ++ma) { // Chat that will be added during this iteration string current = " "; // Place text char when in the text container area if (ma >= monsterHealthX && ma < monsterHealthX + targetText.Length) { current = targetText[ma - monsterHealthX].ToString(); } // Checks if this position in the healthbar should be filled (health) if (ma < Math.Floor(monsterHealthProcent / 100f * width)) { current = current.Colorize(ColorizeColor.BGBLUE); } // Append char to the output attackBarBuilder.Append(current); } } // Place cursor at the position Console.SetCursorPosition(0, posY); // Display the health bar rectangle string barText = attackBarBuilder.ToString(); Console.WriteLine(barText); }
/// <summary> /// Updates move timer for the target monster. /// </summary> /// <param name="monster"> /// Target monster /// </param> /// <returns> /// Boolean that represents if timer hasn't ended yet /// </returns> private bool DecrementMonstersMoveTimer(AMonster monster) { // Check if already started tracking spawn time for this monster // (check if this key is in the dictionary) if (!myMonstersMovementTicks.ContainsKey(monster)) { // Plus one, since we will decrement this value myMonstersMovementTicks[monster] = monster.TicksPerMove + 1; } // Check if timer ended and monster can move now bool isEnded = --myMonstersMovementTicks[monster] <= 0; // Reset timer if timer is ended if (isEnded) { myMonstersMovementTicks[monster] = monster.TicksPerMove; } // Return is not ended status return !isEnded; }
/// <summary> /// Changes player's current target. /// This method affects the player's status bar. /// </summary> public void SetMonsterTarget(AMonster monster) { CurrentTarget = monster; }
/// <summary> /// Removes target monster from the monsters list /// </summary> /// <param name="monster"> /// Target monster /// </param> private void RemoveMonster(AMonster monster) { myMonsters.Remove(monster); }