コード例 #1
0
        public string ExecuteScript(string userId)
        {
            string   message      = null;
            TempChar specificUser = usersCreatingChars.Where(u => u.user.UserID == userId).SingleOrDefault();

            if (specificUser.confirmStep != CreateCharSteps.NONE && specificUser.currentStep != CreateCharSteps.AWAITINGRESPONSE)
            {
                switch (specificUser.confirmStep)
                {
                case CreateCharSteps.CLASS:
                    message = DisplayClassInfo(specificUser.Class);
                    break;

                case CreateCharSteps.RACE:
                    message = DisplayRaceInfo(specificUser.Race);
                    break;
                }
                specificUser.currentStep = CreateCharSteps.AWAITINGRESPONSE;
                return(message);
            }

            if (specificUser != null && specificUser.lastStep != specificUser.currentStep)
            {
                switch (specificUser.currentStep)
                {
                case CreateCharSteps.FIRST_NAME:
                    message = AskForFirstName();
                    specificUser.currentStep = CreateCharSteps.AWAITINGRESPONSE;
                    specificUser.lastStep    = CreateCharSteps.FIRST_NAME;
                    break;

                case CreateCharSteps.LAST_NAME:
                    message = AskForLastName();
                    specificUser.currentStep = CreateCharSteps.AWAITINGRESPONSE;
                    specificUser.lastStep    = CreateCharSteps.LAST_NAME;
                    break;

                case CreateCharSteps.PASSWORD:
                    message = AskForPassword();
                    specificUser.currentStep = CreateCharSteps.AWAITINGRESPONSE;
                    specificUser.lastStep    = CreateCharSteps.PASSWORD;
                    break;

                case CreateCharSteps.PASSWORD_CHECK:
                    message = ReEnterPassword();
                    specificUser.currentStep = CreateCharSteps.AWAITINGRESPONSE;
                    specificUser.lastStep    = CreateCharSteps.PASSWORD_CHECK;
                    break;

                case CreateCharSteps.CLASS:
                    message = AskForClass();
                    specificUser.currentStep = CreateCharSteps.AWAITINGRESPONSE;
                    specificUser.lastStep    = CreateCharSteps.CLASS;
                    break;

                case CreateCharSteps.RACE:
                    message = AskForRace();
                    specificUser.currentStep = CreateCharSteps.AWAITINGRESPONSE;
                    specificUser.lastStep    = CreateCharSteps.RACE;
                    break;

                case CreateCharSteps.GENDER:
                    message = AskForGender();
                    specificUser.currentStep = CreateCharSteps.AWAITINGRESPONSE;
                    specificUser.lastStep    = CreateCharSteps.GENDER;
                    break;

                case CreateCharSteps.LANGUAGE:
                    message = AskForLanguage();
                    specificUser.currentStep = CreateCharSteps.AWAITINGRESPONSE;
                    specificUser.lastStep    = CreateCharSteps.LANGUAGE;
                    break;

                case CreateCharSteps.SKIN_TYPE:
                    message = AskForSkinType();
                    specificUser.currentStep = CreateCharSteps.AWAITINGRESPONSE;
                    specificUser.lastStep    = CreateCharSteps.SKIN_TYPE;
                    break;

                case CreateCharSteps.SKIN_COLOR:
                    message = AskForSkinColor();
                    specificUser.currentStep = CreateCharSteps.AWAITINGRESPONSE;
                    specificUser.lastStep    = CreateCharSteps.SKIN_COLOR;
                    break;

                case CreateCharSteps.BUILD:
                    message = AskForBuildType();
                    specificUser.currentStep = CreateCharSteps.AWAITINGRESPONSE;
                    specificUser.lastStep    = CreateCharSteps.BUILD;
                    break;

                case CreateCharSteps.HAIR_COLOR:
                    message = AskForHairColor();
                    specificUser.currentStep = CreateCharSteps.AWAITINGRESPONSE;
                    specificUser.lastStep    = CreateCharSteps.HAIR_COLOR;
                    break;

                case CreateCharSteps.EYE_COLOR:
                    message = AskForEyeColor();
                    specificUser.currentStep = CreateCharSteps.AWAITINGRESPONSE;
                    specificUser.lastStep    = CreateCharSteps.EYE_COLOR;
                    break;

                case CreateCharSteps.WEIGHT:
                    message = AskForWeight(specificUser.Gender, specificUser.Build);
                    specificUser.currentStep = CreateCharSteps.AWAITINGRESPONSE;
                    specificUser.lastStep    = CreateCharSteps.WEIGHT;
                    break;

                case CreateCharSteps.HEIGHT:
                    message = AskForHeight(specificUser.Race);
                    specificUser.currentStep = CreateCharSteps.AWAITINGRESPONSE;
                    specificUser.lastStep    = CreateCharSteps.HEIGHT;
                    break;

                case CreateCharSteps.SUCCEEDED:
                    Character.Iactor newChar = new Character.Character(specificUser.Race, specificUser.Class, specificUser.Gender, specificUser.Language, specificUser.SkinColor, specificUser.SkinType, specificUser.HairColor, specificUser.EyeColor, specificUser.Build);
                    newChar.FirstName = specificUser.FirstName;
                    newChar.LastName  = specificUser.LastName;
                    newChar.Weight    = specificUser.Weight;
                    newChar.Height    = specificUser.Height;
                    newChar.Password  = specificUser.Password;
                    newChar.Save();     //this creates the ID
                    specificUser.user.Player.ID = newChar.ID;
                    specificUser.user.UserID    = specificUser.user.Player.ID;

                    specificUser.user.Player.Load(specificUser.user.UserID);
                    AssignStatPoints(specificUser.user.Player);
                    specificUser.user.Player.Save();     //we updated the stats now save them.
                    message = "Character created!  Welcome " + specificUser.user.Player.FirstName + " " + specificUser.user.Player.LastName + "!";
                    specificUser.user.CurrentState = User.User.UserState.TALKING;
                    specificUser.user.InBuffer     = "look\r\n";
                    usersCreatingChars.Remove(specificUser);
                    break;

                case CreateCharSteps.AWAITINGRESPONSE:
                default:
                    break;
                }
            }
            else
            {
                if (specificUser != null)
                {
                    if (specificUser.currentStep == CreateCharSteps.LAST_NAME)
                    {
                        message = "A character with that name combination already exists! Select a different last name or name combination.";
                    }
                    else if (specificUser.lastStep == CreateCharSteps.PASSWORD)
                    {
                        message = "Passwords did not match!  Please try again.";
                        specificUser.currentStep = CreateCharSteps.PASSWORD;
                    }
                    else if (specificUser.currentStep == CreateCharSteps.RACE || specificUser.currentStep == CreateCharSteps.GENDER || specificUser.currentStep == CreateCharSteps.LANGUAGE ||
                             specificUser.currentStep == CreateCharSteps.SKIN_TYPE || specificUser.currentStep == CreateCharSteps.SKIN_COLOR || specificUser.currentStep == CreateCharSteps.BUILD)
                    {
                        message = "Invalid selection! Please try again.";
                    }
                    else if (specificUser.currentStep == CreateCharSteps.WEIGHT)
                    {
                        message = "That is an invalid weight for the body type selected! Please choose a weight within the range.";
                    }

                    specificUser.lastStep = CreateCharSteps.NONE;
                }
            }

            return(message);
        }
