Beispiel #1
0
 private void AddLoot(LootInfo l)
 {
     if (LootTracker.IsStandardServer(l.Server))
     {
         lootList.Add(l);
     }
     //LogInfo($"Looted {l.Item} from {l.Source} in {l.Zone}");
 }
Beispiel #2
0
 ///<summary>
 ///Adds the sum of each property of the given TrackedProfile to this instance.
 ///</summary>
 public void MergeStats(TrackedProfile other)
 {
     TotalGold    += other.TotalGold;
     TotalXP      += other.TotalXP;
     DeathCount   += other.DeathCount;
     TotalTimeSpan = TotalTimeSpan.Add(other.TotalTimeSpan);
     LootTracker.Merge(other.LootTracker);
 }
Beispiel #3
0
        /// <summary>
        /// Perform timing tests on all trackers.
        /// </summary>
        public static void TimeTrackers(LogReader file, SpellParser spells)
        {
            var parser = new LogParser();

            parser.Player = LogOpenEvent.GetPlayerFromFileName(file.Path);

            // load raw log lines once
            var events = new List <LogEvent>();

            while (true)
            {
                var s = file.ReadLine();
                if (s == null)
                {
                    break;
                }
                var e = parser.ParseLine(s);
                if (e != null)
                {
                    events.Add(e);
                }
            }
            ;
            Console.Error.WriteLine("Loaded {0} events", events.Count);

            // timer trackers
            var trackers = new List <Action <LogEvent> >();
            var chars    = new CharTracker(spells);

            trackers.Add(chars.HandleEvent);
            var fights = new FightTracker(spells, chars);

            trackers.Add(fights.HandleEvent);
            var buffs = new BuffTracker(spells);

            trackers.Add(buffs.HandleEvent);
            var loot = new LootTracker();

            trackers.Add(loot.HandleEvent);

            // time individual trackers
            foreach (var t in trackers)
            {
                var ptimer = Stopwatch.StartNew();
                var pcount = 0;
                foreach (var e in events)
                {
                    t.Invoke(e);
                }
                Console.Error.WriteLine("{0,-20} {1,10} in {2}", t.Method.DeclaringType.Name, pcount, ptimer.Elapsed);
            }

            Console.WriteLine("***");
        }
Beispiel #4
0
    // Use this for initialization
    void Start()
    {
        dialogue     = FindObjectOfType <StoryDialog>();
        loot         = FindObjectOfType <LootTracker>();
        player       = FindObjectOfType <Player>();
        followCam    = FindObjectOfType <FollowCamera>();
        offerMachine = FindObjectOfType <OfferMachine>();
        levelUpAudio = GetComponent <AudioSource>();

        arcState = ArcState.INITIAL;

        player.enabled = false;
        FadeIn();
    }
Beispiel #5
0
        /// <summary>
        /// Start monitoring a log file from a background task.
        /// </summary>
        private async void WatchFile(string path)
        {
            if (!File.Exists(path))
            {
                return;
            }

            if (String.IsNullOrEmpty(LogOpenEvent.GetPlayerFromFileName(path)))
            {
                LogInfo($"Cannot open {path} because it doesn't use the standard naming convention.");
                return;
            }

            // cancel previous log parsing task
            if (cancellationSource != null)
            {
                cancellationSource.Cancel();
                await Task.Delay(600);
            }

            // always disable auto uploads when opening a file to avoid accidentally uploading a lot of data
            chkAutoUpload.Checked = chkAutoUpload.Enabled = false;

            // we don't know where to find the spell_us.txt file until we open a log file
            // spells should be one folder down from the log folder
            if (!spells.IsReady)
            {
                var spellpath = Path.GetDirectoryName(path) + @"\..\spells_us.txt";
                if (File.Exists(spellpath))
                {
                    LogInfo("Loading " + spellpath);
                    spells.Load(spellpath);
                    if (!spells.IsReady)
                    {
                        LogInfo("spells_us.txt could not be loaded. Class detection and buff tracking will not work properly.");
                    }
                }
                else
                {
                    LogInfo("spells_us.txt not found. Class detection and buff tracking will not work properly.");
                }
            }

            config.Write("filename", path);
            LogInfo("Loading " + path);
            var open   = LogOpenEvent.FromFileName(path);
            var parser = new LogParser();

            parser.Player = open.Player;

            // reset the trackers by creating new ones
            var charTracker = new CharTracker(spells);

            charTracker.Files = new FileService(Path.GetDirectoryName(path) + @"\..\");
            charTracker.HandleEvent(open);
            charTracker.ImportPlayers(config.Read("chars:" + open.Server));

            var fightTracker = new FightTracker(spells, charTracker);

            fightTracker.OnFightFinished += x => fightsQueue.Enqueue(x);
            fightTracker.AddTemplateFromResource();
            fightTracker.HandleEvent(open);

            var lootTracker = new LootTracker();

            lootTracker.OnLoot += x => lootQueue.Enqueue(x);
            lootTracker.HandleEvent(open);

            // reset UI
            lvFights.VirtualListSize = 0;
            fightList.Clear();
            fightListSearchResults     = null;
            toolStripStatusLabel1.Text = "-";
            toolStripStatusLabel2.Text = "-";

            // read roster files to assist player tracking
            if (!String.IsNullOrEmpty(open.Server))
            {
                var files = new DirectoryInfo(Path.GetDirectoryName(path)).Parent
                            .GetFiles("*_" + open.Server + "-*.txt")
                            .Where(x => x.CreationTime > DateTime.Today.AddDays(-14))
                            .Take(20);
                var roster = RosterParser.Load(files);
                foreach (var who in roster)
                {
                    charTracker.HandleEvent(who);
                }
            }

            // this handler runs in a background thread and must be threadsafe
            Action <string> handler = line =>
            {
                var e = parser.ParseLine(line);
                if (e != null)
                {
                    charTracker.HandleEvent(e);
                    fightTracker.HandleEvent(e);
                    lootTracker.HandleEvent(e);
                }
            };

            // this event runs in the main app thread
            // https://stackoverflow.com/questions/661561/how-do-i-update-the-gui-from-another-thread/18033198#18033198
            var progress = new Progress <LogReaderStatus>(p =>
            {
                toolStripStatusLabel1.Text = p.Percent.ToString("P0") + " " + p.Notes;
                var completed         = p.Percent > 0.99;
                chkAutoUpload.Enabled = completed;
            });

            cancellationSource = new CancellationTokenSource();
            var reader = new BackgroundLogReader(path, cancellationSource.Token, handler, progress);

            try
            {
                await reader.Start();
            }
            catch (Exception ex)
            {
                LogInfo("Error: " + ex.Message);
                LogInfo("Last Line: " + reader.LastLine);
            }
            //LogInfo("Closing " + path); // this log message can occur after the form has been disposed
            if (open.Server != null)
            {
                // save a list of players so that we have better information next time we run the parser
                var players = charTracker.ExportPlayers();
                config.Write("chars:" + open.Server, players);
            }

            //await ProcessLogFileAsync(path);
        }