public void CycleMode() { TS = upgradeUI.troop.GetComponent <TroopScript>(); if (index == 0) { TS.ChangeAttackMode(TroopScript.AttackMode.Closest); txt_Mode.text = "Closest"; index++; } else if (index == 1) { TS.ChangeAttackMode(TroopScript.AttackMode.Strongest); txt_Mode.text = "Strongest"; index++; } else if (index == 2) { TS.ChangeAttackMode(TroopScript.AttackMode.First); txt_Mode.text = "First"; index = 0; } }
//Calculate archer damage function //Tank ability public IEnumerator TankAbility() { var tankScript = tank.GetComponent <TroopScript>(); tankScript.tileScript.PlaySmokeParticles(); enemyTroopScript.tileScript.PlaySmokeParticles(); yield return(new WaitForSeconds(1f)); //Store the enemy tank and the target troop positions Vector3 TankPos = new Vector3(tank.transform.position.x, enemySelectedTroop.transform.position.y, tank.transform.position.z); Vector3 TargetPos = new Vector3(enemySelectedTroop.transform.position.x, tank.transform.position.y, enemySelectedTroop.transform.position.z); //Swap the positions of the tank and the target troop tank.transform.position = TargetPos; enemySelectedTroop.transform.position = TankPos; tankScript.ReCallStartPos(); enemyTroopScript.ReCallStartPos(); //Set tank as new target troop and get its script enemySelectedTroop = tank.gameObject; enemyTroopScript = enemySelectedTroop.GetComponent <TroopScript>(); //Calculate damage and chance phase CalculateDamage(); awaitingInput = false; //gameManager.ChangePhase(); }
public static void Assassinate(TroopScript Assassin, TroopScript Victim) { int AssassinChance = Mathf.RoundToInt(((float)Assassin.GetEnergy()/(float)Assassin.GetMaxEnergy())*900+((float)Assassin.GetNumber()/(float)Assassin.GetmaxNumber())*100); int VictimChance = Mathf.RoundToInt(((float)Victim.GetEnergy()/(float)Victim.GetMaxEnergy())*100+((float)Victim.GetNumber()/(float)Victim.GetmaxNumber())*900); if (AssassinChance>VictimChance && Victim.boss == false) Victim.SetNumber(0); }
static void SetTroopBaseStatistics (TroopScript troop,int baseAtk, int baseDef, int baseHitPoints, int baseSpeed, int People, int baseMovement, int BaseRange){ troop.SetBaseAttack(baseAtk); troop.SetBaseDefence(baseDef); troop.SetBaseHitpoints(baseHitPoints); troop.SetBaseSpeed (baseSpeed); troop.SetNumber(People); troop.SetBaseMovement(baseMovement); troop.SetBaseRange(BaseRange); }
public void AimAndShootEffect(TroopScript Caster, TroopScript Target) { NewFightScript.MeleeFightingScript(Caster,Target,Skill.FromListOfSkills(muhSkills.AimAndShoot)); GameManager.instance.playerTurns[GameManager.instance.PlayerTurnIndex].SetPreparation(muhSkills.NoSkill); GameManager.instance.playerTurns[GameManager.instance.PlayerTurnIndex].SetPreparationTargetPlayer(null); GameManager.instance.playerTurns[GameManager.instance.PlayerTurnIndex].SetPreparationTargetTile(null); Caster.SkillRecoveryTime = Skill.FromListOfSkills(muhSkills.AimAndShoot).SkillRecoveryTime; //all the animations and shit }
public void SetTroopStats() { TroopScript ts = troop.GetComponent <TroopScript>(); txt_level.text = "Level: " + ts.GetLevel(); txt_damage.text = "Damage: " + ts.GetDamage(); txt_cooldown.text = "Cooldown: " + ts.GetShootCooldown(); txt_view_radius.text = "View Radius: " + ts.GetViewRadius(); txt_upgradecost.text = "Upgrade $" + ts.GetUpgradeCost(); }
// public static void AccurateShotsTargeting (TroopScript Caster, int range){ //// Color highlightColor = new Color(GameManager.ColorAdapter(0),GameManager.ColorAdapter(255),GameManager.ColorAdapter(0),1); //// Color SHIThighlightColor = new Color(GameManager.ColorAdapter(153),GameManager.ColorAdapter(153),GameManager.ColorAdapter(0),1); // List<TroopScript> PeopleToAttack = new List<TroopScript>(); // // // // Vector2 mousePosition = GameManager.instance.MousePosition; // List<Tile> Targetcells = GameManager.instance.AccurateShotsHighlights(Caster.gridPosition,mousePosition,2,Skill.FromListOfSkills); // int cells = Targetcells.Count; // float TotalDamage = (float)5/cells; // // for (int i = 0; i<cells;i++){ // for (int j = 0; j<GameManager.instance.players.Count;j++){ // if (Targetcells[i].gridPosition == GameManager.instance.players[j].gridPosition && GameManager.instance.players[j].Faction != Caster.Faction) // if (!PeopleToAttack.Contains(GameManager.instance.players[j])) // PeopleToAttack.Add(GameManager.instance.players[j]); // } // } // // Debug.Log(PeopleToAttack.Count); // //only if some shit happens and it stops being triggered per frame idk ill see what i can do // AccurateShotAction(Caster,PeopleToAttack,TotalDamage); // // // } public static void AccurateShotAction(TroopScript Caster, List<TroopScript> Targets, float _skillDamage) { int AttackerBattlefieldEffect = 1; //still to impement for (int i = 0;i<Targets.Count;i++){ int kills = CalculateAccurateShotDamage(Caster,Targets[i],_skillDamage,AttackerBattlefieldEffect); Targets[i].SetNumber(Targets[i].GetNumber()-kills); if (Targets[i].GetNumber()<0) Targets[i].SetNumber(0); if (Targets[i].GetPreparation()!=null) Targets[i].CancelPreparation(); if (Targets[i].GetEnergy()>0)Targets[i].SetEnergy(Targets[i].GetEnergy()-1); } }
public void btn_Click() { if (ps.viewDistanceHighlighterScript.safe && ps.statBlock.GetPlacedTroops() < ps.statBlock.GetMaxTroops()) { GameObject obj = Instantiate(ps.troopList[ps.selectedTroopIndex]); TroopScript ts = obj.GetComponent <TroopScript>(); ps.statBlock.AdjustCash(-ts.GetCost()); ps.statBlock.IncrementPlacedTroops(1); obj.transform.position = new Vector3(ps.GetPoint().x, ts.yPosSpawn, ps.GetPoint().z); ps.Placed(); EventSystem.current.GetComponent <EventSystem>().SetSelectedGameObject(null); } }
public void LevelUp() { TroopScript ts = troop.GetComponent <TroopScript>(); long cost = ts.GetUpgradeCost(); Debug.Log(cost); if (stats.GetCash() >= cost && ts.GetLevel() != 69) { stats.AdjustCash(-cost); ts.LevelUp(); } SetTroopStats(); float scale = troop.GetComponent <TroopScript>().GetViewRadius() * 2; viewDistanceHighlighter.transform.localScale = new Vector3(scale, 0.001f, scale); }
//Place pawn function //Revive public void ReviveTroop(GameObject chosenTroop) { pawnSpawnCount = 0; SelectedTroop = chosenTroop; troopScript = SelectedTroop.GetComponent <TroopScript>(); Dragging = true; spawningTroop = true; //UIManager.reviveUI = false; if (SelectedTroop.tag == "Pawn") { if (gameManager.turn == Turn.Red) { gameManager.RedPawns.Add(SelectedTroop); } else if (gameManager.turn == Turn.Blue) { gameManager.BluePawns.Add(SelectedTroop); } } Debug.Log("ReviveTroopFunction"); }
public void CreateIcewall(Vector2 Position, TroopScript MageThatCreatedIt) { ThirdParty iceicebaby = ((GameObject)Instantiate(IcePrefab, new Vector3(Position.x - Mathf.Floor((float)mapSize/2),1.5f, -Position.y + Mathf.Floor((float)mapSize/2)), Quaternion.Euler(new Vector3()))).GetComponent<ThirdParty>(); Chief Proprietary = new Chief(); AddStuffToChief(Proprietary, "Ice", "Wall", Trait.FromTraitList(ListOfTraits.Fearless),Abilities.fromList(ListOfAbilities.StrongLeadership),Abilities.fromList(ListOfAbilities.Popular),Abilities.fromList(ListOfAbilities.Phalanx),0,0,0,0); Debug.Log (Proprietary); int IceHP = MageThatCreatedIt.GetChief().GetIntelligence()*MageThatCreatedIt.GetNumber()/2; //can be changed in the future iceicebaby.SetBaseTurnSpeed(0); AddStuffToPlayer(iceicebaby,2,muhClasses.Ice,Proprietary, 0, 10,100,12,IceHP,Weaponry.FromName(WeaponryName.TestHammer),Armory.FromName(ArmoryName.TestConfortableClothes)); players.Add(iceicebaby); Debug.Log(iceicebaby); iceicebaby.gridPosition = Position; iceicebaby.Summoner = MageThatCreatedIt; // AITroop aiplayer = ((GameObject)Instantiate(AITroopPrefab, new Vector3(6 - Mathf.Floor(mapSize/2),1.5f, -4 + Mathf.Floor(mapSize/2)), Quaternion.Euler(new Vector3()))).GetComponent<AITroop>(); // aiplayer.gridPosition = new Vector2(6,4); // leader = new Chief(); // AddStuffToChief(leader,"another asshole","Obama", Trait.FromTraitList(ListOfTraits.Fearless),Abilities.fromList(ListOfAbilities.StrongLeadership),Abilities.fromList(ListOfAbilities.Popular),Abilities.fromList(ListOfAbilities.Phalanx),2,3,1,3); // // AddStuffToPlayer(aiplayer,1,muhClasses.Animal,leader, 12,2,100,12,100,Weaponry.FromName(WeaponryName.TestHammer),Armory.FromName(ArmoryName.TestConfortableClothes)); // // players.Add(aiplayer); }
static bool CanCounter(TroopScript Attacker, TroopScript Defender, Skill SkillUsedToAttack) { bool ret = false; bool SkillAllows = SkillUsedToAttack.CanCounter; Vector2 AttackerPosition = Attacker.gridPosition; Vector2 DefenderPosition = Defender.gridPosition; int max = Defender.GetCounterMaxRange(); int min = Defender.GetCounterMinRange(); float value = Mathf.Abs(AttackerPosition.x-DefenderPosition.x)+Mathf.Abs(AttackerPosition.y-DefenderPosition.y); if (value > min && value < max && SkillAllows) ret = true; //yadda yadda check distance and skills return ret; }
// Update is called once per frame void Update() { if (initialize == false) { //Get other script componenets drag = GetComponent <DragAndDrop>(); attack = GetComponent <Attack>(); camMove = GetComponent <CameraMovement>(); UIManager = GetComponent <UIController>(); initialize = true; } //Get the number of pawns in the game RedPawnCount = GameObject.FindGameObjectsWithTag("Pawn").Where(x => x.GetComponent <Pawn>().team == Team.Red).Where(x => x.GetComponent <Pawn>().troopState == TroopState.Alive).Count <GameObject>(); BluePawnCount = GameObject.FindGameObjectsWithTag("Pawn").Where(x => x.GetComponent <Pawn>().team == Team.Blue).Where(x => x.GetComponent <Pawn>().troopState == TroopState.Alive).Count <GameObject>(); switch (state) { case (State.TroopPlacement): //Start the game once all the troops have been placed if (BlueTeam.Count == 6) { StartGame(); } break; case (State.Gameplay): //The teams current piece is the count RedCurPiece = RedTeam[RedCount]; if (BlueTeam[BlueCount] != null) { BlueCurPiece = BlueTeam[BlueCount]; } if (resetPawn == true) { StartCoroutine(ResetDeadPawn()); } if (turn == Turn.Red) { troopScript = RedCurPiece.GetComponent <TroopScript>(); } else if (turn == Turn.Blue) { troopScript = BlueCurPiece.GetComponent <TroopScript>(); } //Change phase if middle mouse button is placed if (Input.GetMouseButtonDown(2) && phase != Phase.Checks) { ChangePhase(); } if (AwaitingResponse == true) { //if player presses N key if (UIManager.YesNo == yesno.no) { AwaitingResponse = false; CheckCount++; StartCoroutine(PerformChecks()); UIManager.YesNo = yesno.notSelected; UIManager.HideQuestion(); } //if players presses Y key else if (UIManager.YesNo == yesno.yes) { PauseChecks = true; //pause checks AwaitingResponse = false; //stop waiting for a response UIManager.YesNo = yesno.notSelected; UIManager.HideQuestion(); //this switch method will allow me to easily add new abilities and checks switch (CheckCount) { case (0): //if priest ability Debug.Log("Calling Revive Function"); var priest = SearchList(RedTeam, "Priest"); //find priest UIManager.RevealDeadTroops(); //UIManager.HideQuestion(); break; case (1): Debug.Log("Spawning Pawn"); drag.kingAbility = true; if (turn == Turn.Red) { RedKingAbilityCount = 0; //reset the count drag.spawnedRedPawn = Instantiate(RedPawnPrefab, new Vector3(0, 0.1f, 0), new Quaternion()); //instantiate new gameobject } else if (turn == Turn.Blue) { BlueKingAbilityCount = 0; //reset the count drag.spawnedBluePawn = Instantiate(BluePawnPrefab, new Vector3(0, 0.1f, 0), new Quaternion(0, 1, 0, 0)); //instantiate new gameobject, rotate to face red team } break; default: break; } } } break; default: break; } }
// Update is called once per frame void Update() { if (initialize == false) { gameManager = GetComponent <GameManager>(); UIManager = GetComponent <UIController>(); animController = GetComponent <TroopAnimController>(); board = GameObject.FindGameObjectWithTag("Board").GetComponent <Board>(); initialize = true; } if (gameManager.phase == Phase.Movement) { //if troop not already selected if (Dragging == false && SelectedTroop == null) { if (Input.GetMouseButtonDown(0)) { difX = 0; difY = 0; SelectTroop(); } } //if troop already selected else if (Dragging == true) { //left mouse click if (Input.GetMouseButtonDown(0)) { switch (gameManager.state) { case (State.TroopPlacement): //in the troop placement state //if troop is in the range of the board if ((SelectedTroop.transform.position.x >= board.Minx && SelectedTroop.transform.position.z >= board.Miny) && (SelectedTroop.transform.position.x <= board.Maxx && SelectedTroop.transform.position.z <= board.Maxy)) { //if the troop is a pawn if (SelectedTroop.tag == "Pawn") { PlacePawn(); //call the place pawn function } //if troop is anything else else { gameManager.PlaceTroop(); //call the place troop function } } break; case (State.Gameplay): //in the gameplay state //if player has moved troops position if (difX != 0 || difY != 0) { //if troop is a pawn if (SelectedTroop.tag == "Pawn") { //Maybe i can shorten this... //if red team turn and not all the pawns have been placed if (gameManager.turn == Turn.Red && pawnMoveCount < gameManager.RedPawnCount) { SelectedTroop.GetComponent <Pawn>().moved = true; gameManager.PlaceTroop(); pawnMoveCount++; //increase pawn moved count } //if red team turn and all the pawns have been placed else if (gameManager.turn == Turn.Red && pawnMoveCount == gameManager.RedPawnCount) { gameManager.PlaceTroop(); for (int i = 0; i < gameManager.RedPawns.Count; i++) { gameManager.RedPawns[i].GetComponent <Pawn>().moved = false; } pawnMoveCount = 1; //reset count gameManager.ChangePhase(); } //if blue team turn and not all the pawns have been placed if (gameManager.turn == Turn.Blue && pawnMoveCount < gameManager.BluePawnCount) { SelectedTroop.GetComponent <Pawn>().moved = true; gameManager.PlaceTroop(); pawnMoveCount++; //increase pawn moved count } //if blue team turn and all the pawns have been placed else if (gameManager.turn == Turn.Blue && pawnMoveCount == gameManager.BluePawnCount) { gameManager.PlaceTroop(); for (int i = 0; i < gameManager.BluePawns.Count; i++) { gameManager.BluePawns[i].GetComponent <Pawn>().moved = false; } pawnMoveCount = 1; //reset count gameManager.ChangePhase(); } //...Maybe i can shorten this } //if troop is a mage else if (SelectedTroop.tag == "Mage" && dif > troopScript.moveDist) { //if tile is out of his movement range if (dif > troopScript.moveDist) { awaitingResponse = true; //wait for players response Dragging = false; //stop moving the mage whilst waiting } //if tile is in his movement range else { //palce troop as normal and change phase gameManager.PlaceTroop(); gameManager.ChangePhase(); } } //if troop is anything else else { //place troop and change phase gameManager.PlaceTroop(); gameManager.ChangePhase(); } } //if player hasn't moved troops position else if (difX == 0 && difY == 0) { //place troop but dont chance phase gameManager.PlaceTroop(); } break; default: break; } } if (Input.GetMouseButtonDown(1)) { SelectedTroop.transform.position = storedPos; Dragging = false; SelectedTroop = null; troopScript = null; Debug.Log("hi"); } if (SelectedTroop != null) { if (SelectedTroop.tag == "Mage") { SkinnedMeshRenderer renderer = SelectedTroop.GetComponentInChildren <SkinnedMeshRenderer>(); if (troopScript.team == Team.Red && mageFullOpac == true && renderer != redMageFullOpac) { notChanged = true; } else if (troopScript.team == Team.Red && mageFullOpac == false && renderer != redMageHalfOpac) { notChanged = true; } else if (troopScript.team == Team.Blue && mageFullOpac == true && renderer != blueMageFullOpac) { notChanged = true; } else if (troopScript.team == Team.Blue && mageFullOpac == false && renderer != blueMageHalfOpac) { notChanged = true; } else { notChanged = false; } } } } if (awaitingResponse == true) { //rewrite debug log to ask question in UI //Debug.Log("About to use mages ability, do you want to continue? Y/N"); UIManager.MageQuestion(); if (UIManager.YesNo == yesno.yes) //if player presses Y key activate mage ability { mageFullOpac = true; ChangeMageOpac(); //Move mage and go to checks //TroopHit.transform.position = moveTo; gameManager.PlaceTroop(); gameManager.ChangePhase(); gameManager.ChangePhase(); awaitingResponse = false; //stop calling this UIManager.HideQuestion(); UIManager.YesNo = yesno.notSelected; } else if (UIManager.YesNo == yesno.no) //if player presses N key { //nothing happens, player chooses new tile for mage Dragging = true; awaitingResponse = false; //stop calling this UIManager.HideQuestion(); UIManager.YesNo = yesno.notSelected; } } } else if (gameManager.phase == Phase.Checks) { if (Dragging == true) { //this switch method will allow me to easily add new abilities and checks switch (gameManager.CheckCount) { case (0): //if priest ability if (Input.GetMouseButtonDown(0)) { //Debug.Log("Test1"); if (SelectedTroop.tag == "Pawn") { //set it so it spawns multiple pawns until there are 3 on the board if (gameManager.turn == Turn.Red && gameManager.RedPawnCount < 2) { GameObject RedPawn = Instantiate(gameManager.RedPawnPrefab, new Vector3(moveTo.x, 0.1f, moveTo.z), new Quaternion(0, 0, 0, 0)); //instantiate new gameobject, rotate to face red team if (pawnSpawnCount == 0) { pawnOne = RedPawn; } else if (pawnSpawnCount == 1) { pawnTwo = RedPawn; } //else if (pawnSpawnCount == 2) { pawnThree = RedPawn; } pawnSpawnCount++; RedPawn.transform.SetParent(GameObject.FindGameObjectWithTag("RedTeam").transform); //set its parent object to its team RedPawn.name = "RedPawn"; //rename pawn RedPawn.GetComponent <TroopScript>().troopState = TroopState.Alive; RedPawn.GetComponent <TroopScript>().Anim = RedPawn.GetComponent <Animator>(); StartCoroutine(RedPawn.GetComponent <TroopScript>().PlayReviveAnim()); } else if (gameManager.turn == Turn.Red && gameManager.RedPawnCount <= 2) { gameManager.priestRedRevive = true; SelectedTroop.GetComponent <TroopScript>().ResetHealth(); SelectedTroop.GetComponent <TroopScript>().troopState = TroopState.Alive; StartCoroutine(animController.ReviveAnim(gameManager, SelectedTroop)); gameManager.PlaceTroop(); gameManager.PauseChecks = false; gameManager.CheckCount++; spawningTroop = false; StartCoroutine(gameManager.PerformChecks()); } else if (gameManager.turn == Turn.Blue && gameManager.BluePawnCount < 2) { GameObject BluePawn = Instantiate(gameManager.BluePawnPrefab, new Vector3(moveTo.x, 0.1f, moveTo.z), new Quaternion(0, 1, 0, 0)); //instantiate new gameobject, rotate to face red team if (pawnSpawnCount == 0) { pawnOne = BluePawn; } else if (pawnSpawnCount == 1) { pawnTwo = BluePawn; } //else if (pawnSpawnCount == 2) { pawnThree = BluePawn; } pawnSpawnCount++; //Debug.Log("Plus one in spawn count"); BluePawn.transform.SetParent(GameObject.FindGameObjectWithTag("BlueTeam").transform); //set its parent object to its team BluePawn.name = "BluePawn"; //rename pawn BluePawn.GetComponent <TroopScript>().troopState = TroopState.Alive; BluePawn.GetComponent <TroopScript>().Anim = BluePawn.GetComponent <Animator>(); StartCoroutine(BluePawn.GetComponent <TroopScript>().PlayReviveAnim()); } else if (gameManager.turn == Turn.Blue && gameManager.BluePawnCount <= 2) { Debug.Log("Test2"); gameManager.priestBlueRevive = true; SelectedTroop.GetComponent <TroopScript>().ResetHealth(); SelectedTroop.GetComponent <TroopScript>().troopState = TroopState.Alive; StartCoroutine(animController.ReviveAnim(gameManager, SelectedTroop)); gameManager.PlaceTroop(); gameManager.PauseChecks = false; gameManager.CheckCount++; spawningTroop = false; StartCoroutine(gameManager.PerformChecks()); } } else { Debug.Log("Test3"); SelectedTroop.GetComponent <TroopScript>().ResetHealth(); SelectedTroop.GetComponent <TroopScript>().troopState = TroopState.Alive; StartCoroutine(animController.ReviveAnim(gameManager, SelectedTroop)); gameManager.PlaceTroop(); spawningTroop = false; if (gameManager.turn == Turn.Red) { gameManager.priestRedRevive = true; } else if (gameManager.turn == Turn.Blue) { gameManager.priestBlueRevive = true; } } } if (Input.GetMouseButtonDown(1)) { Debug.Log("hi"); if (SelectedTroop.tag == "Pawn" && pawnSpawnCount >= 1) { //if (pawnSpawnCount == 1) { Destroy (pawnOne); } //else if (pawnSpawnCount == 2) { Destroy(pawnOne); Destroy(pawnTwo); } if (pawnOne != null) { Destroy(pawnOne); } //else if (pawnSpawnCount == 3) { Destroy(pawnOne); Destroy(pawnTwo); Destroy(pawnThree); } } Dragging = false; var MoveTroop = new Vector3(SelectedTroop.transform.position.x, -5, SelectedTroop.transform.position.x); SelectedTroop.transform.position = MoveTroop; spawningTroop = false; SelectedTroop = null; troopScript = null; UIManager.RevealDeadTroops(); } break; default: break; } } if (kingAbility == true) { switch (gameManager.turn) { case (Turn.Red): if (spawnedRedPawn.transform.position == moveTo) { if (Input.GetMouseButtonDown(0)) { PlacePawn(); } } break; case (Turn.Blue): if (spawnedBluePawn.transform.position == moveTo) { if (Input.GetMouseButtonDown(0)) { PlacePawn(); } } break; default: break; } } } }
// Update is called once per frame public virtual void Update() { WeaponName = WeaponAdopted.NameOfTheEquip; ArmorName = ArmorAdopted.NameOfTheEquip; LeaderName = Leader.GetName(); if (GetNumber() <= 0 ) { transform.rotation = Quaternion.Euler(new Vector3(90,0,0)); //yer ded n***a transform.GetComponent<Renderer>().material.color = Color.red; // and bleeding } if (Summoner != null) if (Summoner.GetNumber()<=0) People = 0; if (SummonedOgreByThisGuy!=null) if (SummonedOgreByThisGuy.GetNumber()<=0){ SummonedOgreByThisGuy = null; Faction = OriginalFaction; } }
public void SetOgreSummonInto(TroopScript Summoner) { SummonedOgreByThisGuy = Summoner; }
public void SummonTrashEffect(TroopScript Caster,Tile TargetTile) { muhSkills thisSkill = muhSkills.SummonTrash; TroopScript Target = null; for (int i = 0;i<GameManager.instance.players.Count;i++) if (GameManager.instance.players[i].gridPosition == TargetTile.gridPosition){ Target = GameManager.instance.players[i]; NewFightScript.SummonYogurtOntoPlayer(Target,Caster); } if (Target == null) GameManager.instance.SummonYogurt (TargetTile.gridPosition,Caster); Caster.SetEnergy(Caster.GetEnergy()-Skill.FromListOfSkills(thisSkill).EnergyCost); if (Skill.FromListOfSkills(thisSkill).DepleteEnergy == true) Caster.SetEnergy(0); SwitchThis = muhSkills.NoSkill; Caster.SkillRecoveryTime = Skill.FromListOfSkills(thisSkill).SkillRecoveryTime; Caster.actionPoints--; }
static bool HandsTriangle(TroopScript Attacker, TroopScript Defender) { bool bonusattack = false; NumberOfHands atkhands = Attacker.GetHands(); NumberOfHands defhands = Defender.GetHands(); if ((atkhands == NumberOfHands.OneHanded && defhands == NumberOfHands.Bow)|| (atkhands == NumberOfHands.TwoHanded && defhands == NumberOfHands.OneHanded)|| (atkhands == NumberOfHands.Bow && defhands == NumberOfHands.TwoHanded)) bonusattack = true; /* Axe>Pole>Sword(estoc)>Axe 2H weapon > 1H weapon > Ranged > 2H weapon Light Armor > Slashing Weapon > No Armor > Bludgeoning Weapons > Heavy Armor > Piercing Weapons > Light Armor */ return bonusattack; }
static bool WeaponTriangle(TroopScript Attacker, TroopScript Defender) { bool bonusattack = false; WeaponType atkwpn = Attacker.GetWeapon().weapType; WeaponType defwpn = Defender.GetWeapon().weapType; if ((atkwpn == WeaponType.Spear && defwpn == WeaponType.Sword) || (atkwpn == WeaponType.Sword && defwpn == WeaponType.Axe) || (atkwpn == WeaponType.Axe && defwpn == WeaponType.Spear)) bonusattack = true; return bonusattack; }
public static void AnkleSnare(TroopScript Caster) { GameManager.instance.highlightTilesAt(Caster.gridPosition,Color.cyan,1,false); //this shit is all in the game manager script }
static int TroopValue(TroopScript playerados) { int value = playerados.GetChief().GetAttack()+playerados.GetChief().GetDefense()+playerados.GetChief().GetIntelligence()+playerados.GetChief().GetSpeed(); return value; }
static int Triangle(TroopScript Attacker, TroopScript Defender) { //not optimal but it's the most readable int DamageModifier= 0; if (HandsTriangle(Attacker,Defender)) DamageModifier+=50; if (WeaponTriangle(Attacker,Defender)) DamageModifier+=20; if (EquipTriangleOffensive(Attacker,Defender)) DamageModifier+=25; if (EquipTriangleDefensive(Attacker,Defender)) DamageModifier-=25; return DamageModifier; }
static int ReturnPeoplePerLine(TroopScript Unit) { int x = Mathf.RoundToInt(Unit.gridPosition.x); int y = Mathf.RoundToInt(Unit.gridPosition.y); Tile _terrain = GameManager.instance.map[x][y]; int PeoplePerLine = _terrain.frontLiners; return PeoplePerLine; }
public List<TroopScript> SharpShoot(TroopScript Caster,TroopScript TargetBridge) { //(TroopScript Caster, TroopScript Target){ List<TroopScript> targets= new List<TroopScript>(); Vector2 myPos = Caster.gridPosition; // Vector2 tarPos = Target.gridPosition; // Vector2 myPos = new Vector2 (11,11); // Vector2 tarPos = MousePosition; Vector2 tarPos = TargetBridge.gridPosition; Vector2 vector = (tarPos - myPos).normalized; float angle = Mathf.Atan2(vector.y, vector.x)*Mathf.Rad2Deg; //if i need to debug and i want degrees float AngleRad = angle*Mathf.Deg2Rad; Vector2 lelPos = new Vector2 (Mathf.RoundToInt(myPos.x+mapSize*2*Mathf.Cos(AngleRad)),Mathf.RoundToInt(myPos.y+mapSize*2*Mathf.Sin (AngleRad))); BresenhamThingy line = new BresenhamThingy( new Vector3( myPos.x, myPos.y, 0 ), new Vector3( lelPos.x, lelPos.y, 0 ) ); List<Vector2> myLine = new List<Vector2>(); List<Tile> HitTiles = new List<Tile> (); foreach( Vector2 point in line ) { myLine.Add(point); } int xPos = Mathf.RoundToInt(Caster.gridPosition.x); int yPos = Mathf.RoundToInt(Caster.gridPosition.y); Tile _positionOfPlayer = map[xPos][yPos]; List <Tile> MapAsAList = TileHighlight.FindHighlight(_positionOfPlayer,999); // Debug.Log(myLine.Count+" "+(int)Vector2.Distance(myPos,tarPos)); // if ((int)Vector2.Distance(myPos,tarPos)>myLine.Count) for (int i = 0;i<(int)Vector2.Distance(myPos,tarPos)+5;i++) //for (int i = 0;i<23;i++) if (myLine[i]!=myPos && myLine[i].x>-1 && myLine[i].y>-1 && myLine[i].x<mapSize && myLine[i].y<mapSize) HitTiles.Add(map[(int)myLine[i].x][(int)myLine[i].y]); highlightTilesAt(myPos,Color.white,999); foreach (Tile t in HitTiles) t.visual.transform.GetComponent<Renderer>().materials[0].color = Color.red; for (int i=0;i<HitTiles.Count;i++) for (int j=0;j<players.Count;j++) if (players[j].gridPosition == HitTiles[i].gridPosition && players[j].Faction != Caster.Faction) targets.Add(players[j]); // BresenhamThingy Line = BresenhamThingy(myPos,lelPos); // foreach( Vector2 point in Line ) // { // Debug.Log( "Point on line at 1f intervals: " + point ); // } return targets; }
static void RatingFromDamage(TroopScript Caster, int Damage) { int value = Mathf.RoundToInt( (Damage / (float)Caster.GetNumber())*5); GameManager.instance.SetAdvantage (Caster,value); }
public static void BattleRating(TroopScript Caster, Skill SkillUsed) { float BattleRatingChange = SkillUsed.BattleEffect; //need to change battle rating but there is none for now oop }
public void FlushPreparationTarget() { preparationTargetTroop = null; preparationTargetGround = null; }
public static void ActivatePhalanx(TroopScript troopThatUsesPhalanx) { troopThatUsesPhalanx.GetArmor().Defence+=Mathf.RoundToInt(troopThatUsesPhalanx.GetArmor().Defence/2); troopThatUsesPhalanx.SetBaseMovement(troopThatUsesPhalanx.GetBaseMovement()-1); }
public void SetPreparationTargetPlayer(TroopScript Target) { preparationTargetTroop = Target; }
public static void DeactivatePhalanx(TroopScript troopThatUsedPhalanx) { troopThatUsedPhalanx.GetArmor().Defence-=Mathf.RoundToInt(troopThatUsedPhalanx.GetArmor().Defence/3); troopThatUsedPhalanx.SetBaseMovement(troopThatUsedPhalanx.GetBaseMovement()+1); }
//Select troop function void SelectTroop() { //cast a ray to mouses position on screen TroopRay = Camera.main.ScreenPointToRay(Input.mousePosition); switch (gameManager.turn) { case (Turn.Red): //red team turn //if ray hits a red troop if (Physics.Raycast(TroopRay, out TroopHit, 100, RedTroopMask)) { //Declare troop gameobject and script SelectedTroop = TroopHit.transform.gameObject; troopScript = SelectedTroop.GetComponent <TroopScript>(); storedPos = SelectedTroop.transform.position; //if player can drag selected troop if (troopScript.canDrag == true && SelectedTroop.tag == "Pawn") { //if troop placement state and the troop is pawn, set count to 1 if (gameManager.state == State.TroopPlacement) { pawnCount = 1; } if (SelectedTroop.GetComponent <Pawn>().moved == false) { Dragging = true; //enable dragging } else if (SelectedTroop.GetComponent <Pawn>().moved == true) { SelectedTroop = null; //deselect troop troopScript = null; //deselect troop } } else if (gameManager.state == State.TroopPlacement && SelectedTroop.tag == "King") { SelectedTroop = null; //deselect troop troopScript = null; //deselect troop } else if (troopScript.canDrag == true && SelectedTroop.tag != "Pawn") { Dragging = true; //enable dragging } //if player can not drag selected troop else if (troopScript.canDrag == false) { SelectedTroop = null; //deselect troop troopScript = null; //deselect troop } } break; case (Turn.Blue): //blue team turn //if ray hits a blue troop if (Physics.Raycast(TroopRay, out TroopHit, 100, BlueTroopMask)) { //Debug.Log(TroopHit.transform.gameObject); //Declare troop gameobject and script SelectedTroop = TroopHit.transform.gameObject; troopScript = SelectedTroop.GetComponent <TroopScript>(); storedPos = SelectedTroop.transform.position; //if player can drag selected troop if (troopScript.canDrag == true && SelectedTroop.tag == "Pawn") { //if troop placement state and the troop is pawn, set count to 1 if (gameManager.state == State.TroopPlacement && SelectedTroop.tag == "Pawn") { pawnCount = 1; } if (SelectedTroop.GetComponent <Pawn>().moved == false) { Dragging = true; //enable dragging } else if (SelectedTroop.GetComponent <Pawn>().moved == true) { SelectedTroop = null; //deselect troop troopScript = null; //deselect troop } } else if (gameManager.state == State.TroopPlacement && SelectedTroop.tag == "King") { SelectedTroop = null; //deselect troop troopScript = null; //deselect troop } else if (troopScript.canDrag == true && SelectedTroop.tag != "Pawn") { Dragging = true; //enable dragging } //if player can not drag selected troop else if (troopScript.canDrag == false) { SelectedTroop = null; //deselect troop troopScript = null; //deselect troop } } break; default: break; } }
// Update is called once per frame void Update() { if (initialize == false) { gameManager = GameObject.FindGameObjectWithTag("GameController"); manager = gameManager.GetComponent <GameManager>(); drag = gameManager.GetComponent <DragAndDrop>(); attack = gameManager.GetComponent <Attack>(); x = gameObject.transform.position.x; y = gameObject.transform.position.z; initialize = true; } //cast ray up from middle of tile //if hits a troop if (Physics.Raycast(transform.position, Vector3.up, out troopCheckHit, 1f, troopMask)) { troopOnTile = true; //set true //if(troop != troopCheckHit.transform.gameObject) //{ troop = troopCheckHit.transform.gameObject; troopScript = troop.GetComponent <TroopScript>(); troopScript.tile = this.gameObject; troopScript.tileScript = this; //} } //if troop not hit else { troopOnTile = false; //set false troop = null; troopScript = null; } if (drag.Dragging == true && calc == false) { floorCalculator(); calc = true; } else if (drag.Dragging == false && calc == true) { StopFloorIndicators(); } if (troopOnTile == true) { if (attack.troopSelected == false && troop.tag == "Pawn" && pawnLight == false && manager.phase == Phase.Attack) { if (manager.turn == Turn.Red && manager.RedCurPiece.tag == "Pawn" && troopScript.team == Team.Red) { PlayRedAttackIndicator(); pawnLight = true; } else if (manager.turn == Turn.Blue && manager.BlueCurPiece.tag == "Pawn" && troopScript.team == Team.Blue) { PlayBlueAttackIndicator(); pawnLight = true; } } else if (pawnLight == true) { StopAttackIndicator(); pawnLight = false; } if (attack.troopSelected == true && attack.enemyIndicator == true && attackCalc == false) { AttackIndicator(); attackCalc = true; } else if (attack.enemyIndicator == false && attackCalc == true) { StopAttackIndicator(); } } }
public List<Tile> WhiteDestructionBeam(TroopScript Caster) { Vector2 originLocation = Caster.gridPosition; List <TroopScript> Targets; Vector2 vector = (MousePosition - originLocation).normalized; float angle = Mathf.Atan2(vector.y, vector.x)*Mathf.Rad2Deg; //if i need to debug and i want degrees float AngleRad = angle*Mathf.Deg2Rad; Vector2 lelPos = new Vector2 (Mathf.RoundToInt(originLocation.x+mapSize*Mathf.Cos(AngleRad)),Mathf.RoundToInt(originLocation.y+mapSize*Mathf.Sin (AngleRad))); BresenhamThingy line = new BresenhamThingy( new Vector3( originLocation.x, originLocation.y, 0 ), new Vector3( lelPos.x, lelPos.y, 0 ) ); List<Vector2> myLine = new List<Vector2>(); List<Tile> HitTiles = new List<Tile> (); highlightTilesAt(originLocation,Color.white,999); if (lelPos.x ==originLocation.x || lelPos.y == originLocation.y){ foreach( Vector2 point in line ) myLine.Add(point); for (int i = 0;i<mapSize;i++) if (myLine[i]!=originLocation && myLine[i].x>-1 && myLine[i].y>-1 && myLine[i].x<mapSize && myLine[i].y<mapSize) HitTiles.Add(map[(int)myLine[i].x][(int)myLine[i].y]);} foreach (Tile t in HitTiles) t.visual.transform.GetComponent<Renderer>().materials[0].color = Color.magenta; return HitTiles; }
//Select troop function //Select enemy function void SelectEnemy() { switch (gameManager.turn) { case (Turn.Red): //red turn //cast ray to mouse position enemyTroopRay = Camera.main.ScreenPointToRay(Input.mousePosition); if (SelectedTroop.tag == "Priest") { //if ray hits a blue troop if (Physics.Raycast(enemyTroopRay, out enemyTroopHit, 100, RedTroopMask)) { //store enemy gameobject and enemy script enemySelectedTroop = enemyTroopHit.transform.gameObject; enemyTroopScript = enemySelectedTroop.GetComponent <TroopScript>(); if (enemySelectedTroop.tag != "Priest") { enemyTroopScript.ResetHealth(); animController.FaceEnemy(SelectedTroop, enemySelectedTroop); enemyIndicator = false; } } } else { //if ray hits a blue troop if (Physics.Raycast(enemyTroopRay, out enemyTroopHit, 100, BlueTroopMask)) { //store enemy gameobject and enemy script enemySelectedTroop = enemyTroopHit.transform.gameObject; enemyTroopScript = enemySelectedTroop.GetComponent <TroopScript>(); if (SelectedTroop.tag == "Mage") { if (SelectedTroop.transform.position.x == enemySelectedTroop.transform.position.x || SelectedTroop.transform.position.z == enemySelectedTroop.transform.position.z) { if (enemySelectedTroop.tag == "King") { //if more than 1 enemy pawn on board if (gameManager.BluePawnCount > 1) { //Debug.Log("cannot attack the king as the pawns are alive."); //change so message appears in UI //Undeclare the enemy gameobject and enemy script enemySelectedTroop = null; enemyTroopScript = null; } else if (gameManager.BluePawnCount <= 1) { tank = gameManager.SearchList(gameManager.BlueTeam, "Tank"); //search list to see if tank is alive //if tank is not null/is alive if (tank != null && enemySelectedTroop.tag != "Tank") { //play tank animation & ask player if we wants to swap UIManager.TankQuestion(enemySelectedTroop.tag.ToString()); awaitingInput = true; //waiting for players input. } //if tank is not alive else { //attack animation either here or in calculate damage CalculateDamage(); //call attack and calculate damage //gameManager.ChangePhase(); } } } else { tank = gameManager.SearchList(gameManager.BlueTeam, "Tank"); //search list to see if tank is alive //if tank is not null/is alive if (tank != null && enemySelectedTroop.tag != "Tank") { //play tank animation & ask player if we wants to swap //REMOVE Debug.Log("Do you want to swap your tanks position with target? Y/N"); //change so it appears un UI UIManager.TankQuestion(enemySelectedTroop.tag.ToString()); awaitingInput = true; //waiting for players input. } //if target troop is knight else if (enemySelectedTroop.tag == "Knight") { KnightBlock(); } //if tank is not alive else { CalculateDamage(); } } } else if (SelectedTroop.transform.position.x != enemySelectedTroop.transform.position.x && SelectedTroop.transform.position.z != enemySelectedTroop.transform.position.z) { //Undeclare the enemy gameobject and enemy script enemySelectedTroop = null; enemyTroopScript = null; } } else { //if enemy is the king if (enemySelectedTroop.tag == "King") //REMEMBER IF KING DIES THEN GAME OVER { //if more than 1 enemy pawn on board if (gameManager.BluePawnCount > 1) { //Debug.Log("cannot attack the king as the pawns are alive."); //change so message appears in UI //Undeclare the enemy gameobject and enemy script enemySelectedTroop = null; enemyTroopScript = null; } //if 1 or less enemy pawn on the board else if (gameManager.BluePawnCount <= 1) { bool inRange = CheckRange(); //check is enemy troop is in attack range; return bool //if return true if (inRange == true) { tank = gameManager.SearchList(gameManager.BlueTeam, "Tank"); //search list to see if tank is alive //if tank is not null/is alive if (tank != null && enemySelectedTroop.tag != "Tank") { //play tank animation & ask player if we wants to swap UIManager.TankQuestion(enemySelectedTroop.tag.ToString()); awaitingInput = true; //waiting for players input. } //if tank is not alive else { //if attacking troop is archer if (SelectedTroop.tag == "Archer") { //attack animation either here or in calculate damage CalculateArcherDamage(); //call archer unique attack and calculate damage //gameManager.ChangePhase(); } else { //attack animation either here or in calculate damage CalculateDamage(); //call attack and calculate damage //gameManager.ChangePhase(); } } } //if not in range else if (inRange == false) { //Undeclare the enemy gameobject and enemy script enemySelectedTroop = null; enemyTroopScript = null; } } } //if king is not the target else { Debug.Log("Test"); bool inRange = CheckRange(); //check is enemy troop is in attack range; return bool //if return true if (inRange == true) { tank = gameManager.SearchList(gameManager.BlueTeam, "Tank"); //search list to see if tank is alive //if tank is not null/is alive if (tank != null && enemySelectedTroop.tag != "Tank") { //play tank animation & ask player if we wants to swap //REMOVE Debug.Log("Do you want to swap your tanks position with target? Y/N"); //change so it appears un UI UIManager.TankQuestion(enemySelectedTroop.tag.ToString()); awaitingInput = true; //waiting for players input. } //if tank is not alive else { //if target troop is knight if (enemySelectedTroop.tag == "Knight") { KnightBlock(); } else { //if attacking troop is archer if (SelectedTroop.tag == "Archer") { //attack animation either here or in calculate damage CalculateArcherDamage(); //call archer unique attack and calculate damage //gameManager.ChangePhase(); } else { //attack animation either here or in calculate damage CalculateDamage(); //call attack and calculate damage //gameManager.ChangePhase(); } } } } //if not in range else if (inRange == false) { //Undeclare the enemy gameobject and enemy script enemySelectedTroop = null; enemyTroopScript = null; } } } } } break; case (Turn.Blue): //cast ray to mouse position enemyTroopRay = Camera.main.ScreenPointToRay(Input.mousePosition); if (SelectedTroop.tag == "Priest") { //if ray hits a blue troop if (Physics.Raycast(enemyTroopRay, out enemyTroopHit, 100, BlueTroopMask)) { //store enemy gameobject and enemy script enemySelectedTroop = enemyTroopHit.transform.gameObject; enemyTroopScript = enemySelectedTroop.GetComponent <TroopScript>(); if (enemySelectedTroop.tag != "Priest") { enemyTroopScript.ResetHealth(); animController.FaceEnemy(SelectedTroop, enemySelectedTroop); enemyIndicator = false; } } } else { //if ray hits a blue troop if (Physics.Raycast(enemyTroopRay, out enemyTroopHit, 100, RedTroopMask)) { //store enemy gameobject and enemy script enemySelectedTroop = enemyTroopHit.transform.gameObject; enemyTroopScript = enemySelectedTroop.GetComponent <TroopScript>(); if (SelectedTroop.tag == "Mage") { if (SelectedTroop.transform.position.x == enemySelectedTroop.transform.position.x || SelectedTroop.transform.position.z == enemySelectedTroop.transform.position.z) { if (enemySelectedTroop.tag == "King") { Debug.Log("4.1 enemy selected troop: " + enemySelectedTroop); Debug.Log("4.1 enemy troop script: " + enemyTroopScript); //if more than 1 enemy pawn on board if (gameManager.RedPawnCount > 1) { //Debug.Log("cannot attack the king as the pawns are alive."); //change so message appears in UI //Undeclare the enemy gameobject and enemy script enemySelectedTroop = null; enemyTroopScript = null; Debug.Log("calling"); } else if (gameManager.RedPawnCount <= 1) { tank = gameManager.SearchList(gameManager.RedTeam, "Tank"); //search list to see if tank is alive //if tank is not null/is alive if (tank != null && enemySelectedTroop.tag != "Tank") { //play tank animation & ask player if we wants to swap //REMOVE Debug.Log("Do you want to swap your tanks position with target? Y/N"); //change so it appears un UI UIManager.TankQuestion(enemySelectedTroop.tag.ToString()); awaitingInput = true; //waiting for players input. } //if tank is not alive else { //attack animation either here or in calculate damage CalculateDamage(); //call attack and calculate damage //gameManager.ChangePhase(); } } } else { tank = gameManager.SearchList(gameManager.RedTeam, "Tank"); //search list to see if tank is alive //if tank is not null/is alive if (tank != null && enemySelectedTroop.tag != "Tank") { //play tank animation & ask player if we wants to swap //REMOVE Debug.Log("Do you want to swap your tanks position with target? Y/N"); //change so it appears un UI UIManager.TankQuestion(enemySelectedTroop.tag.ToString()); awaitingInput = true; //waiting for players input. } //if target troop is knight else if (enemySelectedTroop.tag == "Knight") { KnightBlock(); } else { CalculateDamage(); } } } else if (SelectedTroop.transform.position.x != enemySelectedTroop.transform.position.x && SelectedTroop.transform.position.z != enemySelectedTroop.transform.position.z) { //Undeclare the enemy gameobject and enemy script enemySelectedTroop = null; enemyTroopScript = null; Debug.Log("calling"); } } else { //if enemy is the king if (enemySelectedTroop.tag == "King") //REMEMBER IS KING DIES THEN GAME OVER { //if more than 1 enemy pawn on board if (gameManager.RedPawnCount > 1) { Debug.Log("cannot attack the king as the pawns are alive."); //change so message appears in UI //Undeclare the enemy gameobject and enemy script enemySelectedTroop = null; enemyTroopScript = null; Debug.Log("calling"); } //if 1 or less enemy pawn on the board else if (gameManager.RedPawnCount <= 1) { bool inRange = CheckRange(); //check is enemy troop if in attack range; return bool //if return true if (inRange == true) { tank = gameManager.SearchList(gameManager.RedTeam, "Tank"); //search list to see if tank is alive //if tank is not null/is alive if (tank != null && enemySelectedTroop.tag != "Tank") { //play tank animation & ask player if we wants to swap //REMOVE Debug.Log("Do you want to swap your tanks position with target? Y/N"); //change so it appears un UI UIManager.TankQuestion(enemySelectedTroop.tag.ToString()); awaitingInput = true; //waiting for players input. } //if tank is not alive else { //if attacking troop is archer if (SelectedTroop.tag == "Archer") { //attack animation either here or in calculate damage CalculateArcherDamage(); //call archer unique attack and calculate damage //gameManager.ChangePhase(); } else { //attack animation either here or in calculate damage CalculateDamage(); //call attack and calculate damage //gameManager.ChangePhase(); } } } //if not in range else if (inRange == false) { //Undeclare the enemy gameobject and enemy script enemySelectedTroop = null; enemyTroopScript = null; Debug.Log("calling"); } } } //if king is not the target else { Debug.Log("Test"); bool inRange = CheckRange(); //check if enemy troop is in attack range; return bool //if return true if (inRange == true) { tank = gameManager.SearchList(gameManager.RedTeam, "Tank"); //search list to see if tank is alive //if tank is not null/is alive if (tank != null && enemySelectedTroop.tag != "Tank") { //play tank animation & ask player if we wants to swap //REMOVE Debug.Log("Do you want to swap your tanks position with target? Y/N"); //change so it appears un UI UIManager.TankQuestion(enemySelectedTroop.tag.ToString()); awaitingInput = true; //waiting for players input. } //if tank is not alive else { //if target troop is knight if (enemySelectedTroop.tag == "Knight") { KnightBlock(); } else { //if attacking troop is archer if (SelectedTroop.tag == "Archer") { CalculateArcherDamage(); //call archer unique attack and calculate damage } else { Debug.Log(SelectedTroop); Debug.Log(enemySelectedTroop); CalculateDamage(); //call attack and calculate damage } } } } //if not in range else if (inRange == false) { //Undeclare the enemy gameobject and enemy script enemySelectedTroop = null; enemyTroopScript = null; Debug.Log("calling"); } } } } } break; default: break; } }
public void manageTroop() { GameObject unitGO = allyTroops[getTroopsToManageCount() - 1]; if (isUnit(unitGO)) { Unit unitScript = unitGO.GetComponent <Unit>(); if (unitScript.isTroop()) // Is a Troop { //Debug.Log("IS TROOP :: : : "); TroopScript troop = unitGO.GetComponent <TroopScript>(); bool targetFound = false; if (enemyTroopsAlive()) { foreach (GameObject enemyGO in unitScript.getClosestEnemyTroopWithoutUpdate()) { Debug.Log("Behaviour Tree closestEnemy Troop Count " + unitScript.getClosestEnemyTroopWithoutUpdate().Count); Unit enemyUnitScript = enemyGO.GetComponent <Unit>(); if ((enemyUnitScript.CurrentTroopClass == sb.getMatchups()[unitScript.CurrentTroopClass]) || (enemyUnitScript.CurrentTroopClass == TroopClass.Gatherer)) { troop.moveToGoal(enemyGO); targetFound = true; Task.current.Succeed(); break; } } if (targetFound == false) { troop.moveToGoal(unitScript.EnemySpawner.gameObject); Task.current.Succeed(); } } else { troop.setGoal(unitScript.EnemySpawner.gameObject); Task.current.Succeed(); } } else if (unitScript.isGatherer()) // is a Gatherer { //GatherersAI gatherer = unitGO.GetComponent<GatherersAI>(); //if (gatherer.closestResources.First().gameObject != null) //{ // gatherer.setGoal(gatherer.closestResources.First().gameObject); Task.current.Succeed(); //} //else Task.current.Fail(); } else { Debug.Log("Error in managing troops"); Task.current.Fail(); } decreaseTroopsLeftToManage(); } else { Debug.Log("Non unit in allyTroops list"); Task.current.Fail(); } }
void Update() { Plane plane = new Plane(Vector3.up, -1.1f); float dist; Ray ray; if (Camera.main.GetComponent <FreeFlyCamera>().controllerConnected) { Vector2 midScreen = new Vector2(Screen.width / 2, Screen.height / 2); ray = Camera.main.ScreenPointToRay(midScreen); } else { ray = Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue()); } if (plane.Raycast(ray, out dist)) { point = ray.GetPoint(dist); point = new Vector3(Mathf.Round(point.x), 1, Mathf.Round(point.z)); } if (selectedTroopIndex == -1) { if (highlighter.activeSelf) { highlighter.SetActive(false); } if (viewDistanceHighlighter.activeSelf) { viewDistanceHighlighter.SetActive(false); } if (Mouse.current.leftButton.wasPressedThisFrame || Input.GetButtonDown("AButton")) { RaycastHit hit; if (Physics.Raycast(ray, out hit, 100, TroopLayerMask)) { if (!Camera.main.GetComponent <FreeFlyCamera>().isInViewMode || !Application.isMobilePlatform) { upgradeUI.SetTroop(hit.collider.gameObject); upgradeUI.HidePurchaseButtons(); upgradeUI.OpenUpgradeOptions(); } } } return; } if (point != Vector3.zero) { highlighter.transform.position = point; viewDistanceHighlighter.transform.position = new Vector3(point.x, 1.1f, point.z); } if (!placed) { if (selectedTroopIndex != -1 && !highlighter.activeSelf && !viewDistanceHighlighter.activeSelf) { highlighter.SetActive(true); viewDistanceHighlighter.SetActive(true); gridHighlighter.SetActive(true); float distance = troopList[selectedTroopIndex].GetComponent <TroopScript>().GetViewRadius() * 2; viewDistanceHighlighter.transform.localScale = new Vector3(distance, 0.001f, distance); } if (Mouse.current.leftButton.wasPressedThisFrame) { if (viewDistanceHighlighterScript.safe && statBlock.GetPlacedTroops() < statBlock.GetMaxTroops() && !Camera.main.GetComponent <FreeFlyCamera>().controllerConnected) { GameObject obj = Instantiate(troopList[selectedTroopIndex]); TroopScript ts = obj.GetComponent <TroopScript>(); statBlock.AdjustCash(-ts.GetCost()); statBlock.IncrementPlacedTroops(1); obj.transform.position = new Vector3(point.x, ts.yPosSpawn, point.z); Placed(); } else { Placed(); } } } }
static int CalculateGuardPercent(TroopScript Caster, TroopScript Target, Skill SkillUsedToGuard) { int intelligence = Mathf.RoundToInt(((float)Caster.GetChief().GetIntelligence()+(float)Target.GetChief().GetIntelligence())/2); //if the one you have to guard is a retard guarding is harder int GuardScaling = SkillUsedToGuard.GuardScaling; return Mathf.RoundToInt(intelligence*GuardScaling); }
static bool EquipTriangleOffensive(TroopScript Attacker, TroopScript Defender) { bool bonusattack = false; WeaponType atkwpn = Attacker.GetWeapon().weapType; ArmorType defarmr = Defender.GetArmor().armrType; if ((atkwpn == WeaponType.Sword && defarmr == ArmorType.NoArmor)|| (atkwpn == WeaponType.Axe && defarmr == ArmorType.NoArmor)|| (atkwpn == WeaponType.Mace && defarmr == ArmorType.Heavy)|| (atkwpn == WeaponType.Spear && defarmr == ArmorType.Light)|| (atkwpn == WeaponType.Bow && defarmr == ArmorType.NoArmor)) bonusattack = true; return bonusattack; }
public void SetAdvantage(TroopScript Setter, int Change) { int faction = Setter.Faction; if (faction == 0) PlayerBattleRatio+=Change; else if (faction == 1) AIBattleRatio+=Change; }
static int CountAndSetNumberOfPeopleYouCanBuff(TroopScript BuffCaster, TroopScript Target, Skill BuffSkill) { float multiply = BuffSkill.TroopSizeBuffMultiplier; int people = BuffCaster.GetNumber(); int buffedpeople = Target.GetNumber(); int total = Mathf.RoundToInt(((float)people*multiply/(float)buffedpeople)+multiply); return total; //for the list of buffs }
public void SummonYogurt(Vector2 Position, TroopScript MageThatCreatedIt) { ThirdParty Ogre = ((GameObject)Instantiate(OgrePrefab, new Vector3(Position.x - Mathf.Floor((float)mapSize/2),1.5f, -Position.y + Mathf.Floor((float)mapSize/2)), Quaternion.Euler(new Vector3()))).GetComponent<ThirdParty>(); Ogre.gridPosition = Position; Chief myLeader = new Chief(); Chief summoner = MageThatCreatedIt.GetChief(); AddStuffToChief(myLeader, "Ogre", "McPrettyFace", Trait.FromTraitList(ListOfTraits.Fearless),Abilities.fromList(ListOfAbilities.StrongLeadership),Abilities.fromList(ListOfAbilities.Popular),Abilities.fromList(ListOfAbilities.Phalanx), summoner.GetIntelligence(),summoner.GetIntelligence(),0,summoner.GetSpeed()); int OgreHP = MageThatCreatedIt.GetChief().GetIntelligence()*MageThatCreatedIt.GetNumber()/2; //can be changed in the future AddStuffToPlayer(Ogre,2,muhClasses.Yogurt,myLeader, 0, 10,100,12,OgreHP,Weaponry.FromName(WeaponryName.TestHammer),Armory.FromName(ArmoryName.TestConfortableClothes)); Ogre.Summoner = MageThatCreatedIt; // AITroop aiplayer = ((GameObject)Instantiate(AITroopPrefab, new Vector3(6 - Mathf.Floor(mapSize/2),1.5f, -4 + Mathf.Floor(mapSize/2)), Quaternion.Euler(new Vector3()))).GetComponent<AITroop>(); // aiplayer.gridPosition = new Vector2(6,4); // leader = new Chief(); // AddStuffToChief(leader,"another asshole","Obama", Trait.FromTraitList(ListOfTraits.Fearless),Abilities.fromList(ListOfAbilities.StrongLeadership),Abilities.fromList(ListOfAbilities.Popular),Abilities.fromList(ListOfAbilities.Phalanx),2,3,1,3); // // AddStuffToPlayer(aiplayer,1,muhClasses.Animal,leader, 12,2,100,12,100,Weaponry.FromName(WeaponryName.TestHammer),Armory.FromName(ArmoryName.TestConfortableClothes)); // // players.Add(aiplayer); }
public static void AllyGuard(TroopScript Caster, TroopScript Target, Skill SkillUsedToGuard) { Target.GuardedBy = Caster; Target.GuardedByPercent = CalculateGuardPercent(Caster,Target,SkillUsedToGuard); }
//CHECK THE PATHFINDER void AddStuffToPlayer(TroopScript player,int faction,muhClasses muhclass,Chief leader, int Attack,int Defence,int HitPoints,int Speed,int NumberOfSoldiers, Weaponry _weapon, Armory _armor) { // Classes ClassToSet = Classes.fromList(muhclass); player.Faction = faction; player.SetClassDONTUSETHISAREYOUSUREYOUWANTTOUSETHISYOUREALLYSHOULDNT(muhclass); player.SetChief(leader); player.SetBaseAttack(Attack); player.SetBaseDefence(Defence); player.SetBaseHitpoints(HitPoints); player.SetBaseSpeed(Speed); player.SetNumber(NumberOfSoldiers); player.SetWeapon(_weapon); player.SetArmor(_armor); }
//Select troop function void SelectTroop() { switch (gameManager.turn) { case (Turn.Red): //red turn //if the active piece is not a pawn if (gameManager.RedCurPiece.tag != "Pawn") { //automatically select the troop and declare its variables SelectedTroop = gameManager.RedCurPiece; troopScript = SelectedTroop.GetComponent <TroopScript>(); gameManager.troopScript = troopScript; troopSelected = true; enemyIndicator = true; } //if active piece is a pawn else if (gameManager.RedCurPiece.tag == "Pawn") { //left mouse click2 if (Input.GetMouseButtonDown(0)) { //cast ray to mouse position TroopRay = Camera.main.ScreenPointToRay(Input.mousePosition); //if ray hits a red troop if (Physics.Raycast(TroopRay, out TroopHit, 100, RedTroopMask)) { //if tag of troop is pawn if (TroopHit.transform.tag == "Pawn") { //select and declare its variables SelectedTroop = TroopHit.transform.gameObject; troopScript = SelectedTroop.GetComponent <TroopScript>(); gameManager.troopScript = troopScript; troopSelected = true; enemyIndicator = true; } } } } break; case (Turn.Blue): //blue turn //if active piece is not a pawn if (gameManager.BlueCurPiece.tag != "Pawn") { //automatically select the troop and declare its variables SelectedTroop = gameManager.BlueCurPiece; troopScript = SelectedTroop.GetComponent <TroopScript>(); gameManager.troopScript = troopScript; troopSelected = true; enemyIndicator = true; } //if active piece is a pawn else if (gameManager.BlueCurPiece.tag == "Pawn") { //left mouse click if (Input.GetMouseButtonDown(0)) { //cast ray to mouse position TroopRay = Camera.main.ScreenPointToRay(Input.mousePosition); //if ray hits a red troop if (Physics.Raycast(TroopRay, out TroopHit, 100, BlueTroopMask)) { //if tag of troop is pawn if (TroopHit.transform.tag == "Pawn") { //select and declare its variables SelectedTroop = TroopHit.transform.gameObject; troopScript = SelectedTroop.GetComponent <TroopScript>(); gameManager.troopScript = troopScript; troopSelected = true; enemyIndicator = true; } } } } break; default: break; } }