aorecomp

Anarchy Online classic in the browser

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


server/stat_equipment.go (2240B)


      1 package main
      2 
      3 import "ao/server/gamedata"
      4 
      5 func hasEquipmentStatConsumer(stat uint32) bool {
      6 	if stat >= 16 && stat <= 21 || stat >= 90 && stat <= 97 || stat >= 100 && stat <= 168 {
      7 		return true
      8 	}
      9 	switch stat {
     10 	case 1, 45, 51, 181, 221, 276, 277, 278, 279, 280, 281, 282, 311, 316, 317, 318, 319, 343, 360, 364, 379, 380, 381, 382:
     11 		return true
     12 	}
     13 	return false
     14 }
     15 
     16 func supportedEquipmentModifier(function gamedata.ItemFunction) bool {
     17 	if function.HeaderWords != [2]uint32{0, 4} || function.ArgumentHeader != 9 || function.Target != 2 ||
     18 		len(function.Requirements) != 0 || function.TickCount != 1 || function.TickInterval != 0 ||
     19 		len(function.Arguments) < 2 || function.Arguments[0].Integer == nil || function.Arguments[1].Integer == nil ||
     20 		!hasEquipmentStatConsumer(uint32(*function.Arguments[0].Integer)) {
     21 		return false
     22 	}
     23 	switch function.ID {
     24 	case 53045:
     25 		return len(function.Arguments) == 2
     26 	case 53012:
     27 		return len(function.Arguments) == 3 && function.Arguments[2].BytesHex != nil && *function.Arguments[2].BytesHex == "00000000"
     28 	}
     29 	return false
     30 }
     31 
     32 func (item ownedItem) isStatEquipment() bool {
     33 	definition := gamedata.ItemTemplates[item.Template]
     34 	if item.Type != 51022 || definition == nil || definition.HeaderWords[0] != item.Type ||
     35 		definition.Undecoded != nil ||
     36 		(itemStat(definition, 76) != 1 && itemStat(definition, 76) != 2) || itemStat(definition, 30)&4 == 0 ||
     37 		!gamedata.ItemQualitySupported(item.Template, item.Quality) {
     38 		return false
     39 	}
     40 
     41 	// Admit stat modifiers and native presentation, not unimplemented gameplay effects.
     42 	for _, section := range definition.Sections {
     43 		if section.Type != 2 {
     44 			continue
     45 		}
     46 		// Tower contracts require effects outside ordinary OnWear admission.
     47 		if section.Subtype == 26 {
     48 			return false
     49 		}
     50 		if section.Subtype != 14 {
     51 			continue
     52 		}
     53 		for _, function := range *section.Functions {
     54 			switch function.ID {
     55 			case 53012, 53045:
     56 				if !supportedEquipmentModifier(function) {
     57 					return false
     58 				}
     59 			case 53030, 53035, 53037, 53038, 53039, 53054, 53055, 53079:
     60 				// Mesh, texture and visual effects execute in the native client.
     61 			default:
     62 				// A client no-op does not establish a server-side no-op.
     63 				return false
     64 			}
     65 		}
     66 	}
     67 	return true
     68 }