public void SetInBatch_SetsCorrectly()
        {
            var batch = CreateBatch();

            ActionBehavior.SetInBatch(batch, NewKey, NewValue);

            AssertBehaviorWasSetCorrectly(batch, batch);
        }
        public void SetInCarousel_SetsCorrectly()
        {
            var batch    = CreateBatch();
            var activity = batch[0];

            ActionBehavior.SetInCarousel(activity.Attachments, NewKey, NewValue);

            AssertBehaviorWasSetCorrectly(batch, activity);
        }
        public void SetInActivity_SetsCorrectly()
        {
            var batch    = CreateBatch();
            var activity = batch[0];

            ActionBehavior.SetInActivity(activity, NewKey, NewValue);

            AssertBehaviorWasSetCorrectly(batch, activity);
        }
        public void SetInAttachment_SetsCorrectly()
        {
            var batch      = CreateBatch();
            var attachment = batch[0].Attachments[0];

            ActionBehavior.SetInAttachment(attachment, NewKey, NewValue);

            AssertBehaviorWasSetCorrectly(batch, attachment);
        }
        public void SetInCardAction_SetsCorrectly()
        {
            var batch  = CreateBatch();
            var action = ((AnimationCard)batch[0].Attachments[1].Content).Buttons[0];

            ActionBehavior.SetInCardAction(action, NewKey, NewValue);

            AssertBehaviorWasSetCorrectly(batch, action);
        }
Ejemplo n.º 6
0
 void Start()
 {
     m_vehicle = new Vehicle(100, 10, gameObject.transform);
     m_move = new PlayerMovement(m_vehicle);
     m_bullet = Resources.Load("bullet") as GameObject;
     Vector3 bulletDirection = new Vector3(0, 0, Time.deltaTime * 10);
     m_attack1 = new ActionBehavior(m_vehicle, m_bullet, 0.25f, 10f, bulletDirection, "Enemy");
     m_attack1.setBulletSpeed(1f);
 }
Ejemplo n.º 7
0
    void Start()
    {
        m_vehicle = new Vehicle(100, 10, gameObject.transform);
        m_move    = new PlayerMovement(m_vehicle);
        m_bullet  = Resources.Load("bullet") as GameObject;
        Vector3 bulletDirection = new Vector3(0, 0, Time.deltaTime * 10);

        m_attack1 = new ActionBehavior(m_vehicle, m_bullet, 0.25f, 10f, bulletDirection, "Enemy");
        m_attack1.setBulletSpeed(1f);
    }
Ejemplo n.º 8
0
 public virtual void Start()
 {
     rb          = GetComponent <Rigidbody>();
     anim        = GetComponent <Animator>();
     targeting   = GetComponent <Targeting>();
     stats       = GetComponent <Stats>();
     ab          = GetComponent <ActionBehavior>();
     stats.Speed = baseSpeed;
     audioSource = GetComponent <AudioSource>();
 }
        public void SetInActionData_SetsCorrectly()
        {
            var batch        = CreateBatch();
            var submitAction = (AdaptiveSubmitAction)((AdaptiveCard)batch[0].Attachments[0].Content).Actions[0];

            object actionData = submitAction.Data;

            ActionBehavior.SetInActionData(ref actionData, NewKey, NewValue);

            submitAction.Data = actionData;

            AssertBehaviorWasSetCorrectly(batch, submitAction);
        }
        public void SetInSubmitAction_SetsCorrectly()
        {
            var batch   = CreateBatch();
            var actions = ((AdaptiveCard)batch[0].Attachments[0].Content).Actions;

            object submitAction = actions[0];

            ActionBehavior.SetInSubmitAction(ref submitAction, NewKey, NewValue);

            actions[0] = JObject.FromObject(submitAction).ToObject <AdaptiveSubmitAction>();

            AssertBehaviorWasSetCorrectly(batch, actions[0]);
        }
        public void SetInAdaptiveCard_SetsCorrectly()
        {
            var batch      = CreateBatch();
            var attachment = batch[0].Attachments[0];

            object adaptiveCard = attachment.Content;

            ActionBehavior.SetInAdaptiveCard(ref adaptiveCard, NewKey, NewValue);

            attachment.Content = adaptiveCard;

            AssertBehaviorWasSetCorrectly(batch, attachment);
        }
