Exemplo n.º 1
0
        public static Action <object> ParseMessageToAction(Message message)
        {
            if (message.Type == MsgType.Reply)
            {
                throw new InvalidOperationException("Server received MsgType.Reply... those are meant to only flow the other way.");
            }
            if (message.Type == MsgType.Notify)
            {
                return(null);                                // Notify messages ONLY raise the OnReceiveMessage event and nothing else.
            }
            if (message.Type == MsgType.LaunchActivity)
            {
                var substrings           = message.Content.Split(onNEXT);
                var type                 = Type.GetType(substrings[0]);
                var tdata                = Type.GetType(substrings[1]);
                var serializedPassedInfo = substrings[2]; // Currently nothing is done with this, since it'll be a right pain in the arse to do.

                return((o) =>
                {
                    // Todo - embed the PassedInfo into somewhere (Res? try again for Bundle syntax?) before this.
                    Application.Context.StartActivity(type);
                });
            }
            if (message.Type == MsgType.PushSFX)
            {
                IEffect FX;
                if (!Res.SFX.Effects.TryGetValue($"RequestedFX{NEXT}{message.Content}", out FX))
                {
                    if (!int.TryParse(message.Content, out int ResourceID))
                    {
                        ResourceID = typeof(Resource.Id).GetStaticProperty <int>(message.Content);
                    }
                    FX = Res.SFX.Register($"RequestedFX{NEXT}{message.Content}", ResourceID);
                }
                if (FX == null)
                {
                    return(null);
                }

                return((o) =>
                {
                    FX.Activate();
                    FX.Play();
                });
            }
            if (message.Type == MsgType.PushSpeech)
            {
                return((o) =>
                {
                    Speech.Say(message.Content);
                });
            }
            if (message.Type == MsgType.PushEffect)
            {
                var substrings   = message.Content.Split(onNEXT, 2);
                var effectName   = substrings[0];
                var effectParams = substrings[1];
                //if (!MasterSpellLibrary.CastingResults.ContainsKey(effectName))
                //{
                //    Log.Warn(_tag, $"Unable to locate game effect '{effectName}'.");
                //    return null;
                //}
                if (!GameEffect.Definition.ContainsKey(effectName))
                {
                    Log.Warn(_tag, $"Unable to locate effect '{effectName}'.");
                    return(null);
                }

                //var doFunc = MasterSpellLibrary.CastingResults[effectName];
                return((o) =>
                {
                    GameEffect
                    .Definition[effectName]?
                    .OnReceiving(TemporaryAddressBook_SingleEntry ?? new CommsContact(), effectParams);
                });
            }
            if (message.Type == MsgType.PushEffect2)
            {
                var effectInstance = GameEffectInstance.FromStringForm(message.Content);

                //var doFunc = MasterSpellLibrary.CastingResults[effectName];
                return((o) =>
                {
                    effectInstance?
                    .SourceEffect?
                    .OnReceiving2(effectInstance);
                });
            }
            if (message.Type == MsgType.Query)
            {
                return((o) =>
                {
                    var target = AddressBook.Resolve(message.From);
                    target.SendMessage(DataLibrarian.FetchRequestedData(message, o));
                });
            }
            if (message.Type == MsgType.SetScenarioVariable)
            {
                var substrings = message.Content.Split(onNEXT);
                Encounters.Scenario.Current.SetVariable(substrings[0],
                                                        (Encounters.Scenario.State)Enum.Parse(typeof(Encounters.Scenario.State), substrings[1]), false); // False meaning don't rebroadcast it.
            }
            throw new NotImplementedException();
        }