예제 #1
0
        public override void Cast(IAvatar caster, IActor target, CastResults results)
        {
            IAvatar traveler = target as IAvatar;

            if (traveler != null)
            {
                Place place = this.World.FindPlace(new Point3(this.DestinationX, this.DestinationY, this.DestinationZ));
                if (place != null && place.HasExits())
                {
                    place.Enter(traveler, Direction.Empty);

                    if (Object.ReferenceEquals(caster, traveler))
                    {
                        caster.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Cast,
                                                                String.Format(Resources.SpellTransported, place.Name)));
                    }
                    else
                    {
                        caster.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Cast,
                                                                String.Format(Resources.SpellTransportedTarget, traveler.The(), place.Name)));
                        traveler.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Cast,
                                                                  String.Format(Resources.SpellTransportedByTarget, place.Name)));
                    }
                }
                else
                {
                    this.NoAffect(caster);
                }
            }
            else
            {
                this.NoAffect(caster);
            }
        }
예제 #2
0
        public override void Cast(IAvatar caster, IActor target, CastResults results)
        {
            IAvatar defender = target as IAvatar;

            if (defender != null)
            {
                if (defender is PerenthiaMobile)
                {
                    defender = caster;
                }

                int power = this.Foci.Power + results.CastSuccessCount;
                defender.Attributes.ApplyAffect(this.StatName, power, this.Foci.Duration);
                defender.Context.AddRange(defender.Affects.ToRdl());
                if (Object.ReferenceEquals(caster, defender))
                {
                    caster.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Cast,
                                                            String.Format(Resources.SpellStatGained, this.StatName, power)));
                }
                else
                {
                    caster.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Cast,
                                                            String.Format(Resources.SpellStatGainedTarget, this.StatName, defender.A(), power)));
                    defender.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Cast,
                                                              String.Format(Resources.SpellStatGainedByTarget, caster.A(), this.StatName, power)));
                    defender.Context.AddRange(defender.Attributes.ToRdl());
                }
            }
            else
            {
                this.NoAffect(caster);
            }
        }
예제 #3
0
        public override void Cast(IAvatar caster, IActor target, CastResults results)
        {
            if (!String.IsNullOrEmpty(this.ItemTypeName))
            {
                Item item = this.World.CreateActor(Type.GetType(this.ItemTypeName), this.ItemName) as Item;
                if (item != null)
                {
                    if (caster is Character)
                    {
                        Container container = (caster as Character).GetFirstAvailableContainer(item);
                        if (container != null)
                        {
                            item.Drop(container);
                            item.Save();

                            caster.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Cast,
                                                                    String.Format(Resources.ItemCreated, item.A())));
                        }
                        else
                        {
                            caster.Context.Add(new RdlErrorMessage(Resources.InventoryFull));
                        }
                    }
                    else
                    {
                        item.Drop(caster);
                    }
                }
                else
                {
                    caster.Context.Add(new RdlErrorMessage(Resources.CastFailed));
                }
            }
        }
예제 #4
0
 private void InitResults()
 {
     for (int row = 0; row < ROWS; row++)
     {
         for (int col = 0; col < COLS; col++)
         {
             _casts[row, col] = new CastResults(row, col);
         }
     }
 }
예제 #5
0
        public override void Cast(IAvatar caster, IActor target, CastResults results)
        {
            IAvatar defender = target as IAvatar;

            // Increase the protection value of the target.
            if (defender != null)
            {
                if (defender is PerenthiaMobile)
                {
                    defender = caster;
                }

                int power = this.Foci.Power + results.CastSuccessCount;
                this.AffectPower = power;
                this.Save();

                // If a protection spell already exists using the same skill then remove it
                // and add the current one.
                // Search the list of spells with the same skill and try to find those spells in the
                // affects collection.
                var spellNames = defender.GetAllChildren().Where(c => c is ISpell && (c as ISpell).Skill == this.Skill).Select(c => c.Name);
                foreach (var spellName in spellNames)
                {
                    // If this protection already exists then remove it and add the new one.
                    if (defender.Affects.ContainsKey(spellName))
                    {
                        this.RemoveAffect(defender, false);
                    }
                }

                defender.Protection += power;
                defender.Affects.Add(this, this.Foci.Duration);
                defender.Context.AddRange(defender.Affects.ToRdl());
                if (Object.ReferenceEquals(caster, defender))
                {
                    caster.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Cast,
                                                            String.Format(Resources.SpellProtectionGained, power)));
                }
                else
                {
                    caster.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Cast,
                                                            String.Format(Resources.SpellProtectionGainedTarget, target.A(), power)));
                    defender.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Cast,
                                                              String.Format(Resources.SpellProtectionGainedByTarget, power, caster.A())));
                    if (defender != null)
                    {
                        defender.Context.AddRange(defender.GetRdlProperties(Avatar.ProtectionProperty));
                    }
                }
            }
            else
            {
                this.NoAffect(caster);
            }
        }
