public bool TryHit(Living target)              //is there still a distinction between dodge and miss?
        {
            double hitChance   = HitChance();          // Example: 0.7
            double dodgeChance = target.DodgeChance(); // Example: 0.3

            Debug.WriteLine("(2.5 / (System.Math.Sqrt(36 + creatureLevel + target.creatureLevel))) * (hitChance / dodgeChance)");
            Debug.WriteLine("2.5 / sqrt(36 +" + creatureLevel + " + " + target.creatureLevel + ") * (" + hitChance + " / " + dodgeChance + ")");
            Debug.WriteLine((2.5 / (System.Math.Sqrt(36 + creatureLevel + target.creatureLevel))) * (hitChance / dodgeChance)); // example: (0.5/(sqrt(1+1)) * (0.7/0.3) = 0.82
            return((0.5 / (System.Math.Sqrt(creatureLevel + target.creatureLevel))) * (hitChance / dodgeChance) > GameEnvironment.Random.NextDouble());
        }
Ejemplo n.º 2
0
 public override void DoSkill(Living caster, Living livingTarget, Tile TileTarget)
 {
     if (livingTarget != null)
     {
         caster.Mana         -= ManaCost;
         livingTarget.Health += skillPower;
         if (livingTarget.Health > livingTarget.MaxHealth)
         {
             livingTarget.Health = livingTarget.MaxHealth;
         }
     }
 }
        /// <summary>
        /// Take reflection damage based on Ring power and Base damage
        /// </summary>
        /// <param name="source">The living object giving the reflection damage</param>
        /// <param name="baseDamage">The damage the reflection is based on</param>
        /// <param name="power">The power multiplier of the reflection</param>
        protected void TakeReflectionDamage(Living source, int baseDamage, double power = 1)
        {
            double reflectAmount = 0.8 - 2 / source.Intelligence;

            if (reflectAmount < 0) // makes sure you can never heal the opponent by dealing
            {
                reflectAmount = 0; //     negative reflection damage
            }
            int damageTaken = (int)(baseDamage * reflectAmount * power);

            Health -= damageTaken;
            // TODO: Visual feedback of reflection
        }
Ejemplo n.º 4
0
        private void triggerdTrap(Living victim)
        {
            //not taking armor in to account
            if (victim.DodgeChance() >= GameEnvironment.Random.Next(100))
            {
                victim.Health -= 10;
            }

            //taking armor in to account
            //victim.TakeDamage(trapStrength, damageType);

            triggered = true;
        }
        /// <summary>
        /// Checks if the Attacker is able to attackt the Defender.
        /// This means the Defenders tile is whithin reach of and visible to the Attacker.
        /// </summary>
        /// <param name="att"> Attacking living object</param>
        /// <param name="def">Defending living object</param>
        /// <returns>Returns true when both conditions are met</returns>
        public static bool AbleToHit(Living att, Tile def, int attReach)
        {
            if (def.SeenBy.ContainsKey(att))
            {
                Point  delta = def.TilePosition - att.Tile.TilePosition;
                double reach = attReach + 0.5f; //plus a half tile to get the more natural reach area we discussed (melee can also attack 1 tile diagonaly)

                double distance = Math.Sqrt(Math.Pow(delta.X, 2) + Math.Pow(delta.Y, 2));

                bool result = distance <= reach;
                return(result);
            }
            return(false);
        }
 public override void DoSkill(Living caster, Living livingTarget, Tile TileTarget)
 {
     if (livingTarget != null)
     {
         caster.Mana -= ManaCost;
         NonAnimationSoundEvent MagicBoldSound = new NonAnimationSoundEvent("Sounds/donnerre2");
         LocalServer.SendToClients(MagicBoldSound);
         livingTarget.TakeDamage(skillPower, DamageType.Magic);
     }
     else
     {
         throw new Exception("invalid target");
     }
 }
Ejemplo n.º 7
0
        public void OnDeserialization(object sender)
        {
            tempSeenBy.OnDeserialization(sender);
            seenBy.OnDeserialization(sender);
            foreach (KeyValuePair <string, float> kvp in tempSeenBy)
            {
                Living l = (tempLocal.GetGameObjectByGUID(Guid.Parse(kvp.Key)) ??
                            onTile.Find(obj => obj.GUID == Guid.Parse(kvp.Key))) as Living;
                seenBy.Add(l, kvp.Value);
            }

            tempSeenBy = null;
            tempLocal  = null;
        }
        public void Special_Attack(Living target, double mod)
        {
            int        damageDealt = 0;
            DamageType damageType  = DamageType.Magic;

            double modifier = mod;

            double attackValue = Special_AttackValue(modifier);

            damageDealt = target.TakeDamage(attackValue, damageType);

            if (damageDealt > 0)
            {
                ProcessReflection(damageDealt, target);
            }
            // Display attack missed (feedback on fail)
        }
        private int penaltyDif(Living l)
        {
            int dif = 0;

            if (l.Strength < strRequirement)
            {
                dif += strRequirement - l.Strength;
            }
            if (l.Dexterity < dexRequirement)
            {
                dif += dexRequirement - l.Dexterity;
            }
            if (l.Intelligence < intRequirement)
            {
                dif += intRequirement - l.Intelligence;
            }
            return(dif);
        }
