public bool Process(IEvent e)
        {
            if (e is PlayerInputEvent)
            {
                PlayerInputEvent inputEvent = e as PlayerInputEvent;
                Vector2          pos;

                if (!PlayerPositionsByUID.TryGetValue(inputEvent.PlayerUID, out pos))
                {
                    throw new Exception("Player moved that was not yet created: " + inputEvent.PlayerUID);
                }

                PlayerPositionsByUID[inputEvent.PlayerUID] = pos + NetworkGameMaster.DirectionToMovement(inputEvent.Direction);
            }
            else if (e is PlayerCreatedEvent)
            {
                PlayerCreatedEvent createdEvent = e as PlayerCreatedEvent;

                if (PlayerPositionsByUID.ContainsKey(createdEvent.PlayerUID))
                {
                    throw new Exception("Player was created for a second time: " + createdEvent.PlayerUID);
                }

                PlayerPositionsByUID[createdEvent.PlayerUID] = Vector2.zero;
            }

            return(true);
        }
Exemple #2
0
        public IEvent ApplyMod(DoPlayerInputMod c)
        {
            // Record old value
            PlayerInputEvent e = new PlayerInputEvent {
                Direction   = c.direction,
                PlayerUID   = uid,
                OldPosition = position
            };

            // Apply command
            position += NetworkGameMaster.DirectionToMovement(c.direction);
            position  = new Vector2(Mathf.Clamp(position.x, -1, 1), Mathf.Clamp(position.y, -1, 1));

            // Record new value
            e.NewPosition = position;

            return(e);
        }