Ejemplo n.º 1
0
        private static void ProcessChannelStatus(PlayerInstance ch, string argument,
                                                 Action <CharacterInstance, ChannelTypes> clearAction, Action <CharacterInstance, ChannelTypes> verifyAction)
        {
            if (argument.EqualsIgnoreCase("all"))
            {
                foreach (var chType in ClearAllList)
                {
                    clearAction.Invoke(ch, chType);
                }
                return;
            }

            var channelType = EnumerationExtensions.GetEnumByName <ChannelTypes>(argument);

            var attrib = channelType.GetAttribute <ChannelAttribute>();

            if (attrib == null)
            {
                throw new InvalidOperationException();
            }

            var minTrust    = 0;
            var trustAttrib = channelType.GetAttribute <RequireTrustChannelAttribute>();

            if (trustAttrib != null)
            {
                minTrust = GameConstants.GetConstant <int>(trustAttrib.TrustType);
            }

            if (attrib.Verify(channelType, ch, minTrust))
            {
                verifyAction.Invoke(ch, channelType);
            }
        }
Ejemplo n.º 2
0
        public static void do_shove(CharacterInstance ch, string argument)
        {
            if (CheckFunctions.CheckIfTrue(ch, ch.IsNpc() || !((PlayerInstance)ch).PlayerData.Flags.IsSet(PCFlags.Deadly),
                                           "Only deadly characters can shove."))
            {
                return;
            }
            if (CheckFunctions.CheckIfTrue(ch, ch.HasTimer(TimerTypes.PKilled), "You can't shove a player right now."))
            {
                return;
            }

            var firstArg = argument.FirstWord();

            if (CheckFunctions.CheckIfEmptyString(ch, firstArg, "Shove whom?"))
            {
                return;
            }

            var victim = ch.GetCharacterInRoom(firstArg);

            if (CheckFunctions.CheckIfNullObject(ch, victim, "They aren't here."))
            {
                return;
            }
            if (CheckFunctions.CheckIfEquivalent(ch, ch, victim, "You shove yourself around, to no avail."))
            {
                return;
            }
            if (CheckFunctions.CheckIfTrue(ch, victim.IsNpc() || !((PlayerInstance)victim).PlayerData.Flags.IsSet(PCFlags.Deadly),
                                           "You can only shove deadly characters."))
            {
                return;
            }
            if (CheckFunctions.CheckIfTrue(ch, ch.Level.GetAbsoluteDifference(victim.Level) > 5,
                                           "There is too great an experience difference for you to even bother."))
            {
                return;
            }
            if (CheckFunctions.CheckIfNullObject(ch, victim.HasTimer(TimerTypes.PKilled),
                                                 "You can't shove that player right now."))
            {
                return;
            }

            if (victim.CurrentPosition != PositionTypes.Standing)
            {
                comm.act(ATTypes.AT_PLAIN, "$N isn't standing up.", ch, null, victim, ToTypes.Character);
                return;
            }

            var secondArg = argument.SecondWord();

            if (CheckFunctions.CheckIfEmptyString(ch, secondArg, "Shove them in which direction?"))
            {
                return;
            }
            if (CheckFunctions.CheckIfTrue(ch,
                                           victim.CurrentRoom.Flags.IsSet(RoomFlags.Safe) && !ch.HasTimer(TimerTypes.ShoveDrag),
                                           "That character cannot be shoved right now."))
            {
                return;
            }

            victim.CurrentPosition = PositionTypes.Shove;

            var exitDir = EnumerationExtensions.GetEnumByName <DirectionTypes>(secondArg);
            var exit    = ch.CurrentRoom.GetExit(exitDir);

            if (CheckFunctions.CheckIfNullObject(ch, exit, "There's no exit in that direction."))
            {
                victim.CurrentPosition = PositionTypes.Standing;
                return;
            }
            if (CheckFunctions.CheckIfTrue(ch,
                                           exit.Flags.IsSet(ExitFlags.Closed) &&
                                           (!victim.IsAffected(AffectedByTypes.PassDoor) || exit.Flags.IsSet(ExitFlags.NoPassDoor)),
                                           "There's no exit in that direction."))
            {
                victim.CurrentPosition = PositionTypes.Standing;
                return;
            }

            var toRoom = exit.GetDestination();

            if (CheckFunctions.CheckIfSet(ch, toRoom.Flags, RoomFlags.Death,
                                          "You cannot shove someone into a death trap."))
            {
                victim.CurrentPosition = PositionTypes.Standing;
                return;
            }

            if (CheckFunctions.CheckIfTrue(ch, ch.CurrentRoom.Area != toRoom.Area && !toRoom.Area.IsInHardRange(victim),
                                           "That character cannot enter that area."))
            {
                victim.CurrentPosition = PositionTypes.Standing;
                return;
            }

            var chance = GetChanceByCharacterClass(ch);

            chance += (ch.GetCurrentStrength() - 15) * 3;
            chance += ch.Level - victim.Level;
            chance += GetBonusByCharacterRace(ch);

            if (CheckFunctions.CheckIfTrue(ch, chance < SmaugRandom.D100(), "You failed."))
            {
                victim.CurrentPosition = PositionTypes.Standing;
                return;
            }

            comm.act(ATTypes.AT_ACTION, "You shove $M.", ch, null, victim, ToTypes.Character);
            comm.act(ATTypes.AT_ACTION, "$n shoves you.", ch, null, victim, ToTypes.Victim);
            Move.move_char(victim, exit, 0);

            if (!victim.CharDied())
            {
                victim.CurrentPosition = PositionTypes.Standing;
            }

            Macros.WAIT_STATE(ch, 12);

            if (ch.CurrentRoom.Flags.IsSet(RoomFlags.Safe) && !ch.HasTimer(TimerTypes.ShoveDrag))
            {
                ch.AddTimer(TimerTypes.ShoveDrag, 10);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Process the spell's required components, if any
        /// </summary>
        /// <remarks>
        /// T###		check for item of type ###
        /// V#####	check for item of vnum #####
        /// Kword	check for item with keyword 'word'
        /// G#####	check if player has ##### amount of gold
        /// H####	check if player has #### amount of hitpoints
        ///
        /// Special operators:
        /// ! spell fails if player has this
        /// + don't consume this component
        /// @ decrease component's value[0], and extract if it reaches 0
        /// # decrease component's value[1], and extract if it reaches 0
        /// $ decrease component's value[2], and extract if it reaches 0
        /// % decrease component's value[3], and extract if it reaches 0
        /// ^ decrease component's value[4], and extract if it reaches 0
        /// & decrease component's value[5], and extract if it reaches 0
        /// </remarks>
        public static bool process_spell_components(CharacterInstance ch, int sn)
        {
            var skill = RepositoryManager.Instance.GetEntity <SkillData>(sn);

            if (skill == null || skill.Components.Count == 0)
            {
                return(true);
            }

            ObjectInstance obj = null;
            var            val = -1;

            foreach (var component in skill.Components)
            {
                var found   = false;
                var fail    = false;
                var consume = true;

                switch (component.OperatorType)
                {
                case ComponentOperatorTypes.FailIfPresent:
                    fail = true;
                    break;

                case ComponentOperatorTypes.DoNotConsume:
                    consume = false;
                    break;

                case ComponentOperatorTypes.DecreaseValue0:
                    val = 0;
                    break;

                case ComponentOperatorTypes.DecreaseValue1:
                    val = 1;
                    break;

                case ComponentOperatorTypes.DecreaseValue2:
                    val = 2;
                    break;

                case ComponentOperatorTypes.DecreaseValue3:
                    val = 3;
                    break;

                case ComponentOperatorTypes.DecreaseValue4:
                    val = 4;
                    break;

                case ComponentOperatorTypes.DecreaseValue5:
                    val = 5;
                    break;
                }

                switch (component.RequiredType)
                {
                case ComponentRequiredTypes.ItemType:
                    foreach (var vobj in ch.Carrying)
                    {
                        if (vobj.ItemType ==
                            EnumerationExtensions.GetEnumByName <ItemTypes>(
                                component.RequiredData))
                        {
                            if (CheckFunctions.CheckIfTrue(ch, fail,
                                                           "Something disrupts the casting of this spell..."))
                            {
                                return(false);
                            }
                            found = true;
                            obj   = vobj;
                            break;
                        }
                    }
                    break;

                case ComponentRequiredTypes.ItemVnum:
                    foreach (var vobj in ch.Carrying)
                    {
                        if (vobj.ID == component.RequiredData.ToInt32())
                        {
                            if (CheckFunctions.CheckIfTrue(ch, fail,
                                                           "Something disrupts the casting of this spell..."))
                            {
                                return(false);
                            }
                            found = true;
                            obj   = vobj;
                            break;
                        }
                    }
                    break;

                case ComponentRequiredTypes.ItemKeyword:
                    foreach (var vobj in ch.Carrying)
                    {
                        if (vobj.Name.IsAnyEqual(component.RequiredData))
                        {
                            if (CheckFunctions.CheckIfTrue(ch, fail,
                                                           "Something disrupts the casting of this spell..."))
                            {
                                return(false);
                            }
                            found = true;
                            obj   = vobj;
                            break;
                        }
                    }
                    break;

                case ComponentRequiredTypes.PlayerCoin:
                    if (ch.CurrentCoin >= component.RequiredData.ToInt32())
                    {
                        if (CheckFunctions.CheckIfTrue(ch, fail,
                                                       "Something disrupts the casting of this spell..."))
                        {
                            return(false);
                        }
                        if (consume)
                        {
                            ch.SetColor(ATTypes.AT_GOLD);
                            ch.SendTo("You feel a little lighter...");
                            ch.CurrentCoin -= component.RequiredData.ToInt32();
                        }
                        continue;
                    }
                    break;

                case ComponentRequiredTypes.PlayerHealth:
                    if (ch.CurrentHealth >= component.RequiredData.ToInt32())
                    {
                        if (CheckFunctions.CheckIfTrue(ch, fail,
                                                       "Something disrupts the casting of this spell..."))
                        {
                            return(false);
                        }
                        if (consume)
                        {
                            ch.SetColor(ATTypes.AT_BLOOD);
                            ch.SendTo("You feel a little weaker...");
                            ch.CurrentHealth -= component.RequiredData.ToInt32();
                            ch.UpdatePositionByCurrentHealth();
                        }
                        continue;
                    }
                    break;
                }

                if (fail)
                {
                    continue;
                }
                if (CheckFunctions.CheckIfTrue(ch, !found, "Something is missing..."))
                {
                    return(false);
                }
                if (obj != null)
                {
                    if (val >= 0 && val < 6)
                    {
                        obj.Split();
                        if (obj.Value.ToList()[val] <= 0)
                        {
                            comm.act(ATTypes.AT_MAGIC, "$p dispapears in a puff of smoke!", ch, obj, null, ToTypes.Character);
                            comm.act(ATTypes.AT_MAGIC, "$p disappears in a puff of smoke!", ch, obj, null, ToTypes.Room);
                            obj.Extract();
                            return(false);
                        }

                        if (--obj.Value.ToList()[val] == 0)
                        {
                            comm.act(ATTypes.AT_MAGIC, "$p glows briefly, then disappears in a puff of smoke!", ch, obj, null, ToTypes.Character);
                            comm.act(ATTypes.AT_MAGIC, "$p glows briefly, then disappears in a puff of smoke!", ch, obj, null, ToTypes.Room);
                            obj.Extract();
                        }
                        else
                        {
                            comm.act(ATTypes.AT_MAGIC, "$p glows briefly and a whisp of smoke rises from it.", ch, obj,
                                     null, ToTypes.Room);
                        }
                    }
                    else if (consume)
                    {
                        obj.Split();
                        comm.act(ATTypes.AT_MAGIC, "$p glows briefly, then disappears in a puff of smoke!", ch, obj, null, ToTypes.Character);
                        comm.act(ATTypes.AT_MAGIC, "$p glows briefly, then disappears in a puff of smoke!", ch, obj, null, ToTypes.Room);
                        obj.Extract();
                    }
                    else
                    {
                        var count = obj.Count;
                        obj.Count = 1;
                        comm.act(ATTypes.AT_MAGIC, "$p glows briefly.", ch, obj, null, ToTypes.Character);
                        obj.Count = count;
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 4
0
        public static void do_drag(CharacterInstance ch, string argument)
        {
            if (CheckFunctions.CheckIfNpc(ch, ch, "Only characters can drag."))
            {
                return;
            }
            if (CheckFunctions.CheckIfTrue(ch, ch.HasTimer(TimerTypes.PKilled), "You can't drag a player right now."))
            {
                return;
            }

            var pch = (PlayerInstance)ch;

            var firstArg = argument.FirstWord();

            if (CheckFunctions.CheckIfEmptyString(pch, firstArg, "Drag whom?"))
            {
                return;
            }

            var victim = pch.GetCharacterInRoom(firstArg);

            if (CheckFunctions.CheckIfNullObject(pch, victim, "They aren't here."))
            {
                return;
            }
            if (CheckFunctions.CheckIfEquivalent(pch, pch, victim,
                                                 "You take yourself by the scruff of your neck, but go nowhere."))
            {
                return;
            }
            if (CheckFunctions.CheckIfNpc(ch, victim, "You can only drag characters."))
            {
                return;
            }
            if (CheckFunctions.CheckIfTrue(ch,
                                           !victim.Act.IsSet((int)PlayerFlags.ShoveDrag) || (!victim.IsNpc() && !victim.IsDeadly()),
                                           "That character doesn't seem to appreciate your attentions."))
            {
                return;
            }
            if (CheckFunctions.CheckIfTrue(ch, victim.HasTimer(TimerTypes.PKilled),
                                           "You can't drag that player right now."))
            {
                return;
            }
            if (CheckFunctions.CheckIf(ch, HelperFunctions.IsFighting,
                                       "You try, but can't get close enough.", new List <object> {
                ch
            }))
            {
                return;
            }
            if (CheckFunctions.CheckIfTrue(ch, !ch.IsNpc() && !victim.IsDeadly() && ch.IsDeadly(),
                                           "You can't drag a deadly character."))
            {
                return;
            }
            if (CheckFunctions.CheckIfTrue(ch, !ch.IsNpc() && !ch.IsDeadly() && (int)ch.CurrentPosition > 3,
                                           "They don't seem to need your assistance."))
            {
                return;
            }

            var secondArg = argument.SecondWord();

            if (CheckFunctions.CheckIfEmptyString(ch, secondArg, "Drag them in which direction?"))
            {
                return;
            }
            if (CheckFunctions.CheckIfTrue(ch, Math.Abs(ch.Level - victim.Level) > 5,
                                           "There is too great an experience difference for you to even bother."))
            {
                return;
            }
            if (CheckFunctions.CheckIfTrue(ch,
                                           victim.CurrentRoom.Flags.IsSet(RoomFlags.Safe) && victim.GetTimer(TimerTypes.ShoveDrag) == null,
                                           "That character cannot be dragged right now."))
            {
                return;
            }

            var exitDir = EnumerationExtensions.GetEnumByName <DirectionTypes>(secondArg);
            var exit    = ch.CurrentRoom.GetExit(exitDir);

            if (CheckFunctions.CheckIfNullObject(ch, exit, "There's no exit in that direction."))
            {
                return;
            }
            if (CheckFunctions.CheckIfTrue(ch, !IsPassable(exit, victim), "There's no exit in that direction."))
            {
                return;
            }

            var toRoom = exit.GetDestination();

            if (CheckFunctions.CheckIfSet(ch, toRoom.Flags, RoomFlags.Death,
                                          "You cannot drag someone into a death trap."))
            {
                return;
            }

            if (CheckFunctions.CheckIfTrue(ch, ch.CurrentRoom.Area != toRoom.Area && !toRoom.Area.IsInHardRange(victim),
                                           "That character cannot enter that area."))
            {
                victim.CurrentPosition = PositionTypes.Standing;
                return;
            }

            var chance = CalculateChanceToDrag(ch, victim);

            if (CheckFunctions.CheckIfTrue(ch, chance < SmaugRandom.D100(), "You failed."))
            {
                victim.CurrentPosition = PositionTypes.Standing;
                return;
            }

            if ((int)victim.CurrentPosition < (int)PositionTypes.Standing)
            {
                DragIntoNextRoom(ch, victim, exit);
                return;
            }

            ch.SendTo("You cannot do that to someone who is standing.");
        }