public static string TeleportToQuest(Player player, Random rand = null)
        {
            var lastAttackTimeAgo = Math.Abs(DateTime.UtcNow.Subtract(player.GetLastCombatTimestamp()).TotalMinutes);

            if (lastAttackTimeAgo < TurnTimesStatics.GetMinutesSinceLastCombatBeforeQuestingOrDuelling())
            {
                return(null);
            }

            var quests = QuestProcedures.GetAllAvailableQuestsForPlayer(player, PvPWorldStatProcedures.GetWorldTurnNumber());

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

            rand = rand ?? new Random();
            var index = rand.Next(quests.Count());
            var quest = quests.ToArray()[index];

            if (!Teleport(player, quest.dbName, rand.Next(2) == 0))
            {
                return(null);
            }

            return($"You notice a gold chalice on the shelf, its engraving obscured by dirt.  You decide to blow the dust off and a cloud fills the room.  A frail man with a long white beard and crooked staff emerges from the mist.  \"So, it's a quest you seek?\" comes his shrill, wheezing voice.  \"Well, I have just the thing.  Seek out your victory, young mage.\"  He hands you a scroll.  At the top it is written <b>{quest.Name}</b>.  As you take it you feel yourself transported to a far-off place...");
        }
Ejemplo n.º 2
0
 public void Cant_start_quests_if_level_too_high()
 {
     questStart.MinStartLevel = 3;
     player.Level             = 2;
     Assert.That(QuestProcedures.PlayerCanBeginQuest(player, questStart, questPlayerStatuses, turnNumber),
                 Is.False);
 }
Ejemplo n.º 3
0
        public void Should_not_print_details_for_required_variable()
        {
            b.AddStrictRequirement((int)QuestStatics.RequirementType.Variable, "variable", 0);
            var q = b.GetQuestConnection();

            Assert.That(QuestProcedures.GetRequirementsAsString(q, buffs), Is.Empty);
        }
Ejemplo n.º 4
0
        public virtual ActionResult AbandonConfirm()
        {
            var myMembershipId = User.Identity.GetUserId();
            var me             = PlayerProcedures.GetPlayerFromMembership(myMembershipId);

            // assert that this player is in a quest
            if (me.InQuest <= 0)
            {
                TempData["Error"] = "You are not in a quest.";
                return(RedirectToAction(MVC.PvP.Play()));
            }


            // assert player is not currently in a quest with an end state
            var state = QuestProcedures.GetQuestState(me.InQuestState);

            if (state.QuestEnds != null && state.QuestEnds.Any())
            {
                TempData["Error"]    = "It is too late to abandon this quest.";
                TempData["SubError"] = "You must accept the consequences of your actions, be they for good or ill!";
                return(RedirectToAction(MVC.Quest.Questing()));
            }

            QuestProcedures.PlayerEndQuest(me, (int)QuestStatics.QuestOutcomes.Failed);

            TempData["Result"] = "You abandoned your quest.";
            return(RedirectToAction(MVC.PvP.Play()));
        }
Ejemplo n.º 5
0
        public virtual ActionResult Quest()
        {
            IQuestRepository repo = new EFQuestRepository();

            var myMembershipId = User.Identity.GetUserId();
            var me             = PlayerProcedures.GetPlayerFromMembership(myMembershipId);

            var unopenedMessageCount = DomainRegistry.Repository.FindSingle(new GetUnreadMessageCountByPlayer {
                OwnerId = me.Id
            });
            var openedUnreadMessageCount = DomainRegistry.Repository.FindSingle(new GetReadAndMarkedAsUnreadMessageCountByPlayer {
                OwnerId = me.Id
            });

            var output = new QuestPlayPageViewModel();

            output.Player               = PlayerProcedures.GetPlayerFormViewModel(me.Id);
            output.QuestStart           = QuestProcedures.GetQuest(me.InQuest);
            output.QuestState           = QuestProcedures.GetQuestState(me.InQuestState);
            output.QuestConnections     = QuestProcedures.GetChildQuestConnections(me.InQuestState);
            output.BuffBox              = ItemProcedures.GetPlayerBuffs(me);
            output.QuestPlayerVariables = QuestProcedures.GetAllQuestPlayerVariablesFromQuest(output.QuestStart.Id, me.Id);
            output.HasNewMessages       = unopenedMessageCount != 0;
            output.UnreadMessageCount   = unopenedMessageCount + openedUnreadMessageCount;

            ViewBag.ErrorMessage    = TempData["Error"];
            ViewBag.SubErrorMessage = TempData["SubError"];
            ViewBag.Result          = TempData["Result"];

            output.SetConnectionText((string)TempData["ConnectionText"]);

            return(PartialView(MVC.Quest.Views.Quest, output));
        }
