Пример #1
0
    public Color GetWeightedRandomColor(NPCSizeType type)
    {
        var colors = NPCColorData.Find(colorData => colorData.Type == type).TypeColors;

        if (colors == null)
        {
            colors = new List <NPCTypeColors>()
            {
                new NPCTypeColors {
                    Color = Color.black, Weight = 10
                }
            };
        }
        int totalWeight = colors.Sum(c => c.Weight);
        int rnd         = RandomGenerator.Next(totalWeight);

        for (int i = 0; i < colors.Count; i++)
        {
            if (rnd < colors[i].Weight)
            {
                return(colors[i].Color);
            }
            rnd -= colors[i].Weight;
        }

        throw new System.Exception("NPC color weights are incorrectly set!");
    }
Пример #2
0
 private bool HasSizeFlag(NPCSizeType sizeType)
 {
     if ((MapOrigin.NPCSizeMask & (int)sizeType) != 0)
     {
         return(true);
     }
     return(false);
 }
Пример #3
0
 int GetNPCFrequencyWeight(NPCSizeType type)
 {
     if (NPCFrequencyWeights.ContainsKey(type))
     {
         return(NPCFrequencyWeights[type]);
     }
     return(1);
 }
Пример #4
0
    private Color GetWeightedRandomColor(NPCSizeType type)
    {
        var colors      = NPCColorData.Find(colorData => colorData.Type == type).TypeColors;
        int totalWeight = colors.Sum(c => c.Weight);
        int rnd         = RandomGenerator.Next(totalWeight);

        for (int i = 0; i < colors.Count; i++)
        {
            if (rnd < colors[i].Weight)
            {
                return(colors[i].Color);
            }
            rnd -= colors[i].Weight;
        }

        throw new System.Exception("NPC color weights are incorrectly set!");
    }