Ejemplo n.º 1
0
    private List <TriggerEditorNode> GetChildrenNodes(GameObject root)
    {
        // Root is assumed to contain a Trigger component and maybe an EventSender or Function component.
        List <TriggerEditorNode> nodes = new List <TriggerEditorNode>();

        foreach (Transform child in root.transform)
        {
            EventFilter        filter      = child.GetComponent <EventFilter>();
            EventResponder     responder   = child.GetComponent <EventResponder>();
            TriggerActionGroup actionGroup = child.GetComponent <TriggerActionGroup>();
            if (filter)
            {
                FilterEditorNode filterNode = new FilterEditorNode(filter, _context);
                nodes.Add(filterNode);
                BuildTreeRec(filterNode);
            }
            else if (responder)
            {
                ActionEditorNode actionNode = new ActionEditorNode(responder, _context);
                nodes.Add(actionNode);
                BuildTreeRec(actionNode);
            }
            else if (actionGroup)
            {
                ActionGroupEditorNode groupNode = new ActionGroupEditorNode(actionGroup, _context);
                nodes.Add(groupNode);
                BuildTreeRec(groupNode);
            }
        }
        return(nodes);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Draws the field controls to add and remove any responder from the currently selected event.
    /// </summary>
    private void DrawAddRemoveResponderControls()
    {
        int selection = EditorGUILayout.Popup(currentApplicableResponderTypes.SelectedIndex, currentApplicableResponderTypes.ObjectNames);

        if (selection != currentApplicableResponderTypes.SelectedIndex)
        {
            currentApplicableResponderTypes.SetSelection(selection);
        }

        EditorGUILayout.BeginHorizontal();

        //Add a new responder when clicked
        if (GUILayout.Button("+"))
        {
            EventResponder newResponder = (EventResponder)ScriptableObject.CreateInstance(currentApplicableResponderTypes.SelectedObject);
            currentTargetResponders.AddEventResponder(components.SelectedObject, currentExposedEvents.SelectedObject.Name, newResponder);
            RefreshCurrentEventResponders();

            EditorUtility.SetDirty(currentTargetResponders);
        }

        //Remove the currently selected responder when clicked
        if (GUILayout.Button("-") && currentEventResponders.SelectedObject != null)
        {
            currentTargetResponders.RemoveEventResponder(components.SelectedObject, currentExposedEvents.SelectedObject.Name, currentEventResponders.SelectedObject);
            RefreshCurrentEventResponders();

            EditorUtility.SetDirty(currentTargetResponders);
        }

        EditorGUILayout.EndHorizontal();
    }
Ejemplo n.º 3
0
 private void BuildTreeRec(TriggerEditorNode node)
 {
     foreach (Transform child in node.TriggerComponent.transform)
     {
         EventFilter        filter      = child.GetComponent <EventFilter>();
         EventResponder     responder   = child.GetComponent <EventResponder>();
         TriggerActionGroup actionGroup = child.GetComponent <TriggerActionGroup>();
         if (filter)
         {
             FilterEditorNode filterNode = new FilterEditorNode(filter, _context);
             node.Add(filterNode);
             BuildTreeRec(filterNode);
         }
         else if (responder)
         {
             ActionEditorNode actionNode = new ActionEditorNode(responder, _context);
             node.Add(actionNode);
             BuildTreeRec(actionNode);
         }
         else if (actionGroup)
         {
             ActionGroupEditorNode groupNode = new ActionGroupEditorNode(actionGroup, _context);
             node.Add(groupNode);
             BuildTreeRec(groupNode);
         }
     }
 }
Ejemplo n.º 4
0
    public void refuseReferendum(Nation player, Nation otherMajor, Province disputedProvince)
    {
        // Refuse to hold a referendum
        EventResponder responder = otherMajor.getAI().getEventResponder();

        if (responder.warOverRejection(otherMajor, player, disputedProvince))
        {
            // The AI player responds by declaring war on the human player
            DecisionEvent newEvent = new DecisionEvent();
            eventLogic.initializeAI_DeclaresWarEvent(newEvent, player, otherMajor);
            currentEvent = newEvent;
            showDecisionPanel(player);
            //  war.warBetweenAI(player, otherMajor, prov.getIndex());
        }
        else if (responder.boycottOverRefDemandRejection(otherMajor))
        {
            // AI imposes boycott
            DecisionEvent newEvent = new DecisionEvent();
            eventLogic.initializeAI_BoycottsHumanEvent(newEvent, player, currentEvent);
            currentEvent = newEvent;
            showDecisionPanel(player);
        }
        else
        {
            // AI does nothing and looses face
            otherMajor.decreasePrestige(2);
            nextEventTurn(player);
        }
    }
Ejemplo n.º 5
0
    public static void DrawAddActionSelector(GameObject parent, Action addedActionCallback)
    {
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.Label("Add Action:", GUILayout.ExpandWidth(false));

        Type selectedActionType = null;

        selectedActionType = TriggerGUILayout.DrawActionSelector(selectedActionType);
        if (selectedActionType != null)
        {
            int        ordinal          = GetLastExecutionTime(parent) + 1;
            GameObject actionGameObject = new GameObject(selectedActionType.Name);
            actionGameObject.transform.parent = parent.gameObject.transform;
            EventResponder responder = (EventResponder)actionGameObject.AddComponent(selectedActionType);
            responder.Ordinal = ordinal;
            List <TriggerActionGroupDescriptor> actionGroupDescriptors = responder.GetTriggerActionGroups();
            foreach (TriggerActionGroupDescriptor descriptor in actionGroupDescriptors)
            {
                TriggerActionGroup.CreateActionGroup(descriptor).transform.parent = responder.gameObject.transform;
            }
            addedActionCallback();
        }
        GUILayout.EndHorizontal();
    }
    /// <summary>
    /// Clones this EventResponseWrapper, generating a new EventResponder instance as a copy of our existing one.
    /// </summary>
    /// <param name="targetObject">The gameObject containing the new target component for the cloned instance.</param>
    /// <param name="ownerID">The instance ID to set as the owner of the new EventResponder instance.</param>
    /// <returns></returns>
    public EventResponseWrapper Clone(GameObject targetObject, int ownerID)
    {
        EventResponder clonedResponder = (EventResponder)ScriptableObject.Instantiate(Responder);

        clonedResponder.Owner = ownerID;

        return(new EventResponseWrapper(GetTargetComponent(targetObject), EventName, clonedResponder));
    }
Ejemplo n.º 7
0
    private static IOrderable GetOrderableAtTime(GameObject parentGameObject, int time)
    {
        foreach (Transform transform in parentGameObject.transform)
        {
            EventFilter sibling = transform.GetComponent <EventFilter>();
            if (sibling != null && sibling.Ordinal == time)
            {
                return(sibling);
            }

            EventResponder responderSibling = transform.GetComponent <EventResponder>();
            if (responderSibling != null && responderSibling.Ordinal == time)
            {
                return(responderSibling);
            }
        }

        return(null);
    }
Ejemplo n.º 8
0
    private static int GetLastExecutionTime(GameObject parentGameObject)
    {
        int nextVal = -1;

        foreach (Transform transform in parentGameObject.transform)
        {
            EventFilter sibling = transform.GetComponent <EventFilter>();
            if (sibling != null)
            {
                nextVal = Math.Max(nextVal, sibling.Ordinal);
            }

            EventResponder responder = transform.GetComponent <EventResponder>();
            if (responder != null)
            {
                nextVal = Math.Max(nextVal, responder.Ordinal);
            }
        }

        return(nextVal);
    }
Ejemplo n.º 9
0
    public void crackdown()
    {
        App    app         = UnityEngine.Object.FindObjectOfType <App>();
        int    playerIndex = app.GetHumanIndex();
        Nation player      = State.getNations()[playerIndex];

        eventLogic.playerCrackDownOnRiot(currentEvent.Province);
        Province disputedProvince = State.getProvince(currentEvent.Province);

        if (currentEvent.OtherMajor != -1 && !player.culture.Equals(disputedProvince.getCulture()))
        {
            Nation         otherMajor = State.getNation(currentEvent.OtherMajor);
            EventResponder responder  = otherMajor.getAI().getEventResponder();
            if (responder.demandReferendum(otherMajor, player, disputedProvince))
            {
                //Now you need to update and re-open decision panel
                DecisionEvent newEvent = new DecisionEvent();
                eventLogic.initalizeAIDemandsreferendumEvent(newEvent, player, otherMajor, disputedProvince);
                currentEvent = newEvent;
                showDecisionPanel(player);
            }
            nextEventTurn(player);
        }
    }
Ejemplo n.º 10
0
    /// <summary>
    /// Gets a list of all types of EventResponders that could be used for the given event.
    /// </summary>
    /// <param name="eventName">The event to retrieve the types for.</param>
    /// <returns></returns>
    private List <Type> GetApplicableResponderTypesForEvent(EventInfo eventInfo)
    {
        List <Type> applicableTypes = new List <Type>();

        //Since all events are checked to be of type EventHandler<T>, [0] will always be the argument type
        Type eventArgumentsType = eventInfo.EventHandlerType.GetGenericArguments()[0];

        foreach (Type type in Assembly.GetAssembly(typeof(EventResponder)).GetTypes())
        {
            if (!type.IsAbstract && type.IsSubclassOf(typeof(EventResponder)))
            {
                EventResponder tempInstance = (EventResponder)ScriptableObject.CreateInstance(type);

                if (tempInstance.GetHandledType().IsAssignableFrom(eventArgumentsType))
                {
                    applicableTypes.Add(type);
                }

                ScriptableObject.DestroyImmediate(tempInstance);
            }
        }

        return(applicableTypes);
    }
 /// <summary>
 /// Removes a responder matching the given criteria from storage.
 /// </summary>
 /// <param name="targetComponent">The component on which the event lives.</param>
 /// <param name="eventName">The name of the event for which the responder listens.</param>
 /// <param name="responder">The responder to remove.</param>
 public void RemoveEventResponder(MonoBehaviour targetComponent, string eventName, EventResponder responder)
 {
     ResponseList.RemoveAll(delegate(EventResponseWrapper response)
     {
         if (response.GetTargetComponent(gameObject) == targetComponent && response.EventName == eventName && response.Responder == responder)
         {
             ScriptableObject.DestroyImmediate(response.Responder);
             return(true);
         }
         else
         {
             return(false);
         }
     });
 }
 /// <summary>
 /// Creates a new instance of EventResponseWrapper, tying the given EventResponder to the specified Event.
 /// </summary>
 /// <param name="targetComponent">The MonoBehaviour that contains the event to which the EventResponder will be bound.</param>
 /// <param name="eventName">The string-name of the Event on the target MonoBehaviour.</param>
 /// <param name="responder">The EventResponder object that will be hooked into the specified event.</param>
 public EventResponseWrapper(MonoBehaviour targetComponent, string eventName, EventResponder responder)
 {
     this.targetComponentTypeName = targetComponent.GetType().Name;
     this.eventName = eventName;
     this.responder = responder;
 }
 /// <summary>
 /// Creates a new instance of EventResponseWrapper, tying the given EventResponder to the specified Event.
 /// </summary>
 /// <param name="targetComponent">The MonoBehaviour that contains the event to which the EventResponder will be bound.</param>
 /// <param name="eventName">The string-name of the Event on the target MonoBehaviour.</param>
 /// <param name="responder">The EventResponder object that will be hooked into the specified event.</param>
 public EventResponseWrapper(MonoBehaviour targetComponent, string eventName, EventResponder responder)
 {
     this.targetComponentTypeName = targetComponent.GetType().Name;
     this.eventName = eventName;
     this.responder = responder;
 }
Ejemplo n.º 14
0
    public void processOptionA()
    {
        Debug.Log("Option A");
        Debug.Log(currentEvent.EventType);
        eventDecisionTwoPanel.SetActive(false);
        closeToolTips();
        App                   app            = UnityEngine.Object.FindObjectOfType <App>();
        int                   playerIndex    = app.GetHumanIndex();
        Nation                player         = State.getNations()[playerIndex];
        Nation                otherMajor     = State.getNation(currentEvent.OtherMajor);
        EventRegister         eventLogic     = State.eventRegister;
        Queue <DecisionEvent> decisionevents = eventLogic.DecisionEvents;

        MyEnum.eventType eventType        = currentEvent.EventType;
        Province         disputedProvince = State.getProvince(currentEvent.Province);
        int            minorNationIndex   = currentEvent.OtherMinor;
        EventResponder responder          = otherMajor.getAI().getEventResponder();

        if (eventType == MyEnum.eventType.riotResponce)
        {
            // Crackdown on riots to restore order
            crackdown();
        }
        else if (eventType == MyEnum.eventType.referendumDemanded)
        {
            // Refuse to hold a referendum
            refuseReferendum(player, otherMajor, disputedProvince);
        }



        else if (eventType == MyEnum.eventType.AI_RejectsReferendum)
        {
            Debug.Log("Player Decides to Declare War");
            war = new War(player, otherMajor, disputedProvince.getIndex(), minorNationIndex);
            prepareWarPanel(player, otherMajor, war);
            return;
        }

        else if (currentEvent.EventType == MyEnum.eventType.notificationOfCrackdown)
        {
            DecisionEvent newEvent = new DecisionEvent();
            Debug.Log("We demand Referendum");
            Debug.Log("Player Name: " + player.getNationName());
            Debug.Log("Other Nation: " + otherMajor.getNationName());
            if (responder.acceptRefDemand(otherMajor, player, disputedProvince))
            {
                Debug.Log("Accepts");
                eventLogic.initalizeAI_AcceptsReferendumEvent(newEvent, currentEvent);
            }
            else
            {
                Debug.Log("Rejects");
                eventLogic.initalizeAI_RejectsReferendumEvent(newEvent, currentEvent);
            }
            currentEvent = newEvent;
            showDecisionPanel(player);
        }



        else if (currentEvent.EventType == MyEnum.eventType.AI_RejectsReferendum)
        {
            // Declare war
            DecisionEvent newEvent = new DecisionEvent();
            war = new War(player, otherMajor, disputedProvince.getIndex(), minorNationIndex);
            prepareWarPanel(player, otherMajor, war);
        }

        else if (currentEvent.EventType == MyEnum.eventType.askIfBoycott)
        {
            player.addBoycott(otherMajor.getIndex());
        }

        else if (currentEvent.EventType == MyEnum.eventType.spreadDissentOppertunity)
        {
            Province prov = State.getProvince(currentEvent.Province);
            prov.adjustDiscontentment(1);
            player.InfulencePoints--;
            DecisionEvent newEvent = new DecisionEvent();

            if (eventLogic.spreadDiscontentDetected(player, otherMajor))
            {
                player.Relations[otherMajor.getIndex()] = -10;
                eventLogic.initializeReportDissentCaughtEvent(newEvent, currentEvent);
            }
            else
            {
                eventLogic.initializeReportDissentInfluenceEvent(newEvent, currentEvent);
            }
            currentEvent = newEvent;
        }

        else if (currentEvent.EventType == MyEnum.eventType.navyIntercept)
        {
            // Player decides to intercept enemy navy
        }



        nextEventTurn(player);
    }
Ejemplo n.º 15
0
    public static bool DrawCustomActionInspectorBar(bool expanded, EventResponder responder, out EventResponder newResponder)
    {
        //Event.current.type == EventType.
        EditorGUILayout.BeginHorizontal();

        EditorGUILayoutExt.BeginLabelStyle(12, FontStyle.Bold, new Color(0.45f, 0.45f, 0.45f), null);
        expanded = GUILayout.Button(expanded ? "▼" : "►", GUI.skin.label, GUILayout.ExpandWidth(false)) ? !expanded : expanded;
        bool newEnabled = GUILayout.Toggle(responder.enabled, "", GUILayout.ExpandWidth(false));

        if (newEnabled != responder.enabled)
        {
            responder.enabled = newEnabled;
        }
        EditorGUILayoutExt.BeginLabelStyle(null, null, new Color(1f, 0.72f, 0.72f), null);

        expanded = GUILayout.Button(responder.GetType().Name, GUI.skin.label, GUILayout.ExpandHeight(false), GUILayout.ExpandWidth(false)) ? !expanded : expanded;
        GUILayout.FlexibleSpace();

        EditorGUILayoutExt.EndLabelStyle();
        EditorGUILayoutExt.EndLabelStyle();

        if (GUILayout.Button("▲", GUILayout.ExpandWidth(false)))
        {
            MoveOrderableUp(responder);
        }

        if (GUILayout.Button("▼", GUILayout.ExpandWidth(false)))
        {
            MoveOrderableDown(responder);
        }

        Type eventType = TriggerGUILayout.DrawActionSelector(responder.GetType());

        if (eventType != null)
        {
            if (eventType != responder.GetType())
            {
                GameObject responderGameObject = responder.gameObject;
                int        executionTime       = responder.Ordinal;
                GameObject.DestroyImmediate(responder);
                responder                = (EventResponder)responderGameObject.AddComponent(eventType);
                responder.Ordinal        = executionTime;
                responderGameObject.name = responder.GetType().Name;
            }
        }
        else
        {
            IOrderable next;
            int        time = responder.Ordinal + 1;
            while ((next = GetOrderableAtTime(responder.gameObject.transform.parent.gameObject, time)) != null)
            {
                next.Ordinal -= 1;
                time++;
            }
            GameObject.DestroyImmediate(responder.gameObject);
            responder = null;
        }

        EditorGUILayout.EndHorizontal();

        newResponder = responder;
        return(expanded);
    }
 /// <summary>
 /// Adds a responder for the given event.
 /// </summary>
 /// <param name="eventInfo">Event to add the responder for.</param>
 /// <param name="responder">The responder object to add.</param>
 public void AddEventResponder(MonoBehaviour targetComponent, string eventName, EventResponder responder)
 {
     ResponseList.Add(new EventResponseWrapper(targetComponent, eventName, responder));
 }
Ejemplo n.º 17
0
 public ActionEditorNode(EventResponder responder, EventEditorContext context)
     : base(context)
 {
     Action = responder;
 }