示例#1
0
文件: Player.cs 项目: pakoito/OCTGN
 // C'tor
 internal Player(GameDef g, string name, byte id, ulong pkey)
 {
     // Init fields
     _name = name;
     Id = id;
     PublicKey = pkey;
     // Register the lPlayer
     all.Add(this);
     //Create the color brushes
     SetPlayerColor(id);
     // Create counters
     _counters = new Counter[g.PlayerDefinition.Counters != null ? g.PlayerDefinition.Counters.Length : 0];
     for (int i = 0; i < Counters.Length; i++)
         if (g.PlayerDefinition.Counters != null)
             Counters[i] = new Counter(this, g.PlayerDefinition.Counters[i]);
     // Create variables
     Variables = new Dictionary<string, int>();
     foreach (VariableDef varDef in g.Variables.Where(v => !v.Global))
         Variables.Add(varDef.Name, varDef.DefaultValue);
     // Create global variables
     GlobalVariables = new Dictionary<string, string>();
     foreach (GlobalVariableDef varD in g.PlayerDefinition.GlobalVariables)
         GlobalVariables.Add(varD.Name, varD.Value);
     // Create a hand, if any
     if (g.PlayerDefinition.Hand != null)
         _hand = new Hand(this, g.PlayerDefinition.Hand);
     // Create groups
     _groups = new Group[g.PlayerDefinition.Groups != null ? g.PlayerDefinition.Groups.Length + 1 : 1];
     _groups[0] = _hand;
     for (int i = 1; i < IndexedGroups.Length; i++)
         if (g.PlayerDefinition.Groups != null) _groups[i] = new Pile(this, g.PlayerDefinition.Groups[i - 1]);
     // Raise the event
     if (PlayerAdded != null) PlayerAdded(null, new PlayerEventArgs(this));
 }
示例#2
0
 // C'tor
 internal Player(Definitions.GameDef g, string name, byte id, ulong pkey)
 {
     // Init fields
     this.name = name; this.Id = id; this.PublicKey = pkey;
     // Register the player
     all.Add(this);
     OnPropertyChanged("Color");
     // Create the color brushes
     solidBrush = new System.Windows.Media.SolidColorBrush(Color);
     solidBrush.Freeze();
     transparentBrush = new System.Windows.Media.SolidColorBrush(Color);
     transparentBrush.Opacity = 0.4;
     transparentBrush.Freeze();
     OnPropertyChanged("Brush");
     OnPropertyChanged("TransparentBrush");
     // Create counters
     counters = new Counter[g.PlayerDefinition.Counters != null ? g.PlayerDefinition.Counters.Length : 0];
     for (int i = 0; i < Counters.Length; i++)
         Counters[i] = new Counter(this, g.PlayerDefinition.Counters[i]);
       // Create variables
       Variables = new Dictionary<string, int>();
       foreach (var varDef in g.Variables.Where(v => !v.Global))
     Variables.Add(varDef.Name, varDef.DefaultValue);
     // Create a hand, if any
     if (g.PlayerDefinition.Hand != null)
         hand = new Hand(this, g.PlayerDefinition.Hand);
     // Create groups
     groups = new Group[g.PlayerDefinition.Groups != null ? g.PlayerDefinition.Groups.Length + 1 : 1];
     groups[0] = hand;
     for (int i = 1; i < IndexedGroups.Length; i++)
         groups[i] = new Pile(this, g.PlayerDefinition.Groups[i - 1]);
     // Raise the event
     if (PlayerAdded != null) PlayerAdded(null, new PlayerEventArgs(this));
 }
示例#3
0
        public void CounterSet(int id, int value)
        {
            Counter counter = Counter.Find(id);

            QueueAction(
                () =>
            {
                //Program.GameEngine.EventProxy.MuteEvents = true;
                counter.Value = value;
                //Program.GameEngine.EventProxy.MuteEvents = false;
            });
        }
示例#4
0
文件: GameEvents.cs 项目: haslo/OCTGN
        public void OnChangeCounter(Player player, Counter counter, int oldValue)
        {
            var args = new object[3];
            args[0] = player;
            args[1] = counter;
            args[2] = oldValue;

            if(Program.GameEngine.Definition.Events.ContainsKey("OnChangeCounter"))
            {
                foreach(var e in Program.GameEngine.Definition.Events["OnChangeCounter"])
                {
                    engine.ExecuteFunction(e.PythonFunction,player, counter, oldValue);
                }
              	}
        }
