private async Task MakeNpc(NPCInfo data, IPlayerGrain player) { var npcGrain = GrainFactory.GetGrain <INPCGrain>(player.GetPrimaryKey().ToString() + "Npc" + data.Id); await npcGrain.SetInfo(data, player); IRoomGrain room = GrainFactory.GetGrain <IRoomGrain>(player.GetPrimaryKey().ToString() + "Room" + data.StartIn); await npcGrain.SetRoomGrain(room); await npcGrain.SetPlayerGuid(await player.GetPlayerGuid()); await player.AddNpc(npcGrain); }
private async Task MakeMonster(MonsterInfo data, IPlayerGrain player) { //var monsterGrain = MonsterGrainFactory.GetGrain(data.Id); //var monsterGrain = MonsterGrainFactory.GetGrain(Guid.NewGuid()); var monsterGrain = GrainFactory.GetGrain <IMonsterGrain>(player.GetPrimaryKey().ToString() + "Monster" + data.Id); //var room = await player.GetRandomRoom(); await monsterGrain.SetInfo(data, player); IRoomGrain room = GrainFactory.GetGrain <IRoomGrain>(player.GetPrimaryKey().ToString() + "Room" + data.StartIn); await monsterGrain.SetRoomGrain(room); await monsterGrain.SetPlayerGuid(await player.GetPlayerGuid()); await player.AddMonster(monsterGrain); }
async internal static Task <string> GetDescriptorForState(IGameStateGrain gameState, List <Descriptor> descriptors, IPlayerGrain playerGrain) { if (descriptors != null && descriptors.Count > 0) { if (descriptors.Count == 1) { if (descriptors[0].SetFlags != null && descriptors[0].SetFlags.Count > 0) { await gameState.SetGameStateFlags(descriptors[0].SetFlags); } return(descriptors[0].Text); } else { foreach (var descriptor in descriptors) { if (descriptor.IsDefault != true) { bool conditionsFailed = false; foreach (var flag in descriptor.Flags) { var gs = GrainFactory.GetGrain <IGameStateGrain>(playerGrain.GetPrimaryKey()); if ((await gs.GetStateForKey(flag.Key)) != flag.Value) { conditionsFailed = true; } } if (conditionsFailed == false) { if (descriptor.SetFlags != null && descriptor.SetFlags.Count > 0) { await gameState.SetGameStateFlags(descriptor.SetFlags); } return(descriptor.Text); //return descriptor; } } } if (descriptors[0].SetFlags != null && descriptors[0].SetFlags.Count > 0) { try { await gameState.SetGameStateFlags(descriptors[0].SetFlags); } catch (Exception ex) { Trace.TraceError("Error setting game state flags: " + ex.Message); return("error"); } } return(descriptors[0].Text); } } return("No Descriptors"); }
public async Task setup(IPlayerGrain player) { try { mapFileName = HttpContext.Current.Server.MapPath(mapFileName); if (!File.Exists(mapFileName)) { Trace.WriteLine("Unable to load map file: " + mapFileName, "Error"); throw new Exception("Unable to load map file: " + mapFileName); //return; } var rand = new Random(); var bytes = File.ReadAllText(mapFileName); JavaScriptSerializer deserializer = new JavaScriptSerializer(); var data = deserializer.Deserialize <MapInfo>(bytes); //var rooms = new List<IRoomGrain>(); foreach (var room in data.Rooms) { var roomGr = await MakeRoom(room, player.GetPrimaryKey()); if (room.Id >= 0) { await player.AddRoom(roomGr); } } //await player.SetupRooms(); foreach (var thing in data.Things) { await MakeThing(player, thing); } foreach (var monster in data.Monsters) { await MakeMonster(monster, player); } foreach (var npc in data.NPCs) { await MakeNpc(npc, player); } var thingIds = data.Things.Select(t => t.Id).ToArray(); var monsterIds = data.Monsters.Select(m => m.Id).ToArray(); var npcIds = data.NPCs.Select(n => n.Id).ToArray(); //await player.InitGameState(thingIds, monsterIds, npcIds); await player.InitGameState(data); } catch (Exception ex) { Trace.TraceError("Error with setup: " + ex.Message); Trace.TraceError("Error with setup STACK TRACE: " + ex.StackTrace); } }
async internal static Task<string> GetDescriptorForState(IGameStateGrain gameState, List<Descriptor> descriptors, IPlayerGrain playerGrain) { if (descriptors != null && descriptors.Count > 0) { if (descriptors.Count == 1) { if (descriptors[0].SetFlags != null && descriptors[0].SetFlags.Count > 0) { await gameState.SetGameStateFlags(descriptors[0].SetFlags); } return descriptors[0].Text; } else { foreach (var descriptor in descriptors) { if (descriptor.IsDefault != true) { bool conditionsFailed = false; foreach (var flag in descriptor.Flags) { var gs = GrainFactory.GetGrain<IGameStateGrain>(playerGrain.GetPrimaryKey()); if ((await gs.GetStateForKey(flag.Key)) != flag.Value) conditionsFailed = true; } if (conditionsFailed == false) { if (descriptor.SetFlags != null && descriptor.SetFlags.Count > 0) { await gameState.SetGameStateFlags(descriptor.SetFlags); } return descriptor.Text; //return descriptor; } } } if (descriptors[0].SetFlags != null && descriptors[0].SetFlags.Count > 0) { try { await gameState.SetGameStateFlags(descriptors[0].SetFlags); } catch (Exception ex) { Trace.TraceError("Error setting game state flags: " + ex.Message); return "error"; } } return descriptors[0].Text; } } return "No Descriptors"; }
public async Task setup(IPlayerGrain player) { try { mapFileName = HttpContext.Current.Server.MapPath(mapFileName); if (!File.Exists(mapFileName)) { Trace.WriteLine("Unable to load map file: " + mapFileName, "Error"); throw new Exception("Unable to load map file: " + mapFileName); //return; } var rand = new Random(); var bytes = File.ReadAllText(mapFileName); JavaScriptSerializer deserializer = new JavaScriptSerializer(); var data = deserializer.Deserialize<MapInfo>(bytes); //var rooms = new List<IRoomGrain>(); foreach (var room in data.Rooms) { var roomGr = await MakeRoom(room, player.GetPrimaryKey()); if (room.Id >= 0) await player.AddRoom(roomGr); } //await player.SetupRooms(); foreach (var thing in data.Things) { await MakeThing(player, thing); } foreach (var monster in data.Monsters) { await MakeMonster(monster, player); } foreach (var npc in data.NPCs) { await MakeNpc(npc, player); } var thingIds = data.Things.Select(t => t.Id).ToArray(); var monsterIds = data.Monsters.Select(m => m.Id).ToArray(); var npcIds = data.NPCs.Select(n => n.Id).ToArray(); //await player.InitGameState(thingIds, monsterIds, npcIds); await player.InitGameState(data); } catch (Exception ex) { Trace.TraceError("Error with setup: " + ex.Message); Trace.TraceError("Error with setup STACK TRACE: " + ex.StackTrace); } }
private async Task MakeThing(IPlayerGrain player, Thing thing) { //IRoomGrain roomGrain = await player.GetRoomGrainByRoomId(thing.FoundIn); IRoomGrain roomGrain = GrainFactory.GetGrain <IRoomGrain>(player.GetPrimaryKey().ToString() + "Room" + thing.FoundIn); await roomGrain.Drop(thing); }
private async Task MakeNpc(NPCInfo data, IPlayerGrain player) { var npcGrain = GrainFactory.GetGrain<INPCGrain>(player.GetPrimaryKey().ToString() + "Npc" + data.Id); await npcGrain.SetInfo(data, player); IRoomGrain room = GrainFactory.GetGrain<IRoomGrain>(player.GetPrimaryKey().ToString() + "Room" + data.StartIn); await npcGrain.SetRoomGrain(room); await npcGrain.SetPlayerGuid(await player.GetPlayerGuid()); await player.AddNpc(npcGrain); }
private async Task MakeMonster(MonsterInfo data, IPlayerGrain player) { //var monsterGrain = MonsterGrainFactory.GetGrain(data.Id); //var monsterGrain = MonsterGrainFactory.GetGrain(Guid.NewGuid()); var monsterGrain = GrainFactory.GetGrain<IMonsterGrain>(player.GetPrimaryKey().ToString() + "Monster" + data.Id); //var room = await player.GetRandomRoom(); await monsterGrain.SetInfo(data, player); IRoomGrain room = GrainFactory.GetGrain<IRoomGrain>(player.GetPrimaryKey().ToString() + "Room" + data.StartIn); await monsterGrain.SetRoomGrain(room); await monsterGrain.SetPlayerGuid(await player.GetPlayerGuid()); await player.AddMonster(monsterGrain); }
private async Task MakeThing(IPlayerGrain player, Thing thing) { //IRoomGrain roomGrain = await player.GetRoomGrainByRoomId(thing.FoundIn); IRoomGrain roomGrain = GrainFactory.GetGrain<IRoomGrain>(player.GetPrimaryKey().ToString() + "Room" + thing.FoundIn); await roomGrain.Drop(thing); }