Esempio n. 1
0
    public ADLScript CreateADLScript(string scriptText)
    {
        scriptText = RegexCommentPattern.Replace(scriptText, "");

        this.primaryAgentScript = null;

        Regex  currentRegex          = GetRegexByState(null);
        int    currentADLScriptIndex = 0;
        string parsingState          = "name";
        string nextParsingState;
        Match  token;

        while (currentRegex.IsMatch(scriptText, currentADLScriptIndex))
        {
            token            = currentRegex.Match(scriptText, currentADLScriptIndex);
            nextParsingState = this.Parse(parsingState, token);

            if (nextParsingState == null || !nextParsingState.Equals(parsingState))
            {
                currentRegex = GetRegexByState(nextParsingState);
                parsingState = nextParsingState;
            }
            currentADLScriptIndex = token.Index + token.Length;
        }

        return(this.primaryAgentScript);
    }
Esempio n. 2
0
 private void CompileScript()
 {
     if (this.agentScript == null)
     {
         this.agentScript = ADLScriptFactory.instance.CreateADLScript(this.agentScriptFile.text);
         // Debug.Log("Total SubAgent scripts: " + this.currentScript.subAgentScripts.Count);
         // for (int i = 0; i < this.agentScript.subAgentScripts.Count; i++){
         //  Debug.Log("Projectile Agent:" + this.currentScript.subAgentScripts[i].agentName);
         // }
         //this.PrintEnemyBehavior();
     }
 }
Esempio n. 3
0
    protected override void Perform(ADLAgent agent)
    {
        //Find SubAgentScript by name
        string spawnAgentName = this.getAgentName();
        string spawnDirection = this.getSpawnDirection();

        ADLScript subAgentScript = agent.agentScript.subAgentScripts.Find(
            script => script.agentName.Equals(spawnAgentName));

        //Instantiate new Agent Object and Assign SubAgentScript to it
        GameObject     projectile     = GameObject.Instantiate(agent.agentPrefab) as GameObject;
        SpriteRenderer spriteRenderer = projectile.GetComponent <SpriteRenderer>();

        spriteRenderer.color = Color.red;

        ADLAgent subAgent = projectile.GetComponent <ADLAgent>();

        subAgent.isInitStateExecuted         = false;
        subAgent.agentScript                 = subAgentScript;
        subAgent.agentScript.subAgentScripts = agent.agentScript.subAgentScripts;

        Vector2 colliderSize = projectile.GetComponent <BoxCollider2D>().size;

        projectile.transform.localPosition = agent.transform.localPosition;

        if (spawnDirection.Equals("TowardPlayer"))
        {
            try {
                ADLBaseAgent player = ADLBaseAgent.FindAgent("Player", agent.transform.parent);
                if (player.transform.localPosition.x > agent.transform.localPosition.x)
                {
                    SetProjectilePositionAndDirection(subAgent, ADLBaseAgent.Direction.Normal);
                }
                else
                {
                    SetProjectilePositionAndDirection(subAgent, ADLBaseAgent.Direction.Inverse);
                }
            } catch (Exception e) when(e is NullReferenceException || e is MissingReferenceException)
            {
                Debug.LogError("Player Not Found: " + e.Message);
                SetProjectilePositionAndDirection(subAgent, agent.horizonDirection);
            }
        }
        else
        {
            SetProjectilePositionAndDirection(subAgent, agent.horizonDirection);
        }
        projectile.transform.localScale = new Vector3(this.getWidth() / colliderSize.x, this.getHeight() / colliderSize.y);

        subAgent.Start();
    }
Esempio n. 4
0
    private string ParseLevelName(string parsingState, Match token)
    {
        if (token.Groups["Name"].Length != 0)
        {
            this.compilerStack.Push(parsingState);
            parsingState = "state";

            ADLScript agentScript = new ADLScript(token.Groups["Name"].Value);
            this.currentAgentScript = agentScript;

            if (this.primaryAgentScript == null)
            {
                this.Log("Agent Name : " + token.Groups["Name"]);
                this.primaryAgentScript = agentScript;
            }
            else
            {
                this.Log("SubAgent Name : " + token.Groups["Name"]);
                this.primaryAgentScript.subAgentScripts.Add(agentScript);
            }
        }
        return(parsingState);
    }