Пример #1
0
        public void ParsePlot(Unit caster, SkillCaster casterCaster, BaseUnit target, SkillCastTarget targetCaster,
                              SkillObject skillObject, PlotStep step)
        {
            if (step.Flag != 0)
            {
                foreach (var eff in step.Event.Effects)
                {
                    var template = SkillManager.Instance.GetEffectTemplate(eff.ActualId, eff.ActualType);
                    if (template is BuffEffect)
                    {
                        step.Flag = 6;
                    }
                    template.Apply(caster, casterCaster, target, targetCaster,
                                   new CastPlot(step.Event.PlotId, TlId, step.Event.Id, Template.Id),
                                   this, skillObject, DateTime.Now);
                }
            }

            var time  = (ushort)(step.Flag != 0 ? step.Delay / 10 : 0);
            var unkId = step.Casting || step.Channeling ? caster.ObjId : 0;

            caster.BroadcastPacket(
                new SCPlotEventPacket(TlId, step.Event.Id, Template.Id, caster.ObjId, target.ObjId, unkId, time,
                                      step.Flag),
                true);

            foreach (var st in step.Steps)
            {
                ParsePlot(caster, casterCaster, target, targetCaster, skillObject, st);
            }
        }
Пример #2
0
        public void Use(Unit caster, SkillAction casterAction, SkillAction targetAction)
        {
            var target = (BaseUnit)caster;

            if (Template.TargetType == SkillTargetType.Self)
            {
                if (targetAction.Type == SkillActionType.Unit || targetAction.Type == SkillActionType.Doodad)
                {
                    targetAction.ObjId = target.ObjId;
                }
            }
            else
            {
                // TODO ...
            }

            TlId = (ushort)TlIdManager.Instance.GetNextId();
            if (Template.Plot != null)
            {
                var eventTemplate = Template.Plot.EventTemplate;
                var step          = new PlotStep();
                step.Event = eventTemplate;
                step.Flag  = 2;

                if (!eventTemplate.СheckСonditions(caster, casterAction, target, targetAction))
                {
                    step.Flag = 0;
                }

                var res = true;
                if (step.Flag != 0)
                {
                    foreach (var evnt in eventTemplate.NextEvents)
                    {
                        res = res && BuildPlot(caster, casterAction, target, targetAction, evnt, step);
                    }
                }
                ParsePlot(caster, casterAction, target, targetAction, step);
                if (!res)
                {
                    return;
                }
                TlIdManager.Instance.ReleaseId(TlId);
                TlId = 0;
            }
            else
            {
                if (Template.CastingTime > 0)
                {
                    caster.BroadcastPacket(new SCSkillStartedPacket(Id, TlId, casterAction, targetAction, this), true);
                    caster.SkillTask = new CastTask(this, caster, casterAction, target, targetAction);
                    TaskManager.Instance.Schedule(caster.SkillTask, TimeSpan.FromMilliseconds(Template.CastingTime));
                }
                else
                {
                    Cast(caster, casterAction, target, targetAction);
                }
            }
        }
