public List <FDCreature> GetCreatureInRange(FDRange range, CreatureFaction faction) { List <FDCreature> candidates = null; switch (faction) { case CreatureFaction.Friend: candidates = this.Friends; break; case CreatureFaction.Npc: candidates = this.Npcs; break; case CreatureFaction.Enemy: candidates = this.Enemies; break; } List <FDCreature> result = new List <FDCreature>(); foreach (FDCreature candidate in candidates) { if (range.Contains(candidate.Position)) { result.Add(candidate); } } return(result); }
/// <summary> /// /// </summary> /// <returns></returns> public FDRange CalculateRange() { FDRange range = new FDRange(central); //// range.AddPosition(central); for (int k = this.innerLength; k <= this.outterLength; k++) { for (int t = 0; t <= k; t++) { int posX = central.X + t; int posY = central.Y + (k - t); AddValidPosition(range, FDPosition.At(posX, posY)); posX = central.X - t; posY = central.Y + (k - t); AddValidPosition(range, FDPosition.At(posX, posY)); posX = central.X + t; posY = central.Y - (k - t); AddValidPosition(range, FDPosition.At(posX, posY)); posX = central.X - t; posY = central.Y - (k - t); AddValidPosition(range, FDPosition.At(posX, posY)); } } return(range); }
public FDCreature GetPreferredAttackTargetInRange(int creatureId) { FDCreature creature = this.GetCreature(creatureId); AttackItemDefinition attackItem = creature.Data.GetAttackItem(); if (attackItem == null) { return(null); } FDSpan span = attackItem.AttackScope; DirectRangeFinder finder = new DirectRangeFinder(this.gameField, creature.Position, span.Max, span.Min); FDRange range = finder.CalculateRange(); // Get a preferred target in range foreach (FDPosition position in range.Positions) { FDCreature target = this.GetCreatureAt(position); if (target != null && target.Faction == CreatureFaction.Enemy) { return(target); } } return(null); }
public override StateOperationResult OnSelectPosition(FDPosition position) { if (this.magicRange == null) { // should not happen return(StateOperationResult.Clear()); } if (this.magicRange.Contains(position)) { DirectRangeFinder rangeFinder = new DirectRangeFinder(gameAction.GetField(), position, this.Magic.EffectScope); FDRange magicScope = rangeFinder.CalculateRange(); List <FDCreature> targets = gameAction.GetCreatureInRange(magicScope, CreatureFaction.Enemy); if (targets == null || targets.Count == 0) { // Cannot spell on that position, do nothing return(StateOperationResult.None()); } else { gameAction.DoCreatureSpellMagic(this.Creature.CreatureId, this.Magic.MagicId, position); return(StateOperationResult.Clear()); } } else { // Cancel the magic return(StateOperationResult.Pop()); } }
public override void TakeAction() { if (this.NeedAndCanRecover()) { this.GameAction.DoCreatureRest(this.Creature.CreatureId); return; } // Get target FDCreature target = this.LookForAggressiveTarget(); // According to the target, find the nearest position within the Move scope, and get the path to that position FDMovePath movePath = this.DecidePositionAndPath(target.Position); // Do the walk this.GameAction.CreatureWalk(new SingleWalkAction(this.Creature.CreatureId, movePath)); FDPosition destination = movePath.Desitination ?? this.Creature.Position; AttackItemDefinition item = this.Creature.Data.GetAttackItem(); if (item != null) { FDSpan span = item.AttackScope; DirectRangeFinder finder = new DirectRangeFinder(this.GameAction.GetField(), destination, span.Max, span.Min); FDRange range = finder.CalculateRange(); if (range.Contains(target.Position)) { // If in attack range, attack the target this.GameAction.DoCreatureAttack(this.Creature.CreatureId, target.Position); } } this.GameAction.DoCreatureRest(this.Creature.CreatureId); }
public void AddValidPosition(FDRange range, FDPosition pos) { if (pos.X <= 0 || pos.X > gameField.Width || pos.Y <= 0 || pos.Y > gameField.Height) { return; } range.AddPosition(pos); }
public override void OnEnter() { base.OnEnter(); if (range == null) { DirectRangeFinder finder = new DirectRangeFinder(gameAction.GetField(), this.Creature.Position, 1, 1); range = finder.CalculateRange(); } ShowRangePack rangePack = new ShowRangePack(range); SendPack(rangePack); }
public override void OnEnter() { base.OnEnter(); if (this.ItemRange == null) { DirectRangeFinder rangeFinder = new DirectRangeFinder(this.gameAction.GetField(), this.Creature.Position, 1); this.ItemRange = rangeFinder.CalculateRange(); } // Display the attack range on the UI. ShowRangePack pack = new ShowRangePack(this.ItemRange); SendPack(pack); }
public void PlaceIndicators(FDRange range) { ClearCancellableObjects(); foreach (FDPosition pos in range.Positions) { // Put indicator on the position GameObject obj = new GameObject(); obj.transform.parent = fieldObjectsRoot; UIIndicator indicator = obj.AddComponent <UIIndicator>(); indicator.Initialize(this, pos); cancellableObjects.Add(obj); } }
public override void OnEnter() { base.OnEnter(); if (this.AttackRange == null) { AttackItemDefinition attackItem = this.Creature.Data.GetAttackItem(); if (attackItem == null) { return; } FDSpan span = attackItem.AttackScope; DirectRangeFinder finder = new DirectRangeFinder(gameAction.GetField(), this.Creature.Position, span.Max, span.Min); this.AttackRange = finder.CalculateRange(); } // Display the attack range on the UI. ShowRangePack pack = new ShowRangePack(this.AttackRange); SendPack(pack); }
public ShowRangePack(FDRange range) { this.Type = PackType.ShowRange; this.Range = range; }
public SelectAttackTargetState(IGameAction action, FDCreature creature) : base(action) { this.Creature = creature; this.AttackRange = null; }