public override void ServerSyncFixedUpdate()
    {
        base.ServerSyncFixedUpdate();

        // It seems like "OperationAddSyncState" shouldn't be done in InitStart..
        if (!firstUpdateDone)
        {
            firstUpdateDone = true;
            if (GameManager.GetPlayer(playerOwner).playerObject != null)
            {
                // trip wire won't go up or down, it'll stay straight:
                Vector3 pos = GameManager.GetPlayer(playerOwner).playerObject.transform.position;
                //pos.y = transform.position.y - 1.1f;

                RaycastHit hit;
                if (Physics.Raycast(transform.position + Vector3.down * 1.5f, Vector3.Normalize(pos - (transform.position + Vector3.down * 1.5f)), out hit, 12f, LayerLogic.WorldColliders()))
                {
                    // hmm..
                }

                GameObject obj = (GameObject)Instantiate(arrowTrigger, pos + Vector3.down, Quaternion.identity);
                obj.GetComponent <PlayerMade> ().playerOwner = playerOwner;
                OperationNetwork.OperationAddSyncState(obj);
            }
        }

        GeneralUpdate();
    }
    public override void UpdateServerAndInterp(bool building, bool dieing, float lifeTime)
    {
        // Reveals the trap over the initial time:
        if (lifeTime < getBuildTime())
        {
            // Build handles this
        }
        else
        {
            if (OperationNetwork.isServer)
            {
                ticksSinceLaunch++;
                if (ticksSinceLaunch % 100 == 0)                  // 50 ticks is 1 second
                {
                    float maxMissAngle = 14f;                     // Was 12f
                    // Launch arrow:
                    Vector2 randInUnitCircle = UnityEngine.Random.insideUnitCircle;
                    Vector3 direction        = randInUnitCircle * maxMissAngle * Mathf.PI / 180.0f;              // This is here because the accuracy, is on average less when using a cone to do inaccuracy. This increases the amount of shots that are more accurate. In the future it could just use tan, or maybe tan with this.
                    direction.z = 1.0f;
                    //direction = transform.TransformDirection(direction.normalized);
                    Quaternion fireRot = Quaternion.LookRotation(transform.forward) * Quaternion.LookRotation(direction.normalized);
                    Vector3    fireDir = fireRot * Vector3.forward;

                    GameObject arrowObj = (GameObject)Instantiate(bullet, transform.position + transform.forward * 0.3f, fireRot);
                    arrowObj.GetComponent <SyncGameState> ().playerOwner = playerOwner;
                    arrowObj.GetComponent <Projectile>().SetInitialVelocity(fireDir * Random.Range(5, 8));
                    OperationNetwork.OperationAddSyncState(arrowObj);
                }
            }
        }
    }
Example #3
0
    // Server side:
    void SpawnPlayer()
    {
        // Picks a spawn point here:
        GameObject sP = LevelLogic.getSpawnPoint(team);
        // Picks a spawn point here:
        GameObject playerObject = (GameObject)MonoBehaviour.Instantiate(playerObjects[team * (playerObjects.Length / 2) + classNum], sP.transform.position, sP.transform.rotation);

        playerObject.GetComponent <SyncGameState> ().playerOwner = playerOwner;
        OperationNetwork.OperationAddSyncState(playerObject);
    }
 // Throwable does NOT blow up! It creates a death sphere!
 public override void OnDeath()
 {
     if (deathExplosionPrefab != null && OperationNetwork.isServer)
     {
         GameObject deathExplosion = (GameObject)Instantiate(deathExplosionPrefab, transform.position, transform.rotation);
         deathExplosion.GetComponent <SphereDamage> ().playerOwner = playerOwner;
         deathExplosion.GetComponent <SphereDamage> ().team        = team;
         OperationNetwork.OperationAddSyncState(deathExplosion);
     }
 }
    public void FireBullet(Vector3 cameraForward)
    {
        GameObject bullet = (GameObject)MonoBehaviour.Instantiate(
            bulletPrefab, parentPlayerMove.transform.position + parentPlayerMove.GetMainCameraLocalPos() * parentPlayerMove.transform.localScale.x +
            cameraForward * 0.12f + Quaternion.LookRotation(cameraForward) * Vector3.up * -0.1f + Quaternion.LookRotation(cameraForward) * Vector3.right * 0.11f,
            Quaternion.LookRotation(cameraForward));

        bullet.GetComponent <SyncGameState> ().playerOwner = parentPlayerMove.plyr;
        bullet.GetComponent <Projectile>().SetInitialVelocity(cameraForward * GetSpeed());
        OperationNetwork.OperationAddSyncState(bullet);
    }
