示例#1
0
    void Update()
    {
        time += Time.deltaTime;

        float inX = Input.GetAxisRaw("Horizontal");
        float inZ = Input.GetAxisRaw("Vertical");

        float   movementVectorMagnitude = Time.deltaTime * Player.MovementSpeed;
        Vector3 movementVector          = (this.transform.forward * inZ + this.transform.right * inX).normalized * movementVectorMagnitude;

        if (Input.GetButtonUp("Vertical") || Input.GetButtonUp("Horizontal"))
        {
            stop = false;
        }


        if (!UIController.IsActive && !stop && Player.Alive)
        {
            if (inX != 0 || inZ != 0)
            {
                this.transform.position += movementVector;
                Target = null;
            }
        }

        if (Target != null)
        {
            this.transform.LookAt(Target.transform.position);
            this.transform.eulerAngles = new Vector3(0, this.transform.eulerAngles.y, 0);
            this.transform.position   += this.transform.forward * movementVectorMagnitude;

            if (Vector2.Distance(this.transform.position.XZ(), Target.transform.position.XZ()) < (Range - RANGE_ERROR_POINT))
            {
                Target = null;
            }
        }

        if (time > 0.1f && this.transform.hasChanged)
        {
            transform.hasChanged = false;
            AuthorySender.Movement();
            time = 0;
        }
    }
示例#2
0
    void Awake()
    {
        MasterClientManager = FindObjectOfType <MasterClientManager>();

        //Force SpawnCollection Awake() method for initialization
        SpawnCollection spawnCollection = FindObjectOfType <SpawnCollection>();

        spawnCollection.gameObject.SetActive(false);
        spawnCollection.gameObject.SetActive(true);

        //Force SkillCollection Awake() method for initialization
        SkillCollection skillList = FindObjectOfType <SkillCollection>();

        skillList.gameObject.SetActive(false);
        skillList.gameObject.SetActive(true);

        AuthoryClient = new AuthoryClient(MasterClientManager.GetMapServerAuthString());
        AuthoryClient.Connect(MasterClientManager.MapServerIP, MasterClientManager.MapServerPort, MasterClientManager.MapServerUID);

        NetIncomingMessage msgIn;
        bool     playerInfoArrived = false;
        DateTime start             = DateTime.Now.AddSeconds(5);

        while (playerInfoArrived != true)
        {
            if (start < DateTime.Now)
            {
                return;
            }
            else
            {
                while ((msgIn = AuthoryClient.Client.ReadMessage()) != null)
                {
                    if (msgIn.MessageType == NetIncomingMessageType.Data)
                    {
                        if (((MessageType)msgIn.ReadByte()) == MessageType.PlayerID)
                        {
                            ushort Id   = msgIn.ReadUInt16();
                            string Name = msgIn.ReadString();

                            int maxHealth = msgIn.ReadInt32();
                            int health    = msgIn.ReadInt32();

                            int maxMana = msgIn.ReadInt32();

                            int mana = msgIn.ReadInt32();

                            byte      level     = msgIn.ReadByte();
                            ModelType modelType = (ModelType)msgIn.ReadByte();


                            float x             = msgIn.ReadFloat();
                            float z             = msgIn.ReadFloat();
                            float movementSpeed = msgIn.ReadFloat();

                            ushort END = msgIn.ReadUInt16();
                            ushort STR = msgIn.ReadUInt16();
                            ushort AGI = msgIn.ReadUInt16();
                            ushort INT = msgIn.ReadUInt16();
                            ushort KNW = msgIn.ReadUInt16();
                            ushort LCK = msgIn.ReadUInt16();

                            long experience    = msgIn.ReadInt64();
                            long maxExperience = msgIn.ReadInt64();

                            AuthoryClient.Handler.SetMapSize(msgIn.ReadInt32());

                            GameObject entity = AuthoryClient.Handler.GetEntityObjectByModelType(modelType).gameObject;

                            GameObject.Destroy(entity.GetComponent <Entity>());

                            PlayerEntity playerEntity = entity.AddComponent <PlayerEntity>();
                            entity.AddComponent <PlayerMove>();

                            Camera.main.GetComponent <CameraOrbit>().Target = playerEntity.transform;

                            AuthoryData.Instance.SetPlayer(playerEntity, Id, Name);

                            playerEntity.transform.position = new Vector3(x, 0, z);

                            playerEntity.SetMaxHealth(maxHealth);
                            playerEntity.SetHealth((ushort)health);

                            playerEntity.SetMaxMana(maxMana);
                            playerEntity.SetMana((ushort)mana);

                            playerEntity.Level = level;

                            playerEntity.MovementSpeed = movementSpeed;

                            playerEntity.Attributes.Endurance    = END;
                            playerEntity.Attributes.Strength     = STR;
                            playerEntity.Attributes.Agility      = AGI;
                            playerEntity.Attributes.Intelligence = INT;
                            playerEntity.Attributes.Knowledge    = KNW;
                            playerEntity.Attributes.Luck         = LCK;

                            AuthoryClient.UIController.Player = playerEntity;
                            AuthoryClient.UIController.UpdateMaxExperience(maxExperience, experience);

                            playerInfoArrived = true;
                            break;
                        }
                    }
                }
            }
        }
        AuthorySender.Movement();
    }