Esempio n. 1
0
        public LookupModel(string key, SectorModel sector, LookupRules rules, PlayerModel player, bool readOnly)
            : base(key)
        {
            this.Cards = new ModelCollection(this);

              this.Player = player;
              this.ReadOnly = readOnly;
              this.Sector = sector;
              this.Rules = rules;
              if(rules == null)
            this.Rules = new LookupRules(LookupStyle.All, -1, new List<string>());

              int i = 0;
              switch(rules.Style)
              {
            case LookupStyle.All:
            case LookupStyle.KeepVisibleTop:
            case LookupStyle.Top:
              this.Sector.Cards.CollectionChanged += new CollectionChangedEventHandler(Cards_CollectionChanged);
              for(i = 0; i < sector.Cards.Count(); i++)
              {
            if(this.Rules.Style == LookupStyle.Top && i < Rules.Amount)
              visibleCards.Add(sector.Cards.ElementAt(i).Key);
            InsertCard(sector.Cards.ElementAt(i).Key, i);
              }
              break;
              }
        }
 void Log(SectorModel sector)
 {
     string playerName = Receiver.GetPlayerByKey(Invoker).Info.NickName;
       string commandName = Receiver.GetCommandByKey(COMMANDCODE).Data.Name;
       Receiver.Console.WriteLog(string.Concat(
     "[", playerName, "] ", commandName, " ", sector.Data.Name));
 }
 void Log(CardModel pawn, SectorModel sector)
 {
     string playerName = Receiver.GetPlayerByKey(Invoker).Info.NickName;
       string commandName = Receiver.GetCommandByKey(COMMANDCODE).Data.Name;
       MessageContent logContent = new MessageContent(string.Concat("[", playerName, "] ", commandName, " "));
       logContent.Add(CardLogger.EncodeCardSmartName(pawn));
       Receiver.Console.WriteLog(logContent);
 }
 void Log(SectorModel sector, LookupRules rules)
 {
     string playerName = Receiver.GetPlayerByKey(Invoker).Info.NickName;
       string destinationPlayerName = Receiver.GetPlayerByKey(Arguments.DestinationPlayerKey).Info.NickName;
       bool show = Invoker != Arguments.DestinationPlayerKey;
       string commandName = string.Empty;
       switch(Arguments.Mode)
       {
     case LookupOpenMode.All:
       commandName = Receiver.GetCommandByKey(show ? COMMANDCODE_SHOW_ALL : COMMANDCODE_WATCH_ALL).Data.Name;
       break;
     case LookupOpenMode.KeepVisibleTop:
       commandName = Receiver.GetCommandByKey(COMMANDCODE_KEEP_VISIBLE_TOP).Data.Name;
       break;
     case LookupOpenMode.Top:
       commandName = Receiver.GetCommandByKey(show ? COMMANDCODE_SHOW_TOP : COMMANDCODE_WATCH_TOP).Data.Name;
       break;
       }
       commandName = commandName.Replace("#amount#", Arguments.Amount.ToString());
       string message = string.Concat("[", playerName, "] ", commandName, " (");
       if(!show && sector.Parent.Key != Invoker)
     message += string.Concat(Receiver.GetPlayerByKey(sector.Parent.Key).Info.NickName, "-");
       message += string.Concat(sector.Data.Name, ")");
       if(show)
     message += string.Concat(">", destinationPlayerName);
       Receiver.Console.WriteLog(message);
 }
