server/brawl.go (1847B)
1 package main 2 3 import ( 4 "ao/server/gamedata" 5 "math/rand/v2" 6 "slices" 7 "time" 8 ) 9 10 func (character *character) brawlStunned() bool { 11 return slices.ContainsFunc(character.activeNanos, func(effect activeNano) bool { return effect.program == 125772 }) 12 } 13 14 func (server *server) prepareBrawl(player, target *character, now time.Time) (character, bool) { 15 // Provisional server selector, independent of the native actor-level initializer. 16 skill, _ := player.effectiveStat(142) 17 quality := uint32(min(500, max(1, skill/2))) 18 weapon := interpolateWeapon(gamedata.ItemTemplates[70292], gamedata.ItemTemplates[70293], quality) 19 roll := server.combatRoll 20 if roll == nil { 21 roll = rand.Uint32N 22 } 23 damage := uint32(0) 24 if server.itemAttackLands(player, target, weapon) { 25 chance := min(100, max(0, int64(3)+int64(player.equipmentBonus(379))+int64(player.nanoBonus(379)))) 26 critical := int64(roll(100)) < chance 27 damage = min(target.health, player.itemDamage(target, weapon, critical, roll)) 28 } 29 candidate := server.prepareWeaponDamage(player, target, damage, now) 30 // Authored OnUse can stun even on a miss. Refresh this program only; no NCU debit. 31 chance := uint32(interpolateItemValue(10, 20, 1, 500, quality)) 32 stunned := candidate.health != 0 && roll(100) < chance 33 if stunned { 34 candidate.activeNanos = slices.DeleteFunc(slices.Clone(candidate.activeNanos), func(effect activeNano) bool { return effect.program == 125772 }) 35 candidate.activeNanos = append(candidate.activeNanos, activeNano{program: 125772, caster: player.id, remaining: 3 * time.Second, expiresAt: now.Add(3 * time.Second)}) 36 if candidate.motion != nil { 37 motion := *candidate.motion 38 motion.moving = false 39 candidate.motion, candidate.running = &motion, false 40 } 41 candidate.movement.velocity, candidate.movement.speed = [3]float32{}, 0 42 } 43 return candidate, stunned 44 }