예제 #1
0
        public override void Process()
        {
            var  newHero = m_Room.Players[m_UserId].Heros.Find(h => h.EntityId == m_Request.NewEntityId);
            var  oldHero = m_Room.Players[m_UserId].Heros.Find(h => h.EntityId == m_Request.OldEntityId);
            long now     = DateTime.UtcNow.Ticks;
            int  newHP   = Mathf.Min(Mathf.RoundToInt(newHero.MaxHP * newHero.RecoverHP * ((now - newHero.LastLeaveBattleTime) / TimeSpan.TicksPerSecond)) + newHero.HP, newHero.MaxHP);

            newHero.HP = newHP;
            oldHero.LastLeaveBattleTime = now;
            RCPushEntitySwitchHero pushPacket = new RCPushEntitySwitchHero()
            {
                PlayerId    = m_UserId,
                NewEntityId = m_Request.NewEntityId,
                OldEntityId = m_Request.OldEntityId,
                HP          = newHP,
            };

            byte[] bufferToOthers = CustomActionDispatcher.GeneratePackageStream((int)ActionType.RCPushEntitySwitchHero, ProtoBufUtils.Serialize(pushPacket));
            foreach (var player in m_Room.Players)
            {
                GameSession.Get(player.Key).SendAsync(bufferToOthers, 0, bufferToOthers.Length);
            }
            m_Room.Players[m_UserId].InBattleEntity = m_Request.NewEntityId;
            TraceLog.Write("{0} switch entity from {1} to {2}, now entity {3} is in battle", m_Room.Players[m_UserId].Name, m_Request.OldEntityId, m_Request.NewEntityId, m_Room.Players[m_UserId].InBattleEntity);
            m_Response.Result = true;
        }
예제 #2
0
 public Action5104(ActionGetter actionGetter)
     : base((short)5104, actionGetter)
 {
     m_RequestPacket  = null;
     m_ResponsePacket = null;
     m_UserId         = 0;
 }