Exemple #1
0
func NewGame(config *gutil.LuaConfig) *Game {
	g := Game{config: config}
	g.Objects = game.NewGameObjectMap()

	g.CloseChan = make(chan bool, 1)

	g.player = game.NewGameObject("")

	g.mainpanel = panel.MainScreen()
	g.panels = make(map[string]panel.Panel)

	g.panels["stats"] = NewStatsPanel()
	g.panels["view"] = NewViewPanel(&g)
	g.panels["log"] = NewLogPanel()
	g.panels["player"] = NewPlayerPanel(&g)
	g.panels["chat"] = NewChatPanel(&g, &g.Terminal)

	g.logpanel = g.panels["log"].(*LogPanel)
	g.chatpanel = g.panels["chat"].(*ChatPanel)

	//g.chatbox = NewChatBuffer(&g, &g.Terminal)

	//g.Objects = append(g.Objects, g.Player.GameObject)

	return &g
}
Exemple #2
0
// make a new GameObject
func LuaNewGameObject(name string) game.Object {
	return game.NewGameObject(name)
}
Exemple #3
0
func (gs *GameServer) HandlePacket(cp *ClientPacket) {

	switch cp.Tag {

	// Tchat: chat message from a client
	case "Tchat":
		// broadcast chat
		chatline := cp.Data.(string)
		gs.SendPacketAll(gnet.NewPacket("Rchat", fmt.Sprintf("[chat] %s: %s", cp.Client.Username, chatline)))

		// Taction: movement request
	case "Taction":
		gs.HandleActionPacket(cp)

		// Tconnect: user establishes new connection
	case "Tconnect":
		username, ok := cp.Data.(string)

		if !ok {
			cp.Reply(gnet.NewPacket("Rerror", "invalid username or conversion failed"))
			break
		} else {
			cp.Client.Username = username
		}

		// make new player for client
		var newplayer game.Object
		newplayer = game.NewGameObject(username)
		newplayer.SetTag("player", true)
		newplayer.SetTag("visible", true)

		// setting this lets players pick up other players, lol
		//newplayer.SetTag("gettable", true)
		newplayer.SetGlyph(game.GLYPH_HUMAN)
		newplayer.SetPos(256/2, 256/2)

		// set the session's object
		cp.Client.Player = newplayer

		// put player object in world
		gs.Objects.Add(newplayer)

		// tell client about all other objects
		for o := range gs.Objects.Chan() {
			if o.GetID() != newplayer.GetID() {
				cp.Reply(gnet.NewPacket("Rnewobject", o))
			}
		}

		// tell all clients about the new player
		gs.SendPacketAll(gnet.NewPacket("Rnewobject", newplayer))

		// greet our new player
		cp.Reply(gnet.NewPacket("Rchat", "Welcome to Goland!"))

	case "Tdisconnect":
		// notify clients this player went away
		Action_ItemDrop(gs, cp)
		gs.Objects.RemoveObject(cp.Client.Player)
		gs.Detach(cp.Client)
		gs.SendPacketAll(gnet.NewPacket("Rdelobject", cp.Client.Player))

	case "Tgetplayer":
		if cp.Client.Player != nil {
			cp.Reply(gnet.NewPacket("Rgetplayer", cp.Client.Player.GetID()))
		} else {
			cp.Reply(gnet.NewPacket("Rerror", "nil Player in WorldSession"))
		}

	case "Tloadmap":
		cp.Reply(gnet.NewPacket("Rloadmap", gs.Map))

	default:
		log.Printf("GameServer: HandlePacket: unknown packet type %s", cp.Tag)
	}
}