Ejemplo n.º 12
0
    void Start()
    {
        //movements
        m_transform = gameObject.transform;
        m_movement  = new EnemyMovement(this, m_waypoints);

        //attacks
        m_bullet = Resources.Load("bullet") as GameObject;
        Vector3 bulletOffset = new Vector3(0, 0, 0);

        m_attack = new ActionBehavior(this, m_bullet, fireRate, damage, m_projectileDirection, "Player", bulletOffset);
        m_attack.setBulletSpeed(0.1f);
    }
    private void Start()
    {
        if (buttonTiers.Count != buttonTierUnlocks.Count)
        {
            throw new System.Exception("Tier Counts don't match!!");
        }

        if (buttonTiers.Count != 0)
        {
            CheckButtons();
        }

        ActionBehavior.SetUpClass();
    }
Ejemplo n.º 14
0
        private void SendCommand(ActionBehavior act, WorldObject wo, bool store)
        {
            if (selectedWO != null && !selectedWO.IsDestroyed() && wo != null && !wo.IsDestroyed())
            {
                var message = networkService.CreateClientMessage();
                message.Write(NetworkedScene.WO_ACTION);
                message.Write(selectedWO.Owner.Name);
                message.Write(wo.Owner.Name);
                message.Write((int)act.GetCommand());
                message.Write(store);

                networkService.SendToServer(message, WaveEngine.Networking.Messages.DeliveryMethod.ReliableOrdered);
            }
        }
        public void SetActionBehavior_Existing()
        {
            var actionData = CreateActionData();

            ActionBehavior.SetInActionData(ref actionData, OldKey, NewValue);

            var expected = new JObject
            {
                { OldKey, NewValue },
            };

            var actual = GetLibraryData(actionData);

            Assert.IsTrue(JToken.DeepEquals(expected, actual));
        }
        public void SetActionBehavior_New()
        {
            var actionData = CreateActionData();

            ActionBehavior.SetInActionData(ref actionData, NewKey, NewValue);

            var expected = new JObject
            {
                { OldKey, OldValue },
                { NewKey, NewValue },
            };

            var actual = JObject.FromObject(actionData)[PropertyNames.LibraryData];

            Assert.IsTrue(JToken.DeepEquals(expected, actual));
        }
Ejemplo n.º 17
0
    private void Activate()
    {
        if (actionToRun.transform != transform)
        {
            Debug.Log("Action To Run is not on the button...");
            actionRunning = Instantiate(actionToRun, controller.transform);
        }
        else
        {
            actionRunning = actionToRun;
        }

        actionRunning.SetUp(controller, controller.level);
        controller.OnActionButtonStart(this);

        ClickSound();
    }
Ejemplo n.º 18
0
        /**
         * <summary>
         * Method for executing an action if requires adjacency,
         * or computes a path and stores the action for when it finishes moving closer
         * </summary>
         */
        private void HandleMovementAction(WorldObject wo, LayerTile currentTile, ActionBehavior act)
        {
            if (selectedWO != null && !selectedWO.IsDestroyed() && !selectedWO.IsActionBlocking())
            {
                if (wo.IsAdjacent(selectedWO))
                {
                    SendCommand(act, wo, false);
                }
                else if (selectedWO.IsMobile())
                {
                    List <LayerTile> dPath = new List <LayerTile>();

                    DStarLite dstar = selectedWO.Owner.FindComponent <DStarLite>();

                    LayerTile start = map.GetTileByWorldPosition(selectedWO.GetCenteredPosition());
                    if (currentTile != start)
                    {
                        dPath = dstar.DStar(start, currentTile);
                    }
                    else
                    {
                        //we are in the same tile, we move to an adjacent an enqueue action
                        dPath.Add(start);
                        List <LayerTile> neighbors = IsAdjacentTileFree(start, dstar);
                        if (neighbors.Count > 0)
                        {
                            dPath.Add(neighbors[0]);
                        }
                    }
                    if (dPath.Count > 1)
                    {
                        SendPath(dPath);
                        SendCommand(act, wo, true);
                    }
                }
            }
        }
