Exemplo n.º 1
0
        private void PlayerAdvertise(SharedClass1.RemoteEvents.UserPlayerAdvertiseArguments e)
        {
            CoPlayer c = CoPlayers.SingleOrDefault(k => k.Identity.user == e.user);

            #region does that coplayer already exist?
            if (c == null)
            {
                // the player has just joined

                c = new CoPlayer {
                    Identity = e
                }.AddTo(CoPlayers);



                //c.WalkToTeleported +=
                //    delegate
                //    {
                //        this.Map.WriteLine(c.Identity.name + " has teleported");
                //    };

                //c.WalkToDone +=
                //    delegate
                //    {
                //        this.Map.WriteLine(c.Identity.name + " has stopped");
                //    };

                //c.WalkToStart +=
                //    delegate
                //    {
                //        this.Map.WriteLine(c.Identity.name + " started walking");
                //    };
            }
            #endregion

            if (c.Guard == null)
            {
                Map.WriteLine("coplayer " + e.name + " spawned as a new guard");


                c.Guard = this.Map.CreateGuard().AddTo(this.Map.EgoView.BlockingSprites);
                c.Guard.MinimapZIndex        = SpriteInfoExtended.MinimapZIndex_OnTop;
                c.Guard.MinimapColor         = 0xff0000ff;
                c.Guard.MinimapInactiveColor = 0x80000080;

                c.Guard.TakeDamage +=
                    (damage, DamageOwner) =>
                {
                    // we will broadcast damage by our weapons
                    if (DamageOwner != Map.EgoWeaponIdentity)
                    {
                        return;
                    }

                    // we should not mirror remoted damage
                    if (DisableAddDamageToCoPlayer)
                    {
                        return;
                    }

                    // we have been shot
                    Messages.AddDamageToCoPlayer(c.Identity.user, damage);
                };

                c.Guard.TakeDamageDone +=
                    (damage, DamageOwner) =>
                {
                    if (c.Guard.Health <= 0)
                    {
                        c.Guard.MinimapColor = 0xff00007f;
                        c.Guard = null;

                        Map.WriteLine("coplayer " + e.name + " died and left a corpse");

                        if (DamageOwner == Map.EgoWeaponIdentity)
                        {
                            // ego killed a coplayer

                            // killing a coplayer will result in revealing end level
                            if (this.Map.HalfOfTheTreasureCollected != null)
                            {
                                this.Map.HalfOfTheTreasureCollected();
                            }
                        }
                        else
                        {
                            // coplayer killed a coplayer
                        }
                    }
                };

                this.Map.EgoView.UpdatePOV(true);
            }

            var MemoryStream_UInt8 = e.vector.Select(i => (byte)i).ToArray();
            var ms = new MemoryStream(MemoryStream_UInt8);
            var mr = new BinaryReader(ms);

            c.Guard.Health = mr.ReadDouble();
            c.Kills        = mr.ReadInt32();
            c.Score        = mr.ReadInt32();

            c.Guard.Direction = mr.ReadDouble();
            c.Guard.Position  = new Point(mr.ReadDouble(), mr.ReadDouble());

            //this.Map.WriteLine("present: " + e.name);
        }