예제 #6
0
        public override void Cast(IAvatar caster, IActor target, CastResults results)
        {
            IAvatar defender = target as IAvatar;

            // TODO: Defense against spells?
            int power = this.Foci.Power + results.CastSuccessCount;

            target.SetBody(target.Body - power);

            caster.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Cast,
                                                    String.Format(Resources.SpellDamagedTarget, target.A(), power)));
            if (defender != null)
            {
                defender.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Negative,
                                                          String.Format(Resources.SpellDamagedByTarget, power, caster.A())));
            }
            if (defender != null)
            {
                defender.Context.AddRange(defender.GetRdlProperties(Avatar.BodyProperty));
            }

            if (target.IsDead)
            {
                results.TargetDied = true;
                if (defender != null)
                {
                    // Killed an Avatar.
                    caster.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Cast,
                                                            String.Format(Resources.SpellKilledTarget, target.A())));
                    defender.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Negative,
                                                              String.Format(Resources.SpellKilledByTarget, caster.A())));
                }
                else
                {
                    // Destroyed an object.
                    caster.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Cast,
                                                            String.Format(Resources.SpellDestroyedTraget, target.A())));
                }
            }
            else if (defender != null && defender.IsUnconscious)
            {
                results.TargetUnconscious = true;
                caster.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Cast,
                                                        String.Format(Resources.SpellUnconsciousTarget, target.A())));
                if (defender != null)
                {
                    defender.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Negative,
                                                              String.Format(Resources.SpellUnconsciousByTarget, caster.A())));
                }
            }
        }
예제 #7
0
        public override void Cast(IAvatar caster, IActor target, CastResults results)
        {
            Item item = target as Item;

            if (item != null)
            {
                item.Properties.SetValue(this.EnchantPropertyName, this.Power);
                caster.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Cast,
                                                        String.Format(Resources.SpellEnchanted, item.A())));
            }
            else
            {
                this.NoAffect(caster);
            }
        }
예제 #8
0
        /// <summary>
        /// Converts a(n) <see cref="CastResults"/> to <see cref="ResultCode"/>
        /// </summary>
        /// <param name="castResult"></param>
        public static ResultCode ToResultCode(this CastResults castResult)
        {
            switch (castResult)
            {
            case CastResults.Ok:
                return(ResultCode.Ok);

            case CastResults.OutOfRange:
                return(ResultCode.ObjectIsOutOfRange);

            case CastResults.TargetTooClose:
                return(ResultCode.ObjectIsTooClose);

            case CastResults.NotEnoughPower:
                return(ResultCode.NotEnoughPower);

            case CastResults.TargetIsDead:
                return(ResultCode.TargetIsDead);

            case CastResults.CasterIsDead:
                return(ResultCode.CasterIsDead);

            case CastResults.TargetRequired:
                return(ResultCode.TargetRequired);

            case CastResults.InvalidTarget:
                return(ResultCode.InvalidTarget);

            case CastResults.SpellNotReady:
                return(ResultCode.SpellNotReady);

            case CastResults.SpellNotFound:
                return(ResultCode.SpellNotFound);

            case CastResults.InCooldown:
            case CastResults.InGcd:
                return(ResultCode.SpellInCooldown);

            case CastResults.AlreadyCasting:
                return(ResultCode.AlreadyCasting);

            default:
                return(ResultCode.Fail);
            }
        }
예제 #9
0
        public override void Cast(IAvatar caster, IActor target, CastResults results)
        {
            Character player = caster as Character;

            if (player == null)
            {
                player = target as Character;
            }
            if (player != null)
            {
                player.SightRange = this.Foci.Range;
                player.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Cast, this.SuccessMessage));
            }
            else
            {
                this.NoAffect(caster);
            }
        }
