Exemplo n.º 1
0
    public void OnDataReceived(DataPackage dp)
    {
        if (dp is BaseCapturePackage)
        {
            BaseCapturePackage bcp = (BaseCapturePackage)dp;
            if (bcp.BaseId != BaseId)
            {
                return;
            }

            Owner = GameManager.Instance.GetPlayer(bcp.PlayerIP);
            int playerIndex = GameManager.Instance.GetPlayers().IndexOf(Owner);

            Component[] mrs = transform.root.gameObject.GetComponentsInChildren(typeof(MeshRenderer));
            foreach (MeshRenderer mr in mrs)
            {
                if (mr.material.name.Contains("Material #4"))
                {
                    mr.material = GameManager.Instance.baseMaterials[playerIndex * 2];
                }
                if (mr.material.name.Contains("Material #5"))
                {
                    mr.material = GameManager.Instance.baseMaterials[playerIndex * 2 + 1];
                }
            }
        }
    }
Exemplo n.º 2
0
        public override DataPackage CreateFromBody(string b)
        {
            string[] split = b.Split('|');

            BaseCapturePackage bcp = new BaseCapturePackage();
            bcp.PlayerIP = IPAddress.Parse(split[0]);
            bcp.BaseId = int.Parse(split[1]);

            return bcp;
        }
Exemplo n.º 3
0
        public override DataPackage CreateFromBody(string b)
        {
            string[] split = b.Split('|');

            BaseCapturePackage bcp = new BaseCapturePackage();

            bcp.PlayerIP = IPAddress.Parse(split[0]);
            bcp.BaseId   = int.Parse(split[1]);

            return(bcp);
        }
Exemplo n.º 4
0
    void OnTriggerEnter(Collider col)
    {
        if (!IsControlled)
        {
            return;
        }

        if (col.transform.root.name.Contains("Base"))
        {
            Base b = col.transform.root.gameObject.GetComponentInChildren <Base>();
            Flag f = GameManager.Instance.GetFlag(this);
            if (b == null || f == null || (b.Owner == null && GameManager.Instance.GetPlayerBase(this) != null) ||
                (b.Owner != null && b.Owner != this))
            {
                return;
            }

            if (b.Owner == null)
            {
                //capture base

                BaseCapturePackage bcp = new BaseCapturePackage();
                bcp.PlayerIP = Client.GetLocalIPAddress();
                bcp.BaseId   = b.BaseId;
                NetworkManager.Instance.Client.SendData(bcp);
            }

            FlagPackage fp = new FlagPackage();
            fp.Event  = FlagPackage.FlagEvent.Capture;
            fp.FlagId = f.FlagId;
            NetworkManager.Instance.Client.SendData(fp);
        }
        else if (col.gameObject.name.Contains("Flag"))
        {
            Flag f = col.GetComponentInChildren <Flag>();
            if (GameManager.Instance.GetFlag(this) != null || f == null || f.Owner != null)
            {
                return;
            }

            FlagPackage fp = new FlagPackage();
            fp.Event  = FlagPackage.FlagEvent.PickUp;
            fp.FlagId = f.FlagId;
            NetworkManager.Instance.Client.SendData(fp);
        }
    }
Exemplo n.º 5
0
    void OnTriggerEnter(Collider col)
    {
        if (!IsControlled)
            return;

        if (col.transform.root.name.Contains("Base"))
        {
            Base b = col.transform.root.gameObject.GetComponentInChildren<Base>();
            Flag f = GameManager.Instance.GetFlag(this);
            if (b == null || f == null || (b.Owner == null && GameManager.Instance.GetPlayerBase(this) != null) ||
                (b.Owner != null && b.Owner != this))
                return;

            if (b.Owner == null)
            {
                //capture base

                BaseCapturePackage bcp = new BaseCapturePackage();
                bcp.PlayerIP = Client.GetLocalIPAddress();
                bcp.BaseId = b.BaseId;
                NetworkManager.Instance.Client.SendData(bcp);
            }

            FlagPackage fp = new FlagPackage();
            fp.Event = FlagPackage.FlagEvent.Capture;
            fp.FlagId = f.FlagId;
            NetworkManager.Instance.Client.SendData(fp);
        }
        else if (col.gameObject.name.Contains("Flag"))
        {
            Flag f = col.GetComponentInChildren<Flag>();
            if (GameManager.Instance.GetFlag(this) != null || f == null || f.Owner != null)
                return;

            FlagPackage fp = new FlagPackage();
            fp.Event = FlagPackage.FlagEvent.PickUp;
            fp.FlagId = f.FlagId;
            NetworkManager.Instance.Client.SendData(fp);
        }
    }