Пример #1
0
        public void ActionSelected(Action action)
        {
            InventoryManager.Instance.Opened = false;
            switch (action.getType())
            {
            case Action.GIVE_TO:
            case Action.USE_WITH:
            case Action.CUSTOM_INTERACT:
                // The texture that is already shown is either the icon or
                if (!cursor)
                {
                    cursor = new Texture2D(64, 64, TextureFormat.RGBA32, false, true);
                    try
                    {
                        var texture = sprite.texture;
                        ManuallyCopyTexture(texture, cursor);
                    }
                    catch
                    {
                        var texture = Transparent.CreateReadableTexture(sprite.texture);
                        ManuallyCopyTexture(texture, cursor);
                    }
                }

                Cursor.SetCursor(cursor, new Vector2(cursor.width, cursor.height) / 2f, CursorMode.ForceSoftware);
                GUIManager.Instance.LockCursor();
                uAdventureInputModule.LookingForTarget = this.gameObject;
                targetActionType = action.getType();
                break;

            default:
                Game.Instance.Execute(new EffectHolder(action.getEffects()));
                break;
            }
        }
Пример #2
0
    void Update()
    {
        if (dragging)
        {
            Vector2 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            this.transform.localPosition = pos;
            if (Input.GetMouseButtonUp(0))
            {
                dragging = false;
                Ray          ray            = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit[] hits           = Physics.RaycastAll(ray);
                bool         no_interaction = true;
                ActiveAreaMB aa;

                foreach (RaycastHit hit in hits)
                {
                    aa = hit.transform.GetComponent <ActiveAreaMB> ();
                    if (aa != null)
                    {
                        if (aa.aaData.getId() == drag.getTargetId())
                        {
                            Game.Instance.Execute(new EffectHolder(drag.getEffects()));
                            break;
                        }
                    }
                }
            }
        }
    }
Пример #3
0
    /**
     * Constructor that uses a default action
     *
     * @param action
     *            a normal action
     */

    public CustomAction(Action action)
        : base(
            action.getType(), action.getTargetId(), action.getConditions(), action.getEffects(), action.getNotEffects(),
            action.getClickEffects())
    {
        resources = new List <ResourcesUni>();
    }
Пример #4
0
 public InteractuableResult Interacted(PointerEventData pointerData = null)
 {
     GUIManager.Instance.ShowHand(false);
     MenuMB.Instance.hide(true);
     if (Receiver != null)
     {
         Receiver.ActionSelected(action);
     }
     else
     {
         Game.Instance.Execute(new EffectHolder(action.getEffects()));
     }
     return(InteractuableResult.DOES_SOMETHING);
 }
        /**
         * Contructor.
         *
         * @param action
         *            Next scenes of the data control structure
         *
         *
         */
        public ActionDataControl(Action action, string name)
        {
            this.action = action;

            this.resourcesList            = new List <ResourcesUni>();
            this.resourcesDataControlList = new List <ResourcesDataControl>();

            actionType = Controller.ACTION_TALK_TO;

            // Create subcontrollers
            conditionsController = new ConditionsController(action.getConditions(), actionType, name);
            effectsController    = new EffectsController(action.getEffects());
            notEffectsController = new EffectsController(action.getNotEffects());
        }
Пример #6
0
    void Update()
    {
        if (dragging)
        {
            Vector2 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            this.transform.localPosition = pos;
            if (Input.GetMouseButtonUp(0))
            {
                dragging = false;
                Ray          ray            = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit[] hits           = Physics.RaycastAll(ray);
                bool         no_interaction = true;
                ActiveAreaMB aa;

                foreach (RaycastHit hit in hits)
                {
                    aa = hit.transform.GetComponent <ActiveAreaMB> ();
                    if (aa != null)
                    {
                        if (aa.aaData.getId() == drag.getTargetId())
                        {
                            Game.Instance.Execute(new EffectHolder(drag.getEffects()));
                            break;
                        }
                    }
                }
            }
        }

        if (checkingTransparency)
        {
            RaycastHit hit;
            Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit);

            if (((Texture2D)GetComponent <Renderer>().material.mainTexture).GetPixelBilinear(hit.textureCoord.x, hit.textureCoord.y).a > 0f)
            {
                showHand(true);
            }
            else
            {
                showHand(false);
            }
        }
    }
 public override void updateVarFlagSummary(VarFlagSummary varFlagSummary)
 {
     // Update the flag summary with the effects of the action
     EffectsController.updateVarFlagSummary(varFlagSummary, action.getEffects());
     if (action.getNotEffects() != null)
     {
         EffectsController.updateVarFlagSummary(varFlagSummary, action.getNotEffects());
     }
     ConditionsController.updateVarFlagSummary(varFlagSummary, action.getConditions());
     if (action.getType() == Action.CUSTOM_INTERACT || action.getType() == Action.CUSTOM)
     {
         foreach (ResourcesDataControl resourcesDataControl in resourcesDataControlList)
         {
             resourcesDataControl.updateVarFlagSummary(varFlagSummary);
         }
     }
 }
