public override async Task <FunctionResponse> ProcessMessageAsync(FunctionRequest request) { var message = ""; switch (request.Dead) { case "thanos": message = "EARTH IS SAVED"; break; case "earth": message = "EARTH IS DESTROYED"; break; case "both": message = "THERE IS NOTHING LEFT"; break; } var newItem = new Types.Item { Id = GameLogic.Methods.FormatBattlefieldId(request.RoundNumber, DateTime.UtcNow.ToString(), "MOD", "UPDATE"), Value = message }; // Post the threaten message to API Gateway await Methods.PostBattlefield(newItem); return(new FunctionResponse()); }
public override async Task <FunctionResponse> ProcessMessageAsync(FunctionRequest request) { var response = new FunctionResponse { RoundNumber = request.RoundNumber, EarthPopulation = request.EarthPopulation, ThanosHealth = request.ThanosHealth }; var roundNumber = request.RoundNumber; var thanosPower = GameLogic.Methods.GetThanosRoundPowerLevel(roundNumber); var population = Int32.Parse(request.EarthPopulation); response.EarthPopulation = (population - thanosPower).ToString(); var newItem = new Types.Item { Id = GameLogic.Methods.FormatBattlefieldId(request.RoundNumber, DateTime.UtcNow.ToString(), "THANOS", "KILL"), Value = $"YOU HAVE FAILED TO DEFEND IN TIME. I HAVE KILLED {thanosPower.ToString()} PEOPLE {GameLogic.Methods.FormatThanosMessage(request.EarthPopulation, "PEOPLE REMAINING")}" }; // Post the threaten message to API Gateway await Methods.PostBattlefield(newItem); return(response); }
public override async Task <FunctionResponse> ProcessMessageAsync(FunctionRequest request) { var response = new FunctionResponse { RoundNumber = request.RoundNumber, EarthPopulation = request.EarthPopulation, ThanosHealth = request.ThanosHealth }; if (string.IsNullOrEmpty(request.RoundNumber)) { var introItem = new Types.Item { Id = $"{DateTime.UtcNow}::THANOS::WELCOME", Value = $"WELCOME TO THE BATTLEFIELD, AVENGERS - ARE YOU READY TO FACE YOUR DEATH?" }; // clear battlefield if there is no payload await Methods.InitializeBattlefield(); // Post the intro message to the gateway await Methods.PostBattlefield(introItem); response.RoundNumber = "1"; response.EarthPopulation = GameLogic.Constants.EARTH_POPULATION.ToString(); response.ThanosHealth = GameLogic.Constants.THANOS_HEALTH.ToString(); } // Post Round Number var roundUpdateItem = new Types.Item { Id = GameLogic.Methods.FormatBattlefieldId(response.RoundNumber, DateTime.UtcNow.ToString(), "THANOS", "UPDATE"), Value = $"GET READY FOR THE NEXT WAVE OF MINIONS {GameLogic.Methods.FormatThanosMessage(response.RoundNumber, "ROUND")}, {GameLogic.Methods.FormatThanosMessage(response.EarthPopulation, "PEOPLE REMAINING")}, {GameLogic.Methods.FormatThanosMessage(response.ThanosHealth, "HEALTH")} REMAINING" }; await Methods.PostBattlefield(roundUpdateItem); // var thanosPower = Methods.GetThanosRoundPowerLevel(response.RoundNumber); var thanosUnitCount = Methods.GetThanosRoundUnitCount(response.RoundNumber); var newItem = new Types.Item { Id = GameLogic.Methods.FormatBattlefieldId(response.RoundNumber, DateTime.UtcNow.ToString(), "THANOS", "THREAT"), Value = $"ATTACKING - CHOOSE YOUR BEST {GameLogic.Methods.FormatThanosMessage(thanosUnitCount.ToString(), "UNITS")}, YOU HAVE {GameLogic.Methods.FormatThanosMessage(GameLogic.Constants.TIME_LIMIT.ToString(), "SECONDS")}" }; // Post the threaten message to API Gateway await Methods.PostBattlefield(newItem); return(response); }
public WItem(Types.Item item) { this.Id = item.Id; this.Name = item.Name; this.Description = item.Description; this.AdditionalInfo = item.AdditionalInfo; this.Price = item.Price; this.Availability = item.Availability; this.Weight = item.Weight; this.Quality = item.Quality; this.Quantity = item.Quantity; this.Bonus = item.Bonus; }
public void AddItem(Types.Item item) { _items.Add(item); }
public override async Task <FunctionResponse> ProcessMessageAsync(FunctionRequest request) { var response = new FunctionResponse { RoundNumber = request.RoundNumber, EarthPopulation = request.EarthPopulation, ThanosHealth = request.ThanosHealth }; // get data from Gateway - look for Avengers on battlefield var battlefield = await GameLogic.Methods.GetBattlefieldFromGateway(); var recentItem = GameLogic.Methods.GetLastItemFromBattlefield(battlefield.Items.ToList(), "DEFEND", request.RoundNumber); var lastItem = GameLogic.Methods.ParseBattleFieldId(recentItem); var graveyard = await GameLogic.Methods.GetGrave(); var thanosExpectedUnitCount = GameLogic.Methods.GetThanosRoundUnitCount(response.RoundNumber); var thanosTotalPower = Methods.GetThanosRoundPowerLevel(request.RoundNumber); var deserialzedListOfAvengers = new List <Types.Avenger>(); try { deserialzedListOfAvengers = JsonConvert.DeserializeObject <List <Types.Avenger> >(recentItem.Value); // if wrong number of units submitted, automatically kill if (deserialzedListOfAvengers.Count > thanosExpectedUnitCount) { response.EarthPopulation = (Int32.Parse(response.EarthPopulation) - thanosTotalPower).ToString(); var invalidUnitCountMessage = new Types.Item { Id = GameLogic.Methods.FormatBattlefieldId(request.RoundNumber, DateTime.UtcNow.ToString(), "THANOS", "INVALID SUBMISSION"), Value = $"PLEASE SUBMIT <= ({thanosExpectedUnitCount} UNITS) TO ENTER THE BATTLE" }; await Methods.PostBattlefield(invalidUnitCountMessage); var invalidUnitCountKillMessage = new Types.Item { Id = GameLogic.Methods.FormatBattlefieldId(request.RoundNumber, DateTime.UtcNow.ToString(), "THANOS", "KILL"), Value = $" YOU LOST THIS ROUND.. I HAVE KILLED {GameLogic.Methods.FormatThanosMessage(Math.Abs(thanosTotalPower).ToString(), "PEOPLE")}" }; await Methods.PostBattlefield(invalidUnitCountKillMessage); } // compute power of team and battle else { // add attack power var avengerTeamTotalPower = 0; var cleanListOfAvengers = new List <Types.Avenger>(); foreach (var avenger in deserialzedListOfAvengers) { if (graveyard.Avengers.Any(x => x.id.Equals(avenger.id))) { var graveyardItem = new Types.Item { Id = GameLogic.Methods.FormatBattlefieldId(request.RoundNumber, DateTime.UtcNow.ToString(), "THANOS", "GRAVE"), Value = $"{avenger.name} IS ALREADY DEAD. IGNORING FROM TOTAL TEAM POWER" }; // Post the threaten message to API Gateway await Methods.PostBattlefield(graveyardItem); continue; } cleanListOfAvengers.Add(avenger); avengerTeamTotalPower += Int32.Parse(avenger.power); } var battleResult = avengerTeamTotalPower - thanosTotalPower; var battleMessage = ""; var battleCasualties = CalculateDeaths(cleanListOfAvengers, battleResult, Int32.Parse(response.RoundNumber)); if (battleResult < 0) { response.EarthPopulation = (Int32.Parse(response.EarthPopulation) + battleResult).ToString(); battleMessage += $" YOU LOST THIS ROUND.. I HAVE KILLED {GameLogic.Methods.FormatThanosMessage(Math.Abs(battleResult).ToString(), "PEOPLE")}"; } else if (battleResult > 0) { response.ThanosHealth = (Int32.Parse(response.ThanosHealth) - battleResult).ToString(); battleMessage += $" YOU WON THIS ROUND.. I HAVE TAKEN {GameLogic.Methods.FormatThanosMessage(battleResult.ToString(), "HEALTH")} DAMAGE"; } if (battleCasualties.Count > 0) { battleMessage += $"THESE HEROS HAVE FALLEN {JsonConvert.SerializeObject(battleCasualties)} "; } var newItem = new Types.Item { Id = GameLogic.Methods.FormatBattlefieldId(request.RoundNumber, DateTime.UtcNow.ToString(), "THANOS", "BATTLE"), Value = battleMessage }; await Methods.PostBattlefield(newItem); await Methods.PostGrave(battleCasualties); } } // if team submitted in invalid format then kill catch { response.EarthPopulation = (Int32.Parse(response.EarthPopulation) - thanosTotalPower).ToString(); var invalidUnitCountMessage = new Types.Item { Id = GameLogic.Methods.FormatBattlefieldId(request.RoundNumber, DateTime.UtcNow.ToString(), "THANOS", "INVALID SUBMISSION"), Value = $"SUBMIT YOUR TEAM IN THE CORRECT FORMAT!" }; await Methods.PostBattlefield(invalidUnitCountMessage); var invalidUnitCountKillMessage = new Types.Item { Id = GameLogic.Methods.FormatBattlefieldId(request.RoundNumber, DateTime.UtcNow.ToString(), "THANOS", "KILL"), Value = $" YOU LOST THIS ROUND.. I HAVE KILLED {GameLogic.Methods.FormatThanosMessage(Math.Abs(thanosTotalPower).ToString(), "PEOPLE")}" }; await Methods.PostBattlefield(invalidUnitCountKillMessage); } return(response); }
internal void AddItem(Types.Item item) { m_Items.Add(item); }