server/profession_resources_test.go (2972B)
1 package main 2 3 import ( 4 "encoding/binary" 5 "fmt" 6 "testing" 7 ) 8 9 func TestProfessionResourcesReachFullCharacter(t *testing.T) { 10 for _, scenario := range []struct { 11 profession, level uint16 12 health, nano uint32 13 }{ 14 {1, 1, 37, 35}, {1, 15, 136, 91}, {1, 50, 431, 231}, 15 {1, 100, 931, 431}, {1, 150, 1531, 631}, {1, 190, 2121, 791}, 16 {2, 50, 381, 231}, {2, 190, 2311, 791}, {3, 190, 1171, 1741}, 17 {4, 50, 381, 231}, {4, 190, 1931, 791}, 18 {5, 1, 37, 36}, {5, 190, 1741, 1361}, {6, 190, 1741, 1361}, 19 {7, 190, 1741, 1361}, {8, 190, 1741, 1361}, 20 {9, 1, 38, 35}, {9, 190, 2311, 791}, 21 {10, 1, 37, 35}, {10, 14, 115, 87}, {10, 15, 121, 106}, 22 {10, 49, 325, 276}, {10, 50, 331, 331}, {10, 99, 625, 625}, 23 {10, 100, 631, 731}, {10, 149, 925, 1074}, {10, 150, 931, 1231}, 24 {10, 189, 1165, 1543}, {10, 190, 1171, 1931}, 25 {11, 190, 1171, 1931}, {12, 15, 121, 106}, {12, 190, 1171, 1931}, 26 } { 27 t.Run(fmt.Sprintf("profession%d/level%d", scenario.profession, scenario.level), func(t *testing.T) { 28 player := (userData{ID: 1, Appearance: 0x10, Level: scenario.level, 29 Profession: scenario.profession, Stats: testCharacterStats()}).character() 30 31 packet := fullCharacterPacket(player) 32 stats := make(map[uint32]uint32) 33 count := binary.BigEndian.Uint32(packet[64:68])/1009 - 1 34 for offset := 68; offset < 68+int(count)*8; offset += 8 { 35 stats[binary.BigEndian.Uint32(packet[offset:])] = binary.BigEndian.Uint32(packet[offset+4:]) 36 } 37 38 if stats[1] != scenario.health || stats[27] != scenario.health || stats[221] != scenario.nano || 39 stats[60] != uint32(scenario.profession) { 40 t.Fatalf("profession resources: health=%d/%d nano=%d profession=%d", stats[27], stats[1], stats[221], stats[60]) 41 } 42 }) 43 } 44 } 45 46 func TestProfessionEditClampsResourcesAndPersistsCoefficients(t *testing.T) { 47 for _, scenario := range []struct { 48 from, to uint16 49 health, nano uint32 50 }{ 51 {1, 10, 1171, 791}, {10, 1, 1171, 791}, 52 } { 53 t.Run(fmt.Sprintf("%dto%d", scenario.from, scenario.to), func(t *testing.T) { 54 t.Chdir(t.TempDir()) 55 world, _ := newCombatWorld(t) 56 player := world.newCharacter() 57 player.stats = testCharacterStats() 58 player.level, player.profession = 190, scenario.from 59 player.health, player.nano = player.maximumHealth(), player.maximumNano() 60 destination := player.userData() 61 destination.Profession = scenario.to 62 63 err := world.updateUser(destination) 64 restored := newTestInventoryServer(t).characters[1] 65 66 if err != nil || world.characters[1].health != scenario.health || world.characters[1].nano != scenario.nano { 67 t.Fatalf("profession edit resources: health=%d nano=%d error=%v", world.characters[1].health, world.characters[1].nano, err) 68 } 69 if restored.profession != scenario.to || restored.maximumHealth() != world.characters[1].maximumHealth() || 70 restored.maximumNano() != world.characters[1].maximumNano() { 71 t.Fatal("profession resource coefficients changed across restart") 72 } 73 }) 74 } 75 }