Exemplo n.º 1
0
// findStack takes an item and tries to find a stack of that item in the
// inventory. If a stack exists it returns the item slot letter and true,
// otherwise it returns empty rune and false.
func (c *Creature) findStack(i item.DrawItemer) (hotkey rune, ok bool) {
	if !item.IsStackable(i) {
		return 0x00, false
	}
	for _, v := range c.Inventory {
		if v.Name() == i.Name() {
			return v.Hotkey(), true
		}
	}
	return 0x00, false
}
Exemplo n.º 2
0
func InvText(i item.Itemer) string {
	invStr := ""
	if item.IsStackable(i) {
		name := i.Name()
		if i.Count() > 1 {
			name = inflections.Pluralize(name)
		}
		invStr = fmt.Sprintf("%c - %d %s", i.Hotkey(), i.Count(), name)
	} else {
		invStr = fmt.Sprintf("%c - %s", i.Hotkey(), i.Name())
	}

	if item.IsEquipable(i) {
		if creature.Hero.IsEquipped(i) {
			invStr += " (wielding)"
		}
	}
	return invStr
}
Exemplo n.º 3
0
func NarrativeEquip(pos rune) {
	i := creature.Hero.Equip(pos)
	if i == nil {
		status.Println(unableToEquip, termbox.ColorRed+termbox.AttrBold)
		return
	}

	var equipStr string
	if item.IsStackable(i) {
		equipStr += fmt.Sprintf("%d ", i.Count())
		if i.Count() > 1 {
			inflections.Pluralize(i.Name())
		} else {
			equipStr += i.Name()
		}
	} else {
		equipStr += i.Name()
	}
	status.Println(fmt.Sprintf("You equipped %s.", equipStr), termbox.ColorWhite)
}
Exemplo n.º 4
0
func (c *Creature) DropItem(pos rune, a *area.Area) {
	i := c.Inventory[pos]
	c.UnEquip(i)
	delete(c.Inventory, pos)

	cor := c.Coord()
	if a.Items[cor] == nil {
		a.Items[cor] = new(area.Stack)
	}
	a.Items[cor].Push(i)

	// If the item couldn't be dropped (cursed for example), print unable to
	// drop message.
	if i == nil {
		status.Println(UnableToDrop, termbox.ColorRed+termbox.AttrBold)
		return
	}

	fmtStr := "%s dropped %s."
	cName := strings.Title(c.Name())
	if c.IsHero() {
		cName = "You"
	}
	iName := i.Name()
	if item.IsStackable(i) {
		name := i.Name()
		if i.Count() > 1 {
			name = inflections.Pluralize(name)
		}
		iName = strconv.Itoa(i.Count()) + " " + name
	}

	if c.dist() <= Hero.Sight {
		status.Println(fmt.Sprintf(fmtStr, cName, iName), termbox.ColorWhite)
	}
}