コード例 #2
0
        public User.User.UserState InsertResponse(string response, string userId)
        {
            User.User.UserState state = User.User.UserState.CREATING_CHARACTER;

            if (string.IsNullOrEmpty(response))
            {
                return(state);
            }

            TempChar specificUser = usersCreatingChars.Where(u => u.user.UserID == userId).SingleOrDefault();

            //Get the confirmation from the previous selection
            if (specificUser.confirmStep != CreateCharSteps.NONE)
            {
                if (!ConfirmSelection(response))
                {
                    specificUser.currentStep = specificUser.confirmStep; //go back to the previous selection
                    specificUser.lastStep    = CreateCharSteps.NONE;
                }
                else
                {
                    specificUser.currentStep = specificUser.nextStep;
                }
                specificUser.confirmStep = CreateCharSteps.NONE;
                return(state);
            }


            if (specificUser != null && specificUser.currentStep == CreateCharSteps.AWAITINGRESPONSE)
            {
                switch (specificUser.lastStep)
                {
                case CreateCharSteps.FIRST_NAME:
                    specificUser.FirstName   = response;
                    specificUser.currentStep = CreateCharSteps.LAST_NAME;
                    specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                    break;

                case CreateCharSteps.LAST_NAME:
                    if (ValidatePlayerName(specificUser.user.UserID, response))
                    {
                        if (String.Compare(response, "name", true) != 0)
                        {
                            specificUser.LastName    = response;
                            specificUser.currentStep = CreateCharSteps.PASSWORD;
                            specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                        }
                        else
                        {
                            specificUser.currentStep = CreateCharSteps.FIRST_NAME;
                            specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                        }
                    }
                    else
                    {
                        specificUser.currentStep = CreateCharSteps.FIRST_NAME;
                        specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                    }
                    break;

                case CreateCharSteps.PASSWORD:
                    specificUser.Password    = response;
                    specificUser.currentStep = CreateCharSteps.PASSWORD_CHECK;
                    specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                    break;

                case CreateCharSteps.PASSWORD_CHECK:
                    if (ValidatePlayerPassword(specificUser.user.UserID, response))
                    {
                        specificUser.Password    = response;
                        specificUser.currentStep = CreateCharSteps.CLASS;
                        specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                    }
                    else
                    {
                        specificUser.currentStep = CreateCharSteps.PASSWORD;
                        specificUser.lastStep    = CreateCharSteps.PASSWORD;
                    }
                    break;

                case CreateCharSteps.CLASS: {
                    if (String.Compare(response.Substring(0, 1), "b", true) != 0)
                    {
                        int selection = 0;
                        int.TryParse(response, out selection);
                        int max = (GetMaxEnum <CharacterEnums.CharacterClass>() / 8) + 1;
                        if (selection >= 1 && selection <= max)
                        {
                            specificUser.Class       = (CharacterEnums.CharacterClass)(1 << selection);
                            specificUser.confirmStep = CreateCharSteps.CLASS;
                            specificUser.currentStep = CreateCharSteps.CLASS;
                            specificUser.nextStep    = CreateCharSteps.GENDER;
                            specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                        }
                        else
                        {
                            specificUser.currentStep = CreateCharSteps.CLASS;
                            specificUser.lastStep    = CreateCharSteps.CLASS;
                        }
                    }
                    else
                    {
                        specificUser.currentStep = CreateCharSteps.FIRST_NAME;
                        specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                    }
                    break;
                }

                case CreateCharSteps.GENDER: {
                    if (String.Compare(response.Substring(0, 1), "b", true) != 0)
                    {
                        int selection = 0;
                        int.TryParse(response, out selection);
                        selection--;
                        if (selection >= 0 && selection <= GetMaxEnum <CharacterEnums.Genders>())
                        {
                            specificUser.Gender      = (CharacterEnums.Genders)selection;
                            specificUser.currentStep = CreateCharSteps.RACE;
                            specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                        }
                        else
                        {
                            specificUser.currentStep = CreateCharSteps.GENDER;
                            specificUser.lastStep    = CreateCharSteps.GENDER;
                        }
                    }
                    else
                    {
                        specificUser.currentStep = CreateCharSteps.CLASS;
                        specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                    }
                    break;
                }

                case CreateCharSteps.RACE: {
                    if (String.Compare(response.Substring(0, 1), "b", true) != 0)
                    {
                        int selection = 0;
                        int.TryParse(response, out selection);
                        selection--;
                        if (selection >= 0 && selection <= GetMaxEnum <CharacterEnums.CharacterRace>())
                        {
                            specificUser.Race        = (CharacterEnums.CharacterRace)selection;
                            specificUser.confirmStep = CreateCharSteps.RACE;
                            specificUser.currentStep = CreateCharSteps.RACE;
                            specificUser.nextStep    = CreateCharSteps.LANGUAGE;
                            specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                        }
                        else
                        {
                            specificUser.currentStep = CreateCharSteps.RACE;
                            specificUser.lastStep    = CreateCharSteps.RACE;
                        }
                    }
                    else
                    {
                        specificUser.currentStep = CreateCharSteps.GENDER;
                        specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                    }

                    break;
                }

                case CreateCharSteps.LANGUAGE: {
                    if (String.Compare(response.Substring(0, 1), "b", true) != 0)
                    {
                        int selection = 0;
                        int.TryParse(response, out selection);
                        selection--;
                        if (selection >= 0 && selection <= GetMaxEnum <CharacterEnums.Languages>())
                        {
                            specificUser.Language    = (CharacterEnums.Languages)selection;
                            specificUser.currentStep = CreateCharSteps.SKIN_TYPE;
                            specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                        }
                        else
                        {
                            specificUser.currentStep = CreateCharSteps.LANGUAGE;
                            specificUser.lastStep    = CreateCharSteps.LANGUAGE;
                        }
                    }
                    else
                    {
                        specificUser.currentStep = CreateCharSteps.RACE;
                        specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                    }
                    break;
                }

                case CreateCharSteps.SKIN_TYPE: {
                    if (String.Compare(response.Substring(0, 1), "b", true) != 0)
                    {
                        int selection = 0;
                        int.TryParse(response, out selection);
                        selection--;
                        if (selection >= 0 && selection <= GetMaxEnum <CharacterEnums.SkinType>())
                        {
                            specificUser.SkinType    = (CharacterEnums.SkinType)selection;
                            specificUser.currentStep = CreateCharSteps.SKIN_COLOR;
                            specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                        }
                        else
                        {
                            specificUser.currentStep = CreateCharSteps.SKIN_TYPE;
                            specificUser.lastStep    = CreateCharSteps.SKIN_TYPE;
                        }
                    }
                    else
                    {
                        specificUser.currentStep = CreateCharSteps.LANGUAGE;
                        specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                    }
                    break;
                }

                case CreateCharSteps.SKIN_COLOR: {
                    if (String.Compare(response.Substring(0, 1), "b", true) != 0)
                    {
                        int selection = 0;
                        int.TryParse(response, out selection);
                        selection--;
                        if (selection >= 0 && selection <= GetMaxEnum <CharacterEnums.SkinColors>())
                        {
                            specificUser.SkinColor   = (CharacterEnums.SkinColors)selection;
                            specificUser.currentStep = CreateCharSteps.HAIR_COLOR;
                            specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                        }
                        else
                        {
                            specificUser.currentStep = CreateCharSteps.SKIN_COLOR;
                            specificUser.lastStep    = CreateCharSteps.SKIN_COLOR;
                        }
                    }
                    else
                    {
                        specificUser.currentStep = CreateCharSteps.SKIN_TYPE;
                        specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                    }
                    break;
                }

                case CreateCharSteps.HAIR_COLOR: {
                    if (String.Compare(response.Substring(0, 1), "b", true) != 0)
                    {
                        int selection = 0;
                        int.TryParse(response, out selection);
                        selection--;
                        if (selection >= 0 && selection <= GetMaxEnum <CharacterEnums.HairColors>())
                        {
                            specificUser.HairColor   = (CharacterEnums.HairColors)selection;
                            specificUser.currentStep = CreateCharSteps.EYE_COLOR;
                            specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                        }
                        else
                        {
                            specificUser.currentStep = CreateCharSteps.HAIR_COLOR;
                            specificUser.lastStep    = CreateCharSteps.HAIR_COLOR;
                        }
                    }
                    else
                    {
                        specificUser.currentStep = CreateCharSteps.SKIN_COLOR;
                        specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                    }
                    break;
                }

                case CreateCharSteps.EYE_COLOR: {
                    if (String.Compare(response.Substring(0, 1), "b", true) != 0)
                    {
                        int selection = 0;
                        int.TryParse(response, out selection);
                        selection--;
                        if (selection >= 0 && selection <= GetMaxEnum <CharacterEnums.EyeColors>())
                        {
                            specificUser.EyeColor    = (CharacterEnums.EyeColors)selection;
                            specificUser.currentStep = CreateCharSteps.BUILD;
                            specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                        }
                        else
                        {
                            specificUser.currentStep = CreateCharSteps.EYE_COLOR;
                            specificUser.lastStep    = CreateCharSteps.EYE_COLOR;
                        }
                    }
                    else
                    {
                        specificUser.currentStep = CreateCharSteps.HAIR_COLOR;
                        specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                    }
                    break;
                }

                case CreateCharSteps.BUILD: {
                    if (String.Compare(response.Substring(0, 1), "b", true) != 0)
                    {
                        int selection = 0;
                        int.TryParse(response, out selection);
                        selection--;
                        if (selection >= 0 && selection <= GetMaxEnum <CharacterEnums.BodyBuild>())
                        {
                            specificUser.Build       = (CharacterEnums.BodyBuild)selection;
                            specificUser.currentStep = CreateCharSteps.WEIGHT;
                            specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                        }
                        else
                        {
                            specificUser.currentStep = CreateCharSteps.BUILD;
                            specificUser.lastStep    = CreateCharSteps.BUILD;
                        }
                    }
                    else
                    {
                        specificUser.currentStep = CreateCharSteps.EYE_COLOR;
                        specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                    }
                    break;
                }

                case CreateCharSteps.WEIGHT: {
                    double temp = 0;
                    double.TryParse(response, out temp);
                    BsonDocument doc  = _generalCollection.FindOneAs <BsonDocument>(Query.EQ("_id", "BodyWeight")).AsBsonDocument;
                    BsonArray    arr  = doc["Genders"].AsBsonArray;
                    BsonArray    arr2 = arr.Where(a => a["type"].AsString == specificUser.Gender.ToString().CamelCaseWord()).SingleOrDefault()["Weights"].AsBsonArray;
                    doc = arr2.Where(a => a.AsBsonDocument["name"] == specificUser.Build.ToString().CamelCaseWord()).SingleOrDefault().AsBsonDocument;
                    double min = doc["min"].AsInt32;         //these need to be converted to doubles in DB
                    double max = doc["max"].AsInt32;

                    if (temp >= min && temp <= max)
                    {
                        specificUser.Weight      = temp;
                        specificUser.currentStep = CreateCharSteps.HEIGHT;
                        specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                    }
                    else
                    {
                        specificUser.currentStep = CreateCharSteps.WEIGHT;
                        specificUser.lastStep    = CreateCharSteps.WEIGHT;
                    }
                    break;
                }

                case CreateCharSteps.HEIGHT: {
                    double temp = 0;
                    double.TryParse(response, out temp);
                    //get the min and max height for each race from DB and validate
                    BsonDocument doc = _generalCollection.FindOneAs <BsonDocument>(Query.EQ("_id", "Heights")).AsBsonDocument;
                    BsonArray    arr = doc["Types"].AsBsonArray;
                    double       min = 0.0d, max = 0.0d;

                    foreach (BsonDocument height in arr)
                    {
                        if (height["Name"] == specificUser.Race.ToString().ToUpper())
                        {
                            min = height["Min"].AsDouble;         //these need to be converted to doubles in DB
                            max = height["Max"].AsDouble;
                            break;
                        }
                    }

                    if (temp >= min && temp <= max)
                    {
                        specificUser.Height      = temp;
                        specificUser.currentStep = CreateCharSteps.SUCCEEDED;
                        specificUser.lastStep    = CreateCharSteps.AWAITINGRESPONSE;
                    }
                    else
                    {
                        specificUser.currentStep = CreateCharSteps.HEIGHT;
                        specificUser.lastStep    = CreateCharSteps.HEIGHT;
                    }

                    break;
                }

                default:
                    //something has gone terribly wrong if we get here
                    break;
                }
            }
            return(state);
        }