Example #6
0
    // Server
    public void Launch()
    {
        if (!launched)
        {
            launched = true;

            icicle = (GameObject)Instantiate(icicle, transform.position, transform.rotation);
            icicle.GetComponent <Rigidbody> ().velocity        = transform.forward * 15f;
            icicle.GetComponent <SyncGameState> ().playerOwner = playerOwner;
            OperationNetwork.OperationAddSyncState(icicle);

            // Destroy this: (No need to do alive set)
            exists = false;
        }
    }
    // InitialConnect is key.
    public static void InitialConnect()
    {
        if (OperationNetwork.isServer)
        {
            GameObject lSync = Instantiate(levelSync);
            OperationNetwork.OperationAddSyncState(lSync);

            OperationNetwork.connected = true;             // Server connection works like this.
            PlayerConnect(PlayerInformation.steamName, OperationNetwork.FromServerClient);
        }
        else
        {
            // Sends out request for "Connect" (with name). ID is sent to the player.
            OperationView.RPC(null, "PlayerConnect", OperationNetwork.ToServer, PlayerInformation.steamName);
        }
    }
Example #8
0
    // This could be done in the same way bullets are done..

    // Server only:
    public void FireTakeHealth(Vector3 cameraForward)
    {
        // This comes from the gun, oddly enough:
        GameObject hB = (GameObject)MonoBehaviour.Instantiate(healingBlast, parentPlayerMove.mainCamera.transform.position + cameraForward * 2.8f, Quaternion.LookRotation(cameraForward)); // It gets made at the tip of the gun.

        hB.GetComponent <SyncGameState> ().playerOwner = parentPlayerMove.plyr;                                                                                                             // Redudant.. not used..

        OperationNetwork.OperationAddSyncState(hB);                                                                                                                                         // hB doesn't have any syncing properties beside position / rotation. (TODO implement)

        // Server also calculates the collision right here:

        // Note that HEALING #s are hard coded within BlowUp!
        ExplodeDetection.BlowUp(parentPlayerMove.mainCamera.transform.position + parentPlayerMove.mainCamera.transform.forward * 2.6f,          // Note how it heals in a different location!
                                parentPlayerMove.mainCamera.transform.position, 20f, 2.2f, 1f, 0.5f, parentPlayerMove.gameObject,
                                parentPlayerMove.GetComponent <Combat> ().team, ref healthTaken, parentPlayerMove.plyr);
    }
    // Server only. This is called manually by the server.
    // OperationRPC
    public static void PlayerConnect(string name, short who)     // Information that should be sent to new players: team, kills, deaths
    {
        if (who != OperationNetwork.FromServerClient)
        {
            OperationNetwork.getClient(who).connected = true;              // This is so no data is sent before the following data:

            OperationNetwork.sendDataToSpecificClient(BitConverter.GetBytes(who), who);
        }

        GameObject pSObject = MonoBehaviour.Instantiate(playerSync);

        // Set ID, name, etc. (todo)
        pSObject.GetComponent <Player> ().playerOwner = who;
        pSObject.GetComponent <Player> ().playerName  = name;
        pSObject.GetComponent <Player> ().team        = 0; // Default (Could be based on an "autobalance" system.
        pSObject.GetComponent <Player> ().classNum    = 0; // Default (Could be random)
        OperationNetwork.OperationAddSyncState(pSObject);
    }
