Esempio n. 1
0
 public void StopSimulation()
 {
     this.gameMatchStart = false;
     this.ClearSimulation();
     this.InitializeSimulation();
     SimulationMetricsLogger.SetGameLogger(GameLoggerOptions.StopGameMetrics);
     SimulationMetricsLogger.SetGameLogger(GameLoggerOptions.GameIsOver);
 }
Esempio n. 2
0
 public void StartSimulation()
 {
     this.gameMatchStart = true;
     this.sessionNumber  = 1;
     SimulationMetricsLogger.ResetLogger();
     SimulationMetricsLogger.SetGameLogger(GameLoggerOptions.StartGameMetrics);
     SimulationMetricsLogger.SetGameLogger(GameLoggerOptions.GameIsPlaying);
 }
Esempio n. 3
0
 public void PauseSimulation()
 {
     this.gamePaused = !this.gamePaused;
     if (this.gamePaused)
     {
         SimulationMetricsLogger.SetGameLogger(GameLoggerOptions.GameIsOver);
     }
     else
     {
         SimulationMetricsLogger.SetGameLogger(GameLoggerOptions.GameIsPlaying);
     }
 }
Esempio n. 4
0
 public void TakeDamage(float damageAmount)
 {
     this.currentHealth  -= Mathf.FloorToInt(damageAmount);
     this.recoveryCounter = 0f;
     if (this.currentHealth <= 0)
     {
         MonoBehaviour.Destroy(this.gameObject);
         //EnumTeam index value is constant: Player = 0, Computer = 1
         SimulationMetricsLogger.Increment(GameMetricOptions.Death, (this.teamFaction == EnumTeam.Player) ? 0 : 1);
         SimulationMetricsLogger.Increment(GameMetricOptions.Kills, (this.teamFaction != EnumTeam.Player) ? 0 : 1);
     }
 }
Esempio n. 5
0
        public void FixedUpdate()
        {
            if (this.sessionNumberText != null)
            {
                this.sessionNumberText.text = this.sessionNumber.ToString();
            }

            if (!this.gameMatchStart)
            {
                return;
            }

            if (this.gamePaused)
            {
                this.timePauseCounter = 1f;
                this.yellowTeamAI.Deactivate();
                this.blueTeamAI.Deactivate();
                return;
            }

            if (this.timePauseCounter > 0f)
            {
                this.timePauseCounter -= Time.deltaTime;
                return;
            }
            else
            {
                if (this.yellowTeamUnits.transform.childCount <= 0 && this.blueTeamUnits.transform.childCount <= 0)
                {
                    InitializeSimulation();
                    this.yellowTeamAI.Activate();
                    this.blueTeamAI.Activate();
                    return;
                }
            }

            if (this.yellowTeamAI != null)
            {
                if (this.yellowTeamUnits.transform.childCount > 0)
                {
                    this.yellowTeamAI.Activate();
                }
            }
            if (this.blueTeamAI != null)
            {
                if (this.blueTeamUnits.transform.childCount > 0)
                {
                    this.blueTeamAI.Activate();
                }
            }

            if (this.yellowTeamUnits.transform.childCount <= 0 || this.blueTeamUnits.transform.childCount <= 0)
            {
                this.yellowTeamAI.Deactivate();
                this.blueTeamAI.Deactivate();

                SimulationMetricsLogger.Increment(GameMetricOptions.Wins, (this.yellowTeamUnits.transform.childCount > 0) ? 0 : 1);
                SimulationMetricsLogger.Increment(GameMetricOptions.Losses, (this.yellowTeamUnits.transform.childCount <= 0) ? 0 : 1);

                ContinueSimulation();
            }
        }
