server/starter_professions_test.go (4739B)
1 package main 2 3 import ( 4 "encoding/binary" 5 "fmt" 6 "net/http" 7 "reflect" 8 "slices" 9 "testing" 10 ) 11 12 func TestCreatedProfessionsCanLearnTheirIssuedCrystalsAtLevelOne(t *testing.T) { 13 world := newTestServer(t) 14 var created []uint32 15 for _, scenario := range []struct { 16 profession uint16 17 skills map[uint32]uint16 18 crystals, programs []uint32 19 }{ 20 {1, map[uint32]uint16{128: 8, 130: 6}, []uint32{29092}, []uint32{29091}}, 21 {2, map[uint32]uint16{129: 8, 122: 7}, []uint32{43382}, []uint32{43369}}, 22 {3, map[uint32]uint16{130: 7, 131: 7, 127: 7, 122: 6}, []uint32{43329, 29194}, []uint32{43325, 29188}}, 23 {4, map[uint32]uint16{129: 9, 122: 8}, []uint32{43380}, []uint32{43370}}, 24 {5, map[uint32]uint16{127: 7, 122: 9, 129: 8}, []uint32{43383, 29191}, []uint32{43367, 29153}}, 25 {6, map[uint32]uint16{128: 7, 127: 6}, []uint32{28742}, []uint32{26695}}, 26 {7, map[uint32]uint16{128: 9, 131: 8}, []uint32{43378, 78417}, []uint32{43374, 76742}}, 27 {8, map[uint32]uint16{129: 8, 131: 7, 130: 7}, []uint32{43381, 29625}, []uint32{43368, 29618}}, 28 {9, map[uint32]uint16{129: 7, 122: 6}, []uint32{43379}, []uint32{43371}}, 29 {10, map[uint32]uint16{128: 9, 127: 6, 130: 8}, []uint32{28778, 43384}, []uint32{28665, 43376}}, 30 {11, map[uint32]uint16{130: 9, 131: 7}, []uint32{28815, 42111}, []uint32{28612, 42110}}, 31 {12, map[uint32]uint16{130: 8, 131: 7, 129: 6}, []uint32{43330, 29193}, []uint32{43324, 29114}}, 32 } { 33 t.Run(fmt.Sprint(scenario.profession), func(t *testing.T) { 34 fields := creationForm() 35 fields.Set("profession", fmt.Sprint(scenario.profession)) 36 fields.Set("name", fmt.Sprintf("Profession%d", scenario.profession)) 37 if response := creationRequest(world, accountVisitor(t, world), fields); response.Code != http.StatusNoContent { 38 t.Fatal(response.Code, response.Body.String()) 39 } 40 player := world.characters[world.nextCharacter] 41 client := &worldClient{id: player.id, conn: &combatTestConn{}, target: true, ready: true} 42 world.clients[player.id] = client 43 created = append(created, player.id) 44 before := slices.Clone(player.inventory.Items) 45 46 // Train only the nano skills needed by this Solitus starter kit, using its IP. 47 trained := player.baseStats() 48 for _, field := range trained.trainingStats() { 49 if value, ok := scenario.skills[field.stat]; ok { 50 *field.value = value 51 } 52 } 53 request := skillTrainingRequest(trained) 54 binary.BigEndian.PutUint32(request[28:32], player.id) 55 if err := world.handleSkillTraining(client, request[20:]); err != nil { 56 t.Fatal(err) 57 } 58 if player.stats.ImprovementPoints >= 1500 || player.level != 1 { 59 t.Fatal("starter training was refused") 60 } 61 for _, field := range player.stats.trainingStats() { 62 if value, ok := scenario.skills[field.stat]; ok && *field.value != value { 63 t.Fatal("starter training exceeded its cap or budget", field.stat, *field.value, value) 64 } 65 } 66 67 // Upload the exact issued instances through ordinary inventory Use requests. 68 remaining := slices.Clone(before) 69 for sequence, crystal := range scenario.crystals { 70 index := slices.IndexFunc(before, func(item ownedItem) bool { return item.Template == crystal }) 71 if index < 0 { 72 t.Fatal("missing issued crystal", crystal) 73 } 74 if err := world.handleOwnedItemUse(client, backpackUseRequest(player.id, before[index].Slot, uint32(sequence+1))[20:]); err != nil { 75 t.Fatal(err) 76 } 77 remaining = slices.DeleteFunc(remaining, func(item ownedItem) bool { return item.Template == crystal }) 78 } 79 80 if !slices.Equal(player.inventory.LearnedNanos, scenario.programs) || !reflect.DeepEqual(player.inventory.Items, remaining) || player.experience != 0 || player.inventory.Credits != 0 { 81 t.Fatal("issued crystal admission changed the starter kit", player.inventory.LearnedNanos, scenario.programs) 82 } 83 t.Logf("profession %d: %d issued crystals learned, %d IP remaining", scenario.profession, len(scenario.crystals), player.stats.ImprovementPoints) 84 }) 85 } 86 87 // Recover all independently owned kits together without rebuilding world fixtures. 88 cold := newTestInventoryServer(t) 89 if cold.nextItem != world.nextItem { 90 t.Fatal("recovery changed the shared item allocator") 91 } 92 for _, id := range created { 93 player, restored := world.characters[id], cold.characters[id] 94 programs := slices.Clone(player.inventory.LearnedNanos) 95 slices.Sort(programs) 96 if !reflect.DeepEqual(player.inventory.Items, restored.inventory.Items) || !slices.Equal(programs, restored.inventory.LearnedNanos) || restored.inventory.Credits != 0 || !reflect.DeepEqual(player.stats, restored.stats) || restored.level != 1 || restored.experience != 0 { 97 t.Fatal("starter learning or training changed on recovery", id) 98 } 99 } 100 }