Esempio n. 1
0
        public override void OnEvent(SpellCastRequestEvent spellCastRequest)
        {
            base.OnEvent(spellCastRequest);

            Player caster = World.FindPlayer(spellCastRequest.RaisedBy);
            SpellCastRequestAnswerEvent spellCastAnswer = spellCastRequest.FromSelf
                ? SpellCastRequestAnswerEvent.Create(GlobalTargets.OnlyServer)
                : SpellCastRequestAnswerEvent.Create(spellCastRequest.RaisedBy);

            spellCastAnswer.SpellId = spellCastRequest.SpellId;

            if (caster == null)
            {
                spellCastAnswer.Result = (int)SpellCastResult.CasterNotExists;
                spellCastAnswer.Send();
                return;
            }

            if (!balance.SpellInfosById.TryGetValue(spellCastRequest.SpellId, out SpellInfo spellInfo))
            {
                spellCastAnswer.Result = (int)SpellCastResult.SpellUnavailable;
                spellCastAnswer.Send();
                return;
            }

            SpellCastResult castResult = caster.Spells.CastSpell(spellInfo, new SpellCastingOptions(movementFlags: (MovementFlags)spellCastRequest.MovementFlags));

            if (castResult != SpellCastResult.Success)
            {
                spellCastAnswer.Result = (int)castResult;
                spellCastAnswer.Send();
            }
        }
        private void HandleSpellCast(Event request, int spellId, MovementFlags movementFlags, Vector3?destination = null)
        {
            Player caster = World.FindPlayer(request.RaisedBy);
            SpellCastRequestAnswerEvent spellCastAnswer = request.FromSelf
                ? SpellCastRequestAnswerEvent.Create(GlobalTargets.OnlyServer)
                : SpellCastRequestAnswerEvent.Create(request.RaisedBy);

            spellCastAnswer.SpellId = spellId;

            if (caster == null)
            {
                spellCastAnswer.Result = (int)SpellCastResult.CasterNotExists;
                spellCastAnswer.Send();
                return;
            }

            if (!balance.SpellInfosById.TryGetValue(spellId, out SpellInfo spellInfo))
            {
                spellCastAnswer.Result = (int)SpellCastResult.SpellUnavailable;
                spellCastAnswer.Send();
                return;
            }

            SpellCastingOptions options = destination.HasValue
                ? new SpellCastingOptions(new SpellExplicitTargets {
                Destination = destination.Value
            })
                : new SpellCastingOptions(movementFlags: movementFlags);

            SpellCastResult castResult = caster.Spells.CastSpell(spellInfo, options);

            if (castResult != SpellCastResult.Success)
            {
                spellCastAnswer.Result = (int)castResult;
                spellCastAnswer.Send();
            }
        }
Esempio n. 3
0
        private void OnServerSpellLaunch(Unit caster, SpellInfo spellInfo, SpellProcessingToken processingToken)
        {
            UnitSpellLaunchEvent unitCastEvent = UnitSpellLaunchEvent.Create(caster.BoltEntity, EntityTargets.Everyone);

            unitCastEvent.SpellId           = spellInfo.Id;
            unitCastEvent.ProcessingEntries = processingToken;
            unitCastEvent.Send();

            SpellCastRequestAnswerEvent spellCastAnswer = caster.IsController
                ? SpellCastRequestAnswerEvent.Create(GlobalTargets.OnlyServer, ReliabilityModes.ReliableOrdered)
                : SpellCastRequestAnswerEvent.Create(caster.BoltEntity.Controller, ReliabilityModes.ReliableOrdered);

            spellCastAnswer.SpellId           = spellInfo.Id;
            spellCastAnswer.Result            = (int)SpellCastResult.Success;
            spellCastAnswer.ProcessingEntries = processingToken;
            spellCastAnswer.Send();
        }