public static void InstantTakeoverLocation(Covenant cov, string location) { ILocationInfoRepository repo = new EFLocationInfoRepository(); var info = repo.LocationInfos.FirstOrDefault(l => l.dbName == location); if (info == null) { info = new LocationInfo { dbName = location, }; } info.TakeoverAmount = 100; info.CovenantId = cov.Id; info.LastTakeoverTurn = PvPWorldStatProcedures.GetWorldTurnNumber(); repo.SaveLocationInfo(info); LocationsStatics.LocationList.GetLocation.FirstOrDefault(l => l.dbName == location).CovenantController = cov.Id; }
public static string AttackLocation(Player player, BuffBox buffs) { ILocationInfoRepository repo = new EFLocationInfoRepository(); ICovenantRepository covRepo = new EFCovenantRepository(); var location = LocationsStatics.LocationList.GetLocation.FirstOrDefault(l => l.dbName == player.dbLocationName); var output = ""; if (location == null) { output = "You cast an enchantment here, but you aren't actually anywhere!"; return(output); } var info = repo.LocationInfos.FirstOrDefault(l => l.dbName == player.dbLocationName) ?? new LocationInfo { TakeoverAmount = 75, CovenantId = -1, dbName = player.dbLocationName, }; if (player.Covenant == null) { output = "You cast an enchantment here, but it did no effect as you aren't part of a covenant"; return(output); } if (info.TakeoverAmount >= 100 && info.CovenantId == player.Covenant) { output = "You cast an enchantment here, but it did no effect as this location's enchantment is already at its highest possible level, 100."; return(output); } var takeoverAmount = (float)player.Level / 2.0F; takeoverAmount += buffs.EnchantmentBoost; decimal XPGain = 0; try { XPGain = 40 / Math.Round(Convert.ToDecimal(101 - Math.Abs(info.TakeoverAmount)), 1); } catch (Exception) { XPGain = 0; } if (XPGain > PvPStatics.XP__EnchantmentMaxXP) { XPGain = PvPStatics.XP__EnchantmentMaxXP; } var XPGainText = String.Format("{0:0.#}", XPGain); // location is not controlled; give it to whichever covenant is attacking it if (info.TakeoverAmount <= 0) { info.CovenantId = (int)player.Covenant; info.TakeoverAmount = takeoverAmount; if (info.TakeoverAmount > 100) { info.TakeoverAmount = 100; } info.LastTakeoverTurn = PvPWorldStatProcedures.GetWorldTurnNumber(); output = "<b>Your enchantment settles in this location, converting its energies from the previous controlling covenant to your own! (+" + XPGainText + " XP)</b>"; location.CovenantController = (int)player.Covenant; location.TakeoverAmount = info.TakeoverAmount; var myCov = covRepo.Covenants.First(c => c.Id == player.Covenant); var locationLogMessage = "<b class='playerAttackNotification'>" + player.GetFullName() + " enchanted this location and claimed it for " + myCov.Name + "!</b>"; LocationLogProcedures.AddLocationLog(player.dbLocationName, locationLogMessage); var covLogWinner = player.GetFullName() + " enchanted " + location.Name + " and has claimed it for this covenant."; CovenantProcedures.WriteCovenantLog(covLogWinner, myCov.Id, true); } // otherwise the location is controlled by someone else { // add points toward the attacker's covenant or take them away if it belongs to another if (info.CovenantId == player.Covenant) { info.TakeoverAmount += takeoverAmount; location.TakeoverAmount = info.TakeoverAmount; var cov = covRepo.Covenants.FirstOrDefault(c => c.Id == player.Covenant); output = $"Your enchantment reinforces this location by {takeoverAmount}. New influence level is {info.TakeoverAmount} for your covenant, {cov?.Name ?? "unknown"}. (+{XPGainText} XP)</b>"; } else { info.TakeoverAmount -= takeoverAmount; location.TakeoverAmount = info.TakeoverAmount; var cov = info.CovenantId == null ? null : covRepo.Covenants.FirstOrDefault(c => c.Id == info.CovenantId); if (info.TakeoverAmount <= 0) { // notify old covenant who stole the location and their covenant if (info.CovenantId != null && info.CovenantId > 0) { var attackingCov = CovenantProcedures.GetCovenantViewModel((int)player.Covenant); var covLogLoser = player.GetFullName() + " of " + attackingCov.dbCovenant.Name + " enchanted " + location.Name + ", removing it from this covenant's influence!"; CovenantProcedures.WriteCovenantLog(covLogLoser, (int)info.CovenantId, true); } info.CovenantId = -1; info.LastTakeoverTurn = PvPWorldStatProcedures.GetWorldTurnNumber(); } if (cov != null) { output = "You dispel the enchantment at this location by " + takeoverAmount + ". New influence level is " + info.TakeoverAmount + " for the location's existing controller, " + cov.Name + ". (+" + XPGainText + " XP)</b>"; } else { output = "You dispel the enchantment at this location by " + takeoverAmount + ". New influence level is " + info.TakeoverAmount + ". (+" + XPGainText + " XP)</b>"; } } var locationLogMessage = "<span class='playerAttackNotification'>" + player.GetFullName() + " cast an enchantment on this location.</span>"; LocationLogProcedures.AddLocationLog(player.dbLocationName, locationLogMessage); } if (info.TakeoverAmount > 100) { info.TakeoverAmount = 100; } // cap at 0 to 100 points else if (info.TakeoverAmount <= 0) { info.CovenantId = -1; info.TakeoverAmount = 0; } repo.SaveLocationInfo(info); PlayerProcedures.GiveXP(player, XPGain); PlayerLogProcedures.AddPlayerLog(player.Id, output, false); return(output); }