Ejemplo n.º 1
0
        public virtual ActionResult SetSoulbindingConsent(bool isConsenting)
        {
            var me = PlayerProcedures.GetPlayerFromMembership(User.Identity.GetUserId());

            try
            {
                TempData["Result"] = DomainRegistry.Repository.Execute(new SetSoulbindingConsent {
                    PlayerId = me.Id, IsConsenting = isConsenting
                });
            }
            catch (DomainException e)
            {
                TempData["Error"] = e.Message;
            }

            IItemRepository itemRep     = new EFItemRepository();
            var             inanimateMe = DomainRegistry.Repository.FindSingle(new GetItemByFormerPlayer {
                PlayerId = me.Id
            });

            if (inanimateMe.Owner != null)
            {
                var formRepo = new EFDbStaticFormRepository();
                var form     = formRepo.DbStaticForms.FirstOrDefault(f => f.Id == me.FormSourceId);

                if (isConsenting)
                {
                    PlayerLogProcedures.AddPlayerLog(inanimateMe.Owner.Id, $"{me.GetFullName()}, your {form.FriendlyName}, has agreed to let you soulbind them!", true);
                }
                else
                {
                    PlayerLogProcedures.AddPlayerLog(inanimateMe.Owner.Id, $"{me.GetFullName()}, your {form.FriendlyName}, has withdrawn their soulbinding consent.", false);
                }
            }

            if (isConsenting)
            {
                PlayerLogProcedures.AddPlayerLog(me.Id, $"You have consented to soulbinding.", false);
            }
            else
            {
                PlayerLogProcedures.AddPlayerLog(me.Id, $"You have withdrawn soulbinding consent.", false);
            }

            return(RedirectToAction(MVC.PvP.Play()));
        }
Ejemplo n.º 2
0
        public virtual ActionResult MyBaseForms()
        {
            var myMembershipId = User.Identity.GetUserId();
            var me             = PlayerProcedures.GetPlayerFromMembership(myMembershipId);

            var customRepo  = new EFContributorCustomFormRepository();
            var customForms = customRepo.ContributorCustomForms.Where(c => c.OwnerMembershipId == myMembershipId)
                              .Select(c => c.CustomForm).ToList();

            var formRepo  = new EFDbStaticFormRepository();
            var baseForms = formRepo.DbStaticForms.Where(f => f.FriendlyName == "Regular Guy" || f.FriendlyName == "Regular Girl").ToArray();

            // Shuffle non-custom base forms so players don't always pick the first one
            var rand = new Random();

            for (var backstop = baseForms.Length; backstop > 1; backstop--)
            {
                var dest = backstop - 1;
                var src  = rand.Next(0, backstop);
                var temp = baseForms[dest];
                baseForms[dest] = baseForms[src];
                baseForms[src]  = temp;
            }

            if (me.Mobility == PvPStatics.MobilityFull)
            {
                ViewBag.CurrentForm = me.FormSourceId;
            }
            ViewBag.CurrentBaseForm = me.OriginalFormSourceId;

            if (!customForms.Any(f => f.Id == me.OriginalFormSourceId))
            {
                var currentBase = formRepo.DbStaticForms.FirstOrDefault(f => f.Id == me.OriginalFormSourceId);

                if (currentBase != null)
                {
                    customForms.Add(currentBase);
                }
            }

            customForms.AddRange(baseForms);

            return(View(MVC.Settings.Views.MyBaseForms, customForms));
        }
