public virtual ActionResult SelfCast(int itemId) { var myMembershipId = User.Identity.GetUserId(); var me = PlayerProcedures.GetPlayerFromMembership(myMembershipId); var item = ItemProcedures.GetItemViewModel(itemId); // assert player does own this if (item.dbItem.OwnerId != me.Id) { TempData["Error"] = "You don't own that item."; return(RedirectToAction(MVC.PvP.Play())); } // assert that it is equipped if (!item.dbItem.IsEquipped) { TempData["Error"] = "You cannot use an item you do not have equipped."; return(RedirectToAction(MVC.PvP.Play())); } // assert this item is a transmog if (item.dbItem.ItemSourceId != ItemStatics.AutoTransmogItemSourceId) { TempData["Error"] = "You cannot change form with that item."; return(RedirectToAction(MVC.PvP.Play())); } // assert player has not already used an item this turn if (me.ItemsUsedThisTurn >= PvPStatics.MaxItemUsesPerUpdate) { TempData["Error"] = "You've already used an item this turn."; TempData["SubError"] = "You will be able to use another consumable type item next turn."; return(RedirectToAction(MVC.Item.MyInventory())); } // assert that this player is not in a duel if (me.InDuel > 0) { TempData["Error"] = "You must finish your duel before you use this item."; return(RedirectToAction(MVC.PvP.Play())); } // assert that this player is not in a quest if (me.InQuest > 0) { TempData["Error"] = "You must finish your quest before you use this item."; return(RedirectToAction(MVC.PvP.Play())); } var model = new SelfCastViewModel { ItemId = itemId, Skills = DomainRegistry.Repository.Find(new GetSkillsOwnedByPlayer { playerId = me.Id }).Where(s => s.SkillSource.MobilityType == PvPStatics.MobilityFull) }; return(View(MVC.Item.Views.SelfCast, model)); }
public virtual ActionResult ReadSkillBook(int id) { var myMembershipId = User.Identity.GetUserId(); var me = PlayerProcedures.GetPlayerFromMembership(myMembershipId); // assert player is animate if (me.Mobility != PvPStatics.MobilityFull) { TempData["Error"] = "This curse is too strong to be lifted."; return(RedirectToAction(MVC.PvP.Play())); } // assert player has not already used an item this turn if (me.ItemsUsedThisTurn >= PvPStatics.MaxItemUsesPerUpdate) { TempData["Error"] = "You've already used an item this turn."; TempData["SubError"] = "You will be able to use another consumable next turn."; return(RedirectToAction(MVC.Item.MyInventory())); } var book = ItemProcedures.GetItemViewModel(id); // assert player owns this book if (book.dbItem.OwnerId != me.Id) { TempData["Error"] = "You do not own this book."; return(RedirectToAction(MVC.PvP.Play())); } // make sure that this is actually a book if (book.Item.ConsumableSubItemType != (int)ItemStatics.ConsumableSubItemTypes.Tome) { TempData["Error"] = "You can't read that item!"; TempData["SubError"] = "It's not a book."; return(RedirectToAction(MVC.PvP.Play())); } // assert player hasn't already read this book if (ItemProcedures.PlayerHasReadBook(me, book.dbItem.ItemSourceId)) { TempData["Error"] = "You have already absorbed the knowledge from this book and can learn nothing more from it."; TempData["SubError"] = "Perhaps a friend could use this tome more than you right now."; return(RedirectToAction(MVC.PvP.Play())); } ItemProcedures.DeleteItem(book.dbItem.Id); ItemProcedures.AddBookReading(me, book.dbItem.ItemSourceId); PlayerProcedures.GiveXP(me, 35); PlayerProcedures.AddItemUses(me.Id, 1); StatsProcedures.AddStat(me.MembershipId, StatsProcedures.Stat__LoreBooksRead, 1); TempData["Result"] = "You read your copy of " + book.Item.FriendlyName + ", absorbing its knowledge for 35 XP. The tome slips into thin air so it can provide its knowledge to another mage in a different time and place."; return(RedirectToAction(MVC.PvP.Play())); }
public virtual ActionResult SelfCastSend(int itemId, int skillSourceId) { var myMembershipId = User.Identity.GetUserId(); var me = PlayerProcedures.GetPlayerFromMembership(myMembershipId); // assert player is animate if (me.Mobility != PvPStatics.MobilityFull) { TempData["Error"] = "You must be animate in order to use this."; 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 use this item."; return(RedirectToAction(MVC.PvP.Play())); } // assert that this player is not in a quest if (me.InQuest > 0) { TempData["Error"] = "You must finish your quest before you use this item."; return(RedirectToAction(MVC.PvP.Play())); } // assert player has not already used an item this turn if (me.ItemsUsedThisTurn >= PvPStatics.MaxItemUsesPerUpdate) { TempData["Error"] = "You've already used an item this turn."; TempData["SubError"] = "You will be able to use another consumable type item next turn."; return(RedirectToAction(MVC.Item.MyInventory())); } var item = ItemProcedures.GetItemViewModel(itemId); // assert player does own this if (item.dbItem.OwnerId != me.Id) { TempData["Error"] = "You don't own that item."; return(RedirectToAction(MVC.PvP.Play())); } // assert that it is equipped if (!item.dbItem.IsEquipped) { TempData["Error"] = "You cannot use an item you do not have equipped."; return(RedirectToAction(MVC.PvP.Play())); } // assert this item is a transmog if (item.dbItem.ItemSourceId != ItemStatics.AutoTransmogItemSourceId) { TempData["Error"] = "You cannot change form with that item."; return(RedirectToAction(MVC.PvP.Play())); } // assert player does own this skill var skill = SkillProcedures.GetSkillViewModel(skillSourceId, me.Id); if (skill == null) { TempData["Error"] = "You do not own this spell."; return(RedirectToAction(MVC.PvP.Play())); } // assert desired form is animate if (skill.MobilityType != PvPStatics.MobilityFull) { TempData["Error"] = "The target form must be an animate form."; return(RedirectToAction(MVC.PvP.Play())); } // assert player is not already in the form of the spell if (me.FormSourceId == skill.StaticSkill.FormSourceId) { TempData["Error"] = "You are already in the target form of that spell, so doing this would do you no good."; return(RedirectToAction(MVC.PvP.Play())); } PlayerProcedures.InstantChangeToForm(me, skill.StaticSkill.FormSourceId.Value); ItemProcedures.DeleteItem(itemId); PlayerProcedures.SetTimestampToNow(me); PlayerProcedures.AddItemUses(me.Id, 1); var form = FormStatics.GetForm(skill.StaticSkill.FormSourceId.Value); TempData["Result"] = "You use a " + item.Item.FriendlyName + ", your spell bouncing through the device for a second before getting flung back at you and hitting you square in the chest, instantly transforming you into a " + form.FriendlyName + "!"; StatsProcedures.AddStat(me.MembershipId, StatsProcedures.Stat__TransmogsUsed, 1); return(RedirectToAction(MVC.PvP.Play())); }
public virtual ActionResult RemoveCurseSend(int curseEffectSourceId, int id) { var myMembershipId = User.Identity.GetUserId(); var me = PlayerProcedures.GetPlayerFromMembership(myMembershipId); // assert player is animate if (me.Mobility != PvPStatics.MobilityFull) { TempData["Error"] = "You must be animate in order to use this."; return(RedirectToAction(MVC.PvP.Play())); } // assert player has not already used an item this turn if (me.ItemsUsedThisTurn >= PvPStatics.MaxItemUsesPerUpdate) { TempData["Error"] = "You've already used an item this turn."; TempData["SubError"] = "You will be able to use another consumable next turn."; return(RedirectToAction(MVC.Item.MyInventory())); } // assert player owns this item var itemToUse = ItemProcedures.GetItemViewModel(id); if (itemToUse == null || itemToUse.dbItem.OwnerId != me.Id) { TempData["Error"] = "You do not own the item needed to do this."; return(RedirectToAction(MVC.PvP.Play())); } // assert that the item can remove curses and is not any old item if (itemToUse.dbItem.ItemSourceId != ItemStatics.CurseLifterItemSourceId && itemToUse.dbItem.ItemSourceId != ItemStatics.ButtPlugItemSourceId) { TempData["Error"] = "This item cannot remove curses."; return(RedirectToAction(MVC.PvP.Play())); } var curseToRemove = EffectStatics.GetDbStaticEffect(curseEffectSourceId); // assert this curse is removable if (!curseToRemove.IsRemovable) { TempData["Error"] = "This curse is too strong to be lifted."; return(RedirectToAction(MVC.PvP.Play())); } // back on your feet curse/buff -- just delete outright if (curseToRemove.Id == PvPStatics.Effect_BackOnYourFeetSourceId) { EffectProcedures.RemovePerkFromPlayer(curseToRemove.Id, me); } // regular curse; set duration to 0 but keep cooldown else { EffectProcedures.SetPerkDurationToZero(curseToRemove.Id, me); } // if the item is a consumable type, delete it. Otherwise reset its cooldown if (itemToUse.Item.ItemType == PvPStatics.ItemType_Consumable) { ItemProcedures.DeleteItem(itemToUse.dbItem.Id); } // else if (itemToUse.Item.ItemType == PvPStatics.ItemType_Consumable_Reuseable) else { ItemProcedures.ResetUseCooldown(itemToUse); } PlayerProcedures.AddItemUses(me.Id, 1); var result = $"You have successfully removed the curse <b>{curseToRemove.FriendlyName}</b> from your body!"; TempData["Result"] = result; var playerMessage = itemToUse.Item.UsageMessage_Player; if (string.IsNullOrEmpty(playerMessage)) { PlayerLogProcedures.AddPlayerLog(me.Id, result, false); } else { PlayerLogProcedures.AddPlayerLog(me.Id, $"{playerMessage}<br />{result}", itemToUse.dbItem.FormerPlayerId != null); } if (itemToUse.dbItem.ItemSourceId == ItemStatics.ButtPlugItemSourceId && itemToUse.dbItem.FormerPlayerId != null) { var itemMessage = itemToUse.Item.UsageMessage_Item; var context = $"Your owner just used you to remove the curse <b>{curseToRemove.FriendlyName}</b>! Doesn't that make you feel all warm and tingly?"; itemMessage = string.IsNullOrEmpty(itemMessage) ? context : $"{itemMessage}<br />{context}"; PlayerLogProcedures.AddPlayerLog((int)itemToUse.dbItem.FormerPlayerId, itemMessage, true); } return(RedirectToAction(MVC.PvP.Play())); }
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); }