private async Task Combatant_Death(IEntity deadCombatant) { deadCombatant.Died -= Combatant_Death; Dead.Add(deadCombatant); Debug.WriteLine("Combatant Died " + deadCombatant.Name); // figure out how many are alive per faction foreach (var faction in Factions.Keys.ToList()) { // if a faction has no members alive then we are ending var aliveCount = Factions[faction].Count(e => !Dead.Contains(e)); if (aliveCount == 0) { _ended = true; foreach (var combatant in Combatants.Keys.ToList()) { combatant.Died -= Combatant_Death; } if (Ended != null) { await Ended.Invoke(this, EncounterEndings.Death); } //break; return; } } }
public void SetStates(bool needsLock = true) { if (needsLock) { Do(() => SetStates(false)); return; } foreach (var usr in VC.Users) { usr.ModifyAsync(x => { x.Mute = InDiscussion == false || Dead.Contains(usr.Id); x.Deaf = InDiscussion == false; // ghosts can still listen. }); } }
public void Broadcast(bool needsLock = true) { if (needsLock) { Do(() => Broadcast(false)); return; } List <GroupGameWS> rm = new List <GroupGameWS>(); foreach (var ws in Listeners) { var jobj = new JObject(); jobj["discuss"] = InDiscussion; var jarr = new JArray(); foreach (var usr in VC.Users) { var jUsr = new JObject(); jUsr["id"] = usr.Id.ToString(); jUsr["name"] = usr.Nickname ?? usr.Username; jUsr["dead"] = Dead.Contains(usr.Id); jarr.Add(jUsr); } jobj["dead"] = Dead.Contains(ws.BotUser.Id); jobj["users"] = jarr; try { ws.Context.WebSocket.Send(jobj.ToString()); } catch (Exception ex) { Program.LogMsg($"GM:{ws.BotUser?.Name}", ex); rm.Add(ws); } } foreach (var x in rm) { Listeners.Remove(x); } }
public async Task TickAsync(IGame game) { if (_ended) { return; } // if no factions are on the same map then pause operations var maps = Combatants.Keys.Select(c => c.Map.Id).Distinct(); if (maps.Count() == Combatants.Keys.Count()) { // no combatants are on the same map... skip return; } // any pending actions from not dead combatant? var entities = Combatants.Keys.Where(k => !Dead.Contains(k)).Select(o => o).ToList(); foreach (var entity in entities) { // player offline? if (entity.IsPlayer() && !game.Players.Contains((IPlayer)entity)) { // are there any players left? pause combat // i dont like making the specific decision about no offline combat here.. // needs configuration in future if (Combatants.Keys.Count(k => k.IsPlayer() && game.Players.Contains((IPlayer)k)) == 0) { return; } } var combatant = (ICombatant <GridTargetAction>)Combatants[entity]; if (combatant.CanAttack) { var nextAction = await combatant.GetNextActionAsync(this); if (nextAction == null) { continue; } if (nextAction.SourceEntity == null) { nextAction.SourceEntity = (GridEntity)entity; } if (nextAction.TargetEntities.Count == 0) { await nextAction.SetDefaultTargetAsync(this); } var executed = await nextAction.Execute(); if (executed) { LastAction = DateTime.Now; ActionLog.Add(nextAction); if (ActionExecuted != null) { await ActionExecuted.Invoke(this, nextAction); } } } } }
public bool IsAlive(Player player) { return(!Dead.Contains(player)); }