private LootEvent BuildTestEvent()
 {
     return(new LootEvent
     {
         Timestamp = DateUtil.CurrentTime(),
         LootEventId = Guid.NewGuid(),
         TerritoryTypeId = 1,
         ContentId = 1,
         LootMessage = new LootMessage
         {
             ItemId = 1,
             ItemName = "Pokeball"
         }
     });
 }
Exemple #2
0
        private void PlayerList()
        {
            ImGui.BeginChild(
                "###PlayerTrack_PlayerList_Child",
                new Vector2(205 * ImGuiHelpers.GlobalScale, 0),
                true);

            if (DateUtil.CurrentTime() > this.lastPlayerListRefresh)
            {
                this.players = this.plugin.PlayerService.GetSortedPlayers(this.searchInput);
                this.lastPlayerListRefresh += this.plugin.Configuration.PlayerListRefreshFrequency;
            }

            // use clipper to avoid performance hit on large player lists
            ImGuiListClipperPtr clipper;

            unsafe
            {
                clipper = new ImGuiListClipperPtr(ImGuiNative.ImGuiListClipper_ImGuiListClipper());
            }

            clipper.Begin(this.players.Length);
            while (clipper.Step())
            {
                for (var i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
                {
                    ImGui.BeginGroup();
                    var color = this.plugin.PlayerService.GetPlayerListColor(this.players[i]);
                    ImGui.PushStyleColor(ImGuiCol.Text, color);
                    if (ImGui.Selectable(
                            "###PlayerTrack_Player_Selectable_" + i,
                            this.plugin.WindowManager.Panel !.SelectedPlayer == this.players[i],
                            ImGuiSelectableFlags.AllowDoubleClick))
                    {
                        // suppress double clicks
                        if (ImGui.IsMouseDoubleClicked(ImGuiMouseButton.Left))
                        {
                            // ignored
                        }

                        // hide right panel if clicking same user while already open
                        else if (this.plugin.WindowManager.Panel !.SelectedPlayer?.Key == this.players[i].Key && this.plugin.Configuration.CurrentView == View.PlayerDetail)
                        {
                            this.ClearSelectedPlayer();
                            this.plugin.WindowManager.Panel !.HidePanel();
                        }
Exemple #3
0
 public void UpdateRolls()
 {
     try
     {
         if (_plugin.LootRolls.Count == 0)
         {
             return;
         }
         var currentTime = DateUtil.CurrentTime();
         _plugin.LootRolls.RemoveAll(roll => !roll.IsWon &&
                                     currentTime - roll.Timestamp >
                                     _plugin.Configuration.RollMonitorAddedTimeout);
         _plugin.LootRolls.RemoveAll(roll => roll.IsWon &&
                                     currentTime - roll.Timestamp >
                                     _plugin.Configuration.RollMonitorObtainedTimeout);
         _plugin.IsRolling = _plugin.LootRolls.Count > 0;
         CreateDisplayList();
     }
     catch (Exception ex)
     {
         _plugin.LogError(ex, "Failed to remove old rolls.");
     }
 }
Exemple #4
0
        private void Draw()
        {
            // only show when logged in
            if (!PriceCheckPlugin.ClientState.IsLoggedIn)
            {
                return;
            }

            // draw config if open
            this.ConfigWindowSystem.Draw();

            // run keybind post-click check to use item id set in hover manager
            if (this.Plugin.Configuration.KeybindEnabled && this.Plugin.Configuration.AllowKeybindAfterHover &&
                this.Plugin.IsKeyBindPressed())
            {
                // call price check if item is set from previous hover
                if (this.Plugin.HoveredItemManager.ItemId != 0)
                {
                    this.Plugin.PriceService.ProcessItemAsync(this.Plugin.HoveredItemManager.ItemId, this.Plugin.HoveredItemManager.ItemQuality);
                    this.Plugin.HoveredItemManager.ItemId = 0;
                }
            }

            // draw main window
            if (this.Plugin.Configuration.HideOverlayElapsed != 0 &&
                DateUtil.CurrentTime() - this.Plugin.PriceService.LastPriceCheck >
                this.Plugin.Configuration.HideOverlayElapsed)
            {
                if (!(this.Plugin.Configuration.ShowOverlayByKeybind && this.Plugin.IsKeyBindPressed()))
                {
                    return;
                }
            }

            this.MainWindowSystem.Draw();
        }
        /// <summary>
        /// Load test data.
        /// </summary>
        /// <param name="plugin">kapture plugin.</param>
        public static void LoadTestData(IKapturePlugin plugin)
        {
            // get test data by language
            TestDataSet?testDataSet = null;
            var         langCode    = plugin.ClientLanguage();

            testDataSet = langCode switch
            {
                0 => new TestDataSet
                {
                    ItemName1   = "Ruby Tide Bracelets of Fending",
                    ItemName2   = "Wind-up Aldgoat",
                    PlayerName1 = "Wyatt Earp",
                    PlayerName2 = "April O'Neil",
                },
                1 => new TestDataSet
                {
                    ItemName1   = "Ruby Tide Bracelets of Fending",
                    ItemName2   = "Wind-up Aldgoat",
                    PlayerName1 = "Wyatt Earp",
                    PlayerName2 = "April O'Neil",
                },
                2 => new TestDataSet
                {
                    ItemName1   = "Topasring",
                    ItemName2   = "Kiesgolem",
                    PlayerName1 = "Hans Yolo",
                    PlayerName2 = "April O'Neil",
                },
                3 => new TestDataSet
                {
                    ItemName1   = "Ruby Tide Bracelets of Fending",
                    ItemName2   = "Wind-up Aldgoat",
                    PlayerName1 = "Wyatt Earp",
                    PlayerName2 = "April O'Neil",
                },
                4 => new TestDataSet
                {
                    ItemName1 = "延夏学士指饰", ItemName2 = "改良型田园监督者耳坠", PlayerName1 = "望舒", PlayerName2 = "语嫣",
                },
                _ => testDataSet,
            };

            if (testDataSet == null)
            {
                return;
            }

            // add loot
            var event1 = new LootEvent
            {
                LootEventType     = LootEventType.Add,
                LootEventTypeName = Enum.GetName(typeof(LootEventType), LootEventType.Add) ?? string.Empty,
                Timestamp         = DateUtil.CurrentTime(),
                LootEventId       = Guid.NewGuid(),
                TerritoryTypeId   = 1,
                ContentId         = 1,
                LootMessage       = new LootMessage
                {
                    ItemId   = 1,
                    ItemName = testDataSet.ItemName1,
                },
                ItemName            = testDataSet.ItemName1,
                ItemNameAbbreviated = testDataSet.ItemName1,
            };

            plugin.RollMonitor.ProcessRoll(event1);
            plugin.LootEvents.Add(event1);

            // add again
            var event2 = new LootEvent
            {
                LootEventType     = LootEventType.Add,
                LootEventTypeName = Enum.GetName(typeof(LootEventType), LootEventType.Add) ?? string.Empty,
                Timestamp         = DateUtil.CurrentTime(),
                LootEventId       = Guid.NewGuid(),
                TerritoryTypeId   = 1,
                ContentId         = 1,
                LootMessage       = new LootMessage
                {
                    ItemId   = 1,
                    ItemName = testDataSet.ItemName2,
                },
                ItemName            = testDataSet.ItemName2,
                ItemNameAbbreviated = testDataSet.ItemName2,
            };

            plugin.RollMonitor.ProcessRoll(event2);
            plugin.LootEvents.Add(event2);

            // cast
            var event3 = new LootEvent
            {
                LootEventType     = LootEventType.Cast,
                LootEventTypeName = Enum.GetName(typeof(LootEventType), LootEventType.Cast) ?? string.Empty,
                Timestamp         = DateUtil.CurrentTime(),
                LootEventId       = Guid.NewGuid(),
                TerritoryTypeId   = 1,
                ContentId         = 1,
                LootMessage       = new LootMessage
                {
                    ItemId   = 1,
                    ItemName = testDataSet.ItemName1,
                },
                ItemName            = testDataSet.ItemName1,
                ItemNameAbbreviated = testDataSet.ItemName1,
                PlayerName          = testDataSet.PlayerName1,
            };

            plugin.RollMonitor.ProcessRoll(event3);
            plugin.LootEvents.Add(event3);

            // cast again
            var event4 = new LootEvent
            {
                LootEventType     = LootEventType.Cast,
                LootEventTypeName = Enum.GetName(typeof(LootEventType), LootEventType.Cast) ?? string.Empty,
                Timestamp         = DateUtil.CurrentTime(),
                LootEventId       = Guid.NewGuid(),
                TerritoryTypeId   = 1,
                ContentId         = 1,
                LootMessage       = new LootMessage
                {
                    ItemId   = 1,
                    ItemName = testDataSet.ItemName1,
                },
                ItemName            = testDataSet.ItemName1,
                ItemNameAbbreviated = testDataSet.ItemName1,
                PlayerName          = testDataSet.PlayerName2,
            };

            plugin.RollMonitor.ProcessRoll(event4);
            plugin.LootEvents.Add(event4);

            // need roll
            var event5 = new LootEvent
            {
                LootEventType     = LootEventType.Need,
                LootEventTypeName = Enum.GetName(typeof(LootEventType), LootEventType.Need) ?? string.Empty,
                Timestamp         = DateUtil.CurrentTime(),
                LootEventId       = Guid.NewGuid(),
                TerritoryTypeId   = 1,
                ContentId         = 1,
                LootMessage       = new LootMessage
                {
                    ItemId   = 1,
                    ItemName = testDataSet.ItemName1,
                },
                ItemName            = testDataSet.ItemName1,
                ItemNameAbbreviated = testDataSet.ItemName1,
                PlayerName          = testDataSet.PlayerName2,
                Roll = 45,
            };

            plugin.RollMonitor.ProcessRoll(event5);
            plugin.LootEvents.Add(event5);

            // need roll again
            var event6 = new LootEvent
            {
                LootEventType     = LootEventType.Need,
                LootEventTypeName = Enum.GetName(typeof(LootEventType), LootEventType.Need) ?? string.Empty,
                Timestamp         = DateUtil.CurrentTime(),
                LootEventId       = Guid.NewGuid(),
                TerritoryTypeId   = 1,
                ContentId         = 1,
                LootMessage       = new LootMessage
                {
                    ItemId   = 1,
                    ItemName = testDataSet.ItemName1,
                },
                ItemName            = testDataSet.ItemName1,
                ItemNameAbbreviated = testDataSet.ItemName1,
                PlayerName          = testDataSet.PlayerName1,
                Roll = 57,
            };

            plugin.RollMonitor.ProcessRoll(event6);
            plugin.LootEvents.Add(event6);

            // obtain
            var event7 = new LootEvent
            {
                LootEventType     = LootEventType.Obtain,
                LootEventTypeName = Enum.GetName(typeof(LootEventType), LootEventType.Obtain) ?? string.Empty,
                Timestamp         = DateUtil.CurrentTime(),
                LootEventId       = Guid.NewGuid(),
                TerritoryTypeId   = 1,
                ContentId         = 1,
                LootMessage       = new LootMessage
                {
                    ItemId   = 1,
                    ItemName = testDataSet.ItemName1,
                },
                ItemName            = testDataSet.ItemName1,
                ItemNameAbbreviated = testDataSet.ItemName1,
                PlayerName          = testDataSet.PlayerName1,
            };

            plugin.RollMonitor.ProcessRoll(event7);
            plugin.LootEvents.Add(event7);
        }
Exemple #6
0
        private void PlayerListControls()
        {
            var playerFilterTypeIndex = this.plugin.Configuration.PlayerFilterType;

            ImGui.BeginGroup();

            // filter type
            if (this.Plugin.Configuration.ShowFilterType)
            {
                ImGui.SetNextItemWidth(-1);
                if (ImGui.Combo(
                        "###PlayerTrack_PlayerFilterType_Combo",
                        ref playerFilterTypeIndex,
                        PlayerFilterType.FilterTypeNames.ToArray(),
                        PlayerFilterType.FilterTypeNames.Count))
                {
                    this.plugin.Configuration.PlayerFilterType = PlayerFilterType.GetPlayerFilterTypeByIndex(playerFilterTypeIndex).Index;
                    this.plugin.SaveConfig();
                    this.plugin.PlayerService.ResetViewPlayers();
                }
            }

            // category filter
            if (PlayerFilterType.GetPlayerFilterTypeByIndex(playerFilterTypeIndex) ==
                PlayerFilterType.PlayersByCategory)
            {
                var categoryNames = this.plugin.CategoryService.GetCategoryNames().ToArray();
                var categoryIds   = this.plugin.CategoryService.GetCategoryIds().ToArray();
                var categoryIndex = Array.IndexOf(categoryIds, this.plugin.Configuration.CategoryFilterId);
                ImGui.SetNextItemWidth(-1);
                if (ImGui.Combo(
                        "###PlayerTrack_CategoryFilter_Combo",
                        ref categoryIndex,
                        categoryNames,
                        categoryNames.Length))
                {
                    this.plugin.Configuration.CategoryFilterId = categoryIds[categoryIndex];
                    this.plugin.SaveConfig();
                    this.plugin.PlayerService.ResetViewPlayers();
                }
            }

            // search box
            // ReSharper disable once ConvertIfStatementToSwitchStatement
            if (this.Plugin.Configuration.ShowSearchBox)
            {
                ImGui.SetNextItemWidth(-1);
                if (ImGui.InputTextWithHint(
                        "###PlayerTrack_SearchBox_Input",
                        Loc.Localize("SearchHint", "search"),
                        ref this.searchInput,
                        30))
                {
                    this.lastPlayerListRefresh = DateUtil.CurrentTime();
                }
            }

            // add dummy spacing if nothing available so can still open menu
            if (!this.Plugin.Configuration.ShowSearchBox && !this.Plugin.Configuration.ShowFilterType)
            {
                var vector2 = this.WindowSize;
                if (vector2 != null)
                {
                    ImGui.Dummy(new Vector2(vector2.Value.X, 5f));
                }
            }

            ImGui.EndGroup();

            // open config popup on right click
            if (ImGui.IsItemClicked(ImGuiMouseButton.Right))
            {
                ImGui.OpenPopup("###PlayerTrack_Menu_Popup");
            }

            // config menu popup
            if (ImGui.BeginPopup("###PlayerTrack_Menu_Popup"))
            {
                if (ImGui.MenuItem(
                        Loc.Localize("AddPlayerMenuItem", "Add Player")))
                {
                    this.plugin.WindowManager.Panel !.TogglePanel(View.AddPlayer);
                }

                if (ImGui.MenuItem(
                        Loc.Localize("OpenLodestoneService", "Open Lodestone")))
                {
                    this.plugin.WindowManager.Panel !.TogglePanel(View.Lodestone);
                }

                if (ImGui.MenuItem(
                        Loc.Localize("OpenSettings", "Open Settings")))
                {
                    this.Plugin.WindowManager.ConfigWindow !.IsOpen ^= true;
                }

                ImGui.EndPopup();
            }
        }
Exemple #7
0
        private void OnChatMessageHandled(XivChatType type, uint senderId, ref SeString sender, ref SeString message,
                                          ref bool isHandled)
        {
            // check if enabled
            if (!Configuration.Enabled)
            {
                return;
            }

            // log for debugging
            if (Configuration.DebugLoggingEnabled)
            {
                LogInfo("[ChatMessage]" + type + ":" + message);
            }

            // combat check
            if (Configuration.RestrictInCombat && InCombat())
            {
                return;
            }

            // lookup territory and content
            var xivChatType     = (ushort)type;
            var territoryTypeId = GetTerritoryType();
            var contentId       = GetContentId(territoryTypeId);

            // update content
            InContent = contentId != 0;

            // restrict by user settings
            if (Configuration.RestrictToContent && contentId == 0)
            {
                return;
            }
            if (Configuration.RestrictToHighEndDuty && !IsHighEndDuty(contentId))
            {
                return;
            }
            if (Configuration.RestrictToCustomContent && !Configuration.PermittedContent.Contains(contentId))
            {
                return;
            }

            // filter out bad messages
            if (!Enum.IsDefined(typeof(LootMessageType), xivChatType))
            {
                return;
            }
            if (!message.Payloads.Any(payload => payload is ItemPayload))
            {
                return;
            }
            var logKind = (LogKind)((uint)type & ~(~0 << 7));

            if (!Enum.IsDefined(typeof(LogKind), logKind))
            {
                return;
            }

            // build initial loot message
            var lootMessage = new LootMessage
            {
                XivChatType     = xivChatType,
                LogKind         = logKind,
                LootMessageType = (LootMessageType)xivChatType,
                Message         = message.TextValue
            };

            // add name fields for logging/display
            lootMessage.LogKindName         = Enum.GetName(typeof(LogKind), lootMessage.LogKind);
            lootMessage.LootMessageTypeName = Enum.GetName(typeof(LootMessageType), lootMessage.LootMessageType);

            // add item and message part payloads
            foreach (var payload in message.Payloads)
            {
                switch (payload)
                {
                case TextPayload textPayload:
                    lootMessage.MessageParts.Add(textPayload.Text);
                    break;

                case ItemPayload itemPayload:
                    if (lootMessage.ItemId != 0)
                    {
                        break;
                    }
                    lootMessage.ItemId   = itemPayload.Item.RowId;
                    lootMessage.ItemName = itemPayload.Item.Name.ToString();
                    lootMessage.Item     = itemPayload.Item;
                    lootMessage.IsHq     = itemPayload.IsHQ;
                    break;
                }
            }

            // filter out non-permitted item ids
            if (Configuration.RestrictToCustomItems && !Configuration.PermittedItems.Contains(lootMessage.ItemId))
            {
                return;
            }

            // log for debugging
            if (Configuration.DebugLoggingEnabled)
            {
                LogInfo("[LootChatMessage]" + lootMessage);
            }

            // send to loot processor
            var lootEvent = LootProcessor.ProcessLoot(lootMessage);

            // kick out if didn't process
            if (lootEvent == null)
            {
                return;
            }

            // log for debugging
            if (Configuration.DebugLoggingEnabled)
            {
                LogInfo("[LootEvent]" + lootEvent);
            }

            // enrich
            lootEvent.Timestamp       = DateUtil.CurrentTime();
            lootEvent.LootEventId     = Guid.NewGuid();
            lootEvent.TerritoryTypeId = territoryTypeId;
            lootEvent.ContentId       = contentId;

            // add to list
            if (LootProcessor.IsEnabledEvent(lootEvent))
            {
                LootEvents.Add(lootEvent);
            }

            // process for roll monitor
            RollMonitor.LootEvents.Enqueue(lootEvent);

            // output
            if (Configuration.LoggingEnabled)
            {
                LootLogger.LogLoot(lootEvent);
            }
        }