Esempio n. 1
0
        public void MoveTo(Position destination)
        {
            float moveSpeed = GetAttribute(Attribute.Spd) * 0.01f;

            m_fsm.blackboard.moveSpeed   = moveSpeed;
            m_fsm.blackboard.destination = destination;
            m_fsm.Transition(UnitFSM.State.ID.Move);
            MsgMoveTo_S2C msg = new MsgMoveTo_S2C();

            msg.id   = id;
            msg.spd  = GetAttribute(Attribute.Spd);
            msg.posx = destination.x;
            msg.posy = destination.y;
            m_game.Broadcast(msg);
        }
Esempio n. 2
0
    public void ProcessMsg(ushort _type)
    {
        MsgType type = (MsgType)_type;

        switch (type)
        {
        case MsgType.Login:
        {
            SceneManager.LoadSceneAsync("Lobby");
            m_state = State.Login;
        }
        break;

        case MsgType.Matching:
        {
            m_state = State.Matching;
        }
        break;

        case MsgType.CancelMatching:
        {
            m_state = State.Login;
        }
        break;

        case MsgType.NewGame:
        {
            Debug.Log("NewGame");
            m_state = State.InGame;

            Game.Configs configs = new Game.Configs();

            configs.map = NetSession.In.ReadInt32();
            int playerCount = NetSession.In.ReadInt32();
            for (int i = 0; i < playerCount; i++)
            {
                string name = System.Text.Encoding.Default.GetString(NetSession.In.ReadBytes(16));
                name = name.Substring(0, name.IndexOf(char.MinValue));
                int id = NetSession.In.ReadInt32();
                Game.Configs.Player player = new Game.Configs.Player();
                player.id = id;
                configs.players.Add(player);
                Debug.LogFormat("Player {0}({1}) incoming", name, id);
            }

            Core.NewGame(configs);
        }
        break;

        case MsgType.StartLoad:
        {
            Core.StartLoad();
        }
        break;

        case MsgType.EndGame:
        {
            Debug.Log("EndGame");
        }
        break;

        case MsgType.AddUnit:
        {
            MsgAddUnit_S2C msg = NetSession.In.Read <MsgAddUnit_S2C>();
            Core.Game.AddUnit(msg);
        }
        break;

        case MsgType.AddBullet:
        {
            MsgAddBullet_S2C msg = NetSession.In.Read <MsgAddBullet_S2C>();
            Core.Game.AddBullet(msg);
        }
        break;

        case MsgType.MoveTo:
        {
            MsgMoveTo_S2C msg  = NetSession.In.Read <MsgMoveTo_S2C>();
            Unit          unit = Core.Game.FindUnit(msg.id);
            if (unit)
            {
                unit.MoveTo(msg.posx, msg.posy, msg.spd * 0.01f);
            }
        }
        break;

        case MsgType.DoAction:
        {
            MsgDoAction_S2C msg  = NetSession.In.Read <MsgDoAction_S2C>();
            Unit            unit = Core.Game.FindUnit(msg.id);
            if (unit)
            {
                unit.DoAction(msg.posx, msg.posy, msg.duration, msg.action, msg.effect, msg.dir);
            }
        }
        break;

        default:
        {
            Debug.LogFormat("error msg type {0}.", type.ToString());
        }
        break;
        }
    }