public static void UpdateHonorRankAllPlayers(bool announce) { var eligiblePlayers = CharMgr.Chars.Where(x => x.Value.HonorPoints >= 10); foreach (var player in eligiblePlayers) { try { var currentHonorPoints = player.Value.HonorPoints; // Reduce honor points by X%, unless they are < 10 - in which case make it 0 var newHonorPoints = 0; if (currentHonorPoints < 10) { newHonorPoints = 0; } else { newHonorPoints = (int)(currentHonorPoints * HONOR_REDUCTION_PERCENT); } player.Value.HonorPoints = (ushort)newHonorPoints; var oldHonorRank = player.Value.HonorRank; // Recalculate Honor Rank var honorLevel = new Common.HonorCalculation().GetHonorLevel((int)newHonorPoints); player.Value.HonorRank = (ushort)honorLevel; Logger.Trace( $"Updating honor for {player.Value.Name} [{currentHonorPoints-newHonorPoints}] ({player.Value.CharacterId}) Current => New Honor Pts: {currentHonorPoints} => {player.Value.HonorPoints} ({player.Value.HonorRank}) "); CharMgr.Database.SaveObject(player.Value); PlayerUtil.RecordHonorHistory(currentHonorPoints, (ushort)newHonorPoints, player.Value.CharacterId, player.Value.Name); if (announce) { if (honorLevel > oldHonorRank) { var playerToAnnounce = Player.GetPlayer((uint)player.Value.CharacterId); if (playerToAnnounce.CharacterId == player.Value.CharacterId) { playerToAnnounce.SendClientMessage($"You have reached Honor Rank {honorLevel}", ChatLogFilters.CHATLOGFILTERS_C_ORANGE_L); } } } } catch (Exception e) { Logger.Error($"{e.Message} {e.StackTrace}"); } } }
static void Main(string[] args) { Logger.Info($"Begin processing Honor Updates...."); // Reduce Honor Points for each character, recalculate their Honor Level var connection = new MySqlConnection(ConnectionString); try { connection.Open(); var characterList = connection.Query <Character>($"select CharacterId, Name, AccountId, HonorPoints, HonorRank from war_characters.characters where HonorPoints > 0"); foreach (var character in characterList) { var currentHonorPoints = character.HonorPoints; // Reduce honor points by 10%, unless they are < 10 - in which case make it 0 var newHonorPoints = 0; if (currentHonorPoints < 10) { newHonorPoints = 0; } else { newHonorPoints = (int)(currentHonorPoints * 0.90f); } // Recalculate Honor Rank var honorLevel = new Common.HonorCalculation().GetHonorLevel((int)newHonorPoints); Logger.Debug($"Character : {character.Name} Honor {currentHonorPoints} => {newHonorPoints}"); connection.ExecuteScalar( $"update war_characters.characters set HonorPoints = {newHonorPoints}, HonorRank = {honorLevel} where CharacterId = {character.CharacterId}"); } Logger.Info($"Finish processing Honor Updates...."); } catch (Exception e) { Console.WriteLine(e); Logger.Error($"Exception : {e.Message}"); } finally { connection.Close(); } }
public void ZeroReturnsZero() { var honor = new Common.HonorCalculation(); Assert.IsTrue(honor.GetHonorLevel(0) == 0); }
public void TwoHundredReturnsTwo() { var honor = new Common.HonorCalculation(); Assert.IsTrue(honor.GetHonorLevel(201) == 2); }
public void BigNumberReturnsTen() { var honor = new Common.HonorCalculation(); Assert.IsTrue(honor.GetHonorLevel(122201) == 10); }
public void OneHunderedAndOneReturnsZero() { var honor = new Common.HonorCalculation(); Assert.IsTrue(honor.GetHonorLevel(101) == 1); }