Exemple #1
0
    //ジャンプパラメータをリセット
    private void JumpReset()
    {
        transform.position = move_end;
        transform.rotation = Quaternion.LookRotation(Vector3.Cross(m_Camera.right, jump_target.normal), jump_target.normal);
        switch (m_JumpMode)
        {
        case JumpMode.CapturingJump:
        {
            break;
        }

        case JumpMode.Bodyblow:
        {
            break;
        }

        case JumpMode.StringJump:
        {
            StringAllMinus();
            m_Shooter.StringShoot(move_start, move_end);
            break;
        }

        default:
        {
            if (isEscape)
            {
                m_Shooter.StringShoot(m_Prediction.m_HitStringPoint, move_end);
            }
            else
            {
                m_Shooter.StringShoot(move_start, move_end);
            }
            break;
        }
        }
        waitFrame     = 0;
        m_jumpableNum = -1;
        isEscape      = false;
        isLanding     = false;
        m_Prediction.m_HitStringPoint = Vector3.zero;
        m_EscapeSphere.SetActive(false);
        m_category = TargetCategory.Connecter;
        m_WindLine.Stop();
    }
Exemple #2
0
 //落下着地時の各値リセット
 private void LandingReset(Collider other)
 {
     ResetBodyblow();
     elapse_time    = 0;
     m_failureTime  = 0;
     m_treeWaitTime = 0;
     m_jumpableNum  = -1;
     m_AudioSource.PlayOneShot(m_AudioClips[3]);
     m_Animator.SetTrigger("Landing");
     m_category = TargetCategory.Connecter;
     if (other.transform.tag == "Ground")
     {
         m_StateManager.StateProcassor.State = m_StateManager.GroundTp;
     }
     else
     {
         m_StateManager.StateProcassor.State = m_StateManager.TreeTp;
     }
 }
Exemple #3
0
        /// <summary>
        /// Handles player targeted casting message
        /// </summary>
        public void HandleActionCastTargetedSpell(ObjectGuid guidTarget, uint spellId)
        {
            Player         player         = CurrentLandblock.GetObject(Guid) as Player;
            WorldObject    target         = CurrentLandblock.GetObject(guidTarget) as WorldObject;
            TargetCategory targetCategory = TargetCategory.WorldObject;

            if (guidTarget == Guid)
            {
                targetCategory = TargetCategory.Self;
            }
            if (target == null)
            {
                target         = GetWieldedItem(guidTarget);
                targetCategory = TargetCategory.Wielded;
            }
            if (target == null)
            {
                target         = GetInventoryItem(guidTarget);
                targetCategory = TargetCategory.Inventory;
            }
            if (target == null)
            {
                player.Session.Network.EnqueueSend(new GameEventUseDone(player.Session, errorType: WeenieError.TargetNotAcquired));
                targetCategory = TargetCategory.UnDef;
                return;
            }

            if (targetCategory != TargetCategory.WorldObject)
            {
                CreatePlayerSpell(guidTarget, spellId);
            }
            else
            {
                // turn if required
                var rotateTime  = Rotate(target) - 0.25f;
                var actionChain = new ActionChain();
                actionChain.AddDelaySeconds(rotateTime);

                actionChain.AddAction(this, () => CreatePlayerSpell(guidTarget, spellId));
                actionChain.EnqueueChain();
            }
        }
Exemple #4
0
 //始点、終点、射角、シューター番号、色の設定
 public void SetParameter(Vector3 start, Vector3 end, float angle, int shooterNum,
                          JumpMode mode = JumpMode.NormalJump, TargetCategory category = TargetCategory.Connecter, bool isAttackable = false)
 {
     m_start                 = start;
     m_end                   = end;
     m_angle                 = angle;
     m_shooterNum            = shooterNum;
     m_LineRenderer.material = m_Materials[0];
     m_LineRenderer.material.SetColor("_TintColor", m_Colors[(int)mode]);
     m_isCursorActive = (category == TargetCategory.Enemy || category == TargetCategory.JumpableTree);
     if (category == TargetCategory.None || (category == TargetCategory.Enemy && !isAttackable))
     {
         m_LineRenderer.material = m_Materials[1];
         m_LineRenderer.material.SetColor("_TintColor", m_Colors[(int)mode] / 2);
     }
     if (category != TargetCategory.Enemy)
     {
         m_AttackableImage[0].SetActive(false);
         m_AttackableImage[1].SetActive(false);
         return;
     }
     m_AttackableImage[0].SetActive(isAttackable);
     m_AttackableImage[1].SetActive(!isAttackable);
 }
