aorecomp

Anarchy Online classic in the browser

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


server/world_resource_contract_test.go (2906B)


      1 package main
      2 
      3 import (
      4 	"ao/server/gamedata"
      5 	"math"
      6 	"testing"
      7 )
      8 
      9 func TestWorldResourceDefinitionsRejectMixedOrUnknownAssets(t *testing.T) {
     10 	for _, invalid := range []string{"character body", "character appearance", "unknown template", "wrong mesh", "wrong status", "zero level", "inverted levels"} {
     11 		t.Run(invalid, func(t *testing.T) {
     12 			newWorldResourceWorld(t)
     13 			group := gamedata.NPCGroups["test/resource"]
     14 			switch invalid {
     15 			case "character body":
     16 				group.MonsterData = 17655
     17 			case "character appearance":
     18 				group.Appearance = 229
     19 			case "unknown template":
     20 				group.TemplateCode = "NONE"
     21 			case "wrong mesh":
     22 				group.StaticMesh = 55670
     23 			case "wrong status":
     24 				group.AppearanceStatus = "inferred_species"
     25 			case "zero level":
     26 				group.Levels = [2]uint16{0, 3}
     27 			case "inverted levels":
     28 				group.Levels = [2]uint16{4, 3}
     29 			}
     30 
     31 			definitions, err := readWorldResources()
     32 
     33 			if err == nil || definitions != nil {
     34 				t.Fatal("invalid world-resource contract produced a visible object or character fallback")
     35 			}
     36 		})
     37 	}
     38 }
     39 
     40 func TestWorldResourceExhaustionCannotPublishAPartialZone(t *testing.T) {
     41 	world := newWorldResourceWorld(t)
     42 	world.worldResources[1000003] = worldResource{950, [3]float32{54, 14, 56}, 150274, 4}
     43 	world.nextItem = math.MaxUint32 - 1
     44 	if err := world.flushWorld(); err != nil {
     45 		t.Fatal(err)
     46 	}
     47 
     48 	err := world.ensureWorldResources(950)
     49 	cold := newTestInventoryServer(t)
     50 
     51 	if err == nil || world.nextItem != math.MaxUint32-1 || cold.nextItem != math.MaxUint32-1 ||
     52 		len(world.items) != 0 || len(cold.items) != 0 || len(world.worldItems) != 0 || len(cold.worldItems) != 0 {
     53 		t.Fatal("exhausted zone allocation published its first item or wrapped the identity counter", err)
     54 	}
     55 }
     56 
     57 func TestReviewedBestEffortProfileRequiresItsExplicitTemplateBinding(t *testing.T) {
     58 	for _, scenario := range []struct {
     59 		code, status string
     60 		monster      uint32
     61 		accepted     bool
     62 	}{
     63 		{"SR01", "best_effort", 17708, true},
     64 		{"SR01", "inferred_species", 17708, true},
     65 		{"SR02", "best_effort", 17708, false},
     66 		{"SR01", "placeholder_creature", 17708, false},
     67 		{"SR01", "best_effort", 17655, false},
     68 		{"LEET", "best_effort", 17655, false},
     69 	} {
     70 		t.Run(scenario.code+"/"+scenario.status, func(t *testing.T) {
     71 			data := testNPCData()
     72 			group := &data.Playfields[0].Districts[0].Groups[0]
     73 			group.TemplateCode, group.MonsterData, group.AppearanceStatus = scenario.code, scenario.monster, scenario.status
     74 			group.Levels = [2]uint16{2, 2}
     75 			useNPCData(t, data)
     76 
     77 			world := newTestServer(t)
     78 			if err := world.flushWorld(); err != nil {
     79 				t.Fatal(err)
     80 			}
     81 			cold := newTestInventoryServer(t)
     82 
     83 			if (world.characters[1000000].combatProfile != nil) != scenario.accepted ||
     84 				(cold.characters[1000000].combatProfile != nil) != scenario.accepted {
     85 				t.Fatal("best-effort appearance bypassed or lost its explicit reviewed combat binding")
     86 			}
     87 		})
     88 	}
     89 }