public void HandleResponse(ISFSObject anObjectIn, GameWorldManager ourGWM)
        {
            string aSettlementName = anObjectIn.GetUtfString("Name");
            int ID = anObjectIn.GetInt("ID");
            float[] location = anObjectIn.GetFloatArray("LocationArray");
            int level = anObjectIn.GetInt("CenterNodeLevel");

            GameObject aSettlement = ourGWM.createObject("Prefabs/Settlements/" + aSettlementName + "/" + level.ToString());
            aSettlement.name = "Settlement_" + aSettlementName + "_" + ID;
            aSettlement.transform.position = new Vector3(location[0], location[1], location[2]);
        }
        public void HandleResponse(ISFSObject anObjectIn, GameWorldManager ourGWM)
        {
            string aResourceName = anObjectIn.GetUtfString("Name");
            int ID = anObjectIn.GetInt("ID");
            float[] location = anObjectIn.GetFloatArray("Location");

            GameObject aResource = ourGWM.createObject("Prefabs/Resources/" + aResourceName);
            aResource.name = "Resource_" + aResourceName + "_" + ID;
            aResource.transform.position = new Vector3(location[0], location[1], location[2]);

            //Add Newly spawned resource to Dictionary
            ourGWM.getResourceDictionary().Add(ID, aResource);
        }
 public void HandleResponse(ISFSObject anObjectIn, GameWorldManager ourGWM)
 {
     string aCharacterName = anObjectIn.GetUtfString("CharacterName");
     if(aCharacterName == ourGWM.getLPC().GetName())
     {
         return;
     }
     else if(ourGWM.getPlayerDictionary().ContainsKey(aCharacterName))
     {
         float[] LocationArray = anObjectIn.GetFloatArray("Location");
         bool IsMoving = anObjectIn.GetBool("IsMoving");
         ourGWM.getPlayerDictionary()[aCharacterName].GetComponent<RemotePlayerController>().SetPlayerMoving(IsMoving);
         ourGWM.getPlayerDictionary()[aCharacterName].transform.position = new Vector3(LocationArray[0], LocationArray[1], LocationArray[2]);
     }
 }
        public void HandleResponse(ISFSObject anObjectIn, GameWorldManager ourGWM)
        {
            string aNPCName = anObjectIn.GetUtfString("Name");
            int ID = anObjectIn.GetInt("ID");
            float[] location = anObjectIn.GetFloatArray("Location");

            GameObject aNPC = ourGWM.createObject("Prefabs/NPC/" + aNPCName);
            aNPC.name = "NPC_" + aNPCName + "_" + ID;
            aNPC.AddComponent<RemotePlayerController>();
            aNPC.transform.position = new Vector3(location[0], location[1], location[2]);
            aNPC.GetComponentInChildren<TextMesh>().text = aNPCName;

            //Add Newly spawned player to Dictionary
            ourGWM.getNPCDictionary().Add(ID, aNPC);
        }
        public void HandleResponse(ISFSObject anObjectIn, GameWorldManager ourGWM)
        {
            Debug.Log("Server spawning player.");
            float[] locationArray = anObjectIn.GetFloatArray("Location");
            float aRotation = anObjectIn.GetFloat("Rotation");
            string aCharacterName = anObjectIn.GetUtfString("CharacterName");

            if(anObjectIn.GetBool("IsLocal"))
            {
                GameObject aLocalPlayer = ourGWM.createObject("Prefabs/Player/PlayerBasic");
                aLocalPlayer.transform.position = new Vector3(locationArray[0], locationArray[1], locationArray[2]);
                aLocalPlayer.transform.rotation = Quaternion.identity;

                // Since this is the local player, lets add a controller and fix the camera
                aLocalPlayer.AddComponent<LocalPlayerController>();
                aLocalPlayer.AddComponent<InputController>();
                ourGWM.setLPC(aLocalPlayer.GetComponent<LocalPlayerController>());
                ourGWM.getLPC().SetName(aCharacterName);
                aLocalPlayer.GetComponentInChildren<TextMesh>().text = aCharacterName;

                GameObject cameraAttach = new GameObject();
                cameraAttach.transform.parent = aLocalPlayer.transform;
                cameraAttach.transform.localPosition = new Vector3(1f, 2.5f, 1.0f);
                cameraAttach.name = "Camera Target";
                Camera.main.transform.parent = cameraAttach.transform;
                Camera.main.GetComponent<CameraController>().setTarget(cameraAttach);
                Camera.main.GetComponent<CameraController>().setCursorVisible(false);
            }
            else if(!anObjectIn.GetBool("IsLocal"))
            {
                GameObject aRemotePlayer = ourGWM.createObject("Prefabs/Player/PlayerBasic");

                aRemotePlayer.name = "GameCharacter_" + aCharacterName;
                aRemotePlayer.AddComponent<RemotePlayerController>();
                aRemotePlayer.transform.position = new Vector3(locationArray[0], locationArray[1], locationArray[2]);
                aRemotePlayer.GetComponent<RemotePlayerController>().SetRotation(aRotation);
                aRemotePlayer.GetComponentInChildren<TextMesh>().text = aCharacterName;

                //Add Newly spawned player to Dictionary
                ourGWM.getPlayerDictionary().Add(aCharacterName, aRemotePlayer);
            }
        }
Example #6
0
    private void recieveExplosionForce(ISFSObject msg)
    {
        var force = msg.GetFloat("force");
        var pos = msg.GetFloatArray("pos");
        var team = msg.GetUtfString("team");
        targetPosition = new Vector3(pos[0], Y_PLANE, pos[1]);

        GameObject newExplosion = Instantiate(ExplosionPF, targetPosition, Quaternion.identity) as GameObject;

        if (team == "blue")
        {
            newExplosion.GetComponent<ParticleSystem>().startColor = new Color(0.0f, 0.5f, 1.0f, 1.0f);
        }
        else
        {
            newExplosion.GetComponent<ParticleSystem>().startColor = Color.red;
        }

        Vector3 lightPosition = targetPosition;
        lightPosition.y += 10.0f;

        GameObject explosionLight = Instantiate(ExplosionLightPF, lightPosition, Quaternion.identity) as GameObject;

        if (team == "blue")
        {
            explosionLight.GetComponent<Light>().color = Color.blue;
        }
        else
        {
            explosionLight.GetComponent<Light>().color = Color.red;
        }

        float totalTime = 2.0f * force/160.0f;

        Destroy(newExplosion, totalTime);

        totalTime = totalTime/5.0f;

        Destroy(explosionLight, totalTime);

        GameObject[] blocksArray = GameObject.FindGameObjectsWithTag("Block");
        foreach (GameObject block in blocksArray)
        {
            if (block.GetComponent<BoxCollider>().bounds.Contains(targetPosition))
            {
                var extents = block.GetComponent<BoxCollider>().bounds.extents;
                if(targetPosition.x > block.transform.position.x)
                    targetPosition += new Vector3(extents.x, 0, 0);
                else
                    targetPosition -= new Vector3(extents.x, 0, 0);

                if(targetPosition.z > block.transform.position.z)
                    targetPosition += new Vector3(0, 0, extents.z);
                else
                    targetPosition -= new Vector3(0, 0, extents.z);
            }

            block.GetComponent<Rigidbody>().AddExplosionForce(force, targetPosition, 25.0f, 0.0f, ForceMode.Impulse);
        }
    }
 internal static Vector2 deserializeVec2(ISFSObject props, string key)
 {
     float[] floatArray = props.GetFloatArray(key);
     return(new Vector2(floatArray[0], floatArray[1]));
 }