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!"); }
private bool HasSizeFlag(NPCSizeType sizeType) { if ((MapOrigin.NPCSizeMask & (int)sizeType) != 0) { return(true); } return(false); }
int GetNPCFrequencyWeight(NPCSizeType type) { if (NPCFrequencyWeights.ContainsKey(type)) { return(NPCFrequencyWeights[type]); } return(1); }
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!"); }