Decompose wizard.go createObj and whatis (refactor step 7)
createObj gains createWeaponArmor/createRing; whatis gains whatisPick for its prompt loop. wizard.go is complexity-clean. Behavior unchanged.
This commit is contained in:
161
game/wizard.go
161
game/wizard.go
@@ -27,50 +27,9 @@ func (g *RogueGame) createObj() {
|
|||||||
|
|
||||||
switch obj.Kind {
|
switch obj.Kind {
|
||||||
case KindWeapon, KindArmor:
|
case KindWeapon, KindArmor:
|
||||||
g.msg("blessing? (+,-,n)")
|
g.createWeaponArmor(obj)
|
||||||
bless := g.readchar()
|
|
||||||
g.Msgs.Mpos = 0
|
|
||||||
|
|
||||||
if bless == '-' {
|
|
||||||
obj.Flags.Set(Cursed)
|
|
||||||
}
|
|
||||||
|
|
||||||
if obj.Kind == KindWeapon {
|
|
||||||
g.initWeapon(obj, WeaponKind(obj.Which))
|
|
||||||
|
|
||||||
if bless == '-' {
|
|
||||||
obj.HPlus -= g.rnd(3) + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
if bless == '+' {
|
|
||||||
obj.HPlus += g.rnd(3) + 1
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
obj.ArmorClass = g.data.aClass[obj.Which]
|
|
||||||
if bless == '-' {
|
|
||||||
obj.ArmorClass += g.rnd(3) + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
if bless == '+' {
|
|
||||||
obj.ArmorClass -= g.rnd(3) + 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case KindRing:
|
case KindRing:
|
||||||
switch obj.RingKind() {
|
g.createRing(obj)
|
||||||
case RingProtection, RingAddStrength, RingDexterity, RingIncreaseDamage:
|
|
||||||
g.msg("blessing? (+,-,n)")
|
|
||||||
bless := g.readchar()
|
|
||||||
g.Msgs.Mpos = 0
|
|
||||||
|
|
||||||
if bless == '-' {
|
|
||||||
obj.Flags.Set(Cursed)
|
|
||||||
obj.Bonus = -1
|
|
||||||
} else {
|
|
||||||
obj.Bonus = g.rnd(2) + 1
|
|
||||||
}
|
|
||||||
case RingAggravateMonsters, RingTeleportation:
|
|
||||||
obj.Flags.Set(Cursed)
|
|
||||||
}
|
|
||||||
case KindWand:
|
case KindWand:
|
||||||
g.fixStick(obj)
|
g.fixStick(obj)
|
||||||
case KindGold:
|
case KindGold:
|
||||||
@@ -85,6 +44,61 @@ func (g *RogueGame) createObj() {
|
|||||||
g.addPack(obj, false)
|
g.addPack(obj, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// createWeaponArmor sets up a wizard-created weapon or armor with an
|
||||||
|
// optional blessing (the weapon/armor arm of wizard.c create_obj).
|
||||||
|
func (g *RogueGame) createWeaponArmor(obj *Object) {
|
||||||
|
g.msg("blessing? (+,-,n)")
|
||||||
|
bless := g.readchar()
|
||||||
|
g.Msgs.Mpos = 0
|
||||||
|
|
||||||
|
if bless == '-' {
|
||||||
|
obj.Flags.Set(Cursed)
|
||||||
|
}
|
||||||
|
|
||||||
|
if obj.Kind == KindWeapon {
|
||||||
|
g.initWeapon(obj, WeaponKind(obj.Which))
|
||||||
|
|
||||||
|
if bless == '-' {
|
||||||
|
obj.HPlus -= g.rnd(3) + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if bless == '+' {
|
||||||
|
obj.HPlus += g.rnd(3) + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.ArmorClass = g.data.aClass[obj.Which]
|
||||||
|
if bless == '-' {
|
||||||
|
obj.ArmorClass += g.rnd(3) + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if bless == '+' {
|
||||||
|
obj.ArmorClass -= g.rnd(3) + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// createRing sets up a wizard-created ring, prompting for a bonus on
|
||||||
|
// the bonus rings (the ring arm of wizard.c create_obj).
|
||||||
|
func (g *RogueGame) createRing(obj *Object) {
|
||||||
|
switch obj.RingKind() {
|
||||||
|
case RingProtection, RingAddStrength, RingDexterity, RingIncreaseDamage:
|
||||||
|
g.msg("blessing? (+,-,n)")
|
||||||
|
bless := g.readchar()
|
||||||
|
g.Msgs.Mpos = 0
|
||||||
|
|
||||||
|
if bless == '-' {
|
||||||
|
obj.Flags.Set(Cursed)
|
||||||
|
obj.Bonus = -1
|
||||||
|
} else {
|
||||||
|
obj.Bonus = g.rnd(2) + 1
|
||||||
|
}
|
||||||
|
case RingAggravateMonsters, RingTeleportation:
|
||||||
|
obj.Flags.Set(Cursed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// showMap prints out the whole map for the wizard (wizard.c show_map).
|
// showMap prints out the whole map for the wizard (wizard.c show_map).
|
||||||
func (g *RogueGame) showMap() {
|
func (g *RogueGame) showMap() {
|
||||||
hw := g.scr.Hw
|
hw := g.scr.Hw
|
||||||
@@ -117,34 +131,8 @@ func (g *RogueGame) whatis(insist bool, kind ObjectKind) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var obj *Object
|
obj, ok := g.whatisPick(insist, kind)
|
||||||
for {
|
if !ok {
|
||||||
obj, _ = g.promptPackItem("identify", kind)
|
|
||||||
|
|
||||||
if !insist {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if g.NObjs == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if obj == nil {
|
|
||||||
g.msg("you must identify something")
|
|
||||||
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if !matchesFilter(kind, obj) {
|
|
||||||
g.msg("you must identify a %s", kind)
|
|
||||||
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if obj == nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,6 +152,37 @@ func (g *RogueGame) whatis(insist bool, kind ObjectKind) {
|
|||||||
g.msg("%s", g.inventoryName(obj, false))
|
g.msg("%s", g.inventoryName(obj, false))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// whatisPick prompts for the item to identify, re-asking until a
|
||||||
|
// matching one is chosen when insist is set; ok is false when the
|
||||||
|
// player gives up (the prompt loop of wizard.c whatis).
|
||||||
|
func (g *RogueGame) whatisPick(insist bool, kind ObjectKind) (*Object, bool) {
|
||||||
|
for {
|
||||||
|
obj, _ := g.promptPackItem("identify", kind)
|
||||||
|
|
||||||
|
if !insist {
|
||||||
|
return obj, obj != nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if g.NObjs == 0 {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
if obj == nil {
|
||||||
|
g.msg("you must identify something")
|
||||||
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if !matchesFilter(kind, obj) {
|
||||||
|
g.msg("you must identify a %s", kind)
|
||||||
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// setKnow sets things up when we really know what a thing is (wizard.c
|
// setKnow sets things up when we really know what a thing is (wizard.c
|
||||||
// set_know).
|
// set_know).
|
||||||
func setKnow(obj *Object, info []ObjInfo) {
|
func setKnow(obj *Object, info []ObjInfo) {
|
||||||
|
|||||||
Reference in New Issue
Block a user