Esempio n. 1
0
    void SetMode(string modeName)
    {
        if (objectInfo.draw)
        {
            int newMode = System.Array.IndexOf(COF.ModeNames[2], modeName);
            if (newMode == -1 || !objectInfo.mode[newMode])
            {
                Debug.LogWarning("Failed to set mode '" + modeName + "' of object " + name);
                return;
            }

            if (objectInfo.hasCollision[mode])
            {
                CollisionMap.SetPassable(Iso.Snap(iso.pos), objectInfo.sizeX, objectInfo.sizeY, true, gameObject);
            }

            mode = newMode;

            var cof = COF.Load(@"data\global\objects", objectInfo.token, "HTH", modeName);
            animator.shadow = objectInfo.blocksLight[mode];
            animator.cof    = cof;
            animator.loop   = objectInfo.cycleAnim[mode];
            animator.SetFrameRange(objectInfo.start[mode], objectInfo.frameCount[mode]);
            animator.frameDuration = objectInfo.frameDuration[mode];

            if (objectInfo.hasCollision[mode])
            {
                CollisionMap.SetPassable(Iso.Snap(iso.pos), objectInfo.sizeX, objectInfo.sizeY, false, gameObject);
            }
        }
    }
Esempio n. 2
0
 private void Awake()
 {
     if (materialProperties == null)
     {
         materialProperties = new MaterialPropertyBlock();
     }
     CollisionMap.SetPassable(Iso.MapToIso(transform.position), false);
     animator = GetComponent <SpriteAnimator>();
 }
Esempio n. 3
0
        public void Kill(Unit killer = null)
        {
            _dying      = true;
            _targetUnit = null;
            _moving     = false;
            _usingSkill = false;
            _skillInfo  = null;

            CollisionMap.SetPassable(Iso.Snap(iso.pos), size, size, true, gameObject);

            Events.InvokeUnitDied(this, killer);
        }
Esempio n. 4
0
 void OnAnimationFinish()
 {
     targetCharacter = null;
     usingSkill      = false;
     takingDamage    = false;
     ressurecting    = false;
     skillInfo       = null;
     if (dying)
     {
         dying = false;
         dead  = true;
         CollisionMap.SetPassable(Iso.Snap(iso.pos), size, size, true, gameObject);
     }
 }
Esempio n. 5
0
        public void Hit(int damage, Unit originator = null)
        {
            if (_dying || _dead || _resurrecting)
            {
                return;
            }

            if (!killable)
            {
                return;
            }

            if (originator != null && originator.party == party)
            {
                return;
            }

            health -= damage;
            if (health > 0)
            {
                if (damage > maxHealth * 0.1f)
                {
                    overrideMode = "GH";
                    _targetUnit  = null;
                    _moving      = false;
                    _usingSkill  = false;
                    _skillInfo   = null;
                }

                Events.InvokeUnitTookDamage(this, damage);
            }
            else
            {
                if (originator)
                {
                    LookAtImmediately(originator.iso.pos);
                }
                _dying      = true;
                _targetUnit = null;
                _moving     = false;
                _usingSkill = false;
                _skillInfo  = null;

                CollisionMap.SetPassable(Iso.Snap(iso.pos), size, size, true, gameObject);

                Events.InvokeUnitDied(this, originator);
            }
        }
Esempio n. 6
0
        public void SetMode(StaticObjectMode mode)
        {
            if (!objectInfo.mode[mode.index])
            {
                Debug.LogWarning("Failed to set mode '" + mode + "' of object " + name);
                return;
            }

            if (objectInfo.hasCollision[_mode.index])
            {
                CollisionMap.SetPassable(Iso.Snap(_iso.pos), objectInfo.sizeX, objectInfo.sizeY, true, gameObject);
            }
            if (objectInfo.hasCollision[mode.index])
            {
                CollisionMap.SetPassable(Iso.Snap(_iso.pos), objectInfo.sizeX, objectInfo.sizeY, false, gameObject);
            }

            _mode              = mode;
            _animationTime     = 0;
            _animationDuration = objectInfo.frameCount[_mode.index] * objectInfo.frameDuration[_mode.index];
        }