Ejemplo n.º 6
0
 public void Cant_start_quests_if_not_female_and_needs_female()
 {
     questStart.RequiredGender = (int)QuestStatics.Gender.Female;
     player.Gender             = PvPStatics.GenderMale;
     Assert.That(QuestProcedures.PlayerCanBeginQuest(player, questStart, questPlayerStatuses, turnNumber),
                 Is.False);
 }
Ejemplo n.º 7
0
        public void Should_print_correct_choice_text_1_strict_requirement()
        {
            b.AddStrictRequirement((int)QuestStatics.RequirementType.Luck, "150", (int)QuestStatics.Operator.Greater_Than);
            var q = b.GetQuestConnection();

            Assert.That(QuestProcedures.GetRequirementsAsString(q, buffs), Is.EqualTo("[> 150 Luck]"));
        }
Ejemplo n.º 8
0
        public void Should_hide_only_hidden_requirements_when_mixed()
        {
            b.AddStrictRequirement((int)QuestStatics.RequirementType.Variable, "variable", 0);
            b.AddStrictRequirement((int)QuestStatics.RequirementType.Succour, "25", (int)QuestStatics.Operator.Greater_Than_Or_Equal);
            var q = b.GetQuestConnection();

            Assert.That(QuestProcedures.GetRequirementsAsString(q, buffs), Is.EqualTo("[>= 25 Regeneration]"));
        }
