예제 #1
0
 /// <summary>
 /// Performs a server update
 /// </summary>
 internal void ServerUpdate(WorldPlayer player)
 {
     if (TickMode == TickMode.RealTime)
     {
         TickRealtimeAsync(player);
     }
 }
예제 #2
0
        /// <summary>
        /// Sends player input
        /// </summary>
        /// <param name="input">The input combination to send</param>
        public void SendMovementInput(Input input)
        {
            double speedX = 0, speedY = 0;
            int    horizontal = 0, vertical = 0;

            WorldPlayer me = Me;

            if ((input & Input.HoldSpace) != 0)
            {
                if (me.SpeedX == 0 && !Physics.ApproachingZero(me.m_morx) && !Physics.ApproachingZero(me.m_mox) && me.X % 16 == 0)
                {
                    speedX = (me.SpeedX - (me.m_morx * PhysicsEngine.JumpHeight));
                }

                if (me.SpeedY == 0 && !Physics.ApproachingZero(me.m_mory) && !Physics.ApproachingZero(me.m_moy) && me.Y % 16 == 0)
                {
                    speedY = (me.SpeedY - (me.m_mory * PhysicsEngine.JumpHeight));
                }
            }

            horizontal = Convert.ToInt32((input & Input.HoldLeft) != 0) + Convert.ToInt32((input & Input.HoldRight) != 0);
            vertical   = Convert.ToInt32((input & Input.HoldUp) != 0) + Convert.ToInt32((input & Input.HoldDown) != 0);

            SendMovement(me.X, me.Y, speedX, speedY, me.ModifierX, me.ModifierY, horizontal, vertical, false);
        }
예제 #3
0
        /// <summary>
        /// Changed the current player on screen to the next one in the list
        /// </summary>
        private void ChangePlayer()
        {
            if (_currentPlayerIndex >= 3)
            {
                _currentPlayerIndex = 0;
            }
            else
            {
                _currentPlayerIndex++;
            }
            var currentPos = WorldPlayer.Position;
            var health     = WorldPlayer.Health;
            var currDir    = WorldPlayer.CurrentDirection;
            var isFalling  = WorldPlayer.IsFalling;

            WorldPlayer.RemoveControls();
            WorldPlayer.ChangePlayer = false;
            WorldPlayer.ShotsFired   = new List <Shot>();
            WorldPlayer           = _players[_currentPlayerIndex];
            WorldPlayer.IsFalling = isFalling;
            WorldPlayer.Health    = health;
            WorldPlayer.SetPosition(currentPos);
            WorldPlayer.SetDirection(currDir);
            WorldPlayer.AddControls();
            WorldPlayer.SetWaitToMax();
        }
예제 #4
0
        /// <summary>
        /// Processes the message
        /// </summary>
        /// <param name="connectionBase">The connection base</param>
        /// <param name="message">The playerio message</param>
        /// <param name="handled">Whether the message was already handled</param>
        public void Process(ConnectionBase connectionBase, Message message, bool handled)
        {
            int userId = message.GetInt(0);

            WorldConnection worldCon = (WorldConnection)connectionBase;
            WorldPlayer     player   = worldCon.Players.GetPlayer(userId);

            if (!handled && player != null)
            {
                if (worldCon.CrownHolder != null)
                {
                    worldCon.CrownHolder.HasCrown = false;
                }

                player.HasCrown      = true;
                worldCon.CrownHolder = player;
            }

            if (player != null)
            {
                CrownEvent crownEvent = new CrownEvent()
                {
                    Raw    = message,
                    Player = player
                };

                connectionBase.RaiseServerEvent <CrownEvent>(crownEvent);
            }
        }