예제 #10
0
        public override void Cast(IAvatar caster, IActor target, CastResults results)
        {
            IAvatar defender = target as IAvatar;

            // Do not heal creatures or NPCs
            if (defender is Creature || defender is Npc)
            {
                target   = caster;
                defender = caster;
            }

            // Heal the mind value of the target.
            if (defender != null)
            {
                if (defender.Mind == defender.MindMax)
                {
                    this.NoAffect(caster);
                    this.NoAffect(defender);
                }
                else
                {
                    int power = this.Foci.Power + results.CastSuccessCount;
                    defender.SetMind(defender.Mind + power);
                    if (Object.ReferenceEquals(caster, defender))
                    {
                        // Target is self, only need a message to the caster.
                        caster.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Cast,
                                                                String.Format(Resources.SpellWillpowerGained, power)));
                    }
                    else
                    {
                        // Need to inform both the caster the target of healing.
                        caster.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Cast,
                                                                String.Format(Resources.SpellWillpowerGainedTarget, power, target.The())));
                        defender.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Cast,
                                                                  String.Format(Resources.SpellWillpowerGainedByTarget, power, caster.A())));
                    }
                }
            }
            else
            {
                this.NoAffect(caster);
            }
        }
예제 #11
0
        public override void Cast(IAvatar caster, IActor target, CastResults results)
        {
            IAvatar defender = target as IAvatar;

            // Do not heal creatures or NPCs
            if (defender is PerenthiaMobile)
            {
                target   = caster;
                defender = caster;
            }

            // Heal or increase the body value of the target.
            if (target.Body == target.BodyMax)
            {
                this.NoAffect(caster);
                if (defender != null)
                {
                    this.NoAffect(defender);
                }
            }
            else
            {
                int power = this.Foci.Power + results.CastSuccessCount;
                target.SetBody(target.Body + power);
                if (Object.ReferenceEquals(caster, target))
                {
                    // Target is self, only need a message to the caster.
                    caster.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Cast,
                                                            String.Format(Resources.SpellHealthGained, power)));
                }
                else
                {
                    // Need to inform both the caster the target of healing.
                    caster.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Cast,
                                                            String.Format(Resources.SpellHealthGainedTarget, power, target.The())));
                    if (defender != null)
                    {
                        defender.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Cast,
                                                                  String.Format(Resources.SpellHealthGainedByTarget, power, caster.A())));
                    }
                }
            }
        }
