Skip to content

Commit

Permalink
log issues with auto joining raids and dungeon on server side
Browse files Browse the repository at this point in the history
  • Loading branch information
zerratar committed Oct 15, 2023
1 parent dc378ae commit 5eaff21
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/RavenNest.Blazor/Controllers/GameApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class GameApiController : ControllerBase
private readonly SessionInfoProvider sessionInfoProvider;
private readonly SessionManager sessionManager;
private readonly ISecureHasher secureHasher;
private readonly ILogger logger;
protected readonly ILogger logger;

public GameApiController(
ILogger logger,
Expand Down
2 changes: 2 additions & 0 deletions src/RavenNest.Blazor/Controllers/PlayersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ public bool[] RaidAuto(Many<Guid> characterIds)
}
catch (Exception exc)
{
logger.LogError("Error when auto-joining raid: " + exc);
return new bool[characterIds.Values.Length];
}
}
Expand Down Expand Up @@ -438,6 +439,7 @@ public bool[] DungeonAuto(Many<Guid> characterIds)
}
catch (Exception exc)
{
logger.LogError("Error when auto-joining dungeon: " + exc);
return new bool[characterIds.Values.Length];
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/RavenNest.BusinessLogic/Game/Managers/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public EventItemReward[] GetDungeonRewardsAsync(SessionToken session, int tier,

var knownItems = gameData.GetKnownItems();

const double seasonalTokenDropRate = 0.85;
const double seasonalTokenDropRate = 0.05;

foreach (var c in characters)
{
Expand All @@ -345,14 +345,14 @@ public EventItemReward[] GetDungeonRewardsAsync(SessionToken session, int tier,
var tokenDrop = dl.FirstOrDefault(x => x.ItemId == knownItems.HalloweenToken.Id || x.ItemId == knownItems.ChristmasToken.Id);
if (tokenDrop != null)
{
if (rng.NextDouble() >= seasonalTokenDropRate)
if (rng.NextDouble() <= seasonalTokenDropRate)
{
var inv = inventoryProvider.Get(character.Id);
var stack = inv.AddItem(tokenDrop.ItemId, 1).FirstOrDefault();

// log when a seasonal token is dropped so I can keep track on this.

logger.LogError("Token Drop from Dungeon from 30%, Player: " + character.Name);
logger.LogError("Token Drop from Dungeon from " + (Math.Round(seasonalTokenDropRate * 100)) + "%, Player: " + character.Name);

rewards.Add(new EventItemReward
{
Expand Down Expand Up @@ -407,7 +407,7 @@ public EventItemReward[] GetRaidRewardsAsync(SessionToken session, Guid[] charac
var dropList = GetRaidDropList();
var dropChance = 0.5;

const double seasonalTokenDropRate = 0.9;
const double seasonalTokenDropRate = 0.025;

foreach (var c in characters)
{
Expand All @@ -425,14 +425,14 @@ public EventItemReward[] GetRaidRewardsAsync(SessionToken session, Guid[] charac
var tokenDrop = dl.FirstOrDefault(x => x.ItemId == knownItems.HalloweenToken.Id || x.ItemId == knownItems.ChristmasToken.Id);
if (tokenDrop != null)
{
if (rng.NextDouble() >= seasonalTokenDropRate)
if (rng.NextDouble() <= seasonalTokenDropRate)
{
var inv = inventoryProvider.Get(character.Id);
var stack = inv.AddItem(tokenDrop.ItemId, 1).FirstOrDefault();

// log when a seasonal token is dropped so I can keep track on this.

logger.LogError("Token Drop from Raid from 30%, Player: " + character.Name);
logger.LogError("Token Drop from Raid from " + (Math.Round(seasonalTokenDropRate * 100)) + "%, Player: " + character.Name);

rewards.Add(new EventItemReward
{
Expand Down
20 changes: 20 additions & 0 deletions src/RavenNest.BusinessLogic/Game/Managers/PlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2415,20 +2415,40 @@ public EnchantmentCooldownResult GetEnchantmentCooldown(SessionToken sessionToke

public bool[] AutoJoinRaid(SessionToken sessionToken, IReadOnlyList<Guid> characters)
{
var successCount = 0;
var arr = new bool[characters.Count];
for (var i = 0; i < arr.Length; ++i)
{
arr[i] = AutoJoinRaid(sessionToken, characters[i]);
if (arr[i]) successCount++;
}
if (characters.Count > successCount)
{
logger.LogWarning("Auto Join Raid failed for {0} characters, out of a total {1}, session {2}", characters.Count - successCount, characters.Count, sessionToken.UserName);
}
else
{
logger.LogWarning("[{0}] {1} characters auto joined raid.", sessionToken.UserName, characters.Count);
}
return arr;
}

public bool[] AutoJoinDungeon(SessionToken sessionToken, IReadOnlyList<Guid> characters)
{
var successCount = 0;
var arr = new bool[characters.Count];
for (var i = 0; i < arr.Length; ++i)
{
arr[i] = AutoJoinDungeon(sessionToken, characters[i]);
if (arr[i]) successCount++;
}
if (characters.Count > successCount)
{
logger.LogWarning("Auto Join Dungeon failed for {0} characters, out of a total {1}, session {2}", characters.Count - successCount, characters.Count, sessionToken.UserName);
}
else
{
logger.LogWarning("[{0}] {1} characters auto joined dungeon.", sessionToken.UserName, characters.Count);
}
return arr;
}
Expand Down
84 changes: 83 additions & 1 deletion src/tools/RavenNest.Tools/BackupLib/Backup.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using RavenNest.DataModels;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace RavenNest.Tools.BackupLib
{
Expand Down Expand Up @@ -37,6 +39,86 @@ public class BackupInfo

public static class Backups
{
public static void RepairSkillRecords(string backupFolderA, string backupFolderB)
{
var dataA = List<CharacterSkillRecord>(backupFolderA);

// from both lists, we have to ensure we dont have duplicate records, so we will have to group by character id and skill index
// then we need to ensure that the record with the highest level is the one we keep. but keep in mind the date reached so we don't keep a corrupted record.

var dataADict = new Dictionary<string, CharacterSkillRecord>();
foreach (var record in dataA)
{
var key = record.CharacterId + "_" + record.SkillIndex;
if (dataADict.TryGetValue(key, out var existing))
{
if (existing.SkillLevel > record.SkillLevel)
{
dataADict[key] = record;
}
}
else
{
dataADict[key] = record;
}
}


var dataB = List<CharacterSkillRecord>(backupFolderB);
var dataBDict = new Dictionary<string, CharacterSkillRecord>();
foreach (var record in dataB)
{
var key = record.CharacterId + "_" + record.SkillIndex;
if (dataBDict.TryGetValue(key, out var existing))
{
if (existing.SkillLevel > record.SkillLevel)
{
dataBDict[key] = record;
}
}
else
{
dataBDict[key] = record;
}
}

// dataA has all records that we want to make sure is in dataB
// when these recors has been updated we will save a new dataB
// that we then use for restoring the data to.

int updateCount = 0;
int addCount = 0;
int index = 0;
foreach (var a in dataA)
{
var key = a.CharacterId + "_" + a.SkillIndex;
if (dataBDict.TryGetValue(key, out var b))
{
if (b.DateReached > a.DateReached && a.SkillLevel == 999)
{
updateCount++;
b.DateReached = a.DateReached;
}
}
else
{
// we need to add this record if skill level is above 1
if (a.SkillLevel > 1)
{
dataBDict[key] = a;
addCount++;
}
}
index++;
}

var parentDir = System.IO.Path.GetDirectoryName(System.IO.Path.Combine(backupFolderA, "..\\"));
var newPath = System.IO.Path.Combine(parentDir, "RavenNest.DataModels.CharacterSkillRecord.json");
System.IO.File.WriteAllText(newPath, Newtonsoft.Json.JsonConvert.SerializeObject(dataBDict.Values));

}


public static List<CharacterSkillBackup> GetSkillBackups(string inputFolder, Action<int, int> onLoadProgressed)
{
var backup = new List<CharacterSkillBackup>();
Expand Down
6 changes: 6 additions & 0 deletions src/tools/RavenNest.Tools/MainWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using RavenNest.Tools.Actions;
using RavenNest.Tools.BackupLib;
using Shinobytes.Console.Forms;
using Shinobytes.Console.Forms.Graphics;
using System;
Expand Down Expand Up @@ -74,6 +75,11 @@ public override bool OnKeyDown(KeyInfo key)
{
restoreInventoryItems.Apply();
}
if (key.Key == ConsoleKey.F6)
{
Backups.RepairSkillRecords("C:\\Ravenfall\\backups\\2023-09-15_172453", "C:\\Ravenfall\\backups\\2023-10-15_074440");
}

return base.OnKeyDown(key);
}

Expand Down

0 comments on commit 5eaff21

Please sign in to comment.