예제 #5
0
        /// <summary>
        /// Processes the message
        /// </summary>
        /// <param name="connectionBase">The connection baes</param>
        /// <param name="message">The playerio message</param>
        /// <param name="handled">Whether the message was already handled</param>
        public void Process(ConnectionBase connectionBase, Message message, bool handled)
        {
            int  userId   = message.GetInt(0);
            int  potionId = message.GetInt(1);
            bool isActive = message.GetBoolean(2);

            Potion potion = (Potion)potionId;

            WorldConnection worldCon = (WorldConnection)connectionBase;
            WorldPlayer     player   = worldCon.Players.GetPlayer(userId);

            if (!handled && player != null)
            {
                player.SetPotion(potion, isActive ? PotionState.Active : PotionState.Inactive);
            }

            PotionEvent potionEvent = new PotionEvent()
            {
                Raw      = message,
                Player   = player,
                Potion   = potion,
                IsActive = isActive
            };

            connectionBase.RaiseServerEvent <PotionEvent>(potionEvent);
        }
예제 #6
0
        /// <summary>
        /// Processes the message
        /// </summary>
        /// <param name="connectionBase">The connection base</param>
        /// <param name="message">The message</param>
        /// <param name="handled">Whether the message was already handled</param>
        public void Process(ConnectionBase connectionBase, Message message, bool handled)
        {
            WorldConnection worldCon = (WorldConnection)connectionBase;

            WorldPlayer player = new WorldPlayer(worldCon, message.GetString(1), message.GetInt(0));

            player.Face        = (FaceID)message.GetInt(2);
            player.X           = message.GetInt(3);
            player.Y           = message.GetInt(4);
            player.InGodMode   = message.GetBoolean(5);
            player.IsModerator = message.GetBoolean(6);
            player.HasChat     = message.GetBoolean(7);
            player.GoldCoins   = message.GetInt(8);
            player.BlueCoins   = message.GetInt(9);

            //Message 10 will eventually be removed or changed
            //No need to get purple information

            player.IsFriendsWithYou = message.GetBoolean(11);
            player.HasBuildersClub  = message.GetBoolean(12);

            if (!handled)
            {
                worldCon.Players.Add(player);
            }

            AddEvent addEvent = new AddEvent()
            {
                Raw    = message,
                Player = player
            };

            connectionBase.RaiseServerEvent <AddEvent>(addEvent);
        }
        public static WorldPlayer Load(ZPackage pkg)
        {
            var worldPlayer = new WorldPlayer();

            int num = pkg.ReadInt();

            if (!ValheimVersion.IsPlayerVersionCompatible(num))
            {
                return(null);
            }
            if (num >= 28)
            {
                worldPlayer.PlayerStats_kills  = pkg.ReadInt();
                worldPlayer.PlayerStats_deaths = pkg.ReadInt();
                worldPlayer.PlayerStats_crafts = pkg.ReadInt();
                worldPlayer.PlayerStats_builds = pkg.ReadInt();
            }
            worldPlayer.WorldPlayerData.Clear();
            int num2 = pkg.ReadInt();

            for (int i = 0; i < num2; i++)
            {
                long key             = pkg.ReadLong();
                var  worldPlayerData = new WorldPlayerData();
                worldPlayerData.m_haveCustomSpawnPoint = pkg.ReadBool();
                worldPlayerData.m_spawnPoint           = pkg.ReadVector3();
                worldPlayerData.m_haveLogoutPoint      = pkg.ReadBool();
                worldPlayerData.m_logoutPoint          = pkg.ReadVector3();
                if (num >= 30)
                {
                    worldPlayerData.m_haveDeathPoint = pkg.ReadBool();
                    worldPlayerData.m_deathPoint     = pkg.ReadVector3();
                }
                worldPlayerData.m_homePoint = pkg.ReadVector3();
                if (num >= 29 && pkg.ReadBool())
                {
                    worldPlayerData.m_mapData = pkg.ReadByteArray();
                }
                worldPlayer.WorldPlayerData.Add(key, worldPlayerData);
            }
            worldPlayer.PlayerName = pkg.ReadString();
            worldPlayer.PlayerId   = pkg.ReadLong();
            worldPlayer.StartSeed  = pkg.ReadString();
            if (pkg.ReadBool())
            {
                var byteArray = pkg.ReadByteArray();

                var playerPkg = new ZPackage(byteArray);

                worldPlayer.Player = PlayerReaderWriter.Load(playerPkg);
            }
            else
            {
                worldPlayer.Player = null;
            }
            return(worldPlayer);
        }
