Пример #1
0
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }

        // here temporarily cos lazy change scene
        // proper place should be when player selects single player or multiplayer
        //PlayerPrefs.SetString("Game_Mode", "Online_Coop");

        if (PlayerPrefs.GetString("Game_Mode") == "Single_Player")
        {
            b_foundLocalPlayer = true;
            gameType           = GAME_TYPE.SINGLE_PLAYER;

            GameObject playerPrefab = Resources.Load("Prefabs/PlayerHero") as GameObject;
            localPlayer = GameObject.Instantiate(playerPrefab);
            Debug.Log("DDD");
        }
        else if (PlayerPrefs.GetString("Game_Mode") == "Online_Versus")
        {
            gameType = GAME_TYPE.ONLINE_VS;
        }
        else if (PlayerPrefs.GetString("Game_Mode") == "Online_Coop")
        {
            gameType = GAME_TYPE.ONINE_COOP;
        }
    }
Пример #2
0
 public void AddHp(HealthUI healthUI)
 {
     if (m_damageable.currentHitPoints < m_damageable.maxHitPoints)
     {
         MessageBox.Show("Add HitPoints");
         m_damageable.currentHitPoints++;
         CUseHp msg = new CUseHp();
         if (TreasureInfo.playerTreasure["Elixir_3"].number == 1)
         {
             TreasureInfo.playerTreasure.Remove("Elixir_3");
             // send message
             msg.toDelete = true;
         }
         else
         {
             TreasureInfo.playerTreasure["Elixir_3"].number--;
             // send message
             msg.toDelete = false;
             msg.ownNum   = TreasureInfo.playerTreasure["Elixir_3"].number;
         }
         MyNetwork.Send(msg);
         if (inventoryHandler != null)
         {
             inventoryHandler.UpdateInventory();
         }
         healthUI.ChangeHitPointUI(m_damageable);
     }
     else
     {
         MessageBox.Show("currentHitPoints is already max");
     }
 }
Пример #3
0
        public void SendJumpingAction()
        {
            CPlayerJump action = new CPlayerJump();

            action.player = m_entity.entityId;
            MyNetwork.Send(action);
        }
Пример #4
0
    public void ClickSure()
    {
        Debug.Log(itemName);
        // remove from mall and put in package
        TreasureInfo.treasureMall.Remove(itemName);
        TreasurePackage tmp = new TreasurePackage()
        {
            wear   = false,
            number = 1
        };

        TreasureInfo.playerTreasure.Add(itemName, tmp);
        foreach (var kv in TreasureInfo.playerTreasure)
        {
            Debug.Log(kv.Key);
        }

        // put item back to inventory
        if (handler != null)
        {
            Debug.Log("refresh sell window");
            handler.Refresh();
        }


        // send message
        CNotSell msg = new CNotSell()
        {
            goodsName = itemName
        };

        MyNetwork.Send(msg);
    }
Пример #5
0
        public void GainWeapon()
        {
            int type = 1;

            if (TreasureInfo.playerTreasure.ContainsKey("Shurikens"))
            {
                TreasureInfo.playerTreasure["Shurikens"].number++;
                type = 2;
            }
            else
            {
                TreasureInfo.playerTreasure.Add("Shurikens", new TreasurePackage {
                    number = 1, wear = false
                });
            }
            CBuy buyMessage = new CBuy()
            {
                totalGold   = 0,
                totalSilver = 1,
                Goods       = new List <DTreasureBuy>()
            };

            buyMessage.Goods.Add(new DTreasureBuy()
            {
                name = "Shurikens", number = 1, type = type
            });
            MyNetwork.Send(buyMessage);
            MessageBox.Show("found new Treasure, check it out!");
        }
Пример #6
0
    public void OnSendButtonClick(GameObject inputField)
    {
        InputField input = inputField.GetComponent <InputField>();

        if (input == null)
        {
            return;
        }

        if (input.text.Trim().Length == 0)
        {
            return;
        }


        SendMyMessage(input.text);

        //MessageBox.Show("send message");
        CChatMessage chatMessage = new CChatMessage()
        {
            toName      = PlayerInfo.chatName,
            chatContext = input.text
        };

        MyNetwork.Send(chatMessage);

        input.text = "";
    }
Пример #7
0
        public void SendMovingEnd()
        {
            CPlayerMove action = new CPlayerMove();

            action.state = MoveState.END;
            InitMove(action);
            MyNetwork.Send(action);
        }
Пример #8
0
        public void SendMovingStep()
        {
            CPlayerMove action = new CPlayerMove();

            action.state = MoveState.STEP;
            InitMove(action);
            MyNetwork.Send(action);
        }
