public void report(int worldId) { if (judgeLevelUpped()) { TOWN.levelUped(); } if (judgeSizeUpped()) { TOWN.sizeUped(); } var keys = charactersTraded.Keys; foreach (IFriendly character in keys) { if (judgeLevelUpped()) { if (character is Merchant) { var merchant = (Merchant)character; merchant.levelup(); } if (character is Client) { var client = (Client)character; client.levelup(); } } } ObserverHelper.saveToFile <TownBuilder>(TOWN.compressIntoBuilder(), "TownData", townId, worldId); }
public override void report(int worldId) { this.healItem = HealItemMasterManager.getInstance().getHealItemBuilderFromId(OBSERVE_ITEM_ID); HealItemProgress progress = HealItemMasterManager.getInstance().getProgress(OBSERVE_ITEM_ID); progress.Heal += reportHealValue(); progress.Level = reportItemLevel(progress.Heal); ObserverHelper.saveToFile <HealItemProgress>(progress, "HealItemProgress", OBSERVE_ITEM_ID, worldId); }
public override void report(int worldId) { material = ItemMaterialMasterManager.getInstance().getMaterialBuilderFromId(OBSERVE_ITEM_ID); ItemMaterialProgress progress = ItemMaterialMasterManager.getInstance().getProgress(OBSERVE_ITEM_ID); progress.Quality += progressQuality(); progress.Level = progressLevel(progress.Quality); ObserverHelper.saveToFile <ItemMaterialProgress>(progress, "ItemMaterialProgress", OBSERVE_ITEM_ID, worldId); }
public void CreateHydraulicBoundaryLocationCalculationsObserver_CalculationsNull_ThrowsArgumentNullException() { // Call TestDelegate call = () => ObserverHelper.CreateHydraulicBoundaryLocationCalculationsObserver(null, () => {}); // Assert var exception = Assert.Throws <ArgumentNullException>(call); Assert.AreEqual("calculations", exception.ParamName); }
private void CreateObservers() { failureMechanismContributionObserver = new Observer(UpdateFeatures) { Observable = assessmentSection.FailureMechanismContribution }; hydraulicBoundaryLocationsObserver = new Observer(UpdateFeatures) { Observable = assessmentSection.HydraulicBoundaryDatabase.Locations }; waterLevelCalculationsForSignalFloodingProbabilityObserver = ObserverHelper.CreateHydraulicBoundaryLocationCalculationsObserver( assessmentSection.WaterLevelCalculationsForSignalFloodingProbability, UpdateFeatures); waterLevelCalculationsForMaximumAllowableFloodingProbabilityObserver = ObserverHelper.CreateHydraulicBoundaryLocationCalculationsObserver( assessmentSection.WaterLevelCalculationsForMaximumAllowableFloodingProbability, UpdateFeatures); waterLevelForUserDefinedTargetProbabilitiesCollectionObserver = new Observer(() => { DeleteTargetProbabilitiesObservers(waterLevelCalculationsForTargetProbabilityObservers); CreateTargetProbabilitiesObservers(assessmentSection.WaterLevelCalculationsForUserDefinedTargetProbabilities, waterLevelCalculationsForTargetProbabilityObservers); UpdateFeatures(); }) { Observable = assessmentSection.WaterLevelCalculationsForUserDefinedTargetProbabilities }; waveHeightForUserDefinedTargetProbabilitiesCollectionObserver = new Observer(() => { DeleteTargetProbabilitiesObservers(waveHeightCalculationsForTargetProbabilityObservers); CreateTargetProbabilitiesObservers(assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities, waveHeightCalculationsForTargetProbabilityObservers); UpdateFeatures(); }) { Observable = assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities }; waterLevelForUserDefinedTargetProbabilitiesObserver = new RecursiveObserver <IObservableEnumerable <HydraulicBoundaryLocationCalculationsForTargetProbability>, HydraulicBoundaryLocationCalculationsForTargetProbability>( UpdateFeatures, tp => tp) { Observable = assessmentSection.WaterLevelCalculationsForUserDefinedTargetProbabilities }; waveHeightForUserDefinedTargetProbabilitiesObserver = new RecursiveObserver <IObservableEnumerable <HydraulicBoundaryLocationCalculationsForTargetProbability>, HydraulicBoundaryLocationCalculationsForTargetProbability>( UpdateFeatures, tp => tp) { Observable = assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities }; waterLevelCalculationsForTargetProbabilityObservers = new List <RecursiveObserver <IObservableEnumerable <HydraulicBoundaryLocationCalculation>, HydraulicBoundaryLocationCalculation> >(); CreateTargetProbabilitiesObservers(assessmentSection.WaterLevelCalculationsForUserDefinedTargetProbabilities, waterLevelCalculationsForTargetProbabilityObservers); waveHeightCalculationsForTargetProbabilityObservers = new List <RecursiveObserver <IObservableEnumerable <HydraulicBoundaryLocationCalculation>, HydraulicBoundaryLocationCalculation> >(); CreateTargetProbabilitiesObservers(assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities, waveHeightCalculationsForTargetProbabilityObservers); }
public void CreateHydraulicBoundaryLocationCalculationsObserver_WithData_ReturnsRecursiveObserver() { // Setup var calculations = new ObservableList <HydraulicBoundaryLocationCalculation>(); // Call using (RecursiveObserver <IObservableEnumerable <HydraulicBoundaryLocationCalculation>, HydraulicBoundaryLocationCalculation> observer = ObserverHelper.CreateHydraulicBoundaryLocationCalculationsObserver(calculations, () => {})) { // Assert Assert.AreSame(calculations, observer.Observable); } }
/// <summary> /// Performs a validations when the user tries to change some of the units skill points. /// The new value (value + change) of the skill must be between the mininum and maximum value /// for that skill and team must still have points left to expend. /// </summary> /// <param name="value"></param> /// <param name="maxValue"></param> /// <param name="minValue"></param> /// <param name="change"></param> /// <returns></returns> private double TryChangeDouble(double value, double maxValue, double minValue, double change) { var newVal = value + change; var newPoints = Points + (change < 0 ? 1 : -1); if (newVal <= maxValue && newVal >= minValue && newPoints >= 0 && newPoints <= MainViewModel.MAX_TEAM_POINTS) { value = newVal; Points = newPoints; UsedPoints += (change < 0 ? -1 : 1); ObserverHelper <MainViewModel, int> .NotifyObservers(this, Points); } return(value); }
public void saveWorld() { var saveData = new WorldData(); saveData.Towns = this.towns; saveData.WorldLevel = this.worldLevel; saveData.WorldName = this.worldName; ObserverHelper.saveToFile <WorldData>(saveData, "WorldData", id, id); foreach (Town town in enableTowns) { var builder = town.compressIntoBuilder(); ObserverHelper.saveToFile <TownBuilder>(builder, "TownData", town.getId(), id); MonoBehaviour.Destroy(town.gameObject); } }
public void report(int worldId) { progress.Effect += getValueProgress(Effect); progress.Cost -= getValueProgress(Cost); progress.Delay -= getSpeedProgress(Delay); if (IsAttackSkill) { var attackProgress = (ActiveAttackSkillProgress)progress; attackProgress.Hit += Hit; ObserverHelper.saveToFile <ActiveAttackSkillProgress>(attackProgress, FileAddress, OBSERVE_SKILL_ID, worldId); } else { ObserverHelper.saveToFile <ActiveSkillProgress>(progress, FileAddress, OBSERVE_SKILL_ID, worldId); } }
public void CreateHydraulicBoundaryLocationCalculationsObserver_UpdateObserverActionNull_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var calculations = mocks.Stub <IObservableEnumerable <HydraulicBoundaryLocationCalculation> >(); mocks.ReplayAll(); // Call TestDelegate call = () => ObserverHelper.CreateHydraulicBoundaryLocationCalculationsObserver(calculations, null); // Assert var exception = Assert.Throws <ArgumentNullException>(call); Assert.AreEqual("updateObserverAction", exception.ParamName); mocks.VerifyAll(); }
/// <summary> /// When a unit dies, the MainViewModel unsubscribes the unit events, restores unit points to the /// total of the team points and remove it from the field of battle. /// </summary> /// <param name="sender">The dead unit</param> /// <param name="Team">The team of the dead unit</param> private void Unit_UnitDied(object sender, UnitTeam Team) { var unit = sender as UnitViewModel; unit.UnitAttack -= Unit_UnitAttack; unit.UnitDied -= Unit_UnitDied; if (Team == UnitTeam.Red) { ListRedUnits.Remove(unit); ObserverHelper <MainViewModel, int> .NotifyObservers(unit, RedPoints + unit.UsedPoints); } else { ListBlueUnits.Remove(unit); ObserverHelper <MainViewModel, int> .NotifyObservers(unit, BluePoints + unit.UsedPoints); } }
public void GivenCreatedHydraulicBoundaryLocationCalculationsObserver_WhenCalculationNotifiesObservers_ThenUpdateObserverActionCalled() { // Given var count = 0; var calculation = new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation()); var calculations = new ObservableList <HydraulicBoundaryLocationCalculation> { calculation }; using (ObserverHelper.CreateHydraulicBoundaryLocationCalculationsObserver(calculations, () => { count++; })) { // When calculation.NotifyObservers(); // Then Assert.AreEqual(1, count); } }
public MainViewModel() { ListBlueUnits = new ObservableCollection <UnitViewModel>(); ListRedUnits = new ObservableCollection <UnitViewModel>(); ListBlueUnits.CollectionChanged += ListUnits_CollectionChanged; ListRedUnits.CollectionChanged += ListUnits_CollectionChanged; NewRedInfantryClicked = new RelayCommand(OnNewRedInfantryClicked); NewRedRangedClicked = new RelayCommand(OnNewRedRangedClicked); NewRedCavalryClicked = new RelayCommand(OnNewRedCavalryClicked); NewBlueInfantryClicked = new RelayCommand(OnNewBlueInfantryClicked); NewBlueRangedClicked = new RelayCommand(OnNewBlueRangedClicked); NewBlueCavalryClicked = new RelayCommand(OnNewBlueCavalryClicked); UnitClicked = new RelayCommand <object>(OnUnitClicked); StartBattle = new RelayCommand(DoStartBattle); ClearBattleField = new RelayCommand(DoClearBattleField); KillSelectedUnitClicked = new RelayCommand(OnKillSelectedUnitClicked); CancelEditUnitClicked = new RelayCommand(OnCancelEditUnitClicked); ObserverHelper <MainViewModel, int> .Register(this); InitSampleBattleField(); }
public ObserverActionEventArgs(ObserverHelper observer, NSNotification notification) { this.observer = observer; this.Notification = notification; }
public void report(int worldId) { observeEnemyBuilder = EnemyMasterManager.getInstance().getEnemyBuilderFromId(OBSERVE_ENEMY_ID); var abilities = new Dictionary <BattleAbility, int>(); var keys = Enum.GetValues(typeof(BattleAbility)); foreach (BattleAbility ability in keys) { if (ability == MFT || ability == FFT || ability == MGP) { if (judgeAttackAbilityProgressed()) { abilities.Add(ability, progressAttackAbility()); } else { abilities.Add(ability, 0); } } else { if (judgeExserciseAbilityProgressed()) { abilities.Add(ability, progressExserciseAbility()); } else { abilities.Add(ability, 0); } } } var attributeTable = new Dictionary <AttackSkillAttribute, float>(); var attributeKeys = Enum.GetValues(typeof(AttackSkillAttribute)); foreach (AttackSkillAttribute attribute in attributeKeys) { if (judgeResistanceProsessed(attribute)) { attributeTable.Add(attribute, progressResistance(attribute)); } else { attributeTable.Add(attribute, 0); } } int weponLevel; if (judgeWeponLevelUped()) { weponLevel = weponLevelUp(); } else { weponLevel = 0; } var progress = EnemyMasterManager.getInstance().getProgressFromId(OBSERVE_ENEMY_ID); var abilityKeys = abilities.Keys; foreach (var key in abilityKeys) { progress.Abilities[key] += abilities[key]; } foreach (AttackSkillAttribute key in attributeKeys) { progress.AttributeResistances[key] += attributeTable[key]; } progress.WeponLevel += weponLevel; ObserverHelper.saveToFile <EnemyProgress>(progress, "EnemyProgress", OBSERVE_ENEMY_ID, worldId); }
/// <summary> /// Unresgister the current instance of the viewmodel from the ObserverHelper. /// </summary> public void Dispose() { ObserverHelper <MainViewModel, int> .UnRegister(this); }
private void CreateTargetProbabilitiesObservers(IEnumerable <HydraulicBoundaryLocationCalculationsForTargetProbability> calculationsForUserDefinedTargetProbabilities, List <RecursiveObserver <IObservableEnumerable <HydraulicBoundaryLocationCalculation>, HydraulicBoundaryLocationCalculation> > observers) { observers.AddRange(calculationsForUserDefinedTargetProbabilities.Select(calculationsForTargetProbability => ObserverHelper.CreateHydraulicBoundaryLocationCalculationsObserver( calculationsForTargetProbability.HydraulicBoundaryLocationCalculations, UpdateFeatures))); }