Esempio n. 5
0
        public static void LogMovement(GameModel game, string executorPlayerKey, CardModel card, SectorModel fromSector, 
            SectorModel toSector, int fromIndex, int toIndex, CardVisibility? toCardVisibility, bool verbose)
        {
            if(fromSector.Key == toSector.Key && fromSector.Data.Behavior != SectorBehavior.Simple)
            return;

              IEnumerable<SectorModel> sectors = game.Players.Cast<PlayerModel>().SelectMany(e => e.Sectors).Cast<SectorModel>();
              SectorCardsVisibility fromSectorVisibility = sectors.First(e => e.Data.Code == fromSector.Data.Code).Data.CardsVisibility;
              SectorCardsVisibility toSectorVisibility = sectors.First(e => e.Data.Code == toSector.Data.Code).Data.CardsVisibility;

              PlayerModel fromPlayer = (PlayerModel)fromSector.Parent;
              PlayerModel toPlayer = (PlayerModel)toSector.Parent;
              PlayerModel executorPlayer = game.GetPlayerByKey(executorPlayerKey);

              MessageContent logContent = new MessageContent();
              StringBuilder logText = new StringBuilder(200);

              if(verbose)
              {
            logText.Append("[").Append(executorPlayer.Info.NickName).Append("] ");
            logText.Append(game.GetCommandByKey(MoveCardsCommand.COMMANDCODE_SINGLE).Data.Name).Append(" ");
              }

              bool fromVisible = fromSectorVisibility == SectorCardsVisibility.Visibile ||
            (fromSectorVisibility == SectorCardsVisibility.Private && fromPlayer.Key == game.ActivePlayer.Key);
              if(fromVisible)
              {
            fromVisible = (card.Visibility.Value == CardVisibility.Visible ||
              (card.Visibility.Value == CardVisibility.Private && fromPlayer.Key == game.ActivePlayer.Key));
              }
              bool toVisible = toSectorVisibility == SectorCardsVisibility.Visibile ||
            (toSectorVisibility == SectorCardsVisibility.Private && toPlayer.Key == game.ActivePlayer.Key);
              if(toVisible)
              {
            if(toCardVisibility.HasValue)
              toVisible = (toCardVisibility.Value == CardVisibility.Visible ||
            (toCardVisibility.Value == CardVisibility.Private && toPlayer.Key == game.ActivePlayer.Key));
            else
              toVisible = (card.Visibility.Value == CardVisibility.Visible ||
            (card.Visibility.Value == CardVisibility.Private && toPlayer.Key == game.ActivePlayer.Key));
              }
              logContent.Add(logText.ToString());
              logText.Length = 0;
              logContent.Add(EncodeCardSmartName(card, fromVisible || toVisible));
              if(verbose)
              {
            logText.Append(" (");
            if(fromPlayer.Key != executorPlayerKey)
              logText.Append(fromPlayer.Info.NickName).Append("-");
            logText.Append(fromSector.Data.Name);
            if(fromSector.Data.Behavior == SectorBehavior.Simple)
              logText.Append("[").Append(fromIndex + 1).Append("]");
            logText.Append(">");
            if(toPlayer.Key != executorPlayerKey)
              logText.Append(toPlayer.Info.NickName).Append("-");
            logText.Append(toSector.Data.Name);
            if(toSector.Data.Behavior == SectorBehavior.Simple)
              logText.Append("[").Append(toIndex + 1).Append("]");
            logText.Append(")");
              }
              else
              {
            if(fromSector.Data.Behavior == SectorBehavior.Simple)
              logText.Append("[").Append(fromIndex + 1).Append("]");
            if(toSector.Data.Behavior == SectorBehavior.Simple)
              logText.Append("[").Append(toIndex + 1).Append("]");
              }
              logContent.Add(logText.ToString());
              game.Console.WriteLog(logContent);
        }
 void Log(SectorModel sourceSector, MoveCardsSourceMode sourceMode, SectorModel destinationSector, int amount)
 {
     string playerName = Receiver.GetPlayerByKey(Invoker).Info.NickName;
       string commandName = string.Empty;
       switch(sourceMode)
       {
     case MoveCardsSourceMode.Specific:
       commandName = Receiver.GetCommandByKey(COMMANDCODE_MULTIPLE).Data.Name;
       commandName = commandName.Replace("#amount#", Arguments.CardKeys.Count.ToString());
       break;
     case MoveCardsSourceMode.Random:
       commandName = Receiver.GetCommandByKey(COMMANDCODE_RANDOM).Data.Name;
       commandName = commandName.Replace("#amount#", Arguments.Amount.ToString());
       break;
       }
       Receiver.Console.WriteLog(string.Concat(
     "[", playerName, "] ",
     commandName, " (", sourceSector.Data.Name, ">", destinationSector.Data.Name, ")"
     ));
 }
        public override void Execute()
        {
            switch(Arguments.SourceMode)
              {
            case MoveCardsSourceMode.Random:
              sourceSector = Receiver.GetPlayerByKey(Invoker).Sectors.Cast<SectorModel>().Single(e => e.Data.Code == Arguments.SourceSectorCode);
              oldIndicies = Utils.GetUniqueRandomIndices(sourceSector.Cards.Count - 1, Arguments.Amount, randomSeed).OrderBy(e => e).ToList();
              movedCards = oldIndicies.Select(i => sourceSector.Cards[i]).Cast<CardModel>().ToList();
              break;
            case MoveCardsSourceMode.Specific:
              sourceSector = (SectorModel)Receiver.GetCardByKey(Arguments.CardKeys.First()).Parent;
              movedCards = Arguments.CardKeys.Select(k => sourceSector.Cards.Single(c => c.Key == k)).Cast<CardModel>().ToList();
              oldIndicies = movedCards.Select(c => sourceSector.Cards.IndexOf(c)).ToList();
              break;
              }

              var pawnIndicies = movedCards.Where(c => c.IsPawn).Select(c => sourceSector.Cards.IndexOf(c)).ToList();
              oldPositions = movedCards.Select(c => c.Position.Value).ToList();
              oldVisibilityStates = movedCards.Select(c => c.Visibility.Value).ToList();
              if(string.IsNullOrEmpty(Arguments.DestinationPlayerKey))
            destinationSectors = movedCards.Select(c => Receiver.GetPlayerByKey(c.Owner.Key).Sectors.Cast<SectorModel>().Single(e => e.Data.Code == Arguments.DestinationSectorCode)).ToList();
              else
            destinationSectors = Enumerable.Repeat(Receiver.GetPlayerByKey(Arguments.DestinationPlayerKey).Sectors.Cast<SectorModel>().Single(e => e.Data.Code == Arguments.DestinationSectorCode), movedCards.Count).ToList();

              if(
            (Arguments.SourceMode == MoveCardsSourceMode.Random) ||
            (Arguments.SourceMode == MoveCardsSourceMode.Specific && (Arguments.CardKeys.Count > 1))
            )
            Log(sourceSector, Arguments.SourceMode, destinationSectors.First(), movedCards.Count);

              for(int i = 0; i < movedCards.Count; i++)
              {
            int fromIndex = oldIndicies[i];
            int toIndex = (int)Arguments.Positions[i].Z;

            // log before move, movement can reset card state
            // log only if movement is across sectors or if sector is hidden (tipically in a hidden sector lookup)
            if(sourceSector != destinationSectors[i] || sourceSector.Data.CardsVisibility == SectorCardsVisibility.Hidden)
            {
              bool verbose = (Arguments.SourceMode == MoveCardsSourceMode.Specific && Arguments.CardKeys.Count == 1);
              CardLogger.LogMovement(Receiver, Invoker, movedCards[i], sourceSector, destinationSectors[i], fromIndex, toIndex, Arguments.Visibility, verbose);
            }

            if(sourceSector != destinationSectors[i])
            {
              sourceSector.Cards.Remove(movedCards[i]);

              bool acrossBattlefields = sourceSector.Data.Code == SystemSectors.BATTLEFIELD.ToString() && destinationSectors[i].Data.Code == SystemSectors.BATTLEFIELD.ToString();
              if(!acrossBattlefields)
            movedCards[i].Reset();

              if(acrossBattlefields || !movedCards[i].IsPawn)
              {
            movedCards[i].Position.Value = new CardPosition(Arguments.Positions[i].X, Arguments.Positions[i].Y, 0);
            if(Arguments.Visibility.HasValue)
              movedCards[i].Visibility.Value = Arguments.Visibility.Value;
            toIndex -= pawnIndicies.Count(pi => pi < toIndex); // pawn cannot move throught sectors, adjust subsequent card indexes to fill the gap
            destinationSectors[i].Cards.Insert(toIndex, movedCards[i]);
              }
            }
            else
            {
              sourceSector.Cards.Move(fromIndex, Math.Min(toIndex, sourceSector.Cards.Count - 1));
              movedCards[i].Position.Value = new CardPosition(Arguments.Positions[i].X, Arguments.Positions[i].Y, 0);
              if(Arguments.Visibility.HasValue)
            movedCards[i].Visibility.Value = Arguments.Visibility.Value;
            }
              }
        }
 void Log(PlayerModel destinationPlayer, SectorModel sector)
 {
     string playerName = Receiver.GetPlayerByKey(Invoker).Info.NickName;
     string commandName = string.Empty;
     switch(Arguments.Mode)
     {
       case DisplayCardsMode.ByKeys:
     commandName = Receiver.GetCommandByKey(COMMANDCODE_MULTIPLE).Data.Name;
     commandName = commandName.Replace("#amount#", Arguments.CardKeys.Count.ToString());
     break;
       case DisplayCardsMode.Random:
     commandName = Receiver.GetCommandByKey(COMMANDCODE_RANDOM).Data.Name;
     commandName = commandName.Replace("#amount#", Arguments.Amount.ToString());
     break;
     }
     Receiver.Console.WriteLog(string.Concat(
       "[", playerName, "] ",
       commandName, " (", sector.Data.Name, ")", ">", destinationPlayer.Info.NickName));
 }