示例#5
0
 // C'tor for global items
 internal Player(Definitions.GameDef g)
 {
     var globalDef = g.GlobalDefinition;
     // Register the player
     all.Add(this);
     // Init fields
     name = "Global"; Id = 0; PublicKey = 0;
     // Create counters
     counters = new Counter[globalDef.Counters != null ? globalDef.Counters.Length : 0];
     for (int i = 0; i < Counters.Length; i++)
         Counters[i] = new Counter(this, globalDef.Counters[i]);
     // Create global's player groups
     groups = new Pile[globalDef.Groups != null ? g.GlobalDefinition.Groups.Length + 1 : 0];
     for (int i = 1; i < IndexedGroups.Length; i++)
         groups[i] = new Pile(this, globalDef.Groups[i - 1]);
 }
示例#6
0
		public void CounterReq(Counter counter, int value, bool isScriptChange)
		{
						//Log.Info("[ProtOut] CounterReq");
					    if(Program.Client == null)return;
			MemoryStream stream = new MemoryStream(512);
			stream.Seek(4, SeekOrigin.Begin);
			BinaryWriter writer = new BinaryWriter(stream);

      if (Program.Client.Muted != 0)
          writer.Write(Program.Client.Muted);
      else
          writer.Write(0);
			writer.Write((byte)25);
			writer.Write(counter.Id);
			writer.Write(value);
			writer.Write(isScriptChange);
			writer.Flush(); writer.Seek(0, SeekOrigin.Begin);
			writer.Write((int)stream.Length);
			writer.Close();
			Send(stream.ToArray());
		}
示例#7
0
 public void Counter(Player player, Counter counter, int value, bool isScriptChange)
 {
     counter.SetValue(value, player, false, isScriptChange);
 }
示例#8
0
        public void OnChangeCounter_3_1_0_1(Player player, Counter counter, int oldValue)
        {
            if(Player.LocalPlayer.Spectator)return;
            if(MuteEvents)return;
            if(gameEngine.Definition.ScriptVersion != C_3_1_0_1 )
                return;
            Log.Info("Firing event OnChangeCounter_3_1_0_1");
            var args = new object[3];
            args[0] = player;
            args[1] = counter;
            args[2] = oldValue;

            foreach(var e in eventCache["OnChangeCounter"])
            {
                Log.InfoFormat("Firing event OnChangeCounter_3_1_0_1 -> {0}",e.Name);
                engine.ExecuteFunction(e.PythonFunction,player, counter, oldValue);
            }
        }
示例#9
0
 // C'tor for global items
 internal Player(Definitions.GameDef g)
 {
     var globalDef = g.GlobalDefinition;
     // Register the player
     all.Add(this);
     // Init fields
     name = "Global"; Id = 0; PublicKey = 0;
     if (GlobalVariables == null)
     {
         // Create global variables
         GlobalVariables = new Dictionary<string, string>();
         foreach (var varD in g.PlayerDefinition.GlobalVariables)
             GlobalVariables.Add(varD.Name, varD.Value);
     }
     // Create counters
     counters = new Counter[globalDef.Counters != null ? globalDef.Counters.Length : 0];
     for (int i = 0; i < Counters.Length; i++)
         Counters[i] = new Counter(this, globalDef.Counters[i]);
     // Create global's player groups
     groups = new Pile[globalDef.Groups != null ? g.GlobalDefinition.Groups.Length + 1 : 0];
     for (int i = 1; i < IndexedGroups.Length; i++)
         groups[i] = new Pile(this, globalDef.Groups[i - 1]);
 }
