aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


server/weapon_stats.go (4735B)


      1 package main
      2 
      3 import (
      4 	"ao/server/gamedata"
      5 	"slices"
      6 )
      7 
      8 func (item ownedItem) isWieldableWeapon() bool {
      9 	definition := gamedata.ItemTemplates[item.Template]
     10 	if item.Type != 51018 || definition == nil || definition.HeaderWords[0] != item.Type || definition.Undecoded != nil ||
     11 		!gamedata.ItemQualitySupported(item.Template, item.Quality) || item.templateStat(298)&64 == 0 ||
     12 		item.templateStat(285) < item.templateStat(286) {
     13 		return false
     14 	}
     15 
     16 	// Resource hits and wear events must be supported before any bonus applies.
     17 	for _, section := range definition.Sections {
     18 		if section.Type != 2 {
     19 			continue
     20 		}
     21 		if section.Subtype == 5 {
     22 			for _, function := range *section.Functions {
     23 				if function.ID == 53002 {
     24 					return false
     25 				}
     26 			}
     27 		}
     28 		if section.Subtype != 14 {
     29 			continue
     30 		}
     31 		for _, function := range *section.Functions {
     32 			// HeadText executes through the native presentation handler.
     33 			if function.ID == 53057 && function.HeaderWords == [2]uint32{0, 4} && function.ArgumentHeader == 9 &&
     34 				function.Target == 2 && len(function.Requirements) == 0 && function.TickCount == 1 && function.TickInterval == 0 &&
     35 				len(function.Arguments) == 2 && function.Arguments[0].String != nil && function.Arguments[1].Integer != nil {
     36 				continue
     37 			}
     38 			if !supportedEquipmentModifier(function) {
     39 				return false
     40 			}
     41 		}
     42 	}
     43 	return true
     44 }
     45 
     46 func interpolateWeapon(first, second *gamedata.Item, quality uint32) *gamedata.Item {
     47 	if first == second || quality == *first.Quality {
     48 		return first
     49 	}
     50 	if quality == *second.Quality {
     51 		return second
     52 	}
     53 
     54 	// Keep categorical properties from the nearer endpoint without editing the catalog.
     55 	weapon := *first
     56 	if quality-*first.Quality >= *second.Quality-quality {
     57 		weapon = *second
     58 	}
     59 	weapon.Quality, weapon.Stats = &quality, slices.Clone(weapon.Stats)
     60 	for index, stat := range weapon.Stats {
     61 		weapon.Stats[index][1] = interpolateItemStat(first, second, quality, stat[0])
     62 	}
     63 
     64 	// Combat's OE checks use the same interpolated wear thresholds as equip admission.
     65 	weapon.Sections = slices.Clone(weapon.Sections)
     66 	for sectionIndex, section := range weapon.Sections {
     67 		if section.Actions == nil {
     68 			continue
     69 		}
     70 		actions := slices.Clone(*section.Actions)
     71 		for actionIndex, action := range actions {
     72 			if action.Type != 8 {
     73 				continue
     74 			}
     75 			actions[actionIndex].Requirements = slices.Clone(action.Requirements)
     76 			for index := range actions[actionIndex].Requirements {
     77 				lower := (*first.Sections[sectionIndex].Actions)[actionIndex].Requirements[index]
     78 				upper := (*second.Sections[sectionIndex].Actions)[actionIndex].Requirements[index]
     79 				actions[actionIndex].Requirements[index].Value = interpolateItemValue(lower.Value, upper.Value, *first.Quality, *second.Quality, quality)
     80 			}
     81 		}
     82 		weapon.Sections[sectionIndex].Actions = &actions
     83 	}
     84 	return &weapon
     85 }
     86 
     87 func (character *character) effectiveStat(stat uint32) (int32, bool) {
     88 	switch stat {
     89 	case 4:
     90 		return int32(unpackAppearance(character.appearance).Breed), true
     91 	case 33:
     92 		return int32(unpackAppearance(character.appearance).Side), true
     93 	case 59:
     94 		return int32(unpackAppearance(character.appearance).Sex), true
     95 	case 89:
     96 		return int32(unpackAppearance(character.appearance).Race), true
     97 	case 16, 17, 18, 19, 20, 21:
     98 		return character.effectiveAbility(stat), true
     99 	case 37:
    100 		return int32(character.titleLevel()), true
    101 	case 54:
    102 		return int32(character.level), true
    103 	case 60, 368:
    104 		return int32(character.profession), true
    105 	case 61:
    106 		return int32(character.inventory.Credits), true
    107 	case 62:
    108 		return int32(character.inventory.ClanTokens), true
    109 	case 75:
    110 		return int32(character.inventory.OmniTokens), true
    111 	case 470, 471, 472:
    112 		return int32(character.inventory.MapFlags[stat-470]), true
    113 	}
    114 	stats := character.baseStats()
    115 	for _, field := range stats.trainingStats() {
    116 		if field.stat == stat {
    117 			return character.effectiveSkill(stat, *field.value, gamedata.IPTraining.Weights[stat]), true
    118 		}
    119 	}
    120 	return 0, false
    121 }
    122 
    123 func (character *character) weaponOverequippingTier(weapon *gamedata.Item) uint32 {
    124 	// kkr.dll 10090f10 scans every action-8 operator-2 predicate, including title.
    125 	var tier uint32
    126 	for _, section := range weapon.Sections {
    127 		if section.Actions == nil {
    128 			continue
    129 		}
    130 		for _, action := range *section.Actions {
    131 			if action.Type != 8 {
    132 				continue
    133 			}
    134 			for _, requirement := range action.Requirements {
    135 				if requirement.Operator == 2 && requirement.Value != 0 {
    136 					actual, known := character.effectiveStat(uint32(requirement.Stat))
    137 					if !known {
    138 						return 4
    139 					}
    140 					if actual < requirement.Value {
    141 						tier = max(tier, min(4, uint32((int64(requirement.Value)-int64(actual))*5/int64(requirement.Value))))
    142 					}
    143 				}
    144 			}
    145 		}
    146 	}
    147 	return tier
    148 }