Esempio n. 1
0
        private void AddSoilderByTeam(byte teamId, int posId)
        {
            AbsFightInstance soilderInstance = GetSoilderInstance(teamId, posId);

            fightRoomDTO.entities.Add(soilderInstance);
            instances.Add(soilderInstance.instanceId, soilderInstance);
        }
Esempio n. 2
0
        /// <summary>
        /// 加载一个entity
        /// </summary>
        /// <param name="fightInstance"></param>
        /// <param name="isHost"></param>
        private void LoadEntity(AbsFightInstance fightInstance, bool isHost)
        {
            int key = fightInstance.fightModel.category.GetHashCode() + fightInstance.fightModel.specieId.GetHashCode();

            if (prefabNames.ContainsKey(key))
            {
                string   abAssetName = prefabNames[key];
                string[] nameCompose = abAssetName.Split(' ');
                if (!instanceDic.ContainsKey(abAssetName))
                {
                    instanceDic.Add(abAssetName, new HashSet <AbsFightInstance>());
                }
                if (!instanceDic[abAssetName].Contains(fightInstance))
                {
                    instanceDic[abAssetName].Add(fightInstance);
                }

                if (isHost && fightInstance.teamId == GameRuntimeData.teamId)
                {//当本客户端是主机且这个实例是自己队伍的,那么这个实例运行AI
                    hasAIDic.Add(fightInstance.instanceId);
                }

                SendMsg(Msgs.GetMsgAssetLoadRequest((ushort)AssetLoadEvent.LoadRequest, nameCompose[0], nameCompose[1]));
            }
        }
Esempio n. 3
0
        private AbsFightInstance GetSoilderInstance(byte teamId, int posId)
        {
            entityMinIndex--;

            AbsFightModel    soilderModel    = SoilderData.SoilderModels[teamId];
            AbsFightInstance soilderInstance = new AbsFightInstance();

            soilderInstance.instanceId = entityMinIndex;
            soilderInstance.name       = soilderModel.name;
            soilderInstance.fightModel = soilderModel;
            soilderInstance.teamId     = teamId;
            soilderInstance.atk        = soilderModel.atk;
            soilderInstance.def        = soilderModel.def;
            soilderInstance.hp         = soilderModel.maxHp;
            soilderInstance.atkRange   = soilderModel.atkRange;
            soilderInstance.speed      = soilderModel.speed;
            soilderInstance.atkSpeed   = soilderModel.atkSpeed;
            soilderInstance.eyeRange   = soilderModel.eyeRange;

            if (teamId == 1)
            {
                soilderInstance.posX = MapData.soilderBornPointTeamOne[posId].x;
                soilderInstance.posY = MapData.soilderBornPointTeamOne[posId].y;
                soilderInstance.posZ = MapData.soilderBornPointTeamOne[posId].z;
            }
            else
            {
                soilderInstance.posX = MapData.soilderBornPointTeamTwo[posId].x;
                soilderInstance.posY = MapData.soilderBornPointTeamTwo[posId].y;
                soilderInstance.posZ = MapData.soilderBornPointTeamTwo[posId].z;
            }

            return(soilderInstance);
        }
Esempio n. 4
0
        public void Damage(int level, ref AbsFightInstance atk, ref AbsFightInstance target, ref List <int[]> damages, SkillLevelData skillLevelData = null)
        {
            int value = atk.atk - target.def;

            value     = value > 0 ? value : 1;
            target.hp = target.hp - value <= 0 ? 0 : target.hp - value;
            //一组伤害数据: 目标id、伤害值、是否活着(0为死亡、1为活着)
            damages.Add(new int[] { target.instanceId, value, target.hp == 0 ? 0 : 1 });
        }
Esempio n. 5
0
        private void CreateSoilderByTeam(byte teamId, int posId)
        {
            AbsFightInstance soilderInstance = GetSoilderInstance(teamId, posId);

            instances.Add(soilderInstance.instanceId, soilderInstance);

            //广播新增小兵指令
            brocast(FightProtocol.CREATE_SOILDER_SCMD, soilderInstance);
        }
