Esempio n. 1
0
        public static void KickPlayer(MudObject Player, MudObject Actor)
        {
            var client = Player.GetProperty <Client>("client");

            if (client != null)
            {
                Core.MarkLocaleForUpdate(Player);

                Core.SendMessage(Player, Actor.GetProperty <String>("short") + " has removed you from the server.");
                client.Disconnect();
                Clients.SendGlobalMessage(Actor.GetProperty <String>("short") + " has removed " + Player.GetProperty <String>("short") + " from the server.");
            }
        }
Esempio n. 2
0
        private static IEnumerable <MudObject> _enumerateVisibleTree(MudObject C)
        {
            if (C != null)
            {
                yield return(C);

                if (C.Contents != null)
                {
                    foreach (var list in C.Contents)
                    {
                        if (list.Key == RelativeLocations.IN && C.GetProperty <bool>("openable?") && !C.GetProperty <bool>("open?"))
                        {
                            continue;
                        }
                        foreach (var item in list.Value)
                        {
                            foreach (var sub in _enumerateVisibleTree(item))
                            {
                                yield return(sub);
                            }
                        }
                    }
                }
            }
        }
        public PasswordCommandHandler(MudObject Actor, Action <MudObject, String, String> AuthenticatingCommand, String UserName)
        {
            this.ParentHandler         = Actor.GetProperty <ClientCommandHandler>("command handler");
            this.AuthenticatingCommand = AuthenticatingCommand;
            this.UserName = UserName;

            Core.SendMessage(Actor, "Password: ");
        }
Esempio n. 4
0
        public static List <MudObject> InitializeConversationTopics(this MudObject To)
        {
            if (!To.HasProperty("conversation-topics"))
            {
                To.SetProperty("conversation-topics", new List <MudObject>());
            }

            return(To.GetProperty <List <MudObject> >("conversation-topics"));
        }
