aorecomp

Anarchy Online classic in the browser

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


server/armor_overequipping.go (2128B)


      1 package main
      2 
      3 import "ao/server/gamedata"
      4 
      5 func (character *character) equipmentBonus(stat uint32) int32 {
      6 	// NPC foundations share the existing armor and all-off/all-def consumers.
      7 	if character.npc && character.combatProfile != nil {
      8 		return character.combatProfile.Modifiers[stat] + character.inventory.equipmentBonus(stat)
      9 	}
     10 	// FUN_100734e0's initialized table selects the bonuses affected by armor OE.
     11 	switch stat {
     12 	case 1, 90, 91, 92, 93, 94, 95, 96, 97, 118, 119, 120, 149, 168,
     13 		205, 206, 207, 208, 216, 217, 219, 225, 226, 227, 228, 229, 230, 231, 233, 234,
     14 		276, 277, 278, 279, 280, 281, 282, 311, 316, 317, 318, 341, 379, 380, 382, 383, 393:
     15 	default:
     16 		return character.inventory.equipmentBonus(stat)
     17 	}
     18 	if character.npc {
     19 		return character.inventory.equipmentBonus(stat)
     20 	}
     21 	var bonus int32
     22 	for _, item := range character.inventory.Items {
     23 		tier := uint32(0)
     24 		if item.Slot >= 16 && item.Slot < 32 && item.fitsEquipmentSlot(item.Slot) {
     25 			tier = character.armorOverequippingTier(item)
     26 		}
     27 		bonus += item.equipmentBonus(stat, tier)
     28 	}
     29 	return bonus
     30 }
     31 
     32 func (character *character) armorOverequippingTier(item ownedItem) uint32 {
     33 	// FUN_10062f80/10090f10 uses action 6 and every operator-2 criterion.
     34 	low, high := item.templateIDs()
     35 	first, second := gamedata.ItemTemplates[low], gamedata.ItemTemplates[high]
     36 	var tier uint32
     37 	for sectionIndex, section := range first.Sections {
     38 		if section.Actions == nil {
     39 			continue
     40 		}
     41 		for actionIndex, action := range *section.Actions {
     42 			if action.Type != 6 {
     43 				continue
     44 			}
     45 			for index, requirement := range action.Requirements {
     46 				if requirement.Operator != 2 {
     47 					continue
     48 				}
     49 				value := interpolateItemValue(requirement.Value, (*second.Sections[sectionIndex].Actions)[actionIndex].Requirements[index].Value, *first.Quality, *second.Quality, item.Quality)
     50 				if value == 0 {
     51 					continue
     52 				}
     53 				actual, known := character.effectiveStat(uint32(requirement.Stat))
     54 				if !known {
     55 					return 4
     56 				}
     57 				if actual < value {
     58 					tier = max(tier, min(4, uint32((int64(value)-int64(actual))*5/int64(value))))
     59 				}
     60 			}
     61 		}
     62 	}
     63 	return tier
     64 }