Пример #1
0
        public List <NebulaObject> GroupMemberPlayers(float radius)
        {
            List <NebulaObject> result = new List <NebulaObject>();

            if (group.members != null)
            {
                MmoWorld mmoWorld = nebulaObject.world as MmoWorld;

                List <string> gameRefs = new List <string>();
                foreach (var groupMember in group.members)
                {
                    gameRefs.Add(groupMember.Value.gameRefID);
                }

                var actors = mmoWorld.GetMmoActorsConcurrent((player) => {
                    return(gameRefs.Contains(player.nebulaObject.Id) && (transform.DistanceTo(player.transform) < radius));
                });

                foreach (var pActor in actors)
                {
                    result.Add(pActor.Value.nebulaObject);
                }
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// Creates a new <see cref="Group"/>
        /// </summary>
        public Group(MmoWorld world)
        {
            this.world = world;

            this.members          = new List <GroupMemberStructure>(4);   // 4 items = 4 cap, 5 items = 8 cap.
            this.memberReferences = new Dictionary <MmoGuid, Reference <IGroupMember> >(4);
        }
        public string GetKillOtherPlayerMessage(PlayerCharacterObject player, NebulaObject enemy)
        {
            MmoWorld       world          = player.nebulaObject.mmoWorld();
            RaceableObject playerRaceable = player.GetComponent <RaceableObject>();

            PlayerCharacterObject enemyCharacter = enemy.GetComponent <PlayerCharacterObject>();
            RaceableObject        enemyRaceable  = enemy.GetComponent <RaceableObject>();

            string systemName     = world.Resource().Zones.GetZoneName(world.Name);
            string playerName     = player.characterName;
            string playerRaceName = world.Resource().Zones.GetRaceName(playerRaceable.getRace());

            string sourceCoalitionName = player.guildName;

            if (sourceCoalitionName == null)
            {
                sourceCoalitionName = string.Empty;
            }

            string enemyName     = enemyCharacter.characterName;
            string enemyRaceName = world.Resource().Zones.GetRaceName(enemyRaceable.getRace());

            string enemyCoalitionName = enemyCharacter.guildName;

            if (enemyCoalitionName == null)
            {
                enemyCoalitionName = string.Empty;
            }

            return(string.Format("scm11:zone={0};chname={1};chrace={2};chcoal={3};enname={4};enrace={5};encoal={6}",
                                 world.Name, playerName, playerRaceable.race, sourceCoalitionName,
                                 enemyName, enemyRaceable.race, enemyCoalitionName));
        }
Пример #4
0
        /// <summary>
        ///   The setup clients.
        /// </summary>
        /// <param name = "world">
        ///   The world.
        /// </param>
        /// <param name = "clients">
        ///   The clients.
        /// </param>
        /// <param name = "t">
        ///   The stopwatch.
        /// </param>
        private static void SetupClients(MmoWorld world, List <Client> clients, Stopwatch t)
        {
            for (int x = world.Area.Min.X + (world.TileDimensions.X / 2); x < world.Area.Max.X; x += world.TileDimensions.X)
            {
                for (int y = world.Area.Min.Y + (world.TileDimensions.Y / 2); y < world.Area.Max.Y; y += world.TileDimensions.Y)
                {
                    string name   = string.Format("MyUsername{0}/{1}", x, y);
                    var    client = new Client(name, new[] { x / 100f, y / 100f });
                    client.BeginConnect();
                    clients.Add(client);
                    clientCount++;
                }

                for (int y = world.Area.Min.Y + (world.TileDimensions.Y / 2) + 1; y < world.Area.Max.Y; y += world.TileDimensions.Y)
                {
                    string name   = string.Format("MyUsername{0}/{1}", x + 1, y);
                    var    client = new Client(name, new[] { (x + 1) / 100f, y / 100f });
                    client.BeginConnect();
                    clients.Add(client);
                    clientCount++;
                }
            }

            clients.ForEach(c => Assert.IsTrue(c.EndConnect()));
            log.InfoFormat("connect completed, {0} clients", clientCount);

            clients.ForEach(c => EnterWorldBegin(c, world));
            clients.ForEach(EnterWorldEnd);
            clients.ForEach(c => BeginReceiveEvent(c, EventCode.ItemSubscribed, d => (string)d[(byte)ParameterCode.ItemId] != c.Username, 500));
            clients.ForEach(c => EndReceiveEvent(c, EventCode.ItemSubscribed));
            PrintStats(t);
            Client.ResetStats();
            Assert.AreEqual(0, Client.Exceptions, "Exceptions occured at start");
            log.Info("enter completed");
        }
Пример #5
0
 public override bool Check(MmoWorld world, NebulaObjectData data)
 {
     if (world.invulnerable)
     {
         return(true);
     }
     return(false);
 }
Пример #6
0
        //private SpawnCheckManager mSpawnCheckManager = new SpawnCheckManager();


        public MmoWorldNebulaObjectManager(MmoWorld world)
        {
            mWorld         = world;
            mNebulaObjects = mWorld.Zone.nebulaObjects;

            //foreach(var nebObj in mNebulaObjects) {
            //    if(!string.IsNullOrEmpty(nebObj.Value.scriptFile)) {
            //        nebObj.Value.script.Load(mWorld, System.IO.Path.Combine(mWorld.Resource().path, "Data/ServerScripts/" + nebObj.Value.scriptFile + ".txt"));
            //    }
            //}
        }
Пример #7
0
        /// <summary>
        ///   The create world.
        /// </summary>
        /// <param name = "world">
        ///   The world.
        /// </param>
        /// <param name = "client">
        ///   The client.
        /// </param>
        private static void CreateWorld(MmoWorld world, Client client)
        {
            Operations.CreateWorld(client, world.Name, world.Area.Min.ToFloatArray(2), world.Area.Max.ToFloatArray(2), world.TileDimensions.ToFloatArray(2));

            client.BeginReceiveResponse(0);

            OperationResponse data;

            Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Response not received");
            Assert.IsTrue(data.ReturnCode == (int)ReturnCode.Ok || data.ReturnCode == (int)ReturnCode.WorldAlreadyExists);
        }
Пример #8
0
 public Collector()
 {
     mStatList = new List <StatsData>();
     mRes      = new Res("");
     mRes.Load();
     mWorld = new MmoWorld("", new GameMath.Vector {
         X = -100, Y = -100, Z = -100
     }, new GameMath.Vector {
         X = 100, Y = 100, Z = 100
     }, new GameMath.Vector {
         X = 100, Y = 100, Z = 100
     }, mRes);
 }
Пример #9
0
        /// <summary>
        ///   The enter world.
        /// </summary>
        /// <param name = "client">
        ///   The client.
        /// </param>
        /// <param name = "world">
        ///   The world.
        /// </param>
        private static void EnterWorldBegin(Client client, MmoWorld world)
        {
            var viewDistanceEnter = new[] { 1f, 1f };
            var viewDistanceExit  = new[] { 2f, 2f };

            ThreadPoolEnqueue(
                client,
                () =>
            {
                Operations.EnterWorld(client, world.Name, client.Username, null, client.Position, viewDistanceEnter, viewDistanceExit);
                client.BeginReceiveResponse(10);
            });
        }
Пример #10
0
        /// <summary>
        /// Save world info, if world info don't exists create and save new world info
        /// </summary>
        /// <param name="world">Target world to be saved</param>
        public void SetWorld(MmoWorld world)
        {
            lock (sync) {
                var document = GetWorld(world.Zone.Id);
                if (document == null)
                {
                    //world info not found in DB, than create new world info
                    var worldInfo = new WorldInfo {
                        worldID     = world.Zone.Id,
                        currentRace = (int)(byte)world.ownedRace,
                        startRace   = (int)(byte)world.Zone.InitiallyOwnedRace,
                        underAttack = world.underAttack,
                        worldType   = (int)world.Zone.worldType,
                        attackRace  = (byte)world.attackedRace,
                        playerCount = world.playerCount
                    };
                    document = new WorldDocument {
                        info = worldInfo
                    };
                }
                else
                {
                    //check the document info not null
                    if (document.info == null)
                    {
                        document.info = new WorldInfo {
                            worldID = world.Zone.Id
                        };
                    }

                    //world info found in db, get world info and update data from MmoWorld
                    document.info.currentRace = (int)(byte)world.ownedRace;
                    document.info.startRace   = (int)(byte)world.Zone.InitiallyOwnedRace;
                    document.info.underAttack = world.underAttack;
                    document.info.worldType   = (int)world.Zone.worldType;
                    document.info.attackRace  = (byte)world.attackedRace;
                    document.info.playerCount = world.playerCount;
                }

                /*
                 * log.InfoFormat("save world state = [{0}, {1}, {2}, {3}, {4}, {5}] [red]",
                 *  document.info.worldID,
                 *  (Race)(byte)document.info.currentRace,
                 *  (Race)(byte)document.info.startRace,
                 *  document.info.underAttack,
                 *  (WorldType)(int)document.info.worldType,
                 *  document.info.playerCount);*/
                //save updated world info
                Worlds.Save(document);
            }
        }
Пример #11
0
        private void NotifyChestDamager(DamageInfo damager)
        {
            MmoWorld     world = nebulaObject.mmoWorld();
            NebulaObject playerObj;

            if (world.TryGetObject((byte)damager.DamagerType, damager.DamagerId, out playerObj))
            {
                var petManager = playerObj.GetComponent <PetManager>();
                if (petManager)
                {
                    petManager.ChestFilled(nebulaObject);
                }
            }
        }
Пример #12
0
        /// <summary>
        /// The setup clients. creates 2 clients per region.
        /// </summary>
        /// <param name="world">
        /// The world.
        /// </param>
        /// <returns>
        /// the list of created clients
        /// </returns>
        private static List <Client> SetupClients(MmoWorld world)
        {
            Stopwatch t = Stopwatch.StartNew();

            var clients = new List <Client>();

            for (int x = world.Area.Min.X + (world.TileDimensions.X / 2); x < world.Area.Max.X; x += world.TileDimensions.X)
            {
                for (int y = world.Area.Min.Y + (world.TileDimensions.Y / 2);
                     y < world.Area.Max.Y;
                     y += world.TileDimensions.Y)
                {
                    string name   = string.Format("MyUsername{0}/{1}", x, y);
                    var    client = new Client(name);
                    EnterWorldBegin(client, world, new[] { x / 100f, y / 100f });

                    clients.Add(client);
                    clientCount++;

                    Sleep();
                }

                for (int y = world.Area.Min.Y + (world.TileDimensions.Y / 2) + 1;
                     y < world.Area.Max.Y;
                     y += world.TileDimensions.Y)
                {
                    string name   = string.Format("MyUsername{0}/{1}", x + 1, y);
                    var    client = new Client(name);
                    EnterWorldBegin(client, world, new[] { (x + 1) / 100f, y / 100f });

                    clients.Add(client);
                    clientCount++;

                    Sleep();
                }
            }

            clients.ForEach(EnterWorldEnd);
            clients.ForEach(c => BeginReceiveEvent(c, EventCode.ItemSubscribed, d => true));
            clients.ForEach(c => EndReceiveEvent(c, EventCode.ItemSubscribed));
            PrintStats(t);

            Assert.AreEqual(0, Client.Exceptions, "Exceptions occured at start");
            log.Info("enter completed");

            Assert.AreEqual(0, Client.Exceptions, "Exceptions occured at exit");

            return(clients);
        }
Пример #13
0
 public void RestoreObjectsFromSave(MmoWorld world)
 {
     CheckMembers();
     foreach (var pSave in saves)
     {
         var data = pSave.Value.ConvertToNebulaObjectData();
         if (data != null)
         {
             var nebObj = ObjectCreate.NebObject(world, data);
             nebObj.AddToWorld();
             nebObj.SetDatabaseSaveable(true);
             log.InfoFormat("restored object from save = {0} [dy]", nebObj.Id);
         }
     }
 }
Пример #14
0
        /// <summary>
        /// The enter world.
        /// </summary>
        /// <param name="client">
        /// The client.
        /// </param>
        /// <param name="world">
        /// The world.
        /// </param>
        /// <param name="position">
        /// The position.
        /// </param>
        private static void EnterWorldBegin(Client client, MmoWorld world, float[] position)
        {
            var viewDistanceEnter = new[] { 1f, 1f };
            var viewDistanceExit  = new[] { 2f, 2f };

            client.Position = position;

            ThreadPoolEnqueue(
                client,
                () =>
            {
                client.SendOperation(Operations.EnterWorld(world.Name, client.Username, null, position, viewDistanceEnter, viewDistanceExit));
                client.BeginReceiveResponse();
            });
        }
Пример #15
0
        public Item(Vector position, Hashtable properties, string id, byte type, MmoWorld world)
        {
            this.Position = position;
            this.eventChannel = new MessageChannel<ItemEventMessage>(ItemEventMessage.CounterEventSend);
            this.disposeChannel = new MessageChannel<ItemDisposedMessage>(MessageCounters.CounterSend);
            this.positionUpdateChannel = new MessageChannel<ItemPositionMessage>(MessageCounters.CounterSend);
            this.properties = properties ?? new Hashtable();
            if (properties != null)
            {
                this.PropertiesRevision++;
            }

            this.id = id;
            this.world = world;
            this.type = type;
        }
Пример #16
0
        /// <summary>
        /// Creates a new instance of the <see cref="WorldServerPeer"/> class
        /// </summary>
        /// <param name="initResponse"></param>
        /// <param name="application"></param>
        public WorldServerPeer(InitResponse initResponse, WorldApplication application)
            : base(initResponse, application)
        {
            this.application = application;

            this.messageFiber = new ThreadFiber(new DefaultQueue(), "WorldMessageFiber", true, ThreadPriority.Highest);
            this.messageFiber.Start();

            // the lock will wait indefinitely
            this.sessions = new ConcurrentStorageMap <int, ISession>(-1);

            this.configuration = GameConfig.Initialize(this.application.BinaryPath);
            this.world         = MmoWorld.Instantiate(this, configuration, new WorldDescription());

            this.CreateWorldZones();
            this.RequestFiber.Enqueue(this.Register);
        }
Пример #17
0
 public bool Check(MmoWorld world, NebulaObjectData data, out bool hasCheck)
 {
     hasCheck = false;
     if (data.componentCollection.ContainsKey(ComponentID.NebulaObject))
     {
         NebulaObjectComponentData nebData = data.componentCollection[ComponentID.NebulaObject] as NebulaObjectComponentData;
         if (!string.IsNullOrEmpty(nebData.badge))
         {
             if (mChecks.ContainsKey(nebData.badge.ToLower().Trim()))
             {
                 hasCheck = true;
                 return(mChecks[nebData.badge.ToLower().Trim()].Check(world, data));
             }
         }
     }
     return(true);
 }
        public string GetStartAttackMessage(PlayerCharacterObject player, NebulaObject enemy)
        {
            MmoWorld        world          = player.nebulaObject.mmoWorld();
            RaceableObject  playerRaceable = player.GetComponent <RaceableObject>();
            CharacterObject enemyCharacter = enemy.GetComponent <CharacterObject>();
            BotObject       botObject      = enemy.GetComponent <BotObject>();

            string systemName = world.Resource().Zones.GetZoneName(world.Name);
            string playerName = player.characterName;
            //string playerRaceName = world.Resource().Zones.GetRaceName(playerRaceable.getRace());
            string npcName  = GenerateStandardNpcName(systemName, enemy.Id);
            int    npcLevel = enemyCharacter.level;

            string coalitionName = player.guildName;

            if (coalitionName == null)
            {
                coalitionName = string.Empty;
            }


            switch (botObject.getSubType())
            {
            case BotItemSubType.Drill:
                return(string.Format("scm4:zone={0};chname={1};chrace={2};chcoal={3};enname={4};enlvl={5}",
                                     world.Name, playerName,
                                     playerRaceable.race, coalitionName,
                                     npcName, npcLevel));

            case BotItemSubType.Outpost:
                return(string.Format("scm5:zone={0};chname={1};chrace={2};chcoal={3};enname={4};enlvl={5}",
                                     world.Name, playerName,
                                     playerRaceable.race, coalitionName,
                                     npcName, npcLevel));

            case BotItemSubType.MainOutpost:
                return(string.Format("scm6:zone={0};chname={1};chrace={2};chcoal={3};enname={4};enlvl={5}",
                                     world.Name, playerName,
                                     playerRaceable.race, coalitionName,
                                     npcName, npcLevel));

            default:
                return(string.Empty);
            }
        }
Пример #19
0
        public void FillSaves(MmoWorld world)
        {
            CheckMembers();
            saves.Clear();

            var itemsToSave = world.GetItems((item) => item.databaseSaveable);

            foreach (var pItem in itemsToSave)
            {
                var save = NebulaObjectSave.FromGameObject(pItem.Value as GameObject);
                if (save != null)
                {
                    if (saves.ContainsKey(save.id))
                    {
                        saves.Remove(save.id);
                    }
                    saves.Add(save.id, save);
                }
            }
        }
        public string GetSetMiningStationMessage(PlayerCharacterObject player)
        {
            MmoWorld       world          = player.nebulaObject.mmoWorld();
            RaceableObject playerRaceable = player.GetComponent <RaceableObject>();
            string         playerName     = player.characterName;
            string         coalitionName  = player.guildName;

            if (coalitionName == null)
            {
                coalitionName = string.Empty;
            }


            return(string.Format("scm1:zone={0};chname={1};chrace={2};chcoal={3}",
                                 world.Name,
                                 playerName,
                                 playerRaceable.race,
                                 coalitionName
                                 ));
        }
Пример #21
0
        public void Setup(MmoWorld world)
        {
            m_World = world;
            if (m_World.Zone.worldType == Common.WorldType.instance)
            {
                m_Cells = new PlanetWorldCell[m_World.Zone.celss.rows, m_World.Zone.celss.columns];

                for (int i = 0; i < m_World.Zone.celss.rows; i++)
                {
                    for (int j = 0; j < m_World.Zone.celss.columns; j++)
                    {
                        m_Cells[i, j] = new PlanetWorldCell();
                        m_Cells[i, j].SetData(m_World.Zone.celss.GetCell(i, j));
                    }
                }
            }
            else
            {
                m_Cells = new PlanetWorldCell[0, 0];
            }
        }
        public string GetSetOutpostMessage(PlayerCharacterObject player)
        {
            MmoWorld       world          = player.nebulaObject.mmoWorld();
            RaceableObject playerRaceable = player.GetComponent <RaceableObject>();
            string         systemName     = world.Resource().Zones.GetZoneName(world.Name);
            string         playerName     = player.characterName;
            string         playerRaceName = world.Resource().Zones.GetRaceName(playerRaceable.getRace());
            string         coalitionName  = player.guildName;

            if (coalitionName == null)
            {
                coalitionName = string.Empty;
            }


            return(string.Format("scm3:zone={0};chname={1};chrace={2};chcoal={3}",
                                 systemName,
                                 playerName,
                                 playerRaceable.race,
                                 coalitionName
                                 ));
        }
Пример #23
0
 public WorldNpcManager(MmoWorld inWorld)
 {
     mWorld = inWorld;
 }
Пример #24
0
 public abstract bool Check(MmoWorld world, NebulaObjectData data);
Пример #25
0
 private WorldNpcObjectOwner(MmoWorld world)
 {
     this.world = world;
 }
Пример #26
0
 public static NpcObjectOwner CreateWorld(MmoWorld world)
 {
     return(WorldNpcObjectOwner.Create(world));
 }
Пример #27
0
 public static WorldNpcObjectOwner Create(MmoWorld world)
 {
     return(new WorldNpcObjectOwner(world));
 }
Пример #28
0
 public WorldAsteroidManager(MmoWorld world)
 {
     mWorld = world;
 }
Пример #29
0
 public override void Start()
 {
     base.Start();
     m_World = nebulaObject.mmoWorld();
 }