Ejemplo n.º 1
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.º 2
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);
                }
            }
        }