Пример #9
0
        public void SendMovingBegin()
        {
            CPlayerMove action = new CPlayerMove();

            action.state = MoveState.BEGIN;
            InitMove(action);
            MyNetwork.Send(action);
        }
Пример #10
0
 void Update()
 {
     if (!run)
     {
         MyNetwork.debugConnect();
         run = true;
     }
 }
Пример #11
0
        public void SendAttackingAction()
        {
            CPlayerAttack action = new CPlayerAttack();

            action.player = m_entity.entityId;
            action.target = m_attackTarget;
            MyNetwork.Send(action);
        }
Пример #12
0
        public void SendAttackingAction()
        {
            CPlayerAttack action = new CPlayerAttack();

            action.player = m_entity.entityId;
            action.target = m_attackTarget;
            Debug.Log(string.Format("SendAttackingAction {0:D}", m_attackTarget));
            MyNetwork.Send(action);
        }
Пример #13
0
    public void OnClickBuy()
    {
        // varify whether has enough money to buy
        if (PlayerInfo.GoldNum >= totalGold && PlayerInfo.SilverNum >= totalSilver)
        {
            PlayerInfo.SilverNum -= totalSilver;

            CBuy buyMessage = new CBuy()
            {
                totalGold   = totalGold,
                totalSilver = totalSilver,
                Goods       = new List <DTreasureBuy>()
            };

            foreach (string GoldName in GoldGoods)
            {
                buyMessage.Goods.Add(new DTreasureBuy()
                {
                    name = GoldName, type = 0
                });
            }

            foreach (var kv in SilverGoods)
            {
                string sliverName = kv.Key;
                int    sliverNum  = kv.Value;
                if (TreasureInfo.playerTreasure.ContainsKey(sliverName))
                {
                    TreasureInfo.playerTreasure[sliverName].number += sliverNum;
                    buyMessage.Goods.Add(new DTreasureBuy()
                    {
                        name = sliverName, number = TreasureInfo.playerTreasure[sliverName].number, type = 2
                    });
                }
                else
                {
                    TreasurePackage tmp = new TreasurePackage()
                    {
                        number = sliverNum, wear = false
                    };
                    TreasureInfo.playerTreasure.Add(sliverName, tmp);
                    buyMessage.Goods.Add(new DTreasureBuy()
                    {
                        name = sliverName, number = sliverNum, type = 1
                    });
                }
            }
            MyNetwork.Send(buyMessage);

            cleanCache();
        }
        else
        {
            MessageBox.Show("don't have enough money!");
        }
    }
Пример #14
0
 void Awake()
 {
     if (instance != null)
     {
     }
     else
     {
         instance = this;
     }
 }
Пример #15
0
    void Test()
    {
        // test
        //List<string> test = new List<string>();
        //test.Add("123");

        //foreach (string request in test)
        foreach (string request in PlayerInfo.friendRequest)
        {
            addFriends.Add(GameObject.Instantiate(RequestInfo));
            addFriends[addFriends.Count - 1].name = request;
            addFriends[addFriends.Count - 1].transform.SetParent(transform, false);
            addFriends[addFriends.Count - 1].SetActive(true);
            var Textvalue = addFriends[addFriends.Count - 1].GetComponentInChildren <Text>();
            Textvalue.text = request;

            // bind a click event
            foreach (Button buttonTmp in addFriends[addFriends.Count - 1].GetComponentsInChildren <Button>())
            {
                //Debug.Log("bind button " + buttonTmp.name);
                if (buttonTmp.name.Equals("agree"))
                {
                    agree = buttonTmp;
                    agree.onClick.AddListener(delegate() {
                        Debug.Log("agree add friend: " + request);
                        Destroy(addFriends[addFriends.Count - 1]);
                        PlayerInfo.friendRequest.Remove(request);
                        CAddFriend msg = new CAddFriend()
                        {
                            success    = true,
                            friendName = request
                        };
                        MyNetwork.Send(msg);
                        PlayerInfo.friends.Add(request);
                    });
                }
                else if (buttonTmp.name.Equals("disagree"))
                {
                    disagree = buttonTmp;
                    disagree.onClick.AddListener(delegate() {
                        Debug.Log("disagree add friend: " + request);
                        Destroy(addFriends[addFriends.Count - 1]);
                        PlayerInfo.friendRequest.Remove(request);
                        CAddFriend msg = new CAddFriend()
                        {
                            success    = false,
                            friendName = request
                        };
                        MyNetwork.Send(msg);
                    });
                }
            }
        }
    }
