public HeroUnit CreateHeroUnit(string unit_name, int id, Vector3 pos) { GDSKit.unit unit_gds = GDSKit.unit.GetInstance(unit_name); GameObject hero_unit_gameobj = ObjectPoolManager.Instance().GetObject(unit_gds.resource_name); hero_unit_gameobj.transform.SetParent(cache_root_unit_node); HeroUnit hero_unit = hero_unit_gameobj.GetComponent <HeroUnit>(); // 属性相关设置 hero_unit.unit_name = unit_name; hero_unit.unit_type = UnitType.Hero; hero_unit.unit_id = id; hero_unit.resource_key = unit_gds.resource_name; hero_unit.position = pos; if (all_unit_list.ContainsKey(hero_unit.unit_id)) { Debug.LogError("相同名字的unit已经在管理器里了 id : " + hero_unit.unit_id); return(null); } all_unit_list.Add(hero_unit.unit_id, hero_unit); hero_unit_list.Add(hero_unit.unit_id, hero_unit); hero_unit.PlayIdle(); return(hero_unit); }
public void WaveStart() { Time.timeScale = GameManager.Instance.timeScale; if (0 == citadel.GetActiveUnitCount()) { uiMessageBox.message = "마법사를 먼저 성에 배치 해주세요."; return; } Util.EventSystem.Publish(EventID.WaveStart, null); uiPlayPanel.gameObject.SetActive(true); gameState = GameState.Play; foreach (CitadelParts parts in citadel.citadelParts) { if (null != parts.slot.equippedUnit) { HeroUnit unit = parts.slot.equippedUnit; unit.SetActive(true); } if (null != parts.slot.touch) { parts.slot.SetActive(false); } } Wave wave = new Wave(); waveCoroutine = wave.WaveStart(); StartCoroutine(waveCoroutine); }
public HeroUnit GetHeroCard() { HeroUnit cardToGive = heroCards.First(); heroCards.Remove(cardToGive); return(cardToGive); }
public void Init() { { Transform t = transform.Find("Heros"); for (int i = 0; i < t.childCount; i++) { HeroUnit hero = t.GetChild(i).GetComponent <HeroUnit> (); hero.gameObject.SetActive(false); heros [hero.info.id] = hero; } } { Transform t = transform.Find("Animation/Parts"); citadelParts = new CitadelParts[t.childCount]; for (int i = 0; i < t.childCount; i++) { CitadelParts parts = t.GetChild(i).GetComponent <CitadelParts> (); parts.Init(); parts.gameObject.SetActive(false); citadelParts [parts.slotIndex] = parts; } } boughtUnitCount = 1; }
public void SetUnit(HeroUnit unit) { this.unit = unit; unitIcon.sprite = unit.info.icon; unitName.text = unit.info.name; unitDescription.text = unit.info.description; if (null != unit.activeAttack) { skillIcon.sprite = unit.activeAttack.info.icon; } else { skillIcon.gameObject.SetActive(false); } if (true == unit.equiped) { unitEquip.gameObject.SetActive(true); } else { unitEquip.gameObject.SetActive(false); } unitLevel.text = "Lv." + unit.level.ToString(); if (true == unit.purchased) { unitPrice.text = "구매 완료"; } else { unitPrice.text = unit.info.purchasePrice.ToString() + " G"; } }
public CardMini() { this.InitializeComponent(); Hero = new HeroUnit(); ResourceLoader rl = new ResourceLoader(); StatLine = rl.GetString("CardMiniStatsLine"); }
public void FortifyAction(float mult) { HeroUnit player = GetComponent <HeroUnit> (); player.isFortified = true; player.fortifyMultiplier = +mult; EndTurn(); }
public override void informOfParent(GameObject playerIn) { // cycleTargetLock = true; thePlayer = playerIn; //startTransform = thePlayer.gameObject.GetComponent<Transform>(); myHero = thePlayer.gameObject.GetComponent <HeroUnit>(); toRet = new List <GameObject>(); }
public HeroUnit GenerateHero(UnitStats stats, int rarity, StatType primaryStat, int cost) { HeroUnit hero = Instantiate(heroPrefab); hero.name = StatHelper.MakeName(); hero.rarity = rarity; hero.SetStats(stats); hero.cost = cost; Ability[] abilites = { }; if (primaryStat == StatType.STR) { abilites = strAbilities; } else if (primaryStat == StatType.INT) { abilites = Random.Range(0.0f, 1.0f) > 0.5f ? intDmgAbilities : intSupAbilities; } else if (primaryStat == StatType.DEX) { abilites = dexAbilities; } UnitAbilityController abilityRoot = hero.GetAbilityController(); foreach (Ability abilityPrefab in abilites) { Ability ability = Instantiate(abilityPrefab); ability.transform.parent = abilityRoot.transform; ability.transform.localPosition = Vector3.zero; } abilityRoot.UpdateAbilityList(); abilityRoot.enabled = false; if (abilites == intSupAbilities) { hero.targettingAlignment = TargettingAlignment.Friendly; } UnitMovementController movementController; if (abilites == strAbilities) { movementController = hero.gameObject.AddComponent <MeleeUnitMovementController>(); } else { movementController = hero.gameObject.AddComponent <RangedUnitMovementController>(); } movementController.Disable(); int seatIndex = Random.Range(0, seats.Count); Transform seat = seats[seatIndex]; seats.RemoveAt(seatIndex); hero.transform.position = seat.position; heroList.AddHero(hero); return(hero); }
public void AddHero(HeroUnit hero) { HeroInfo info = Instantiate(infoPrefab); info.InParty = isPartyList; info.SetHero(hero); info.transform.SetParent(transform, false); heroInfoMap.Add(hero, info); }
public void RemoveHero(HeroUnit hero) { if (heroInfoMap.ContainsKey(hero)) { HeroInfo info = heroInfoMap[hero]; heroInfoMap.Remove(hero); Destroy(info.gameObject); } }
/// <summary> /// 有行为树,会攻击,会寻路的AI /// </summary> public BattleUnit AddOneEnemyUnit() { BattleProperty property = new BattleProperty(npcPropertyTable.Instance.GetTableItem(102)); HeroUnit unit = new HeroUnit(GetUniqueID(), BattleCamp.ENEMY, property); unit.enemyCamp = BattleCamp.FRIENDLY; m_UnitMgr.AddUnit(unit); return(unit); }
public void WaveEnd(WaveResult result) { Time.timeScale = 1.0f; Util.EventSystem.Publish(EventID.WaveEnd, null); uiPlayPanel.gameObject.SetActive(false); gameState = GameState.Ready; if (WaveResult.Win == result) { waveLevel += 1; } else { enemyManager.Clear(); } uiResultPanel.Active(result); if (null != waveCoroutine) { StopCoroutine(waveCoroutine); } foreach (CitadelParts parts in citadel.citadelParts) { if (null != parts.slot.equippedUnit) { HeroUnit unit = parts.slot.equippedUnit; unit.Init(); unit.SetActive(false); } if (null != parts.slot.touch) { parts.slot.SetActive(true); } } uiWaveProgress.transform.Find("Text").GetComponent <Text> ().text = "WAVE " + waveLevel; uiWaveProgress.progress = 1.0f; while (0 < enemyManager.transform.childCount) { Transform child = enemyManager.transform.GetChild(0); child.SetParent(null); Object.Destroy(child.gameObject); } while (0 < creatures.childCount) { Transform child = creatures.GetChild(0); child.SetParent(null); Object.Destroy(child.gameObject); } citadel.Reset(); Save(); }
public void OnEndMove(object[] all_params) { int unit_id = (int)all_params[0]; HeroUnit unit = GetHeroUnit(unit_id); if (unit != null) { unit.is_move = false; unit.PlayIdle(); } }
public void OnStartMove(object[] all_params) { int unit_id = (int)all_params[0]; HeroUnit unit = GetHeroUnit(unit_id); if (unit != null) { unit.is_move = true; unit.PlayMove(); } }
public void ShowActionButtons( BaseUnit.UnitType unitType, HeroUnit.ActionSpell actionSpell ) { switch ( unitType ) { case BaseUnit.UnitType.hero: cuiv.AddHeroActionButton( actionSpell ); break; default: cuiv.HideActionButton(); break; } }
public void RemoveMember(HeroUnit hero) { if (party.Contains(hero)) { party.Remove(hero); } if (hero.gameObject.scene != SceneManager.GetActiveScene()) { SceneManager.MoveGameObjectToScene(hero.gameObject, SceneManager.GetActiveScene()); } }
public void Load() { Debug.Log("persistent data path:" + Application.persistentDataPath); if (false == File.Exists(Application.persistentDataPath + "/playerdata.dat")) { return; } BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/playerdata.dat", FileMode.Open); SaveData data = (SaveData)bf.Deserialize(file); gold = data.gold; citadel.level = data.citadelLevel; if (data.version == SAVE_FORMAT_VERSION) { waveLevel = data.waveLevel; foreach (var itr in data.heros) { HeroUnit.SaveData saveData = itr.Value; HeroUnit hero = citadel.heros [saveData.id]; hero.level = saveData.level; hero.purchased = saveData.purchased; hero.slotIndex = saveData.slotIndex; hero.equiped = saveData.equiped; if (true == hero.equiped) { citadel.citadelParts [hero.slotIndex].slot.EquipUnit(hero); } } if (null != data.citadelParts) { for (int i = 0; i < citadel.citadelParts.Length; i++) { if (null == data.citadelParts [i]) { continue; } if (true == data.citadelParts [i].active) { citadel.citadelParts [i].gameObject.SetActive(true); } } } for (int i = 0; i < data.citadelBuffs.Length; i++) { CitadelBuff buff = citadel.citadelBuffs [i]; buff.level = data.citadelBuffs [i].level; } } file.Close(); }
public IActionResult UpdateHero(HeroUnit model) { if (ModelState.IsValid) { _heroService.UpdateModel(model); return(Ok(model)); } return(BadRequest(ModelState)); }
public void Start() { buttonBuy.onClick.AddListener(() => { if (null == GameManager.Instance.selectedUnit) { return; } HeroUnit unit = GameManager.Instance.selectedUnit; if (GameManager.Instance.gold < unit.info.purchasePrice) { GameManager.Instance.uiMessageBox.message = "골드가 부족 합니다"; return; } GameManager.Instance.gold -= unit.info.purchasePrice; unit.purchased = true; GameManager.Instance.selectedSlot.EquipUnit(unit); GameManager.Instance.selectedSlot = null; GameManager.Instance.selectedUnit = null; GameManager.Instance.uiHeroInfoPanel.gameObject.SetActive(false); GameManager.Instance.uiHeroShopPanel.gameObject.SetActive(false); GameManager.Instance.Save(); }); buttonEquip.onClick.AddListener(() => { if (null == GameManager.Instance.selectedUnit) { return; } HeroUnit unit = GameManager.Instance.selectedUnit; GameManager.Instance.selectedSlot.EquipUnit(unit); GameManager.Instance.selectedUnit = null; GameManager.Instance.selectedSlot = null; GameManager.Instance.uiHeroInfoPanel.gameObject.SetActive(false); GameManager.Instance.uiHeroShopPanel.gameObject.SetActive(false); GameManager.Instance.Save(); }); buttonLevelup.onClick.AddListener(() => { if (null == GameManager.Instance.selectedUnit) { return; } HeroUnit unit = GameManager.Instance.selectedUnit; unit.Upgrade(); Init(); contentHeroShop.SetUnit(unit); GameManager.Instance.Save(); }); }
public BLUnitHero CreateHeroUnit(int unit_id, string gds_name, BLIntVector3 pos, int team_id) { GDSKit.unit unit_gds = GDSKit.unit.GetInstance(gds_name); BLUnitHero hero_unit = new BLUnitHero(); // 属性相关设置 hero_unit.gds_name = gds_name; hero_unit.unit_type = UnitType.Hero; hero_unit.unit_id = unit_id; hero_unit.revive_cool_down = unit_gds.revive_cd; hero_unit.move_speed = unit_gds.move_speed; hero_unit.attack_range = unit_gds.attack_range; hero_unit.vision = unit_gds.attack_vision; hero_unit.attack_speed = unit_gds.attack_speed; hero_unit.attack_power = unit_gds.unit_attack; hero_unit.hp = unit_gds.unit_hp; hero_unit.max_hp = unit_gds.unit_hp; hero_unit.is_move_attack = unit_gds.is_move_attack; hero_unit.is_fly = unit_gds.is_fly; hero_unit.can_attack_fly = unit_gds.can_attack_fly; hero_unit.can_attack_ground = unit_gds.can_attack_ground; hero_unit.can_pursue = unit_gds.can_pursue; hero_unit.aoe_radius = unit_gds.aoe_radius; hero_unit.bullet_speed = unit_gds.bullet_speed; hero_unit.position = pos; hero_unit.team_id = team_id; if (all_unit_list.ContainsKey(hero_unit.unit_id)) { Debug.LogError("相同名字的unit已经在管理器里了 id : " + hero_unit.unit_id); return(null); } all_unit_list.Add(hero_unit.unit_id, hero_unit); hero_unit_list.Add(hero_unit.unit_id, hero_unit); hero_unit.OnInit(); // 表现层 HeroUnit unit_renderer = UnitManager.Instance().CreateHeroUnit(hero_unit.gds_name, hero_unit.unit_id, hero_unit.position.Vector3Value()); // 表现层需要显示迷雾,攻击范围,所以需要这些数据 unit_renderer.attack_vision = hero_unit.vision * 0.001f; unit_renderer.team_id = hero_unit.team_id; unit_renderer.attack_range = (hero_unit.attack_range * 0.001f); unit_renderer.OnInit(); return(hero_unit); }
public void UnequipUnit() { if (null == equippedUnit) { return; } equippedUnit.equiped = false; equippedUnit.gameObject.SetActive(false); equippedUnit = null; GetComponent <SpriteRenderer> ().enabled = true; }
public override void Init() { foreach (var itr in GameManager.Instance.citadel.heros) { HeroUnit unit = itr.Value; if (null != unit.activeAttack) { unit.activeAttack.manaBuff -= this.Buff; unit.activeAttack.manaBuff += this.Buff; } } }
public void SetHero(HeroUnit hero) { this.hero = hero; nameText.text = hero.name; if (!InParty) { buttonText.text = "Hire (" + hero.cost + " Gold)"; } else { buttonText.text = "Remove from party"; } if (!InParty && hero.cost > PartyManager.it.GetGold()) { actionButton.interactable = false; } levelText.text = "Rarity " + hero.rarity; UnitStats stats = hero.GetStats(); strStatImage.transform.localScale = new Vector3(stats.strength / 25.0f, 1.0f, 1.0f); intStatImage.transform.localScale = new Vector3(stats.intelligence / 25.0f, 1.0f, 1.0f); dexStatImage.transform.localScale = new Vector3(stats.dexterity / 25.0f, 1.0f, 1.0f); switch (stats.GetPrimaryStat()) { case StatType.STR: GetComponent <Image>().sprite = strPanel; break; case StatType.INT: GetComponent <Image>().sprite = intPanel; break; case StatType.DEX: GetComponent <Image>().sprite = dexPanel; break; } Ability[] abilities = hero.GetAbilityController().GetAbilities(); foreach (Ability ability in abilities) { GameObject o = new GameObject(); Text text = o.AddComponent <Text>(); text.text = ability.name; text.resizeTextForBestFit = true; text.font = font; text.alignment = TextAnchor.MiddleCenter; o.transform.SetParent(abilitiesList, false); } }
public void AddHeroActionButton( HeroUnit.ActionSpell actionSpell ) { //FIXME add buttons for each spells actionButtonCounter = 0; actionButtonArray[actionButtonCounter].SetActive( true ); actionButtonArray[actionButtonCounter].GetComponent<Image>().sprite = uiViewPresenter.iceBoltIcon; if ( !actionSpell.spells[0].cd ) actionButtonArray[actionButtonCounter].GetComponent<Image>().color = Color.white; actionButtonArray[actionButtonCounter].GetComponent<Button>().onClick.RemoveAllListeners(); actionButtonArray[actionButtonCounter].GetComponent<Button>().onClick.AddListener( () => { int idx = 0; if (!actionSpell.spells[idx].cd ) { cursorAction( InputController.CursorsType.TargetSpell ); Action<UnitViewPresenter> currentTargetSpell = x => { actionSpell.targetSpell( actionSpell.spells[idx], x ); cursorAction( InputController.CursorsType.Simple ); actionButtonArray[idx].GetComponent<Image>().color = Color.gray; }; this.currentTargetSpell( currentTargetSpell ); } }); ++actionButtonCounter; actionButtonArray[actionButtonCounter].SetActive( true ); actionButtonArray[actionButtonCounter].GetComponent<Image>().sprite = uiViewPresenter.meteorShawerIcon; if ( !actionSpell.spells[1].cd ) actionButtonArray[actionButtonCounter].GetComponent<Image>().color = Color.white; actionButtonArray[actionButtonCounter].GetComponent<Button>().onClick.RemoveAllListeners(); actionButtonArray[actionButtonCounter].GetComponent<Button>().onClick.AddListener( () => { int idx = 1; if ( !actionSpell.spells[idx].cd ) { cursorAction( InputController.CursorsType.PositionSpell ); Action<Vector3> currentPositionSpell = x => { actionSpell.positionSpell( actionSpell.spells[idx], x ); cursorAction( InputController.CursorsType.Simple ); actionButtonArray[idx].GetComponent<Image>().color = Color.gray; }; this.currentPositionSpell( currentPositionSpell ); } } ); ++actionButtonCounter; actionButtonArray[actionButtonCounter].SetActive( true ); actionButtonArray[actionButtonCounter].GetComponent<Image>().sprite = uiViewPresenter.levelUpIcon; ++actionButtonCounter; }
public void OnPlayAttack(object[] all_params) { int unit_id = (int)all_params[0]; int target_unit_id = (int)all_params[1]; HeroUnit unit = GetHeroUnit(unit_id); BaseUnit target = GetUnit(target_unit_id); if (unit != null && target != null) { unit.PlayAttack(target); } }
// Use this for initialization void Awake() { source = GetComponent<AudioSource> (); GameObject hero = (GameObject)Instantiate (heroObject, new Vector2 (0, 0), Quaternion.identity); hero.transform.SetParent (transform); frontHero = hero.GetComponent<HeroUnit> (); Core.getInstance ().heroLine ().Add (frontHero); Core.getInstance ().setCurrentHeadHero (frontHero); Core.getInstance ().getCurrentHead ().setHead (true); Core.getInstance ().getCurrentHead ().isGet = true; Core.getInstance ().getCurrentHead ().addHp (20); delay = 0.3f; }
public int GetActiveUnitCount() { int count = 0; foreach (var v in heros) { HeroUnit unit = v.Value; if (true == unit.equiped) { count++; } } return(count); }
public override void informOfParent(GameObject playerIn) { // Debug.Log("I am basic attack and I think I am attached to : "+ playerIn.name); thePlayer = playerIn; myHero = thePlayer.GetComponent <HeroUnit>(); startTransform = thePlayer.GetComponent <Transform>(); damageSteps = new int[3]; toRet = new List <GameObject>(); // myHero = (HeroUnit)gameObject.GetComponentInParent(typeof (HeroUnit)); //Debug.Log("111Basic attack thinks it is attached to unti: " +myHero.gameObject.name); attackDamageScaler = 2; hasASpellAnimation = false; }
public void Init() { HeroUnit unit = GameManager.Instance.selectedUnit; if (null == unit) { return; } unit.Init(); textName.text = unit.info.name; imageUnit.sprite = unit.info.icon; textLevel.text = unit.level.ToString(); textAttackPower.gameObject.SetActive(false); textAttackSpeed.gameObject.SetActive(false); textCritical.gameObject.SetActive(false); imageUnit.gameObject.SetActive(true); textAttackPower.gameObject.SetActive(true); textAttackSpeed.gameObject.SetActive(true); textCritical.gameObject.SetActive(true); textAttackPower.text = (Mathf.Round(unit.passiveAttack.data.power * 10.0f) * 0.1f).ToString(); textAttackSpeed.text = (Mathf.Round(unit.passiveAttack.data.speed * 10.0f) * 0.1f).ToString(); passiveSkill.Init(unit.passiveAttack); activeSkill.Init(unit.activeAttack); int upgradeGold = unit.info.upgradePrice * unit.level; buttonLevelup.transform.Find("Text").GetComponent <Text> ().text = "Upgrade\n<size=10>(" + upgradeGold.ToString() + " G)</size>"; buttonBuy.gameObject.SetActive(false); buttonBuy.transform.Find("Text").GetComponent <Text> ().text = "Buy\n<size=10>(" + unit.info.purchasePrice.ToString() + " G)</size>"; buttonEquip.gameObject.SetActive(false); buttonLevelup.gameObject.SetActive(false); if (true == unit.purchased) { buttonLevelup.gameObject.SetActive(true); } else { buttonBuy.gameObject.SetActive(true); } if (true == unit.purchased && (unit.slotIndex != GameManager.Instance.selectedSlot.slotIndex || false == unit.equiped)) { buttonEquip.gameObject.SetActive(true); } }
public HeroUnit AddHeroUnit(string hero_key) { HeroUnitBuilder hero_unit_builder = new HeroUnitBuilder(); UnitDirector director = new UnitDirector(hero_unit_builder); director.Construct(hero_key); HeroUnit unit = hero_unit_builder.GetResult(); g_hero_list.Add(unit); Debug.Log("add_hero:" + unit.unit_name + ",hp:" + unit.max.hp); if (updateHeroUnitList != null) { updateHeroUnitList(); } return(unit); }
public void Save() { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(Application.persistentDataPath + "/playerdata.dat"); SaveData data = new SaveData(); data.version = SAVE_FORMAT_VERSION; data.gold = gold; data.waveLevel = waveLevel; data.citadelLevel = citadel.level; data.heros = new Dictionary <string, HeroUnit.SaveData> (); foreach (var itr in citadel.heros) { HeroUnit hero = itr.Value; if (false == hero.purchased) { continue; } HeroUnit.SaveData saveData = new HeroUnit.SaveData(); saveData.id = hero.info.id; saveData.level = hero.level; saveData.purchased = hero.purchased; saveData.slotIndex = hero.slotIndex; saveData.equiped = hero.equiped; data.heros [hero.info.id] = saveData; } data.citadelParts = new CitadelParts.SaveData[citadel.citadelParts.Length]; for (int i = 0; i < citadel.citadelParts.Length; i++) { CitadelParts.SaveData saveData = new CitadelParts.SaveData(); saveData.active = citadel.citadelParts [i].gameObject.activeSelf; data.citadelParts [i] = saveData; } data.citadelBuffs = new CitadelBuff.SaveData[citadel.citadelBuffs.Length]; for (int i = 0; i < citadel.citadelBuffs.Length; i++) { CitadelBuff.SaveData saveData = new CitadelBuff.SaveData(); saveData.level = citadel.citadelBuffs [i].level; data.citadelBuffs [i] = saveData; } bf.Serialize(file, data); file.Close(); }
void Init() { while (0 < content.childCount) { Transform child = content.GetChild(0); child.SetParent(null); Object.Destroy(child.gameObject); } foreach (var itr in GameManager.Instance.citadel.heros) { HeroUnit unit = itr.Value; ContentHeroShop contentHeroShop = GameObject.Instantiate <ContentHeroShop>(contentPrefab); contentHeroShop.SetUnit(unit); contentHeroShop.transform.SetParent(content); contentHeroShop.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); } }
public HeroUnitController( EntityController.Select entityControllerSelect, HeroViewPresentor unitViewPresenter, BaseUnit.UnitCharacteristics unitCharacteristics, EntityController.GetTarget getTarget, EntityController.Faction faction, DeathDestroy updateDeath, EntityController.HeroResurrect heroResurrect, BaraksModel.SetUpdeteCharacteristicsDelegate setUpdeteCharacteristicsDelegate ) : base(entityControllerSelect, unitViewPresenter, unitCharacteristics, getTarget, faction, updateDeath, setUpdeteCharacteristicsDelegate) { this.updateDeath = updateDeath; EffectsController effectsController = new EffectsController(); this.heroResurrect = heroResurrect; unitBehaviour.CallDeathFSMEvent(); unitBehaviour = new HeroBehaviour( getTarget, faction, unitViewPresenter, animationController ); unitModel = new HeroUnit( "Unit", unitCharacteristics, SpellInit( effectsController ), faction, effectsController, _UpdateCharacteristics, UpdateDeath, LevelUpEffect, setUpdeteCharacteristicsDelegate, DeleteVisualEffect ); unitView = new HeroView( unitViewPresenter, Selected, GetDamage, ((HeroUnit)unitModel).GetXp ); }
public void setCurrentHeadHero(HeroUnit hero) { currentHead = hero; }
// When head hero die, rearrange the line private void losingHero() { source.PlayOneShot (loseSound); Core.getInstance ().setTempPosition (((HeroUnit)Core.getInstance ().heroLine () [0]).transform.position); Core.getInstance ().setTempDirection (((HeroUnit)Core.getInstance ().heroLine () [0]).getFlipDirection ()); Debug.Log ("crash"); Core.getInstance ().getCurrentHead ().addHp (-100); Core.getInstance ().heroLine ().RemoveAt (0); if (Core.getInstance ().heroLine ().Count == 0) { Core.gameEnd = true; Core.anotherRound = true; } else { frontHero = ((HeroUnit)Core.getInstance ().heroLine () [0]); heroSize = frontHero.GetComponent<RectTransform> (); Debug.Log (frontHero.name); Core.getInstance ().setCurrentHeadHero (frontHero); Core.getInstance ().getCurrentHead ().setHead (true); Core.getInstance ().getCurrentHead ().setDirection (currentDirection); //setMove (currentDirection); if (Core.heroCrash) Core.heroCrash = false; else { for (int j = 0; j < Core.getInstance().heroLine().Count; j++) { Vector3 otherTemp = ((HeroUnit)Core.getInstance ().heroLine () [j]).transform.position; string dirTemp = ((HeroUnit)Core.getInstance ().heroLine () [j]).getFlipDirection (); ((HeroUnit)Core.getInstance ().heroLine () [j]).transform.position = Core.getInstance ().getTempPosition (); ((HeroUnit)Core.getInstance ().heroLine () [j]).flip (Core.getInstance ().getTempDirection ()); Core.getInstance ().setTempPosition (otherTemp); Core.getInstance ().setTempDirection (dirTemp); } } } }
// Update is called once per frame void FixedUpdate() { if (Core.gameStart && !Core.gameEnd) { if (Core.gameRestart) { if (Core.anotherRound) { for (int i =0; i < GetComponentsInChildren<UnitProfile>().Length; i++) Destroy (GetComponentsInChildren <UnitProfile> () [i].gameObject); Awake (); } Core.gameRestart = false; nextUsage = Time.time + delay; heroSize = frontHero.GetComponent<RectTransform> (); nextAttack = 0; nextChange = 0; moveX = 0; moveY = - heroSize.rect.height * heroSize.localScale.y; currentDirection = "down"; setMove (currentDirection); for (int i = 0; i < 2; i++) { spawnUnits (); } for (int i =0; i < GetComponentsInChildren<UnitProfile>().Length; i++) { Debug.Log (GetComponentsInChildren <UnitProfile> () [i].name); } } // change character from button z or x if (!Core.getInstance ().isFight () && Time.time > nextChange) { // switching from front to endline if (Input.GetKeyUp ("x")) { source.PlayOneShot (swapSound); //nextChange = Time.time + delayChange; Debug.Log (((HeroUnit)Core.getInstance ().heroLine () [0]).name); // first, set tmp direction and position Core.getInstance ().setTempPosition (((HeroUnit)Core.getInstance ().heroLine () [0]).transform.position); Core.getInstance ().setTempDirection (((HeroUnit)Core.getInstance ().heroLine () [0]).getFlipDirection ()); // set the current head to false frontHero.setHead (false); frontHero.enabled = false; // and move up the line from character 2 up ahead for (int j = 1; j < Core.getInstance().heroLine().Count; j++) { Vector3 otherTemp = ((HeroUnit)Core.getInstance ().heroLine () [j]).transform.position; string dirTemp = ((HeroUnit)Core.getInstance ().heroLine () [j]).getFlipDirection (); ((HeroUnit)Core.getInstance ().heroLine () [j]).transform.position = Core.getInstance ().getTempPosition (); ((HeroUnit)Core.getInstance ().heroLine () [j]).flip (Core.getInstance ().getTempDirection ()); Core.getInstance ().setTempPosition (otherTemp); Core.getInstance ().setTempDirection (dirTemp); } // then move the first hero to the last of the line ((HeroUnit)Core.getInstance ().heroLine () [0]).transform.position = Core.getInstance ().getTempPosition (); ((HeroUnit)Core.getInstance ().heroLine () [0]).flip (Core.getInstance ().getTempDirection ()); // now swap the array and set the rest Core.getInstance ().heroLine ().RemoveAt (0); Core.getInstance ().heroLine ().Add (frontHero); frontHero.enabled = true; frontHero = ((HeroUnit)Core.getInstance ().heroLine () [0]); Debug.Log (((HeroUnit)Core.getInstance ().heroLine () [0]).name); heroSize = frontHero.GetComponent<RectTransform> (); Core.getInstance ().setCurrentHeadHero (frontHero); Core.getInstance ().getCurrentHead ().setHead (true); Core.getInstance ().getCurrentHead ().setDirection (currentDirection); // switching from end to frontline } else if (Input.GetKeyUp ("z")) { source.PlayOneShot (swapSound); //nextChange = Time.time + delayChange; // first, set tmp direction and position Core.getInstance ().setTempPosition (((HeroUnit)Core.getInstance ().heroLine () [Core.getInstance ().heroLine ().Count - 1]).transform.position); Core.getInstance ().setTempDirection (((HeroUnit)Core.getInstance ().heroLine () [Core.getInstance ().heroLine ().Count - 1]).getFlipDirection ()); // set the current head to false frontHero.setHead (false); frontHero = (HeroUnit)Core.getInstance ().heroLine () [Core.getInstance ().heroLine ().Count - 1]; frontHero.enabled = false; Vector3 otherTemp; string dirTemp; // and move back the line from hero before last to the last for (int j = Core.getInstance().heroLine().Count-2; j >= 0; j--) { otherTemp = ((HeroUnit)Core.getInstance ().heroLine () [j]).transform.position; dirTemp = ((HeroUnit)Core.getInstance ().heroLine () [j]).getFlipDirection (); ((HeroUnit)Core.getInstance ().heroLine () [j]).transform.position = Core.getInstance ().getTempPosition (); ((HeroUnit)Core.getInstance ().heroLine () [j]).flip (Core.getInstance ().getTempDirection ()); Core.getInstance ().setTempPosition (otherTemp); Core.getInstance ().setTempDirection (dirTemp); } // then move the last hero to the front of the line otherTemp = ((HeroUnit)Core.getInstance ().heroLine () [Core.getInstance ().heroLine ().Count - 1]).transform.position; dirTemp = ((HeroUnit)Core.getInstance ().heroLine () [Core.getInstance ().heroLine ().Count - 1]).getFlipDirection (); ((HeroUnit)Core.getInstance ().heroLine () [Core.getInstance ().heroLine ().Count - 1]).transform.position = Core.getInstance ().getTempPosition (); ((HeroUnit)Core.getInstance ().heroLine () [Core.getInstance ().heroLine ().Count - 1]).flip (Core.getInstance ().getTempDirection ()); Core.getInstance ().setTempPosition (otherTemp); Core.getInstance ().setTempDirection (dirTemp); // now swap the array Core.getInstance ().heroLine ().RemoveAt (Core.getInstance ().heroLine ().Count - 1); Core.getInstance ().heroLine ().Insert (0, frontHero); frontHero.enabled = true; heroSize = frontHero.GetComponent<RectTransform> (); Core.getInstance ().setCurrentHeadHero (frontHero); Core.getInstance ().getCurrentHead ().setHead (true); Core.getInstance ().getCurrentHead ().setDirection (currentDirection); } } if (!isClicked) { if (Input.GetKey ("up") && !onDown) { moveX = 0; moveY = heroSize.rect.height * heroSize.localScale.y; isClicked = true; if ((onRight || onLeft) && isNearbyWallUp) setMove (currentDirection); else { currentDirection = "up"; setMove (currentDirection); } } else if (Input.GetKey ("down") && !onUp) { moveX = 0; moveY = - heroSize.rect.height * heroSize.localScale.y; isClicked = true; if ((onRight || onLeft) && isNearbyWallDown) setMove (currentDirection); else { currentDirection = "down"; setMove (currentDirection); } } else if (Input.GetKey ("left") && !onRight) { moveX = - heroSize.rect.width * heroSize.localScale.x; moveY = 0; isClicked = true; if ((onUp || onDown) && isNearbyWallLeft) setMove (currentDirection); else { currentDirection = "left"; setMove (currentDirection); } } else if (Input.GetKey ("right") && !onLeft) { moveX = heroSize.rect.width * heroSize.localScale.x; moveY = 0; isClicked = true; if ((onUp || onDown) && isNearbyWallRight) setMove (currentDirection); else { currentDirection = "right"; setMove (currentDirection); } } } if (Core.heroCrash) { losingHero (); nextUsage = Time.time + delay; } // check if is battle if (Core.getInstance ().isFight () && Time.time > nextAttack) { //check if still on fight if (Core.getInstance ().getCurrentHead () != null && !Core.getInstance ().heroWin () && !Core.getInstance ().enemyWin ()) { source.PlayOneShot (atkSound); nextAttack = Time.time + delayAttack; Core.getInstance ().getFight (); Debug.Log ("fight"); } //check if hero death in each time if (Core.getInstance ().enemyWin ()) { source.PlayOneShot (loseSound); Core.getInstance ().getCurrentEnemy ().setDirection ("none"); Core.getInstance ().setTempPosition (((HeroUnit)Core.getInstance ().heroLine () [0]).transform.position); Core.getInstance ().setTempDirection (((HeroUnit)Core.getInstance ().heroLine () [0]).getFlipDirection ()); Core.getInstance ().heroLine ().RemoveAt (0); if (Core.getInstance ().heroLine ().Count == 0) { Core.getInstance ().setActive (false); Core.gameEnd = true; Core.anotherRound = true; } else { frontHero = ((HeroUnit)Core.getInstance ().heroLine () [0]); heroSize = frontHero.GetComponent<RectTransform> (); Debug.Log (frontHero.name); Core.getInstance ().setCurrentHeadHero (frontHero); for (int j = 0; j < Core.getInstance().heroLine().Count; j++) { Debug.Log ("count" + Core.getInstance ().heroLine ().Count); Vector3 otherTemp = ((HeroUnit)Core.getInstance ().heroLine () [j]).transform.position; string dirTemp = ((HeroUnit)Core.getInstance ().heroLine () [j]).getFlipDirection (); ((HeroUnit)Core.getInstance ().heroLine () [j]).transform.position = Core.getInstance ().getTempPosition (); ((HeroUnit)Core.getInstance ().heroLine () [j]).flip (Core.getInstance ().getTempDirection ()); Core.getInstance ().setTempPosition (otherTemp); Core.getInstance ().setTempDirection (dirTemp); } Core.getInstance ().getCurrentHead ().setHead (true); Core.getInstance ().getCurrentHead ().setDirection (currentDirection); //setMove (currentDirection); //Core.getInstance ().setHeroDirection (currentDirection); Core.getInstance ().getCurrentEnemy ().setDirection (Core.getInstance ().getCurrentEnemy ().getTempEnemyStatus ()); } Debug.Log ("enemy win"); } else if (Core.getInstance ().heroWin ()) { source.PlayOneShot (winSound); Core.getInstance ().setActive (false); Core.getInstance ().getCurrentEnemy ().setDirection ("death"); Core.getInstance ().removeCurrentEnemy (currentDirection); moveX = tmpX; moveY = tmpY; Debug.Log ("hero win"); for (int i = 0; i < Core.getInstance().heroLine().Count; i++) { Core.getInstance ().addScore (((HeroUnit)Core.getInstance ().heroLine () [i]).getHp ()); } spawnUnits (); if (delay > 0.05) delay -= 0.01f; } } // While walking if (!Core.getInstance ().isFight () && Time.time > nextUsage && !Core.gameEnd) { source.PlayOneShot (walkSound); for (int i = 0; i < Core.getInstance().heroLine().Count; i++) { //if on first hero if (i == 0) { Core.getInstance ().getCurrentHead ().flip (currentDirection); Core.getInstance ().setTempPosition (((HeroUnit)Core.getInstance ().heroLine () [i]).transform.position); Core.getInstance ().setTempDirection (((HeroUnit)Core.getInstance ().heroLine () [i]).getFlipDirection ()); if (Core.getInstance ().getToEnemy (currentDirection)) { tmpX = moveX; tmpY = moveY; moveX = 0; moveY = 0; Core.getInstance ().setHeroDirection (currentDirection); Core.getInstance ().setActive (true); break; } else { isClicked = false; } frontHero.transform.position = new Vector3 ( Mathf.Clamp (frontHero.transform.position.x + moveX, -5.04f, 5.04f), Mathf.Clamp (frontHero.transform.position.y + moveY, -3.6f, 3.6f), frontHero.transform.position.z); nextUsage = Time.time + delay; if (isCrash ()) { losingHero (); break; //Core.getInstance ().heroLine ().re } } else { Vector3 otherTemp = ((HeroUnit)Core.getInstance ().heroLine () [i]).transform.position; string dirTemp = ((HeroUnit)Core.getInstance ().heroLine () [i]).getFlipDirection (); ((HeroUnit)Core.getInstance ().heroLine () [i]).transform.position = Core.getInstance ().getTempPosition (); ((HeroUnit)Core.getInstance ().heroLine () [i]).flip (Core.getInstance ().getTempDirection ()); Core.getInstance ().setTempPosition (otherTemp); Core.getInstance ().setTempDirection (dirTemp); } } } //Debug.Log("x : "+ (frontHero.transform.position.x + moveX) + " y : "+ (frontHero.transform.position.y + moveY)); } }
public void AddXpDelegate( HeroUnit.GetXpDelegate GetXpDelegate ) { this.GetXpDelegate = GetXpDelegate; }
public HeroView( HeroViewPresentor unitViewPresenter, BaseUnitController.SelectUnit selectUnit, BaseUnit.DamageDelegate damageDelegate, HeroUnit.GetXpDelegate GetXpDelegate ) : base(unitViewPresenter, selectUnit, damageDelegate) { unitViewPresenter.AddXpDelegate( GetXpDelegate ); }