Example #1
0
        private bool ReceiveWorldState(ArraySegment <byte> rawData)
        {
            Logger.Debug("Total: {sizeInMemory} bytes.", rawData.Count);
            InMemDriver stream = DeserializeWorldState(rawData);

            if (stream == null)
            {
                Logger.Error("Error during world state serialization. Abort.");
                return(false);
            }

            LoadGameResult loadResult = SaveLoad.LoadSaveGameData(stream);

            if (loadResult == null)
            {
                Logger.Error("Unable to load world state. Abort.");
                return(false);
            }

            if (loadResult.LoadResult.Successful)
            {
                Logger.Info(loadResult.ToFriendlyString());
            }
            else
            {
                Logger.Error(loadResult.ToFriendlyString());
            }

            GameLoopRunner.RunOnMainThread(() => SaveLoad.LoadGame(loadResult.LoadResult));
            return(true);
        }
        public MobileParty GetMobilePartyByIndex(int iPartyIndex)
        {
            MobileParty ret = null;

            GameLoopRunner.RunOnMainThread(
                () =>
            {
                ret = MobileParty.All.SingleOrDefault(p => p.Party.Index == iPartyIndex);
            });
            return(ret);
        }
Example #3
0
        public byte[] SerializeInitialWorldState()
        {
            CampaignEventDispatcher.Instance.OnBeforeSave();

            // Save to memory
            InMemDriver  memStream = new InMemDriver();
            SaveGameData save      = null;

            GameLoopRunner.RunOnMainThread(() => save = SaveLoad.SaveGame(Game.Current, memStream));
            if (save == null)
            {
                throw new Exception("Saving the game failed. Abort.");
            }

            Logger.Info(save);

            // Write packet
            ByteWriter writer = new ByteWriter();

            writer.Binary.Write((int)ECommand.InitialWorldState);
            save.Serialize(writer);
            return(writer.ToArray());
        }