Inheritance: NetworkBehaviour
Exemple #1
0
        public void Attack()
        {
            if (this.targetEnemy != null) {
                //Attack Reach. If a nearby enemy game unit is within attack range, engage and attack.
                AttackArea area = this.GetComponentInChildren<AttackArea>();
                if (area != null) {
                    if (area.enemiesInAttackRange.Contains(this.targetEnemy)) {
                        if (this.attackCooldownCounter <= 0f) {
                            CmdAttack(this.targetEnemy.gameObject, this.unitAttributes.attackCooldownPrefabList[this.level]);

                            GameMetricLogger.Increment(GameMetricOptions.Attacks);
                            GameMetricLogger.Increment(GameMetricOptions.AttackTime);
                        }
                    }
                    else if (area.enemiesInAttackRange.Count > 0) {
                        this.targetEnemy = area.enemiesInAttackRange[0];
                    }

                    GameMetricLogger.Increment(GameMetricOptions.BattleEngagementTime);
                }
            }
            else if (this.targetAIEnemy != null) {
                AttackArea area = this.GetComponentInChildren<AttackArea>();
                if (area != null) {
                    if (area.otherEnemies.Contains(this.targetAIEnemy)) {
                        if (this.attackCooldownCounter <= 0f) {
                            if (this.unitAttributes.attackCooldownPrefabList.Count > 0) {
                                AttackAI(this.targetAIEnemy.gameObject, this.unitAttributes.attackCooldownPrefabList[this.level]);
                            }
                            else {
                                AttackAI(this.targetAIEnemy.gameObject, 1f);
                            }

                            GameMetricLogger.Increment(GameMetricOptions.Attacks);
                            GameMetricLogger.Increment(GameMetricOptions.AttackTime);
                        }
                    }
                    else if (area.otherEnemies.Count > 0) {
                        this.targetAIEnemy = area.otherEnemies[0];
                    }

                    GameMetricLogger.Increment(GameMetricOptions.BattleEngagementTime);
                }
            }
        }
Exemple #2
0
        public override void OnStartClient()
        {
            base.OnStartAuthority();

            //Initialization code for local player (local client on the host, and remote clients).
            this.oldTargetPosition = Vector3.one * -9999f;
            this.oldEnemyTargetPosition = Vector3.one * -9999f;
            this.targetEnemy = null;
            this.targetAIEnemy = null;
            this.isSelected = false;
            this.isDirected = false;
            this.currentHealth = this.maxHealth;
            this.recoverCounter = 1f;
            //this.recoverCooldown = this.attackCooldown + 3.5f;
            this.attackCooldownCounter = this.attackCooldown;
            this.teamFaction = EnumTeam.Player;
            if (this.attackPower <= 1f) {
                this.attackPower = 1f;
            }
            this.level = 1;
            this.previousLevel = 1;

            UpdateUnitAttributes();

            Renderer renderer = this.GetComponent<Renderer>();
            if (renderer != null) {
                this.initialColor = renderer.material.color;
            }
        }