Пример #16
0
    void Start()
    {
        MyNetwork = GetComponent <MyNetwork>();
        NetPeerConfiguration config = new NetPeerConfiguration(appName);

        config.Port = 3000;
        config.MaximumConnections = 32;
        config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
        peer = new NetServer(config);
        peer.Start();
    }
Пример #17
0
        private void OnTriggerStay(Collider other)
        {
            var pc = other.GetComponent <PlayerController>();

            if (pc != null && pc.IsMine)
            {
                CDamage msg = new CDamage();
                msg.entityId = pc.Entity.entityId;
                msg.decHP    = damageAmount;
                MyNetwork.Send(msg);
            }
        }
Пример #18
0
    void Start()
    {
        MyNetwork = GetComponent <MyNetwork>();
        NetPeerConfiguration config = new NetPeerConfiguration(appName);

        peer = new NetClient(config);
        peer.Start();

        NetOutgoingMessage approval = peer.CreateMessage();

        connection = peer.Connect("localhost", 3000, approval);
    }
Пример #19
0
 void PositionRevise()
 {
     if (m_target != null && m_target is PlayerController)
     {
         PlayerController controller = (PlayerController)(m_target);
         if (controller.IsMine)
         {
             CPositionRevise msg = new CPositionRevise();
             msg.entityId = m_entity.EntityId;
             msg.pos.x    = transform.position.x;
             msg.pos.y    = transform.position.y;
             msg.pos.z    = transform.position.z;
             MyNetwork.Send(msg);
         }
     }
 }
Пример #20
0
        public void PlayerTakeItem()
        {
            CCreateItem msg = new CCreateItem();

            Debug.Log("Take item");
            int count = FrontEnd.World.Instance.fPlayer.inventory.Count;

            if (count >= FrontEnd.World.Instance.fPlayer.inventory_max)
            {
                MessageBox.Show("Can't get more Items.");
            }
            else
            {
                MyNetwork.Send(msg);
            }
        }
Пример #21
0
        public Robot(IWebDriver driver)
        {
            this.driver = driver;
            Util        = new Util(driver);

            Landing = new Landing(driver);
            Login   = new Login(driver);

            Common = new Common(driver);
            Home   = new Home(driver);

            MyNetwork   = new MyNetwork(driver);
            Connections = new Connections(driver);

            Profile = new Profile(driver);
        }
Пример #22
0
    public void OnConnectClicked()
    {
        string host = m_hostInput.text;
        short  port = short.Parse(m_portInput.text);
        bool   ok   = MyNetwork.Connect(host, port);

        if (!ok)
        {
            MessageBox.Show(string.Format("connect to {0}:{1} fail", host, port));
        }
        else
        {
            PlayerPrefs.SetString(MyNetwork.HOST, host);
            PlayerPrefs.SetInt(MyNetwork.PORT, port);
            MessageBox.Show(string.Format("connect to {0}:{1} success", host, port));
        }
    }
Пример #23
0
        public void SendFlash(int x_, int y_, int z_)
        {
            CPlayerFlash action = new CPlayerFlash();

            action.player = m_entity.entityId;
            action.rot.x  = transform.rotation.x;
            action.rot.y  = transform.rotation.y;
            action.rot.z  = transform.rotation.z;
            action.rot.w  = transform.rotation.w;
            action.pos.x  = x_;
            action.pos.y  = y_;
            action.pos.z  = z_;
            //action.pos = new Vector3(1, 2, 3);//!!!!!!!!!!!!
            Debug.Log("======================");
            print(action.player);
            Debug.Log("======================");
            MyNetwork.Send(action);
            //Client.Instance.Send(action);
            Debug.Log("success use flashfuction in step 1");
        }
Пример #24
0
    public void OnChatHistoryButtonClick(InputField inputNum)
    {
        int num = 0;

        if (inputNum == null || !Int32.TryParse(inputNum.text, out num))
        {
            inputNum.text = "";
            return;
        }

        CGetChatHistory chatHistoryMessage = new CGetChatHistory()
        {
            chatWithName = PlayerInfo.chatName,
            maxChatNum   = num
        };

        MyNetwork.Send(chatHistoryMessage);

        inputNum.text = "";
    }
Пример #25
0
        void OnTriggerEnter(Collider other)
        {
            var pc = other.GetComponent <PlayerController>();

            if (pc != null && pc.IsMine)
            {
                CDamage msg = new CDamage();
                msg.entityId = pc.Entity.entityId;
                msg.decHP    = int.MaxValue;
                MyNetwork.Send(msg);
            }
            if (audio != null)
            {
                audio.transform.position = other.transform.position;
                if (!audio.isPlaying)
                {
                    audio.Play();
                }
            }
        }
Пример #26
0
        private void OnTriggerEnter(Collider other)
        {
            if ((ColliderLayer.value & 1 << other.gameObject.layer) == 0)
            {
                return;
            }

            PlayerController player = other.gameObject.GetComponent <PlayerController>();

            if (player == null || !player.IsMine)
            {
                return;
            }

            CEnemyClosing msg = new CEnemyClosing();

            msg.entityId = m_entity.entityId;
            msg.enemyId  = player.Entity.entityId;
            MyNetwork.Send(msg);
        }
Пример #27
0
 public void SearchFriend()
 {
     if (searchFriend != null)
     {
         string searchName = searchFriend.text;
         Debug.Log("search friend: " + searchName);
         if (PlayerInfo.friends.Contains(searchName))
         {
             MessageBox.Show(searchName + " is alreay your friend");
         }
         else
         {
             MessageBox.Show("Send friend request successfully");
             CSearchAddFriend msg = new CSearchAddFriend()
             {
                 name = searchName
             };
             MyNetwork.Send(msg);
         }
     }
 }
Пример #28
0
        public void PlayerTakeWeapon(GameObject weapon)
        {
            if (m_controller.CanAttack)
            {
                return;
            }

            NetworkEntity weaponEntity = weapon.GetComponent <NetworkEntity>();

            if (weaponEntity == null)
            {
                return;
            }

            CPlayerTake msg = new CPlayerTake();

            msg.byName     = weaponEntity.canClone;
            msg.targetName = weapon.name;
            msg.playerId   = m_entity.entityId;
            msg.targetId   = weaponEntity.entityId;
            MyNetwork.Send(msg);
        }
Пример #29
0
    public void SendMessage()
    {
        // attribute message
        CPlayerAttribute msg1 = new CPlayerAttribute()
        {
            intelligence = PlayerInfo.intelligence,
            speed        = PlayerInfo.speed,
            attack       = PlayerInfo.attack,
            defense      = PlayerInfo.defense
        };

        MyNetwork.Send(msg1);

        // treasure wear or put off message
        if (TreasureInfo.modifiedTreasure.Count != 0)
        {
            CTreasureWear msg2 = new CTreasureWear()
            {
                treasureWear = new Dictionary <string, bool>(TreasureInfo.modifiedTreasure)
            };
            MyNetwork.Send(msg2);
        }
    }
Пример #30
0
    // Update is called once per frame
    void Update()
    {
        foreach (string request in PlayerInfo.friendRequest)
        {
            bool addRequest = true;
            foreach (GameObject tmp in addFriends)
            {
                if (tmp.name.Equals(request))
                {
                    addRequest = false;
                }
            }

            if (addRequest)
            {
                //MessageBox.Show("online friends count: " + PlayerInfo.friends.Count);

                addFriends.Add(GameObject.Instantiate(RequestInfo));
                addFriends[addFriends.Count - 1].name = request;
                addFriends[addFriends.Count - 1].transform.SetParent(transform, false);
                addFriends[addFriends.Count - 1].SetActive(true);
                var Textvalue = addFriends[addFriends.Count - 1].GetComponentInChildren <Text>();
                Textvalue.text = request;

                // bind a click event
                foreach (Button buttonTmp in addFriends[addFriends.Count - 1].GetComponents <Button>())
                {
                    if (buttonTmp.name.Equals("agree"))
                    {
                        agree = buttonTmp;
                        agree.onClick.AddListener(delegate() {
                            Debug.Log("agree add friend: " + request);
                            Destroy(addFriends[addFriends.Count - 1]);
                            PlayerInfo.friendRequest.Remove(request);
                            CAddFriend msg = new CAddFriend()
                            {
                                success    = true,
                                friendName = request
                            };
                            MyNetwork.Send(msg);
                            PlayerInfo.friends.Add(request);
                        });
                    }
                    else if (buttonTmp.name.Equals("disagree"))
                    {
                        disagree = buttonTmp;
                        disagree.onClick.AddListener(delegate() {
                            Debug.Log("disagree add friend: " + request);
                            Destroy(addFriends[addFriends.Count - 1]);
                            PlayerInfo.friendRequest.Remove(request);
                            CAddFriend msg = new CAddFriend()
                            {
                                success    = false,
                                friendName = request
                            };
                            MyNetwork.Send(msg);
                        });
                    }
                }
            }
        }
    }