Beispiel #1
0
        public override void Update()
        {
            if (_overrider || _stunTime <= 0 || _stunTarget == null)
            {
                if (!_overrider && _stunTarget != null)
                {
                    _stunTarget.immobilized = false;
                }
                Level.Remove(this);
                return;
            }

            _stunTarget.immobilized = true;

            Ragdoll rag = _stunTarget.ragdoll;

            rag._part1.vSpeed  += NetRand.Float(-2f, 2f);
            rag._part3.vSpeed  += NetRand.Float(-2f, 2f);
            rag._part2.vSpeed  -= NetRand.Float(1.5f, 2f);
            rag._part2.position = ipos + new Vec2(10f * mover.value);
            rag._timeSinceNudge = 0f;

            _stunTime--;

            base.Update();
        }
Beispiel #2
0
        private float DoTest(int runs, int probability, int precision)
        {
            int jep = 0;

            for (int i = 0; i < runs; i++)
            {
                jep += NetRand.Chance(probability, precision) ? 1 : 0;
            }
            return(jep * 1f / runs);
        }
Beispiel #3
0
        public CardDeck(ISquad owner, IEnumerable <ICardData> cards)
        {
            Owner           = owner;
            MaximumHandSize = 10;

            _drawPile = new Stack <Card>(cards.OrderBy(_ => NetRand.Next()).Select((c, i) => new Card(i, c)));

            _discardPile = new List <Card>();
            _handCards   = new List <Card>();

            _bus = ServiceLocator.Instance.GetService <IMessageBus>();
        }
Beispiel #4
0
        private void ChanceTest()
        {
            NetRand.Seed(0);
            Debug.Log($"5, 10: {DoTest(10000, 5, 10)}");

            NetRand.Seed(0);
            Debug.Log($"1, 10: {DoTest(10000, 1, 10)}");

            NetRand.Seed(0);
            Debug.Log($"3, 10: {DoTest(10000, 3, 10)}");

            NetRand.Seed(0);
            Debug.Log($"2, 3: {DoTest(10000, 2, 3)}");

            NetRand.Seed(0);
            Debug.Log($"45, 100: {DoTest(10000, 45, 100)}");
        }
Beispiel #5
0
        public void DrawCard()
        {
            if (_handCards.Count >= MaximumHandSize)
            {
                return;
            }

            if (_drawPile.Count == 0)
            {
                foreach (var c in _discardPile.OrderBy(_ => NetRand.Next()))
                {
                    _drawPile.Push(c);
                }
                _discardPile.Clear();
            }

            var card = _drawPile.Pop();

            _handCards.Add(card);

            _bus.Publish(new CardDrawnMessage(this, card));
        }
Beispiel #6
0
        public static ISet <HexCubeCoord> Polymino(IHexCoord origin, int size)
        {
            // OBACHT!
            // use NetRand for now, should replace with some interface thingy, that can be passed as parameter!

            var center = origin.CubeCoord;

            var coords = new HashSet <HexCubeCoord>();

            coords.Add(center);

            int tries = 0;

            while (coords.Count < size)
            {
                // choose hex
                // TODO: add parameter for lengthy/bulky polyminos
                // param=1 => choose hexes farther from origin, param=0 => prefer hexes near origin

                // maybe each hex can only be chosen once / twice?
                center = coords.ElementAt(NetRand.Range(0, coords.Count));

                // add max dist parameter?

                // choose random neighbor, here the lengthy/bulky param could also be used?
                var neighbor = center + Offset(NetRand.Enum <HexDirection>());

                // add neighbor to collection
                coords.Add(neighbor);

                tries++;
            }

            //Debug.Log($"generated polymino of size {size}. took {tries} tries.");

            return(coords);
        }
