Example #1
0
        private static void LimitDrops(CharacterDrop __instance, List <KeyValuePair <GameObject, int> > __result)
        {
            try
            {
                if (ConfigurationManager.GeneralConfig is null)
                {
                    return;
                }

                for (int i = 0; i < __result.Count; ++i)
                {
                    var item = __result[i];
                    if (ConfigurationManager.GeneralConfig.DropLimit > 0 && item.Value > ConfigurationManager.GeneralConfig.DropLimit)
                    {
                        Log.LogTrace($"Limiting {item.Key.name}:{item.Value} to {ConfigurationManager.GeneralConfig.DropLimit}");

                        __result[i] = Limit(item, ConfigurationManager.GeneralConfig.DropLimit);
                        continue;
                    }

                    var config = TempDropListCache.GetDrop(__instance, i);

                    if (config is not null && config.Config.SetAmountLimit > 0 && item.Value > config.Config.SetAmountLimit)
                    {
                        Log.LogTrace($"Limiting {item.Key.name}:{item.Value} to {config.Config.SetAmountLimit}");

                        __result[i] = Limit(item, config.Config.SetAmountLimit);
                    }
                }
            }
            catch (Exception e)
            {
                Log.LogError("Error while checking and applying drop amount limits.", e);
            }
        }
Example #2
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);
        }
Example #3
0
 public static void Postfix(CharacterDrop __instance)
 {
     if (__instance.m_dropsEnabled)
     {
         EpicLoot.OnCharacterDeath(__instance);
     }
 }
        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 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);
        }
Example #6
0
        private static void Postfix(CharacterDrop __instance, ref List <KeyValuePair <GameObject, int> > __result)
        {
            var playerList = new List <Player>();

            Player.GetPlayersInRange(__instance.m_character.transform.position, 100f, playerList);

            var richesAmount = Random.Range(10, 100);
            var richesChance = playerList.Sum(player => player.m_nview.GetZDO().GetInt("el-rch")) * 0.01f;

            if (richesChance > 1)
            {
                richesAmount = Mathf.RoundToInt(richesAmount * richesChance);
            }

            if (Random.Range(0f, 1f) < richesChance)
            {
                foreach (var richesKv in RichesTable)
                {
                    if (richesKv.Value <= richesAmount)
                    {
                        var amount = richesAmount / richesKv.Value;
                        __result.Add(new KeyValuePair <GameObject, int>(richesKv.Key, amount));
                        richesAmount -= amount * richesKv.Value;
                    }
                }
            }
        }
Example #7
0
    // Token: 0x06000260 RID: 608 RVA: 0x00013508 File Offset: 0x00011708
    private void SpawnLoot(Vector3 center)
    {
        ZDO zdo  = this.m_nview.GetZDO();
        int @int = zdo.GetInt("drops", 0);

        if (@int <= 0)
        {
            return;
        }
        List <KeyValuePair <GameObject, int> > list = new List <KeyValuePair <GameObject, int> >();

        for (int i = 0; i < @int; i++)
        {
            int        int2   = zdo.GetInt("drop_hash" + i, 0);
            int        int3   = zdo.GetInt("drop_amount" + i, 0);
            GameObject prefab = ZNetScene.instance.GetPrefab(int2);
            if (prefab == null)
            {
                ZLog.LogWarning("Ragdoll: Missing prefab:" + int2 + " when dropping loot");
            }
            else
            {
                list.Add(new KeyValuePair <GameObject, int>(prefab, int3));
            }
        }
        CharacterDrop.DropItems(list, center + Vector3.up * 0.75f, 0.5f);
    }
Example #8
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);
        }
Example #9
0
 public static void SaveLootListPrefix(Ragdoll __instance, CharacterDrop characterDrop)
 {
     if (characterDrop.m_character.GetSEMan().HaveStatusEffect("ChainExplosionListener"))
     {
         explosionList.Add(__instance.GetInstanceID(), characterDrop.m_character.GetMaxHealth() * (float)balance["AxeFire"]["effectVal"]);
     }
 }
        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);
        }
