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); }
/// <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)); }
/// <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"); }
public override bool Check(MmoWorld world, NebulaObjectData data) { if (world.invulnerable) { return(true); } return(false); }
//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")); // } //} }
/// <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); }
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); }
/// <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); }); }
/// <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); } }
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); } } }
/// <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); }
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); } } }
/// <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(); }); }
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; }
/// <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); }
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); } }
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 )); }
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 )); }
public WorldNpcManager(MmoWorld inWorld) { mWorld = inWorld; }
public abstract bool Check(MmoWorld world, NebulaObjectData data);
private WorldNpcObjectOwner(MmoWorld world) { this.world = world; }
public static NpcObjectOwner CreateWorld(MmoWorld world) { return(WorldNpcObjectOwner.Create(world)); }
public static WorldNpcObjectOwner Create(MmoWorld world) { return(new WorldNpcObjectOwner(world)); }
public WorldAsteroidManager(MmoWorld world) { mWorld = world; }
public override void Start() { base.Start(); m_World = nebulaObject.mmoWorld(); }