战斗系统01

1,技能,前面博客已经写过

有限状态机的变化控制,Itentity类,怪物打斗Entity中的OnTriggerEnter方法

//玩家进入塔,碰到别的怪物,走进树林
    private void OnTriggerEnter(Collider other)
    {
        if (this.SyncEntity == null || !(other is SphereCollider))
        {
            return;
        }
        Iselfplayer player = PlayerManager.Instance.LocalPlayer;
        if (this.SyncEntity.GameObjGUID != player.GameObjGUID)          //当前ENTITY 不是玩家
        {
            return;
        }
        Entity entity = other.gameObject.GetComponent<Entity>();
        if(entity == null || entity.SyncEntity == null)                 //进入对象的entity为空
        {
            return;
        }
        if (player.AbsorbMonsterType[0] == 0 && player.AbsorbMonsterType[1] == 0)    //没有附身对象
        {
            return;
        }
        if (entity.SyncEntity.EntityCamp != player.EntityCamp || entity.SyncEntity.entityType != EntityType.Building            //如果进入的不是友方祭坛、
            || entity.SyncEntity.NPCCateChild != ENPCCateChild.eNPCChild_BUILD_Altar)
        {
            return;
        }
        Game.AudioManager.Instance.PlayEffectAudio(player.GetAltarClip());
        EventCenter.Broadcast(EGameEvent.eGameEvent_PlayerEnterAltar);
        if (UIAltarSelect.Instance == null)
        {
            GameUI.Instance.OnOpenUI(GameConstDefine.AltarSoldierSelect);
            UIAltarSelect.Instance.OnTriggerAltar(entity.SyncEntity);
        }
    }

2,数据

//战斗类信息
public class HeroBattleInfo
{
    public UInt64 SGUID;
    public string HeroName;
    public int Level;
    public int Kills;
    public int Deaths;
    public int Assist;//助攻
    public int HeadIcon;
    public int LastHit;//
    public int Cp;
    public EntityCampType campType;
    public Dictionary<int, int> GoodsItemsInfo = new Dictionary<int, int>();

    public Dictionary<int, int> GetItemsInfo()
    {
        return GoodsItemsInfo;
    }
    public void AddGoodItem(int index, int id)
    {
        if (!GoodsItemsInfo.ContainsKey(index))
        {
            GoodsItemsInfo.Add(index, id);
            return;
        }
        GoodsItemsInfo[index] = id;
    }
    public void DelGoodsItem(int index)
    {
        if (GoodsItemsInfo.ContainsKey(index))
        {
            GoodsItemsInfo[index] = 0;
        }
    }
    public int GetId(int index)
    {
        for (int i = 0; i < GoodsItemsInfo.Count; i++)
        {
            int id = GoodsItemsInfo.ElementAt(i).Value;
            int temp = GoodsItemsInfo.ElementAt(i).Key;
            if ((index) == temp)
            {
                index = id;
                return index;
            }
        }
        return 0;
    }
    public void ClearGoods()
    {
        GoodsItemsInfo.Clear();
    }
}
        /// <summary>
        /// 播放效果音
        /// </summary>
        /// <param name="adClip"></param>
        /// <returns></returns>
        public AudioSource PlayEffectAudio(AudioClip adClip)
        {
            if (adClip == null)
            {
                return null;
            }
            AudioSource adio = EffectAudioSourceQueue.Dequeue();
            adio.clip = adClip;
            adio.volume = 1.0f;
            adio.Play();
            EffectAudioSourceQueue.Enqueue(adio);
            return adio;
        }

音效的队列 

 

 

3,特效

频繁使用的放对象池中,如:特效,小怪,UITip,血条

每实例化一次都要申请内存造成很多内存碎片

对象池,一次性实例化出需要的数目,用的时候激活,不用的时候藏起来,

IselfPlayer====》Iplayer====》IEntity

经常改动的和具体逻辑放子类,玩家自己=======玩家=======建筑怪物玩家

数据驱动,模块化处理,FSM,网络处理

有限状态机 EntityFSM  状态类函数的父类

Itentity 实物类接口  EntityManager来管理

