public static TreasureMaterialColor Clone(this TreasureMaterialColor materialColor) { var result = new TreasureMaterialColor(); result.ColorCode = materialColor.ColorCode; result.Id = materialColor.Id; result.MaterialId = materialColor.MaterialId; result.PaletteTemplate = materialColor.PaletteTemplate; result.Probability = materialColor.Probability; return(result); }
public static void InitClothingColors() { for (uint i = 1; i < 19; i++) { TreasureMaterialColor tmc = new TreasureMaterialColor { PaletteTemplate = i, Probability = 1 }; clothingColors.Add(tmc); } }
/// <summary> /// Assign a random color (Int.PaletteTemplate and Float.Shade) to a World Object based on the material assigned to it. /// </summary> /// <returns>WorldObject with a random applicable PaletteTemplate and Shade applied, if available</returns> private static void MutateColor(WorldObject wo) { if (wo.MaterialType == 0 || wo.TsysMutationData == null || wo.ClothingBase == null) { return; } byte colorCode = (byte)(((uint)wo.TsysMutationData >> 16) & 0xFF); // BYTE spellCode = (tsysMutationData >> 24) & 0xFF; // BYTE colorCode = (tsysMutationData >> 16) & 0xFF; // BYTE gemCode = (tsysMutationData >> 8) & 0xFF; // BYTE materialCode = (tsysMutationData >> 0) & 0xFF; List <TreasureMaterialColor> colors; // This is a unique situation that typically applies to Under Clothes. // If the Color Code is 0, they can be PaletteTemplate 1-18, assuming there is a MaterialType // (gems have ColorCode of 0, but also no MaterialCode as they are defined by the weenie) if (colorCode == 0 && (uint)wo.MaterialType > 0) { colors = new List <TreasureMaterialColor>(); for (uint i = 1; i < 19; i++) { TreasureMaterialColor tmc = new TreasureMaterialColor { PaletteTemplate = i, Probability = 1 }; colors.Add(tmc); } } else { colors = DatabaseManager.World.GetCachedTreasureMaterialColors((int)wo.MaterialType, colorCode); } // Load the clothingBase associated with the WorldObject DatLoader.FileTypes.ClothingTable clothingBase = DatLoader.DatManager.PortalDat.ReadFromDat <DatLoader.FileTypes.ClothingTable>((uint)wo.ClothingBase); // TODO : Probably better to use an intersect() function here. I defer to someone who knows how these work better than I - Optim // Compare the colors list and the clothingBase PaletteTemplates and remove any invalid items var colorsValid = new List <TreasureMaterialColor>(); foreach (var e in colors) { if (clothingBase.ClothingSubPalEffects.ContainsKey((uint)e.PaletteTemplate)) { colorsValid.Add(e); } } colors = colorsValid; float totalProbability = GetTotalProbability(colors); // If there's zero chance to get a random color, no point in continuing. if (totalProbability == 0) { return; } var rng = ThreadSafeRandom.Next(0.0f, totalProbability); uint paletteTemplate = 0; float probability = 0.0f; // Loop through the colors until we've reach our target value foreach (var color in colors) { probability += color.Probability; if (probability > rng || probability == totalProbability) { paletteTemplate = color.PaletteTemplate; break; } } if (paletteTemplate > 0) { var cloSubPal = clothingBase.ClothingSubPalEffects[(uint)paletteTemplate]; // Make sure this entry has a valid icon, otherwise there's likely something wrong with the ClothingBase value for this WorldObject (e.g. not supposed to be a loot item) if (cloSubPal.Icon > 0) { // Assign the appropriate Icon and PaletteTemplate wo.IconId = cloSubPal.Icon; wo.PaletteTemplate = (int)paletteTemplate; // Throw some shade, at random wo.Shade = ThreadSafeRandom.Next(0.0f, 1.0f); // Some debug info... // log.Info($"Color success for {wo.MaterialType}({(int)wo.MaterialType}) - {wo.WeenieClassId} - {wo.Name}. PaletteTemplate {paletteTemplate} applied."); } } else { log.Warn($"[LOOT] Color looked failed for {wo.MaterialType} ({(int)wo.MaterialType}) - {wo.WeenieClassId} - {wo.Name}."); } }