public override Task OnActivateAsync() { this.myInfo = new PlayerInfo { Key = this.GetPrimaryKey(), Name = "nobody" }; return base.OnActivateAsync(); }
Task IRoomGrain.Enter(PlayerInfo player) { players.RemoveAll(x => x.Key == player.Key); players.Add(player); return TaskDone.Done; }
Task IRoomGrain.Exit(PlayerInfo player) { players.RemoveAll(x => x.Key == player.Key); return TaskDone.Done; }
Task<string> IRoomGrain.Description(PlayerInfo whoisAsking) { StringBuilder sb = new StringBuilder(); sb.AppendLine(this.description); if (things.Count > 0) { sb.AppendLine("The following things are present:"); foreach (var thing in things) { sb.Append(" ").AppendLine(thing.Name); } } var others = players.Where(pi => pi.Key != whoisAsking.Key).ToArray(); if (others.Length > 0 || monsters.Count > 0) { sb.AppendLine("Beware! These guys are in the room with you:"); if (others.Length > 0) foreach (var player in others) { sb.Append(" ").AppendLine(player.Name); } if (monsters.Count > 0) foreach (var monster in monsters) { sb.Append(" ").AppendLine(monster.Name); } } return Task.FromResult(sb.ToString()); }