Ejemplo n.º 10
0
        public void disarmTrap(Living l)
        {
            //attempt to disarm the trap, if succesfull trap is disarmed whithout the livingObject taking damage, else trap is sprung (same effect as stepping on it)
            int disarmChance = (int)l.CalculateValue(40, l.Luck, 0, 1);
            int disarmValue  = GameEnvironment.Random.Next(100);

            if (disarmChance >= disarmValue)//check if the livingObject succesfully disarms the trap
            {
                triggered = true;
                if (l.GetType() == typeof(Player))
                {
                    (l as Player).ReceiveExp(trapExp);
                }
            }
            else
            {
                triggerdTrap(l);
            }
        }
        private void UpdateTurn()
        {
            Living turn = livingObjects[turnIndex];

            livingObjects.RemoveAll(l => l.Health <= 0); //Remove all the dead.
            turnIndex = livingObjects.IndexOf(turn);

            if (livingObjects[turnIndex].ActionPoints <= 0)
            {
                turnIndex = (turnIndex + 1) % livingObjects.Count;
                livingObjects[turnIndex].ActionPoints = Living.MaxActionPoints;
                if (livingObjects[turnIndex] is Player && !updatedLevelSent)
                {
                    SendToAllClients(new LevelChangedEvent(new List <GameObject>()
                    {
                        livingObjects[turnIndex]
                    }));
                }
            }
        }
        /// <summary>
        /// Handles attacking an opponent. First checks if attacker hits opponent, if succesfull sends attackvalue to defending side, if unsuccesfull displays miss feedback
        /// </summary>
        /// <param name="target"></param>
        public void Attack(Living target)
        {
            string     hitSound    = "Sounds/muted_metallic_crash_impact";
            int        damageDealt = 0;
            DamageType damageType  = DamageType.Physical;

            if (Weapon.SlotItem != null)
            {
                WeaponEquipment weaponItem = Weapon.SlotItem as WeaponEquipment;
                damageType = weaponItem.GetDamageType;
                hitSound   = weaponItem.HitSound;
            }

            //double hitNumber = GameEnvironment.Random.NextDouble();
            //if (hitNumber < HitChance())
            if (TryHit(target))
            {
                double attackValue = AttackValue();
                NonAnimationSoundEvent hitSoundEvent = new NonAnimationSoundEvent(hitSound);
                //no annimation for attacks (hit or miss) yet. when inplementing that, include sound effect there and remove this.
                LocalServer.SendToClients(hitSoundEvent);
                damageDealt = target.TakeDamage(attackValue, damageType);
            }
            else
            {
                //TODO: Display attack missed (visual feedback on fail)

                NonAnimationSoundEvent missSoundEvent = new NonAnimationSoundEvent("Sounds/Dodge");
                //no annimation for attacks (hit or miss) yet. when inplementing that, include sound effect there and remove this.
                LocalServer.SendToClients(missSoundEvent);
            }

            if (damageDealt > 0)
            {
                ProcessReflection(damageDealt, target);
            }
        }
Ejemplo n.º 13
0
        public virtual bool SkillValidation(Living caster, Living livingTarget, Tile TileTarget)
        {
            if (caster.CurrentSkill != null)
            {
                bool manacost = caster.Mana >= ManaCost;
                bool AtH;

                if (livingTarget != null)
                {
                    AtH = AttackEvent.AbleToHit(caster, livingTarget.Tile, skillReach);
                }
                else if (TileTarget != null)
                {
                    AtH = AttackEvent.AbleToHit(caster, TileTarget, skillReach);
                }
                else
                {
                    throw new Exception("invalid target");
                }

                return(manacost && AtH);
            }
            return(false);
        }
Ejemplo n.º 14
0
        public override void ItemAction(Living caller)
        {
            TakenPotionEvent p = new TakenPotionEvent(caller as Player, this);

            Server.Send(p);
        }
Ejemplo n.º 15
0
 public override void ItemAction(Living caller)
 {
     //TODO: send event to switch this equipment with the equipment currently in the appropriate slot.
 }
Ejemplo n.º 16
0
 public virtual void ItemAction(Living caller)
 {
 }
 public DeathAnimationEvent(Living dead, string soundAssetName, bool playerSpecific = false, string LocalPlayerName = "") : base(soundAssetName, playerSpecific, LocalPlayerName)
 {
     this.dead = dead;
 }
 public LivingMoveAnimationEvent(SerializationInfo info, StreamingContext context) : base(info, context)
 {
     toMove      = context.GetVars().Local.GetGameObjectByGUID(Guid.Parse(info.GetString("toMoveGUID"))) as Living;
     destination = context.GetVars().Local.GetGameObjectByGUID(Guid.Parse(info.GetString("destinationGUID"))) as Tile;
 }
 public LivingMoveAnimationEvent(Living toMove, Tile destination, string soundAssetName, bool playerSpecific = false, string LocalPlayerName = "") : base(soundAssetName, playerSpecific, LocalPlayerName)
 {
     this.toMove      = toMove;
     this.destination = destination;
 }
 public DeathAnimationEvent(SerializationInfo info, StreamingContext context) : base(info, context)
 {
     dead = context.GetVars().Local.GetGameObjectByGUID(Guid.Parse(info.GetString("deadGUID"))) as Living;
 }
 public AttackEvent(SerializationInfo info, StreamingContext context) : base(info, context)
 {
     Defender = context.GetVars().Local.GetGameObjectByGUID(Guid.Parse(info.GetString("DefenderGUID"))) as Living;
 }
 public AttackEvent(Player attacker, Living defender) : base(attacker)
 {
     Defender = defender;
 }
Ejemplo n.º 23
0
 public abstract void DoSkill(Living caster, Living livingTarget, Tile TileTarget);