public MergeGroup(GameUnit ownerUnit, GameUnit mergingUnit, float mergeFactor) { this.ownerUnit = ownerUnit; this.mergingUnit = mergingUnit; this.ownerUnit.isMerging = true; this.mergingUnit.isMerging = true; this.elapsedTime = 0f; this.ownerPosition = ownerUnit.gameObject.transform.position; this.mergingPosition = mergingUnit.gameObject.transform.position; this.origin = Vector3.Lerp(this.ownerPosition, this.mergingPosition, 0.5f); this.ownerScale = ownerUnit.gameObject.transform.localScale; this.mergingScale = mergingUnit.gameObject.transform.localScale; this.mergeSpeedFactor = mergeFactor; if (ownerUnit.unitAttributes == null) { Debug.LogError("Owner unit attributes are null."); } else { } if (mergingUnit.unitAttributes == null) { Debug.LogError("Merging unit attributes are null."); } this.Stop(); }
public SplitGroup(GameUnit ownerUnit, GameUnit splitUnit, float angle, float splitFactor) { this.ownerUnit = ownerUnit; this.splitUnit = splitUnit; this.elapsedTime = 0f; this.origin = ownerUnit.gameObject.transform.position; this.splitFactor = splitFactor; SpawnRange range = this.ownerUnit.GetComponentInChildren<SpawnRange>(); this.rotationVector = Quaternion.Euler(0f, angle, 0f) * (Vector3.one * range.radius); this.rotationVector.y = 0f; NavMeshAgent agent = this.ownerUnit.GetComponent<NavMeshAgent>(); if (agent != null) { agent.ResetPath(); agent.Stop(); } agent = this.splitUnit.GetComponent<NavMeshAgent>(); if (agent != null) { agent.ResetPath(); agent.Stop(); } NetworkTransform transform = this.ownerUnit.GetComponent<NetworkTransform>(); if (transform != null) { transform.transformSyncMode = NetworkTransform.TransformSyncMode.SyncNone; } transform = this.splitUnit.GetComponent<NetworkTransform>(); if (transform != null) { transform.transformSyncMode = NetworkTransform.TransformSyncMode.SyncNone; } }
private static void Increment(GameUnit unit) { unit.isSelected = !unit.isSelected; unit.isDirected = !unit.isDirected; unit.isSplitting = !unit.isSplitting; unit.isMerging = !unit.isMerging; unit.currentHealth++; unit.maxHealth++; unit.attackPower++; unit.attackCooldown++; unit.speed++; //unit.recoverCooldown++; unit.level++; unit.previousLevel++; unit.teamColorValue = (unit.teamColorValue + 1) % 3; }
private static void Copy(GameUnit original, GameUnit copy) { copy.isSelected = original.isSelected; copy.isSplitting = original.isSplitting; copy.isMerging = original.isMerging; copy.transform.position = original.transform.position; copy.transform.rotation = original.transform.rotation; copy.transform.localScale = original.transform.localScale; copy.oldTargetPosition = original.oldTargetPosition = -Vector3.one * 9999f; copy.isDirected = original.isDirected = false; copy.level = original.level; copy.previousLevel = original.previousLevel; copy.currentHealth = original.currentHealth; copy.maxHealth = original.maxHealth; if (copy.currentHealth > copy.maxHealth) { copy.currentHealth = copy.maxHealth; } if (original.currentHealth > original.maxHealth) { original.currentHealth = original.maxHealth; } //copy.recoverCooldown = original.recoverCooldown; copy.recoverCounter = original.recoverCounter = 1f; copy.speed = original.speed; copy.attackCooldown = original.attackCooldown; copy.attackCooldownCounter = original.attackCooldownCounter = 0; copy.attackPower = original.attackPower; copy.unitAttributes = original.unitAttributes; copy.teamColorValue = original.teamColorValue; original.SetTeamColor(original.teamColorValue); copy.SetTeamColor(copy.teamColorValue); copy.teamFaction = original.teamFaction; }
public void Update() { //Because the game is now spawning objects from the player-owned objects (spawning from NetworkManager-spawned objects), don't check for //isLocalPlayer, but instead check to see if the clients have authority over the non-player owned objects spawned from the NetworkManager-spawned objects. //Wordy, I know... if (!this.hasAuthority) { return; } if (this.isSplitting || this.isMerging) { return; } //Simple, "quick," MOBA-style controls. Hence, the class name. if (this.isSelected) { this.selectionRing.SetActive(true); Vector3 screenPoint = Camera.main.ScreenToViewportPoint(Input.mousePosition); if (!MinimapStuffs.Instance.minimapCamera.rect.Contains(screenPoint)) { if (Input.GetMouseButtonDown(1)) { CastRay(false, Input.mousePosition, null); } } } else { this.selectionRing.SetActive(false); } //Obtaining the nav mesh agent here for future uses. NavMeshAgent agent = this.GetComponent <NavMeshAgent>(); //Non-directed, self-defense LineOfSight sight = this.GetComponentInChildren <LineOfSight>(); AttackArea area = this.GetComponentInChildren <AttackArea>(); if (!this.isDirected || agent.remainingDistance < 0.5f) { //Line of Sight. Detects if there are nearby enemy game units, and if so, follow them to engage in battle. if (sight != null && area != null) { //There are 4 cases when detecting an enemy in both areas, line of sight and attack range. I had to consider each of the cases //in order to ease the Console error gods... // (12/5/2015) Now there are 8 cases in total. Consider AI players. GameUnit sightGameUnit = null; if (sight.enemiesInRange.Count > 0) { foreach (GameUnit temp in sight.enemiesInRange) { if (temp != null) { sightGameUnit = temp; break; } } } GameUnit attackGameUnit = null; if (sight.enemiesInRange.Count > 0) { foreach (GameUnit temp in sight.enemiesInRange) { if (temp != null) { attackGameUnit = temp; break; } } } AIUnit sightAiUnit = null; if (sight.otherEnemies.Count > 0) { foreach (AIUnit temp in sight.otherEnemies) { if (temp != null) { sightAiUnit = temp; break; } } } AIUnit attackAiUnit = null; if (sight.otherEnemies.Count > 0) { foreach (AIUnit temp in sight.otherEnemies) { if (temp != null) { attackAiUnit = temp; break; } } } if (sightGameUnit != null && attackGameUnit != null) { SetTargetEnemy(this.gameObject, sightGameUnit.gameObject, attackGameUnit.gameObject); CmdSetTargetEnemy(this.gameObject, sightGameUnit.gameObject, attackGameUnit.gameObject); } else if (sightGameUnit != null && attackGameUnit == null) { SetTargetEnemy(this.gameObject, sightGameUnit.gameObject, sightGameUnit.gameObject); CmdSetTargetEnemy(this.gameObject, sightGameUnit.gameObject, sightGameUnit.gameObject); } else if (sightGameUnit == null && attackGameUnit != null) { SetTargetEnemy(this.gameObject, attackGameUnit.gameObject, attackGameUnit.gameObject); CmdSetTargetEnemy(this.gameObject, attackGameUnit.gameObject, attackGameUnit.gameObject); } else { SetTargetEnemy(this.gameObject, this.gameObject, this.gameObject); CmdSetTargetEnemy(this.gameObject, this.gameObject, this.gameObject); } if (sightAiUnit != null && attackAiUnit != null) { SetTargetAIEnemy(this.gameObject, sightAiUnit.gameObject, attackAiUnit.gameObject); } else if (sightAiUnit != null && attackAiUnit == null) { SetTargetAIEnemy(this.gameObject, sightAiUnit.gameObject, sightAiUnit.gameObject); } else if (sightAiUnit == null && attackAiUnit != null) { SetTargetAIEnemy(this.gameObject, attackAiUnit.gameObject, attackAiUnit.gameObject); } else { SetTargetAIEnemy(this.gameObject, this.gameObject, this.gameObject); } } } //Start attacking. Attack(); //Updating status. UpdateStatus(); //Keeping track of whether the game unit is carrying out a player's command, or is carrying out self-defense. if (agent != null && agent.ReachedDestination()) { this.isDirected = false; } }