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 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); }
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); }
public void ApplyModifications(GameObject item, DropExtended extended, Vector3 pos) { if (item is null || extended is null) { return; } #if DEBUG Log.LogDebug($"Applying modifiers to item {item.name}"); #endif var context = new DropContext { Item = item, Extended = extended, Pos = pos }; foreach (var modifier in DropModifiers) { try { modifier?.Modify(context); } catch (Exception e) { Log.LogError($"Error while attempting to modify item drop {item.name}", e); } } }
public bool ShouldFilter(CharacterDrop.Drop drop, DropExtended dropExtended, CharacterDrop characterDrop) { var envMan = EnvMan.instance; if (dropExtended.Config.ConditionNotDay.Value && envMan.IsDay()) { Log.LogTrace($"{nameof(dropExtended.Config.ConditionNotDay)}: Disabling drop {drop.m_prefab.name} due to time of day."); return(true); } if (dropExtended.Config.ConditionNotAfternoon.Value && envMan.IsAfternoon()) { Log.LogTrace($"{nameof(dropExtended.Config.ConditionNotAfternoon)}: Disabling drop {drop.m_prefab.name} due to time of day."); return(true); } if (dropExtended.Config.ConditionNotNight.Value && envMan.IsNight()) { Log.LogTrace($"{nameof(dropExtended.Config.ConditionNotNight)}: Disabling drop {drop.m_prefab.name} due to time of day."); return(true); } return(false); }
public bool ShouldFilter(CharacterDrop.Drop drop, DropExtended dropExtended, CharacterDrop characterDrop) { if (!string.IsNullOrEmpty(dropExtended.Config.ConditionGlobalKeys.Value)) { var requiredKeys = dropExtended.Config.ConditionGlobalKeys.Value.SplitByComma(); if (requiredKeys.Count > 0) { bool foundRequiredKey = false; foreach (var key in requiredKeys) { foundRequiredKey = ZoneSystem.instance.GetGlobalKey(key); if (foundRequiredKey) { break; } } if (!foundRequiredKey) { Log.LogTrace($"{nameof(dropExtended.Config.ConditionGlobalKeys)}: Disabling drop {drop.m_prefab.name} due to not finding any of the requires global keys '{dropExtended.Config.ConditionGlobalKeys.Value}'."); return(true); } } } return(false); }
public static bool ValidConditionNotCreatureStates(CharacterDrop.Drop drop, DropExtended extended, Character character) { if (extended.Config.ConditionNotCreatureStates.Value.Length > 0) { var states = extended.Config.ConditionNotCreatureStates.Value.SplitByComma(); if (states.Count == 0) { #if DEBUG Log.LogDebug("No conditions for not having a creature state were found."); #endif //Skip if we have no states to check. This indicates all are allowed. return(true); } if (states.Any(x => HasState(character, x))) { Log.LogTrace($"{nameof(extended.Config.ConditionNotCreatureStates)}: Disabling drop {drop.m_prefab.name} due to forbidden creature state."); return(false); } } return(true); }
public static void SetDrop(object key, int index, DropExtended extended) { #if DEBUG Log.LogDebug($"Setting temp drop cache {index}:{key.GetHashCode()}"); #endif var cache = DropListTable.GetOrCreateValue(key); cache.ConfigByIndex[index] = extended; }
public bool ShouldFilter(CharacterDrop.Drop drop, DropExtended extended, CharacterDrop characterDrop) { if (IsValid(extended?.Config)) { return(false); } Log.LogTrace($"Filtered drop '{drop}' due to not being within required CLLC world level."); return(true); }
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); }
private static void InsertDrops(CharacterDrop instance, CharacterDropItemConfiguration dropConfig) { //Sanity checks if (!dropConfig.IsValid()) { #if DEBUG Log.LogDebug($"Drop config {dropConfig.SectionKey} is not valid or enabled."); #endif return; } GameObject item = ObjectDB.instance.GetItemPrefab(dropConfig.PrefabName?.Value); if (item.IsNull()) { item = ZNetScene.instance.GetPrefab(dropConfig.PrefabName.Value); } if (item.IsNull()) { Log.LogWarning($"[{dropConfig.SectionKey}]: No item '{dropConfig.PrefabName}' exists"); return; } CharacterDrop.Drop newDrop = new CharacterDrop.Drop { m_prefab = item, m_amountMax = dropConfig.SetAmountMax.Value, m_amountMin = dropConfig.SetAmountMin.Value, m_chance = dropConfig.SetChanceToDrop.Value / 100, m_levelMultiplier = dropConfig.SetScaleByLevel.Value, m_onePerPlayer = dropConfig.SetDropOnePerPlayer.Value, }; DropExtended.Set(newDrop, dropConfig); if (!GeneralConfig.AlwaysAppendCharacterDrops.Value) { int index = dropConfig.Index; if (instance.m_drops.Count > index) { Log.LogDebug($"[{dropConfig.SectionKey}]: Removing overriden item '{instance.m_drops[index].m_prefab.name}' at index '{index}'."); instance.m_drops.RemoveAt(index); } } Insert(instance, dropConfig, newDrop); }
public bool ShouldFilter(CharacterDrop.Drop drop, DropExtended extended, CharacterDrop characterDrop) { if (!characterDrop || characterDrop is null || extended?.Config is null) { return(false); } if (IsValid(characterDrop.transform.position, extended.Config)) { return(false); } Log.LogTrace($"Filtered drop '{drop.m_prefab.name}' due not being within required distance to center of map."); return(true); }
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); }
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); }
private static void CarryExtended(List <KeyValuePair <GameObject, int> > dropItems, CharacterDrop.Drop drop, CharacterDrop characterDrop) { try { if (dropItems is null) { #if DEBUG Log.LogWarning("Unable to carry drop due to dropitems being null."); #endif } if (drop is null) { #if DEBUG Log.LogWarning($"Unable to carry drop due to being null for {characterDrop}."); #endif return; } var extended = DropExtended.GetExtension(drop); if (extended is not null && dropItems is not null) { #if DEBUG Log.LogDebug($"Carrying configs for drop {extended.Config.SectionKey}:{characterDrop.GetHashCode()}"); Log.LogDebug($"Carrying configs for drop {drop.m_prefab.name}"); #endif TempDropListCache.SetDrop(characterDrop, dropItems.Count - 1, extended); } #if DEBUG else if (dropItems is null) { Log.LogDebug("Disregard. No items to carry"); //Log.LogDebug($"Carrying configs for drop {drop.m_prefab.name}"); } else if (extended is null) { Log.LogDebug($"Disregard. No config to carry for item {drop}:{(drop.m_prefab.IsNull() ? "" : drop.m_prefab.name)}"); } #endif }
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); }
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); }
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); }
public List <CharacterDrop.Drop> Filter(CharacterDrop characterDrop, IEnumerable <ICondition> conditions) { List <CharacterDrop.Drop> validDrops = new List <CharacterDrop.Drop>(); foreach (var drop in characterDrop.m_drops) { var dropExtended = DropExtended.GetExtension(drop); if (dropExtended is null) { validDrops.Add(drop); continue; } if (!conditions.Any(x => x?.ShouldFilter(drop, dropExtended, characterDrop) ?? false)) { validDrops.Add(drop); } } return(validDrops); }
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 dropExtended, CharacterDrop characterDrop) { if (!string.IsNullOrEmpty(dropExtended.Config.ConditionEnvironments.Value)) { var envMan = EnvMan.instance; var currentEnv = envMan.GetCurrentEnvironment(); var environments = dropExtended.Config.ConditionEnvironments.Value.SplitByComma(true); if (environments.Count > 0) { var requiredSet = new HashSet <string>(environments); if (!requiredSet.Contains(currentEnv.m_name.Trim().ToUpperInvariant())) { Log.LogTrace($"{nameof(dropExtended.Config.ConditionEnvironments)}: Disabling drop {drop.m_prefab.name} due to environment {currentEnv.m_name} not being in required list."); return(true); } } } return(false); }
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); }