public Task RefreshListGroupDice() { return(Task.Run(() => { var listGroupDice = _diceDataBase.GetGroupDice(Bag.ID); //First Login in app if (Bag == null || Bag.ID == 0) { ExecuteResetBagCommand(); } else if (listGroupDice == null || listGroupDice.Count == 0) { DesactiveBag(Bag); return; } GroupDices.Clear(); foreach (var item in listGroupDice) { GroupDices.Add(item); } var taskLog = _diceDataBase.GetLogRollAsync(); var log = taskLog.Result; LogRoll.Clear(); foreach (var item in log) { LogRoll.Add(item); } taskLog.Wait(); })); }
private void WriteDescriptionRollDice(ref LogRoll logRoll) { var description = logRoll.GroupDice.Name + "("; foreach (var dice in logRoll.GroupDice?.Dices) { if (!dice.Equals(logRoll.GroupDice.Dices.First())) { description += "+"; } var aux = ""; foreach (var itemResult in dice.Result) { description += $"{aux}{itemResult} "; aux = "+"; } } if (logRoll.GroupDice.Modifier > 0) { description += "+" + logRoll.GroupDice.Modifier.ToString(); } else if (logRoll.GroupDice.Modifier < 0) { description += logRoll.GroupDice.Modifier.ToString(); } description += $")"; logRoll.Description = description; }
public void ExecuteRollDiceCommand(GroupDice groupDice) { var result = _diceService.RollDice(groupDice); LogRoll.Add(result); _diceDataBase.SaveLogRoll(result); groupDice.LastResult = result.Result; GroupDices.ReportItemChange(groupDice); }
public Task <int> SaveLogRoll(LogRoll logRoll) { if (logRoll.ID != 0) { return(database.UpdateAsync(logRoll)); } else { return(database.InsertAsync(logRoll)); } }
public LogRoll RollDice(GroupDice groupDice) { var logRoll = new LogRoll(); logRoll.GroupDice = groupDice; logRoll.Date = DateTime.Now; Random rnd = new Random(); logRoll.Result = 0; foreach (var dice in logRoll.GroupDice.Dices) { dice.Result = new List <int>(); for (int i = 0; i < dice.Quantity; i++) { dice.Result.Add(rnd.Next(1, (1 + dice.NumberFaceOfDice))); } } logRoll.Result = logRoll.GroupDice.Dices.Sum(_ => _.Result.Sum()); logRoll.Result += groupDice.Modifier; WriteDescriptionRollDice(ref logRoll); return(logRoll); }
public void ExecuteClearLogCommand() { LogRoll.Clear(); _diceDataBase.DeleteLogRoll(); }