async Task IMonsterGrain.SetRoomGrain(IRoomGrain room) { if (this.roomGrain != null) await this.roomGrain.Exit(this.monsterInfo); this.roomGrain = room; await this.roomGrain.Enter(this.monsterInfo); }
private Task MakeMonster(MonsterInfo data, IRoomGrain room) { var monsterGrain = GrainFactory.GetGrain<IMonsterGrain>(data.Id); monsterGrain.SetInfo(data); monsterGrain.SetRoomGrain(room); return Task.FromResult(true); }
Task<string> IMonsterGrain.Kill(IRoomGrain room) { if (this.roomGrain != null) { if (this.roomGrain.GetPrimaryKey() != room.GetPrimaryKey()) { return Task.FromResult(monsterInfo.Name + " snuck away. You were too slow!"); } return this.roomGrain.Exit(this.monsterInfo).ContinueWith(t => monsterInfo.Name + " is dead."); } return Task.FromResult(monsterInfo.Name + " is already dead. You were too slow and someone else got to him!"); }
async Task Move() { var directions = new string [] { "north", "south", "west", "east" }; var rand = new Random().Next(0, 4); IRoomGrain nextRoom = await this.roomGrain.ExitTo(directions[rand]); if (null == nextRoom) return; await this.roomGrain.Exit(this.monsterInfo); await nextRoom.Enter(this.monsterInfo); this.roomGrain = nextRoom; }
async Task IPlayerGrain.Die() { // Drop everything var tasks = new List<Task<string>>(); foreach (var thing in new List<Thing>(things)) { tasks.Add(this.Drop(thing)); } await Task.WhenAll(tasks); // Exit the game if (this.roomGrain != null) { await this.roomGrain.Exit(myInfo); this.roomGrain = null; killed = true; } }
private async Task MakeMonster(MonsterInfo data, IRoomGrain room) { var monsterGrain = GrainClient.GrainFactory.GetGrain<IMonsterGrain>(data.Id); await monsterGrain.SetInfo(data); await monsterGrain.SetRoomGrain(room); }
async Task<string> Go(string direction) { IRoomGrain destination = await this.roomGrain.ExitTo(direction); StringBuilder description = new StringBuilder(); if (destination != null) { await this.roomGrain.Exit(myInfo); await destination.Enter(myInfo); this.roomGrain = destination; var desc = await destination.Description(myInfo); if (desc != null) description.Append(desc); } else { description.Append("You cannot go in that direction."); } if (things.Count > 0) { description.AppendLine("You are holding the following items:"); foreach (var thing in things) { description.AppendLine(thing.Name); } } return description.ToString(); }
Task IPlayerGrain.SetRoomGrain(IRoomGrain room) { this.roomGrain = room; return room.Enter(myInfo); }