示例#1
0
文件: pioneer.go 项目: onewland/gomud
func Pioneer(p *mud.Player, args []string) {
	direction := args[0]

	mud.Log("Pioneer", args)

	p.Room().WithExit(direction, func(rei *mud.RoomExitInfo) {
		p.WriteString("That exit already exists.\n")
		return
	}, func() {
		BuildPioneerRoom(p, direction)
	})
}
示例#2
0
文件: fruit.go 项目: onewland/gomud
func BecomePlant(atl AgingTimeListener) {
	f := atl.(*Fruit)

	if f.Room() != nil {
		mud.Log("Age MakePlant clause, room =", f.Room())
		p := MakePlant(f.universe, f.name)
		f.Room().AddChild(p)
		p.SetRoom(f.Room())

		p.Room().Actions() <- mud.VanishAction{Target: f}
	}
}
示例#3
0
文件: plant.go 项目: onewland/gomud
func BecomeTree(atl AgingTimeListener) {
	p := atl.(*Plant)

	if p.Room() != nil {
		mud.Log("Age MakeTree clause, room =", p.Room())
		if TreeCount(p.Room()) < 3 {
			t := MakeFruitTree(p.universe, p.name)
			p.Room().AddChild(t)
		} else {
			p.Room().Actions() <- mud.VanishAction{Target: p}
		}
	}
}
示例#4
0
文件: seed.go 项目: onewland/gomud
func LoadUniverse(universe *mud.Universe) *mud.Room {
	roomIds := universe.Store.GlobalSetGet("rooms")
	roomConnIds := universe.Store.GlobalSetGet("roomConnects")
	for _, roomId := range roomIds {
		if idNo, err := strconv.Atoi(roomId); err == nil {
			// Note that load room also loads any children
			// persisters
			mud.LoadRoom(universe, idNo)
		} else {
			mud.Log("[warn] strange roomId", roomId)
		}
	}

	for _, roomIdConn := range roomConnIds {
		if idNo, err := strconv.Atoi(roomIdConn); err == nil {
			mud.LoadRoomConn(universe, idNo)
		} else {
			mud.Log("[warn] strange roomConnId", roomIdConn)
		}
	}
	return universe.Rooms[1]
}
示例#5
0
func ffHandleSay(s mud.Stimulus, n *simple.NPC) {
	scast, ok := s.(mud.TalkerSayStimulus)
	if !ok {
		panic("FF should only receive TalkerSayStimulus")
	} else {
		args := strings.SplitN(scast.Text(), " ", 3)
		mud.Log("FF args:", args)
		if args[0] == "bling" {
			switch args[1] {
			case "set":
				n.Meta["lastText"] = args[2]
				n.SetDescription(n.Meta["lastText"].(string))
			}
		}
	}
}
示例#6
0
文件: npc.go 项目: onewland/gomud
func (n *NPC) AddStimHandler(stimName string, handler SimpleStimulusHandler) {
	mud.Log("AddStimHandler", stimName, handler)
	n.supportedStimuli[stimName] = handler
}
示例#7
0
文件: tree.go 项目: onewland/gomud
func (f *FruitTree) Bloom() {
	mud.Log("Bloom in room", f.room)
	newFruit := MakeFruit(f.universe, f.fruitName)
	f.room.Broadcast(TreeFlowerStimulus{ft: f})
	f.room.AddChild(newFruit)
}
示例#8
0
文件: mud.go 项目: onewland/gomud
func main() {
	flagPort := flag.Int("port", 3000,
		"port to listen for mud clients")
	flagUseSeed := flag.Bool("seed", false,
		"flush DB and seed universe with prototype's seed.go")
	flagUseLoad := flag.Bool("load", true,
		"load objects from DB")
	flagSpeedupFactor := flag.Float64("speedup", 1.0,
		"factor to speed up heartbeat loop (2.0 means heartbeats come twice as often)")
	flagRedisDbNo := flag.Int("dbno", 3,
		"redis DB# to load from/seed into")
	flag.Usage = func() {
		flag.PrintDefaults()
	}
	flag.Parse()
	mud.Log("program args: ", os.Args)

	rand.Seed(time.Now().Unix())
	listener, err := net.Listen("tcp", fmt.Sprintf(":%d", *flagPort))
	universe := mud.NewUniverse(*flagRedisDbNo)
	universe.Maker = BuildFFInRoom
	playerRemoveChan := make(chan *mud.Player)

	var theRoom *mud.Room
	if *flagUseSeed {
		mud.Log("Seeding Universe")
		universe.ClearDB()
		theRoom = InitUniverse(universe)
	} else if *flagUseLoad {
		mud.Log("Loading Universe")
		theRoom = LoadUniverse(universe)
		mud.Log("theRoom", theRoom)
	}

	mud.Log("len(rooms) =", len(universe.Rooms))

	go universe.HandlePersist()
	go universe.HeartbeatLoop(*flagSpeedupFactor)

	if err == nil {
		go mud.PlayerListManager(playerRemoveChan, universe.Players)
		defer listener.Close()

		mud.Log("Listening on port", *flagPort)
		for {
			conn, aerr := listener.Accept()
			if aerr == nil {
				namePrompt := new(NamePrompt)
				namePrompt.universe = universe
				namePrompt.StartRoom = theRoom
				namePrompt.PlayerRemoveChan = playerRemoveChan
				mud.NewUserConnection(conn, namePrompt)
			} else {
				mud.Log("Error in accept")
				mud.Log(aerr)
			}
		}
	} else {
		mud.Log("Error in listen", err)
	}
}