Beispiel #1
0
 public void ShouldCastToDate()
 {
     var castable = new Castable();
     var expected = new DateTime(2000, 1, 1, 1, 1, 1);
     var result = castable.To<DateTime>("2000/1/1 01:01:01");
     Assert.Equal(expected, result);
 }
Beispiel #2
0
 public void ShouldCastToDecimal()
 {
     var castable = new Castable();
     decimal expected = 2.3m;
     decimal result = castable.To<decimal>("2.3");
     Assert.Equal(expected, result);
 }
Beispiel #3
0
 public void ShouldCastToDouble()
 {
     var castable = new Castable();
     double expected = 2.3;
     double result = castable.To<double>("2.3");
     Assert.Equal(expected, result);
 }
Beispiel #4
0
        public static string[] OnWillSaveAssets(string[] paths)
        {
            int uniqueId = 0;

            string[] prefabs = AssetDatabase.FindAssets("t:Prefab");
            foreach (string prefab in prefabs)
            {
                string path = AssetDatabase.GUIDToAssetPath(prefab);
                UnityEngine.Object[] objects = AssetDatabase.LoadAllAssetsAtPath(path);
                foreach (UnityEngine.Object obj in objects)
                {
                    GameObject gameObject = obj as GameObject;
                    if (gameObject != null)
                    {
                        Castable castable = gameObject.GetComponent <Castable>();
                        if (castable != null)
                        {
                            castable.SetUnique(uniqueId);
                        }
                        Weapon weapon = gameObject.GetComponent <Weapon>();
                        if (weapon != null)
                        {
                            weapon.SetUnique(uniqueId);
                        }
                    }
                }
                uniqueId++;
            }
            return(paths);
        }
Beispiel #5
0
        public void LoadInst(Castable values)
        {
            if (values["is_hidden"])
            {
                this.WindowState = FormWindowState.Minimized;
            }
            else
            {
                this.WindowState = FormWindowState.Normal;
            }
            this.Width  = values["width"];
            this.Height = values["height"];
            this.Left   = values["pos_x"];
            this.Top    = values["pos_y"];

            if (values["login"])
            {
                MainApi.MainWin.Login(new AuthInstance()
                {
                    IsNormal      = values["is_normal"],
                    EmailOrAccKey = values["email_or_key"],
                    PassOrId      = values["pass_or_id"]
                });
            }
        }
Beispiel #6
0
 public void ShouldCastToInt()
 {
     var castable = new Castable();
     int expected = 2;
     int result = castable.To<int>("2");
     Assert.Equal(expected, result);
 }
Beispiel #7
0
 public CreatureStatus(Status xmlstatus, Creature target, Castable castable = null,
                       int durationOverride = -1, int tickOverride = -1)
 {
     _init(xmlstatus, target, castable);
     Start             = DateTime.Now;
     _durationOverride = durationOverride;
     _tickOverride     = tickOverride;
 }
Beispiel #8
0
        public static void Serialize(XmlWriter xWrite, Castable contents)
        {
            XmlSerializer           Writer = new XmlSerializer(contents.GetType());
            XmlSerializerNamespaces ns     = new XmlSerializerNamespaces();

            ns.Add("", "http://www.hybrasyl.com/XML/Actions");
            Writer.Serialize(xWrite, contents, ns);
        }
Beispiel #9
0
        public void ShouldCastToDouble()
        {
            var    castable = new Castable();
            double expected = 2.3;
            double result   = castable.To <double>("2.3");

            Assert.Equal(expected, result);
        }
Beispiel #10
0
        public void ShouldCastToInt()
        {
            var castable = new Castable();
            int expected = 2;
            int result   = castable.To <int>("2");

            Assert.Equal(expected, result);
        }
Beispiel #11
0
        public void ShouldCastToDecimal()
        {
            var     castable = new Castable();
            decimal expected = 2.3m;
            decimal result   = castable.To <decimal>("2.3");

            Assert.Equal(expected, result);
        }
Beispiel #12
0
        public void ShouldCastToDate()
        {
            var castable = new Castable();
            var expected = new DateTime(2000, 1, 1, 1, 1, 1);
            var result   = castable.To <DateTime>("2000/1/1 01:01:01");

            Assert.Equal(expected, result);
        }