예제 #8
0
        /// <summary>
        /// Adds a player into the world.
        /// </summary>
        /// <param name="Player">Player object.</param>
        public static void AddPlayer(WorldPlayer player)
        {
            int mapX = player.PosX / 8192;
            int mapY = player.PosY / 8192;

            int tileX = ((player.PosX - (mapX * 8192)) / 32);
            int tileY = ((player.PosY - (mapY * 8192)) / 32);

            _maps[mapX, mapY].AddPlayer(tileX, tileY, player);
        }
예제 #9
0
        /// <summary>
        /// Sends a private message to a player
        /// </summary>
        /// <param name="player">The player</param>
        /// <param name="message">The message</param>
        public void PrivateMessage(WorldPlayer player, string message)
        {
            if (player == null)
            {
                //Player could be null from getting player from Players
                return;
            }

            this.PrivateMessage(player.Username, message);
        }
예제 #10
0
        /// <summary>
        /// Kills a player
        /// </summary>
        /// <param name="player">The player</param>
        public void KillPlayer(WorldPlayer player)
        {
            if (player == null)
            {
                m_Client.Log.Add(FluidLogCategory.Suggestion, "Check if your player is null before attempting to use it.");
                return;
            }

            this.SendMessage("say", string.Format("/kill {0}", player.Username));
        }
예제 #11
0
        /// <summary>
        /// Teleports a player to a location
        /// </summary>
        /// <param name="player">The player</param>
        /// <param name="location">The location</param>
        public void TeleportPlayer(WorldPlayer player, FluidPoint location)
        {
            if (player == null)
            {
                m_Client.Log.Add(FluidLogCategory.Suggestion, "Check if your player is null before attempting to use it.");
                return;
            }

            this.SendMessage("say", string.Format("/teleport {0} {1} {2}", player.Username, location.X, location.Y));
        }
예제 #12
0
        /// <summary>
        /// Teleports a player to another player
        /// </summary>
        /// <param name="player">The source player</param>
        /// <param name="target">The target player</param>
        public void TeleportPlayer(WorldPlayer player, WorldPlayer target)
        {
            if (player == null)
            {
                m_Client.Log.Add(FluidLogCategory.Suggestion, "Check if your player is null before attempting to use it.");
                return;
            }

            this.TeleportPlayer(player, target.GetBlockLocation());
        }
예제 #13
0
        /// <summary>
        /// Touches the player with a potion
        /// </summary>
        /// <param name="player">The player</param>
        /// <param name="potion">The potion</param>
        public void TouchPlayer(WorldPlayer player, Potion potion)
        {
            if (player == null)
            {
                m_Client.Log.Add(FluidLogCategory.Suggestion, "Check if your player is null before attempting to use it.");
                return;
            }

            this.SendMessage("touch", player.Id, potion);
        }
예제 #14
0
        public static List <Character> GetPlayersInArea(WorldPlayer player)
        {
            int mapX = player.PosX / 8192;
            int mapY = player.PosY / 8192;

            int tileX = ((player.PosX - (mapX * 8192)) / 32);
            int tileY = ((player.PosY - (mapY * 8192)) / 32);

            return(_maps[mapX, mapY].GetPlayers(tileX, tileY, player));
        }
예제 #15
0
        /// <summary>
        /// Processes the message
        /// </summary>
        /// <param name="connectionBase">The connection base</param>
        /// <param name="message">The playerio message</param>
        /// <param name="handled">Whether the message was already handled</param>
        public void Process(ConnectionBase connectionBase, Message message, bool handled)
        {
            WorldConnection worldCon = (WorldConnection)connectionBase;

            List <WorldPlayer> players = new List <WorldPlayer>();

            bool isWorldReset = message.GetBoolean(0);

            uint index = 1;

            while (index + 2 < message.Count)
            {
                WorldPlayer player = worldCon.Players.GetPlayer(message.GetInt(index));
                if (player != null)
                {
                    if (!handled)
                    {
                        Vector loc = new Vector(message.GetInt(index + 1), message.GetInt(index + 2));
                        player.SetLocationInternal(loc);

                        if (!isWorldReset)
                        {
                            player.Respawn();
                        }
                    }

                    players.Add(player);
                }

                index += 3;
            }

            if (isWorldReset)
            {
                ResetEvent resetEvent = new ResetEvent()
                {
                    Raw = message
                };

                connectionBase.RaiseServerEvent <ResetEvent>(resetEvent);
            }
            else
            {
                for (int i = 0; i < players.Count; i++)
                {
                    KillEvent killEvent = new KillEvent()
                    {
                        Raw    = message,
                        Player = players[i]
                    };

                    connectionBase.RaiseServerEvent <KillEvent>(killEvent);
                }
            }
        }