Пример #8
0
    private void addActionToActionsByEffect(Action a)
    {
        Dictionary <string, float> effs = a.getEffects();

        Dictionary <string, float> .KeyCollection.Enumerator stepper = effs.Keys.GetEnumerator();

        while (stepper.Current != null)
        {
            List <Action> actions = null;
            if (!actionsByEffect.TryGetValue(stepper.Current, out actions))
            {
                actions = new List <Action>();
                actionsByEffect.Add(stepper.Current, actions);
            }
            actions.Add(a);
            if (!stepper.MoveNext())
            {
                return;
            }
        }
    }
Пример #9
0
        /**
         * Returns the info of the actions contained in the list.
         *
         * @return Array with the information of the actions. It contains the type
         *         of the action, and information about whether they have conditions
         *         and effects
         */
        public string[][] getActionsInfo()
        {
            string[][] actionsInfo = null;

            // Create the list for the actions
            actionsInfo = new string[actionsList.Count][];
            for (int i = 0; i < actionsList.Count; i++)
            {
                actionsInfo[i] = new string[3];
            }

            // Fill the array with the info
            for (int i = 0; i < actionsList.Count; i++)
            {
                Action action = actionsList[i];

                if (action.getType() == Action.EXAMINE)
                {
                    actionsInfo[i][0] = TC.get("ActionsList.ExamineAction");
                }
                else if (action.getType() == Action.GRAB)
                {
                    actionsInfo[i][0] = TC.get("ActionsList.GrabAction");
                }
                else if (action.getType() == Action.CUSTOM)
                {
                    actionsInfo[i][0] = TC.get("ActionsList.CustomAction", ((CustomAction)action).getName());
                }
                else if (action.getType() == Action.GIVE_TO)
                {
                    actionsInfo[i][0] = TC.get("ActionsList.GiveToAction", action.getTargetId());
                }
                else if (action.getType() == Action.USE_WITH)
                {
                    actionsInfo[i][0] = TC.get("ActionsList.UseWithAction", action.getTargetId());
                }
                else if (action.getType() == Action.CUSTOM_INTERACT)
                {
                    actionsInfo[i][0] = TC.get("ActionsList.CustomInteractAction", action.getTargetId());
                }
                else if (action.getType() == Action.USE)
                {
                    actionsInfo[i][0] = TC.get("ActionsList.UseAction");
                }
                else if (action.getType() == Action.TALK_TO)
                {
                    actionsInfo[i][0] = TC.get("ActionsList.TalkToAction");
                }
                else if (action.getType() == Action.DRAG_TO)
                {
                    actionsInfo[i][0] = TC.get("ActionsList.DragToAction");
                }

                if (action.getConditions().IsEmpty())
                {
                    actionsInfo[i][1] = TC.get("GeneralText.No");
                }
                else
                {
                    actionsInfo[i][1] = TC.get("GeneralText.Yes");
                }

                if (action.getEffects().IsEmpty())
                {
                    actionsInfo[i][2] = TC.get("GeneralText.No");
                }
                else
                {
                    actionsInfo[i][2] = TC.get("GeneralText.Yes");
                }
            }

            return(actionsInfo);
        }