Beispiel #13
0
        public Castable ExecuteScalar(string storeProcedure, ConexionParameters parameters)
        {
            Castable result;

            try
            {
                ConexionOpen();

                using (var cmd = this._conexion.CreateCommand())
                {
                    cmd.CommandText    = storeProcedure;
                    cmd.Transaction    = _transaction;
                    cmd.CommandTimeout = ConexionTimeOut;

                    if (parameters != null)
                    {
                        cmd.CommandType = CommandType.StoredProcedure;

                        foreach (var p in parameters.Parameters)
                        {
                            var pt = cmd.CreateParameter();
                            pt.ParameterName = p.Name;
                            pt.DbType        = p.Type;
                            pt.Value         = p.Value;
                            pt.Size          = p.Size;
                            pt.Direction     = p.Direction;

                            cmd.Parameters.Add(pt);
                        }
                    }

                    var scalar = cmd.ExecuteScalar();
                    result = new Castable(scalar);

                    if (parameters != null)
                    {
                        foreach (IDbDataParameter p in cmd.Parameters)
                        {
                            var param = parameters.Parameters.FirstOrDefault(x => x.Name == p.ParameterName);
                            if (param != null)
                            {
                                param.Value = p.Value;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ThrowExceptionExecuteMessage + ex.Message, ex);
            }
            finally
            {
                ConexionClose();
            }

            return(result);
        }
Beispiel #14
0
    public void Deactivate()
    {
        collider2D.enabled = false;
        state = State.Following;

        if (currentSustainedCast)
        {
            currentSustainedCast.EndCast();
            currentSustainedCast = null;
        }
    }
Beispiel #15
0
        public static T To <T>(this object input)
        {
            if (typeof(T) == typeof(object))
            {
                return((T)input);
            }

            var castable = new Castable();

            return(castable.To <T>(input));
        }
Beispiel #16
0
 private static double _evalFormula(string formula, Castable castable, Creature target, Creature source)
 {
     try
     {
         return(new FormulaParser(source, castable, target).Eval(formula));
     }
     catch (Exception e)
     {
         Logger.Error($"NumberCruncher formula error: castable {castable.Name}, target {target.Name}, source {source?.Name ?? "no source"}: {formula}, error: {e}");
         return(0);
     }
 }
Beispiel #17
0
        public void ImplicitOperatorForPlus()
        {
            dynamic d      = new Castable();
            dynamic result = d + 1;

            Assert.Equal(3, result);
            result = 5 + d;
            Assert.Equal(7, result);
            result = d + "def";
            Assert.Equal("abcdef", result);
            result = "xyz" + d;
            Assert.Equal("xyzabc", result);
        }
Beispiel #18
0
        public CreatureStatus(Status xmlstatus, Creature target, Castable castable = null)
        {
            _init(xmlstatus, target, castable);
            Start = DateTime.Now;

            var addList = castable?.Statuses.Add.Where(e => e.Value == xmlstatus.Name);

            if (addList?.Count() > 0)
            {
                var addObj = addList.First();
                _durationOverride = addObj.Duration * xmlstatus.Duration;
                _tickOverride     = (int)Math.Floor(addObj.Speed * xmlstatus.Tick);
            }
        }
Beispiel #19
0
        public static Castable Deserialize(XmlReader reader, Castable contents = null)
        {
            if (contents == null)
            {
                contents = new Castable();
            }
            //reader.Settings.IgnoreWhitespace = false;
            XmlSerializer XmlSerial = new XmlSerializer(contents.GetType());

            if (XmlSerial.CanDeserialize(reader))
            {
                var xContents = XmlSerial.Deserialize(reader);
                contents = (Castable)xContents;
            }
            return(contents);
        }
Beispiel #20
0
    IEnumerator Attack()
    {
        currentlyShooting = true;
        // Attack animation and sound
        //animator.SetTrigger("attack");
        AudioSource.PlayClipAtPoint(attackSoundEffect, new Vector3(0, 0, 0));

        if (weaponPrefab.GetCastTime() > 0)
        {
            yield return(new WaitForSeconds(weaponPrefab.GetCastTime()));
        }

        int weaponDirection = spriteRenderer.flipX ? -1 : 1;

        if (isBackwards)
        {
            weaponDirection *= -1;
        }
        Vector3 weaponWorldPosition = weaponSpawnPoint.position;

        Vector3 weaponLocalPosition = transform.InverseTransformPoint(weaponWorldPosition);//new Vector3(transform.position.x + weaponDirection * 0.5f, transform.position.y + 0.5f, transform.position.z);

        if (spriteRenderer.flipX)
        {
            weaponLocalPosition.x *= -1;
        }
        if (isBackwards)
        {
            weaponLocalPosition.x *= -1;
        }

        weaponWorldPosition = transform.TransformPoint(weaponLocalPosition);
        Castable weapon = Instantiate(weaponPrefab, weaponWorldPosition, Quaternion.identity);

        //weapon.gameObject.layer = LayerMask.NameToLayer("IgnorePlayer");


        if (weaponPrefab is Bullet)
        {
            Bullet bullet = (Bullet)weapon;
            bullet.direction = weaponDirection;
        }

        yield return(new WaitForSeconds(1f));

        currentlyShooting = false;
    }
Beispiel #21
0
        private int?_Search(string Txt, bool IsArtist, int?Count = 1, int?Offset = null)
        {
            Log(MessageStatus.Request, string.Format(LogStrings.Info.Audio.SearchRequest, Txt, IsArtist, Count, Offset));
            AddSearchHis(Txt);
            //Get
            var parameters = new Dictionary <string, string>();

            parameters.Add("q", Txt);
            parameters.Add("v", "5.41");
            parameters.Add("performer_only", Convert.ToInt16(IsArtist).ToString());
            parameters.Add("auto_complete", "1");
            parameters.Add("sort", "2");
            if (Offset != null)
            {
                parameters.Add("offset", Offset.ToString());
            }
            parameters.Add("count", Count.ToString());
            var answer = ApiDirectCall("audio.search", parameters, false);
            var json   = Newtonsoft.Json.Linq.JObject.Parse(answer)["response"];
            //Serialize

            List <VkNet.Model.Attachments.Audio> AudioList = new List <VkNet.Model.Attachments.Audio>();

            foreach (var audioItem in json["items"] as Newtonsoft.Json.Linq.JArray)
            {
                var item = new Castable(audioItem);
                AudioList.Add(new VkNet.Model.Attachments.Audio()
                {
                    Id       = item["id"],
                    OwnerId  = item["owner_id"],
                    Artist   = item["artist"],
                    Title    = item["title"],
                    Duration = item["duration"],
                    Url      = item["url"],
                    LyricsId = item["lyrics_id"],
                    AlbumId  = item["album_id"],
                    Genre    = item["genre_id"] == null ? null : Util.NullableEnumFrom <VkNet.Enums.AudioGenre>(item["genre_id"])
                });
            }
            _LastAudioList = AudioList.Where(c => c.Url != null).ToList();

            LogResponse(_LastAudioList);

            return((int)json["count"]);
        }
Beispiel #22
0
        /// <summary>
        /// Calculate the healing for a castable.
        /// </summary>
        /// <param name="castable">The castable to use for the calculation</param>
        /// <param name="target">The target of the castable (i.e. the spell/skill target)</param>
        /// <param name="source">The source of the castable (i.e. the caster), optional parameter</param>
        /// <returns></returns>
        public static double CalculateHeal(Castable castable, Creature target, Creature source = null)
        {
            var    rand = new Random();
            double heal = 0;

            if (castable.Effects?.Heal == null)
            {
                return(heal);
            }

            if (castable.Effects.Heal.IsSimple)
            {
                heal = _evalSimple(castable.Effects.Heal.Simple) * target.Stats.HealModifier;
            }
            else
            {
                heal = _evalFormula(castable.Effects.Heal.Formula, castable, target, source);
            }
            return(heal * target.Stats.HealModifier);
        }
Beispiel #23
0
    IEnumerator Attack()
    {
        animator.SetTrigger("attack");

        yield return(new WaitForSeconds(.5f));

        int weaponDirection = mainRenderer.flipX ? -1 : 1;

        if (isBackwards)
        {
            weaponDirection *= -1;
        }
        Vector3 weaponWorldPosition = state == State.Small?weaponSpawnPointSmall.position:weaponSpawnPointBig.position;

        Vector3 weaponLocalPosition = transform.InverseTransformPoint(weaponWorldPosition);//new Vector3(transform.position.x + weaponDirection * 0.5f, transform.position.y + 0.5f, transform.position.z);

        if (mainRenderer.flipX)
        {
            weaponLocalPosition.x *= -1;
        }
        //if (isBackwards) weaponLocalPosition.x *= -1;

        weaponWorldPosition = transform.TransformPoint(weaponLocalPosition);
        Castable weapon = Instantiate(weaponPrefab, weaponWorldPosition, Quaternion.identity);

        //weapon.gameObject.layer = LayerMask.NameToLayer("IgnorePlayer");


        if (weaponPrefab is Bullet)
        {
            Bullet bullet = (Bullet)weapon;
            bullet.direction = weaponDirection;
        }

        if (attackSoundEffect)
        {
            AudioSource.PlayClipAtPoint(attackSoundEffect, new Vector3(0, 0, 0));
        }
    }
Beispiel #24
0
    IEnumerator Cast()
    {
        // Attack animation and sound
        animator.SetTrigger("attack");
        AudioSource.PlayClipAtPoint(attackSoundEffect, new Vector3(0, 0, 0));
        if (weaponPrefab.GetCastTime() > 0)
        {
            yield return(new WaitForSeconds(weaponPrefab.GetCastTime()));
        }

        int     weaponDirection     = spriteRenderer.flipX ? -1 : 1;
        Vector3 weaponWorldPosition = weaponSpawnPoint.position;

        Vector3 weaponLocalPosition = transform.InverseTransformPoint(weaponWorldPosition);//new Vector3(transform.position.x + weaponDirection * 0.5f, transform.position.y + 0.5f, transform.position.z);

        if (spriteRenderer.flipX)
        {
            weaponLocalPosition.x *= -1;
        }
        weaponWorldPosition = transform.TransformPoint(weaponLocalPosition);
        Castable weapon = Instantiate(weaponPrefab, weaponWorldPosition, Quaternion.identity);

        //weapon.gameObject.layer = LayerMask.NameToLayer("IgnorePlayer");

        if (weapon.GetCastType() == Castable.CastType.Sustained)
        {
            currentSustainedCast = weapon;
            animator.SetBool("shield", true);
        }

        if (weaponPrefab is Bullet)
        {
            Bullet bullet = (Bullet)weapon;
            bullet.direction = weaponDirection;
        }

        weapon.StartCast(this);
    }
Beispiel #25
0
        public Castable TryParameter(String name, bool decrypt, Func <Castable> onError, string comment = null)
        {
            String result = null;

            XmlNodeList nodes  = _xml.DocumentElement.GetElementsByTagName(CONF_Parameters)[0].SelectNodes(CONF_Parameter);
            Boolean     finded = false;

            foreach (XmlNode nod in nodes)
            {
                if (nod.Attributes[CONF_Parameter_Name].Value == name)
                {
                    result = nod.Attributes[CONF_Parameter_Value].Value;
                    result = decrypt ? _encrypter.Decrypt(result) : result;

                    finded = true;
                    break;
                }
            }

            if (!finded)
            {
                var value = onError();

                if (value != null)
                {
                    Create(AppConfigurationType.Parameter, name, value.ToString(), decrypt, comment);
                }
                else
                {
                    value = new Castable("");
                }

                return(value);
            }

            return(new Castable(result));
        }
Beispiel #26
0
        /// <summary>
        /// Calculate the healing for a status tick.
        /// </summary>
        /// <param name="castable">Castable responsible for the status</param>
        /// <param name="effect">ModifierEffect structure for the status</param>
        /// <param name="target">Target for the healing (e.g. the player or creature with the status)</param>
        /// <param name="source">Original source of the status</param>
        /// <param name="statusName">The name of the status</param>
        /// <returns></returns>
        public static double CalculateHeal(Castable castable, ModifierEffect effect, Creature target, Creature source, string statusName)
        {
            // Defaults
            double heal = 0;

            if (effect?.Heal == null)
            {
                return(heal);
            }

            var statusAdd = castable?.Statuses?.Add?.Where(e => e.Value == statusName)?.ToList();
            var intensity = statusAdd != null ? statusAdd[0].Intensity : 1;

            if (effect.Heal.IsSimple)
            {
                heal = _evalSimple(effect.Heal.Simple);
            }
            else
            {
                heal = _evalFormula(effect.Damage.Formula, castable, target, source);
            }

            return(heal * intensity * target.Stats.HealModifier);
        }
Beispiel #27
0
        public virtual bool UseCastable(Castable castObject, Creature target = null)
        {
            if (!Condition.CastingAllowed)
            {
                return(false);
            }

            if (this is User)
            {
                ActivityLogger.Info($"UseCastable: {Name} begin casting {castObject.Name} on target: {target?.Name ?? "no target"} CastingAllowed: {Condition.CastingAllowed}");
            }

            var             damage = castObject.Effects.Damage;
            List <Creature> targets;

            targets = GetTargets(castObject, target);

            if (targets.Count() == 0)
            {
                return(false);
            }

            // We do these next steps to ensure effects are displayed uniformly and as fast as possible
            var deadMobs = new List <Creature>();

            foreach (var tar in targets)
            {
                foreach (var user in tar.viewportUsers)
                {
                    user.SendEffect(tar.Id, castObject.Effects.Animations.OnCast.Target.Id, castObject.Effects.Animations.OnCast.Target.Speed);
                }
            }

            if (castObject.Effects?.Animations?.OnCast?.SpellEffect != null)
            {
                Effect(castObject.Effects.Animations.OnCast.SpellEffect.Id, castObject.Effects.Animations.OnCast.SpellEffect.Speed);
            }

            if (castObject.Effects.Sound != null)
            {
                PlaySound(castObject.Effects.Sound.Id);
            }

            ActivityLogger.Info($"UseCastable: {Name} casting {castObject.Name}, {targets.Count()} targets");
            foreach (var tar in targets)
            {
                if (castObject.Effects?.ScriptOverride == true)
                {
                    // TODO: handle castables with scripting
                    // DoStuff();
                    continue;
                }
                if (castObject.Effects?.Damage != null)
                {
                    Enums.Element attackElement;
                    var           damageOutput = NumberCruncher.CalculateDamage(castObject, tar, this);
                    if (castObject.Element == Castables.Element.Random)
                    {
                        Random rnd      = new Random();
                        var    Elements = Enum.GetValues(typeof(Enums.Element));
                        attackElement = (Enums.Element)Elements.GetValue(rnd.Next(Elements.Length));
                    }
                    else if (castObject.Element != Castables.Element.None)
                    {
                        attackElement = (Enums.Element)castObject.Element;
                    }
                    else
                    {
                        attackElement = (Stats.OffensiveElementOverride == Enums.Element.None ? Stats.OffensiveElementOverride : Stats.OffensiveElement);
                    }
                    if (this is User)
                    {
                        ActivityLogger.Info($"UseCastable: {Name} casting {castObject.Name} - target: {tar.Name} damage: {damageOutput}, element {attackElement}");
                    }

                    tar.Damage(damageOutput.Amount, attackElement, damageOutput.Type, damageOutput.Flags, this, false);
                    if (tar.Stats.Hp <= 0)
                    {
                        deadMobs.Add(tar);
                    }
                }
                // Note that we ignore castables with both damage and healing effects present - one or the other.
                // A future improvement might be to allow more complex effects.
                else if (castObject.Effects.Heal != null)
                {
                    var healOutput = NumberCruncher.CalculateHeal(castObject, tar, this);
                    tar.Heal(healOutput, this);
                    if (this is User)
                    {
                        ActivityLogger.Info($"UseCastable: {Name} casting {castObject.Name} - target: {tar.Name} healing: {healOutput}");
                    }
                }

                // Handle statuses

                foreach (var status in castObject.Effects.Statuses.Add.Where(e => e.Value != null))
                {
                    Status applyStatus;
                    if (World.WorldData.TryGetValueByIndex <Status>(status.Value, out applyStatus))
                    {
                        ActivityLogger.Info($"UseCastable: {Name} casting {castObject.Name} - applying status {status.Value}");
                        ApplyStatus(new CreatureStatus(applyStatus, tar, castObject));
                    }
                    else
                    {
                        ActivityLogger.Error($"UseCastable: {Name} casting {castObject.Name} - failed to add status {status.Value}, does not exist!");
                    }
                }

                foreach (var status in castObject.Effects.Statuses.Remove)
                {
                    Status applyStatus;
                    if (World.WorldData.TryGetValueByIndex <Status>(status, out applyStatus))
                    {
                        ActivityLogger.Error($"UseCastable: {Name} casting {castObject.Name} - removing status {status}");
                        RemoveStatus(applyStatus.Icon);
                    }
                    else
                    {
                        ActivityLogger.Error($"UseCastable: {Name} casting {castObject.Name} - failed to remove status {status}, does not exist!");
                    }
                }
            }
            // Now flood away
            foreach (var dead in deadMobs)
            {
                World.ControlMessageQueue.Add(new HybrasylControlMessage(ControlOpcodes.HandleDeath, dead));
            }

            return(true);
        }
Beispiel #28
0
 private void _init(Status xmlstatus, Creature target, Castable castable)
 {
     XMLStatus = xmlstatus;
     Target    = target;
     Castable  = castable;
 }
Beispiel #29
0
        public static T To <T>(this object input, T or)
        {
            var castable = new Castable();

            return(castable.To(input, or));
        }
Beispiel #30
0
        public static T To <T>(this string input)
        {
            var castable = new Castable();

            return(castable.To <T>(input));
        }
Beispiel #31
0
    public static int Main()
    {
        //Console.WriteLine("Execution started. Attach debugger and press enter.");
        //Console.ReadLine();

        try
        {
            object implProxy = new Castable(
                new Dictionary <Type, Type>()
            {
                { typeof(IRetArg <string>), typeof(RetArgImpl) },
                { typeof(IRetArg <int>), typeof(GenRetArgImpl <int>) },
                { typeof(IRetThis), typeof(RetThisImpl) },
                { typeof(IExtra), null },      //we should never use it
            }
                );

            // testing simple cases
            Assert(implProxy is IRetThis, "implProxy should be castable to IRetThis via is");
            Assert(!(implProxy is IUnimplemented), "implProxy should not be castable to IUnimplemented via is");
            Assert((implProxy as IRetThis) != null, "implProxy should be castable to IRetThis is as");
            Assert((implProxy as IUnimplemented) == null, "implProxy should not be castable to IUnimplemented is as");
            var retThis = (IRetThis)implProxy;
            Assert(object.ReferenceEquals(retThis.ReturnThis(), implProxy), "RetThis should return implProxy");
            Assert(retThis.GetMyType() == typeof(Castable), "GetMyType should return typeof(Castable)");

            Assert(!(implProxy is IUnimplemented), "implProxy should not be castable to IUnimplemented via is");
            Assert((implProxy as IUnimplemented) == null, "implProxy should not be castable to IUnimplemented via as");


            // testing generics
            IRetArg <string> retArgStr = (IRetArg <string>)implProxy;
            Assert(retArgStr.ReturnArg("hohoho") == "hohoho", "retArgStr.ReturnArg() should return arg");

            IRetArg <int> retArgInt = (IRetArg <int>)implProxy;
            Assert(retArgInt.ReturnArg(42) == 42, "retArgInt.ReturnArg() should return arg");


            // testing Castable implemeting other interfaces
            var extra = (IExtra)implProxy;
            Assert(extra.InnocentMethod() == 3, "InnocentMethod() should be called on Castable and return 3");

            // testing error handling
            try
            {
                var _ = (IUnimplemented)implProxy;
                Assert(false, "pProxy should not be castable to I1");
            }
            catch (InvalidCastException) {}

            object nullCastable = new Castable(null);
            try
            {
                var _ = (IRetThis)nullCastable;
                Assert(false, "Exceptions should be thrown from IsInstanceOfInterface");
            }
            catch (CastableException) {}

            object badCastable = new BadCastable();
            try
            {
                var r = (IRetThis)badCastable;
                r.ReturnThis();
                Assert(false, "Exceptions should be thrown from ReturnThis()");
            }
            catch (EntryPointNotFoundException) {}

            //delegate testing
            Func <int> fInt = new Func <int>(extra.InnocentMethod);
            Assert(fInt() == 3, "Delegate call to InnocentMethod() should return 3");

            Func <IRetThis> func = new Func <IRetThis>(retThis.ReturnThis);
            Assert(object.ReferenceEquals(func(), implProxy), "Delegate call to ReturnThis() should return this");
        }
        catch (Exception e)
        {
            Assert(false, e.ToString());
        }

        if (passed)
        {
            Console.WriteLine("Test PASSED!");
            return(100);
        }
        else
        {
            Console.WriteLine("Test FAILED!");
            return(-1);
        }
    }
Beispiel #32
0
        /// <summary>
        /// Calculate the damage for a status tick.
        /// </summary>
        /// <param name="castable">Castable responsible for the status</param>
        /// <param name="effect">ModifierEffect structure for the status</param>
        /// <param name="target">Target for the damage (e.g. the player or creature with the status)</param>
        /// <param name="source">Original source of the status</param>
        /// <param name="statusName">The name of the status</param>
        /// <returns></returns>
        public static (double Amount, Enums.DamageType Type, Castables.DamageFlags Flags) CalculateDamage(Castable castable, ModifierEffect effect, Creature target, Creature source, string statusName)
        {
            // Defaults
            double dmg  = 0;
            var    type = EnumUtil.ParseEnum(effect.Damage.Type.ToString(), Enums.DamageType.Magical);

            if (effect?.Damage == null)
            {
                return(dmg, type, Castables.DamageFlags.None);
            }

            var statusAdd = castable?.Statuses?.Add?.Where(e => e.Value == statusName)?.ToList();
            var intensity = statusAdd != null ? statusAdd[0].Intensity : 1;

            if (effect.Damage.IsSimple)
            {
                dmg = _evalSimple(effect.Damage.Simple);
            }
            else
            {
                dmg = _evalFormula(effect.Damage.Formula, castable, target, source);
            }
            return(dmg * intensity * target.Stats.DamageModifier, type, (Castables.DamageFlags)effect.Damage.Flags);
        }
Beispiel #33
0
        /// <summary>
        /// Calculate the healing for a castable.
        /// </summary>
        /// <param name="castable">The castable to use for the calculation</param>
        /// <param name="target">The target of the castable (i.e. the spell/skill target)</param>
        /// <param name="source">The source of the castable (i.e. the caster)</param>
        /// <returns></returns>
        public static (double Amount, Enums.DamageType Type, Castables.DamageFlags Flags) CalculateDamage(Castable castable, Creature target, Creature source = null)
        {
            var rand = new Random();
            // Defaults
            double dmg  = 1;
            var    type = EnumUtil.ParseEnum(castable.Effects.Damage.Type.ToString(), Enums.DamageType.Magical);

            if (castable.Effects?.Damage == null)
            {
                return(dmg, type, Castables.DamageFlags.None);
            }

            if (castable.Effects.Damage.IsSimple)
            {
                var simple = castable.Effects.Damage.Simple;
                dmg = _evalSimple(simple);
            }
            else
            {
                var formula = castable.Effects.Damage.Formula;
                dmg = _evalFormula(formula, castable, target, source);
            }

            return(dmg * target.Stats.DamageModifier, type, castable.Effects.Damage.Flags);
        }
Beispiel #34
0
    protected override void Update()
    {
        if (state == State.Active)
        {
            base.Update();
        }

        UpdateAnimationProperties();

        if (state == State.Active && Input.GetButtonDown("Fire1") && weaponPrefab)
        {
            StartCoroutine(Cast());
        }
        if (Input.GetButtonUp("Fire1") && currentSustainedCast)
        {
            currentSustainedCast.EndCast();
            animator.SetBool("shield", false);
            currentSustainedCast = null;
        }

        if (state == State.Following)
        {
            Vector3 newPos;
            if (settleAmount > 0.01f)
            {
                Vector3 settleLerpPos = Vector3.MoveTowards(transform.position, settlePosition, 6f * Time.deltaTime);
                Vector3 pos           = Vector3.Lerp(exactPathPosition, settleLerpPos, settleAmount);
                pos.y  = exactPathPosition.y;
                newPos = pos;
            }
            else
            {
                newPos = exactPathPosition;
            }

            velocity           = (newPos - transform.position) / Time.deltaTime;
            transform.position = newPos;

            if (isStill)
            {
                settleAmount = Mathf.MoveTowards(settleAmount, 1f, 2f * Time.deltaTime);
            }
            else
            {
                settleAmount = Mathf.MoveTowards(settleAmount, 0f, 2f * Time.deltaTime);

                // Set the sprite direction
                if (velocity.x > 0)
                {
                    direction = 1;
                }
                else if (velocity.x < 0)
                {
                    direction = -1;
                }
            }
        }

        if (animator.runtimeAnimatorController)
        {
            if (Mathf.Abs(velocity.x) > Mathf.Epsilon)
            {
                animator.SetBool("moving", true);
            }
            else
            {
                animator.SetBool("moving", false);
            }

            if (velocity.y > Mathf.Epsilon)
            {
                animator.SetBool("jumping", true);
                animator.SetBool("falling", false);
            }
            else if (velocity.y < -Mathf.Epsilon)
            {
                animator.SetBool("falling", true);
                animator.SetBool("jumping", false);
            }
            else
            {
                animator.SetBool("falling", false);
                animator.SetBool("jumping", false);
            }
        }
    }