Esempio n. 6
0
        private void EnterBattle(UserToken token)
        {
            int userId = GetUserId(token);

            if (IsEntered(token))
            {
                return;
            }
            base.Enter(token);
            if (!enterList.Contains(userId))
            {
                enterList.Add(userId);
            }

            if (enterList.Count == heroCount)
            {
                GameFW.Utility.Tools.debuger.Log("开始战斗");
                fightRoomDTO.isHost = false;
                long minDelayTeamOne     = long.MaxValue;
                long minDelayTeamTwo     = long.MaxValue;
                int  minDelayHostTeamOne = -1;
                int  minDelayHostTeamTwo = -1;

                foreach (int i in enterList)
                {
                    AbsFightInstance instance = instances[i];
                    long             delay    = userBiz.GetDelayAndFloatingById(i).delay;

                    if (instance.teamId == 1)
                    {
                        if (delay < minDelayTeamOne)
                        {
                            minDelayTeamOne     = delay;
                            minDelayHostTeamOne = i;
                        }
                    }
                    else
                    {
                        if (delay < minDelayTeamTwo)
                        {
                            minDelayTeamTwo     = delay;
                            minDelayHostTeamTwo = i;
                        }
                    }
                }

                brocast(Protocol.Protocol.TYPE_FIGHT, area, FightProtocol.START_BRO, fightRoomDTO, new int[2] {
                    minDelayHostTeamOne, minDelayHostTeamTwo
                });

                fightRoomDTO.isHost = true;//最后在双方各找一个延迟最低的客户端来做运行AI的主机
                Send(minDelayHostTeamOne, FightProtocol.START_BRO, fightRoomDTO);
                Send(minDelayHostTeamTwo, FightProtocol.START_BRO, fightRoomDTO);
                //CreateSoilderTask();
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 初始化Register和Driver脚本
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="fightInstance"></param>
        private void InitialScripts(GameObject entity, AbsFightInstance fightInstance)
        {
            //Data Model setting
            EntityRegister register = entity.GetComponent <EntityRegister>();

            if (register == null)
            {
                register = entity.AddComponent <EntityRegister>();
            }
            register.Regist(fightInstance.instanceId);
            //register to aoi
            register.RegistAOI(fightInstance.instanceId, entity);

            FightDriver fightDriver = entity.GetComponent <FightDriver>();

            if (fightDriver == null)
            {
                fightDriver = entity.AddComponent <FightDriver>();
            }
            fightDriver.Initial(fightInstance);
        }
Esempio n. 8
0
        /// <summary>
        /// 创建实体实例
        /// </summary>
        /// <param name="fightInstance"></param>
        /// <param name="obj"></param>
        /// <param name="hasAI"></param>
        private void CreateEntityInstance(AbsFightInstance fightInstance, UnityEngine.Object obj, bool hasAI)
        {
            GameObject entity = null;

            switch (fightInstance.fightModel.category)
            {
            case (byte)ModelType.Building:
                BuildingInstance buildingInstance = fightInstance as BuildingInstance;
                entity = GameObject.Instantiate(obj, new Vector3(buildingInstance.posX, buildingInstance.posY, buildingInstance.posZ), Quaternion.Euler(0, 0, 0)) as GameObject;
                entity.transform.eulerAngles = new Vector3(buildingInstance.eAngleX, buildingInstance.eAngleY, buildingInstance.eAngleZ);
                entity.transform.localScale  = new Vector3(buildingInstance.scaleX, buildingInstance.scaleY, buildingInstance.scaleZ);
                break;

            case (byte)ModelType.Hero:
                entity = GameObject.Instantiate(obj, new Vector3(fightInstance.posX, fightInstance.posY, fightInstance.posZ), Quaternion.Euler(0, 0, 0)) as GameObject;
                break;

            case (byte)ModelType.Creature:
                entity = GameObject.Instantiate(obj, new Vector3(fightInstance.posX, fightInstance.posY, fightInstance.posZ), Quaternion.Euler(0, 0, 0)) as GameObject;
                break;
            }

            if (entity != null)
            {
                if (fightInstance.teamId == 1)
                {
                    entity.layer = LayerIds.TeamOneLayer;
                }
                else
                {
                    entity.layer = LayerIds.TeamTwoLayer;
                }
            }

            InitialScripts(entity, fightInstance);
            InitialAI(hasAI, entity, fightInstance);
        }
Esempio n. 9
0
 public override void Initial(AbsFightInstance fightInstance)
 {
     base.Initial(fightInstance);
     animator = gameObject.GetComponent <Animator>();
 }
Esempio n. 10
0
 /// <summary>
 /// 初始化数据
 /// </summary>
 /// <param name="buildingInstance"></param>
 public override void Initial(AbsFightInstance buildingInstance)
 {
     base.Initial(buildingInstance);
     this.buildingInstance = buildingInstance as BuildingInstance;
     isAttacking           = false;
 }
Esempio n. 11
0
 public MsgNPCCreate(ushort msgId, AbsFightInstance npcInstance, bool isHost)
 {
     this.msgId       = msgId;
     this.npcInstance = npcInstance;
     this.isHost      = isHost;
 }
Esempio n. 12
0
        /// <summary>
        /// 初始化AI脚本
        /// </summary>
        /// <param name="hasAI"></param>
        /// <param name="entity"></param>
        /// <param name="fightInstance"></param>
        private void InitialAI(bool hasAI, GameObject entity, AbsFightInstance fightInstance)
        {
            if (hasAI)
            {
                FightAgent fightAgent = entity.GetComponent <FightAgent>();
                switch (fightInstance.fightModel.category)
                {
                case (byte)ModelType.Building:
                    if (entity.GetComponent <NavMeshAgent>() != null)
                    {
                        Destroy(entity.GetComponent <NavMeshAgent>());
                    }

                    fightAgent = AddBuildingAgentScript(entity, fightInstance.fightModel.specieId);
                    break;

                case (byte)ModelType.Creature:
                    if (entity.GetComponent <NavMeshAgent>() == null)
                    {
                        entity.AddComponent <NavMeshAgent>();
                    }
                    break;

                case (byte)ModelType.Hero:
                    break;
                }
                if (entity.GetComponent <PosSyncDriver>() != null)
                {
                    Destroy(entity.GetComponent <PosSyncDriver>());
                }

                if (fightAgent != null)
                {
                    //Data Model setting
                    fightAgent.Id = fightInstance.instanceId;
                    //start ai
                    fightAgent.Initial();
                    fightAgent.StartAI();
                }
            }
            else
            {
                if (entity.GetComponent <FightAgent>() != null)
                {
                    Destroy(entity.GetComponent <FightAgent>());
                }
                if (entity.GetComponent <NavMeshAgent>() != null)
                {
                    Destroy(entity.GetComponent <NavMeshAgent>());
                }
                switch (fightInstance.fightModel.category)
                {
                case (byte)ModelType.Building:
                    if (entity.GetComponent <PosSyncDriver>() != null)
                    {
                        Destroy(entity.GetComponent <PosSyncDriver>());
                    }
                    break;

                case (byte)ModelType.Creature:
                case (byte)ModelType.Hero:
                    if (entity.GetComponent <PosSyncDriver>() == null)
                    {
                        entity.AddComponent <PosSyncDriver>();
                    }
                    break;
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        /// 计算伤害、存储结果、并向客户端发送消息
        /// </summary>
        /// <param name="token"></param>
        /// <param name="damageDTO"></param>
        private void Damage(UserToken token, DamageDTO damageDTO)
        {
            int userId = GetUserId(token);
            AbsFightInstance atkInstance;
            int skillLevel = 0;

            //判断攻击者是玩家英雄 还是小兵
            if (damageDTO.userId >= 0)//是英雄
            {
                if (damageDTO.userId != userId)
                {
                    return;
                }
                atkInstance = instances[userId];
                if (damageDTO.skill > 0)
                {
                    skillLevel = (atkInstance as HeroInstance).SkillLevel(damageDTO.skill);
                    if (skillLevel == -1)
                    {
                        return;
                    }
                    else
                    {
                    }
                }
            }
            else//是兵或者建筑
            {
                //TODO:
                atkInstance = instances[userId];
            }

            if (!SkillData.SkillModels.ContainsKey(damageDTO.skill))
            {
                return;
            }

            //1.获取技能方法
            ISkill       skill   = SkillProcessMap.Get(damageDTO.skill);
            List <int[]> damages = new List <int[]>();

            //2.根据技能定义,获取目标数据和攻击者数据,计算伤害值
            foreach (int[] item in damageDTO.targetDamages)
            {
                AbsFightInstance target = instances[item[0]];
                //计算伤害值并存储
                skill.Damage(skillLevel, ref atkInstance, ref target, ref damages);
                if (target.hp == 0)
                {
                    switch (target.fightModel.category)
                    {
                    case (byte)ModelType.Hero:
                        //击杀英雄
                        //奖励玩家
                        //启动定时任务 指定时间之后发送英雄复活信息 并且将英雄数据设置为满状态


                        break;

                    case (byte)ModelType.Creature:
                        //发送消息
                        //TODO 给钱、经验
                        //移除生物数据

                        break;

                    case (byte)ModelType.Building:
                        //摧毁建筑 给钱,通知进攻树变更

                        break;
                    }
                }
            }
            damageDTO.targetDamages = damages.ToArray();
            brocast(FightProtocol.DAMAGE_BRO, damageDTO);
        }
Esempio n. 14
0
 public static MsgNPCCreate GetMsgNPCCreate(ushort msgId, AbsFightInstance instance, bool isHost)
 {
     msgNPCCreate.SetNPCCreate(msgId, instance, isHost);
     return(msgNPCCreate);
 }
Esempio n. 15
0
 public virtual void Initial(AbsFightInstance buildingInstance)
 {
     this.fightInstance = buildingInstance;
     MgrCenter.Instance.SendMsg(Msgs.GetMsgHUD((ushort)HUDEvent.CreateHUD, fightInstance.instanceId, transform.position, fightInstance.name, 1f));
 }