/// <summary> /// Determine experience gains for a gang after a battle. /// </summary> /// <param name="battleReport">Battle report</param> /// <returns>Gang level up report</returns> public GangLevelUpReport ProcessExperience(BattleReport battleReport) { var gang = _gangManager.GetGang(battleReport.GangId); var underdogBonus = GetUnderdogBonus(gang.GangRating, battleReport.OpponentGangRating, battleReport.HasWon); var advancements = new List <GangerLevelUpReport>(); foreach (var gangerStats in battleReport.GangBattleStats) { var ganger = _gangerManager.GetGanger(gangerStats.GangerId); var experience = 0; experience += GetLeaderBonus(ganger, battleReport.GameType, battleReport.HasWon, battleReport.IsAttacker); experience += GetWoundingHitBonus(gangerStats.Kills); experience += GetObjectivesBonus(gangerStats.Objectives, battleReport.GameType); experience += GetWinningBonus(battleReport.HasWon, battleReport.GameType); experience += GetSurvivalBonus(); var advanceRolls = GetNumberOfAdvanceRolls(ganger, experience); while (advanceRolls > 0) { advancements.Add(DoAdvanceRoll(ganger, gang.GangHouse)); advanceRolls--; } ganger.Experience += experience; _gangerManager.UpdateGanger(ganger); } return(new GangLevelUpReport() { GangerAdvancements = advancements, }); }
/// <summary> /// Process income /// </summary> /// <param name="battleReport">Battle reports</param> /// <param name="deaths">Number of gangers who've died in the last battle.</param> /// <returns>Income report</returns> public IncomeReport ProcessIncome(BattleReport battleReport, int deaths) { var gang = _gangManager.GetGang(battleReport.GangId); var territories = _territoryManager.GetTerritoriesByGangId(battleReport.GangId).ToList(); territories.Sort(); var gangers = GetGangers(battleReport.GangId).ToList(); var gross = new List <TerritoryIncomeReport>(); for (int i = 0; i < gangers.Count() && i < territories.Count && i < MaximumTerritoriesWorked; i++) { var status = new TerritoryWorkStatus() { TerritoryName = territories[i].Name, Deaths = deaths, Ganger = gangers[i], GangId = battleReport.GangId, Objectives = battleReport.GangBattleStats.Select(stats => stats.Objectives).Sum(), PreviousBattleType = battleReport.GameType, Roll = _diceRoller.ParseDiceString(territories[i].Income), }; gross.Add(territories[i].WorkTerritory(status)); } int territoryGross = gross.Select(territoryReport => territoryReport.Income).Sum(); int giantKillerBonus = GetGiantKillerBonus(gang.GangRating, battleReport.OpponentGangRating); int incomeAfterUpkeep = GetGangUpkeep(GetNumberOfGangMembers(battleReport.GangId), territoryGross + giantKillerBonus); var report = new IncomeReport() { Gross = gross, GiantKillerBonus = giantKillerBonus, Upkeep = territoryGross + giantKillerBonus - incomeAfterUpkeep, Income = incomeAfterUpkeep, }; gang.Credits += report.Income; _gangManager.UpdateGang(gang); return(report); }
public void HandleRequest(IRequest request) { using (var scope = Db.CreateTransaction()) { var character = request.Session.Character; var answer = request.Data.GetOrDefault <int>(k.answer); var currentGang = _gangManager.GetGangByMember(character); if (currentGang != null) { throw new PerpetuumException(ErrorCodes.CharacterAlreadyInGang); } var gangInvite = _gangInviteService.GetInvite(character).ThrowIfNull(ErrorCodes.NoSuchGangInvite); var gang = _gangManager.GetGang(gangInvite.gangGuid).ThrowIfNull(ErrorCodes.GangNotFound); _gangInviteService.RemoveInvite(gangInvite); if (answer > 0) { _gangManager.JoinMember(gang, character, true); } Transaction.Current.OnCommited(() => { var data = new Dictionary <string, object> { { k.characterID, gangInvite.member.Id }, { k.answer, answer } }; // feladonak Message.Builder.SetCommand(Commands.GangInviteReply) .WithData(data) .ToCharacter(gangInvite.sender) .Send(); data = new Dictionary <string, object> { { k.answer, answer } }; if (answer > 0) { data.Add(k.gang, gang.ToDictionary()); } // membernek Message.Builder.FromRequest(request).WithData(data).Send(); }); scope.Complete(); } }
public Gang GetGang([FromUri] string gangId) { return(_gangManager.GetGang(gangId)); }