protected override LootEvent ProcessOtherPlayerRoll(LootMessage message)
        {
            var lootEvent = new LootEvent
            {
                IsLocalPlayer = false,
                PlayerName    = message.MessageParts[0]
            };

            // Cast Lot (Other Player)
            if (message.MessageParts.Count >= 2 && ProcessOtherPlayerRollCastRegex.IsMatch(message.MessageParts[1]))
            {
                lootEvent.LootEventType = LootEventType.Cast;
            }

            // Need Roll (Other Player)
            else if (message.MessageParts.Count >= 2 && ProcessOtherPlayerRollNeedRegex.IsMatch(message.MessageParts[1]))
            {
                lootEvent.LootEventType = LootEventType.Need;
                lootEvent.Roll          = Convert.ToUInt16(RollRegex.Match(message.MessageParts[1]).Groups["Roll"].Value);
            }

            // Greed Roll (Other Player)
            else if (message.MessageParts.Count >= 2 && ProcessOtherPlayerRollGreedRegex.IsMatch(message.MessageParts[1]))
            {
                lootEvent.LootEventType = LootEventType.Greed;
                lootEvent.Roll          = Convert.ToUInt16(RollRegex.Match(message.MessageParts[1]).Groups["Roll"].Value);
            }

            else
            {
                return(null);
            }

            return(lootEvent);
        }
        /// <inheritdoc />
        protected override LootEvent?ProcessOtherPlayerRoll(LootMessage message)
        {
            var lootEvent = new LootEvent
            {
                IsLocalPlayer = false,
                PlayerName    = message.MessageParts.First(),
                World         = message.Player?.World.Name.ToString() ?? string.Empty,
            };

            // Cast Lot (Other Player)
            if (message.MessageParts.Count >= 2 && this.ProcessOtherPlayerRollCastRegex.IsMatch(message.MessageParts[1]))
            {
                lootEvent.LootEventType = LootEventType.Cast;
            }

            // Need Roll (Other Player)
            else if (message.MessageParts.Count >= 2 && this.ProcessOtherPlayerRollNeedRegex.IsMatch(message.MessageParts[1]))
            {
                lootEvent.LootEventType = LootEventType.Need;
                lootEvent.Roll          = Convert.ToUInt16(this.RollRegex.Match(message.MessageParts.Last()).Groups["Roll"].Value);
            }

            // Greed Roll (Other Player)
            else if (message.MessageParts.Count >= 2 && this.ProcessOtherPlayerRollGreedRegex.IsMatch(message.MessageParts[1]))
            {
                lootEvent.LootEventType = LootEventType.Greed;
                lootEvent.Roll          = Convert.ToUInt16(this.RollRegex.Match(message.MessageParts.Last()).Groups["Roll"].Value);
            }
            else
            {
                return(null);
            }

            return(lootEvent);
        }
        protected override LootEvent ProcessLocalPlayerRoll(LootMessage message)
        {
            var lootEvent = new LootEvent
            {
                IsLocalPlayer = true,
                PlayerName    = Plugin.GetLocalPlayerName()
            };

            // Cast Lot (Local Player)
            if (ProcessLocalPlayerRollCastRegex.IsMatch(message.MessageParts.First()))
            {
                lootEvent.LootEventType = LootEventType.Cast;
            }

            // Need Roll (Local Player)
            else if (message.MessageParts.Count >= 1 && ProcessLocalPlayerRollNeedRegex.IsMatch(message.MessageParts[0]))
            {
                lootEvent.LootEventType = LootEventType.Need;
                lootEvent.Roll          = Convert.ToUInt16(RollRegex.Match(message.MessageParts.First()).Groups["Roll"].Value);
            }

            // Greed Roll (Local Player)
            else if (ProcessLocalPlayerRollGreedRegex.IsMatch(message.MessageParts.First()))
            {
                lootEvent.LootEventType = LootEventType.Greed;
                lootEvent.Roll          = Convert.ToUInt16(RollRegex.Match(message.MessageParts.First()).Groups["Roll"].Value);
            }

            else
            {
                return(null);
            }

            return(lootEvent);
        }