Esempio n. 7
0
        public void TakeDamage(int damage, Character originator = null)
        {
            if (_dying || _dead || _resurrecting)
            {
                return;
            }

            if (!killable)
            {
                return;
            }

            if (originator != null && originator.party == party)
            {
                return;
            }

            health -= damage;
            if (health > 0)
            {
                if (OnTakeDamage != null)
                {
                    OnTakeDamage(originator, damage);
                }
                if (damage > maxHealth * 0.1f)
                {
                    overrideMode     = "GH";
                    _targetCharacter = null;
                    _moving          = false;
                    _usingSkill      = false;
                    _skillInfo       = null;
                }

                if (monStat != null)
                {
                    AudioManager.instance.Play(monStat.sound.hit, transform, monStat.sound.hitDelay);
                }
            }
            else
            {
                if (originator)
                {
                    LookAtImmediately(originator.iso.pos);
                }
                _dying           = true;
                _targetCharacter = null;
                _moving          = false;
                _usingSkill      = false;
                _skillInfo       = null;

                CollisionMap.SetPassable(Iso.Snap(iso.pos), size, size, true, gameObject);

                if (OnDeath != null)
                {
                    OnDeath(this, originator);
                }

                if (monStat != null)
                {
                    AudioManager.instance.Play(monStat.sound.death, transform, monStat.sound.deathDelay);
                }
            }
        }
Esempio n. 8
0
    static Renderer CreateTile(DT1.Tile tile, int x, int y, int orderInLayer = 0, Transform parent = null)
    {
        var texture = tile.texture;
        var pos     = Iso.MapTileToWorld(x, y);

        GameObject gameObject = new GameObject();

        gameObject.name = tile.mainIndex + "_" + tile.subIndex + "_" + tile.orientation;
        gameObject.transform.position = pos;
        if (parent)
        {
            gameObject.transform.SetParent(parent);
        }
        var   meshRenderer = gameObject.AddComponent <MeshRenderer>();
        var   meshFilter   = gameObject.AddComponent <MeshFilter>();
        Mesh  mesh         = new Mesh();
        float x0           = tile.textureX;
        float y0           = tile.textureY;
        float w            = tile.width / Iso.pixelsPerUnit;
        float h            = (-tile.height) / Iso.pixelsPerUnit;

        if (tile.orientation == 0 || tile.orientation == 15)
        {
            var topLeft = new Vector3(-1f, 0.5f);
            if (tile.orientation == 15)
            {
                topLeft.y += tile.roofHeight / Iso.pixelsPerUnit;
            }
            mesh.vertices = new Vector3[] {
                topLeft,
                topLeft + new Vector3(0, -h),
                topLeft + new Vector3(w, -h),
                topLeft + new Vector3(w, 0)
            };
            mesh.triangles = new int[] { 2, 1, 0, 3, 2, 0 };
            mesh.uv        = new Vector2[] {
                new Vector2(x0 / texture.width, -y0 / texture.height),
                new Vector2(x0 / texture.width, (-y0 + tile.height) / texture.height),
                new Vector2((x0 + tile.width) / texture.width, (-y0 + tile.height) / texture.height),
                new Vector2((x0 + tile.width) / texture.width, -y0 / texture.height)
            };

            meshRenderer.sortingLayerName = tile.orientation == 0 ? "Floor" : "Roof";
            meshRenderer.sortingOrder     = orderInLayer;
        }
        else
        {
            var topLeft = new Vector3(-1f, h - 0.5f);
            mesh.vertices = new Vector3[] {
                topLeft,
                topLeft + new Vector3(0, -h),
                topLeft + new Vector3(w, -h),
                topLeft + new Vector3(w, 0)
            };
            mesh.triangles = new int[] { 2, 1, 0, 3, 2, 0 };
            mesh.uv        = new Vector2[] {
                new Vector2(x0 / texture.width, (-y0 - tile.height) / texture.height),
                new Vector2(x0 / texture.width, -y0 / texture.height),
                new Vector2((x0 + tile.width) / texture.width, -y0 / texture.height),
                new Vector2((x0 + tile.width) / texture.width, (-y0 - tile.height) / texture.height)
            };
            meshRenderer.sortingOrder = Iso.SortingOrder(pos) - 4;
        }
        meshFilter.mesh = mesh;

        int  flagIndex          = 0;
        var  collisionMapOffset = Iso.Snap(Iso.MapToIso(pos));
        byte mask = DT1.BlockFlags.Walk | DT1.BlockFlags.PlayerWalk;

        for (int dy = 2; dy > -3; --dy)
        {
            for (int dx = -2; dx < 3; ++dx, ++flagIndex)
            {
                var  subCellPos = collisionMapOffset + new Vector2i(dx, dy);
                bool passable   = (tile.flags[flagIndex] & mask) == 0;
                if (tile.orientation == 0)
                {
                    CollisionMap.SetPassable(subCellPos, passable);
                }
                else if (CollisionMap.Passable(subCellPos) && !passable)
                {
                    CollisionMap.SetPassable(subCellPos, false);
                }
            }
        }

        meshRenderer.material = tile.material;
        return(meshRenderer);
    }
Esempio n. 9
0
 private void OnDisable()
 {
     CollisionMap.SetPassable(Iso.MapToIso(transform.position), true);
 }