public NightInstruction(Game game, NightFormModel model) { Action = model.Action; Actor = game.Players.Where(p => p.Id == model.ActorId).Single(); if (Action != NightActionEnum.Sleep) { Whom = game.Players.Where(p => p.Id == model.Whom).Single(); } }
public void ProcessNightInstruction(NightFormModel model) { var i = new NightInstruction(this, model); i.Actor.AI.LastNightAction = model; var logEvent = new GameEvent(i); AddToLog(logEvent); if (CurrentTurn().NightInstructions.Any()) { var existing = CurrentTurn().NightInstructions.Where(x => x.Actor == i.Actor).FirstOrDefault(); if (existing != null) { throw new Exception("Night instructions already given for player & turn."); } } CurrentTurn().NightInstructions.Add(i); Hub.DisplayNightActionsEntered(this); if (CurrentTurn().NightInstructions.Count() == MobilePlayers.Count()) { FinishNight(); } }
public NightFormModel GetNightInstruction(List <string> ids, int turnId) { var otherIds = ids.Where(x => x != Me.Id).ToList(); // if it's the first night, ensure we have a relation object for each other player foreach (var id in otherIds) { var dummy = Relation(id); } var d = new NightFormModel() { ActorId = Me.Id }; if (otherIds.Any()) { d.Whom = RandomId(otherIds); if (Me.IsVampire) { if (r.NextDouble() * 10 - r.NextDouble() * 5 < turnId) { d.Action = NightActionEnum.Bite; } else if (r.NextDouble() * 10 < 3) { d.Action = NightActionEnum.Watch; } else { d.Action = NightActionEnum.Sleep; } } else { if (r.NextDouble() * 10 < 5) { d.Action = NightActionEnum.Watch; } else { d.Action = NightActionEnum.Sleep; } } if (d.Action == NightActionEnum.Bite) { var maxTastiness = 0d; foreach (var re in Relations.Where(x => otherIds.Contains(x.PlayerId)).Where(x => !x.KnownVampire)) { var t = re.GussedBites; if (t > 2.5) { t = 2.5; } t = t + r.NextDouble() * 2; // if we think someone may already be a vampire, don't bite them // todo: but it helps to know for sure they are..... t -= MIstrustToMult(0 - re.DarkSideSuspicion); if (t > maxTastiness) { maxTastiness = t; d.Whom = re.PlayerId; } } Relation(d.Whom).KnownBites++; Relation(d.Whom).GussedBites++; if (Relation(d.Whom).KnownBites >= 3) { Relation(d.Whom).KnownVampire = true; Relation(d.Whom).Enmity -= 2; Relation(d.Whom).DarkSideSuspicion += 10; } } } else { d.Action = NightActionEnum.Sleep; } if (d.Action == NightActionEnum.Sleep || ( d.Action == NightActionEnum.Bite && r.NextDouble() * 5 - r.NextDouble() * 5 > SuspicionAgainstMe ) ) { if (Me.Strategy == StrategyEnum.AI) { var isTrue = d.Action == NightActionEnum.Sleep; var comms = new CommsEvent(Me, CommsTypeEnum.WillSleep, !isTrue, Me); SuspicionAgainstMe -= .1; Hub.AnnounceComms(Me.Game, comms); LastNightAnnouncedSleep.Add(Me.Id); } } LastNightAction = d; if (d.Action != NightActionEnum.Sleep) { // assuming someone might observe SuspicionAgainstMe += .2; } return(d); }