public override void BlowUp(DungeonObject source, float damage)
 {
     if (!locked)
     {
         base.BlowUp(source, damage);
     }
 }
Пример #2
0
 void Awake()
 {
     baseObject                   = GetComponent <DungeonObject>();
     tickable                     = GetComponent <Tickable>();
     baseObject.onMove           += OnMove;
     baseObject.onPickedUpObject += OnPickedUpObject;
 }
Пример #3
0
    public static DungeonObject SelectRandomObject(BiomeDropRate[] rates)
    {
        // Get the total of all probabilities
        float totalProbability = rates.Sum(pob => pob.probability);
        // Generate a random number within the probability range
        float aRandomNumber = UnityEngine.Random.Range(0, totalProbability);

        // Randomly select an object such that objects with a higher probability are more likely to be selected
        float         currentProbability  = 0;
        float         previousProbability = 0;
        DungeonObject selectedObject      = null;

        foreach (var probability in rates)
        {
            previousProbability = currentProbability;
            currentProbability += probability.probability;
            if (aRandomNumber >= previousProbability && aRandomNumber < currentProbability)
            {
                selectedObject = probability.item;
                break;
            }
        }

        // TODO: Respect min and max and shit
        return(selectedObject);
    }
Пример #4
0
 public Meteor(SpellDef def, DungeonObject owner, Vector2 position)
     : base(def, owner, owner.Position)
 {
     Position            = new Vector2((int)position.X / 16 * 16, (int)position.Y / 16 * 16);
     State               = Active;
     StateCompleteAction = () => State = Hit;
 }
Пример #5
0
 void OnPickedUpObject(DungeonObject ob)
 {
     if (ob.GetComponent <Weapon>() != null)
     {
         WeildRightHand(ob);
     }
 }
Пример #6
0
    void AddTileObjects(Map map, int x, int y)
    {
        map.tileObjects[y][x].RemoveAllObjects();
        if (tiles[y][x] == TileType.NOTHING)
        {
            DungeonObject ob = GetRandomBaseTile(TileType.NOTHING);
            map.tileObjects[y][x].SpawnAndAddObject(ob);
        }
        else
        {
            // Pick a floor tile based on spawn rates
            DungeonObject ob = GetRandomBaseTile(TileType.FLOOR);
            map.tileObjects[y][x].SpawnAndAddObject(ob);
            if (tiles[y][x] != TileType.FLOOR)
            {
                var type = tiles[y][x];
                ob = GetRandomBaseTile(type);
                var instanceOb = map.tileObjects[y][x].SpawnAndAddObject(ob);

                if (type == TileType.DOOR)
                {
                    Direction orientation = Direction.UP;
                    if (y > 0 && tiles[y - 1][x] == TileType.WALL && y < tiles.Length - 1 && tiles[y + 1][x] == TileType.WALL)
                    {
                        orientation = Direction.RIGHT;
                    }
                    foreach (var glyph in instanceOb.GetComponentsInChildren <OrientedGlyph>(true))
                    {
                        glyph.orientation = orientation;
                    }
                }
            }
        }
    }
Пример #7
0
 public void CollideWith(DungeonObject ob, bool isInstigator)
 {
     if (onCollision != null)
     {
         onCollision(ob, isInstigator);
     }
 }
 public void TakeDamage(int amount, DungeonObject source)
 {
     if (invincible)
     {
         return;
     }
     if (heartLocketActive)
     {
         heartLocketActive  = false;
         invincibilityTime += invincibilityOnDamage * 2;
         return;
     }
     if ((health -= amount) <= 0)
     {
         health = 0;
         Die(source);
     }
     invincibilityTime += invincibilityOnDamage;
     if (hasLibPolicy && health == 1)
     {
         invincible = true;
         shieldTime = 5;
     }
     UpdateUI();
 }