예제 #16
0
        /// <summary>
        /// Gets a player
        /// </summary>
        /// <param name="id">The player's id</param>
        /// <returns>The player if found; otherwise null</returns>
        public WorldPlayer GetPlayer(int id)
        {
            WorldPlayer player = null;

            if (m_Players.TryGetValue(id, out player))
            {
                return(player);
            }

            return(null);
        }
예제 #17
0
 /// <summary>
 /// Pause worldly actions
 /// </summary>
 public void Pause()
 {
     _localPause = true;
     foreach (var enemy in EnemiesOnMap)
     {
         enemy.Stop();
         enemy.ResetWaitTime();
         enemy.ShotsFired = new List <Shot>();
     }
     WorldPlayer.RemoveControls();
     WorldPlayer.ResetWaitTime();
 }
예제 #18
0
 /// <summary>
 /// Reset the game world scene
 /// </summary>
 /// <param name="numOfLives">The number of lives remaining</param>
 /// <param name="spawnEnemies">Do the enemies need to be respawned</param>
 private void Reset(int numOfLives, bool spawnEnemies)
 {
     NumberOfPlayerLives = numOfLives;
     WorldPlayer.Health  = 100;
     WorldPlayer.SetPosition(WorldMap.PlayerInitialPosition);
     if (spawnEnemies)
     {
         EnemiesOnMap = SpawnEnemies();
     }
     _displayLives       = true;
     _dispControllerTime = true;
 }
예제 #19
0
        /// <summary>
        /// Processes the message
        /// </summary>
        /// <param name="connectionBase">The connection base</param>
        /// <param name="message">The playerio message</param>
        /// <param name="handled">Whether the message was already handled</param>
        public void Process(ConnectionBase connectionBase, Message message, bool handled)
        {
            WorldConnection worldCon = (WorldConnection)connectionBase;
            World           world    = worldCon.World;

            Layer   layer   = (Layer)message.GetInt(0);
            int     x       = message.GetInt(1);
            int     y       = message.GetInt(2);
            BlockID blockId = (BlockID)message.GetInt(3);

            Block block = null;

            if (message.Count > 4)
            {
                int userId = message.GetInt(4);

                WorldPlayer player = worldCon.Players.GetPlayer(userId);
                block = new Block(worldCon, blockId, layer, x, y)
                {
                    Placer = player
                };
            }
            else
            {
                block = new Block(worldCon, blockId, layer, x, y);
            }

            if (!handled)
            {
                if (blockId == 0)
                {
                    Block old = world[x, y, layer];
                    if (old.ID == BlockID.CoinGold ||
                        old.ID == BlockID.CoinBlue)
                    {
                        worldCon.Physics.RemoveCoin(old);
                    }
                }

                world.SetBlock(block);
            }

            worldCon.CheckBlock(block);
            BlockEvent blockEvent = new BlockEvent()
            {
                Raw   = message,
                Block = block
            };

            connectionBase.RaiseServerEvent <BlockEvent>(blockEvent);
        }
예제 #20
0
        /// <summary>
        /// Processes the message
        /// </summary>
        /// <param name="connectionBase">The connection baes</param>
        /// <param name="message">The playerio message</param>
        /// <param name="handled">Whether the message was already handled</param>
        public void Process(ConnectionBase connectionBase, Message message, bool handled)
        {
            int userId = message.GetInt(0);

            WorldConnection worldCon = (WorldConnection)connectionBase;
            WorldPlayer     player   = worldCon.Players.GetPlayer(userId);

            WootUpEvent wootUpEvent = new WootUpEvent()
            {
                Raw    = message,
                Player = player
            };

            connectionBase.RaiseServerEvent <WootUpEvent>(wootUpEvent);
        }
