Ejemplo n.º 1
0
        public IEnumerable <PortalModel> FindLinkablePortals(Faction faction, KeyInventoryModel inventory, PortalModel source)
        {
            string message;

            if (!IsLinkableSource(faction, source, out message))
            {
                Debug.Log(message);
                return(Enumerable.Empty <PortalModel>());
            }

            var candidatePortals = portals.Where(p => IsLinkableTarget(faction, inventory, source, p, out message)).ToList();

            candidatePortals.Sort((a, b) => a.DistanceFrom(source.Position).CompareTo(b.DistanceFrom(source.Position)));
            return(candidatePortals);
        }
Ejemplo n.º 2
0
        public LinkModel AddLink(Faction faction, KeyInventoryModel inventory, PortalModel source, PortalModel target)
        {
            string message;

            if (IsLinkableSource(faction, source, out message) && IsLinkableTarget(faction, inventory, source, target, out message))
            {
                LinkModel newLink = new LinkModel(source, target);
                links.Add(newLink);
                source.NumberOfLinks++;
                target.NumberOfLinks++;
                return(newLink);
            }
            else
            {
                throw new Exception(message);
            }
        }
Ejemplo n.º 3
0
        public bool IsLinkableTarget(Faction faction, KeyInventoryModel inventory, PortalModel source, PortalModel target, out string message)
        {
            if (source == target)
            {
                message = string.Format("Source portal {0} is also the target portal.", source);
                return(false);
            }

            if (target.Faction != faction)
            {
                message = string.Format("Target portal {0} is an enemy portal.", target);
                return(false);
            }

            if (!inventory.HasKey(target))
            {
                message = string.Format("No key for target portal {0}.", target);
                return(false);
            }

            if (links.Any(link => link.Overlaps(target)))
            {
                message = string.Format("Target portal {0} is overlapped by a link.", target);
                return(false);
            }

            LinkModel newLink = new LinkModel(source, target);

            if (links.Any(link => link.EqualsIgnoreDirection(newLink)))
            {
                message = string.Format("Link already exists between portal {0} and {1}.", source, target);
                return(false);
            }

            if (links.Any(link => link.Intersects(newLink)))
            {
                message = "Link crosses an existing link.";
                return(false);
            }

            message = "";
            return(true);
        }