private static void DropCure(int turnNumber) { for (var i = 0; i < 2; i++) { var cmd = new CreateItem { dbLocationName = LocationsStatics.GetRandomLocationNotInDungeon(), IsEquipped = false, IsPermanent = false, Level = 0, PvPEnabled = 2, OwnerId = null, TurnsUntilUse = 0, EquippedThisTurn = false, ItemSourceId = ItemStatics.GetStaticItem(CureItemSourceId).Id }; if (turnNumber % 3 == 0) { cmd.PvPEnabled = 1; } DomainRegistry.Repository.Execute(cmd); } }
public static MvcHtmlString PrintOwnerSubPortrait(PlayerFormViewModel owner) { var output = ""; if (owner == null) { return(new MvcHtmlString(output)); } var portraits = "portraits"; var portraitUrl = owner.Form.PortraitUrl; if (owner.Player.Mobility == PvPStatics.MobilityInanimate) { portraits = "itemsPortraits"; portraitUrl = ItemStatics.GetStaticItem(owner.Form.ItemSourceId.Value)?.PortraitUrl; } else if (owner.Player.Mobility == PvPStatics.MobilityPet) { portraits = "animalPortraits"; portraitUrl = ItemStatics.GetStaticItem(owner.Form.ItemSourceId.Value)?.PortraitUrl; } var strThumb = "Thumbnails/100/"; if (!File.Exists($"{AppDomain.CurrentDomain.BaseDirectory}{PvPStatics.ImageFolder}{portraits}/{strThumb}{portraitUrl}")) { strThumb = ""; } output = $"<div class='subportrait' style='background-image: url({PvPStatics.ImageURL}{portraits}/{strThumb}{portraitUrl});' title = 'You are owned by {owner.Player.GetFullName()}, a {owner.Form.FriendlyName}.'></div>"; return(new MvcHtmlString(output)); }
public static string UseFurniture(int furnitureId, Player user) { IFurnitureRepository furnRepo = new EFFurnitureRepository(); var dbFurniture = furnRepo.Furnitures.FirstOrDefault(f => f.Id == furnitureId); dbFurniture.LastUseTimestamp = DateTime.UtcNow; dbFurniture.LastUsersIds = user.Id.ToString(); furnRepo.SaveFurniture(dbFurniture); var furnitureStatic = furnRepo.DbStaticFurniture.FirstOrDefault(f => f.dbType == dbFurniture.dbType); var logMessage = "<b>" + user.GetFullName() + "</b> used <b>" + dbFurniture.HumanName + "</b>."; CovenantProcedures.WriteCovenantLog(logMessage, (int)user.Covenant, false); // furniture gives AP reserve bonus if (furnitureStatic.APReserveRefillAmount > 0) { IPlayerRepository playerRepo = new EFPlayerRepository(); var dbPlayer = playerRepo.Players.FirstOrDefault(p => p.Id == user.Id); dbPlayer.ActionPoints_Refill += furnitureStatic.APReserveRefillAmount; if (dbPlayer.ActionPoints_Refill > TurnTimesStatics.GetActionPointReserveLimit()) { dbPlayer.ActionPoints_Refill = TurnTimesStatics.GetActionPointReserveLimit(); } dbPlayer.LastActionTimestamp = DateTime.UtcNow; playerRepo.SavePlayer(dbPlayer); return("You used " + dbFurniture.HumanName + ", a human voluntarily transformed into furniture and leased by your covenant, and gained " + furnitureStatic.APReserveRefillAmount + " reserve action points."); } // furniture gives effect else if (furnitureStatic.GivesEffectSourceId != null) { EffectProcedures.GivePerkToPlayer(furnitureStatic.GivesEffectSourceId.Value, user); PlayerProcedures.SetTimestampToNow(user); return("You used " + dbFurniture.HumanName + ", a human voluntarily transformed into furniture and leased by your covenant, and gained the " + EffectStatics.GetDbStaticEffect(furnitureStatic.GivesEffectSourceId.Value).FriendlyName + " effect."); } //furniture gives item else if (furnitureStatic.GivesItemSourceId != null) { ItemProcedures.GiveNewItemToPlayer(user, furnitureStatic.GivesItemSourceId.Value); PlayerProcedures.SetTimestampToNow(user); var itemGained = ItemStatics.GetStaticItem(furnitureStatic.GivesItemSourceId.Value); return("You used " + dbFurniture.HumanName + ", a human voluntarily transformed into furniture and leased by your covenant, gaining a " + itemGained.FriendlyName + "."); } return("ERROR"); }
public static string PlayerEndQuest(Player player, int endType) { var message = ""; IPlayerRepository playerRepo = new EFPlayerRepository(); var dbPlayer = playerRepo.Players.FirstOrDefault(p => p.Id == player.Id); dbPlayer.InQuest = 0; dbPlayer.InQuestState = 0; playerRepo.SavePlayer(dbPlayer); IQuestRepository questRepo = new EFQuestRepository(); var questPlayerStatus = questRepo.QuestPlayerStatuses.FirstOrDefault(q => q.PlayerId == player.Id && q.QuestId == player.InQuest); if (questPlayerStatus == null) { questPlayerStatus = new QuestPlayerStatus { PlayerId = player.Id, QuestId = player.InQuest, }; } questPlayerStatus.LastEndedTurn = PvPWorldStatProcedures.GetWorldTurnNumber(); questPlayerStatus.Outcome = endType; questRepo.SaveQuestPlayerStatus(questPlayerStatus); // assing completion bonuses if (endType == (int)QuestStatics.QuestOutcomes.Completed) { var questState = GetQuestState(player.InQuestState); decimal xpGain = 0; foreach (var q in questState.QuestEnds) { // experience gain if (q.RewardType == (int)QuestStatics.RewardType.Experience) { xpGain += Int32.Parse(q.RewardAmount); } // item gain else if (q.RewardType == (int)QuestStatics.RewardType.Item) { var item = ItemStatics.GetStaticItem(System.Convert.ToInt32(q.RewardAmount)); ItemProcedures.GiveNewItemToPlayer(player, item); message += " <br>You received a <b>" + item.FriendlyName + "</b>."; } // effect gain else if (q.RewardType == (int)QuestStatics.RewardType.Effect) { var effect = EffectStatics.GetDbStaticEffect(System.Convert.ToInt32(q.RewardAmount)); EffectProcedures.GivePerkToPlayer(effect.Id, player.Id); message += "<br>You received the effect <b>" + effect.FriendlyName + "</b>."; } // spell gain else if (q.RewardType == (int)QuestStatics.RewardType.Spell) { var spell = SkillStatics.GetStaticSkill(System.Convert.ToInt32(q.RewardAmount)); SkillProcedures.GiveSkillToPlayer(player.Id, spell.Id); message += "<br>You learned the spell <b>" + spell.FriendlyName + "</b>."; } } if (xpGain > 0) { message += "<br>You earned <b>" + xpGain + "</b> XP."; } PlayerProcedures.GiveXP(player, xpGain); } // delete all of the player's quest variables var vars = QuestProcedures.GetAllQuestPlayerVariablesFromQuest(player.InQuest, player.Id).ToList(); foreach (var v in vars) { questRepo.DeleteQuestPlayerVariable(v.Id); } return(message); }
public static void SpawnValentine() { var valentine = DomainRegistry.Repository.FindSingle(new GetPlayerByBotId { BotId = AIStatics.ValentineBotId }); if (valentine == null) { var cmd = new CreatePlayer { FirstName = ValentineFirstName, LastName = ValentineLastName, Location = GetStanceLocation(), Gender = PvPStatics.GenderMale, Health = 100000, Mana = 100000, MaxHealth = 100000, MaxMana = 100000, FormSourceId = ValentineFormSourceId, Money = 1000, Mobility = PvPStatics.MobilityFull, Level = 30, BotId = AIStatics.ValentineBotId, }; var id = DomainRegistry.Repository.Execute(cmd); var playerRepo = new EFPlayerRepository(); var valentineEF = playerRepo.Players.FirstOrDefault(p => p.Id == id); valentineEF.ReadjustMaxes(ItemProcedures.GetPlayerBuffs(valentineEF)); playerRepo.SavePlayer(valentineEF); // give Valentine his reward item drop var createItemCmd = new CreateItem { dbLocationName = "", EquippedThisTurn = false, IsEquipped = false, IsPermanent = false, Level = 6, OwnerId = id, PvPEnabled = -1, ItemSourceId = ItemStatics.GetStaticItem(QueensPantiesItemSourceId).Id }; DomainRegistry.Repository.Execute(createItemCmd); // save his aiDirective, just for the sake of knowing his spawn turn IAIDirectiveRepository aiRepo = new EFAIDirectiveRepository(); var directive = new AIDirective { OwnerId = id, Timestamp = DateTime.UtcNow, SpawnTurn = PvPWorldStatProcedures.GetWorldTurnNumber(), DoNotRecycleMe = true, }; aiRepo.SaveAIDirective(directive); for (var i = 0; i < 2; i++) { DomainRegistry.Repository.Execute(new GiveRune { ItemSourceId = RuneStatics.VAMPIRE_RUNE, PlayerId = valentineEF.Id }); } } }
public static string ReturnToAnimate(Player player, bool dungeonPenalty) { IInanimateXPRepository inanimXpRepo = new EFInanimateXPRepository(); IItemRepository itemRepo = new EFItemRepository(); var inanimXP = inanimXpRepo.InanimateXPs.FirstOrDefault(i => i.OwnerId == player.Id); var currentGameTurn = PvPWorldStatProcedures.GetWorldTurnNumber(); if (inanimXP == null) { inanimXP = new InanimateXP { OwnerId = player.Id, Amount = 0, // set the initial times struggled proportional to how high of a level the player is TimesStruggled = -6 * player.Level, LastActionTimestamp = DateTime.UtcNow, LastActionTurnstamp = currentGameTurn - 1, }; } double strugglebonus = currentGameTurn - inanimXP.LastActionTurnstamp; if (strugglebonus > TurnTimesStatics.GetItemMaxTurnsBuildup()) { strugglebonus = TurnTimesStatics.GetItemMaxTurnsBuildup(); } if (strugglebonus < 0) { strugglebonus = 0; } if (PvPStatics.ChaosMode) { strugglebonus = 100; } // increment the player's attack count. Also decrease their player XP some. IPlayerRepository playerRepo = new EFPlayerRepository(); var dbPlayer = playerRepo.Players.FirstOrDefault(p => p.Id == player.Id); dbPlayer.TimesAttackingThisUpdate++; var strugglesMade = Convert.ToDouble(GetStruggleChance(player, dungeonPenalty)); var rand = new Random(); var roll = rand.NextDouble() * 100; var dbPlayerItem = DomainRegistry.Repository.FindSingle(new GetItemByFormerPlayer { PlayerId = player.Id }); if (dbPlayerItem == null) { return("Cannot struggle - no player item"); } if (dbPlayerItem.Owner != null) { var owner = PlayerProcedures.GetPlayer(dbPlayerItem.Owner.Id); dbPlayer.dbLocationName = owner.dbLocationName; } var itemPlus = ItemStatics.GetStaticItem(dbPlayerItem.ItemSource.Id); if (roll < strugglesMade) { // assert that the covenant the victim is in is not too full to accept them back in if (dbPlayer.Covenant > 0) { var victimCov = CovenantProcedures.GetCovenantViewModel((int)dbPlayer.Covenant).dbCovenant; if (victimCov != null && CovenantProcedures.GetPlayerCountInCovenant(victimCov, true) >= PvPStatics.Covenant_MaximumAnimatePlayerCount) { return("Although you had enough energy to break free from your body as a " + itemPlus.FriendlyName + " and restore your regular body, you were unfortunately not able to break free because there is no more room in your covenant for any more animate mages."); } } // if the item has an owner, notify them via a message. if (dbPlayerItem.Owner != null) { var message = player.FirstName + " " + player.LastName + ", your " + itemPlus.FriendlyName + ", successfully struggles against your magic and reverses their transformation. You can no longer claim them as your property, not unless you manage to turn them back again..."; PlayerLogProcedures.AddPlayerLog(dbPlayerItem.Owner.Id, message, true); } // change the player's form and mobility DomainRegistry.Repository.Execute(new ChangeForm { PlayerId = dbPlayer.Id, FormSourceId = dbPlayer.OriginalFormSourceId }); dbPlayer.ActionPoints = TurnTimesStatics.GetActionPointLimit(); dbPlayer.ActionPoints_Refill = TurnTimesStatics.GetActionPointReserveLimit(); dbPlayer.CleansesMeditatesThisRound = PvPStatics.MaxCleansesMeditatesPerUpdate; dbPlayer.TimesAttackingThisUpdate = PvPStatics.MaxAttacksPerUpdate; // don't let the player spawn in the dungeon as they will have Back On Your Feet // and may not be meet the level and game mode requirements if (dbPlayer.IsInDungeon()) { dbPlayer.dbLocationName = LocationsStatics.GetRandomLocationNotInDungeon(); } dbPlayer = PlayerProcedures.ReadjustMaxes(dbPlayer, ItemProcedures.GetPlayerBuffs(dbPlayer)); dbPlayer.Health = dbPlayer.MaxHealth / 3; dbPlayer.Mana = dbPlayer.MaxHealth / 3; playerRepo.SavePlayer(dbPlayer); // drop any runes embedded on the player-item, or return them to the former owner's inventory DomainRegistry.Repository.Execute(new UnbembedRunesOnItem { ItemId = dbPlayerItem.Id }); // delete the item or animal that this player had turned into itemRepo.DeleteItem(dbPlayerItem.Id); // delete the inanimate XP item inanimXpRepo.DeleteInanimateXP(inanimXP.Id); // give the player the recovery buff EffectProcedures.GivePerkToPlayer(PvPStatics.Effect_BackOnYourFeetSourceId, dbPlayer); var msg = "You have managed to break free from your form as " + itemPlus.FriendlyName + " and occupy an animate body once again!"; if (PvPStatics.ChaosMode) { msg += $" [CHAOS MODE: Struggle value overriden to {strugglebonus:0}% per struggle.]"; } PlayerLogProcedures.AddPlayerLog(dbPlayer.Id, msg, false); StatsProcedures.AddStat(dbPlayer.MembershipId, StatsProcedures.Stat__SuccessfulStruggles, 1); return(msg); } // failure to break free; increase time struggles else { // raise the probability of success for next time somewhat proportion to how many turns they missed inanimXP.TimesStruggled += Convert.ToInt32(strugglebonus); inanimXP.LastActionTimestamp = DateTime.UtcNow; inanimXP.LastActionTurnstamp = currentGameTurn; inanimXpRepo.SaveInanimateXP(inanimXP); playerRepo.SavePlayer(dbPlayer); if (dbPlayerItem.Owner != null) { var message = $"{player.FirstName} {player.LastName}, your {itemPlus.FriendlyName}, struggles but fails to return to an animate form. [Recovery chance next struggle: {(int)GetStruggleChance(player, dungeonPenalty)}%]"; PlayerLogProcedures.AddPlayerLog(dbPlayerItem.Owner.Id, message, true); } PlayerLogProcedures.AddPlayerLog(dbPlayer.Id, "You struggled to return to a human form.", false); return($"Unfortunately you are not able to struggle free from your form as {itemPlus.FriendlyName}. Keep trying and you might succeed later... [Recovery chance next struggle: {(int)GetStruggleChance(player, dungeonPenalty)}%]"); } }
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); }