コード例 #1
0
        public WorldObjectData ReadNextWorldObjectData(Stream src, Int32 objectType)
        {
            WorldObjectData objData = new WorldObjectData();

            switch (objectType)
            {
            case 0:
                objData.type             = "Component";
                objData.parentEntityName = ReadNextString(src);
                break;

            case 1:
                objData.type             = "Entity";
                objData.needTransform    = ReadNextInt32(src) == 1;
                objData.rotation         = ReadNextQuat(src);
                objData.position         = ReadNextVector(src);
                objData.scale            = ReadNextVector(src);
                objData.wasPlacedInLevel = ReadNextInt32(src) == 1;
                break;

            default:
                break;
            }

            return(objData);
        }
コード例 #2
0
    public SettlementBuilder(GameGenerator gameGen, SettlementBase set)
    {
        GameGenerator = gameGen;
        if (gameGen != null)
        {
            GenerationRandom = new GenerationRandom(gameGen.Seed);
        }
        else
        {
            GenerationRandom = new GenerationRandom(0);
        }
        BaseChunk         = set.BaseChunk;
        Centre            = set.Centre;
        BaseCoord         = set.BaseCoord;
        SettlementChunks  = set.SettlementChunks;
        TileSize          = set.TileSize;
        PathTile          = Tile.STONE_PATH;
        MidTile           = new Vec2i(TileSize / 2, TileSize / 2);
        Tiles             = new Tile[TileSize, TileSize];
        SettlementObjects = new WorldObjectData[TileSize, TileSize];
        Buildings         = new List <Building>();
        //PathNodes = new List<Vec2i>();
        BuildingPlots  = new List <Recti>();
        SettlementType = set.SettlementType;
        //TestNodes = new List<SettlementPathNode>();
        TestNodes2 = new SettlementPathNode[TileSize / NODE_RES, TileSize / NODE_RES];

        //Defines a path node to be once every chunk
        PathNodeRes = World.ChunkSize;
        PathNodes   = new float[TileSize / NODE_RES, TileSize / NODE_RES];
        PNSize      = TileSize / PathNodeRes;
    }
コード例 #3
0
 /// <summary>
 /// Adds the given world object to the given world position.
 /// If the object is placed in a loaded chunk, then we load the object into the game
 /// </summary>
 /// <param name="worldPos"></param>
 /// <param name="worldObject"></param>
 public void AddNewObject(WorldObjectData worldObject)
 {
     //Get relevent chunk of object placement.
     //Vec2i chunkPos = World.GetChunkPosition(worldObject.WorldPosition);
     //ChunkData2 c = CRManager.GetChunk(chunkPos);
     return;
 }
コード例 #4
0
        private static void CreatePrototype(WorldObjectData prototype, IBehaviour behaviour, IRenderer renderer)
        {
            var name               = prototype.Name;
            var hollowPlacement    = prototype.HollowPlacement;
            var mergeWithNeighbors = prototype.MergeWithNeighbors;
            var dragBuild          = prototype.DragBuild;
            var encloses           = prototype.Encloses;
            var movementCost       = prototype.MovementCost;
            var canRotate          = prototype.CanRotate;
            var destroyOnPlace     = prototype.DestroyOnPlace;
            var emitsLight         = prototype.EmitsLight;
            var blocksLight        = prototype.BlocksLight;
            var storesItems        = prototype.StoresItems;

            if (WorldObjectPrototypes.ContainsKey(name))
            {
                Console.WriteLine($"Prototype with name {name} has already been created.");
                return;
            }

            var worldObject =
                WorldObject.CreatePrototype(name, hollowPlacement, mergeWithNeighbors, dragBuild, encloses,
                                            movementCost, canRotate, destroyOnPlace, storesItems, emitsLight, blocksLight, behaviour, renderer);

            worldObject.ItemRequirements = prototype.ItemRequirements;
            WorldObjectPrototypes.Add(name, worldObject);
        }
