public void CreateEntityView(int objId)
 {
     if (objId <= 0)
     {
         LogSystem.Error("Error:CreateEntityView objId<=0 !!!");
         Helper.LogCallStack();
         return;
     }
     if (!m_EntityViews.ContainsKey(objId))
     {
         EntityInfo obj = PluginFramework.Instance.EntityManager.GetEntityInfo(objId);
         if (null != obj)
         {
             EntityViewModel view = new EntityViewModel();
             view.Create(obj);
             m_EntityViews.Add(objId, view);
             if (null != view.Actor)
             {
                 if (m_Object2Ids.ContainsKey(view.Actor))
                 {
                     m_Object2Ids[view.Actor] = objId;
                 }
                 else
                 {
                     m_Object2Ids.Add(view.Actor, objId);
                 }
             }
             else
             {
                 LogSystem.Warn("CreateEntityView:{0}, model:{1}, actor is null", objId, obj.GetModel());
             }
         }
     }
 }
Esempio n. 2
0
 public static MemoryStream ReadAsMemoryStream(string filePath)
 {
     try {
         byte[] buffer = ReadAsArray(filePath);
         if (buffer == null)
         {
             LogSystem.Error("Err ReadFileAsMemoryStream failed:{0}\n", filePath);
             return(null);
         }
         return(new MemoryStream(buffer));
     } catch (Exception e) {
         LogSystem.Error("Exception:{0}\n", e.Message);
         Helper.LogCallStack();
         return(null);
     }
 }
        public static void Calc(EntityInfo npc, TableConfig.Skill cfg)
        {
            int oldHp = npc.Hp;

            AttrCalculator.CopyBaseProperty(npc);
            AttrCalculator.RefixAttrByImpact(npc);
            if (null != cfg)
            {
                RefixAttrBySkill(npc, cfg);
            }
            Calculator.Calc(npc.SceneContext, npc.ActualProperty, null, "attr");

            if (oldHp > 0 && npc.Hp <= 0)
            {
                LogSystem.Error("hp calc to {0}", npc.Hp);
                Helper.LogCallStack();
            }
        }
