Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file modified _datafiles/html/static/public/audio/sound/combat/explosion2.mp3
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
itemid: 20045
value: 100
name: rat-skin cape
namesimple: cape
description: A patchwork cape made up of many rat hides.
type: neck
subtype: wearable
damagereduction: 5
wornbuffids:
- 3 # Cold Tolerant
1 change: 1 addition & 0 deletions _datafiles/world/default/keywords.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ help:
- build
- command
- deafen
- item
- grant
- locate
- modify
Expand Down
3 changes: 3 additions & 0 deletions _datafiles/world/default/rooms/frostfang/611.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ description: As you step into this residence, a sense of artistic flair is immed
the owner's artistic inclinations. This home feels like a personal retreat, a place
for creativity and relaxation amidst the harshness of Frostfang.
biome: house
containers:
tattertail loom:
recipes: {20045: [20001, 20001, 20001, 20001, 20001, 20001, 20001, 20001, 20001]}
exits:
north:
roomid: 260
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{{- $displayed := 0 -}}
{{- $itemCt := len . -}}
<ansi fg="white">Inside you see: </ansi>
<ansi fg="white"> ┌─────────────────────────────────────────────────────────────────────────┐</ansi>

<ansi fg="white">Inside you see: </ansi>
{{- if ne $itemCt 0 -}}
{{- range $index, $itemName := . -}}
{{- $displayed = add $displayed 1 -}}
Expand All @@ -9,3 +11,4 @@
{{ else -}}
Nothing
{{ end }}
<ansi fg="white"> └─────────────────────────────────────────────────────────────────────────┘</ansi>
1 change: 1 addition & 0 deletions _datafiles/world/empty/keywords.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ help:
- build
- command
- deafen
- item
- grant
- locate
- modify
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{{- $displayed := 0 -}}
{{- $itemCt := len . -}}
<ansi fg="white"> ┌─────────────────────────────────────────────────────────────────────────┐</ansi>

<ansi fg="white">Inside you see: </ansi>
{{- if ne $itemCt 0 -}}
{{- range $index, $itemName := . -}}
Expand All @@ -9,3 +11,4 @@
{{ else -}}
Nothing
{{ end }}
<ansi fg="white"> └─────────────────────────────────────────────────────────────────────────┘</ansi>
58 changes: 58 additions & 0 deletions internal/rooms/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Container struct {
Items []items.Item `yaml:"items,omitempty"` // Save contents now, since players can put new items in there
Gold int `yaml:"gold,omitempty"` // Save contents now, since players can put new items in there
DespawnRound uint64 `yaml:"despawnround,omitempty"` // If this is set, it's a chest that will disappear with time.
Recipes map[int][]int `yaml:"recipes,omitempty,flow"` // Item Id's (key) that are created when the recipe is present in the container (values) and it is "used"
}

func (c Container) HasLock() bool {
Expand Down Expand Up @@ -44,3 +45,60 @@ func (c *Container) FindItem(itemName string) (items.Item, bool) {

return items.Item{}, false
}

func (c *Container) FindItemById(itemId int) (items.Item, bool) {

// Search floor
for _, matchItem := range c.Items {
if matchItem.ItemId == itemId {
return matchItem, true
}
}

return items.Item{}, false
}

// Returns an itemId if it can produce one based on contents + recipe
func (c *Container) RecipeReady() int {

if len(c.Recipes) == 0 {
return 0
}

for finalItemId, recipeList := range c.Recipes {

totalNeeded := 0
neededItems := map[int]int{}

for _, inputItemId := range recipeList {
neededItems[inputItemId] += 1
totalNeeded++
}

for _, containsItem := range c.Items {
if neededItems[containsItem.ItemId] > 0 {
neededItems[containsItem.ItemId] -= 1
totalNeeded--
}
if totalNeeded == 0 {
break
}
}

if totalNeeded < 1 {
return finalItemId
}
}

return 0
}

func (c *Container) Count(itemId int) int {
total := 0
for _, containsItem := range c.Items {
if containsItem.ItemId == itemId {
total++
}
}
return total
}
9 changes: 8 additions & 1 deletion internal/usercommands/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ func Get(rest string, user *users.UserRecord, room *rooms.Room) (bool, error) {

scripting.TryItemScriptEvent(`onFound`, matchItem, user.UserId)

return true, nil

} else {
user.SendText(
fmt.Sprintf(`You can't carry the <ansi fg="itemname">%s</ansi>.`, matchItem.DisplayName()),
Expand Down Expand Up @@ -314,7 +316,12 @@ func Get(rest string, user *users.UserRecord, room *rooms.Room) (bool, error) {
return true, nil
}

user.SendText(fmt.Sprintf("You don't see a %s around.", rest))
containerName = room.FindContainerByName(rest)
if containerName != `` {
user.SendText(fmt.Sprintf(`You can't pick up the <ansi fg="container">%s</ansi>. Try looking at it.`, containerName))
} else {
user.SendText(fmt.Sprintf("You don't see a %s around.", rest))
}

return true, nil
}
34 changes: 34 additions & 0 deletions internal/usercommands/look.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/volte6/gomud/internal/buffs"
"github.com/volte6/gomud/internal/gametime"
"github.com/volte6/gomud/internal/items"
"github.com/volte6/gomud/internal/keywords"
"github.com/volte6/gomud/internal/mobs"
"github.com/volte6/gomud/internal/rooms"
Expand Down Expand Up @@ -165,10 +166,43 @@ func Look(rest string, user *users.UserRecord, room *rooms.Room) (bool, error) {
chestStuff = append(chestStuff, item.DisplayName())
}

if len(container.Recipes) > 0 {

user.SendText(``)
user.SendText(fmt.Sprintf(`You can <ansi fg="command">use</ansi> the <ansi fg="container">%s</ansi> if you put the following objects inside:`, containerName))

for finalItemId, recipeList := range container.Recipes {

neededItems := map[int]int{}

for _, inputItemId := range recipeList {
neededItems[inputItemId] += 1
}

user.SendText(``)

finalItem := items.New(finalItemId)
user.SendText(fmt.Sprintf(` To receive 1 <ansi fg="itemname">%s</ansi>: `, finalItem.DisplayName()))

for inputItemId, qtyNeeded := range neededItems {
tmpItem := items.New(inputItemId)
totalContained := container.Count(inputItemId)
colorClass := "9"
if totalContained == qtyNeeded {
colorClass = "14"
}
user.SendText(fmt.Sprintf(` <ansi fg="%s">[%d/%d]</ansi> <ansi fg="itemname">%s</ansi>`, colorClass, totalContained, qtyNeeded, tmpItem.DisplayName()))
}

}

}

textOut, _ := templates.Process("descriptions/insidecontainer", chestStuff)

user.SendText(``)
user.SendText(textOut)
user.SendText(``)

return true, nil
}
Expand Down
48 changes: 48 additions & 0 deletions internal/usercommands/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,54 @@ import (

func Use(rest string, user *users.UserRecord, room *rooms.Room) (bool, error) {

containerName := room.FindContainerByName(rest)
if containerName != `` {

container := room.Containers[containerName]

if len(container.Recipes) > 0 {

if container.Lock.IsLocked() {
user.SendText(``)
user.SendText(fmt.Sprintf(`The <ansi fg="container">%s</ansi> is locked.`, containerName))
user.SendText(``)
return true, nil
}

recipeReadyItemId := container.RecipeReady()

if recipeReadyItemId == 0 {
user.SendText("")
user.SendText(fmt.Sprintf(`The <ansi fg="container">%s</ansi> seems to be missing something.`, containerName))
user.SendText("")
return true, nil
}

for _, removeItem := range container.Recipes[recipeReadyItemId] {
if matchItem, found := container.FindItemById(removeItem); found {
container.RemoveItem(matchItem)
}
}

newItem := items.New(recipeReadyItemId)

container.AddItem(newItem)
room.Containers[containerName] = container

room.PlaySound(`sound/other/change.mp3`, `other`)

user.SendText(``)
user.SendText(fmt.Sprintf(`The <ansi fg="container">%s</ansi> produces a <ansi fg="itemname">%s</ansi>!`, containerName, newItem.DisplayName()))
user.SendText(``)

room.SendText(fmt.Sprintf(`<ansi fg="username">%s</ansi> does something with the <ansi fg="container">%s</ansi>.`, user.Character.Name, containerName), user.UserId)

return true, nil

}

}

// Check whether the user has an item in their inventory that matches
matchItem, found := user.Character.FindInBackpack(rest)

Expand Down
Loading