private void NewTileMaybe(int column, int row)
 {
     if (!tileTable.Contains(column, row) && HexUtils.Distance(column, row, playerCoords.x, playerCoords.y) <= generateDistance + 1)
     {
         HexTile hexTile = maker.GenerateTile(column, row);
         tileTable.Set(column, row, hexTile);
     }
 }
Example #2
0
        private static async Task runGame()
        {
            var state = GetState();
            var board = new GameBoard(state);

            MongoGameState.GameEntity ent;
            int px;
            int pz;

            Random rand    = new Random();
            var    details = EntityDetails.Detail;

            while (true)
            {
                bool result;

                while (true)
                {
                    if (rand.Next(0, 100) < 30)
                    {
                        count++;
                        var p = rand.Next(0, board.GameState.Entities.Count);
                        ent = board.GameState.Entities[p];
                        var detail = details[ent.EntityType];

                        var entities = board.GameState.Entities.Where(
                            a => a != ent &&
                            a.FactionId != ent.FactionId &&
                            HexUtils.Distance(board.GetHexagon(a.X, a.Z), board.GetHexagon(ent.X, ent.Z)) <
                            detail.AttackRadius
                            ).ToArray();

                        if (entities.Length == 0)
                        {
                            continue;
                        }

                        var attackEnt = entities[rand.Next(0, entities.Length)];

                        result = await Vote(new PostVoteRequest()
                        {
                            EntityId   = ent.Id,
                            Action     = VoteActionType.Attack,
                            UserId     = "faa",
                            Generation = board.GameState.Generation,
                            X          = attackEnt.X,
                            Z          = attackEnt.Z
                        });

                        if (result)
                        {
                            state = GetState();
                            board = new GameBoard(state);
                        }
                    }
                    else
                    {
                        count++;
                        var p = rand.Next(0, board.GameState.Entities.Count);
                        ent = board.GameState.Entities[p];
                        var detail = details[ent.EntityType];
                        px = ent.X + rand.Next(-detail.MoveRadius, detail.MoveRadius + 1);
                        pz = ent.Z + rand.Next(-detail.MoveRadius, detail.MoveRadius + 1);
                        if (px == 0 && pz == 0)
                        {
                            continue;
                        }
                        if (board.GetHexagon(px, pz) == null)
                        {
                            continue;
                        }
                        if (board.GetHexagon(ent.X, ent.Z) == null)
                        {
                            continue;
                        }

                        var distance = HexUtils.Distance(board.GetHexagon(px, pz), board.GetHexagon(ent.X, ent.Z));
                        if (distance > detail.MoveRadius)
                        {
                            break;
                        }
                        result = await Vote(new PostVoteRequest()
                        {
                            EntityId   = ent.Id,
                            Action     = VoteActionType.Move,
                            UserId     = "faa",
                            Generation = board.GameState.Generation,
                            X          = px,
                            Z          = pz
                        });

                        if (result)
                        {
                            state = GetState();
                            board = new GameBoard(state);
                        }
                    }
                }
            }
        }