Ejemplo n.º 19
0
        public override async Task ExecuteAsync(ExecutionContext context, ExecutionBranchContext branchContext)
        {
            await base.ExecuteAsync(context, branchContext);

            var hit = context.Reader.ReadBit();

            context.Writer.Write(hit);

            if (hit) // Hit
            {
                if (CheckEnvironment)
                {
                    var checkEnvironment = context.Reader.ReadBit(); // Check environment

                    context.Writer.WriteBit(checkEnvironment);
                }

                var targets = new GameObject[context.Reader.Read <uint>()];

                context.Writer.Write((uint)targets.Length);

                for (var i = 0; i < targets.Length; i++)
                {
                    var targetId = context.Reader.Read <long>();

                    context.Writer.Write(targetId);

                    if (!context.Associate.Zone.TryGetGameObject(targetId, out var target))
                    {
                        Logger.Error($"{context.Associate} sent invalid TacArc target: {targetId}");

                        continue;
                    }

                    targets[i] = target;
                }

                foreach (var target in targets)
                {
                    ((Player)context.Associate)?.SendChatMessage($"ATTACKING: {target}");

                    var branch = new ExecutionBranchContext(target)
                    {
                        Duration = branchContext.Duration
                    };

                    await ActionBehavior.ExecuteAsync(context, branch);
                }
            }
            else
            {
                if (Blocked)
                {
                    var isBlocked = context.Reader.ReadBit();

                    context.Writer.WriteBit(isBlocked);

                    if (isBlocked) // Is blocked
                    {
                        await BlockedBehavior.ExecuteAsync(context, branchContext);
                    }
                    else
                    {
                        await MissBehavior.ExecuteAsync(context, branchContext);
                    }
                }
                else
                {
                    await MissBehavior.ExecuteAsync(context, branchContext);
                }
            }
        }
Ejemplo n.º 20
0
        private void lbxActions_SelectedIndexChanged(object sender, EventArgs e)
        {
            pnlActionInfo.Enabled = lbxActions.SelectedIndex != -1;

            if (lbxActions.SelectedIndex != -1 && currentEnemy != null)
            {
                currentAction = currentEnemy.Behavior.Actions[lbxActions.SelectedIndex];
                cbbActionType.SelectedIndex = (int)currentAction.ActionType;
                cbbNewBehavior.SelectedIndex = (int)currentAction.NewBehavior;
                lbxSkillUsed.SelectedValue = currentAction.SkillId;
                LoadConditions();
                LoadActionSkill();
            }
        }
Ejemplo n.º 21
0
 private void btnNewAction_Click(object sender, EventArgs e)
 {
     ActionBehavior action = new ActionBehavior();
     currentEnemy.Behavior.Actions.Add(action);
     LoadActions();
 }
Ejemplo n.º 22
0
Archivo: Enemy.cs Proyecto: sseng/omega
    void Start()
    {
        //movements
        m_transform = gameObject.transform;
        m_movement = new EnemyMovement(this, m_waypoints);

        //attacks
        m_bullet = Resources.Load("bullet") as GameObject;
        Vector3 bulletOffset = new Vector3(0, 0, 0);
        m_attack = new ActionBehavior(this, m_bullet, fireRate, damage, m_projectileDirection, "Player", bulletOffset);
        m_attack.setBulletSpeed(0.1f);
    }
