Ejemplo n.º 1
0
 public List <KeyValuePair <int, string> > PlayerPiles(int id)
 {
     return(Player.Find((byte)id)
            .Groups.OfType <Pile>()
            .Select(g => new KeyValuePair <int, string>(g.Id, g.Name))
            .ToList());
 }
Ejemplo n.º 2
0
        /// <summary>Creates new Cards as well as the corresponding CardIdentities. All cards are created in the same group.</summary>
        /// <param name="id">An array with the new CardIdentity ids.</param>
        /// <param name="type">An array containing the corresponding CardModel guids (encrypted)</param>
        /// <param name="group">The group, in which the cards are added.</param>
        /// <seealso cref="CreateCard(int[], ulong[], Group[])"> to add cards to several groups</seealso>
        public void CreateCard(int[] id, Guid[] type, string[] size, Group group)
        {
            var who = Player.Find((byte)(id[0] >> 16));

            WriteReplayAction(who.Id);
            if (IsLocalPlayer(who))
            {
                return;
            }
            for (var i = 0; i < id.Length; i++)
            {
                var owner = group.Owner;
                if (owner == null)
                {
                    Program.GameMess.Warning("[CreateCard] Player not found.");
                    return;
                }
                var c = Card.Find(id[0]);

                Program.GameMess.PlayerEvent(owner, "{0} creates {1} {2} in {3}'s {4}", owner.Name, id.Length, c == null ? "card" : (object)c, group.Owner.Name, group.Name);
                // Ignore cards created by oneself

                var card = new Card(owner, id[i], Program.GameEngine.Definition.GetCardById(type[i]), false, size[i]); group.AddAt(card, group.Count);
            }
        }
Ejemplo n.º 3
0
        /// <summary>Loads a player deck.</summary>
        /// <param name="id">An array containing the loaded CardIdentity ids.</param>
        /// <param name="type">An array containing the corresponding CardModel guids (encrypted).</param>
        /// <param name="group">An array indicating the group the cards must be loaded into.</param>
        public void LoadDeck(int[] id, Guid[] type, Group[] group, string[] size, string sleeve, bool limited)
        {
            if (id.Length != type.Length || id.Length != group.Length)
            {
                Program.GameMess.Warning("[LoadDeck] Protocol violation: inconsistent arrays sizes.");
                return;
            }

            if (id.Length == 0)
            {
                return;                   // Loading an empty deck --> do nothing
            }
            var who = Player.Find((byte)(id[0] >> 16));

            if (who == null)
            {
                Program.GameMess.Warning("[LoadDeck] Player not found.");
                return;
            }
            if (limited)
            {
                Program.GameMess.System("{0} loads a limited deck.", who);
            }
            else
            {
                Program.GameMess.System("{0} loads a deck.", who);
            }
            CreateCard(id, type, group, size, sleeve);
            Log.Info("LoadDeck Starting Task to Fire Event");
            Program.GameEngine.EventProxy.OnLoadDeck_3_1_0_0(who, @group.Distinct().ToArray());
            Program.GameEngine.EventProxy.OnLoadDeck_3_1_0_1(who, @group.Distinct().ToArray());
            Program.GameEngine.EventProxy.OnDeckLoaded_3_1_0_2(who, @group.Distinct().ToArray());
        }
Ejemplo n.º 4
0
        public void RemoteCall(int playerid, string func, string args = "")
        {
            //if (args == null) args = new object[0];

            //var argString = Program.GameEngine.ScriptEngine.FormatObject(args);

            //var rargs = args.ToArray();
            //var sb = new StringBuilder();
            //for (var i = 0; i < rargs.Length; i++)
            //{
            //    var isLast = i == rargs.Length - 1;
            //    var a = rargs[i];
            //    if (a is Array)
            //    {
            //        var arr = a as Array;
            //        sb.Append("[");
            //        var argStrings = new List<string>();
            //        foreach (var o in arr)
            //        {
            //            argStrings.Add(Program.GameEngine.ScriptEngine.FormatObject(o));
            //        }
            //        sb.Append(string.Join(",", argStrings));
            //        sb.Append("]");
            //    }
            //    else
            //        sb.Append(Program.GameEngine.ScriptEngine.FormatObject(a));

            //    if (!isLast) sb.Append(", ");
            //}

            var player = Player.Find((byte)playerid);

            using (CreateMute())
                Program.Client.Rpc.RemoteCall(player, func, args);
        }
Ejemplo n.º 5
0
 public List <KeyValuePair <int, string> > PlayerCounters(int id)
 {
     return(Player.Find((byte)id)
            .Counters
            .Select(c => new KeyValuePair <int, string>(c.Id, c.Name))
            .ToList());
 }
