private IEnumerator MoveUnit(UnitLoader currentEnemy, Vector2 targetPosition) { while (currentEnemy.transform.localPosition.x != targetPosition.x) { if (currentEnemy.transform.localPosition.x > targetPosition.x) { currentEnemy.GetComponent <Animator>().SetBool("Left", true); } else { currentEnemy.GetComponent <Animator>().SetBool("Right", true); } currentEnemy.transform.localPosition = Vector2.MoveTowards(currentEnemy.transform.localPosition, new Vector2(targetPosition.x, currentEnemy.transform.localPosition.y), 2f * Time.deltaTime); yield return(null); } while (currentEnemy.transform.localPosition.y != targetPosition.y) { if (currentEnemy.transform.localPosition.y > targetPosition.y) { currentEnemy.GetComponent <Animator>().SetBool("Down", true); } else { currentEnemy.GetComponent <Animator>().SetBool("Up", true); } currentEnemy.transform.localPosition = Vector2.MoveTowards(currentEnemy.transform.localPosition, new Vector2(currentEnemy.transform.localPosition.x, targetPosition.y), 2f * Time.deltaTime); yield return(null); } currentEnemy.GetComponent <Animator>().SetBool("Right", false); }
public bool LoadFromFile(string taskDataFile) { if (!LoadXmlFile(taskDataFile)) { return(false); } if (!VerifyIsoVersion()) { return(false); } LinkedIds = LinkListLoader.Load(this); Units = UnitLoader.Load(this); Customers = CustomerLoader.Load(this); Farms = FarmLoader.Load(this); Crops = CropLoader.Load(this); Fields = FieldLoader.Load(this); Products = ProductLoader.Load(this); ProductMixes = ProductMixLoader.Load(this); Workers = WorkerLoader.Load(this); Comments = CommentLoader.Load(this); Tasks = TaskLoader.Load(this); RasterPrescriptions = PrescriptionLoader.Load(this); Machines = DeviceLoader.Load(this); return(true); }
public static void LoadGraphicsAssetsFromFiles(Ruleset ruleset, Rules rules) { TerrainLoader.LoadTerrain(ruleset, rules); UnitLoader.LoadUnits(ruleset); LoadIcons(ruleset); LoadPeopleIcons(ruleset); LoadCityWallpaper(ruleset); }
private IEnumerator EffectAnimation(UnitLoader attacker, UnitLoader defender) { var effect = Instantiate(attacker.equippedWeapon.animation, defender.transform.position, Quaternion.identity); yield return(new WaitForSeconds(attacker.equippedWeapon.animationLength.length)); Destroy(effect); yield return(null); }
public static void LoadUnits(string filepath) { foreach (var file in Directory.GetFiles(filepath, "*.json")) { var unit = UnitLoader.LoadUnitDefinition(file); var type = unit.GetComponent <UnitComponent>(); _prototypes.Add(type.UnitType, unit); } }
public void OneTimeSetUp() { loader = new UnitLoader(new XmlSlideLoader()); courseSettings = new CourseSettings(CourseSettings.DefaultSettings); courseSettings.Scoring.Groups.Add("ScoringGroup1", new ScoringGroup { Id = "ScoringGroup1" }); }
public UnitLoader() { if (instance != null) { Debug.LogError ("Cannot have two instances of singleton. Self destruction in 3..."); return; } instance = this; }
public void EngageAttack(UnitLoader attacker, UnitLoader defender) { StartCoroutine(Attack(attacker, defender)); attackerHealth.maxValue = attacker.unit.statistics.health; attackerHealth.value = attacker.currentHealth; defenderHealth.maxValue = defender.unit.statistics.health; defenderHealth.value = defender.currentHealth; }
public void FillSlot(UnitLoader unit) { slotUnit = unit; sprite.sprite = unit.unit.sprite; unitName.text = unit.unit.unitName; unitWeapon.text = unit.equippedWeapon.name; unitLvl.text = unit.unit.level.ToString(); unitEXP.text = unit.unit.exp.ToString(); unitHealth.text = unit.currentHealth.ToString() + " / " + unit.unit.statistics.health.ToString(); }
private bool CheckAttackSpeed(UnitLoader attacker, UnitLoader defender) { if (attacker.CombatStatistics().attackSpeed > defender.CombatStatistics().attackSpeed + 5) { return(true); } else { return(false); } }
private IEnumerator BehaviorSystem() { cursor.enemyTurn = true; List <UnitLoader> enemies = enemyOrder; //Iterates through each enemy in the enemy list for (int i = 0; i < enemies.Count; i++) { currentEnemy = enemies[i]; enemyAnimator = currentEnemy.GetComponent <Animator>(); StartCoroutine(MoveCamera(enemies[i])); yield return(new WaitUntil(() => mainCamera.transform.position == cameraTarget)); if (enemies[i].GetComponent <BehaviorTag>().blitz) { Blitz(currentEnemy); yield return(new WaitUntil(() => currentEnemy.rested || !currentEnemy)); yield return(new WaitForSeconds(0.5f)); walkableTiles.Clear(); enemiesInRange.Clear(); } else if (enemies[i].GetComponent <BehaviorTag>().defensive) { Defensive(); if (IsLastEnemy() && combatReadout.activeSelf == false) { yield return(new WaitForSeconds(0.5f)); } else { yield return(new WaitUntil(() => currentEnemy.rested || !currentEnemy)); yield return(new WaitForSeconds(0.5f)); } walkableTiles.Clear(); enemiesInRange.Clear(); } yield return(new WaitUntil(() => !combatReadout.activeSelf)); yield return(new WaitForSeconds(0.6f)); } enemyOrder.Clear(); SetEnemyOrder(); cursor.enemyTurn = false; if (fastModeIndicator.activeSelf) { fastModeIndicator.GetComponent <Animator>().SetTrigger("Exit"); } yield return(null); }
private void OnDisable() { slotUnit = null; sprite.sprite = null; unitName.text = null; unitWeapon.text = null; unitLvl.text = null; unitEXP.text = null; unitHealth.text = null; Destroy(gameObject); }
private bool CritRoll(UnitLoader unit) { int roll = Random.Range(0, 99); if (roll > unit.CombatStatistics().crit) { return(false); } else { return(true); } }
private string CheckForDeaths(UnitLoader attacker, UnitLoader defender) { if (defender.currentHealth <= 0) { AIManager.instance.enemyOrder.Remove(defender); TurnManager.instance.RefreshTiles(); return("Defender"); } else if (attacker.currentHealth <= 0) { TurnManager.instance.RefreshTiles(); return("Attacker"); } return(null); }
private UnitLoader DetermineWeakestUnit() { UnitLoader weakestUnit = null; int highestDamage = 0; foreach (UnitLoader unit in enemiesInRange) { if (CombatManager.instance.Hit(currentEnemy, unit) > highestDamage) { highestDamage = CombatManager.instance.Hit(currentEnemy, unit); weakestUnit = unit; } } return(weakestUnit); }
public void DisplayInventory(UnitLoader unit) { int amountOfItems = unit.inventory.inventory.Count; for (int i = 0; i < transform.childCount; i++) { transform.GetChild(i).gameObject.SetActive(false); } for (int i = 0; i < amountOfItems; i++) { transform.GetChild(i).gameObject.SetActive(true); transform.GetChild(i).GetComponent <InventorySlot>().item = unit.inventory.inventory[i]; transform.GetChild(i).GetComponent <InventorySlot>().FillSlot(); } }
private Node FindClosestTile(UnitLoader unit) { int lowestSoFar = 100; Node targetTile = map.ReturnNodeAt((int)unit.transform.localPosition.x, (int)unit.transform.localPosition.y); Node closestTile = null; foreach (Node tile in walkableTiles) { if (tile.DistanceTo(targetTile) < lowestSoFar && map.CanTraverse(tile.x, tile.y)) { lowestSoFar = tile.DistanceTo(targetTile); closestTile = tile; } } return(closestTile); }
private void DefenderAttack(UnitLoader attacker, UnitLoader defender) { if (CheckDistance(defender, attacker) <= 1 || defender.equippedWeapon.range >= attacker.equippedWeapon.range) { //Check for a hit if (HitRoll(defender)) { //Checks for a crit if (CritRoll(defender)) { //Unit Crits SoundManager.instance.PlayFX(4); battleText.SetText("Crit"); Instantiate(battleText, attacker.transform.position, Quaternion.identity); attacker.currentHealth = attacker.currentHealth - Critical(defender, attacker); StartCoroutine(Shake(Critical(defender, attacker), false)); attackerHealth.value = attacker.currentHealth; //Display critial quote if (defender.unit.allyUnit && !attacker.defeatedDialogue) { MapDialogueManager.instance.WriteSingle(defender.GetComponent <BattleDialogue>().RandomCritQuote()); dialoguePlayed = true; } } else { //Unit Hits SoundManager.instance.PlayFX(3); battleText.SetText("Hit"); Instantiate(battleText, attacker.transform.position, Quaternion.identity); attacker.currentHealth = attacker.currentHealth - Hit(defender, attacker); StartCoroutine(Shake(Hit(defender, attacker), false)); attackerHealth.value = attacker.currentHealth; } } else { //Unit Misses SoundManager.instance.PlayFX(5); battleText.SetText("Miss"); Instantiate(battleText, attacker.transform.position, Quaternion.identity); return; } } }
public void Rest() { foreach (UnitLoader unit in TurnManager.instance.enemyUnits) { if (unit.spriteRenderer.color == Color.red) { unit.spriteRenderer.color = Color.white; } } hasMoved = true; rested = true; currentPath = null; enemiesInRange.Clear(); target = null; spriteRenderer.color = Color.grey; map.DehighlightTiles(); }
private void Defensive() { currentEnemy.currentPath = null; GetEnemies(); if (enemiesInRange.Count == 0) { currentEnemy.Rest(); } else if (enemiesInRange.Count == 1) { CombatManager.instance.EngageAttack(currentEnemy, enemiesInRange[0]); } else if (enemiesInRange.Count >= 2) { UnitLoader weakestUnit = DetermineWeakestUnit(); CombatManager.instance.EngageAttack(currentEnemy, weakestUnit); } }
private UnitLoader FindClosestAlly() { int closestSoFar = 100; UnitLoader closestUnit = null; Node currentNode = map.ReturnNodeAt((int)currentEnemy.transform.localPosition.x, (int)currentEnemy.transform.localPosition.y); Node unitNode = null; foreach (UnitLoader unit in TurnManager.instance.allyUnits) { unitNode = map.ReturnNodeAt((int)unit.transform.localPosition.x, (int)unit.transform.localPosition.y); if ((currentNode.DistanceTo(unitNode)) <= closestSoFar) { closestSoFar = currentNode.DistanceTo(unitNode); closestUnit = unit; } } return(closestUnit); }
public async Task Load() { await Task.WhenAll(IssueLoader.Load(), DecisionsLoader.Load(), EventsLoader.Load(), InventionsLoader.Load(), TechnologiesLoader.Load(), PopLoader.Load(), UnitLoader.Load(), ProvinceLoader.Load(), PopTypeLoader.Load(), DiplomacyLoader.Load(), OobLoader.Load(), WarLoader.Load(), BookmarkLoader.Load(), BuildingLoader.Load(), CbLoader.Load(), CotColorLoader.Load(), NationalFocusLoader.Load(), GraphicalCultureLoader.Load(), IdeologyLoader.Load(), CountryLoader.Load(), CountryColorsLoader.Load(), CrimeLoader.Load(), CultureLoader.Load(), DefinesLoader.Load(), EventModifiersLoader.Load(), GoodsLoader.Load(), GovernmentsLoader.Load(), NationalValueLoader.Load(), OnActionsLoader.Load(), PopTypeLoader.Load(), ProductionTypeLoader.Load(), RebelTypeLoader.Load(), ReligionLoader.Load(), StaticModifiersLoader.Load(), TechSchoolLoader.Load(), TraitsLoader.Load(), TriggeredModifiersLoader.Load(), CountryDirectoryLoader.Load() ); }
private void Blitz(UnitLoader currentEnemy) { GetEnemies(); if (enemiesInRange.Count == 0) { GetWalkableTiles(); UnitLoader closestAlly = FindClosestAlly(); Node closestTile = FindClosestTile(closestAlly); map.GeneratePathTo(closestTile.x, closestTile.y, currentEnemy); NodeMove(currentEnemy); } else if (enemiesInRange.Count == 1) { CombatManager.instance.EngageAttack(currentEnemy, enemiesInRange[0]); } else if (enemiesInRange.Count >= 2) { CombatManager.instance.EngageAttack(currentEnemy, DetermineWeakestUnit()); } }
public void Initialise(string unitsFilepath, string mapFilename, string weaponFilepath, string modelFilepath) { // todo: refactor this to: // unit = LoadUnitModel(); // LoadTexture(unit.Texture); // factories.Initialise..? TextureFactory.LoadTextures(@"C:\Source\MapEditor\MapEngine\Content\Textures"); WeaponFactory.LoadWeapons(weaponFilepath); // todo: code stink - requires factories to be initialised in an order UnitFactory.LoadUnits(unitsFilepath); ModelFactory.LoadModel(modelFilepath); var units = UnitLoader.LoadUnits(mapFilename); foreach (var unit in units) { _messageHub.Post(new CreateEntityCommand { Entity = unit }); } }
private void ActionCamera(UnitLoader attacker, UnitLoader defender) { var point1 = attacker.transform.localPosition; var point2 = defender.transform.localPosition; if (point1.x < cursor.cameraLeft) { point1.x = cursor.cameraLeft; } else if (point2.x < cursor.cameraLeft) { point2.x = cursor.cameraLeft; } var centerPoint = (point1 + point2) / 2; Vector3 zoomPoint = new Vector3(centerPoint.x, centerPoint.y, -10); StartCoroutine(MoveCamera(zoomPoint)); }
private IEnumerator MoveCamera(UnitLoader enemy) { var moveSpeed = 5; if (fastMode) { moveSpeed = 10; } else { moveSpeed = 5; } cameraTarget = new Vector3(enemy.transform.position.x, enemy.transform.position.y, -10); if (cameraTarget.x > cursor.cameraRight) { cameraTarget.x = cursor.cameraRight; } if (cameraTarget.x < cursor.cameraLeft) { cameraTarget.x = cursor.cameraLeft; } if (cameraTarget.y > cursor.cameraTop) { cameraTarget.y = cursor.cameraTop; } if (cameraTarget.y < cursor.cameraBottom) { cameraTarget.y = cursor.cameraBottom; } while (mainCamera.transform.position != cameraTarget) { mainCamera.transform.position = Vector3.MoveTowards(mainCamera.transform.position, cameraTarget, moveSpeed * Time.deltaTime); yield return(null); } }
/// <summary> /// 生成单位 /// </summary> /// <param name="_name">单位类型名称</param> /// <param name="_pos">单位一维坐标</param> /// <param name="_camp">单位阵营编号</param> public void AddUnit(string _name, int _pos, int _camp) { GameObject unit = UnitLoader.LoadUnitToBattleField(_name); unit.tag = "Player_" + _camp; Vector3 pos = GameObject.Find(_pos.ToString()).transform.position; pos.y = 0.5f; unit.transform.position = pos; // 单位池与战场单位池记录单位及其位置 unitPool.Add(unit, _pos); bfm.AddUnit(unit, _pos); // 发送位置信息给单位 unit.SendMessage("SetPosition", _pos); // 设置阵营 unit.SendMessage("SetCamp", _camp); // 订阅死亡信息 unit.SendMessage("subscribeUnitDead", (Action <GameObject>)RemoveUnit); }
public int Hit(UnitLoader attacker, UnitLoader defender) { return(attacker.CombatStatistics().attack - defender.CombatStatistics().protection); }
// 유저 마스터 불러오기 // 씬에서 작업된 모델에 위치, 애니메이션, 트랙정보 등 저장 -> 사본(유저별 마스터)에 적용후 원본 삭제 private void LoadMaster() { var master = UserDataManager.Instance.UserMasterCharacter; if (master == null || _goMaster == null) { return; } var originAnimator = _goMaster.GetComponent <Animator>(); Animator originHairAnimator = null; var animators = _goMaster.GetComponentsInChildren <Animator>(); foreach (var animator in animators) { if (animator != null && animator.gameObject.name.ToLower().Contains("hair")) { originHairAnimator = animator; break; } } var loader = UnitLoader.GetLoader(master); if (loader == null) { return; } var goModel = loader.LoadCharacter(UnitLoader.LoadType.None, UnitLoader.CharMatType.Hd, _goMaster.transform.parent); if (goModel == null) { return; } goModel.SetLayerRecursively(_goMaster.layer); var trCurrent = _goMaster.transform; var trModel = goModel.transform; trModel.localPosition = trCurrent.localPosition; trModel.localRotation = trCurrent.localRotation; trModel.localScale = trCurrent.localScale; var uma = goModel.GetComponent <UnitMasterActor>(); if (uma != null) { uma.SetLoadType(UnitLoader.LoadType.None, UnitLoader.CharMatType.Hd); } var newAnimator = goModel.GetComponent <Animator>(); var newAnimators = goModel.GetComponentsInChildren <Animator>(); Animator newHairAnimator = null; if (originHairAnimator != null) { foreach (var animator in newAnimators) { if (animator != null && animator.gameObject.name.ToLower().Contains("hair")) { newHairAnimator = animator; } } } if (newAnimator != null && _directorIntro != null) { var timelineAsset = _directorIntro.playableAsset as TimelineAsset; if (timelineAsset != null) { var tracks = timelineAsset.GetOutputTracks(); foreach (var track in tracks) { var bindingObject = _directorIntro.GetGenericBinding(track); if (bindingObject == originAnimator) { _directorIntro.SetGenericBinding(track, newAnimator); } else if (newHairAnimator != null && originHairAnimator != null && bindingObject == originHairAnimator) { _directorIntro.SetGenericBinding(track, newHairAnimator); } AddEffectSound(track); } } if (_directorLoop != null) { var timelineAsset2 = _directorLoop.playableAsset as TimelineAsset; if (timelineAsset2 != null) { var tracks = timelineAsset2.GetOutputTracks(); foreach (var track in tracks) { var bindingObject = _directorLoop.GetGenericBinding(track); if (bindingObject == originAnimator) { _directorLoop.SetGenericBinding(track, newAnimator); } else if (newHairAnimator != null && originHairAnimator != null && bindingObject == originHairAnimator) { _directorLoop.SetGenericBinding(track, newHairAnimator); } AddEffectSound(track); } } } } DestroyImmediate(_goMaster); _goMaster = goModel; }
private int Critical(UnitLoader attacker, UnitLoader defender) { return(attacker.CombatStatistics().attack * 2 - defender.CombatStatistics().protection); }
private float CheckDistance(UnitLoader unit1, UnitLoader unit2) { return(Mathf.Abs(unit1.transform.position.x - unit2.transform.position.x) + Mathf.Abs(unit1.transform.position.y - unit2.transform.position.y)); }