public void BulletTarget() { GetComponent <BoxCollider>().enabled = true; int startingYTile = Facing == FacingType.Left ? StartingTile.y - BulletGapStartingTile.y : StartingTile.y + BulletGapStartingTile.y; GameObject go = TargetIndicatorManagerScript.Instance.GetTargetIndicator(AttackType.Particles); go.transform.position = GridManagerScript.Instance.GetBattleBestTileInsideTheBattlefield(DestinationTile, Facing).transform.position; go.GetComponent <BattleTileTargetScript>().StartTarget( (Vector3.Distance(transform.position, GridManagerScript.Instance.GetBattleBestTileInsideTheBattlefield(DestinationTile, Facing).transform.position) * CharInfo.SpeedStats.BulletSpeed) / Vector3.Distance(transform.position, GridManagerScript.Instance.GetBattleBestTileInsideTheBattlefield(DestinationTile, Facing).transform.position)); bts = GridManagerScript.Instance.GetBattleBestTileInsideTheBattlefield(DestinationTile, Facing); float duration = CharInfo.SpeedStats.BulletSpeed; foreach (Vector2Int item in BulletEffectTiles) { if (GridManagerScript.Instance.isPosOnField(DestinationTile + item)) { BattleTileScript btsT = GridManagerScript.Instance.GetBattleTile(DestinationTile + item, Facing == FacingType.Left ? WalkingSideType.LeftSide : WalkingSideType.RightSide); if (btsT != null) { go = TargetIndicatorManagerScript.Instance.GetTargetIndicator(AttackType.Particles); go.transform.position = btsT.transform.position; go.GetComponent <BattleTileTargetScript>().StartTarget(duration); } } } }
public IEnumerator SetCharInPos(BaseCharacter currentCharacter, BattleTileScript bts, bool withArrivingAnim) { GridManagerScript.Instance.SetBattleTileState(bts.Pos, BattleTileStateType.Occupied); currentCharacter.UMS.CurrentTilePos = bts.Pos; currentCharacter.CurrentBattleTiles = new List <BattleTileScript>(); for (int i = 0; i < currentCharacter.UMS.Pos.Count; i++) { currentCharacter.UMS.Pos[i] += bts.Pos; GridManagerScript.Instance.SetBattleTileState(currentCharacter.UMS.Pos[i], BattleTileStateType.Occupied); BattleTileScript cbts = GridManagerScript.Instance.GetBattleTile(currentCharacter.UMS.Pos[i]); currentCharacter.CurrentBattleTiles.Add(cbts); } foreach (Vector2Int item in currentCharacter.UMS.Pos) { GridManagerScript.Instance.SetBattleTileState(item, BattleTileStateType.Occupied); } if (withArrivingAnim) { currentCharacter.SetUpEnteringOnBattle(); } else { currentCharacter.CharArrivedOnBattleField(); } if (currentCharacter.SpineAnim.CurrentAnim != CharacterAnimationStateType.Arriving.ToString()) { } yield return(BattleManagerScript.Instance.MoveCharToBoardWithDelay(withArrivingAnim ? 0.2f : 0, currentCharacter, bts.transform.position)); }
// Start is called before the first frame update public void CreateChar() { Destroy(charOnScene); BattleTileScript bts = GridManagerScript.Instance.GetBattleTile(new Vector2Int(3, 9)); charOnScene = Instantiate(CharacterBasePrefab, bts.transform.position, Quaternion.identity); GameObject child = Instantiate(Characters.Where(r => r.CharName.ToString() == CharToUse.options[CharToUse.value].text).First().Char, charOnScene.transform.position, Quaternion.identity, charOnScene.transform); BaseCharacter currentCharacter = (BaseCharacter)charOnScene.AddComponent(System.Type.GetType(child.GetComponentInChildren <CharacterInfoScript>().BaseCharacterType.ToString())); currentCharacter.UMS = currentCharacter.GetComponent <UnitManagementScript>(); currentCharacter.UMS.CurrentAttackType = (AttackType)Enum.Parse(typeof(AttackType), Attack.options[Attack.value].text); currentCharacter.UMS.CharOwner = currentCharacter; currentCharacter.VFXTestMode = true; currentCharacter.UMS.CurrentTilePos = bts.Pos; currentCharacter.CurrentBattleTiles = new List <BattleTileScript>(); for (int i = 0; i < currentCharacter.UMS.Pos.Count; i++) { currentCharacter.UMS.Pos[i] += bts.Pos; BattleTileScript cbts = GridManagerScript.Instance.GetBattleTile(currentCharacter.UMS.Pos[i]); currentCharacter.CurrentBattleTiles.Add(cbts); } currentCharacter.CharInfo.SpeedStats.AttackSpeedRatio = AttackSpeed.value; currentCharacter.UMS.Side = SideType.RightSide; currentCharacter.CharInfo.ClassType = (CharacterClassType)Enum.Parse(typeof(CharacterClassType), CharacterClass.options[CharacterClass.value].text); currentCharacter.CharInfo.SpeedStats.BulletSpeed = SpeedOfBullets.value; currentCharacter.CharInfo.CurrentAttackTypeInfo = AttacksTypeInfo.Where(r => r.ParticlesAtk.CharacterClass == currentCharacter.CharInfo.ClassType).ToList(); currentCharacter.CharInfo.DamageStats.ChildrenBulletDelay = MountainDelay.value; }
public void SetCharInPos(BaseCharacter currentCharacter, Vector2Int pos) { BattleTileScript bts = GridManagerScript.Instance.GetBattleTile(pos); currentCharacter.UMS.CurrentTilePos = bts.Pos; currentCharacter.CurrentBattleTiles = new List <BattleTileScript>(); for (int i = 0; i < currentCharacter.UMS.Pos.Count; i++) { currentCharacter.UMS.Pos[i] += bts.Pos; BattleTileScript cbts = GridManagerScript.Instance.GetBattleTile(currentCharacter.UMS.Pos[i]); currentCharacter.CurrentBattleTiles.Add(cbts); } foreach (Vector2Int item in currentCharacter.UMS.Pos) { GridManagerScript.Instance.SetBattleTileState(item, BattleTileStateType.Occupied); } currentCharacter.SetUpEnteringOnBattle(); StartCoroutine(BattleManagerScript.Instance.MoveCharToBoardWithDelay(0.2f, currentCharacter, bts.transform.position)); }
// Start is called before the first frame update public void CreateChar() { Destroy(charOnScene); BattleTileScript bts = GridManagerScript.Instance.GetBattleTile(new Vector2Int(2, 3)); charOnScene = Instantiate(CharacterBasePrefab, bts.transform.position, Quaternion.identity); GameObject child = Instantiate(Characters.Where(r => r.CharName.ToString() == CharToUse.options[CharToUse.value].text).First().Char, charOnScene.transform.position, Quaternion.identity, charOnScene.transform); currentCharacter = (BaseCharacter)charOnScene.AddComponent(Type.GetType(child.GetComponentInChildren <CharacterInfoScript>().BaseCharacterType.ToString())); currentCharacter.UMS = currentCharacter.GetComponent <UnitManagementScript>(); currentCharacter.UMS.CurrentAttackType = (AttackType)Enum.Parse(typeof(AttackType), CharacterAttackType.options[CharacterAttackType.value].text); currentCharacter.UMS.CharOwner = currentCharacter; currentCharacter.UMS.Facing = FacingType.Right; currentCharacter.UMS.WalkingSide = WalkingSideType.LeftSide; currentCharacter.UMS.Side = SideType.LeftSide; currentCharacter.UMS.CurrentTilePos = bts.Pos; currentCharacter.CharInfo.ClassType = (CharacterClassType)Enum.Parse(typeof(CharacterClassType), CharacterClass.options[CharacterClass.value].text); currentCharacter.VFXTestMode = true; currentCharacter.UMS.Pos.Add(bts.Pos); currentCharacter.SetupCharacterSide(); currentCharacter.SpineAnimatorsetup(); }
//Get free tile for a more than one tile character public BattleTileScript GetFreeBattleTile(WalkingSideType walkingSide, List <Vector2Int> occupiedTiles) { List <BattleTileScript> emptyBattleTiles = new List <BattleTileScript>(); emptyBattleTiles = BattleTiles.Where(r => r.BattleTileState == BattleTileStateType.Empty && (r.WalkingSide == walkingSide || walkingSide == WalkingSideType.Both)).ToList(); bool areOccupiedTileFree = true; BattleTileScript emptyTile = null; while (emptyBattleTiles.Count > 0) { emptyTile = emptyBattleTiles[Random.Range(0, emptyBattleTiles.Count)]; emptyBattleTiles.Remove(emptyTile); areOccupiedTileFree = true; foreach (Vector2Int item in occupiedTiles) { BattleTileScript tileToCheck = BattleTiles.Where(r => r.Pos == emptyTile.Pos + item).FirstOrDefault(); if (tileToCheck == null) { areOccupiedTileFree = false; break; } else { if (tileToCheck.BattleTileState != BattleTileStateType.Empty) { areOccupiedTileFree = false; break; } } } if (areOccupiedTileFree) { return(emptyTile); } } return(null); }
public BattleTileScript[] GetTilesAdjacentTo(Vector2Int originPos, int withinRadius = 1, bool circularRadius = false, WalkingSideType side = WalkingSideType.Both) { BattleTileScript originTile = BattleTiles.Where(r => r.Pos == originPos).FirstOrDefault(); if (originTile == null) { return(null); } Vector2Int curTilePos = new Vector2Int(); BattleTileScript curTile = null; List <BattleTileScript> adjTiles = new List <BattleTileScript>(); //WalkingSideType side = BattleTiles.Where(r => r.Pos == originPos).First().WalkingSide; for (int x = -withinRadius; x <= withinRadius; x++) { for (int y = -withinRadius; y <= withinRadius; y++) { curTilePos = new Vector2Int(x, y) + originPos; curTile = side != WalkingSideType.Both ? GetBattleTile(curTilePos, side) : BattleTiles.Where(r => r.Pos == originPos).FirstOrDefault(); if (curTile != null && curTilePos != originPos && (circularRadius ? Vector2Int.Distance(curTilePos, originPos) - 0.5f < withinRadius : true)) { adjTiles.Add(curTile); } } } if (adjTiles.Count == 0) { return(null); } else { return(adjTiles.ToArray()); } }
public BattleTileScript GetBattleBestTileInsideTheBattlefield(Vector2Int pos, FacingType facing) { BattleTileScript res = null; int startValue = pos.y; if (facing == FacingType.Left) { for (int i = startValue; i < YGridSeparator; i++) { pos.y = i; res = BattleTiles.Where(r => r.Pos == new Vector2Int(pos.x, i)).FirstOrDefault(); if (res.BattleTileState != BattleTileStateType.Blocked) { return(res); } } } else { for (int i = startValue; i >= YGridSeparator; i--) { pos.y = i; res = BattleTiles.Where(r => r.Pos == pos).FirstOrDefault(); if (res == null) { } if (res.BattleTileState != BattleTileStateType.Blocked) { return(res); } } } return(res); }
IEnumerator GridLeapSequence(float duration, Vector3 translation, bool moveChars = true) { //Ensure new grid is set and moved to correct position before everything jumpingchars.Clear(); float jumpHeight = 2f; CharacterAnimationStateType jumpAnim = CharacterAnimationStateType.DashUp; Vector3 cameraStartPos = MainCamera.transform.position; CameraInfoClass cic = CameraStage.CameraInfo.Where(r => r.StageIndex == currentGridIndex && !r.used).First(); Vector3 cameraOffsetChange = cic.CameraPosition - CameraManagerScript.Instance.CurrentCameraOffset; float cameraStartOrtho = MainCamera.orthographicSize; float cameraEndOrtho = cic.OrthographicSize; cic.used = true; //DONT FORGET TO ADD CAMERA OFFSET ADJUSTMENT if (moveChars) { chars = System.Array.ConvertAll(BattleManagerScript.Instance.AllCharactersOnField.Where(r => r.IsOnField).ToArray(), item => (CharacterType_Script)item); } else { chars = new CharacterType_Script[0]; } Vector3[] charStartPositions = new Vector3[chars != null ? chars.Length : 0]; Vector3[] charGridPosOffsets = new Vector3[chars != null ? chars.Length : 0]; for (int i = 0; i < (chars != null ? chars.Length : 0); i++) { charStartPositions[i] = chars[i].transform.position; BattleTileScript bts = GridManagerScript.Instance.BattleTiles.Where(r => r.Pos == chars[i].UMS.CurrentTilePos).FirstOrDefault(); if (bts.BattleTileState != BattleTileStateType.Empty || chars[i].UMS.WalkingSide != bts.WalkingSide) { BattleTileScript newGridTile = GridManagerScript.Instance.GetRandomFreeAdjacentTile(chars[i].UMS.CurrentTilePos, 5, false, chars[i].UMS.WalkingSide); Debug.Log(newGridTile.Pos); charGridPosOffsets[i] = GridManagerScript.GetTranslationBetweenTiles(GridManagerScript.Instance.BattleTiles.Where(r => r.Pos == chars[i].UMS.CurrentTilePos).First(), newGridTile); GridManagerScript.Instance.SetBattleTileState(newGridTile.Pos, BattleTileStateType.Occupied); chars[i].CurrentBattleTiles = new List <BattleTileScript>() { newGridTile }; chars[i].UMS.CurrentTilePos = newGridTile.Pos; chars[i].UMS.Pos = new List <Vector2Int>() { newGridTile.Pos }; } else { GridManagerScript.Instance.SetBattleTileState(bts.Pos, BattleTileStateType.Occupied); charGridPosOffsets[i] = Vector3.zero; } chars[i].SetAttackReady(false); if (translation == Vector3.zero && charGridPosOffsets[i] == Vector3.zero) { continue; } jumpingchars.Add(chars[i]); chars[i].SetAnimation(jumpAnim); } float timeRemaining = duration; float progress = 0; float xPos = 0f; float yPos = 0f; bool hasStarted = false; while (timeRemaining != 0 || !hasStarted) { hasStarted = true; timeRemaining = Mathf.Clamp(timeRemaining - Time.deltaTime, 0f, 9999f); progress = 1f - (timeRemaining / (duration != 0f ? duration : 1f)); MainCamera.transform.position = Vector3.Lerp(cameraStartPos, cameraStartPos + translation + cameraOffsetChange, UniversalGameBalancer.Instance.cameraTravelCurve.Evaluate(progress)); MainCamera.orthographicSize = Mathf.Lerp(cameraStartOrtho, cameraEndOrtho, progress); for (int i = 0; i < (jumpingchars != null ? jumpingchars.Count : 0); i++) { xPos = Mathf.Lerp(charStartPositions[i].x, charStartPositions[i].x + translation.x + charGridPosOffsets[i].x, UniversalGameBalancer.Instance.cameraTravelCurve.Evaluate(progress)); yPos = Mathf.Lerp(charStartPositions[i].y, charStartPositions[i].y + translation.y + charGridPosOffsets[i].y, UniversalGameBalancer.Instance.cameraTravelCurve.Evaluate(progress)); yPos += jumpHeight * UniversalGameBalancer.Instance.characterJumpCurve.Evaluate(progress); jumpingchars[i].transform.position = new Vector3(xPos, yPos, jumpingchars[i].transform.position.z); jumpingchars[i].SpineAnim.SetAnimationSpeed(UniversalGameBalancer.Instance.jumpAnimationCurve.Evaluate(progress)); } yield return(null); } CameraManagerScript.Instance.CurrentCameraOffset = cic.CameraPosition; if (chars.Length != 0) { foreach (CharacterType_Script character in BattleManagerScript.Instance.PlayerControlledCharacters) { character.SetAttackReady(true); } } }
IEnumerator MoveCharactersToFitNewGridSequence(float duration) { float jumpHeight = 2f; CharacterAnimationStateType jumpAnim = CharacterAnimationStateType.DashUp; CharacterType_Script[] chars = BattleManagerScript.Instance.PlayerControlledCharacters; List <CharacterType_Script> charsToMove = new List <CharacterType_Script>(); List <Vector3> charStartPositions = new List <Vector3>(); List <Vector3> charGridPosOffsets = new List <Vector3>(); for (int i = 0; i < (chars != null ? chars.Length : 0); i++) { if (GridManagerScript.Instance.BattleTiles.Where(r => r.Pos == chars[i].UMS.CurrentTilePos).FirstOrDefault().BattleTileState == BattleTileStateType.Blocked || GridManagerScript.Instance.BattleTiles.Where(r => r.Pos == chars[i].UMS.CurrentTilePos).FirstOrDefault().WalkingSide != chars[i].UMS.WalkingSide) { BattleTileScript newGridTile = GridManagerScript.Instance.GetRandomFreeAdjacentTile(chars[i].UMS.CurrentTilePos, 5, false, chars[i].UMS.WalkingSide); GridManagerScript.Instance.SetBattleTileState(newGridTile.Pos, BattleTileStateType.Occupied); charsToMove.Add(chars[i]); charStartPositions.Add(chars[i].transform.position); charGridPosOffsets.Add(GridManagerScript.GetTranslationBetweenTiles(GridManagerScript.Instance.BattleTiles.Where(r => r.Pos == chars[i].UMS.CurrentTilePos).First(), newGridTile)); chars[i].CurrentBattleTiles = new List <BattleTileScript>() { newGridTile }; chars[i].UMS.CurrentTilePos = newGridTile.Pos; chars[i].UMS.Pos = new List <Vector2Int>() { newGridTile.Pos }; chars[i].SetAnimation(jumpAnim); } chars[i].SetAttackReady(false); } float timeRemaining = duration; float progress = 0; float xPos = 0f; float yPos = 0f; bool hasStarted = false; while (timeRemaining != 0 || !hasStarted) { hasStarted = true; timeRemaining = Mathf.Clamp(timeRemaining - Time.deltaTime, 0f, 9999f); progress = 1f - (timeRemaining / (duration != 0f ? duration : 1f)); for (int i = 0; i < (charsToMove != null ? charsToMove.Count : 0); i++) { xPos = Mathf.Lerp(charStartPositions[i].x, charStartPositions[i].x + charGridPosOffsets[i].x, UniversalGameBalancer.Instance.cameraTravelCurve.Evaluate(progress)); yPos = Mathf.Lerp(charStartPositions[i].y, charStartPositions[i].y + charGridPosOffsets[i].y, UniversalGameBalancer.Instance.cameraTravelCurve.Evaluate(progress)); yPos += jumpHeight * UniversalGameBalancer.Instance.characterJumpCurve.Evaluate(progress); charsToMove[i].transform.position = new Vector3(xPos, yPos, charsToMove[i].transform.position.z); charsToMove[i].SpineAnim.SetAnimationSpeed(UniversalGameBalancer.Instance.jumpAnimationCurve.Evaluate(progress)); } yield return(null); } if (chars != null) { foreach (CharacterType_Script character in chars) { character.SetAttackReady(true); } } }
public override IEnumerator AI() { while (BattleManagerScript.Instance.PlayerControlledCharacters.Length == 0) { yield return(null); } int times = 0; int MoveTime = 0; bool val = true; InputDirection dir = InputDirection.Down; bool goBack = false; while (val) { yield return(null); if (IsOnField) { while (BattleManagerScript.Instance.CurrentBattleState != BattleState.Battle) { yield return(null); } if (MoveTime == 0) { MoveTime = Random.Range(1, 2); } else { times++; if (times == MoveTime) { yield return(new WaitForSecondsRealtime(1)); if (goBack) { if (CharInfo.Health > 0) { yield return(MoveCharOnDir_Co(dir == InputDirection.Down ? InputDirection.Up : dir == InputDirection.Up ? InputDirection.Down : dir == InputDirection.Left ? InputDirection.Right : InputDirection.Left)); goBack = false; } } else { for (int i = 0; i < 10; i++) { dir = (InputDirection)Random.Range(0, 4); BattleTileScript bts = GridManagerScript.Instance.GetBattleTile(UMS.CurrentTilePos + (dir == InputDirection.Down ? new Vector2Int(1, 0) : dir == InputDirection.Up ? new Vector2Int(-1, 0) : dir == InputDirection.Left ? new Vector2Int(0, -1) : new Vector2Int(0, 1))); if (bts.BattleTileState == BattleTileStateType.Empty && bts.WalkingSide == UMS.WalkingSide) { break; } } goBack = true; if (CharInfo.Health > 0) { yield return(MoveCharOnDir_Co(dir)); } } times = 0; MoveTime = 0; } } yield return(AttackSequence()); yield return(null); } } }
public virtual IEnumerator Move() { while (true) { if (MoveCoOn && currentAttackPhase == AttackPhasesType.End && !Attacking) { float timer = 0; float MoveTime = Random.Range(CharInfo.MovementTimer.x, CharInfo.MovementTimer.y) / 3; while (timer < MoveTime && !AIMove) { yield return(null); while (BattleManagerScript.Instance.CurrentBattleState != BattleState.Battle || Attacking) { yield return(null); } // Debug.Log(timer + " " + MoveTime); timer += Time.deltaTime; } AIMove = false; if (CharInfo.Health > 0) { while (currentAttackPhase != AttackPhasesType.End) { yield return(null); } InputDirection dir = InputDirection.Up; foreach (var item in BattleManagerScript.Instance.AllCharactersOnField.Where(a => a.IsOnField).OrderBy(r => Mathf.Abs(r.UMS.CurrentTilePos.x - UMS.CurrentTilePos.x))) { dir = item.UMS.CurrentTilePos.x > UMS.CurrentTilePos.x ? InputDirection.Down : InputDirection.Up; BattleTileScript bts = GridManagerScript.Instance.GetBattleTile(UMS.CurrentTilePos + GridManagerScript.Instance.GetVectorFromDirection(dir)); if (bts != null && bts.BattleTileState == BattleTileStateType.Empty) { break; } else { for (int i = 0; i < 2; i++) { bts = GridManagerScript.Instance.GetBattleTile(UMS.CurrentTilePos + GridManagerScript.Instance.GetVectorFromDirection((InputDirection)1 + i)); if (bts != null && bts.BattleTileState == BattleTileStateType.Empty) { break; } } if (bts != null && bts.BattleTileState == BattleTileStateType.Empty) { break; } } } MoveCharOnDirection(dir); } else { timer = 0; } } yield return(null); } }
public PortalInfoClass(BattleTileScript portalPos, PortalType portal, int idPortal) { PortalPos = portalPos; Portal = portal; IDPortal = idPortal; }
public static Vector3 GetTranslationBetweenTiles(BattleTileScript startTile, BattleTileScript endTile) { return(endTile.transform.position - startTile.transform.position); }