Ejemplo n.º 1
0
    void Update()
    {
        if (!GameManager.Instance.dead)
        {
            while (levelCount < MaxSpawn)
            {
                Level s_Level = Instantiate(g_Level.gameObject, transform).GetComponent <Level>();
                s_Level.name = "Level " + level;
                level++;

                if (curLevel != null)
                {
                    s_Level.Obstacle = true;
                    if (!firstWall)
                    {
                        int j = 0;
                        for (int i = 1; i < 4; i++)
                        {
                            if (i != ((side + 2) % 4) && i != ((side + 2) % 4))
                            {
                                availableSides[j] = i;
                                j++;
                            }
                        }
                        side = availableSides[(int)(Lehmer.Next() * j)];
                    }
                    else
                    {
                        side      = 2;
                        firstWall = false;
                    }

                    Wall_Door prev = GetWall(curLevel, side);
                    Wall_Door next = GetWall(s_Level, (side + 2) % 4);

                    prev.Opened   = true;
                    next.Opened   = true;
                    next.Entrance = true;

                    switch (side)
                    {
                    case 1:
                        pos.x += LevelUnits;
                        break;

                    case 2:
                        pos.z += LevelUnits;
                        break;

                    case 3:
                        pos.x -= LevelUnits;
                        break;
                    }
                }

                s_Level.transform.position = pos;
                curLevel = s_Level;

                levels.Add(s_Level);
                levelCount++;
            }
        }
    }
    GameObject OffsetPrefab(PrefabSet sectionItem, GameObject obs)
    {
        Vector3 ori = obs.transform.position;
        Vector3 pos = ori;

        if (sectionItem.Origin != OriginPara.Center)
        {
            float xo = 0;
            float yo = 0;

            switch (sectionItem.Origin)
            {
            case OriginPara.NorthEast:
                xo = levelUnits / 2;
                yo = levelUnits / 2;
                break;

            case OriginPara.NorthWest:
                xo = -levelUnits / 2;
                yo = levelUnits / 2;
                break;

            case OriginPara.SouthEast:
                xo = levelUnits / 2;
                yo = -levelUnits / 2;
                break;

            case OriginPara.SouthWest:
                xo = -levelUnits / 2;
                yo = -levelUnits / 2;
                break;

            case OriginPara.RandomCorner:
                xo = levelUnits / 2 * ((Lehmer.Next() > 0.5) ? -1 : 1);
                yo = levelUnits / 2 * ((Lehmer.Next() > 0.5) ? -1 : 1);
                break;

            case OriginPara.Random:
                if (Lehmer.Next() > 0.5)
                {
                    xo = levelUnits / 2 * ((Lehmer.Next() > 0.5) ? -1 : 1);
                    yo = levelUnits / 2 * ((Lehmer.Next() > 0.5) ? -1 : 1);
                }
                break;
            }

            float ao = (start == 1 || start == 3) ? yo : xo;
            float bo = (start == 1 || start == 3) ? xo : yo;

            switch (start)
            {
            case 1:
                ao *= -1;
                break;

            case 2:
                ao *= -1;
                bo *= -1;
                break;

            case 3:
                bo *= -1;
                break;
            }

            pos.x += ao;
            pos.z += bo;
        }

        Vector2 d = Vector2.zero;

        if (sectionItem.UseCustomPos)
        {
            d = (sectionItem.EndPos - sectionItem.StartPos);
        }
        else
        {
            d = (levelUnits * Vector2.one) - sectionItem.Size;
        }

        float x = (int)(Lehmer.Next() * d.x);
        float y = (int)(Lehmer.Next() * d.y);

        float a = (start == 1 || start == 3) ? y : x;
        float b = (start == 1 || start == 3) ? x : y;

        switch (start)
        {
        case 1:
            a *= -1;
            break;

        case 2:
            a *= -1;
            b *= -1;
            break;

        case 3:
            b *= -1;
            break;
        }

        a -= ((pos - ori).x == 0.0f) ? a : (((pos - ori).x > 0) ? (sectionItem.Size.x / 2) : -(sectionItem.Size.y / 2));
        b -= ((pos - ori).z == 0.0f) ? b : (((pos - ori).z > 0) ? (sectionItem.Size.y / 2) : -(sectionItem.Size.y / 2));

        pos.x += a;
        pos.z += b;

        if (sectionItem.Offset != OffsetPara.None)
        {
            float offset = 4.0f;
            int   dir    = 0;

            switch (sectionItem.Offset)
            {
            case OffsetPara.Closer:
                dir = 1;
                break;

            case OffsetPara.Further:
                dir = -1;
                break;

            case OffsetPara.Random:
                dir = (Lehmer.Next() > 0.5) ? -1 : 1;
                break;
            }

            switch (start)
            {
            case 0:
                pos.z -= offset * dir;
                break;

            case 1:
                pos.x += offset * dir;
                break;

            case 2:
                pos.z += offset * dir;
                break;

            case 3:
                pos.x -= offset * dir;
                break;
            }
        }

        pos.y = 0.0f;
        obs.transform.position = pos;

        if (start == 1 || start == 3)
        {
            obs.transform.rotation = Quaternion.AngleAxis(90.0f, Vector3.up);
        }

        return(obs);
    }
