server/arrival_hall.go (5105B)
1 package main 2 3 import ( 4 "ao/server/gamedata" 5 "slices" 6 "time" 7 ) 8 9 func arrivalHallSide(group string) (uint16, bool) { 10 // Original fixed placements identify the three representatives. See arrival-hall.md. 11 switch group { 12 case "4604/district/0/fixed/0": 13 return 1, true 14 case "4604/district/0/fixed/1": 15 return 0, true 16 case "4604/district/0/fixed/19": 17 return 2, true 18 } 19 return 0, false 20 } 21 22 func arrivalHallDialogue(group, choice string) gamedata.Dialogue { 23 side, _ := arrivalHallSide(group) 24 if choice == "goodbye" { 25 return gamedata.Dialogue{Text: "You can speak to the other representatives before deciding."} 26 } 27 if choice != "" { 28 return gamedata.Dialogue{} 29 } 30 // These concise instructions are provisional, not recovered original dialogue. 31 return gamedata.Dialogue{ 32 Text: []string{ 33 "You can remain neutral. If you are ready, I can send you to the Neutral Training ground with your starting map.", 34 "You can join the Clans. If you are ready, I can send you to the Clan Training ground with your starting map and Clan equipment.", 35 "You can join Omni-Tek. If you are ready, I can send you to the Omni Training ground with your starting map and Omni-Tek equipment.", 36 }[side], 37 Choices: []gamedata.DialogueChoice{ 38 {ID: "depart", Text: []string{"Remain neutral and enter the training ground.", "Join the Clans and enter the training ground.", "Join Omni-Tek and enter the training ground."}[side]}, 39 {ID: "goodbye", Text: "I want to look around first."}, 40 }, 41 } 42 } 43 44 func arrivalHallExit(position [3]float32) (uint16, bool) { 45 // Original OnCollide statels set Side at the three corridor ends. See arrival-hall.md. 46 for side, exit := range [3][3]float32{ 47 {182.74585, 1.3142736, 157.6853}, 48 {192.28783, 1.3145673, 157.6162}, 49 {172.67474, 1.3137777, 157.44034}, 50 } { 51 x, y, z := position[0]-exit[0], position[1]-exit[1], position[2]-exit[2] 52 if x*x+y*y+z*z <= 2*2 { 53 return uint16(side), true 54 } 55 } 56 return 0, false 57 } 58 59 func (server *server) leaveArrivalHall(client *worldClient, npcID uint32, side uint16) (string, error) { 60 player, npc := server.characters[client.id], server.characters[npcID] 61 if server.clients[client.id] != client || !client.ready || client.loading || player.health == 0 || 62 player.playfield != 4604 || unpackAppearance(player.appearance).Side != 0 { 63 return "", nil 64 } 65 position := predictedPosition(player, time.Now()) 66 selected, permitted := arrivalHallExit(position) 67 if npcID != 0 { 68 if npc == nil || !npc.npc || npc.playfield != 4604 || !client.npcs[npcID] { 69 return "", nil 70 } 71 selected, permitted = arrivalHallSide(npc.npcDefinitionID) 72 x, y, z := npc.position[0]-position[0], npc.position[1]-position[1], npc.position[2]-position[2] 73 permitted = permitted && x*x+y*y+z*z <= 10*10 74 } 75 if !permitted || selected != side { 76 return "", nil 77 } 78 if client.trade != nil || client.equipment != nil || client.shop != nil { 79 return "Finish your current trade before leaving the Arrival Hall.", nil 80 } 81 82 // Stage faction, arrival and the deferred faction items without changing live state. 83 start, err := server.startingPosition(side) 84 if err != nil { 85 return "", err 86 } 87 updated := *player 88 appearance := unpackAppearance(player.appearance) 89 appearance.Side = side 90 updated.appearance = appearance.packed() 91 updated.playfield, updated.position, updated.rotation, updated.returnDoor = start.Playfield, start.Position, start.Rotation, start.ReturnDoor 92 updated.inventory.Items = slices.Clone(player.inventory.Items) 93 templates := [][]uint32{{116697}, {116696, 96358}, {116693, 99719, 29426}}[side] 94 first, err := server.reserveItems(uint32(len(templates))) 95 if err != nil { 96 return "", err 97 } 98 updated.inventory.LastID = first - 1 99 for _, template := range templates { 100 slot := updated.inventory.freeSlot() 101 if slot == 94 { 102 return "Make room in your inventory for your starting map and equipment, then try leaving again.", nil 103 } 104 definition := gamedata.ItemTemplates[template] 105 updated.inventory.LastID++ 106 updated.inventory.Items = append(updated.inventory.Items, ownedItem{ 107 ID: updated.inventory.LastID, Type: definition.HeaderWords[0], Template: template, 108 Quality: *definition.Quality, Slot: slot, Count: 1, 109 }) 110 } 111 server.prepareUser(player, &updated) 112 store, err := server.itemStore(player, updated.inventory) 113 if err != nil { 114 return "", err 115 } 116 store.edited = []*character{&updated} 117 if err := server.writeItemStore(store); err != nil { 118 return "", err 119 } 120 121 // Departure is the one-time completion gate; reconnect resumes the committed zone. 122 updated.savedProfile, updated.savedPosition, updated.savedVitals = updated.profile(), start, updated.vitals() 123 updates := make(map[*worldClient][][]byte) 124 if client.dialogue != nil { 125 updates[client] = append(updates[client], npcDialoguePacket(0x270a4c62, client.id, client.dialogue.npc, []byte{0, 0, 0, 5, 0, 0, 0, 0})) 126 } 127 client.dialogue = nil 128 server.replaceUser(player, &updated, updates) 129 if err := server.transferPlayer(player); err != nil { 130 return "", err 131 } 132 server.sendCombatUpdates(updates) 133 return "", server.teleportUser(client, updated.userData(), 4604) 134 }