private void AddOrUpdate(IDataSnapshot snap) { Debug.Print(snap.Key); string previousKey = this.LastKey; foreach (IDataSnapshot child in snap.Children) { IFireObject fireObjectInstance = (IFireObject)JsonConvert.DeserializeObject(child.Value(), this.ObjectType); fireObjectInstance.Key = child.Key; this.addOrUpdate(fireObjectInstance); } if (previousKey != this.LastKey) { myQuery.Off(); if (this.UserId != null) { //filter on user //.StartAtKey(lastKey) myQuery = FireDictDelegate.firebaseApp.Child(this.Path).OrderByChild(USERIDKEY).EqualTo(this.UserId).StartAtKey(lastKey).On(FIREEVENTADD, (snap2, previous_child, context) => AddOrUpdate(snap2)); } else { myQuery = FireDictDelegate.firebaseApp.Child(this.Path).StartAtKey(lastKey).On(FIREEVENTADD, (snap2, previous_child, context) => AddOrUpdate(snap2)); } } }
private void Removed(IDataSnapshot snap, string previous_child, object context) { Debug.Print(snap.Key); IFireObject fireObjectInstance = (IFireObject)JsonConvert.DeserializeObject(snap.Value(), this.ObjectType); fireObjectInstance.Key = snap.Key; this.remove(fireObjectInstance); }
public void object_deleted(IFireObject fireObject) { Debug.Print("Object deleted : " + fireObject.Revision); if (fireObject.Path == "GameCommand") { updateMap(); } }
public void Add(IFireObject new_firecamp) { this.m_Firecamps.Add(new_firecamp); foreach (Construction construction in Construction.s_EnabledConstructions) { if ((construction.gameObject.GetComponent <IFireObject>() == null || !this.m_Firecamps.Contains((IFireObject)construction)) && !this.m_SurroundingConstructions.Contains(construction) && new_firecamp.GetConstruction().transform.position.Distance(construction.transform.position) <= 15f) { this.m_SurroundingConstructions.Add(construction); } } this.UpdateBounds(); }
public void object_added(IFireObject fireObject) { if (fireObject.Path == "PlayerMapTile") { //redraw game // this.redrawMap(); PlayerMapTile gameMapTile = (PlayerMapTile)fireObject; PlayerGame playerGame = this.flPlayerGames.TypedItems <PlayerGame>().Where(c => c.UserId == me.Id).FirstOrDefault(); if (playerGame != null) { MapTile mapTile = playerGame.Map.MapTiles.Where(c => c.Xpos == gameMapTile.Tile.Xpos && c.Ypos == gameMapTile.Tile.Ypos).FirstOrDefault(); if (mapTile != null) { mapTile = gameMapTile.Tile; RedrawMapTile(mapTile); } } } else if (fireObject.Path == "PlayerUnit") { updateMap(); } else if (fireObject.Path == "CommandFeedback") { SpeechSynthesizer synthesizer = new SpeechSynthesizer(); synthesizer.Volume = 100; // 0...100 synthesizer.Rate = -2; // -10...10 // Asynchronous CommandFeedback feedback = (CommandFeedback)fireObject; //foreach (InstalledVoice voice in synthesizer.GetInstalledVoices()) //{ // Debug.Print(voice.VoiceInfo.Name); //} //synthesizer.SelectVoice(synthesizer.GetInstalledVoices()[1].VoiceInfo.Name); synthesizer.SpeakAsync(feedback.Feedback); } else if (fireObject.Path == "PlayerGame") { //All visible player units (both own and enemy) PlayerGame pg = (PlayerGame)fireObject; this.flPlayerUnits = new FireList(this.FAppPrivate, typeof(PlayerUnit), this, new FireListBox(lbxPlayerUnits), userId: pg.GameId, userIDKey: "GameId"); } Debug.Print("Object added : " + fireObject.Revision); }
public void OnDestroyFirecamp(IFireObject firecamp) { if (firecamp.GetConstruction().IsSceneObject()) { return; } foreach (FirecampGroup firecampGroup in this.m_FirecampGroups) { if (firecampGroup.Contains(firecamp)) { firecampGroup.Remove(firecamp); if (firecampGroup.GetAllCount() == 0) { this.m_FirecampGroups.Remove(firecampGroup); break; } break; } } }
public bool CanAdd(IFireObject new_firecamp) { using (List <IFireObject> .Enumerator enumerator = this.m_Firecamps.GetEnumerator()) { while (enumerator.MoveNext()) { if (enumerator.Current.GetConstruction().transform.position.Distance(new_firecamp.GetConstruction().transform.position) <= 15f) { return(true); } } } foreach (Construction construction in this.m_SurroundingConstructions) { if (construction && construction.transform.position.Distance(new_firecamp.GetConstruction().transform.position) <= 15f) { return(true); } } return(false); }
public void OnCreateFirecamp(IFireObject firecamp) { if (firecamp.GetConstruction().IsSceneObject()) { return; } this.m_TempFirecampGroups.Clear(); foreach (FirecampGroup firecampGroup in this.m_FirecampGroups) { if (firecampGroup.CanAdd(firecamp)) { firecampGroup.Add(firecamp); this.m_TempFirecampGroups.Add(firecampGroup); } } if (this.m_TempFirecampGroups.Count == 0) { FirecampGroup firecampGroup2 = new FirecampGroup(); firecampGroup2.Add(firecamp); this.m_FirecampGroups.Add(firecampGroup2); return; } if (this.m_TempFirecampGroups.Count > 1) { float num = 0f; foreach (FirecampGroup firecampGroup3 in this.m_TempFirecampGroups) { num = Mathf.Max(num, firecampGroup3.m_BurningFactor); } FirecampGroup firecampGroup4 = this.m_TempFirecampGroups[0]; firecampGroup4.m_BurningFactor = num; while (this.m_TempFirecampGroups.Count > 1) { firecampGroup4.Add(this.m_TempFirecampGroups[1]); this.m_FirecampGroups.Remove(this.m_TempFirecampGroups[1]); this.m_TempFirecampGroups.RemoveAt(1); } } }
public void updateDelegates(IFireObject fireObject) { // InvokeRequired required compares the thread ID of the // calling thread to the thread ID of the creating thread. // If these threads are different, it returns true. foreach (IFireControl control in this.UISubscriptionList) { if (control == null) { return; } if (control.InvokeRequired) { SetListCrudCallback d = new SetListCrudCallback(updateDelegates); ((Form)this.FireDictDelegate).Invoke(d, new object[] { fireObject }); } else { control.Update((this.Items.Select(x => x.Value))); } } }
public void IgniteFireObject(IFireObject fire_object) { this.m_Animator.SetTrigger(this.m_TCarriedFireIgnite); this.m_FireObjectToIgnite = fire_object; }
public void Remove(IFireObject firecamp) { this.m_Firecamps.Remove(firecamp); this.UpdateBounds(); }
public void Add(IFireObject item) { this.ListBox.Items.Add(item); }
public bool Contains(IFireObject firecamp) { return(this.m_Firecamps.Contains(firecamp)); }
public void object_added(IFireObject fireObject) { if (fireObject.Path == "PlayerMapTile") { //redraw game // this.redrawMap(); PlayerMapTile gameMapTile = (PlayerMapTile)fireObject; PlayerGame playerGame = this.flPlayerGames.TypedItems<PlayerGame>().Where(c => c.UserId == me.Id).FirstOrDefault(); if (playerGame != null) { MapTile mapTile = playerGame.Map.MapTiles.Where(c => c.Xpos == gameMapTile.Tile.Xpos && c.Ypos == gameMapTile.Tile.Ypos).FirstOrDefault(); if (mapTile != null) { mapTile = gameMapTile.Tile; RedrawMapTile(mapTile); } } } else if (fireObject.Path == "PlayerUnit") { updateMap(); } else if (fireObject.Path == "CommandFeedback") { SpeechSynthesizer synthesizer = new SpeechSynthesizer(); synthesizer.Volume = 100; // 0...100 synthesizer.Rate = -2; // -10...10 // Asynchronous CommandFeedback feedback = (CommandFeedback)fireObject; synthesizer.SpeakAsync(feedback.Feedback); } else if (fireObject.Path == "PlayerGame") { //All visible player units (both own and enemy) PlayerGame pg = (PlayerGame)fireObject; this.flPlayerUnits = new FireList(this.FAppPrivate, typeof(PlayerUnit), this, new FireListBox(lbxPlayerUnits), userId: pg.GameId, userIDKey: "GameId"); } Debug.Print("Object added : " + fireObject.Revision); }
public void remove(IFireObject fireObject) { this.addOrUpdate(fireObject, true); }
public void IgniteFireObject(IFireObject fire_object) { this.m_FireObject = fire_object; this.m_Animator.SetBool(this.m_TorchHash, true); this.m_Animator.SetTrigger(this.m_TorchIgniteHash); }
public void addOrUpdate(IFireObject fireObject, bool deleted = false) { if (this.Items.Keys.Count > 0 && this.Items.Keys.Contains(fireObject.Id)) { //exists in cache if (deleted) { //deleted this.Items.Remove(fireObject.Id); fireObject.ObjectState = enObjectState.deleted; } else { if (this.Items[fireObject.Id].Revision == fireObject.Revision) { //unchanged fireObject.ObjectState = enObjectState.unchanged; } else { //changed fireObject.ObjectState = enObjectState.updated; this.Items[fireObject.Id] = fireObject; } } } else { //new this.Items.Add(fireObject.Id, fireObject); this.LastKey = fireObject.Key; // for listener optimization fireObject.ObjectState = enObjectState.added; } //send notifications switch (fireObject.ObjectState) { case enObjectState.unchanged: //nothing required break; case enObjectState.updated: this.FireDictDelegate.object_updated(fireObject); if (this.UISubscriptionList != null) { this.updateDelegates(fireObject); } break; case enObjectState.added: this.FireDictDelegate.object_added(fireObject); if (this.UISubscriptionList != null) { this.updateDelegates(fireObject); } break; case enObjectState.deleted: this.FireDictDelegate.object_deleted(fireObject); if (this.UISubscriptionList != null) { this.updateDelegates(fireObject); } break; default: break; } }
public void object_added(IFireObject fireObject) { Debug.Print("Object added : " + fireObject.Revision); if (fireObject.Path == "GameCommand") { GameCommand cmdReceived = (GameCommand)this.fdCommands.Items.Where(c => c.Id == fireObject.Id).FirstOrDefault(); try { if (cmdReceived == null) { new CommandFeedback(cmdReceived, enCommandStatus.Rejected, "Command not found").Save(this.FAppPrivate); } else { Player player = this.fdPlayers.TypedItems<Player>().Where(c => c.UserId == cmdReceived.UserId).FirstOrDefault(); if (player == null) { new CommandFeedback(cmdReceived, enCommandStatus.Rejected, "Player not found").Save(this.FAppPrivate); } else { PlayerGame playerGame = this.flPlayerGames.TypedItems<PlayerGame>().Where(c => c.UserId == cmdReceived.UserId).FirstOrDefault(); string gameId; if (playerGame != null) { gameId = playerGame.GameId; } else { gameId = cmdReceived.ObjectId; } Game game = this.fdGames.TypedItems<Game>().Where(c => c.Id == gameId).FirstOrDefault(); switch (cmdReceived.Command) { case enCommand.JoinGame: JoinGame(cmdReceived, player, playerGame, game); break; case enCommand.LeaveGame: LeaveGame(cmdReceived, playerGame, game); break; case enCommand.AddUnit: AddUnit(cmdReceived, playerGame, game); break; case enCommand.MoveForward: MoveUnit(cmdReceived, playerGame, game); break; case enCommand.MoveBackward: cmdReceived.Distance = -cmdReceived.Distance; MoveUnit(cmdReceived, playerGame, game); break; case enCommand.RotateCCW: //per 45 graden RotateUnit(cmdReceived, playerGame, game); break; case enCommand.RotateCW: RotateUnit(cmdReceived, playerGame, game); break; case enCommand.FireFixedGun: FireFixedGun(cmdReceived, playerGame, game); break; case enCommand.RotateTurretCCW: break; case enCommand.RotateTurretCW: break; default: new CommandFeedback(cmdReceived, enCommandStatus.Rejected, "Unknown command").Save(this.FAppPrivate); break; } } } cmdReceived.Delete(this.FAppPrivate); } catch (Exception e) { new CommandFeedback(cmdReceived, enCommandStatus.Rejected, "Error: " + e.InnerException.Message).Save(this.FAppPrivate); cmdReceived.Delete(this.FAppPrivate); //throw; } } }
public void object_deleted(IFireObject fireObject) { Debug.Print("Object deleted : " + fireObject.Revision); }
public void object_added(IFireObject fireObject) { Debug.Print("Object added : " + fireObject.Revision); if (fireObject.Path == "GameCommand") { GameCommand cmdReceived = (GameCommand)this.fdCommands.Items.Where(c => c.Id == fireObject.Id).FirstOrDefault(); try { if (cmdReceived == null) { new CommandFeedback(cmdReceived, enCommandStatus.Rejected, "Command not found").Save(this.FAppPrivate); } else { Player player = this.fdPlayers.TypedItems <Player>().Where(c => c.UserId == cmdReceived.UserId).FirstOrDefault(); if (player == null) { new CommandFeedback(cmdReceived, enCommandStatus.Rejected, "Player not found").Save(this.FAppPrivate); } else { PlayerGame playerGame = this.flPlayerGames.TypedItems <PlayerGame>().Where(c => c.UserId == cmdReceived.UserId).FirstOrDefault(); string gameId; if (playerGame != null) { gameId = playerGame.GameId; } else { gameId = cmdReceived.ObjectId; } Game game = this.fdGames.TypedItems <Game>().Where(c => c.Id == gameId).FirstOrDefault(); switch (cmdReceived.Command) { case enCommand.JoinGame: JoinGame(cmdReceived, player, playerGame, game); break; case enCommand.LeaveGame: LeaveGame(cmdReceived, playerGame, game); break; case enCommand.AddUnit: AddUnit(cmdReceived, playerGame, game); break; case enCommand.MoveForward: MoveUnit(cmdReceived, playerGame, game); break; case enCommand.MoveBackward: cmdReceived.Distance = -cmdReceived.Distance; MoveUnit(cmdReceived, playerGame, game); break; case enCommand.RotateCCW: //per 45 graden RotateUnit(cmdReceived, playerGame, game); break; case enCommand.RotateCW: RotateUnit(cmdReceived, playerGame, game); break; case enCommand.FireFixedGun: FireFixedGun(cmdReceived, playerGame, game); break; case enCommand.RotateTurretCCW: break; case enCommand.RotateTurretCW: break; default: new CommandFeedback(cmdReceived, enCommandStatus.Rejected, "Unknown command").Save(this.FAppPrivate); break; } } } cmdReceived.Delete(this.FAppPrivate); } catch (Exception e) { new CommandFeedback(cmdReceived, enCommandStatus.Rejected, "Error: " + e.InnerException.Message).Save(this.FAppPrivate); cmdReceived.Delete(this.FAppPrivate); //throw; } } }
public void object_updated(IFireObject fireObject) { Debug.Print("Object updated : " + fireObject.Revision); }