Ejemplo n.º 9
0
        public virtual JsonResult ShowAllUsedQuestVariables(int Id)
        {
            IQuestRepository repo = new EFQuestRepository();

            var output = QuestProcedures.GetAllPossibleVariablesNamesInQuest(Id);

            return(Json(output, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 10
0
        public virtual ActionResult Questing()
        {
            var myMembershipId = User.Identity.GetUserId();
            var me             = PlayerProcedures.GetPlayerFromMembership(myMembershipId);

            var questStart = QuestProcedures.GetQuest(me.InQuest);

            return(View(MVC.Quest.Views.Questing, questStart));
        }
Ejemplo n.º 11
0
        public void Should_print_correct_choice_text_1_roll_requirement()
        {
            b.AddRollRequirement((int)QuestStatics.RequirementType.Luck, 1.25f, 10);
            var q = b.GetQuestConnection();

            buffs.FromEffects_Luck = 50;

            Assert.That(QuestProcedures.GetRequirementsAsString(q, buffs), Is.EqualTo("[Luck - 72.5%]"));
        }
Ejemplo n.º 12
0
        // GET: QuestWriter
        public virtual ActionResult Index()
        {
            var output = QuestProcedures.GetAllQuestStarts().ToList();

            ViewBag.ErrorMessage    = TempData["Error"];
            ViewBag.SubErrorMessage = TempData["SubError"];
            ViewBag.Result          = TempData["Result"];

            return(View(MVC.QuestWriter.Views.Index, output));
        }
Ejemplo n.º 13
0
 public void Cant_start_quests_if_quest_already_completed()
 {
     questPlayerStatuses.Add(new QuestPlayerStatus
     {
         QuestId = fakeTestId,
         Outcome = (int)QuestStatics.QuestOutcomes.Completed
     });
     Assert.That(QuestProcedures.PlayerCanBeginQuest(player, questStart, questPlayerStatuses, turnNumber),
                 Is.False);
 }
Ejemplo n.º 14
0
        public void Should_print_correct_choice_text_2_strict_requirement()
        {
            b.AddStrictRequirement((int)QuestStatics.RequirementType.Luck, "150", (int)QuestStatics.Operator.Greater_Than);
            b.AddStrictRequirement((int)QuestStatics.RequirementType.Perception, "35", (int)QuestStatics.Operator.Equal_To);

            var q = b.GetQuestConnection();

            buffs.FromEffects_Luck = 50;

            Assert.That(QuestProcedures.GetRequirementsAsString(q, buffs), Is.EqualTo("[> 150 Luck, = 35 Perception]"));
        }
Ejemplo n.º 15
0
 public void Can_start_quests_if_quest_not_recently_failed()
 {
     questPlayerStatuses.Add(new QuestPlayerStatus
     {
         QuestId       = fakeTestId,
         Outcome       = (int)QuestStatics.QuestOutcomes.Failed,
         LastEndedTurn = turnNumber - QuestStatics.QuestFailCooldownTurnLength - 1
     });
     Assert.That(QuestProcedures.PlayerCanBeginQuest(player, questStart, questPlayerStatuses, turnNumber),
                 Is.True);
 }
Ejemplo n.º 16
0
        public void Should_print_correct_choice_text_mixed_requirements()
        {
            b.AddStrictRequirement((int)QuestStatics.RequirementType.Fortitude, "10", (int)QuestStatics.Operator.Greater_Than_Or_Equal);
            b.AddRollRequirement((int)QuestStatics.RequirementType.Magicka, 1.0f, -50);
            var q = b.GetQuestConnection();

            buffs.FromEffects_Magicka = 60;

            Assert.That(QuestProcedures.GetRequirementsAsString(q, buffs),
                        Is.EqualTo("[>= 10 Fortitude, Magicka - 10%]"));
        }
Ejemplo n.º 17
0
        public void Should_print_correct_choice_text_2_roll_requirements()
        {
            b.AddRollRequirement((int)QuestStatics.RequirementType.Charisma, .5f, 0);
            b.AddRollRequirement((int)QuestStatics.RequirementType.Magicka, .5f, 15);
            var q = b.GetQuestConnection();


            buffs.FromEffects_Charisma = 25;

            Assert.That(QuestProcedures.GetRequirementsAsString(q, buffs),
                        Is.EqualTo("[Charisma - 12.5%, Magicka - 15%]"));
        }
Ejemplo n.º 18
0
        public virtual ActionResult QuestsAvailableHere()
        {
            var myMembershipId = User.Identity.GetUserId();
            var me             = PlayerProcedures.GetPlayerFromMembership(myMembershipId);

            var output = new QuestsAtLocationViewModel
            {
                AllQuests       = QuestProcedures.GetAllQuestStartsAtLocation(me.dbLocationName),
                AvailableQuests = QuestProcedures.GetAvailableQuestsAtLocation(me, PvPWorldStatProcedures.GetWorldTurnNumber()),
            };

            return(View(MVC.Quest.Views.QuestsAvailableHere, output));
        }
Ejemplo n.º 19
0
        public void Can_start_quest_if_prerequisite_test_is_completed()
        {
            questStart.PrerequisiteQuest = 2;

            questPlayerStatuses.Add(new QuestPlayerStatus
            {
                QuestId = 2,
                Outcome = (int)QuestStatics.QuestOutcomes.Completed
            });

            Assert.That(QuestProcedures.PlayerCanBeginQuest(player, questStart, questPlayerStatuses, turnNumber),
                        Is.True);
        }
Ejemplo n.º 20
0
        public virtual JsonResult ShowAllActivePlayerVariables(int Id)
        {
            var myMembershipId = User.Identity.GetUserId();
            var me             = PlayerProcedures.GetPlayerFromMembership(myMembershipId);

            var variables = QuestProcedures.GetAllQuestPlayerVariablesFromQuest(Id, me.Id);

            var output = from v in variables
                         select new
            {
                Name  = v.VariableName,
                Value = v.VariableValue
            };

            return(Json(output, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 21
0
        public virtual ActionResult ResetQuests()
        {
            var myMembershipId = User.Identity.GetUserId();
            var me             = PlayerProcedures.GetPlayerFromMembership(myMembershipId);

            if (!PvPStatics.ChaosMode)
            {
                TempData["Error"] = "You can only do this in chaos mode.";
                return(RedirectToAction(MVC.PvP.Play()));
            }

            QuestProcedures.PlayerClearAllQuestStatuses(me);
            QuestProcedures.ClearQuestPlayerVariables(me.Id, me.InQuest);

            return(RedirectToAction(MVC.PvP.Play()));
        }
Ejemplo n.º 22
0
        public virtual ActionResult QuestConnection(int Id, int QuestId, int FromQuestId, int ToQuestId)
        {
            IQuestRepository repo = new EFQuestRepository();

            var questConnection = repo.QuestConnections.FirstOrDefault(q => q.Id == Id);

            if (questConnection == null)
            {
                questConnection = new QuestConnection
                {
                    QuestId = QuestId,
                    QuestConnectionRequirements = new List <QuestConnectionRequirement>(),
                    QuestStateFromId            = FromQuestId,
                    QuestStateToId     = ToQuestId,
                    QuestStateFailToId = 0,
                };
            }

            var output = new QuestConnectionFormViewModel
            {
                QuestConnection = questConnection,
            };

            if (FromQuestId > 0)
            {
                output.FromQuestState = QuestProcedures.GetQuestState(FromQuestId);
            }
            if (ToQuestId > 0)
            {
                output.ToQuestState = QuestProcedures.GetQuestState(ToQuestId);
            }

            if (questConnection.QuestStateFailToId > 0)
            {
                output.FailToQuestState = QuestProcedures.GetQuestState(questConnection.QuestStateFailToId);
            }

            return(PartialView(MVC.QuestWriter.Views.QuestConnection, output));
        }
Ejemplo n.º 23
0
        public virtual ActionResult ShowAllQuestStarts()
        {
            var output = QuestProcedures.GetAllQuestStarts();

            return(PartialView(MVC.QuestWriter.Views.ShowAllQuestStarts, output));
        }
Ejemplo n.º 24
0
 public void Cant_start_quest_if_prerequisite_test_not_completed()
 {
     questStart.PrerequisiteQuest = 2;
     Assert.That(QuestProcedures.PlayerCanBeginQuest(player, questStart, questPlayerStatuses, turnNumber),
                 Is.False);
 }
Ejemplo n.º 25
0
        public virtual ActionResult Choice(int Id)
        {
            IQuestRepository repo = new EFQuestRepository();

            var myMembershipId = User.Identity.GetUserId();
            var me             = PlayerProcedures.GetPlayerFromMembership(myMembershipId);

            // assert player is animate
            if (me.Mobility != PvPStatics.MobilityFull)
            {
                TempData["Error"] = "You are not animate.";
                return(RedirectToAction(MVC.Quest.Quest()));
            }

            // assert player has enough AP
            if (me.ActionPoints < QuestStatics.ActionAPCost)
            {
                TempData["Error"]    = "You don't have enough action points for this.";
                TempData["SubError"] = "Wait a while; you will get more action points soon.";
                return(RedirectToAction(MVC.Quest.Quest()));
            }

            var currentState      = QuestProcedures.GetQuestState(me.InQuestState);
            var desiredConnection = QuestProcedures.GetQuestConnection(Id);
            var nextState         = QuestProcedures.GetQuestState(desiredConnection.QuestStateToId);

            // assert desired state is in same quest
            if (nextState.QuestId != me.InQuest || desiredConnection.QuestId != me.InQuest)
            {
                TempData["Error"] = "Unavailable";
                return(RedirectToAction(MVC.Quest.Quest()));
            }

            // assert a connection does exist between current state and chosen one
            if (desiredConnection.QuestStateFromId != me.InQuestState)
            {
                TempData["Error"] = "Unavailable";
                return(RedirectToAction(MVC.Quest.Quest()));
            }

            var output = new QuestPlayPageViewModel();

            output.Player               = PlayerProcedures.GetPlayerFormViewModel(me.Id);
            output.QuestStart           = QuestProcedures.GetQuest(me.InQuest);
            output.QuestPlayerVariables = QuestProcedures.GetAllQuestPlayerVariablesFromQuest(output.QuestStart.Id, me.Id);
            var buffs = ItemProcedures.GetPlayerBuffs(me);

            // assert player has the right requirements for this
            if (!QuestProcedures.QuestConnectionIsAvailable(desiredConnection, me, buffs, output.QuestPlayerVariables))
            {
                TempData["Error"] = "You're not able to do that.";
                return(RedirectToAction(MVC.Quest.Quest()));
            }

            // make rolls for pass / fail
            if (desiredConnection.RequiresRolls())
            {
                var passes = QuestProcedures.RollForQuestConnection(desiredConnection, me, buffs, output.QuestPlayerVariables);

                // player fails; reroute to the failure quest state
                if (!passes)
                {
                    nextState = QuestProcedures.GetQuestState(desiredConnection.QuestStateFailToId);
                    TempData["RollResult"] = "fail";
                }
                else
                {
                    TempData["RollResult"] = "pass";
                }
            }
            else
            {
                TempData["RollResult"] = "none";
            }

            QuestProcedures.PlayerSetQuestState(me, nextState);
            QuestProcedures.ProcessQuestStatePreactions(me, nextState);

            var keepPlayerOnline = me.LastActionTimestamp > DateTime.UtcNow.AddMinutes(-TurnTimesStatics.GetOfflineAfterXMinutes());

            PlayerProcedures.ChangePlayerActionMana(-1, 0, 0, me.Id, keepPlayerOnline);

            TempData["ConnectionText"] = desiredConnection.Text;

            return(RedirectToAction(MVC.Quest.Quest()));
        }
Ejemplo n.º 26
0
        public virtual ActionResult StartQuest(int Id)
        {
            var myMembershipId = User.Identity.GetUserId();

            if (PvPStatics.AnimateUpdateInProgress)
            {
                TempData["Error"]    = "Player update portion of the world update is still in progress.";
                TempData["SubError"] = "Try again a bit later when the update has progressed farther along.";
                return(RedirectToAction(MVC.PvP.Play()));
            }

            var me = PlayerProcedures.GetPlayerFromMembership(myMembershipId);

            // assert player is in an okay form to do this
            if (me.Mobility != PvPStatics.MobilityFull)
            {
                TempData["Error"] = "You must be animate in order to begin a quest.";
                return(RedirectToAction(MVC.PvP.Play()));
            }

            // assert that this player is not in a duel
            if (me.InDuel > 0)
            {
                TempData["Error"] = "You must finish your duel before you begin a quest.";
                return(RedirectToAction(MVC.PvP.Play()));
            }

            // assert that this player is not in a quest
            if (me.InQuest > 0)
            {
                TempData["Error"] = "You must finish your current quest before you start another.";
                return(RedirectToAction(MVC.PvP.Play()));
            }

            // assert player has not been in combat recently
            var lastAttackTimeAgo = Math.Abs(Math.Floor(me.GetLastCombatTimestamp().Subtract(DateTime.UtcNow).TotalMinutes));

            if (lastAttackTimeAgo < TurnTimesStatics.GetMinutesSinceLastCombatBeforeQuestingOrDuelling())
            {
                TempData["Error"]    = "You have been in combat too recently in order to begin this quest.";
                TempData["SubError"] = "You must stay out of combat for another " + (TurnTimesStatics.GetMinutesSinceLastCombatBeforeQuestingOrDuelling() - lastAttackTimeAgo) + " minutes.";
                return(RedirectToAction(MVC.PvP.Play()));
            }

            var questStart = QuestProcedures.GetQuest(Id);

            // assert player is in the correct place
            if (me.dbLocationName != questStart.Location)
            {
                TempData["Error"] = "You are not in the correct location to begin this quest.";
                return(RedirectToAction(MVC.PvP.Play()));
            }

            var gameTurnNum = PvPWorldStatProcedures.GetWorldTurnNumber();

            // assert player did not fail or abandon this quest too soon ago
            var lastTurnAttempted = QuestProcedures.GetLastTurnQuestEnded(me, questStart.Id);

            if (PvPWorldStatProcedures.GetWorldTurnNumber() - lastTurnAttempted < QuestStatics.QuestFailCooldownTurnLength)
            {
                TempData["Error"]    = "You recently failed or abandoned this quest.";
                TempData["SubError"] = "You must wait another " + (QuestStatics.QuestFailCooldownTurnLength - (gameTurnNum - lastTurnAttempted)) + " turns before you can attempt this quest again.";
                return(RedirectToAction(MVC.PvP.Play()));
            }

            var questPlayerStatuses = QuestProcedures.GetQuestPlayerStatuses(me);

            var canStartQuest = QuestProcedures.PlayerCanBeginQuest(me, questStart, questPlayerStatuses, gameTurnNum);

            // assert player meets level / game turn requirements for this quest
            if (!canStartQuest)
            {
                TempData["Error"] = "You do not meet all of the criteria to begin this quest.";
                return(RedirectToAction(MVC.PvP.Play()));
            }

            // all checks have passed; start the player on this quest
            QuestProcedures.PlayerBeginQuest(me, questStart);
            LocationLogProcedures.AddLocationLog(me.dbLocationName, "<span class='playerMediatingNotification'><b>" + me.GetFullName() + "</b> began the quest <b>" + questStart.Name + "</b> here.</span>");

            TempData["Result"] = "You started the quest " + questStart.Name + ".";
            return(RedirectToAction(MVC.Quest.Questing()));
        }
Ejemplo n.º 27
0
 public void Cant_start_quests_that_are_not_live()
 {
     questStart.IsLive = false;
     Assert.That(QuestProcedures.PlayerCanBeginQuest(player, questStart, questPlayerStatuses, turnNumber),
                 Is.False);
 }
Ejemplo n.º 28
0
        public virtual ActionResult EndQuest(bool restore)
        {
            var myMembershipId = User.Identity.GetUserId();
            var me             = PlayerProcedures.GetPlayerFromMembership(myMembershipId);

            // assert that this player is in a quest
            if (me.InQuest <= 0)
            {
                TempData["Error"] = "You are not in a quest.";
                return(RedirectToAction(MVC.PvP.Play()));
            }

            var quest = QuestProcedures.GetQuest(me.InQuest);
            var state = QuestProcedures.GetQuestState(me.InQuestState);

            // assert that there is an end state to this quest state
            if (!state.QuestEnds.Any())
            {
                TempData["Error"]    = "You are not yet at the end of your quest!";
                TempData["SubError"] = "If it is impossible for you to continue with this quest, you may abandon it.";
                return(RedirectToAction(MVC.Quest.Quest()));
            }

            var endType = state.QuestEnds.First().EndType;

            // if the player is not animate, either restore them or create a new item for them to exist as
            if (me.Mobility != PvPStatics.MobilityFull)
            {
                if (restore && me.Mobility != PvPStatics.MobilityFull)
                {
                    PlayerProcedures.InstantRestoreToBase(me);
                }
                else if (!restore)
                {
                    var newform = FormStatics.GetForm(me.FormSourceId);
                    ItemProcedures.PlayerBecomesItem(me, newform, null);
                }
            }

            // fail!
            if (endType == (int)QuestStatics.QuestOutcomes.Failed)
            {
                QuestProcedures.PlayerEndQuest(me, (int)QuestStatics.QuestOutcomes.Failed);
                QuestProcedures.ClearQuestPlayerVariables(me.Id, me.InQuest);

                StatsProcedures.AddStat(me.MembershipId, StatsProcedures.Stat__QuestsFailed, 1);

                TempData["Result"] = "You unfortunately failed the quest <b>" + quest.Name + "</b>.  Better luck next time!  If there is one...";
                return(RedirectToAction(MVC.PvP.Play()));
            }

            // pass!
            var victoryMessage = QuestProcedures.PlayerEndQuest(me, (int)QuestStatics.QuestOutcomes.Completed);

            QuestProcedures.ClearQuestPlayerVariables(me.Id, me.InQuest);

            StatsProcedures.AddStat(me.MembershipId, StatsProcedures.Stat__QuestsPassed, 1);

            TempData["Result"] = "Congratulations, you completed the quest <b>" + quest.Name + "</b>!" + victoryMessage;

            return(RedirectToAction(MVC.PvP.Play()));
        }