Exemple #5
0
        public bool VerifySpellRange(WorldObject target, TargetCategory targetCategory, Spell spell, uint magicSkill)
        {
            if (targetCategory != TargetCategory.WorldObject || target.Guid == Guid)
            {
                return(true);
            }

            var targetLoc = target;

            if (targetLoc.WielderId != null)
            {
                targetLoc = CurrentLandblock?.GetObject(targetLoc.WielderId.Value);
            }

            float distanceTo = Location.Distance2D(targetLoc.Location);

            if (distanceTo > spell.BaseRangeConstant + magicSkill * spell.BaseRangeMod)
            {
                Session.Network.EnqueueSend(new GameMessageSystemChat($"Target is out of range!", ChatMessageType.Magic));
                SendUseDoneEvent(WeenieError.None);
                return(false);
            }
            return(true);
        }
Exemple #6
0
    //ジャンプ
    private void Jump(Ray ray, RaycastHit hit)
    {
        isFlyable = false;
        bool  jump     = false;
        bool  bodyBlow = false;
        float addLimit = 0;

        //糸を狙うのかどうか
        if (Input.GetKeyUp(KeyCode.K) || Input.GetButtonDown("LB"))
        {
            //m_enemy = null;
            isTargetString = !isTargetString;
            m_AudioSource.PlayOneShot(m_AudioClips[6]);
        }
        if (hit.collider.tag == "Tree")
        {
            var tree = hit.collider.GetComponent <Tree>();
            if (tree.m_SideNumber == m_Shooter.m_SideNumber)
            {
                addLimit = tree.m_TerritoryRate;
            }
        }
        else if (hit.collider.tag == "String")
        {
            var s = hit.collider.GetComponent <StringUnit>();
            addLimit = Vector3.Distance(s.m_PointA, s.m_PointB);
        }

        List <GameObject> jumpable_tree = new List <GameObject>();

        jumpable_tree.Add(m_Enemy);
        foreach (GameObject g in m_trees)
        {
            if (Vector3.Distance(transform.position, g.transform.position) < m_JumpLimit + addLimit &&
                g != m_hitinfo.collider.gameObject)
            {
                jumpable_tree.Add(g);
            }
        }

        if (isTargetString)
        {
            if (!(jump = Physics.Raycast(ray, out jump_target, m_JumpLimit + addLimit, m_NetLayer)))
            {
                jump = Physics.SphereCast(ray, 1f, out jump_target, m_JumpLimit + addLimit, m_StringLayer);
            }
        }
        else
        {
            jump = Physics.Raycast(ray, out jump_target, m_JumpLimit + addLimit, m_TreeLayer);
        }

        if (Input.GetKeyDown(KeyCode.J) || Input.GetButtonDown("RB"))
        {
            m_AudioSource.PlayOneShot(m_AudioClips[5]);
            if (m_jumpableNum == -1)
            {
                m_category = TargetCategory.Enemy;
                m_jumpableNum++;
            }
            else if (jumpable_tree.Count >= m_jumpableNum)
            {
                if (jumpable_tree.Count - 1 == m_jumpableNum)
                {
                    m_category    = TargetCategory.Connecter;
                    m_jumpableNum = -1;
                    m_Prediction.SetActive(false);
                    return;
                }
                else
                {
                    m_category = TargetCategory.JumpableTree;
                    m_jumpableNum++;
                }
            }
        }
        if (Input.GetAxis("Horizontal2") != 0 || Input.GetAxis("Vertical2") != 0)
        {
            m_category    = TargetCategory.Connecter;
            m_jumpableNum = -1;
            m_Prediction.SetActive(false);
            return;
        }
        if (m_category == TargetCategory.Enemy)
        {
            bodyBlow   = true;
            jump       = false;
            m_JumpMode = JumpMode.Bodyblow;
            Vector3 dir = m_Enemy.transform.position - m_center;
            m_CameraPivot.transform.rotation = Quaternion.LookRotation(Vector3.Lerp(m_CameraPivot.transform.forward, dir, 0.1f), Vector3.up);
        }
        else if (m_category == TargetCategory.JumpableTree)
        {
            bodyBlow = false;
            jump     = true;
            if (jumpable_tree.Count > m_jumpableNum)
            {
                Vector3 posY = new Vector3(0, 10f, 0);
                Vector3 dir  = (jumpable_tree[m_jumpableNum].transform.position + posY) - m_center;
                m_CameraPivot.transform.rotation = Quaternion.LookRotation(Vector3.Lerp(m_CameraPivot.transform.forward, dir, 0.1f), Vector3.up);
                Ray   ableRay = new Ray(m_center, dir);
                float dis     = Vector3.Distance(m_center, jumpable_tree[m_jumpableNum].transform.position + posY);
                jump = Physics.Raycast(ableRay, out jump_target, dis, m_TreeLayer);
            }
        }

        if (jump)
        {
            if (hit.collider.gameObject == jump_target.collider.gameObject)
            {
                if (Vector3.Distance(transform.position, jump_target.point) < jumpLower)
                {
                    m_Prediction.SetActive(false);
                    return;
                }
            }
            if (jump_target.transform.tag == "String" || jump_target.transform.tag == "Net")
            {
                if (jump_target.transform.GetComponent <Connecter>().m_SideNumber != m_Shooter.m_SideNumber)
                {
                    return;
                }
            }

            float dis = Vector3.Distance(transform.position, jump_target.point);
            if (dis > m_JumpLimit)
            {
                if (hit.collider.tag == "Tree")
                {
                    m_JumpMode = JumpMode.CapturingJump;
                }
                else if (hit.collider.tag == "String")
                {
                    m_JumpMode = JumpMode.StringJump;
                }
            }
            else
            {
                m_JumpMode = JumpMode.NormalJump;
            }
            //予測線、カーソル表示
            m_Prediction.SetActive(true);
            m_Prediction.SetParameter(transform.position, jump_target.point, m_Angle, m_Shooter.m_SideNumber, m_JumpMode, m_category);
            m_Prediction.Calculation();
            isFlyable = true;
            //ジャンプ
            if (Input.GetKeyDown(KeyCode.Space) || Input.GetButtonDown("Jump"))
            {
                m_WindLine.Play();
                m_AudioSource.PlayOneShot(m_AudioClips[4]);
                m_Prediction.SetActive(false);
                TreeRateMinus();
                move_start = transform.position;
                move_end   = jump_target.point;
                m_Animator.SetTrigger("Jump");
                m_Animator.SetBool("IsJump", true);
                m_escapeInterval = 0;
                isFlyable        = false;
                if (m_hitinfo.collider != jump_target.collider)
                {
                    m_treeWaitTime = 0;
                }
                JumpCalculation(move_start, move_end, m_Angle);
                m_StateManager.StateProcassor.State = m_StateManager.JumpTp;
            }
            return;
        }
        else if (bodyBlow)
        {
            //体当たり
            float len          = Vector3.Distance(m_Enemy.transform.position, m_center);
            var   enemy        = m_Enemy.GetComponent <EnemyAI4>();
            Ray   dirRay       = new Ray(m_center + transform.forward, (m_Enemy.transform.position - m_center));
            bool  isAttackable = len < m_JumpLimit && m_hitinfo.collider.gameObject != enemy.nearObj && !Physics.Raycast(dirRay, len - 1f, m_TreeLayer) && enemy.TreeDist();
            m_Prediction.SetActive(true);
            m_Prediction.SetParameter(transform.position, m_Enemy.transform.position, 1f, m_Shooter.m_SideNumber, JumpMode.NormalJump, m_category, isAttackable);
            m_Prediction.Calculation();
            if (isAttackable && (Input.GetKeyDown(KeyCode.Space) || Input.GetButtonDown("Jump")))
            {
                //体当たり実行
                m_WindLine.Play();
                m_AudioSource.PlayOneShot(m_AudioClips[4]);
                m_Prediction.SetActive(false);
                if (m_hitinfo.collider.tag == "Tree")
                {
                    m_hitinfo.collider.GetComponent <Tree>().m_TerritoryRate -= JumpDemeritRate;
                }
                move_start = transform.position;
                move_end   = m_Enemy.transform.position;
                m_Animator.SetTrigger("Jump");
                m_Animator.SetBool("IsJump", false);
                m_escapeInterval = 0;
                JumpCalculation(move_start, move_end, m_Angle);
                m_StateManager.StateProcassor.State = m_StateManager.BodyBlow;
            }
            return;
        }
        else if (!jump && Physics.Raycast(ray, m_JumpLimit + 100f, m_TreeLayer))
        {
            //届かない場合の予測線描画
            m_Prediction.SetActive(true);
            m_Prediction.SetParameter(
                transform.position,
                m_Camera.position + m_Camera.forward * (m_JumpLimit + addLimit),
                m_Angle, m_Shooter.m_SideNumber, m_JumpMode, TargetCategory.None);
            m_Prediction.Calculation();
            return;
        }
        m_Prediction.SetActive(false);
        m_Prediction.m_HitStringPoint = Vector3.zero;
        //m_enemy = null;
    }
