public void Update(float dt) { List <Arena> arenas = CacheManager.instance.arenas; for (int i = 0; i < arenas.Count; i++) { Arena a = arenas[i]; a.Update(dt); if (a.elapsedTime >= Arena.battleTime) { //通知战斗结束 NotifyArenaEnd notify = new NotifyArenaEnd(); notify.blueKillCount = a.blueKillCount; notify.redKillCount = a.redKillCount; if (notify.blueKillCount > notify.redKillCount) { notify.winteam = (int)ETeam.Blue; } else if (notify.blueKillCount < notify.redKillCount) { notify.winteam = (int)ETeam.Red; } else { notify.winteam = (int)ETeam.None; } for (int j = 0; j < a.accounts.Count; j++) { AccountData acc = a.accounts[j]; TankKillData d = new TankKillData(); d.account = acc.account; d.deathCount = acc.deathCount; d.hurt = acc.hurt; d.kill = acc.killCount; d.team = (int)acc.team; notify.datas.Add(d); acc.killCount = 0; acc.team = ETeam.None; acc.hurt = 0; acc.deathCount = 0; } MsgSender.SendAll <NotifyArenaEnd>(a.accounts, (int)MsgID.NotifyArenaEnd, notify); arenas.Remove(a); } } }
void ArenaTankDeath(AccountData acc, AccountData enemy, Battle battle) { Arena arena = battle as Arena; if (acc.team == ETeam.Blue) { arena.blueKillCount++; } else { arena.redKillCount++; } if (arena.blueKillCount >= 5 || arena.redKillCount >= 5) { //通知战斗结束 NotifyArenaEnd notify = new NotifyArenaEnd(); notify.blueKillCount = arena.blueKillCount; notify.redKillCount = arena.redKillCount; if (notify.blueKillCount > notify.redKillCount) { notify.winteam = (int)ETeam.Blue; } else if (notify.blueKillCount < notify.redKillCount) { notify.winteam = (int)ETeam.Red; } else { notify.winteam = (int)ETeam.None; } for (int i = 0; i < arena.accounts.Count; i++) { AccountData accData = arena.accounts[i]; TankKillData d = new TankKillData(); d.account = accData.account; d.deathCount = accData.deathCount; d.hurt = accData.hurt; d.kill = accData.killCount; d.team = (int)acc.team; notify.datas.Add(d); accData.killCount = 0; accData.team = ETeam.None; accData.hurt = 0; accData.deathCount = 0; } MsgSender.SendAll <NotifyArenaEnd>(arena.accounts, (int)MsgID.NotifyArenaEnd, notify); arena.timers.Clear(); CacheManager.instance.arenas.Remove(arena); } else { Timer timer = new Timer(3f, () => { Tank t = arena.GetTank(enemy.account); if (t == null) { return; } t.hp = 100; //真随机 Random r = new Random(System.Guid.NewGuid().GetHashCode()); t.pos = SpawnPoint.point[r.Next(0, 5)]; NotifyReborn notify = new NotifyReborn(); notify.tank = new TankDTO(); notify.tank.id = t.uid; notify.tank.hp = t.hp; notify.tank.pos = Tools.ToVec_3(t.pos); notify.tank.color = Tools.UC2TC(t.color); notify.tank.team = (int)t.team; notify.tank.nickName = t.nickName; MsgSender.SendAll <NotifyReborn>(arena.accounts, (int)MsgID.NotifyReborn, notify); }); arena.timers.Add(timer); } }
private void OnReqHit(UserToken token, SocketModel model) { ReqHit req = SerializeUtil.Deserialize <ReqHit>(model.message); if (req.bulletPos == null) { return; } Random r = new Random(); var atk = r.Next(10, 20); AccountData acc = CacheManager.instance.GetAccount(token.accountid); AccountData enemy = CacheManager.instance.GetAccount(req.enemy); if (acc.battleType == EBattle.Arena && acc.team == enemy.team) { return; } Battle battle = CacheManager.instance.GetBattle(acc.battleid, acc.battleType); if (battle == null) { return; } Tank t = battle.GetTank(req.enemy); Tank attacker = battle.GetTank(acc.account); if (t != null && t.hp > 0 && attacker != null && attacker.hp > 0) { Console.WriteLine(Vector3.Distance(Tools.ToLunaVec3(req.bulletPos), t.pos)); //校验子弹和敌人的坐标 if (Vector3.Distance(Tools.ToLunaVec3(req.bulletPos), t.pos) > 2.5f) { return; } // Console.WriteLine(Time.time * 0.001f - attacker.lastHitTime); ////校验两次命中时间 // if (Time.time * 0.001f - attacker.lastHitTime < 0.7f) return; attacker.lastHitTime = Time.time * 0.001f; t.hp -= atk; //伤害统计 acc.hurt += atk; NotifyHit notify = new NotifyHit(); notify.id = req.enemy; notify.damage = atk; MsgSender.SendAll <NotifyHit>(battle.accounts, (int)MsgID.NotifyHit, notify); //死亡 if (t.hp <= 0) { t.hp = 0; acc.killCount++; enemy.deathCount++; //通知所有人有个坦克死了 NotifyDeath not = new NotifyDeath(); not.id = req.enemy; MsgSender.SendAll <NotifyDeath>(battle.accounts, (int)MsgID.NotifyDeath, not); if (battle.type == EBattle.Survival) { SurvivalTankDeath(acc, enemy, battle); } else { ArenaTankDeath(acc, enemy, battle); } } } }
private void OnReqEnterRoom(UserToken token, SocketModel model) { ReqEnterRoom req = SerializeUtil.Deserialize <ReqEnterRoom>(model.message); AccountData acc = CacheManager.instance.GetAccount(token.accountid); if (acc.roomid != 0) { return; } Room r = CacheManager.instance.GetWaitRoom((EBattle)req.battleType, req.limitNumber); r.AddAccount(acc); RspEnterRoom rsp = new RspEnterRoom(); rsp.roomid = r.roomid; NetworkManager.Send <RspEnterRoom>(token, (int)MsgID.RspEnterRoom, rsp); //房间满 if (r.accounts.Count >= r.limtNum) { Battle b = null; if (req.battleType == (int)EBattle.Arena) { b = CacheManager.instance.CreateArena(r.limtNum, r.accounts); } else { b = CacheManager.instance.CreateSurvival(r.limtNum, r.accounts); } //清空roomid for (int i = 0; i < r.accounts.Count; i++) { r.accounts[i].roomid = 0; } //通知战斗开始 NotifyBattleStart notify = new NotifyBattleStart(); notify.battleid = b.battleid; notify.battleType = req.battleType; notify.numberLimit = req.limitNumber; List <Tank> tanks = b.GetALLTanks(); for (int i = 0; i < tanks.Count; i++) { Tank t1 = tanks[i]; TankDTO dto = new TankDTO(); dto.id = t1.uid; dto.hp = t1.hp; dto.nickName = t1.nickName; dto.pos = Tools.ToVec_3(t1.pos); dto.color = Tools.UC2TC(t1.color); dto.team = (int)t1.team; notify.tanks.Add(dto); } MsgSender.SendAll <NotifyBattleStart>(r.accounts, (int)MsgID.NotifyBattleStart, notify); CacheManager.instance.RemoveRoom(r.roomid); } }