Пример #9
0
    public void OnCollision(DungeonObject ob, bool isInstigator)
    {
        if (isInstigator)
        {
            return;
        }

        if (isLocked)
        {
            if (ob.GetComponent <Creature>())
            {
                DungeonObject key;
                bool          hasKey = ob.inventory.items.TryGetValue("Key", out key);
                if (hasKey)
                {
                    key.quantity--;
                    if (key.quantity == 0)
                    {
                        ob.inventory.items.Remove("Key");
                    }

                    SetOpen(true);
                }
            }
        }
        else
        {
            if (Random.value * 2 > openDifficulty)
            {
                SetOpen(true);
            }
        }
    }
 // Start is called before the first frame update
 void Awake()
 {
     floor            = FloorName.GARDEN;
     activeObjectType = DungeonObjectType.TILE;
     activeTile       = tiles[0];
     activeObject     = objects[0];
 }
 public void BlowUp(DungeonObject source, float damage)
 {
     if (damage > 0f)
     {
         TakeDamage(2, source);
     }
 }
    void AddObject(int x, int y)
    {
        if (x < 0 || y < 0 || x >= Room.gridWidth || y >= Room.gridHeight)
        {
            return;
        }
        if (activeObject == null)
        {
            return;
        }
        GameObject    _newObject = PrefabUtility.InstantiatePrefab(activeObject.gameObject) as GameObject;
        DungeonObject newObject  = _newObject.GetComponent <DungeonObject>();

        newObject.transform.SetParent(loadedRoom.transform);

        Vector2 postion;

        postion.x = x - Room.gridWidth / 2f + .5f;
        postion.y = y - Room.gridHeight / 2f + .5f;
        newObject.transform.position = loadedRoom.transform.TransformPoint(postion);

        newObject.room = loadedRoom;
        newObject.EnableDebug();

        loadedRoom.contents.objects.Add(newObject);
    }
Пример #13
0
    public static DungeonObject LoadDungeon(string Path)
    {
        string        JsonData      = File.ReadAllText($"{Path}");
        DungeonObject LoadedDungeon = JsonUtility.FromJson <DungeonObject>(JsonData);

        return(LoadedDungeon);
    }
Пример #14
0
    public override void Collide(DungeonObject ob)
    {
        if (isLocked)
        {
            if (ob.GetType() == typeof(Creature) || ob.GetType().IsSubclassOf(typeof(Creature)))
            {
                var           creature = (Creature)ob;
                DungeonObject key;
                bool          hasKey = creature.inventory.items.TryGetValue("Key", out key);
                if (hasKey)
                {
                    key.quantity--;
                    if (key.quantity == 0)
                    {
                        creature.inventory.items.Remove("Key");
                    }

                    SetOpen(true);
                }
            }
        }
        else
        {
            if (Random.value * 2 > openDifficulty)
            {
                SetOpen(true);
            }
        }
    }
Пример #15
0
    public void SaveFile()
    {
        string Filename = FilenameInput.text;

        DungeonObject dungeon = new DungeonObject();

        foreach (DungeonLevelEditorCell cell in m_AllCells)
        {
            switch (cell.CurrentCellType)
            {
            case DungeonLevelEditorCell.ECellType.Ground:
                dungeon.GroundPositions.Add(cell.transform.position);
                break;

            case DungeonLevelEditorCell.ECellType.Wall:
                dungeon.WallPositions.Add(cell.transform.position);
                break;

            case DungeonLevelEditorCell.ECellType.StartPosition:
                dungeon.StartPosition = cell.transform.position;
                break;

            case DungeonLevelEditorCell.ECellType.Upstairs:
                dungeon.UpstairsPosition = cell.transform.position;
                break;

            case DungeonLevelEditorCell.ECellType.Downstairs:
                dungeon.DownstairsPosition = cell.transform.position;
                break;
            }
        }

        DungeonHelpers.SaveDungeon(dungeon, $"{m_prependPath}/{Filename}");
    }
Пример #16
0
    void OnMapLoaded()
    {
        if (identity == null)
        {
            identity = Instantiate(playerPrefab);
            foreach (var behaviour in identity.GetComponents <TickableBehaviour>())
            {
                behaviour.enabled = false;
            }
            playerBehaviour         = identity.GetComponent <Tickable>().AddBehaviour <PlayerBehaviour>();
            identity.onSetPosition += OnPositionChange;
        }

        Tile startTile = map.GetRandomTileThatAllowsSpawn();

        startTile.AddObject(identity);
        map.UpdateLighting();
        map.Reveal(identity.x, identity.y, identity.viewDistance);

        mainCamera.GetComponent <PlayerCamera>().SetRotation(startTile.x, startTile.y, float.Epsilon, float.MaxValue);
        if (map.dungeonLevel == 1)
        {
            mainCamera.GetComponent <EntryAnimation>().isAnimating = true;
        }
        else
        {
            mainCamera.GetComponent <PlayerCamera>().SetY(identity.transform.position.y, 1, float.MaxValue);
        }
    }
