Ejemplo n.º 1
0
        private MapTeams CreateModel()
        {
            var dataSourceId = RenderingContext.CurrentOrNull.Rendering.DataSource;
            var item         = Sitecore.Context.Database.GetItem(dataSourceId);

            var mapTeams = new MapTeams()
            {
                Title = new HtmlString(FieldRenderer.Render(item, "Title")),
                Close = item.Fields["Close"].Value,
                Teams = Common.GetTeams(item)
            };

            return(mapTeams);
        }
Ejemplo n.º 2
0
        void IGroupPlaceableGenContext <Team> .PlaceItems(Team itemBatch, Loc[] locs)
        {
            if (locs != null)
            {
                if (locs.Length != itemBatch.Players.Count)
                {
                    throw new Exception("Team members not matching locations!");
                }
                for (int ii = 0; ii < itemBatch.Players.Count; ii++)
                {
                    itemBatch.Players[ii].CharLoc = locs[ii];
                }
            }

            MapTeams.Add(itemBatch);
        }
Ejemplo n.º 3
0
        public List <Character> RespawnMob()
        {
            List <Character> respawns = new List <Character>();

            if (TeamSpawns.Count > 0)
            {
                bool[][] traversedGrid = new bool[Width][];
                for (int xx = 0; xx < Width; xx++)
                {
                    traversedGrid[xx] = new bool[Height];
                }

                List <Loc> freeTiles = new List <Loc>();
                Grid.FloodFill(new Rect(new Loc(), new Loc(Width, Height)),
                               (Loc testLoc) =>
                {
                    if (traversedGrid[testLoc.X][testLoc.Y])
                    {
                        return(true);
                    }
                    return(TileBlocked(testLoc));
                },
                               (Loc testLoc) =>
                {
                    if (traversedGrid[testLoc.X][testLoc.Y])
                    {
                        return(true);
                    }
                    return(TileBlocked(testLoc, true));
                },
                               (Loc testLoc) =>
                {
                    traversedGrid[testLoc.X][testLoc.Y] = true;

                    //must be walkable, not have a nonwalkable on at least 3 cardinal directions, not be within eyesight of any of the player characters
                    foreach (Character character in ActiveTeam.Players)
                    {
                        if (character.IsInSightBounds(testLoc))
                        {
                            return;
                        }
                    }

                    foreach (Team team in MapTeams)
                    {
                        foreach (Character character in team.Players)
                        {
                            if (!character.Dead && character.CharLoc == testLoc)
                            {
                                return;
                            }
                        }
                    }
                    freeTiles.Add(testLoc);
                },
                               EntryPoints[0].Loc);

                if (freeTiles.Count > 0)
                {
                    for (int ii = 0; ii < 10; ii++)
                    {
                        Team newTeam = TeamSpawns.Pick(Rand).Spawn(this);
                        if (newTeam == null)
                        {
                            continue;
                        }
                        Loc trialLoc = freeTiles[Rand.Next(freeTiles.Count)];
                        //find a way to place all members- needs to fit all of them in, or else fail the spawn

                        Grid.LocTest checkOpen = (Loc testLoc) =>
                        {
                            if (TileBlocked(testLoc))
                            {
                                return(false);
                            }

                            Character locChar = GetCharAtLoc(testLoc);
                            if (locChar != null)
                            {
                                return(false);
                            }
                            return(true);
                        };
                        Grid.LocTest checkBlock = (Loc testLoc) =>
                        {
                            return(TileBlocked(testLoc, true));
                        };
                        Grid.LocTest checkDiagBlock = (Loc testLoc) =>
                        {
                            return(TileBlocked(testLoc, true, true));
                        };

                        List <Loc> resultLocs = new List <Loc>();
                        foreach (Loc loc in Grid.FindClosestConnectedTiles(new Loc(), new Loc(Width, Height),
                                                                           checkOpen, checkBlock, checkDiagBlock, trialLoc, newTeam.Players.Count))
                        {
                            resultLocs.Add(loc);
                        }


                        if (resultLocs.Count >= newTeam.Players.Count)
                        {
                            for (int jj = 0; jj < newTeam.Players.Count; jj++)
                            {
                                newTeam.Players[jj].CharLoc = resultLocs[jj];
                            }

                            MapTeams.Add(newTeam);

                            foreach (Character member in newTeam.Players)
                            {
                                member.RefreshTraits();
                                respawns.Add(member);
                            }
                            break;
                        }
                    }
                }
            }
            return(respawns);
        }