Esempio n. 6
0
        public void Update()
        {
            if (this.attackCooldownCounter >= 0f)
            {
                this.attackCooldownCounter -= Time.deltaTime / this.attackCooldownFactor;
            }

            //Check if targetEnemy is within sight range.
            if (this.targetEnemy != null)
            {
                if (this.lineOfSight != null)
                {
                    this.lineOfSight.sphereColliderRigidBody.WakeUp();
                    if (!this.lineOfSight.enemies.Contains(this.targetEnemy.gameObject))
                    {
                        this.targetEnemy  = null;
                        this.currentState = State.Idle;
                        this.lineOfSight.Clean();
                    }
                }
                else if (this.attackRange != null)
                {
                    this.attackRange.sphereColliderRigidBody.WakeUp();
                    if (!this.attackRange.enemies.Contains(this.targetEnemy.gameObject))
                    {
                        this.targetEnemy  = null;
                        this.currentState = State.Idle;
                        this.attackRange.Clean();
                    }
                }
            }

            if (this.targetEnemy == null && this.currentState != State.Split && this.currentState != State.Merge)
            {
                if (this.lineOfSight != null)
                {
                    this.lineOfSight.sphereColliderRigidBody.WakeUp();
                    if (this.lineOfSight.enemies.Count > 0)
                    {
                        for (int i = 0; i < this.lineOfSight.enemies.Count; i++)
                        {
                            GameObject enemy = this.lineOfSight.enemies[i];
                            if (enemy != null)
                            {
                                AIUnit   aiUnit     = enemy.GetComponentInParent <AIUnit>();
                                GameUnit playerUnit = enemy.GetComponent <GameUnit>();
                                if (aiUnit != null || playerUnit != null)
                                {
                                    if (aiUnit != null && aiUnit.teamFaction != this.teamFaction)
                                    {
                                        if (this.agent != null)
                                        {
                                            this.agent.SetDestination(aiUnit.transform.position);
                                        }
                                        this.currentState = State.Attack;
                                        break;
                                    }
                                    else if (playerUnit != null && playerUnit.teamFaction != this.teamFaction)
                                    {
                                        if (this.agent != null)
                                        {
                                            this.agent.SetDestination(playerUnit.transform.position);
                                        }
                                        this.currentState = State.Attack;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            switch (this.currentState)
            {
            default:
            case State.Idle:
                if (this.targetEnemy != null)
                {
                    this.currentState = State.Attack;
                    break;
                }
                if (this.agent != null)
                {
                    if (!this.agent.ReachedDestination())
                    {
                        this.agent.ResetPath();
                    }
                }
                break;

            case State.Split:
                if (this.splitCounter > 0f)
                {
                    this.splitCounter -= Time.deltaTime / this.splitFactor;
                }
                else
                {
                    this.currentState = State.Idle;
                    if (this.agent != null)
                    {
                        this.agent.ResetPath();
                    }
                    //EnumTeam index value is constant: Player = 0, Computer = 1
                    SimulationMetricsLogger.Increment(GameMetricOptions.Splits, (this.teamFaction == EnumTeam.Player) ? 0 : 1);
                }
                break;

            case State.Scout:
                if (this.targetEnemy != null)
                {
                    this.currentState = State.Attack;
                    break;
                }
                if (this.agent != null)
                {
                    if (this.agent.ReachedDestination())
                    {
                        this.targetEnemy  = null;
                        this.currentState = State.Idle;
                    }
                }
                break;

            case State.Merge:
                if (this.targetEnemy != null)
                {
                    this.currentState = State.Attack;
                    break;
                }
                if (this.mergeCounter > 0f)
                {
                    this.mergeCounter -= Time.deltaTime / this.mergeFactor;
                }
                else
                {
                    this.currentState = State.Idle;
                    //EnumTeam index value is constant: Player = 0, Computer = 1
                    SimulationMetricsLogger.Increment(GameMetricOptions.Merges, (this.teamFaction == EnumTeam.Player) ? 0 : 1);
                }
                break;

            case State.Attack:
                //Attack logic.
                if (this.attackCooldownCounter < 0f)
                {
                    if (this.lineOfSight != null && this.lineOfSight.enemies.Count > 0 && this.attackRange != null && this.attackRange.enemies.Count > 0)
                    {
                        for (int i = 0; i < this.attackRange.enemies.Count; i++)
                        {
                            GameObject enemy = this.attackRange.enemies[i];
                            if (enemy != null)
                            {
                                AIUnit   aiUnit     = enemy.GetComponentInParent <AIUnit>() as AIUnit;
                                GameUnit playerUnit = enemy.GetComponent <GameUnit>() as GameUnit;
                                if (aiUnit != null && aiUnit.teamFaction != this.teamFaction)
                                {
                                    this.attackCooldownCounter = 1f;
                                    this.targetEnemy           = aiUnit;
                                    aiUnit.TakeDamage(this.attackFactor);
                                    //EnumTeam index value is constant: Player = 0, Computer = 1
                                    SimulationMetricsLogger.Increment(GameMetricOptions.Attacks, (this.teamFaction == EnumTeam.Player) ? 0 : 1);
                                    SimulationMetricsLogger.Increment(GameMetricOptions.AttackTime, (this.teamFaction == EnumTeam.Player) ? 0 : 1);
                                    break;
                                }
                                if (playerUnit != null && playerUnit.teamFaction != this.teamFaction)
                                {
                                    this.attackCooldownCounter = 1f;
                                    this.targetEnemy           = playerUnit;
                                    playerUnit.CmdTakeDamage(playerUnit.gameObject, playerUnit.currentHealth - 1);
                                    //EnumTeam index value is constant: Player = 0, Computer = 1
                                    SimulationMetricsLogger.Increment(GameMetricOptions.Attacks, (this.teamFaction == EnumTeam.Player) ? 0 : 1);
                                    SimulationMetricsLogger.Increment(GameMetricOptions.AttackTime, (this.teamFaction == EnumTeam.Player) ? 0 : 1);
                                    break;
                                }
                            }
                        }
                    }
                }
                //EnumTeam index value is constant: Player = 0, Computer = 1
                SimulationMetricsLogger.Increment(GameMetricOptions.BattleEngagementTime, (this.teamFaction == EnumTeam.Player) ? 0 : 1);
                break;
            }

            if (this.recoveryCounter < 1f)
            {
                this.recoveryCounter += Time.deltaTime;
            }
            Renderer renderer = this.GetComponent <Renderer>();

            if (renderer != null)
            {
                renderer.material.color = Color.Lerp(this.takeDamageColor, this.initialColor, this.recoveryCounter);
            }
        }