Decompose ringOn and totalWinner (refactor step 7)
ringOn gains pickRingHand and chooseTerse messages; totalWinner's appraisal switch becomes objectWorth with loreWorth/ringWorth/ wandWorth. Behavior unchanged.
This commit is contained in:
@@ -14,11 +14,8 @@ func (g *RogueGame) ringOn() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if obj.Kind != KindRing {
|
if obj.Kind != KindRing {
|
||||||
if !g.Options.Terse {
|
g.msg("%s", g.chooseTerse("not a ring",
|
||||||
g.msg("it would be difficult to wrap that around a finger")
|
"it would be difficult to wrap that around a finger"))
|
||||||
} else {
|
|
||||||
g.msg("not a ring")
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -28,24 +25,8 @@ func (g *RogueGame) ringOn() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var ring int
|
ring := g.pickRingHand()
|
||||||
|
if ring < 0 {
|
||||||
switch {
|
|
||||||
case p.CurRing[Left] == nil && p.CurRing[Right] == nil:
|
|
||||||
if ring = g.gethand(); ring < 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
case p.CurRing[Left] == nil:
|
|
||||||
ring = Left
|
|
||||||
case p.CurRing[Right] == nil:
|
|
||||||
ring = Right
|
|
||||||
default:
|
|
||||||
if !g.Options.Terse {
|
|
||||||
g.msg("you already have a ring on each hand")
|
|
||||||
} else {
|
|
||||||
g.msg("wearing two")
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,6 +49,26 @@ func (g *RogueGame) ringOn() {
|
|||||||
g.msg("%s (%c)", g.inventoryName(obj, true), obj.PackCh)
|
g.msg("%s (%c)", g.inventoryName(obj, true), obj.PackCh)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pickRingHand chooses the hand for a new ring, asking when both are
|
||||||
|
// free; negative aborts (rings.c ring_on).
|
||||||
|
func (g *RogueGame) pickRingHand() int {
|
||||||
|
p := &g.Player
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case p.CurRing[Left] == nil && p.CurRing[Right] == nil:
|
||||||
|
return g.gethand()
|
||||||
|
case p.CurRing[Left] == nil:
|
||||||
|
return Left
|
||||||
|
case p.CurRing[Right] == nil:
|
||||||
|
return Right
|
||||||
|
default:
|
||||||
|
g.msg("%s", g.chooseTerse("wearing two",
|
||||||
|
"you already have a ring on each hand"))
|
||||||
|
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ringOff takes off a ring (rings.c ring_off).
|
// ringOff takes off a ring (rings.c ring_off).
|
||||||
func (g *RogueGame) ringOff() {
|
func (g *RogueGame) ringOff() {
|
||||||
p := &g.Player
|
p := &g.Player
|
||||||
|
|||||||
91
game/rip.go
91
game/rip.go
@@ -115,8 +115,25 @@ func (g *RogueGame) totalWinner() {
|
|||||||
line := 1
|
line := 1
|
||||||
|
|
||||||
for _, obj := range p.Pack {
|
for _, obj := range p.Pack {
|
||||||
worth := 0
|
worth := g.objectWorth(obj)
|
||||||
|
|
||||||
|
g.scr.Std.MvPrintwf(line, 0, "%c) %5d %s", obj.PackCh, worth,
|
||||||
|
g.inventoryName(obj, false))
|
||||||
|
line++
|
||||||
|
p.Purse += worth
|
||||||
|
}
|
||||||
|
|
||||||
|
g.scr.Std.MvPrintwf(line, 0, " %5d Gold Pieces ", oldpurse)
|
||||||
|
g.refresh()
|
||||||
|
g.score(p.Purse, 2, ' ')
|
||||||
|
g.myExit()
|
||||||
|
}
|
||||||
|
|
||||||
|
// objectWorth appraises one pack item on the way out, marking it known
|
||||||
|
// (the switch of rip.c total_winner).
|
||||||
|
func (g *RogueGame) objectWorth(obj *Object) int {
|
||||||
it := &g.Items
|
it := &g.Items
|
||||||
|
worth := 0
|
||||||
|
|
||||||
switch obj.Kind {
|
switch obj.Kind {
|
||||||
case KindFood:
|
case KindFood:
|
||||||
@@ -131,26 +148,42 @@ func (g *RogueGame) totalWinner() {
|
|||||||
worth += 10 * (g.data.aClass[obj.Which] - obj.ArmorClass)
|
worth += 10 * (g.data.aClass[obj.Which] - obj.ArmorClass)
|
||||||
obj.Flags.Set(Known)
|
obj.Flags.Set(Known)
|
||||||
case KindScroll:
|
case KindScroll:
|
||||||
op := &it.Scrolls[obj.Which]
|
worth = loreWorth(&it.Scrolls[obj.Which], obj.Count)
|
||||||
|
|
||||||
worth = op.Worth * obj.Count
|
|
||||||
if !op.Know {
|
|
||||||
worth /= 2
|
|
||||||
}
|
|
||||||
|
|
||||||
op.Know = true
|
|
||||||
case KindPotion:
|
case KindPotion:
|
||||||
op := &it.Potions[obj.Which]
|
worth = loreWorth(&it.Potions[obj.Which], obj.Count)
|
||||||
|
case KindRing:
|
||||||
|
worth = g.ringWorth(obj)
|
||||||
|
case KindWand:
|
||||||
|
worth = g.wandWorth(obj)
|
||||||
|
case KindAmulet:
|
||||||
|
worth = 1000
|
||||||
|
}
|
||||||
|
|
||||||
worth = op.Worth * obj.Count
|
if worth < 0 {
|
||||||
|
worth = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return worth
|
||||||
|
}
|
||||||
|
|
||||||
|
// loreWorth appraises a scroll or potion, halved when unidentified, and
|
||||||
|
// identifies it (rip.c total_winner).
|
||||||
|
func loreWorth(op *ObjInfo, count int) int {
|
||||||
|
worth := op.Worth * count
|
||||||
if !op.Know {
|
if !op.Know {
|
||||||
worth /= 2
|
worth /= 2
|
||||||
}
|
}
|
||||||
|
|
||||||
op.Know = true
|
op.Know = true
|
||||||
case KindRing:
|
|
||||||
op := &it.Rings[obj.Which]
|
return worth
|
||||||
worth = op.Worth
|
}
|
||||||
|
|
||||||
|
// ringWorth appraises a ring: bonus rings gain by their bonus, cursed
|
||||||
|
// ones are junk (rip.c total_winner).
|
||||||
|
func (g *RogueGame) ringWorth(obj *Object) int {
|
||||||
|
op := &g.Items.Rings[obj.Which]
|
||||||
|
worth := op.Worth
|
||||||
|
|
||||||
if obj.RingKind() == RingAddStrength || obj.RingKind() == RingIncreaseDamage ||
|
if obj.RingKind() == RingAddStrength || obj.RingKind() == RingIncreaseDamage ||
|
||||||
obj.RingKind() == RingProtection || obj.RingKind() == RingDexterity {
|
obj.RingKind() == RingProtection || obj.RingKind() == RingDexterity {
|
||||||
@@ -168,9 +201,15 @@ func (g *RogueGame) totalWinner() {
|
|||||||
obj.Flags.Set(Known)
|
obj.Flags.Set(Known)
|
||||||
|
|
||||||
op.Know = true
|
op.Know = true
|
||||||
case KindWand:
|
|
||||||
op := &it.Sticks[obj.Which]
|
return worth
|
||||||
worth = op.Worth
|
}
|
||||||
|
|
||||||
|
// wandWorth appraises a wand or staff by its charges (rip.c
|
||||||
|
// total_winner).
|
||||||
|
func (g *RogueGame) wandWorth(obj *Object) int {
|
||||||
|
op := &g.Items.Sticks[obj.Which]
|
||||||
|
worth := op.Worth
|
||||||
|
|
||||||
worth += 20 * obj.Charges
|
worth += 20 * obj.Charges
|
||||||
if !obj.Flags.Has(Known) {
|
if !obj.Flags.Has(Known) {
|
||||||
@@ -180,24 +219,8 @@ func (g *RogueGame) totalWinner() {
|
|||||||
obj.Flags.Set(Known)
|
obj.Flags.Set(Known)
|
||||||
|
|
||||||
op.Know = true
|
op.Know = true
|
||||||
case KindAmulet:
|
|
||||||
worth = 1000
|
|
||||||
}
|
|
||||||
|
|
||||||
if worth < 0 {
|
return worth
|
||||||
worth = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
g.scr.Std.MvPrintwf(line, 0, "%c) %5d %s", obj.PackCh, worth,
|
|
||||||
g.inventoryName(obj, false))
|
|
||||||
line++
|
|
||||||
p.Purse += worth
|
|
||||||
}
|
|
||||||
|
|
||||||
g.scr.Std.MvPrintwf(line, 0, " %5d Gold Pieces ", oldpurse)
|
|
||||||
g.refresh()
|
|
||||||
g.score(p.Purse, 2, ' ')
|
|
||||||
g.myExit()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// killname converts a code to a monster name (rip.c killname).
|
// killname converts a code to a monster name (rip.c killname).
|
||||||
|
|||||||
Reference in New Issue
Block a user