コード例 #5
0
    /// <summary>
    /// Called when the inventory is opened
    /// </summary>
    private void OnEnable()
    {
        Player = GameManager.PlayerManager.Player;
        CurrentInventoryItemTag = ItemTag.WEAPON;

        MainInventory.gameObject.SetActive(true);
        MainInventory.SetInventory(Player.Inventory);
        MainInventory.SetItemTag(CurrentInventoryItemTag);
        MainInventory.SetMain(true);

        //Check if there are any inventories near the player to display
        WorldObjectData invObj = GameManager.WorldManager.World.InventoryObjectNearPoint(Vec2i.FromVector3(Player.Position));

        if (invObj == null || !(invObj is IInventoryObject))
        {
            //If no object is found, turn secondary inventory off
            SecondInventory.gameObject.SetActive(false);
        }
        else
        {
            Inventory inv = (invObj as IInventoryObject).GetInventory();
            SecondInventory.SetInventory(inv);
            SecondInventory.SetItemTag(CurrentInventoryItemTag);
            SecondInventory.SetMain(false);
            SecondInventory.gameObject.SetActive(true);
        }
    }
コード例 #6
0
    /// <summary>
    /// Adds given object to the array of building objects.
    /// Checks if the designated spot is already filled, if so we do not place the object and returns false.
    /// If the object covers a single tile, we add it and return true
    /// If the object is multi tile, we check if it is placed within bounds, and if every child tile is free.
    /// if so, we return true, otherwise we return false and do not place the object
    /// </summary>
    /// <param name="current"></param>
    /// <param name="nObj"></param>
    /// <param name="x"></param>
    /// <param name="z"></param>
    public static bool AddObject(Building building, WorldObjectData nObj, int x, int z, bool nInstance = false)
    {
        //If not in bounds, return false
        if (!(x > 0 && x < building.Width && z > 0 && z < building.Height))
        {
            return(false);
        }
        //Check if this is a single tile object
        if (!(nObj is IMultiTileObject))
        {
            //Single tile objects, we only need to check the single tile
            if (building.BuildingObjects[x, z] == null)
            {
                //If the tile is empty, add object and return true
                building.BuildingObjects[x, z] = nObj;
                building.AddObjectReference(nObj);
                return(true);
            }
            //If the tile is taken, we don't place the object
            return(false);
        }
        if (!(+nObj.Size.x < building.Width && z + nObj.Size.z < building.Height))
        {
            //If the bounds of the multiu tile object are too big, return false;
            return(false);
        }
        //For multi tile objects, we iterate the whole size
        for (int i = 0; i < nObj.Size.x; i++)
        {
            for (int j = 0; j < nObj.Size.z; j++)
            {
                //if any of the tiles is not null, we don't place and return false
                if (building.BuildingObjects[x + i, z + j] != null)
                {
                    return(false);
                }
            }
        }
        //Set reference, then get chilren
        building.AddObjectReference(nObj);
        building.BuildingObjects[x, z]    = nObj;
        IMultiTileObjectChild[,] children = (nObj as IMultiTileObject).GetChildren();
        //Iterate again to set children
        for (int i = 0; i < nObj.Size.x; i++)
        {
            for (int j = 0; j < nObj.Size.z; j++)
            {
                if (i == 0 && j == 0)
                {
                    continue;
                }

                //if any of the tiles is not null, we don't place and return false
                building.BuildingObjects[x + i, z + j] = (children[i, j] as WorldObjectData);
            }
        }

        return(true);
    }
コード例 #7
0
    public void TravelThroughDoor(params object[] args)
    {
        ISubworldEntranceObject entrObjec = args[0] as ISubworldEntranceObject;
        WorldObjectData         objDat    = entrObjec as WorldObjectData;
        WorldObject             obj       = objDat.LoadedObject;

        obj.OnEntityInteract(Entity);
    }
コード例 #8
0
 public BuildingWall(Vec2i worldPosition, string wallBase, int wallHeight, WorldObjectData wallobject = null, int wallObjectPosition = 0, int wallObjectHeight = 1) : base(worldPosition, null, null)
 {
     WallBase           = wallBase;
     WallObject         = wallobject;
     WallObjectHeight   = wallObjectHeight;
     WallObjectPosition = wallObjectPosition;
     WallHeight         = wallHeight;
 }
