1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
package game
import (
"fmt"
"strings"
"thehouseoficarus/internal/game/hacking"
"thehouseoficarus/internal/net"
"thehouseoficarus/internal/player"
)
func (g *Game) handleHackingInput(sess *net.Session, input string) {
p := sess.Player
if p == nil {
sess.State = net.StateGame
return
}
hs, ok := g.hackingStates[p.Name]
if !ok {
sess.State = net.StateGame
g.writePrompt(sess)
return
}
input = strings.TrimSpace(input)
lower := strings.ToLower(input)
if lower == "jack out" || lower == "quit" || lower == "disconnect" {
g.endHacking(sess, p, false, false)
return
}
hs.Started = true
output, done, won := hs.Minigame.HandleInput(input)
sess.WriteLine(output)
if done {
g.endHacking(sess, p, true, won)
return
}
sess.Write("\nhack> ")
}
func (g *Game) endHacking(sess *net.Session, p *player.Player, completed bool, won bool) {
hs, ok := g.hackingStates[p.Name]
if !ok {
sess.State = net.StateGame
g.writePrompt(sess)
return
}
tDef := hacking.Terminals[hs.TerminalID]
var xp int
if completed && won {
xp = hacking.CalcXP(tDef.BaseXPWin, hs.Level, hs.ReqLevel)
sess.WriteLine("Connection terminated. Contract complete.")
} else if completed {
xp = hacking.CalcXP(tDef.BaseXPLose, hs.Level, hs.ReqLevel)
sess.WriteLine("Connection lost.")
} else if hs.Started {
xp = hacking.CalcXP(tDef.BaseXPLose, hs.Level, hs.ReqLevel)
sess.WriteLine("You jack out of the terminal.")
} else {
sess.WriteLine("You jack out of the terminal.")
}
if won {
if b, ok := hs.Minigame.(hacking.XPBonuser); ok {
bonus := b.BonusXP()
if bonus > 0 {
xp += hacking.CalcXP(bonus, hs.Level, hs.ReqLevel)
}
}
}
if xp > 0 {
g.awardSkillXP(sess, p, player.Hacking, xp)
if p.OptionBool("xp_drops") {
sess.WriteLine(g.colorize(sess, "xp",
fmt.Sprintf("(+%dxp %s)", xp, player.SkillAbbr[player.Hacking])))
}
g.AccountStore.SaveCharacter(p)
}
delete(g.hackingStates, p.Name)
p.ActionState = nil
sess.State = net.StateGame
g.writePrompt(sess)
}
|