예제 #21
0
        /// <summary>
        /// Processes the y step
        /// </summary>
        /// <param name="worldPlayer">The player</param>
        /// <param name="remainderX">The x remainder</param>
        /// <param name="currentSX">The current speed in the x direction</param>
        /// <param name="remainderY">The y remainder</param>
        /// <param name="currentSY">The current speed in the y direction</param>
        private void StepY(WorldPlayer worldPlayer, ref double remainderX, ref double currentSX, ref double remainderY, ref double currentSY)
        {
            double oy  = worldPlayer.Y;
            double osy = currentSY;

            if (currentSY > 0)
            {
                if ((currentSY + remainderY) >= 1)
                {
                    worldPlayer.Y += 1 - remainderY;
                    worldPlayer.Y  = Math.Floor(worldPlayer.Y);
                    currentSY     -= 1 - remainderY;
                    remainderY     = 0;
                }
                else
                {
                    worldPlayer.Y += currentSY;
                    currentSY      = 0;
                }
            }
            else
            {
                if (currentSY < 0)
                {
                    if (!ApproachingZero(remainderY) && (remainderY + currentSY) < 0)
                    {
                        worldPlayer.Y -= remainderY;
                        worldPlayer.Y  = Math.Floor(worldPlayer.Y);
                        currentSY     += remainderY;
                        remainderY     = 1;
                    }
                    else
                    {
                        worldPlayer.Y += currentSY;
                        currentSY      = 0;
                    }
                }
            }

            if (Overlaps(worldPlayer))
            {
                worldPlayer.Y        = oy;
                worldPlayer.m_speedY = 0;
                currentSY            = osy;
                worldPlayer.m_doney  = true;
            }
        }
예제 #22
0
        /// <summary>
        /// Processes the x step
        /// </summary>
        /// <param name="worldPlayer">The player</param>
        /// <param name="remainderX">The x remainder</param>
        /// <param name="currentSX">The current speed in the x direction</param>
        /// <param name="remainderY">The y remainder</param>
        /// <param name="currentSY">The current speed in the y direction</param>
        private void StepX(WorldPlayer worldPlayer, ref double remainderX, ref double currentSX, ref double remainderY, ref double currentSY)
        {
            double ox  = worldPlayer.X;
            double osx = currentSX;

            if (currentSX > 0)
            {
                if ((currentSX + remainderX) >= 1)
                {
                    worldPlayer.X += 1 - remainderX;
                    worldPlayer.X  = Math.Floor(worldPlayer.X);
                    currentSX     -= 1 - remainderX;
                    remainderX     = 0;
                }
                else
                {
                    worldPlayer.X += currentSX;
                    currentSX      = 0;
                }
            }
            else
            {
                if (currentSX < 0)
                {
                    if (!ApproachingZero(remainderX) && (remainderX + currentSX) < 0)
                    {
                        currentSX     += remainderX;
                        worldPlayer.X -= remainderX;
                        worldPlayer.X  = Math.Floor(worldPlayer.X);
                        remainderX     = 1;
                    }
                    else
                    {
                        worldPlayer.X += currentSX;
                        currentSX      = 0;
                    }
                }
            }

            if (Overlaps(worldPlayer))
            {
                worldPlayer.X        = ox;
                worldPlayer.m_speedX = 0;
                currentSX            = osx;
                worldPlayer.m_donex  = true;
            }
        }
예제 #23
0
        /// <summary>
        /// Ticks up to real time
        /// </summary>
        private void TickRealtimeAsync(WorldPlayer player)
        {
            Task.Run(delegate()
            {
                //Catch up to the server whom is five ticks ahead approximatly
                for (int t = 0; t < 5; t++)
                {
                    this.Tick(player);

                    PhysicsUpdateEvent updateEvent = new PhysicsUpdateEvent()
                    {
                        Player = player
                    };

                    m_WorldConnection.RaiseEventAsync <PhysicsUpdateEvent>(updateEvent);
                }
            });
        }
