void Start () 
	{
		left = Screen.width / 9;
		top = Screen.height / 9;
		width = 400f;
		height = 400f;
		asl = GameObject.Find("ASL").GetComponent<ASL>();
		anotherPlayer = GameObject.Find("AnotherPlayer").GetComponent<AnotherPlayer>();
		child = GameObject.Find("Child").GetComponent<Child>();
	}
Esempio n. 2
0
 void Start()
 {
     left          = Screen.width / 9;
     top           = Screen.height / 9;
     width         = 400f;
     height        = 400f;
     asl           = GameObject.Find("ASL").GetComponent <ASL>();
     anotherPlayer = GameObject.Find("AnotherPlayer").GetComponent <AnotherPlayer>();
     child         = GameObject.Find("Child").GetComponent <Child>();
 }
Esempio n. 3
0
    IEnumerator server_function()
    {
        while (true)
        {
            Server.Send("31");
            yield return(new WaitForSeconds(0.5f));

            Server.Send("32");
            yield return(new WaitForSeconds(0.5f));

            Server.Send("33");
            yield return(new WaitForSeconds(0.5f));

            //	Server.Send ("23");
            try{
                if (State.PosX != -1 && State.PosZ != -1 && State.mainPlayerStatus == false)
                {
                    PlayerGameObject       = (GameObject)Instantiate(Player, new Vector3(State.PosX, 1.5f, State.PosZ), Player.transform.rotation);
                    PlayerGameObject.name  = State.PlayerName;
                    State.PlayerGameObject = PlayerGameObject;
                    State.mainPlayerStatus = true;
                    GameObject joyG = (GameObject)Instantiate(joy, joy.transform.position, joy.transform.rotation);
                    State.joy = joyG;
                }
                if (State.mainPlayerStatus == true)
                {
                    Server.Send("41" + State.PosX + "," + State.PosZ);
                }

                foreach (string HouseIDKey in State.HouseList.Keys)
                {
                    if (State.HouseID.ContainsKey(HouseIDKey))
                    {
                        if (!State.HouseStatus[HouseIDKey])
                        {
                            BuildNow = (Rigidbody)Instantiate(build[State.HouseKind[HouseIDKey]], new Vector3(State.HousePositionX[HouseIDKey], 0, State.HousePositionZ[HouseIDKey]), build[State.HouseKind[HouseIDKey]].transform.rotation);
                            build thisBuild = BuildNow.gameObject.GetComponent <build>();
                            State.HouseGameObject.Add(HouseIDKey, BuildNow.gameObject);
                            thisBuild.HouseID         = State.HouseID[HouseIDKey];
                            thisBuild.PlayerID        = State.HousePlayerID[HouseIDKey];
                            thisBuild.gameObject.name = State.HouseID[HouseIDKey];
                            thisBuild.kind            = State.HouseKind[HouseIDKey];
                            thisBuild.HouseLevel      = State.HouseLevel[HouseIDKey];
                            thisBuild.HP     = State.HouseHP[HouseIDKey];
                            thisBuild.MaxHP  = State.HouseMaxHP[HouseIDKey];
                            thisBuild.status = State.HouseStatusNow[HouseIDKey];

                            if (State.HousePlayerID [HouseIDKey] != State.PlayerName)
                            {
                                BuildNow.gameObject.tag = "Enemy";
                            }

                            if (State.HouseKind[HouseIDKey] == 0)
                            {
                                Destroy(BuildNow.gameObject.transform.FindChild("HomePlane").gameObject);
                                BuildNow.gameObject.collider.enabled = true;
                            }

                            State.HouseStatus[HouseIDKey] = true;
                            continue;
                        }
                        State.HouseUpdate[HouseIDKey]--;
                        build buildNow = State.HouseGameObject[HouseIDKey].GetComponent <build>();
                        if (buildNow.status == 2 || buildNow.status == 3 || buildNow.status == 4)
                        {
                            if (State.HouseStatusNow[HouseIDKey] == 1)
                            {
                                Vector3 Pos = new Vector3(State.HousePositionX[HouseIDKey], 4f, State.HousePositionZ[HouseIDKey]);

                                GameObject BombAnimateNow = (GameObject)Instantiate(BigBomb, Pos, BigBomb.transform.rotation);


                                Destroy(BombAnimateNow, 2);
                            }
                        }
                        if (State.HouseStatusNow[HouseIDKey] == 6)
                        {
                            Vector3 Pos = new Vector3(State.HousePositionX[HouseIDKey], 4f, State.HousePositionZ[HouseIDKey]);

                            GameObject BombAnimateNow = (GameObject)Instantiate(BigBomb, Pos, BigBomb.transform.rotation);

                            Destroy(BombAnimateNow, 2);
                            Server.Send("58" + HouseIDKey + "," + (-1 * buildNow.HP));
                        }

                        if (State.HouseHP[HouseIDKey] <= 0)
                        {
                            Server.Send("57" + HouseIDKey);
                            destroyThisHouse(HouseIDKey);
                            break;
                        }

                        if (State.HouseUpdate[HouseIDKey] <= 0)
                        {
                            print("error15");
                            destroyThisHouse(HouseIDKey);
                            continue;
                        }

                        if (buildNow.kind != State.HouseKind[HouseIDKey])
                        {
                            print("error10");

                            Destroy(State.HouseGameObject[HouseIDKey]);
                            State.PlayerGameObject.GetComponent <Player>().click = false;
                            if (State.HousePlayerID[HouseIDKey] != State.PlayerName)
                            {
                                Vector3 Pos = new Vector3(State.HousePositionX[HouseIDKey] - 1, 5f, State.HousePositionZ[HouseIDKey] + 1);

                                GameObject animateNow = (GameObject)Instantiate(Building, Pos, Building.transform.rotation);
                                Pos = new Vector3(State.HousePositionX[HouseIDKey], 4f, State.HousePositionZ[HouseIDKey]);

                                GameObject SomkeNow = (GameObject)Instantiate(Smoke, Pos, Building.transform.rotation);
                                Pos = new Vector3(State.HousePositionX[HouseIDKey], 4.1f, State.HousePositionZ[HouseIDKey]);

                                GameObject SmokeAnimateNow = (GameObject)Instantiate(SmokeAnimation, Pos, Building.transform.rotation);

                                Destroy(animateNow, 5);
                                Destroy(SomkeNow, 5);
                                Destroy(SmokeAnimateNow, 5);
                            }
                            BuildNow = (Rigidbody)Instantiate(build[State.HouseKind[HouseIDKey]], new Vector3(State.HousePositionX[HouseIDKey], 0, State.HousePositionZ[HouseIDKey]), build[State.HouseKind[HouseIDKey]].transform.rotation);
                            build thisBuild = BuildNow.gameObject.GetComponent <build>();
                            State.HouseGameObject[HouseIDKey] = BuildNow.gameObject;
                            thisBuild.HouseID         = State.HouseID[HouseIDKey];
                            thisBuild.PlayerID        = State.HousePlayerID[HouseIDKey];
                            thisBuild.gameObject.name = State.HouseID[HouseIDKey];
                            thisBuild.kind            = State.HouseKind[HouseIDKey];
                            thisBuild.HouseLevel      = State.HouseLevel[HouseIDKey];
                            thisBuild.HP    = State.HouseHP[HouseIDKey];
                            thisBuild.MaxHP = State.HouseMaxHP[HouseIDKey];


                            if (State.HousePlayerID [HouseIDKey] != State.PlayerName)
                            {
                                BuildNow.gameObject.tag = "Enemy";
                            }

                            //destroyThisHouse(HouseIDKey);
                            print("error11");
                            continue;
                        }

                        if (buildNow.HP > State.HouseHP[HouseIDKey])
                        {
                            Vector3 Pos = new Vector3(State.HousePositionX[HouseIDKey], 4f, State.HousePositionZ[HouseIDKey]);

                            GameObject SomkeNow = (GameObject)Instantiate(Smoke, Pos, Building.transform.rotation);
                            Pos = new Vector3(State.HousePositionX[HouseIDKey], 4.1f, State.HousePositionZ[HouseIDKey]);

                            GameObject SmokeAnimateNow = (GameObject)Instantiate(SmokeAnimation, Pos, Building.transform.rotation);
                            Pos = new Vector3(State.HousePositionX[HouseIDKey], 4.2f, State.HousePositionZ[HouseIDKey]);

                            GameObject BombAnimateNow = (GameObject)Instantiate(BombAnimation, Pos, Building.transform.rotation);

                            Destroy(SomkeNow, 3);
                            Destroy(SmokeAnimateNow, 3);
                            Destroy(BombAnimateNow, 3);
                        }

                        if (State.HousePlayerID [HouseIDKey] == State.PlayerName && buildNow.kind == 1 && buildNow.HouseLevel >= 2)
                        {
                            if (Math.Abs(State.PosX - buildNow.transform.position.x) < Math.Abs(State.housePosX) && Math.Abs(State.PosZ - buildNow.transform.position.z) < Math.Abs(State.housePosZ))
                            {
                                State.housePosX = buildNow.transform.position.x;
                                State.housePosZ = buildNow.transform.position.z;
                            }
                            //State.house=BuildNow.gameObject;
                        }
                        buildNow.kind       = State.HouseKind[HouseIDKey];
                        buildNow.HouseLevel = State.HouseLevel[HouseIDKey];
                        buildNow.HP         = State.HouseHP[HouseIDKey];
                        buildNow.MaxHP      = State.HouseMaxHP[HouseIDKey];
                        buildNow.status     = State.HouseStatusNow[HouseIDKey];
                    }            //if containkey
                }                //house Foreach


                foreach (string PlayerIDKey in State.AnotherPlayerList.Keys)
                {
                    if (State.PlayerID.ContainsKey(PlayerIDKey))
                    {
                        if (!State.PlayerStatus[PlayerIDKey])
                        {
                            AnotherPlayerNow = (Rigidbody)Instantiate(AnotherPlayer, new Vector3(State.PlayerPositionX[PlayerIDKey], 0, State.PlayerPositionZ[PlayerIDKey]), AnotherPlayer.transform.rotation);
                            AnotherPlayer thisPlayer = AnotherPlayerNow.gameObject.GetComponent <AnotherPlayer>();
                            State.AnotherPlayerGameObject.Add(PlayerIDKey, AnotherPlayerNow.gameObject);
                            thisPlayer.PlayerID             = State.PlayerID[PlayerIDKey];
                            State.PlayerStatus[PlayerIDKey] = true;
                        }
                        State.PlayerUpdate[PlayerIDKey]--;
                        if (State.PlayerUpdate[PlayerIDKey] <= 0)
                        {
                            destroyThisPlayer(PlayerIDKey);
                            continue;
                        }
                    }            //if containkey
                }                //Player foreach

                foreach (string SourceIDKey in State.SourceList.Keys)
                {
                    if (State.SourceID.ContainsKey(SourceIDKey))
                    {
                        if (!State.SourceStatus[SourceIDKey])
                        {
                            print("SourceError");
                            SourceNow = (Rigidbody)Instantiate(source[State.Sourcekind[SourceIDKey]], new Vector3(State.SourcePositionX[SourceIDKey], 0, State.SourcePositionZ[SourceIDKey]), source[State.Sourcekind[SourceIDKey]].transform.rotation);
                            Source thisSource = SourceNow.gameObject.GetComponent <Source>();
                            State.SourceGameObject.Add(SourceIDKey, SourceNow.gameObject);

                            thisSource.SourceID        = State.SourceID[SourceIDKey];
                            thisSource.gameObject.name = State.SourceID[SourceIDKey];

                            thisSource.kind    = State.Sourcekind[SourceIDKey];
                            thisSource.quatity = State.SourceQuatity[SourceIDKey];
                            State.SourceStatus[SourceIDKey] = true;
                        }

                        Source suildNow = State.SourceGameObject[SourceIDKey].GetComponent <Source>();


                        suildNow.quatity = State.SourceQuatity[SourceIDKey];

                        State.SourceUpdate[SourceIDKey]--;
                        if (State.SourceUpdate[SourceIDKey] <= 0)
                        {
                            destroyThisSource(SourceIDKey);
                            continue;
                        }
                    }
                }                //Source foreach
            }catch (Exception) {
                print("error6");
                //State.isConnect=false;

                StartCoroutine("server_function");
            }
        }
    }