예제 #1
0
        /// <summary>
        /// Checks if the given commandText matched an exit in the current room.
        /// If there is a match the correctly formatted command is returned, else null is.
        /// </summary>
        /// <param name="commandText">User entered command.</param>
        /// <returns>Formatted command for procesing or null.</returns>
        private string CheckRoomExitCodes(string commandText)
        {
            SMCharacter smc = new SlackMud().GetCharacter(this.UserID);

            if (smc == null)
            {
                return(null);
            }

            // Get a list of all exits.
            List <SMExit> exits = smc.GetRoom().RoomExits;

            if (exits == null || !exits.Any())
            {
                return(null);
            }

            // Loop through the exits comparing the commandText to the shortcut.
            foreach (SMExit exit in exits)
            {
                if (exit.Shortcut.ToLower() == commandText.ToLower())
                {
                    return($"move {exit.Shortcut}");
                }
            }

            return(null);
        }
예제 #2
0
        /// <summary>
        /// Character "Shout" method
        /// </summary>
        /// <param name="speech">What the character is "Shouting"</param>
        /// <param name="charSpeaking">The character who is speaking</param>
        public void ChatShout(string speech, SMCharacter charSpeaking)
        {
            // variable for the message sending used later.
            string message;

            // Send the message to all people connected to the room
            foreach (SMCharacter smc in this.GetPeople())
            {
                // construct the local message to be sent.
                message = this.Formatter.Bold(charSpeaking.GetFullName() + " shouts:", 0) + " \"" + speech + "\"";
                this.ChatSendMessage(smc, message);
            }

            // Send a message to people connected to rooms around this room
            foreach (SMExit sme in this.RoomExits)
            {
                // Get the room details from the exit id
                SMRoom otherRooms = new SMRoom();

                otherRooms = new SlackMud().GetRoom(sme.RoomID);

                // Get the "from" location
                SMExit smre = otherRooms.RoomExits.FirstOrDefault(smef => smef.RoomID == this.RoomID);

                // Construct the message
                message = this.Formatter.Italic("Someone shouts from " + smre.Description + " (" + smre.Shortcut + "):", 0) + " \"" + speech + "\"";

                // Send the message to all people connected to the room
                foreach (SMCharacter smcInOtherRoom in otherRooms.GetPeople())
                {
                    otherRooms.ChatSendMessage(smcInOtherRoom, message);
                }
            }
        }