Пример #10
0
        public override bool addElement(int type, string id)
        {
            Action newAction = null;

            switch (type)
            {
            case Controller.ACTION_EXAMINE:
                newAction = new Action(Action.EXAMINE);

                break;

            case Controller.ACTION_USE:
                newAction = new Action(Action.USE);
                break;

            case Controller.ACTION_GRAB:
                var item = parent as ItemDataControl;
                newAction = new Action(Action.GRAB)
                {
                    Effects = new Effects()
                    {
                        new RemoveElementEffect(item.getId()),
                        new GenerateObjectEffect(item.getId())
                    }
                };
                break;

            case Controller.ACTION_TALK_TO:

                string[] conversations = controller.IdentifierSummary.getIds <Conversation>();
                if (id != null && conversations.Contains(id))
                {
                    newAction = new Action(Action.TALK_TO);
                    newAction.getEffects().Add(new TriggerConversationEffect(id));
                }
                else
                {
                    var options         = conversations.ToList();
                    var newConversation = "--- New ---";
                    options.Insert(0, newConversation);
                    controller.ShowInputDialog(TC.get("TalkToAction.MessageSelectConversation"), TC.get("TalkToAction.MessageSelectConversation"), options.ToArray(), (nothing, conversationId) =>
                    {
                        var action = new Action(Action.TALK_TO);
                        if (conversationId == newConversation)
                        {
                            var conversationList = controller.SelectedChapterDataControl.getConversationsList();
                            conversationList.addElement(Controller.CONVERSATION_GRAPH, null, false, this, (sender, newConversationId) =>
                            {
                                action.getEffects().Add(new TriggerConversationEffect(newConversationId));
                                performAddAction(action);
                                if (controller.ShowStrictConfirmDialog("Open conversation?", "Do you want to open the new conversation?"))
                                {
                                    controller.SelectElement(conversationList.getConversations().Last());
                                }
                            });
                        }
                        else
                        {
                            action.getEffects().Add(new TriggerConversationEffect(conversationId));
                            performAddAction(action);
                        }
                    });
                    return(true);
                }

                break;

            // For these tree the creation pipeline is the same
            case Controller.ACTION_USE_WITH:
            case Controller.ACTION_DRAG_TO:
            case Controller.ACTION_GIVE_TO:

                string        message    = "";
                int           actionType = -1;
                System.Type[] validTypes = { };

                // Select the elements, the action, and the popup message
                switch (type)
                {
                case Controller.ACTION_DRAG_TO:
                    validTypes = new System.Type[] { typeof(Item), typeof(ActiveArea), typeof(NPC) };
                    actionType = Action.DRAG_TO;
                    message    = TC.get("CustomAction.MessageSelectInteraction");
                    break;

                case Controller.ACTION_USE_WITH:
                    validTypes = new System.Type[] { typeof(Item), typeof(ActiveArea) };
                    actionType = Action.USE_WITH;
                    message    = TC.get("Action.MessageSelectItem");
                    break;

                case Controller.ACTION_GIVE_TO:
                    validTypes = new System.Type[] { typeof(NPC) };
                    message    = TC.get("Action.MessageSelectNPC");
                    actionType = Action.GIVE_TO;
                    break;
                }

                // If the list has elements, show the dialog with the options
                auxCreateInteractiveAction(message, actionType, validTypes, (selectedTarget) =>
                {
                    var action     = new Action(actionType, selectedTarget);
                    var parentItem = parent as ItemDataControl;
                    if (parentItem != null && controller.ShowStrictConfirmDialog("Consume item?", "Do you want the item to be removed from the inventory in the action?"))
                    {
                        action.Effects.Add(new ConsumeObjectEffect(parentItem.getId()));
                    }
                    return(action);
                });
                break;
            }


            if (type == Controller.ACTION_CUSTOM_INTERACT)
            {
                controller.ShowInputDialog(TC.get("CustomAction.GetNameTitle"), TC.get("CustomAction.GetNameMessage"), (sender, name) =>
                {
                    if (string.IsNullOrEmpty(name))
                    {
                        name = "NONAME_" + Random.Range(0, 1000);
                    }

                    string[] options = { TC.get("Element.Action"), TC.get("Element.Interaction") };
                    controller.ShowInputDialog(TC.get("CustomAction.SelectTypeMessage"), TC.get("CustomAction.SelectTypeTitle"), options, (sender2, optionSelected) =>
                    {
                        switch (System.Array.IndexOf(options, optionSelected))
                        {
                        case 0:
                            {
                                var customAction = new CustomAction(Action.CUSTOM);
                                customAction.setName(name);
                                performAddAction(customAction);
                            }
                            break;

                        case 1:
                            auxCreateInteractiveAction(TC.get("CustomAction.MessageSelectInteraction"),
                                                       Action.CUSTOM_INTERACT, new System.Type[] { typeof(Item), typeof(ActiveArea), typeof(NPC) },
                                                       (selectedTarget) =>
                            {
                                var customAction = new CustomAction(Action.CUSTOM_INTERACT, selectedTarget);
                                customAction.setName(name);
                                return(customAction);
                            });
                            break;
                        }
                    });
                });
            }
            else if (type == Controller.ACTION_CUSTOM)
            {
                controller.ShowInputDialog(TC.get("CustomAction.GetNameTitle"), TC.get("CustomAction.GetNameMessage"), (sender, name) =>
                {
                    if (string.IsNullOrEmpty(name))
                    {
                        name = "NONAME_" + Random.Range(0, 1000);
                    }

                    var customAction = new CustomAction(Action.CUSTOM);
                    customAction.setName(name);
                    performAddAction(customAction);
                });
            }

            // If an action was added, create a controller and store it
            if (newAction != null)
            {
                performAddAction(newAction);
            }

            return(newAction != null);
        }
    /*
     * (non-Javadoc)
     *
     * @see es.eucm.eadventure.engine.loader.subparsers.SubParser#endElement(java.lang.string, java.lang.string,
     *      java.lang.string)
     */
    public override void endElement(string namespaceURI, string sName, string qName)
    {
        // If no element is being subparsed
        if (subParsing == SUBPARSING_NONE)
        {

            // If it is a character tag, store the character in the game data
            if (qName.Equals("character"))
            {
                chapter.addCharacter(npc);
            }

            // If it is a documentation tag, hold the documentation in the character
            else if (qName.Equals("documentation"))
            {
                if (reading == READING_NONE)
                    npc.setDocumentation(currentstring.ToString().Trim());
                else if (reading == READING_CONVERSATION_REFERENCE)
                    conversationReference.setDocumentation(currentstring.ToString().Trim());
            }

            // If it is a resources tag, add the resources in the character
            else if (qName.Equals("resources"))
            {
                npc.addResources(currentResources);
                reading = READING_NONE;
            }

            // If it is a conversation reference tag, add the reference to the character
            else if (qName.Equals("conversation-ref"))
            {

                //npc.addConversationReference( conversationReference );
                Action action = new Action(Action.TALK_TO);
                action.setConditions(conversationReference.getConditions());
                action.setDocumentation(conversationReference.getDocumentation());
                TriggerConversationEffect effect = new TriggerConversationEffect(conversationReference.getTargetId());
                action.getEffects().add(effect);
                npc.addAction(action);
                reading = READING_NONE;
            }

            // Reset the current string
            currentstring = "";
        }

        // If a condition is being subparsed
        else if (subParsing == SUBPARSING_CONDITION)
        {

            // Spread the end element call
            subParser.endElement(namespaceURI, sName, qName);

            // If the condition is being closed
            if (qName.Equals("condition"))
            {
                // Add the condition to the resources
                if (reading == READING_RESOURCES)
                    currentResources.setConditions(currentConditions);

                // Add the condition to the conversation reference
                if (reading == READING_CONVERSATION_REFERENCE)
                    conversationReference.setConditions(currentConditions);

                // Stop subparsing
                subParsing = SUBPARSING_NONE;
            }
        }
        else if (subParsing == SUBPARSING_ACTIONS)
        {
            subParser.endElement(namespaceURI, sName, qName);
            if (qName.Equals("actions"))
            {
                subParsing = SUBPARSING_NONE;
            }
        }

        // If it is a description tag, create the new description (with its id)
        else if (subParsing == SUBPARSING_DESCRIPTION)
        {
            // Spread the call
            subParser.endElement(namespaceURI, sName, qName);
            if (qName.Equals("description"))
            {
                this.descriptions.Add(description);
                subParsing = SUBPARSING_NONE;
            }
        }
    }
    public override void ParseElement(XmlElement element)
    {
        XmlNodeList
            resourcess    = element.SelectNodes("resources"),
            descriptionss = element.SelectNodes("description"),
            assets,
            conditions,
            frontcolors,
            bordercolors,
            textcolors       = element.SelectNodes("textcolor"),
            conversationsref = element.SelectNodes("conversation-ref"),
            voices           = element.SelectNodes("voice"),
            actionss         = element.SelectNodes("actions");

        string tmpArgVal;

        string characterId = element.GetAttribute("id");

        npc = new NPC(characterId);

        descriptions = new List <Description>();
        npc.setDescriptions(descriptions);

        if (element.SelectSingleNode("documentation") != null)
        {
            npc.setDocumentation(element.SelectSingleNode("documentation").InnerText);
        }

        foreach (XmlElement el in resourcess)
        {
            currentResources = new ResourcesUni();
            tmpArgVal        = el.GetAttribute("name");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                currentResources.setName(el.GetAttribute(tmpArgVal));
            }

            assets = el.SelectNodes("asset");
            foreach (XmlElement ell in assets)
            {
                string type = "";
                string path = "";

                tmpArgVal = ell.GetAttribute("type");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    type = tmpArgVal;
                }
                tmpArgVal = ell.GetAttribute("uri");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    path = tmpArgVal;
                }
                currentResources.addAsset(type, path);
            }

            conditions = el.SelectNodes("condition");
            foreach (XmlElement ell in conditions)
            {
                currentConditions = new Conditions();
                new ConditionSubParser_(currentConditions, chapter).ParseElement(ell);
                currentResources.setConditions(currentConditions);
            }

            npc.addResources(currentResources);
        }


        foreach (XmlElement el in textcolors)
        {
            tmpArgVal = el.GetAttribute("showsSpeechBubble");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                npc.setShowsSpeechBubbles(tmpArgVal.Equals("yes"));
            }

            tmpArgVal = el.GetAttribute("bubbleBkgColor");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                npc.setBubbleBkgColor(tmpArgVal);
            }

            tmpArgVal = el.GetAttribute("bubbleBorderColor");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                npc.setBubbleBorderColor(tmpArgVal);
            }

            frontcolors = el.SelectNodes("frontcolor");
            foreach (XmlElement ell in frontcolors)
            {
                string color = "";

                tmpArgVal = ell.GetAttribute("color");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    color = tmpArgVal;
                }

                npc.setTextFrontColor(color);
            }

            bordercolors = el.SelectNodes("bordercolor");
            foreach (XmlElement ell in bordercolors)
            {
                string color = "";

                tmpArgVal = ell.GetAttribute("color");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    color = tmpArgVal;
                }

                npc.setTextBorderColor(color);
            }
        }


        foreach (XmlElement el in conversationsref)
        {
            string idTarget = "";

            tmpArgVal = el.GetAttribute("idTarget");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                idTarget = tmpArgVal;
            }

            conversationReference = new ConversationReference(idTarget);

            conditions = el.SelectNodes("condition");
            foreach (XmlElement ell in conditions)
            {
                currentConditions = new Conditions();
                new ConditionSubParser_(currentConditions, chapter).ParseElement(ell);

                conversationReference.setConditions(currentConditions);
            }

            conversationReference.setDocumentation(el.SelectSingleNode("documentation").InnerText);

            Action action = new Action(Action.TALK_TO);
            action.setConditions(conversationReference.getConditions());
            action.setDocumentation(conversationReference.getDocumentation());
            TriggerConversationEffect effect = new TriggerConversationEffect(conversationReference.getTargetId());
            action.getEffects().add(effect);
            npc.addAction(action);
        }

        foreach (XmlElement el in voices)
        {
            string voice = "";
            string response;
            bool   alwaysSynthesizer = false;

            tmpArgVal = el.GetAttribute("name");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                voice = tmpArgVal;
            }

            tmpArgVal = el.GetAttribute("synthesizeAlways");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                response = tmpArgVal;
                if (response.Equals("yes"))
                {
                    alwaysSynthesizer = true;
                }
            }

            npc.setAlwaysSynthesizer(alwaysSynthesizer);
            npc.setVoice(voice);
        }

        foreach (XmlElement el in actionss)
        {
            new ActionsSubParser_(chapter, npc).ParseElement(el);
        }

        foreach (XmlElement el in descriptionss)
        {
            description = new Description();
            new DescriptionsSubParser_(description, chapter).ParseElement(el);
            this.descriptions.Add(description);
        }

        chapter.addCharacter(npc);
    }
