server/mission_booths.go (2439B)
1 package main 2 3 import ( 4 "ao/server/gamedata" 5 "encoding/binary" 6 "time" 7 ) 8 9 func (server *server) missionBoothEligibility(client *worldClient, booth gamedata.MissionBooth) (uint32, bool) { 10 player := server.characters[client.id] 11 if player.playfield != booth.Playfield || client.equipment != nil || client.trade != nil { 12 return 0, false 13 } 14 position := predictedPosition(player, time.Now()) 15 x, y, z := position[0]-booth.Position[0], position[1]-booth.Position[1], position[2]-booth.Position[2] 16 definition := gamedata.ItemTemplates[booth.Template] 17 accepted := x*x+y*y+z*z <= 5*5 && itemStat(definition, 30)&8 != 0 && player.templateUseRequirementsMet(definition) 18 originator := itemStat(definition, 490) 19 for _, stat := range booth.Stats { 20 if stat[0] == 490 { 21 originator = stat[1] 22 } 23 } 24 25 // QuestBooth::Use requires two free inventory slots and a team for even origins. 26 free := 30 27 for _, item := range player.inventory.Items { 28 if item.Slot >= 64 { 29 free-- 30 } 31 } 32 return originator, accepted && free >= 2 && (originator%2 != 0 || player.team != nil) 33 } 34 35 func (server *server) handleMissionBoothUse(client *worldClient, body []byte) error { 36 if len(body) != 48 { 37 return nil 38 } 39 player := server.characters[client.id] 40 if !client.target || server.clients[client.id] != client || !client.ready || client.loading || player.health == 0 || 41 binary.BigEndian.Uint32(body[4:8]) != 50000 || binary.BigEndian.Uint32(body[8:12]) != client.id || 42 binary.BigEndian.Uint32(body[16:20]) != 0 || binary.BigEndian.Uint32(body[24:28]) != 3 || 43 binary.BigEndian.Uint32(body[28:32]) != 1 || binary.BigEndian.Uint32(body[32:36]) != 50000 || 44 binary.BigEndian.Uint32(body[36:40]) != client.id || binary.BigEndian.Uint32(body[40:44]) != 56001 { 45 return nil 46 } 47 sequence := binary.BigEndian.Uint32(body[20:24]) 48 if sequence <= client.useSequence { 49 return nil 50 } 51 client.useSequence = sequence 52 53 // Validate the authored object and its Use criteria before the native callback. 54 booth, exists := gamedata.MissionBooths[binary.BigEndian.Uint32(body[44:48])] 55 accepted := false 56 if exists { 57 _, accepted = server.missionBoothEligibility(client, booth) 58 } 59 60 // Opening the difficulty window does not accept a mission or grant rewards. 61 reply := append([]byte(nil), body[16:]...) 62 binary.BigEndian.PutUint32(reply, 2) 63 if accepted { 64 binary.BigEndian.PutUint32(reply, 1) 65 } 66 return client.send(n3Packet(0x52526858, 50000, client.id, reply)) 67 }