Ejemplo n.º 3
0
        void CommmitDirtyData(DirtyData dirtyData, CommitItems commitItems)
        {
            lock (_revenueLock)
            {
                foreach (var tick in dirtyData.DirtyRevenueTicks)
                {
                    var revenues = GetRevenueReceivers(tick);

                    _revenueReceiversStroage.UpdateEntry(tick, revenues.ToByteArray());
                    _revenueReceiversStroage.LastAvailableTick = Math.Max(tick, _revenueReceiversStroage.LastAvailableTick);
                }

                var last = GetRevenueReceivers(_revenueReceiversStroage.LastAvailableTick);
                if (last != null)
                {
                    var previous      = GetRevenueReceivers(last.PreviousTick);
                    var lastProcessed = _revenueReceiversStroage.LastProcessedTick;

                    while (previous != null)
                    {
                        if (previous.Tick <= lastProcessed)
                        {
                            break;
                        }

                        var tick        = previous.Tick;
                        var accounts    = previous.Accounts;
                        var count       = accounts.Count;
                        var revenueInfo = previous.RevenueInfo;

                        var tickRevenue    = revenueInfo.Revenue * revenueInfo.AccountRevenueFactor;
                        var accountRevenue = tickRevenue / count;
                        var maxCount       = tickRevenue / Currency.OneCen;

                        if (count > maxCount)
                        {
                            var list = new List <long>(accounts);
                            list.Sort((a, b) => a.CompareTo(b));

                            var rand = new Lehmer(count);
                            for (var i = 0; i < count; i++)
                            {
                                var a = rand.Next(count);

                                var tmp = list[i];
                                list[i] = list[a];
                                list[a] = tmp;
                            }

                            for (var i = 0; i < maxCount; i++)
                            {
                                var accountId = list[i];
                                var account   = GetMaintainAccount(accountId);
                                account.AddRevenue(tick, (int)Currency.OneCen);
                                commitItems.DirtyAccounts.Add(accountId);
                            }
                        }
                        else
                        {
                            foreach (var accountId in accounts)
                            {
                                var account = GetMaintainAccount(accountId);
                                account.AddRevenue(tick, accountRevenue);
                                commitItems.DirtyAccounts.Add(accountId);
                            }
                        }

                        previous = GetRevenueReceivers(previous.PreviousTick);
                    }

                    _revenueReceiversStroage.LastProcessedTick = last.PreviousTick;
                }
            }

            foreach (var accountId in commitItems.DirtyAccounts)
            {
                var account = GetMaintainAccount(accountId);
                _maintainAccountStorage.UpdateEntry(accountId, account.ToByteArray());
            }
        }
    public void GenerateObstacles()
    {
        if (obstacles.Count > 0)
        {
            foreach (GameObject obj in obstacles)
            {
                Destroy(obj);
            }
            obstacles.Clear();
        }

        if (enemies.Count > 0)
        {
            foreach (GameObject obj in enemies)
            {
                Destroy(obj);
            }
            enemies.Clear();
        }

        for (int i = 0; i < 4; i++)
        {
            Wall_Door wall = GetWall(i);
            if (wall.Opened)
            {
                if (wall.Entrance)
                {
                    start = i;
                }
                else
                {
                    end = i;
                }
            }
        }

        int        selection;
        PrefabSet  sectionItem;
        GameObject item;
        GameObject obs;

        if (Lehmer.Next() > 0.5)
        {
            selection   = Mathf.FloorToInt((float)Lehmer.Next() * Sections.Length);
            sectionItem = Sections[selection];

            item = sectionItem.Prefab;
            obs  = Instantiate(item, transform);
            obs  = OffsetPrefab(sectionItem, obs);

            obstacles.Add(obs);
        }

        if (Lehmer.Next() > 0.5)
        {
            selection   = Mathf.FloorToInt((float)Lehmer.Next() * Enemies.Length);
            sectionItem = Enemies[selection];

            item = sectionItem.Prefab;
            obs  = Instantiate(item, transform);
            obs  = OffsetPrefab(sectionItem, obs);

            enemies.Add(obs);
        }
    }