Esempio n. 1
0
 public void Start()
 {
     if (this.attributePanelUI != null)
     {
         //This is only set if the game allows the player to do customizations to the AI players.
         //Else, the game is in the menu, with the AI players duking out in the background.
         this.aiLevelRateHandler = this.attributePanelUI.aiLevelingRatesObject;
         if (this.aiLevelRateHandler != null && this.aiLevelRateHandler.allAttributes != null)
         {
             List <LevelRate> healthList         = this.aiLevelRateHandler.allAttributes[Category.Health.value];
             List <LevelRate> attackList         = this.aiLevelRateHandler.allAttributes[Category.Attack.value];
             List <LevelRate> attackCooldownList = this.aiLevelRateHandler.allAttributes[Category.AttackCooldown.value];
             List <LevelRate> speedList          = this.aiLevelRateHandler.allAttributes[Category.Speed.value];
             List <LevelRate> splitList          = this.aiLevelRateHandler.allAttributes[Category.Split.value];
             List <LevelRate> mergeList          = this.aiLevelRateHandler.allAttributes[Category.Merge.value];
             for (int i = 0; i < this.maxTiersLimit; i++)
             {
                 TierUpgrade tierUpgrade = this.tiers[i];
                 tierUpgrade.health         = healthList[i].rate;
                 tierUpgrade.attack         = attackList[i].rate;
                 tierUpgrade.attackCooldown = attackCooldownList[i].rate;
                 tierUpgrade.speed          = speedList[i].rate;
                 tierUpgrade.split          = splitList[i].rate;
                 tierUpgrade.merge          = mergeList[i].rate;
                 this.tiers[i] = tierUpgrade;
             }
         }
         else
         {
             Debug.LogError("Something is wrong. Please check.");
         }
     }
 }
Esempio n. 2
0
        public void SetDirectAttackCooldownAttribute(string mathExpression)
        {
            float previousAnswer = 0f;

            for (int i = 0; i < this.tiers.Count; i++)
            {
                float answer = (float)MathParser.ProcessEquation(mathExpression, AttributeProperty.AttackCooldown, i, i - 1, previousAnswer);
                previousAnswer = answer;
                TierUpgrade tier = this.tiers[i];
                tier.attackCooldown = answer;
                this.tiers[i]       = tier;
            }
        }
Esempio n. 3
0
        public void Awake()
        {
            Debug.Log("Initializing AI attribute manager.");
            this.maxTiersLimit = Attributes.MAX_NUM_OF_LEVELS;
            this.tiers         = new List <TierUpgrade>();
            for (int i = 0; i < this.maxTiersLimit; i++)
            {
                TierUpgrade tier = new TierUpgrade();
                if (i == 0)
                {
                    tier.level          = i + 1;
                    tier.health         = 3f;
                    tier.attack         = 1f;
                    tier.speed          = 1.2f;
                    tier.split          = 2f;
                    tier.merge          = 2f;
                    tier.attackCooldown = 3f;
                }
                else
                {
                    TierUpgrade previous = this.tiers[i - 1];
                    tier.level          = i + 1;
                    tier.health         = previous.health * 2f;
                    tier.attack         = previous.attack * 1.2f;
                    tier.speed          = previous.speed * 1.2f;
                    tier.split          = previous.split * 2f;
                    tier.merge          = previous.merge * 2f;
                    tier.attackCooldown = previous.attackCooldown;
                }
                this.tiers.Add(tier);
            }
            GameObject tempAttribute = GameObject.FindGameObjectWithTag("AIAttributePanel");

            if (tempAttribute != null)
            {
                this.attributePanelUI = tempAttribute.GetComponent <AttributePanelUI>();
                if (this.attributePanelUI == null)
                {
                    Debug.LogError("Something is not right.");
                }
            }
            //If tempAttribute is null, then it means the game does not allow the player to do customizations.
            //This means, the only scenario that doesn't allow the player to make customizations would be in
            //the menu screen, where the AI players are duking out without player's interventions.
        }
