Exemplo n.º 1
0
        public void CreateWorld(Player player)
        {
            World world = null;

            foreach (var p in Program.Resources.Worlds.Data.Values
                     .Where(p => p.portals != null && p.portals.Contains(ObjectType)))
            {
                if (p.id < 0)
                {
                    world = player.Manager.GetWorld(p.id);
                }
                else
                {
                    DynamicWorld.TryGetWorld(p, player.Client, out world);
                    world = player.Manager.AddWorld(world ?? new World(p));
                }
                break;
            }

            if (PlayerOpened)
            {
                world.PlayerDungeon = true;
                world.Opener        = Opener;
                world.Invites       = new HashSet <string>();
                world.Invited       = new HashSet <string>();
            }

            WorldInstance = world;
            WorldInstanceSet?.Invoke(this, world);
        }
Exemplo n.º 2
0
        private void AddWorld(ProtoWorld proto, bool actAsNexus = false)
        {
            int id;

            if (actAsNexus)
            {
                id = World.Nexus;
            }
            else
            {
                id = (proto.id < 0)
                    ? proto.id
                    : Interlocked.Increment(ref _nextWorldId);
            }

            DynamicWorld.TryGetWorld(proto, null, out var world);
            if (world != null)
            {
                if (world is Marketplace && !Config.serverSettings.enableMarket)
                {
                    return;
                }

                AddWorld(id, world);
                return;
            }

            AddWorld(id, new World(proto));
        }
Exemplo n.º 3
0
        private void AddWorld(ProtoWorld proto, bool actAsNexus = false)
        {
            int id;

            if (actAsNexus)
            {
                id = World.Nexus;
            }
            else
            {
                id = (proto.id < 0)
                    ? proto.id
                    : Interlocked.Increment(ref _nextWorldId);
            }

            World world;

            DynamicWorld.TryGetWorld(proto, null, out world);
            if (world != null)
            {
                AddWorld(id, world);
                return;
            }

            AddWorld(id, new World(proto));
        }
Exemplo n.º 4
0
 public void Initialize(float[,,] data, int XZSize, int YSize, Material material, DynamicWorld world)
 {
     this.meshFilter   = GetComponent <MeshFilter>();
     this.meshCollider = GetComponent <MeshCollider>();
     this.GetComponent <MeshRenderer>().material = material;
     this.data        = data;
     this.size        = XZSize;
     this.height      = YSize;
     this.parentWorld = world;
 }
Exemplo n.º 5
0
        private static void Handle(Player player)
        {
            var cli = player.Client;

            if (cli.Account.RaidToken < 1)
            {
                player.SendError("You do not have an Alert to launch.");
                return;
            }

            if (cli.Account.Credits < 1000)
            {
                player.SendError("You do not have the required amount of gold to launch an Alert.");
                return;
            }

            var rnd = new Random();

            cli.Manager.Database.UpdateAlertToken(cli.Account, -1);
            player.AlertToken--;
            player.ForceUpdate(player.AlertToken);

            player.SendHelp("Launching Alert... Good luck!");
            var alertArea = player.Owner.Manager.Resources.Worlds[AlertAreas[rnd.Next(AlertAreas.Length)]];

            DynamicWorld.TryGetWorld(alertArea, player.Client, out var world);
            world = player.Owner.Manager.AddWorld(world ?? new World(alertArea));

            player.Owner.Timers.Add(new WorldTimer(8000, (w, t) => {
                player.Client.Reconnect(new Reconnect {
                    Host        = "",
                    Port        = 2050,
                    GameId      = world.Id,
                    Name        = world.SBName,
                    IsFromArena = false
                });
            }));
        }
Exemplo n.º 6
0
 public void InitWorld()
 {
     _world = new DynamicWorld();
     _numRB = 0;
 }