Exemple #7
0
        /// <summary>
        /// Method used for handling player targeted spell casts
        /// </summary>
        public void CreatePlayerSpell(ObjectGuid guidTarget, uint spellId)
        {
            Player         player         = CurrentLandblock.GetObject(Guid) as Player;
            WorldObject    target         = CurrentLandblock.GetObject(guidTarget);
            TargetCategory targetCategory = TargetCategory.WorldObject;

            if (target == null)
            {
                target         = GetWieldedItem(guidTarget);
                targetCategory = TargetCategory.Wielded;
            }
            if (target == null)
            {
                target         = GetInventoryItem(guidTarget);
                targetCategory = TargetCategory.Inventory;
            }
            if (target == null)
            {
                player.Session.Network.EnqueueSend(new GameEventUseDone(player.Session, errorType: WeenieError.TargetNotAcquired));
                targetCategory = TargetCategory.UnDef;
                return;
            }

            SpellTable spellTable = DatManager.PortalDat.SpellTable;

            if (!spellTable.Spells.ContainsKey(spellId))
            {
                player.Session.Network.EnqueueSend(new GameEventUseDone(player.Session, errorType: WeenieError.MagicInvalidSpellType));
                return;
            }

            SpellBase spell = spellTable.Spells[spellId];

            if (IsInvalidTarget(spell, target))
            {
                player.Session.Network.EnqueueSend(new GameEventCommunicationTransientString(player.Session, $"{spell.Name} cannot be cast on {target.Name}."));
                player.Session.Network.EnqueueSend(new GameEventUseDone(player.Session, errorType: WeenieError.None));
                return;
            }

            Database.Models.World.Spell spellStatMod = DatabaseManager.World.GetCachedSpell(spellId);
            if (spellStatMod == null)
            {
                player.Session.Network.EnqueueSend(new GameMessageSystemChat($"{spell.Name} spell not implemented, yet!", ChatMessageType.System));
                player.Session.Network.EnqueueSend(new GameEventUseDone(player.Session, errorType: WeenieError.MagicInvalidSpellType));
                return;
            }

            if (player.IsBusy == true)
            {
                player.Session.Network.EnqueueSend(new GameEventUseDone(player.Session, errorType: WeenieError.YoureTooBusy));
                return;
            }
            else
            {
                player.IsBusy = true;
            }

            uint targetEffect = spell.TargetEffect;

            // Grab player's skill level in the spell's Magic School
            var magicSkill = player.GetCreatureSkill(spell.School).Current;

            if (targetCategory == TargetCategory.WorldObject)
            {
                if (guidTarget != Guid)
                {
                    float distanceTo = Location.Distance2D(target.Location);

                    if (distanceTo > spell.BaseRangeConstant + magicSkill * spell.BaseRangeMod)
                    {
                        player.Session.Network.EnqueueSend(new GameEventUseDone(player.Session, errorType: WeenieError.MagicTargetOutOfRange),
                                                           new GameMessageSystemChat($"{target.Name} is out of range!", ChatMessageType.Magic));
                        player.IsBusy = false;
                        return;
                    }
                }
            }

            // Ensure that a harmful spell isn't being cast on a player target that doesn't have the same PK status
            if (target.WeenieClassId == 1 && player.PlayerKillerStatus != ACE.Entity.Enum.PlayerKillerStatus.NPK)
            {
                bool isSpellHarmful = IsSpellHarmful(spell);
                if (player.PlayerKillerStatus != target.PlayerKillerStatus && isSpellHarmful)
                {
                    player.Session.Network.EnqueueSend(new GameEventUseDone(player.Session, errorType: WeenieError.InvalidPkStatus));
                    player.IsBusy = false;
                    return;
                }
            }

            float scale   = SpellAttributes(player.Session.Account, spellId, out float castingDelay, out MotionCommand windUpMotion, out MotionCommand spellGesture);
            var   formula = SpellTable.GetSpellFormula(spellTable, spellId, player.Session.Account);

            bool spellCastSuccess = false || ((Physics.Common.Random.RollDice(0.0f, 1.0f) > (1.0f - SkillCheck.GetMagicSkillChance((int)magicSkill, (int)spell.Power))) &&
                                              (magicSkill >= (int)spell.Power - 50) && (magicSkill > 0));

            // Calculating mana usage
            #region
            CreatureSkill mc = player.GetCreatureSkill(Skill.ManaConversion);
            double        z  = mc.Current;
            double        baseManaPercent = 1;
            if (z > spell.Power)
            {
                baseManaPercent = spell.Power / z;
            }
            double preCost;
            uint   manaUsed;
            if ((int)Math.Floor(baseManaPercent) == 1)
            {
                preCost  = spell.BaseMana;
                manaUsed = (uint)preCost;
            }
            else
            {
                preCost = spell.BaseMana * baseManaPercent;
                if (preCost < 1)
                {
                    preCost = 1;
                }
                manaUsed = (uint)Physics.Common.Random.RollDice(1, (int)preCost);
            }
            if (spell.MetaSpellType == SpellType.Transfer)
            {
                uint vitalChange, casterVitalChange;
                vitalChange = (uint)(player.GetCurrentCreatureVital((PropertyAttribute2nd)spellStatMod.Source) * spellStatMod.Proportion);
                if (spellStatMod.TransferCap != 0)
                {
                    if (vitalChange > spellStatMod.TransferCap)
                    {
                        vitalChange = (uint)spellStatMod.TransferCap;
                    }
                }
                casterVitalChange = (uint)(vitalChange * (1.0f - spellStatMod.LossPercent));
                vitalChange       = (uint)(casterVitalChange / (1.0f - spellStatMod.LossPercent));

                if (spellStatMod.Source == (int)PropertyAttribute2nd.Mana && (vitalChange + 10 + manaUsed) > player.Mana.Current)
                {
                    ActionChain resourceCheckChain = new ActionChain();

                    resourceCheckChain.AddAction(this, () =>
                    {
                        CurrentLandblock.EnqueueBroadcast(Location, new GameMessageScript(Guid, ACE.Entity.Enum.PlayScript.Fizzle, 0.5f));
                    });

                    resourceCheckChain.AddDelaySeconds(2.0f);
                    resourceCheckChain.AddAction(this, () =>
                    {
                        player.Session.Network.EnqueueSend(new GameEventUseDone(player.Session, errorType: WeenieError.YouDontHaveEnoughManaToCast));
                        player.IsBusy = false;
                    });

                    resourceCheckChain.EnqueueChain();

                    return;
                }
                else if ((vitalChange + 10) > player.GetCurrentCreatureVital((PropertyAttribute2nd)spellStatMod.Source))
                {
                    ActionChain resourceCheckChain = new ActionChain();

                    resourceCheckChain.AddAction(this, () =>
                    {
                        CurrentLandblock.EnqueueBroadcast(Location, new GameMessageScript(Guid, ACE.Entity.Enum.PlayScript.Fizzle, 0.5f));
                    });

                    resourceCheckChain.AddDelaySeconds(2.0f);
                    resourceCheckChain.AddAction(this, () => player.IsBusy = false);
                    resourceCheckChain.EnqueueChain();

                    return;
                }
            }
            else if (manaUsed > player.Mana.Current)
            {
                ActionChain resourceCheckChain = new ActionChain();

                resourceCheckChain.AddAction(this, () =>
                {
                    CurrentLandblock.EnqueueBroadcast(Location, new GameMessageScript(Guid, ACE.Entity.Enum.PlayScript.Fizzle, 0.5f));
                });

                resourceCheckChain.AddDelaySeconds(2.0f);
                resourceCheckChain.AddAction(this, () =>
                {
                    player.Session.Network.EnqueueSend(new GameEventUseDone(player.Session, errorType: WeenieError.YouDontHaveEnoughManaToCast));
                    player.IsBusy = false;
                });

                resourceCheckChain.EnqueueChain();

                return;
            }
            else
            {
                player.UpdateVital(player.Mana, player.Mana.Current - manaUsed);
            }
            #endregion

            ActionChain spellChain = new ActionChain();

            uint fastCast = (spell.Bitfield >> 14) & 0x1u;
            if (fastCast != 1)
            {
                spellChain.AddAction(this, () =>
                {
                    var motionWindUp = new UniversalMotion(MotionStance.Spellcasting);
                    motionWindUp.MovementData.CurrentStyle   = (ushort)((uint)MotionStance.Spellcasting & 0xFFFF);
                    motionWindUp.MovementData.ForwardCommand = (uint)windUpMotion;
                    motionWindUp.MovementData.ForwardSpeed   = 2;
                    DoMotion(motionWindUp);
                });
            }

            spellChain.AddAction(this, () =>
            {
                CurrentLandblock.EnqueueBroadcast(Location, new GameMessageCreatureMessage(SpellComponentsTable.GetSpellWords(DatManager.PortalDat.SpellComponentsTable,
                                                                                                                              formula), Name, Guid.Full, ChatMessageType.Magic));
            });

            spellChain.AddAction(this, () =>
            {
                var motionCastSpell = new UniversalMotion(MotionStance.Spellcasting);
                motionCastSpell.MovementData.CurrentStyle   = (ushort)((uint)MotionStance.Spellcasting & 0xFFFF);
                motionCastSpell.MovementData.ForwardCommand = (uint)spellGesture;
                motionCastSpell.MovementData.ForwardSpeed   = 2;
                DoMotion(motionCastSpell);
            });

            if (fastCast == 1)
            {
                spellChain.AddDelaySeconds(castingDelay * 0.26f);
            }
            else
            {
                spellChain.AddDelaySeconds(castingDelay);
            }

            if (spellCastSuccess == false)
            {
                spellChain.AddAction(this, () => CurrentLandblock.EnqueueBroadcast(Location, new GameMessageScript(Guid, ACE.Entity.Enum.PlayScript.Fizzle, 0.5f)));
            }
            else
            {
                spellChain.AddAction(this, () =>
                {
                    bool targetDeath;
                    string message;

                    switch (spell.School)
                    {
                    case MagicSchool.WarMagic:
                        WarMagic(target, spell, spellStatMod);
                        break;

                    case MagicSchool.VoidMagic:
                        VoidMagic(target, spell, spellStatMod);
                        break;

                    case MagicSchool.CreatureEnchantment:
                        if (IsSpellHarmful(spell))
                        {
                            // Retrieve player's skill level in the Magic School
                            var playerMagicSkill = player.GetCreatureSkill(spell.School).Current;

                            // Retrieve target's Magic Defense Skill
                            Creature creature           = (Creature)target;
                            var targetMagicDefenseSkill = creature.GetCreatureSkill(Skill.MagicDefense).Current;

                            if (MagicDefenseCheck(playerMagicSkill, targetMagicDefenseSkill))
                            {
                                CurrentLandblock.EnqueueBroadcastSound(player, Sound.ResistSpell);
                                player.Session.Network.EnqueueSend(new GameMessageSystemChat($"{creature.Name} resists {spell.Name}", ChatMessageType.Magic));
                                break;
                            }
                        }
                        CurrentLandblock.EnqueueBroadcast(Location, new GameMessageScript(target.Guid, (PlayScript)spell.TargetEffect, scale));
                        message = CreatureMagic(target, spell, spellStatMod);
                        if (message != "")
                        {
                            player.Session.Network.EnqueueSend(new GameMessageSystemChat(message, ChatMessageType.Magic));
                        }
                        break;

                    case MagicSchool.LifeMagic:
                        if (spell.MetaSpellType != SpellType.LifeProjectile)
                        {
                            if (IsSpellHarmful(spell))
                            {
                                // Retrieve player's skill level in the Magic School
                                var playerMagicSkill = player.GetCreatureSkill(spell.School).Current;

                                // Retrieve target's Magic Defense Skill
                                Creature creature           = (Creature)target;
                                var targetMagicDefenseSkill = creature.GetCreatureSkill(Skill.MagicDefense).Current;

                                if (MagicDefenseCheck(playerMagicSkill, targetMagicDefenseSkill))
                                {
                                    CurrentLandblock.EnqueueBroadcastSound(player, Sound.ResistSpell);
                                    player.Session.Network.EnqueueSend(new GameMessageSystemChat($"{creature.Name} resists {spell.Name}", ChatMessageType.Magic));
                                    break;
                                }
                            }
                        }
                        CurrentLandblock.EnqueueBroadcast(Location, new GameMessageScript(target.Guid, (PlayScript)spell.TargetEffect, scale));
                        targetDeath = LifeMagic(target, spell, spellStatMod, out message);
                        if (message != null)
                        {
                            player.Session.Network.EnqueueSend(new GameMessageSystemChat(message, ChatMessageType.Magic));
                        }
                        if (targetDeath == true)
                        {
                            Creature creatureTarget = (Creature)target;
                            creatureTarget.Die();
                            Strings.DeathMessages.TryGetValue(DamageType.Base, out var messages);
                            player.Session.Network.EnqueueSend(new GameMessageSystemChat(string.Format(messages[0], target.Name), ChatMessageType.Broadcast));
                            player.EarnXP((long)target.XpOverride);
                        }
                        break;

                    case MagicSchool.ItemEnchantment:
                        if (guidTarget == Guid)
                        {
                            CurrentLandblock.EnqueueBroadcast(Location, new GameMessageScript(Guid, (PlayScript)spell.CasterEffect, scale));
                        }
                        else
                        {
                            CurrentLandblock.EnqueueBroadcast(Location, new GameMessageScript(target.Guid, (PlayScript)spell.TargetEffect, scale));
                        }
                        message = ItemMagic(target, spell, spellStatMod);
                        if (message != "")
                        {
                            player.Session.Network.EnqueueSend(new GameMessageSystemChat(message, ChatMessageType.Magic));
                        }
                        break;

                    default:
                        break;
                    }
                });
            }

            spellChain.AddAction(this, () =>
            {
                var motionReturnToCastStance = new UniversalMotion(MotionStance.Spellcasting);
                motionReturnToCastStance.MovementData.CurrentStyle   = (ushort)((uint)MotionStance.Spellcasting & 0xFFFF);
                motionReturnToCastStance.MovementData.ForwardCommand = (uint)MotionCommand.Invalid;
                DoMotion(motionReturnToCastStance);
            });

            spellChain.AddDelaySeconds(1.0f);

            spellChain.AddAction(this, () =>
            {
                player.Session.Network.EnqueueSend(new GameEventUseDone(player.Session, errorType: WeenieError.None));
                player.IsBusy = false;
            });

            spellChain.EnqueueChain();

            return;
        }
