server/stats.go (8873B)
1 package main 2 3 import "ao/server/gamedata" 4 5 type characterStats struct { 6 ImprovementPoints uint32 7 Abilities characterAbilitiesStats 8 Body characterBodyStats 9 Melee characterMeleeStats 10 MiscWeapons characterMiscWeaponsStats 11 Ranged characterRangedStats 12 Speed characterSpeedStats 13 TradeRepair characterTradeRepairStats 14 NanoAiding characterNanoAidingStats 15 Spying characterSpyingStats 16 Navigation characterNavigationStats 17 } 18 19 type characterAbilitiesStats struct { 20 Strength uint16 21 Agility uint16 22 Stamina uint16 23 Intelligence uint16 24 Sense uint16 25 Psychic uint16 26 } 27 28 type characterBodyStats struct { 29 MartialArts uint16 30 Brawling uint16 31 Riposte uint16 32 Dimach uint16 33 Adventuring uint16 34 Swimming uint16 35 BodyDevelopment uint16 36 NanoPool uint16 37 } 38 39 type characterMeleeStats struct { 40 OneHandBlunt uint16 41 OneHandEdged uint16 42 Piercing uint16 43 TwoHandBlunt uint16 44 TwoHandEdged uint16 45 MeleeEnergy uint16 46 Parry uint16 47 SneakAttack uint16 48 MultiMelee uint16 49 FastAttack uint16 50 } 51 52 type characterMiscWeaponsStats struct { 53 SharpObjects uint16 54 Grenade uint16 55 HeavyWeapons uint16 56 } 57 58 type characterRangedStats struct { 59 Bow uint16 60 Pistol uint16 61 AssaultRifle uint16 62 SubmachineGun uint16 63 Shotgun uint16 64 Rifle uint16 65 RangedEnergy uint16 66 FlingShot uint16 67 AimedShot uint16 68 Burst uint16 69 FullAuto uint16 70 BowSpecialAttack uint16 71 MultiRanged uint16 72 } 73 74 type characterSpeedStats struct { 75 MeleeInitiative uint16 76 RangedInitiative uint16 77 PhysicalInitiative uint16 78 NanoInitiative uint16 79 DodgeRanged uint16 80 EvadeClose uint16 81 DuckExplosions uint16 82 NanoResist uint16 83 RunSpeed uint16 84 } 85 86 type characterTradeRepairStats struct { 87 MechanicalEngineering uint16 88 ElectricalEngineering uint16 89 QuantumFieldTechnology uint16 90 WeaponSmithing uint16 91 PharmaceuticalTechnology uint16 92 NanoProgramming uint16 93 ComputerLiteracy uint16 94 Psychology uint16 95 Chemistry uint16 96 Tutoring uint16 97 } 98 99 type characterNanoAidingStats struct { 100 MatterMetamorphosis uint16 101 BiologicalMetamorphosis uint16 102 PsychologicalModification uint16 103 MatterCreation uint16 104 TimeAndSpace uint16 105 SensoryImprovement uint16 106 FirstAid uint16 107 Treatment uint16 108 } 109 110 type characterSpyingStats struct { 111 Concealment uint16 112 BreakingAndEntering uint16 113 TrapDisarm uint16 114 Perception uint16 115 } 116 117 type characterNavigationStats struct { 118 VehicleAir uint16 119 VehicleGround uint16 120 VehicleWater uint16 121 MapNavigation uint16 122 } 123 124 func defaultCharacterStats(breed uint16) characterStats { 125 abilities := gamedata.IPTraining.Breeds[breed].Base 126 return characterStats{ 127 ImprovementPoints: 1500, 128 Abilities: characterAbilitiesStats{uint16(abilities[0]), uint16(abilities[1]), uint16(abilities[2]), uint16(abilities[3]), uint16(abilities[4]), uint16(abilities[5])}, 129 Body: characterBodyStats{5, 5, 5, 5, 5, 5, 5, 5}, 130 Melee: characterMeleeStats{5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, 131 MiscWeapons: characterMiscWeaponsStats{5, 5, 5}, 132 Ranged: characterRangedStats{5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, 133 Speed: characterSpeedStats{5, 5, 5, 5, 5, 5, 5, 5, 5}, 134 TradeRepair: characterTradeRepairStats{5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, 135 NanoAiding: characterNanoAidingStats{5, 5, 5, 5, 5, 5, 5, 5}, 136 Spying: characterSpyingStats{5, 5, 5, 5}, 137 Navigation: characterNavigationStats{5, 5, 5, 5}, 138 } 139 } 140 141 func (character *character) baseStats() characterStats { 142 if character.stats == (characterStats{}) { 143 breed := character.appearance >> 4 & 7 144 // Nonplayer breed codes retain the default player skill foundation. 145 if _, exists := gamedata.IPTraining.Breeds[breed]; !exists { 146 breed = 1 147 } 148 stats := defaultCharacterStats(breed) 149 if character.npc && character.combatProfile != nil { 150 for _, field := range stats.trainingStats() { 151 if value, exists := character.combatProfile.Skills[field.stat]; exists { 152 *field.value = uint16(value) 153 } 154 } 155 } 156 return stats 157 } 158 return character.stats 159 } 160 161 func (character *character) effectiveAbility(stat uint32) int32 { 162 abilities := character.baseStats().Abilities 163 values := [6]uint16{abilities.Strength, abilities.Agility, abilities.Stamina, abilities.Intelligence, abilities.Sense, abilities.Psychic} 164 base := int32(values[stat-16]) 165 return base - character.shockReduction(base) + character.inventory.equipmentBonus(stat) + character.nanoBonus(stat) 166 } 167 168 func (character *character) effectiveSkill(stat uint32, base uint16, weights [6]uint32) int32 { 169 // kkr.dll FUN_10073fa0, weights from resource type 1000204. 170 var weighted int32 171 for index, weight := range weights { 172 weighted += character.effectiveAbility(16+uint32(index)) * int32(weight) 173 } 174 // Preserve the native float constants before truncating at integer boundaries. 175 value := int32(base) + int32(float64(weighted)*float64(float32(0.01))*0.25) 176 return value - character.shockReduction(value) + character.equipmentBonus(stat) + character.nanoBonus(stat) 177 } 178 179 func (character *character) shockReduction(base int32) int32 { 180 // kkr.dll FUN_10074a30 scales the unmodified value using float32 .0001. 181 return int32(float64(character.resurrectionShock) * float64(base) * float64(float32(0.0001))) 182 } 183 184 type trainedStat struct { 185 stat uint32 186 value *uint16 187 } 188 189 func (stats *characterStats) trainingStats() []trainedStat { 190 return []trainedStat{ 191 {16, &stats.Abilities.Strength}, 192 {17, &stats.Abilities.Agility}, 193 {18, &stats.Abilities.Stamina}, 194 {19, &stats.Abilities.Intelligence}, 195 {20, &stats.Abilities.Sense}, 196 {21, &stats.Abilities.Psychic}, 197 {100, &stats.Body.MartialArts}, 198 {142, &stats.Body.Brawling}, 199 {143, &stats.Body.Riposte}, 200 {144, &stats.Body.Dimach}, 201 {137, &stats.Body.Adventuring}, 202 {138, &stats.Body.Swimming}, 203 {152, &stats.Body.BodyDevelopment}, 204 {132, &stats.Body.NanoPool}, 205 {102, &stats.Melee.OneHandBlunt}, 206 {103, &stats.Melee.OneHandEdged}, 207 {106, &stats.Melee.Piercing}, 208 {107, &stats.Melee.TwoHandBlunt}, 209 {105, &stats.Melee.TwoHandEdged}, 210 {104, &stats.Melee.MeleeEnergy}, 211 {145, &stats.Melee.Parry}, 212 {146, &stats.Melee.SneakAttack}, 213 {101, &stats.Melee.MultiMelee}, 214 {147, &stats.Melee.FastAttack}, 215 {108, &stats.MiscWeapons.SharpObjects}, 216 {109, &stats.MiscWeapons.Grenade}, 217 {110, &stats.MiscWeapons.HeavyWeapons}, 218 {111, &stats.Ranged.Bow}, 219 {112, &stats.Ranged.Pistol}, 220 {116, &stats.Ranged.AssaultRifle}, 221 {114, &stats.Ranged.SubmachineGun}, 222 {115, &stats.Ranged.Shotgun}, 223 {113, &stats.Ranged.Rifle}, 224 {133, &stats.Ranged.RangedEnergy}, 225 {150, &stats.Ranged.FlingShot}, 226 {151, &stats.Ranged.AimedShot}, 227 {148, &stats.Ranged.Burst}, 228 {167, &stats.Ranged.FullAuto}, 229 {121, &stats.Ranged.BowSpecialAttack}, 230 {134, &stats.Ranged.MultiRanged}, 231 {118, &stats.Speed.MeleeInitiative}, 232 {119, &stats.Speed.RangedInitiative}, 233 {120, &stats.Speed.PhysicalInitiative}, 234 {149, &stats.Speed.NanoInitiative}, 235 {154, &stats.Speed.DodgeRanged}, 236 {155, &stats.Speed.EvadeClose}, 237 {153, &stats.Speed.DuckExplosions}, 238 {168, &stats.Speed.NanoResist}, 239 {156, &stats.Speed.RunSpeed}, 240 {125, &stats.TradeRepair.MechanicalEngineering}, 241 {126, &stats.TradeRepair.ElectricalEngineering}, 242 {157, &stats.TradeRepair.QuantumFieldTechnology}, 243 {158, &stats.TradeRepair.WeaponSmithing}, 244 {159, &stats.TradeRepair.PharmaceuticalTechnology}, 245 {160, &stats.TradeRepair.NanoProgramming}, 246 {161, &stats.TradeRepair.ComputerLiteracy}, 247 {162, &stats.TradeRepair.Psychology}, 248 {163, &stats.TradeRepair.Chemistry}, 249 {141, &stats.TradeRepair.Tutoring}, 250 {127, &stats.NanoAiding.MatterMetamorphosis}, 251 {128, &stats.NanoAiding.BiologicalMetamorphosis}, 252 {129, &stats.NanoAiding.PsychologicalModification}, 253 {130, &stats.NanoAiding.MatterCreation}, 254 {131, &stats.NanoAiding.TimeAndSpace}, 255 {122, &stats.NanoAiding.SensoryImprovement}, 256 {123, &stats.NanoAiding.FirstAid}, 257 {124, &stats.NanoAiding.Treatment}, 258 {164, &stats.Spying.Concealment}, 259 {165, &stats.Spying.BreakingAndEntering}, 260 {135, &stats.Spying.TrapDisarm}, 261 {136, &stats.Spying.Perception}, 262 {139, &stats.Navigation.VehicleAir}, 263 {166, &stats.Navigation.VehicleGround}, 264 {117, &stats.Navigation.VehicleWater}, 265 {140, &stats.Navigation.MapNavigation}, 266 } 267 } 268 269 func (stats characterStats) nativeStats() [][2]uint32 { 270 values := [][2]uint32{{53, stats.ImprovementPoints}} 271 for _, field := range stats.trainingStats() { 272 values = append(values, [2]uint32{field.stat, uint32(*field.value)}) 273 } 274 return values 275 }