Example #10
0
    // Note that placeType is only used for its type currently. It does not use PlacePlayerMade placePlayerMades byte dictionary because it does not need to.
    public static void AddObject(PlayerMove parentPlayerMove, Vector3 pos, Quaternion rot, byte placeType, byte team, short playerOwner)
    {
        try {
            GameObject obj = (GameObject)MonoBehaviour.Instantiate(placementSphere,
                                                                   parentPlayerMove.transform.TransformPoint(parentPlayerMove.GetComponent <CapsuleCollider> ().center) /* Approximate for now.*/,
                                                                   parentPlayerMove.mainCamera.transform.rotation);

            GameObject cutOut = cutOuts [placeType];

            obj.GetComponent <PlacementSphere>().cutOut      = cutOut;
            obj.GetComponent <PlacementSphere>().team        = team;
            obj.GetComponent <PlacementSphere>().playerOwner = playerOwner;
            obj.GetComponent <PlacementSphere> ().placeType  = placeType;
            obj.GetComponent <PlacementSphere>().toPosition  = pos;           // fromPosition is set by initStart.
            obj.GetComponent <PlacementSphere>().objRotation = rot;

            OperationNetwork.OperationAddSyncState(obj);
        } catch (Exception e) {
            Debug.LogError("Failure in adding trap: " + placeType + ", " + e.Message);
        }
    }
    public override void deathAnimation(float deathTime)
    {
        // Reveals the trap over the initial time:
        if (!playedLaunchSound)
        {
            SoundHandler.soundHandler.PlayVoiceLine((byte)4, (byte)255, transform);
            playedLaunchSound = true;
        }
        if (deathTime < delayTime)
        {
            if (!GetComponent <Renderer> ().enabled)
            {
                GetComponent <Renderer> ().enabled = true;
            }
            SetTransparency((delayTime - deathTime) / delayTime);
        }
        else
        {
            if (OperationNetwork.isServer)
            {
                ticksSinceLaunch++;
                if (ticksSinceLaunch <= 150 && ticksSinceLaunch % 5 == 0)                   // 150 ticks is 3 seconds.
                {
                    float maxMissAngle = 25f;
                    // Launch arrow:
                    Vector2 randInUnitCircle = UnityEngine.Random.insideUnitCircle;
                    Vector3 direction        = randInUnitCircle * maxMissAngle * Mathf.PI / 180.0f;              // This is here because the accuracy, is on average less when using a cone to do inaccuracy. This increases the amount of shots that are more accurate. In the future it could just use tan, or maybe tan with this.
                    direction.z = 1.0f;
                    //direction = transform.TransformDirection(direction.normalized);
                    Quaternion fireRot = Quaternion.LookRotation(transform.forward) * Quaternion.LookRotation(direction.normalized);
                    Vector3    fireDir = fireRot * Vector3.forward;

                    GameObject arrowObj = (GameObject)Instantiate(arrow, transform.position + transform.forward * 0.6f + transform.right * 1f * randInUnitCircle.x + transform.up * 1f * randInUnitCircle.y, fireRot);
                    arrowObj.GetComponent <SyncGameState> ().playerOwner = playerOwner;
                    arrowObj.GetComponent <Projectile>().SetInitialVelocity(fireDir * Random.Range(24, 32));
                    OperationNetwork.OperationAddSyncState(arrowObj);
                }
            }
        }
    }