Ejemplo n.º 23
0
 public void SetNextAction(Action action)
 {
     Behavior = new ActionBehavior(action);
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Construct an argument with specified action and behavior flag.
 /// </summary>
 /// <param name="action">action is currently performing.</param>
 /// <param name="behavior">behavior flag of current operation.</param>
 public ActionEventArgs(IAction action, ActionBehavior behavior)
 {
     this.action   = action;
     this.Behavior = behavior;
 }
Ejemplo n.º 25
0
 public ObjectActionEventArgs(object obj, IAction action, ActionBehavior behavior)
     : base(action, behavior)
 {
     this.Object = obj;
 }
Ejemplo n.º 26
0
 public ActionEventArgs(IAction action, ActionBehavior behavior)
 {
     this.action = action;
     this.Behavior = behavior;
 }
Ejemplo n.º 27
0
        public static IEnumerable <IBehavior> BuildFromAttributes(IActor linkedActor)
        {
            CheckArg.Actor(linkedActor);
            var bhvs = new List <IBehavior>();

            // Launch reflexion
            MemberInfo[] memberInfo = linkedActor.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance);
            foreach (var mi in memberInfo)
            {
#if NETCOREAPP1_1
                ActionBehaviorAttribute deco = mi.GetCustomAttribute <ActionBehaviorAttribute>();
#else
                ActionBehaviorAttribute deco = (ActionBehaviorAttribute)Attribute.GetCustomAttribute(mi, typeof(ActionBehaviorAttribute));
#endif
                if (deco != null)
                {
                    var parameters = ((MethodInfo)mi).GetParameters();
                    switch (parameters.Length)
                    {
                    case 0:
                    {
                        IBehavior bhv = new ActionBehavior(
                            (a) => a.GetType() == mi.GetType(),
                            (a) => a()
                            );
                        bhvs.Add(bhv);
                        break;
                    }

                    case 1:
                    {
                        var             genericArg  = parameters[0].ParameterType;
                        var             genericType = typeof(ActionBehavior <>).MakeGenericType(new Type[] { genericArg });
                        ConstructorInfo ci          = genericType.GetConstructor(Type.EmptyTypes);
                        object          o           = ci.Invoke(new object[] { });
                        bhvs.Add(o as IBehavior);
                        break;
                    }

                    case 2:
                    {
                        IBehavior bhv = new ActionBehavior <object, object>(
                            (a, o1, o2) => a.GetType() == mi.GetType(),
                            (a, o1, o2) => a(o1, o2)
                            );
                        bhvs.Add(bhv);
                        break;
                    }

                    case 3:
                    {
                        Behavior bhv = new Behavior(
                            s =>
                            {
                                return(s.GetType().Name == typeof(MessageParam <, ,>).Name);
                            },
                            s =>
                            {
                                var ts   = s.GetType();
                                var arg1 = ts.GetProperty("Item1").GetValue(s);
                                var arg2 = ts.GetProperty("Item2").GetValue(s);
                                var arg3 = ts.GetProperty("Item3").GetValue(s);
                                ((MethodInfo)mi).Invoke(linkedActor, new[] { arg1, arg2, arg3 });
                            });
                        bhvs.Add(bhv);
                        break;
                    }

                    default:
                    {
                        throw new ActorException(MessageTooMuchArgumentsOnDecoratedActor);
                    }
                    }
                }
            }
            return(bhvs);
        }
Ejemplo n.º 28
0
 public ObjectActionEventArgs(object obj, IAction action, ActionBehavior behavior)
     : base(action, behavior)
 {
     this.Object = obj;
 }
