예제 #1
0
        private void Start()
        {
            var map  = Config.instance.map;
            var size = new Vector2Int(map.terrainArray.Length, map.terrainArray[0].Length);

            // check to load data
            if (GameData.dataToLoad != null)
            {
                var data = GameData.dataToLoad;
                for (int x = 0; x < size.x; ++x)
                {
                    for (int y = 0; y < size.y; ++y)
                    {
                        data.tombstones[x][y]?.Load();
                        data.terrains[x][y].Load();
                        data.units[x][y]?.Load();
                    }
                }
            }
            else
            {
                var index = new Vector3Int();
                for (index.x = 0; index.x < size.x; ++index.x)
                {
                    for (index.y = 0; index.y < size.y; ++index.y)
                    {
                        var wPos = index.ArrayToWorld();
                        AETerrain.DeSerialize(map.terrainArray[index.x][index.y], wPos);
                        Unit.DeSerialize(map.unitArray[index.x][index.y], wPos);
                    }
                }
            }
        }
예제 #2
0
            public virtual object Load(bool use = true)
            {
                var unit = New(name, Army.dict[armyColor], pos.ArrayToWorld());

                Set(unit);
                if (use)
                {
                    unit.Use();
                }
                return(unit);
            }
예제 #3
0
            public object Load(bool use = true)
            {
                var tombstone = Instantiate(R.asset.prefab.tombstone, pos.ArrayToWorld(), Quaternion.identity);

                tombstone.turn = turn;

                if (use)
                {
                    tombstone.Use();
                }
                return(tombstone);
            }
        private void Start()
        {
            var  level     = Level.instance;
            bool hasBottom = level.bottomArray != null;
            var  size      = new Vector2Int(level.middleArray.Length, level.middleArray[0].Length);
            var  index     = new Vector3Int();

            for (index.x = 0; index.x < size.x; ++index.x)
            {
                for (index.y = 0; index.y < size.y; ++index.y)
                {
                    Platform bottomPlatform = null, middlePlatform = null, topPlatform = null;
                    Mover    mover = null;
                    var      wPos = index.ArrayToWorld();
                    int      bottomID = -1, middleID = -1, topID = -1, moverID = -1;

                    // Find all IDs
                    middleID = level.middleArray[index.x][index.y];
                    topID    = level.topArray[index.x][index.y];
                    if (hasBottom)
                    {
                        bottomID = level.bottomArray[index.x][index.y];
                        moverID  = middleID;
                    }
                    else
                    {
                        moverID = topID;
                    }

                    // Deserialize Platform and Mover
                    if (bottomID != -1)
                    {
                        bottomPlatform = Platform.DeSerialize(bottomID, wPos);
                    }
                    if (moverID != -1)
                    {
                        mover = Mover.DeSerialize(moverID, wPos);
                    }
                    if (middleID != -1)
                    {
                        middlePlatform = Platform.DeSerialize(middleID, wPos);
                    }
                    if (topID != -1)
                    {
                        topPlatform = Platform.DeSerialize(topID, wPos);
                    }
                }
            }

            startGame = false;
        }
예제 #5
0
        public override void Load(string json)
        {
            ChessPiece.RecycleAll();
            var data = JsonUtility.FromJson <JsonData>(json);
            var size = new Vector2Int(data.array.Length, data.array[0].items.Length);

            array = new ChessPiece[size.x][];
            var index = new Vector3Int();

            for (index.x = 0; index.x < size.x; ++index.x)
            {
                array[index.x] = new ChessPiece[size.y];
                for (index.y = 0; index.y < size.y; ++index.y)
                {
                    var item = data.array[index.x].items[index.y];
                    if (item.hasPlayerID)
                    {
                        array[index.x][index.y] = ChessPiece.Get(item.playerID, index.ArrayToWorld());
                    }
                }
            }
        }
예제 #6
0
        public virtual async Task Attack(Vector3Int target, float eDeltaH, float thisDeltaH)
        {
            var enemy = array[target.x][target.y];

            if (!R.pool.selectCircle.activeSelf)
            {
                R.pool.selectCircle.SetActive(true);
                R.pool.selectCircle.transform.position = target.ArrayToWorld();
            }
            else
            {
                await R.Move(R.pool.selectCircle, target.ArrayToWorld(), 0.5f);
            }

            R.info.armyUI.UpdateTerrain(target);
            R.pool.Show(ObjectPool.POOL_KEY.YELLOW_FIRE, enemy.transform.position);
            await Task.Delay(600);

            R.pool.Hide(ObjectPool.POOL_KEY.YELLOW_FIRE);

            // Calculate attack health
            enemy.health -= (army == Battle.instance.army) ? eDeltaH : thisDeltaH;
            if (enemy.health <= 0f)
            {
                bool isActive = army == Battle.instance.army;
                if (isActive)
                {
                    UpdateUnitInfo(eDeltaH);
                }
                else
                {
                    UpdateUnitInfo(thisDeltaH);
                    enemy.UpdateUnitInfo(eDeltaH);
                }

                R.input.Wait(enemy.Die());
                if (isActive)
                {
                    isSleep = true;
                }
                R.pool.selectCircle.SetActive(false);
                return;
            }

            // Can enemy re-attack ?
            var thisPos = transform.position.WorldToArray();

            if (army == Battle.instance.army)
            {
                if (thisDeltaH >= 0f)
                {
                    await enemy.Attack(thisPos, eDeltaH, thisDeltaH);
                }
                else
                {
                    UpdateUnitInfo(eDeltaH);
                }
            }
            else
            {
                UpdateUnitInfo(thisDeltaH);
                enemy.UpdateUnitInfo(eDeltaH);
            }

            isSleep = array[thisPos.x][thisPos.y]?.army == Battle.instance.army;
            R.pool.selectCircle.SetActive(false);
        }
예제 #7
0
 protected void Set(AETerrain terrain)
 {
     terrain.transform.position = pos.ArrayToWorld();
     terrain.increaseDefend     = increaseDefend;
     terrain.decreaseMove       = decreaseMove;
 }