Пример #17
0
    public void FinishAttack(DungeonObject dOb)
    {
        Creature creature = dOb.GetComponent <Creature>();
        Weapon   weapon   = null;

        if (rightHandObject != null)
        {
            weapon = rightHandObject.GetComponent <Weapon>();
        }

        if (attackWillHit && creature)
        {
            creature.baseObject.DamageFlash(1);
            // Got past armor / defense
            if (weapon == null)
            {
                creature.baseObject.TakeDamage(1);
            }
            else
            {
                int damage = UnityEngine.Random.Range(weapon.minBaseDamage, weapon.maxBaseDamage + 1);
                creature.baseObject.TakeDamage(damage);
            }
        }

        Vector3 originalPosition = baseObject.originalGlyphPosition;

        baseObject.glyphs.transform.localPosition = originalPosition;

        //tickable.nextActionTime = TimeManager.instance.time + (ulong)ticksPerAttack;
    }
Пример #18
0
        public static DungeonTile[,] Load(string json)
        {
            var  map = (JsonObject)SimpleJson.DeserializeObject(json);
            uint w = (uint)(long)map["width"], h = (uint)(long)map["height"];
            var  result = new DungeonTile[w, h];

            var    tiles = new Dictionary <ushort, DungeonTile>();
            ushort id    = 0;

            foreach (JsonObject tile in (JsonArray)map["dict"])
            {
                var mapTile  = new DungeonTile();
                var tileType = (string)tile.GetValueOrDefault("ground", "Space");
                mapTile.TileType = new TileType(tileType == "Space" ? 0xfe : (uint)tileType.GetHashCode(), tileType);

                mapTile.Region = tile.ContainsKey("regions") ? (string)((JsonObject)((JsonArray)tile["regions"])[0])["id"] : null;
                if (tile.ContainsKey("objs"))
                {
                    var obj     = (JsonObject)((JsonArray)tile["objs"])[0];
                    var tileObj = new DungeonObject
                    {
                        ObjectType = new ObjectType((uint)((string)obj["id"]).GetHashCode(), (string)obj["id"])
                    };
                    if (obj.ContainsKey("name"))
                    {
                        var attrs = (string)obj["name"];
                        tileObj.Attributes = attrs.Split(';')
                                             .Where(attr => !string.IsNullOrEmpty(attr))
                                             .Select(attr => attr.Split(':'))
                                             .Select(attr => new KeyValuePair <string, string>(attr[0], attr[1]))
                                             .ToArray();
                    }
                    else
                    {
                        tileObj.Attributes = Empty <KeyValuePair <string, string> > .Array;
                    }

                    mapTile.Object = tileObj;
                }
                else
                {
                    mapTile.Object = null;
                }
                tiles[id++] = mapTile;
            }

            var data  = RotMG.Common.IO.Zlib.Decompress(Convert.FromBase64String((string)map["data"]));
            var index = 0;

            for (var y = 0; y < h; y++)
            {
                for (var x = 0; x < w; x++)
                {
                    result[x, y] = tiles[(ushort)((data[index++] << 8) | data[index++])];
                }
            }

            return(result);
        }
Пример #19
0
 public static void kill(DungeonObject obj, float waitTime = 5f)
 {
     instance.map_manager.de_instantiate(obj.grid_pos, waitTime);
     if (obj is GameAgent)
     {
         instance.turn_manager.removeFromRoster(obj as GameAgent);
     }
 }
Пример #20
0
 public override void TakeDamage(int damage, DungeonObject attacker)
 {
     if (type == objectType.Trap)
     {
         damage *= 2;
     }
     base.TakeDamage(damage, attacker);
 }
Пример #21
0
 public Spell(SpellDef def, DungeonObject owner, Vector2 position) : base(def, position, "spells", state: Cast)
 {
     SpellDef = def;
     Position = new((int)Position.X / 16 * 16, (int)Position.Y / 16 * 16);
     game     = DungeonGame.Instance;
     player   = DungeonPlayer.Instance;
     Owner    = owner;
 }
Пример #22
0
 public void AddObject(DungeonObject ob)
 {
     ob.SetPosition(x, y);
     ob.transform.parent        = transform;
     ob.transform.localPosition = Vector3.zero;
     objectList.AddFirst(ob);
     SetRevealed(isRevealed);
 }
Пример #23
0
    /// <summary>
    /// Prepares the wall object for tile.
    /// </summary>
    /// <returns>
    /// Prepared wall object as dungeon object.
    /// </returns>
    /// <param name='code'>
    /// Code of tile.
    /// </param>
    /// <param name='objectType'>
    /// Object type.
    /// </param>
    /// <param name='prefabReference'>
    /// Prefab string reference to resource.
    /// </param>
    /// <param name='fromI'>
    /// I index of source tile.
    /// </param>
    /// <param name='fromJ'>
    /// J index of source tile.
    /// </param>
    /// <param name='toI'>
    /// I index of target tile.
    /// </param>
    /// <param name='toJ'>
    /// J index of target tile.
    /// </param>
    public static DungeonObject PrepareWallObject(int code, DungeonObjectType objectType, string prefabReference, int fromI, int fromJ, int toI, int toJ)
    {
        DungeonObject newDungeonObject = new DungeonObject(code, objectType, prefabReference);

        newDungeonObject.rotation = DungeonUtils.GetRotationFromToTile(fromI, fromJ, toI, toJ);
        newDungeonObject.offset   = newDungeonObject.rotation * new Vector3(0f, 0f, -DungeonUtils.TileSize * 0.5f);
        return(newDungeonObject);
    }
