Exemplo n.º 1
0
        public async Task <CharacterFull> GetActiveCharacter(string userID)
        {
            var resID = GetActiveCharacterID(userID);

            if (string.IsNullOrEmpty(resID))
            {
                return(null);
            }
            return((await characterCache.GetCharacter(resID)).character);
        }
        public async Task <bool> ChangeCharacterName(string userID, string charID, string charName)
        {
            var character = await characterCache.GetCharacter(charID);

            if (character != null)
            {
                if (character.character.userID == userID)
                {
                    character.CharacterName = charName;
                    eventManager.InvokeEvent(UserServiceEvents.CHARACTER_CHANGE_EVENT, charID);
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 3
0
        public bool ShouldFilter(CharacterDrop.Drop drop, DropExtended dropExtended, CharacterDrop characterDrop)
        {
            var character = CharacterCache.GetCharacter(characterDrop);

            int minLevel = dropExtended.Config.ConditionMinLevel.Value;

            if (minLevel >= 0 && character is not null)
            {
                if (character.GetLevel() < minLevel)
                {
                    Log.LogTrace($"{nameof(dropExtended.Config.ConditionMinLevel)}: Disabling drop {drop.m_prefab.name} due to level {character.GetLevel()} being below limit {minLevel}.");

                    return(true);
                }
            }

            int maxLevel = dropExtended.Config.ConditionMaxLevel.Value;

            if (maxLevel >= 0 && character is not null)
            {
                if (character.GetLevel() > maxLevel)
                {
                    Log.LogTrace($"{nameof(dropExtended.Config.ConditionMaxLevel)}: Disabling drop {drop.m_prefab.name} due to level {character.GetLevel()} being above limit {maxLevel}.");

                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 4
0
        public bool ShouldFilter(CharacterDrop.Drop drop, DropExtended dropExtended, CharacterDrop characterDrop)
        {
            if (!string.IsNullOrEmpty(dropExtended.Config.ConditionBiomes.Value))
            {
                var character = CharacterCache.GetCharacter(characterDrop);

                var biomes = dropExtended.Config.ConditionBiomes.Value.Split(new[] { ',' }, System.StringSplitOptions.RemoveEmptyEntries);

                var currentBiome        = WorldGenerator.instance.GetBiome(character.GetCenterPoint()).ToString().ToUpperInvariant();
                var currentBiomeCleaned = currentBiome.ToUpperInvariant();

                if (biomes.Length > 0)
                {
                    bool foundBiome = biomes.Any(x => x.Trim().ToUpperInvariant() == currentBiome);

                    if (!foundBiome)
                    {
                        Log.LogTrace($"{nameof(dropExtended.Config.ConditionBiomes)}: Disabling drop {drop.m_prefab.name} due to biome {currentBiome} not being in required list.");

                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 5
0
        public bool ShouldFilter(CharacterDrop.Drop drop, DropExtended extended, CharacterDrop characterDrop)
        {
            if (extended?.Config?.Subsections is null)
            {
                return(false);
            }

            var character = CharacterCache.GetCharacter(characterDrop);

            if (!character.IsBoss())
            {
                return(false);
            }

            if (extended.Config.Subsections.TryGetValue(CharacterDropModConfigCLLC.ModName, out Config config) && config is CharacterDropModConfigCLLC cllcConfig)
            {
                if (!ValidConditionBossAffix(drop, cllcConfig, character))
                {
                    return(true);
                }

                if (!ValidConditionNotBossAffix(drop, cllcConfig, character))
                {
                    return(true);
                }
            }

            return(false);
        }
        public override async Task <Empty> SaveUserData(CharacterInfo request, ServerCallContext context)
        {
            var cachedCharacter = await characterCache.GetCharacter(request.CharID);

            cachedCharacter.characterGameData = JsonConvert.DeserializeObject <JObject>(request.CharData);
            eventManager.InvokeEvent(UserServiceEvents.CHARACTER_CHANGE_EVENT, request.CharID);

            return(new Empty());
        }
Exemplo n.º 7
0
    public bool ShouldFilter(CharacterDrop.Drop drop, DropExtended extended, CharacterDrop characterDrop)
    {
        if (drop is null ||
            characterDrop.IsNull() ||
            extended?.Config is null)
        {
            return(false);
        }

        var character = CharacterCache.GetCharacter(characterDrop);

        // Ignore if no character is associated with drop.
        if (character.IsNull())
        {
            return(false);
        }

#if DEBUG && VERBOSE
        Log.LogTrace($"[{character.name}] Checking ConditionHitByEntityTypeRecently=" + extended.Config.ConditionHitByEntityTypeRecently.Value);
#endif

        var configTypes = extended.Config.ConditionHitByEntityTypeRecently.Value.SplitByComma();

        List <EntityType> entities;

        if (configTypes.Count == 0)
        {
            // Ignore if there are no entity types for condition to check.
            return(false);
        }
        else if (!configTypes.TryConvertToEnum(out entities))
        {
#if DEBUG
            Log.LogWarning($"[{character.name}] Failed to convert EntityType to enum: " + configTypes.Join());
#endif
            return(false);
        }

        var recentHits = RecordRecentHits.GetRecentHits(character);

#if DEBUG && VERBOSE
        Log.LogTrace($"[{character.name}] Checking recent hits: " + recentHits.Select(x => GetHitterType(x)).Join());
        Log.LogTrace($"[{character.name}] Searching for hits by: " + entities.Join());
#endif

        var match = recentHits.Any(x => entities.Contains(GetHitterType(x)));

        if (!match)
        {
            Log.LogTrace($"Filtered drop '{drop.m_prefab.name}' due not being hit recently by required entity type.");
        }

        return(!match);
    }
        public bool ShouldFilter(CharacterDrop.Drop drop, DropExtended extended, CharacterDrop characterDrop)
        {
            var character = CharacterCache.GetCharacter(characterDrop);

            if (!ValidConditionCreatureStates(drop, extended, character))
            {
                return(true);
            }

            if (!ValidConditionNotCreatureStates(drop, extended, character))
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 9
0
        public bool ShouldFilter(CharacterDrop.Drop drop, DropExtended extended, CharacterDrop characterDrop)
        {
            if (!characterDrop || characterDrop is null || extended?.Config is null)
            {
                return(false);
            }

            var character = CharacterCache.GetCharacter(characterDrop);

            if (IsValid(character, extended.Config))
            {
                return(false);
            }

            Log.LogTrace($"Filtered drop '{drop.m_prefab.name}' due not being killed by required entity type.");
            return(true);
        }
Exemplo n.º 10
0
        public bool ShouldFilter(CharacterDrop.Drop drop, DropExtended dropExtended, CharacterDrop characterDrop)
        {
            if (!characterDrop || characterDrop is null || dropExtended?.Config?.ConditionLocation is null)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(dropExtended.Config.ConditionLocation.Value))
            {
                return(false);
            }

            var character = CharacterCache.GetCharacter(characterDrop);

            var locations = dropExtended.Config.ConditionLocation.Value.SplitByComma(toUpper: true);

            var currentLocation = LocationHelper.FindLocation(character.GetCenterPoint());

            if (locations.Count > 0)
            {
                if (currentLocation is null)
                {
                    Log.LogTrace($"{nameof(dropExtended.Config.ConditionLocation)}: Disabling drop {drop.m_prefab.name} due to not being in required location.");
                    return(true);
                }

                var currentLocationName = currentLocation.LocationName.Trim().ToUpperInvariant();

                if (locations.Any(x => x == currentLocationName))
                {
                    return(false);
                }
                else
                {
                    Log.LogTrace($"{nameof(dropExtended.Config.ConditionLocation)}: Disabling drop {drop.m_prefab.name} due to not being in required location.");
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 11
0
        public bool ShouldFilter(CharacterDrop.Drop drop, DropExtended extended, CharacterDrop characterDrop)
        {
            if (!characterDrop || characterDrop is null || extended?.Config is null)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(extended.Config.ConditionKilledWithStatus?.Value))
            {
                return(false);
            }

            var character = CharacterCache.GetCharacter(characterDrop);

            if (IsValid(drop, extended.Config, character))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 12
0
        public bool ShouldFilter(CharacterDrop.Drop drop, DropExtended dropExtended, CharacterDrop characterDrop)
        {
            if (!characterDrop || characterDrop is null || dropExtended?.Config is null)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(dropExtended.Config.ConditionKilledByDamageType?.Value))
            {
                return(false);
            }

            var character = CharacterCache.GetCharacter(characterDrop);

            if (ValidConditionKilledByDamageType(drop, dropExtended.Config, character))
            {
                return(false);
            }

            return(true);
        }
        public bool ShouldFilter(CharacterDrop.Drop drop, DropExtended extended, CharacterDrop characterDrop)
        {
            if (!extended.Config.Subsections.TryGetValue(CharacterDropModConfigSpawnThat.ModName, out Config modConfig))
            {
                return(false);
            }

            var config = modConfig as CharacterDropModConfigSpawnThat;

            if (config is null || string.IsNullOrWhiteSpace(config.ConditionTemplateId.Value))
            {
                return(false);
            }

            var character = CharacterCache.GetCharacter(characterDrop);

            if (!character || character is null)
            {
                return(false);
            }

            var zdo = ZdoCache.GetZDO(character.gameObject);

            if (zdo is null)
            {
                return(false);
            }

            var templateId = zdo.GetString(SpawnModifierSetTemplateId.ZdoFeature, null);

            var configTemplateIds = config.ConditionTemplateId.Value.SplitByComma();

            if (!configTemplateIds.Any(x => x == templateId))
            {
                Log.LogTrace($"{nameof(config.ConditionTemplateId)}: Disabling drop {drop.m_prefab.name} due to not having required spawn template id {config.ConditionTemplateId.Value}.");
                return(true);
            }

            return(false);
        }
Exemplo n.º 14
0
        public bool ShouldFilter(CharacterDrop.Drop drop, DropExtended extended, CharacterDrop characterDrop)
        {
            if (drop is null || extended is null || !characterDrop || characterDrop is null)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(extended.Config.ConditionFaction.Value))
            {
                return(false);
            }

            var character = CharacterCache.GetCharacter(characterDrop);

            if (!character || character is null)
            {
                return(false);
            }

            var characterFaction = character.GetFaction();

            var requiredFactions = extended.Config.ConditionFaction.Value.SplitByComma();

            foreach (var requiredFaction in requiredFactions)
            {
                if (Enum.TryParse(requiredFaction, true, out Character.Faction faction))
                {
                    if (characterFaction == faction)
                    {
                        return(false);
                    }
                }
            }

            Log.LogTrace($"{nameof(extended.Config.ConditionFaction)}: Disabling drop {drop.m_prefab.name} due to {characterFaction} not being in required list.");
            return(true);
        }
        public bool ShouldFilter(CharacterDrop.Drop drop, DropExtended extended, CharacterDrop characterDrop)
        {
            var character = CharacterCache.GetCharacter(characterDrop);
            var inventory = CharacterCache.GetInventory(character);

            if (inventory is null)
            {
#if DEBUG
                Log.LogDebug("No inventory for creature were found.");
#endif

                //No inventory to compare against. Assume that all is allowed.
                return(false);
            }

            var items = extended.Config.ConditionHasItem.Value.SplitByComma(true);

            if (items.Count == 0)
            {
                return(false);
            }

            HashSet <string> inventoryItems;

            if (InstallationManager.RRRInstalled && character.name.StartsWith("RRR"))
            {
                // This is an RRR creature, item names will have been set with a specific pattern.
                inventoryItems = new();

                foreach (var item in inventory.GetAllItems())
                {
                    var firstSection = item.m_dropPrefab.name.IndexOf('@');

                    if (firstSection < 0)
                    {
                        // Unformatted item, add as is
                        inventoryItems.Add(PrepareName(item.m_dropPrefab));
                        continue;
                    }

                    var endSection = item.m_dropPrefab.name.IndexOf('@', firstSection + 1);

                    if (endSection < 0)
                    {
                        inventoryItems.Add(CleanName(item.m_dropPrefab.name.Substring(firstSection + 1)));
                    }
                    else
                    {
                        inventoryItems.Add(CleanName(item.m_dropPrefab.name.Substring(firstSection + 1, endSection - firstSection - 1)));
                    }
                }
            }
            else
            {
                inventoryItems = inventory
                                 .GetAllItems()
                                 .Select(x => x.m_dropPrefab.name.Trim().ToUpperInvariant())
                                 .ToHashSet();
            }

#if DEBUG
            Log.LogTrace("Inventory: " + inventoryItems.Join());
#endif
            if (!items.Any(x => inventoryItems.Contains(x)))
            {
                //No inventory items matched an item in condition list.
                Log.LogTrace($"{nameof(CharacterDropItemConfiguration.ConditionHasItem)}: Found none of the required items '{items.Join()}' in inventory.");

                return(true);
            }

            return(false);
        }