Exemple #8
0
        /// <summary>
        /// Method used for handling player targeted spell casts
        /// </summary>
        /// <param name="builtInSpell">If TRUE, casting a built-in spell from a weapon</param>
        public void CreatePlayerSpell(WorldObject target, TargetCategory targetCategory, uint spellId, bool builtInSpell = false)
        {
            var creatureTarget = target as Creature;

            if (!VerifyBusy())
            {
                return;
            }

            var spell = ValidateSpell(spellId, builtInSpell);

            if (spell == null)
            {
                return;
            }

            if (!VerifySpellTarget(spell, target))
            {
                return;
            }

            // if casting implement has spell built in,
            // use spellcraft from the item, instead of player's magic skill?
            var caster        = GetEquippedWand();
            var isWeaponSpell = builtInSpell && IsWeaponSpell(spell.Id);

            // Grab player's skill level in the spell's Magic School
            var magicSkill = GetCreatureSkill(spell.School).Current;

            if (isWeaponSpell && caster.ItemSpellcraft != null)
            {
                magicSkill = (uint)caster.ItemSpellcraft;
            }

            // verify spell range
            if (!VerifySpellRange(target, targetCategory, spell, magicSkill))
            {
                return;
            }

            // get casting pre-check status
            var castingPreCheckStatus = GetCastingPreCheckStatus(spell, magicSkill, isWeaponSpell);

            // calculate mana usage
            if (!CalculateManaUsage(castingPreCheckStatus, spell, target, isWeaponSpell, out var manaUsed))
            {
                return;
            }

            // spell words
            DoSpellWords(spell, isWeaponSpell);

            // begin spellcasting
            MagicState.OnCastStart();

            var spellChain = new ActionChain();

            StartPos = new Position(Location);

            // do wind-up gestures: fastcast has no windup (creature enchantments)
            DoWindupGestures(spell, isWeaponSpell, spellChain);

            // cast spell
            DoCastGesture(spell, isWeaponSpell, spellChain);

            MagicState.SetCastParams(spell, isWeaponSpell, magicSkill, manaUsed, target, castingPreCheckStatus);
            spellChain.AddAction(this, () => DoCastSpell(MagicState));

            spellChain.EnqueueChain();
        }