Example #11
0
        public static void OnCharacterDeath(CharacterDrop characterDrop)
        {
            var characterName = GetCharacterCleanName(characterDrop.m_character);
            var level         = characterDrop.m_character.GetLevel();
            var dropPoint     = characterDrop.m_character.GetCenterPoint() + characterDrop.transform.TransformVector(characterDrop.m_spawnOffset);

            OnCharacterDeath(characterName, level, dropPoint);
        }
        private static void Postfix(CharacterDrop __instance)
        {
            try
            {
                if (ConfigurationManager.CharacterDropConfigs == null)
                {
                    Log.LogDebug("Loading drop tables");
                    ConfigurationManager.LoadAllCharacterDropConfigurations();
                }

                string name = __instance.gameObject.name;

                CharacterDropMobConfiguration configMatch = FindConfigMatch(name);

                // Find drop list
                string dropListName = configMatch?.UseDropList?.Value;

                CharacterDropListConfiguration listConfig = null;

                if (!string.IsNullOrWhiteSpace(dropListName) &&
                    ConfigurationManager.CharacterDropLists is not null &&
                    ConfigurationManager.CharacterDropLists.TryGet(dropListName, out CharacterDropListConfiguration dropList))
                {
                    listConfig = dropList;
                }

                bool skipExisting = false;

                if (GeneralConfig.ClearAllExistingCharacterDrops ||
                    GeneralConfig.ClearAllExistingCharacterDropsWhenModified &&
                    (configMatch?.Subsections?.Any(x => x.Value.EnableConfig) == true ||
                     listConfig?.Subsections?.Any(x => x.Value.EnableConfig) == true))
                {
                    skipExisting = true;
                }

                if (skipExisting && __instance.m_drops.Count > 0)
                {
                    Log.LogTrace($"[{name}]: Clearing '{__instance.m_drops.Count}'");
                    __instance.m_drops.Clear();
                }

                // Merge list and mob config
                var configs = MobDropInitializationService.PrepareInsertion(listConfig, configMatch);

                foreach (var config in configs)
                {
                    InsertDrops(__instance, config);
                }

                __instance.m_drops = ConditionChecker.FilterOnStart(__instance);
            }
            catch (Exception e)
            {
                Log.LogError("Error while attempting to configure creature drops.", e);
            }
        }
Example #13
0
 private void Awake()
 {
     m_nview           = gameObject.GetComponent <ZNetView>();
     m_chrct           = gameObject.GetComponent <Character>();
     m_mai             = gameObject.GetComponent <MonsterAI>();
     m_cDrop           = GetComponent <CharacterDrop>();
     m_chrct.m_onDeath = (Action)Delegate.Combine(new Action(this.OnDeath), m_chrct.m_onDeath);
     m_hum             = gameObject.GetComponent <Humanoid>();
 }
Example #14
0
        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);
        }
Example #15
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);
    }
Example #16
0
    // Token: 0x060000E0 RID: 224 RVA: 0x00006C00 File Offset: 0x00004E00
    private void OnDeath()
    {
        if (!this.m_dropsEnabled)
        {
            return;
        }
        List <KeyValuePair <GameObject, int> > drops = this.GenerateDropList();
        Vector3 centerPos = this.m_character.GetCenterPoint() + base.transform.TransformVector(this.m_spawnOffset);

        CharacterDrop.DropItems(drops, centerPos, 0.5f);
    }
Example #17
0
 public static List <CharacterDrop.Drop> FilterOnDeath(CharacterDrop characterDrop)
 {
     try
     {
         return(Instance.Filter(characterDrop, Instance.OnDeathConditions));
     }
     catch (Exception e)
     {
         Log.LogError("Error while attempting to run OnDeath conditions. Skipping filtering.", e);
         return(characterDrop.m_drops);
     }
 }
 public static void Postfix(CharacterDrop __instance, ref List <KeyValuePair <GameObject, int> > __result)
 {
     for (var index = 0; index < __result.Count; index++)
     {
         var dropEntry = __result[index];
         if (dropEntry.Key.name == "Coins")
         {
             __result.RemoveAt(index);
             var newAmount = dropEntry.Value * AdventureDataManager.Config.FulingCoinDropScale;
             __result.Insert(index, new KeyValuePair <GameObject, int>(dropEntry.Key, Mathf.RoundToInt(newAmount)));
         }
     }
 }
Example #19
0
 static void SetEnemyLootLevel(ref CharacterDrop __instance)
 {
     if (__instance.m_character.m_name.StartsWith("$enemy_"))
     {
         string enemyName = __instance.m_character.m_name.Substring(7, __instance.m_character.m_name.Length - 7);
         int    level     = GetLootLevelForEnemy(enemyName);
         if (level > 0)
         {
             __instance.m_character.m_level = level;
             logger.LogInfo("Setting " + enemyName + " to level " + level + " before it generates drops");
         }
     }
 }
        public static void Postfix(Ragdoll __instance, CharacterDrop characterDrop)
        {
            if (characterDrop == null || characterDrop.m_character == null || characterDrop.m_character.IsPlayer())
            {
                return;
            }

            var characterName = EpicLoot.GetCharacterCleanName(characterDrop.m_character);
            var level         = characterDrop.m_character.GetLevel();

            __instance.m_nview.m_zdo.Set("characterName", characterName);
            __instance.m_nview.m_zdo.Set("level", level);
        }
        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);
        }
Example #22
0
        public static void OnCharacterDeath(CharacterDrop characterDrop)
        {
            var characterName = characterDrop.name.Replace("(Clone)", "");

            if (LootTables.TryGetValue(characterName, out LootTable lootTable))
            {
                Debug.Log($"CharacterDrop OnDeath: {characterName}");
                List <GameObject> loot = GetLoot(lootTable, characterName);
                DropItems(loot, characterDrop.m_character.GetCenterPoint() + characterDrop.transform.TransformVector(characterDrop.m_spawnOffset), 0.5f);
            }
            else
            {
                Debug.Log($"CharacterDrop OnDeath (no loot table): {characterName}");
            }
        }