示例#10
0
        private void InitializePlayerSummary(object sender, EventArgs e)
        {
            var textBlock = (TextBlock)sender;
            var player    = textBlock.DataContext as Player;
//            if (player != null && player.IsGlobalPlayer)
//            {
//                textBlock.Visibility = Visibility.Collapsed;
//                return;
//            }
            string format;

            if (player != null && player.IsGlobalPlayer)
            {
                format = Program.GameEngine.Definition.GlobalPlayer.IndicatorsFormat;
            }
            else
            {
                format = Program.GameEngine.Definition.Player.IndicatorsFormat;
            }

            if (format == null)
            {
                textBlock.Visibility = Visibility.Collapsed;
                return;
            }

            var multi       = new MultiBinding();
            int placeholder = 0;

            format = Regex.Replace(format, @"{#([^}]*)}", delegate(Match match)
            {
                string name = match.Groups[1].Value;
                if (player != null)
                {
                    Counter counter =
                        player.Counters.FirstOrDefault(
                            c => c.Name == name);
                    if (counter != null)
                    {
                        multi.Bindings.Add(new Binding("Value")
                        {
                            Source = counter
                        });
                        return("{" + placeholder++ + "}");
                    }
                }
                if (player != null)
                {
                    Group group =
                        player.IndexedGroups.FirstOrDefault(
                            g => g != null && g.Name == name);
                    if (@group != null)
                    {
                        multi.Bindings.Add(new Binding("Count")
                        {
                            Source = @group.Cards
                        });
                        return("{" + placeholder++ + "}");
                    }
                }
                return("?");
            });
            multi.StringFormat = format;
            textBlock.SetBinding(TextBlock.TextProperty, multi);
        }
示例#11
0
 public void Counter(Player player, Counter counter, int value)
 {
     counter.SetValue(value, player, false);
 }
示例#12
0
        public void CounterReq(Counter counter, int value)
        {
            StringBuilder sb = new StringBuilder();
            XmlWriter writer = XmlWriter.Create(sb, xmlSettings);

            writer.WriteStartElement("CounterReq");
            if (Script.ScriptEngine.CurrentScript != null && Script.ScriptEngine.CurrentScript.muted)
              writer.WriteAttributeString("muted", Script.ScriptEngine.CurrentScript.GetUniqueId().ToString(CultureInfo.InvariantCulture));
              else if (Program.Client.Muted != 0)
              writer.WriteAttributeString("muted", Program.Client.Muted.ToString(CultureInfo.InvariantCulture));
            writer.WriteElementString("counter", counter.Id.ToString(CultureInfo.InvariantCulture));
            writer.WriteElementString("value", value.ToString(CultureInfo.InvariantCulture));
            writer.WriteEndElement();
            writer.Close();
            Send(sb.ToString());
        }
示例#13
0
        public void CounterReq(Counter counter, int value)
        {
            StringBuilder sb = new StringBuilder();
            XmlWriter writer = XmlWriter.Create(sb, xmlSettings);

            writer.WriteStartElement("CounterReq");
            if(Program.Client.Muted != 0)
                writer.WriteAttributeString("muted", Program.Client.Muted.ToString(CultureInfo.InvariantCulture));
            writer.WriteElementString("counter", counter.Id.ToString(CultureInfo.InvariantCulture));
            writer.WriteElementString("value", value.ToString(CultureInfo.InvariantCulture));
            writer.WriteEndElement();
            writer.Close();
            Send(sb.ToString());
        }
示例#14
0
 public int CounterGet(int id)
 {
     return(Counter.Find(id).Value);
 }
示例#15
0
文件: GameEvents.cs 项目: octgn/OCTGN
 public void OnChangeCounter_3_1_0_1(Player player, Counter counter, int oldValue)
 {
     if(Player.LocalPlayer.Spectator)return;
     if(MuteEvents)return;
     if(gameEngine.Definition.ScriptVersion != C_3_1_0_1 )
         return;
     var thisVersion = Version.Parse("3.1.0.1");
     dynamic args = new System.Dynamic.ExpandoObject();
     if(thisVersion >= BASEOBJECTVERSION)
     {
         args.player = player;
         args.counter = counter;
         args.oldValue = oldValue;
     }
     foreach(var e in eventCache["OnChangeCounter"])
     {
         if(thisVersion < BASEOBJECTVERSION)
             engine.ExecuteFunction(e.PythonFunction,player, counter, oldValue);
         else
         {
             engine.ExecuteFunction(e.PythonFunction, args);
         }
     }
 }
