public Bullet AddBullet(int config_id, Position position, int target) { BulletConfig config = database.GetBulletConfig(config_id); if (config == null) { m_context.Log(string.Format("AddBullet({0}) failed", config_id)); return(null); } int id = ++m_increase_id; Bullet bullet = new Bullet(); bullet.Init(this, id, position, target, config.duration); m_bullets.Add(bullet); MsgAddBullet_S2C msg = new MsgAddBullet_S2C(); msg.id = id; msg.posx = position.x; msg.posy = position.y; msg.look = config.look; msg.target = target; msg.duration = config.duration; foreach (var pair in m_players) { pair.Value.Send(msg); } return(bullet); }
internal void AddBullet(MsgAddBullet_S2C config) { GameObject go = new GameObject("bullet_" + config.id.ToString()); go.transform.position = new Vector3(config.posx, 0, config.posy); Bullet bullet = go.AddComponent <Bullet>(); bullet.Init(config.id, config.target, config.duration); bullet.transform.position = new Vector3(config.posx, 1.0f, config.posy); bullet.ChangeModel(config.look); Destroy(bullet.gameObject, config.duration); }
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; } }