Esempio n. 4
0
 public static byte[] ReadAsArray(string filePath)
 {
     byte[] buffer = null;
     try {
         if (OnReadAsArray != null)
         {
             buffer = OnReadAsArray(filePath);
         }
         else
         {
             LogSystem.Error("ReadFileByEngine handler have not register: {0}", filePath);
         }
     } catch (Exception e) {
         LogSystem.Error("Exception:{0}\n", e.Message);
         Helper.LogCallStack();
         return(null);
     }
     return(buffer);
 }
        public bool LoadFromBinary(string file)
        {
            long        t1     = TimeUtility.GetElapsedTimeUs();
            bool        result = true;
            BinaryTable table  = new BinaryTable();

            table.Load(HomePath.GetAbsolutePath(file));
            long t2 = TimeUtility.GetElapsedTimeUs();

            long t3 = TimeUtility.GetElapsedTimeUs();

            for (int index = 0; index < table.Records.Count; ++index)
            {
                try {
                    TData data = new TData();
                    bool  ret  = data.ReadFromBinary(table, index);
                    if (ret && !m_DataContainer.ContainsKey(data.GetId()))
                    {
                        m_DataContainer.Add(data.GetId(), data);
                    }
                    else
                    {
                        string info = string.Format("DataTempalteMgr.CollectDataFromBinary collectData Row:{0} failed in {1}!", index, file);
                        LogSystem.Error(info);
                        Helper.LogCallStack(true);
                        result = false;
                    }
                } catch (System.Exception ex) {
                    LogSystem.Error("CollectData failed. file:{0} rowIndex:{1}\nException:{2}\n{3}", file, index, ex.Message, ex.StackTrace);
                }
            }
            long t4 = TimeUtility.GetElapsedTimeUs();

            LogSystem.Info("binary load {0} parse {1}, file {2}", t2 - t1, t4 - t3, file);
            return(result);
        }
        internal bool StartSkill(int actorId, TableConfig.Skill configData, int seq, params Dictionary <string, object>[] locals)
        {
            bool ret = false;

            if (null == configData)
            {
                LogSystem.Error("{0} can't cast skill, config is null !", actorId, seq);
                Helper.LogCallStack();
                return(false);
            }
            if (!m_Scene.EntityController.CanCastSkill(actorId, configData, seq))
            {
                m_Scene.EntityController.CancelCastSkill(actorId);
                LogSystem.Warn("{0} can't cast skill {1} {2}, cancel.", actorId, configData.id, seq);
                m_Scene.EntityController.CancelIfImpact(actorId, configData, seq);
                return(false);
            }
            GfxSkillSenderInfo senderInfo = m_Scene.EntityController.BuildSkillInfo(actorId, configData, seq, m_Scene);

            if (null != senderInfo && null != senderInfo.GfxObj)
            {
                int            skillId   = senderInfo.SkillId;
                EntityInfo     obj       = senderInfo.GfxObj;
                SkillLogicInfo logicInfo = m_SkillLogicInfos.Find(info => info.GfxObj == obj && info.SkillId == skillId && info.Seq == seq);
                if (logicInfo != null)
                {
                    LogSystem.Warn("{0} is casting skill {1} {2}, cancel.", actorId, skillId, seq);
                    m_Scene.EntityController.CancelIfImpact(actorId, configData, seq);
                    return(false);
                }
                SkillInstanceInfo inst          = null;
                SkillInstance     innerInstance = null;
                if (skillId == PredefinedSkill.c_EmitSkillId)
                {
                    for (int i = 0; i < locals.Length; ++i)
                    {
                        object instObj;
                        if (locals[i].TryGetValue("emitskill", out instObj))
                        {
                            innerInstance = instObj as SkillInstance;
                        }
                    }
                    if (null == innerInstance)
                    {
                        LogSystem.Warn("{0} use predefined skill {1} {2} but not found emitskill, cancel.", actorId, skillId, seq);
                        //m_Scene.EntityController.CancelIfImpact(actorId, configData, seq);
                        //return false;
                    }
                }
                else if (skillId == PredefinedSkill.c_HitSkillId)
                {
                    for (int i = 0; i < locals.Length; ++i)
                    {
                        object instObj;
                        if (locals[i].TryGetValue("hitskill", out instObj))
                        {
                            innerInstance = instObj as SkillInstance;
                        }
                    }
                    if (null == innerInstance)
                    {
                        LogSystem.Warn("{0} use predefined skill {1} {2} but not found hitskill, cancel.", actorId, skillId, seq);
                        //m_Scene.EntityController.CancelIfImpact(actorId, configData, seq);
                        //return false;
                    }
                }
                if (null == innerInstance)
                {
                    inst = NewSkillInstance(skillId, senderInfo.ConfigData);
                }
                else
                {
                    inst = NewInnerSkillInstance(skillId, innerInstance);
                }
                if (null != inst)
                {
                    m_SkillLogicInfos.Add(new SkillLogicInfo(senderInfo, inst));
                }
                else
                {
                    LogSystem.Warn("{0} cast skill {1} {2}, alloc failed.", actorId, skillId, seq);
                    m_Scene.EntityController.CancelIfImpact(actorId, configData, seq);
                    return(false);
                }

                logicInfo = m_SkillLogicInfos.Find(info => info.GfxObj == obj && info.SkillId == skillId && info.Seq == seq);
                if (null != logicInfo)
                {
                    if (null != locals)
                    {
                        int localCount = locals.Length;
                        for (int i = 0; i < localCount; ++i)
                        {
                            foreach (KeyValuePair <string, object> pair in locals[i])
                            {
                                logicInfo.SkillInst.SetVariable(pair.Key, pair.Value);
                            }
                        }
                    }
                    EntityInfo target = senderInfo.TargetGfxObj;
                    if (null != target && target != obj && configData.type == (int)SkillOrImpactType.Skill)
                    {
                        TriggerUtil.Lookat(m_Scene, obj, target.GetMovementStateInfo().GetPosition3D());
                    }
                    m_Scene.EntityController.ActivateSkill(actorId, skillId, seq);
                    logicInfo.SkillInst.Context = m_Scene;
                    logicInfo.SkillInst.Start(logicInfo.Sender);
                    ret = true;
                }
            }
            return(ret);
        }