/// <summary> /// 使用技能 /// </summary> /// <param name="skillId"></param> /// <param name="targetId"></param> private void OnSkill(MobaClient client, int skillId, int attackId, int targetId, float x, float y, float z) { int playerId = playerCache.GetId(client); FightRoom room = fightCache.GetRoom(playerId, client); //先判断是不是普通攻击 if (skillId == 1) { //参数 1使用者,2目标者 room.Brocast(OpCode.FightCode, OpFight.Skill, 0, "有人进行普通攻击", null, attackId, targetId); } //从技能配置获取技能信息,在广播 else { if (targetId == -1) { //定点技能 room.Brocast(OpCode.FightCode, OpFight.Skill, 1, "定点释放技能", null, skillId, attackId, -1, x, y, z); } else { //指定目标技能 room.Brocast(OpCode.FightCode, OpFight.Skill, 1, "选择目标释放技能", null, skillId, attackId, targetId); } } }
/// <summary> /// 使用技能 /// </summary> /// <param name="v1"></param> /// <param name="v2"></param> private void onSkill(MobaClient client, int skillId, int attackId, int targetId, float x, float y, float z) { int playerId = playerCache.GetId(client); FightRoom room = fightCache.GetRoom(playerId); //先判断 是不是普通攻击 if (skillId == 1) { //TODO //参数:1.攻击者ID 2.被攻击者ID room.Brocast(OpCode.FightCode, OpFight.Skill, 0, "有人普通攻击", null, attackId, targetId); } //是技能 从技能配置表里面通过技能ID获取到技能信息 然后再广播 else { if (targetId == -1) { //指定点的技能 room.Brocast(OpCode.FightCode, OpFight.Skill, 1, "有人释放指定点的技能了", null, skillId, attackId, -1, x, y, z); } else { //指定目标的技能 room.Brocast(OpCode.FightCode, OpFight.Skill, 1, "有人释放指定目标的技能了", null, skillId, attackId, targetId); } } }
/// <summary> /// 处理游戏结束 /// </summary> private void OnGameOver(FightRoom room, int winTeam) { room.Brocast(OpCode.FightCode, OpFight.GameOver, 0, "游戏结束", null, winTeam); //更新玩家的数据 foreach (MobaClient client in room.clientList) { //获取玩家数据模型 PlayerModel playerModel = playerCache.GetModel(client); //检测是否逃跑 if (room.leaveClient.Contains(client)) { //更新逃跑场次 playerCache.UpdateModel(playerModel, 2); } //胜利失败判断 HeroModel heroModel = room.GetHeroModel(playerModel.Id); if (heroModel.Team == winTeam) { //赢了 playerCache.UpdateModel(playerModel, 0); } else { //输了 playerCache.UpdateModel(playerModel, 1); } } //销毁战斗房间 fightCache.Destroy(room.Id); }
/// <summary> /// 游戏结束 /// </summary> /// <param name="room"></param> /// <param name="winTeam"></param> private void onGameOver(FightRoom room, int winTeam) { //广播游戏结束的消息,参数是胜利的部队 room.Brocast(OpCode.FightCode, OpFight.GameOver, 0, "游戏结束", null, winTeam); //更新玩家的数据 foreach (MobaClient client in room.ClientList) { PlayerModel model = playerCache.GetModel(client); //检测是否逃跑 if (room.LeaveClient.Contains(client)) { //更新逃跑场次 playerCache.UpdateModel(model, 2); } //队伍1赢了 if (winTeam == 1) { HeroModel hero = room.GetHeroModel(model.Id); if (hero.Team == winTeam) { //赢了 playerCache.UpdateModel(model, 0); } else { //输了 playerCache.UpdateModel(model, 1); } } } //销毁房间 fightCache.Destroy(room.Id); }
/// <summary> /// 买装备 /// </summary> /// <param name="client"></param> /// <param name="itemId"></param> private void onBuy(MobaClient client, int itemId) { //检测有没有装备 ItemModel item = ItemData.GetItem(itemId); if (item == null) { return; } //获取房间模型 int playerId = playerCache.GetId(client); FightRoom room = fightCache.GetRoom(playerId); if (room == null) { return; } //获取英雄数据模型 HeroModel hero = room.GetHeroModel(playerId); //检测钱够不够 if (hero.Money < item.Price) { Send(client, OpCode.FightCode, OpFight.Buy, -1, "金币不足"); return; } //添加装备 for (int i = 0; i < hero.Equipments.Length; i++) { //-1 代表没有装备 if (hero.Equipments[i] == -1) { //开始购买 hero.Money -= item.Price; //给他装备的ID hero.Equipments[i] = itemId; //增加属性 hero.Attack += item.Attack; hero.Defense += item.Defense; hero.MaxHp += item.Hp; //给房间内所有客户端发消息了 谁 买了什么装备(HeroModel) room.Brocast(OpCode.FightCode, OpFight.Buy, 0, "有人购买装备了", null, JsonMapper.ToJson(hero)); return; } } //给当前客户端发送 购买成功 // Send(client, OpCode.FightCode, OpFight.Buy, 0, "购买成功"); //有没有格子 // if (hero.Equipments.Length == 6) //{ //如果走到这里 就代表没买成功,肯定是一种结果 没有格子了 Send(client, OpCode.FightCode, OpFight.Buy, -2, "装备已满"); return; // } }
/// <summary> /// 移动 /// </summary> /// <param name="client"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> private void OnWalk(MobaClient client, float x, float y, float z) { int playerId = playerCache.GetId(client); FightRoom room = fightCache.GetRoom(playerId, client); if (room == null) { return; } //给每个客户端发送信息,谁移动到哪 room.Brocast(OpCode.FightCode, OpFight.Walk, 0, "有玩家移动", null, playerId, x, y, z); }
/// <summary> /// 技能升级 /// </summary> /// <param name="client"></param> /// <param name="SkillId"></param> private void OnSkillUp(MobaClient client, int SkillId) { //1、获取房间 int playerId = playerCache.GetId(client); FightRoom room = fightCache.GetRoom(playerId, client); if (room == null) { return; } //获取英雄模型 HeroModel hero = room.GetHeroModel(playerId); if (hero == null) { return; } if (hero.SkillPoints <= 0) { return; } //可以加点 for (int i = 0; i < hero.Skills.Length; i++) { SkillModel skill = hero.Skills[i]; if (skill.Id != SkillId) { continue; } //玩家等级没有到达技能学习要求 或者技能已满级 if (skill.LearnLevel > hero.Level || skill.LearnLevel == -1) { return; } //先获取技能下一级的数据 hero.SkillPoints--; skill.Level++; SkillLevelDataModel data = SkillData.GetSkllData(SkillId).LvModels[skill.Level]; //修改技能 skill.LearnLevel = data.LearnLv; skill.Distance = data.Distance; skill.CoolDown = data.CoolDown; //广播谁更新了什么技能 room.Brocast(OpCode.FightCode, OpFight.SkillUp, 0, "有人点技能了", null, playerId, JsonMapper.ToJson(skill)); return; } }
/// <summary> /// 玩家移动 /// </summary> /// <param name="client"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> private void onWalk(MobaClient client, float x, float y, float z) { int playerId = playerCache.GetId(client); FightRoom room = fightCache.GetRoom(playerId); if (room == null) { return; } //给每一个客户端发送信息:谁移动到哪 //这里是发请求后再移动,也可以发请求的同时就移动 room.Brocast(OpCode.FightCode, OpFight.Walk, 0, "有玩家移动", null, playerId, x, y, z); }
/// <summary> /// 玩家移动 /// </summary> /// <param name="client"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> private void onWalk(MobaClient client, float x, float y, float z) { int playerId = playerCache.GetId(client); FightRoom room = fightCache.GetRoom(playerId); if (room == null) { return; } //给每一个客户端发送信息:谁 移动到 哪 MobaApplication.LogInfo("123"); room.Brocast(OpCode.FightCode, OpFight.Walk, 0, "有玩家移动", null, playerId, x, y, z); }
/// <summary> /// 响应购买请求 /// </summary> /// <param name="client"></param> /// <param name="buyId"></param> private void OnBuy(MobaClient client, int buyId) { ItemModel model = ItemData.GetItem(buyId); if (model == null) { return; } //1、获取房间 int playerId = playerCache.GetId(client); FightRoom room = fightCache.GetRoom(playerId, client); if (room == null) { return; } //获取英雄模型 HeroModel hero = room.GetHeroModel(playerId); if (hero.Money < model.Price) { Send(client, OpCode.FightCode, OpFight.Buy, -1, "金币不足"); return; } //开始购买装备 hero.Money -= model.Price; //添加装备 for (int i = 0; i < hero.Equipments.Length; i++) { // -1代表没有装备 if (hero.Equipments[i] == -1) { //装备Id hero.Equipments[i] = model.Id; hero.AddItem(model); //给房间内所有客户端发消息,谁了什么装备 发送heroModel; room.Brocast(OpCode.FightCode, OpFight.Buy, 0, "有人购买了装备", null, JsonMapper.ToJson(hero)); return; } } //有没有格子 if (hero.Equipments.Length == 6) { Send(client, OpCode.FightCode, OpFight.Buy, -2, "装备已满"); return; } }
/// <summary> /// 技能升级 /// </summary> /// <param name="client"></param> /// <param name="v"></param> private void onSkillUp(MobaClient client, int skillId) { //1.获取房间模型 int playerid = playerCache.GetId(client); FightRoom room = fightCache.GetRoom(playerid); if (room == null) { return; } //获取英雄数据模型 HeroModel hero = room.GetHeroModel(playerid); if (hero == null) { return; } //没有技能点数了 就不作处理 if (hero.Points <= 0) { return; } //可以加点 foreach (var item in hero.Skills) { if (item.Id != skillId) { continue; } //如果玩家等级没有到达 技能学习的要求 或者技能已满级 if (item.LearnLevel > hero.Level || item.LearnLevel == -1) { return; } //扣点数 hero.Points--; //先获取技能下一级的数据 SkillLevelDataModel data = SkillData.GetSkillData(skillId).LvModels[++item.Level]; //修改技能 item.LearnLevel = data.LearnLv; item.Distance = data.Distance; item.CoolDown = data.CoolDown; //等等 在这里修改想修改的数据 //广播 谁 更新了 什么技能 room.Brocast(OpCode.FightCode, OpFight.SkillUp, 0, "有人点技能了", null, playerid, JsonMapper.ToJson(item)); return; } }
/// <summary> /// 玩家ID /// </summary> /// <param name="playerId"></param> private void onEnter(MobaClient client, int playerId) { FightRoom room = fightCache.Enter(playerId, client); if (room == null) { return; } //首先要判断 是否全部进入了 //作用 保证竞技游戏的公平 if (!room.IsAllEnter) { return; } room.spawnDog(); //给每个客户端发送战斗房间的信息 room.Brocast(OpCode.FightCode, OpFight.GetInfo, 0, "加载战斗场景", null, JsonMapper.ToJson(room.Heros), JsonMapper.ToJson(room.Builds)); }
/// <summary> /// 卖装备 /// </summary> /// <param name="client"></param> /// <param name="itemId"></param> private void onSale(MobaClient client, int itemId) { //检测有没有装备 ItemModel item = ItemData.GetItem(itemId); if (item == null) { return; } //获取房间模型 int playerId = playerCache.GetId(client); FightRoom room = fightCache.GetRoom(playerId); if (room == null) { return; } //获取英雄数据模型 HeroModel hero = room.GetHeroModel(playerId); //开始遍历 for (int i = 0; i < hero.Equipments.Length; i++) { if (hero.Equipments[i] == itemId) { //开始出售 hero.Money += item.Price; //给他装备的ID hero.Equipments[i] = -1; //增加属性 hero.Attack -= item.Attack; hero.Defense -= item.Defense; hero.MaxHp -= item.Hp; //给房间内所有客户端发消息了 谁 买了什么装备(HeroModel) room.Brocast(OpCode.FightCode, OpFight.Sale, 0, "有人出售装备了", null, JsonMapper.ToJson(hero)); return; } } //走到这里就代表出售失败了 Send(client, OpCode.FightCode, OpFight.Sale, -1, "出售失败"); return; }
/// <summary> /// 卖装备 /// </summary> /// <param name="client"></param> /// <param name="itemId"></param> private void OnSale(MobaClient client, int itemId) { ItemModel model = ItemData.GetItem(itemId); if (model == null) { return; } //1、获取房间 int playerId = playerCache.GetId(client); FightRoom room = fightCache.GetRoom(playerId, client); if (room == null) { return; } //获取英雄模型 HeroModel hero = room.GetHeroModel(playerId); //添加装备 for (int i = 0; i < hero.Equipments.Length; i++) { // -1代表没有装备 if (hero.Equipments[i] == itemId) { hero.Money += model.Price; //装备Id hero.Equipments[i] = -1; hero.ReduceItem(model); //给房间内所有客户端发消息,谁了什么装备 发送heroModel; room.Brocast(OpCode.FightCode, OpFight.Sale, 0, "有人卖装备了", null, JsonMapper.ToJson(hero)); return; } } //代表出售失败了 Send(client, OpCode.FightCode, OpFight.Sale, -1, "出售失败"); return; }
private void chatRequest(ClientPeer client, int chatType) { if (userCache.IsOnline(client) == false) { return; } int userId = userCache.GetId(client); ChatDto chatDto = new ChatDto(userId, chatType); if (matchCache.IsMatching(userId)) { MatchRoom mRoom = matchCache.GetRoom(userId); mRoom.Brocast(OpCode.CHAT, ChatCode.SERS, chatDto); Console.WriteLine("快捷喊话:" + chatDto.ChatType); } else if (fightCache.IsFighting(userId)) { FightRoom fightRoom = fightCache.GetRoomByUId(userId); fightRoom.Brocast(OpCode.CHAT, ChatCode.SERS, chatDto); Console.WriteLine("快捷喊话:" + chatDto.ChatType); } }
/// <summary> /// 玩家进入战斗 /// </summary> /// <param name="playerId"></param> private void OnEnter(MobaClient client, int playerId) { FightRoom room = fightCache.Enter(playerId, client); if (room == null) { return; } //是否全部进入,保证竞技游戏的公平 if (!room.IsAllEnter) { return; } //给每个客户端发送进入战斗信息 string Builds = JsonMapper.ToJson(room.Builds); string Heros = JsonMapper.ToJson(room.Heros); room.Brocast(OpCode.FightCode, OpFight.GetInfo, 0, "进入战斗", null, Heros, Builds); }
private void chatRequest(ClientPeer client, int chatType) { if (userCache.IsOnline(client) == false) { return; } int userId = userCache.GetId(client); //获取发送者的id userId //发送 ChatDto dto = new ChatDto(userId, chatType); //广播给房间内的玩家 if (matchCache.IsMatching(userId)) { MatchRoom mRoom = matchCache.GetRoom(userId); mRoom.Brocast(OpCode.CHAT, ChatCode.SRES, dto); } if (fightCache.IsFighting(userId)) { FightRoom fRoom = fightCache.GetRoomByUId(userId); fRoom.Brocast(OpCode.CHAT, ChatCode.SRES, dto, client); } }
/// <summary> /// 响应伤害请求 /// </summary> /// <param name="request"></param> private void OnDamage(MobaClient client, int attackId, int skillId, int[] targetIds) { //1、获取房间 int playerId = playerCache.GetId(client); FightRoom room = fightCache.GetRoom(playerId, client); //2、谁攻击谁 DogModel attackModel = null; if (attackId >= 0) { //英雄攻击 attackModel = room.GetHeroModel(attackId); } else if (attackId <= -100 && attackId > -300) { //防御塔的攻击 attackModel = room.GetBuildModel(attackId); } else if (attackId <= -1000) { //小兵的攻击 } DogModel[] targetModels = new DogModel[targetIds.Length]; for (int i = 0; i < targetIds.Length; i++) { int targetId = targetIds[i]; if (targetId >= 0) { //英雄攻击 targetModels[i] = room.GetHeroModel(targetId); } else if (targetId <= -100 && targetId > -300) { //防御塔的攻击 targetModels[i] = room.GetBuildModel(targetId); } else if (targetId <= -1000) { //小兵的攻击 targetModels[i] = room.GetDogModel(targetId); } } //3、根据技能id 普通攻击 特殊技能 ISkill skill = null; List <DamageModel> damages = null; if (skillId == 1) { //普通攻击 skill = DamageData.GetSkill(skillId); //4、根据技能id获取damage计算伤害 damages = skill.Damage(skillId, 0, attackModel, targetModels); //5、检测死亡 给钱 给经验 } else { //特殊技能 skill = DamageData.GetSkill(skillId); //4、根据技能id获取damage计算伤害 HeroModel hero = attackModel as HeroModel; SkillModel skillModel = hero.GetSkillModel(skillId); damages = skill.Damage(skillId, skillModel.Level, attackModel, targetModels); //5、检测死亡 给钱 给经验 } //6、给房间内的客户端广播数据模型 room.Brocast(OpCode.FightCode, OpFight.Damage, 0, "有伤害产生", null, JsonMapper.ToJson(damages.ToArray())); //结算 foreach (DogModel item in targetModels) { if (item.CurrHp == 0) { switch (item.ModelType) { case ModelType.HERO: #region 英雄 if (attackModel.Id >= 0) { ((HeroModel)attackModel).Kill++; ((HeroModel)attackModel).AddProprity(300, 50); if (((HeroModel)attackModel).Exp > ((HeroModel)attackModel).Level * 100) { ((HeroModel)attackModel).Level++; ((HeroModel)attackModel).SkillPoints++; ((HeroModel)attackModel).Exp = 0; HeroDataModel data = HeroData.GetHeroData(attackModel.Id); ((HeroModel)attackModel).Attack += data.GrowAttack; ((HeroModel)attackModel).Defense += data.GrowDefens; ((HeroModel)attackModel).MaxHp += data.GrowHp; ((HeroModel)attackModel).MaxMp += data.GrowMp; } //给客户端发送数据模型 attackModel room.Brocast(OpCode.FightCode, OpFight.UpdateModel, 0, "更新数据模型", null, JsonMapper.ToJson(attackModel as HeroModel)); } //目标英雄死亡 ((HeroModel)item).Dead++; //开启定时任务 复活 room.StartSchedule(DateTime.UtcNow.AddSeconds( (double)((HeroModel)item).Level * 5), () => { ((HeroModel)item).CurrHp = ((HeroModel)item).MaxHp; //给客户端发送复活消息 room.Brocast(OpCode.FightCode, OpFight.Resurge, 0, "有模型复活了", null, JsonMapper.ToJson(item as HeroModel)); }); #endregion break; case ModelType.BUILD: #region 建筑 //判断是否英雄击杀 if (attackModel.Id >= 0) { ((HeroModel)attackModel).AddProprity(150, 0); //给客户端发送数据模型 attackModel room.Brocast(OpCode.FightCode, OpFight.UpdateModel, 0, "更新数据模型", null, JsonMapper.ToJson(attackModel as HeroModel)); } //防御塔是否可以重生 if (((BuildModel)item).ReBirth) { //开启定时任务 复活塔 room.StartSchedule(DateTime.UtcNow.AddSeconds( (double)(((BuildModel)item).ReBirthTime)), () => { ((BuildModel)item).CurrHp = ((BuildModel)item).MaxHp; //给客户端发送复活消息 room.Brocast(OpCode.FightCode, OpFight.Resurge, 1, "有模型复活了", null, JsonMapper.ToJson(item as BuildModel)); }); } else { room.RemoveBuild((BuildModel)item); } //游戏结束判断 if (item.Id == -100) { //队伍2赢了 OnGameOver(room, 2); } else if (item.Id == -200) { //队伍1赢了 OnGameOver(room, 1); } #endregion break; case ModelType.DOG: #region 小兵 //英雄攻击 if (attackModel.Id >= 0) { ((HeroModel)attackModel).AddProprity(20, 10); if (((HeroModel)attackModel).Exp > ((HeroModel)attackModel).Level * 100) { ((HeroModel)attackModel).Level++; ((HeroModel)attackModel).SkillPoints++; ((HeroModel)attackModel).Exp = 0; HeroDataModel data = HeroData.GetHeroData(attackModel.Id); ((HeroModel)attackModel).Attack += data.GrowAttack; ((HeroModel)attackModel).Defense += data.GrowDefens; ((HeroModel)attackModel).MaxHp += data.GrowHp; ((HeroModel)attackModel).MaxMp += data.GrowMp; } //给客户端发送数据模型 attackModel room.Brocast(OpCode.FightCode, OpFight.UpdateModel, 0, "更新数据模型", null, JsonMapper.ToJson(attackModel as HeroModel)); } //移除小兵 room.RemoveDog(item); #endregion break; default: break; } } } }
/// <summary> /// 计算伤害 /// </summary> private void onDamage(MobaClient client, int attackId, int skillId, int[] targetId) { //1.获取房间模型 int playerid = playerCache.GetId(client); FightRoom room = fightCache.GetRoom(playerid); //2.判断是谁攻击 谁被攻击 //攻击者的数据模型 DogModel attackModel = null; if (attackId >= 0) { //攻击者的ID大于等于0 就是英雄攻击 attackModel = room.GetHeroModel(attackId); } else if (attackId <= -10 && attackId >= -30) { //ID为-10~-30 防御塔攻击 attackModel = room.GetBuildModel(attackId); } else if (attackId <= -1000) { //小兵攻击 attackModel = room.GetDogModel(attackId); } //被攻击者的数据模型 DogModel[] targetModels = new DogModel[targetId.Length]; for (int i = 0; i < targetId.Length; i++) { if (targetId[i] >= 0) { //被攻击者的ID大于等于0 就是英雄被攻击 targetModels[i] = room.GetHeroModel(targetId[i]); } else if (targetId[i] <= -10 && targetId[i] >= -30) { //ID为-10~-30 防御塔被攻击 targetModels[i] = room.GetBuildModel(targetId[i]); } else if (targetId[i] <= -1000) { //小兵被攻击 targetModels[i] = room.GetDogModel(targetId[i]); } } //3.根据技能ID判断出 是 普通攻击 还是特殊技能 //4.根据伤害表 根据技能id获取ISKILL 调用damage 计算伤害 ISkill skill = null; List <DamageModel> damages = null; //获取skill skill = DamageData.GetSkill(skillId); //计算出伤害 damages = skill.Damage(skillId, 0, attackModel, targetModels); //6.给房间内的客户端广播数据模型 room.Brocast(OpCode.FightCode, OpFight.Damage, 0, "有伤害产生", null, JsonMapper.ToJson(damages.ToArray())); //结算 foreach (DogModel item in targetModels) { if (item.CurrHp <= 0) { switch (item.ModelType) { case ModelType.DOG: #region 小兵 //如果是英雄攻击导致死亡 那么就给奖励 if (attackModel.Id >= 0) { //加钱 ((HeroModel)attackModel).Money += 20; //加经验 ((HeroModel)attackModel).Exp += 20; //检测是否升级 if (((HeroModel)attackModel).Exp > ((HeroModel)attackModel).Level * 100) { //升级 ((HeroModel)attackModel).Level++; ((HeroModel)attackModel).Points++; //重置经验值 ((HeroModel)attackModel).Exp = 0; HeroDataModel data = HeroData.GetHeroData(attackModel.Id); //英雄成长属性 增加 ((HeroModel)attackModel).Attack += data.GrowAttack; ((HeroModel)attackModel).Defense += data.GrowDefense; ((HeroModel)attackModel).MaxHp += data.GrowHp; ((HeroModel)attackModel).MaxMp += data.GrowMp; } //给客户端发送 这个数据模型 attackModel 客户端更新 room.Brocast(OpCode.FightCode, OpFight.UpdateModel, 0, "更新数据模型", null, JsonMapper.ToJson((HeroModel)attackModel)); } //移除小兵 room.RemoveDog(item); #endregion break; case ModelType.BUILD: #region 建筑 //判断是不是英雄击杀 if (attackModel.Id >= 0) { //加钱 ((HeroModel)attackModel).Money += 150; //给客户端发attackModel room.Brocast(OpCode.FightCode, OpFight.UpdateModel, 0, "更新数据模型", null, JsonMapper.ToJson((HeroModel)attackModel)); } //检测防御塔是否可重生 if (((BuildModel)item).Rebirth) { //开启一个定时任务 在指定的事件之后复活 room.StartSchedule(DateTime.UtcNow.AddSeconds((double)((BuildModel)item).RebirthTime), () => { //满状态 ((BuildModel)item).CurrHp = ((BuildModel)item).MaxHp; //给客户端发送一个复活的消息 参数 item room.Brocast(OpCode.FightCode, OpFight.Resurge, 1, "有模型复活", null, JsonMapper.ToJson((BuildModel)item)); }); } //不重生 直接移除数据模型 else { room.RemoveBuild((BuildModel)item); } //游戏结束的判断 if (item.Id == -10) { onGameOver(room, 2); } else if (item.Id == -20) { onGameOver(room, 1); } #endregion break; case ModelType.HERO: #region 英雄 //发奖励 if (attackModel.Id >= 0) { //加杀人数 ((HeroModel)attackModel).Kill++; //加钱 ((HeroModel)attackModel).Money += 300; //加经验 ((HeroModel)attackModel).Exp += 50; //检测是否升级 if (((HeroModel)attackModel).Exp > ((HeroModel)attackModel).Level * 100) { //升级 ((HeroModel)attackModel).Level++; ((HeroModel)attackModel).Points++; //重置经验值 ((HeroModel)attackModel).Exp = 0; HeroDataModel data = HeroData.GetHeroData(attackModel.Id); //英雄成长属性 增加 ((HeroModel)attackModel).Attack += data.GrowAttack; ((HeroModel)attackModel).Defense += data.GrowDefense; ((HeroModel)attackModel).MaxHp += data.GrowHp; ((HeroModel)attackModel).MaxMp += data.GrowMp; } //给客户端发送 这个数据模型 attackModel 客户端更新 room.Brocast(OpCode.FightCode, OpFight.UpdateModel, 0, "更新数据模型", null, JsonMapper.ToJson((HeroModel)attackModel)); } //目标英雄死亡 //加死亡数 ((HeroModel)item).Dead++; //开启一个定时任务 在指定的事件之后复活 room.StartSchedule(DateTime.UtcNow.AddSeconds(((HeroModel)attackModel).Level * 5), () => { //满状态 ((HeroModel)item).CurrHp = ((HeroModel)item).MaxHp; //给客户端发送一个复活的消息 参数 item room.Brocast(OpCode.FightCode, OpFight.Resurge, 0, "有模型复活", null, JsonMapper.ToJson((HeroModel)item)); }); #endregion break; default: break; } } } }