Пример #1
0
        public static Warp Create(int x, int y, LevelWarpInfo warpInfo, LevelInfo sourceLevel, LevelInfo targetLevel, Transform parent)
        {
            var offset = new Vector3(warpInfo.offsetX, warpInfo.offsetY);
            var pos    = new Vector3(x, y) * Iso.SubTileCount - new Vector3(2, 2) + offset;

            pos = Iso.MapToWorld(pos);

            var warpObject = new GameObject(targetLevel.levelWarp);

            warpObject.transform.position = pos;
            warpObject.transform.SetParent(parent);
            var warp = warpObject.AddComponent <Warp>();

            warp.sourceLevel   = sourceLevel;
            warp.targetLevel   = targetLevel;
            warp.info          = warpInfo;
            warp.transform     = warpObject.transform;
            warp.selectSize    = new Vector3(warpInfo.selectDX, warpInfo.selectDY) / Iso.pixelsPerUnit;
            warp.selectOffset  = new Vector3(warpInfo.selectX, -warpInfo.selectY) / Iso.pixelsPerUnit;
            warp.selectOffset += new Vector3(warp.selectSize.x, -warp.selectSize.y) / 2;
            warpInfo.instance  = warp;
            return(warp);
        }
Пример #2
0
    public static bool Passable(int index, int size = 1, bool debug = false, GameObject ignore = null)
    {
        UnityEngine.Profiling.Profiler.BeginSample("PassableTile");
        if (index - size - size * instance.width < 0 || index + size + size * instance.width >= instance.map.Length)
        {
            return(false);
        }

        index = index - size / 2 - size / 2 * instance.height;
        int step = instance.width - size;

        for (int y = 0; y < size; ++y)
        {
            int end = index + size;
            while (index < end)
            {
                if (debug)
                {
                    var tilePos = instance.MapToIso(index);
                    Iso.DebugDrawTile(tilePos, 0.1f);
                }

                var cell = instance.map[index];
                if (!cell.passable && (ignore == null || ignore != cell.gameObject))
                {
                    UnityEngine.Profiling.Profiler.EndSample();
                    return(false);
                }
                ++index;
            }
            index += step;
        }

        UnityEngine.Profiling.Profiler.EndSample();

        return(true);
    }
Пример #3
0
        private void InstantiateDebugGrid(Vector2i offset, Transform root)
        {
            UnityEngine.Profiling.Profiler.BeginSample("LevelBuilder.InstantiateDebugGrid");
            var grid = new GameObject("debug grid");

            grid.transform.SetParent(root);
            grid.layer = UnityLayers.SpecialTiles;

            for (int y = 0; y < gridHeight; ++y)
            {
                for (int x = 0; x < gridWidth; ++x)
                {
                    var cellObject = new GameObject(x + ", " + y);
                    cellObject.transform.position = Iso.MapToWorld(
                        (x * gridX + offset.x) * Iso.SubTileCount - 2,
                        (y * gridY + offset.y) * Iso.SubTileCount - 2);
                    cellObject.transform.SetParent(grid.transform);
                    cellObject.layer = UnityLayers.SpecialTiles;
                    var line = cellObject.AddComponent <LineRenderer>();
                    line.startWidth    = 0.1f;
                    line.endWidth      = 0.1f;
                    line.material      = Materials.normal;
                    line.useWorldSpace = false;
                    var corners = new Vector3[] {
                        Iso.MapTileToWorld(0, 0),
                        Iso.MapTileToWorld(0 + gridX, 0),
                        Iso.MapTileToWorld(0 + gridX, gridY),
                        Iso.MapTileToWorld(0, gridY),
                        Iso.MapTileToWorld(0, 0)
                    };
                    line.positionCount = corners.Length;
                    line.SetPositions(corners);
                }
            }
            UnityEngine.Profiling.Profiler.EndSample();
        }