Example #12
0
    public void ServerPlacementValidCheck()
    {
        bool isPlacementValid = IsPlacementValid();



        if (isPlacementValid)
        {
            GameObject properObj = (GameObject)Instantiate(playerMadeObjects[team], transform.position, transform.rotation);

            properObj.GetComponent <PlayerMade> ().playerOwner = playerOwner;

            OperationNetwork.OperationAddSyncState(properObj);
            Destroy(gameObject);
        }
        else
        {
            // Did not place!! Prediction FAILURE!! RESET COOLDOWN

            // Simple system now. Reset cooldown!!

            if (GameManager.PlayerExists(playerOwner))
            {
                bool found = false;
                if (GameManager.GetPlayer(playerOwner).playerObject != null)
                {
                    foreach (Unlock unlock in GameManager.GetPlayer(playerOwner).playerObject.GetComponent <ClassControl>().getUnlocks())
                    {
                        if (unlock is PlacePlayerMade && !(unlock is PlaceTrap) && ((PlacePlayerMade)unlock).cutOut.GetComponent <CollideCheck>().placeType == placeType)
                        {
                            if (unlock is PlaceIcicle)
                            {
                                ((PlaceIcicle)unlock).AmmoStored = Mathf.Min(((PlaceIcicle)unlock).AmmoStored + 1, PlaceIcicle.maxAmmoStored);
                            }
                            else
                            {
                                Debug.LogError("Resette");
                                ((PlacePlayerMade)unlock).coolDownStartedAt = -1000f;
                            }


                            found = true;
                            break;
                        }
                    }
                }
                // Could be trap:
                if (!found)
                {
                    for (int i = 0; i < GameManager.GetPlayer(playerOwner).trapTypes.Length; i++)
                    {
                        Debug.Log(placeType + ": " + GameManager.GetPlayer(playerOwner).trapTypes [i]);
                        if (GameManager.GetPlayer(playerOwner).trapTypes [i] == placeType)
                        {
                            Debug.Log("Reset");
                            GameManager.GetPlayer(playerOwner).trapCoolDownsStartedAt [i] = GameManager.GetPlayer(playerOwner).resetTrapCoolDownsTo [i];
                        }
                    }
                }
            }



            Destroy(gameObject);
            return;
        }
    }
Example #13
0
 public GameObject facadeObject = null;     // SERVER ONLY
 void SpawnFacade(GameObject facade)
 {
     facadeObject = (GameObject)MonoBehaviour.Instantiate(facade, transform.position, transform.rotation);
     facadeObject.GetComponent <SyncFacade> ().playerOwner = plyr;        // This is only used server side on SyncFacade
     OperationNetwork.OperationAddSyncState(facadeObject);
 }
Example #14
0
    void Update(float timeSinceChargeStarted)
    {
        if (!launched && timeSinceChargeStarted > getAppearTime())
        {
            if (throwable == null)
            {
                appear();
            }

            // Launch
            if (timeSinceChargeStarted > getLaunchTime())
            {
                launched = true;
                if (throwable != null)
                {
                    MonoBehaviour.Destroy(throwable);                     // Hmm.. it'll desync on the player side. (And possibly client side, for that matter)
                    throwable = null;
                    if (OperationNetwork.isServer)
                    {
                        GameObject throwObj = (GameObject)MonoBehaviour.Instantiate(throwablePrefab, rightHand.transform.TransformPoint(-0.35f, 0, 0), rightHand.transform.rotation);


                        // Note how yDir is negative for both:
                        float yDir;
                        if (parentPlayerMove.thisIsMine || OperationNetwork.isServer)
                        {
                            yDir = -parentPlayerMove.mainCamera.transform.eulerAngles.x;
                        }
                        else
                        {
                            yDir = parentPlayerMove.currentPlayerRotUpDown;
                        }

                        yDir = yDir * Mathf.PI / 180.0f;
                        if (yDir > Math.PI)
                        {
                            yDir -= Mathf.PI * 2;
                        }
                        if (yDir < -Math.PI)
                        {
                            yDir += Mathf.PI * 2;
                        }

                        float yDirIncrease = Mathf.PI / 12.0f;

                        Vector3 fireDir;
                        if (yDir > -yDirIncrease)
                        {
                            fireDir = Vector3.RotateTowards(parentPlayerMove.transform.forward, Vector3.up, yDir + yDirIncrease, 1f);
                        }
                        else
                        {
                            fireDir = Vector3.RotateTowards(parentPlayerMove.transform.forward, Vector3.down, -yDir - yDirIncrease, 1f);
                        }

                        Throw(throwObj, fireDir);

                        OperationNetwork.OperationAddSyncState(throwObj);
                        // We could keep the moveDirection / effectDirection of the Z direction, and perhaps the Y direction (if it is > 0)
                    }

                    // Player and Server:
                    if (OperationNetwork.isServer || parentPlayerMove.thisIsMine)
                    {
                        setCoolDown();
                        isEnabled = false;
                        parentPlayerMove.GetComponent <ClassControl> ().defaultSetup(true);                         // This is a method which is only called when runEffects = true
                    }
                }
            }
        }
    }