Multi-target slapping in the house.

This commit is contained in:
2024-12-12 07:42:08 -05:00
parent 913d5e93d4
commit fe428bee12

View File

@@ -26,6 +26,7 @@ type ClientData struct {
Position gamedata.Coordinates Position gamedata.Coordinates
Hit bool Hit bool
Target int Target int
Targets []int
Slapping bool Slapping bool
} }
@@ -137,6 +138,7 @@ func (s *Server) HandleClient(conn net.Conn, id int) {
//collision, mark it //collision, mark it
cd.Hit = true cd.Hit = true
cd.Target = client.Id cd.Target = client.Id
cd.Targets = append(cd.Targets, client.Id)
} }
} }
@@ -145,11 +147,15 @@ func (s *Server) HandleClient(conn net.Conn, id int) {
s.clientlist[conn] = cd s.clientlist[conn] = cd
s.mu.Unlock() s.mu.Unlock()
case *pb.ClientEnvelope_Slap: case *pb.ClientEnvelope_Slap:
if s.clientlist[conn].Target != 0 && s.clientlist[conn].Hit {
s.BroadcastSlap(id, s.clientlist[conn].Target) s.mu.Lock()
} else { slapper := s.clientlist[conn]
fmt.Println("Invalid slap detected.") s.mu.Unlock()
for _, target := range slapper.Targets {
s.BroadcastSlap(id, target)
} }
} }
} }