Пример #4
0
        public GameObject Instantiate(Vector2i offset)
        {
            UnityEngine.Profiling.Profiler.BeginSample("LevelBuilder.Instantiate");
            var root = new GameObject(name);

            if (info != null)
            {
                var collider = root.AddComponent <PolygonCollider2D>();
                collider.offset    = Iso.MapTileToWorld(offset);
                collider.points    = Iso.CreateTileRectPoints(info.sizeX, info.sizeY);
                collider.isTrigger = true;

                var level = root.AddComponent <Level>();
                level.info = info;

                SelectMonsterTypes();
            }

            InstantiateGrid(offset, root.transform);
            InstantiateDebugGrid(offset, root.transform);

            UnityEngine.Profiling.Profiler.EndSample();
            return(root);
        }
Пример #5
0
        public static Pickup Create(Vector3 position, string flippyFile, string name, string title = null, int dir = 0)
        {
            position = Iso.MapToIso(position);
            if (!CollisionMap.Fit(position, out position, mask: CollisionLayers.Item))
            {
                Debug.LogError("Can't fit pickup");
                return(null);
            }
            position = Iso.MapToWorld(position);
            var gameObject = new GameObject(name);

            gameObject.transform.position = position;
            // todo: Maybe add customized palette
            var palette     = Palette.GetPalette(PaletteType.Act1);
            var spritesheet = DC6.Load(flippyFile, palette);
            var animator    = gameObject.AddComponent <SpriteAnimator>();

            animator.SetSprites(spritesheet.GetSprites(dir));
            animator.loop = false;
            var pickup = gameObject.AddComponent <Pickup>();

            pickup.title = title;
            return(pickup);
        }
Пример #6
0
    void OperateWithTarget()
    {
        if (takingDamage || dead || dying || ressurecting || usingSkill)
        {
            return;
        }

        if (targetEntity)
        {
            var distance = Vector2.Distance(iso.pos, Iso.MapToIso(targetEntity.transform.position));
            if (distance <= size + targetEntity.operateRange)
            {
                var localEntity = targetEntity;
                moving       = false;
                targetEntity = null;
                localEntity.Operate(this);
                PlayerController.instance.FlushInput();
            }
            else
            {
                moving = true;
            }
        }
    }
Пример #7
0
    IEnumerator Attack()
    {
        while (true)
        {
            if (Random.Range(0, 100) > 60)
            {
                character.GoTo(iso.pos);
                yield return(new WaitForSeconds(Random.Range(0.5f, 0.7f)));
            }

            character.UseSkill(SkillInfo.Attack, target);
            yield return(new WaitForSeconds(Random.Range(1.5f, 2f)));

            Iso targetIso = target.GetComponent <Iso>();
            if (Vector2.Distance(targetIso.pos, iso.pos) > maxAgroDistance)
            {
                yield return(new WaitForSeconds(Random.Range(0.5f, 1f)));

                target = null;
                StartCoroutine(Roam());
                yield break;
            }
        }
    }
Пример #8
0
 public void GetLocalInstant_29thOfFebruaryInNonLeapYear_Throws()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => Iso.ValidateYearMonthDay(2010, 2, 29));
 }
Пример #9
0
 public void ValidateYearMonthDay_InvalidYear_Throws()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => Iso.ValidateYearMonthDay(50000, 2, 20));
 }
Пример #10
0
 void Awake()
 {
     iso            = GetComponent <Iso>();
     animator       = GetComponent <COFAnimator>();
     animator.equip = gear;
 }
Пример #11
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);
                }
            }
        }
