public static int HitPower(StarObject starObject, SRSController srs, double power) { double distance = getDistance(starObject.Row, starObject.Col, srs.GetMyRow(), srs.GetMyCol()); distance = power / Math.Pow(distance, 0.4); return((int)(power < 5 ? 5 : distance)); }
private void GenerateHypercorridors() { var hypercorridorsToIgnore = new HashSet <KeyValuePair <string, string> >(); foreach (StarObject star in starByName.Values) { foreach (MapGenerator.CellStar adjacentCell in star.cell.adjacentStars) { var pairToCheck = new KeyValuePair <string, string>(adjacentCell.name, star.cell.name); if (hypercorridorsToIgnore.Contains(pairToCheck)) { continue; } hypercorridorsToIgnore.Add(new KeyValuePair <string, string>(star.cell.name, adjacentCell.name)); GameObject hypercorridor = Instantiate(HypercorridorPrefab); _hypercorridors.Add(hypercorridor); hypercorridor.transform.parent = StarsContainer.transform; StarObject adjacentStar = starByName[adjacentCell.name]; if (star.cell.path.Count > adjacentCell.path.Count) { star.HypercorridorToSun = hypercorridor; } else { adjacentStar.HypercorridorToSun = hypercorridor; } Vector3 from = adjacentStar.transform.localPosition; Vector3 to = star.transform.localPosition; hypercorridor.transform.localPosition = (to + from) / 2f; hypercorridor.transform.localRotation = Quaternion.LookRotation(from - to, Vector3.up); hypercorridor.transform.localScale = new Vector3(0.001f, 0.001f, (to - from).magnitude); } } }
public void Init() { //init starinfo for (int ct = 0; ct < Random.Range(6 - difficult, 8 - difficult); ct++) { starInfos.Add(new StarInfo(StarType.Check, ct < 3)); } starInfos.Add(new StarInfo(StarType.End)); //init log if (SYS_Logger.Direct.logging) { foreach (StarInfo starInfo in starInfos) { Debug.LogWarning("[Gen]BayerID : " + starInfo.sID + " , BayerName : " + starInfo.sName + " , Type : " + starInfo.sType.ToString() + " , Location : " + starInfo.sPos); } } //gen star foreach (StarInfo starInfo in starInfos) { StarObject objGen = Instantiate(starPfb).GetComponent <StarObject>(); RectTransform objRect = objGen.GetComponent <RectTransform>(); objGen.transform.SetParent(transform); objGen.Regist(starInfo); objRect.anchoredPosition3D = starInfo.sPos; if (starInfo.sType == StarType.End) { objGen.sRawImage.GetComponent <RectTransform>().sizeDelta = new Vector2(80, 80); } objGen.sRawImage.color = starInfo.sColor; objRect.localScale = Vector3.one; } }
private bool OnStarPressed(StarObject star) { if ( star.cell.adjacentStars.Count() != 1 || star.cell.name == MapGenerator.SUN_NAME || _submittedStars.Contains(star.cell.name) || solved ) { Audio.PlaySoundAtTransform("NotOutskirts", star.transform); return(true); } Debug.LogFormat("[Space Traders #{0}] Pressed star: {1}", _moduleId, star.cell.name); Debug.LogFormat("[Space Traders #{0}] Current time: {1}", _moduleId, BombInfo.GetFormattedTime()); Debug.LogFormat("[Space Traders #{0}] Path: {1}", _moduleId, star.cell.path.Select((c) => c.name).Join(",")); IEnumerable <MapGenerator.CellStar> starsWithTax = star.cell.path.Where((s) => StarData.HasTaxAt(s, this)); Debug.LogFormat("[Space Traders #{0}] Stars with tax: {1}", _moduleId, starsWithTax.Select((c) => c.name).Join(",")); int tax = starsWithTax.Select((s) => s.tax).Sum(); Debug.LogFormat("[Space Traders #{0}] Required tax: {1}", _moduleId, tax); if (tax > maxTax) { Debug.LogFormat("[Space Traders #{0}] Required tax greater than maximum allowed", _moduleId); BombModule.HandleStrike(); Debug.LogFormat("[Space Traders #{0}] Reseting module", _moduleId); ResetModule(true); return(false); } Audio.PlaySoundAtTransform("StarSubmitted", star.transform); if (soldProductsCount + 1 == productsCountToBeSold) { _forceSolved = false; } soldProductsCount += 1; Debug.LogFormat("[Space Traders #{0}] Sold products count: {1}/{2}", _moduleId, soldProductsCount, productsCountToBeSold); _submittedStars.Add(star.cell.name); foreach (StarObject pathStar in star.cell.path.Select((pathCell) => starByName[pathCell.name])) { pathStar.HypercorridorToSun.GetComponent <Renderer>().material = UsedHypercorridorMaterial; } return(true); }
// This method is called at the beginning of the program void start() { // creates stars as well as gameobjects corresponding to those stars getStars(); for (int i = 0; i < n; i++) { starObjects[i] = new StarObject(stars[i], RAs[i], decs[i], mags[i], spectralType[i]); GameObject s = GameObject.CreatePrimitive(PrimitiveType.Sphere); s.transform.localScale = new Vector3((float)starObjects[i].starRad(), (float)starObjects[i].starRad(), (float)starObjects[i].starRad()); s.transform.position = starObjects[i].cart(sidCalc(), latitude); var meshFilter = s.AddComponent <MeshFilter>(); s.AddComponent <MeshRenderer>(); meshFilter.sharedMesh = Sphere; starsShown[i] = s; } }
private void GenerateStars() { HashSet <MapGenerator.CellStar> cells = MapGenerator.Generate(this); foreach (MapGenerator.CellStar cell in cells) { Debug.LogFormat("[Space Traders #{0}] Star generated: {1}-{2}-{3}-{4}:{5} -> {6}", _moduleId, cell.name, cell.race, cell.regime, cell.position.x, cell.position.y, cell.adjacentStars.Select((c) => c.name).Join(",")); StarObject star = Instantiate(StarPrefab); star.cell = cell; star.transform.parent = StarsContainer.transform; float x = CELL_SIZE * (cell.position.x - (GRID_WIDHT - 1) / 2f); x += Random.Range(-CELL_SIZE / 2f, CELL_SIZE / 2f); float y = Random.Range(STAR_MIN_HEIGHT, STAR_MAX_HEIGHT); float z = CELL_SIZE * (cell.position.y - (GRID_HEIGHT - 1) / 2f); z += Random.Range(-CELL_SIZE / 2f, CELL_SIZE / 2f); star.transform.localPosition = new Vector3(x, y, z); star.transform.localScale = new Vector3(0.005f, 0.005f, 0.005f); star.transform.localRotation = Quaternion.Euler(0f, 0f, 0f); starByName[cell.name] = star; } GenerateHypercorridors(); }
//Method used to read in all the trials of the game private List<EventStats> ReadStarEvents(XmlNode eventsNode) { List<EventStats> starEvents = new List<EventStats>(); //For all the trials foreach(XmlNode trial in eventsNode.ChildNodes){ StarEvent sE = new StarEvent(); int lS=0; int bS=0; int d=0; int t=0; List<StarObject> objs = new List<StarObject>(); for (int i=0; i<trial.ChildNodes.Count; i++){ //Make sure were trying to deal with event if(trial.ChildNodes[i].Name =="event"){ int type = -1; Vector2 pos = new Vector2(Mathf.Infinity,Mathf.Infinity); float rotation = 0; foreach(XmlAttribute attri in trial.ChildNodes[i].Attributes){ //Type if(attri.Name.ToLower() == "type"){ if(int.TryParse(attri.Value.ToLower(),out type)){ if(type <0 && type>3){ NeuroLog.Error("Invalid value for 'type' at event #" + (i+1).ToString() + ". Needs to be between 0 and 4."); type = -1; } else{ if(type == 0) lS++; else if(type ==1) bS++; else if(type ==2) d++; else if(type ==3) t++; } } else NeuroLog.Error("Invalid value for 'type' at event #" + (i+1).ToString() + ". Needs to be a int."); } //Position else if(attri.Name.ToLower() =="position"){ string[] input = attri.Value.Split(','); float x = Mathf.Infinity; float y = Mathf.Infinity; if(float.TryParse(input[0],out x)){ if(x!=Mathf.Infinity){ if(x>170 || x<-170){ x = Mathf.Infinity; NeuroLog.Error("Invalid value for 'position.x' at event #" + (i+1).ToString() + ". Needs to be between -170 and 170."); } } } else NeuroLog.Error("Invalid value for 'position.x' at event #" + (i+1).ToString() + ". Needs to be a float."); if(float.TryParse(input[1],out y)){ if(y!=Mathf.Infinity){ if(y>90 || y<-75){ y = Mathf.Infinity; NeuroLog.Error("Invalid value for 'position.y' at event #" + (i+1).ToString() + ". Needs to be between -75 and 90."); } } } else NeuroLog.Error("Invalid value for 'position.y' at event #" + (i+1).ToString() + ". Needs to be a float."); pos = new Vector2(x,y); } //Rotation else if(attri.Name.ToLower() == "rotation"){ if(!float.TryParse(attri.Value.ToLower(),out rotation)) NeuroLog.Error("Invalid value for 'rotation' at event #" + (i+1).ToString() + ". Needs to be a float."); } //Other attributes that don't have cases else NeuroLog.Error("Unknown attribute '" + attri.Name + "' at event #" + (i+1).ToString() + "."); } if(type!=-1 && pos.x != Mathf.Infinity && pos.y != Mathf.Infinity){ StarObject sO = new StarObject(type,pos,rotation); objs.Add(sO); } } } sE.Objects = objs; sE.NumBigStars = bS; sE.NumLittleStars=lS; sE.NumTriangles = t; sE.NumDots = d; starEvents.Add(sE); } return starEvents; }
private void HandleStarObject(StarObject obj) { CheckDiscovere(obj); CheckNodeObjects(obj); }
//Method used to read in all the trials of the game private List<EventStats> ReadStarEvents(CsvReader csv) { List<EventStats> starEvents = new List<EventStats>(); int fieldCount = csv.FieldCount; string[] headers = csv.GetFieldHeaders(); int i =2; StarEvent sE = new StarEvent(); int lS=0; int bS=0; int d=0; int t=0; int block =0; List<StarObject> objs = new List<StarObject>(); while (csv.ReadNextRecord()){ int type = -1; int b=-1; Vector2 pos = new Vector2(Mathf.Infinity,Mathf.Infinity); float rotation = 0; for(int j = 0;j<fieldCount;j++){ //Type if(headers[j].ToLower() == "type"){ if(int.TryParse(csv[j].ToLower(),out type)){ if(type <0 && type>3){ NeuroLog.Log("Invalid value for 'type' at line #" + i.ToString() + ". Needs to be between 0 and 4."); type = -1; } else{ if(type == 0) lS++; else if(type ==1) bS++; else if(type ==2) d++; else if(type ==3) t++; } } else NeuroLog.Log("Invalid value for 'type' at line #" + i.ToString() + ". Needs to be a int."); } //Position else if(headers[j].ToLower() =="position"){ string[] input = csv[j].Split(';'); float x = Mathf.Infinity; float y = Mathf.Infinity; if(float.TryParse(input[0],out x)){ if(x!=Mathf.Infinity){ if(x>170 || x<-170){ x = Mathf.Infinity; NeuroLog.Log("Invalid value for 'position.x' at line #" + i.ToString() + ". Needs to be between -170 and 170."); } } } else NeuroLog.Log("Invalid value for 'position.x' at line #" + i.ToString() + ". Needs to be a float."); if(float.TryParse(input[1],out y)){ if(y!=Mathf.Infinity){ if(y>90 || y<-75){ y = Mathf.Infinity; NeuroLog.Log("Invalid value for 'position.y' at line #" + i.ToString() + ". Needs to be between -75 and 90."); } } } else NeuroLog.Log("Invalid value for 'position.y' at line #" + i.ToString() + ". Needs to be a float."); pos = new Vector2(x,y); } //Rotation else if(headers[j].ToLower() == "rotation"){ if(!float.TryParse(csv[j].ToLower(),out rotation)) NeuroLog.Log("Invalid value for 'rotation' at line #" + i.ToString() + ". Needs to be a float."); } //Block Num else if (headers[j].ToLower() =="blocknum"){ if(int.TryParse(csv[j],out b)){ if(block ==0){ block = b; } else if(b <block){ NeuroLog.Log("Invalid value for 'dot' at line #" + i.ToString() + ". Needs to be greater than "+block +" at this point. Please keep block num's together"); b = -1; } else if(b> block+1){ NeuroLog.Log("Invalid value for 'dot' at line #" + i.ToString() + ". Needs to be less than "+(block+1).ToString() +" at this point. Do not jump ahead."); b = -1; } } else NeuroLog.Log("Invalid value for 'BlockNum' at line #" + i.ToString() + ". Needs to be a int."); } } if(b != -1){ if(b != block){ block = b; sE.Objects = objs; if(type == 0) lS--; else if(type ==1) bS--; else if(type ==2) d--; else if(type ==3) t--; sE.NumBigStars = bS; sE.NumLittleStars=lS; sE.NumTriangles = t; sE.NumDots = d; starEvents.Add(sE); lS=0; bS=0; d=0; t=0; if(type == 0) lS++; else if(type ==1) bS++; else if(type ==2) d++; else if(type ==3) t++; objs = new List<StarObject>(); sE = new StarEvent(); } if(type!=-1 && pos.x != Mathf.Infinity && pos.y != Mathf.Infinity){ StarObject sO = new StarObject(type,pos,rotation); objs.Add(sO); } } i++; } if(objs.Count>0){ sE.Objects = objs; sE.NumBigStars = bS; sE.NumLittleStars=lS; sE.NumTriangles = t; sE.NumDots = d; starEvents.Add(sE); } return starEvents; }
public IEnumerator ProcessTwitchCommand(string command) { if (!activated) { yield return("sendtochat {0}, !{1} not activated"); yield break; } command = command.Trim().ToLower(); if (command == "outskirts") { IEnumerable <StarObject> stars = starByName.Values.Where(s => s.cell.adjacentStars.Count == 1 && s.cell.name != MapGenerator.SUN_NAME); yield return(null); if (stars.Count() > 3) { yield return("waiting music"); } foreach (StarObject star in stars) { star.GetComponent <KMSelectable>().Highlight.transform.GetChild(0).gameObject.SetActive(true); star.Highlight(); yield return(new WaitForSeconds(5f)); star.GetComponent <KMSelectable>().Highlight.transform.GetChild(0).gameObject.SetActive(false); star.RemoveHighlight(); yield return(null); if (TwitchShouldCancelCommand) { yield return("cancelled"); yield break; } } yield break; } if (command.StartsWith("trace ")) { string starName = command.Skip(6).Join("").Trim(); if (starName == MapGenerator.SUN_NAME) { yield break; } if ( !StarData.HasLowerCasedStarName(starName) || !starByName.ContainsKey(StarData.LowerCasedStarNameToActual(starName)) ) { yield return("sendtochat {0}, !{1} " + string.Format("Star \"{0}\" not found", starName)); yield break; } StarObject target = starByName[StarData.LowerCasedStarNameToActual(starName)]; yield return(null); if (target.cell.path.Count > 3) { yield return("waiting music"); } foreach (MapGenerator.CellStar cell in target.cell.path) { StarObject star = starByName[cell.name]; star.GetComponent <KMSelectable>().Highlight.transform.GetChild(0).gameObject.SetActive(true); star.Highlight(); yield return(new WaitForSeconds(5f)); star.GetComponent <KMSelectable>().Highlight.transform.GetChild(0).gameObject.SetActive(false); star.RemoveHighlight(); yield return(null); if (TwitchShouldCancelCommand) { yield return("cancelled"); yield break; } } yield break; } if (command.StartsWith("send ")) { string[] starsName = command.Split(' ').Skip(1).Where((n) => n.Length > 0).ToArray(); string[] unknownStars = starsName.Where((s) => ( !StarData.HasLowerCasedStarName(s) || !starByName.ContainsKey(StarData.LowerCasedStarNameToActual(s)) )).ToArray(); if (unknownStars.Length > 0) { yield return("sendtochat {0}, !{1} " + string.Format( "Stars {0} not found", unknownStars.Select((s) => string.Format("\"{0}\"", s)).Join(", ") )); yield break; } foreach (StarObject star in starsName.Select((s) => starByName[StarData.LowerCasedStarNameToActual(s)])) { bool success = OnStarPressed(star); if (!success) { break; } } yield return(new KMSelectable[] { }); yield break; } if (command.StartsWith("look ")) { string[] starsName = command.Split(' ').Skip(1).Where((n) => n.Length > 0).ToArray(); string[] unknownStars = starsName.Where((s) => ( !StarData.HasLowerCasedStarName(s) || !starByName.ContainsKey(StarData.LowerCasedStarNameToActual(s)) )).ToArray(); if (unknownStars.Length > 0) { yield return("sendtochat {0}, !{1} " + string.Format( "Stars {0} not found", unknownStars.Select((s) => string.Format("\"{0}\"", s)).Join(", ") )); yield break; } yield return(null); if (starsName.Count() > 3) { yield return("waiting music"); } foreach (string starName in starsName) { StarObject star = starByName[StarData.LowerCasedStarNameToActual(starName)]; star.GetComponent <KMSelectable>().Highlight.transform.GetChild(0).gameObject.SetActive(true); star.Highlight(); yield return(new WaitForSeconds(5f)); star.GetComponent <KMSelectable>().Highlight.transform.GetChild(0).gameObject.SetActive(false); star.RemoveHighlight(); yield return(null); if (TwitchShouldCancelCommand) { yield return("cancelled"); yield break; } } yield break; } yield return(null); }