Пример #1
0
        private static IDictionary <int, byte> CachedMatches = new Dictionary <int, byte>();        // Static; shouldn't expect to change



        ////////////////

        /// <summary>
        /// Gets a paint type of the color with the nearest approximation of the given color.
        /// </summary>
        /// <param name="color"></param>
        /// <returns>Internal paint id (not item id).</returns>
        public static byte GetNearestPaintType(Color color)
        {
            int colorCode = (((int)color.R >> 3) << 3) +
                            (((int)color.G >> 3) << 11) +
                            (((int)color.B >> 3) << 19);

            if (PaintLibraries.CachedMatches.ContainsKey(colorCode))
            {
                return(PaintLibraries.CachedMatches[colorCode]);
            }

            float minVal = 9999;
            int   minIdx = 0;

            for (int i = 1; i <= 30; i++)
            {
                Color compare = WorldGen.paintColor(i);
                Color dist    = XNAColorLibraries.DistanceRGB(color, compare);
                float distAmt = Math.Abs(XNAColorLibraries.SumRGB(dist));

                if (minVal > distAmt)
                {
                    minVal = distAmt;
                    minIdx = i;
                }
            }

            PaintLibraries.CachedMatches[colorCode] = (byte)minIdx;

            return((byte)minIdx);
        }
Пример #2
0
        internal static void ApplyVisualFx(NPC npc, ref Color drawColor, float lastKnownDrawScale)
        {
            int npcWho = npc.whoAmI;

            float getMagnitude()
            {
                NPC mynpc = Main.npc[npcWho];

                if (mynpc.active != true || !mynpc.boss)
                {
                    CameraShaker.Current = null;
                    return(0f);
                }

                float dist             = (npc.Center - Main.LocalPlayer.Center).Length();
                float magnitudePercent = 1f - (dist / 768f);

                return(8f * magnitudePercent);
            }

            //

            // Add red tint
            var newColor = new Color(255, 128, 128);

            drawColor = XNAColorLibraries.Mul(drawColor, newColor);

            // Add NPC vibration
            npc.scale = ((Main.rand.NextFloat() * 0.2f) - 0.1f) + lastKnownDrawScale;

            //magnitude *= Main.LocalPlayer.Center.Y == 0f
            //	? magnitude
            //	: magnitude * 4f;
            CameraShaker.Current = new CameraShaker(
                name: "EnragedShake",
                peakMagnitude: getMagnitude(),
                toDuration: 0,
                lingerDuration: 30,
                froDuration: 0,
                isSmoothed: false,
                onRun: () => {
                CameraShaker.Current.SetPeakMagnitude(getMagnitude());
            }
                );
        }
Пример #3
0
        /// <summary>
        /// Generates an English-formatted string indicating an amount of money.
        /// </summary>
        /// <param name="money"></param>
        /// <param name="addDenom"></param>
        /// <param name="addColors"></param>
        /// <param name="tint"></param>
        /// <returns></returns>
        public static string[] RenderMoneyDenominations(long money, bool addDenom, bool addColors, Color tint)
        {
            var denoms   = ItemMoneyLibraries.GetMoneyDenominations(money);
            var rendered = new List <string>(4);

            if (denoms.platinum != 0)
            {
                string render = denoms.platinum.ToString();
                if (addDenom)
                {
                    render += " " + Language.GetTextValue("Currency.Platinum");                          //Lang.inter[15];
                }
                if (addColors)
                {
                    Color  color    = XNAColorLibraries.Mul(ItemMoneyLibraries.PlatinumCoinColor, tint);
                    string colorHex = MiscLibraries.RenderColorHex(color);
                    render = "[c/" + colorHex + ":" + render + "]";
                }
                rendered.Add(render);
            }
            if (denoms.gold != 0)
            {
                string render = denoms.gold.ToString();
                if (addDenom)
                {
                    render += " " + Language.GetTextValue("Currency.Gold");                          //Lang.inter[16];
                }
                if (addColors)
                {
                    Color  color    = XNAColorLibraries.Mul(ItemMoneyLibraries.GoldCoinColor, tint);
                    string colorHex = MiscLibraries.RenderColorHex(color);
                    render = "[c/" + colorHex + ":" + render + "]";
                }
                rendered.Add(render);
            }
            if (denoms.silver != 0)
            {
                string render = denoms.silver.ToString();
                if (addDenom)
                {
                    render += " " + Language.GetTextValue("Currency.Silver");                          //Lang.inter[17];
                }
                if (addColors)
                {
                    Color  color    = XNAColorLibraries.Mul(ItemMoneyLibraries.SilverCoinColor, tint);
                    string colorHex = MiscLibraries.RenderColorHex(color);
                    render = "[c/" + colorHex + ":" + render + "]";
                }
                rendered.Add(render);
            }
            if (denoms.copper != 0)
            {
                string render = denoms.copper.ToString();
                if (addDenom)
                {
                    render += " " + Language.GetTextValue("Currency.Copper");                          //Lang.inter[18];
                }
                if (addColors)
                {
                    Color  color    = XNAColorLibraries.Mul(ItemMoneyLibraries.CopperCoinColor, tint);
                    string colorHex = MiscLibraries.RenderColorHex(color);
                    render = "[c/" + colorHex + ":" + render + "]";
                }
                rendered.Add(render);
            }

            return(rendered.ToArray());
        }