Exemplo n.º 1
0
 public void ToAnswer(out ISkill skill, out List <Card> cards, out List <Player> players, int wrtPlayerId)
 {
     skill = null;
     if (SkillItem != null)
     {
         skill = SkillItem.ToSkill();
     }
     cards = new List <Card>();
     if (CardItems != null)
     {
         foreach (var card in CardItems)
         {
             cards.Add(card.ToCard(wrtPlayerId));
         }
         if (cards.Any(c => c == null))
         {
             cards = new List <Card>();
         }
     }
     players = new List <Player>();
     if (PlayerItems != null)
     {
         players = new List <Player>();
         foreach (var player in PlayerItems)
         {
             players.Add(player.ToPlayer());
         }
         if (players.Any(p => p == null))
         {
             players = new List <Player>();
         }
     }
 }
Exemplo n.º 2
0
        public static AskForCardUsageResponse Parse(int id, ISkill skill, List <Card> cards, List <Player> players, int wrtPlayerId)
        {
            AskForCardUsageResponse response = new AskForCardUsageResponse();

            response.Id        = id;
            response.SkillItem = SkillItem.Parse(skill);
            if (cards == null)
            {
                response.CardItems = null;
            }
            else
            {
                response.CardItems = new List <CardItem>();
                foreach (var card in cards)
                {
                    response.CardItems.Add(CardItem.Parse(card, wrtPlayerId));
                }
            }
            if (players == null)
            {
                response.PlayerItems = null;
            }
            else
            {
                response.PlayerItems = new List <PlayerItem>();
                foreach (var player in players)
                {
                    response.PlayerItems.Add(PlayerItem.Parse(player));
                }
            }
            return(response);
        }
Exemplo n.º 3
0
        public static SkillItem Parse(ISkill skill)
        {
            if (skill == null)
            {
                return(null);
            }
            SkillItem result;

            if (skill is CheatSkill)
            {
                CheatSkillItem csi = new CheatSkillItem();
                CheatSkill     cs  = skill as CheatSkill;
                result        = csi;
                csi.CardId    = cs.CardId;
                csi.CheatType = (int)cs.CheatType;
                csi.SkillName = cs.SkillName;
            }
            else if (skill is IAdditionalTypedSkill)
            {
                var atsi = new AdditionalTypedSkillItem();
                var ats  = skill as IAdditionalTypedSkill;
                result = atsi;
                atsi.AdditionalTypeId = GameEngine.Serialize(ats.AdditionalType);
            }
            else
            {
                result = new SkillItem();
            }

            result.PlayerItem = PlayerItem.Parse(skill.Owner);
            if (skill.Owner != null)
            {
                result.SkillId = (byte)skill.Owner.ActionableSkills.IndexOf(skill);
            }
            return(result);
        }
Exemplo n.º 4
0
 public static ISkill Translate(SkillItem item)
 {
     if (item.playerId >= 0 && item.playerId < Game.CurrentGame.Players.Count)
     {
         foreach (var skill in Game.CurrentGame.Players[item.playerId].ActionableSkills)
         {
             if (skill.GetType().Name.Equals(item.name))
             {
                 if (skill is IAdditionalTypedSkill)
                 {
                     (skill as IAdditionalTypedSkill).AdditionalType = TranslateCardType(item.additionalType, item.additionalTypeHorseName);
                 }
                 return skill;
             }
         }
     }
     return null;
 }
Exemplo n.º 5
0
 public static SkillItem Translate(ISkill skill)
 {
     SkillItem item = new SkillItem();
     item.playerId = skill.Owner.Id;
     item.name = skill.GetType().Name;
     if (skill is IAdditionalTypedSkill)
     {
         item.additionalType = (skill as IAdditionalTypedSkill).AdditionalType.GetType();
     }
     return item;
 }
