Exemple #1
0
func (c *Creature) Use(i item.Itemer) {
	if !item.IsUsable(i) {
		status.Println("You can't use that item!", termbox.ColorRed+termbox.AttrBold)
		return
	}
	if !item.IsPermanent(i) {
		if i.Count() > 1 {
			i.SetCount(i.Count() - 1)
		} else {
			delete(c.Inventory, i.Hotkey())
		}
	}
	c.use(i)
}
Exemple #2
0
func ShowItemDetails(i item.Itemer, a *area.Area) bool {
	ui.Clear()

	// Print item title.
	msgs := makeDrawable(fmt.Sprintf("%c - %s", i.Hotkey(), i.Name()))
	PrintLong(msgs, 0)
	rows := len(msgs)

	// Print flavor text.
	msgs = makeDrawable(i.FlavorText())
	PrintLong(msgs, rows)
	rows += len(msgs)

	// Print flavor text.
	msgs = makeDrawable(StringEffects(i.Effects()))
	PrintLong(msgs, rows)
	rows += len(msgs)

	actionStr := dropAction
	if item.IsEquipable(i) && !creature.Hero.IsEquipped(i) {
		actionStr += " You can (e)quip this " + strings.ToLower(i.Cat()) + "."
	}
	if creature.Hero.IsEquipped(i) {
		actionStr += " You can (r)emove this " + strings.ToLower(i.Cat()) + "."
	}
	if item.IsUsable(i) {
		actionStr += " You can (u)se this " + strings.ToLower(i.Cat()) + "."
	}

	msgs = makeDrawable(actionStr)
	for y, m := range msgs {
		t := text.New(m, termbox.ColorCyan)
		ui.Print(t, ui.Inventory.XOffset, y+rows, ui.Inventory.Width)
	}

	termbox.Flush()

itemDetailLoop:
	for {
		switch detailsEvent := termbox.PollEvent(); detailsEvent.Type {
		case termbox.EventKey:
			if detailsEvent.Key == ui.CancelKey {
				break itemDetailLoop
			}

			switch string(detailsEvent.Ch) {
			case string(ui.DropItemKey):
				creature.Hero.DropItem(i.Hotkey(), a)
				return true
			case string(ui.EquipItemKey):
				NarrativeEquip(i.Hotkey())
				return true
			case string(ui.UseItemKey):
				NarrativeUse(i.Hotkey())
				return true
			case string(ui.UnEquipItemKey):
				NarrativeUnEquip(i.Hotkey())
				return true
			}
		}
	}
	return false
}