Exemple #1
0
func ItemWeight(item types.Item) int {
	template := GetTemplate(item.GetTemplateId())
	weight := template.GetWeight()
	items := ItemsIn(item.GetId())
	for _, item := range items {
		weight += ItemWeight(item)
	}

	return weight
}
Exemple #2
0
	},
	"buy": {
		exec: func(s *Session, arg string) {
			store := model.StoreIn(s.pc.GetRoomId())
			if store == nil {
				s.printError("There is no store here")
				return
			}

			if arg == "" {
				s.printError("Usage: buy <item name>")
			}

			items := model.ItemsIn(store.GetId())
			index, err := strconv.Atoi(arg)
			var item types.Item

			if err == nil {
				index--
				if index < len(items) && index >= 0 {
					item = items[index]
				} else {
					s.printError("Invalid selection")
				}
			} else {
				index := utils.BestMatch(arg, items.Names())

				if index == -1 {
					s.printError("Not found")
				} else if index == -2 {
					s.printError("Which one do you mean?")