Esempio n. 5
0
        public static void MeleeAttack(MudObject Attacker, MudObject Target)
        {
            if (!Target.HasProperty("combat health"))
            {
                return;
            }

            MudObject weapon = Attacker.GetProperty <MudObject>("combat weapon");

            if (weapon == null)
            {
                weapon          = GetDefaultWeapon();
                weapon.Location = Attacker;
            }

            var hitModifier = weapon.GetProperty <int>("combat hit modifier");
            var armorClass  = Target.GetProperty <int>("combat armor class");

            Core.SendMessage(Attacker, "Hit mod " + hitModifier + " vs AC " + armorClass);
            var hitRoll = Core.RollDice("1d20") + hitModifier;


            if (hitRoll == 20 || hitRoll >= armorClass)
            {
                var damageDie = weapon.GetProperty <String>("combat damage die");
                var damage    = Core.RollDice(damageDie);
                Core.SendMessage(Attacker, "Hit for (" + damageDie + ") - " + damage + " damage!");
                if (hitRoll == 20)
                {
                    var additionalDamage = Core.RollDice(damageDie);
                    Core.SendMessage(Attacker, "Critical! " + additionalDamage + " additional damage!");
                    damage += additionalDamage;
                }

                Core.SendLocaleMessage(Attacker, "^<0> hits ^<1> for " + damage + " damage!", Attacker, Target);
            }
            else
            {
                Core.SendMessage(Attacker, "@you miss", Attacker, Target);
                Core.SendLocaleMessage(Attacker, "@they miss", Attacker, Target);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Given a portal, find the opposite side. Portals are used to connect two rooms. The opposite side of
        /// the portal is assumed to be the portal in the linked room that faces the opposite direction. For example,
        /// if portal A is in room 1, faces west, and is linked to room 2, the opposite side would be the portal
        /// in room 2 that faces east. It does not actually check to see if the opposite side it finds is linked
        /// to the correct room.
        /// </summary>
        /// <param name="Portal"></param>
        /// <returns></returns>
        public static MudObject FindOppositeSide(MudObject Portal)
        {
            // Every object added to a room as a portal will be given the 'portal?' property, with a value of true.
            if (Portal.GetProperty <bool>("portal?") == false)
            {
                return(null);                                              // Not a portal.
            }
            var destination = Core.GetObject(Portal.GetProperty <String>("link destination"));

            if (destination == null)
            {
                return(null);                     // Link is malformed in some way.
            }
            var direction         = Portal.GetProperty <Direction>("link direction");
            var oppositeDirection = Link.Opposite(direction);
            var mirrorLink        = destination.EnumerateObjects().FirstOrDefault(p =>
                                                                                  p.GetProperty <bool>("portal?") && p.GetProperty <Direction>("link direction") == oppositeDirection);

            return(mirrorLink);
        }
Esempio n. 7
0
 public static void OfferQuest(this MudObject This, MudObject Actor, MudObject Quest)
 {
     if (Actor != null)
     {
         Core.SendMessage(Actor, "[To accept this quest, enter the command 'accept quest'.]");
         if (Actor.GetProperty <MudObject>("active-quest") != null)
         {
             Core.SendMessage(Actor, "[Accepting this quest will abandon your active quest.]");
         }
         Actor.SetProperty("offered-quest", Quest);
     }
 }
Esempio n. 8
0
 private static void RememberActor(MudObject Player, MudObject Actor)
 {
     if (String.IsNullOrEmpty(Actor.Path))
     {
         return;                                   // Don't remember unimportant mobs.
     }
     if (!Player.HasProperty("introduction memory"))
     {
         Player.SetProperty("introduction memory", new Dictionary <string, bool>());
     }
     Player.GetProperty <Dictionary <String, bool> >("introduction memory").Upsert(Actor.Path, true);
 }
Esempio n. 9
0
        public void Authenticate(MudObject Actor, String UserName, String Password)
        {
            var existingAccount = Accounts.LoadAccount(UserName);

            if (existingAccount == null || Accounts.VerifyAccount(existingAccount, Password) == false)
            {
                Core.SendMessage(Actor, "Could not verify account.");
                return;
            }

            var client = Actor.GetProperty <Client>("client");

            LoginCommandHandler.LogPlayerIn(client as NetworkClient, existingAccount);
        }
Esempio n. 10
0
        /// <summary>
        /// Given a portal, find the opposite side. Portals are used to connect two rooms. The opposite side of 
        /// the portal is assumed to be the portal in the linked room that faces the opposite direction. For example,
        /// if portal A is in room 1, faces west, and is linked to room 2, the opposite side would be the portal
        /// in room 2 that faces east. It does not actually check to see if the opposite side it finds is linked
        /// to the correct room.
        /// </summary>
        /// <param name="Portal"></param>
        /// <returns></returns>
        public static MudObject FindOppositeSide(MudObject Portal)
        {
            // Every object added to a room as a portal will be given the 'portal?' property, with a value of true.
            if (Portal.GetPropertyOrDefault<bool>("portal?", false) == false) return null; // Not a portal.

            var destination = MudObject.GetObject(Portal.GetProperty<String>("link destination")) as Room;
            if (destination == null) return null; // Link is malformed in some way.

            var direction = Portal.GetPropertyOrDefault<Direction>("link direction", Direction.NOWHERE);
            var oppositeDirection = Link.Opposite(direction);
            var mirrorLink = destination.EnumerateObjects().FirstOrDefault(p =>
                p.GetBooleanProperty("portal?") && p.GetPropertyOrDefault<Direction>("link direction", Direction.NOWHERE) == oppositeDirection);
            return mirrorLink;
        }
Esempio n. 11
0
        private static bool RecallActor(MudObject Player, MudObject Actor)
        {
            if (String.IsNullOrEmpty(Actor.Path))
            {
                return(false);                                  // Some mob.
            }
            if (!Player.HasProperty("introduction memory"))
            {
                return(false);
            }
            var memory = Player.GetProperty <Dictionary <String, bool> >("introduction memory");

            if (!memory.ContainsKey(Actor.Path))
            {
                return(false);
            }
            return(memory[Actor.Path]);
        }
Esempio n. 12
0
        public static void SendMessage(MudObject Actor, String Message, params Object[] MentionedObjects)
        {
            if (String.IsNullOrEmpty(Message))
            {
                return;
            }
            if (Core.SilentFlag)
            {
                return;
            }
            Core.OutputQueryTriggered = true;

            if (Actor != null)
            {
                var client = Actor.GetProperty <Client>("client");
                if (client != null)
                {
                    Core.PendingMessages.Add(new PendingMessage(client, Core.FormatMessage(Actor, Message, MentionedObjects)));
                }
            }
        }
Esempio n. 13
0
        public void Authenticate(MudObject Actor, String UserName, String Password)
        {
            var existingAccount = Accounts.LoadAccount(UserName);

            if (existingAccount != null)
            {
                Core.SendMessage(Actor, "Account already exists.");
                return;
            }

            var newAccount = Accounts.CreateAccount(UserName, Password);

            if (newAccount == null)
            {
                Core.SendMessage(Actor, "Could not create account.");
                return;
            }

            var client = Actor.GetProperty <Client>("client");

            LoginCommandHandler.LogPlayerIn(client as NetworkClient, newAccount);
        }
Esempio n. 14
0
        public List <MudObject> GetObjects(PossibleMatch State, MatchContext Context)
        {
            MudObject source = null;

            if (!String.IsNullOrEmpty(LocutorArgument))
            {
                source = State[LocutorArgument] as MudObject;
            }
            else if (Context.ExecutingActor.HasProperty("interlocutor"))
            {
                source = Context.ExecutingActor.GetProperty <MudObject>("interlocutor");
            }

            if (source != null)
            {
                if (source.HasProperty("conversation-topics"))
                {
                    return(new List <MudObject>(source.GetProperty <List <MudObject> >("conversation-topics").Where(t => Core.GlobalRules.ConsiderCheckRuleSilently("topic available?", Context.ExecutingActor, source, t) == CheckResult.Allow)));
                }
            }

            return(new List <MudObject>());
        }