Exemple #1
0
        /// <summary>
        /// Print an Actor Entity to the output window
        /// </summary>
        /// <param name="entity"></param>
        private void PrintEntity(ActorItem entity)
        {
            output.AppendText(String.Format("Name: {0}", entity.Name) + Environment.NewLine);
            output.AppendText(String.Format("Level: {0}", entity.Level) + Environment.NewLine);
            output.AppendText(String.Format("HP: {0}/{1}", entity.HPCurrent, entity.HPMax) + Environment.NewLine);
            output.AppendText(String.Format("MP: {0}/{1}", entity.MPCurrent, entity.MPMax) + Environment.NewLine);

            output.AppendText(String.Format("Model ID: {0}", entity.ModelID) + Environment.NewLine);
            output.AppendText(String.Format("NPCID 1: {0}", entity.NPCID1) + Environment.NewLine);
            output.AppendText(String.Format("NPCID 2: {0}", entity.NPCID2) + Environment.NewLine);
            output.AppendText(String.Format("Owner ID: {0}", entity.OwnerID) + Environment.NewLine);
            output.AppendText(String.Format("Memory ID: {0}", entity.ID) + Environment.NewLine);
            output.AppendText(String.Format("Map ID: {0}", entity.MapID) + Environment.NewLine);
            output.AppendText(String.Format("Map Index: {0}", entity.MapIndex) + Environment.NewLine);
            output.AppendText(String.Format("Map Territory: {0}", entity.MapTerritory) + Environment.NewLine);

            output.AppendText(String.Format("Is Casting: {0}", entity.IsCasting ? "Yes" : "No") + Environment.NewLine);
            output.AppendText(String.Format("Is Claimed: {0}", entity.IsClaimed ? "Yes" : "No") + Environment.NewLine);
            output.AppendText(String.Format("Is Fate: {0}", entity.IsFate ? "Yes" : "No") + Environment.NewLine);
            output.AppendText(String.Format("Status: {0}", entity.Status) + Environment.NewLine);
            output.AppendText(String.Format("Type: {0}", entity.Type) + Environment.NewLine);
            output.AppendText(String.Format("Target Type: {0}", entity.TargetType) + Environment.NewLine);

            output.AppendText(String.Format("Position: X {0} / Y {1} / Z {2}", entity.X, entity.Y, entity.Z) + Environment.NewLine);
            output.AppendText(String.Format("Distance from player: {0}", entity.GetDistanceTo(player)) + Environment.NewLine);
            output.AppendText("---------------------------------------------------------" + Environment.NewLine);
        }
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            var bc = new BrushConverter();

            ActorItem user = XIVInfoViewModel.Instance.CurrentUser;

            if (user == null)
            {
                return;
            }

            var origin = new Coordinate {
                X = (float)(this.ActualWidth / 2),
                Y = (float)(this.ActualHeight / 2),
            };

            var scale = (float)(this.ActualHeight / 2.0f) / 125.0f;
            var angle = Math.Abs(user.Heading * (180 / Math.PI) - 180);

            var drawingGroup = new DrawingGroup();

            if (Settings.Default.RadarCompassMode)
            {
                drawingGroup.Transform = new RotateTransform {
                    Angle   = angle,
                    CenterX = origin.X,
                    CenterY = origin.Y,
                };
            }

            drawingGroup.Children.Add(new ImageDrawing(Game.RadarHeading, new Rect(origin.X - 64, origin.Y - 128, 128, 128)));
            drawingGroup.Children.Add(new ImageDrawing(Game.Player, new Rect(origin.X - 8, origin.Y - 16, 16, 21)));

            this.DrawDrawing(drawingContext, drawingGroup);

            var sb = new StringBuilder();

            List <ActorItem> npcEntites     = new List <ActorItem>(XIVInfoViewModel.Instance.CurrentNPCs.Select(kvp => kvp.Value).ToList());
            List <ActorItem> monsterEntites = new List <ActorItem>(XIVInfoViewModel.Instance.CurrentMonsters.Select(kvp => kvp.Value).ToList());
            List <ActorItem> pcEntites      = new List <ActorItem>(XIVInfoViewModel.Instance.CurrentPCs.Select(kvp => kvp.Value).ToList());

            if (Settings.Default.FilterRadarItems)
            {
                List <RadarFilterItem> npcFilters = PluginViewModel.Instance.Filters.Where(filter => filter.Type != "PC" && filter.Type != "Monster").ToList();
                if (npcFilters.Any())
                {
                    npcEntites = RadarFilterHelper.ResolveFilteredEntities(npcFilters, npcEntites);
                }

                List <RadarFilterItem> monsterFilters = PluginViewModel.Instance.Filters.Where(filter => filter.Type == "Monster").ToList();
                if (PluginViewModel.Instance.RankedFilters.Any())
                {
                    monsterFilters.AddRange(PluginViewModel.Instance.RankedFilters);
                }

                if (monsterFilters.Any())
                {
                    monsterEntites = RadarFilterHelper.ResolveFilteredEntities(monsterFilters, monsterEntites);
                }

                List <RadarFilterItem> pcFilters = PluginViewModel.Instance.Filters.Where(filter => filter.Type == "PC").ToList();
                if (pcFilters.Any())
                {
                    pcEntites = RadarFilterHelper.ResolveFilteredEntities(pcFilters, pcEntites);
                }

                monsterEntites = RadarFilterHelper.CleanupEntities(monsterEntites);
            }

            #region Resolve PCs

            if (Settings.Default.PCShow)
            {
                foreach (ActorItem actorEntity in pcEntites)
                {
                    sb.Clear();
                    var fontSizeModifier = 0;
                    drawingContext.PushOpacity(1);
                    try {
                        if (!actorEntity.IsValid || user == null)
                        {
                            continue;
                        }

                        if (actorEntity.ID == user.ID)
                        {
                            continue;
                        }

                        Coordinate screen;
                        if (Settings.Default.RadarCompassMode)
                        {
                            Coordinate coord = user.Coordinate.Subtract(actorEntity.Coordinate).Scale(scale);
                            screen = new Coordinate(-coord.X, 0, -coord.Y).Add(origin);
                        }
                        else
                        {
                            screen = user.Coordinate.Subtract(actorEntity.Coordinate).Rotate2D(user.Heading).Scale(scale).Add(origin);
                        }

                        screen = screen.Add(-8, -8, 0);
                        if (Settings.Default.PCShowName)
                        {
                            sb.Append(actorEntity.Name);
                        }

                        if (Settings.Default.PCShowHPPercent)
                        {
                            sb.AppendFormat(" {0:P0}", actorEntity.HPPercent);
                        }

                        if (Settings.Default.PCShowDistance)
                        {
                            sb.AppendFormat(" {0:N2} {1}", user.GetDistanceTo(actorEntity), this.ResolveHeightVariance(user, actorEntity));
                        }

                        var useJob = Settings.Default.PCShowJob;
                        if (Settings.Default.PCShowJob)
                        {
                            #region Get Job Icons

                            switch (actorEntity.Job)
                            {
                            case Actor.Job.Unknown:
                                if (actorEntity.OwnerID > 0 && actorEntity.OwnerID < 3758096384)
                                {
                                    this.DrawImage(drawingContext, Game.Chocobo, new Rect(new Point(), new Size(16, 16)));
                                }

                                useJob = false;
                                break;

                            default:
                                this.DrawImage(drawingContext, Game.GetIconByName(actorEntity.Job.ToString()), new Rect(new Point(screen.X, screen.Y), new Size(16, 16)));
                                break;
                            }

                            #endregion
                        }

                        if (!useJob)
                        {
                            BitmapImage imageSource = actorEntity.HPCurrent > 0
                                                          ? Game.Player
                                                          : Game.Unknown;
                            this.DrawImage(drawingContext, imageSource, new Rect(new Point(screen.X, screen.Y), new Size(16, 16)));
                        }

                        this.RenderDebugInformation(actorEntity, ref sb);

                        if (Settings.Default.PCShowName || Settings.Default.PCShowHPPercent)
                        {
                            var text = new FormattedText(sb.ToString(), this._cultureInfo, this._flowDirection, this._typeface, int.Parse(Settings.Default.PCFontSize) + fontSizeModifier, (SolidColorBrush)bc.ConvertFromString(Settings.Default.PCFontColor));
                            this.DrawText(drawingContext, text, screen.X + 20, screen.Y);
                        }
                    }
                    catch (Exception ex) {
                        Logging.Log(Logger, new LogItem(ex, true));
                    }

                    drawingContext.Pop();
                }
            }

            #endregion

            #region Resolve Monsters

            if (Settings.Default.MonsterShow)
            {
                foreach (ActorItem actorEntity in monsterEntites)
                {
                    sb.Clear();
                    var fontSizeModifier = 0;
                    var fontColor        = Settings.Default.MonsterFontColor;

                    List <string> RankB = LocaleHelper.GetRankedMonsters("B");
                    List <string> RankA = LocaleHelper.GetRankedMonsters("A");
                    List <string> RankS = LocaleHelper.GetRankedMonsters("S");

                    var isRanked = false;

                    if (Settings.Default.MonsterShowRankColor)
                    {
                        if (RankA.Any(x => x.Equals(actorEntity.Name, StringComparison.InvariantCultureIgnoreCase)))
                        {
                            fontColor         = Settings.Default.MonsterFontColorARank;
                            fontSizeModifier += 2;
                            isRanked          = true;
                        }
                        else if (RankS.Any(x => x.Equals(actorEntity.Name, StringComparison.InvariantCultureIgnoreCase)))
                        {
                            fontColor         = Settings.Default.MonsterFontColorSRank;
                            fontSizeModifier += 2;
                            isRanked          = true;
                        }
                        else if (RankB.Any(x => x.Equals(actorEntity.Name, StringComparison.InvariantCultureIgnoreCase)))
                        {
                            fontColor         = Settings.Default.MonsterFontColorBRank;
                            fontSizeModifier += 2;
                            isRanked          = true;
                        }
                    }

                    drawingContext.PushOpacity(1);

                    try {
                        if (!actorEntity.IsValid || user == null)
                        {
                            continue;
                        }

                        if (actorEntity.ID == user.ID)
                        {
                            continue;
                        }

                        Coordinate screen;
                        if (Settings.Default.RadarCompassMode)
                        {
                            Coordinate coord = user.Coordinate.Subtract(actorEntity.Coordinate).Scale(scale);
                            screen = new Coordinate(-coord.X, 0, -coord.Y).Add(origin);
                        }
                        else
                        {
                            screen = user.Coordinate.Subtract(actorEntity.Coordinate).Rotate2D(user.Heading).Scale(scale).Add(origin);
                        }

                        screen = screen.Add(-8, -8, 0);
                        BitmapImage actorIcon;

                        if (actorEntity.IsFate)
                        {
                            actorIcon = Game.MobFate;
                        }
                        else
                        {
                            switch (actorEntity.DifficultyRank)
                            {
                            case 6:
                                actorIcon = actorEntity.IsAggressive
                                                    ? Game.MobAggressive5
                                                    : Game.MobPassive5;
                                break;

                            case 4:
                                actorIcon = actorEntity.IsAggressive
                                                    ? Game.MobAggressive3
                                                    : Game.MobPassive3;
                                break;

                            case 3:
                                actorIcon = actorEntity.IsAggressive
                                                    ? Game.MobAggressive2
                                                    : Game.MobPassive2;
                                break;

                            case 2:
                                actorIcon = actorEntity.IsAggressive
                                                    ? Game.MobAggressive6
                                                    : Game.MobPassive6;
                                break;

                            case 1:
                                actorIcon = actorEntity.IsAggressive
                                                    ? Game.MobAggressive4
                                                    : Game.MobPassive4;
                                break;

                            default:
                                actorIcon = actorEntity.IsAggressive
                                                    ? Game.MobAggressive1
                                                    : Game.MobPassive1;
                                break;
                            }

                            if (actorEntity.OwnerID > 0 && actorEntity.OwnerID < 3758096384)
                            {
                                actorIcon = Game.Chocobo;
                            }
                        }

                        var iconSize = new Size(16, 16);
                        var point    = new Point(screen.X, screen.Y);

                        if (isRanked)
                        {
                            iconSize = new Size(24, 24);
                            point    = new Point(screen.X - 4, screen.Y - 4);
                        }

                        if (actorEntity.HPCurrent > 0)
                        {
                            if (actorIcon != null)
                            {
                                this.DrawImage(drawingContext, actorIcon, new Rect(point, iconSize));
                            }
                        }
                        else
                        {
                            this.DrawImage(drawingContext, Game.Unknown, new Rect(point, iconSize));
                        }

                        if (Settings.Default.MonsterShowName)
                        {
                            sb.Append(actorEntity.Name);
                        }

                        if (Settings.Default.MonsterShowHPPercent)
                        {
                            sb.AppendFormat(" {0:P0}", actorEntity.HPPercent);
                        }

                        if (Settings.Default.MonsterShowDistance)
                        {
                            sb.AppendFormat(" {0:N2} {1}", user.GetDistanceTo(actorEntity), this.ResolveHeightVariance(user, actorEntity));
                        }

                        this.RenderDebugInformation(actorEntity, ref sb);

                        if (Settings.Default.MonsterShowName || Settings.Default.MonsterShowHPPercent)
                        {
                            var text = new FormattedText(sb.ToString(), this._cultureInfo, this._flowDirection, this._typeface, int.Parse(Settings.Default.MonsterFontSize) + fontSizeModifier, (SolidColorBrush)bc.ConvertFromString(fontColor));
                            this.DrawText(drawingContext, text, screen.X + 20, screen.Y);
                        }
                    }
                    catch (Exception ex) {
                        Logging.Log(Logger, new LogItem(ex, true));
                    }

                    drawingContext.Pop();
                }
            }

            #endregion

            #region Resolve NPCs, Gathering & Other

            foreach (ActorItem actorEntity in npcEntites)
            {
                sb.Clear();
                var fontSizeModifier = 0;
                drawingContext.PushOpacity(1);

                try {
                    if (!actorEntity.IsValid || user == null)
                    {
                        continue;
                    }

                    if (actorEntity.ID == user.ID)
                    {
                        continue;
                    }

                    Coordinate screen;
                    if (Settings.Default.RadarCompassMode)
                    {
                        Coordinate coord = user.Coordinate.Subtract(actorEntity.Coordinate).Scale(scale);
                        screen = new Coordinate(-coord.X, 0, -coord.Y).Add(origin);
                    }
                    else
                    {
                        screen = user.Coordinate.Subtract(actorEntity.Coordinate).Rotate2D(user.Heading).Scale(scale).Add(origin);
                    }

                    screen = screen.Add(-8, -8, 0);
                    BitmapImage actorIcon;

                    switch (actorEntity.Type)
                    {
                    case Actor.Type.NPC:

                        #region Resolve NPCs

                        if (Settings.Default.NPCShow)
                        {
                            try {
                                if (Settings.Default.NPCShowName)
                                {
                                    sb.Append(actorEntity.Name);
                                }

                                if (Settings.Default.NPCShowHPPercent)
                                {
                                    sb.AppendFormat(" {0:P0}", actorEntity.HPPercent);
                                }

                                if (Settings.Default.NPCShowDistance)
                                {
                                    sb.AppendFormat(" {0:N2} {1}", user.GetDistanceTo(actorEntity), this.ResolveHeightVariance(user, actorEntity));
                                }

                                actorIcon = actorEntity.HPCurrent > 0
                                                    ? Game.Vendor
                                                    : Game.Unknown;
                                this.DrawImage(drawingContext, actorIcon, new Rect(new Point(screen.X, screen.Y), new Size(16, 16)));

                                this.RenderDebugInformation(actorEntity, ref sb);

                                if (Settings.Default.NPCShowName || Settings.Default.NPCShowHPPercent)
                                {
                                    var text = new FormattedText(sb.ToString(), this._cultureInfo, this._flowDirection, this._typeface, int.Parse(Settings.Default.NPCFontSize) + fontSizeModifier, (SolidColorBrush)bc.ConvertFromString(Settings.Default.NPCFontColor));
                                    this.DrawText(drawingContext, text, screen.X + 20, screen.Y);
                                }
                            }
                            catch (Exception ex) {
                                Logging.Log(Logger, new LogItem(ex, true));
                            }

                            drawingContext.Pop();
                        }

                        #endregion

                        break;

                    case Actor.Type.Gathering:

                        #region Resolve Gathering

                        if (Settings.Default.GatheringShow && actorEntity.GatheringInvisible == 0)
                        {
                            try {
                                if (Settings.Default.GatheringShowName)
                                {
                                    sb.Append(actorEntity.Name);
                                }

                                if (Settings.Default.GatheringShowHPPercent)
                                {
                                    sb.AppendFormat(" {0:P0}", actorEntity.HPPercent);
                                }

                                if (Settings.Default.GatheringShowDistance)
                                {
                                    sb.AppendFormat(" {0:N2} {1}", user.GetDistanceTo(actorEntity), this.ResolveHeightVariance(user, actorEntity));
                                }

                                actorIcon = Game.Gathering;
                                if (Constants.GatheringNodes.TryGetValue(user.Job.ToString(), out List <GatheringNode> node))
                                {
                                    GatheringNode nodeMatch = node.FirstOrDefault(n => n.Localization.Matches(actorEntity.Name));
                                    if (nodeMatch != null)
                                    {
                                        switch (user.Job)
                                        {
                                        case Actor.Job.BTN:
                                            actorIcon = Game.Harvesting;
                                            switch (nodeMatch.Rarity)
                                            {
                                            case GatheringRarity.Unspoiled:
                                            case GatheringRarity.Ephemeral:
                                            case GatheringRarity.Legendary:
                                                actorIcon = Game.HarvestingSuper;
                                                break;
                                            }

                                            break;

                                        case Actor.Job.FSH:
                                            actorIcon = Game.Fishing;
                                            break;

                                        case Actor.Job.MIN:
                                            actorIcon = Game.Mining;
                                            switch (nodeMatch.Rarity)
                                            {
                                            case GatheringRarity.Unspoiled:
                                            case GatheringRarity.Ephemeral:
                                            case GatheringRarity.Legendary:
                                                actorIcon = Game.MiningSuper;
                                                break;
                                            }

                                            break;
                                        }
                                    }
                                }

                                this.DrawImage(drawingContext, actorIcon, new Rect(new Point(screen.X, screen.Y), new Size(16, 16)));

                                this.RenderDebugInformation(actorEntity, ref sb);

                                if (Settings.Default.GatheringShowName || Settings.Default.GatheringShowHPPercent)
                                {
                                    var text = new FormattedText(sb.ToString(), this._cultureInfo, this._flowDirection, this._typeface, int.Parse(Settings.Default.GatheringFontSize) + fontSizeModifier, (SolidColorBrush)bc.ConvertFromString(Settings.Default.GatheringFontColor));
                                    this.DrawText(drawingContext, text, screen.X + 20, screen.Y);
                                }
                            }
                            catch (Exception ex) {
                                Logging.Log(Logger, new LogItem(ex, true));
                            }

                            drawingContext.Pop();
                        }

                        #endregion

                        break;

                    default:

                        #region Resolve Other

                        if (Settings.Default.OtherShow)
                        {
                            try {
                                switch (actorEntity.Type)
                                {
                                case Actor.Type.Aetheryte:
                                    actorIcon = Game.Aetheryte;
                                    break;

                                case Actor.Type.Minion:
                                    actorIcon = Game.Avatar;
                                    break;

                                default:
                                    actorIcon = Game.Vendor;
                                    break;
                                }

                                if (actorEntity.HPCurrent > 0 || actorEntity.Type == Actor.Type.Aetheryte)
                                {
                                    if (actorIcon != null)
                                    {
                                        this.DrawImage(drawingContext, actorIcon, new Rect(new Point(screen.X, screen.Y), new Size(16, 16)));
                                    }
                                }
                                else
                                {
                                    this.DrawImage(drawingContext, Game.Unknown, new Rect(new Point(screen.X, screen.Y), new Size(16, 16)));
                                }

                                if (Settings.Default.OtherShowName)
                                {
                                    sb.Append(actorEntity.Name);
                                }

                                if (Settings.Default.OtherShowHPPercent)
                                {
                                    sb.AppendFormat(" {0:P0}", actorEntity.HPPercent);
                                }

                                if (Settings.Default.OtherShowDistance)
                                {
                                    sb.AppendFormat(" {0:N2} {1}", user.GetDistanceTo(actorEntity), this.ResolveHeightVariance(user, actorEntity));
                                }

                                this.RenderDebugInformation(actorEntity, ref sb);

                                if (Settings.Default.OtherShowName || Settings.Default.OtherShowHPPercent)
                                {
                                    var text = new FormattedText(sb.ToString(), this._cultureInfo, this._flowDirection, this._typeface, int.Parse(Settings.Default.OtherFontSize) + fontSizeModifier, (SolidColorBrush)bc.ConvertFromString(Settings.Default.OtherFontColor));
                                    this.DrawText(drawingContext, text, screen.X + 20, screen.Y);
                                }
                            }
                            catch (Exception ex) {
                                Logging.Log(Logger, new LogItem(ex, true));
                            }

                            drawingContext.Pop();
                        }

                        #endregion

                        break;
                    }
                }
                catch (Exception ex) { }
            }

            #endregion
        }