public void SendJumpingAction()
        {
            CPlayerJump action = new CPlayerJump();

            action.player = m_entity.entityId;
            MyNetwork.Send(action);
        }
Exemple #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");
     }
 }
Exemple #3
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 = "";
    }
Exemple #4
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!");
        }
Exemple #5
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);
    }
        public void SendMovingStep()
        {
            CPlayerMove action = new CPlayerMove();

            action.state = MoveState.STEP;
            InitMove(action);
            MyNetwork.Send(action);
        }
        public void SendMovingEnd()
        {
            CPlayerMove action = new CPlayerMove();

            action.state = MoveState.END;
            InitMove(action);
            MyNetwork.Send(action);
        }
        public void SendMovingBegin()
        {
            CPlayerMove action = new CPlayerMove();

            action.state = MoveState.BEGIN;
            InitMove(action);
            MyNetwork.Send(action);
        }
        public void SendAttackingAction()
        {
            CPlayerAttack action = new CPlayerAttack();

            action.player = m_entity.entityId;
            action.target = m_attackTarget;
            MyNetwork.Send(action);
        }
Exemple #10
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);
        }
Exemple #11
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!");
        }
    }
Exemple #12
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);
                    });
                }
            }
        }
    }
Exemple #13
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);
            }
        }
Exemple #14
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);
         }
     }
 }
Exemple #15
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);
            }
        }
Exemple #16
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();
                }
            }
        }
Exemple #17
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");
        }
Exemple #18
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 = "";
    }
Exemple #19
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);
        }
Exemple #20
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);
         }
     }
 }
        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);
        }
Exemple #22
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);
        }
    }
Exemple #23
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);
                        });
                    }
                }
            }
        }
    }
Exemple #24
0
    public void SellGoods()
    {
        if (itemName != null)
        {
            price_ = int.Parse(price.text);
            if (price_ < 0)
            {
                MessageBox.Show("Input text must > 0!");
                return;
            }

            if (isMall)
            {
                if (price_ > TreasureInfo.playerTreasure[itemName].number)
                {
                    MessageBox.Show("You do not have so many treasure!");
                    return;
                }

                CSellSilver msg = new CSellSilver();
                // sell back to mall, remove treasure from package and add silverCoin number
                PlayerInfo.SilverNum += price_ * TreasureInfo.treasureMall[itemName].price;
                msg.silverCoin        = PlayerInfo.SilverNum;
                msg.goods             = itemName;

                if (TreasureInfo.playerTreasure[itemName].number > price_)
                {
                    TreasureInfo.playerTreasure[itemName].number -= price_;
                    msg.sellAll   = false;
                    msg.remainNum = TreasureInfo.playerTreasure[itemName].number;
                }
                else
                {
                    TreasureInfo.playerTreasure.Remove(itemName);
                    msg.sellAll = true;
                }

                // send message
                MyNetwork.Send(msg);
            }
            else
            {
                // gold treasures, remove treasure from package and add to mall
                TreasureInfo.playerTreasure.Remove(itemName);
                TreasureMall tmp = new TreasureMall()
                {
                    ownerName = PlayerInfo.name,
                    price     = price_,
                    isGold    = true
                };
                TreasureInfo.treasureMall.Add(itemName, tmp);

                // send message
                CSellGold msg2 = new CSellGold()
                {
                    goods = itemName,
                    price = price_
                };
                MyNetwork.Send(msg2);
            }
        }

        if (packageHandler != null)
        {
            packageHandler.ClearAfterAdd();
        }

        // scene
        if (inventoryHandler != null)
        {
            inventoryHandler.UpdateInventory();
        }
    }