Beispiel #7
0
        public static bool Generate(IGameConfiguration game, IHexMap _map, IEntityManager _gem, out List <Squad> _squads)
        {
            _map.Columns = game.Map.Columns;
            _map.Rows    = game.Map.Rows;

            _map.GenParams.noiseOffset = game.Map.NoiseOffset;
            _map.GenParams.noiseScale  = game.Map.NoiseScale;
            _map.GenParams.heightScale = game.Map.HeightScale;

            // Initialize Random with seed!
            NetRand.Seed(game.RandomSeed);

            _map.BuildMap();

            var deckConfig = Resources.Load <CardDeckConfig>("Basic_Deck");

            _squads = new List <Squad>();
            foreach (var config in game.Squads)
            {
                var squad = new Squad(config, deckConfig);
                squad.CreateMembers(_gem);

                _squads.Add(squad);
            }

            var blacklist = new HashSet <HexOffsetCoord>();

            foreach (var s in _squads)
            {
                foreach (var e in s.Members)
                {
                    blacklist.UnionWith(HexFun.Ring(e.GetComponent <HexPosComp>().Position).Select(c => c.OffsetCoord));
                }
            }

            // hole in the middle
            var center = _map.Center.CubeCoord + HexFun.Offset(HexDirection.West);

            /*
             * //for (int i = 0; i < 2; i++)
             * {
             *  var pos = center;// + HexCubeCoord.Offset(NetRand.Enum<HexDirection>(), 1);
             *  foreach (var c in HexCubeCoord.Spiral(pos))
             *      if (NetRand.Chance(7, 10))
             *          _map.RemoveTile(c);
             * }
             * {
             *  var pos = center + HexCubeCoord.Offset(HexDirection.SouthEast) + HexCubeCoord.Offset(HexDirection.East);
             *  foreach (var c in HexCubeCoord.Spiral(pos))
             *      if (NetRand.Chance(7, 10))
             *          _map.RemoveTile(c);
             * }
             */
            foreach (var c in HexFun.Polymino(center, 9))
            {
                //_map.GetTile(c)?.SetColor(Color.blue);
                _map.RemoveTile(c);
            }

            // cut of corners with no altar
            // hard code this for now
            for (int c = 0; c < _map.Columns; c++)
            {
                for (int r = 0; r < _map.Rows; r++)
                {
                    var coord = new HexOffsetCoord(c, r).CubeCoord;
                    if (Mathf.Abs(coord.x - 2) > NetRand.Range(6, 8))
                    {
                        //_map.GetTile(coord)?.SetColor(Color.green);
                        _map.RemoveTile(coord);
                    }
                }
            }

            //foreach (var c in blacklist)
            //    _map.GetTile(c)?.SetColor(Color.red);

            // spawn debris on map
            int debrisCount = NetRand.Range(7, 10);

            for (int i = 0; i < debrisCount; i++)
            {
                // find empty position
                var pos  = NetRand.HexOffset(_map.Columns, _map.Rows);
                var tile = _map.GetTile(pos);
                while (tile == null || blacklist.Contains(pos) || tile.HasEntityOnTop)
                {
                    pos  = NetRand.HexOffset(_map.Columns, _map.Rows);
                    tile = _map.GetTile(pos);
                }

                var deb = _gem.CreateEntity("mountain");
                deb.GetComponent <HexPosComp>().SetPosition(pos);

                foreach (var npos in HexFun.Ring(pos, 2))
                {
                    var neighbor = _map.GetTile(npos);
                    if (neighbor == null || blacklist.Contains(npos.OffsetCoord) || neighbor.HasEntityOnTop)
                    {
                        continue;
                    }
                    if (NetRand.Chance(3, 10))
                    {
                        var ndeb = _gem.CreateEntity("mountain");
                        ndeb.GetComponent <HexPosComp>().SetPosition(npos);
                    }
                }
            }

            // generate forest patches
            int treeCount = NetRand.Range(7, 16);

            for (int i = 0; i < debrisCount; i++)
            {
                var pos  = NetRand.HexOffset(_map.Columns, _map.Rows);
                var tile = _map.GetTile(pos);
                while (tile == null || tile.Terrain != HexTerrain.Plain || tile.HasEntityOnTop)
                {
                    pos  = NetRand.HexOffset(_map.Columns, _map.Rows);
                    tile = _map.GetTile(pos);
                }

                tile.Terrain = HexTerrain.Forest;

                foreach (var npos in HexFun.Ring(pos))
                {
                    var neighbor = _map.GetTile(npos);
                    if (neighbor == null || neighbor.Terrain != HexTerrain.Plain || neighbor.HasEntityOnTop)
                    {
                        continue;
                    }
                    if (NetRand.Chance(3, 10))
                    {
                        neighbor.Terrain = HexTerrain.Forest;
                    }
                }
            }

            // check that there is a path from base to base
            var altarPos = _squads[0].Members[0].GetComponent <HexPosComp>().Position;
            var nav      = _map.GetNav(new HexNavSettings(altarPos));

            var otherAltar = _squads[1].Members[0].GetComponent <HexPosComp>().Position;

            var target  = otherAltar;
            int minDist = int.MaxValue;

            foreach (var n in HexFun.Ring(otherAltar))
            {
                var dist = nav.GetDistance(n);
                if (dist == null)
                {
                    Debug.Log("NO PATH BETWEEN ALTARS!");
                    return(false);
                }
                if (dist.Value < minDist)
                {
                    minDist = dist.Value;
                    target  = n.CubeCoord;
                }
            }

            //var path = nav.PathToOrigin(target).ToList();
            //foreach (var c in path)
            //{
            //    _map.GetTile(c).SetColor(new Color32(163, 198, 255, 255));
            //}

            return(true);
        }