Ejemplo n.º 1
0
        public LootEvent ProcessLoot(LootMessage message)
        {
            try
            {
                LootEvent lootEvent;

                // process by message type
                switch (message.LootMessageType)
                {
                case LootMessageType.System:
                    lootEvent = ProcessSystem(message);
                    break;

                case LootMessageType.LocalPlayerObtainLoot:
                    lootEvent = ProcessLocalPlayerObtainLoot(message);
                    break;

                case LootMessageType.LocalPlayerRoll:
                    lootEvent = ProcessLocalPlayerRoll(message);
                    break;

                case LootMessageType.OtherPlayerObtainLoot:
                    lootEvent = ProcessOtherPlayerObtainLoot(message);
                    break;

                case LootMessageType.OtherPlayerRoll:
                    lootEvent = ProcessOtherPlayerRoll(message);
                    break;

                case LootMessageType.AddDesynthSell:
                    lootEvent = ProcessAddDesynthSell(message);
                    break;

                case LootMessageType.LocalPlayerUse:
                    lootEvent = ProcessLocalPlayerUse(message);
                    break;

                case LootMessageType.LocalPlayerSpecialObtain:
                    lootEvent = ProcessLocalPlayerSpecialObtain(message);
                    break;

                case LootMessageType.OtherPlayerUse:
                    lootEvent = ProcessOtherPlayerUse(message);
                    break;

                case LootMessageType.FastCraft:
                    lootEvent = ProcessFastCraft(message);
                    break;

                case LootMessageType.Gather:
                    lootEvent = ProcessGather(message);
                    break;

                case LootMessageType.LocalPlayerSynthesize:
                    lootEvent = ProcessLocalPlayerSynthesize(message);
                    break;

                case LootMessageType.OtherPlayerSynthesize:
                    lootEvent = ProcessOtherPlayerSynthesize(message);
                    break;

                case LootMessageType.AllianceOtherPlayerObtain:
                    lootEvent = ProcessOtherPlayerObtainLoot(message);
                    break;

                case LootMessageType.AllianceOtherPlayerRoll:
                    lootEvent = ProcessOtherPlayerRoll(message);
                    break;

                default:
                    lootEvent = null;
                    break;
                }

                // reject if unsupported type
                if (lootEvent == null)
                {
                    return(null);
                }

                // set common fields
                lootEvent.LootMessage       = message;
                lootEvent.LootEventTypeName = Enum.GetName(typeof(LootEventType), lootEvent.LootEventType);
                lootEvent.ItemName          = lootEvent.LootMessage.ItemName;
                if (string.IsNullOrEmpty(lootEvent.ItemName))
                {
                    lootEvent.ItemNameAbbreviated = lootEvent.ItemName;
                }
                else
                {
                    lootEvent.ItemNameAbbreviated = lootEvent.LootMessage.ItemName.Length <= 30
                        ? lootEvent.LootMessage.ItemName
                        : lootEvent.LootMessage.ItemName.Substring(0, 26) + "...";
                }
                lootEvent.PlayerDisplayName = Plugin.FormatPlayerName(Plugin.Configuration.LootNameFormat, lootEvent.PlayerName);
                if (lootEvent.LootMessage.IsHq)
                {
                    lootEvent.ItemNameAbbreviated += " " + Plugin.GetSeIcon(SeIconChar.HighQuality);
                }
                return(lootEvent);
            }
            catch (Exception ex)
            {
                Plugin.LogError(ex, "Failed to process item.");
                return(null);
            }
        }
Ejemplo n.º 2
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.");
            }
        }