aorecomp

Anarchy Online classic in the browser

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


server/item_catalog.go (3758B)


      1 package main
      2 
      3 import (
      4 	"ao/server/gamedata"
      5 	"fmt"
      6 	"html"
      7 	"io"
      8 	"strings"
      9 )
     10 
     11 var itemClassNames = map[uint32]string{0: "Miscellaneous", 1: "Weapon", 2: "Armor", 3: "Implant", 4: "NPC", 5: "Spirit", 6: "Utility", 7: "Tower"}
     12 
     13 func itemCatalogProperties(w io.Writer, item ownedItem, definition *gamedata.Item) {
     14 	fmt.Fprint(w, "<h2>Catalog properties</h2>")
     15 	fmt.Fprintf(w, "<table><tr><th scope='row'>Template</th><td>%d</td></tr><tr><th scope='row'>Template QL</th><td>%d</td></tr><tr><th scope='row'>Attribute QL</th><td>%d</td></tr><tr><th scope='row'>Native object type</th><td>%d</td></tr><tr><th scope='row'>Resource type</th><td>%d</td></tr>", definition.ID, *definition.Quality, item.Quality, definition.HeaderWords[0], definition.RecordType)
     16 	if item.templateStat(0)&0x04000000 != 0 {
     17 		fmt.Fprint(w, "<tr><th scope='row'>Shop sale</th><td>Not allowed (NoDrop)</td></tr>")
     18 	}
     19 	fmt.Fprint(w, "</table>")
     20 	fmt.Fprintf(w, "<table><tr><th>Field</th><th>ID</th><th>Value at QL %d</th><th>Meaning</th></tr>", item.Quality)
     21 	for _, stat := range definition.Stats {
     22 		name := gamedata.ItemStatNames[stat[0]]
     23 		if name == "" {
     24 			name = "Unknown attribute"
     25 		}
     26 		if stat[0] == 74 {
     27 			name = "Base price (unmodified)"
     28 		}
     29 		value := item.templateStat(stat[0])
     30 		fmt.Fprintf(w, "<tr><td>%s</td><td>%d</td><td>%d</td><td>%s</td></tr>", html.EscapeString(name), stat[0], value, html.EscapeString(itemCatalogStatMeaning(item, stat[0], value)))
     31 	}
     32 	fmt.Fprint(w, "</table>")
     33 }
     34 
     35 func itemCatalogStatMeaning(item ownedItem, stat, value uint32) string {
     36 	// Flag names follow CellAO.Enums.ItemFlags and CanFlags; see docs/items.md.
     37 	var bits []string
     38 	switch stat {
     39 	case 0:
     40 		bits = []string{
     41 			"Visible", "ModifiedDescription", "ModifiedName", "CanBeTemplateItem",
     42 			"TurnOnUse", "HasMultiplecount", "Locked", "Open",
     43 			"ItemSocialArmour", "TellCollision", "NoSelectionIndicator", "UseEmptyDestruct",
     44 			"Stationary", "Repulsive", "DefaultTarget", "ItemTextureOverride",
     45 			"Null", "HasAnimation", "HasRotation", "WantCollision",
     46 			"WantSignals", "HasSentFirstIir", "HasEnergy", "MirrorInLeftHand",
     47 			"IllegalClan", "IllegalOmni", "NoDrop", "Unique",
     48 			"CanBeAttacked", "DisableFalling", "HasDamage", "DisableStatelCollision",
     49 		}
     50 	case 30:
     51 		bits = []string{
     52 			"Carry", "Sit", "Wear", "Use", "ConfirmUse", "Consume", "TutorChip", "TutorDevice",
     53 			"BreakAndEnter", "Stackable", "NoAmmo", "Burst", "FlingShot", "FullAuto", "AimedShot", "Bow",
     54 			"ThrowAttack", "SneakAttack", "FastAttack", "DisarmTraps",
     55 			"AutoSelect", "ApplyOnFriendly", "ApplyOnHostile", "ApplyOnSelf",
     56 			"CantSplit", "Brawl", "Dimach", "EnableHandAttractors",
     57 			"CanBeWornWithSocialArmor", "CanParryRiposte", "CanBeParriedRiposted", "ApplyOnFightingTarget",
     58 		}
     59 	case 54:
     60 		return "Quality level"
     61 	case 74:
     62 		return "Base price"
     63 	case 76:
     64 		return itemClassNames[value]
     65 	case 88, 298:
     66 		// Placement bits are local to the weapon, clothing or implant page.
     67 		class := item.templateStat(76)
     68 		if class < 1 || class > 3 {
     69 			if value == 0 {
     70 				return "None"
     71 			}
     72 			return ""
     73 		}
     74 		if stat == 88 {
     75 			if value < 16 {
     76 				return equipmentSlots[(class-1)*16+value]
     77 			}
     78 			return ""
     79 		}
     80 		bits = make([]string, 32)
     81 		for bit := uint32(0); bit < 16; bit++ {
     82 			bits[bit] = equipmentSlots[(class-1)*16+bit]
     83 		}
     84 	case 426:
     85 		return "Vendor buys from player (%)"
     86 	case 427:
     87 		return "Vendor sells to player (%)"
     88 	default:
     89 		return ""
     90 	}
     91 
     92 	// Keep unrecognized placement bits visible instead of silently dropping them.
     93 	var names []string
     94 	for bit, name := range bits {
     95 		if value&(uint32(1)<<bit) != 0 {
     96 			if name == "" {
     97 				name = fmt.Sprintf("Unknown bit %d", bit)
     98 			}
     99 			names = append(names, name)
    100 		}
    101 	}
    102 	if len(names) == 0 {
    103 		return "None"
    104 	}
    105 	return strings.Join(names, ", ")
    106 }