Exemplo n.º 6
0
 public object Receive()
 {
     object o = null;
     ItemType type = ItemType.Serializable;
     try
     {
         type = (ItemType)deserializer.DeserializeInt();
         Trace.TraceInformation("Trying to parse a {0}", type);
         switch (type)
         {
             case ItemType.CardItem:
                 var cardItem = new CardItem();
                 cardItem.playerId = deserializer.DeserializeInt();
                 cardItem.place = deserializer.DeserializeInt();
                 cardItem.rank = deserializer.DeserializeInt();
                 cardItem.suit = deserializer.DeserializeInt();
                 cardItem.id = deserializer.DeserializeInt();
                 cardItem.deckName = deserializer.DeserializeString();
                 cardItem.typeName = deserializer.DeserializeString();
                 cardItem.typeHorseName = deserializer.DeserializeString();
                 o = cardItem;
                 break;
             case ItemType.Player:
                 int? id = deserializer.DeserializeNInt();
                 o = (id == null ? null : Game.CurrentGame.Players[(int)id]);
                 break;
             case ItemType.Int:
                 o = deserializer.DeserializeInt();
                 break;
             case ItemType.SkillItem:
                 var skillItem = new SkillItem();
                 skillItem.playerId = deserializer.DeserializeInt();
                 skillItem.skillId = deserializer.DeserializeInt();
                 skillItem.name = deserializer.DeserializeString();
                 skillItem.additionalTypeName = deserializer.DeserializeString();
                 skillItem.additionalTypeHorseName = deserializer.DeserializeString();
                 o = skillItem;
                 break;
             case ItemType.CommandItem:
                 CommandItem item = new CommandItem();
                 item.command = (Command)deserializer.DeserializeInt();
                 item.type = (ItemType)deserializer.DeserializeInt();
                 if (item.type == ItemType.Int)
                     item.data = deserializer.DeserializeInt();
                 else if (item.type == ItemType.HandCardMovement)
                     item.data = deserializer.Deserialize(typeof(HandCardMovement));
                 else if (item.type == ItemType.CardRearrangement)
                     item.data = deserializer.Deserialize(typeof(CardRearrangement));
                 else if (item.type == ItemType.CardUsageResponded)
                     item.data = deserializer.Deserialize(typeof(CardUsageResponded));
                 o = item;
                 break;
             case ItemType.ValueType:
                 Type objectType = Type.GetType(deserializer.DeserializeString());
                 o = deserializer.Deserialize(objectType);
                 break;
             case ItemType.Serializable:
                 o = formatter.Deserialize(stream);
                 break;
             default:
                 o = null;
                 Trace.TraceError("Unknown item type: {0}", type);
                 break;
         }
     }
     catch (Exception e)
     {
         Trace.TraceError("Error occured when trying to deserialize an {0}, {1}. ", type, e.StackTrace);
         return null;
     }
     return o;
 }
Exemplo n.º 7
0
        public static SkillItem Parse(ISkill skill)
        {
            if (skill == null) return null;
            SkillItem result;
            if (skill is CheatSkill)
            {
                CheatSkillItem csi = new CheatSkillItem();
                CheatSkill cs = skill as CheatSkill;
                result = csi;
                csi.CardId = cs.CardId;
                csi.CheatType = (int)cs.CheatType;
                csi.SkillName = cs.SkillName;
            }
            else if (skill is IAdditionalTypedSkill)
            {
                var atsi = new AdditionalTypedSkillItem();
                var ats = skill as IAdditionalTypedSkill;
                result = atsi;
                atsi.AdditionalTypeId = GameEngine.Serialize(ats.AdditionalType);
            }
            else
            {
                result = new SkillItem();
            }

            result.PlayerItem = PlayerItem.Parse(skill.Owner);
            if (skill.Owner != null)
            {
                result.SkillId = (byte)skill.Owner.ActionableSkills.IndexOf(skill);
            }
            return result;
        }
Exemplo n.º 8
0
 private void QueueSkill(SkillItem skill)
 {
     serializer.Serialize(ItemType.SkillItem);
     serializer.Serialize(skill.playerId);
     serializer.Serialize(skill.skillId);
     serializer.Serialize(skill.name ?? string.Empty);
     serializer.Serialize(skill.additionalTypeName ?? string.Empty);
     serializer.Serialize(skill.additionalTypeHorseName ?? string.Empty);
 }
Exemplo n.º 9
0
 private void QueueSkill(SkillItem skill)
 {
     formatter.Serialize(stream, skill);
 }
Exemplo n.º 10
0
        public static ISkill EncodeSkill(SkillItem item)
        {
            if (item.playerId >= 0 && item.playerId < Game.CurrentGame.Players.Count)
            {
                if (Game.CurrentGame.Players[item.playerId].ActionableSkills.Count <= item.skillId)
                {
                    Trace.TraceWarning("Client sending invalid skills");
                    return null;
                }

                ISkill skill = Game.CurrentGame.Players[item.playerId].ActionableSkills[item.skillId];
            #if DEBUG
                Trace.Assert(item.name == skill.GetType().Name);
            #endif
                if (skill is IAdditionalTypedSkill)
                {
                    (skill as IAdditionalTypedSkill).AdditionalType = DecodeCardHandler(item.additionalTypeName, item.additionalTypeHorseName);
                }
                return skill;
            }
            return null;
        }
Exemplo n.º 11
0
 public static SkillItem EncodeSkill(ISkill skill)
 {
     SkillItem item = new SkillItem();
     item.playerId = skill.Owner.Id;
     item.name = skill.GetType().Name;
     item.skillId = Game.CurrentGame.Players[skill.Owner.Id].ActionableSkills.IndexOf(skill);
     Trace.Assert(item.skillId >= 0);
     if (skill is IAdditionalTypedSkill)
     {
         var type = (skill as IAdditionalTypedSkill).AdditionalType;
         string horseName;
         EncodeCardHandler(type, out item.additionalTypeName, out horseName);
     }
     return item;
 }
Exemplo n.º 12
0
 public static SkillItem Translate(ISkill skill)
 {
     SkillItem item = new SkillItem();
     item.playerId = skill.Owner.Id;
     item.name = skill.GetType().Name;
     item.skillId = Game.CurrentGame.Players[skill.Owner.Id].ActionableSkills.IndexOf(skill);
     Trace.Assert(item.skillId >= 0);
     if (skill is IAdditionalTypedSkill)
     {
         item.additionalType = (skill as IAdditionalTypedSkill).AdditionalType.GetType();
     }
     return item;
 }