Beispiel #1
0
        internal static Msg_RC_CreateNpc BuildCreateNpcMessage(NpcInfo npc)
        {
            Msg_RC_CreateNpc bder = new Msg_RC_CreateNpc();

            bder.npc_id  = npc.GetId();
            bder.unit_id = npc.GetUnitId();
            Vector3 pos = npc.GetMovementStateInfo().GetPosition3D();

            ArkCrossEngineMessage.Position pos_bd = new ArkCrossEngineMessage.Position();
            pos_bd.x            = (float)pos.X;
            pos_bd.z            = (float)pos.Z;
            bder.cur_pos        = pos_bd;
            bder.face_direction = (float)npc.GetMovementStateInfo().GetFaceDir();
            bder.link_id        = npc.GetLinkId();
            if (npc.GetUnitId() <= 0)
            {
                bder.camp_id = npc.GetCampId();
            }
            if (npc.OwnerId > 0)
            {
                bder.owner_id = npc.OwnerId;
            }
            bder.level = npc.GetLevel();
            return(bder);
        }
Beispiel #2
0
        private void CalcKillIncome(NpcInfo npc)
        {
            if (null == npc)
            {
                return;
            }
            UpdateKillCount(npc);
            //死亡掉落
            UserInfo userKiller = UserManager.GetUserInfo(npc.KillerId);

            if (null != userKiller && m_DropMoneyData.ContainsKey(npc.GetUnitId()) && m_DropMoneyData[npc.GetUnitId()] > 0)
            {
                DelayActionProcessor.QueueAction(DropNpc,
                                                 0,
                                                 npc.GetId(),
                                                 DropOutType.GOLD,
                                                 m_SceneDropOut.m_GoldModel,
                                                 m_SceneDropOut.m_GoldParticle,
                                                 m_DropMoneyData[npc.GetUnitId()]);
            }
        }
        private void OnImpactDamage(CharacterInfo entity, int attackerId, int damage, bool isKiller, bool isCritical, bool isOrdinary)
        {
            if (null != entity)
            {
                Msg_RC_ImpactDamage bd = new Msg_RC_ImpactDamage();
                bd.role_id     = entity.GetId();
                bd.attacker_id = attackerId;
                bd.is_killer   = isKiller;
                bd.is_critical = isCritical;
                bd.is_ordinary = isOrdinary;
                bd.hp          = damage;

                Scene scene = entity.SceneContext.CustomData as Scene;
                if (null != scene)
                {
                    if (entity.IsHaveStoryFlag(StoryListenFlagEnum.Damage))
                    {
                        scene.StorySystem.SendMessage("objdamage", entity.GetId(), attackerId, damage, 0, isCritical ? 1 : 0);
                        NpcInfo npc = entity as NpcInfo;
                        if (null != npc)
                        {
                            scene.StorySystem.SendMessage("npcdamage:" + npc.GetUnitId(), entity.GetId(), attackerId, damage, 0, isCritical ? 1 : 0);
                        }
                    }

                    int estimateDamage = damage;
                    if (isCritical)
                    {
                        estimateDamage /= 2;
                    }
                    if (entity.Hp + estimateDamage <= 0)
                    {
                        scene.TryFireFinalBlow(entity);
                    }
                }

                for (LinkedListNode <UserInfo> linkNode = entity.UserManager.Users.FirstValue; null != linkNode; linkNode = linkNode.Next)
                {
                    UserInfo info = linkNode.Value;
                    if (null != info && null != info.CustomData)
                    {
                        User u = info.CustomData as User;
                        if (null != u)
                        {
                            u.SendMessage(bd);
                        }
                    }
                }
                entity.SetAttackerInfo(attackerId, 0, isKiller, isOrdinary, isCritical, damage, 0);
            }
        }
Beispiel #4
0
        public NpcInfo GetNpcInfoByUnitId(int id)
        {
            NpcInfo npc = null;

            for (LinkedListNode <NpcInfo> linkNode = m_Npcs.FirstValue; null != linkNode; linkNode = linkNode.Next)
            {
                NpcInfo info = linkNode.Value;
                if (info.GetUnitId() == id)
                {
                    npc = info;
                    break;
                }
            }
            return(npc);
        }
