diff options
Diffstat (limited to 'internal/game/act_fletch.go')
| -rw-r--r-- | internal/game/act_fletch.go | 80 |
1 files changed, 53 insertions, 27 deletions
diff --git a/internal/game/act_fletch.go b/internal/game/act_fletch.go index 9796bda..d4adff0 100644 --- a/internal/game/act_fletch.go +++ b/internal/game/act_fletch.go @@ -32,6 +32,7 @@ func (g *Game) doInstantFletch(sess *net.Session, p *player.Player, def *item.It batches := 0 totalOutput := 0 + failures := 0 skill := player.SkillName(c.EffectiveSkill()) tmpItem := &item.ItemDef{Craft: item.CraftList{*c}} inventoryFull := false @@ -39,24 +40,33 @@ func (g *Game) doInstantFletch(sess *net.Session, p *player.Player, def *item.It if !g.canDoFletchItem(p, tmpItem) { break } - // A full inventory must never destroy materials: check placement - // BEFORE consuming the batch. - if !craftOutputFits(p, def.ID, def) { + // A full inventory must never destroy materials: check placement of + // BOTH the output and any fail replacement BEFORE consuming. + if !craftOutputFits(p, def.ID, def) || !g.craftFailFits(p, c) { inventoryFull = true break } + byproducts := g.collectByproducts(p, def) + if !consumeIngredients(c, p.CountItem, p.RemoveItem) { break } - placeCraftOutput(p, def.ID, def, outputQty) - if c.XP > 0 { - g.awardSkillXP(sess, p, skill, c.XP) - } + if craftRollSuccess(c, p.Level(skill)) { + placeCraftOutput(p, def.ID, def, outputQty) + g.placeCraftByproducts(p, byproducts) - batches++ - totalOutput += outputQty + if c.XP > 0 { + g.awardSkillXP(sess, p, skill, c.XP) + } + + batches++ + totalOutput += outputQty + } else { + g.placeCraftFail(p, c) + failures++ + } if count > 0 { count-- @@ -69,6 +79,8 @@ func (g *Game) doInstantFletch(sess *net.Session, p *player.Player, def *item.It if batches == 0 { if inventoryFull { sess.WriteLine("Your inventory is too full!") + } else if failures > 0 { + sess.WriteLine("You fail to fletch anything.") } else { sess.WriteLine("You don't have the materials for that.") } @@ -153,38 +165,52 @@ func (g *Game) advanceFletch(sess *net.Session, p *player.Player) { outputQty = 1 } - // A full inventory must never destroy materials: verify the output can - // be placed BEFORE consuming the batch. - if !craftOutputFits(p, itemID, def) { + // A full inventory must never destroy materials: verify BOTH the output + // and any fail replacement can be placed BEFORE consuming the batch. + if !craftOutputFits(p, itemID, def) || !g.craftFailFits(p, c) { sess.WriteLine("Your inventory is too full!") g.cancelBgAction(p) return } skill := player.SkillName(c.EffectiveSkill()) + byproducts := g.collectByproducts(p, def) + hasItem := craftConsumedHasItem(c, p.CountItem, p.HasItem) if !consumeIngredients(c, p.CountItem, p.RemoveItem) { g.cancelBgAction(p) return } - if !placeCraftOutput(p, itemID, def, outputQty) { - // Defensive: the fits check above should have guaranteed a stack - // or slot. - sess.WriteLine("Your inventory is too full!") - g.cancelBgAction(p) - return - } - if c.XP > 0 { - g.awardSkillXP(sess, p, skill, c.XP) - } - g.saveCharacter(p) + if craftRollSuccess(c, p.Level(skill)) { + if !placeCraftOutput(p, itemID, def, outputQty) { + // Defensive: the fits check above should have guaranteed a + // stack or slot. + sess.WriteLine("Your inventory is too full!") + g.cancelBgAction(p) + return + } + g.placeCraftByproducts(p, byproducts) - msg := g.resolveCraftMessage(sess, c.SuccessMessage, "You fletch a %n.", c, def.ID, nil, p.HasItem) - if p.OptionBool("xp_drops") && c.XP > 0 { - msg += g.formatXpDropSingle(sess, p, skill, c.XP) + if c.XP > 0 { + g.awardSkillXP(sess, p, skill, c.XP) + } + g.saveCharacter(p) + + msg := g.resolveCraftMessage(sess, c.SuccessMessage, "You fletch a %n.", c, def.ID, byproducts, hasItem) + if p.OptionBool("xp_drops") && c.XP > 0 { + msg += g.formatXpDropSingle(sess, p, skill, c.XP) + } + sess.WriteLine(msg) + } else { + g.placeCraftFail(p, c) + g.saveCharacter(p) + + msg := g.resolveCraftMessage(sess, c.FailMessage, "", c, def.ID, nil, hasItem) + if msg != "" { + sess.WriteLine(g.colorize(sess, "damage_taken", msg)) + } } - sess.WriteLine(msg) if remaining > 0 { remaining-- |