예제 #12
0
        /// <summary>
        /// Causes the user to attack its current target with the current Item as the weapon. If the user's target is a mobile
        /// a counter attack check will occur and if successful the mobile will counter attack.
        /// </summary>
        /// <param name="weapon">The current item to use as a weapon.</param>
        /// <param name="user">The actor instance using the item as a weapon.</param>
        public static void Attack(this Item weapon, IActor user)
        {
            //if (user is IAvatar)
            //{
            //    if ((user as IAvatar).CombatMatch != Guid.Empty)
            //    {
            //        // Already engaged in combat, ignore the command.
            //    }
            //    else
            //    {
            //        // If the target is already engaged then join the match??
            //    }
            //}

            try
            {
                IAvatar avatar, target;
                IAvatar defender = null;
                IAvatar attacker = null;

                avatar = user as IAvatar;
                if (avatar != null)
                {
                    if (avatar.Target != null && avatar.Target is IAvatar)
                    {
                        target = avatar.Target as IAvatar;

                        // If the target is the user then exit.
                        if (avatar.ID == target.ID)
                        {
                            avatar.Context.Add(new RdlErrorMessage(Resources.CanNotAttackSelf));
                            return;
                        }

                        // Target must also have the avatar targeted or be set to null.
                        if (target.Target == null)
                        {
                            target.Target = avatar;
                        }
                        else if (target.Target.ID != avatar.ID)
                        {
                            avatar.Context.Add(new RdlErrorMessage(String.Format(Resources.TargetEngaged, target.TheUpper())));
                            return;
                        }

                        // Check for death and unconsioussness.
                        if (avatar.IsDead)
                        {
                            avatar.Context.Add(new RdlErrorMessage(Resources.PlayerDead));
                            return;
                        }
                        if (avatar.IsUnconscious)
                        {
                            avatar.Context.Add(new RdlErrorMessage(Resources.PlayerUnconscious));
                            return;
                        }

                        if (target.IsDead)
                        {
                            avatar.Context.Add(new RdlErrorMessage(Resources.TargetDead));
                            return;
                        }

                        // Can not attack certain mobiles, need to check for safe mobiles.
                        if (target is PerenthiaMobile && !(target as PerenthiaMobile).CanAttack)
                        {
                            avatar.Context.Add(new RdlErrorMessage(String.Format(Resources.ActionCanNotPerform, target.A())));
                            return;
                        }

                        // Can not attack a Character unless the IsPvpEnabled is set to true.
                        if (target is Character)
                        {
                            if (avatar is Character && !(target as Character).IsPvpEnabled)
                            {
                                avatar.Context.Add(new RdlErrorMessage(String.Format(Resources.ActionCanNotPerform, target.A())));
                                return;
                            }
                        }

                        // Increase the skill of the player using the item.
                        IPlayer currentPlayer = null;
                        string  skill         = null;
                        if (avatar is IPlayer)
                        {
                            currentPlayer = avatar as IPlayer;
                            skill         = weapon.GetOffensiveSkill();
                        }
                        else if (target is IPlayer)
                        {
                            currentPlayer = target as IPlayer;
                            skill         = target.GetDefensiveSkill();
                        }
                        if (weapon is Spell)
                        {
                            skill = weapon.Skill;
                        }
                        if (currentPlayer != null && !(weapon is Spell))
                        {
                            // NOTE: Skill advancement occuring in combat and magic manager classes.
                            // Advance the skill of the current player.
                            //SkillManager.AdvanceSkill(currentPlayer, skill, weapon.SkillLevelRequiredToEquip, currentPlayer.Context);
                        }

                        bool performCounterAttack = false;
                        if (weapon is Spell)
                        {
                            // CAST A SPELL
                            CastResults results = MagicManager.PerformCast((ISpell)weapon, avatar, target);
                            if (results.TargetDied)
                            {
                                attacker = avatar;
                                defender = target;
                            }
                            else
                            {
                                // If the target is a mobile then counter attack.
                                if (!avatar.IsDead && target is IMobile && !target.IsDead && !target.IsUnconscious)
                                {
                                    performCounterAttack = true;
                                }
                            }
                        }
                        else
                        {
                            // USE A WEAPON
                            if (CombatManager.PerformSimpleCombatTurn(
                                    avatar,
                                    (IWeapon)weapon,
                                    target,
                                    target.GetDefensiveSkill(),
                                    AttributeType.Dexterity,
                                    0))
                            {
                                // Killed defender.
                                attacker = avatar;
                                defender = target;
                            }
                            else
                            {
                                // DUAL WIELD
                                // If attacker has dual wield skill and an equipped second weapon then
                                // perform another attack.
                                IWeapon secondaryWeapon = avatar.GetSecondaryWeapon();
                                if (secondaryWeapon != null)
                                {
                                    if (CombatManager.PerformSimpleCombatTurn(
                                            avatar,
                                            secondaryWeapon,
                                            "Dual Wield",
                                            target,
                                            target.GetDefensiveSkill(),
                                            AttributeType.Dexterity,
                                            0))
                                    {
                                        // Killed defender.
                                        attacker = avatar;
                                        defender = target;
                                    }
                                    else
                                    {
                                        // Defender counter attack.
                                        // Only counter if a mobile.
                                        if (target is IMobile && !target.IsDead && !target.IsUnconscious)
                                        {
                                            performCounterAttack = true;
                                        }
                                    }
                                }
                                else
                                {
                                    // Defender counter attack.
                                    // Only counter if a mobile.
                                    if (target is IMobile && !target.IsDead && !target.IsUnconscious)
                                    {
                                        performCounterAttack = true;
                                    }
                                }
                            }
                        }

                        if (performCounterAttack)
                        {
                            if (!target.IsStunned && !target.IsFrozen && !avatar.IsDead)
                            {
                                // TODO: Have mobiles attack with spells??
                                // USE A WEAPON
                                if (CombatManager.PerformSimpleCombatTurn(
                                        target,
                                        target.GetWeapon(),
                                        avatar,
                                        avatar.GetDefensiveSkill(),
                                        AttributeType.Dexterity,
                                        0))
                                {
                                    // Killed attacker.
                                    attacker = target;
                                    defender = avatar;
                                }

                                // Update the mobile's last attack time.
                                (target as PerenthiaMobile).LastAttackTime = DateTime.Now;
                            }
                        }

                        // Send down stats for both attacker and defender.
                        var attackerProps = avatar.GetRdlProperties(Avatar.BodyProperty, Avatar.MindProperty);
                        var defenderProps = target.GetRdlProperties(Avatar.BodyProperty, Avatar.MindProperty);
                        avatar.Context.AddRange(attackerProps);
                        avatar.Context.AddRange(defenderProps);
                        target.Context.AddRange(attackerProps);
                        target.Context.AddRange(defenderProps);

                        if (defender != null && attacker != null)
                        {
                            if (attacker is IPlayer)
                            {
                                //=========================================================================================
                                // PLAYER KILLED MOBILE
                                //=========================================================================================
                                // The mobile dies, cause it to respawn at a later date.
                                PerenthiaMobile mob = defender as PerenthiaMobile;
                                if (mob != null)
                                {
                                    // Mobile is a clone but is stored as an instance on the mobile object.
                                    DateTime killTime = DateTime.Now;
                                    mob.RespawnTime = killTime.Add(mob.RespawnDelay);
                                    mob.KilledBy.AddKilledBy(attacker.ID, killTime);
                                }
                                attacker.Context.AddRange(defender.ToSimpleRdl());

                                // Since the player killed the mobile, give them some experience.
                                Character player = attacker as Character;
                                if (player != null && mob != null)
                                {
                                    int xp = LevelManager.GetXpForMobileKill(player.Level, mob.Level);
                                    if (xp > 0)
                                    {
                                        player.Experience      += xp;
                                        player.TotalExperience += xp;
                                        player.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Positive,
                                                                                String.Format(Resources.ExperienceGained, xp)));
                                    }

                                    // Raise an event indicating that the player has killed something.
                                    player.World.OnAvatarKilledAvatar(player, mob);

                                    // Raise an internal event on the player instance for quests and awards.
                                    player.OnKilledActor(mob);

                                    // Cause the player to advance if the required experience requirements are met.
                                    LevelManager.AdvanceIfAble(player);

                                    // Mobiles should drop random items, mostly items related to crafting.
                                    mob.GenerateRandomDropItems();

                                    // Send down changed properties.
                                    player.Context.AddRange(player.GetRdlProperties(
                                                                Character.ExperienceProperty,
                                                                Character.ExperienceMaxProperty,
                                                                Character.CurrencyProperty));

                                    // Save the player instance.
                                    player.Save();
                                }
                            }
                            else if (defender is IPlayer)
                            {
                                //=========================================================================================
                                // MOBILE KILLED PLAYER
                                //=========================================================================================
                                // A player died, dock some experience.
                                // Only loose experience after level 5.
                                Character player = defender as Character;
                                if (player != null && player.Experience > 0 && player.Level > 5)
                                {
                                    int penaltyXp = player.Level * 50 + (Dice.Roll(player.Level, 10));
                                    if (penaltyXp > player.Experience)
                                    {
                                        penaltyXp = player.Experience - 2;
                                    }
                                    player.Experience      -= penaltyXp;
                                    player.TotalExperience -= penaltyXp;
                                    player.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Negative,
                                                                            String.Format(Resources.ExperienceLost, penaltyXp)));

                                    // Send down changed properties.
                                    player.Context.AddRange(player.GetRdlProperties(
                                                                Character.ExperienceProperty,
                                                                Character.ExperienceMaxProperty));
                                }

                                // Raise an event on the player for quests and awards.
                                if (defender != null)
                                {
                                    player.OnDied(defender);
                                }

                                if (attacker != null && defender != null)
                                {
                                    // Raise an event indicating that the defender has killed the attacker.
                                    defender.World.OnAvatarKilledAvatar(attacker, defender);
                                }

                                // Find the nearest temple and resurrect the player there.
                                Temple temple = Game.FindTemple(defender.Location);
                                if (temple != null)
                                {
                                    temple.Resurrect(defender);
                                }
                                else
                                {
                                    // Otherwise, spaw a temple right above the player's starting location and send them there.
                                    Race   race      = defender.World.Races[defender.Race];
                                    Temple newTemple = new Temple()
                                    {
                                        Location = new Point3(race.StartingLocation.X, race.StartingLocation.Y, race.StartingLocation.Z + 1),
                                        Name     = "Temple",
                                        World    = defender.World,
                                        Terrain  = defender.World.Terrain[1].ID,
                                    };
                                    newTemple.Exits.SetValue(KnownDirection.Down, true);
                                    defender.World.Places.Add(newTemple.Location, newTemple);
                                    Game.AddTemple(newTemple);
                                }

                                // Save the player instance.
                                defender.Save();
                            }
                            // Do not reset targets after combat as the target might be clone of a mob and will need
                            // to remain set for proper looting.
                            // Reset targets.
                            //attacker.Target = null;
                            //defender.Target = null;
                            //attacker.Context.AddRange(attacker.GetRdlProperties(Avatar.TargetIDProperty));
                            //defender.Context.AddRange(defender.GetRdlProperties(Avatar.TargetIDProperty));
                        }
                    }
                    else
                    {
                        avatar.Context.Add(new RdlErrorMessage(String.Format("You must have a target selected to use {0}.", weapon.The())));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }