Exemplo n.º 1
0
    public void OnButtonPressed()
    {
        Static_Var.Money += 150;
        string level = "Level" + Static_Var.currentLevel.ToString();

        FFMessage <TriggerFade> .SendToLocal(new TriggerFade(level));
    }
Exemplo n.º 2
0
    private void OnTriggerExit(Collider other)
    {
        LeaveArea la;

        la.area = transform;
        FFMessage <LeaveArea> .SendToLocal(la);
    }
Exemplo n.º 3
0
    private void OnClickStartNewServer()
    {
        if (_playerName != null && _playerName.Length > 0)
        {
            StartNewServerEvent SNSE;
            string ipAddress = FFClient.GetLocalIP().ToString();
            SNSE.serverIpAddress = System.Net.IPAddress.Parse(ipAddress);
            SNSE.serverName      = _playerName;
            FFMessage <StartNewServerEvent> .SendToLocal(SNSE);

#if UNITY_WEBPLAYER
            // Start + Connect to local Server
            FFServer.StartServer(80, _playerName + "'s Server", true);
            FFClient.StartClient(ipAddress, 80, _playerName);
#endif

#if UNITY_STANDALONE
            // Start + Connect to local Server
            FFServer.StartServer(6532, _playerName + "'s Server", true);
            FFClient.StartClient(ipAddress, 6532, _playerName);
#endif
            ChangeLevelStateEvent CLSE;
            CLSE.newState = LevelState.In_Game;
            FFMessage <ChangeLevelStateEvent> .SendToLocal(CLSE);
        }
        else
        {
            NoticeAddPlayerName();
        }
        Debug.Log("Clicked StartNewServer"); // debug
    }
Exemplo n.º 4
0
    // Update is called once per frame
    void FixedUpdate()
    {
        distance += Time.fixedDeltaTime * speed;

        var path = PathToFollow.GetComponent <FFPath>();

        if (path)
        {
            var PrevPos    = path.PointAlongPath(distance - 0.01f);
            var position   = path.PointAlongPath(distance);
            var vecForward = Vector3.Normalize(position - PrevPos);

            transform.position = position;
            transform.up       = vecForward;

            if ((int)(distance / path.PathLength) > loopCounter)
            {
                loopCounter = (int)(distance / path.PathLength);
                PathFollowerCompletedLoopEvent e;
                e.distTraveled = path.PathLength;
                e.obj          = gameObject;
                FFMessage <PathFollowerCompletedLoopEvent> .SendToLocal(e);
            }
        }
    }
Exemplo n.º 5
0
    private void OnClickJoinServer()
    {
        if (_serverIPAddress != null && _playerName != null && _playerName.Length > 0)
        {
            JoinServerEvent e;
            e.serverIpAddress = _serverIPAddress;
            e.playerName      = _playerName;
            FFMessage <JoinServerEvent> .SendToLocal(e);

            FFClient.StartClient(_serverIPAddress.ToString(), 6532, _playerName);

            ChangeLevelStateEvent CLSE;
            CLSE.newState = LevelState.In_Game;
            FFMessage <ChangeLevelStateEvent> .SendToLocal(CLSE);
        }
        else
        {
            if (_serverIPAddress == null)
            {
                NoticeValidIPAddress();
            }
            if (_playerName == null)
            {
                NoticeAddPlayerName();
            }
        }

        Debug.Log("Clicked JoinServer"); // debug
    }
Exemplo n.º 6
0
    private static void OnClientConnected(ClientConnectedEvent e)
    {
        if (e.clientGuid == singleton._clientData.clientGuid)
        {
            double localwatchtime = FFSystem.clientWatchTime;
            FFSystem.ResetClientWatch();

            // Set ping ( 0 < ping < 1.0 )
            double calculatedPingTime = Math.Min(Math.Max((localwatchtime - e.clientSendTime) / 2.0, 0.0), 1.0);
            singleton._serverPingTime = (calculatedPingTime + singleton._serverPingTime * 4.0) / 5.0;

            singleton._clientId            = e.clientId;
            singleton._serverLifeTime      = e.serverTime + singleton._serverPingTime;
            singleton._serverStartDateTime = e.serverStartTime;
            singleton._serverName          = e.serverName;

            Debug.Log("Retrieved id: " + singleton._clientId
                      + " from Server with start time of: " + e.serverStartTime
                      + ", and a server life time of: " + e.serverTime);

            singleton._ready = true;
            ClientConnectionReadyEvent CCRE;
            CCRE.clientId   = singleton._clientId;
            CCRE.clientTime = clientTime;
            FFMessage <ClientConnectionReadyEvent> .SendToLocal(CCRE);

            FFLocalEvents.TimeChangeEvent TCE;
            TCE.newCurrentTime = FFSystem.time;
            FFMessage <FFLocalEvents.TimeChangeEvent> .SendToLocal(TCE);
        }
    }
Exemplo n.º 7
0
    float QueryLight()
    {
        QueryLight lightVal = new QueryLight(transform.position);

        FFMessage <QueryLight> .SendToLocal(lightVal);

        return(lightVal.out_intensity);
    }
Exemplo n.º 8
0
    void SetCursor(Sprite sprite, Color color)
    {
        ChangePlayerCursorEvent cpce;

        cpce.color  = color;
        cpce.sprite = sprite;
        FFMessage <ChangePlayerCursorEvent> .SendToLocal(cpce);
    }
Exemplo n.º 9
0
    void FixedUpdate()
    {
        Ser_FixedUpdateEvent e;

        e.deltaTime  = Time.deltaTime;
        e.serverTime = serverTime;
        FFMessage <Ser_FixedUpdateEvent> .SendToLocal(e);
    }
Exemplo n.º 10
0
    // Used to unpack messages from the net
    public override bool SendToLocal(FFBasePacket package)
    {
        FFPacket <EventType> sentPackage = (FFPacket <EventType>)package;

        FFPacket <EventType> .Decrypt(ref sentPackage.message);

        return(FFMessage <EventType> .SendToLocal(sentPackage.message));
    }
Exemplo n.º 11
0
    private void OnTriggerEnter(Collider other)
    {
        Debug.Log("Enter Area");
        EnterArea ea;

        ea.area = transform;
        FFMessage <EnterArea> .SendToLocal(ea);
    }
Exemplo n.º 12
0
    public static void RefreshUI()
    {
        MoneyStruct msg;

        msg.updatedString = money.ToString();
        msg.color         = Color.black;
        FFMessage <MoneyStruct> .SendToLocal(msg);
    }
Exemplo n.º 13
0
    IEnumerator endLevel()
    {
        yield return(null);

        string level = "Level" + Static_Var.currentLevel.ToString();

        FFMessage <TriggerFade> .SendToLocal(new TriggerFade(level));
    }
Exemplo n.º 14
0
 int DoThing(PathFollowerCompletedLoopEvent p)
 {
     if (p.obj.name.Contains("Player"))
     {
         string level = "Office";
         FFMessage <TriggerFade> .SendToLocal(new TriggerFade(level));
     }
     return(0);
 }
Exemplo n.º 15
0
    void LateUpdate()
    {
        ExecuteMessages();

        FFLocalEvents.LateUpdateEvent e;
        e.dt   = Time.deltaTime;
        e.time = FFSystem.time;
        FFMessage <FFLocalEvents.LateUpdateEvent> .SendToLocal(e);
    }
Exemplo n.º 16
0
    void UpdatePlayerMessage(PlayerMessage pm, float progress = -1.0f)
    {
        UI_Text ut;

        ut.font     = pm.font;
        ut.text     = pm.message;
        ut.progress = progress;

        FFMessage <UI_Text> .SendToLocal(ut);
    }
Exemplo n.º 17
0
    IEnumerator waitAndExit()
    {
        yield return(new WaitForSeconds(5f));

        string level = "Level" + Static_Var.currentLevel.ToString();

        FFMessage <TriggerFade> .SendToLocal(new TriggerFade(level));

        PlayerPrefs.SetInt("IsLate", 0);
    }
Exemplo n.º 18
0
    void FixedUpdate()
    {
        ExecuteMessages();

        FFLocalEvents.FixedUpdateEvent e;
        e.dt      = Time.fixedDeltaTime;
        e.time    = FFSystem.time;
        e.fixedDt = Time.fixedDeltaTime;
        FFMessage <FFLocalEvents.FixedUpdateEvent> .SendToLocal(e);
    }
Exemplo n.º 19
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyUp(KeyCode.K))  // Activator Triggered
     {
         PlayerDiedEvent e = new PlayerDiedEvent();
         e.Killer         = gameObject;
         e.timeOfDeath    = Time.realtimeSinceStartup;
         e.overkillDamage = 9001.0f;
         FFMessage <PlayerDiedEvent> .SendToLocal(e);
     }
 }
Exemplo n.º 20
0
    private void OnClickLeaveServer()
    {
        ChangeLevelStateEvent CLSE;

        CLSE.newState = LevelState.In_Menu;
        FFMessage <ChangeLevelStateEvent> .SendToLocal(CLSE);

        // 1.0 seconds to make sure everything is finished in the ChangelevelState event
        // before we close down networking
        DisconnectSequence.Delay(0.5);
        DisconnectSequence.Sync();
        DisconnectSequence.Call(DestroyClientAndServer);
    }
    IEnumerator minusMoney()
    {
        yield return(new WaitForEndOfFrame());

        Static_Var.RefreshUI();
        yield return(new WaitForSeconds(3f));

        Static_Var.Money -= Daily_Income;
        UI_Text tx = new UI_Text {
            text = "-100 FROM INCOME", font = font, progress = 0f
        };

        FFMessage <UI_Text> .SendToLocal(tx);
    }
Exemplo n.º 22
0
    void UpdateMovement(float dt)
    {
        var movementVec = Vector3.zero;

        if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
        {
            movementVec += Vector3.up;
        }
        if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
        {
            movementVec -= Vector3.up;
        }
        if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
        {
            movementVec += Vector3.right;
        }
        if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
        {
            movementVec -= Vector3.right;
        }

        // normalize movement
        if (movementVec != Vector3.zero)
        {
            movementVec = movementVec.normalized;
            lookDir     = movementVec;
        }


        if (movementVec == Vector3.zero)
        {
            rigid.velocity = Vector2.Lerp(rigid.velocity, Vector2.zero, slowCoeficient * dt);
        }
        else // want to move
        {
            rigid.velocity += new Vector2(movementVec.x, movementVec.y) * acceleration * dt;
        }

        // limit speed
        if (rigid.velocity.magnitude > maxSpeed)
        {
            rigid.velocity = rigid.velocity.normalized * maxSpeed;
        }

        if (Input.GetKey(KeyCode.P))
        {
            FFMessage <TriggerFade> .SendToLocal(new TriggerFade("EndScene"));
        }
    }
Exemplo n.º 23
0
    public static void StartServer(int portNumber, string serverName, bool serverIsClient)
    {
        FFServer.GetReady();
        if (singleton._TCPSocket != null ||
            singleton._UDPClient != null)
        {
            Debug.LogError("ERROR, Tried to make a second server with an existing one, Delete the old one first");
            return;
        }

        AddMessageInterceptors();

        if (serverIsClient)
        {
            singleton._sendToLocal = false;
        }

        singleton._serverName = serverName;
        singleton._portNumber = portNumber;


        #region SocketStart
        try
        {
            // Setup TCP
            singleton._TCPSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            singleton._TCPSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            singleton._TCPSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ExclusiveAddressUse, false);
            singleton._TCPSocket.Bind(new IPEndPoint(IPAddress.Any, portNumber)); // TODO change to loopback?
            singleton._TCPSocket.Listen(250);
            singleton._TCPSocket.BeginAccept(new AsyncCallback(AcceptCallback), singleton._TCPSocket);

            singleton._serverStartTime = DateTime.Now.ToUniversalTime();
            singleton._serverWatch.Reset();
            singleton._serverWatch.Start();

            Debug.Log("Server Started..." +
                      "\nportNumber:" + portNumber + " serverName:" + serverName);
        }
        catch (Exception exp)
        {
            Debug.Log(exp.Message);
        }
        #endregion

        Ser_StartupEvent e;
        FFMessage <Ser_StartupEvent> .SendToLocal(e);
    }
Exemplo n.º 24
0
    void Awake()
    {
        if (this == singleton)
        {
            _clientWatch.Start();
            //FFMessage<NetObjectCreatedEvent>.Connect(OnNetObjectCreatedEvent);
            //FFMessage<NetObjectDestroyedEvent>.Connect(OnNetObjectDestroyedEvent);
            //FFMessage<ClientConnectionReadyEvent>.Connect(OnClientConnectionReady);
            //FFMessage<GameObjectNetIdRecievedEvent>.Connect(OnGameObjectNetIdRecieved);
            Debug.Log("FFSystem is awake!");

            FFLocalEvents.TimeChangeEvent TCE;
            TCE.newCurrentTime = FFSystem.time;
            FFMessage <FFLocalEvents.TimeChangeEvent> .SendToLocal(TCE);
        }
    }
    // Use this for initialization
    void Start()
    {
        Static_Var.currentLevel = ((Static_Var.currentLevel + 1) % 3) + 1;

        StartCoroutine(minusMoney());

        FogMsg fog;

        fog.FogDensity = Static_Var.FogValue;
        Debug.Log("Fog Value " + Static_Var.FogValue);
        FFMessage <FogMsg> .SendToLocal(fog);

        if (Static_Var.FogValue >= 1.9)
        {
            Debug.Log("Transition to end scene");
        }
    }
Exemplo n.º 26
0
    // Wait For Input State
    void WaitForInput()
    {
        var goForard =
            Input.GetButtonUp("A" + 0) ||
            Input.GetButtonUp("A" + 1) ||
            Input.GetButtonUp("A" + 2) ||
            Input.GetKeyDown(KeyCode.RightArrow);

        if (goForard)  // go forwards
        {
            if (currentPointNumber < PathToFollow.points.Length)
            {
                ++currentPointNumber;
                movementSeq.Call(MoveForward);
                PlayAudio();
                return;
            }
            else // finished Path, Goto Next level
            {
                TriggerFade tf;
                FFMessage <TriggerFade> .SendToLocal(tf);
            }
        }


        var gobackward =
            //Input.GetButtonUp("B" + 0) ||
            //Input.GetButtonUp("B" + 1) ||
            //Input.GetButtonUp("B" + 2) ||
            Input.GetKeyDown(KeyCode.LeftArrow);

        if (gobackward)  // go backwards
        {
            if (currentPointNumber > 0)
            {
                --currentPointNumber;
                movementSeq.Call(MoveBackward);
                PlayAudio();
                return;
            }
        }

        movementSeq.Sync();
        movementSeq.Call(WaitForInput);
    }
Exemplo n.º 27
0
    void OnDestroy()
    {
        _clientWatch.Reset();

        // Notify any FFAction of the time shift
        FFLocalEvents.TimeChangeEvent TCE;
        TCE.newCurrentTime = FFSystem.time;
        FFMessage <FFLocalEvents.TimeChangeEvent> .SendToLocal(TCE);


        singleton.recievedMessages.Clear();
        singleton = null;
        //FFMessage<ClientConnectionReadyEvent>.Disconnect(OnClientConnectionReady);
        //FFMessage<GameObjectNetIdRecievedEvent>.Disconnect(OnGameObjectNetIdRecieved);
        //FFMessage<NetObjectCreatedEvent>.Disconnect(OnNetObjectCreatedEvent);
        //FFMessage<NetObjectDestroyedEvent>.Disconnect(OnNetObjectDestroyedEvent);
        Debug.Log("On Destroy of FFSystem, recieved Messages erased: " + recievedMessages.Count);
    }
    private void Timer_behavior_OnTimerEnd(string timerName)
    {
        if (timerName.Contains("Office Time"))
        {
            PlayerPrefs.SetInt("IsLate", 1);
        }
        else if (timerName.Contains("World Time"))
        {
            Static_Var.FogValue = Static_Var.FogValue + 0.3f;
            UI_Text tx = new UI_Text {
                text = "SLEEP TIME...", font = font, progress = 0f
            };
            FFMessage <UI_Text> .SendToLocal(tx);

            string level = "Level" + Static_Var.currentLevel.ToString();
            FFMessage <TriggerFade> .SendToLocal(new TriggerFade(level));
        }
    }
Exemplo n.º 29
0
    // Update is called once per frame
    void Update()
    {
        distance += Time.deltaTime * speed;

        var path = PathToFollow.GetComponent <FFPath>();

        if (path)
        {
            var position = path.PointAlongPath(distance);
            transform.position = position;
            if ((int)(distance % path.PathLength) > loopCounter)
            {
                loopCounter = (int)(distance % path.PathLength);
                PathFollowerCompletedLoopEvent e;
                e.distTraveled = path.PathLength;
                FFMessage <PathFollowerCompletedLoopEvent> .SendToLocal(e);
            }
        }
    }
Exemplo n.º 30
0
    public void OnValueChange(string value)
    {
        if (inputText)
        {
            inputText = false;
            return;
        }

        inputText = true;

        //Display the string.
        stringTracker++;
        string display = workString.Substring(0, Mathf.Min(stringTracker * 4, workString.Length - 1));

        inputTextField.text          = display;
        inputTextField.caretPosition = stringTracker * 4;

        //Handle player sound
        if (enumerator != null)
        {
            StopAllCoroutines();
        }
        StartCoroutine(PlayerKeyDown());

        //update progress bar
        UI_Text tx = new UI_Text {
            text = "WORK HARDER", font = office_Font, progress = (stringTracker / 50f)
        };

        FFMessage <UI_Text> .SendToLocal(tx);

        //Check for button interactable condition
        if (stringTracker > game_end_string_length)
        {
            end_game_button.interactable = true;
        }
        else
        {
            end_game_button.interactable = false;
        }
    }