Пример #13
0
 /**
  * Constructor that uses a default action
  *
  * @param action
  *            a normal action
  */
 public CustomAction(Action action)
     : base(action.getType(), action.getTargetId(), action.getConditions(), action.getEffects(), action.getNotEffects(),
         action.getClickEffects())
 {
     resources = new List<ResourcesUni>();
 }
Пример #14
0
        public override bool addElement(int type, string id)
        {
            Action newAction = null;

            if (type == Controller.ACTION_EXAMINE)
            {
                newAction = new Action(Action.EXAMINE);
            }

            else if (type == Controller.ACTION_GRAB)
            {
                newAction = new Action(Action.GRAB);
            }

            else if (type == Controller.ACTION_USE)
            {
                newAction = new Action(Action.USE);
            }

            else if (type == Controller.ACTION_TALK_TO)
            {
                string[] conversations = controller.getIdentifierSummary().getConversationsIds();
                if (conversations.Length > 0)
                {
                    string selectedElement = controller.showInputDialog(TC.get("Action.OperationAddAction"), TC.get("TalkToAction.MessageSelectConversation"), conversations);
                    if (selectedElement != null)
                    {
                        newAction = new Action(Action.TALK_TO);
                        newAction.getEffects().add(new TriggerConversationEffect(selectedElement));
                    }
                }
                else
                {
                    controller.showErrorDialog(TC.get("Action.OperationAddAction"), TC.get("Action.ErrorNoItems"));
                }
            }
            else if (type == Controller.ACTION_CUSTOM_INTERACT)
            {
                //FIX:
                //string name = JOptionPane.showInputDialog( null, TC.get( "CustomAction.GetNameMessage" ), TC.get( "CustomAction.GetNameTitle" ), JOptionPane.QUESTION_MESSAGE );


                string name = controller.showInputDialog(TC.get("CustomAction.GetNameTitle"), TC.get("CustomAction.GetNameMessage"));
                // if user cancels the operation, finish the new action creation

                /*if( name == null || name.Equals( "" ) ) {
                 *  name = "NONAME_" + ( new Random( ) ).nextInt( 1000 );
                 * }*/

                // if user do not cancel the operation
                if (name != null)
                {
                    // if user press "accept" without introduce any name
                    if (name.Equals(""))
                    {
                        name = "NONAME_" + (new System.Random()).Next(1000);
                    }


                    string[] options = { TC.get("Element.Action"), TC.get("Element.Interaction") };
                    // TODO: implementation
                    //int option = JOptionPane.showOptionDialog(null, TC.get("CustomAction.SelectTypeMessage"), TC.get("CustomAction.SelectTypeTitle"), JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, 0);
                    //if (option != JOptionPane.CLOSED_OPTION)
                    //{
                    //    if (option == 0)
                    //    {
                    //        newAction = new CustomAction(Action.CUSTOM);
                    //        ((CustomAction)newAction).setName(name);
                    //    }
                    //    else {
                    //        string[] items = controller.getIdentifierSummary().getItemAndActiveAreaIds();
                    //        string[] npcs = controller.getIdentifierSummary().getNPCIds();
                    //        string[] elements = new string[items.Length + npcs.Length];
                    //        for (int i = 0; i < elements.Length; i++)
                    //        {
                    //            if (i < items.Length)
                    //            {
                    //                elements[i] = items[i];
                    //            }
                    //            else {
                    //                elements[i] = npcs[i - items.Length];
                    //            }
                    //        }

                    //        // If the list has elements, show the dialog with the options
                    //        if (elements.Length > 0)
                    //        {
                    //            string selectedElement = controller.showInputDialog(TC.get("Action.OperationAddAction"), TC.get("CustomAction.MessageSelectInteraction"), elements);

                    //            // If some value was selected
                    //            if (selectedElement != null)
                    //            {
                    //                newAction = new CustomAction(Action.CUSTOM_INTERACT, selectedElement);
                    //                ((CustomAction)newAction).setName(name);
                    //            }
                    //        }

                    //        // If the list had no elements, show an error dialog
                    //        else
                    //            controller.showErrorDialog(TC.get("Action.OperationAddAction"), TC.get("Action.ErrorNoItems"));

                    //    }
                    //}// end if user cancel the action adition after introducing the name
                }// end if that controls if user
            }
            else if (type == Controller.ACTION_CUSTOM)
            {
                string name = controller.showInputDialog(TC.get("CustomAction.GetNameMessage"), TC.get("CustomAction.GetNameTitle"));
                // if name == null, the user cancel the action addition
                if (name != null)
                {
                    if (name.Equals(""))
                    {
                        name = "NONAME_" + (new System.Random()).Next(1000);
                    }

                    newAction = new CustomAction(Action.CUSTOM);
                    ((CustomAction)newAction).setName(name);
                }
            }

            // If the type of action is use-with, we must ask for a second item
            else if (type == Controller.ACTION_USE_WITH)
            {
                // Take the list of the items
                string[] items = controller.getIdentifierSummary().getItemAndActiveAreaIds();

                // If the list has elements, show the dialog with the options
                if (items.Length > 0)
                {
                    string selectedItem = controller.showInputDialog(TC.get("Action.OperationAddAction"), TC.get("Action.MessageSelectItem"), items);

                    // If some value was selected
                    if (selectedItem != null)
                    {
                        newAction = new Action(Action.USE_WITH, selectedItem);
                    }
                }

                // If the list had no elements, show an error dialog
                else
                {
                    controller.showErrorDialog(TC.get("Action.OperationAddAction"), TC.get("Action.ErrorNoItems"));
                }
            }

            // If the type of action is drag-to, we must ask for a second item
            else if (type == Controller.ACTION_DRAG_TO)
            {
                // Take the list of the items
                string[] items = controller.getIdentifierSummary().getItemActiveAreaNPCIds();

                // If the list has elements, show the dialog with the options
                if (items.Length > 0)
                {
                    string selectedItem = controller.showInputDialog(TC.get("Action.OperationAddAction"), TC.get("Action.MessageSelectItem"), items);

                    // If some value was selected
                    if (selectedItem != null)
                    {
                        newAction = new Action(Action.DRAG_TO, selectedItem);
                    }
                }

                // If the list had no elements, show an error dialog
                else
                {
                    controller.showErrorDialog(TC.get("Action.OperationAddAction"), TC.get("Action.ErrorNoItems"));
                }
            }

            // If the type of action is give-to, we must ask for a character
            else if (type == Controller.ACTION_GIVE_TO)
            {
                // Take the list of the characters
                string[] npcs = controller.getIdentifierSummary().getNPCIds();

                // If the list has elements, show the dialog with the options
                if (npcs.Length > 0)
                {
                    string selectedNPC = controller.showInputDialog(TC.get("Action.OperationAddAction"), TC.get("Action.MessageSelectNPC"), npcs);

                    // If some value was selected
                    if (selectedNPC != null)
                    {
                        newAction = new Action(Action.GIVE_TO, selectedNPC);
                    }
                }

                // If the list had no elements, show an error dialog
                else
                {
                    controller.showErrorDialog(TC.get("Action.OperationAddAction"), TC.get("Action.ErrorNoNPCs"));
                }
            }

            // If an action was added, create a controller and store it
            if (newAction != null)
            {
                actionsList.Add(newAction);
                if (newAction.getType() == Action.CUSTOM || newAction.getType() == Action.CUSTOM_INTERACT)
                {
                    actionsDataControlList.Add(new CustomActionDataControl((CustomAction)newAction));
                }
                else
                {
                    actionsDataControlList.Add(new ActionDataControl(newAction));
                }
                //controller.dataModified( );
            }

            return(newAction != null);
        }
