Beispiel #1
0
        public void UpdateExtendedPinData()
        {
            if (m_nview == null)
            {
                return;
            }

            var extendedPinData = ExtendedPinData.SerializeList();

            m_nview.ClaimOwnership();
            m_nview.GetZDO().Set(nameof(extendedPinData), extendedPinData);
            Utils.Log("Writing ExtendedPinData");
        }
        public static void MergeSharedMapPinData(List <Minimap.PinData> sharedMapPins, List <Minimap.PinData> playerPins,
                                                 Minimap minimap, Dictionary <string, PlayerSyncData> playerSyncDatas, Dictionary <string, ExtendedPinData> extendedPinDatas)
        {
            if (sharedMapPins == null || playerSyncDatas == null || extendedPinDatas == null)
            {
                return;
            }

            Utils.Log("mergeSharedMapPinData executing.");
            //Build some hashes
            var sharedMapPinsDict = new Dictionary <string, Minimap.PinData>();
            var playerPinsDict    = new Dictionary <string, Minimap.PinData>();

            sharedMapPins.ForEach(p =>
            {
                sharedMapPinsDict[GetPinKey(p)] = p;
            });

            playerPins.ForEach(p =>
            {
                playerPinsDict[GetPinKey(p)] = p;
            });

            Utils.Log("Hashes built.");
            //Get last player sync date
            var lastSyncDate = DateTime.MinValue;

            if (playerSyncDatas.ContainsKey(Player.m_localPlayer.GetPlayerName()))
            {
                lastSyncDate = playerSyncDatas[Player.m_localPlayer.GetPlayerName()].SyncDate;
                Utils.Log($"Last player sync: {lastSyncDate}");
            }
            else
            {
                Utils.Log($"No last player sync for {Player.m_localPlayer.GetPlayerName()}");
            }

            //Delete any pins from incoming data player has removed since last sync - from the shared map pins dict and list
            DeleteRemovedPinsFromSharedMap(lastSyncDate, sharedMapPins, sharedMapPinsDict, playerPinsDict, extendedPinDatas);
            DeleteRemovedPinsFromPlayer(playerPinsDict, extendedPinDatas, minimap);

            //If the player is sharing their own pins, add them to the shared and extended pin data
            if (Settings.MapSettings.SendPinShares.Value)
            {
                playerPins.ForEach(p =>
                {
                    var pKey = GetPinKey(p);
                    sharedMapPinsDict[pKey] = p;
                    extendedPinDatas[pKey]  = new ExtendedPinData(pKey, DateTime.Now, false);
                });
            }

            //add any pins to the map from incoming data that the player is missing
            foreach (var pin in sharedMapPinsDict)
            {
                var pVal = pin.Value;
                if (!playerPinsDict.ContainsKey(pin.Key))
                {
                    minimap.AddPin(pVal.m_pos, pVal.m_type, pVal.m_name, pVal.m_save, pVal.m_checked);
                }
            }
        }