示例#16
0
        public void OnChangeCounter_3_1_0_1(Player player, Counter counter, int oldValue)
        {
            if(Player.LocalPlayer.Spectator)return;
            if(MuteEvents)return;
            if(gameEngine.Definition.ScriptVersion != C_3_1_0_1 )
                return;
            var args = new object[3];
            args[0] = player;
            args[1] = counter;
            args[2] = oldValue;

            foreach(var e in eventCache["OnChangeCounter"])
            {
                //Log.InfoFormat("Firing event OnChangeCounter_3_1_0_1 -> {0}",e.Name);
                //System.Diagnostics.Stopwatch sw = null;
                //if (Library.X.Instance.Debug || Library.X.Instance.ReleaseTest || Program.DeveloperMode)
                //{
                //    sw = new System.Diagnostics.Stopwatch();
                //	sw.Start();
                //}
                engine.ExecuteFunction(e.PythonFunction,player, counter, oldValue);
                //if (Library.X.Instance.Debug || Library.X.Instance.ReleaseTest || Program.DeveloperMode)
                //{
                //	sw.Stop();
                //	if(sw.Elapsed.TotalSeconds < 1)
                //		Program.GameMess.AddMessage(new Octgn.Core.Play.DebugMessage("[E OnChangeCounter_3_1_0_1] {0} ms",sw.Elapsed.TotalMilliseconds));
                //	else
                //		Program.GameMess.AddMessage(new Octgn.Core.Play.DebugMessage("[E OnChangeCounter_3_1_0_1] {0} sec",sw.Elapsed.TotalSeconds));
                //}
            }
        }
示例#17
0
文件: GameEvents.cs 项目: octgn/OCTGN
 public void OnCounterChanged_3_1_0_2(Player player, Counter counter, int value, bool scripted)
 {
     if(Player.LocalPlayer.Spectator)return;
     if(MuteEvents)return;
     if(gameEngine.Definition.ScriptVersion != C_3_1_0_2 )
         return;
     var thisVersion = Version.Parse("3.1.0.2");
     dynamic args = new System.Dynamic.ExpandoObject();
     if(thisVersion >= BASEOBJECTVERSION)
     {
         args.player = player;
         args.counter = counter;
         args.value = value;
         args.scripted = scripted;
     }
     foreach(var e in eventCache["OnCounterChanged"])
     {
         if(thisVersion < BASEOBJECTVERSION)
             engine.ExecuteFunction(e.PythonFunction,player, counter, value, scripted);
         else
         {
             engine.ExecuteFunction(e.PythonFunction, args);
         }
     }
 }
示例#18
0
 public void Counter(Player player, Counter counter, int value, bool isScriptChange)
 {
     WriteReplayAction(player.Id);
     counter.SetValue(value, player, false, isScriptChange);
 }
示例#19
0
文件: Player.cs 项目: pakoito/OCTGN
 // C'tor for global items
 internal Player(GameDef g)
 {
     SharedDef globalDef = g.GlobalDefinition;
     // Register the lPlayer
     all.Add(this);
     // Init fields
     _name = "Global";
     Id = 0;
     PublicKey = 0;
     if (GlobalVariables == null)
     {
         // Create global variables
         GlobalVariables = new Dictionary<string, string>();
         foreach (GlobalVariableDef varD in g.PlayerDefinition.GlobalVariables)
             GlobalVariables.Add(varD.Name, varD.Value);
     }
     // Create counters
     _counters = new Counter[globalDef.Counters != null ? globalDef.Counters.Length : 0];
     for (int i = 0; i < Counters.Length; i++)
         if (globalDef.Counters != null) Counters[i] = new Counter(this, globalDef.Counters[i]);
     // Create global's lPlayer groups
     // TODO: This could fail with a run-time exception on write, make it safe
     _groups = new Pile[globalDef.Groups != null ? g.GlobalDefinition.Groups.Length + 1 : 0];
     for (int i = 1; i < IndexedGroups.Length; i++)
         if (globalDef.Groups != null) _groups[i] = new Pile(this, globalDef.Groups[i - 1]);
 }
示例#20
0
        public void CounterReq(Counter counter, int value)
        {
            MemoryStream stream = new MemoryStream(512);
            stream.Seek(4, SeekOrigin.Begin);
            BinaryWriter writer = new BinaryWriter(stream);

              if (Program.Client.Muted != 0)
              writer.Write(Program.Client.Muted);
              else
              writer.Write(0);
            writer.Write((byte)26);
            writer.Write(counter.Id);
            writer.Write(value);
            writer.Flush(); writer.Seek(0, SeekOrigin.Begin);
            writer.Write((int)stream.Length);
            writer.Close();
            Send(stream.ToArray());
        }
示例#21
0
 public void Counter(Player player, Counter counter, int value, bool isScriptChange)
 {
     counter.SetValue(value, player, false, isScriptChange);
 }
示例#22
0
 public void Counter(Player player, Counter counter, int value)
 {
     var old = counter.Value;
     counter.SetValue(value, player, false);
     Program.GameEngine.EventProxy.OnChangeCounter(player,counter,old);
 }