public PortalModel AddPortal(Vector2 position, Faction faction) { var portal = new PortalModel(position, faction); portals.Add(portal); return(portal); }
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)); }
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); }
private void VisitPortal(PortalModel portal) { if (!visitedPortals.Contains(portal)) { Explorer++; visitedPortals.Add(portal); } }
public void Hack(PortalModel portal, Faction faction = Faction.Player) { Hacker++; AP += (portal.Faction == Faction.None || portal.Faction == faction) ? 0 : 100; VisitPortal(portal); APChanged(); }
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)); }
public void Capture(PortalModel portal) { VisitPortal(portal); Liberator++; if (!capturedPortals.Contains(portal)) { Pioneer++; capturedPortals.Add(portal); } AP += 125 * 8 + 500 + 250; APChanged(); }
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); } }
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); }
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; }
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); }
public bool HasKey(PortalModel portal) { return(portals.Contains(portal)); }
public void RemoveKey(PortalModel portal) { portals.Remove(portal); }
public void AddKey(PortalModel portal) { portals.Add(portal); }
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); }
public LinkModel(PortalModel source, PortalModel target) { Source = source; Target = target; }
public bool IsConnecting(PortalModel portal) { return(Source == portal || Target == portal); }