public override StateOperationResult OnSelectPosition(FDPosition position) { if (range == null || !range.Contains(position)) { return(StateOperationResult.Pop()); } // No creature or not a friend/NPC FDCreature targetCreature = this.gameAction.GetCreatureAt(position); if (targetCreature == null || targetCreature.Faction == Definitions.CreatureFaction.Enemy) { return(StateOperationResult.None()); } if (!targetCreature.Data.IsItemsFull()) { gameAction.DoCreatureExchangeItem(this.CreatureId, this.SelectedItemIndex, targetCreature.CreatureId); return(StateOperationResult.Clear()); } else { subState = SubState.SelectExchangeItem; this.TargetCreature = targetCreature; CreatureShowInfoPack pack = new CreatureShowInfoPack(targetCreature, CreatureInfoType.SelectAllItem); SendPack(pack); return(StateOperationResult.None()); } }
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); }
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); }