public static FuzzyInstrument GetFuzzyInstrument(this Indicator indicator, BarsPeriodType periodType, int value, string tradingHours) { if (indicator == null) { throw new ArgumentNullException("no indicator for fuzzy insturment (?)"); } FuzzyInstrument myFuzzyInstrument = new FuzzyInstrument { Period = new BarsPeriod { BarsPeriodType = periodType, Value = value }, TradingHours = tradingHours }; try { myFuzzyInstrument.InstrumentName = indicator.Instrument.FullName; } catch { myFuzzyInstrument.InstrumentName = DefaultInstrumentName; #if DEBUG NinjaScript.Log(string.Format("{0} Had to use default data series when adding {1} ({2})", indicator.Name, myFuzzyInstrument.InstrumentName, myFuzzyInstrument.Period), LogLevel.Error); #endif } return(myFuzzyInstrument); }
/// <summary> /// This MUST be overridden for any custom service properties to be copied over when instances of the service are created /// </summary> /// <param name="ninjaScript"></param> public override void CopyTo(NinjaScript ninjaScript) { base.CopyTo(ninjaScript); // Recompiling NinjaTrader.Custom after a Share service has been added will cause the Type to change. // Use reflection to set the appropriate properties, rather than casting ninjaScript to Mail. PropertyInfo[] props = ninjaScript.GetType().GetProperties(); foreach (PropertyInfo pi in props) { if (pi.Name == "Email") { pi.SetValue(ninjaScript, Email); } else if (pi.Name == "MmsAddress") { pi.SetValue(ninjaScript, MmsAddress); } else if (pi.Name == "PhoneNumber") { pi.SetValue(ninjaScript, PhoneNumber); } else if (pi.Name == "SmsAddress") { pi.SetValue(ninjaScript, SmsAddress); } } }
/// <summary> /// This MUST be overridden for any custom service properties to be copied over when instances of the service are created /// </summary> /// <param name="ninjaScript"></param> public override void CopyTo(NinjaScript ninjaScript) { base.CopyTo(ninjaScript); // Recompiling NinjaTrader.Custom after a Share service has been added will cause the Type to change. // Use reflection to set the appropriate properties, rather than casting ninjaScript to Twitter. PropertyInfo[] props = ninjaScript.GetType().GetProperties(); foreach (PropertyInfo pi in props) { if (pi.Name == "LastTimeConfigured") { pi.SetValue(ninjaScript, LastTimeConfigured); } else if (pi.Name == "OAuth_Token") { pi.SetValue(ninjaScript, OAuth_Token); } else if (pi.Name == "OAuth_Token_Secret") { pi.SetValue(ninjaScript, OAuth_Token_Secret); } else if (pi.Name == "UserName") { pi.SetValue(ninjaScript, UserName); } } }
// Use this for initialization void Start() { NinjaScript.minDistance = minDistanceBetweenNinjas; NinjaScript.attackDistance = ninjaAttackDistance; NinjaScript.updateNinjasOnScreen(); NinjaScript.initSpawns(); DroneScript.initSpawns(); DroneCannonScript.initRockets(); DroneCannonScript.timeBetweenRockets = 5.0f; RocketScript.rocketSpeed = 2.5f; RocketScript.hiddenLocation = new Vector3(100, 100, 100); RocketScript.explosionForce = 500.0f; RocketScript.explosionRadius = 1.0f; RocketScript.initRbs(); RocketScript.initExplosions(explosion); compilators = GameObject.FindObjectsOfType <CompilatorScript>(); lastCompilatorActive = Random.Range(0, compilators.Length); compilators[lastCompilatorActive].Init(); compilators[lastCompilatorActive].active = true; compilatorsUsed = new HashSet <int>(); compilatorsUsed.Add(lastCompilatorActive); maxFillComp = compilationBar.sizeDelta.x; minFillComp = 0; maxFillDamage = damageBar.sizeDelta.x; minFillDamage = 0; compilatorsLife = compilationTotalDamage; }
public override void CopyTo(NinjaScript ninjaScript) { base.CopyTo(ninjaScript); Type newInstType = ninjaScript.GetType(); System.Reflection.PropertyInfo gannAnglePropertyInfo = newInstType.GetProperty("GannAngles"); if (gannAnglePropertyInfo == null) { return; } IList newInstGannAngles = gannAnglePropertyInfo.GetValue(ninjaScript) as IList; if (newInstGannAngles == null) { return; } // Since new instance could be past set defaults, clear any existing newInstGannAngles.Clear(); foreach (GannAngle oldGannAngle in GannAngles) { try { // Clone from the new assembly here to prevent losing existing GannAngles on compile object newInstance = oldGannAngle.AssemblyClone(Core.Globals.AssemblyRegistry.GetType(typeof(GannAngle).FullName)); if (newInstance == null) { continue; } newInstGannAngles.Add(newInstance); } catch (ArgumentException) { // In compiled assembly case, Add call will fail for different assemblies so do normal clone instead object newInstance = oldGannAngle.Clone(); if (newInstance == null) { continue; } // Make sure to update our stroke to a new instance so we dont try to use the old one IStrokeProvider strokeProvider = newInstance as IStrokeProvider; if (strokeProvider != null) { Stroke oldStroke = strokeProvider.Stroke; strokeProvider.Stroke = new Stroke(); oldStroke.CopyTo(strokeProvider.Stroke); } newInstGannAngles.Add(newInstance); } catch { } } }
public static void instantiateNinja() { GameObject ninja = (GameObject.FindObjectOfType <NinjaScript>()).gameObject; GameObject newNinja = Instantiate(ninja, new Vector3(100, 100, 100), Quaternion.identity); newNinja.GetComponent <NinjaScript>().dead = true; NinjaScript.updateNinjasOnScreen(); }
public override void CopyTo(NinjaScript ninjaScript) { DrawingToolTile dti = ninjaScript as DrawingToolTile; if (dti != null) { dti.Left = Left; dti.Top = Top; } base.CopyTo(ninjaScript); }
public void TestSetValueWithIndex() { NinjaScript ns1 = new NinjaScript { Name = "Test" }; var pi = ns1.GetType().GetProperty("Name"); string val = (string)pi.GetValue(ns1, null); pi.SetValue(ns1, val + "1", null); Assert.AreEqual("Test1", ns1.Name); }
/// <summary> /// This MUST be overridden for any custom service properties to be copied over when instances of the service are created /// </summary> /// <param name="ninjaScript"></param> public override void CopyTo(NinjaScript ninjaScript) { base.CopyTo(ninjaScript); // Recompiling NinjaTrader.Custom after a Share service has been added will cause the Type to change. // Use reflection to set the appropriate properties, rather than casting ninjaScript to Mail. PropertyInfo[] props = ninjaScript.GetType().GetProperties(); foreach (PropertyInfo pi in props) { if (pi.Name == "FromMailAddress") { pi.SetValue(ninjaScript, FromMailAddress); } if (pi.Name == "SenderDisplayName") { pi.SetValue(ninjaScript, SenderDisplayName); } else if (pi.Name == "IsBodyHtml") { pi.SetValue(ninjaScript, IsBodyHtml); } else if (pi.Name == "Password") { pi.SetValue(ninjaScript, Password); } else if (pi.Name == "Port") { pi.SetValue(ninjaScript, Port); } else if (pi.Name == "Server") { pi.SetValue(ninjaScript, Server); } else if (pi.Name == "Subject") { pi.SetValue(ninjaScript, Subject); } else if (pi.Name == "ToMailAddress") { pi.SetValue(ninjaScript, ToMailAddress); } else if (pi.Name == "UserName") { pi.SetValue(ninjaScript, UserName); } else if (pi.Name == "UseSSL") { pi.SetValue(ninjaScript, UseSSL); } } }
public override void CopyTo(NinjaScript ninjaScript) { base.CopyTo(ninjaScript); Type newInstType = ninjaScript.GetType(); PropertyInfo segmentPropertyInfo = newInstType.GetProperty("PathToolSegments"); if (segmentPropertyInfo == null) { return; } IList newInstPathToolSegments = segmentPropertyInfo.GetValue(ninjaScript) as IList; if (newInstPathToolSegments == null) { return; } // Since new instance could be past set defaults, clear any existing newInstPathToolSegments.Clear(); foreach (PathToolSegment oldPathToolSegment in PathToolSegments) { try { object newInstance = oldPathToolSegment.AssemblyClone(Core.Globals.AssemblyRegistry.GetType(typeof(PathToolSegment).FullName)); if (newInstance == null) { continue; } newInstPathToolSegments.Add(newInstance); } catch (ArgumentException) { // In compiled assembly case, Add call will fail for different assemblies so do normal clone instead object newInstance = oldPathToolSegment.Clone(); if (newInstance == null) { continue; } newInstPathToolSegments.Add(newInstance); } catch { } } }
public override void CopyTo(NinjaScript ninjaScript) { base.CopyTo(ninjaScript); /* Handle price levels updating. * We can't use a cast here, because the incoming NS could be from a newer assembly, * so the cast would always fail. Dig it up using reflection. For the same reason, * we need to cast as something without specific type, List<PriceLevel> could fail, because * it could try to resovle PriceLevel to current assembly, when its holding a list of PriceLevels * from newer assembly as well. For this reason we cast to IList */ Type newInstType = ninjaScript.GetType(); PropertyInfo priceLevelPropertyInfo = newInstType.GetProperty("PriceLevels"); if (priceLevelPropertyInfo == null) { return; } IList newInstPriceLevels = priceLevelPropertyInfo.GetValue(ninjaScript) as IList; if (newInstPriceLevels == null) { return; } // Since new instance could be past set defaults, clear any existing newInstPriceLevels.Clear(); foreach (PriceLevel oldPriceLevel in PriceLevels) { try { object newInstance = oldPriceLevel.AssemblyClone(Core.Globals.AssemblyRegistry.GetType(typeof(PriceLevel).FullName)); if (newInstance == null) { continue; } // Make sure to update our stroke to a new instance so we dont try to use the old one IStrokeProvider strokeProvider = newInstance as IStrokeProvider; if (strokeProvider != null) { Stroke oldStroke = strokeProvider.Stroke; strokeProvider.Stroke = new Stroke(); oldStroke.CopyTo(strokeProvider.Stroke); } newInstPriceLevels.Add(newInstance); } catch { } } }
public override void CopyTo(NinjaScript ninjascript) { base.CopyTo(ninjascript); PathTool p = ninjascript as PathTool; if (p != null && ChartAnchors != null) { p.ChartAnchors.Clear(); // We have to deep copy our List of Chart Anchors foreach (ChartAnchor ca in ChartAnchors) { p.ChartAnchors.Add(ca.Clone() as ChartAnchor); } } }
public override void CopyTo(NinjaScript ninjaScript) { base.CopyTo(ninjaScript); Type newInstType = ninjaScript.GetType(); System.Reflection.PropertyInfo gannAnglePropertyInfo = newInstType.GetProperty("GannAngles"); if (gannAnglePropertyInfo == null) { return; } IList newInstGannAngles = gannAnglePropertyInfo.GetValue(ninjaScript) as IList; if (newInstGannAngles == null) { return; } // Since new instance could be past set defaults, clear any existing newInstGannAngles.Clear(); foreach (GannAngle oldGannAngle in GannAngles) { try { object newInstance = oldGannAngle.AssemblyClone(Core.Globals.AssemblyRegistry.GetType(typeof(GannAngle).FullName)); if (newInstance == null) { continue; } // Make sure to update our stroke to a new instance so we dont try to use the old one IStrokeProvider strokeProvider = newInstance as IStrokeProvider; if (strokeProvider != null) { Stroke oldStroke = strokeProvider.Stroke; strokeProvider.Stroke = new Stroke(); oldStroke.CopyTo(strokeProvider.Stroke); } newInstGannAngles.Add(newInstance); } catch (Exception e) { NinjaTrader.Code.Output.Process(e.ToString(), PrintTo.OutputTab1); } } }
// Update is called once per frame void Update() { if (!IntroScript.introFinished) { return; } if (compilatorsLife <= 0) { SceneManager.LoadScene("Win", LoadSceneMode.Single); } if (timer >= compilationTime) { SceneManager.LoadScene("Lose", LoadSceneMode.Single); } timer += Time.deltaTime; float fill = timer / compilationTime; float width = fill * (maxFillComp - minFillComp); compilationBar.sizeDelta = new Vector2(width, compilationBar.sizeDelta.y); fill = compilatorsLife / compilationTotalDamage; width = fill * (maxFillDamage - minFillDamage); damageBar.sizeDelta = new Vector2(width, damageBar.sizeDelta.y); NinjaScript.checkDistances(); if (!compilators[lastCompilatorActive].active) { int newCompilator = lastCompilatorActive; while (compilatorsUsed.Contains(newCompilator)) { newCompilator = Random.Range(0, compilators.Length); } compilators[newCompilator].Init(); compilators[newCompilator].active = true; compilatorsUsed.Add(newCompilator); lastCompilatorActive = newCompilator; } }
// This function is executed at each of our game frame void Update() { //if(Cursor.lockState != CursorLockMode.Confined) //Cursor.lockState = CursorLockMode.Confined; // keep confined in the game window //// Depreciated for UNITY 5_3 // Check the Day/Night Settings GameObject SunLight = GameObject.Find("Sun"); SunLight.GetComponent <Light>().intensity = currentLightSettings; // Turning on the moon when the light intensity goes down GameObject Moon = GameObject.Find("MoonCrescent"); GameObject SunHalo = GameObject.Find("SunHalo"); GameObject Pl1 = GameObject.Find("Point light_1"); GameObject Pl2 = GameObject.Find("Point light_2"); GameObject Pl3 = GameObject.Find("Point light_3"); if (currentLightSettings < 0.25) { SunHalo.GetComponent <SpriteRenderer>().enabled = false; // Turn off Sun SunHalo.GetComponent <SpriteRenderer>().enabled = false; Moon.GetComponent <SpriteRenderer>().enabled = true; // Turn on Moon Pl1.GetComponent <Light>().enabled = true; Pl2.GetComponent <Light>().enabled = true; Pl3.GetComponent <Light>().enabled = true; } else { SunHalo.GetComponent <SpriteRenderer>().enabled = true; // Turn on Sun Moon.GetComponent <SpriteRenderer>().enabled = false; // Turn off Moon Pl1.GetComponent <Light>().enabled = false; Pl2.GetComponent <Light>().enabled = false; Pl3.GetComponent <Light>().enabled = false; } // Find the player object playerObject = GameObject.FindGameObjectWithTag("Player"); realTrailObject = GameObject.FindGameObjectWithTag("RealTrail"); //Add a shortcut button for turning on the trajectory TrajectoryPredictor trajectoryScript01 = playerObject.GetComponent("TrajectoryPredictor") as TrajectoryPredictor; TrajectoryPredictor trajectoryScript02 = realTrailObject.GetComponent("TrajectoryPredictor") as TrajectoryPredictor; if (PlayerPrefs.GetString("DebuggerMode").Equals("True")) { //// For Player trajectoryScript01.drawDebugOnUpdate = true; trajectoryScript01.drawDebugOnPrediction = true; //// For Real Trail trajectoryScript02.drawDebugOnUpdate = true; trajectoryScript02.drawDebugOnPrediction = true; } else { bool ctrl = Input.GetKey(KeyCode.RightControl); bool alt = Input.GetKey(KeyCode.RightAlt); bool t = Input.GetKeyDown(KeyCode.T); if ((ctrl && alt && t) || (alt && ctrl && t)) { if (!pressedOnce) { pressedOnce = true; } else { pressedOnce = false; } } if (pressedOnce) { // For Player trajectoryScript01.drawDebugOnUpdate = true; trajectoryScript01.drawDebugOnPrediction = true; // For Real Trail trajectoryScript02.drawDebugOnUpdate = true; trajectoryScript02.drawDebugOnPrediction = true; } else if (!pressedOnce) { // For Player trajectoryScript01.drawDebugOnUpdate = false; trajectoryScript01.drawDebugOnPrediction = false; // For Real Trail trajectoryScript02.drawDebugOnUpdate = false; trajectoryScript02.drawDebugOnPrediction = false; } } // Check the Magnetism Properties and trail renderer properties NinjaScript ninjaScript = playerObject.GetComponent("NinjaScript") as NinjaScript; if (magnetismOn) { ninjaScript.magnetismOn = true; } else { ninjaScript.magnetismOn = false; } // Check the Trajectory Assistance Properties and trail renderer properties if (trajectoryAssistanceOn) { ninjaScript.trajectoryAssistanceOn = true; } else { ninjaScript.trajectoryAssistanceOn = false; } // Timer Game Object GameObject timerObject = GameObject.Find("Timer"); // Timer settings shown on top of the screen if (timeStarted == true && timePaused == false && timer > 1) { timer -= Time.deltaTime; elapsedTime += Time.deltaTime; //elapsedTime = totalGameTime * 60 - timer; int minutes = Mathf.FloorToInt(timer / 60F); int seconds = Mathf.FloorToInt(timer - minutes * 60); string niceTime = string.Format("{0:00}:{1:00}", minutes, seconds); timerObject.GetComponent <Text>().text = niceTime; } else if (timer <= 1 && timeStarted == true && timePaused == false && !calledOnce) { timeStarted = false; timePaused = true; // Show the Game Over Screen again but with Time Out wriiten // Enable Canvas section GameObject canvasObject = GameObject.Find("Canvas"); Instantiate(canvasObject); canvasObject.GetComponent <Canvas>().enabled = true; Image panelImage = canvasObject.GetComponentInChildren <CanvasRenderer>().GetComponent <Image>(); panelImage.color = new Color(0, 0, 0, 1); //newPanelColor; // Disable Game Over Image GameObject gameOverObj = GameObject.Find("GameOverImage"); gameOverObj.GetComponent <Image>().enabled = false; // Enable TimeOut Image Text TimeOutObj = GameObject.Find("TimeOutText").GetComponent <Text>(); TimeOutObj.enabled = true; // Disbale the restart button GameObject buttonRestart = GameObject.Find("ButtonRestart"); buttonRestart.GetComponent <Image>().enabled = false; buttonRestart.GetComponent <Button>().enabled = false; // Destroy the player first to remove any additional log GameObject player = GameObject.FindGameObjectWithTag("Player"); Destroy(player); playerIsAlive = false; // pause for 5 seconds and then destroy everything StartCoroutine(TimeUp(5)); } else if (timePaused) { timerObject.GetComponent <Text>().text = "PAUSED"; RectTransform rt = timerObject.GetComponent <RectTransform>(); rt.localPosition = new Vector2(35, 0); rt.localScale = new Vector2(0.60F, 0.60F); } //float playerYPosition = GameObject.FindWithTag("Player").transform.position.y; float playersXvelocity = GameObject.FindGameObjectWithTag("Player").GetComponent <Rigidbody2D>().velocity.x; float playersYvelocity = GameObject.FindGameObjectWithTag("Player").GetComponent <Rigidbody2D>().velocity.y; // Mouse button is down, but ninja isn't jumping/falling (its y velocity is zero) and the ninja is not charging if (Input.GetButtonDown("Fire1") && playersXvelocity == 0 && playersYvelocity == 0 && !isCharging && playerIsAlive && !timePaused) { // check if the real trail exist or not if (GameObject.FindWithTag("RealTrail") != null) { //Destroy(GameObject.FindWithTag("RealTrail")); GameObject.FindWithTag("RealTrail").transform.position = playerObject.transform.position; GameObject.FindWithTag("RealTrail").transform.rotation = playerObject.transform.rotation; //Debug.Log("realTrailObject.transform.position: " + realTrailObject.transform.position); } isCharging = true; // now the ninja will be charging } // Mouse button released and the ninja is charging but not jumping/falling (its y velocity is zero) if (Input.GetButtonUp("Fire1") && playersXvelocity == 0 && playersYvelocity == 0 && isCharging && playerIsAlive && !timePaused) { isCharging = false; // player is no longer charging so set the isCharging to false GameObject powerObject = GameObject.FindWithTag("Power"); // get the game object tagged as "Power" PowerScript script = powerObject.GetComponent("PowerScript") as PowerScript; // inside the object tagged as "Power", get PowerScript script GameObject player = GameObject.FindGameObjectWithTag("Player"); player.SendMessage("Jump", maxJumpForce * script.chargePowerSender); // find the object tagged as "Player" and send "Jump" message, with the proper force updateScore = true; // Set the updateScore to true because the player just jumped } }
public override void CopyTo(NinjaScript ninjaScript) { base.CopyTo(ninjaScript); Type newInstType = ninjaScript.GetType(); // Loop through each Collection for (int i = 1; i <= 5; i++) { PropertyInfo noteTextPropertyInfo = newInstType.GetProperty("Note" + i + "Text"); Collection <IndiChartNotes.StringWrapper> NoteText; switch (i) { case 1: NoteText = new Collection <IndiChartNotes.StringWrapper>(Note1Text); break; case 2: NoteText = new Collection <IndiChartNotes.StringWrapper>(Note2Text); break; case 3: NoteText = new Collection <IndiChartNotes.StringWrapper>(Note3Text); break; case 4: NoteText = new Collection <IndiChartNotes.StringWrapper>(Note4Text); break; case 5: NoteText = new Collection <IndiChartNotes.StringWrapper>(Note5Text); break; default: NoteText = new Collection <IndiChartNotes.StringWrapper>(Note1Text); break; } // Reflect Note from old assembly if (noteTextPropertyInfo != null) { IList newInstNoteText = noteTextPropertyInfo.GetValue(ninjaScript) as IList; if (newInstNoteText != null) { // Since new instance could be past set defaults, clear any existing newInstNoteText.Clear(); foreach (IndiChartNotes.StringWrapper oldStringWrapper in NoteText) { try { object newInstance = oldStringWrapper.AssemblyClone(Core.Globals.AssemblyRegistry.GetType(typeof(IndiChartNotes.StringWrapper).FullName)); if (newInstance == null) { continue; } newInstNoteText.Add(newInstance); } catch { } } } } } }