Пример #12
0
		public SizeF GetPaperSize(DiagramUnit unit, Iso name)
		{
			Size mm = new Size();

			if (name == Iso.FourA) mm = new Size(1682,2378);
			if (name == Iso.TwoA) mm = new Size(1189,1682);
			if (name == Iso.A0) mm = new Size(841,1189);
			if (name == Iso.A1) mm = new Size(594,841);
			if (name == Iso.A2) mm = new Size(420,594);
			if (name == Iso.A3) mm = new Size(297,420);
			if (name == Iso.A4) mm = new Size(210,297);
			if (name == Iso.A5) mm = new Size(148,210);
			if (name == Iso.A6) mm = new Size(105,148);
			if (name == Iso.A7) mm = new Size(74,105);
			if (name == Iso.A8) mm = new Size(52,74);
			if (name == Iso.A9) mm = new Size(37,52);
			if (name == Iso.A10) mm = new Size(26,37);

			if (name == Iso.FourB) mm = new Size(2000,2828);
			if (name == Iso.TwoB) mm = new Size(1414,2000);
			if (name == Iso.B0) mm = new Size(1000,1414);
			if (name == Iso.B1) mm = new Size(707,1000);
			if (name == Iso.B2) mm = new Size(500,707);
			if (name == Iso.B3) mm = new Size(353,500);
			if (name == Iso.B4) mm = new Size(250,353);
			if (name == Iso.B5) mm = new Size(176,250);
			if (name == Iso.B6) mm = new Size(125,176);
			if (name == Iso.B7) mm = new Size(88,125);
			if (name == Iso.B8) mm = new Size(62,88);
			if (name == Iso.B9) mm = new Size(44,62);
			if (name == Iso.B10) mm = new Size(31,44);

			if (name == Iso.C0) mm = new Size(917,1297);
			if (name == Iso.C1) mm = new Size(648,917);
			if (name == Iso.C2) mm = new Size(458,648);
			if (name == Iso.C3) mm = new Size(324,458);
			if (name == Iso.C4) mm = new Size(229,324);
			if (name == Iso.C5) mm = new Size(162,229);
			if (name == Iso.C6) mm = new Size(114,162);
			if (name == Iso.C7) mm = new Size(81,114);
			if (name == Iso.C8) mm = new Size(57,81);
			if (name == Iso.C9) mm = new Size(40,57);
			if (name == Iso.C10) mm = new Size(28,40);

			//Convert to diagram unit supplied
			return ConvertSize(mm,DiagramUnit.Millimeter,unit);
		}
Пример #13
0
 private void OnDisable()
 {
     CollisionMap.SetBlocked(Iso.MapToIso(transform.position), CollisionLayers.None);
 }
Пример #14
0
        public void Do(Unit self, Unit targetUnit, Vector3 target)
        {
            if (srvDoFunc == 27)
            {
                // teleport
                self.InstantMove(target);
            }

            if (srvDoFunc == 1)
            {
                Item           weapon   = self.equip == null ? null : self.equip.GetWeapon();
                int            damage   = 10;
                WeaponHitClass hitClass = WeaponHitClass.HandToHand;
                bool           ranged   = false;
                if (weapon != null)
                {
                    WeaponInfo weaponInfo = weapon.info.weapon;
                    hitClass = weaponInfo.hitClass;
                    if (weaponInfo.twoHanded)
                    {
                        damage = Random.Range(weaponInfo.twoHandedMinDamage, weaponInfo.twoHandedMaxDamage + 1);
                    }
                    else
                    {
                        damage = Random.Range(weaponInfo.minDamage, weaponInfo.maxDamage + 1);
                    }

                    ranged = weapon.info.type.shoots != null;
                }

                if (ranged)
                {
                    var missile = Missile.Create("arrow", target, self);
                    missile.weaponDamage = damage;
                }
                else if (targetUnit != null && IsRangeOk(self, targetUnit, target))
                {
                    AudioManager.instance.Play(hitClass.hitSound, targetUnit.transform.position);
                    targetUnit.Hit(damage, self);
                }
            }
            else if (srvDoFunc == 17)
            {
                // charged bold, bolt sentry
                int boltCount = 7;
                for (int i = 0; i < boltCount; ++i)
                {
                    var offset = new Vector3(Random.Range(-boltCount / 2f, boltCount / 2f), Random.Range(-boltCount / 2f, boltCount / 2f));
                    Missile.Create(clientMissileA, self.iso.pos, target + offset, self);
                }
            }
            else if (srvDoFunc == 22)
            {
                // nova, poison nova, howl
                int missileCount = 64;
                Missile.CreateRadially(clientMissileA, self.iso.pos, self, missileCount);
            }
            else if (srvDoFunc == 31)
            {
                // raise skeleton, raise skeletal mage
                var pos     = Iso.MapToWorld(target);
                var monster = global::Diablerie.Game.World.WorldBuilder.SpawnMonster(summon, pos, summoner: self);
                monster.overrideMode = summode;
                Missile.Create(clientMissileA, target, target, self);
            }
            else if (srvDoFunc == 45)
            {
                // traps
                var pos     = Iso.MapToWorld(target);
                var monster = global::Diablerie.Game.World.WorldBuilder.SpawnMonster(summon, pos, summoner: self);
                monster.overrideMode = summode;
                Missile.Create(clientMissileA, target, target, self);
            }
            else if (srvDoFunc == 56 || srvDoFunc == 57)
            {
                // 57 iron golem, 56 other golems
                var pos     = Iso.MapToWorld(target);
                var monster = global::Diablerie.Game.World.WorldBuilder.SpawnMonster(summon, pos, summoner: self);
                monster.overrideMode = summode;
            }
            else if (srvDoFunc == 114)
            {
                // raven
                var pos     = Iso.MapToWorld(target);
                var monster = global::Diablerie.Game.World.WorldBuilder.SpawnMonster(summon, pos, summoner: self);
                monster.overrideMode = summode;
            }
            else if (srvDoFunc == 119)
            {
                // summon grizzly, wolves, spirits
                var pos     = Iso.MapToWorld(target);
                var monster = global::Diablerie.Game.World.WorldBuilder.SpawnMonster(summon, pos, summoner: self);
                monster.overrideMode = summode;
            }
            else if (srvDoFunc == 68)
            {
                // barbarian howls
                int missileCount = 64;
                Missile.CreateRadially(clientMissileA, self.iso.pos, self, missileCount);
            }
            else
            {
                if (clientMissileA != null)
                {
                    Missile.Create(clientMissileA, self.iso.pos, target, self);
                }
            }

            if (clientMissile != null)
            {
                Missile.Create(clientMissile, self.iso.pos, target, self);
            }
        }
