Exemple #1
0
        private void ResetDamageTracker(ResetPlayerStatsMessage message = null)
        {
            if (Server == null)
            {
                return;
            }

            var saveEncounter = message != null && message.ShouldSaveCurrent;

            if (saveEncounter && !DamageTracker.IsArchived && DamageTracker.StatsByUser.Count > 0 &&
                DamageTracker.FirstAttack != null && DamageTracker.LastAttack != null)
            {
                DamageTracker.IsArchived = true;
                DamageTracker.Abnormals  = _abnormalityStorage.Clone();
                ArchivedDamageTrackers.Add(DamageTracker);
                return;
            }
            if (message != null && !message.ShouldSaveCurrent && DamageTracker.IsArchived)
            {
                ArchivedDamageTrackers.Remove(DamageTracker);
            }

            _abnormalityStorage.ClearEnded();
            DamageTracker = new DamageTracker
            {
                OnlyBosses     = OnlyBosses,
                IgnoreOneshots = IgnoreOneshots,
                Abnormals      = _abnormalityStorage,
                MeterPlayer    = _playerTracker?.Me()
            };
        }
Exemple #2
0
        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;
            }
        }