static bool DoEclipsePhaseDice(Campfire.Room room, Campfire.Message msg) { if (!msg.UserID.HasValue) { return(true); } int targetNum; string description = null; string[] diceParams = msg.Body.Remove(0, 3).Trim().Split(new char[] { ' ', '\t' }); if (diceParams.Length == 0) { return(true); } try { targetNum = Convert.ToInt32(diceParams[0]); } catch (FormatException) { return(true); } if (targetNum < 0) { return(true); } if (diceParams.Length > 1) { description = diceParams.Skip(1).Aggregate((first, second) => first + " " + second); } StringBuilder response = new StringBuilder("EPD ("); response.Append(msg.User.Name); if (description != null) { response.Append(' '); response.Append(description); } response.Append(") "); response.Append(" ==> "); DiceRoll roll = m_dice.Roll(1, 100, 0); response.Append(GenerateEclipsePhaseResult(roll.Value, targetNum)); room.Speak("TextMessage", response.ToString()); return(true); }
static bool DoDice(Campfire.Room room, Campfire.Message msg) { if (!msg.UserID.HasValue) { return(true); } List <string> diceSpecs = new List <string>(); string description = null; string[] diceParams = msg.Body.Remove(0, 5).Trim().Split(new char[] { ' ', '\t' }); if (diceParams.Length == 0) { return(true); } for (int i = 0; i < diceParams.Length; ++i) { if (DiceRoll.LooksLikeASpec(diceParams[i])) { diceSpecs.Add(diceParams[i]); } else { if (i == 0) { return(true); } description = diceParams.Skip(i).Aggregate((first, second) => first + " " + second); break; } } StringBuilder response = new StringBuilder(); foreach (string diceSpec in diceSpecs) { if (response.Length != 0) { response.Append("\r\n"); } response.Append("DICE ("); response.Append(msg.User.Name); if (description != null) { response.Append(' '); response.Append(description); } response.Append(") "); response.Append(" ==> "); try { DiceRoll roll = m_dice.Roll(diceSpec); response.Append(roll.Description); } catch (ArgumentException) { return(true); } } room.Speak(diceSpecs.Count() == 1 ? "TextMessage" : "PasteMessage", response.ToString()); return(true); }