Exemplo n.º 1
0
        private void DispatchPartyChangeEvent()
        {
            var combatants = FFXIVRepository.GetCombatants();

            if (combatants == null)
            {
                return;
            }

            List <PartyMember> result = new List <PartyMember>(24);

            // The partyList contents from the PartyListChangedDelegate
            // are equivalent to the set of ids enumerated by |query|
            var query = combatants.Where(c => c.PartyType != PartyTypeEnum.None);

            foreach (var c in query)
            {
                result.Add(new PartyMember()
                {
                    id      = $"{c.ID:X}",
                    name    = c.Name,
                    worldId = c.WorldID,
                    job     = c.Job,
                    inParty = c.PartyType == PartyTypeEnum.Party,
                });
            }

            DispatchAndCacheEvent(JObject.FromObject(new
            {
                type  = PartyChangedEvent,
                party = result,
            }));
        }
        private List <Dictionary <string, object> > GetCombatants(List <uint> ids, List <string> names, List <string> props)
        {
            List <Dictionary <string, object> > filteredCombatants = new List <Dictionary <string, object> >();

            var combatants = repository.GetCombatants();

            foreach (var combatant in combatants)
            {
                if (combatant.ID == 0)
                {
                    continue;
                }

                bool include = false;

                var combatantName = CachedCombatantPropertyInfos["Name"].GetValue(combatant).ToString();

                if (ids.Count == 0 && names.Count == 0)
                {
                    include = true;
                }
                else
                {
                    foreach (var id in ids)
                    {
                        if (combatant.ID == id)
                        {
                            include = true;
                            break;
                        }
                    }

                    if (!include)
                    {
                        foreach (var name in names)
                        {
                            if (String.Equals(combatantName, name, StringComparison.InvariantCultureIgnoreCase))
                            {
                                include = true;
                                break;
                            }
                        }
                    }
                }

                if (include)
                {
                    Dictionary <string, object> filteredCombatant = new Dictionary <string, object>();
                    if (props.Count > 0)
                    {
                        foreach (var prop in props)
                        {
                            if (CachedCombatantPropertyInfos.ContainsKey(prop))
                            {
                                filteredCombatant.Add(prop, CachedCombatantPropertyInfos[prop].GetValue(combatant));
                            }
                        }
                    }
                    else
                    {
                        foreach (var prop in CachedCombatantPropertyInfos.Keys)
                        {
                            filteredCombatant.Add(prop, CachedCombatantPropertyInfos[prop].GetValue(combatant));
                        }
                    }
                    filteredCombatants.Add(filteredCombatant);
                }
            }

            return(filteredCombatants);
        }