Пример #1
0
        public void Update()
        {
            if (Find.VisibleMap != null)
            {
                try
                {
                    var colonistsToSend = new List <ColonistData>();

                    foreach (Pawn current in PawnsFinder.AllMapsAndWorld_Alive)
                    {
                        if (current.IsColonist)
                        {
                            var newColonist = new ColonistData {
                                ID = current.ThingID, Name = current.Name.ToStringShort, CurrentJob = current.jobs.curDriver.GetReport().CapitalizeFirst()
                            };
                            var newColonistHash = HashColonist(newColonist);

                            if (_colonistHashes.ContainsKey(newColonist.ID))
                            {
                                var currentColonistHash = _colonistHashes[newColonist.ID];
                                if (currentColonistHash != newColonistHash)
                                {
                                    colonistsToSend.Add(newColonist);
                                    _colonistHashes[newColonist.ID] = newColonistHash;
                                }
                            }
                            else
                            {
                                _colonistHashes[newColonist.ID] = newColonistHash;
                                colonistsToSend.Add(newColonist);
                            }
                        }
                    }
                    if (colonistsToSend.Count > 0)
                    {
                        SendPacket(ListToJson(colonistsToSend));
                    }
                }
                catch (Exception ex)
                {
                    enabled = false;
                    Log.Error(ex.Message);
                }
            }
        }
Пример #2
0
        // Works
        private string HashColonist(ColonistData colonist)
        {
            var text = colonist.ID + colonist.Name + colonist.CurrentJob;

            return(Base64Encode(text));
        }