예제 #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);
 }