public void TestValueAccessWithOpenContext() { RunTestWithRealm((realmFactory, _) => { ILive <RealmBeatmap>?liveBeatmap = null; Task.Factory.StartNew(() => { using (var threadContext = realmFactory.CreateContext()) { var beatmap = threadContext.Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata()))); liveBeatmap = beatmap.ToLive(); } }, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait(); Debug.Assert(liveBeatmap != null); Task.Factory.StartNew(() => { Assert.DoesNotThrow(() => { using (realmFactory.CreateContext()) { var resolved = liveBeatmap.Value; Assert.IsTrue(resolved.Realm.IsClosed); Assert.IsTrue(resolved.IsValid); // can access properties without a crash. Assert.IsFalse(resolved.Hidden); } }); }, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait(); }); }
public void TestScopedReadWithoutContext() { RunTestWithRealm((realmFactory, _) => { ILive <RealmBeatmap>?liveBeatmap = null; Task.Factory.StartNew(() => { using (var threadContext = realmFactory.CreateContext()) { var beatmap = threadContext.Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata()))); liveBeatmap = beatmap.ToLive(realmFactory); } }, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait(); Debug.Assert(liveBeatmap != null); Task.Factory.StartNew(() => { liveBeatmap.PerformRead(beatmap => { Assert.IsTrue(beatmap.IsValid); Assert.IsFalse(beatmap.Hidden); }); }, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait(); }); }
public void TestScoreImportThenDelete() { ILive <ScoreInfo> imported = null; AddStep("create button without replay", () => { Child = downloadButton = new TestReplayDownloadButton(getScoreInfo(false)) { Anchor = Anchor.Centre, Origin = Anchor.Centre, }; }); AddUntilStep("wait for load", () => downloadButton.IsLoaded); AddUntilStep("state is not downloaded", () => downloadButton.State.Value == DownloadState.NotDownloaded); AddStep("import score", () => imported = scoreManager.Import(getScoreInfo(true)).Result); AddUntilStep("state is available", () => downloadButton.State.Value == DownloadState.LocallyAvailable); AddStep("delete score", () => scoreManager.Delete(imported.Value)); AddUntilStep("state is not downloaded", () => downloadButton.State.Value == DownloadState.NotDownloaded); }
public void TestValueAccessWithoutOpenContextFails() { RunTestWithRealm((realmFactory, _) => { ILive <RealmBeatmap>?liveBeatmap = null; Task.Factory.StartNew(() => { using (var threadContext = realmFactory.CreateContext()) { var beatmap = threadContext.Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata()))); liveBeatmap = beatmap.ToLive(realmFactory); } }, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait(); Debug.Assert(liveBeatmap != null); Task.Factory.StartNew(() => { Assert.Throws <InvalidOperationException>(() => { var unused = liveBeatmap.Value; }); }, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait(); }); }
protected Skin(SkinInfo skin, IStorageResourceProvider resources, [CanBeNull] Stream configurationStream = null) { SkinInfo = skin.ToLive(); this.resources = resources; configurationStream ??= getConfigurationStream(); if (configurationStream != null) { // stream will be closed after use by LineBufferedReader. ParseConfigurationStream(configurationStream); } else { Configuration = new SkinConfiguration(); } // skininfo files may be null for default skin. SkinInfo.PerformRead(s => { // we may want to move this to some kind of async operation in the future. foreach (SkinnableTarget skinnableTarget in Enum.GetValues(typeof(SkinnableTarget))) { string filename = $"{skinnableTarget}.json"; // skininfo files may be null for default skin. var fileInfo = s.Files.FirstOrDefault(f => f.Filename == filename); if (fileInfo == null) { continue; } byte[] bytes = resources?.Files.Get(fileInfo.File.GetStoragePath()); if (bytes == null) { continue; } try { string jsonContent = Encoding.UTF8.GetString(bytes); var deserializedContent = JsonConvert.DeserializeObject <IEnumerable <SkinnableInfo> >(jsonContent); if (deserializedContent == null) { continue; } DrawableComponentInfo[skinnableTarget] = deserializedContent.ToArray(); } catch (Exception ex) { Logger.Error(ex, "Failed to load skin configuration."); } } }); }
public void TestLiveAssumptions() { RunTestWithRealm((realmFactory, _) => { int changesTriggered = 0; using (var updateThreadContext = realmFactory.CreateContext()) { updateThreadContext.All <RealmBeatmap>().SubscribeForNotifications(gotChange); ILive <RealmBeatmap>?liveBeatmap = null; Task.Factory.StartNew(() => { using (var threadContext = realmFactory.CreateContext()) { var ruleset = CreateRuleset(); var beatmap = threadContext.Write(r => r.Add(new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), new RealmBeatmapMetadata()))); // add a second beatmap to ensure that a full refresh occurs below. // not just a refresh from the resolved Live. threadContext.Write(r => r.Add(new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), new RealmBeatmapMetadata()))); liveBeatmap = beatmap.ToLive(); } }, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait(); Debug.Assert(liveBeatmap != null); // not yet seen by main context Assert.AreEqual(0, updateThreadContext.All <RealmBeatmap>().Count()); Assert.AreEqual(0, changesTriggered); var resolved = liveBeatmap.Value; // retrieval causes an implicit refresh. even changes that aren't related to the retrieval are fired at this point. Assert.AreEqual(2, updateThreadContext.All <RealmBeatmap>().Count()); Assert.AreEqual(1, changesTriggered); // even though the realm that this instance was resolved for was closed, it's still valid. Assert.IsTrue(resolved.Realm.IsClosed); Assert.IsTrue(resolved.IsValid); // can access properties without a crash. Assert.IsFalse(resolved.Hidden); updateThreadContext.Write(r => { // can use with the main context. r.Remove(resolved); }); } void gotChange(IRealmCollection <RealmBeatmap> sender, ChangeSet changes, Exception error) { changesTriggered++; } }); }
private void assertImportedOnce(ILive <SkinInfo> import1, ILive <SkinInfo> import2) { import1.PerformRead(i1 => import2.PerformRead(i2 => { Assert.That(i2.ID, Is.EqualTo(i1.ID)); Assert.That(i2.Hash, Is.EqualTo(i1.Hash)); Assert.That(i2.Files.First(), Is.EqualTo(i1.Files.First())); })); }
public void LvlUp(ILive hero) { //var b=new BleedingSting(); // hero.battleSkills.Add(b); foreach (var i in BattleSkillEnum.BattleSkills) { if (i.SkillCondition(hero)) hero.battleSkills.Add(i as IBattleSkill); } }
public void TestLiveEquality() { RunTestWithRealm((realmFactory, _) => { ILive <RealmBeatmap> beatmap = realmFactory.CreateContext().Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata()))).ToLive(realmFactory); ILive <RealmBeatmap> beatmap2 = realmFactory.CreateContext().All <RealmBeatmap>().First().ToLive(realmFactory); Assert.AreEqual(beatmap, beatmap2); }); }
private void updateSelectedSkinFromConfig() { ILive <SkinInfo> skin = null; if (Guid.TryParse(configBindable.Value, out var configId)) { skin = skinDropdown.Items.FirstOrDefault(s => s.ID == configId); } dropdownBindable.Value = skin ?? skinDropdown.Items.First(); }
/// <summary>Creates a new instance of Poloniex API .NET's client service.</summary> /// <param name="publicApiKey">Your public API key.</param> /// <param name="privateApiKey">Your private API key.</param> public PoloniexClient(string publicApiKey, string privateApiKey) { var apiWebClient = new ApiWebClient(Helper.ApiUrlHttpsBase); Authenticator = new Authenticator(apiWebClient, publicApiKey, privateApiKey); Markets = new Markets(apiWebClient); Trading = new Trading(apiWebClient); Wallet = new Wallet(apiWebClient); Live = new Live(); }
public void TestLiveCastability() { RunTestWithRealm((realmFactory, _) => { RealmLive <RealmBeatmap> beatmap = realmFactory.CreateContext().Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata()))).ToLive(); ILive <IBeatmapInfo> iBeatmap = beatmap; Assert.AreEqual(0, iBeatmap.Value.Length); }); }
public void LvlUp(ILive hero) { hero.Lvl++; hero.experienceToLvl += (int)(hero.experienceToLvl*0.5); switch (hero.Type) { case "Warrior": var w=new Warrior(); w.LvlUp(hero); break; } }
public string Kick(ILive first, ILive second, IBattleSkill skill = null) { var batleRandom = new BatleCalculates(); string result = ""; if (first.HPCurent > 0 && second.HPCurent > 0) { bool chance = batleRandom.ChanceToHit(first); if (!chance) { result = "You MISS!"; } else { if (skill == null) second.HPCurent = second.HPCurent - batleRandom.Damage(first) / second.DefCurent; else { first.skillInUse.Add(skill as Skill); second.HPCurent = second.HPCurent - skill.Smash(first, second) / second.DefCurent; } } if (first.HPCurent > 0 && second.HPCurent > 0) { chance = batleRandom.ChanceToHit(second); if (!chance) result += "He MISS!Ha-Ha"; else { first.HPCurent = first.HPCurent - batleRandom.Damage(second) / first.DefCurent; } } GoEffect(first, second); } if (first.HPCurent <= 0) { first.HPCurent = 0; result += "You are dead!:("; batleRandom.Experience(second, first); } if (second.HPCurent <= 0) { second.HPCurent = 0; result += "He is dead!:)"; batleRandom.Experience(first, second); } return result; }
private void assertCorrectMetadata(ILive <SkinInfo> import1, string name, string creator, OsuGameBase osu) { import1.PerformRead(i => { Assert.That(i.Name, Is.EqualTo(name)); Assert.That(i.Creator, Is.EqualTo(creator)); // for extra safety let's reconstruct the skin, reading from the skin.ini. var instance = i.CreateInstance((IStorageResourceProvider)osu.Dependencies.Get(typeof(SkinManager))); Assert.That(instance.Configuration.SkinInfo.Name, Is.EqualTo(name)); Assert.That(instance.Configuration.SkinInfo.Creator, Is.EqualTo(creator)); }); }
public void Go(ILive victim, int i) { if (victim.effects[i].Time > 0) { victim.HPCurent -= (float)0.4; victim.effects[i].Time -= 1; } else { victim.effects.RemoveAt(i); } }
private void button1_Click(object sender, EventArgs e) { Fight f = new Fight(); string result; result = f.Kick(hero1, hero2); richTextBox1.Text = richTextBox1.Text + hero1.Name + " - " + hero1.HPCurent.ToString() + " - " + hero2.Name + " " + hero2.HPCurent.ToString() + "\n" + result + " \n"; if (hero1.HPCurent == 0 ) { hero1 = null; button1.Enabled = false; } if( hero2.HPCurent == 0) { hero2 = null; button1.Enabled = false; } }
public string Kick(ILive first, ILive second) { BatleCalculates batleRandom = new BatleCalculates(); string result = ""; if (first.HPCurent > 0 && second.HPCurent > 0) { bool chance = batleRandom.ChanceToHit(first); if (!chance) { result = "You MISS!"; } else { second.HPCurent = second.HPCurent - batleRandom.Damage(first) / second.DefCurent; } if (first.HPCurent > 0 && second.HPCurent > 0) { chance = batleRandom.ChanceToHit(second); if (!chance) result += "He MISS!Ha-Ha"; else { first.HPCurent = first.HPCurent - batleRandom.Damage(second) / first.DefCurent; } } } if (first.HPCurent <= 0) { first.HPCurent = 0; result += "You are dead!:("; batleRandom.Experience(second, first); } if (second.HPCurent <= 0) { second.HPCurent = 0; result += "He is dead!:)"; batleRandom.Experience( first,second); } return result; }
/// <summary> /// Шанс попадания /// </summary> /// <param name="first"></param> /// <returns></returns> public bool ChanceToHit(ILive first) { var rand = new Random(); double chanceToHit = rand.NextDouble(); switch (first.Type) { case "Defender": if (chanceToHit > 0.8) return false; break; case "Wizard": break; case "DD": if (chanceToHit > 0.9) return false; break; case "Monster1": if (chanceToHit > 0.5) return false; break; case "Monster2": if (chanceToHit > 0.6) return false; break; case "Monster3": if (chanceToHit > 0.7) return false; break; } return true; }
/// <summary> /// Hit chance /// </summary> /// <param name="first"></param> /// <returns>bool.If True - Hit, if False - miss</returns> public bool ChanceToHit(ILive first) { var rand = new Random(); Thread.Sleep(10); // here and in future @Thread.Sleep(10);@ - for good random value. Fix before librerary compilation. double chanceToHit = rand.NextDouble(); switch (first.Type) { case "Warrior": if (chanceToHit > 0.7) return false; break; case "Wizard": break; case "DD": if (chanceToHit > 0.8) return false; break; case "Monster1": if (chanceToHit > 0.5) return false; break; case "Monster2": if (chanceToHit > 0.6) return false; break; case "Monster3": if (chanceToHit > 0.7) return false; break; } return true; }
/// <summary>Creates a new instance of Poloniex API .NET's client service.</summary> /// <param name="publicApiKey">Your public API key.</param> /// <param name="privateApiKey">Your private API key.</param> public PoloniexClient(string publicApiKey, string privateApiKey, bool simulated = false) { var apiWebClient = new ApiWebClient(Helper.ApiUrlHttpsBase); Authenticator = new Authenticator(apiWebClient, publicApiKey, privateApiKey); if (simulated) { Markets = new MarketsCustom(apiWebClient); Trading = new TradingSimulated(apiWebClient); Wallet = new WalletSimulated(apiWebClient); Live = new LiveCustom(); } else { Markets = new MarketsCustom(apiWebClient); Trading = new TradingCustom(apiWebClient); Wallet = new WalletCustom(apiWebClient); Live = new LiveCustom(); } }
public void GoEffect(ILive first, ILive second) { for (int i = 0; i < first.effects.Count; i++) { first.effects[i].Go(first,i); } for (int i = 0; i < second.effects.Count; i++) { second.effects[i].Go(second,i); } for (int i = 0; i < first.skillInUse.Count; i++) { first.skillInUse[i].ToCollDown(first); } for (int i = 0; i < second.skillInUse.Count; i++) { second.skillInUse[i].ToCollDown(second); } }
private void Awake() { _life = GetComponent <ILive>(); _animator = GetComponent <Animator>(); _hit = Animator.StringToHash(triggerName); }
public void Experience(ILive winner, ILive loser) { winner.experience += (int)loser.HP; }
public float Damage(ILive hero) { return RandomFloat(hero.DamageCurent - hero.DamageCurent / 3, hero.DamageCurent + hero.DamageCurent / 3); }
public float Damage(ILive Hero) { return RandomFloat(Hero.DamageCurent - Hero.DamageCurent / 10, Hero.DamageCurent + Hero.DamageCurent / 10); }
private void importBeatmap() => AddStep("import beatmap", () => importedBeatmap = manager.Import(CreateBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo.BeatmapSet).Result);
private void button6_Click(object sender, EventArgs e) { if (hero1 == null || hero1.HPCurent == 0) { richTextBox1.Clear(); hero1 = new Hero().SetWizard(); richTextBox1.Text = "Welcome Wizard!"; } else { hero2 = new Hero().SetWizard(); richTextBox1.Text += "\nWelcome Wizard!\n"; button1.Enabled = true; } }
public bool Equals(ILive <T>?other) => ID == other?.ID;
public void MoveToRight(ILive hero, bool[,] arrea) { if (hero.mapPosition.X < Math.Sqrt(arrea.Length)) hero.mapPosition = new Point(hero.mapPosition.X + 1, hero.mapPosition.Y); }
public void MoveUp(ILive hero, bool[,] arrea) { if (hero.mapPosition.Y < Math.Sqrt(arrea.Length)) hero.mapPosition = new Point(hero.mapPosition.X, hero.mapPosition.Y+1); }
public void NewFight(ILive hero) { if (_hero1 == null || _hero1.HPCurent == 0) { richTextBox1.Clear(); _hero1 = hero; richTextBox1.Text = "Welcome " + _hero1.Name + "!"; button8.Enabled = true; } else { _hero2 = hero; richTextBox1.Text += "\nWelcome " + _hero2.Name + "!\n"; button1.Enabled = true; } }
public float SkillDamage(ILive you) { _skillDamage = you.DamageCurent * _damage; return _skillDamage; }
public override bool SkillCondition(ILive you) { if (you.Lvl>0&&you.Type!="Wizard") {return true;} return false; }
public virtual bool SkillCondition(ILive you) { return true; }
//public Eff SkillEffect //{ // get { return _skillEffect; } // set { _skillEffect = value as Bleeding; } //} public float Smash(ILive you, ILive victim) { SkillDamage(you); victim.effects.Add(new Bleeding()); return _skillDamage; }
public void ToCollDown(ILive you) { if (_cooldown > 0) { CoolDown--; isCooled = false; } else { isCooled = true; you.skillInUse.Remove(this); _cooldown = RollBack; } }
private void Button1Click(object sender, EventArgs e) { var f = new Fight(); string result = f.Kick(_hero1, _hero2); richTextBox1.Text = richTextBox1.Text + _hero1.Name + " - " + _hero1.HPCurent.ToString() + " - " + _hero2.Name + " " + _hero2.HPCurent.ToString() + "\n" + result + " \n"; if (_hero1.HPCurent == 0) { _hero1 = null; button1.Enabled = false; button8.Enabled = false; } if (_hero2.HPCurent == 0) { _hero2 = null; var asd = new BatleCalculates(); asd.LvlUp(_hero1); button1.Enabled = false; } if (_hero1 != null) { if (_hero1.skillInUse.Count == 0) { button9.Enabled = true; } else { foreach (var i in _hero1.skillInUse) { if (i.Name == "BleedingSting") { if (i.IsCooled) button9.Enabled = true; } } } } }
protected override LocalisableString GenerateItemText(ILive <SkinInfo> item) => item.ToString();
private void button9_Click(object sender, EventArgs e) { foreach (Skill i in _hero1.battleSkills) { if (i.Name == "BleedingSting") { var f = new Fight(); string result = f.Kick(_hero1, _hero2, i as IBattleSkill); richTextBox1.Text = richTextBox1.Text + _hero1.Name + " - " + _hero1.HPCurent.ToString() + " - " + _hero2.Name + " " + _hero2.HPCurent.ToString() + "\n" + result + " \n"; if (_hero1.HPCurent == 0) { _hero1 = null; button1.Enabled = false; button8.Enabled = false; } if (_hero2.HPCurent == 0) { _hero2 = null; var asd = new BatleCalculates(); asd.LvlUp(_hero1); button1.Enabled = false; } button9.Enabled = false; } else { MessageBox.Show("You have not this skill!"); } } }
private void load() { dependencies.CacheAs(this); dependencies.Cache(SentryLogger); dependencies.Cache(osuLogo = new OsuLogo { Alpha = 0 }); // bind config int to database RulesetInfo configRuleset = LocalConfig.GetBindable <string>(OsuSetting.Ruleset); uiScale = LocalConfig.GetBindable <float>(OsuSetting.UIScale); var preferredRuleset = int.TryParse(configRuleset.Value, out int rulesetId) // int parsing can be removed 20220522 ? RulesetStore.GetRuleset(rulesetId) : RulesetStore.GetRuleset(configRuleset.Value); try { Ruleset.Value = preferredRuleset ?? RulesetStore.AvailableRulesets.First(); } catch (Exception e) { // on startup, a ruleset may be selected which has compatibility issues. Logger.Error(e, $@"Failed to switch to preferred ruleset {preferredRuleset}."); Ruleset.Value = RulesetStore.AvailableRulesets.First(); } Ruleset.ValueChanged += r => configRuleset.Value = r.NewValue.ShortName; // bind config int to database SkinInfo configSkin = LocalConfig.GetBindable <string>(OsuSetting.Skin); SkinManager.CurrentSkinInfo.ValueChanged += skin => configSkin.Value = skin.NewValue.ID.ToString(); configSkin.ValueChanged += skinId => { ILive <SkinInfo> skinInfo = null; if (Guid.TryParse(skinId.NewValue, out var guid)) { skinInfo = SkinManager.Query(s => s.ID == guid); } if (skinInfo == null) { if (guid == SkinInfo.CLASSIC_SKIN) { skinInfo = DefaultLegacySkin.CreateInfo().ToLive(); } } SkinManager.CurrentSkinInfo.Value = skinInfo ?? DefaultSkin.CreateInfo().ToLive(); }; configSkin.TriggerChange(); IsActive.BindValueChanged(active => updateActiveState(active.NewValue), true); Audio.AddAdjustment(AdjustableProperty.Volume, inactiveVolumeFade); SelectedMods.BindValueChanged(modsChanged); Beatmap.BindValueChanged(beatmapChanged, true); }
private void Awake() { _live = GetComponent <ILive>(); }