Пример #1
0
        public void OnPlayerMapUpdate(ushort id, Math.Vector2 position)
        {
            if (position == Math.Vector2.Zero)
            {
                // We have received an empty update, which means that we need to remove
                // the icon if it exists
                if (_mapIcons.TryGetValue(id, out _))
                {
                    RemovePlayerIcon(id);
                }

                return;
            }

            // If there does not exist a player icon for this id yet, we create it
            if (!_mapIcons.TryGetValue(id, out _))
            {
                CreatePlayerIcon(id, position);

                return;
            }

            // Check whether the object still exists
            var mapObject = _mapIcons[id];

            if (mapObject == null)
            {
                _mapIcons.Remove(id);
                return;
            }

            // Check if the transform is still valid and otherwise destroy the object
            // This is possible since whenever we receive a new update packet, we
            // will just create a new map icon
            var transform = mapObject.transform;

            if (transform == null)
            {
                Object.Destroy(mapObject);
                _mapIcons.Remove(id);
                return;
            }

            var unityPosition = new Vector3(position.X, position.Y);

            // Update the position of the player icon
            // TODO: prevent icon Z-fighting
            transform.localPosition = unityPosition;
        }
Пример #2
0
        private void CreatePlayerIcon(ushort id, Math.Vector2 position)
        {
            var gameMap = GetGameMap();

            if (gameMap == null)
            {
                return;
            }

            var compassIconPrefab = gameMap.compassIcon;

            if (compassIconPrefab == null)
            {
                Logger.Get().Error(this, "CompassIcon prefab is null");
                return;
            }

            // Create a new player icon relative to the game map
            var mapIcon = Object.Instantiate(
                compassIconPrefab,
                gameMap.gameObject.transform
                );

            mapIcon.SetActive(_displayingIcons);

            var unityPosition = new Vector3(position.X, position.Y);

            // Set the position of the player icon
            // Subtract ID * 0.01 from the Z position to prevent Z-fighting with the icons
            mapIcon.transform.localPosition = unityPosition - new Vector3(0f, 0f, id * 0.01f);

            // Remove the bob effect when walking with the map
            Object.Destroy(mapIcon.LocateMyFSM("Mapwalk Bob"));

            // Put it in the list
            _mapIcons[id] = mapIcon;
        }
Пример #3
0
        private void HeroControllerOnUpdate(On.HeroController.orig_Update orig, HeroController self)
        {
            // Execute the original method
            orig(self);

            // If we are not connect, we don't have to send anything
            if (!_netClient.IsConnected)
            {
                return;
            }

            var sendEmptyUpdate = false;

            if (!_gameSettings.AlwaysShowMapIcons)
            {
                if (!_gameSettings.OnlyBroadcastMapIconWithWaywardCompass)
                {
                    sendEmptyUpdate = true;
                }
                else
                {
                    // We do not always show map icons, but only when we are wearing wayward compass
                    // So we need to check whether we are wearing wayward compass
                    if (!PlayerData.instance.equippedCharm_2)
                    {
                        sendEmptyUpdate = true;
                    }
                }
            }

            if (sendEmptyUpdate)
            {
                if (_lastSentEmptyUpdate)
                {
                    return;
                }

                _netClient.UpdateManager.UpdatePlayerMapPosition(Math.Vector2.Zero);

                // Set the last position to zero, so that when we
                // equip it again, we immediately send the update since the position changed
                _lastPosition = Vector3.zero;

                _lastSentEmptyUpdate = true;

                return;
            }

            var newPosition = GetMapLocation();

            // Only send update if the position changed
            if (newPosition != _lastPosition)
            {
                var vec2 = new Math.Vector2(newPosition.x, newPosition.y);

                _netClient.UpdateManager.UpdatePlayerMapPosition(vec2);

                // Update the last position, since it changed
                _lastPosition = newPosition;

                _lastSentEmptyUpdate = false;
            }
        }
Пример #4
0
        public void UpdatePosition(Math.Vector2 position)
        {
            var unityPos = new Vector3(position.X, position.Y);

            GameObject.GetComponent <PositionInterpolation>().SetNewPosition(unityPos);
        }
Пример #5
0
        private void OnPlayerUpdate(On.HeroController.orig_Update orig, HeroController self)
        {
            // Make sure the original method executes
            orig(self);

            // Ignore player position updates on non-gameplay scenes
            var currentSceneName = SceneUtil.GetCurrentSceneName();

            if (SceneUtil.IsNonGameplayScene(currentSceneName))
            {
                return;
            }

            // If we are not connected, there is nothing to send to
            if (!_netClient.IsConnected)
            {
                return;
            }

            var heroTransform = HeroController.instance.transform;

            var newPosition = heroTransform.position;

            // If the position changed since last check
            if (newPosition != _lastPosition)
            {
                // Update the last position, since it changed
                _lastPosition = newPosition;

                if (_sceneChanged)
                {
                    _sceneChanged = false;


                    // Set some default values for the packet variables in case we don't have a HeroController instance
                    // This might happen when we are in a non-gameplay scene without the knight
                    var    position        = Math.Vector2.Zero;
                    var    scale           = Vector3.zero;
                    ushort animationClipId = 0;

                    // If we do have a HeroController instance, use its values
                    if (HeroController.instance != null)
                    {
                        var transform    = HeroController.instance.transform;
                        var transformPos = transform.position;

                        position        = new Math.Vector2(transformPos.x, transformPos.y);
                        scale           = transform.localScale;
                        animationClipId = (ushort)_animationManager.GetCurrentAnimationClip();
                    }

                    Logger.Get().Info(this, "Sending EnterScene packet");

                    _netClient.UpdateManager.SetEnterSceneData(
                        SceneUtil.GetCurrentSceneName(),
                        position,
                        scale.x > 0,
                        animationClipId
                        );
                }
                else
                {
                    // If this was not the first position update after a scene change,
                    // we can simply send a position update packet
                    _netClient.UpdateManager.UpdatePlayerPosition(new Math.Vector2(newPosition.x, newPosition.y));
                }
            }

            var newScale = heroTransform.localScale;

            // If the scale changed since last check
            if (newScale != _lastScale)
            {
                _netClient.UpdateManager.UpdatePlayerScale(newScale.x > 0);

                // Update the last scale, since it changed
                _lastScale = newScale;
            }
        }