Пример #3
0
        public bool BuildPlot(Unit caster, SkillCaster casterCaster, BaseUnit target, SkillCastTarget targetCaster, SkillObject skillObject,
                              PlotNextEvent nextEvent, PlotStep baseStep)
        {
            if (nextEvent.Delay > 0)
            {
                baseStep.Delay   = nextEvent.Delay;
                caster.SkillTask = new PlotTask(this, caster, casterCaster, target, targetCaster, skillObject, nextEvent);
                TaskManager.Instance.Schedule(caster.SkillTask, TimeSpan.FromMilliseconds(nextEvent.Delay));
                return(false);
            }

            if (nextEvent.Speed > 0)
            {
                baseStep.Speed   = nextEvent.Speed;
                caster.SkillTask = new PlotTask(this, caster, casterCaster, target, targetCaster, skillObject, nextEvent);
                TaskManager.Instance.Schedule(caster.SkillTask,
                                              TimeSpan.FromMilliseconds(nextEvent.Speed * 40)); // TODO зависит от расстояния, найти формулу
                return(false);
            }

            var step = new PlotStep();

            step.Event      = nextEvent.Event;
            step.Flag       = 2;
            step.Casting    = nextEvent.Casting;
            step.Channeling = nextEvent.Channeling;
            foreach (var condition in nextEvent.Event.Conditions)
            {
                if (condition.Condition.Check(caster, casterCaster, target, targetCaster, skillObject))
                {
                    continue;
                }
                step.Flag = 0;
                break;
            }

            baseStep.Steps.AddLast(step);
            if (step.Flag == 0)
            {
                return(true);
            }
            var res = true;

            foreach (var e in nextEvent.Event.NextEvents)
            {
                res = res && BuildPlot(caster, casterCaster, target, targetCaster, skillObject, e, step);
            }
            return(res);
        }
Пример #4
0
        public override void Execute()
        {
            _caster.SkillTask = null;
            var step = new PlotStep();

            step.Event      = _nextEvent.Event;
            step.Casting    = _nextEvent.Casting;
            step.Channeling = _nextEvent.Channeling;
            step.Flag       = 2;
            foreach (var condition in _nextEvent.Event.Conditions)
            {
                if (condition.Condition.Check(_caster, _casterCaster, _target, _targetCaster, _skillObject))
                {
                    continue;
                }
                step.Flag = 0;
                break;
            }

            var res = true;

            if (step.Flag != 0)
            {
                foreach (var evnt in _nextEvent.Event.NextEvents)
                {
                    res = res && Skill.BuildPlot(_caster, _casterCaster, _target, _targetCaster, _skillObject, evnt,
                                                 step, _counter);
                }
            }
            Skill.ParsePlot(_caster, _casterCaster, _target, _targetCaster, _skillObject, step);
            if (!res)
            {
                return;
            }
            TlIdManager.Instance.ReleaseId(Skill.TlId);
            Skill.TlId = 0;
        }