Ejemplo n.º 6
0
 public void SetActivePlayer(int id, bool force)
 {
     if (Program.GameEngine.ActivePlayer == null || Program.GameEngine.ActivePlayer == Player.LocalPlayer)
     {
         Program.Client.Rpc.NextTurn(Player.Find((byte)id), true, force);
     }
 }
Ejemplo n.º 7
0
        /// <summary>Creates new cards on the table, as well as the corresponding CardIdentities.</summary>
        /// <param name="id">An array with the new CardIdentity ids</param>
        /// <param name="modelId"> </param>
        /// <param name="x">The x position of the cards on the table.</param>
        /// <param name="y">The y position of the cards on the table.</param>
        /// <param name="faceUp">Whether the cards are face up or not.</param>
        /// <param name="key"> </param>
        /// <param name="persist"> </param>
        public void CreateCardAt(int[] id, Guid[] modelId, int[] x, int[] y, bool faceUp, bool persist)
        {
            if (id.Length == 0)
            {
                Program.GameMess.Warning("[CreateCardAt] Empty id parameter.");
                return;
            }
            if (id.Length != x.Length || id.Length != y.Length || id.Length != modelId.Length)
            {
                Program.GameMess.Warning("[CreateCardAt] Inconsistent parameters length.");
                return;
            }
            var owner = Player.Find((byte)(id[0] >> 16));

            if (owner == null)
            {
                Program.GameMess.Warning("[CreateCardAt] Player not found.");
                return;
            }
            WriteReplayAction(owner.Id);
            var table = Program.GameEngine.Table;

            // Bring cards created by oneself to top, for z-order consistency
            if (IsLocalPlayer(owner))
            {
                for (var i = id.Length - 1; i >= 0; --i)
                {
                    var card = Card.Find(id[i]);
                    if (card == null)
                    {
                        Program.GameMess.Warning("[CreateCardAt] Card not found.");
                        return;
                    }
                    table.SetCardIndex(card, table.Count + i - id.Length);
                }
            }
            else
            {
                for (var i = 0; i < id.Length; i++)
                {
                    new CreateCard(owner, id[i], faceUp, Program.GameEngine.Definition.GetCardById(modelId[i]), x[i], y[i], !persist).Do();
                }
            }

            if (modelId.All(m => m == modelId[0]))
            {
                Program.GameMess.PlayerEvent(owner, "creates {1} '{2}'", owner, modelId.Length, IsLocalPlayer(owner) || faceUp ? Program.GameEngine.Definition.GetCardById(modelId[0]).Name : "card");
            }
            else
            {
                foreach (var m in modelId)
                {
                    Program.GameMess.PlayerEvent(owner, "{0} creates a '{1}'", owner, IsLocalPlayer(owner) || faceUp ? Program.GameEngine.Definition.GetCardById(m).Name : "card");
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>Loads a player deck.</summary>
        /// <param name="id">An array containing the loaded CardIdentity ids.</param>
        /// <param name="type">An array containing the corresponding CardModel guids (encrypted).</param>
        /// <param name="group">An array indicating the group the cards must be loaded into.</param>
        public void LoadDeck(int[] id, Guid[] type, Group[] group, string[] size, string sleeve, bool limited)
        {
            if (id.Length != type.Length || id.Length != group.Length)
            {
                Program.GameMess.Warning("[LoadDeck] Protocol violation: inconsistent arrays sizes.");
                return;
            }

            if (id.Length == 0)
            {
                return;                   // Loading an empty deck --> do nothing
            }
            var who = Player.Find((byte)(id[0] >> 16));

            if (who == null)
            {
                Program.GameMess.Warning("[LoadDeck] Player not found.");
                return;
            }
            WriteReplayAction(who.Id);

            if (limited)
            {
                Program.GameMess.System("{0} loads a limited deck.", who);
            }
            else
            {
                Program.GameMess.System("{0} loads a deck.", who);
            }

            if (!IsLocalPlayer(who))
            {
                try {
                    var sleeveObj = Sleeve.FromString(sleeve);

                    who.SetSleeve(sleeveObj);
                } catch (SleeveException ex) {
                    Log.Warn(ex.Message, ex);

                    Program.GameMess.Warning($"There was an error loading {0}'s deck sleeve: " + ex.Message, who);
                } catch (Exception ex) {
                    Log.Warn(ex.Message, ex);

                    Program.GameMess.Warning($"There was an unknown error loading {0}'s deck sleeve.", who);
                }
            }

            CreateCard(id, type, group, size);
            Log.Info("LoadDeck Starting Task to Fire Event");
            Program.GameEngine.EventProxy.OnLoadDeck_3_1_0_0(who, @group.Distinct().ToArray());
            Program.GameEngine.EventProxy.OnLoadDeck_3_1_0_1(who, @group.Distinct().ToArray());
            Program.GameEngine.EventProxy.OnDeckLoaded_3_1_0_2(who, @group.Distinct().ToArray());
        }
Ejemplo n.º 9
0
        public string PlayerGetGlobalVariable(int id, string name)
        {
            Player p = Player.Find((byte)id);

            if (p == null)
            {
                return("");
            }
            if (p.GlobalVariables.ContainsKey(name) == false)
            {
                Program.GameMess.Warning("Global variable '{0}' isn't defined for player '{1}'", name, p.Name);
                return("");
            }
            return(p.GlobalVariables[name]);
        }
Ejemplo n.º 10
0
        public void GroupRemoveViewer(int id, int pid)
        {
            Group  group  = Group.Find(id);
            Player player = Player.Find((byte)pid);

            if (group.Controller != Player.LocalPlayer)
            {
                Program.GameMess.Warning("{0} can't set visibility on {0} because they don't control it.", Player.LocalPlayer.Name, group.Name);
                return;
            }
            if (!group.Viewers.Contains(player))
            {
                return;
            }
            else
            {
                QueueAction(() => group.RemoveViewer(player, true));
            }
        }
Ejemplo n.º 11
0
        /// <summary>Creates new Cards as well as the corresponding CardIdentities. The cards may be in different groups.</summary>
        /// <param name="id">An array with the new CardIdentity ids.</param>
        /// <param name="type">An array containing the corresponding CardModel guids (encrypted)</param>
        /// <param name="groups">An array indicating the group the cards must be loaded into.</param>
        /// <seealso cref="CreateCard(int[], ulong[], Group)"> for a more efficient way to insert cards inside one group.</seealso>
        private static void CreateCard(IList <int> id, IList <Guid> type, IList <Group> groups, IList <string> sizes, string sleeveUrl = "")
        {
            // Ignore cards created by oneself
            if (Player.Find((byte)(id[0] >> 16)) == Player.LocalPlayer)
            {
                return;
            }
            for (var i = 0; i < id.Count; i++)
            {
                var group = groups[i];
                var owner = group.Owner;
                if (owner == null)
                {
                    Program.GameMess.Warning("[CreateCard] Player not found.");
                    continue;
                }

                var c = new Card(owner, id[i], Program.GameEngine.Definition.GetCardById(type[i]), false, sizes[i]); c.SetSleeve(sleeveUrl); group.AddAt(c, group.Count);
            }
        }
Ejemplo n.º 12
0
        public void GroupSetController(int id, int player)
        {
            var g = Group.Find(id);
            var p = Player.Find((byte)player);

            if (p == Player.LocalPlayer)
            {
                if (g.Controller == Player.LocalPlayer)
                {
                    return;
                }
                QueueAction(() => g.TakeControl());
            }
            else
            {
                if (g.Controller != Player.LocalPlayer)
                {
                    return;
                }
                QueueAction(() => g.PassControlTo(p));
            }
        }
Ejemplo n.º 13
0
        public void PlayerSetGlobalVariable(int id, string name, object value)
        {
            string val = String.Format("{0}", value);
            Player p   = Player.Find((byte)id);

            if (p == null || p.Id != Player.LocalPlayer.Id)
            {
                return;
            }
            string oldvalue = "";

            if (Player.LocalPlayer.GlobalVariables.ContainsKey(name))
            {
                oldvalue = Player.LocalPlayer.GlobalVariables[name];
                QueueAction(() => Player.LocalPlayer.GlobalVariables[name] = val);
            }
            else
            {
                QueueAction(() => Player.LocalPlayer.GlobalVariables.Add(name, val));
            }
            Program.Client.Rpc.PlayerSetGlobalVariable(Player.LocalPlayer, name, oldvalue ?? "", val);
        }
Ejemplo n.º 14
0
        public void SetController(int id, int player)
        {
            Card   c          = Card.Find(id);
            Player p          = Player.Find((byte)player);
            Player controller = c.Controller;

            if (p == Player.LocalPlayer)
            {
                if (c.Controller == Player.LocalPlayer)
                {
                    return;
                }
                QueueAction(() => c.TakeControl());
            }
            else
            {
                if (c.Controller != Player.LocalPlayer)
                {
                    return;
                }
                QueueAction(() => c.PassControlTo(p));
            }
        }
Ejemplo n.º 15
0
        public int PlayerHandId(int id)
        {
            Hand hand = Player.Find((byte)id).Hand;

            return(hand != null ? hand.Id : 0);
        }
Ejemplo n.º 16
0
 public string PlayerName(int id)
 {
     return(Player.Find((byte)id).Name);
 }
Ejemplo n.º 17
0
 public string PlayerColor(int id)
 {
     return(Player.Find((byte)id).Color.ToString().Remove(1, 2));
 }
Ejemplo n.º 18
0
 public bool PlayerHasInvertedTable(int id)
 {
     return(Player.Find((byte)id).InvertedTable);
 }