private void HandleMessageReceived(Message obj) { var message = _messageFactory.Create(obj); if (DamageTracker.IsArchived) { var npcOccupier = message as SNpcOccupierInfo; if (npcOccupier != null) { Entity ent = _entityTracker.GetOrPlaceholder(npcOccupier.NPC); if (ent is NpcEntity) { var npce = ent as NpcEntity; if (npce.Info.Boss && npcOccupier.Target != EntityId.Empty) { CasualMessenger.Instance.ResetPlayerStats(true); //Stop viewing saved encounter on boss aggro } } return; } } _entityTracker?.Update(message); var skillResultMessage = message as EachSkillResultServerMessage; if (skillResultMessage != null) { if (skillResultMessage.IsValid(DamageTracker)) { var skillResult = new SkillResult(skillResultMessage, _entityTracker, _playerTracker, _teraData.SkillDatabase, null, _abnormalityTracker); CheckUpdate(skillResult); } return; } _playerTracker?.UpdateParty(message); _abnormalityTracker?.Update(message); var despawnNpc = message as SDespawnNpc; if (despawnNpc != null) { Entity ent = _entityTracker.GetOrPlaceholder(despawnNpc.Npc); if (ent is NpcEntity) { var npce = ent as NpcEntity; if (npce.Info.Boss && despawnNpc.Dead && !DamageTracker.IsArchived) { //no need to do something if we didn't count any skill against this boss if (DamageTracker.StatsByUser.SelectMany(x => x.SkillLog).Any(x => x.Target == npce)) { DamageTracker.PrimaryTarget = npce; //Name encounter with the last dead boss DamageTracker.IsPrimaryTargetDead = despawnNpc.Dead; //determine type ExportType exportType = ExportType.None; if (SettingsHelper.Instance.Settings.ExcelExport) { exportType = exportType | ExportType.Excel; } if (SettingsHelper.Instance.Settings.SiteExport) { exportType = exportType | ExportType.Upload; } if (exportType != ExportType.None) { DataExporter.ToTeraDpsApi(exportType, DamageTracker, _teraData); } if (AutosaveEncounters) { ResetDamageTracker(new ResetPlayerStatsMessage { ShouldSaveCurrent = true }); } } } } return; } var spawnNpc = message as SpawnNpcServerMessage; if (spawnNpc != null) { if (spawnNpc.NpcArea == 950 && spawnNpc.NpcId == 9501) { var bosses = DamageTracker.StatsByUser.SelectMany(x => x.SkillLog).Select(x => x.Target).OfType <NpcEntity>().ToList(); var vergosPhase2Part1 = bosses.FirstOrDefault(x => x.Info.HuntingZoneId == 950 && x.Info.TemplateId == 1000); var vergosPhase2Part2 = bosses.FirstOrDefault(x => x.Info.HuntingZoneId == 950 && x.Info.TemplateId == 2000); //determine type ExportType exportType = ExportType.None; if (SettingsHelper.Instance.Settings.ExcelExport) { exportType = exportType | ExportType.Excel; } if (SettingsHelper.Instance.Settings.SiteExport) { exportType = exportType | ExportType.Upload; } if (exportType != ExportType.None) { DataExporter.ToTeraDpsApi(exportType, DamageTracker, _teraData, vergosPhase2Part1); } DataExporter.ToTeraDpsApi(exportType, DamageTracker, _teraData, vergosPhase2Part2); if (AutosaveEncounters) { ResetDamageTracker(new ResetPlayerStatsMessage { ShouldSaveCurrent = true }); } } if (spawnNpc.NpcArea == 950 && spawnNpc.NpcId == 9502) { var bosses = DamageTracker.StatsByUser.SelectMany(x => x.SkillLog).Select(x => x.Target).OfType <NpcEntity>().ToList(); var vergosPhase3 = bosses.FirstOrDefault(x => x.Info.HuntingZoneId == 950 && x.Info.TemplateId == 3000); //determine type ExportType exportType = ExportType.None; if (SettingsHelper.Instance.Settings.ExcelExport) { exportType = exportType | ExportType.Excel; } if (SettingsHelper.Instance.Settings.SiteExport) { exportType = exportType | ExportType.Upload; } if (exportType != ExportType.None) { DataExporter.ToTeraDpsApi(exportType, DamageTracker, _teraData, vergosPhase3); } if (AutosaveEncounters) { ResetDamageTracker(new ResetPlayerStatsMessage { ShouldSaveCurrent = true }); } } return; } var sLogin = message as LoginServerMessage; if (sLogin != null) { if (_needInit) { Server = BasicTeraData.Servers.GetServer(sLogin.ServerId, Server); _messageFactory.Region = Server.Region; Logger.Info($"Logged in to server {Server.Name}."); _teraData = BasicTeraData.DataForRegion(Server.Region); _entityTracker = new EntityTracker(_teraData.NpcDatabase, _userLogoTracker); _playerTracker = new PlayerTracker(_entityTracker, BasicTeraData.Servers); _abnormalityTracker = new AbnormalityTracker(_entityTracker, _playerTracker, _teraData.HotDotDatabase, _abnormalityStorage, CheckUpdate); _entityTracker.Update(message); if (!DamageTracker.IsArchived) { DamageTracker.MeterPlayer = _playerTracker.Me(); } _needInit = false; } _abnormalityStorage.EndAll(message.Time.Ticks); _abnormalityTracker = new AbnormalityTracker(_entityTracker, _playerTracker, _teraData.HotDotDatabase, _abnormalityStorage, CheckUpdate); return; } var cVersion = message as C_CHECK_VERSION; if (cVersion != null) { var opCodeNamer = new OpCodeNamer(Path.Combine(BasicTeraData.ResourceDirectory, $"opcodes/{cVersion.Versions[0]}.txt")); _messageFactory = new MessageFactory(opCodeNamer, Server.Region, cVersion.Versions[0]); return; } var sGetUserList = message as S_GET_USER_LIST; if (sGetUserList != null) { _userLogoTracker.SetUserList(sGetUserList); return; } }
private void HandleMessageReceived(Message obj) { var message = _messageFactory.Create(obj); var despawnNpc = message as SDespawnNpc; if (despawnNpc != null) { Entity ent = _entityTracker.GetOrPlaceholder(despawnNpc.NPC); if (ent is NpcEntity) { _abnormalityTracker.StopAggro(despawnNpc); _abnormalityTracker.DeleteAbnormality(despawnNpc); var npce = ent as NpcEntity; if (npce.Info.Boss && despawnNpc.Dead && !DamageTracker.IsArchived) { //no need to do something if we didn't count any skill against this boss if (DamageTracker.StatsByUser.SelectMany(x => x.SkillLog).Any(x => x.Target == npce)) { DataExporter.ToTeraDpsApi(despawnNpc, DamageTracker, _entityTracker, _teraData); DamageTracker.Name = npce.Info.Name; //Name encounter with the last dead boss if (AutosaveEncounters) { CasualMessenger.Instance.ResetPlayerStats(true); } } } } return; } if (DamageTracker.IsArchived) { var npcOccupier = message as SNpcOccupierInfo; if (npcOccupier != null) { Entity ent = _entityTracker.GetOrPlaceholder(npcOccupier.NPC); if (ent is NpcEntity) { var npce = ent as NpcEntity; if (npce.Info.Boss && npcOccupier.Target != EntityId.Empty) { CasualMessenger.Instance.ResetPlayerStats(true); //Stop viewing saved encounter on boss aggro } } return; } } var skillResultMessage = message as EachSkillResultServerMessage; if (skillResultMessage != null) { if (skillResultMessage.IsValid(DamageTracker)) { var skillResult = new SkillResult(skillResultMessage, _entityTracker, _playerTracker, _teraData.SkillDatabase); CheckUpdate(skillResult); } return; } var changeHp = message as SCreatureChangeHp; if (changeHp != null) { _abnormalityTracker.Update(changeHp); return; } var pchangeHp = message as SPartyMemberChangeHp; if (pchangeHp != null) { var user = _playerTracker.GetOrNull(pchangeHp.ServerId, pchangeHp.PlayerId); if (user == null) { return; } _abnormalityTracker.RegisterSlaying(user.User, pchangeHp.Slaying, pchangeHp.Time.Ticks); return; } var pmstatupd = message as S_PARTY_MEMBER_STAT_UPDATE; if (pmstatupd != null) { var user = _playerTracker.GetOrNull(pmstatupd.ServerId, pmstatupd.PlayerId); if (user == null) { return; } _abnormalityTracker.RegisterSlaying(user.User, pmstatupd.Slaying, pmstatupd.Time.Ticks); return; } var pstatupd = message as S_PLAYER_STAT_UPDATE; if (pstatupd != null) { _abnormalityTracker.RegisterSlaying(_entityTracker.MeterUser, pstatupd.Slaying, pstatupd.Time.Ticks); return; } var changeMp = message as SPlayerChangeMp; if (changeMp != null) { _abnormalityTracker.Update(changeMp); return; } var npcStatus = message as SNpcStatus; if (npcStatus != null) { _abnormalityTracker.RegisterNpcStatus(npcStatus); return; } var dead = message as SCreatureLife; if (dead != null) { _abnormalityTracker.RegisterDead(dead); return; } var abnormalityBegin = message as SAbnormalityBegin; if (abnormalityBegin != null) { _abnormalityTracker.AddAbnormality(abnormalityBegin); return; } var abnormalityEnd = message as SAbnormalityEnd; if (abnormalityEnd != null) { _abnormalityTracker.DeleteAbnormality(abnormalityEnd); return; } var abnormalityRefresh = message as SAbnormalityRefresh; if (abnormalityRefresh != null) { _abnormalityTracker.RefreshAbnormality(abnormalityRefresh); return; } var despawnUser = message as SDespawnUser; if (despawnUser != null) { _charmTracker.CharmReset(despawnUser.User, new List <CharmStatus>(), despawnUser.Time.Ticks); _abnormalityTracker.DeleteAbnormality(despawnUser); return; } var charmEnable = message as SEnableCharmStatus; if (charmEnable != null) { _charmTracker.CharmEnable(_entityTracker.MeterUser.Id, charmEnable.CharmId, charmEnable.Time.Ticks); return; } var pcharmEnable = message as SPartyMemberCharmEnable; if (pcharmEnable != null) { var player = _playerTracker.GetOrNull(pcharmEnable.ServerId, pcharmEnable.PlayerId); if (player == null) { return; } _charmTracker.CharmEnable(player.User.Id, pcharmEnable.CharmId, pcharmEnable.Time.Ticks); return; } var charmReset = message as SResetCharmStatus; if (charmReset != null) { _charmTracker.CharmReset(charmReset.TargetId, charmReset.Charms, charmReset.Time.Ticks); return; } var pcharmReset = message as SPartyMemberCharmReset; if (pcharmReset != null) { var player = _playerTracker.GetOrNull(pcharmReset.ServerId, pcharmReset.PlayerId); if (player == null) { return; } _charmTracker.CharmReset(player.User.Id, pcharmReset.Charms, pcharmReset.Time.Ticks); return; } var charmDel = message as SRemoveCharmStatus; if (charmDel != null) { _charmTracker.CharmDel(_entityTracker.MeterUser.Id, charmDel.CharmId, charmDel.Time.Ticks); return; } var pcharmDel = message as SPartyMemberCharmDel; if (pcharmDel != null) { var player = _playerTracker.GetOrNull(pcharmDel.ServerId, pcharmDel.PlayerId); if (player == null) { return; } _charmTracker.CharmDel(player.User.Id, pcharmDel.CharmId, pcharmDel.Time.Ticks); return; } var charmAdd = message as SAddCharmStatus; if (charmAdd != null) { _charmTracker.CharmAdd(charmAdd.TargetId, charmAdd.CharmId, charmAdd.Status, charmAdd.Time.Ticks); return; } var pcharmAdd = message as SPartyMemberCharmAdd; if (pcharmAdd != null) { var player = _playerTracker.GetOrNull(pcharmAdd.ServerId, pcharmAdd.PlayerId); if (player == null) { return; } _charmTracker.CharmAdd(player.User.Id, pcharmAdd.CharmId, pcharmAdd.Status, pcharmAdd.Time.Ticks); return; } _entityTracker.Update(message); _playerTracker.UpdateParty(message); var spawnMe = message as SpawnMeServerMessage; if (spawnMe != null) { _abnormalityStorage.EndAll(message.Time.Ticks); _abnormalityTracker = new AbnormalityTracker(_entityTracker, _playerTracker, _teraData.HotDotDatabase, _abnormalityStorage, CheckUpdate); _charmTracker = new CharmTracker(_abnormalityTracker); return; } var sLogin = message as LoginServerMessage; if (sLogin != null) { _abnormalityStorage.EndAll(message.Time.Ticks); _abnormalityTracker = new AbnormalityTracker(_entityTracker, _playerTracker, _teraData.HotDotDatabase, _abnormalityStorage, CheckUpdate); _charmTracker = new CharmTracker(_abnormalityTracker); Server = BasicTeraData.Servers.GetServer(sLogin.ServerId, Server); return; } }