Ejemplo n.º 29
0
        public override async Task CalculateAsync(NpcExecutionContext context, ExecutionBranchContext branchContext)
        {
            if (!context.Associate.TryGetComponent <BaseCombatAiComponent>(out var baseCombatAiComponent))
            {
                return;
            }

            var validTarget = baseCombatAiComponent.SeekValidTargets();

            var sourcePosition = context.CalculatingPosition; // Change back to author position?

            var targets = validTarget.Where(target =>
            {
                var transform = target.Transform;

                var distance = Vector3.Distance(transform.Position, sourcePosition);

                return(distance <= context.MaxRange && context.MinRange <= distance);
            }).ToList();

            targets.ToList().Sort((g1, g2) =>
            {
                var distance1 = Vector3.Distance(g1.Transform.Position, sourcePosition);
                var distance2 = Vector3.Distance(g2.Transform.Position, sourcePosition);

                return((int)(distance1 - distance2));
            });

            var selectedTargets = new List <GameObject>();

            foreach (var target in targets)
            {
                if (selectedTargets.Count < MaxTargets)
                {
                    selectedTargets.Add(target);
                }
            }

            if (!context.Alive)
            {
                selectedTargets.Clear(); // No targeting if dead
            }

            var any = selectedTargets.Any();

            context.Writer.WriteBit(any); // Hit

            if (any)
            {
                baseCombatAiComponent.Target = selectedTargets.First();

                context.FoundTarget = true;

                if (CheckEnvironment)
                {
                    // TODO
                    context.Writer.WriteBit(false);
                }

                context.Writer.Write((uint)selectedTargets.Count);

                foreach (var target in selectedTargets)
                {
                    context.Writer.Write(target.Id);
                }

                foreach (var target in selectedTargets)
                {
                    if (!(target is Player player))
                    {
                        continue;
                    }

                    player.SendChatMessage($"You are a target! [{context.SkillSyncId}]");
                }

                foreach (var target in selectedTargets)
                {
                    var branch = new ExecutionBranchContext(target)
                    {
                        Duration = branchContext.Duration
                    };

                    await ActionBehavior.CalculateAsync(context, branch);
                }
            }
            else
            {
                if (Blocked)
                {
                    // TODO
                    context.Writer.WriteBit(false);
                }
                else
                {
                    await MissBehavior.CalculateAsync(context, branchContext);
                }
            }
        }
Ejemplo n.º 30
0
        public override async Task ExecuteAsync(ExecutionContext context, ExecutionBranchContext branchContext)
        {
            await base.ExecuteAsync(context, branchContext);

            if (UsePickedTarget && context.ExplicitTarget != null)
            {
                var branch = new ExecutionBranchContext(context.ExplicitTarget)
                {
                    Duration = branchContext.Duration
                };

                await ActionBehavior.ExecuteAsync(context, branch);

                return;
            }

            var hit = context.Reader.ReadBit();

            if (hit) // Hit
            {
                var targets = new List <GameObject>();

                if (CheckEnvironment)
                {
                    context.Reader.ReadBit();
                }

                var specifiedTargets = context.Reader.Read <uint>();

                for (var i = 0; i < specifiedTargets; i++)
                {
                    var targetId = context.Reader.Read <long>();

                    if (!context.Associate.Zone.TryGetGameObject(targetId, out var target))
                    {
                        Logger.Error($"{context.Associate} sent invalid TacArc target: {targetId}");

                        continue;
                    }

                    targets.Add(target);
                }

                foreach (var target in targets)
                {
                    var branch = new ExecutionBranchContext(target)
                    {
                        Duration = branchContext.Duration
                    };

                    await ActionBehavior.ExecuteAsync(context, branch);
                }
            }
            else
            {
                if (Blocked)
                {
                    var isBlocked = context.Reader.ReadBit();

                    if (isBlocked) // Is blocked
                    {
                        await BlockedBehavior.ExecuteAsync(context, branchContext);
                    }
                    else
                    {
                        await MissBehavior.ExecuteAsync(context, branchContext);
                    }
                }
                else
                {
                    await MissBehavior.ExecuteAsync(context, branchContext);
                }
            }
        }
Ejemplo n.º 31
0
 public ActionReceiver(ActionBehavior orig, WorldObject dest)
 {
     sender   = orig;
     receiver = dest;
 }