Exemplo n.º 7
0
        private void AEUnlockPortal(RealmTime time, Item item, Position target, ActivateEffect eff)
        {
            var gameData = Manager.Resources.GameData;

            // find locked portal
            var portals = Owner.StaticObjects.Values
                          .Where(s => s is Portal && s.ObjectDesc.ObjectId.Equals(eff.LockedName) && s.DistSqr(this) <= 9)
                          .Select(s => s as Portal);

            if (!portals.Any())
            {
                return;
            }
            var portal = portals.Aggregate(
                (curmin, x) => (curmin == null || x.DistSqr(this) < curmin.DistSqr(this) ? x : curmin));

            if (portal == null)
            {
                return;
            }

            // get proto of world
            ProtoWorld proto;

            if (!Manager.Resources.Worlds.Data.TryGetValue(eff.DungeonName, out proto))
            {
                Log.Error("Unable to unlock portal. \"" + eff.DungeonName + "\" does not exist.");
                return;
            }

            if (proto.portals == null || proto.portals.Length < 1)
            {
                Log.Error("World is not associated with any portals.");
                return;
            }

            // create portal of unlocked world
            var portalType = (ushort)proto.portals[0];
            var uPortal    = Resolve(Manager, portalType) as Portal;

            if (uPortal == null)
            {
                Log.Error("Error creating portal: {0}", portalType);
                return;
            }

            var portalDesc  = gameData.Portals[portal.ObjectType];
            var uPortalDesc = gameData.Portals[portalType];

            // create world
            World world;

            if (proto.id < 0)
            {
                world = Manager.GetWorld(proto.id);
            }
            else
            {
                DynamicWorld.TryGetWorld(proto, Client, out world);
                world = Manager.AddWorld(world ?? new World(proto));
            }
            uPortal.WorldInstance = world;

            // swap portals
            if (!portalDesc.NexusPortal || !Manager.Monitor.RemovePortal(portal))
            {
                Owner.LeaveWorld(portal);
            }
            uPortal.Move(portal.X, portal.Y);
            uPortal.Name = uPortalDesc.DisplayId;
            var uPortalPos = new Position()
            {
                X = portal.X - .5f, Y = portal.Y - .5f
            };

            if (!uPortalDesc.NexusPortal || !Manager.Monitor.AddPortal(world.Id, uPortal, uPortalPos))
            {
                Owner.EnterWorld(uPortal);
            }

            // setup timeout
            if (!uPortalDesc.NexusPortal)
            {
                var timeoutTime = gameData.Portals[portalType].Timeout;
                Owner.Timers.Add(new WorldTimer(timeoutTime * 1000, (w, t) => w.LeaveWorld(uPortal)));
            }

            // announce
            Owner.BroadcastPacket(new Notification
            {
                Color    = new ARGB(0xFF00FF00),
                ObjectId = Id,
                Message  = "Unlocked by " + Name
            }, null);
            foreach (var player in Owner.Players.Values)
            {
                player.SendInfo(string.Format("{0} unlocked by {1}!", world.SBName, Name));
            }
        }
