UIViewController CreateControllerForConversation(ConversationItem[] items, int currentItem, Entity speaker)
        {
            var item = items [currentItem];

            /*
             * if (item.DependencyScripts != null) {
             *  foreach (var script in item.DependencyScripts) {
             *      LuaEngine.ExecuteScript (script, item);
             *  }
             * }
             */
            var text  = string.Join("\n", item.Character);
            var alert = UIAlertController.Create(speaker.Model.Name, text, UIAlertControllerStyle.Alert);

            // Don't want to evaluate the ids everytime
            var ids = item.ResponseIds;

            if (ids == null || ids.Length == 0)
            {
                Console.WriteLine("No responses");
                return(alert);
            }

            foreach (var responseId in ids)
            {
                var localResponseId = responseId - 1;
                var responseItem    = items [localResponseId];

                var a = UIAlertAction.Create(responseItem.Player[0], 0, async(obj) => {
                    controller.DismissViewController(false, null);

                    if (responseItem.ActionScripts != null)
                    {
                        foreach (var script in responseItem.ActionScripts)
                        {
                            LuaEngine.ExecuteScript(script, responseItem);
                        }
                    }

                    if (responseItem.Character == null)
                    {
                        return;
                    }

                    controller.PresentViewController(CreateControllerForConversation(items, localResponseId, speaker), false, null);

                    if (responseItem.ResponseIds == null)
                    {
                        await Task.Delay(2500);

                        controller.DismissViewController(false, null);
                    }
                });
                alert.AddAction(a);
            }

            return(alert);
        }
Example #2
0
        public GameScene(IntPtr handle) : base(handle)
        {
            Player = new Professor();
            var invComp = Player.GetComponent <InventoryComponent> ();

            InvManager = new InventoryManager(invComp);

            LuaEngine.SetGlobalVariable("inventory", InvManager);
            LuaEngine.SetGlobalVariable("game", this);

            try {
                LuaEngine.ExecuteScriptFromFile("Main.lua");
            } catch (Exception e) {
                Console.WriteLine($"{e}");
            }
        }
Example #3
0
        async void HandleLookNotification(NSNotification note)
        {
            var userInfo = note.UserInfo;

            var itemEntity = (Entity)userInfo [ItemEntityKey];

            var description = (string)LuaEngine.ExecuteScript(itemEntity.Model.LookCommand)[0];

            var alert = UIAlertController.Create("", description, UIAlertControllerStyle.Alert);

            controller.PresentViewController(alert, false, null);

            await Task.Delay(5000);

            controller.DismissViewController(false, null);
        }
Example #4
0
        async void HandleCollectNotification(NSNotification note)
        {
            var userInfo = note.UserInfo;

            var itemEntity   = (Entity)userInfo [ItemEntityKey];
            var playerEntity = (Entity)userInfo [PlayerEntityKey];

            var invComponent = playerEntity.GetComponent <InventoryComponent> ();

            if (invComponent == null)
            {
                throw new InvalidOperationException("No inventory component");
            }

            bool add = true;

            if (!string.IsNullOrEmpty(itemEntity.Model.CollectCommand))
            {
                Console.WriteLine($"{itemEntity.Model.CollectCommand}");
                var results = LuaEngine.ExecuteScript(itemEntity.Model.CollectCommand);
                Console.WriteLine("Parsed");
                add = (bool)results [1];

                Console.WriteLine($"{add}");
                if (!string.IsNullOrEmpty((string)results [0]))
                {
                    var alert = UIAlertController.Create("", (string)results [0], UIAlertControllerStyle.Alert);
                    controller.PresentViewController(alert, false, null);

                    await Task.Delay(5000);

                    controller.DismissViewController(false, null);
                }
            }

            if (add)
            {
                invComponent.AddItem(itemEntity);
            }
        }