Log() public static method

public static Log ( float f ) : float
f float
return float
コード例 #1
0
/**
 * Tweet cart is the whole script, fit in one tweet, i.e. code length must be <= 280 characters
 *
 * Tigra tweet cart shortcuts:
 *
 * Functions:
 * TIC() is called 60 times per second.
 *
 * Variables:
 * t:  elapsed time in seconds
 * f:  frame counter
 *
 * Aliases:
 * B:  bool
 * F:  float
 * I:  int
 * M:  UnityEngine.Mathf
 * R:  UnityEngine.Random
 * S:  System.String
 * V2: UnityEngine.Vector2
 * V3: UnityEngine.Vector3
 * Z:  Tic80
 *
 * Delegates:
 * CD: circ & circb delegate
 * RD: rect & rectb delegate
 * TD: tri & trib delegate
 *
 * Beautify/minify C# online tool:
 * https://codebeautify.org/csharpviewer
 */
class Tc6 : Z { F v = 0, hz = 1, step, d = 1.05f; void TIC()
                {
                    cls(); if (btn(0))
                    {
                        hz *= d;
                    }
                    if (btn(1))
                    {
                        hz /= d;
                    }
                    v %= 240 / hz; v += 4; if (hz < 1)
                    {
                        step = 1;
                    }
                    else if (hz > 50)
                    {
                        step = .02f;
                    }
                    else
                    {
                        step = 1 / hz;
                    } for (F x = -v; x < 240; x += step)
                    {
                        F y = 68 + 40 * M.Cos(x * M.PI / 120 * hz); pix(x + v, y, 3);
                    }
                    print(M.Log(hz) / M.Log(d), 1, 127); line(0, 67, 240, 67, 3);
                }
コード例 #2
0
        private ItemEffect GenerateEffect(Item item)
        {
            Random rnd          = new Random();
            float  itemPriceMax = 2 * PriceMax - item.Class.Price;
            float  manaMax      = item.Class.Material.MagicVolume * item.Class.Class.MagicVolume - item.ManaUsage;
            // note: this will not work correctly if SlotsWarrior or SlotsMage values for a slot are not sorted by ascending order.
            //       parameters that appear first will "override" parameters with the same weight appearing later.
            int lastValue;

            Templates.TplModifier lastModifier = TemplateLoader.Templates.Modifiers[TemplateLoader.Templates.Modifiers.Count - 1];
            if ((item.Class.Option.SuitableFor & 1) != 0)
            {
                lastValue = lastModifier.SlotsFighter[item.Class.Option.Slot - 1];
            }
            else
            {
                lastValue = lastModifier.SlotsMage[item.Class.Option.Slot - 1];
            }
            int randomValue = rnd.Next(0, lastValue) + 1;

            Templates.TplModifier matchingModifier = null;
            if (item.Class.Option.SuitableFor == 2 && item.Class.Option.Slot == 1)
            {
                matchingModifier = TemplateLoader.Templates.Modifiers[(int)ItemEffect.Effects.CastSpell];
            }
            else
            {
                for (int i = 1; i < TemplateLoader.Templates.Modifiers.Count; i++)
                {
                    Templates.TplModifier prevModifier = TemplateLoader.Templates.Modifiers[i - 1];
                    Templates.TplModifier modifier     = TemplateLoader.Templates.Modifiers[i];
                    int prevValue;
                    int value;
                    if ((item.Class.Option.SuitableFor & 1) != 0)
                    {
                        prevValue = prevModifier.SlotsFighter[item.Class.Option.Slot - 1];
                        value     = modifier.SlotsFighter[item.Class.Option.Slot - 1];
                    }
                    else
                    {
                        prevValue = prevModifier.SlotsMage[item.Class.Option.Slot - 1];
                        value     = modifier.SlotsMage[item.Class.Option.Slot - 1];
                    }
                    if (prevValue < randomValue && randomValue <= value)
                    {
                        matchingModifier = modifier;
                        break;
                    }
                }
            }
            if (matchingModifier == null)
            {
                // parameter not found. weird, but happens.
                return(null);
            }
            if ((matchingModifier.UsableBy & item.Class.Option.SuitableFor) == 0)
            {
                // parameter for class not found in the item.
                return(null);
            }
            // parameter found. calculate max possible power
            ItemEffect effect = new ItemEffect();

            effect.Type1 = (ItemEffect.Effects)matchingModifier.Index;
            float maxPower;
            float absoluteMax = manaMax / matchingModifier.ManaCost;

            if (matchingModifier.Index == (int)ItemEffect.Effects.CastSpell)
            {
                // select spell to cast.
                // if for fighter, choose between fighter-specific spells.
                // if for mage, choose between mage-specific spells.
                Spell.Spells[] spells;
                if ((item.Class.Option.SuitableFor & 1) != 0)
                {
                    spells = new Spell.Spells[] { Spell.Spells.Stone_Curse, Spell.Spells.Drain_Life }
                }
                ;
                else
                {
                    spells = new Spell.Spells[] { Spell.Spells.Fire_Arrow, Spell.Spells.Lightning, Spell.Spells.Prismatic_Spray, Spell.Spells.Stone_Curse, Spell.Spells.Drain_Life, Spell.Spells.Ice_Missile, Spell.Spells.Diamond_Dust }
                };
                // choose random spell
                Spell.Spells spell = spells[rnd.Next(0, spells.Length)];
                effect.Value1 = (int)spell;
                // calculate max power
                Templates.TplSpell spellTemplate = TemplateLoader.Templates.Spells[effect.Value1];
                maxPower = Mathf.Log(itemPriceMax / (spellTemplate.ScrollCost * 10f)) / Mathf.Log(2);
                if (!float.IsNaN(maxPower) && maxPower > 0)
                {
                    maxPower = (Mathf.Pow(1.2f, maxPower) - 1) * 30;
                }
                else
                {
                    return(null);
                }
                maxPower = Mathf.Min(maxPower, absoluteMax);
                maxPower = Mathf.Min(maxPower, 100);
            }
            else
            {
                maxPower = Mathf.Log(itemPriceMax / (manaMax * 50) - 1) / Mathf.Log(1.5f) * 70f / matchingModifier.ManaCost;
                if (float.IsNaN(maxPower))
                {
                    return(null);
                }
                maxPower = Mathf.Min(maxPower, absoluteMax);
                maxPower = Mathf.Min(maxPower, matchingModifier.AffectMax);
                if (maxPower < matchingModifier.AffectMin)
                {
                    return(null);
                }
            }

            if (maxPower <= 1)
            {
                // either some limit hit, or something else
                return(null);
            }

            // max parameter power found. randomize values
            switch (effect.Type1)
            {
            case ItemEffect.Effects.CastSpell:
                effect.Value2 = rnd.Next(1, (int)maxPower + 1);
                break;

            case ItemEffect.Effects.DamageFire:
            case ItemEffect.Effects.DamageWater:
            case ItemEffect.Effects.DamageAir:
            case ItemEffect.Effects.DamageEarth:
            case ItemEffect.Effects.DamageAstral:
                effect.Value1 = rnd.Next(1, (int)maxPower + 1);
                effect.Value2 = rnd.Next(1, (int)(maxPower / 2) + 1);
                break;

            default:
                effect.Value1 = (int)Mathf.Max(matchingModifier.AffectMin, rnd.Next(1, (int)maxPower + 1));
                break;
            }

            return(effect);
        }