Ejemplo n.º 1
0
 private void SetProjectilePositionAndDirection(ADLAgent projectile, ADLBaseAgent.Direction direction)
 {
     if (direction.Equals(ADLBaseAgent.Direction.Normal))
     {
         projectile.transform.localPosition += new Vector3(this.getX(), this.getY(), 0);
         projectile.horizonDirection         = ADLBaseAgent.Direction.Normal;
     }
     else
     {
         projectile.transform.localPosition += new Vector3(-this.getX(), this.getY(), 0);
         projectile.horizonDirection         = ADLBaseAgent.Direction.Inverse;
     }
 }
Ejemplo n.º 2
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();
    }
Ejemplo n.º 3
0
 private void ResetEnemy(bool isEnemyAlive)
 {
     if (isEnemyAlive)
     {
         this.Enemy.agentScript         = BossFightAcademy.Instance.RandomEnemyScript();
         this.Enemy.isInitStateExecuted = false;
         this.Enemy.Start();
     }
     else
     {
         Text       enemyLifePointText = this.Enemy.agentLifePointText;
         GameObject enemy = Instantiate(EnemyPrefab, this.transform.parent);
         this.Enemy                    = enemy.GetComponent <ADLAgent>();
         this.Enemy.agentScript        = BossFightAcademy.Instance.RandomEnemyScript();
         this.Enemy.agentLifePointText = enemyLifePointText;
     }
 }
Ejemplo n.º 4
0
    protected override void Perform(ADLAgent agent)
    {
        Vector2 directionVector;

        if (ADLAgent.currentUpdatingAgent.simulationState.singleQueryProperties[this].ContainsKey(this))
        {
            directionVector = (Vector2)ADLAgent.currentUpdatingAgent.simulationState.singleQueryProperties[this][this];
        }
        else
        {
            Vector2 position = agent.GetComponent <Rigidbody2D>().position;
            Vector2 target   = new Vector2(this.GetX(), this.GetY());
            directionVector = (target - position).normalized;
            ADLAgent.currentUpdatingAgent.simulationState.singleQueryProperties[this].Add(this, directionVector);
        }

        agent.velocity = directionVector * this.GetVelocity();
    }
Ejemplo n.º 5
0
    protected override void Perform(ADLAgent agent)
    {
        ADLBaseAgent player = ADLBaseAgent.FindAgent("Player", agent.transform.parent);

        try {
            if (player.transform.localPosition.x > agent.transform.localPosition.x)
            {
                agent.horizonDirection = ADLBaseAgent.Direction.Normal;
            }
            else
            {
                agent.horizonDirection = ADLBaseAgent.Direction.Inverse;
            }
        } catch (Exception e) when(e is NullReferenceException || e is MissingReferenceException)
        {
            Debug.LogError("Player Not Found: " + e.Message);
        }
    }
Ejemplo n.º 6
0
    public override object PerformFunction()
    {
        ADLAction currentAction = ADLAction.performingAction;
        ADLAgent  currentAgent  = ADLAgent.currentUpdatingAgent;

        if (!currentAgent.simulationState.singleQueryProperties[currentAction].ContainsKey(this))
        {
            currentAgent.simulationState.singleQueryProperties[currentAction].Add(this, 0);
        }

        int count = (int)currentAgent.simulationState.singleQueryProperties[currentAction][this];

        if (this.GetIsConditionMatched())
        {
            count++;
            currentAgent.simulationState.singleQueryProperties[currentAction][this] = count;
        }
        return(count >= this.GetAmount());
    }
Ejemplo n.º 7
0
    // Update is called once per frame
    protected new void FixedUpdate()
    {
        if (this.agentScript != null)
        {
            ADLAgent.currentUpdatingAgent = this;

            this.PerformAction();

            base.FixedUpdate();

            this.UpdateSimulationState();

            this.collisionList.Clear();

            if (this.isProjectile && !this.isHittableByEnvironment)
            {
                if (this.rb2d.position.x < -12 || this.rb2d.position.x > 12 ||
                    this.rb2d.position.y < -8 || this.rb2d.position.y > 8)
                {
                    Destroy(this.gameObject);
                }
            }
        }
    }
Ejemplo n.º 8
0
 protected override void Perform(ADLAgent agent)
 {
     agent.velocity = new Vector2(this.GetXVelocity(agent), this.GetYVelocity(agent));
 }
