• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang command.Command类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中code/wolfmud/org/WolfMUD/git/utils/command.Command的典型用法代码示例。如果您正苦于以下问题:Golang Command类的具体用法?Golang Command怎么用?Golang Command使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Command类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: dropInventory

// dropInventory drops everything the player is carrying.
func (p *Player) dropInventory(cmd *command.Command) {
	for _, o := range p.Inventory.List() {
		if c, ok := o.(command.Interface); ok {
			if aliases := o.Aliases(); len(aliases) > 0 {
				cmd.New("DROP " + o.Aliases()[0])
				c.Process(cmd)
			}
		}
	}
}
开发者ID:iaingmackay,项目名称:simplemud,代码行数:11,代码来源:player.go


示例2: cpustart

// cpustart implement the 'CPUSTART' command and starts CPU profiling.
//
// TODO: Remove - for debugging only
func (p *Player) cpustart(cmd *command.Command) (handled bool) {
	f, err := os.Create("cpuprof")
	if err != nil {
		cmd.Respond("CPU Profile Not Started: %s", err)
		return false
	}
	pprof.StartCPUProfile(f)

	cmd.Respond("CPU profile started")
	return true
}
开发者ID:iaingmackay,项目名称:simplemud,代码行数:14,代码来源:player.go


示例3: memprof

// memprof implements the 'MEMPROF' command and writes out a memprofile.
//
// NOTE: Need to change the value of MemProfileRate in server.go
// TODO: Remove - for debugging only
func (p *Player) memprof(cmd *command.Command) (handled bool) {
	f, err := os.Create("memprof")
	if err != nil {
		cmd.Respond("Memory Profile Not Dumped: %s", err)
		return false
	}
	pprof.WriteHeapProfile(f)
	f.Close()

	cmd.Respond("Memory profile dumped")
	return true
}
开发者ID:iaingmackay,项目名称:simplemud,代码行数:16,代码来源:player.go


示例4: get

// get removes an Item from the command issuer's current location and puts it
// into it's own inventory. For this to happen a few conditions must be true:
//
//	1. Issuer must be at some sort of location
//	2. Issuer must implement an inventory
//	3. Issuer's location must contain the requested item
//
func (i *Item) get(cmd *command.Command) (handled bool) {
	if m, ok := cmd.Issuer.(location.Locateable); ok {
		if inv, ok := cmd.Issuer.(inventory.Interface); ok {
			if l := m.Locate(); l.Contains(i) {
				l.Remove(i)
				cmd.Broadcast([]thing.Interface{cmd.Issuer}, "You see %s pick up %s.", cmd.Issuer.Name(), i.Name())

				inv.Add(i)
				cmd.Respond("You pickup %s.", i.Name())

				handled = true
			}
		}
	}
	return
}
开发者ID:iaingmackay,项目名称:simplemud,代码行数:23,代码来源:item.go


示例5: quit

// quit implements the 'QUIT' command.
//
// quit extracts a player from the world cleanly. If the player's location is
// not crowded it also announces their departure - in a crowded location their
// departure will go unnoticed.
func (p *Player) quit(cmd *command.Command) (handled bool) {
	log.Printf("%s is quiting", p.Name())
	p.quitting = true
	p.dropInventory(cmd)

	l := p.Locate()

	if !l.Crowded() {
		cmd.Broadcast([]thing.Interface{p}, "%s gives a strangled cry of 'Bye Bye', and then slowly fades away and is gone.", p.Name())
	}

	cmd.Flush()

	l.Remove(p)
	PlayerList.Remove(p)

	return true
}
开发者ID:iaingmackay,项目名称:simplemud,代码行数:23,代码来源:player.go


示例6: inv

// inv implements the 'INVENTORY' command. This provides information about what
// a mobile is currently carrying. Currently a mobile can only examine it's own
// inventory - but someone like a theif might find it handy to look into someone
// elses inventory ;)
//
// TODO: Currently very basic, needs to deal with held, weilded, worn items.
func (m *Mobile) inv(cmd *command.Command) (handled bool) {

	if cmd.Target != "" {
		return
	}

	response := ""

	if inventory := m.Inventory.List(); len(inventory) == 0 {
		response = "You are not carrying anything."
	} else {
		response = "You are currently carrying:\n"
		for _, item := range inventory {
			response += "\t" + item.Name() + "\n"
		}
	}
	cmd.Respond(response)

	return true
}
开发者ID:iaingmackay,项目名称:simplemud,代码行数:26,代码来源:mobile.go