Пример #15
0
        private static void Spawn(MonStat monStat, int x, int y, int level, Transform root)
        {
            CollisionLayers collisionMask = CollisionLayers.Walk;

            if (!CollisionMap.Passable(new Vector2i(x, y) * Iso.SubTileCount, collisionMask, monStat.ext.sizeX))
            {
                return;
            }

            int count = Random.Range(monStat.minGrp, monStat.maxGrp + 1);

            for (int i = 0; i < count; ++i)
            {
                var mon = global::Diablerie.Game.World.WorldBuilder.SpawnMonster(monStat, Iso.MapTileToWorld(x, y), root);
                mon.level = level;
            }

            if (monStat.minion1 != null)
            {
                int minionCount = Random.Range(monStat.partyMin, monStat.partyMax);
                for (int i = 0; i < minionCount; ++i)
                {
                    var mon = global::Diablerie.Game.World.WorldBuilder.SpawnMonster(monStat.minion1, Iso.MapTileToWorld(x, y), root);
                    mon.level = level;
                }
            }
        }
Пример #16
0
    void Start()
    {
        Vector2i playerPos = CreateAct1();

        SpawnPlayer(className, Iso.MapTileToWorld(playerPos));
    }
Пример #17
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.sortingLayerID = tile.orientation == 0 ? SortingLayers.Floor : SortingLayers.Roof;
                meshRenderer.sortingOrder   = orderInLayer;

                gameObject.name += tile.orientation == 0 ? " (floor)" : " (roof)";
            }
            else if (tile.orientation > 15)
            {
                int upperPart = Math.Min(96, -tile.height);
                y0 -= upperPart;
                var topLeft = new Vector3(-1f, upperPart / Iso.pixelsPerUnit - 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 / 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.sortingLayerID = SortingLayers.LowerWall;
                meshRenderer.sortingOrder   = orderInLayer;

                gameObject.name += " (lower wall)";
            }
            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)
                };
                if (tile.orientation == 13) // shadows
                {
                    meshRenderer.sortingLayerID = SortingLayers.Shadow;
                }
                meshRenderer.sortingOrder = Iso.SortingOrder(pos) - 4;
            }
            meshFilter.mesh = mesh;

            int flagIndex          = 0;
            var collisionMapOffset = Iso.Snap(Iso.MapToIso(pos));

            DT1.BlockFlags mask = DT1.BlockFlags.Walk | DT1.BlockFlags.PlayerWalk;
            for (int dy = 2; dy > -3; --dy)
            {
                for (int dx = -2; dx < 3; ++dx, ++flagIndex)
                {
                    Vector2i        subCellPos    = collisionMapOffset + new Vector2i(dx, dy);
                    bool            passable      = (tile.flags[flagIndex] & mask) == 0;
                    CollisionLayers blockedLayers = passable ? CollisionLayers.None : CollisionLayers.Walk;
                    if (tile.orientation == 0)
                    {
                        CollisionMap.SetBlocked(subCellPos, blockedLayers);
                    }
                    else if (CollisionMap.Passable(subCellPos, CollisionLayers.Walk) && !passable)
                    {
                        CollisionMap.SetBlocked(subCellPos, blockedLayers);
                    }
                }
            }

            meshRenderer.material = tile.material;
            return(meshRenderer);
        }
