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 void SpawnAIPsychopaths(int count) { var rand = new Random(); IPlayerRepository playerRepo = new EFPlayerRepository(); var turnNumber = PvPWorldStatProcedures.GetWorldTurnNumber(); var botCount = playerRepo.Players.Count(b => b.BotId == AIStatics.PsychopathBotId); for (var i = (0 + botCount); i < (count + botCount); i++) { var cmd = new CreatePlayer { FirstName = "Psychopath", Location = LocationsStatics.GetRandomLocationNotInDungeon(), Health = 100000, MaxHealth = 100000, Mana = 100000, MaxMana = 100000, BotId = AIStatics.PsychopathBotId, UnusedLevelUpPerks = 0, XP = 0, Money = 100, LastName = NameService.GetRandomLastName(), Gender = i % 2 == 1 ? PvPStatics.GenderMale : PvPStatics.GenderFemale, }; var strength = GetPsychopathLevel(turnNumber); if (strength == 1) { cmd.Level = 1; } else if (strength == 3) { cmd.FirstName = "Fierce " + cmd.FirstName; cmd.Level = 3; } else if (strength == 5) { cmd.FirstName = "Wrathful " + cmd.FirstName; cmd.Level = 5; } else if (strength == 7) { cmd.FirstName = "Loathful " + cmd.FirstName; cmd.Level = 7; } else if (strength == 9) { cmd.FirstName = "Soulless " + cmd.FirstName; cmd.Level = 9; } var idAndFormName = GetPsychoFormFromLevelAndSex(cmd.Level, cmd.Gender); cmd.FormSourceId = idAndFormName.Item1; // assert this name isn't already taken var ghost = playerRepo.Players.FirstOrDefault(p => p.FirstName == cmd.FirstName && p.LastName == cmd.LastName); if (ghost != null) { continue; } var id = DomainRegistry.Repository.Execute(cmd); // give this bot a random skill var eligibleSkills = SkillStatics.GetLearnablePsychopathSkills().ToList(); double max = eligibleSkills.Count; var randIndex = Convert.ToInt32(Math.Floor(rand.NextDouble() * max)); var skillToLearn = eligibleSkills.ElementAt(randIndex); SkillProcedures.GiveSkillToPlayer(id, skillToLearn.Id); // give this bot the Psychpathic perk if (strength == 1) { EffectProcedures.GivePerkToPlayer(PsychopathicForLevelOneEffectSourceId, id); } else if (strength == 3) { EffectProcedures.GivePerkToPlayer(PsychopathicForLevelThreeEffectSourceId, id); } else if (strength == 5) { EffectProcedures.GivePerkToPlayer(PsychopathicForLevelFiveEffectSourceId, id); } else if (strength == 7) { EffectProcedures.GivePerkToPlayer(PsychopathicForLevelSevenEffectSourceId, id); } else if (strength == 9) { EffectProcedures.GivePerkToPlayer(PsychopathicForLevelNineEffectSourceId, id); } // give this psycho a new rune with some random chance it is a higher level than they are, to a max of level 13 var random = new Random(Guid.NewGuid().GetHashCode()); var roll = random.NextDouble(); if (roll < .1) { strength += 4; } else if (roll < .3) { strength += 2; } var quantity = Math.Floor(random.NextDouble() * 2) + 1; // 1 or 2 for (var c = 0; c < quantity; c++) { var runeId = DomainRegistry.Repository.FindSingle(new GetRandomRuneAtLevel { RuneLevel = strength, Random = random }); DomainRegistry.Repository.Execute(new GiveRune { ItemSourceId = runeId, PlayerId = id }); } var psychoEF = playerRepo.Players.FirstOrDefault(p => p.Id == id); psychoEF.ReadjustMaxes(ItemProcedures.GetPlayerBuffs(psychoEF)); playerRepo.SavePlayer(psychoEF); } }
public static List <Exception> RunPsychopathActions(WorldDetail worldDetail) { var rand = new Random(DateTime.Now.Millisecond); var errors = new List <Exception>(); IPlayerRepository playerRepo = new EFPlayerRepository(); //spawn in more bots if there are less than the default var botCount = playerRepo.Players.Count(b => b.BotId == AIStatics.PsychopathBotId && b.Mobility == PvPStatics.MobilityFull); if (botCount < PvPStatics.PsychopathDefaultAmount) { SpawnAIPsychopaths(PvPStatics.PsychopathDefaultAmount - botCount); } var bots = playerRepo.Players.Where(p => p.BotId == AIStatics.PsychopathBotId && p.Mobility == PvPStatics.MobilityFull).ToList(); foreach (var bot in bots) { try { // if bot is no longer fully animate or is null, skip them if (bot == null || bot.Mobility != PvPStatics.MobilityFull) { continue; } bot.LastActionTimestamp = DateTime.UtcNow; if (!EffectProcedures.PlayerHasActiveEffect(bot.Id, JokeShopProcedures.PSYCHOTIC_EFFECT)) { #region drop excess items var botItems = DomainRegistry.Repository.Find(new GetItemsOwnedByPsychopath { OwnerId = bot.Id }).ToList(); string[] itemTypes = { PvPStatics.ItemType_Hat, PvPStatics.ItemType_Accessory, PvPStatics.ItemType_Pants, PvPStatics.ItemType_Pet, PvPStatics.ItemType_Shirt, PvPStatics.ItemType_Shoes, PvPStatics.ItemType_Underpants, PvPStatics.ItemType_Undershirt }; foreach (var typeToDrop in itemTypes) { if (botItems.Count(i => i.ItemSource.ItemType == typeToDrop) > 1) { var dropList = botItems.Where(i => i.ItemSource.ItemType == typeToDrop).Skip(1); foreach (var i in dropList) { ItemProcedures.DropItem(i.Id); var name = "a"; if (i.FormerPlayer != null) { name = "<b>" + i.FormerPlayer.FullName + "</b> the"; } if (i.ItemSource.ItemType == PvPStatics.ItemType_Pet) { LocationLogProcedures.AddLocationLog(bot.dbLocationName, "<b>" + bot.GetFullName() + "</b> released " + name + " pet <b>" + i.ItemSource.FriendlyName + "</b> here."); } else { LocationLogProcedures.AddLocationLog(bot.dbLocationName, "<b>" + bot.GetFullName() + "</b> dropped " + name + " <b>" + i.ItemSource.FriendlyName + "</b> here."); } } } } #endregion } var botbuffs = ItemProcedures.GetPlayerBuffs(bot); var meditates = 0; // meditate if needed if (bot.Mana < bot.MaxMana * .5M) { var manaroll = (int)Math.Floor(rand.NextDouble() * 4.0D); for (var i = 0; i < manaroll; i++) { DomainRegistry.Repository.Execute(new Meditate { PlayerId = bot.Id, Buffs = botbuffs, NoValidate = true }); meditates++; } } // cleanse if needed, less if psycho has cleansed lately if (bot.Health < bot.MaxHealth * .5M) { var healthroll = (int)Math.Floor(rand.NextDouble() * 4.0D); for (var i = meditates; i < healthroll; i++) { DomainRegistry.Repository.Execute(new Cleanse { PlayerId = bot.Id, Buffs = botbuffs, NoValidate = true }); } } var directive = AIDirectiveProcedures.GetAIDirective(bot.Id); // the bot has an attack target, so go chase it if (directive.State == "attack") { var myTarget = PlayerProcedures.GetPlayer(directive.TargetPlayerId); var(mySkills, weakenSkill, inanimateSkill) = GetPsychopathSkills(bot); // if the target is offline, no longer animate, in the dungeon, or in the same form as the spells' target, go into idle mode if (PlayerProcedures.PlayerIsOffline(myTarget) || myTarget.Mobility != PvPStatics.MobilityFull || mySkills.IsEmpty() || inanimateSkill == null || myTarget.FormSourceId == inanimateSkill.StaticSkill.FormSourceId || myTarget.IsInDungeon() || myTarget.InDuel > 0 || myTarget.InQuest > 0) { AIDirectiveProcedures.SetAIDirective_Idle(bot.Id); } // the target is okay for attacking else { // the bot must move to its target location. if (myTarget.dbLocationName != bot.dbLocationName) { if (botbuffs.MoveActionPointDiscount() > -100 && CanMove(worldDetail, myTarget)) { var maxSpaces = NumPsychopathMoveSpaces(bot); var newplace = MoveTo(bot, myTarget.dbLocationName, maxSpaces); bot.dbLocationName = newplace; } } // if the bot is now in the same place as the target, attack away, so long as the target is online and animate if (bot.dbLocationName == myTarget.dbLocationName && !PlayerProcedures.PlayerIsOffline(myTarget) && myTarget.Mobility == PvPStatics.MobilityFull && CanAttack(worldDetail, bot, myTarget) ) { playerRepo.SavePlayer(bot); var numAttacks = Math.Min(3, (int)(bot.Mana / PvPStatics.AttackManaCost)); var complete = false; for (var attackIndex = 0; attackIndex < numAttacks && !complete; ++attackIndex) { var skill = SelectPsychopathSkill(myTarget, mySkills, weakenSkill, rand); (complete, _) = AttackProcedures.Attack(bot, myTarget, skill); } if (complete) { EquipDefeatedPlayer(bot, myTarget); } } } } // the bot has no target, so wander and try to find new targets and attack them. else { if (botbuffs.MoveActionPointDiscount() > -100) { var newplace = MoveTo(bot, LocationsStatics.GetRandomLocationNotInDungeon(), 5); bot.dbLocationName = newplace; } // attack stage var playersHere = playerRepo.Players.Where (p => p.dbLocationName == bot.dbLocationName && p.Mobility == PvPStatics.MobilityFull && p.Id != bot.Id && p.BotId == AIStatics.PsychopathBotId && p.Level >= bot.Level).ToList(); // filter out offline players and Lindella var onlinePlayersHere = playersHere.Where(p => !PlayerProcedures.PlayerIsOffline(p)).ToList(); if (onlinePlayersHere.Count > 0) { var roll = Math.Floor(rand.NextDouble() * onlinePlayersHere.Count); var victim = onlinePlayersHere.ElementAt((int)roll); AIDirectiveProcedures.SetAIDirective_Attack(bot.Id, victim.Id); playerRepo.SavePlayer(bot); var(mySkills, weakenSkill, inanimateSkill) = GetPsychopathSkills(bot); if (!mySkills.IsEmpty()) { var numAttacks = Math.Min(3, (int)(bot.Mana / PvPStatics.AttackManaCost)); var complete = false; for (var attackIndex = 0; attackIndex < numAttacks && !complete; ++attackIndex) { var skill = SelectPsychopathSkill(victim, mySkills, weakenSkill, rand); (complete, _) = AttackProcedures.Attack(bot, victim, skill); } if (complete) { EquipDefeatedPlayer(bot, victim); } } } } playerRepo.SavePlayer(bot); } catch (Exception e) { errors.Add(e); } } return(errors); }
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)}%]"); } }