Example #1
0
        public override void OnGui()
        {
            State state = m_Container.m_Editor.m_TargetObject.GetComponent(typeof(State)) as State;

            if (state != null)
            {
                List <string> variableNames;
                state.GetVariables(out variableNames);

                if (variableNames.Count > 0)
                {
                    int selection = variableNames.FindIndex(x => x == m_VariableName);
                    selection = Math.Max(0, selection);

                    EditorGUILayout.BeginHorizontal();
                    selection      = EditorGUILayout.Popup(selection, variableNames.ToArray());
                    m_VariableName = variableNames[selection];
                    Variable variable;
                    state.GetVariable(m_VariableName, out variable);
                    m_VariableType = variable.GetVariableType();
                    EditorGUILayout.EndHorizontal();
                }
                else
                {
                    EditorGUILayout.HelpBox("Please Add Variables", MessageType.Info);
                }
            }
        }
Example #2
0
        XMLRules.ActionType MakeAction(NodeBase node)
        {
            if (node.m_NodeType == NodeType.SETVARIABLE)
            {
                SetNode setNode = (SetNode)node;

                if (m_State != null)
                {
                    Variable variable;

                    if (setNode.m_Children.Count >= 1)
                    {
                        if (m_State.GetVariable(setNode.m_VariableName, out variable))
                        {
                            ArithmeticExpression value = CreateArithmeticExpression(setNode.m_Children[0]);
                            return(m_RuleMaker.MakeStateChangeAction(setNode.m_VariableName, variable.m_Type, value));
                        }
                        else
                        {
                            Debug.LogError("Invalid assignment: variable " + setNode.m_VariableName + " not found");
                        }
                    }
                    else
                    {
                        Debug.LogError("Invalid assignment: no value was specified");
                    }
                }
            }
            else if (node.m_NodeType == NodeType.CALLSCRIPT)
            {
                CallNode callNode = (CallNode)node;
                return(m_RuleMaker.MakeCallScriptAction(callNode));
            }

            return(null);
        }
Example #3
0
        public override bool Execute()
        {
            ele         = Go.GetComponent <Unite>();
            deplacement = ele.deplacement;
            mouvement   = ele.mouvement;
            State    etat = Go.GetComponent <State>();
            Variable var  = new Variable();

            etat.GetVariable("prox", out var);
            if ((int)var.GetValue() == 1)
            {
                if (!calcule)
                {
                    direction = 1;
                    Vector2 res = FindRessource();
                    ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, (int)res.x, (int)res.y);
                    deplacement     = ele.deplacement;
                    calcule         = true;
                    init            = 1;
                }
            }
            else if ((int)var.GetValue() == 2)
            {
                if (!calcule)
                {
                    direction = 2;
                    Vector2 res = FindRessource();
                    ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, (int)res.x, (int)res.y);
                    calcule         = true;
                    if (Go.GetComponent <Element>().camp == "Ours")
                    {
                        Score.ressource_IA[0]       += Unite.stockage * init;
                        Score.ressourcediv_IA[0][0] += Unite.stockage * init * Batiment.aggressivite / 100;
                        Score.ressourcediv_IA[0][1] += Unite.stockage * init * (1 - Batiment.aggressivite / 100) * Batiment.defense / 100;
                        Score.ressourcediv_IA[0][2] += Unite.stockage * init * (1 - Batiment.aggressivite / 100) * Batiment.technologie / 100;
                    }
                    else if (Go.GetComponent <Element>().camp == "Poulpe")
                    {
                        Score.ressource_IA[1]       += Unite.stockage * init;
                        Score.ressourcediv_IA[1][0] += Unite.stockage * init * Batiment.aggressivite / 100;
                        Score.ressourcediv_IA[1][1] += Unite.stockage * init * (1 - Batiment.aggressivite / 100) * Batiment.defense / 100;
                        Score.ressourcediv_IA[1][2] += Unite.stockage * init * (1 - Batiment.aggressivite / 100) * Batiment.technologie / 100;
                    }
                }
            }
            else if ((int)var.GetValue() == 0)
            {
                calcule = false;
            }
            if (deplacement != null)
            {
                if (deplacement.Count != 0)
                {
                    for (int i = 0; i < ele.hauteur; i++)
                    {
                        for (int j = 0; j < ele.largeur; j++)
                        {
                            ele.list_case[i, j] = Niveau.grille[(int)(i + Go.transform.position.x - 0.5), (int)(j + Go.transform.position.y - 0.5)];
                            ele.list_case[i, j].GetComponent <Case>().occupe  = false;
                            ele.list_case[i, j].GetComponent <Case>().element = null;
                        }
                    }

                    StartCoroutine("MoveTowards");
                }
                else
                {
                    Vector2 res = FindRessource();
                    ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, (int)res.x, (int)res.y);
                    mouvement       = 0;
                }
            }
            return(true);
        }