Пример #18
0
 void Awake()
 {
     iso       = GetComponent <Iso>();
     character = GetComponent <Character>();
 }
Пример #19
0
    void Process(string input)
    {
        if (input == "")
        {
            return;
        }

        if (history.Count == 0 || history[history.Count - 1] != input)
        {
            history.Add(input);
        }

        string[] parts = input.Split(' ');
        if (parts.Length >= 2 && parts[0] == "/spawn")
        {
            var pos = Iso.MapToWorld(IsoInput.mouseTile);
            if (parts[1] == "pickup")
            {
                string flippyFile = @"data\global\items\flp" + parts[2] + ".dc6";
                Pickup.Create(pos, flippyFile, flippyFile);
                return;
            }

            if (parts[1] == "item")
            {
                string code = parts[2];
                ItemDrop.Drop(code, pos, 100);
                return;
            }

            if (parts[1] == "itemset")
            {
                string subname = parts[2];
                var    set     = ItemSet.sheet.Find(s => s.id.ToLower().Contains(subname));
                if (set != null)
                {
                    foreach (var setItem in set.items)
                    {
                        var item = Item.Create(setItem.itemCode);
                        item.quality    = Item.Quality.Set;
                        item.level      = setItem.level;
                        item.identified = false;
                        ItemDrop.GenerateSetItem(item);
                        Pickup.Create(pos, item);
                    }
                }
                return;
            }

            var id = parts[1];

            var objectInfo = ObjectInfo.Find(id);
            if (objectInfo != null)
            {
                var obj = World.SpawnObject(objectInfo, pos, fit: true);
                if (obj != null && parts.Length > 2)
                {
                    obj.modeName = parts[2];
                }
                return;
            }

            World.SpawnMonster(id, pos);
        }
        else
        {
            Debug.LogWarning(input);
        }
    }
Пример #20
0
 protected override void Start()
 {
     base.Start();
     _renderer.sortingOrder = Iso.SortingOrder(transform.position);
 }
 public override int GetHashCode()
 {
     return(Iso.GetHashCode());
 }
Пример #22
0
 public void LookAtImmediately(Vector3 target)
 {
     _directionIndex = _desiredDirection = Iso.Direction(iso.pos, target, DirectionCount);
 }
Пример #23
0
    void ControlCharacter()
    {
        if (character == null)
        {
            return;
        }

        DrawDebugPath();

        if (_mouseItem != null)
        {
            if (Input.GetMouseButtonDown(0))
            {
                Pickup.Create(character.transform.position, _mouseItem);
                FlushInput();
                mouseItem = null;
            }
            return;
        }

        usingSkills = false;
        for (int i = 0; i < hotSkills.Count; ++i)
        {
            SkillInfo skill = hotSkills[i];
            KeyCode   key   = hotSkillsBindings[i];
            if (skill == null || !Input.GetKey(key))
            {
                continue;
            }

            usingSkills = true;
            if (MouseSelection.current != null)
            {
                var targetCharacter = MouseSelection.current.GetComponent <Character>();
                if (targetCharacter != null)
                {
                    character.UseSkill(skill, targetCharacter);
                }
                else
                {
                    character.UseSkill(skill, Iso.MapToIso(MouseSelection.current.transform.position));
                }
            }
            else
            {
                character.UseSkill(skill, IsoInput.mousePosition);
            }
        }

        // move to PlayerController members once Datasheets loading done not in static section
        SkillInfo leftSkill  = SkillInfo.Attack;
        SkillInfo rightSkill = SkillInfo.Attack;

        if (!usingSkills)
        {
            if (Input.GetMouseButton(1) || (Input.GetKey(KeyCode.LeftShift) && Input.GetMouseButton(0)))
            {
                character.UseSkill(rightSkill, IsoInput.mousePosition);
            }
            else if (Input.GetMouseButton(0) && !EventSystem.current.IsPointerOverGameObject())
            {
                if (MouseSelection.current != null)
                {
                    var targetCharacter = MouseSelection.current.GetComponent <Character>();
                    if (targetCharacter != null)
                    {
                        if (targetCharacter.monStat != null && targetCharacter.monStat.npc)
                        {
                            // todo interact with npc
                        }
                        else
                        {
                            character.UseSkill(leftSkill, targetCharacter);
                        }
                    }
                    else
                    {
                        character.Use(MouseSelection.current);
                    }
                }
                else
                {
                    character.GoTo(IsoInput.mousePosition);
                }
            }
            else
            {
                character.LookAt(IsoInput.mousePosition);
            }
        }

        character.run = run;
    }
