Example #1
0
        public void EnterForce(NecClient client, MapPosition mapPosition = null)
        {
            Enter(client, mapPosition);
            _server.Router.Send(new RecvMapChangeForce(this, mapPosition, _server.Setting), client);

            // currently required to prevent disconnect by force changing
            _server.Router.Send(new RecvMapChangeSyncOk(), client);
        }
Example #2
0
 public MapTransition()
 {
     ToPos = new MapPosition();
 }
        public void Enter(NecClient client, MapPosition mapPosition = null)
        {
            if (client.map != null)
            {
                client.map.Leave(client);
            }
            client.map = this;

            _Logger.Info(client, $"Entering Map: {id}:{fullName}");
            // If position is passed in use it and set character position, if null then use map default coords
            // If this isn't set here, the wrong coords are in character until send_movement_info updates it.
            if (mapPosition != null)
            {
                client.character.x       = mapPosition.x;
                client.character.y       = mapPosition.y;
                client.character.z       = mapPosition.z;
                client.character.heading = mapPosition.heading;
            }
            //set character coords to default map entry coords If arriving form another map.
            else if (client.character.mapId != id)
            {
                client.character.x       = x;
                client.character.y       = y;
                client.character.z       = z;
                client.character.heading = orientation;
            }

            client.character.mapId     = id;
            client.character.mapChange = false;
            clientLookup.Add(client);
            _Logger.Debug($"Client Lookup count is now : {clientLookup.GetAll().Count}  for map  {id} ");
            _Logger.Debug($"Character State for character {client.character.name} is {client.character.state}");
            //Send your character data to the other living or dead players on the map.

            //on successful map entry, update the client database position
            if (!_server.database.UpdateCharacter(client.character))
            {
                _Logger.Error("Could not update the database with current known player position");
            }
            if (!_server.database.UpdateSoul(client.soul))
            {
                _Logger.Error("Could not update the database with soul details ");
            }

            //ToDo  move all this rendering logic to Send_Map_Entry.   We dont need a copy of this logic on every map instance.
            RecvDataNotifyCharaData myCharacterData = new RecvDataNotifyCharaData(client.character, client.soul.name);

            //dead
            //you are dead here.  only getting soul form characters. sorry bro.
            if (client.character.state.HasFlag(CharacterState.SoulForm))
            {
                foreach (NecClient otherClient in clientLookup.GetAll())
                {
                    if (otherClient == client)
                    {
                        continue;
                    }
                    if (otherClient.character.state.HasFlag(CharacterState.SoulForm))
                    {
                        _server.router.Send(myCharacterData, otherClient);
                    }
                }
            }
            else //Bro, you alive! You gon see living characters!
            {
                foreach (NecClient otherClient in clientLookup.GetAll())
                {
                    if (otherClient == client)
                    {
                        continue;
                    }
                    if (otherClient.character.state.HasFlag(CharacterState.SoulForm))
                    {
                        continue;
                    }
                    _server.router.Send(myCharacterData, otherClient);
                }
            }

            if (client.union != null)
            {
                RecvDataNotifyUnionData myUnionData = new RecvDataNotifyUnionData(client.character, client.union.name);
                _server.router.Send(this, myUnionData, client);
            }

            Task.Delay(TimeSpan.FromSeconds(10)).ContinueWith
                (t1 =>
            {
                foreach (MonsterSpawn monsterSpawn in monsterSpawns.Values)
                {
                    if (monsterSpawn.active)
                    {
                        monsterSpawn.spawnActive = true;
                        if (!monsterSpawn.taskActive)
                        {
                            MonsterTask monsterTask = new MonsterTask(_server, monsterSpawn);
                            if (monsterSpawn.defaultCoords)
                            {
                                monsterTask.monsterHome = monsterSpawn.monsterCoords[0];
                            }
                            else
                            {
                                monsterTask.monsterHome = monsterSpawn.monsterCoords.Find(x => x.coordIdx == 64);
                            }
                            monsterTask.Start();
                        }
                        else
                        {
                            if (monsterSpawn.monsterVisible)
                            {
                                _Logger.Debug($"MonsterTask already running for [{monsterSpawn.name}]");
                                RecvDataNotifyMonsterData monsterData = new RecvDataNotifyMonsterData(monsterSpawn);
                                _server.router.Send(monsterData, client);
                                if (!monsterSpawn.GetAgro())
                                {
                                    monsterSpawn.MonsterMove(_server, client, monsterSpawn.monsterWalkVelocity, 2,
                                                             0);
                                }
                            }
                        }
                    }
                }
            }
                );
        }
Example #4
0
        public void Enter(NecClient client, MapPosition mapPosition = null)
        {
            if (client.Map != null)
            {
                client.Map.Leave(client);
            }

            Logger.Info(client, $"Entering Map: {Id}:{FullName}");
            // If position is passed in use it and set character position, if null then use map default coords
            // If this isn't set here, the wrong coords are in character until send_movement_info updates it.
            if (mapPosition != null)
            {
                client.Character.X       = mapPosition.X;
                client.Character.Y       = mapPosition.Y;
                client.Character.Z       = mapPosition.Z;
                client.Character.Heading = mapPosition.Heading;
            }
            else
            {
                client.Character.X       = this.X;
                client.Character.Y       = this.Y;
                client.Character.Z       = this.Z;
                client.Character.Heading = this.Orientation;
            }

            client.Map                 = this;
            client.Character.MapId     = Id;
            client.Character.mapChange = false;
            ClientLookup.Add(client);
            Logger.Debug($"Client Lookup count is now : {ClientLookup.GetAll().Count}  for map  {this.Id} ");

            RecvDataNotifyCharaData myCharacterData = new RecvDataNotifyCharaData(client.Character, client.Soul.Name);

            _server.Router.Send(this, myCharacterData, client);
            if (client.Union != null)
            {
                RecvDataNotifyUnionData myUnionData = new RecvDataNotifyUnionData(client.Character, client.Union.Name);
                _server.Router.Send(this, myUnionData, client);
            }

            foreach (MonsterSpawn monsterSpawn in this.MonsterSpawns.Values)
            {
                if (monsterSpawn.Active == true)
                {
                    monsterSpawn.SpawnActive = true;
                    if (!monsterSpawn.TaskActive)
                    {
                        MonsterTask monsterTask = new MonsterTask(_server, monsterSpawn);
                        if (monsterSpawn.defaultCoords)
                        {
                            monsterTask.monsterHome = monsterSpawn.monsterCoords[0];
                        }
                        else
                        {
                            monsterTask.monsterHome = monsterSpawn.monsterCoords.Find(x => x.CoordIdx == 64);
                        }
                        monsterTask.Start();
                    }
                    else
                    {
                        if (monsterSpawn.MonsterVisible)
                        {
                            Logger.Debug($"MonsterTask already running for [{monsterSpawn.Name}]");
                            RecvDataNotifyMonsterData monsterData = new RecvDataNotifyMonsterData(monsterSpawn);
                            _server.Router.Send(monsterData, client);
                            if (!monsterSpawn.GetAgro())
                            {
                                monsterSpawn.MonsterMove(_server, client, monsterSpawn.MonsterWalkVelocity, (byte)2,
                                                         (byte)0);
                            }
                        }
                    }
                }
            }

            //on successful map entry, update the client database position
            if (!_server.Database.UpdateCharacter(client.Character))
            {
                Logger.Error("Could not update the database with current known player position");
            }
        }