Пример #1
0
 public static void CallAIProcessSub(string aiType, int tickCount, int mapNum, int mapNpcSlot)
 {
     if (aiType != null && script != null && NPCAIType.ContainsKey(aiType))
     {
         string className = NPCAIType.GetValue(aiType);
         InvokeAISub(className, "ProcessAI", tickCount, mapNum, mapNpcSlot);
     }
 }
Пример #2
0
 public static void CreateAIInstance(string className, string aiType)
 {
     if (script != null)
     {
         if (NPCAIType.ContainsKey(aiType) == false)
         {
             Type    type     = script.GetType(className);
             IAICore instance = (IAICore)script.CreateInstance(className);
             AITypes.Add(className, type);
             AIInstances.Add(className, instance);
             NPCAIType.Add(aiType, className);
             //InvokeSub(className, "Init", Globals.mNetScript, Globals.mObjFactory, Globals.mIOTools, Globals.mDebug);
         }
     }
 }
Пример #3
0
        public static void PopulateAIList()
        {
            AITypes.Clear();
            AIInstances.Clear();
            NPCAIType.Clear();
            Type ti = typeof(IAICore);

            if (script != null)
            {
                foreach (Type t in script.GetTypes())
                {
                    if (ti.IsAssignableFrom(t) && t.IsPublic)
                    {
                        CreateAIInstance(t.FullName, t.Name);
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// 释放技能效果
        /// </summary>
        /// <param name="src">效果发起者</param>
        /// <param name="skTarget">技能选择的目标</param>
        /// <param name="target">技能先选择目标后,再次Effect选择后的目标</param>
        /// <param name="skDirectHurt">是否是技能的直接伤害</param>
        /// <param name="container">所有数据展现的容器,本次Effect施法的效果会依次加入</param>
        public void Cast(ServerNPC src, IEnumerable <ServerNPC> skTarget, IEnumerable <ServerNPC> target, bool skDirectHurt, List <MsgParam> container)
        {
                        #if DEBUG
            Utils.Assert(cfg == null, "Effect Configure is null in SwitchNpcEffect.");
                        #endif

            int       SwitchToId = cfg.Param1;
            UVec3     Locale     = src.transform.position;
            NPCAIType AI         = (NPCAIType)Enum.ToObject(typeof(NPCAIType), cfg.Param2);

            //数据源
            CtorNpcSource datasrc  = (CtorNpcSource)Enum.ToObject(typeof(CtorNpcSource), cfg.Param3);
            int           chargeOf = cfg.Param4;
            float         duration = cfg.Param5 * Consts.OneThousand;

            //参数10,是否继承普通攻击
            bool inheritNorAtk = cfg.Param10 == 0;

            NPCConfigData  npcCfg = null;
            NPCRuntimeData npcRt  = null;

            //获取参数配置
            NPCModel model = Core.Data.getIModelConfig <NPCModel>();
            switch (datasrc)
            {
            case CtorNpcSource.NPC_Castor_Init:
                npcCfg = src.data.configData.ShallowCopy();
                break;

            case CtorNpcSource.NPC_Castro_Cur:
                npcCfg = src.data.configData.ShallowCopy();
                npcRt  = src.data.rtData.ShallowCopy();
                break;

            case CtorNpcSource.NPC_Table:
                npcCfg = model.get(SwitchToId);
                Utils.Assert(npcCfg == null, "Can't find NPC configure. NPC ID = " + SwitchToId);
                break;
            }

            if (inheritNorAtk == false)
            {
                NPCConfigData swtNpcCfg = model.get(SwitchToId);
                Utils.Assert(swtNpcCfg == null, "Can't find NPC configure. NPC ID = " + SwitchToId);
                npcCfg.ID        = SwitchToId;
                npcCfg.normalHit = swtNpcCfg.normalHit;
            }

            npcRt = npcRt ?? new NPCRuntimeData(npcCfg);

            //额外的属性修改
            NPCAttributeModel AttModel = Core.Data.getIModelConfig <NPCAttributeModel>();
            AttrbuteConfig    att1     = AttModel.get(cfg.Param6);
            AttrbuteConfig    att2     = AttModel.get(cfg.Param8);

            //参数
            float param1 = cfg.Param7 * Consts.OneThousand;
            float param2 = cfg.Param9 * Consts.OneThousand;

            //修正属性的值
            if (att1 != null)
            {
                if (att1.type == "int")
                {
                    npcRt.addIntegerValue(att1.note, param1);
                }
                else if (att1.type == "float")
                {
                    npcRt.addFloatValue(att1.note, param1);
                }
            }

            if (att2 != null)
            {
                if (att2.type == "int")
                {
                    npcRt.addIntegerValue(att2.note, param2);
                }
                else if (att2.type == "float")
                {
                    npcRt.addFloatValue(att2.note, param2);
                }
            }

            //Buff的列表
            int[] BuffIds = cfg.Param11;

            ///
            /// 统计信息
            ///
            WarSrcAnimParam SrcParam = new WarSrcAnimParam()
            {
                OP             = EffectOp.SwitchNpc,
                ShootAction    = skCfg.ShootAction,
                ShootEventTime = skCfg.ShootEventTime,
                ShootTime      = skCfg.ShootTime,
                described      = new SelfDescribed()
                {
                    src    = src.UniqueID,
                    target = src.UniqueID,
                    act    = Verb.Creature,
                    srcEnd = new EndResult {
                        param1 = SwitchToId,
                        param2 = (int)AI,
                        param3 = chargeOf,
                        param8 = duration,
                    },
                    targetEnd = null,
                },

                SkillId   = skCfg.ID,
                OringinOP = EffectOp.SwitchNpc,
            };

            SrcParam.described.srcEnd.obj = ctorToShowcase(npcRt, npcCfg, BuffIds, Locale);

            container.Add(SrcParam);
        }
Пример #5
0
        //初始化AI
        private void InitAi(BNPC npc)
        {
            //如果是npc刷新点
            if (npc.data.num == NpcMgr <ServerNPC> .FRESH_NPC)
            {
                #if NO_SOLDIER
                #else
                BehaviorTree tree = npc.gameObject.GetComponent <BehaviorTree> ();
                if (tree == null)
                {
                    tree = npc.gameObject.AddComponent <BehaviorTree>();
                }

                tree.ExternalBehavior    = AiLoader.load(AILoader.NPC_FRESH);
                tree.StartWhenEnabled    = true;
                tree.RestartWhenComplete = false;
                #endif
            }
            else
            {
                NPCAIType type = (NPCAIType)npc.dataInScene.AIType;
                switch (type)
                {
                case NPCAIType.Pathfind_Atk:
                {
                    BehaviorTree tree = npc.gameObject.GetComponent <BehaviorTree> ();
                    if (tree == null)
                    {
                        tree = npc.gameObject.AddComponent <BehaviorTree>();
                    }

                    tree.ExternalBehavior    = AiLoader.load(AILoader.PATHFIND_ATK);
                    tree.StartWhenEnabled    = true;
                    tree.RestartWhenComplete = true;
                    break;
                }

                case NPCAIType.Simple_PfAtk:
                {
                    BehaviorTree tree = npc.gameObject.GetComponent <BehaviorTree> ();
                    if (tree == null)
                    {
                        tree = npc.gameObject.AddComponent <BehaviorTree>();
                    }

                    tree.ExternalBehavior    = AiLoader.load(AILoader.SIMPLE_PFATK);
                    tree.StartWhenEnabled    = true;
                    tree.RestartWhenComplete = true;
                    break;
                }

                case NPCAIType.Patrol:
                {
                    BehaviorTree tree = npc.gameObject.GetComponent <BehaviorTree> ();
                    if (tree == null)
                    {
                        tree = npc.gameObject.AddComponent <BehaviorTree>();
                    }

                    tree.ExternalBehavior    = AiLoader.load(AILoader.NORMAL_ATTACK);
                    tree.StartWhenEnabled    = true;
                    tree.RestartWhenComplete = true;
                    break;
                }
                }
            }
        }
Пример #6
0
        void AttachAI(ServerNPC npc, int ai)
        {
            ServerLifeNpc lifeNpc = npc as ServerLifeNpc;

            if (lifeNpc == null)
            {
                return;
            }
            lifeNpc.data.btData     = new NPCBattleData();
            lifeNpc.data.btData.way = BATTLE_WAY.None;
            AILoader  AiLoader = Core.ResEng.getLoader <AILoader>();
            NPCAIType type     = (NPCAIType)ai;

            switch (type)
            {
            case NPCAIType.Pathfind_Atk:
            {
                BehaviorTree tree = npc.gameObject.GetComponent <BehaviorTree> ();
                if (tree == null)
                {
                    tree = npc.gameObject.AddComponent <BehaviorTree>();
                }

                tree.ExternalBehavior    = AiLoader.load(AILoader.PATHFIND_ATK);
                tree.StartWhenEnabled    = true;
                tree.RestartWhenComplete = true;
                lifeNpc.AutoAiTree       = tree;
            }
            break;

            case NPCAIType.Simple_PfAtk:
            {
                BehaviorTree tree = npc.gameObject.GetComponent <BehaviorTree> ();
                if (tree == null)
                {
                    tree = npc.gameObject.AddComponent <BehaviorTree>();
                }

                tree.ExternalBehavior    = AiLoader.load(AILoader.SIMPLE_PFATK);
                tree.StartWhenEnabled    = true;
                tree.RestartWhenComplete = true;
                lifeNpc.AutoAiTree       = tree;
            }
            break;

            case NPCAIType.Patrol:
            {
                BehaviorTree tree = npc.gameObject.GetComponent <BehaviorTree> ();
                if (tree == null)
                {
                    tree = npc.gameObject.AddComponent <BehaviorTree>();
                }

                tree.ExternalBehavior    = AiLoader.load(AILoader.NORMAL_ATTACK);
                tree.StartWhenEnabled    = true;
                tree.RestartWhenComplete = true;
                lifeNpc.AutoAiTree       = tree;
            }
            break;
            }
        }