Exemplo n.º 8
0
    public static void FillMesh(ref Mesh meshToUpdate, int chunkX, int chunkY, int chunkZ, DynamicWorld world, int size, int height, float surfaceCrossValue)
    {
        int vertexIndex = 0;

        Vector3[] interpolatedValues = new Vector3[12];

        List <Vector3> vertices        = new List <Vector3>();
        List <int>     triangleIndices = new List <int>();

        for (int x = 0; x < size; x++)
        {
            for (int y = 0; y < height - 1; y++)
            {
                for (int z = 0; z < size; z++)
                {
                    if (vertices.Count > 64000)
                    {
                        //Maximum vertex count for a mesh is 65k
                        //If reaching this limit we should be making smaller or less complex meshes
                        break;
                    }

                    Vector3 basePoint = new Vector3(x, y, z);

                    //Get the 8 corners of this cube
                    float p0 = world.GetValue(chunkX + x, chunkY + y, chunkZ + z);
                    float p1 = world.GetValue(chunkX + x + 1, chunkY + y, chunkZ + z);
                    float p2 = world.GetValue(chunkX + x, chunkY + y + 1, chunkZ + z);
                    float p3 = world.GetValue(chunkX + x + 1, chunkY + y + 1, chunkZ + z);
                    float p4 = world.GetValue(chunkX + x, chunkY + y, chunkZ + z + 1);
                    float p5 = world.GetValue(chunkX + x + 1, chunkY + y, chunkZ + z + 1);
                    float p6 = world.GetValue(chunkX + x, chunkY + y + 1, chunkZ + z + 1);
                    float p7 = world.GetValue(chunkX + x + 1, chunkY + y + 1, chunkZ + z + 1);

                    //A bitmap indicating which edges the surface of the volume crosses
                    int crossBitMap = 0;


                    if (p0 < surfaceCrossValue)
                    {
                        crossBitMap |= 1;
                    }
                    if (p1 < surfaceCrossValue)
                    {
                        crossBitMap |= 2;
                    }

                    if (p2 < surfaceCrossValue)
                    {
                        crossBitMap |= 8;
                    }
                    if (p3 < surfaceCrossValue)
                    {
                        crossBitMap |= 4;
                    }

                    if (p4 < surfaceCrossValue)
                    {
                        crossBitMap |= 16;
                    }
                    if (p5 < surfaceCrossValue)
                    {
                        crossBitMap |= 32;
                    }

                    if (p6 < surfaceCrossValue)
                    {
                        crossBitMap |= 128;
                    }
                    if (p7 < surfaceCrossValue)
                    {
                        crossBitMap |= 64;
                    }

                    //Use the edge look up table to determin the configuration of edges
                    int edgeBits = Contouring3D.EdgeTableLookup[crossBitMap];

                    //The surface did not cross any edges, this cube is either complelety inside, or completely outside the volume
                    if (edgeBits == 0)
                    {
                        continue;
                    }

                    float interpolatedCrossingPoint = 0f;

                    //Calculate the interpolated positions for each edge that has a crossing value

                    //Bottom four edges
                    if ((edgeBits & 1) > 0)
                    {
                        interpolatedCrossingPoint = (surfaceCrossValue - p0) / (p1 - p0);
                        interpolatedValues[0]     = Vector3.Lerp(new Vector3(x, y, z), new Vector3(x + 1, y, z), interpolatedCrossingPoint);
                    }
                    if ((edgeBits & 2) > 0)
                    {
                        interpolatedCrossingPoint = (surfaceCrossValue - p1) / (p3 - p1);
                        interpolatedValues[1]     = Vector3.Lerp(new Vector3(x + 1, y, z), new Vector3(x + 1, y + 1, z), interpolatedCrossingPoint);
                    }
                    if ((edgeBits & 4) > 0)
                    {
                        interpolatedCrossingPoint = (surfaceCrossValue - p2) / (p3 - p2);
                        interpolatedValues[2]     = Vector3.Lerp(new Vector3(x, y + 1, z), new Vector3(x + 1, y + 1, z), interpolatedCrossingPoint);
                    }
                    if ((edgeBits & 8) > 0)
                    {
                        interpolatedCrossingPoint = (surfaceCrossValue - p0) / (p2 - p0);
                        interpolatedValues[3]     = Vector3.Lerp(new Vector3(x, y, z), new Vector3(x, y + 1, z), interpolatedCrossingPoint);
                    }

                    //Top four edges
                    if ((edgeBits & 16) > 0)
                    {
                        interpolatedCrossingPoint = (surfaceCrossValue - p4) / (p5 - p4);
                        interpolatedValues[4]     = Vector3.Lerp(new Vector3(x, y, z + 1), new Vector3(x + 1, y, z + 1), interpolatedCrossingPoint);
                    }
                    if ((edgeBits & 32) > 0)
                    {
                        interpolatedCrossingPoint = (surfaceCrossValue - p5) / (p7 - p5);
                        interpolatedValues[5]     = Vector3.Lerp(new Vector3(x + 1, y, z + 1), new Vector3(x + 1, y + 1, z + 1), interpolatedCrossingPoint);
                    }
                    if ((edgeBits & 64) > 0)
                    {
                        interpolatedCrossingPoint = (surfaceCrossValue - p6) / (p7 - p6);
                        interpolatedValues[6]     = Vector3.Lerp(new Vector3(x, y + 1, z + 1), new Vector3(x + 1, y + 1, z + 1), interpolatedCrossingPoint);
                    }
                    if ((edgeBits & 128) > 0)
                    {
                        interpolatedCrossingPoint = (surfaceCrossValue - p4) / (p6 - p4);
                        interpolatedValues[7]     = Vector3.Lerp(new Vector3(x, y, z + 1), new Vector3(x, y + 1, z + 1), interpolatedCrossingPoint);
                    }

                    //Side four edges
                    if ((edgeBits & 256) > 0)
                    {
                        interpolatedCrossingPoint = (surfaceCrossValue - p0) / (p4 - p0);
                        interpolatedValues[8]     = Vector3.Lerp(new Vector3(x, y, z), new Vector3(x, y, z + 1), interpolatedCrossingPoint);
                    }
                    if ((edgeBits & 512) > 0)
                    {
                        interpolatedCrossingPoint = (surfaceCrossValue - p1) / (p5 - p1);
                        interpolatedValues[9]     = Vector3.Lerp(new Vector3(x + 1, y, z), new Vector3(x + 1, y, z + 1), interpolatedCrossingPoint);
                    }
                    if ((edgeBits & 1024) > 0)
                    {
                        interpolatedCrossingPoint = (surfaceCrossValue - p3) / (p7 - p3);
                        interpolatedValues[10]    = Vector3.Lerp(new Vector3(x + 1, y + 1, z), new Vector3(x + 1, y + 1, z + 1), interpolatedCrossingPoint);
                    }
                    if ((edgeBits & 2048) > 0)
                    {
                        interpolatedCrossingPoint = (surfaceCrossValue - p2) / (p6 - p2);
                        interpolatedValues[11]    = Vector3.Lerp(new Vector3(x, y + 1, z), new Vector3(x, y + 1, z + 1), interpolatedCrossingPoint);
                    }

                    //Shift the cross bit map to use as an index into the triangle look up table
                    crossBitMap <<= 4;

                    int triangleIndex = 0;
                    while (Contouring3D.TriangleLookupTable[crossBitMap + triangleIndex] != -1)
                    {
                        //For each triangle in the look up table, create a triangle and add it to the list.
                        int index1 = Contouring3D.TriangleLookupTable[crossBitMap + triangleIndex];
                        int index2 = Contouring3D.TriangleLookupTable[crossBitMap + triangleIndex + 1];
                        int index3 = Contouring3D.TriangleLookupTable[crossBitMap + triangleIndex + 2];

                        vertices.Add(new Vector3(interpolatedValues[index1].x, interpolatedValues[index1].y, interpolatedValues[index1].z));
                        vertices.Add(new Vector3(interpolatedValues[index2].x, interpolatedValues[index2].y, interpolatedValues[index2].z));
                        vertices.Add(new Vector3(interpolatedValues[index3].x, interpolatedValues[index3].y, interpolatedValues[index3].z));

                        triangleIndices.Add(vertexIndex);
                        triangleIndices.Add(vertexIndex + 1);
                        triangleIndices.Add(vertexIndex + 2);
                        vertexIndex   += 3;
                        triangleIndex += 3;
                    }
                }
            }
        }

        //Create texture coordinates for all the vertices
        List <Vector2> texCoords       = new List <Vector2>();
        Vector2        emptyTexCoords0 = new Vector2(0, 0);
        Vector2        emptyTexCoords1 = new Vector2(0, 1);
        Vector2        emptyTexCoords2 = new Vector2(1, 1);

        for (int texturePointer = 0; texturePointer < vertices.Count; texturePointer += 3)
        {
            //There should be as many texture coordinates as vertices.
            //This example does not support textures, so fill with zeros
            texCoords.Add(emptyTexCoords1);
            texCoords.Add(emptyTexCoords2);
            texCoords.Add(emptyTexCoords0);
        }

        //Generate the mesh using the vertices and triangle indices we just created
        meshToUpdate.Clear();
        meshToUpdate.vertices  = vertices.ToArray();
        meshToUpdate.triangles = triangleIndices.ToArray();
        meshToUpdate.uv        = texCoords.ToArray();
        meshToUpdate.RecalculateNormals();
        meshToUpdate.RecalculateBounds();
    }