コード例 #9
0
    public void PersueThroughDoor(params object[] args)
    {
        ISubworldEntranceObject entrObjec = args[0] as ISubworldEntranceObject;
        WorldObjectData         objDat    = entrObjec as WorldObjectData;
        WorldObject             obj       = objDat.LoadedObject;

        obj.OnEntityInteract(Entity);
        Entity.GetLoadedEntity().LEPathFinder.SetEntityTarget(CurrentTarget);
    }
コード例 #10
0
ファイル: Building.cs プロジェクト: the8thbit/ProceduralRPG
    public Building(int width, int height)
    {
        Width  = width;
        Height = height;

        BuildingTiles    = new Tile[width, height];
        BuildingObjects  = new WorldObjectData[width, height];
        BuildingObjects_ = new List <WorldObjectData>();
    }
コード例 #11
0
    public static Vector3 WorkPosition(this IWorkEquiptmentObject obj)
    {
        WorldObjectData objDat = obj as WorldObjectData;
        float           x      = obj.DeltaPosition.x * Mathf.Cos(objDat.Rotation * Mathf.Deg2Rad)
                                 + obj.DeltaPosition.z * Mathf.Sin(objDat.Rotation * Mathf.Deg2Rad);

        float z = -obj.DeltaPosition.x * Mathf.Sin(objDat.Rotation * Mathf.Deg2Rad)
                  + obj.DeltaPosition.z * Mathf.Cos(objDat.Rotation * Mathf.Deg2Rad);

        return(objDat.Position + new Vector3(x, obj.DeltaPosition.y, z));
    }
コード例 #12
0
    public void ExitThroughDoor(params object[] args)
    {
        Debug.Log("reached door?");
        ISubworldEntranceObject entrObjec = args[0] as ISubworldEntranceObject;
        WorldObjectData         objDat    = entrObjec as WorldObjectData;
        WorldObject             obj       = objDat.LoadedObject;

        obj.OnEntityInteract(Entity);
        IsRunningFromCombat = false;
        RunFromCombat();
    }
