Skip to content

Commit

Permalink
Merge pull request #113 from 9451589/main
Browse files Browse the repository at this point in the history
  • Loading branch information
shalzuth authored Aug 14, 2022
2 parents 9903995 + c8650bd commit 0a99859
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 6 deletions.
47 changes: 47 additions & 0 deletions LostArkLogger/Data/BattleItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Collections.Generic;

namespace LostArkLogger
{
public class BattleItem
{
public static Dictionary<uint, string> Projectiles = new Dictionary<uint, string>()
{
{33200, "Pheromone Bomb" },
{32000, "Flash Grenade" }, {32004, "Splendid Flash Grenade"},
{32010, "Flame Grenade" }, {32016, "Splendid Flame Grenade"},
{32020, "Frost Grenade" }, {23025, "Splendid Frost Grenade"},
{32030, "Electric Grenade"}, {32035, "Splendid Lightening Grenade"},
{32240, "Dark Grenade" }, {32244, "Splendid Dark Grenade" },
{32260, "Corrosive Bomb" }, {32262, "Splendid Corrosive Bomb"},
{32310, "Whirlwind Grenade"}, {32313, "Splendid Whirlwind Greande"},
{32320, "Clay Grenade" }, {32325, "Splendid Clay Grenade"},
{32350, "Sleep Bomb" }, {32352, "Splendid Sleep Bomb"},
{32360, "Sacred Bomb" }, {32363, "Splendid Sleep Bomb"},
{32140, "Destruction Bomb" }, {32142, "Splendid Destruction Bomb"}
};
public static Dictionary<uint, string> Buffs = new Dictionary<uint, string>()
{
{32380, "Atropine Potion" },
{32100, "Marching Flag" }, {32102, "Splendid Marching Flag"},
{32270, "Protective Potion"}, {32271, "Splendid Protective Potion"},
{32300, "Sprinter's Robe" }, {32301, "Splendid Sprinter's Robe" },
{33500, "Time Stop Potion" },
{32402, "Thunder Potion" }, {32403, "Splendid Thunder Potion"}
};

public static bool IsBattleItem(uint id, string type)
{
if (type == "projectile") return Projectiles.ContainsKey(id);
if (type == "buff") return Buffs.ContainsKey(id);
else return false;
}

public static string GetBattleItemName(uint id)
{
if (Projectiles.ContainsKey(id))
return Projectiles[id];
else
return Buffs[id];
}
}
}
12 changes: 12 additions & 0 deletions LostArkLogger/Data/Encounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,17 @@ public Dictionary<String, Tuple<UInt64, UInt32, UInt32, UInt64>> GetStatusEffect
return grouped.Select(i => new KeyValuePair<String, Tuple<UInt64, UInt32, UInt32, UInt64>>(i.Key, Tuple.Create((UInt64)i.Sum(sum), (UInt32)i.Count(), (UInt32)i.Count(log => log.Crit), (UInt64)i.Sum(j => (Single)j.TimeAlive)))).ToDictionary(x => x.Key, x => x.Value);
//return grouped.Select(i => new KeyValuePair<String, UInt64>(i.Key, (UInt64)i.Sum(j => (Single)j.Damage))).ToDictionary(x => x.Key, x => x.Value);
}