예제 #24
0
        /// <summary>
        /// Processes the message
        /// </summary>
        /// <param name="connectionBase">The connection base</param>
        /// <param name="message">The playerio message</param>
        /// <param name="handled">Whether the message was already handled</param>
        public void Process(ConnectionBase connectionBase, Message message, bool handled)
        {
            WorldConnection worldCon = (WorldConnection)connectionBase;
            World           world    = worldCon.World;

            int      x        = message.GetInt(0);
            int      y        = message.GetInt(1);
            BlockID  blockId  = (BlockID)message.GetInt(2);
            Rotation rotation = (Rotation)message.GetUInt(3);

            uint portalId       = message.GetUInt(4);
            uint portalTargetId = message.GetUInt(5);

            Portal portal = null;

            if (message.Count > 6)
            {
                int         userId = message.GetInt(6);
                WorldPlayer player = worldCon.Players.GetPlayer(userId);

                portal = new Portal(worldCon, blockId, x, y, rotation, portalId, portalTargetId)
                {
                    Placer = player
                };
            }
            else
            {
                portal = new Portal(worldCon, blockId, x, y, rotation, portalId, portalTargetId);
            }

            if (!handled)
            {
                world.SetBlock(portal);
            }

            worldCon.CheckBlock(portal);
            PortalBlockEvent portalBlockEvent = new PortalBlockEvent()
            {
                Raw    = message,
                Portal = portal
            };

            connectionBase.RaiseServerEvent <PortalBlockEvent>(portalBlockEvent);
        }
예제 #25
0
        /// <summary>
        /// Processes the message
        /// </summary>
        /// <param name="connectionBase">The connection base</param>
        /// <param name="message">The playerio message</param>
        /// <param name="handled">Whether the message was already handled</param>
        public void Process(ConnectionBase connectionBase, Message message, bool handled)
        {
            WorldConnection worldCon = (WorldConnection)connectionBase;
            World           world    = worldCon.World;

            int     x        = message.GetInt(0);
            int     y        = message.GetInt(1);
            BlockID blockId  = (BlockID)message.GetInt(2);
            string  text     = message.GetString(3);
            string  hexColor = message.GetString(4);

            LabelBlock labelBlock = null;

            if (message.Count > 5)
            {
                int userId = message.GetInt(5);

                WorldPlayer player = worldCon.Players.GetPlayer(userId);
                labelBlock = new LabelBlock(worldCon, blockId, x, y, text, hexColor)
                {
                    Placer = player
                };
            }
            else
            {
                labelBlock = new LabelBlock(worldCon, blockId, x, y, text, hexColor);
            }

            if (!handled)
            {
                world.SetBlock(labelBlock);
            }

            worldCon.CheckBlock(labelBlock);
            LabelBlockEvent labelBlockEvent = new LabelBlockEvent()
            {
                Raw        = message,
                LabelBlock = labelBlock
            };

            connectionBase.RaiseServerEvent <LabelBlockEvent>(labelBlockEvent);
        }
예제 #26
0
        /// <summary>
        /// Processes the message
        /// </summary>
        /// <param name="connectionBase">The connection base</param>
        /// <param name="message">The playerio message</param>
        /// <param name="handled">Whether the message was already handled</param>
        public void Process(ConnectionBase connectionBase, Message message, bool handled)
        {
            int userId = message.GetInt(0);

            WorldConnection worldCon = (WorldConnection)connectionBase;
            WorldPlayer     player   = worldCon.Players.GetPlayer(userId);

            if (!handled && player != null)
            {
                player.m_deaths++;
            }

            KillEvent killEvent = new KillEvent()
            {
                Raw    = message,
                Player = player
            };

            connectionBase.RaiseServerEvent <KillEvent>(killEvent);
        }
예제 #27
0
        /// <summary>
        /// Processes the message
        /// </summary>
        /// <param name="connectionBase">The connection base</param>
        /// <param name="message">The playerio message</param>
        /// <param name="handled">Whether the message was already handled</param>
        public void Process(ConnectionBase connectionBase, Message message, bool handled)
        {
            int userId = message.GetInt(0);

            WorldConnection worldCon = (WorldConnection)connectionBase;
            WorldPlayer     player   = worldCon.Players.GetPlayer(userId);

            if (!handled && player != null)
            {
                player.InGuadianMode = !player.InGuadianMode;
            }

            GuardianModeEvent guardianModeEvent = new GuardianModeEvent()
            {
                Raw    = message,
                Player = player
            };

            connectionBase.RaiseServerEvent <GuardianModeEvent>(guardianModeEvent);
        }