Esempio n. 4
0
        public void SetMergeAttribute(string mathExpression)
        {
            if (mathExpression.Equals("") || mathExpression.Length <= 0)
            {
                return;
            }
            List <LevelRate> mergeList      = this.aiLevelRateHandler.allAttributes[Category.Merge.value];
            float            previousAnswer = 0f;

            for (int i = 0; i < Attributes.MAX_NUM_OF_LEVELS; i++)
            {
                if (i < mergeList.Count)
                {
                    float answer = (float)MathParser.ProcessEquation(mathExpression, AttributeProperty.Merge, i, i - 1, previousAnswer);
                    previousAnswer = answer;
                    LevelRate rate = mergeList[i];
                    rate.rate  = answer;
                    rate.level = i + 1;
                    if (i > 0)
                    {
                        float rateDiff = rate.rate - mergeList[i - 1].rate;
                        if (rateDiff < 0)
                        {
                            rate.isIncreasing = -1;
                        }
                        else if (rateDiff > 0)
                        {
                            rate.isIncreasing = 1;
                        }
                        else
                        {
                            rate.isIncreasing = 0;
                        }
                    }
                    mergeList[i] = rate;
                }
                if (i < this.tiers.Count)
                {
                    TierUpgrade tier = this.tiers[i];
                    tier.merge    = mergeList[i].rate;
                    this.tiers[i] = tier;
                }
            }
        }
 public void Awake()
 {
     Debug.Log("Initializing AI attribute manager.");
     this.maxTiersLimit = Attributes.MAX_NUM_OF_LEVELS;
     this.tiers = new List<TierUpgrade>();
     for (int i = 0; i < this.maxTiersLimit; i++) {
         TierUpgrade tier = new TierUpgrade();
         if (i == 0) {
             tier.level = i + 1;
             tier.health = 3f;
             tier.attack = 1f;
             tier.speed = 1.2f;
             tier.split = 2f;
             tier.merge = 2f;
             tier.attackCooldown = 3f;
         }
         else {
             TierUpgrade previous = this.tiers[i - 1];
             tier.level = i + 1;
             tier.health = previous.health * 2f;
             tier.attack = previous.attack * 1.2f;
             tier.speed = previous.speed * 1.2f;
             tier.split = previous.split * 2f;
             tier.merge = previous.merge * 2f;
             tier.attackCooldown = previous.attackCooldown;
         }
         this.tiers.Add(tier);
     }
     GameObject tempAttribute = GameObject.FindGameObjectWithTag("AIAttributePanel");
     if (tempAttribute != null) {
         this.attributePanelUI = tempAttribute.GetComponent<AttributePanelUI>();
         if (this.attributePanelUI == null) {
             Debug.LogError("Something is not right.");
         }
     }
     //If tempAttribute is null, then it means the game does not allow the player to do customizations.
     //This means, the only scenario that doesn't allow the player to make customizations would be in
     //the menu screen, where the AI players are duking out without player's interventions.
 }
Esempio n. 6
0
        public void Update()
        {
            if (this.unitCount <= 0 && !this.startAIFlag && this.isSingleAIPlayer && this.hasLostTheGame)
            {
                if (!GameMetricLogger.instance.isShownToScreen)
                {
                    GameMetricLogger.ShowPrintLog();
                }
                return;
            }

            if (this.splitGroupList.Count > 0)
            {
                for (int i = 0; i < this.splitGroupList.Count; i++)
                {
                    SplitGroup splitGroup = this.splitGroupList[i];
                    if (splitGroup.elapsedTime > 1f)
                    {
                        this.splitGroupList.RemoveAt(i);
                        i--;
                    }
                    else
                    {
                        splitGroup.Update();
                        splitGroup.elapsedTime += Time.deltaTime;
                        this.splitGroupList[i]  = splitGroup;
                    }
                }
            }
            if (this.mergeGroupList.Count > 0)
            {
                for (int i = 0; i < this.mergeGroupList.Count; i++)
                {
                    MergeGroup mergeGroup = this.mergeGroupList[i];
                    if (mergeGroup.elapsedTime > 1f)
                    {
                        if (mergeGroup.owner != null)
                        {
                            AIUnit unit = mergeGroup.owner.GetComponent <AIUnit>();
                            unit.previousLevel = unit.level;
                            unit.level++;

                            //TODO: Use the attribute manager to manage the attributes after merging.
                            TierUpgrade tier = this.aiAttributeManager.tiers[unit.level - 1];

                            //float temp = unit.currentHealth;
                            unit.currentHealth = (int)tier.health;                          // (temp * tier.health);
                            //temp = unit.maxHealth;
                            unit.maxHealth = (int)tier.health;                              //(temp * tier.health);

                            unit.attackFactor         = tier.attack;
                            unit.mergeFactor          = tier.merge;
                            unit.attackCooldownFactor = tier.attackCooldown;
                            unit.splitFactor          = tier.split;
                            unit.mergeFactor          = tier.merge;
                            unit.speedFactor          = tier.speed;
                        }
                        if (mergeGroup.merge != null)
                        {
                            this.removeUnitList.Add(mergeGroup.merge.GetComponent <AIUnit>());
                        }
                        //MonoBehaviour.Destroy(mergeGroup.merge);
                        this.mergeGroupList.RemoveAt(i);
                        i--;
                    }
                    else
                    {
                        mergeGroup.Update();
                        mergeGroup.elapsedTime += Time.deltaTime;
                        this.mergeGroupList[i]  = mergeGroup;
                    }
                }
            }
            if (this.removeUnitList.Count > 0)
            {
                foreach (AIUnit unit in this.removeUnitList)
                {
                    if (unit != null)
                    {
                        MonoBehaviour.Destroy(unit.gameObject);
                    }
                }
                this.removeUnitList.Clear();
            }
            this.unitCount = this.unitContainer.transform.childCount;
        }
