private void CalculateCastableSkills() { castableSkills.Clear(); HashSet <Location> destinations = new HashSet <Location>(); for (int creatureID = 0; creatureID < Creatures.Count; creatureID++) { CreatureController bot = Creatures[creatureID]; int moveSteps = (bot.ActionPoints - bot.NextSkill.actionPointsCost) / bot.MoveCost; if (moveSteps < 0) { continue; } // Ally skill cast to next bot to simplify the AI complexity. Increase the skill design and config set complexity. Location targetLoc = bot.NextSkillTarget.Loc; bool shouldMove = true; foreach (var cp in bot.NextSkill.CastPattern) { foreach (var el in bot.NextSkill.GetSubEffectZone(bot.Loc, cp)) { if (el == bot.NextSkillTarget.Loc) { shouldMove = false; castableSkills.Add(new CastableSkill(creatureID, new CastSkillAction(bot.Loc, bot.Loc + cp))); break; } } } if (shouldMove) { bool finished = false; foreach (var cp in bot.NextSkill.CastPattern) { foreach (var ep in bot.NextSkill.EffectPattern) { Location destination = bot.NextSkillTarget.Loc - ep.loc - cp; if (destination.IsUnblocked() && !destinations.Contains(destination)) { Location tmp = bot.Loc.GetLocationWithGivenStep(destination, moveSteps); if (tmp == destination) { castableSkills.Add(new CastableSkill(creatureID, new CastSkillAction(destination, destination + cp))); destinations.Add(destination); // Set map temporary GridManager.Instance.Nav.SetTileWeight(bot.Loc, 1); GridManager.Instance.Nav.SetTileWeight(destination, 0); finished = true; break; } } } if (finished) { break; } } } } // Resume map status foreach (var bot in Creatures) { GridManager.Instance.Nav.SetTileWeight(bot.Loc, 0); } foreach (var loc in destinations) { GridManager.Instance.Nav.SetTileWeight(loc, 1); } }
public void OnBotDeath(CreatureController cc) { Creatures.Remove(cc); }
private IEnumerator DecisionMaking() { yield return(StartCoroutine(CastGivenLabelSkill(Label.Combo1st))); yield return(StartCoroutine(CastGivenLabelSkill(Label.Combo2rd))); yield return(StartCoroutine(CastGivenLabelSkill(Label.Combo3th))); // Cast left skills foreach (var skill in castableSkills) { CreatureController bot = Creatures[skill.creatureID]; if (player.IsDeath) { break; } AnimationManager.Instance.AddAnimClip(new OutlineEntityAnimClip(bot.Hash, Color.red)); AnimationManager.Instance.AddAnimClip(new BaseAnimClip(AnimType.Delay, 0.5f)); bot.MoveToTile(skill.action.destination, bot.MoveCost); bot.CastSkill(bot.NextCastSkillID, skill.action.castLocation); if (player.IsDeath) { break; } AnimationManager.Instance.AddAnimClip(new OutlineEntityAnimClip(bot.Hash, Color.black)); yield return(null); } // Consume spare action points foreach (var bot in Creatures) { int sparePoints = bot.ActionPoints + bot.ActionPointsPerTurn - bot.MaxActionPoints; if (sparePoints > 0) { bool shouldMove = true; foreach (var el in bot.NextSkill.GetEffectZone(bot.Loc)) { if (el == bot.NextSkillTarget.Loc) { shouldMove = false; break; } } if (shouldMove) { bool finished = false; foreach (var cp in bot.NextSkill.CastPattern) { foreach (var ep in bot.NextSkill.EffectPattern) { Location destination = bot.NextSkillTarget.Loc - cp - ep.loc; if (destination.IsUnblocked()) { destination = bot.Loc.GetLocationWithGivenStep(destination, sparePoints); //Debug.Log("creature id: " + Creatures.IndexOf(bot) + "destination loc: " + destination.ToString() + ", spare points: " + sparePoints); AnimationManager.Instance.AddAnimClip(new OutlineEntityAnimClip(bot.Hash, Color.red)); bot.MoveToTile(destination, bot.MoveCost); AnimationManager.Instance.AddAnimClip(new OutlineEntityAnimClip(bot.Hash, Color.black)); finished = true; break; } } if (finished) { break; } } } } } }