Ejemplo n.º 3
0
        public static string GetMCFriendlyName(int id)
        {
            var formRepo = new EFDbStaticFormRepository();
            var form     = formRepo.DbStaticForms.SingleOrDefault(f => f.Id == id);

            if (form.Id == MindControlStatics.MindControl__MovementFormSourceId)
            {
                return("Forced March");
            }
            else if (form.Id == MindControlStatics.MindControl__StripFormSourceId)
            {
                return("Take a Load Off!");
            }
            else if (form.Id == MindControlStatics.MindControl__MeditateFormSourceId)
            {
                return("Am I Bugging You?");
            }
            else
            {
                return("ERROR:  UNKNOWN");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Allows a player to claim a new base form if they have earned one.
        /// </summary>
        /// <returns></returns>
        public virtual ActionResult SetBaseForm(int baseId)
        {
            var myMembershipId = User.Identity.GetUserId();
            var me             = PlayerProcedures.GetPlayerFromMembership(myMembershipId);

            if (baseId == me.OriginalFormSourceId)
            {
                TempData["Error"] = "You already have this form selected as your base.";
                return(RedirectToAction(MVC.PvP.Play()));
            }

            // Prevent switching to existing form as a means of quickly escaping a TG orb's effects
            if (baseId == me.FormSourceId && me.Mobility == PvPStatics.MobilityFull)
            {
                TempData["Error"] = "You cannot select your current form as your base form.";
                return(RedirectToAction(MVC.PvP.Play()));
            }

            // Look for a match among custom forms
            IContributorCustomFormRepository repo = new EFContributorCustomFormRepository();
            var match = repo.ContributorCustomForms.Where(c => c.OwnerMembershipId == myMembershipId &&
                                                          c.CustomForm.Id == baseId)
                        .Select(c => c.CustomForm).FirstOrDefault();

            if (match == null)
            {
                // Look for a match among standard starter forms
                var formRepo = new EFDbStaticFormRepository();
                match = formRepo.DbStaticForms.Where(f => f.Id == baseId &&
                                                     (f.FriendlyName == "Regular Guy" || f.FriendlyName == "Regular Girl")).FirstOrDefault();

                if (match == null)
                {
                    TempData["Error"] = "You do not own that custom base form.";
                    return(RedirectToAction(MVC.PvP.Play()));
                }
            }

            var instant = false;

            // When player is already in their base form change them instantly.
            if (me.FormSourceId == me.OriginalFormSourceId)
            {
                PlayerProcedures.SetCustomBase(me, baseId);
                me.OriginalFormSourceId = baseId;
                PlayerProcedures.InstantRestoreToBase(me);
                instant = true;
            }
            else
            {
                PlayerProcedures.SetCustomBase(me, baseId);
            }

            if (me.Mobility == PvPStatics.MobilityFull)
            {
                if (instant)
                {
                    TempData["Result"] = $"You are suddenly overwhelmed as you spontaneously transform into a {match.FriendlyName}!";
                }
                else
                {
                    TempData["Result"] = $"Your inner {match.FriendlyName} is begging to be let out, if only you could return yourself to base form...";
                }
            }
            else
            {
                TempData["Result"] = $"Your dreams of becoming a {match.FriendlyName} could come true, if only you could return to animacy...";
            }

            return(RedirectToAction(MVC.PvP.Play()));
        }
Ejemplo n.º 5
0
        internal static BountyInfo BountyDetails(Player player, int effectId)
        {
            var effect = MAPPINGS.FirstOrDefault(e => e.EffectSourceId == effectId);

            if (effect == null || !EffectProcedures.PlayerHasEffect(player, effect.EffectSourceId))
            {
                return(null);
            }

            var possibleFormSourceIds = JokeShopProcedures.Forms(e => e.Category == effect.Category).Select(e => e.FormSourceId).ToArray();
            var numFormSourceIds      = possibleFormSourceIds.Count();

            if (numFormSourceIds == 0)
            {
                return(null);
            }

            var playerEffect = EffectProcedures.GetPlayerEffects2(player.Id).FirstOrDefault(e => e.dbEffect.EffectSourceId == effect.EffectSourceId);

            if (playerEffect == null || playerEffect.dbEffect.Duration == 0)
            {
                return(null);
            }

            var duration = playerEffect.dbEffect.Duration;

            if (duration <= 0)
            {
                return(null);
            }

            var turn = PvPStatics.LastGameTurn;

            if (turn == 0)
            {
                // Check server hasn't been restarted mid-game (in which case PvPStatics.LastGameTurn is not accurate)
                var worldStats = DomainRegistry.Repository.FindSingle(new GetWorld());
                turn = worldStats.TurnNumber;
            }

            var expiresTurn  = turn + duration;
            var formIndex    = player.Id + expiresTurn;
            var formSourceId = possibleFormSourceIds[formIndex % possibleFormSourceIds.Count()];

            // Locate the desired form
            IDbStaticFormRepository formsRepo = new EFDbStaticFormRepository();
            var form = formsRepo.DbStaticForms.FirstOrDefault(f => f.Id == formSourceId);

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

            // Calculate the reward that could be claimed right now
            var reward = Math.Min(MAXIMUM_REWARD, BASE_REWARD + (MAXIMUM_REWARD - BASE_REWARD) * duration / TURNS_OF_BOUNTY);

            if (form.MobilityType == PvPStatics.MobilityFull)
            {
                reward /= 2;
            }

            var category = MAPPINGS.Where(m => m.EffectSourceId == effect.EffectSourceId).Select(m => m.Category).FirstOrDefault();

            return(new BountyInfo {
                PlayerName = player.GetFullName(), Form = form, ExpiresTurn = expiresTurn, CurrentReward = reward, Category = category
            });
        }
Ejemplo n.º 6
0
        public static string GiveInanimateXP(string membershipId, bool isWhitelist)
        {
            IInanimateXPRepository inanimXpRepo = new EFInanimateXPRepository();
            IItemRepository        itemRep      = new EFItemRepository();

            // get the current level of this player based on what item they are
            var me = PlayerProcedures.GetPlayerFromMembership(membershipId);
            var inanimateMeHack = DomainRegistry.Repository.FindSingle(new GetItemByFormerPlayer {
                PlayerId = me.Id
            });
            var inanimateMe = itemRep.Items.FirstOrDefault(i => i.Id == inanimateMeHack.Id); // TODO: Replace with proper Command

            var currentGameTurn = PvPWorldStatProcedures.GetWorldTurnNumber();

            decimal xpGain = 0;

            // get the number of inanimate accounts under this IP
            IPlayerRepository playerRepo  = new EFPlayerRepository();
            decimal           playerCount = playerRepo.Players.Count(p => p.IpAddress == me.IpAddress && (p.Mobility == PvPStatics.MobilityInanimate || p.Mobility == PvPStatics.MobilityPet) && p.BotId == AIStatics.ActivePlayerBotId);

            if (playerCount == 0 || isWhitelist)
            {
                playerCount = 1;
            }

            var xp = inanimXpRepo.InanimateXPs.FirstOrDefault(i => i.OwnerId == me.Id);

            if (xp == null)
            {
                xp = new InanimateXP
                {
                    OwnerId             = me.Id,
                    Amount              = xpGain / playerCount,
                    TimesStruggled      = -6 * me.Level,
                    LastActionTimestamp = DateTime.UtcNow,
                    LastActionTurnstamp = currentGameTurn - 1,
                };

                if (me.Mobility == PvPStatics.MobilityInanimate)
                {
                    StatsProcedures.AddStat(me.MembershipId, StatsProcedures.Stat__InanimateXPEarned, (float)xpGain);
                }
                else if (me.Mobility == PvPStatics.MobilityPet)
                {
                    StatsProcedures.AddStat(me.MembershipId, StatsProcedures.Stat__PetXPEarned, (float)xpGain);
                }
            }
            else
            {
                double turnsSinceLastAction = currentGameTurn - xp.LastActionTurnstamp;

                if (turnsSinceLastAction > TurnTimesStatics.GetItemMaxTurnsBuildup())
                {
                    turnsSinceLastAction = TurnTimesStatics.GetItemMaxTurnsBuildup();
                }

                if (turnsSinceLastAction < 0)
                {
                    turnsSinceLastAction = 0;
                }

                xpGain += Convert.ToDecimal(turnsSinceLastAction) * InanimateXPStatics.XPGainPerInanimateAction;
                xpGain  = xpGain / playerCount;

                if (me.Mobility == PvPStatics.MobilityInanimate)
                {
                    StatsProcedures.AddStat(me.MembershipId, StatsProcedures.Stat__InanimateXPEarned, (float)xpGain);
                }
                else if (me.Mobility == PvPStatics.MobilityPet)
                {
                    StatsProcedures.AddStat(me.MembershipId, StatsProcedures.Stat__PetXPEarned, (float)xpGain);
                }

                xp.Amount             += xpGain;
                xp.TimesStruggled     -= 2 * Convert.ToInt32(turnsSinceLastAction);
                xp.LastActionTimestamp = DateTime.UtcNow;
                xp.LastActionTurnstamp = currentGameTurn;
            }

            var resultMessage = "  ";

            if (xp.Amount >= Convert.ToDecimal(ItemProcedures.GetXPRequiredForItemPetLevelup(inanimateMe.Level)))
            {
                xp.Amount -= Convert.ToDecimal(ItemProcedures.GetXPRequiredForItemPetLevelup(inanimateMe.Level));
                inanimateMe.Level++;
                itemRep.SaveItem(inanimateMe);

                resultMessage += $"  You have gained {xpGain:0.#} xp.  <b>Congratulations, you have gained a level!  Your owner will be so proud...</b>";

                var wearerMessage = "<span style='color: darkgreen'>" + me.FirstName + " " + me.LastName + ", currently your " + ItemStatics.GetStaticItem(inanimateMe.ItemSourceId).FriendlyName + ", has gained a level!  Treat them kindly and they might keep helping you out...</span>";

                // now we need to change the owner's max health or mana based on this leveling
                if (inanimateMe.OwnerId > 0)
                {
                    PlayerLogProcedures.AddPlayerLog((int)inanimateMe.OwnerId, wearerMessage, true);
                    var inanimateMePlus = ItemProcedures.GetItemViewModel(inanimateMe.Id);

                    if (inanimateMePlus.Item.HealthBonusPercent != 0.0M || inanimateMePlus.Item.ManaBonusPercent != 0.0M)
                    {
                        var myowner = playerRepo.Players.FirstOrDefault(p => p.Id == inanimateMe.OwnerId);

                        var healthChange = PvPStatics.Item_LevelBonusModifier * inanimateMePlus.Item.HealthBonusPercent;
                        var manaChange   = PvPStatics.Item_LevelBonusModifier * inanimateMePlus.Item.ManaBonusPercent;

                        myowner.MaxHealth += healthChange;
                        myowner.MaxMana   += manaChange;

                        if (myowner.MaxHealth < 1)
                        {
                            myowner.MaxHealth = 1;
                        }

                        if (myowner.MaxMana < 1)
                        {
                            myowner.MaxMana = 1;
                        }

                        if (myowner.Health > myowner.MaxHealth)
                        {
                            myowner.Health = myowner.MaxHealth;
                        }

                        if (myowner.Mana > myowner.MaxMana)
                        {
                            myowner.Mana = myowner.MaxMana;
                        }

                        playerRepo.SavePlayer(myowner);
                    }
                }
            }
            else
            {
                resultMessage = $"  You have gained {xpGain:0.#} xp.  ({xp.Amount:0.#}/{ItemProcedures.GetXPRequiredForItemPetLevelup(inanimateMe.Level):0.#} to next level).";
            }

            inanimXpRepo.SaveInanimateXP(xp);

            // lock the player into their fate if their inanimate XP gets too high
            if (xp.TimesStruggled <= TurnTimesStatics.GetStruggleXPBeforeItemPermanentLock() * .5 && xp.TimesStruggled > TurnTimesStatics.GetStruggleXPBeforeItemPermanentLock() && !inanimateMe.IsPermanent)
            {
                resultMessage += "  Careful, if you keep doing this you may find yourself stuck in your current form forever...";
            }

            if (xp.TimesStruggled <= TurnTimesStatics.GetStruggleXPBeforeItemPermanentLock() && !inanimateMe.IsPermanent)
            {
                inanimateMe.IsPermanent = true;
                itemRep.SaveItem(inanimateMe);
                DomainRegistry.Repository.Execute(new RemoveSoulbindingOnPlayerItems {
                    PlayerId = me.Id
                });
                DomainRegistry.Repository.Execute(new DropAllItems {
                    PlayerId = me.Id, IgnoreRunes = false
                });

                var formRepo = new EFDbStaticFormRepository();
                var form     = formRepo.DbStaticForms.FirstOrDefault(f => f.Id == me.FormSourceId);

                if (inanimateMe.OwnerId != null && form != null)
                {
                    PlayerLogProcedures.AddPlayerLog(inanimateMe.OwnerId.Value, $"{me.GetFullName()} has locked and is now unable to escape their form as your {form.FriendlyName}!", true);
                }

                PlayerLogProcedures.AddPlayerLog(me.Id, $"You have locked in your current form as a {form.FriendlyName}!", false);
                resultMessage += "  <b>You find the last of your old human self slip away as you permanently embrace your new form.</b>";
            }

            return(resultMessage);
        }