protected (GChess, Vector2Int?) DecideTargetAndDestination() { GChess target = null; Vector2Int?destination = null; Vector2Int[] moveRange = aiChess.navComponent.GetMoveRangeWithoutOccupy(); System.Random r = new System.Random(); moveRange = moveRange.OrderBy(x => r.Next()).ToArray(); GChess[] allTargets = GridManager.instance.GetChesses(aiChess.targetTeam); allTargets = allTargets.OrderBy(x => r.Next()).ToArray(); List <GChess> targets = new List <GChess>(); if (targetModifier?.enable == true) { targets.AddRange(targetModifier.GetPreferTarget()); } targets.AddRange(allTargets); foreach (GChess curTarget in targets) { Vector2Int?result = DecideDestinationByTarget(curTarget, moveRange); if (result != null) { target = curTarget; destination = result; break; } } return(target, destination); }
/// <summary> /// AI根据移动范围以及技能释放范围决定 /// </summary> public void Visit() { target = null; desination = AIChess.location; AIChess.navComponent.GenNavInfo(); Vector2Int[] moveRange = AIChess.navComponent.GetMoveRangeWithoutOccupy(); System.Random r = new System.Random(); moveRange = moveRange.OrderBy(x => r.Next()).ToArray(); var originLocation = AIChess.location; foreach (Vector2Int location in moveRange) { AIChess.location = location;//暂时更改location以供skill.GetRange来判断 GChess[] targets = GridManager.instance.GetChesses(GameManager.instance.playerTeam); foreach (GChess curTarget in targets) { if (AIChess.skill.GetRange().InRange(curTarget.location)) { target = curTarget; desination = location; break; } } } AIChess.location = originLocation; }
GChess[] DelOneChess(GChess chess, GChess[] chesses) { List <GChess> list = new List <GChess>(chesses); list.Remove(chess); return(list.ToArray()); }
public override async UniTask <bool> Decide(GChess target) { this.target = target; if (attackType == SkillAttackType.flatShot) { if (target == null) { direction = Vector2Int.zero; return(false); } direction = target.location - owner.location; direction = direction.Normalized(); } else if (attackType == SkillAttackType.projectile) { if (target == null) { offset = Vector2Int.zero; return(false); } offset = target.location - owner.location; } if (willLockTarget) { LockAt(target); } return(true); }
protected Vector2Int?DecideDestinationByTarget(GChess target, Vector2Int[] moveRange) { var originLocation = aiChess.location; List <Vector2Int> finalMoveRange = new List <Vector2Int>(); if (targetModifier?.enable == true) { Vector2Int[] temp = targetModifier.GetPreferLocation(target); foreach (Vector2Int location in temp) { if (moveRange.Contains(location) || location == aiChess.location) { finalMoveRange.Add(location); } } } finalMoveRange.AddRange(moveRange); finalMoveRange.Add(aiChess.location); foreach (Vector2Int location in finalMoveRange) { aiChess.location = location;//暂时更改location以供skill.GetRange来判断 if (aiChess.postSkill.GetTargetRange().InRange(target.location)) { aiChess.location = originLocation; return(location); } } aiChess.location = originLocation; return(null); }
public override void PreCast() { GChess chess = GridManager.instance.GetChess(owner.location + direction); if (chess != null) { chess.FreezeFoot(); UnityAction a; UnityAction <Element> b; a = () => { chess.DeactiveFreezeFoot(); }; b = (element) => { if (element == Element.Fire) { chess.DeactiveFreezeFoot(); } ; }; owner.eBePush.AddListener(a); owner.eElementReaction.AddListener(b); chess.eFreezeFootBroken.AddListener(() => { owner.eBePush.RemoveListener(a); owner.eElementReaction.RemoveListener(b); }); } }
void OverTile(Vector2Int location) { if (overTileFloorHUD != null) { Destroy(overTileFloorHUD); } if (aliveOutline != null) { aliveOutline.RemoveReference(); aliveOutline = null; } if (location != Vector2Int.down) { overTileFloorHUD = CreateFloorHUD(location, Color.yellow); GetComponent <AudioSource>().PlayOneShot(overTileClip, 0.04f); } GChess t = GridManager.instance.GetChess(location); GFloor f = GridManager.instance.GetFloor(location); var list = new List <IGetInfo>(); if (t != null) { list.AddRange(t.GetInfos()); aliveOutline = t.outline; aliveOutline.AddReference(); } if (f != null) { list.AddRange(f.GetInfos()); } list.AddRange(GridManager.instance.GetEnvironmentInformation(location)); CreateMessage(list); }
IEnumerator PreTurnAIExcute() { foreach (var AI in AIs) { GChess chess = AI.actor as GChess; if (chess.unableAct) { continue; } curAI = AI.gameObject; AI.Visit(); var t = UIManager.instance.CreateFloorHUD(AI.actor.location, Color.yellow); yield return(1f); Destroy(t); AI.PerformMove(); yield return(null);//移动完成后继续执行 AI.PrepareSkill(); yield return(null);//准备完成后继续执行 } IEnumerator spawnCor = enemySpawn.SpawnEnemy(); while (spawnCor.MoveNext()) { yield return(spawnCor.Current); } GameManager.instance.AIPreTurnEnd(); }
/// <summary> /// 敌人搜索 /// </summary> GameObject EnemySearch() { Vector2Int[] search = GridManager.instance.GetOneRayRange(location, direction.ToVector2(), AtkRange); GChess[] chesses = GridManager.instance.GetChessesInRange(search);//攻击范围的棋子 //获得最近的 可攻击棋子 while (true) { GChess chess = SortByDistance(chesses); if (chess == null) { return(null); } //foreach (var chess in chesses) //{ if (chess.chessType == ChessType.shooterTower) { return(chess.gameObject); } else if (chess.chessType == ChessType.ememy) { return(chess.gameObject); } //} //return null; chesses = DelOneChess(chess, chesses); } }
public HealthBar(GChess chess) { owner = chess; healthBarObject = UIManager.instance.CreateHealthBar(chess); Refresh(); //FloorHUD res = new FloorHUD(); }
public void Cast(GChess chess) { Vector2Int direction = chess.location - owner.location; chess.PushToward(direction, distance); chess.ElementReaction(element); }
/// <summary> /// 向一个方向推动这个Chess,如果遇到障碍物则停下 /// </summary> /// <param name="direction">方向,请保证是单位向量</param> /// <param name="distance">推动的距离</param> public void PushToward(Vector2Int direction, int distance) { Vector2Int destination = location; for (int i = 0; i < distance; i++) { Vector2Int curLocation = destination + direction; GChess t = GridManager.instance.GetChess(curLocation); if (t || !GridManager.instance.InRange(curLocation)) { //if(t) //{ // t.PushToward(direction, distance - i); //} //destination.x break; } else { destination = destination + direction; } } eBePush.Invoke(); MoveToDirectly(destination); DeactiveFreezeFoot(); }
public GameObject CreateHealthBar(GChess chess) { GameObject gameObject = GameObject.Instantiate(prefabHealthBar, chess.render.transform); gameObject.GetComponent <GetImage>().Init(chess); return(gameObject); }
async public override UniTask ProcessAsync() { await ElementSystem.ApplyElementAtAsync(owner.location + direction, element, damage); GChess chess = GridManager.instance.GetChess(owner.location + direction);; Debug.Log(chess ? chess.ToString(): "Empty"); }
public override void Exit() { GChess chess = (owner as GChess); chess.ActiveAction(); owner.render.GetComponent <Animator>().speed = 1; base.Exit(); }
async public override UniTask ProcessAsync(GActor[] inputParams) { GChess target = inputParams[0] as GChess; Vector2Int direction = target.location - owner.location; await ElementSystem.ApplyElementAtAsync(target.location, element, damage); await target.PushTowardAsync(direction, 1); }
public override void Perform() { GChess chess = GridManager.instance.GetChess(owner.location + direction); if (chess != null) { chess.ElementReaction(Element.Ice); } }
async public override UniTask ProcessAsync(GActor[] inputParams) { GChess targetChess = inputParams[0] as GChess; Vector2Int targetLocation = inputParams[1].location; await Shoot(targetLocation); targetChess.Teleport(targetLocation); }
public void CancelSkill() { if (floorHUD != null) { floorHUD.Release(); floorHUD = null; } target = null; }
public override void InitByOwner(GChess owner) { base.InitByOwner(owner); owner.eLocationChange.AddListener(DisConnect); caster.eLocationChange.AddListener(DisConnect); owner.eDie.AddListener(DisConnect); caster.eDie.AddListener(DisConnect); Connect(); }
public override async UniTask <bool> Decide(GChess target) { if (!target) { return(false); } this.target = target; return(true); }
public override async UniTask <bool> Decide(GChess target) { if (target == null) { return(false); } direction = target.location - owner.location; return(true); }
public override void Perform() { GChess chess = GridManager.instance.GetChess(owner.location + direction); if (chess != null) { chess.PushToward(direction, 1); } }
public override List <GChess> GetPreferTarget() { GChess[] result = new GChess[speceficTargetID.Count]; for (int i = 0; i < result.Length; i++) { result[i] = AIManager.instance.GetSpeceficTarget(speceficTargetID[i]); } return(new List <GChess>(result)); }
public override Vector2Int[] GetPreferLocation(GChess target) { Vector2Int[] result = new Vector2Int[speceficLocationOffset.Count]; for (int i = 0; i < result.Length; i++) { result[i] = target.location + speceficLocationOffset[i]; } return(result); }
//public Material snowMaterial; public override void Enter() { base.Enter(); owner.render.material.SetColor("_Color", Color.white); owner.render.material.SetFloat("_Blend", 1f); owner.render.GetComponent <Animator>().speed = 0; GChess chess = (owner as GChess); chess.DisableAction(); }
public GChess InstansiateChessAt(GameObject prefab, Vector2Int location) { var res = Instantiate(prefab, chessContainer); res.transform.position = GridManager.instance.GetChessPosition3D(location); GChess chess = res.GetComponent <GChess>(); chess.location = location; return(chess); }
public override void Perform() { Vector2Int[] range = GetAffectRange(); Vector2Int targetPosition = range[range.Length - 1]; GChess chess = GridManager.instance.GetChess(targetPosition); if (chess != null) { chess.ElementReaction(element); } }
public override async UniTask <bool> Decide(GChess target) { if (target == null) { direction = Vector2Int.zero; return(false); } direction = target.location - owner.location; direction = direction.Normalized(); return(true); }
public void AddModifier(Modifier modifier, GChess caster = null) { if (caster == null) { caster = this; } modifier = Instantiate(modifier); modifier.InitByCaster(caster); modifier.InitByOwner(this); modifiers.Add(modifier); }