예제 #3
0
        private void ProcessResponse(NPCResponses npr, SMCharacter invokingCharacter, SMItem itemIn)
        {
            // Process each of the response steps
            foreach (NPCResponseStep NPCRS in npr.ResponseSteps)
            {
                // Get the invoking character
                invokingCharacter = new SlackMud().GetCharacter(invokingCharacter.UserID);

                // Check the character is still in the same room
                if (invokingCharacter.RoomID == this.RoomID)
                {
                    switch (NPCRS.ResponseStepType)
                    {
                    case "Conversation":
                        ProcessConversation(NPCRS, invokingCharacter);
                        break;

                    case "Attack":
                        this.Attack(invokingCharacter.GetFullName());
                        break;

                    case "UseSkill":
                        string[] dataSplit = null;
                        if (NPCRS.ResponseStepData.Contains('.'))
                        {
                            dataSplit = NPCRS.ResponseStepData.Split('.');
                        }
                        else
                        {
                            dataSplit[0] = NPCRS.ResponseStepData;
                            dataSplit[1] = null;
                        }

                        this.UseSkill(dataSplit[0], dataSplit[1]);
                        break;

                    case "ItemCheck":
                        // Get the additional data
                        string[] itemType = npr.AdditionalData.Split('.');

                        if (itemType[0] == "Family")
                        {
                            if (itemIn.ItemFamily != itemType[1])
                            {
                                // Drop the item
                                this.GetRoom().AddItem(itemIn);
                                this.GetRoom().Announce(OutputFormatterFactory.Get().Italic($"\"{this.GetFullName()}\" dropped {itemIn.SingularPronoun} {itemIn.ItemName}."));
                            }
                            else
                            {
                                ProcessConversation(NPCRS, invokingCharacter);
                            }
                        }

                        break;
                    }
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Remove an NPC from the memory
        /// </summary>
        /// <param name="charToRemoveID">The id of the NPC to remove</param>
        public void RemoveNPCFromMemory(string charToRemoveID)
        {
            SMNPC        npcchar = new SlackMud().GetNPC(charToRemoveID);
            List <SMNPC> npcl    = (List <SMNPC>)HttpContext.Current.Application["SMNPCs"];

            npcl.Remove(npcchar);
            HttpContext.Current.Application["SMNPCs"] = npcl;
        }
예제 #5
0
        /// <summary>
        /// Send a message to the player
        /// </summary>
        /// <param name="msg">The message to send</param>
        private void SendMessage(string msg)
        {
            SMCharacter smc = new SlackMud().GetCharacter(this.UserID);

            if (smc != null)
            {
                smc.sendMessageToPlayer(msg);
            }
        }
예제 #6
0
        protected void createBtnClick(object sender, EventArgs e)
        {
            bool error = false;

            if ((newUsername.Text != "") && (email.Text != "") && (newPassword.Text != "") && (repeatPassword.Text != ""))
            {
                // TODO need some other checks here for errors i.e. the passwords not being the same!

                if (new SMAccountHelper().CheckUserName(newUsername.Text))
                {
                    string userID = new SlackMUDRPG.CommandClasses.SlackMud().CreateCharacter(
                        Guid.NewGuid().ToString(),
                        "New",
                        "Arrival",
                        "m",
                        "18",
                        "BaseCharacter",
                        null,
                        newUsername.Text,
                        newPassword.Text,
                        false
                        );

                    this.setUserIDCookie(userID);
                    this.setEverLoggedInCookie();

                    // show logout button
                    Master.showLogoutBtn();

                    this.clearCreateForm();
                }
                else
                {
                    // Set the error text
                    lit_CreateError.Text = this.getAlertHtml("Username already taken, please try another.", "warning");
                    error = true;
                }
            }
            else
            {
                // Set the error text
                lit_CreateError.Text = this.getAlertHtml("Please enter details in all fields.");
                error = true;
            }

            if (error)
            {
                // Have to display an error
                pnl_LoginError.Visible  = false;
                pnl_CreateError.Visible = true;

                this.showCreateForm();
            }
        }
예제 #7
0
        /// <summary>
        /// Repeats to last command used or returns an error message.
        /// </summary>
        /// <returns>Empty string if the previous command is successfully handed of to a new thread otherwise an error message.</returns>
        private string HandleRepeats()
        {
            SMCharacter smc = new SlackMud().GetCharacter(this.UserID);

            if (smc != null)
            {
                string previousCommand = smc.GetLastUsedCommand();
                if (previousCommand != null)
                {
                    return(new SMCommandUtility(this.UserID).InitateCommand(previousCommand));
                }
            }

            return(this.GetCommandNotFoundMsg("!"));
        }
예제 #8
0
        /// <summary>
        /// Updates the character running to the command with the details of the command run and when.
        /// </summary>
        private void UpdateLastRunCommand()
        {
            // Exclude login commands as a player must be logged in before its character can be accessed.
            if (this.CmdHelper.cmdName != "login")
            {
                SMCharacter smc = new SlackMud().GetCharacter(this.UserID);

                if (smc != null)
                {
                    smc.LastUsedCommand     = this.CmdHelper.userCmd;
                    smc.LastInteractionDate = DateTime.Now;
                    smc.SaveToApplication();
                }
            }
        }
예제 #9
0
        public void SendMessageToAllPartyMembers(SMParty sp, string messageToSend)
        {
            // Send a message to all the party members to let them know that the person has left.
            foreach (SMPartyMember smpm in sp.PartyMembers)
            {
                // Find the character by their id
                SMCharacter smc = new SlackMud().GetCharacter(smpm.UserID);

                // If the character exists...
                if (smc != null)
                {
                    // Replace the player character element with the actual character name
                    messageToSend = messageToSend.Replace("{playercharacter", smpm.CharacterName);

                    // ... Send the message to the player
                    smc.sendMessageToPlayer(messageToSend);
                }
            }
        }
예제 #10
0
        public override void OnOpen()
        {
            this.userID = this.WebSocketContext.QueryString["userID"];

            WebSocketCollection wsClients = (WebSocketCollection)HttpContext.Current.Application["WSClients"];

            wsClients.Add(this);
            HttpContext.Current.Application["WSClients"] = wsClients;
            string loginResponse = new SlackMUDRPG.CommandClasses.SlackMud().Login(this.userID, false, null, "WS");

            if (loginResponse == null)
            {
                this.Send("Character not found?");
            }
            else if (loginResponse != "")
            {
                this.Send(loginResponse);
                new SMCommandUtility(this.userID).InitateCommand("look");
            }
            ;
        }
예제 #11
0
        /// <summary>
        /// Checks if the given commandText matched a NPC interaction awaiting response.
        /// If there is a match the correctly formatted command is returned, else null is.
        /// </summary>
        /// <param name="commandText">User entered command.</param>
        /// <returns>Formatted command for procesing or null.</returns>
        private string CheckNPCResponses(string commandText)
        {
            SMCharacter smc = new SlackMud().GetCharacter(this.UserID);

            if (smc == null)
            {
                return(null);
            }

            // Get a list of awaiting responses for the characters current room
            List <AwaitingResponseFromCharacter> npcResponses = smc.GetAwaitingResponsesForRoom();

            if (npcResponses != null)
            {
                foreach (AwaitingResponseFromCharacter response in npcResponses)
                {
                    // Check the resonse has not expored
                    if (Utils.GetUnixTime() <= response.TimeOut)
                    {
                        // Loop around the shortcut tokens looking for a match
                        foreach (ShortcutToken token in response.ShortCutTokens)
                        {
                            if (token.ShortCutToken.ToLower() == commandText.ToLower())
                            {
                                return($"resp {token.ShortCutToken}");
                            }

                            if (token.ShortCutToken.ToLower() == "{variable}")
                            {
                                token.ShortCutToken = commandText;

                                return($"resp {token.ShortCutToken}");
                            }
                        }
                    }
                }
            }

            return(null);
        }
예제 #12
0
        public void MoveAllPartyMembersToLocation(string roomIDToMoveTo, string leavingMethod, string enteringMethod, bool processResponses = true)
        {
            // See if the person being invited exists in memory
            List <SMCharacter> characterList = (List <SMCharacter>)HttpContext.Current.Application["SMCharacters"];

            SMRoom smr = new SlackMud().GetRoom(roomIDToMoveTo);

            // Scroll through the party members
            foreach (SMPartyMember smpmToMove in this.PartyMembers)
            {
                // See if the person being invited exists in memory
                SMCharacter smc = characterList.FirstOrDefault(ch => ch.GetFullName() == smpmToMove.CharacterName);

                if (smc != null)
                {
                    // Move the player.
                    smc.ActualMove(smr, leavingMethod, enteringMethod, processResponses);

                    // Save the player move.
                    smc.SaveToApplication();
                }
            }
        }