Exemple #4
0
 public void LogLoot(LootEvent lootEvent)
 {
     if (lootEvent == null)
     {
         return;
     }
     _logEventQueue.Enqueue(lootEvent);
 }
Exemple #5
0
        public void SetLogFormat()
        {
            var logFormat     = LogFormat.GetLogFormatByCode(_plugin.Configuration.LogFormat);
            var fileName      = LogFormat.GetFileName(logFormat);
            var alreadyExists = _plugin.DataManager.DoesDataFileExist(fileName);

            _plugin.DataManager.InitDataFiles(new[] { fileName });
            if (!alreadyExists)
            {
                if (logFormat == LogFormat.CSV)
                {
                    _plugin.DataManager.SaveDataStr(fileName, LootEvent.GetCsvHeadings() + Environment.NewLine);
                }
                else
                {
                    _plugin.DataManager.CreateDataFile(fileName);
                }
            }
        }
        /// <inheritdoc />
        protected override LootEvent?ProcessLocalPlayerRoll(LootMessage message)
        {
            var lootEvent = new LootEvent
            {
                IsLocalPlayer = true,
            };

            // Cast Lot (Local Player)
            if (this.ProcessLocalPlayerRollCastRegex.IsMatch(message.MessageParts.First()))
            {
                lootEvent.LootEventType = LootEventType.Cast;
            }

            // Need Roll (Local Player)
            else if (this.ProcessLocalPlayerRollNeedRegex.IsMatch(message.MessageParts.First()))
            {
                lootEvent.LootEventType = LootEventType.Need;
                lootEvent.Roll          = Convert.ToUInt16(this.RollRegex.Match(message.MessageParts.Last()).Groups["Roll"].Value);
            }

            // Greed Roll (Local Player)
            else if (this.ProcessLocalPlayerRollGreedRegex.IsMatch(message.MessageParts.First()))
            {
                lootEvent.LootEventType = LootEventType.Greed;
                lootEvent.Roll          = Convert.ToUInt16(this.RollRegex.Match(message.MessageParts.Last()).Groups["Roll"].Value);
            }
            else
            {
                return(null);
            }

            lootEvent.PlayerName = this.Plugin.GetLocalPlayerName();
            lootEvent.World      = this.Plugin.GetLocalPlayerWorld();

            return(lootEvent);
        }
        /// <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 #8
0
 public bool IsEnabledEvent(LootEvent lootEvent)
 {
     return(IsEnabledType(lootEvent.LootEventType) && IsEnabledPlayer(lootEvent.PlayerName));
 }
