Example #1
0
func (h *Hero) GiveItem(item world.Visible) bool {
	if i, ok := item.(world.Item); !ok || i.AdminOnly() {
		if a, ok := h.Outer().(world.AdminLike); !ok || !a.IsAdmin() {
			if m, ok := h.Outer().(world.SendMessageLike); ok {
				m.SendMessage("the " + item.Name() + " deems you unworthy and decides to stay where it is.")
			}
			return false
		}
	}

	h.mtx.Lock()
	if h.Outer().(HeroLike).canHoldItem(item) {
		h.giveItem(item)
	}
	h.mtx.Unlock()

	return true
}
Example #2
0
func addSprites(u *packetUpdateObject, obj world.Visible) *packetUpdateObject {
	sheet := obj.Sprite()
	x, y := obj.SpritePos()
	width, height := obj.SpriteSize()
	scale := obj.Scale()
	animation := obj.AnimationType()
	for i, c := range obj.Colors() {
		if c == "" {
			continue
		}
		u.Sprites = append(u.Sprites, packetUpdateSprite{
			Sheet: sheet,
			Color: c,
			Extra: map[string]interface{}{
				"w": width,
				"h": height,
				"x": x,
				"y": y + uint(i),
				"s": scale,
				"a": animation,
			},
		})
	}
	for _, a := range obj.Attached() {
		addSprites(u, a)
	}
	return u
}