Esempio n. 1
0
        /// <summary>
        /// Executes behavior with given context
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public override BehaviorReturnCode Behave(IBehaviorContext context)
        {
            UnitBehaviorContext unitContext = context as UnitBehaviorContext;

            if (unitContext == null || unitContext.Unit == null || unitContext.Unit.StrikeGroup == null)
            {
                returnCode = BehaviorReturnCode.Failure;
                return(returnCode);
            }

            MoveableUnit unit = unitContext.Unit as MoveableUnit;

            if (!unit.IsInDock)
            {
                returnCode = BehaviorReturnCode.Failure;
                return(returnCode);
            }

            MoveableUnit dockUnit = unit.GetDockUnit() as MoveableUnit;

            if (dockUnit != null && dockUnit.StrikeGroup == unit.StrikeGroup)
            {
                returnCode = BehaviorReturnCode.Success;
                return(returnCode);
            }

            returnCode = BehaviorReturnCode.Failure;
            return(returnCode);
        }
Esempio n. 2
0
        /// <summary>
        /// Executes behavior with given context
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public override BehaviorReturnCode Behave(IBehaviorContext context)
        {
            UnitBehaviorContext unitContext = context as UnitBehaviorContext;

            if (unitContext == null || unitContext.Unit == null || unitContext.Unit.StrikeGroup == null || unitContext.Unit.StrikeGroup.GroupLeader == null)
            {
                returnCode = BehaviorReturnCode.Failure;
                return(returnCode);
            }

            MoveableUnit groupLeader = unitContext.Unit.StrikeGroup.GroupLeader as MoveableUnit;

            if (groupLeader == null || !groupLeader.IsInDock)
            {
                returnCode = BehaviorReturnCode.Failure;
                return(returnCode);
            }

            StaticUnit unit = unitContext.Unit as StaticUnit;

            unit.Target = groupLeader.GetDockUnit() as BaseUnit;
            if (unit.Target == null)
            {
                returnCode = BehaviorReturnCode.Failure;
                return(returnCode);
            }

            returnCode = BehaviorReturnCode.Success;
            return(returnCode);
        }
Esempio n. 3
0
        /// <summary>
        /// Executes behavior with given context
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public override BehaviorReturnCode Behave(IBehaviorContext context)
        {
            UnitBehaviorContext unitContext = context as UnitBehaviorContext;

            if (unitContext == null)
            {
                returnCode = BehaviorReturnCode.Failure;
                return(returnCode);
            }

            MoveableUnit unit = unitContext.Unit as MoveableUnit;

            if (unit == null || unit.IsDead)
            {
                returnCode = BehaviorReturnCode.Failure;
                return(returnCode);
            }

            BaseUnit dockUnit = unit.GetDockUnit() as BaseUnit;

            if (dockUnit == null)
            {
                returnCode = BehaviorReturnCode.Failure;
                return(returnCode);
            }

            LeaveDockTask task = new LeaveDockTask(unit, dockUnit);

            task.Execute();

            if (task.IsTaskFinished)
            {
                returnCode = BehaviorReturnCode.Success;
                return(returnCode);
            }

            returnCode = BehaviorReturnCode.Failure;
            return(returnCode);
        }