예제 #28
0
        /// <summary>
        /// Processes the message
        /// </summary>
        /// <param name="connectionBase">The connection base</param>
        /// <param name="message">The playerio message</param>
        /// <param name="handled">Whether the message was already handled</param>
        public void Process(ConnectionBase connectionBase, Message message, bool handled)
        {
            WorldConnection worldCon = (WorldConnection)connectionBase;

            int userId = message.GetInt(0);

            WorldPlayer player = worldCon.Players.GetPlayer(userId);
            LeftEvent leftEvent = new LeftEvent()
            {
                Raw = message,
                Player = player
            };

            if (!handled)
            {
                worldCon.Players.Remove(userId);
            }

            connectionBase.RaiseServerEvent<LeftEvent>(leftEvent);
        }
예제 #29
0
        /// <summary>
        /// Processes the message
        /// </summary>
        /// <param name="connectionBase">The connection base</param>
        /// <param name="message">The playerio message</param>
        /// <param name="handled">Whether the message was already handled</param>
        public void Process(ConnectionBase connectionBase, Message message, bool handled)
        {
            int userId = message.GetInt(0);

            WorldConnection worldCon = (WorldConnection)connectionBase;
            WorldPlayer     player   = worldCon.Players.GetPlayer(userId);

            if (!handled && player != null)
            {
                player.HasSilverCrown = true;
            }

            SilverCrownEvent silverCrownEvent = new SilverCrownEvent()
            {
                Raw    = message,
                Player = player
            };

            connectionBase.RaiseServerEvent <SilverCrownEvent>(silverCrownEvent);
        }
예제 #30
0
        /// <summary>
        /// Updates a player's position on the map when moving.
        /// </summary>
        /// <param name="Player">Player object.</param>
        /// <param name="Dx">Movement on X axis</param>
        /// <param name="Dy">Movement on Y axis</param>
        public static void UpdatePlayer(WorldPlayer player, sbyte dx, sbyte dy)
        {
            int mapX = player.PosX / 8192;
            int mapY = player.PosY / 8192;

            int tileX = ((player.PosX - (mapX * 8192)) / 32);
            int tileY = ((player.PosY - (mapY * 8192)) / 32);

            int mapX_ = (player.PosX - dx) / 8192;
            int tapY_ = (player.PosY - dy) / 8192;

            int tileX_ = (((player.PosX - dx) - (mapX * 8192)) / 32);
            int tileY_ = (((player.PosY - dy) - (mapY * 8192)) / 32);

            if (mapX == mapX_ && mapY == tapY_)
            {
                if (tileX == tileX_ && tileY == tileY_)
                {
                    return;
                }

                byte zoneX = (byte)(tileX / 32);
                byte zoneY = (byte)(tileY / 32);

                byte zoneX_ = (byte)(tileX_ / 32);
                byte zoneY_ = (byte)(tileY_ / 32);

                if (zoneX == zoneX_ && zoneY == zoneY_)
                {
                    return;
                }

                _maps[mapX, mapY].RemovePlayer(tileX_, tileY_, player);
                _maps[mapX, mapY].AddPlayer(tileX, tileY, player);

                return;
            }

            _maps[mapX_, tapY_].RemovePlayer(tileX_, tileY_, player);
            _maps[mapX, mapY].AddPlayer(tileX, tileY, player);
        }
예제 #31
0
        // when this gets too big spin off a new controller
        public void LoadContent(Game game)
        {
            var screenCentre = new Point(game.Window.ClientBounds.Width / 2, game.Window.ClientBounds.Height / 2);
            _cameraOffset = new CameraOffset(screenCentre);

            _worldPlayer = new WorldPlayer();
            _worldPlayer.Postion = new Vector2(850, 550);
            _worldPlayerView = new WorldPlayerView(_worldPlayer);
            _worldPlayerView.LoadContent(game);
            _worldPlayerController = new WorldPlayerController(_worldPlayer);

            _worldMonsterController = new WorldMonsterController(_cameraOffset);
            _worldMonsterController.LoadContent(game);

            _map = new Map(game, @"C:\Users\Jake\Documents\Games\RPG Content\Maps\map2.xml");
            _mapView = new MapView(game, _map);

            // add views to ComponentDrawer
            _componentDrawer.MapView = _mapView;
            _componentDrawer.PlayerView = _worldPlayerView;
        }