Ejemplo n.º 9
0
 protected override void Perform(ADLAgent agent)
 {
     //Do Nothing
 }
Ejemplo n.º 10
0
 protected override void Perform(ADLAgent agent)
 {
     agent.simulationState.SetCurrentState(agent.agentScript.FindState(this.GetStateName()));
 }
Ejemplo n.º 11
0
    protected override void Perform(ADLAgent agent)
    {
        Rigidbody2D rigidbody2D = agent.GetComponent <Rigidbody2D>();

        agent.horizonDirection = ADLBaseAgent.GetOppositeDirection(agent.horizonDirection);
    }
Ejemplo n.º 12
0
 protected abstract void Perform(ADLAgent agent);
Ejemplo n.º 13
0
 public void PerformAction(ADLAgent agent)
 {
     ADLAction.performingAction = this;
     this.Perform(agent);
 }
Ejemplo n.º 14
0
 protected override void Perform(ADLAgent agent)
 {
     Object.Destroy(agent.gameObject);
 }
Ejemplo n.º 15
0
    protected override void Perform(ADLAgent agent)
    {
        switch (this.GetPropertyName())
        {
        case "x":
            agent.transform.localPosition = new Vector3((float)this.GetValue(), agent.transform.localPosition.y, agent.transform.localPosition.z);
            break;

        case "y":
            agent.transform.localPosition = new Vector3(agent.transform.localPosition.x, (float)this.GetValue(), agent.transform.localPosition.z);
            break;

        case "width": {
            Vector2 colliderSize = agent.GetComponent <BoxCollider2D>().size;
            float   width        = (float)this.GetValue();
            agent.transform.localScale = new Vector3(width / colliderSize.x, agent.transform.localScale.y, 1);
            break;
        }

        case "height": {
            Vector2 colliderSize = agent.GetComponent <BoxCollider2D>().size;
            float   height       = (float)this.GetValue();
            agent.transform.localScale = new Vector3(agent.transform.localScale.x, height / colliderSize.y, 1);
            break;
        }

        case "lifePoint":
            agent.lifePoint = (float)this.GetValue();
            break;

        case "attack":
            agent.attack = (float)this.GetValue();
            break;

        case "isAttacker":
            agent.isAttacker = (bool)this.GetValue();
            break;

        case "isDefender":
            agent.isDefender = (bool)this.GetValue();
            break;

        case "isFlippable":
            agent.isFlippable = (bool)this.GetValue();
            break;

        case "isFlipper":
            agent.isFlipper = (bool)this.GetValue();
            break;

        case "isProjectile":
            agent.isProjectile = (bool)this.GetValue();
            break;

        case "group":
            string groupName = this.GetValue().ToString();
            groupName = groupName.Substring(1, groupName.Length - 2);
            switch (groupName)
            {
            case "Player":
                agent.group = ADLBaseAgent.Group.Player;
                break;

            case "Enemy":
                agent.group = ADLBaseAgent.Group.Enemy;
                break;

            default:
                break;
            }
            break;

        case "horizontalDirection":
            agent.horizonDirection = ((float)this.GetValue()) > 0 ? ADLBaseAgent.Direction.Normal : ADLBaseAgent.Direction.Inverse;
            break;

        case "verticalDirection":
            agent.verticalDirection = ((float)this.GetValue()) > 0 ? ADLBaseAgent.Direction.Normal : ADLBaseAgent.Direction.Inverse;
            break;

        case "spawnDirection":
            string spawnDirection = this.GetValue().ToString();
            spawnDirection = spawnDirection.Substring(1, spawnDirection.Length - 2);
            switch (spawnDirection)
            {
            case "Player":
                break;

            case "Normal":
                break;

            default:
                break;
            }
            break;

        case "isInvulnerable":
            agent.isInvulnerable = (bool)this.GetValue();
            break;

        case "isHittableByProjectile":
            agent.isHittableByProjectile = (bool)this.GetValue();
            break;

        case "isHittableByEnvironment":
            agent.isHittableByEnvironment = (bool)this.GetValue();
            break;

        case "safeEnvironmentList":
            for (int i = 1; i < this.parameters.Count; i++)
            {
                agent.safeEnvironmentList.Add(this.GetStringParameter(i));
            }
            break;
        }
    }
Ejemplo n.º 16
0
 public new bool PerformAction(ADLAgent agent)
 {
     base.PerformAction(agent);
     return(this.GetBoolParameter(0));
 }