创建事物,已经把实物加入字典中进行存储

 游戏物体在场景中出现的时候服务端会发消息

  //游戏实体在场景中出现
    public void OnNetMsg_NotifyGameObjectAppearCoroutine(System.IO.Stream stream)
    {
        if (GameStateManager.Instance.GetCurState().GetStateType() == GameStateType.GS_Play)
        {
            GSToGC.GOAppear pMsg;
            if (!ProtoDes(out pMsg, stream))
            {
                return;
            }

            foreach (GSToGC.GOAppear.AppearInfo info in pMsg.info)
            {
                UInt64 sMasterGUID = info.masterguid;
                UInt64 sObjGUID = info.objguid;
                if (sObjGUID < 1)
                {
                    Debug.LogError("objguid:" + sObjGUID);
                }
                Int32 IntCamp = info.camp;
                Vector3 mvPos = this.ConvertPosToVector3(info.pos);
                Vector3 mvDir = this.ConvertDirToVector3(info.dir);
                mvDir.y = 0.0f;
                EntityCampType Type = GameMethod.GetEntityCamp(IntCamp);
                GSToGC.ObjType objType = info.obj_type;

                if (EntityManager.AllEntitys.ContainsKey(sObjGUID))
                {
                    if (objType == GSToGC.ObjType.ObjType_Hero)
                    {
                        PlayerManager.Instance.ShowEntity(sObjGUID, mvPos, mvDir);
                        //发送通知
                        EventCenter.Broadcast<Ientity>(EGameEvent.eGameEvent_AddMiniMap, EntityManager.AllEntitys[sObjGUID]);
                    }
                    continue;
                }

                Ientity entity = null;
                if (CTools.IfTypeNPC((EObjectType)info.obj_type_id))
                {
                    entity = NpcManager.Instance.HandleCreateEntity(sObjGUID, Type);
                    entity.EntityCamp = Type;
                    entity.ObjTypeID = info.obj_type_id;
                    NpcManager.Instance.CreateEntityModel(entity, sObjGUID, mvDir, mvPos);
                }
                else if (CTools.IfTypeHero((EObjectType)info.obj_type_id))
                {
                    Iplayer player = null;
                    if (!PlayerManager.Instance.AccountDic.TryGetValue(sMasterGUID, out player))
                    {
                        player = (Iplayer)PlayerManager.Instance.HandleCreateEntity(sMasterGUID, Type);
                        player.ObjTypeID = info.obj_type_id;
                        PlayerManager.Instance.AddAccount(sMasterGUID, player);
                    }
                    player.EntityCamp = Type;
                    entity = player;
                    entity.ObjTypeID = info.obj_type_id;
                    PlayerManager.Instance.CreateEntityModel(entity, sObjGUID, mvDir, mvPos);
                    GameMethod.CreateCharacterController(player);
                    ReadPreLoadConfig.Instance.AddPreLoadRoleEffect((int)entity.ObjTypeID);
                }
                if (entity != null)
                {
                    entity.GameObjGUID = sObjGUID;
                    EntityManager.Instance.AddEntity(sObjGUID, entity);
                    if (GameUserModel.Instance.IsLocalPlayer(sMasterGUID))
                    {
                        Debug.Log("Set local player guid!" + sMasterGUID);
                        PlayerManager.Instance.LocalPlayer = (Iselfplayer)entity;
                        GameMethod.GetMainCamera.target = entity.realObject.transform;
                        GamePlayCtrl.Instance.UpdateSkillPriv((int)info.obj_type_id);

                        CPChanggeManager.Instance.ClearList();
                        EventCenter.Broadcast(EGameEvent.eGameEvent_InitMiniMap);
                    }
                    entity.InitWhenCreateModel();
                    entity.OnCreateShadow();
                    entity.GOSSI.sServerBeginPos = mvPos;
                    entity.GOSSI.sServerSyncPos = mvPos;
                    //先改变状态机的数据层
                    entity.EntityFSMChangedata(mvPos, mvDir);
                    //实例化了一个freeFSM
                    entity.OnFSMStateChange(EntityFreeFSM.Instance);
                    //播放加载小地图的消息
                    EventCenter.Broadcast<Ientity>(EGameEvent.eGameEvent_AddMiniMap, entity);
                }
            }
        }

        // StartBattle();
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值