// Use this for initialization
    void Start()
    {
        ProbabilityList <char> list = new ProbabilityList <char>();

        list.Add('A', 1, false);    // Normal Probability
        list.Add('B', 2, false);    // Double normal probability
        list.Add('C', .5, false);   // Half normal probability
        list.Add('Z', .001, false); // very rare
        Test(list, Max, false);

        // Make a func that sets customized probability modifiers based on level
        LeveledPool <char> leveled = new LeveledPool <char>((playerLevel, itemLevel) =>
        {
            int diff = Math.Abs(itemLevel - playerLevel);
            // Return the probability multiplier we want for this current itemLevel
            if (diff > 10)
            {
                return(-1);
            }
            return(Math.Pow(2, -diff));
        });

        leveled.Add('A', 1, false, 5);    // level 5 entry with normal prob
        leveled.Add('B', 2, false, 4);    // level 4 entry with double prob
        leveled.Add('C', .5, false, 7);   // level 7 entry with half prob
        leveled.Add('Z', .001, false, 6); // level 6 entry rare
        leveled.Add('X', 1, false, 20);   // Should be cut out
        Test(leveled, Max, false, 5);     // Testing against level 5
    }
    public void Test <T>(LeveledPool <T> pool, int max, bool print, ushort forLevel)
    {
        pool.SetFor(forLevel);
        Test(pool, max, print);

        //Can also just ask the list for something relative to level 5
        T item;

        pool.Get(new System.Random(), out item, 5);
    }
Exemple #3
0
    public NPC SpawnNPC(GridSpace g, GenericFlags <SpawnKeywords> keywords)
    {
        LeveledPool <NPC> pool = GetPool(keywords);
        NPC n;

        if (!pool.Get(Probability.SpawnRand, out n, BigBoss.Player.Level))
        {
            throw new ArgumentException("NPC Pool was empty for keywords: " + keywords);
        }
        return(SpawnNPC(g, n));
    }
Exemple #4
0
    public override ProbabilityPool <T> Filter(Func <T, bool> filter)
    {
        LeveledPool <T> ret = new LeveledPool <T>(levelCurve);

        foreach (ProbContainer cont in prototypePool)
        {
            if (filter(cont.Item))
            {
                ret.Add(cont);
            }
        }
        return(ret);
    }
Exemple #5
0
    public override void AddAll(ProbabilityPool <T> rhs)
    {
        LeveledPool <T> lrhs = rhs as LeveledPool <T>;

        if (lrhs == null)
        {
            foreach (ProbabilityItem <T> p in rhs)
            {
                AddInternal(p.Item, p.Multiplier, p.Unique, 1);
            }
        }
        else
        {
            foreach (ProbabilityItem <T> p in rhs)
            {
                ProbContainer cont = (ProbContainer)p;
                AddInternal(cont.Item, cont.Multiplier, cont.Unique, cont.Level);
            }
        }
        Clear();
    }
Exemple #6
0
    protected LeveledPool <NPC> GetPool(GenericFlags <SpawnKeywords> keywords)
    {
        LeveledPool <NPC> pool;

        if (!npcPools.TryGetValue(keywords, out pool))
        {
            #region DEBUG
            if (BigBoss.Debug.logging(Logs.NPCs))
            {
                BigBoss.Debug.printHeader(Logs.NPCs, "Get Pool");
                BigBoss.Debug.w(Logs.NPCs, "Keywords:");
                BigBoss.Debug.incrementDepth(Logs.NPCs);
                keywords.ToLog(Logs.NPCs);
                BigBoss.Debug.decrementDepth(Logs.NPCs);
            }
            #endregion
            pool = new LeveledPool <NPC>(DefaultLevelCurve);
            npcPools.Add(keywords, pool);
            foreach (NPC n in BigBoss.Objects.NPCs.Prototypes)
            {
                if (!keywords.Empty && n.SpawnKeywords.Contains(keywords) || // NPC has keywords
                    (keywords.Empty && !n.Flags[NPCFlags.NO_RANDOM_SPAWN]))    // If keywords empty
                {
                    pool.Add(n);
                }
            }
            #region DEBUG
            if (BigBoss.Debug.logging(Logs.NPCs))
            {
                pool.ToLog(Logs.NPCs, "NPCs");
                BigBoss.Debug.printFooter(Logs.NPCs, "Get Pool");
            }
            #endregion
        }
        return(pool);
    }