Esempio n. 7
0
        public void Start()
        {
            bool initialStateFlag = false;

            if (this.unitManager != null)
            {
                AIAttributeManager aiAttributeManager = this.unitManager.aiAttributeManager;
                if (aiAttributeManager.tiers != null)
                {
                    TierUpgrade firstTier = aiAttributeManager.tiers[0];
                    this.maxHealth            = (int)(firstTier.health);
                    this.currentHealth        = this.maxHealth;
                    this.attackFactor         = firstTier.attack;
                    this.attackCooldownFactor = firstTier.attackCooldown;
                    this.speedFactor          = firstTier.speed;
                    this.splitFactor          = firstTier.split;
                    this.mergeFactor          = firstTier.merge;

                    initialStateFlag = true;
                }
            }

            this.currentState          = State.Idle;
            this.level                 = 1;
            this.previousLevel         = 1;
            this.isSplitting           = false;
            this.splitCounter          = 0f;
            this.mergeCounter          = 0f;
            this.attackCooldownCounter = 1f;
            this.recoveryCounter       = 1f;

            if (!initialStateFlag)
            {
                this.speedFactor = 1f;
                if (this.attackFactor == 0f)
                {
                    this.attackFactor = 1f;
                }
                if (this.splitFactor == 0f)
                {
                    this.splitFactor = 1f;
                }
                if (this.mergeFactor == 0f)
                {
                    this.mergeFactor = 1f;
                }
                if (this.attackCooldownFactor == 0f)
                {
                    this.attackCooldownFactor = 1f;
                }
                this.currentHealth = this.maxHealth;
            }
            if (this.lineOfSight == null)
            {
                this.lineOfSight = this.GetComponentInChildren <AILineOfSight>();
                if (this.lineOfSight == null)
                {
                    Debug.LogError("Cannot find Line of Sight component for the AI unit.");
                }
            }
            if (this.attackRange == null)
            {
                this.attackRange = this.GetComponentInChildren <AIAttackRange>();
                if (this.attackRange == null)
                {
                    Debug.LogError("Cannot find Attack Range component for the AI unit.");
                }
            }
            this.agent = this.GetComponent <NavMeshAgent>();
            if (this.agent != null)
            {
                this.agent.stoppingDistance = 1.5f;
                if (!initialStateFlag)
                {
                    this.agent.speed = this.speedFactor;
                }
            }

            GameObject minimapObject = GameObject.FindGameObjectWithTag("Minimap");

            if (minimapObject != null)
            {
                Camera camera = minimapObject.GetComponent <Camera>();
                this.minimapCameraRect = camera.rect;
            }
            else
            {
                minimapObject = GameObject.FindGameObjectWithTag("Menu");
                if (minimapObject != null)
                {
                    Image image = minimapObject.GetComponent <Image>();
                    this.minimapCameraRect = image.rectTransform.rect;
                }
            }
        }