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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
package game
import (
"fmt"
"strings"
"thehouseoficarus/internal/behavior"
"thehouseoficarus/internal/color"
"thehouseoficarus/internal/combat"
"thehouseoficarus/internal/engine"
"thehouseoficarus/internal/net"
"thehouseoficarus/internal/player"
"thehouseoficarus/internal/world"
)
func (g *Game) mobAttack(sess *net.Session, p *player.Player, mob *world.MobInstance) {
if g.isSafespotted(p.Name) && g.safespotBlocksMob(p, mob) {
return
}
attRoll, defRoll := g.calculateMobAttack(p, mob)
if combat.HitCheck(attRoll, defRoll) {
g.applyMobHit(sess, p, mob)
} else {
g.applyMobMiss(sess, mob)
}
}
func (g *Game) calculateMobAttack(p *player.Player, mob *world.MobInstance) (attRoll int, defRoll int) {
_, _, defStyleBonus := combat.AttackStyleBonus(string(p.AttackStyle))
mobAttackType := mob.AttackType
if mobAttackType == "" {
mobAttackType = "crush"
}
attRoll = combat.EffectiveRoll(mob.Attack, 0, mob.AttackBonus)
totals := g.playerEquipBonuses(p)
equipDef := combat.SelectBonus(mobAttackType,
totals.StabDefense, totals.SlashDefense, totals.CrushDefense,
totals.ScienceDefense, totals.RangedDefense)
defRoll = combat.EffectiveRoll(p.Level(player.Defense)+g.techLevelBonus(p, "defense")+g.buffLevelBonus(p, "defense"), defStyleBonus, equipDef)
return
}
func (g *Game) applyMobHit(sess *net.Session, p *player.Player, mob *world.MobInstance) {
maxHit := combat.MaxHit(mob.Strength, 0, mob.StrengthBonus)
dmg := combat.RollDamage(maxHit)
dmg = g.applyTechProtection(p, mob, dmg)
if mob.DamageWithout != "" {
hasProtection := false
for _, itemID := range p.Equipment {
if itemID == mob.DamageWithout {
hasProtection = true
break
}
}
if !hasProtection {
dmg = dmg * 3 / 2
if dmg < 1 {
dmg = 1
}
cs := g.Combat.Get(p.Name)
if cs != nil && !cs.DamageWarningShown {
cs.DamageWarningShown = true
fbDef, _ := g.ItemStore.Load(mob.DamageWithout)
fbName := mob.DamageWithout
if fbDef != nil {
fbName = fbDef.Name
}
attacker := mob.Name
if !mob.Unique {
attacker = "The " + mob.Name
}
sess.WriteLine(g.colorize(sess, "warning",
fmt.Sprintf(" %s's attack is extra effective! Equip %s for protection.",
attacker, fbName)))
}
}
}
p.HP -= dmg
if p.HP < 0 {
p.HP = 0
}
p.StartRegen()
g.AccountStore.SaveCharacter(p)
attacker := mob.Name
if !mob.Unique {
attacker = "The " + mob.Name
}
mobName := mobDisplayName(mob, true)
w := len(fmt.Sprintf("%s hits you for %d damage.", attacker, 999))
if w2 := len(fmt.Sprintf("You hit %s for %d damage.", mobName, 999)); w2 > w {
w = w2
}
prefix := fmt.Sprintf("%s hits you for %s damage.", g.colorize(sess, "mob", attacker), g.colorize(sess, "damage_taken", fmt.Sprint(dmg)))
visLen := color.VisibleLen(prefix)
if visLen < w {
prefix += strings.Repeat(" ", w-visLen+1)
}
hpSuffix := fmt.Sprintf("%s [%2d/%d]", g.hpBar(sess, p.HP, p.MaxHP()), p.HP, p.MaxHP())
sess.WriteLine(prefix + hpSuffix)
if ss, hasSS := g.safespot.Get(p.Name); hasSS && ss.HideCountdown > 0 {
g.safespot.Delete(p.Name)
sess.WriteLine(g.colorize(sess, "error", "You're hit while repositioning! You failed to hide."))
}
if p.MoveTicks > 0 {
p.ClearMoveState()
sess.WriteLine("Can't escape!")
}
if p.Action != nil && p.Action.Type == behavior.TypeTriggerModule {
g.cancelAction(p)
p.AttackTimer = 0
sess.WriteLine("Your concentration is broken!")
}
}
func (g *Game) applyMobMiss(sess *net.Session, mob *world.MobInstance) {
attacker := mob.Name
if !mob.Unique {
attacker = "The " + mob.Name
}
sess.WriteLine(g.colorize(sess, "miss", fmt.Sprintf("%s misses you.", attacker)))
}
func (g *Game) endCombat(sess *net.Session, p *player.Player, mob *world.MobInstance) {
g.Combat.Leave(p.Name)
if p.HP <= 0 {
g.killPlayer(sess, p, mob)
return
}
if mob != nil && mob.HP <= 0 {
isTask := mob.IsTask()
p.Stats.RecordMobKill(mob.DefID)
if isTask {
complete := mob.CompleteMessage
if complete == "" {
complete = fmt.Sprintf("You finish your work on %s!", mobDisplayName(mob, true))
}
sess.WriteLine(g.colorize(sess, "victory", complete))
} else {
sess.WriteLine(g.colorize(sess, "victory", fmt.Sprintf("You have defeated %s!", mobDisplayName(mob, true))))
g.onAssassinKill(sess, p, mob)
}
if g.Hub != nil {
for _, other := range g.Hub.PlayersInRoom(p.RoomID) {
if other != sess && other.Player != nil {
if isTask {
other.WriteLine(g.colorize(other, "broadcast", fmt.Sprintf("%s finishes working on %s.", p.Name, mobDisplayName(mob, false))))
} else {
op := other.Player
mobLvl := mobCombatLevel(mob)
levelStr := g.levelColorize(other, op.CombatLevel(), mobLvl, fmt.Sprintf("(level %d)", mobLvl))
other.WriteLine(g.colorize(other, "broadcast", fmt.Sprintf("%s has slain %s %s!", p.Name, mobDisplayName(mob, false), levelStr)))
}
}
}
}
dropLabel := func() string {
if isTask {
return "You receive:"
}
dropper := mob.Name
if !mob.Unique {
dropper = "The " + mob.Name
}
return dropper + " drops:"
}()
if mob.Drops.Remains != "" {
g.World.AddReservedItem(p.RoomID, mob.Drops.Remains, 1, p.Name)
def, _ := g.ItemStore.Load(mob.Drops.Remains)
name := mob.Drops.Remains
if def != nil {
name = def.Name
}
coloredName := g.itemColorize(sess, def, name)
sess.WriteLine(fmt.Sprintf("%s %s", g.colorize(sess, "drop_message", dropLabel), coloredName))
}
if len(mob.Drops.Loot) > 0 {
for _, entry := range behavior.ResolveDropList(g.DataDir, mob.Drops.Loot) {
if entry.ItemID == "" {
continue
}
qty := entry.Quantity
if qty <= 0 {
qty = 1
}
g.World.AddReservedItem(p.RoomID, entry.ItemID, qty, p.Name)
def, _ := g.ItemStore.Load(entry.ItemID)
name := entry.ItemID
if def != nil {
name = def.Name
}
coloredName := g.itemColorize(sess, def, name)
if qty > 1 {
sess.WriteLine(fmt.Sprintf("%s %d x %s", g.colorize(sess, "drop_message", dropLabel), qty, coloredName))
} else {
sess.WriteLine(fmt.Sprintf("%s %s", g.colorize(sess, "drop_message", dropLabel), coloredName))
}
}
}
respawnTicks := engine.ToTicks(mob.RespawnTicks)
if respawnTicks <= 0 {
respawnTicks = engine.ToTicks(30)
}
instanceID := mob.InstanceID
if mob.SpawnedByTrigger {
g.Ticks.Subscribe(10, func() bool {
g.MobStore.RemoveInstance(instanceID)
return false
})
} else {
g.Ticks.Subscribe(respawnTicks, func() bool {
g.respawnMob(instanceID)
return false
})
}
g.writePrompt(sess)
}
}
// killPlayer handles a player death from any source (combat or a room hazard).
// mob may be nil (e.g. a hazard kill); it is only used for Dead Man's Switch
// retribution.
func (g *Game) killPlayer(sess *net.Session, p *player.Player, mob *world.MobInstance) {
if p.GodMode {
p.HP = 1
sess.WriteLine(g.colorize(sess, "miss", "Your divine power prevents death."))
g.writePrompt(sess)
return
}
g.Combat.Leave(p.Name)
if p.HasActiveTech("retribution") {
retDef := GetTechDef("retribution")
if retDef != nil && mob != nil && mob.HP > 0 {
retDmg := int(float64(p.MaxHP()) * retDef.Effects.RetributionPct)
if retDmg > 0 {
mob.HP -= retDmg
if mob.HP < 0 {
mob.HP = 0
}
sess.WriteLine(fmt.Sprintf("Dead Man's Switch activates! %s takes %d damage!",
mobDisplayName(mob, true), retDmg))
}
}
}
p.DeactivateAllTechs()
p.Stats.RecordDeath()
sess.WriteLine(g.colorize(sess, "death", "Oh dear, you are dead!"))
p.Action = nil
p.ClearMoveState()
p.HazardTimer = 0
if ss, ok := g.safespot.Get(p.Name); ok {
g.forceLeaveSafespot(sess, p, &ss, "")
}
g.dropItemsOnDeath(p)
p.HP = p.MaxHP()
p.RoomID = g.StartingRoom
g.AccountStore.SaveCharacter(p)
if g.Hub != nil {
g.Hub.EnterRoom(sess, p.RoomID)
}
g.doLook(sess)
g.writePrompt(sess)
}
func (g *Game) awardCombatXP(sess *net.Session, p *player.Player, dmg int, isRanged bool) []xpGain {
baseXP := dmg * 4
var gains []xpGain
if isRanged {
gains = []xpGain{
{string(player.Ranged), baseXP * 3 / 4},
{string(player.Hitpoints), baseXP / 4},
}
} else {
switch p.AttackStyle {
case player.Accurate:
gains = []xpGain{{string(player.Accuracy), baseXP * 3 / 4}, {string(player.Hitpoints), baseXP / 4}}
case player.Aggressive:
gains = []xpGain{{string(player.Strength), baseXP * 3 / 4}, {string(player.Hitpoints), baseXP / 4}}
case player.Defensive:
gains = []xpGain{{string(player.Defense), baseXP * 3 / 4}, {string(player.Hitpoints), baseXP / 4}}
case player.Balanced:
quarter := baseXP / 4
gains = []xpGain{
{string(player.Accuracy), quarter},
{string(player.Strength), quarter},
{string(player.Defense), quarter},
{string(player.Hitpoints), quarter},
}
}
}
for _, gain := range gains {
g.awardSkillXP(sess, p, player.SkillName(gain.Skill), gain.XP)
}
g.AccountStore.SaveCharacter(p)
return gains
}
func (g *Game) stopCombat(playerName string) {
if cs := g.Combat.Get(playerName); cs != nil {
g.Combat.Leave(playerName)
}
}
|