예제 #32
0
파일: M_Map.cs 프로젝트: KalOnline/KaLua
        /// <summary>
        /// Gets all the players in surrounding zones.
        /// </summary>
        /// <param name="TileX">Position on X axis</param>
        /// <param name="TileY">Position on Y axis</param>
        /// <param name="Player">Player to base search on.</param>
        /// <returns>A list of players around the base player.</returns>
        public List<Character> GetPlayers(int tileX, int tileY, WorldPlayer basePlayer)
        {
            byte zoneX = (byte)(tileX / 32);
            byte zoneY = (byte)(tileY / 32);

            List<Character> playersInRange = new List<Character>();

            foreach(WorldPlayer playerObj in _grid[zoneX, zoneY].Players.Values)
            {
                if (playerObj!= basePlayer)
                {
                    if(World.GetDistance(playerObj, basePlayer) < World.PLAYER_SIGHT_RANGE) {
                        playersInRange.Add((Character)playerObj);
                    }
                }
            }

            foreach(WorldPlayer playerObj in _grid[zoneX + 1, zoneY].Players.Values)
            {
                if (playerObj!= basePlayer)
                {
                    if(World.GetDistance(playerObj, basePlayer) < World.PLAYER_SIGHT_RANGE) {
                        playersInRange.Add((Character)playerObj);
                    }
                }
            }

            foreach(WorldPlayer playerObj in _grid[zoneX, zoneY + 1].Players.Values)
            {
                if (playerObj!= basePlayer)
                {
                    if(World.GetDistance(playerObj, basePlayer) < World.PLAYER_SIGHT_RANGE) {
                        playersInRange.Add((Character)playerObj);
                    }
                }
            }

            foreach(WorldPlayer playerObj in _grid[zoneX -1 , zoneY].Players.Values)
            {
                if (playerObj!= basePlayer)
                {
                    if(World.GetDistance(playerObj, basePlayer) < World.PLAYER_SIGHT_RANGE) {
                        playersInRange.Add((Character)playerObj);
                    }
                }
            }

            foreach(WorldPlayer playerObj in _grid[zoneX, zoneY - 1].Players.Values)
            {
                if (playerObj!= basePlayer)
                {
                    if(World.GetDistance(playerObj, basePlayer) < World.PLAYER_SIGHT_RANGE) {
                        playersInRange.Add((Character)playerObj);
                    }
                }
            }

            return playersInRange;
        }
예제 #33
0
파일: M_Map.cs 프로젝트: KalOnline/KaLua
        /// <summary>
        /// Removes a plaer on the map.
        /// </summary>
        /// <param name="TileX">Position on X axis</param>
        /// <param name="TileY">Position on Y axis</param>
        /// <param name="Player">Player object.</param>
        public void RemovePlayer( int tileX, int tileY, WorldPlayer player )
        {
            byte zoneX = (byte)(tileX / 32);
            byte zoneY = (byte)(tileY / 32);

            _grid[zoneX,zoneY].Players.Remove(player.WorldID);
        }
예제 #34
0
파일: M_Map.cs 프로젝트: KalOnline/KaLua
        /// <summary>
        /// Registers a player on the map.
        /// </summary>
        /// <param name="TileX">Position on X axis</param>
        /// <param name="TileY">Position on Y axis</param>
        /// <param name="Player">Player object.</param>
        public void AddPlayer(int tileX, int tileY, WorldPlayer player)
        {
            byte zoneX = (byte)(tileX / 32);
            byte zoneY = (byte)(tileY / 32);

            _grid[zoneX,zoneY].Players[player.WorldID] = player;
        }
예제 #35
0
 public WorldPlayerController(WorldPlayer worldPlayer)
 {
     _worldPlayer = worldPlayer;
 }