Beispiel #5
0
        private void TickNpcs()
        {
            List <NpcInfo> deletes = new List <NpcInfo>();

            for (LinkedListNode <NpcInfo> linkNode = m_NpcMgr.Npcs.FirstValue; null != linkNode; linkNode = linkNode.Next)
            {
                NpcInfo info = linkNode.Value;
                if (info.LevelChanged || info.GetShootStateInfo().WeaponChanged || info.GetSkillStateInfo().BuffChanged || info.GetEquipmentStateInfo().EquipmentChanged)
                {
                    NpcAttrCalculator.Calc(info);
                    info.LevelChanged = false;
                    info.GetShootStateInfo().WeaponChanged        = false;
                    info.GetSkillStateInfo().BuffChanged          = false;
                    info.GetEquipmentStateInfo().EquipmentChanged = false;
                }

                // 约定npc的高度低于140时,直接判定npc死亡。
                if (140.0f > info.GetMovementStateInfo().GetPosition3D().Y)
                {
                    info.SetHp(Operate_Type.OT_Absolute, 0);
                }
                if (info.NeedDelete)
                {
                    deletes.Add(info);
                }
                else if (info.Hp <= 0)
                {
                    if (!info.LogicDead)
                    {
                        GfxSystem.PublishGfxEvent("ge_on_npc_dead", "story", info.GetUnitId());
                        info.LogicDead = true;
                    }
                    if (info.DeadTime <= 0)
                    {
                    }
                    else if (TimeUtility.GetServerMilliseconds() - info.DeadTime > info.ReleaseTime)
                    {
                        deletes.Add(info);
                    }
                }
                if (info.IsBorning && IsNpcBornOver(info))
                {
                    info.IsBorning = false;
                    info.SetAIEnable(true);
                    info.SetStateFlag(Operate_Type.OT_RemoveBit, CharacterState_Type.CST_Invincible);
                }
            }
            if (deletes.Count > 0)
            {
                foreach (NpcInfo ni in deletes)
                {
                    CharacterView view = EntityManager.Instance.GetCharacterViewById(ni.GetId());
                    if (null != view)
                    {
                        GfxSystem.SendMessage(view.Actor, "OnDead", null);
                    }
                    EntityManager.Instance.DestroyNpcView(ni.GetId());
                    WorldSystem.Instance.DestroyCharacterById(ni.GetId());
                    return;
                }
            }
        }
        private void TickNpcs()
        {
            List <NpcInfo> deletes        = new List <NpcInfo>();
            List <NpcInfo> deletes2       = new List <NpcInfo>();
            Msg_RC_NpcDead npcDeadBuilder = new Msg_RC_NpcDead();

            for (LinkedListNode <NpcInfo> linkNode = NpcManager.Npcs.FirstValue; null != linkNode; linkNode = linkNode.Next)
            {
                NpcInfo info = linkNode.Value;
                if (info.LevelChanged || info.GetSkillStateInfo().BuffChanged || info.GetEquipmentStateInfo().EquipmentChanged || info.GetLegacyStateInfo().LegacyChanged)
                {
                    NpcAttrCalculator.Calc(info);
                    info.LevelChanged = false;
                    info.GetSkillStateInfo().BuffChanged          = false;
                    info.GetEquipmentStateInfo().EquipmentChanged = false;
                    info.GetLegacyStateInfo().LegacyChanged       = false;
                }
                // 伙伴自动掉血
                if ((int)NpcTypeEnum.Partner == info.NpcType)
                {
                    UserInfo owner = UserManager.GetUserInfo(info.OwnerId);
                    if (null != owner)
                    {
                        PartnerInfo pi = owner.GetPartnerInfo();
                        if (null != pi && TimeUtility.GetServerMilliseconds() - pi.LastTickTime > pi.TickInterval)
                        {
                            info.SetHp(Operate_Type.OT_Relative, (int)pi.GetHpCostPerTick(info.GetActualProperty().HpMax));
                            pi.LastTickTime = TimeUtility.GetServerMilliseconds();
                        }
                    }
                }
                if (info.NeedDelete)
                {
                    deletes2.Add(info);
                }
                else if (info.IsDead())
                {
                    if (info.DeadTime <= 0)
                    {
                        info.DeadTime = TimeUtility.GetServerMilliseconds();
                        //击杀收益计算
                        CalcKillIncome(info);
                        //解除控制
                        ReleaseControl(info);
                        //发送npc死亡消息
                        npcDeadBuilder.npc_id = info.GetId();
                        NotifyAllUser(npcDeadBuilder);

                        if (info.IsCombatNpc())
                        {
                            m_StorySystem.SendMessage("objkilled", info.GetId(), GetBattleNpcCount());
                            m_StorySystem.SendMessage(string.Format("npckilled:{0}", info.GetUnitId()), info.GetId(), GetBattleNpcCount());
                            if (info.GetUnitId() > 0)
                            {
                                if (m_IsAttemptScene)
                                {
                                    if ((int)NpcTypeEnum.BigBoss == info.NpcType)
                                    {
                                        TryFireAllNpcKilled();
                                    }
                                }
                                else
                                {
                                    TryFireAllNpcKilled();
                                }
                            }
                        }
                    }
                    else if (TimeUtility.GetServerMilliseconds() - info.DeadTime > info.ReleaseTime && info.GfxDead)
                    {
                        deletes.Add(info);
                    }
                }
                if (info.IsBorning && IsNpcBornOver(info))
                {
                    info.IsBorning = false;
                    info.SetAIEnable(true);
                    info.SetStateFlag(Operate_Type.OT_RemoveBit, CharacterState_Type.CST_Invincible);
                }
                CheckNpcOwnerId(info);
            }
            if (deletes.Count > 0)
            {
                Msg_RC_DestroyNpc destroyNpcBuilder = new Msg_RC_DestroyNpc();
                foreach (NpcInfo ni in deletes)
                {
                    //发送npc消失消息
                    destroyNpcBuilder.npc_id           = ni.GetId();
                    destroyNpcBuilder.need_play_effect = true;
                    NotifyAllUser(destroyNpcBuilder);
                    //删除npc
                    NpcManager.RemoveNpc(ni.GetId());
                    LogSystem.Debug("Npc {0}  name {1} is deleted.", ni.GetId(), ni.GetName());
                }
            }
            if (deletes2.Count > 0)
            {
                Msg_RC_DestroyNpc destroyNpcBuilder = new Msg_RC_DestroyNpc();
                foreach (NpcInfo ni in deletes2)
                {
                    //发送npc消失消息
                    destroyNpcBuilder.npc_id           = ni.GetId();
                    destroyNpcBuilder.need_play_effect = false;
                    NotifyAllUser(destroyNpcBuilder);
                    //删除npc
                    NpcManager.RemoveNpc(ni.GetId());
                    LogSystem.Debug("Npc {0}  name {1} is deleted.", ni.GetId(), ni.GetName());
                }
            }
            NpcManager.ExecuteDelayAdd();
        }