Example #23
0
        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);
        }
        private static void StoreConfigReferences(ZDO zdo, CharacterDrop drop, List <KeyValuePair <GameObject, int> > drops)
        {
            try
            {
#if DEBUG
                Log.LogDebug($"Packing config references for zdo {zdo.m_uid}");
#endif

                var cache = TempDropListCache.GetDrops(drops);
                cache ??= TempDropListCache.GetDrops(drop); // If we somehow failed to keep a consistent list reference (probably mod conflict). Attempt with the original CharacterDrop instead.

                if (cache is null)
                {
#if DEBUG
                    Log.LogDebug($"Found no drops for zdo {zdo.m_uid}");
#endif
                    return;
                }

                List <DropConfig> package = cache.ConfigByIndex
                                            .Select(x =>
                                                    new DropConfig
                {
                    Index     = x.Key,
                    ConfigKey = x.Value.Config.SectionKey,
                    IsList    = x.Value.Config.IsFromNamedList,
                })
                                            .ToList();

                using (MemoryStream memStream = new MemoryStream())
                {
                    BinaryFormatter binaryFormatter = new BinaryFormatter();
                    binaryFormatter.Serialize(memStream, package);

                    byte[] serialized = memStream.ToArray();

#if DEBUG
                    Log.LogDebug($"Serialized and set drops for zdo {zdo.m_uid}");
#endif

                    zdo.Set(ZDOKey, serialized);
                }
            }
            catch (Exception e)
            {
                Log.LogError("Error while attempting to store configurations for items to be dropped on ragdoll 'puff'.", e);
            }
        }
        private static void Insert(CharacterDrop __instance, CharacterDropItemConfiguration config, CharacterDrop.Drop drop)
        {
            int index = config.Index;

            if (index >= 0 && __instance.m_drops.Count >= index && !ConfigurationManager.GeneralConfig.AlwaysAppendCharacterDrops.Value)
            {
                Log.LogDebug($"[{__instance.gameObject.name}]: Inserting drop {config.PrefabName.Value} at index '{index}'.");

                __instance.m_drops.Insert(index, drop);
            }
            else
            {
                Log.LogDebug($"[{__instance.gameObject.name}]: Adding item {config.PrefabName.Value}.");
                __instance.m_drops.Add(drop);
            }
        }
        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);
        }
Example #27
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);
        }
Example #28
0
    // Token: 0x0600025F RID: 607 RVA: 0x0001346C File Offset: 0x0001166C
    private void SaveLootList(CharacterDrop characterDrop)
    {
        List <KeyValuePair <GameObject, int> > list = characterDrop.GenerateDropList();

        if (list.Count > 0)
        {
            ZDO zdo = this.m_nview.GetZDO();
            zdo.Set("drops", list.Count);
            for (int i = 0; i < list.Count; i++)
            {
                KeyValuePair <GameObject, int> keyValuePair = list[i];
                int prefabHash = ZNetScene.instance.GetPrefabHash(keyValuePair.Key);
                zdo.Set("drop_hash" + i, prefabHash);
                zdo.Set("drop_amount" + i, keyValuePair.Value);
            }
        }
    }
Example #29
0
 // Token: 0x0600025E RID: 606 RVA: 0x00013380 File Offset: 0x00011580
 public void Setup(Vector3 velocity, float hue, float saturation, float value, CharacterDrop characterDrop)
 {
     velocity.x *= this.m_velMultiplier;
     velocity.z *= this.m_velMultiplier;
     this.m_nview.GetZDO().Set("InitVel", velocity);
     this.m_nview.GetZDO().Set("Hue", hue);
     this.m_nview.GetZDO().Set("Saturation", saturation);
     this.m_nview.GetZDO().Set("Value", value);
     if (this.m_mainModel)
     {
         this.m_mainModel.material.SetFloat("_Hue", hue);
         this.m_mainModel.material.SetFloat("_Saturation", saturation);
         this.m_mainModel.material.SetFloat("_Value", value);
     }
     if (characterDrop)
     {
         this.SaveLootList(characterDrop);
     }
 }
        private static void MoveConfigReferenceFromComponentToDrop(CharacterDrop __instance, List <KeyValuePair <GameObject, int> > __result)
        {
            try
            {
                var instanceReferences = TempDropListCache.GetDrops(__instance);

                if (instanceReferences is not null)
                {
                    //Re-associate result with configs.
                    foreach (var reference in instanceReferences.ConfigByIndex)
                    {
                        TempDropListCache.SetDrop(__result, reference.Key, reference.Value);
                    }
                }
            }
            catch (Exception e)
            {
                Log.LogWarning("Error while attempting to keep track of drops.", e);
            }
        }