コード例 #13
0
ファイル: Building.cs プロジェクト: nikitapond/ProceduralRPG
 public bool ObjectIntersects(WorldObjectData obj)
 {
     foreach (WorldObjectData obj_ in InternalObjects)
     {
         if (obj.Intersects(obj_))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #14
0
    public void SetData(WorldObjectData data)
    {
        Start();

        name           = data.type;
        ObjectId       = data.objectId;
        objectName     = data.objectName;
        hitPoints      = data.hitPoints;
        isBusy         = data.isBusy;
        ActiveStatuses = data.activeStatuse.Select(status =>
        {
            var statusObject  = (GameObject)GameObject.Instantiate(ResourceManager.GetStatus(status.type));
            var createdStatus = statusObject.GetComponent <Status>();
            createdStatus.transform.parent = statusesWrapper.transform;

            createdStatus.SetData(status);

            return(createdStatus);
        }).ToList();
        currentlySelected            = data.currentlySelected;
        movingIntoPosition           = data.movingIntoPosition;
        aiming                       = data.aiming;
        aimRotation                  = data.aimRotation;
        attackDelayFrameCounter      = data.attackDelayFrameCounter;
        currentWeaponChargeTime      = data.currentWeaponChargeTime;
        currentWeaponMultiChargeTime = data.currentWeaponMultiChargeTime;
        currentAttackDelayTime       = data.currentAttackDelayTime;
        isInvincible                 = data.isInvincible;
        if (data.stateController != null)
        {
            stateController.SetData(data.stateController);
            stateController.controlledObject = this;
        }
        underAttackFrameCounter = data.underAttackFrameCounter;

        if (data.fogOfWarAgent != null)
        {
            fogOfWarAgent.SetData(data.fogOfWarAgent);
        }

        UpdateChildRenderers();
        CalculateBounds();
        var humanPlayer = PlayerManager.GetHumanPlayer(FindObjectsOfType <Player>());

        if (humanPlayer)
        {
            targetManager = humanPlayer.GetComponentInChildren <TargetManager>();
        }

        SetPlayer();
    }
コード例 #15
0
    public bool AddObject(WorldObjectData data, bool force = false, bool debug = false)
    {
        //Find local chunk position of object
        Vec2i cPos = World.GetChunkPosition(Vec2i.FromVector3(data.Position));
        //The global position of this object
        Vector3 finalPos = (BaseChunk * World.ChunkSize).AsVector3() + data.Position;

        //If force, we do not check for collision with other objects.
        if (force)
        {
            if (ObjectMaps[cPos.x, cPos.z] == null)
            {
                ObjectMaps[cPos.x, cPos.z] = new List <WorldObjectData>();
            }

            ObjectMaps[cPos.x, cPos.z].Add(data);

            if (debug)
            {
                Debug.Log("Object " + data + " added at local chunk " + cPos + " -> global chunk " + (cPos + BaseChunk) + " total objects now:" + ObjectMaps[cPos.x, cPos.z].Count);
            }
            return(true);
        }

        if (ObjectMaps[cPos.x, cPos.z] != null)
        {
            //iterate all obejcts in chunk, check for intersection
            foreach (WorldObjectData objDat in ObjectMaps[cPos.x, cPos.z])
            {
                //If we intersect, return false and don't place the object
                if (data.Intersects(objDat))
                {
                    return(false);
                }
            }



            ObjectMaps[cPos.x, cPos.z].Add(data);
            return(true);
        }
        else
        {
            ObjectMaps[cPos.x, cPos.z] = new List <WorldObjectData>();
            ObjectMaps[cPos.x, cPos.z].Add(data);
            return(true);
        }
    }
コード例 #16
0
    public void SetObject(int x, int z, WorldObjectData obj)
    {
        if (Objects == null)
        {
            Objects = new Dictionary <int, WorldObjectData>();
        }
        int hash = WorldObject.ObjectPositionHash(x, z);

        if (!Objects.ContainsKey(hash))
        {
            Objects.Add(hash, obj);
        }
        else
        {
            Objects[hash] = obj;
        }
    }
コード例 #17
0
    public Inventory GetSecondInventory()
    {
        if (SecondInventory.Inventory == null)
        {
            Vec2i playerPos = Vec2i.FromVector2(Player.Position2);
            //Get current object on player position
            WorldObjectData currentSpace = GameManager.WorldManager.World.GetWorldObject(playerPos);
            if (currentSpace == null)
            {
                //if there is no object here, we create one
                LootSack lootsack = new LootSack(playerPos);
                GameManager.WorldManager.AddNewObject(lootsack);
                SecondInventory.SetInventory(lootsack.GetInventory());

                SecondInventory.gameObject.SetActive(true);

                return(SecondInventory.Inventory);
            }
            //If current tile is taken, we check all the surrounding tiles
            Vec2i[] surrounding = GameManager.WorldManager.World.EmptyTilesAroundPoint(playerPos);
            foreach (Vec2i v in surrounding)
            {
                WorldObjectData surSpace = GameManager.WorldManager.World.GetWorldObject(v);
                if (surSpace == null)
                {
                    //if there is no object here, we create one
                    LootSack lootsack = new LootSack(v);
                    GameManager.WorldManager.AddNewObject(lootsack);
                    SecondInventory.SetInventory(lootsack.GetInventory());

                    SecondInventory.gameObject.SetActive(true);

                    return(SecondInventory.Inventory);
                }
            }
            //If there is no space near, we return null
            return(null);
        }
        else
        {
            //If the inventory is not null, we add to it
            return(SecondInventory.Inventory);
        }
    }
コード例 #18
0
ファイル: World.cs プロジェクト: the8thbit/ProceduralRPG
    /// <summary>
    /// Finds all empty points around a given world object.
    /// Object must be an instance
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    public Vec2i[] EmptyTilesAroundWorldObject(WorldObjectData obj)
    {
        Vec2i instPos = obj.WorldPosition;

        if (instPos == null)
        {
            Debug.Error("Provided world object has no instance: " + obj.ToString());
            return(null);
        }
        return(EmptyTilesAroundPoint(instPos));

        /*
         * //Check if this object is part of a multicell object.
         * if(obj.HasMetaData && (obj.MetaData.IsParent || obj.MetaData.Parent!=null))
         * {
         *  WorldObject parent = obj.MetaData.IsParent ? obj : obj.MetaData.Parent; //Get the valid parent
         *  List<Vec2i> toTry = new List<Vec2i>(parent.MetaData.MultiCellWidth*2 + parent.MetaData.MultiCellHeight*3);
         *  //Iterate all boundary tiles
         *  for(int x=-1; x<parent.MetaData.MultiCellWidth+1; x++)
         *  {
         *      toTry.Add(instPos + new Vec2i(x, -1));
         *      toTry.Add(instPos + new Vec2i(x, parent.MetaData.MultiCellHeight+1));
         *  }
         *  for (int z = 0; z < parent.MetaData.MultiCellHeight; z++)
         *  {
         *      toTry.Add(instPos + new Vec2i(-1, z));
         *      toTry.Add(instPos + new Vec2i(parent.MetaData.MultiCellWidth+1, z));
         *
         *  }
         *  List<Vec2i> freeTiles = new List<Vec2i>(parent.MetaData.MultiCellWidth * 2 + parent.MetaData.MultiCellHeight * 3);
         *  foreach (Vec2i v_ in toTry)
         *  {
         *      if (GetWorldObject(v_) == null)
         *          freeTiles.Add(v_);
         *  }
         *  return freeTiles.ToArray();
         * }
         * else
         * {
         *  //If no meta data, this must be a single tile object, so return free points around the isntance pos
         *  return EmptyTilesAroundPoint(instPos);
         * }*/
    }
コード例 #19
0
    /// <summary>
    /// Creates a castle, size must be 48x48
    /// </summary>
    /// <returns></returns>
    public static Castle GenerateCastle(int size)
    {
        Tile[,] buildingBase = new Tile[size, size];
        WorldObjectData[,] buildingObjects = new WorldObjectData[size, size];
        Castle c = new Castle(size, size);

        c.SetBuilding(buildingBase, buildingObjects);
        //c.Entrances.Add(new BuildingEntrance(new Vec2i(1, size / 2 - 2), new Vec2i(1, size / 2 + 2)));
        Vec2i entr = GenerateWallsFloorAndEntrance(size, size, c.BuildingObjects, c.BuildingTiles, 0, BuildingStyle.stone, entraceDis: size / 2);


        AddEntrance(c, 0, entr.x - 1);
        AddEntrance(c, 0, entr.x - 2);

        AddEntrance(c, 0, entr.x + 1);
        AddEntrance(c, 0, entr.x + 2);

        return(c);
    }
コード例 #20
0
ファイル: World.cs プロジェクト: the8thbit/ProceduralRPG
    public WorldObjectData InventoryObjectNearPoint(Vec2i v)
    {
        Vec2i[] toTry = new Vec2i[] { new Vec2i(1, 0) + v, new Vec2i(0, 1) + v, new Vec2i(-1, 0) + v, new Vec2i(0, -1) + v, v,
                                      new Vec2i(1, 1) + v, new Vec2i(1, -1) + v, new Vec2i(-1, 1) + v, new Vec2i(-1, -1) + v };

        foreach (Vec2i v_ in toTry)
        {
            if (v_.x < 0 || v_.z < 0)
            {
                continue;
            }
            WorldObjectData obj = GetWorldObject(v_);
            if (obj != null && obj is IInventoryObject)
            {
                return(obj);
            }
        }
        return(null);
    }
コード例 #21
0
    public static bool AddObject(Building build, BuildingVoxels vox, WorldObjectData obj, bool force = false)
    {
        if (force)
        {
            build.AddInternalObject(obj);
            return(true);
        }
        else
        {
            //Iterate all objects in the building and check for intersection.
            foreach (WorldObjectData obj_ in build.GetBuildingInternalObjects())
            {
                //If they intersect, then we cannot place this object.
                if (obj_.Intersects(obj))
                {
                    return(false);
                }
            }

            //Find the integer bounds
            Recti bounds = obj.CalculateIntegerBounds();
            int   yMin   = (int)obj.Position.y;
            int   yMax   = yMin + (int)obj.Size.y;
            //Iterate the voxel position of the object bounds.
            for (int x = bounds.X; x < bounds.X + bounds.Width; x++)
            {
                for (int z = bounds.Y; z < bounds.Y + bounds.Height; z++)
                {
                    for (int y = yMin; y < yMax; y++)
                    {
                        //If any single voxel is non-none, then we cannot place the object here.
                        if (vox.GetVoxel(x, y, z) != Voxel.none)
                        {
                            return(false);
                        }
                    }
                }
            }
            build.AddInternalObject(obj);
            return(true);
        }
    }
コード例 #22
0
    /// <summary>
    /// Adds the given world object to the given world position.
    /// If the object is placed in a loaded chunk, then we load the object into the game
    /// </summary>
    /// <param name="worldPos"></param>
    /// <param name="worldObject"></param>
    public void AddNewObject(WorldObjectData worldObject)
    {
        //Get relevent chunk of object placement.
        Vec2i     chunkPos = World.GetChunkPosition(worldObject.WorldPosition);
        ChunkData c        = CRManager.GetChunk(chunkPos);

        Vec2i localPos = new Vec2i(worldObject.WorldPosition.x % World.ChunkSize, worldObject.WorldPosition.z % World.ChunkSize);

        c.SetObject(localPos.x, localPos.z, worldObject);

        //Check if the object has been added to a loaded chunk
        LoadedChunk loaded = CRManager.GetLoadedChunk(chunkPos);

        if (loaded != null)
        {
            WorldObject newObject = worldObject.CreateWorldObject(loaded.transform);

            loaded.LoadedWorldObjects[localPos.x, localPos.z] = newObject;
        }
    }
コード例 #23
0
    /// <summary>
    /// Checks if the bounds of the two objects intersect
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    public bool Intersects(WorldObjectData obj)
    {
        if (IsCollision == false)
        {
            return(false);
        }
        else if (obj.IsCollision == false)
        {
            return(false);
        }
        return(Vector3.Distance(obj.Position, Position) <=
               Mathf.Max(obj.Size.x, obj.Size.y, obj.Size.z, Size.x, Size.y, Size.z));

        Vector3 aMin = Position;
        Vector3 bMin = obj.Position;
        Vector3 aMax = aMin + Size;
        Vector3 bMax = bMin + obj.Size;

        return(aMin.x < bMax.x && aMin.x > bMin.x && aMin.y < bMax.y && aMin.y > bMin.y && aMin.z < bMax.z && aMin.z > bMin.z ||
               aMax.x < bMax.x && aMax.x > bMin.x && aMax.y < bMax.y && aMax.y > bMin.y && aMax.z < bMax.z && aMax.z > bMin.z);
    }
コード例 #24
0
    /// <summary>
    /// Generates a map of moveable tiles based on the given region
    /// </summary>
    /// <param name="chunkRegion"></param>
    public void LoadRegion(ChunkRegion chunkRegion)
    {
        Debug.Log("[PathFinding] Chunk Region " + chunkRegion.X + "," + chunkRegion.Z + " loading");
        //Get region position & generate empty array
        Vec2i rPos = new Vec2i(chunkRegion.X, chunkRegion.Z);

        float[,] tileData = new float[RegionTileSize, RegionTileSize];
        //Iterate whole region and fill array as required
        //TODO - see if there is a quicker way to do this...
        for (int cx = 0; cx < World.RegionSize; cx++)
        {
            for (int cz = 0; cz < World.RegionSize; cz++)
            {
                for (int x = 0; x < World.ChunkSize; x++)
                {
                    for (int z = 0; z < World.ChunkSize; z++)
                    {
                        ChunkData c = chunkRegion.Chunks[cx, cz];
                        if (c == null)
                        {
                            Debug.Error("Chunk Region " + chunkRegion.ToString() + " has null chunk with local: " + cx + "," + cz);
                            continue;
                        }
                        float val = tileData[cx * World.ChunkSize + x, cz *World.ChunkSize + z] = c.GetTile(x, z).SpeedMultiplier;
                        if (c.Objects != null && c.GetObject(x, z) != null)
                        {
                            WorldObjectData wod = c.GetObject(x, z);
                            if (wod.IsCollision)
                            {
                                val = Mathf.Infinity;
                            }
                        }

                        tileData[cx * World.ChunkSize + x, cz *World.ChunkSize + z] = val;
                    }
                }
            }
        }
        RegionTileValues.Add(rPos, tileData);
    }
コード例 #25
0
    private void LoadSingleObject(int count = 0)
    {
        if (count > 10)
        {
            return;
        }

        WorldObjectData objData = null;


        lock (ObjectsToLoadLock) {
            objData = ObjectsToLoad[0];
            ObjectsToLoad.RemoveAt(0);
        }
        //Find the chunk for the first object to generate
        Vec2i chunk = World.GetChunkPosition(objData.Position);



        LoadedChunk2 lc2 = ChunkRegionManager.GetLoadedChunk(chunk);

        if (lc2 == null)
        {
            //Debug.Log(chunk);
            Debug.Log("[ChunkLoader] Chunk ( " + chunk + " ) for object ( " + objData + " ) is not loaded, attempting another object");
            //if the chunk is null, we throw this object to the end of the que and try again.
            lock (ObjectsToLoadLock)
            {
                ObjectsToLoad.Add(objData);
            }
            LoadSingleObject(count + 1);
            return;
        }
        Vec2i       localPos = Vec2i.FromVector3(objData.Position.Mod(World.ChunkSize));
        float       off      = lc2.Chunk.GetHeight(localPos);
        WorldObject obj      = WorldObject.CreateWorldObject(objData, lc2.transform, off + 0.7f);
        //Debug.Log("Created object " + obj);
        //obj.AdjustHeight();
    }
コード例 #26
0
    private static void PlaceOutsideObjects(GenerationRandom genRan, Blacksmith smith, BuildingVoxels vox, Vec2i outMin, Vec2i outMax)
    {
        List <WorldObjectData> toPlace = new List <WorldObjectData>(new WorldObjectData[] { new Anvil(), new Anvil() });
        bool isFinished = false;

        while (!isFinished)
        {
            WorldObjectData toPlaceCur = toPlace[0];
            toPlace.RemoveAt(0);
            Vector3 pos = genRan.RandomVector3(outMin.x, outMax.x, 0, 0, outMin.z, outMax.z);
            toPlaceCur.SetPosition(pos);
            while (!BuildingGenerator.AddObject(smith, vox, toPlaceCur))
            {
                pos = genRan.RandomVector3(outMin.x, outMax.x, 0, 0, outMin.z, outMax.z);
                toPlaceCur.SetPosition(pos);
            }
            if (toPlace.Count == 0)
            {
                isFinished = true;
            }
        }
    }
コード例 #27
0
    public static WorldObject CreateWorldObject(WorldObjectData data, Transform parent = null)
    {
        GameObject gameObject = Instantiate(ResourceManager.GetWorldObject(data.ID));
        //gameObject.layer = 8;
        WorldObject obj = gameObject.AddComponent <WorldObject>();


        if (parent != null)
        {
            gameObject.transform.parent = parent;
        }
        if (data.HasMetaData())
        {
            if (data.GetMetaData().Direction != null)
            {
                float angle = Vector2.SignedAngle(new Vector2(0, 1), data.GetMetaData().Direction.AsVector2());
                obj.transform.rotation = Quaternion.Euler(0, angle, 0);
            }
        }


        gameObject.transform.localPosition = new Vector3(data.WorldPosition.x % World.ChunkSize, 0, data.WorldPosition.z % World.ChunkSize) + data.ObjectDeltaPosition;
        if (data.Size != null)
        {
            float height = 1;
            if (data.HasMetaData())
            {
                height = data.GetMetaData().Height;
            }
            if (!(data is IMultiTileObject))
            {
                gameObject.transform.localScale = new Vector3(data.Size.x, height, data.Size.z);
            }
        }
        obj.Data = data;
        data.OnObjectLoad(obj);
        return(obj);
    }
コード例 #28
0
    public static WorldObject CreateWorldObject(WorldObjectData data, Transform parent = null, float heightOffset = 0)
    {
        if (GROUND_LAYER_MASK == -1)
        {
            GROUND_LAYER_MASK = LayerMask.GetMask("Ground");
        }

        GameObject gameObject = Instantiate(data.ObjectPrefab);
        //gameObject.layer = 8;
        WorldObject obj = gameObject.GetComponent <WorldObject>();

        if (parent != null)
        {
            gameObject.transform.parent = parent;
        }
        gameObject.transform.RotateAround(data.Position + data.Size / 2, Vector3.up, data.Rotation);
        gameObject.transform.localPosition = data.Position.Mod(World.ChunkSize);
        gameObject.transform.localScale    = data.Scale;
        obj.Data = data;
        obj.Data.LoadedObject = obj;
        data.OnObjectLoad(obj);
        obj.CoroutineAdjust();
        return(obj);
    }
コード例 #29
0
 public WorldTile()
 {
     DynamicWorldObjectData     = new WorldObjectData(DefaultWorldObjectData);
     TimeEventManager.OnDayEnd += DayEnd;
 }
コード例 #30
0
    private void ProcessObjectFileLine(string[] elements, ref WorldObjectData objectTemp)
    {
        elements[0] = elements[0].Trim(); // gets rid of leading whitespace

        switch(elements[0])
        {
        case "name":
            objectTemp.Name = elements[1];
            break;
        case "desc":
            objectTemp.Desc = elements[1];
            break;
        case "collectable":
            string t = elements[1].ToLower();
            if(t.CompareTo("true") == 0 || t.CompareTo("1") == 0)
                objectTemp.isCollectable = true;
            break;
        case "icon":
            objectTemp.IconFileName = elements[1];
            break;
        }
    }
コード例 #31
0
    void LoadObjects(string fileName)
    {
        string line;
        StreamReader file = new StreamReader(fileName, Encoding.Default);

        if(file != null)
        {
            WorldObjectData objectTemp = new WorldObjectData();

            do
            {
                line = file.ReadLine();

                if (line != null)
                {
                    if(line[0] == '{')
                    {
                        objectTemp.Reset();
                        bool done = false;
                        //string[] elements;
                        do
                        {
                            line = file.ReadLine();
                            if(line == null)
                                done = true;
                            else if(line[0] == '}')
                                done = true;
                            else
                            {
                                string[] elements = line.Split('=');
                                if(elements.Length < 2)
                                    done = true;
                                else
                                    ProcessObjectFileLine(elements, ref objectTemp);
                            }
                        }
                        while (!done);

                        Base_Object b;
                        if(objectTemp.isCollectable)
                        {
                            Texture2D texture = (Texture2D)Resources.Load("textures/items/" + objectTemp.IconFileName);
                            b = new Collectable(objectTemp.Name, objectTemp.Desc, texture);
                        }
                        else
                        {
                            b = new Base_Object(objectTemp.Name, objectTemp.Desc);
                        }
                        db.AddObject(b);
                    }
                }
            }
            while (line != null);

            file.Close();
        }
    }
コード例 #32
0
ファイル: Building.cs プロジェクト: the8thbit/ProceduralRPG
 /// <summary>
 /// Adds the specified WorldObject to the list containing
 /// all objects in this building.
 /// WARNING - this does not add the object to the array of objects itself
 /// </summary>
 public void AddObjectReference(WorldObjectData obj)
 {
     BuildingObjects_.Add(obj);
 }