Example #3
0
        public static async Task <PostVoteResponse> VoteAction(VoteServerLogic logic, PostVoteRequest model)
        {
            if (logic.GameManager.Locked)
            {
                return new PostVoteResponse()
                       {
                           IssueVoting = true
                       }
            }
            ;

            var gameState = logic.GameManager.GameState;
            var board     = logic.GameManager.GameBoard;

            if (model.Generation != gameState.Generation)
            {
                return(new PostVoteResponse()
                {
                    GenerationMismatch = true
                });
            }

            var entity = gameState.GetEntityById(model.EntityId);

            if (entity == null)
            {
                return new PostVoteResponse()
                       {
                           IssueVoting = true
                       }
            }
            ;
            MongoGameVote.VoteAction action;

            var hex1 = board.GetHexagon(entity.X, entity.Z);
            var hex2 = board.GetHexagon(model.X, model.Z);

            if (hex1 == null || hex2 == null)
            {
                return(new PostVoteResponse()
                {
                    IssueVoting = true
                });
            }
            var distance = HexUtils.Distance(hex1, hex2);


            var detail = EntityDetails.Detail[entity.EntityType];


            switch (model.Action)
            {
            case VoteActionType.Move:

                if (distance <= 0 || distance > detail.MoveRadius)
                {
                    return(new PostVoteResponse()
                    {
                        IssueVoting = true
                    });;
                }
                action = new MongoGameVote.MoveVoteAction()
                {
                    EntityId = model.EntityId, X = model.X, Z = model.Z
                };
                break;

            case VoteActionType.Attack:

                if (distance <= 0 || distance > detail.AttackRadius)
                {
                    return(new PostVoteResponse()
                    {
                        IssueVoting = true
                    });;
                }
                var attackEntity = gameState.GetEntityByLocation(model.X, model.Z);
                if (attackEntity == null || attackEntity.FactionId == entity.FactionId)
                {
                    return(new PostVoteResponse()
                    {
                        IssueVoting = true
                    });;
                }
                action = new MongoGameVote.AttackVoteAction()
                {
                    EntityId = model.EntityId, X = model.X, Z = model.Z
                };
                break;

            case VoteActionType.Spawn:
                if (distance <= 0 || distance > detail.SpawnRadius)
                {
                    return(new PostVoteResponse()
                    {
                        IssueVoting = true
                    });;
                }
                action = new MongoGameVote.SpawnVoteAction()
                {
                    EntityId = model.EntityId, X = model.X, Z = model.Z, EntityType = model.EntityType.Value
                };
                break;

            default:
                throw new RequestValidationException("Action not found");
            }



            MongoGameVote.GameVote gameVote = new MongoGameVote.GameVote()
            {
                Generated  = DateTime.UtcNow,
                Generation = model.Generation,
                UserId     = model.UserId,
                Action     = action
            };

            gameVote.Insert();



            var trackedVotes = logic.GameManager.TrackedVotes.Where(a => a.Action.EntityId == model.EntityId).ToList();
            var trackedVote  = trackedVotes.FirstOrDefault(a => action.ActionType == a.Action.ActionType && action.Equates(a.Action));

            if (trackedVote == null)
            {
                trackedVotes.Add(new TrackedVote()
                {
                    Action = action,
                    Votes  = 1,
                });
            }
            else
            {
                trackedVote.Votes++;
            }

            logic.Client.SendAllPoolMessage("VotePool", "AddVote", new GameVoteMessage()
            {
                Vote = gameVote
            });


            return(new PostVoteResponse()
            {
                Votes = trackedVotes.ToArray()
            });
        }
    }
}
        // Update is called once per frame
        void Update()
        {
            //if (keepPlayerAbove ) {
            //	HexNavMeshManager.EnsureAboveMap(targetObject.transform);
            //}

            playerCoords = maker.WorldPositionToAxialCoords(targetObject.transform.position);

            //Debug.Log(playerCoords);

            if (HexUtils.Distance(lastPlayerCoords, playerCoords) > 0)
            {
                //int x = playerCoords.x - lastPlayerCoords.x;
                //int y = playerCoords.y - lastPlayerCoords.y;
                //// TODO: if the player teleports this function doesn't know what to do
                //HexDirection direction = HexUtils.VectorToDirection(x, y);

                int z = HexUtils.Z(playerCoords.x, playerCoords.y);
                //switch (direction) {
                //	case HexDirection.E:
                RemoveMinColumns();
                AddMaxColumns();

                RemoveMaxZs(z);
                AddMinZs(z);

                //		break;
                //	case HexDirection.NE:
                RemoveMinRows();
                AddMaxRows();

                //		RemoveMaxZs(z);
                //		AddMinZs(z);
                //		break;
                //	case HexDirection.NW:
                //		RemoveMinRows();
                //		AddMaxRows();

                RemoveMaxColumns();
                AddMinColumns();

                //		break;
                //	case HexDirection.W:
                //		RemoveMaxColumns();
                //		AddMinColumns();

                RemoveMinZs(z);
                AddMaxZs(z);

                //		break;
                //	case HexDirection.SW:
                RemoveMaxRows();
                AddMinRows();

                //		RemoveMinZs(z);
                //		AddMaxZs(z);
                //		break;
                //	case HexDirection.SE:
                //		RemoveMinColumns();
                //		AddMaxColumns();
                //		RemoveMaxRows();
                //		AddMinRows();
                //		break;
                //}
            }

            lastPlayerCoords = playerCoords;
        }