public bool QuestV2RunEvent(QUEST_HELPER pQuestHelper, int nEventID)
        {
            // Lookup the corresponding NPC.
            if (pQuestHelper.strLuaFilename == "01_main.lua" ||
                pQuestHelper.strLuaFilename == "1_main.lua")
            {
                m_sEventNid = 10000;
            }

            Npc  pNpc   = g_pMain.GetNpcPtr(m_sEventNid);
            bool result = false;

            if (pNpc == null || pNpc.isDead())
            {
                return(false);
            }

            m_nQuestHelperID = pQuestHelper.nIndex;
            using (Engine luaEngine = new Engine())
            {
                luaEngine.ExecuteScript(this, pNpc, nEventID, bSelectedReward, pQuestHelper.strLuaFilename);
            }

            return(true);
        }
Exemple #2
0
        public short GetDamage(Npc pTarget /* , _MAGIC_TABLE *pSkill = nullptr, bool bPreviewOnly = false*/)
        {
            if (pTarget == null)
            {
                return(-1);
            }

            int  damage = 0;
            int  random = 0;
            int  temp_hit = 0, temp_ac = 0, temp_ap = 0, temp_hit_B = 0;
            byte result;

            if (pTarget == null || pTarget.isDead())
            {
                return(-1);
            }

            temp_ac = pTarget.m_sTotalAc;
            // A unit's total AC shouldn't ever go below 0.
            if ((pTarget.m_sACAmount) <= 0)
            {
                pTarget.m_sACAmount = 0;
            }
            else
            {
                temp_ac += pTarget.m_sACAmount;
            }

            if (pTarget.m_sACPercent > 0 && pTarget.m_sACPercent < 100)
            {
                temp_ac -= temp_ac * (100 - pTarget.m_sACPercent) / 100;
            }

            temp_ap = m_sTotalHit * m_bAttackAmount;

            temp_hit_B = (int)((temp_ap * 200 / 100) / (temp_ac + 240));

            temp_hit = temp_ap / 100;
            result   = GetHitRate(m_fTotalHitrate / pTarget.m_fTotalEvasionrate);

            short Hit = (short)m_sTotalHit, Ac = pTarget.m_sTotalAc;

            result = GetHitRate(m_fTotalHitrate / pTarget.m_fTotalEvasionrate);

            switch (result)
            {
            case GREAT_SUCCESS:
            case SUCCESS:
            case NORMAL:    /*
                             * if (pSkill != nullptr)
                             * {
                             * // Skill Hit.
                             * damage = temp_hit;
                             * random = myrand(0, damage);
                             * if (pSkill->bType[0] == 1)
                             * damage = (short)((temp_hit + 0.3f * random) + 0.99f);
                             * else
                             * damage = (short)(((temp_hit * 0.6f) + 1.0f * random) + 0.99f);
                             * }
                             * else
                             * {   // Normal Hit.
                             */
                if (isGM()) //&& !pTarget->isPlayer()/)
                {
                    //if (g_pMain->m_nGameMasterRHitDamage != 0)
                    // {
                    damage = MAX_DAMAGE;
                    return((short)damage);
                    // }
                }

                damage = temp_hit_B;
                random = myrand(0, damage);
                damage = (short)((0.85f * temp_hit_B) + 0.3f * random);
                break;

            case FAIL:
                //if (pSkill != nullptr)
                //{    // Skill Hit.
                //
                //}
                //else
                //{ // Normal Hit.
                if (isGM())
                {
                    damage = MAX_DAMAGE;
                    return((short)damage);
                }
                // }
                break;
            }

            //   damage = GetMagicDamage(damage, pTarget, bPreviewOnly);

            if (damage > MAX_DAMAGE)
            {
                damage = MAX_DAMAGE;
            }

            return((short)damage);
        }
Exemple #3
0
        public void Attack(Packet pkt)
        {
            byte  bType = pkt, bResult = pkt;
            short tid = pkt, sid = -1, damage, delaytime = pkt, distance = pkt;

            RemoveStealth();

            if (tid >= Headers.GameDefine.NPC_BAND)
            {
                Npc pTarget = g_pMain.m_NpcList.Where(i => i.Key == tid).Select(i => i.Value).FirstOrDefault();
                if (pTarget == null)
                {
                    return;
                }

                if (isAttackable(pTarget) && CanCastRHit())
                {
                    /*
                     * if (isInTempleEventZone() &&
                     *                  (!isSameEventRoom(pTarget)
                     || !g_pMain->pTempleEvent.isAttackable[GetEventRoom()]
                     ||                 && isEventUser()))
                     ||                 return;
                     ||
                     ||         if (isInTempleQuestEventZone() &&
                     ||                 (!isSameEventRoom(pTarget)
                     || !g_pMain->pQuestEvent.isAttackable
                     ||                 && isQuestEventUser()))
                     ||                 return;
                     ||
                     ||         if (pTarget->isPlayer() && pTarget->hasBuff(BUFF_TYPE_FREEZE))
                     ||                 return;*/

                    damage = GetDamage(pTarget);

                    if (GetZoneID() == ZONE_SNOW_BATTLE /*&& g_pMain->m_byBattleOpen == SNOW_BATTLE*/)
                    {
                        damage = 0;
                    }
                    else if (GetZoneID() == ZONE_PRISON)
                    {
                        if (m_sMp < (m_iMaxMp / 5))
                        {
                            return;
                        }

                        damage = 1;
                        MSpChange(-(m_iMaxMp / 5));
                    }

                    switch (pTarget.m_tNpcType)
                    {
                    case NPC_FOSIL:
                        damage = 1;
                        break;

                    case NPC_TREE:
                        damage = 20;
                        break;

                    case NPC_REFUGEE:
                        damage = 10;
                        break;

                    case NPC_PARTNER_TYPE:
                        return;
                    }

                    if (damage > 0)
                    {
                        pTarget.HpChange(-damage, this);
                        if (pTarget.isDead())
                        {
                            bResult = ATTACK_TARGET_DEAD;
                        }
                        else
                        {
                            bResult = ATTACK_SUCCESS;
                        }

                        // Every attack takes a little of your weapon's durability.
                        //ItemWoreOut(ATTACK, damage);

                        // Every hit takes a little of the defender's armour durability.
                        //if (pTarget->isPlayer())
                        //    TO_USER(pTarget)->ItemWoreOut(DEFENCE, damage);
                    }
                }
            }

            Packet result = new Packet(WIZ.ATTACK, bType);

            result = result + bResult + GetSocketID() + tid;
            SendToRegion(result);
        }