/// <summary> /// /// </summary> /// <param name="attacker"></param> /// <param name="target"></param> /// <returns>A winner if one exists</returns> private async Task <Uwudle> AttackCycle(Uwudle attacker, Uwudle target) { if (attacker == null || target == null) { throw new BattleException(); } if (attacker.Health.Hp == 0) { return(target); } else if (target.Health.Hp == 0) { return(attacker); } attacker.AttackAnimation(target.transform); Debug.Log($"{attacker}:{attacker.Health.Hp} attacking {target}:{target.Health.Hp}"); await Task.Delay(_delayTime / 2); int attackerDamage = attacker.CalcDamage(target.Element); if (target.Health.Hp - attackerDamage <= 0) { target.Health.Hp = 0; return(attacker); } target.AnimateDamage(attackerDamage, _delayTime / 1000.0f / 2); await Task.Delay(_delayTime / 2); return(null); }
public Battle(Uwudle u1, Uwudle u2, float turnTime = 2) { _u1 = u1; _u2 = u2; _delayTime = (int)(turnTime * 1000); Phase = BattlePhase.Starting; }
public void OnSacrificeMinionClicked(int uwudleNum) { AudioManager.Instance.playSound("Sacrifice"); Debug.Log("Trying to Sacrifice Minion #" + uwudleNum + 1); Debug.Log("numpartymembers" + PlayerStats.Instance.NumPartyMembers); Uwudle uwudleToSacrifice = PlayerStats.Instance.PartyMembers[uwudleNum]; GameScript.Instance.AddCandy(10 * uwudleToSacrifice.level); if (uwudleNum < PlayerStats.Instance.NumPartyMembers - 1) { Uwudle nextUwudle = PlayerStats.Instance.PartyMembers[uwudleNum + 1]; if (uwudleNum == 0) { Debug.Log("Sacrificing first minion"); nextUwudle.Movement.Strategy = new FollowStrategy(nextUwudle.NavAgent, PlayerStats.Instance.transform); } else { Debug.Log("Sacrificing minion " + uwudleNum + 1); nextUwudle.Movement.Strategy = new FollowStrategy(nextUwudle.NavAgent, PlayerStats.Instance.PartyMembers[uwudleNum - 1].transform); } } PlayerStats.Instance.PartyMembers.RemoveAt(uwudleNum); InventoryController.Instance.removeUwudle(uwudleToSacrifice); Destroy(uwudleToSacrifice.gameObject); OnQuitMenuClicked(); }
public void SpawnUwudle() { Uwudle newWudle = _builder.BuildRandom(); newWudle.transform.position = spawnLocation.position; newWudle.transform.rotation = spawnLocation.rotation; newWudle.NavAgent.Warp(spawnLocation.position); if (PlayerStats.Instance.NumPartyMembers > 0) { newWudle.Movement.Strategy = new FollowStrategy(newWudle.NavAgent, PlayerStats.Instance.PartyMembers[PlayerStats.Instance.NumPartyMembers - 1].transform); } else { newWudle.Movement.Strategy = new FollowStrategy(newWudle.NavAgent, PlayerStats.Instance.transform); } PlayerStats.Instance.PartyMembers.Add(newWudle); UI.FaceTransform faceTransform = newWudle.GetComponentInChildren <UI.FaceTransform>(); faceTransform.Target = Camera.main.transform; newWudle.gameObject.name = "uwudle" + PlayerStats.Instance.NumPartyMembers; newWudle.gameObject.SetActive(true); Debug.Log("Spawned an Uwudle, numPartyMembers: " + PlayerStats.Instance.NumPartyMembers); InventoryController.Instance.addUwudle(newWudle); }
void Awake() { foreach (Uwudle uwudle in startUwudles) { addUwudle(uwudle); } activeUwu = (orderedUwudles.Count > 0) ? orderedUwudles[0] : null; }
private void Update() { // send active uwudle if (!inBattle && Input.GetMouseButtonDown(0)) { Uwudle targetUwudle = cursor.getTargetUwudle(); Uwudle activeUwudle = InventoryController.Instance.getActiveUwudle(); if (targetUwudle != null && activeUwudle != null) { startbattle(activeUwudle, targetUwudle); } } }
private void startbattle(Uwudle ourUwudle, Uwudle target) { MovementStrategy ourOldStrat = ourUwudle.Movement.Strategy; MovementStrategy targetOldStrat = target.Movement.Strategy; ourUwudle.Movement.Stop(); target.Movement.Stop(); ourUwudle.Movement.Strategy = MovementStrategy.Idle; target.Movement.Strategy = MovementStrategy.Idle; teleportUwudle(ourUwudle, target); currentBattle = new Battle(ourUwudle, target); inBattle = true; currentBattle.Start((Uwudle winner) => endBattle(winner, ourUwudle, target, ourOldStrat, targetOldStrat)); }
private async Task <Uwudle> BattleTask() { Uwudle winner = null; bool u1Attacker = true; while (!winner) { Uwudle attacker = u1Attacker ? _u1 : _u2; Uwudle target = u1Attacker ? _u2 : _u1; winner = await AttackCycle(attacker, target); u1Attacker = !u1Attacker; } Debug.Log("Battle OVER :0"); return(winner); }
public async void Start(Action <Uwudle> finishCallback) { try { Uwudle winner = await BattleTask(); finishCallback(winner); } catch (BattleException e) { Debug.Log(e); } catch (Exception e) { Debug.LogException(e); finishCallback(null); } }
public void removeUwudle(Uwudle uwudle) { Debug.Log("remove uwudleUI"); UI.UwudleUI ui = activeUwudles[uwudle]; activeUwudles.Remove(uwudle); orderedUwudles.Remove(uwudle); Destroy(ui.gameObject); currentIndex = 0; if (orderedUwudles.Count > 0) { activeUwu = orderedUwudles[currentIndex]; } else { activeUwu = null; } }
public void addUwudle(Uwudle uwudle) { if (uwudle == null) { return; } orderedUwudles.Add(uwudle); UI.UwudleUI ui = Instantiate(uwudleUIPrefab); ui.uwudle = uwudle; ui.transform.SetParent(uwudleUIContainer); activeUwudles.Add(uwudle, ui); if (orderedUwudles.Count == 1) { currentIndex = 0; activeUwu = orderedUwudles[currentIndex]; } }
public void endBattle(Uwudle winner, Uwudle ourUwudle, Uwudle target, MovementStrategy ourOldStrat, MovementStrategy targetOldStrat) { inBattle = false; ourUwudle.Movement.Strategy = ourOldStrat; target.Movement.Strategy = targetOldStrat; ourUwudle.Movement.Move(); target.Movement.Move(); if (ourUwudle.Health.Hp == 0) { ourUwudle.PoofWoodle(); } ourUwudle.Health.Hp = ourUwudle.Health.MaxHp; var wild = target.GetComponent <WildUwudle>(); if (wild && target.Health.Hp == 0) { wild.Kill(); ourUwudle.LevelUp(); } }
private void teleportUwudle(Uwudle ourUwudle, Uwudle target) { Bounds?ourBounds = FollowStrategy.GetMeshBounds(ourUwudle); Bounds?targetBounds = FollowStrategy.GetMeshBounds(target); float boundsOffset = 0; // calculates the distance that the two uwudles should stand // from eachother's center points if (ourBounds.HasValue) { boundsOffset += ourBounds.Value.size.z * ourUwudle.transform.lossyScale.z; } if (targetBounds.HasValue) { boundsOffset += targetBounds.Value.size.z * target.transform.lossyScale.z; } boundsOffset /= 2; boundsOffset += _spacing; // ensure that teleport position is infront of the target uwudle Vector3 tpPos = target.transform.position; tpPos += boundsOffset * target.transform.forward; if (poofPrefab != null) { Instantiate(poofPrefab, ourUwudle.transform.position, Quaternion.identity); Instantiate(poofPrefab, tpPos, Quaternion.identity); } ourUwudle.NavAgent.Warp(tpPos); ourUwudle.NavAgent.updateRotation = false; target.NavAgent.updateRotation = false; ourUwudle.transform.LookAt(target.transform.position); target.transform.LookAt(ourUwudle.transform.position); ourUwudle.NavAgent.updateRotation = true; target.NavAgent.updateRotation = true; }
private void SpawnWildUwudle(int spawnId) { Uwudle uwudle = _builder.BuildRandom(); uwudle.GetComponentInChildren <UI.Healthbar>().GetComponent <Image>().color = Color.blue; uwudle.NavAgent.Warp(_spawnPoints[spawnId].position); uwudle.transform.rotation = _spawnPoints[spawnId].rotation; var wild = uwudle.gameObject.AddComponent <WildUwudle>(); SetLayerInAllChildren(uwudle.transform, LayerMask.NameToLayer("Enemy Uwudle")); uwudle.Movement.Strategy = new RoamStrategy(uwudle.NavAgent) { RoamTime = 1000, RoamRange = 10 }; UI.FaceTransform ft = uwudle.GetComponentInChildren <UI.FaceTransform>(); if (ft) { ft.Target = Camera.main.transform; } }
private void playerScroll() { float scroll = Input.GetAxis("Mouse ScrollWheel"); if (activeUwu == null) { activeUwu = orderedUwudles[currentIndex]; } activeUwudles[activeUwu].enableOutline(false); if (scroll < 0) { // scroll up currentIndex = (currentIndex + 1) % orderedUwudles.Count; activeUwu = orderedUwudles[currentIndex]; } else if (scroll > 0) { // scroll down currentIndex = (currentIndex == 0) ? (orderedUwudles.Count - 1) : (currentIndex - 1); activeUwu = orderedUwudles[currentIndex]; } activeUwudles[activeUwu].enableOutline(true); }