Пример #5
0
        public void Use(Unit caster, SkillCaster casterCaster, SkillCastTarget targetCaster, SkillObject skillObject = null)
        {
            if (skillObject == null)
            {
                skillObject = new SkillObject();
            }
            var effects = caster.Effects.GetEffectsByType(typeof(BuffTemplate));

            foreach (var effect in effects)
            {
                if (((BuffTemplate)effect.Template).RemoveOnStartSkill || ((BuffTemplate)effect.Template).RemoveOnUseSkill)
                {
                    effect.Exit();
                }
            }
            effects = caster.Effects.GetEffectsByType(typeof(BuffEffect));
            foreach (var effect in effects)
            {
                if (((BuffEffect)effect.Template).Buff.RemoveOnStartSkill || ((BuffEffect)effect.Template).Buff.RemoveOnUseSkill)
                {
                    effect.Exit();
                }
            }

            var target = (BaseUnit)caster;

            if (Template.TargetType == SkillTargetType.Self)
            {
                if (targetCaster.Type == SkillCastTargetType.Unit || targetCaster.Type == SkillCastTargetType.Doodad)
                {
                    targetCaster.ObjId = target.ObjId;
                }
            }
            else if (Template.TargetType == SkillTargetType.Friendly)
            {
                if (targetCaster.Type == SkillCastTargetType.Unit || targetCaster.Type == SkillCastTargetType.Doodad)
                {
                    target             = targetCaster.ObjId > 0 ? WorldManager.Instance.GetBaseUnit(targetCaster.ObjId) : caster;
                    targetCaster.ObjId = target.ObjId;
                }
                else
                {
                    // TODO ...
                }

                if (caster.Faction.GetRelationState(target.Faction.Id) != RelationState.Friendly)
                {
                    return; //TODO отправлять ошибку?
                }
            }
            else if (Template.TargetType == SkillTargetType.Hostile)
            {
                if (targetCaster.Type == SkillCastTargetType.Unit || targetCaster.Type == SkillCastTargetType.Doodad)
                {
                    target             = targetCaster.ObjId > 0 ? WorldManager.Instance.GetBaseUnit(targetCaster.ObjId) : caster;
                    targetCaster.ObjId = target.ObjId;
                }
                else
                {
                    // TODO ...
                }

                if (caster.Faction.GetRelationState(target.Faction.Id) != RelationState.Hostile)
                {
                    return; //TODO отправлять ошибку?
                }
            }
            else if (Template.TargetType == SkillTargetType.AnyUnit)
            {
                if (targetCaster.Type == SkillCastTargetType.Unit || targetCaster.Type == SkillCastTargetType.Doodad)
                {
                    target             = targetCaster.ObjId > 0 ? WorldManager.Instance.GetBaseUnit(targetCaster.ObjId) : caster;
                    targetCaster.ObjId = target.ObjId;
                }
                else
                {
                    // TODO ...
                }
            }
            else if (Template.TargetType == SkillTargetType.Doodad)
            {
                if (targetCaster.Type == SkillCastTargetType.Unit || targetCaster.Type == SkillCastTargetType.Doodad)
                {
                    target             = targetCaster.ObjId > 0 ? WorldManager.Instance.GetBaseUnit(targetCaster.ObjId) : caster;
                    targetCaster.ObjId = target.ObjId;
                }
                else
                {
                    // TODO ...
                }
            }
            else if (Template.TargetType == SkillTargetType.Item)
            {
                // TODO ...
            }
            else if (Template.TargetType == SkillTargetType.Others)
            {
                if (targetCaster.Type == SkillCastTargetType.Unit || targetCaster.Type == SkillCastTargetType.Doodad)
                {
                    target             = targetCaster.ObjId > 0 ? WorldManager.Instance.GetBaseUnit(targetCaster.ObjId) : caster;
                    targetCaster.ObjId = target.ObjId;
                }
                else
                {
                    // TODO ...
                }

                if (caster.ObjId == target.ObjId)
                {
                    return; //TODO отправлять ошибку?
                }
            }
            else if (Template.TargetType == SkillTargetType.FriendlyOthers)
            {
                if (targetCaster.Type == SkillCastTargetType.Unit || targetCaster.Type == SkillCastTargetType.Doodad)
                {
                    target             = targetCaster.ObjId > 0 ? WorldManager.Instance.GetBaseUnit(targetCaster.ObjId) : caster;
                    targetCaster.ObjId = target.ObjId;
                }
                else
                {
                    // TODO ...
                }

                if (caster.ObjId == target.ObjId)
                {
                    return; //TODO отправлять ошибку?
                }
                if (caster.Faction.GetRelationState(target.Faction.Id) != RelationState.Friendly)
                {
                    return; //TODO отправлять ошибку?
                }
            }
            else if (Template.TargetType == SkillTargetType.Building)
            {
                if (targetCaster.Type == SkillCastTargetType.Unit || targetCaster.Type == SkillCastTargetType.Doodad)
                {
                    target             = targetCaster.ObjId > 0 ? WorldManager.Instance.GetBaseUnit(targetCaster.ObjId) : caster;
                    targetCaster.ObjId = target.ObjId;
                }
                else
                {
                    // TODO ...
                }

                if (caster.ObjId == target.ObjId)
                {
                    return; //TODO отправлять ошибку?
                }
            }
            else if (Template.TargetType == SkillTargetType.Pos)
            {
                var positionTarget = (SkillCastPositionTarget)targetCaster;
                var positionUnit   = new BaseUnit();
                positionUnit.Position         = new Point(positionTarget.PosX, positionTarget.PosY, positionTarget.PosZ);
                positionUnit.Position.ZoneId  = caster.Position.ZoneId;
                positionUnit.Position.WorldId = caster.Position.WorldId;
                positionUnit.Region           = caster.Region;
                target = positionUnit;
            }
            else
            {
                // TODO ...
            }

            TlId = (ushort)TlIdManager.Instance.GetNextId();
            if (Template.Plot != null)
            {
                var eventTemplate = Template.Plot.EventTemplate;
                var step          = new PlotStep();
                step.Event = eventTemplate;
                step.Flag  = 2;

                if (!eventTemplate.СheckСonditions(caster, casterCaster, target, targetCaster, skillObject))
                {
                    step.Flag = 0;
                }

                var res = true;
                if (step.Flag != 0)
                {
                    foreach (var evnt in eventTemplate.NextEvents)
                    {
                        res = res && BuildPlot(caster, casterCaster, target, targetCaster, skillObject, evnt, step);
                    }
                }
                ParsePlot(caster, casterCaster, target, targetCaster, skillObject, step);
                if (!res)
                {
                    return;
                }
                TlIdManager.Instance.ReleaseId(TlId);
                TlId = 0;
            }
            else
            {
                if (Template.CastingTime > 0)
                {
                    caster.BroadcastPacket(new SCSkillStartedPacket(Id, TlId, casterCaster, targetCaster, this, skillObject), true);
                    caster.SkillTask = new CastTask(this, caster, casterCaster, target, targetCaster, skillObject);
                    TaskManager.Instance.Schedule(caster.SkillTask, TimeSpan.FromMilliseconds(Template.CastingTime));
                }
                else
                {
                    Cast(caster, casterCaster, target, targetCaster, skillObject);
                }
            }
        }
