// Start is called before the first frame update void Start() { //Check if there is already an instance of SoundManager if (instance == null) { //if not, set it to this. instance = this; } //If instance already exists: else if (instance != this) { //Destroy this, this enforces our singleton pattern so there can only be one instance of SoundManager. Destroy(gameObject); BoltConsole.Write("ItemBox copy destroyed"); } gamestate = GameObject.Find("GameState(Clone)").GetComponent <NetworkGameState>(); localPlayer = GameObject.FindGameObjectWithTag("LocalPlayer").GetComponent <Player>(); itemForGrabsStr = gamestate.ItemForGrabs(); if (itemForGrabsStr != null && !itemForGrabsStr.Equals("")) { textStatus.text = yesItemHere; itemObjNetwork = ItemList.instance.GetItemFromName(itemForGrabsStr); itemSlotButton.onClick.AddListener(() => inventory.ShowThirdPartyItemInfo(itemObjNetwork)); itemForGrabsImage.sprite = itemObjNetwork.sprite; itemForGrabsImage.enabled = true; } else { textStatus.text = noItemHere; } }
public void SetupCharacterSelectionUI() { BoltConsole.Write("SetupPlayer", Color.green); Debug.Log("SetupPlayer"); //this.transform.SetParent(GameObject.Find("LobbyPanel").transform); //Hardcoded for prototyping and testing //this.transform.localPosition = new Vector3(200f, -800f, 0f); //this.transform.localScale = new Vector3(.6f, .6f, 1f); alchemistButton.onClick.RemoveAllListeners(); alchemistButton.onClick.AddListener(OnAlchemistClicked); arcanistButton.onClick.RemoveAllListeners(); arcanistButton.onClick.AddListener(OnArcanistClicked); elementalistButton.onClick.RemoveAllListeners(); elementalistButton.onClick.AddListener(OnElementalistClicked); chronomancerButton.onClick.RemoveAllListeners(); chronomancerButton.onClick.AddListener(OnChronomancerClicked); illusionistButton.onClick.RemoveAllListeners(); illusionistButton.onClick.AddListener(OnIllusionistClicked); summonerButton.onClick.RemoveAllListeners(); summonerButton.onClick.AddListener(OnSummonerClicked); }
/* * // Called from Network, everyone recieves this. * public void CheckCrisisPhase1(Player p, string crisisName, string location) * { * CheckCrisis(p, crisisName, location); * }*/ // Called from Network, everyone recieves this. // finishAction is either: // FinishPlague() // FinishTsunami() // FinishBossBattle() // // spellcasterHero is an empty string if everyone failed to counter the crisis public void FinishCrisis(Action finishAction, bool isSolved, string spellcasterHero) { BoltConsole.Write("Finish Crisis. "); this.spellcasterHero = spellcasterHero; crisisSolved = isSolved; finishAction(); }
/*TODO: Have this only be called when Host presess start game in the lobby*/ public void determineGlobalEvents() { spellcasterList = NetworkGameState.instance.spellcasterList; list_AllEvents = new List <GlobalEvent>(); evntInfo = new Dictionary <string, string>(); if (spellcasterList[elementalistID] > 0) { Debug.Log("Adding elementalist"); GlobalEvent tsunami = new GlobalEvent("Tsunami", GlobalEventDescriptions.tsunamiDesc, 2, 3, Tsunami); evntInfo[tsunami.name] = tsunami.description; list_AllEvents.Add(tsunami); } /*Randomize event order at the start of the game*/ Shuffler.Shuffle(list_AllEvents); GlobalEvent finalBoss = new GlobalEvent("Apocalypse", "Final Boss", 7, 10, FinalBossBattle); list_AllEvents.Add(finalBoss); evntInfo[finalBoss.name] = finalBoss.description; BoltConsole.Write("Global Event Order:"); Debug.Log("Global Event Order:"); foreach (GlobalEvent evnt in list_AllEvents) { BoltConsole.Write(evnt.name); Debug.Log(evnt.name); } NetworkGameState.instance. setNextEvent(list_AllEvents[currentEventIndex].name, list_AllEvents[currentEventIndex].description, list_AllEvents[currentEventIndex].yearsItTakesToHappen); }
// Bolt's version of the Unity's Start() public override void Attached() { BoltConsole.Write("Attached - NetworkGameState"); //Check if there is already an instance of SoundManager if (instance == null) { //if not, set it to this. instance = this; } //If instance already exists: else if (instance != this) { //Destroy this, this enforces our singleton pattern so there can only be one instance of SoundManager. Destroy(gameObject); } DontDestroyOnLoad(this); if (entity.isOwner) { spellcasterList = new int[6]; //state.SpellcasterList[0] = 0; //combatOrder = new int[6]; state.BossMaxHealth = 30f; state.BossHealth = 30f; state.TapSecondsAllowed = 8f; turnOrder = new List <int>(); } }
/*Only the server recieves this event.*/ public override void OnEvent(SelectSpellcaster evnt) { BoltConsole.Write("SERVER: Recieved a new character selection event"); if (evnt.RaisedBy != null) { //BoltConsole.Write("Sent by: " + evnt.RaisedBy.ToString()); //Get the connection as a string and update the dictionary using that as the key. string con = evnt.RaisedBy.ToString(); if (connection_spellcaster.ContainsKey(con)) { connection_spellcaster[evnt.RaisedBy.ToString()] = evnt.spellcasterID; } else { connection_spellcaster.Add(con, evnt.spellcasterID); } } // Let the gamestate know about the new selected spellcaster and the previous selected one (if any). gameStateEntity.GetComponent <NetworkGameState>() .onSpellcasterSelected(evnt.spellcasterID, evnt.previousID); //Show the start button to the host if all player's have selected their spellcaster if (gameStateEntity.GetComponent <NetworkGameState>().allPlayersSelected()) { startGameButton.SetActive(true); } }
public override void Connected(BoltConnection connection) { BoltLog.Warn("Connected"); ServerAcceptToken acceptToken = connection.AcceptToken as ServerAcceptToken; if (acceptToken != null) { BoltConsole.Write("AcceptToken: " + acceptToken.GetType().ToString()); BoltConsole.Write("AcceptToken: " + acceptToken.data); } else { BoltLog.Warn("AcceptToken is NULL"); } ServerConnectToken connectToken = connection.ConnectToken as ServerConnectToken; if (connectToken != null) { BoltConsole.Write("ConnectToken: " + connectToken.GetType().ToString()); BoltConsole.Write("ConnectToken: " + connectToken.data); } else { BoltLog.Warn("ConnectToken is NULL"); } }
public override void Connected(BoltConnection connection) { if (BoltNetwork.IsClient) { BoltConsole.Write("Connected Client: " + connection, Color.blue); infoPanel.gameObject.SetActive(false); string prevMatch = PreviousMatchName(); BoltConsole.Write("Previous match if any: " + prevMatch); if (prevMatch != matchName) { BoltConsole.Write("New Game"); ChangeTo(lobbyPanel); } else { BoltConsole.Write("Joining previous match"); var returnPlayerEvnt = ReturnPlayerEvent.Create(Bolt.GlobalTargets.OnlyServer); returnPlayerEvnt.Send(); } } else if (BoltNetwork.IsServer) { BoltConsole.Write("Connected Server: " + connection, Color.blue); BoltEntity entity = BoltNetwork.Instantiate(BoltPrefabs.CharacterSelectionEntity); entity.AssignControl(connection); int numPlayers = gameStateEntity.GetComponent <NetworkGameState>().onPlayerJoined(); var playerTurnEvnt = PlayerJoinedEvent.Create(Bolt.GlobalTargets.Everyone); playerTurnEvnt.numOfPlayers = numPlayers; playerTurnEvnt.Send(); } }
public override void OnEvent(TakeDamageEvent evnt) { if (evnt.Entity.IsOwner) { if (evnt.Entity.Source == null) { BoltEntity entity = evnt.Entity; PlayerHealth playerHealth = entity.GetComponent <PlayerHealth>(); playerHealth.TakeDamage(evnt.Damage); } } else { if (evnt.Entity.Source == null) { BoltConsole.Write("empty soiurce"); } else { var newEvnt = TakeDamageEvent.Create(evnt.Entity.Source); newEvnt.Damage = evnt.Damage; newEvnt.Entity = evnt.Entity; newEvnt.Send(); } } }
public override void SceneLoadLocalDone(string map) { BoltConsole.Write("New scene: " + map, Color.yellow); try { if (lobbyScene.SimpleSceneName == map) { ChangeTo(mainMenuPanel); topPanel.isInGame = false; } else if (gameScene.SimpleSceneName == map) { ChangeTo(null); backDelegate = Stop; topPanel.isInGame = true; topPanel.ToggleVisibility(false); // Spawn Player // SpawnGamePlayer(); } } catch (Exception e) { BoltConsole.Write(e.Message, Color.red); BoltConsole.Write(e.Source, Color.red); BoltConsole.Write(e.StackTrace, Color.red); } }
// ----------------- Server callbacks ------------------ public override void BoltStartBegin() { BoltConsole.Write("BoltStartBegin breh"); BoltNetwork.RegisterTokenClass <RoomProtocolToken>(); BoltNetwork.RegisterTokenClass <ServerAcceptToken>(); BoltNetwork.RegisterTokenClass <ServerConnectToken>(); }
public void SetupPlayer() { BoltConsole.Write("SetupPlayer", Color.green); LobbyPlayerList._instance.AddPlayer(this); localPlayer = this; nameInput.interactable = true; remoteIcone.gameObject.SetActive(false); localIcone.gameObject.SetActive(true); removePlayerButton.gameObject.SetActive(false); removePlayerButton.interactable = false; ChangeReadyButtonColor(JoinColor); readyButton.transform.GetChild(0).GetComponent <Text>().text = "JOIN"; readyButton.interactable = true; //we switch from simple name display to name input colorButton.interactable = true; nameInput.interactable = true; nameInput.onEndEdit.RemoveAllListeners(); nameInput.onEndEdit.AddListener(OnNameChanged); colorButton.onClick.RemoveAllListeners(); colorButton.onClick.AddListener(OnColorClicked); readyButton.onClick.RemoveAllListeners(); readyButton.onClick.AddListener(OnReadyClicked); OnClientReady(state.Ready); }
public override void ControlGained() { BoltConsole.Write("ControlGained", Color.blue); readyButton.transform.GetChild(0).GetComponent <Text>().color = Color.white; SetupPlayer(); }
public override void OnEvent(LogEvent evnt) { Debug.Log(evnt.Message); BoltConsole.Write(evnt.Message); staticData.myAdditiveWorld = evnt.Message; sceneLoader.LoadWorld(); }
private void RemoveDisconnectedPlayerContainers() { BoltConsole.Write("RemoveDisconnectedPlayerContainers", Color.yellow); players.RemoveAll(x => x.InGame == false); RebuildRosterList(); }
public override void Connected(BoltConnection connection) { if (BoltNetwork.IsClient) { Debug.Log(BoltNetwork.Server.AcceptToken); BoltConsole.Write(BoltNetwork.Server.AcceptToken.ToString()); } }
IEnumerator UpdateHostInfoRoutine(System.Object protocolToken) { var t = new Timer(ROOM_CREATE_TIMEOUT); while (_lbClient.State != ClientState.JoinedLobby && t.Waiting) { yield return(null); } if (_lbClient.State != ClientState.Joined) { BoltLog.Warn("Can't call BoltNetwork.UpdateHostInfo while not in a room"); yield break; } //var maxPlayers = dedicated ? BoltNetwork.maxConnections : BoltNetwork.maxConnections + 1; var customRoomProperties = default(ExitGames.Client.Photon.Hashtable); // check for old host info token var hostInfoToken = protocolToken as PhotonHostInfoToken; if (hostInfoToken != null) { customRoomProperties = hostInfoToken.CustomRoomProperties; } // check for new interface based version var boltPhotonCloudRoomProperties = protocolToken as IBoltPhotonCloudRoomProperties; if (boltPhotonCloudRoomProperties != null) { customRoomProperties = boltPhotonCloudRoomProperties.CustomRoomProperties; } // last resort, create a new empty table if (customRoomProperties == null) { customRoomProperties = new ExitGames.Client.Photon.Hashtable(); } // if we have a protocol token, and it's not PhotonHostInfoToken package it into the room properties as Byte[] if (protocolToken != null && !(protocolToken is PhotonHostInfoToken)) { customRoomProperties["UserToken"] = ProtocolTokenUtils.ToByteArray((IProtocolToken)protocolToken); } // session id //customRoomProperties["UdpSessionId"] = Guid.NewGuid().ToString(); // if we allow punch //if(_config.UsePunchThrough) { // customRoomProperties["SocketPeerId"] = BoltNetwork.UdpSocket.SocketPeerId.ToString(); //} // _lbClient.OpSetCustomPropertiesOfRoom(customRoomProperties); BoltConsole.Write("Updating room properties"); }
public NetworkError(string name, string cause, string tip) { this.Name = name; this.Cause = cause; this.Tip = tip; UnityEngine.Debug.LogError("Error: " + name + " - " + cause + " - " + tip); BoltConsole.Write("Error: " + name + " - " + cause + " - " + tip, UnityEngine.Color.red); }
private void OnSceneLoadedLocally(string scene) { BoltConsole.Write("OnSceneLoadedLocally", Color.yellow); if (scene == "Debug") { BoltNetwork.Instantiate(player); } }
//TODO: start combat here. public override void OnEvent(FinalBoss evnt) { BoltConsole.Write("Final Boss battle (not yet implemented so everyone dies)"); BoltConsole.Write("Final Boss battle (not yet implemented so everyone dies)"); PanelHolder.instance.displayNotify("Final Boss Battle", "(not yet implemented so everyone dies)", "OK"); playerSpellcaster = playerEntity.GetComponent <Player>().spellcaster; playerSpellcaster.TakeDamage((int)(playerSpellcaster.fCurrentHealth)); SpellCaster.savePlayerData(playerSpellcaster); }
/*Only the server recieves this event. * Similar to NextTurnEvent, but doesn't update the turn. * Used for network disconnection. * Sends the current spellcasterId. */ public override void OnEvent(NotifyTurnEvent evnt) { BoltConsole.Write("SERVER: Recieved a Notify turn event"); int currentSpellcaster = gameStateEntity.GetComponent <NetworkGameState>().getCurrentTurn(); var nextTurnEvnt = NextPlayerTurnEvent.Create(Bolt.GlobalTargets.Everyone); nextTurnEvnt.NextSpellcaster = currentSpellcaster; nextTurnEvnt.Send(); }
//Clear the itembox when a player takes an item. public string ClearItemBox() { string item = state.ItemForGrab; BoltConsole.Write("Item is Picked up : " + item); state.ItemForGrab = ""; BoltConsole.Write("Item is now cleared : " + state.ItemForGrab); return(item); }
public int startNewTurn() { turn_i++; //If everyone moved this turn, then a year/round has passed. if (turn_i >= turnOrder.Count) { if (state.YearsUntilNextEvent <= 1 && !GlobalEventHappened && !savedByHero) { BoltConsole.Write("Global EVENT happening!!"); GlobalEventHappened = true; globalEvents.executeGlobalEvent(); //needToNotifyPlayersNewEvent = true; } else if (state.YearsUntilNextEvent <= 1 && !GlobalEventHappened && savedByHero) { NetworkManager.s_Singleton.ResolveCrisis(currentCrisis, hero); GlobalEventHappened = true; } BoltConsole.Write("NEW ROUND!!!!!"); turn_i = 0; if (!globalEvents.AllCrisisHappened()) { yearsUntilNextEvent--; state.YearsUntilNextEvent--; } else { //Temporary hack. yearsUntilNextEvent = 100; state.YearsUntilNextEvent = 100; } if (PeacefulYear) { BoltConsole.Write("Peaceful year ended"); PeacefulYear = false; GlobalEventHappened = false; bool crisisPrepared = globalEvents.PrepareNextEvent(); if (crisisPrepared) { ResetSavedByHero(); DisplayNextEvent(); } } if (GlobalEventHappened) //|| savedByHero { PeacefulYear = true; //After the global event happends let players play a round with no crisis to prep for. //needToNotifyPlayersNewEvent = false; BoltConsole.Write("Starting Peaceful year"); } } state.CurrentSpellcasterTurn = turnOrder[turn_i]; return(turnOrder[turn_i]); }
public override void ConnectRequest(UdpEndPoint endpoint, IProtocolToken token) { //base.ConnectRequest(endpoint, token); BoltConsole.Write("Connect request"); ServerAcceptToken tok = new ServerAcceptToken(); tok.playerIndex = BoltPhysicsCallbacks.numPlayers; BoltPhysicsCallbacks.numPlayers++; BoltNetwork.Accept(endpoint, tok); }
private void PlayerConnected(BoltConnection connection) { BoltConsole.Write("PlayerConnected", Color.yellow); PlayerContainer PC = new PlayerContainer(Random.Range(1000000, 9999999).ToString(), connection); players.Add(PC); RebuildRosterList(); }
public override void Connected(BoltConnection c) { BoltConsole.Write("Connected", Color.red); c.UserData = new Player(); c.GetPlayer().connection = c; c.GetPlayer().name = "CLIENT:" + c.RemoteEndPoint.Port; c.SetStreamBandwidth(1024 * 1024); }
private void Setup(string playerName, Color playerColor) { BoltConsole.Write("Setup BomberPlayer"); if (entity.IsOwner) { state.Color = playerColor; state.Name = playerName; } }
public override void ConnectRequest(UdpKit.UdpEndPoint endpoint, Bolt.IProtocolToken token) { BoltConsole.Write("ConnectRequest", Color.red); if (token != null) { BoltConsole.Write("Token Received", Color.red); } BoltNetwork.Accept(endpoint); }
public override void ControlGained() { BoltConsole.Write("ControlGained", Color.blue); try { SetupCharacterSelectionUI(); } catch { //loading previous game. } }
public override void SceneLoadRemoteDone(BoltConnection connection) { BoltConsole.Write("SceneLoadRemoteDone"); base.SceneLoadRemoteDone(connection); //scene is loaded on the client, send him an event to create a test player with a specific onlineIndex if (BoltNetwork.isServer) { CreatePlayerEvent e = CreatePlayerEvent.Create(connection); e.onlineIndex = totalPlayers; totalPlayers++; e.Send(); } }