Exemple #9
0
        /// <summary>
        /// Method used for handling player targeted spell casts
        /// </summary>
        public void CreatePlayerSpell(WorldObject target, TargetCategory targetCategory, uint spellId)
        {
            var player         = this;
            var creatureTarget = target as Creature;

            if (player.IsBusy == true)
            {
                player.Session.Network.EnqueueSend(new GameEventUseDone(player.Session, WeenieError.YoureTooBusy));
                return;
            }
            player.IsBusy = true;

            var spell = new Spell(spellId);

            if (spell.NotFound)
            {
                if (spell._spellBase == null)
                {
                    Session.Network.EnqueueSend(new GameEventCommunicationTransientString(Session, $"SpellId {spellId} Invalid."));
                    Session.Network.EnqueueSend(new GameEventUseDone(Session, WeenieError.None));
                }
                else
                {
                    Session.Network.EnqueueSend(new GameMessageSystemChat($"{spell.Name} spell not implemented, yet!", ChatMessageType.System));
                    Session.Network.EnqueueSend(new GameEventUseDone(Session, WeenieError.MagicInvalidSpellType));
                }

                player.IsBusy = false;
                return;
            }

            if (IsInvalidTarget(spell, target))
            {
                player.Session.Network.EnqueueSend(new GameEventCommunicationTransientString(player.Session, $"{spell.Name} cannot be cast on {target.Name}."));
                player.Session.Network.EnqueueSend(new GameEventUseDone(player.Session, WeenieError.None));
                player.IsBusy = false;
                return;
            }

            // if casting implement has spell built in,
            // use spellcraft from the item, instead of player's magic skill?
            var caster        = GetEquippedWand();
            var isWeaponSpell = IsWeaponSpell(spell);

            // Grab player's skill level in the spell's Magic School
            var magicSkill = player.GetCreatureSkill(spell.School).Current;

            if (isWeaponSpell && caster.ItemSpellcraft != null)
            {
                magicSkill = (uint)caster.ItemSpellcraft;
            }

            if (targetCategory == TargetCategory.WorldObject)
            {
                if (target.Guid != Guid)
                {
                    var targetLoc = target;
                    if (targetLoc.WielderId != null)
                    {
                        targetLoc = CurrentLandblock?.GetObject(targetLoc.WielderId.Value);
                    }

                    float distanceTo = Location.Distance2D(targetLoc.Location);

                    if (distanceTo > spell.BaseRangeConstant + magicSkill * spell.BaseRangeMod)
                    {
                        player.Session.Network.EnqueueSend(new GameEventUseDone(player.Session, WeenieError.None),
                                                           new GameMessageSystemChat($"Target is out of range!", ChatMessageType.Magic));
                        player.IsBusy = false;
                        return;
                    }
                }
            }

            var difficulty = spell.Power;

            // is this needed? should talismans remain the same, regardless of player spell formula?
            spell.Formula.GetPlayerFormula(player);

            var castingPreCheckStatus = CastingPreCheckStatus.CastFailed;

            if (magicSkill > 0 && magicSkill >= (int)difficulty - 50)
            {
                var chance = 1.0f - SkillCheck.GetMagicSkillChance((int)magicSkill, (int)difficulty);
                var rng    = ThreadSafeRandom.Next(0.0f, 1.0f);
                if (chance < rng || isWeaponSpell)
                {
                    castingPreCheckStatus = CastingPreCheckStatus.Success;
                }
            }

            // limit casting time between war and void
            if (spell.School == MagicSchool.VoidMagic && LastSuccessCast_School == MagicSchool.WarMagic ||
                spell.School == MagicSchool.WarMagic && LastSuccessCast_School == MagicSchool.VoidMagic)
            {
                // roll each time?
                var timeLimit = ThreadSafeRandom.Next(3.0f, 5.0f);

                if (Time.GetUnixTime() - LastSuccessCast_Time < timeLimit)
                {
                    var curType  = spell.School == MagicSchool.WarMagic ? "War" : "Void";
                    var prevType = LastSuccessCast_School == MagicSchool.VoidMagic ? "Nether" : "Elemental";

                    Session.Network.EnqueueSend(new GameMessageSystemChat($"The {prevType} energies permeating your blood cause this {curType} magic to fail.", ChatMessageType.Magic));

                    castingPreCheckStatus = CastingPreCheckStatus.CastFailed;
                }
            }

            // Calculate mana usage
            uint manaUsed = CalculateManaUsage(player, spell, target);

            var currentMana = player.Mana.Current;

            if (isWeaponSpell)
            {
                currentMana = (uint)(caster.ItemCurMana ?? 0);
            }

            if (manaUsed > currentMana)
            {
                player.Session.Network.EnqueueSend(new GameEventUseDone(player.Session, WeenieError.YouDontHaveEnoughManaToCast));
                IsBusy = false; // delay?
                return;
            }

            // begin spellcasting
            Proficiency.OnSuccessUse(player, player.GetCreatureSkill(Skill.ManaConversion), spell.PowerMod);

            if (!isWeaponSpell)
            {
                player.UpdateVitalDelta(player.Mana, -(int)manaUsed);
            }
            else
            {
                caster.ItemCurMana -= (int)manaUsed;
            }

            spell.Formula.GetPlayerFormula(player);

            string spellWords = spell._spellBase.GetSpellWords(DatManager.PortalDat.SpellComponentsTable);

            if (spellWords != null && !isWeaponSpell)
            {
                EnqueueBroadcast(new GameMessageCreatureMessage(spellWords, Name, Guid.Full, ChatMessageType.Spellcasting));
            }

            var spellChain = new ActionChain();
            var castSpeed  = 2.0f;  // hardcoded for player spell casting?

            var startPos = new Position(Location);

            // do wind-up gestures: fastcast has no windup (creature enchantments)
            if (!spell.Flags.HasFlag(SpellFlags.FastCast) && !isWeaponSpell)
            {
                // note that ACE is currently sending the windup motion and the casting gesture
                // at the same time. the client is automatically queueing these animations to run at the correct time.

                foreach (var windupGesture in spell.Formula.WindupGestures)
                {
                    spellChain.AddAction(this, () =>
                    {
                        var motionWindUp = new Motion(MotionStance.Magic, windupGesture, castSpeed);
                        EnqueueBroadcastMotion(motionWindUp);
                    });
                }
            }

            // cast spell
            spellChain.AddAction(this, () =>
            {
                var castGesture = spell.Formula.CastGesture;
                if (isWeaponSpell && caster.UseUserAnimation != 0)
                {
                    castGesture = caster.UseUserAnimation;
                }

                var motionCastSpell = new Motion(MotionStance.Magic, castGesture, castSpeed);
                EnqueueBroadcastMotion(motionCastSpell);
            });

            var castingDelay = spell.Formula.GetCastTime(MotionTableId, castSpeed, isWeaponSpell);

            spellChain.AddDelaySeconds(castingDelay);

            bool movedTooFar = false;

            spellChain.AddAction(this, () =>
            {
                if (!isWeaponSpell)
                {
                    TryBurnComponents(spell);
                }

                // check windup move distance cap
                var endPos = new Position(Location);
                var dist   = startPos.DistanceTo(endPos);

                if (dist > Windup_MaxMove)
                {
                    castingPreCheckStatus = CastingPreCheckStatus.CastFailed;
                    movedTooFar           = true;
                }

                var pk_error = CheckPKStatusVsTarget(player, target, spell);
                if (pk_error != null)
                {
                    castingPreCheckStatus = CastingPreCheckStatus.InvalidPKStatus;
                }

                var useDone = WeenieError.None;

                switch (castingPreCheckStatus)
                {
                case CastingPreCheckStatus.Success:

                    if ((spell.Flags & SpellFlags.FellowshipSpell) == 0)
                    {
                        CreatePlayerSpell(target, spell);
                    }
                    else
                    {
                        var fellows = GetFellowshipTargets();
                        foreach (var fellow in fellows)
                        {
                            CreatePlayerSpell(fellow, spell);
                        }
                    }
                    break;

                case CastingPreCheckStatus.InvalidPKStatus:

                    if (spell.NumProjectiles > 0)
                    {
                        switch (spell.School)
                        {
                        case MagicSchool.WarMagic:
                            WarMagic(target, spell);
                            break;

                        case MagicSchool.VoidMagic:
                            VoidMagic(target, spell);
                            break;

                        case MagicSchool.LifeMagic:
                            LifeMagic(target, spell, out uint damage, out bool critical, out var enchantmentStatus);
                            break;
                        }