Beispiel #1
0
        private async Task BuildAsync()
        {
            await using var ctx = new CdClientContext();

            foreach (var skill in BehaviorIds)
            {
                var root = BehaviorBase.Cache.ToArray().FirstOrDefault(b => b.BehaviorId == skill.BaseBehavior);

                if (root == default)
                {
                    var behavior = await ctx.BehaviorTemplateTable.FirstOrDefaultAsync(
                        t => t.BehaviorID == skill.BaseBehavior
                        );

                    if (behavior?.TemplateID == null)
                    {
                        continue;
                    }

                    var behaviorTypeId = (BehaviorTemplateId)behavior.TemplateID;

                    if (!Behaviors.TryGetValue(behaviorTypeId, out var behaviorType))
                    {
                        Logger.Error($"No behavior type of \"{behaviorTypeId}\" found.");

                        continue;
                    }

                    var instance = (BehaviorBase)Activator.CreateInstance(behaviorType);

                    instance.BehaviorId = skill.BaseBehavior;

                    BehaviorBase.Cache.Add(instance);

                    await instance.BuildAsync();

                    root = instance;
                }

                SkillRoots[skill.SkillId] = root;

                if (RootBehaviors.TryGetValue(skill.CastType, out var list))
                {
                    list.Add(root);
                }
                else
                {
                    RootBehaviors[skill.CastType] = new List <BehaviorBase> {
                        root
                    };
                }
            }
        }
Beispiel #2
0
        public async Task <ExecutionContext> UseAsync(GameObject associate, BitReader reader, GameObject target)
        {
            var context = new ExecutionContext(associate, reader, default);

            if (!RootBehaviors.TryGetValue(SkillCastType.OnUse, out var list))
            {
                return(context);
            }

            foreach (var root in list)
            {
                context.Root = root;

                var branchContext = new ExecutionBranchContext(target);

                await root.ExecuteAsync(context, branchContext);
            }

            return(context);
        }
Beispiel #3
0
        public async Task <ExecutionContext> DismantleAsync(GameObject associate)
        {
            var context = new ExecutionContext(associate, new BitReader(new MemoryStream()),
                                               new BitWriter(new MemoryStream()));

            if (!RootBehaviors.TryGetValue(SkillCastType.OnEquip, out var list))
            {
                return(context);
            }

            foreach (var root in list)
            {
                context.Root = root;

                var branchContext = new ExecutionBranchContext(associate);

                await root.DismantleAsync(context, branchContext);
            }

            return(context);
        }
Beispiel #4
0
        /// <summary>
        ///     Execute a user preformed skill
        /// </summary>
        /// <param name="associate">Executioner</param>
        /// <param name="reader">Client skill data</param>
        /// <param name="writer">Data to be sent to clients</param>
        /// <param name="castType">Type of skill</param>
        /// <param name="target">Explicit target</param>
        /// <returns>Context</returns>
        public async Task <ExecutionContext> ExecuteAsync(GameObject associate, BitReader reader,
                                                          SkillCastType castType = SkillCastType.OnEquip, GameObject target = default)
        {
            var context = new ExecutionContext(associate, reader, default)
            {
                ExplicitTarget = target
            };

            if (RootBehaviors.TryGetValue(SkillCastType.Default, out var defaultList))
            {
                foreach (var root in defaultList)
                {
                    context.Root = root;

                    var branchContext = new ExecutionBranchContext(associate);

                    await root.ExecuteAsync(context, branchContext);
                }
            }

            if (!RootBehaviors.TryGetValue(castType, out var list))
            {
                return(context);
            }

            foreach (var root in list)
            {
                context.Root = root;

                var branchContext = new ExecutionBranchContext(associate);

                await root.ExecuteAsync(context, branchContext);
            }

            return(context);
        }