示例7: look

// look implements the 'LOOK' command. It describes the location displaying the
// title, description, things and directional exits.
//
// TODO: Implement brief mode.
//
// TODO: Implement looking in a specific direction with a maximum viewing
// distance.
func (b *Basic) look(cmd *command.Command) (handled bool) {

	things := ""

	if b.Crowded() {
		things = "[GREEN]You can see a crowd here.\n"
	} else {
		list := b.List(cmd.Issuer)
		thingsHere := make([]string, 0, len(list))
		for _, o := range list {
			thingsHere = append(thingsHere, "You can see "+o.Name()+" here.")
		}
		if len(thingsHere) > 0 {
			things = "[GREEN]" + strings.Join(thingsHere, "\n") + "\n"
		}
	}

	cmd.Respond("[CYAN]%s\n[WHITE]%s\n%s\n%s", b.Name(), b.Description(), things, b.directionalExits)

	return true
}
开发者ID:iaingmackay,项目名称:simplemud,代码行数:28,代码来源:basic.go


示例8: move

// move implements the directional movement commands. This allows movement from
// location to location by typing a direction such as N or North.
//
// TODO: Modify command so that it can handle buffering of multiple location
// broadcasts.
func (b *Basic) move(cmd *command.Command, d direction) (handled bool) {
	if to := b.directionalExits[d]; to != nil {
		if !cmd.CanLock(to) {
			cmd.AddLock(to)
			return true
		}

		b.Remove(cmd.Issuer)

		// If the location is crowded you are not going to notice someone leaving
		if !b.Crowded() {
			b.Broadcast([]thing.Interface{cmd.Issuer}, "[YELLOW]You see %s go %s.", cmd.Issuer.Name(), directionLongNames[d])
		}

		to.Add(cmd.Issuer)

		// If the location is crowded you are not going to notice someone entering
		if !to.Crowded() {
			to.Broadcast([]thing.Interface{cmd.Issuer}, "[YELLOW]You see %s walk in.", cmd.Issuer.Name())
		}

		to.look(cmd)
	} else {
		cmd.Respond("[RED]You can't go %s from here!", directionLongNames[d])
	}
	return true
}
开发者ID:iaingmackay,项目名称:simplemud,代码行数:32,代码来源:basic.go


示例9: who

// who implements the 'WHO' command. This lists all the players currently on
// the server.
func (l *playerList) who(cmd *command.Command) (handled bool) {

	b := new(bytes.Buffer)

	if l.Length() < 2 {
		b.WriteString("You are all alone in this world.")
	} else {

		cmd.Broadcast([]thing.Interface{cmd.Issuer}, "You see %s concentrate.", cmd.Issuer.Name())

		for _, p := range PlayerList.nonLockingList(cmd.Issuer) {
			b.WriteString("  ")
			b.WriteString(p.Name())
			b.WriteString("\n")
		}
		b.WriteString("\nTOTAL PLAYERS: ")
		b.WriteString(strconv.Itoa(l.Length()))

	}
	cmd.Respond(b.String())

	return true
}
开发者ID:iaingmackay,项目名称:simplemud,代码行数:25,代码来源:playerList.go


示例10: say

// say implements the 'SAY' command, alias "'". Say sends a message to all
// other responders at the current location.
func (p *Player) say(cmd *command.Command) (handled bool) {

	if len(cmd.Nouns) == 0 {
		cmd.Respond("[RED]Was there anything in particular you wanted to say?")
	} else {
		message := strings.Join(cmd.Input[1:], ` `)

		cmd.Broadcast([]thing.Interface{cmd.Issuer}, "[CYAN]%s says: %s", cmd.Issuer.Name(), message)
		cmd.Respond("[YELLOW]You say: %s", message)
	}

	return true
}
开发者ID:iaingmackay,项目名称:simplemud,代码行数:15,代码来源:player.go


示例11: drop