Пример #24
0
 protected override void Awake()
 {
     base.Awake();
     iso       = GetComponent <Iso>();
     _animator = GetComponent <COFAnimator>();
 }
Пример #25
0
    public void Use(MiscInfo itemInfo)
    {
        Debug.Log("Use item " + itemInfo.name + ", function: " + itemInfo.useFunction);
        switch (itemInfo.useFunction)
        {
        case MiscInfo.UseFunction.None:
            break;

        case MiscInfo.UseFunction.IdentifyItem:
            break;

        case MiscInfo.UseFunction.TownPortal:
            var pos      = Iso.MapToWorld(iso.pos);
            var teleport = World.SpawnObject("TP", pos, fit: true);
            teleport.modeName = "OP";
            var sound = SoundInfo.Find("player_townportal_cast");
            AudioManager.instance.Play(sound, pos);
            break;

        case MiscInfo.UseFunction.Potion:
            if (itemInfo.stat1 == "hpregen")
            {
                character.health += itemInfo.calc1;
            }
            if (itemInfo.stat1 == "manarecovery")
            {
                character.mana += itemInfo.calc1;
            }
            break;

        case MiscInfo.UseFunction.RejuvPotion:
            if (itemInfo.stat1 == "hitpoints")
            {
                character.health += (int)(itemInfo.calc1 / 100.0f * character.maxHealth);
            }
            if (itemInfo.stat1 == "mana")
            {
                character.mana += (int)(itemInfo.calc1 / 100.0f * character.maxMana);
            }
            if (itemInfo.stat2 == "hitpoints")
            {
                character.health += (int)(itemInfo.calc2 / 100.0f * character.maxHealth);
            }
            if (itemInfo.stat2 == "mana")
            {
                character.mana += (int)(itemInfo.calc2 / 100.0f * character.maxMana);
            }
            break;

        case MiscInfo.UseFunction.TemporaryPotion:
            break;

        case MiscInfo.UseFunction.HoradricCube:
            break;

        case MiscInfo.UseFunction.Elixir:
            break;

        case MiscInfo.UseFunction.StaminaPotion:
            break;
        }
    }
Пример #26
0
 public void ValidateYearMonthDay_AllValues_ValidValuesDoesntThrow()
 {
     Iso.ValidateYearMonthDay(20, 2, 20);
 }
Пример #27
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);
    }
Пример #28
0
 public void GetLocalInstant_InvalidMonth_Throws()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => Iso.ValidateYearMonthDay(2010, 13, 20));
 }