Пример #15
0
    /*
     * (non-Javadoc)
     *
     * @see es.eucm.eadventure.engine.loader.subparsers.SubParser#endElement(java.lang.string, java.lang.string,
     *      java.lang.string)
     */
    public override void endElement(string namespaceURI, string sName, string qName)
    {
        // If no element is being subparsed
        if (subParsing == SUBPARSING_NONE)
        {
            // If it is a character tag, store the character in the game data
            if (qName.Equals("character"))
            {
                chapter.addCharacter(npc);
            }

            // If it is a documentation tag, hold the documentation in the character
            else if (qName.Equals("documentation"))
            {
                if (reading == READING_NONE)
                {
                    npc.setDocumentation(currentstring.ToString().Trim());
                }
                else if (reading == READING_CONVERSATION_REFERENCE)
                {
                    conversationReference.setDocumentation(currentstring.ToString().Trim());
                }
            }

            // If it is a resources tag, add the resources in the character
            else if (qName.Equals("resources"))
            {
                npc.addResources(currentResources);
                reading = READING_NONE;
            }

            // If it is a conversation reference tag, add the reference to the character
            else if (qName.Equals("conversation-ref"))
            {
                //npc.addConversationReference( conversationReference );
                Action action = new Action(Action.TALK_TO);
                action.setConditions(conversationReference.getConditions());
                action.setDocumentation(conversationReference.getDocumentation());
                TriggerConversationEffect effect = new TriggerConversationEffect(conversationReference.getTargetId());
                action.getEffects().add(effect);
                npc.addAction(action);
                reading = READING_NONE;
            }

            // Reset the current string
            currentstring = "";
        }

        // If a condition is being subparsed
        else if (subParsing == SUBPARSING_CONDITION)
        {
            // Spread the end element call
            subParser.endElement(namespaceURI, sName, qName);

            // If the condition is being closed
            if (qName.Equals("condition"))
            {
                // Add the condition to the resources
                if (reading == READING_RESOURCES)
                {
                    currentResources.setConditions(currentConditions);
                }

                // Add the condition to the conversation reference
                if (reading == READING_CONVERSATION_REFERENCE)
                {
                    conversationReference.setConditions(currentConditions);
                }

                // Stop subparsing
                subParsing = SUBPARSING_NONE;
            }
        }
        else if (subParsing == SUBPARSING_ACTIONS)
        {
            subParser.endElement(namespaceURI, sName, qName);
            if (qName.Equals("actions"))
            {
                subParsing = SUBPARSING_NONE;
            }
        }

        // If it is a description tag, create the new description (with its id)
        else if (subParsing == SUBPARSING_DESCRIPTION)
        {
            // Spread the call
            subParser.endElement(namespaceURI, sName, qName);
            if (qName.Equals("description"))
            {
                this.descriptions.Add(description);
                subParsing = SUBPARSING_NONE;
            }
        }
    }
