Example #1
0
        public override double AIScore(TurnContext context, ActionSelectionAI weights)
        {
            Element self = context.Element;
            var     mDS  = self?.GetData <MapData>();
            var     mA   = self.GetData <MapAwareness>();

            // TEMP:
            Element target = ((RLState)context.State).Controlled;
            var     mDT    = target?.GetData <MapData>();

            if (mDT != null && !target.IsDeleted && mA.AwarenessOfCell(mDT.MapCell.Index) > 0)
            {
                // Distance calculation:
                double manDist = mDS.Position.DistanceTo(mDT.Position);
                // Works for sword slash, but need more detail for other things:
                if (manDist < 2) //TEMP
                {
                    return(1.5); // 0.5 + context.RNG.NextDouble() * 1;
                }
            }
            return(-0.5);
        }
Example #2
0
        protected override void GenerateActions(TurnContext context, AvailableActions addTo)
        {
            // Movement:
            Element self = context.Element;
            MapData mD   = self?.GetData <MapData>();

            if (mD != null && mD.MapCell != null)
            {
                IList <MapCell> adjacent = context.Stage?.Map?.AdjacentCells(mD.MapCell.Index);
                foreach (var cell in adjacent)
                {
                    foreach (var element in cell.Contents)
                    {
                        var exit = element.GetData <StageExit>();
                        if (exit != null)
                        {
                            addTo.Actions.Add(new ExitStageAction(cell, exit));
                        }
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// Process the start of the turn
        /// </summary>
        /// <param name="element"></param>
        public void StartTurnOf(Element element)
        {
            var context = new TurnContext(this, Stage, element, RNG);

            Active = element;
            for (int i = 0; i < element.Data.Count; i++)
            {
                IElementDataComponent dC = element.Data[i];
                if (dC is IStartOfTurn)
                {
                    ((IStartOfTurn)dC).StartOfTurn(context);
                }
                if (dC is IDeletable && ((IDeletable)dC).IsDeleted)
                {
                    element.Data.RemoveAt(i);
                    i--;
                }
            }

            if (element != Controlled)
            {
                var        ai      = new ActionSelectionAI(); //TEMP?
                var        actions = element.GetData <AvailableActions>();
                GameAction tAction = ai.SelectAction(context, actions.Actions);

                tAction.Enact(Log, new EffectContext(element, this));
                EndTurnOf(element);
            }
            else
            {
                var actions = element.GetData <AvailableActions>();
                if (actions == null || actions.Actions.Count == 0)
                {
                    EndTurnOf(element);
                }
            }
        }
Example #4
0
        protected override void GenerateActions(TurnContext context, AvailableActions addTo)
        {
            // Bump attack:
            MapData mD = context.Element?.GetData <MapData>();

            if (mD != null && mD.MapCell != null)
            {
                IList <MapCell> adjacent = context.Stage?.Map?.AdjacentCells(mD.MapCell.Index);
                //TODO: Diagonal?
                foreach (var cell in adjacent)
                {
                    Vector  direction = cell.Position - mD.MapCell.Position;
                    Element target    = context.Element.GetData <MapCellCollider>()?.Blocker(cell);
                    if (target != null)
                    {
                        if (context.Element?.GetData <Faction>()?.IsEnemy(target?.GetData <Faction>()) ?? false)
                        {
                            // Only allow bump attacks on elements of an opposing faction?
                            addTo.Actions.Add(new BumpAttackAction(target, cell, direction));
                        }
                    }
                }
            }
        }
Example #5
0
        public override double AIScore(TurnContext context, ActionSelectionAI weights)
        {
            Element self = context.Element;
            var     mDS  = self?.GetData <MapData>();
            var     mA   = self.GetData <MapAwareness>();

            // TEMP:
            Element target = ((RLState)context.State).Controlled;
            var     mDT    = target?.GetData <MapData>();

            if (mDT != null && !target.IsDeleted && mA.AwarenessOfCell(mDT.MapCell.Index) > 0)
            {
                // Manhatten distance calculation:
                Vector newPos = context.Stage.Map.CellPosition(_CellIndex);
                return(mDS.Position.ManhattenDistanceTo(mDT.Position)
                       - newPos.ManhattenDistanceTo(mDT.Position) + 0.05);
            }
            else
            {
                return(context.RNG.NextDouble());
            }

            // TODO: Employ influence maps
        }
Example #6
0
        public override double AIScore(TurnContext context, ActionSelectionAI weights)
        {
            double result = 0;

            foreach (MapCell cell in Target)
            {
                // Create a copy so that modifications to cell contents
                // don't screw up the enumeration:
                var elements = cell.Contents.ToList();

                foreach (var element in elements)
                {
                    if (context.Element?.GetData <Faction>()?.IsEnemy(element?.GetData <Faction>()) ?? false)
                    {
                        result += 10;
                    }
                    if (context.Element?.GetData <Faction>()?.IsAlly(element?.GetData <Faction>()) ?? false)
                    {
                        result -= context.RNG.NextDouble();
                    }
                }
            }
            return(result);
        }
Example #7
0
        protected override void GenerateActions(TurnContext context, AvailableActions addTo)
        {
            Element  actor    = context.Element;
            Equipped equipped = actor?.GetData <Equipped>();

            if (equipped != null)
            {
                foreach (EquipmentSlot slot in equipped.Slots)
                {
                    if (slot.Item != null)
                    {
                        var iA = slot.Item.GetData <ItemActions>();
                        if (iA?.Prototype != null)
                        {
                            var action = iA.Prototype.Duplicate();
                            action.Trigger = new ActionInputTrigger(slot.HotKey);
                            addTo.Actions.Add(action);
                        }
                    }
                }
            }
            //TODO: Base on items
            //addTo.Actions.Add(new WindUpAction(InputFunction.Ability_1));
        }
Example #8
0
 protected abstract void GenerateActions(TurnContext context, AvailableActions addTo);
 /// <summary>
 /// Generate the action for the specified direction and trigger cell
 /// </summary>
 /// <param name="direction"></param>
 /// <param name="triggerCell"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 protected abstract GameAction ActionForDirection(Vector position, Vector direction, MapCell triggerCell, TurnContext context);
Example #10
0
 public override void StartOfTurn(TurnContext context)
 {
     base.StartOfTurn(context);
     Delete();
 }
Example #11
0
 public override double AIScore(TurnContext context, ActionSelectionAI weights)
 {
     return(0);
 }
Example #12
0
 /// <summary>
 /// Generate a score for this action based on the specified
 /// set of weightings
 /// </summary>
 /// <param name="weights"></param>
 /// <returns></returns>
 public virtual double AIScore(TurnContext context, ActionSelectionAI weights)
 {
     return(1.0);
 }
Example #13
0
 protected override void GenerateActions(TurnContext context, AvailableActions addTo)
 {
     //TODO: Add extra effects
     addTo.Actions.Add(new WaitAction());
 }
Example #14
0
 /// <summary>
 /// Generate actions given the specified context and add them to the available actions
 /// </summary>
 /// <param name="context"></param>
 /// <param name="addTo"></param>
 public abstract void GenerateActions(TurnContext context, AvailableActions addTo);
Example #15
0
 /// <summary>
 /// Is this ability currently disabled by a status effect?
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 protected virtual bool IsDisabled(TurnContext context)
 {
     return(context.Element.HasData <DisableActions>());
 }
Example #16
0
        protected override GameAction ActionForDirection(Vector position, Vector direction, MapCell triggerCell, TurnContext context)
        {
            var pattern = Offsets.Rotate(direction.Angle).Move(position);
            var cells   = context.Stage.Map.CellsAt(pattern);

            return(new AOEAttackAction(cells, triggerCell, direction, SourceSFX));
        }
Example #17
0
 public void EndOfTurn(TurnContext context)
 {
     // Clear all available actions
     Actions.Clear();
 }
Example #18
0
 /// <summary>
 /// End the status effect, performing any necessary clearup
 /// </summary>
 /// <param name="context"></param>
 public virtual void EndStatus(TurnContext context)
 {
 }
Example #19
0
 protected override bool IsDisabled(TurnContext context)
 {
     return(false); //TODO: Make disableable by status debuffs?
 }