Пример #1
0
        public PortalModel AddPortal(Vector2 position, Faction faction)
        {
            var portal = new PortalModel(position, faction);

            portals.Add(portal);
            return(portal);
        }
Пример #2
0
 public bool Overlaps(PortalModel portal)
 {
     return
         (IsSameSide(Portals[0].Position, Portals[1].Position, Portals[2].Position, portal.Position) &&
          IsSameSide(Portals[1].Position, Portals[2].Position, Portals[0].Position, portal.Position) &&
          IsSameSide(Portals[2].Position, Portals[0].Position, Portals[1].Position, portal.Position));
 }
Пример #3
0
 public PortalModel OtherEnd(PortalModel portal)
 {
     if (!IsConnecting(portal))
     {
         throw new ArgumentException(string.Format("Portal {0} is not a part of link {1}", portal, this));
     }
     return(Source == portal ? Target : Target == portal ? Source : null);
 }
Пример #4
0
 private void VisitPortal(PortalModel portal)
 {
     if (!visitedPortals.Contains(portal))
     {
         Explorer++;
         visitedPortals.Add(portal);
     }
 }
Пример #5
0
        public void Hack(PortalModel portal, Faction faction = Faction.Player)
        {
            Hacker++;

            AP += (portal.Faction == Faction.None || portal.Faction == faction) ? 0 : 100;

            VisitPortal(portal);

            APChanged();
        }
Пример #6
0
        public bool Overlaps(PortalModel portal)
        {
            if (IsConnecting(portal))
            {
                return(false); // connecting is OK
            }

            var p = portal.Position - Source.Position;

            return(Vector3.Cross(Vector, p).z == 0 && Util.InRange(Vector2.Dot(Vector, p) / Vector.sqrMagnitude, 0, 1));
        }
Пример #7
0
        public void Capture(PortalModel portal)
        {
            VisitPortal(portal);

            Liberator++;

            if (!capturedPortals.Contains(portal))
            {
                Pioneer++;
                capturedPortals.Add(portal);
            }

            AP += 125 * 8 + 500 + 250;

            APChanged();
        }
Пример #8
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);
            }
        }
Пример #9
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);
        }
Пример #10
0
        public void DestroyPortal(PortalModel portal, out IList <LinkModel> destroyedLinksResult, out IList <CFModel> destroyedCFsResult)
        {
            var destroyedLinks = links.Where(link => link.IsConnecting(portal)).ToList();
            var destroyedCFs   = cfs.Where(cf => destroyedLinks.Any(cf.Contains)).ToList();

            foreach (var link in destroyedLinks)
            {
                link.Source.NumberOfLinks--;
                link.Target.NumberOfLinks--;
                links.Remove(link);
            }

            foreach (var cf in destroyedCFs)
            {
                cfs.Remove(cf);
            }

            destroyedLinksResult = destroyedLinks;
            destroyedCFsResult   = destroyedCFs;
        }
Пример #11
0
        public bool IsLinkableSource(Faction faction, PortalModel source, out string message)
        {
            if (source.Faction != faction)
            {
                message = string.Format("Source portal {0} is an enemy portal.", source);
                return(false);
            }

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

            if (cfs.Any(cf => cf.Overlaps(source)))
            {
                message = string.Format("Source portal {0} is overlapped by a CF.", source);
                return(false);
            }

            message = null;
            return(true);
        }
Пример #12
0
 public bool HasKey(PortalModel portal)
 {
     return(portals.Contains(portal));
 }
Пример #13
0
 public void RemoveKey(PortalModel portal)
 {
     portals.Remove(portal);
 }
Пример #14
0
 public void AddKey(PortalModel portal)
 {
     portals.Add(portal);
 }
Пример #15
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);
        }
Пример #16
0
 public LinkModel(PortalModel source, PortalModel target)
 {
     Source = source;
     Target = target;
 }
Пример #17
0
 public bool IsConnecting(PortalModel portal)
 {
     return(Source == portal || Target == portal);
 }