Пример #29
0
    static bool CreateObject(SpawnPreset obj, int x, int y, int level, Transform root)
    {
        var pos = Iso.MapToWorld(x - 2, y - 2);

        if (obj.type == 2)
        {
            if (obj.objectId >= ObjectInfo.sheet.Count)
            {
                return(false);
            }
            ObjectInfo objectInfo   = ObjectInfo.sheet[obj.objectId];
            var        staticObject = World.SpawnObject(objectInfo, pos, parent: root);
            staticObject.modeName = obj.mode;
            return(true);
        }
        else
        {
            string      monPreset   = MonPreset.Find(obj.act, obj.id);
            MonStat     monStat     = null;
            SuperUnique superUnique = null;

            if (monPreset != null)
            {
                monStat = MonStat.Find(monPreset);
                if (monStat == null)
                {
                    superUnique = SuperUnique.Find(monPreset);
                }
            }
            else
            {
                monStat = MonStat.sheet[obj.id];
            }

            if (monStat != null)
            {
                World.SpawnMonster(monStat, pos, root);
                return(true);
            }

            if (superUnique != null)
            {
                var monster = World.SpawnMonster(superUnique.monStat, pos, root);
                monster.gameObject.name = superUnique.nameStr;
                monster.title           = superUnique.name;
                monster.level           = level;
                int minionCount = Random.Range(superUnique.minGrp, superUnique.maxGrp + 1);
                for (int i = 0; i < minionCount; ++i)
                {
                    var minion = World.SpawnMonster(superUnique.monStat, pos, root);
                    minion.level = level;
                }
                return(true);
            }

            if (obj.id == 10)
            {
                // Fallens
                for (int i = 0; i < 4; ++i)
                {
                    World.SpawnMonster("fallen1", pos, root);
                }
                return(true);
            }

            if (obj.id == 11)
            {
                // Fallen shaman + fallens
                Spawn(MonStat.Find("fallenshaman1"), x, y, level, root);
                for (int i = 0; i < 4; ++i)
                {
                    var fallen = World.SpawnMonster("fallen1", pos, root);
                    fallen.level = level;
                }
                return(true);
            }

            if (obj.id == 27)
            {
                // Fallen shaman
                Spawn(MonStat.Find("fallenshaman1"), x, y, level, root);
                return(true);
            }

            return(false);
        }
    }
Пример #30
0
 public void GetLocalInstant_29thOfFebruaryInLeapYear_DoesntThrow()
 {
     Iso.ValidateYearMonthDay(2012, 2, 29);
 }
Пример #31
0
    public static Character SpawnMonster(MonStat monStat, Vector3 pos, Transform parent = null)
    {
        pos = Iso.MapToIso(pos);
        if (!CollisionMap.Fit(pos, out pos, monStat.ext.sizeX))
        {
            return(null);
        }
        pos = Iso.MapToWorld(pos);

        var monster = new GameObject(monStat.nameStr);

        monster.transform.SetParent(parent);
        monster.transform.position = pos;

        var character = monster.AddComponent <Character>();

        character.monStat     = monStat;
        character.title       = monStat.name;
        character.basePath    = @"data\global\monsters";
        character.token       = monStat.code;
        character.weaponClass = monStat.ext.baseWeaponClass;
        character.run         = false;
        character.walkSpeed   = monStat.speed;
        character.runSpeed    = monStat.runSpeed;
        character.size        = monStat.ext.sizeX;

        var monLvl = MonLvl.Find(monStat.level[0]);

        if (monLvl != null && !monStat.noRatio)
        {
            character.health = Random.Range(monLvl.hp[0] * monStat.stats[0].minHP, monLvl.hp[0] * monStat.stats[0].maxHP + 1) / 100;
        }
        else
        {
            character.health = Random.Range(monStat.stats[0].minHP, monStat.stats[0].maxHP + 1);
        }
        character.maxHealth = character.health;

        var animator = character.GetComponent <COFAnimator>();

        animator.equip = new string[monStat.ext.gearVariants.Length];
        for (int i = 0; i < animator.equip.Length; ++i)
        {
            var variants = monStat.ext.gearVariants[i];
            if (variants == null)
            {
                continue;
            }
            animator.equip[i] = variants[Random.Range(0, variants.Length)];
        }

        if (monStat.ai == "Npc")
        {
            monster.AddComponent <NpcController>();
        }
        else if (monStat.ai != "Idle" && monStat.ai != "NpcStationary")
        {
            monster.AddComponent <MonsterController>();
        }

        var body = monster.AddComponent <Rigidbody2D>();

        body.isKinematic = true;
        var collider = monster.AddComponent <CircleCollider2D>();

        collider.radius = monStat.ext.sizeX * Iso.tileSizeY;

        return(character);
    }