Пример #16
0
 public InteractuableResult Interacted(RaycastHit hit = new RaycastHit())
 {
     Game.Instance.Execute(new EffectHolder(action.getEffects()));
     return(InteractuableResult.DOES_SOMETHING);
 }
    public override void ParseElement(XmlElement element)
    {
        XmlNodeList
            resourcess = element.SelectNodes("resources"),
            descriptionss = element.SelectNodes("description"),
            assets,
            conditions,
            frontcolors,
            bordercolors,
            textcolors = element.SelectNodes("textcolor"),
            conversationsref = element.SelectNodes("conversation-ref"),
            voices = element.SelectNodes("voice"),
            actionss = element.SelectNodes("actions");

        string tmpArgVal;

        string characterId = element.GetAttribute("id");

        npc = new NPC(characterId);

        descriptions = new List<Description>();
        npc.setDescriptions(descriptions);

        if (element.SelectSingleNode("documentation") != null)
            npc.setDocumentation(element.SelectSingleNode("documentation").InnerText);

        foreach (XmlElement el in resourcess)
        {
            currentResources = new ResourcesUni();
            tmpArgVal = el.GetAttribute("name");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                currentResources.setName(el.GetAttribute(tmpArgVal));
            }

            assets = el.SelectNodes("asset");
            foreach (XmlElement ell in assets)
            {
                string type = "";
                string path = "";

                tmpArgVal = ell.GetAttribute("type");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    type = tmpArgVal;
                }
                tmpArgVal = ell.GetAttribute("uri");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    path = tmpArgVal;
                }
                currentResources.addAsset(type, path);
            }

            conditions = el.SelectNodes("condition");
            foreach (XmlElement ell in conditions)
            {
                currentConditions = new Conditions();
                new ConditionSubParser_(currentConditions, chapter).ParseElement(ell);
                currentResources.setConditions(currentConditions);
            }

            npc.addResources(currentResources);
        }

        foreach (XmlElement el in textcolors)
        {
            tmpArgVal = el.GetAttribute("showsSpeechBubble");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                npc.setShowsSpeechBubbles(tmpArgVal.Equals("yes"));
            }

            tmpArgVal = el.GetAttribute("bubbleBkgColor");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                npc.setBubbleBkgColor(tmpArgVal);
            }

            tmpArgVal = el.GetAttribute("bubbleBorderColor");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                npc.setBubbleBorderColor(tmpArgVal);
            }

            frontcolors = el.SelectNodes("frontcolor");
            foreach (XmlElement ell in frontcolors)
            {
                string color = "";

                tmpArgVal = ell.GetAttribute("color");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    color = tmpArgVal;
                }

                npc.setTextFrontColor(color);
            }

            bordercolors = el.SelectNodes("bordercolor");
            foreach (XmlElement ell in bordercolors)
            {
                string color = "";

                tmpArgVal = ell.GetAttribute("color");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    color = tmpArgVal;
                }

                npc.setTextBorderColor(color);
            }
        }

        foreach (XmlElement el in conversationsref)
        {
            string idTarget = "";

            tmpArgVal = el.GetAttribute("idTarget");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                idTarget = tmpArgVal;
            }

            conversationReference = new ConversationReference(idTarget);

            conditions = el.SelectNodes("condition");
            foreach (XmlElement ell in conditions)
            {
                currentConditions = new Conditions();
                new ConditionSubParser_(currentConditions, chapter).ParseElement(ell);

                conversationReference.setConditions(currentConditions);
            }

            conversationReference.setDocumentation(el.SelectSingleNode("documentation").InnerText);

            Action action = new Action(Action.TALK_TO);
            action.setConditions(conversationReference.getConditions());
            action.setDocumentation(conversationReference.getDocumentation());
            TriggerConversationEffect effect = new TriggerConversationEffect(conversationReference.getTargetId());
            action.getEffects().add(effect);
            npc.addAction(action);
        }

        foreach (XmlElement el in voices)
        {
            string voice = "";
            string response;
            bool alwaysSynthesizer = false;

            tmpArgVal = el.GetAttribute("name");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                voice = tmpArgVal;
            }

            tmpArgVal = el.GetAttribute("synthesizeAlways");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                response = tmpArgVal;
                if (response.Equals("yes"))
                    alwaysSynthesizer = true;
            }

            npc.setAlwaysSynthesizer(alwaysSynthesizer);
            npc.setVoice(voice);
        }

        foreach (XmlElement el in actionss)
        {
            new ActionsSubParser_(chapter, npc).ParseElement(el);
        }

        foreach (XmlElement el in descriptionss)
        {
            description = new Description();
            new DescriptionsSubParser_(description, chapter).ParseElement(el);
            this.descriptions.Add(description);
        }

        chapter.addCharacter(npc);
    }
        public ActionDataControl(Action action)
        {
            this.action = action;

            this.resourcesList            = new List <ResourcesUni>();
            this.resourcesDataControlList = new List <ResourcesDataControl>();

            string actionName = null;

            // Store the type of the action
            switch (action.getType())
            {
            case Action.EXAMINE:
                actionType = Controller.ACTION_EXAMINE;
                actionName = "";
                break;

            case Action.GRAB:
                actionType = Controller.ACTION_GRAB;
                actionName = "";
                break;

            case Action.USE:
                actionType = Controller.ACTION_USE;
                actionName = "";
                break;

            case Action.CUSTOM:
                actionType = Controller.ACTION_CUSTOM;
                CustomAction custom = (CustomAction)action;
                actionName = custom.getName();
                break;

            case Action.USE_WITH:
                actionType = Controller.ACTION_USE_WITH;
                actionName = action.getTargetId();
                break;

            case Action.GIVE_TO:
                actionType = Controller.ACTION_GIVE_TO;
                actionName = action.getTargetId();
                break;

            case Action.CUSTOM_INTERACT:
                actionType = Controller.ACTION_CUSTOM_INTERACT;
                CustomAction custom2 = (CustomAction)action;
                actionName = custom2.getName() + " " + action.getTargetId();
                break;

            case Action.TALK_TO:
                actionType = Controller.ACTION_TALK_TO;
                actionName = action.getTargetId();
                break;

            case Action.DRAG_TO:
                actionType = Controller.ACTION_DRAG_TO;
                actionName = action.getTargetId();
                break;
            }

            // Create subcontrollers
            conditionsController = new ConditionsController(action.getConditions(), actionType, actionName);
            effectsController    = new EffectsController(action.getEffects());
            notEffectsController = new EffectsController(action.getNotEffects());
        }