public Dictionary<String, Tuple<UInt64, UInt32, UInt32, UInt64>> GetBattleItems(Func<LogInfo, float> sum, Entity entity = default(Entity))
{
var baseSearch = Infos.Where(i => i.SourceEntity.Type == Entity.EntityType.Player).Where(i => i.BattleItem);

IEnumerable<IGrouping<String, LogInfo>> grouped;
if (entity != default(Entity))
grouped = baseSearch.Where(i => i.SourceEntity == entity).GroupBy(i => i.SkillName);
else
grouped = baseSearch.GroupBy(i => i.SourceEntity.VisibleName);
return grouped.Select(i => new KeyValuePair<String, Tuple<UInt64, UInt32, UInt32, UInt64>>(i.Key, Tuple.Create((UInt64)i.Sum(sum), (UInt32)i.Count(), (UInt32)i.Count(log => log.Crit), (UInt64)i.Sum(j => (Single)j.TimeAlive)))).ToDictionary(x => x.Key, x => x.Value);
}
}
}
1 change: 1 addition & 0 deletions LostArkLogger/Data/LogInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class LogInfo
public Boolean Counter { get; set; }
public Boolean Death { get; set; }
public TimeSpan Duration { get; set; }
public Boolean BattleItem { get; set; }
public override string ToString()
{
return Time.ToString("yy:MM:dd:HH:mm:ss.f") + "," +
Expand Down
2 changes: 2 additions & 0 deletions LostArkLogger/GUI/Overlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ enum Level // need better state, suboverlay type/etc.
TimeAlive,
RaidTimeAlive,
RaidDamage,
BattleItems,
Max
}
enum Scope // need better state, suboverlay type/etc.
Expand Down Expand Up @@ -197,6 +198,7 @@ protected override void OnPaint(PaintEventArgs e)
else if (level == Level.Counterattacks) rows = encounter.Counterattacks.ToDictionary(x => x.Key, x => Tuple.Create(x.Value, 0u, 0u, 0ul));
else if (level == Level.Stagger) rows = encounter.Stagger.ToDictionary(x => x.Key, x => Tuple.Create(x.Value, 0u, 0u, 0ul));
else if (level == Level.TimeAlive) rows = encounter.TimeAlive.ToDictionary(x => x.Key, x => Tuple.Create(x.Value, 0u, 0u, 0ul));
else if (level == Level.BattleItems) rows = encounter.GetBattleItems((i => i.BattleItem ? 1 : 0), SubEntity);
else if (level == Level.RaidTimeAlive)
{
rows = encounter.RaidTimeAlive.ToDictionary(x => x.Key, x => Tuple.Create(x.Value, 0u, 0u, 0ul));
Expand Down
8 changes: 4 additions & 4 deletions LostArkLogger/Packets/Steam/NpcStruct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ public partial class NpcStruct
{
public void SteamDecode(BitReader reader)
{
u64_0 = reader.ReadUInt64();
NpcId = reader.ReadUInt64();
b_0 = reader.ReadByte();
if (b_0 == 1)
NpcType = reader.ReadUInt32();
u32_2 = reader.ReadUInt32();
b_11 = reader.ReadByte();
if (b_11 == 1)
b_12 = reader.ReadByte();
Expand Down Expand Up @@ -40,7 +40,7 @@ public void SteamDecode(BitReader reader)
b_6 = reader.ReadByte();
if (b_6 == 1)
u32_0 = reader.ReadUInt32();
NpcId = reader.ReadUInt64();
u64_0 = reader.ReadUInt64();
b_7 = reader.ReadByte();
if (b_7 == 1)
u16_0 = reader.ReadUInt16();
Expand All @@ -63,7 +63,7 @@ public void SteamDecode(BitReader reader)
b_17 = reader.ReadByte();
if (b_17 == 1)
u32_1 = reader.ReadUInt32();
u32_2 = reader.ReadUInt32();
NpcType = reader.ReadUInt32();
b_18 = reader.ReadByte();
u16_2 = reader.ReadUInt16();
statPair = reader.Read<StatPair>();
Expand Down
4 changes: 2 additions & 2 deletions LostArkLogger/Packets/Steam/StatusEffectData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public partial class StatusEffectData
{
public void SteamDecode(BitReader reader)
{
SourceId = reader.ReadSimpleInt();
u64_1 = reader.ReadSimpleInt();
bytearraylist_0 = reader.ReadList<Byte[]>(7);
hasValue = reader.ReadByte();
if (hasValue == 1)
Expand All @@ -18,8 +18,8 @@ public void SteamDecode(BitReader reader)
u64_0 = reader.ReadUInt64();
u32_0 = reader.ReadUInt32();
StatusEffectId = reader.ReadUInt32();
u64_1 = reader.ReadUInt64();
InstanceId = reader.ReadUInt64();
SourceId = reader.ReadUInt64();
SkillLevel = reader.ReadByte();
}
}
Expand Down
31 changes: 31 additions & 0 deletions LostArkLogger/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,22 @@ void ProcessPacket(List<Byte> data)
EntityId = projectile.ProjectileId,
Type = Entity.EntityType.Projectile
});
var battleitem = BattleItem.IsBattleItem(projectile.SkillId, "projectile");
if (battleitem)
{
Entity entity = currentEncounter.Entities.GetOrAdd(projectile.OwnerId);
var log = new LogInfo
{
Time = DateTime.Now,
SourceEntity = entity,
DestinationEntity = entity, //projectiles don't have destination, but can't be null causes exception getting encounter name
SkillName = BattleItem.GetBattleItemName(projectile.SkillId),
SkillId = projectile.SkillId,
BattleItem = battleitem
};
currentEncounter.Infos.Add(log);
Logger.AppendLog(15, projectile.OwnerId.ToString("X"), entity.Name, projectile.SkillId.ToString(), BattleItem.GetBattleItemName(projectile.SkillId));
}
}
else if (opcode == OpCodes.PKTInitEnv)
{
Expand Down Expand Up @@ -523,6 +539,21 @@ 5 on suc 6 on fail
else if (opcode == OpCodes.PKTStatusEffectAddNotify) // shields included
{
var statusEffect = new PKTStatusEffectAddNotify(new BitReader(payload));
var battleItem = BattleItem.IsBattleItem(statusEffect.statusEffectData.StatusEffectId, "buff");
if (battleItem)
{
var log = new LogInfo
{
Time = DateTime.Now,
SourceEntity = currentEncounter.Entities.GetOrAdd(statusEffect.statusEffectData.SourceId),
DestinationEntity = currentEncounter.Entities.GetOrAdd(statusEffect.ObjectId),
SkillId = statusEffect.statusEffectData.StatusEffectId,
SkillName = BattleItem.GetBattleItemName(statusEffect.statusEffectData.StatusEffectId),
BattleItem = battleItem
};
currentEncounter.Infos.Add(log);
Logger.AppendLog(15, statusEffect.statusEffectData.SourceId.ToString("X"), currentEncounter.Entities.GetOrAdd(statusEffect.statusEffectData.SourceId).Name, statusEffect.statusEffectData.StatusEffectId.ToString(), BattleItem.GetBattleItemName(statusEffect.statusEffectData.StatusEffectId));
}
statusEffectTracker.Add(statusEffect);
var amount = statusEffect.statusEffectData.hasValue == 1 ? BitConverter.ToUInt32(statusEffect.statusEffectData.Value, 0) : 0;
}
Expand Down

0 comments on commit 0a99859

Please sign in to comment.