// drop removes an Item from the command issuer's inventory and puts it into
// the inventory of the issuer's current location. For this to happen a few
// conditions must be true:
//
//	1. Issuer must be at some sort of location
//	2. Issuer must implement an inventory
//	3. Inventory must contain the requested item
//
func (i *Item) drop(cmd *command.Command) (handled bool) {
	if m, ok := cmd.Issuer.(location.Locateable); ok {
		if inv, ok := cmd.Issuer.(inventory.Interface); ok {
			if inv.Contains(i) {
				inv.Remove(i)
				cmd.Respond("You drop %s.", i.Name())
				cmd.Broadcast([]thing.Interface{cmd.Issuer}, "You see %s drop %s.", cmd.Issuer.Name(), i.Name())

				m.Locate().Add(i)

				handled = true
			}
		}
	} else {
		cmd.Respond("You don't see anywhere to drop %s.", i.Name())
		cmd.Broadcast([]thing.Interface{cmd.Issuer}, "You see %s try and drop %s.", cmd.Issuer.Name(), i.Name())
		handled = true
	}
	return
}
开发者ID:iaingmackay,项目名称:simplemud,代码行数:28,代码来源:item.go


示例12: parseStage2

// parseStage2 is called by Parse to take advantage of defer unwinding. By
// splitting the parsing we can easily obtain the locks we want and defer the
// unlocking. This makes both Parse and parseStage2 very simple.
func (p *Player) parseStage2(cmd *command.Command) (retry bool) {
	for _, l := range cmd.Locks {
		l.Lock()
		defer l.Unlock()
	}

	// If player moved before we locked we need to retry
	if !cmd.CanLock(p.Locate()) {
		return true
	}

	handled := p.Process(cmd)
	retry = cmd.LocksModified()

	if !handled && !retry {
		cmd.Respond("[RED]Eh?")
	}

	if !retry {
		cmd.Flush()
	}

	return
}
开发者ID:iaingmackay,项目名称:simplemud,代码行数:27,代码来源:player.go


示例13: weigh

// weigh estimates the weight of the specified item.
func (i *Item) weigh(cmd *command.Command) (handled bool) {
	cmd.Respond("You estimate %s to weigh about %s.", i.Name(), i.weight)
	cmd.Broadcast([]thing.Interface{cmd.Issuer}, "You see %s estimate the weight of %s.", cmd.Issuer.Name(), i.Name())
	return true
}
开发者ID:iaingmackay,项目名称:simplemud,代码行数:6,代码来源:item.go


示例14: junk

// TODO: Implement junk command
func (i *Item) junk(cmd *command.Command) (handled bool) {
	cmd.Respond("Junk not implemented yet.")
	return true
}
开发者ID:iaingmackay,项目名称:simplemud,代码行数:5,代码来源:item.go


示例15: exits

// exits implements the 'EXITS' command. It displays the currently available
// directional exits from the location.
func (b *Basic) exits(cmd *command.Command) (handled bool) {
	cmd.Respond("%s", b.directionalExits)
	return true
}
开发者ID:iaingmackay,项目名称:simplemud,代码行数:6,代码来源:basic.go


示例16: sneeze

// sneeze implements the 'SNEEZE' command.
//
// TODO: Remove - for debugging responders and broadcasters
func (p *Player) sneeze(cmd *command.Command) (handled bool) {
	cmd.Respond("You sneeze. Aaahhhccchhhooo!")
	cmd.Broadcast([]thing.Interface{p}, "You see %s sneeze.", cmd.Issuer.Name())
	PlayerList.Broadcast(p.Locate().List(), "You hear a loud sneeze.")
	return true
}
开发者ID:iaingmackay,项目名称:simplemud,代码行数:9,代码来源:player.go


示例17: examine

// examine describes the specific item.
func (i *Item) examine(cmd *command.Command) (handled bool) {
	cmd.Respond("You examine %s. %s", i.Name(), i.Description())
	cmd.Broadcast([]thing.Interface{cmd.Issuer}, "You see %s study %s.", cmd.Issuer.Name(), i.Name())
	return true
}
开发者ID:iaingmackay,项目名称:simplemud,代码行数:6,代码来源:item.go


示例18: cpustop

// cpustop implements the 'CPUSTOP' command, stops CPU profiling and writes the
// profile to cpuprofile in the bin directory.
//
// TODO: Remove - for debugging only
func (p *Player) cpustop(cmd *command.Command) (handled bool) {
	pprof.StopCPUProfile()
	cmd.Respond("CPU profile stopped")
	return true
}
开发者ID:iaingmackay,项目名称:simplemud,代码行数:9,代码来源:player.go



注:本文中的code/wolfmud/org/WolfMUD/git/utils/command.Command类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang ProblemReader.ProblemReader类代码示例发布时间:2022-05-24
下一篇:
Golang proto.ColumnEncoding类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap