aboutsummaryrefslogtreecommitdiff
path: root/internal/game
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game')
-rw-r--r--internal/game/action.go4
-rw-r--r--internal/game/action_burn.go515
-rw-r--r--internal/game/action_gather.go19
-rw-r--r--internal/game/action_use.go4
-rw-r--r--internal/game/cmd_attack.go15
-rw-r--r--internal/game/cmd_get.go4
-rw-r--r--internal/game/cmd_look.go65
-rw-r--r--internal/game/cmd_remove.go10
-rw-r--r--internal/game/cmd_wear.go14
-rw-r--r--internal/game/game.go6
-rw-r--r--internal/game/utils.go13
11 files changed, 644 insertions, 25 deletions
diff --git a/internal/game/action.go b/internal/game/action.go
index 018c4fb..7d2549f 100644
--- a/internal/game/action.go
+++ b/internal/game/action.go
@@ -190,6 +190,10 @@ func (g *Game) AdvanceActions() {
g.advanceGather(sess, p)
case "use":
g.advanceUse(sess, p)
+ case "burn":
+ g.advanceBurn(sess, p)
+ case "stoke":
+ g.advanceStoke(sess, p)
}
}
}
diff --git a/internal/game/action_burn.go b/internal/game/action_burn.go
new file mode 100644
index 0000000..d57307a
--- /dev/null
+++ b/internal/game/action_burn.go
@@ -0,0 +1,515 @@
+package game
+
+import (
+ "fmt"
+ "math/rand"
+
+ "thirdcollapse/internal/action"
+ "thirdcollapse/internal/net"
+ "thirdcollapse/internal/object"
+ "thirdcollapse/internal/player"
+)
+
+func (g *Game) doBurn(sess *net.Session, p *player.Player, input string) {
+ if p.Action != nil {
+ g.CancelAction(p)
+ }
+
+ itemID, fromGround, ambiguous := g.resolveBurnTarget(p, input)
+ if ambiguous {
+ sess.WriteLine("Burn what?")
+ return
+ }
+ if itemID == "" {
+ sess.WriteLine("Burn what?")
+ return
+ }
+
+ g.startBurn(sess, p, itemID, fromGround)
+}
+
+func (g *Game) doStoke(sess *net.Session, p *player.Player, input string) {
+ if p.Action != nil {
+ g.CancelAction(p)
+ }
+
+ if !g.hasFireObject(p.RoomID) {
+ sess.WriteLine("There's no fire here to stoke.")
+ return
+ }
+
+ itemID, ambiguous := g.resolveStokeTarget(p, input)
+ if ambiguous {
+ sess.WriteLine("Stoke what?")
+ return
+ }
+ if itemID == "" {
+ sess.WriteLine("You have no logs to stoke with!")
+ return
+ }
+
+ g.startStoke(sess, p, itemID)
+}
+
+func (g *Game) startBurn(sess *net.Session, p *player.Player, itemID string, fromGround bool) {
+ if p.FirstFreeSlot() == -1 && !fromGround {
+ sess.WriteLine("Your inventory is too full!")
+ return
+ }
+
+ if g.hasFireObject(p.RoomID) {
+ sess.WriteLine("There is already a fire burning here.")
+ return
+ }
+
+ logDef, err := g.ItemStore.Load(itemID)
+ if err != nil {
+ sess.WriteLine("Something is wrong with that item.")
+ return
+ }
+
+ if logDef.BurnTicks <= 0 {
+ sess.WriteLine(fmt.Sprintf("You can't burn the %s.", logDef.Name))
+ return
+ }
+
+ skillLevel := p.Level(player.Firemaking)
+ if logDef.FireLevel > 0 && skillLevel < logDef.FireLevel {
+ sess.WriteLine(fmt.Sprintf("You need level %d firemaking to burn %s.", logDef.FireLevel, logDef.Name))
+ return
+ }
+
+ toolSpeed, ok := g.findFireTool(sess, p)
+ if !ok {
+ return
+ }
+
+ if !fromGround {
+ if !p.HasItem(itemID) {
+ sess.WriteLine(fmt.Sprintf("You don't have any %s.", logDef.Name))
+ return
+ }
+ } else {
+ ground := g.World.GroundItems(p.RoomID)
+ if ground[itemID] <= 0 {
+ sess.WriteLine(fmt.Sprintf("There are no %s on the ground here.", logDef.Name))
+ return
+ }
+ }
+
+ phase := 1
+ if !fromGround {
+ phase = 0
+ }
+
+ p.Action = &action.Action{
+ Type: "burn",
+ TargetID: itemID,
+ TargetName: logDef.Name,
+ WaitLeft: 0,
+ Data: map[string]any{
+ "item_id": itemID,
+ "tool_speed": toolSpeed,
+ "level": logDef.FireLevel,
+ "xp": logDef.FireXP,
+ "burn_ticks": logDef.BurnTicks,
+ "phase": phase,
+ },
+ }
+}
+
+func (g *Game) startStoke(sess *net.Session, p *player.Player, itemID string) {
+ fireKey := g.findFireObjectKey(p.RoomID)
+ if fireKey == "" {
+ sess.WriteLine("There's no fire here to stoke.")
+ return
+ }
+
+ logDef, err := g.ItemStore.Load(itemID)
+ if err != nil || logDef.BurnTicks <= 0 {
+ sess.WriteLine(fmt.Sprintf("You can't stoke the fire with that."))
+ return
+ }
+
+ if !p.HasItem(itemID) {
+ sess.WriteLine(fmt.Sprintf("You don't have any %s.", logDef.Name))
+ return
+ }
+
+ sess.WriteLine("You begin to tend to the fire.")
+
+ p.Action = &action.Action{
+ Type: "stoke",
+ TargetID: itemID,
+ TargetName: logDef.Name,
+ WaitLeft: 10,
+ Data: map[string]any{
+ "item_id": itemID,
+ "fire_key": fireKey,
+ "burn_ticks": logDef.BurnTicks,
+ "xp": logDef.FireXP,
+ },
+ }
+}
+
+func (g *Game) advanceBurn(sess *net.Session, p *player.Player) {
+ data := p.Action.Data
+ itemID := data["item_id"].(string)
+ toolSpeed := data["tool_speed"].(int)
+ phase := data["phase"].(int)
+
+ logDef, err := g.ItemStore.Load(itemID)
+ if err != nil {
+ g.CancelAction(p)
+ return
+ }
+
+ if phase == 0 {
+ if !p.HasItem(itemID) {
+ sess.WriteLine(fmt.Sprintf("You're out of %s.", logDef.Name))
+ g.CancelAction(p)
+ return
+ }
+ p.RemoveItem(itemID, 1)
+ g.World.AddGroundItem(p.RoomID, itemID, 1)
+ g.AccountStore.SaveCharacter(p)
+
+ sess.WriteLine(fmt.Sprintf("You drop the %s and begin to make a fire...", logDef.Name))
+ g.broadcastDrop(p, logDef.Name)
+
+ data["phase"] = 1
+ p.Action.WaitLeft = toolSpeed
+ return
+ }
+
+ ground := g.World.GroundItems(p.RoomID)
+ if ground[itemID] <= 0 {
+ sess.WriteLine("The thing you were trying to burn is gone.")
+ g.CancelAction(p)
+ return
+ }
+
+ if phase == 1 {
+ sess.WriteLine(fmt.Sprintf("You try burning the %s on the ground...", logDef.Name))
+ data["phase"] = 2
+ p.Action.WaitLeft = toolSpeed
+ return
+ }
+
+ if phase == 2 {
+ skillLevel := p.Level(player.Firemaking)
+ chance := 0.5 + float64(skillLevel-logDef.FireLevel)*0.02
+ if chance > 0.95 {
+ chance = 0.95
+ }
+ if chance < 0.05 {
+ chance = 0.05
+ }
+
+ if rand.Float64() < chance {
+ g.World.RemoveGroundItem(p.RoomID, itemID, 1)
+ g.World.AddObjInstance(p.RoomID, "fire", logDef.BurnTicks)
+
+ xp := logDef.FireXP
+ if xp > 0 {
+ if newLevel := p.AddSkillXP(player.Firemaking, xp); newLevel > 0 {
+ sess.WriteLine(fmt.Sprintf("*** You are now level %d firemaking! ***", newLevel))
+ }
+ }
+
+ g.AccountStore.SaveCharacter(p)
+ g.CancelAction(p)
+
+ msg := fmt.Sprintf("You manage to get a fire going!")
+ if xp > 0 && p.OptionBool("xpdrops") {
+ msg += fmt.Sprintf(" (+%dxp %s)", xp, player.SkillAbbr[player.Firemaking])
+ }
+ sess.WriteLine(msg)
+
+ for _, other := range g.Hub.PlayersInRoom(p.RoomID) {
+ if other != sess {
+ other.WriteLine(fmt.Sprintf("\n%s started a fire!", p.Name))
+ }
+ }
+ return
+ }
+
+ sess.WriteLine("You can't seem to get a fire going.")
+ data["phase"] = 1
+ p.Action.WaitLeft = toolSpeed
+ }
+}
+
+func (g *Game) advanceStoke(sess *net.Session, p *player.Player) {
+ data := p.Action.Data
+ itemID := data["item_id"].(string)
+ fireKey := data["fire_key"].(string)
+ burnTicks := data["burn_ticks"].(int)
+ xp := data["xp"].(int)
+
+ st := g.World.GetObjStateByKey(fireKey)
+ if st == nil || st.Quality <= 0 {
+ sess.WriteLine("The fire went out!")
+ g.CancelAction(p)
+ return
+ }
+
+ logDef, _ := g.ItemStore.Load(itemID)
+ name := itemID
+ if logDef != nil {
+ name = logDef.Name
+ }
+
+ if !p.HasItem(itemID) {
+ sess.WriteLine(fmt.Sprintf("You're out of %s and the fire is roaring.", name))
+ g.CancelAction(p)
+ return
+ }
+
+ p.RemoveItem(itemID, 1)
+ st.Quality += burnTicks / 2
+
+ if xp > 0 {
+ if newLevel := p.AddSkillXP(player.Firemaking, xp); newLevel > 0 {
+ sess.WriteLine(fmt.Sprintf("*** You are now level %d firemaking! ***", newLevel))
+ }
+ }
+
+ g.AccountStore.SaveCharacter(p)
+
+ msg := fmt.Sprintf("You throw %s onto the fire.", name)
+ if xp > 0 && p.OptionBool("xpdrops") {
+ msg += fmt.Sprintf(" (+%dxp %s)", xp, player.SkillAbbr[player.Firemaking])
+ }
+ sess.WriteLine(msg)
+
+ if !p.HasItem(itemID) {
+ sess.WriteLine(fmt.Sprintf("You're out of %s and the fire is roaring.", name))
+ g.CancelAction(p)
+ return
+ }
+
+ p.Action.WaitLeft = 10
+}
+
+func (g *Game) findFireTool(sess *net.Session, p *player.Player) (toolSpeed int, ok bool) {
+ toolSpeed = -1
+ var toolItemID string
+
+ if itemID, equipped := p.Equipment[object.SlotMainHand]; equipped {
+ def, err := g.ItemStore.Load(itemID)
+ if err == nil && def.ToolType == "fire" {
+ toolSpeed = def.ToolSpeed
+ toolItemID = itemID
+ }
+ }
+
+ if toolSpeed < 0 {
+ for _, slot := range p.Inventory {
+ if slot == nil || slot.Quantity <= 0 {
+ continue
+ }
+ def, err := g.ItemStore.Load(slot.ItemID)
+ if err != nil || def.ToolType != "fire" {
+ continue
+ }
+ toolSpeed = def.ToolSpeed
+ toolItemID = slot.ItemID
+ break
+ }
+ }
+
+ if toolSpeed < 0 {
+ sess.WriteLine("You need a fire starter to do that.")
+ return 0, false
+ }
+
+ if !g.consumeFireTool(sess, p, toolItemID) {
+ return 0, false
+ }
+
+ return toolSpeed, true
+}
+
+func (g *Game) consumeFireTool(sess *net.Session, p *player.Player, toolItemID string) bool {
+ def, _ := g.ItemStore.Load(toolItemID)
+
+ if def != nil && def.MaxQuality > 0 {
+ for _, slot := range p.Inventory {
+ if slot != nil && slot.ItemID == toolItemID && slot.MaxQuality > 0 {
+ if slot.Quality <= 0 {
+ sess.WriteLine("The lighter is out of butane!")
+ return false
+ }
+ slot.Quality--
+ g.AccountStore.SaveCharacter(p)
+ return true
+ }
+ }
+ if q, ok := p.EquipQuality[toolItemID]; ok {
+ if q <= 0 {
+ sess.WriteLine("The lighter is out of butane!")
+ return false
+ }
+ p.EquipQuality[toolItemID] = q - 1
+ g.AccountStore.SaveCharacter(p)
+ return true
+ }
+ }
+
+ if def != nil && def.Stackable {
+ if p.HasItem(toolItemID) {
+ p.RemoveItem(toolItemID, 1)
+ g.AccountStore.SaveCharacter(p)
+ return true
+ }
+ for slot, itemID := range p.Equipment {
+ if itemID == toolItemID {
+ delete(p.Equipment, slot)
+ g.AccountStore.SaveCharacter(p)
+ return true
+ }
+ }
+ sess.WriteLine("You need a fire starter to do that.")
+ return false
+ }
+
+ return true
+}
+
+func (g *Game) findFireObjectKey(roomID int) string {
+ objs := g.World.AllObjInstances(roomID)
+ for _, st := range objs {
+ if st.DefID == "fire" && st.Quality > 0 {
+ return g.World.ObjStateKey(st.RoomID, st.DefID, st.Index)
+ }
+ }
+ return ""
+}
+
+func (g *Game) hasFireObject(roomID int) bool {
+ return g.findFireObjectKey(roomID) != ""
+}
+
+func (g *Game) broadcastDrop(p *player.Player, itemName string) {
+ for _, other := range g.Hub.PlayersInRoom(p.RoomID) {
+ op, ok := other.Player.(*player.Player)
+ if ok && op.Name != p.Name {
+ other.WriteLine(fmt.Sprintf("\n%s drops a %s.", p.Name, itemName))
+ }
+ }
+}
+
+func (g *Game) FireTick() {
+ for _, st := range g.World.AllFireStates() {
+ st.Quality--
+ if st.Quality <= 0 {
+ g.World.RemoveObjInstance(st.RoomID, st.DefID)
+ g.cancelStokers(st.RoomID)
+ if def, err := g.ObjectStore.Load(st.DefID); err == nil && def.RemovalItem != "" {
+ g.World.AddGroundItem(st.RoomID, def.RemovalItem, 1)
+ }
+ }
+ }
+}
+
+func (g *Game) cancelStokers(roomID int) {
+ for _, other := range g.Hub.PlayersInRoom(roomID) {
+ op, ok := other.Player.(*player.Player)
+ if ok && op.Action != nil && op.Action.Type == "stoke" {
+ other.WriteLine("The fire went out!")
+ g.CancelAction(op)
+ }
+ }
+}
+
+func (g *Game) resolveBurnTarget(p *player.Player, input string) (itemID string, fromGround bool, ambiguous bool) {
+ if input != "" {
+ return g.resolveNamedBurnTarget(p, input)
+ }
+ return g.resolveDefaultBurnTarget(p)
+}
+
+func (g *Game) collectBurnableGround(roomID int, name string) []string {
+ var out []string
+ for itemID := range g.World.GroundItems(roomID) {
+ def, err := g.ItemStore.Load(itemID)
+ if err != nil || def.BurnTicks <= 0 {
+ continue
+ }
+ if name == "" || def.MatchesName(name) {
+ out = append(out, itemID)
+ }
+ }
+ return out
+}
+
+func (g *Game) collectBurnableInv(p *player.Player, name string) []string {
+ var out []string
+ seen := make(map[string]bool)
+ for _, slot := range p.Inventory {
+ if slot == nil || slot.Quantity <= 0 {
+ continue
+ }
+ def, err := g.ItemStore.Load(slot.ItemID)
+ if err != nil || def.BurnTicks <= 0 || seen[slot.ItemID] {
+ continue
+ }
+ if name == "" || def.MatchesName(name) {
+ seen[slot.ItemID] = true
+ out = append(out, slot.ItemID)
+ }
+ }
+ return out
+}
+
+func (g *Game) resolveNamedBurnTarget(p *player.Player, input string) (itemID string, fromGround bool, ambiguous bool) {
+ groundMatches := g.collectBurnableGround(p.RoomID, input)
+ if len(groundMatches) > 1 {
+ return "", false, true
+ }
+ if len(groundMatches) == 1 {
+ return groundMatches[0], true, false
+ }
+
+ invMatches := g.collectBurnableInv(p, input)
+ if len(invMatches) > 1 {
+ return "", false, true
+ }
+ if len(invMatches) == 1 {
+ return invMatches[0], false, false
+ }
+
+ return "", false, false
+}
+
+func (g *Game) resolveDefaultBurnTarget(p *player.Player) (itemID string, fromGround bool, ambiguous bool) {
+ groundBurnable := g.collectBurnableGround(p.RoomID, "")
+ if len(groundBurnable) == 1 {
+ return groundBurnable[0], true, false
+ }
+ if len(groundBurnable) > 1 {
+ return "", false, true
+ }
+
+ invBurnable := g.collectBurnableInv(p, "")
+ if len(invBurnable) == 1 {
+ return invBurnable[0], false, false
+ }
+ if len(invBurnable) > 1 {
+ return "", false, true
+ }
+
+ return "", false, false
+}
+
+func (g *Game) resolveStokeTarget(p *player.Player, input string) (string, bool) {
+ invBurnable := g.collectBurnableInv(p, input)
+ if len(invBurnable) == 1 {
+ return invBurnable[0], false
+ }
+ if len(invBurnable) > 1 {
+ return "", true
+ }
+ return "", false
+}
diff --git a/internal/game/action_gather.go b/internal/game/action_gather.go
index 2ca2e82..7e53e87 100644
--- a/internal/game/action_gather.go
+++ b/internal/game/action_gather.go
@@ -214,7 +214,9 @@ func (g *Game) advanceGather(sess *net.Session, p *player.Player) {
xp = cfg.XP
}
if xp > 0 {
- p.AddXP(player.SkillName(cfg.Skill), xp)
+ if newLevel := p.AddSkillXP(player.SkillName(cfg.Skill), xp); newLevel > 0 {
+ sess.WriteLine(fmt.Sprintf("*** You are now level %d %s! ***", newLevel, cfg.Skill))
+ }
}
g.AccountStore.SaveCharacter(p)
@@ -232,7 +234,7 @@ func (g *Game) advanceGather(sess *net.Session, p *player.Player) {
if shared {
st := g.World.GetObjStateByKey(instanceKey)
if st != nil && st.SharedTimer <= 0 {
- g.depleteSharedTree(sess, p, st, cfg.DepleteDelay, instanceKey)
+ g.depleteSharedTree(sess, p, st, cfg, instanceKey)
return
}
}
@@ -301,12 +303,17 @@ func filterDropsByLevel(drops []action.DropEntry, level int) []action.DropEntry
return eligible
}
-func (g *Game) depleteSharedTree(sess *net.Session, p *player.Player, st *world.ObjState, respawnTicks int, instanceKey string) {
+func (g *Game) depleteSharedTree(sess *net.Session, p *player.Player, st *world.ObjState, cfg *action.GatherConfig, instanceKey string) {
st.Depleted = true
- st.DepleteTimer = respawnTicks
+ st.DepleteTimer = cfg.DepleteDelay
st.SharedTimer = 0
- sess.WriteLine(fmt.Sprintf("\nThe %s falls to the ground!", p.Action.TargetName))
+ msg := cfg.ExhaustedMessage
+ if msg == "" {
+ msg = fmt.Sprintf("The %s falls to the ground!", p.Action.TargetName)
+ }
+
+ sess.WriteLine(fmt.Sprintf("\n%s", msg))
for _, other := range g.Hub.PlayersInRoom(p.RoomID) {
if other == sess {
@@ -317,7 +324,7 @@ func (g *Game) depleteSharedTree(sess *net.Session, p *player.Player, st *world.
continue
}
if op.Action.Data["instance_key"] == instanceKey {
- other.WriteLine(fmt.Sprintf("\nThe %s falls to the ground!", p.Action.TargetName))
+ other.WriteLine(fmt.Sprintf("\n%s", msg))
g.CancelAction(op)
}
}
diff --git a/internal/game/action_use.go b/internal/game/action_use.go
index 69d29c1..497ceac 100644
--- a/internal/game/action_use.go
+++ b/internal/game/action_use.go
@@ -96,7 +96,9 @@ func (g *Game) advanceUse(sess *net.Session, p *player.Player) {
p.SetInvSlot(freeSlot, &player.InventorySlot{ItemID: cfg.Reward.ItemID, Quantity: qty})
if cfg.XP > 0 {
- p.AddXP(player.SkillName(cfg.Skill), cfg.XP)
+ if newLevel := p.AddSkillXP(player.SkillName(cfg.Skill), cfg.XP); newLevel > 0 {
+ sess.WriteLine(fmt.Sprintf("*** You are now level %d %s! ***", newLevel, cfg.Skill))
+ }
}
g.AccountStore.SaveCharacter(p)
diff --git a/internal/game/cmd_attack.go b/internal/game/cmd_attack.go
index f6ccf0c..2f79c16 100644
--- a/internal/game/cmd_attack.go
+++ b/internal/game/cmd_attack.go
@@ -195,7 +195,11 @@ func (g *Game) playerAttack(sess *net.Session, p *player.Player, mob *world.MobI
if mob.HP < mob.MaxHP && mob.HP > 0 {
mob.StartRegen()
}
- gains := g.awardCombatXP(p, dmg)
+ gains, leveled := g.awardCombatXP(p, dmg)
+
+ for _, skill := range leveled {
+ sess.WriteLine(fmt.Sprintf("*** You are now level %d %s! ***", p.Level(skill), skill))
+ }
mobName := mobDisplayName(mob, true)
attacker := mob.Name
@@ -348,9 +352,10 @@ func (g *Game) endCombat(sess *net.Session, p *player.Player, mob *world.MobInst
}
}
-func (g *Game) awardCombatXP(p *player.Player, dmg int) []xpGain {
+func (g *Game) awardCombatXP(p *player.Player, dmg int) ([]xpGain, []player.SkillName) {
baseXP := dmg * 4
var gains []xpGain
+ var leveledUp []player.SkillName
switch p.AttackStyle {
case player.Accurate:
@@ -370,10 +375,12 @@ func (g *Game) awardCombatXP(p *player.Player, dmg int) []xpGain {
}
for _, gain := range gains {
- p.AddXP(player.SkillName(gain.Skill), gain.XP)
+ if newLevel := p.AddSkillXP(player.SkillName(gain.Skill), gain.XP); newLevel > 0 {
+ leveledUp = append(leveledUp, player.SkillName(gain.Skill))
+ }
}
g.AccountStore.SaveCharacter(p)
- return gains
+ return gains, leveledUp
}
func (g *Game) dropItemsOnDeath(p *player.Player) {
diff --git a/internal/game/cmd_get.go b/internal/game/cmd_get.go
index 70b458e..f4c7426 100644
--- a/internal/game/cmd_get.go
+++ b/internal/game/cmd_get.go
@@ -96,7 +96,7 @@ func (g *Game) doGet(sess *net.Session, input string) {
return
}
_ = removed
- p.SetInvSlot(freeSlot, &player.InventorySlot{ItemID: itemID, Quantity: qty})
+ p.SetInvSlot(freeSlot, g.newInvSlot(itemID, qty))
g.AccountStore.SaveCharacter(p)
if qty == 1 {
sess.WriteLine(fmt.Sprintf("You pick up a %s.", def.Name))
@@ -329,7 +329,7 @@ func (g *Game) doGetAll(sess *net.Session) {
if !ok {
break
}
- p.SetInvSlot(freeSlot, &player.InventorySlot{ItemID: itemID, Quantity: qty})
+ p.SetInvSlot(freeSlot, g.newInvSlot(itemID, qty))
name := itemID
if def != nil {
name = def.Name
diff --git a/internal/game/cmd_look.go b/internal/game/cmd_look.go
index 6d19023..e0e98fe 100644
--- a/internal/game/cmd_look.go
+++ b/internal/game/cmd_look.go
@@ -96,6 +96,7 @@ func (g *Game) doLook(sess *net.Session) {
sharedMax int
sharedCur int
respawnIn int
+ quality int
}
var instances []instInfo
for i := 0; i < count; i++ {
@@ -109,6 +110,7 @@ func (g *Game) doLook(sess *net.Session) {
sharedMax: st.SharedMax,
sharedCur: st.SharedTimer,
respawnIn: st.DepleteTimer,
+ quality: st.Quality,
})
}
multi := len(instances) > 1
@@ -126,19 +128,35 @@ func (g *Game) doLook(sess *net.Session) {
}
}
+ roomDesc := def.InRoomDescription
+
if len(freshIdxs) > 0 {
+ var line string
+ if roomDesc != "" {
+ line = roomDesc
+ } else if len(freshIdxs) == 1 {
+ line = "A " + def.Name + " is here."
+ } else {
+ line = fmt.Sprintf("%d %ss are here.", len(freshIdxs), def.Name)
+ }
var suffix string
if multi && (len(timed) > 0 || len(depleted) > 0) {
suffix = fmt.Sprintf(" [%s]", intsJoin(freshIdxs))
}
- if len(freshIdxs) == 1 {
- sess.WriteLine(fmt.Sprintf(" A %s is here.%s", def.Name, suffix))
- } else {
- sess.WriteLine(fmt.Sprintf(" %d %ss are here.%s", len(freshIdxs), def.Name, suffix))
+ qualityTimer := ""
+ if showTimers && len(instances) > 0 && instances[0].quality > 0 {
+ qualityTimer = fmt.Sprintf(" (Burning for %d more ticks)", instances[0].quality)
}
+ sess.WriteLine(fmt.Sprintf(" %s%s%s", line, suffix, qualityTimer))
}
for _, ins := range timed {
+ var line string
+ if roomDesc != "" {
+ line = roomDesc
+ } else {
+ line = "A " + def.Name + " is here."
+ }
tag := ""
if multi {
tag = fmt.Sprintf(" [%d]", ins.idx)
@@ -147,10 +165,16 @@ func (g *Game) doLook(sess *net.Session) {
if showTimers {
timer = fmt.Sprintf(" (despawn: %d/%d)", ins.sharedCur, ins.sharedMax)
}
- sess.WriteLine(fmt.Sprintf(" A %s is here.%s%s", def.Name, tag, timer))
+ sess.WriteLine(fmt.Sprintf(" %s%s%s", line, tag, timer))
}
for _, ins := range depleted {
+ var line string
+ if roomDesc != "" {
+ line = roomDesc
+ } else {
+ line = "A " + def.Name + " is here."
+ }
tag := ""
if multi {
tag = fmt.Sprintf(" [%d]", ins.idx)
@@ -159,7 +183,7 @@ func (g *Game) doLook(sess *net.Session) {
if showTimers {
timer = fmt.Sprintf(" (respawns in %d ticks)", ins.respawnIn)
}
- sess.WriteLine(fmt.Sprintf(" 1 depleted %s is here.%s%s", def.Name, tag, timer))
+ sess.WriteLine(fmt.Sprintf(" %s (depleted)%s%s", line, tag, timer))
}
}
}
@@ -203,14 +227,21 @@ func (g *Game) doLook(sess *net.Session) {
if len(prefix) > maxPrefix {
maxPrefix = len(prefix)
}
- reserved := ""
+ var parts []string
if info.ReservedFor != "" {
if p.OptionBool("reserve") {
- reserved = fmt.Sprintf(" (reserved for %s for %d ticks)", info.ReservedFor, info.ReserveTimer)
+ parts = append(parts, fmt.Sprintf("reserved for %s %dt", info.ReservedFor, info.ReserveTimer))
} else {
- reserved = " (reserved)"
+ parts = append(parts, "reserved")
}
}
+ if p.OptionBool("despawn") && !info.IsSpawn {
+ parts = append(parts, fmt.Sprintf("despawns %dt", info.DespawnTimer))
+ }
+ reserved := ""
+ if len(parts) > 0 {
+ reserved = fmt.Sprintf(" (%s)", strings.Join(parts, ", "))
+ }
lines = append(lines, groundLine{prefix, reserved})
}
@@ -362,6 +393,14 @@ func (g *Game) doLookTarget(sess *net.Session, input string) {
}
}
}
+ for _, ist := range instances {
+ if ist.Quality > 0 {
+ if qdesc, ok := def.Props["quality_description"].(string); ok && qdesc != "" {
+ qdesc = strings.ReplaceAll(qdesc, "{quality}", fmt.Sprintf("%d", ist.Quality))
+ sess.WriteLine(fmt.Sprintf(" %s", qdesc))
+ }
+ }
+ }
return
}
@@ -389,12 +428,16 @@ func (g *Game) doLookTarget(sess *net.Session, input string) {
if err != nil || !def.MatchesName(input) {
continue
}
- sess.WriteLines(
+ lines := []string{
"",
def.Name,
fmt.Sprintf(" %s", def.Description),
fmt.Sprintf(" Value: %d credits", def.Value),
- )
+ }
+ if slot.MaxQuality > 0 {
+ lines = append(lines, fmt.Sprintf(" Has %d units of butane left.", slot.Quality))
+ }
+ sess.WriteLines(lines...)
return
}
diff --git a/internal/game/cmd_remove.go b/internal/game/cmd_remove.go
index 9f0cbe8..f511ec4 100644
--- a/internal/game/cmd_remove.go
+++ b/internal/game/cmd_remove.go
@@ -56,7 +56,15 @@ func (g *Game) doRemove(sess *net.Session, input string) {
}
delete(p.Equipment, foundSlot)
- p.SetInvSlot(freeSlot, &player.InventorySlot{ItemID: foundItemID, Quantity: 1})
+ invSlot := &player.InventorySlot{ItemID: foundItemID, Quantity: 1}
+ if q, ok := p.EquipQuality[foundItemID]; ok {
+ invSlot.Quality = q
+ if def, _ := g.ItemStore.Load(foundItemID); def != nil {
+ invSlot.MaxQuality = def.MaxQuality
+ }
+ delete(p.EquipQuality, foundItemID)
+ }
+ p.SetInvSlot(freeSlot, invSlot)
g.AccountStore.SaveCharacter(p)
name := foundItemID
diff --git a/internal/game/cmd_wear.go b/internal/game/cmd_wear.go
index c4b5d12..4554dfc 100644
--- a/internal/game/cmd_wear.go
+++ b/internal/game/cmd_wear.go
@@ -62,6 +62,13 @@ func (g *Game) doWear(sess *net.Session, input string) {
p.SetInvSlot(match.Slot, nil)
}
+ if slot.Quality > 0 && slot.MaxQuality > 0 {
+ if p.EquipQuality == nil {
+ p.EquipQuality = make(map[string]int)
+ }
+ p.EquipQuality[slot.ItemID] = slot.Quality
+ }
+
p.Equipment[def.EquipSlot] = slot.ItemID
g.AccountStore.SaveCharacter(p)
@@ -127,6 +134,13 @@ func (g *Game) doWearAll(sess *net.Session) {
p.SetInvSlot(best.invSlot, nil)
}
+ if invSlot != nil && invSlot.Quality > 0 && invSlot.MaxQuality > 0 {
+ if p.EquipQuality == nil {
+ p.EquipQuality = make(map[string]int)
+ }
+ p.EquipQuality[best.itemID] = invSlot.Quality
+ }
+
p.Equipment[eqSlot] = best.itemID
def, _ := g.ItemStore.Load(best.itemID)
name := best.itemID
diff --git a/internal/game/game.go b/internal/game/game.go
index cc187a7..21dee76 100644
--- a/internal/game/game.go
+++ b/internal/game/game.go
@@ -234,6 +234,12 @@ func (g *Game) handleGameCommand(sess *net.Session, input string) {
g.StartAction(sess, "talk", strings.Join(args, " "))
return
}
+ case "burn":
+ g.doBurn(sess, p, strings.Join(args, " "))
+ return
+ case "stoke":
+ g.doStoke(sess, p, strings.Join(args, " "))
+ return
case "alias":
g.doAlias(sess, args)
return
diff --git a/internal/game/utils.go b/internal/game/utils.go
index c78889d..969eba4 100644
--- a/internal/game/utils.go
+++ b/internal/game/utils.go
@@ -121,6 +121,19 @@ func actionDesc(p *player.Player) string {
return "talking to " + target
case "use":
return "using a " + target
+ case "burn":
+ return "trying to start a fire"
+ case "stoke":
+ return "tending to a fire"
}
return ""
}
+
+func (g *Game) newInvSlot(itemID string, qty int) *player.InventorySlot {
+ slot := &player.InventorySlot{ItemID: itemID, Quantity: qty}
+ if def, err := g.ItemStore.Load(itemID); err == nil && def.MaxQuality > 0 {
+ slot.Quality = def.Quality
+ slot.MaxQuality = def.MaxQuality
+ }
+ return slot
+}