Пример #6
0
        public bool BuildPlot(Unit caster, SkillCaster casterCaster, BaseUnit target, SkillCastTarget targetCaster,
                              SkillObject skillObject, PlotNextEvent nextEvent, PlotStep baseStep, Dictionary <uint, int> counter)
        {
            if (counter.ContainsKey(nextEvent.Event.Id))
            {
                var nextCount = counter[nextEvent.Event.Id] + 1;
                if (nextCount > nextEvent.Event.Tickets)
                {
                    return(true);
                }
                counter[nextEvent.Event.Id] = nextCount;
            }
            else
            {
                counter.Add(nextEvent.Event.Id, 1);
            }

            if (nextEvent.Delay > 0)
            {
                baseStep.Delay   = nextEvent.Delay;
                caster.SkillTask =
                    new PlotTask(this, caster, casterCaster, target, targetCaster, skillObject, nextEvent, counter);
                TaskManager.Instance.Schedule(caster.SkillTask, TimeSpan.FromMilliseconds(nextEvent.Delay));
                return(false);
            }

            if (nextEvent.Speed > 0)
            {
                baseStep.Speed   = nextEvent.Speed;
                caster.SkillTask =
                    new PlotTask(this, caster, casterCaster, target, targetCaster, skillObject, nextEvent, counter);
                var dist = MathUtil.CalculateDistance(caster.Position, target.Position, true);
                TaskManager.Instance.Schedule(caster.SkillTask,
                                              TimeSpan.FromSeconds(dist / nextEvent.Speed));
                return(false);
            }

            var step = new PlotStep();

            step.Event      = nextEvent.Event;
            step.Flag       = 2;
            step.Casting    = nextEvent.Casting;
            step.Channeling = nextEvent.Channeling;
            foreach (var condition in nextEvent.Event.Conditions)
            {
                if (condition.Condition.Check(caster, casterCaster, target, targetCaster, skillObject))
                {
                    continue;
                }
                step.Flag = 0;
                break;
            }

            baseStep.Steps.AddLast(step);
            if (step.Flag == 0)
            {
                return(true);
            }
            var res = true;

            foreach (var e in nextEvent.Event.NextEvents)
            {
                res = res && BuildPlot(caster, casterCaster, target, targetCaster, skillObject, e, step, counter);
            }
            return(res);
        }