void CheckForMultiply(UnitProfile profile, Transform holder, int iter) { if ((numberOfTicksInSession + 1) % profile.multiplyFrequency != 0) { return; } int healthyUnits = 0; if (profile.consumer) { foreach (Transform u in holder) { if (u.GetComponent <Unit>().IsHealthy) { healthyUnits++; } } } else { healthyUnits = holder.childCount; } int timesToMultiply = healthyUnits / profile.parentCountRequired; for (int i = 0; i < timesToMultiply; i++) { for (int j = 0; j < profile.childCountProduced; j++) { CreateUnit(profile, iter); } } }
public void OnUnitDeath(UnitProfile profile) { for (int i = 0; i < unitTypeCount; i++) { if (profile == unitProfiles[i]) { unitCount[i]--; } } }
private void Start() { unitAttack = this.gameObject.AddComponent <UnitAttack>(); unitAttack.Initialize(this.gameObject); unitProfile = this.gameObject.AddComponent <UnitProfile>(); unitProfile.Initialize(); movement = this.gameObject.AddComponent <Movement>(); movement.Initialize(groundTilemap, collisionTilemap); startingPosition = gameObject.transform.position; }
List <UnitProfile> AddUnitToListOfUnitProfiles(Unit aUnit, List <UnitProfile> listOfUnitProfiles) { if (listOfUnitProfiles == null || !listOfUnitProfiles.Any()) { listOfUnitProfiles = new List <UnitProfile>(); } UnitProfile aProfile = new UnitProfile(); aProfile.Unit = aUnit; listOfUnitProfiles.Add(aProfile); return(listOfUnitProfiles); }
public Unit() { Definition = null; Profile = new UnitProfile(); Status = new UnitStatus(); Status.CharacterLevel = 1; Status.ItemLevel = 0; Status.Life = 1; Status.MaxLife = 1; Skills = new List <Skill>(); JoinedParty = null; }
public void Initialize(UnitProfile profile, Biome biome, int k, Vector3 spawnPoint) { this.profile = profile; this.biome = biome; //Debug.Log(biome.countsCreated[k]); name = profile.name + biome.countsCreated[k]; transform.SetParent(biome.nativeHolders[k]); biome.countsCreated[k]++; biome.counts[k]++; statesOfUnit = new int[profile.statesOfLife - 1]; for (int i = 0; i < profile.statesOfLife - 1; i++) { statesOfUnit[i] = CalculateStateValues(i); } //biome.nativeHolders[k] = GetAPlace(k); Instantiate(profile.modelObject, spawnPoint, Quaternion.identity); }/*
public void Initialize(UnitProfile profile, ForestSystem forest, int i) { this.profile = profile; this.forest = forest; baseName = profile.name + " " + forest.unitsCreated[i]; transform.SetParent(forest.unitHolders[i]); forest.unitsCreated[i]++; forest.unitCount[i]++; if (profile.consumer) { SetName(); } else { name = baseName; } }
public void TestUserHasNoRightstoRetrieveUnits() { Unit aUnit = new Unit() { UNIT_ID = 1001 }; UnitProfile unitProfile = new UnitProfile() { Unit = aUnit }; mockUnitProfileService.Setup(s => s.GetById(It.IsAny <long>())).Returns(Task.FromResult(unitProfile)); mockAuthenticationService.Setup(s => s.UserHasPrivs(It.IsAny <User>())).Returns(false); unitController = new UnitController(mockUnitProfileService.Object); Assert.ThrowsAsync <UnauthorizedAccessException>(async() => await unitController.GetAll()); }
public void TestUserhasPrivsToDeactivateUnit() { Unit aUnit = new Unit() { UNIT_ID = 1001, UNIT_CODE = "R10001", ACTIVE_FLAG = 0 }; UnitProfile unitProfile = new UnitProfile() { Unit = aUnit }; mockUnitProfileService.Setup(s => s.RemoveItem(It.IsAny <UnitProfile>())).Returns(Task.FromResult(unitProfile)); mockAuthenticationService.Setup(s => s.UserHasPrivs(It.IsAny <User>())).Returns(true); unitController = new UnitController(mockUnitProfileService.Object); Assert.DoesNotThrowAsync(async() => await unitController.Post(unitProfile)); }
public void TestUserHasNoPrivstoDeactivateUnits() { Unit aUnit = new Unit() { UNIT_ID = 1001, UNIT_CODE = "R10001", ACTIVE_FLAG = 0 }; UnitProfile unitProfile = new UnitProfile() { Unit = aUnit }; // mockUnitService.Setup(s => s.RemoveItem(It.IsAny<Unit>())).Returns(Task.FromResult(aUnit)); mockAuthenticationService.Setup(s => s.UserHasPrivs(It.IsAny <User>())).Returns(false); unitController = new UnitController(mockUnitProfileService.Object); Assert.ThrowsAsync <UnauthorizedAccessException>(async() => await unitController.Post(unitProfile)); }
public void TestRetrieveaUnitById() { Unit aUnit = new Unit() { UNIT_ID = 1001 }; UnitProfile unitProfile = new UnitProfile() { Unit = aUnit }; mockUnitProfileService.Setup(s => s.GetById(It.IsAny <long>())).Returns(Task.FromResult(unitProfile)); mockAuthenticationService.Setup(s => s.UserHasPrivs(It.IsAny <User>())).Returns(true); unitController = new UnitController(mockUnitProfileService.Object); var result = unitController.Get(aUnit.UNIT_ID); var entity = result.Result; Assert.That(entity.Unit.UNIT_ID, Is.EqualTo(aUnit.UNIT_ID)); }
public Unit(UnitDefinition definition, SkillLibrary skillLib) { Definition = definition; Profile = new UnitProfile(); Profile.Name = definition.DisplayedName; Status = new UnitStatus(); SetLevelFullStats(1, 0); Skills = new List <Skill>(); if (definition.InnateSkills != null) { foreach (string skillName in definition.InnateSkills) { skillLib.LearnSkill(this, skillName); } } JoinedParty = null; }
public void AssignNewUserDefinedName(Unit unit) { if (unit == null) { throw new NullReferenceException("unit"); } UnitProfile unitProfile = unit.UnitDesign as UnitProfile; if (unitProfile == null || !unitProfile.IsHero) { Diagnostics.LogError("Won't assign a user defined name to the given unit because it is not a hero."); return; } List <string> list; if (!this.names.TryGetValue(unit.UnitDesign.Name, out list)) { list = new List <string>(); } if (list.Count == 0) { IDatabase <UnitProfileNames> database = Databases.GetDatabase <UnitProfileNames>(false); UnitProfileNames unitProfileNames; if (database != null && database.TryGetValue(unit.UnitDesign.Name, out unitProfileNames)) { System.Random random = new System.Random(); List <string> collection = unitProfileNames.Names.ToList <string>().Randomize(random); list.AddRange(collection); } if (list.Count > 0 && !this.names.ContainsKey(unit.UnitDesign.Name)) { this.names.Add(unit.UnitDesign.Name, list); } } if (list.Count > 0) { unit.UnitDesign.LocalizationKey = list[list.Count - 1]; list.RemoveAt(list.Count - 1); } }
public void TestUserUpdateUnitWithUpdateResponse() { Unit aUnit = new Unit() { UNIT_ID = 1001, UNIT_CODE = "R10001" }; UnitProfile unitProfile = new UnitProfile() { Unit = aUnit }; mockUnitProfileService.Setup(s => s.SaveOrUpdate(It.IsAny <UnitProfile>())).Returns(Task.FromResult(unitProfile)); mockAuthenticationService.Setup(s => s.UserHasPrivs(It.IsAny <User>())).Returns(true); unitController = new UnitController(mockUnitProfileService.Object); var result = unitController.Post(unitProfile); var resultingProfile = result.Result; Assert.That(resultingProfile.Unit.UNIT_CODE, Is.EqualTo(aUnit.UNIT_CODE)); }
public void TestUserUpdateUnitDeactivatedUpdateResponse() { Unit aUnit = new Unit() { UNIT_ID = 1001, UNIT_CODE = "R10001", ACTIVE_FLAG = 0 }; UnitProfile unitProfile = new UnitProfile() { Unit = aUnit }; mockUnitProfileService.Setup(s => s.RemoveItem(It.IsAny <UnitProfile>())).Returns(Task.FromResult(unitProfile)); mockAuthenticationService.Setup(s => s.UserHasPrivs(It.IsAny <User>())).Returns(true); unitController = new UnitController(mockUnitProfileService.Object); var result = unitController.Post(unitProfile); var resultingProfile = result.Result; Assert.That(resultingProfile.Unit.ACTIVE_FLAG, Is.EqualTo(0)); }
private void Start() { if (this.gameObject.GetComponent <AttackManager>() == true) { attackManager = this.gameObject.GetComponent <AttackManager>(); } else { attackManager = new AttackManager(); } if (player == null) { player = GameObject.Find("Player"); } unitAttack = this.gameObject.AddComponent <UnitAttack>(); unitAttack.Initialize(this.gameObject); if (this.gameObject.GetComponent <UnitProfile>() == null) { unitProfile = this.gameObject.AddComponent <UnitProfile>(); unitProfile.Initialize(); } movement = this.gameObject.AddComponent <Movement>(); //Enemy doesn't need to initialize }
void CreateUnit(UnitProfile profile, int i) { Unit newUnit = new GameObject().AddComponent <Unit>(); newUnit.Initialize(profile, this, i); }
public async Task <UnitProfile> Post([FromBody] UnitProfile aUnit) { throw new NotImplementedException(); }
void CreateUnit(UnitProfile profile, int i, Vector3 spawnPoint) { Unit newUnit = new GameObject().AddComponent <Unit>(); newUnit.Initialize(profile, this, i, spawnPoint); }
protected override IEnumerator OnShow(params object[] parameters) { if (this.Background != null) { this.Background.TintColor = this.NonEmbarkedBackgroundColor; } this.abilityReferences.Clear(); if (this.context is IUnitAbilityController) { UnitAbilityReference[] abilities = (this.context as IUnitAbilityController).GetAbilities(); if (abilities != null) { UnitAbilityReference[] array = abilities; for (int i = 0; i < array.Length; i++) { UnitAbilityReference ability = array[i]; if (this.abilityReferences.Any((UnitAbilityReference match) => match.Name == ability.Name)) { int index = this.abilityReferences.FindIndex((UnitAbilityReference match) => match.Name == ability.Name); if (ability.Level > this.abilityReferences[index].Level) { this.abilityReferences[index] = ability; } } else { this.abilityReferences.Add(ability); } } } } this.abilityReferences.RemoveAll((UnitAbilityReference match) => !this.unitAbilityDatatable.ContainsKey(match.Name) || this.unitAbilityDatatable.GetValue(match.Name).Hidden); if (this.abilityReferences.Count > this.smallPrefabThreshold && this.abilityReferences.Count <= this.minimalPrefabThreshold && this.ResizeSelf) { if (this.previousSize != PanelFeatureCapacities.CapacityPrefabSizes.Small) { this.CapacitiesTable.DestroyAllChildren(); this.previousSize = PanelFeatureCapacities.CapacityPrefabSizes.Small; } this.CapacitiesTable.ReserveChildren(this.abilityReferences.Count, this.CapacitySmallPrefab, "Item"); } else if (this.abilityReferences.Count > this.minimalPrefabThreshold && this.ResizeSelf) { if (this.previousSize != PanelFeatureCapacities.CapacityPrefabSizes.Minimal) { this.CapacitiesTable.DestroyAllChildren(); this.previousSize = PanelFeatureCapacities.CapacityPrefabSizes.Minimal; } this.CapacitiesTable.ReserveChildren(this.abilityReferences.Count, this.CapacityMinimalPrefab, "Item"); } else { if (this.previousSize != PanelFeatureCapacities.CapacityPrefabSizes.Normal) { this.CapacitiesTable.DestroyAllChildren(); this.previousSize = PanelFeatureCapacities.CapacityPrefabSizes.Normal; } this.CapacitiesTable.ReserveChildren(this.abilityReferences.Count, this.CapacityPrefab, "Item"); } GuiUnit guiUnit = this.context as GuiUnit; Unit unit = this.context as Unit; List <UnitAbilityReference> listToCheck = new List <UnitAbilityReference>(); List <UnitAbilityReference> HeroAbilities = new List <UnitAbilityReference>(); List <UnitAbilityReference> ItemAbilities = new List <UnitAbilityReference>(); UnitDesign unitDesign = null; if (unit != null) { unitDesign = unit.UnitDesign; } if (guiUnit != null) { unitDesign = guiUnit.UnitDesign; } if (unitDesign != null) { if (unitDesign.UnitBodyDefinition.UnitAbilities != null && unitDesign.UnitBodyDefinition.UnitAbilities.Length != 0) { listToCheck = unitDesign.UnitBodyDefinition.UnitAbilities.ToList <UnitAbilityReference>(); } UnitProfile unitProfile = unitDesign as UnitProfile; if (unitProfile != null && unitProfile.ProfileAbilityReferences != null && unitProfile.ProfileAbilityReferences.Length != 0) { HeroAbilities = unitProfile.ProfileAbilityReferences.ToList <UnitAbilityReference>(); } if (unitDesign.UnitEquipmentSet != null) { List <StaticString> list = new List <StaticString>(unitDesign.UnitEquipmentSet.Slots.Length); IDatabase <ItemDefinition> database = Databases.GetDatabase <ItemDefinition>(false); Diagnostics.Assert(database != null); for (int j = 0; j < unitDesign.UnitEquipmentSet.Slots.Length; j++) { UnitEquipmentSet.Slot slot = unitDesign.UnitEquipmentSet.Slots[j]; if (!list.Contains(slot.ItemName)) { StaticString key = slot.ItemName.ToString().Split(DepartmentOfDefense.ItemSeparators)[0]; ItemDefinition itemDefinition; if (database.TryGetValue(key, out itemDefinition)) { Diagnostics.Assert(itemDefinition != null); if (itemDefinition.AbilityReferences != null) { ItemAbilities.AddRange(itemDefinition.AbilityReferences); list.Add(slot.ItemName); } } } } } } this.abilityReferences.Sort(delegate(UnitAbilityReference left, UnitAbilityReference right) { bool flag = !this.ContainsAbilityReference(HeroAbilities, left) && !this.ContainsAbilityReference(ItemAbilities, left); bool flag2 = this.ContainsAbilityReference(HeroAbilities, left); bool flag3 = this.ContainsAbilityReference(ItemAbilities, left); bool flag4 = !this.ContainsAbilityReference(HeroAbilities, right) && !this.ContainsAbilityReference(ItemAbilities, right); bool flag5 = this.ContainsAbilityReference(HeroAbilities, right); bool flag6 = this.ContainsAbilityReference(ItemAbilities, right); string x = left.Name + Mathf.Max((float)left.Level, 0f); string text = ""; GuiElement guiElement; if (this.GuiService.GuiPanelHelper.TryGetGuiElement(x, out guiElement)) { text = AgeLocalizer.Instance.LocalizeString(guiElement.Title); } x = right.Name + Mathf.Max((float)right.Level, 0f); string strB = ""; if (this.GuiService.GuiPanelHelper.TryGetGuiElement(x, out guiElement)) { strB = AgeLocalizer.Instance.LocalizeString(guiElement.Title); } if (flag && flag5) { return(-1); } if (flag && flag6) { return(-1); } if (flag2 && flag4) { return(1); } if (flag3 && flag4) { return(1); } if (flag2 && flag6) { return(-1); } if (flag3 && flag2) { return(1); } if ((flag && flag4) || (flag2 && flag5) || (flag3 && flag6)) { return(text.CompareTo(strB)); } return(0); }); this.CapacitiesTable.RefreshChildrenIList <UnitAbilityReference>(this.abilityReferences, this.refreshAbilityReferenceDelegate, true, false); this.CapacitiesTable.ArrangeChildren(); int num = this.CapacitiesTable.ComputeVisibleChildren(); if (num > 0) { this.CapacitiesTable.Visible = true; AgeTransform ageTransform = this.CapacitiesTable.GetChildren()[num - 1]; this.CapacitiesTable.Height = ageTransform.Y + ageTransform.Height + this.CapacitiesTable.VerticalMargin; this.Title.Text = AgeLocalizer.Instance.LocalizeString("%FeatureCapacitiesTitle"); if (this.ResizeSelf) { base.AgeTransform.Height = this.CapacitiesTable.PixelMarginTop + this.CapacitiesTable.Height + this.CapacitiesTable.PixelMarginBottom; } if (guiUnit != null && (guiUnit.Unit != null || guiUnit.UnitSnapshot != null) && this.Background != null && ((guiUnit.Unit != null && guiUnit.Unit.Embarked) || (guiUnit.UnitSnapshot != null && guiUnit.UnitSnapshot.Embarked))) { this.Title.Text = "%FeatureCapacitiesEmbarkedTitle"; this.Background.TintColor = this.EmbarkedBackgroundColor; } Color tintColor = PanelFeatureCapacities.Colorlist[Amplitude.Unity.Framework.Application.Registry.GetValue <int>(new StaticString("Settings/ELCP/UI/CapacityColor1"), 0)]; Color tintColor2 = PanelFeatureCapacities.Colorlist[Amplitude.Unity.Framework.Application.Registry.GetValue <int>(new StaticString("Settings/ELCP/UI/CapacityColor2"), 2)]; Color tintColor3 = PanelFeatureCapacities.Colorlist[Amplitude.Unity.Framework.Application.Registry.GetValue <int>(new StaticString("Settings/ELCP/UI/CapacityColor3"), 8)]; for (int k = 0; k < this.abilityReferences.Count; k++) { FeatureItemCapacity component = this.CapacitiesTable.GetChildren()[k].GetComponent <FeatureItemCapacity>(); if (component != null && !this.ContainsAbilityReference(listToCheck, this.abilityReferences[k])) { component.Icon.TintColor = tintColor; if (this.ContainsAbilityReference(HeroAbilities, this.abilityReferences[k])) { component.Icon.TintColor = tintColor2; } else if (this.ContainsAbilityReference(ItemAbilities, this.abilityReferences[k])) { component.Icon.TintColor = tintColor3; } else { component.Icon.TintColor = tintColor; } } else if (component != null && this.ContainsAbilityReference(listToCheck, this.abilityReferences[k])) { component.Icon.TintColor = tintColor; } } } else { this.CapacitiesTable.Visible = false; this.Title.Text = AgeLocalizer.Instance.LocalizeString("%FeatureNoCapacitiesTitle"); if (this.ResizeSelf) { base.AgeTransform.Height = this.CapacitiesTable.PixelMarginTop; } } yield return(base.OnShow(parameters)); yield break; }
public HeroDescriptor(UnitProfile unitProfile) { this.UnitProfile = (UnitProfile)unitProfile.Clone(); }
bool IHeroManagementService.TryAllocateSkillPoints(Unit unit) { if (unit == null) { throw new ArgumentNullException("unit"); } UnitProfile unitProfile = unit.UnitDesign as UnitProfile; if (unitProfile == null || !unitProfile.IsHero) { return(false); } int num = (int)Math.Floor((double)(unit.GetPropertyValue(SimulationProperties.MaximumSkillPoints) - unit.GetPropertyValue(SimulationProperties.SkillPointsSpent))); if (num <= 0) { return(false); } if (unitProfile.UnitSkillAllocationSchemeReference == null || StaticString.IsNullOrEmpty(unitProfile.UnitSkillAllocationSchemeReference)) { return(false); } IDatabase <Droplist> database = Databases.GetDatabase <Droplist>(false); if (database == null) { return(false); } Droplist droplist; if (database.TryGetValue(unitProfile.UnitSkillAllocationSchemeReference, out droplist)) { UnitSkill[] availableUnitSkills = DepartmentOfEducation.GetAvailableUnitSkills(unit); for (int i = 0; i < num; i++) { Droplist droplist2; DroppableString droppableString = droplist.Pick(null, out droplist2, new object[0]) as DroppableString; if (droppableString != null) { if (!string.IsNullOrEmpty(droppableString.Value)) { StaticString subcategory = droppableString.Value; List <UnitSkill> list = (from iterator in availableUnitSkills where iterator.SubCategory == subcategory && DepartmentOfEducation.IsUnitSkillUnlockable(unit, iterator) select iterator).ToList <UnitSkill>(); if (list.Count > 0) { while (list.Count > 0) { int index = UnityEngine.Random.Range(0, list.Count); int num2 = 0; if (unit.IsSkillUnlocked(list[index].Name)) { num2 = unit.GetSkillLevel(list[index].Name) + 1; int num3 = 0; if (list[index].UnitSkillLevels != null) { num3 = list[index].UnitSkillLevels.Length - 1; } if (num2 > num3) { list.Remove(list[index]); continue; } } unit.UnlockSkill(list[index].Name, num2); num = (int)Math.Floor((double)(unit.GetPropertyValue(SimulationProperties.MaximumSkillPoints) - unit.GetPropertyValue(SimulationProperties.SkillPointsSpent))); break; } } } } } } return(true); }