Пример #24
0
 public void WeildRightHand(DungeonObject ob)
 {
     if (rightHandObject != null)
     {
         rightHandObject.isWeilded = false;
     }
     rightHandObject = ob;
     ob.isWeilded    = true;
 }
Пример #25
0
    public DungeonObject SpawnAndAddObject(DungeonObject dungeonObject, int quantity = 1)
    {
        var ob = Instantiate(dungeonObject).GetComponent <DungeonObject>();

        ob.quantity = quantity;
        AddObject(ob);

        return(ob);
    }
Пример #26
0
    public static void SaveDungeon(DungeonObject dungeon, string Path)
    {
        string JsonFile = JsonUtility.ToJson(dungeon, true);

        Debug.Log(JsonFile);
        Debug.Log(Application.dataPath);

        File.WriteAllText($"{Application.dataPath}{Path}", JsonFile);
    }
Пример #27
0
 public override void TakeDamage(int damage, DungeonObject attacker)
 {
     anim.SetTrigger("Damage");
     if (hero == heroClass.Tank)
     {
         damage = Mathf.FloorToInt(damage * 0.5f);
     }
     base.TakeDamage(damage, attacker);
 }
Пример #28
0
    /// <summary>
    /// Updates the visible tiles.
    /// </summary>
    /// <param name='posI'>
    /// Position I index.
    /// </param>
    /// <param name='posJ'>
    /// Position J index.
    /// </param>
    public void UpdateVisibleTiles(int posI, int posJ)
    {
        Dictionary <int, List <GameObject> > newObjects = new Dictionary <int, List <GameObject> > ();

        //for every tile, that should be visible
        for (int j = -visibleTilesInFront; j < visibleTilesInFront; j++)
        {
            for (int i = -visibleTilesInFront; i < visibleTilesInFront; i++)
            {
                int objI = i + posI;
                int objJ = j + posJ;
                int code = DungeonUtils.GetCodeOfTileByIndex(objI, j + posJ);

                // If objects for this tile already instantiated
                if (createdObjects.ContainsKey(code))
                {
                    newObjects.Add(code, createdObjects [code]);
                    // Remove this list from old dictionary, so this objects will not be destroyed
                    createdObjects.Remove(code);
                }
                else                     // else if objects hasn't been instantiated for this tile, create it
                {
                    if (CurrentDungeon.Tiles.ContainsKey(code))
                    {
                        DungeonDataTile tile = CurrentDungeon.Tiles [code];
                        // Create new list
                        List <GameObject> tileObjects = new List <GameObject> ();
                        newObjects.Add(code, tileObjects);

                        // Instantiate every tile object
                        for (int objIndex = 0; objIndex < tile.Objects.Count; objIndex++)
                        {
                            DungeonObject dungeonObject = tile.Objects [objIndex];
                            GameObject    newObject     = Instantiate(
                                ResourceManager.GetResource(dungeonObject.type, dungeonObject.prefabReference) as Object,
                                DungeonUtils.GetPositionByIndex(objI, objJ) + dungeonObject.offset,
                                dungeonObject.rotation
                                ) as GameObject;
                            newObject.name = dungeonObject.prefabReference + "_" + code;
                            tileObjects.Add(newObject);
                        }
                    }
                }
            }
        }

        // Remove objects from dictionaries differences
        foreach (List <GameObject> objectListToRemove in createdObjects.Values)
        {
            for (int i = 0; i < objectListToRemove.Count; i++)
            {
                Destroy(objectListToRemove [i]);
            }
        }

        createdObjects = newObjects;
    }
Пример #29
0
    void AddSlot(DungeonObject item)
    {
        var slot = Instantiate(slotPrefab.gameObject, transform).GetComponent <InventorySlotGUI>();

        slot.Init(item);

        slots.Add(item.objectName, slot);

        UpdateIndexes();
    }
    public void Die(DungeonObject source)
    {
        Application.Quit();
#if UNITY_EDITOR
        if (EditorApplication.isPlaying)
        {
            UnityEditor.EditorApplication.isPlaying = false;
        }
#endif
    }