Exemple #9
0
        public void ProcessRoll(LootEvent lootEvent)
        {
            try
            {
                if (lootEvent.ContentId == 0)
                {
                    return;
                }
                switch (lootEvent.LootEventType)
                {
                case LootEventType.Add:
                    _plugin.LootRolls.Add(new LootRoll
                    {
                        Timestamp           = lootEvent.Timestamp,
                        ItemId              = lootEvent.LootMessage.ItemId,
                        ItemName            = lootEvent.ItemName,
                        ItemNameAbbreviated = lootEvent.ItemNameAbbreviated
                    });
                    break;

                case LootEventType.Cast:
                {
                    var lootRoll = _plugin.LootRolls.FirstOrDefault(roll =>
                                                                    roll.ItemId == lootEvent.LootMessage.ItemId && !roll.IsWon &&
                                                                    !roll.Rollers.Any(roller => roller.PlayerName.Equals(lootEvent.PlayerName)));
                    if (lootRoll == null)
                    {
                        return;
                    }
                    lootRoll.Rollers.Add(new LootRoller {
                            PlayerName = lootEvent.PlayerName
                        });
                    lootRoll.RollerCount += 1;
                    lootRoll.RollersDisplay.Clear();
                    foreach (var roller in lootRoll.Rollers)
                    {
                        lootRoll.RollersDisplay.Add(new KeyValuePair <string, Vector4>(_plugin.FormatPlayerName(
                                                                                           _plugin.Configuration.RollNameFormat,
                                                                                           roller.PlayerName), UIColor.GetColorByNumber(0)));
                    }
                    lootRoll.RollersDisplay = lootRoll.RollersDisplay.OrderBy(pair => pair.Key).ToList();
                    break;
                }

                case LootEventType.Need:
                case LootEventType.Greed:
                {
                    var lootRoll = _plugin.LootRolls.FirstOrDefault(roll =>
                                                                    roll.ItemId == lootEvent.LootMessage.ItemId &&
                                                                    roll.Rollers.Any(roller =>
                                                                                     roller.PlayerName.Equals(lootEvent.PlayerName) && roller.Roll == 0));
                    var lootRoller = lootRoll?.Rollers.FirstOrDefault(roller =>
                                                                      roller.PlayerName.Equals(lootEvent.PlayerName) && roller.Roll == 0);
                    if (lootRoller == null)
                    {
                        return;
                    }
                    lootRoller.Roll = lootEvent.Roll;
                    lootRoll.RollersDisplay.Clear();
                    foreach (var roller in lootRoll.Rollers)
                    {
                        if (roller.Roll == 0)
                        {
                            lootRoll.RollersDisplay.Add(new KeyValuePair <string, Vector4>(_plugin.FormatPlayerName(
                                                                                               _plugin.Configuration.RollNameFormat,
                                                                                               roller.PlayerName) + " [x]", UIColor.GetColorByNumber(0)));
                        }
                        else
                        {
                            lootRoll.RollersDisplay.Add(new KeyValuePair <string, Vector4>(_plugin.FormatPlayerName(
                                                                                               _plugin.Configuration.RollNameFormat,
                                                                                               roller.PlayerName) + " [" + roller.Roll + "]", UIColor.GetColorByNumber(roller.Roll)));
                        }
                    }
                    lootRoll.RollersDisplay = lootRoll.RollersDisplay.OrderBy(pair => pair.Key).ToList();
                    break;
                }

                case LootEventType.Obtain:
                {
                    var lootRoll =
                        _plugin.LootRolls.FirstOrDefault(roll =>
                                                         roll.ItemId == lootEvent.LootMessage.ItemId && !roll.IsWon);
                    if (lootRoll == null)
                    {
                        return;
                    }
                    lootRoll.Timestamp = lootEvent.Timestamp;
                    var winningRoller =
                        lootRoll.Rollers.FirstOrDefault(roller => roller.PlayerName.Equals(lootEvent.PlayerName));
                    if (winningRoller != null)
                    {
                        winningRoller.IsWinner = true;
                    }
                    lootRoll.Timestamp = lootEvent.Timestamp;
                    lootRoll.IsWon     = true;
                    lootRoll.Winner    =
                        _plugin.FormatPlayerName(_plugin.Configuration.RollNameFormat, lootEvent.PlayerName);
                    break;
                }

                case LootEventType.Lost:
                {
                    var lootRoll =
                        _plugin.LootRolls.FirstOrDefault(roll =>
                                                         roll.ItemId == lootEvent.LootMessage.ItemId && !roll.IsWon);
                    if (lootRoll == null)
                    {
                        return;
                    }
                    lootRoll.Timestamp = lootEvent.Timestamp;
                    lootRoll.IsWon     = true;
                    lootRoll.Winner    = Loc.Localize("RollMonitorLost", "Dropped to floor");
                    lootRoll.RollersDisplay.Clear();
                    foreach (var roller in lootRoll.Rollers)
                    {
                        lootRoll.RollersDisplay.Add(new KeyValuePair <string, Vector4>(_plugin.FormatPlayerName(
                                                                                           _plugin.Configuration.RollNameFormat,
                                                                                           roller.PlayerName) + " [x]", UIColor.GetColorByNumber(0)));
                    }
                    lootRoll.RollersDisplay = lootRoll.RollersDisplay.OrderBy(pair => pair.Key).ToList();
                    break;
                }
                }

                CreateDisplayList();
            }
            catch (Exception ex)
            {
                _plugin.LogError(ex, "Failed to process for roll monitor.");
            }
        }