public void CreateEffect(Unit.Action _action) { InfoTab tempTab = Instantiate(infoTabPrefab, transform).GetComponent <InfoTab>(); tempTab.affliation = affliation; if (affliation == GameManager.Affliation.DEFENCE) { tempTab.transform.localPosition = new Vector3(0, 0.5f, -0.4f); } else { tempTab.transform.localPosition = new Vector3(0, -0.5f, -0.4f); } Effect tempEffect = new Effect { actionType = _action.actionType, value = _action.value, immune = _action.immune, infoTab = tempTab, affliation = _action.affliation }; tempTab.LoadTab(tempEffect); effects.Add(tempEffect); }
public override void BuffWorkTo(Unit unit, Unit.Action action) { Player player = unit as Player; player.ChangeMp(-1.2f); count--; }
public override void BuffWorkTo(Unit unit, Unit.Action action) { if (unit is Player) { unit.ChangeHp(5); } count--; }
public bool validPos(Vector3 pos_w, Unit.Action todo) { // treating nowalking map like entities i.e. blocks walking but not attacks // except for "only entities" which is targetting units, not map features bool skipentities = true; bool onlyentities = false; if (todo != null) { if (todo.GetActType() != Unit.ActType.Movement) { skipentities = false; } if (todo.GetActType() == Unit.ActType.Targetted || todo.GetActType() == Unit.ActType.Melee) { onlyentities = true; } //} //if (todo) //Debug.Log(todo.GetActType()); } Vector3Int pos = grid.WorldToCell(pos_w); // NOTE TO SELF: USE THIS MORE if (pos.x > xmin && pos.x < xmax && pos.y > ymin && pos.y < ymax) { pos[2] = 0; if (!onlyentities) { return(passable[pos.x - xmin, pos.y - ymin] && tileMap.HasTile(pos) && (!skipentities || (!HasObj(pos.x, pos.y) && nowalking[pos.x - xmin, pos.y - ymin]))); } else { if (todo.GetTag() != "") { GameObject obj = GetObjectPrecise(pos.x, pos.y); if (obj == null || obj.tag != todo.GetTag()) { return(false); } } return(HasObj(pos.x, pos.y)); } //return !collisionMap.HasTile(pos) && tileMap.HasTile(pos); } else { return(false); } }
/** * @todo 플레이어가 이동/공격 중인지 확인해주어야 한다. */ public override void BuffWorkTo(Unit unit, Unit.Action action) { if (unit is Player) { if (action == Unit.Action.Attack || action == Unit.Action.Move) { unit.ChangeHp(-5); } else { unit.ChangeHp(-2); } } count--; }
public void RemoveEffect(Unit.Action _action) { for (int j = 0; j < effects.Count; j++) { if (effects[j].actionType == _action.actionType && effects[j].affliation == _action.affliation) { effects[j].Remove(_action); if (effects[j].value <= 0 && effects[j].immune <= 0) { DestroyEffect(effects[j]); } break; } } }
public Vector3Int RandomValidPos(Unit.Action todo) { int breaker = 0; int x, y; Vector3 testpos = Vector3.zero; do { x = Random.Range(xmin, xmax); y = Random.Range(ymin, ymax); testpos[0] = x; testpos[1] = y; breaker++; } while (!validPos(testpos, todo) && breaker < 1000); return(Vector3Int.FloorToInt(testpos)); }
public void AddEffect(Unit.Action _action) { bool effectExists = false; for (int j = 0; j < effects.Count; j++) { if (effects[j].actionType == _action.actionType && effects[j].affliation == _action.affliation) { effectExists = true; effects[j].Add(_action); break; } } if (!effectExists) { CreateEffect(_action); } }
public void UndoAction(Unit.Action _action) { RemoveEffect(_action); UpdateTabs(); }
/** * 이 함수는 플레이어의 정신력과 배고픔을 먼저 체크하여 환각과 굶주림 판정을 한 후, 플레이어의 버프를 체크하여 효과를 부여한다. * 이 게임의 턴 진행을 위한 함수. 이 게임의 턴 진행 로직은 다음과 같다. * 1. 각 플레이어가 할 수 있는 행동을 구현하는 함수 마지막에서 EndPlayerTurn() 함수를 호출한다. * 2. EndPlayerTurn() 함수에서 차례로 CheckPlayerStatus(), EnemyTurn(), CheckEnemyStatus(), AlltheTurnEnd() 함수를 호출한다. * 3. 턴을 끝내고 다음 플레이어 행동을 기다린다. */ private void CheckPlayerStatus(Unit.Action _action) { //정신력 체크 DecreaseMpByTurn(); //1층 보스시 추가감소 GameObject[] enemyList = GameObject.FindGameObjectsWithTag("Enemy"); GameObject [] bossList = GameObject.FindGameObjectsWithTag("Boss"); foreach (var bossObject in bossList) { var boss = bossObject.GetComponent <Boss> (); boss.EnemyAction.Other(); } bool tmpHallucinated = player.isHallucinated; if (player.Mp <= 30 && !player.isHallucinated) { player.SetMpZero(); player.AddBuff(new Hallucinated(-1)); player.isHallucinated = true; } if (player.isHallucinated && player.Mp >= 60) { player.DeleteBuff(new Hallucinated(1)); player.SetMpBy100(); player.isHallucinated = false; } if (tmpHallucinated != player.isHallucinated) { foreach (var bossObject in bossList) { bossObject.GetComponent <Boss> ().ChangeStatus(player.isHallucinated); } foreach (var enemyObject in enemyList) //환각에 따른 몹 상태변화 { enemyObject.GetComponent <Enemy>().ChangeStatus(player.isHallucinated); } } //상태이상 체크 IncreaseHungryByTurn(); if (IsDead()) { Buff B = new Starve(); messageMaker.MakeDeathMessage(B); KillPlayer(); return; } if (player.Hungry < 60) { if (player.HungryPrevious >= 160) { player.DeleteBuff(new Hunger()); player.isHungry = false; player.AddBuff(new Full(-1)); player.isFull = true; } else if (player.HungryPrevious >= 60) { player.AddBuff(new Full(-1)); player.isFull = true; } } else if (player.Hungry < 160) { if (player.HungryPrevious < 60) { player.DeleteBuff(new Full(-1)); player.isFull = false; } else if (player.HungryPrevious >= 210) { player.DeleteBuff(new Starve()); player.isStarved = false; } else if (player.HungryPrevious >= 160) { player.DeleteBuff(new Hunger()); player.isHungry = false; } } else if (player.Hungry < 210) { if (player.HungryPrevious < 160) { player.AddBuff(new Hunger()); player.isHungry = true; } else if (player.HungryPrevious >= 210) { player.DeleteBuff(new Starve()); player.isStarved = false; player.AddBuff(new Hunger()); player.isHungry = true; } } else if (player.HungryPrevious < 210) { player.DeleteBuff(new Hunger()); player.isHungry = false; player.AddBuff(new Starve()); player.isStarved = true; } player.SyncHungry(); List <Buff> buffToDelete = new List <Buff>(); foreach (Buff buff in player.Bufflist) { Debug.Log(buff); buff.BuffWorkTo(player, _action); if (buff.Count == 0) { buffToDelete.Add(buff); } if (IsDead()) { messageMaker.MakeDeathMessage(buff); KillPlayer(); } } foreach (Buff buffToDel in buffToDelete) { player.DeleteBuff(buffToDel); } Debug.Log(player.Hp.ToString() + " " + player.Mp.ToString() + " " + player.Hungry); Debug.Log("ATK : " + player.Attack + ", DEF : " + player.Defense); if (IsDead()) { KillPlayer(); } ; if (_action == Unit.Action.Move) { playerTurn = true; return; } else { enemyAttackTurn = true; return; } }
public override float BuffAction(Unit.Action action) { return(1f); }
public override void BuffWorkTo(Unit unit, Unit.Action action) { Player player = unit as Player; player.ChangeHp(2); }
public void Remove(Unit.Action _action) { value -= _action.value; immune -= _action.immune; }
/** * 이 함수는 플레어어의 턴을 종류하는 역할을 한다. * 이 게임의 턴 진행을 위한 함수. 이 게임의 턴 진행 로직은 다음과 같다. * 1. 각 플레이어가 할 수 있는 행동을 구현하는 함수 마지막에서 EndPlayerTurn() 함수를 호출한다. * 2. EndPlayerTurn() 함수에서 차례로 CheckPlayerStatus(), EnemyTurn(), CheckEnemyStatus(), AlltheTurnEnd() 함수를 호출한다. * 3. 턴을 끝내고 다음 플레이어 행동을 기다린다. */ public void EndPlayerTurn(Unit.Action _action) { playerTurn = false; action = _action; }
public void SetAction(Unit.Action act) { currentAction = act; maxdist = currentAction.GetRange(); }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.M)) { cam.GetComponent <AudioSource>().enabled = !cam.GetComponent <AudioSource>().enabled; } if (Input.GetButton("Cancel")) { //Debug.Log(quitbutton); quitbutton += Time.deltaTime; if (quitbutton > 1) { //Debug.Log("quit"); Application.Quit(); } } else { quitbutton -= Time.deltaTime; if (quitbutton < 0) { quitbutton = 0; } } if (firstupdate) { for (int i = 0; i < 2; i++) { difficulty += difficultyincreaserate; gridController.AddPod(Mathf.FloorToInt(difficulty), true); } /*EnemyUnits.Clear(); * foreach (GameObject obj in GameObject.FindGameObjectsWithTag("EnemyUnit")) * { * EnemyUnits.Add(obj.GetComponent<EnemyUnit>()); * EnemyUnits[EnemyUnits.Count - 1].movesLeft += 3; * }*/ gridController.GenAIMap(); firstupdate = false; } if (gridController.defeatedfoes > maxenemies && gridController.defeatedfoes >= gridController.addedfoes) { won = true; } cx = Input.GetAxis("Horizontal"); cy = Input.GetAxis("Vertical"); cz = Input.GetAxis("Mouse ScrollWheel"); camscript.orthographicSize -= cz; if (camscript.orthographicSize < 1) { camscript.orthographicSize = 1; } if (camscript.orthographicSize > 15) { camscript.orthographicSize = 15; } newcampos += new Vector3(cx / 2f, cy / 2f, 0); if (newcampos.x < gridController.xmin + camscript.orthographicSize * camscript.aspect) { newcampos[0] = gridController.xmin + camscript.orthographicSize * camscript.aspect; } if (newcampos.x > gridController.xmax - camscript.orthographicSize * camscript.aspect) { newcampos[0] = gridController.xmax - camscript.orthographicSize * camscript.aspect; } if (newcampos.y < gridController.ymin + camscript.orthographicSize) { newcampos[1] = gridController.ymin + camscript.orthographicSize; } if (newcampos.y > gridController.ymax - camscript.orthographicSize) { newcampos[1] = gridController.ymax - camscript.orthographicSize; } cam.transform.position = newcampos; //cam.transform.position[1] += cy; if (won || lost) { restartcounter += Time.deltaTime; if (won) { winMsg.SetActive(true); occupied.SetActive(false); } else { loseMsg.SetActive(true); } if (restartcounter > 10) { SceneManager.LoadScene("TeamSelect"); } return; } if (currentUnit != null && !currentUnit.readyToMove()) { return; } if (currentEnemyUnit != null && !currentEnemyUnit.readyToMove()) { return; } if (playerturn == false) { if (addnew) { if (occupiedbool) { occupied.SetActive(true); foreach (Unit playerunit in PlayerUnits) { playerunit.Damage(1, Vector3.positiveInfinity, "EnemyUnit"); } } else { occupied.SetActive(false); } addnew = false; gridController.GenAIMap(); if (gridController.addedfoes - gridController.defeatedfoes > maxatonce || gridController.addedfoes > maxenemies) { return; } difficulty += difficultyincreaserate; gridController.AddPod(Mathf.FloorToInt(difficulty)); //gridController.GenAIMap(); } if (recalcresist) { foreach (Unit unt in PlayerUnits) { if (unt != null) { unt.CalcResistance(); } } foreach (EnemyUnit unt in EnemyUnits) { if (unt != null) { unt.CalcResistance(); } } recalcresist = false; } //Debug.Log("Enemyturn?"); // Enemy turn goes here if (unit == null && EnemyUnits.Count > 0) { currentEnemyUnit = EnemyUnits[enemyid]; if (currentEnemyUnit != null) { unit = currentEnemyUnit.gameObject; } } if (currentEnemyUnit != null && currentEnemyUnit.MovesLeft()) { if (currentEnemyUnit.readyToMove()) { currentEnemyUnit.RunAI(); } } else { enemyid++; if (enemyid < EnemyUnits.Count) { currentEnemyUnit = EnemyUnits[enemyid]; if (currentEnemyUnit == null) { EnemyUnits.RemoveAt(enemyid); enemyid--; return; } unit = currentEnemyUnit.gameObject; } else { unit = null; currentUnit = null; playerturn = true; enemyid = 0; PlayerUnits.Clear(); foreach (GameObject obj in GameObject.FindGameObjectsWithTag("Unit")) { PlayerUnits.Add(obj.GetComponent <Unit>()); } if (PlayerUnits.Count == 0) { lost = true; return; } foreach (Unit punit in PlayerUnits) { punit.RenewMoves(); } foreach (EnemyUnit punit in EnemyUnits) { punit.RenewMoves(); } recalcresist = true; } } return; } /*else { * addnew = true; * }*/ if (currentUnit != null && currentUnit.readyToMove() && !currentUnit.MovesLeft()) { currentUnit = null; unit = null; return; } newpos = Vector3Int.RoundToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition) - offset); transform.position = offset + newpos; if (oldpos != newpos) { //Debug.Log("old"+oldpos); //Debug.Log("new"+newpos); oldpos = newpos + Vector3Int.zero;; validpath = false; if (gridController.validPos(transform.position, currentAction)) { if (unit != null && currentAction != null && currentUnit.readyToMove()) { srend.color = Color.cyan; linesteps.Clear(); attackarealine.Clear(); //Debug.Log("Valid pos?"); // Define path. Getpath does pathfinding (movement + melee) // Raycast otherwise // public enum ActType { Movement, Melee, Targetted, Cone, LineOfSight, Grenade }; switch (currentAction.GetActType()) { default: /*Debug.Log(Vector3Int.FloorToInt(unit.transform.position)); * Debug.Log(newpos); * Debug.Log(maxdist);*/ if (!gridController.CheckLine(Vector3Int.FloorToInt(unit.transform.position), newpos, maxdist)) { linesteps.Add(Vector3Int.FloorToInt(unit.transform.position)); linesteps.Add(newpos); float range2 = currentAction.GetRange2(); float range = currentAction.GetRange(); if (currentAction.GetActType() == Unit.ActType.Cone) { Vector3 direction = ((linesteps[1] - linesteps[0]) + Vector3.zero); //.normalized; direction[2] = 0; direction = direction.normalized; Vector3 perpdir = new Vector3(direction[1], -direction[0]); attackarealine.Add(linesteps[0]); attackarealine.Add(Vector3Int.RoundToInt(linesteps[0] + direction * range + perpdir * range2 / 2)); attackarealine.Add(Vector3Int.RoundToInt(linesteps[0] + direction * range - perpdir * range2 / 2)); attackarealine.Add(linesteps[0]); } else if (currentAction.GetActType() == Unit.ActType.Grenade) { //float anglesteps= for (int i = 0; i < 9; i++) { attackarealine.Add(Vector3Int.RoundToInt( newpos + range2 * (Quaternion.Euler(0, 0, i * 45) * Vector3.right) )); } } } break; case Unit.ActType.Melee: gridController.getPath(Vector3Int.FloorToInt(unit.transform.position), newpos, linesteps, maxdist); break; case Unit.ActType.Movement: /**/ gridController.PathFromCache(Vector3Int.FloorToInt(unit.transform.position), newpos, linesteps, maxdist); break; } if (linesteps.Count > 0) { line.enabled = true; if (attackarealine.Count > 0) { line.positionCount = attackarealine.Count; for (int i = 0; i < attackarealine.Count; i++) { line.SetPosition(i, attackarealine[i] + offset); } } else { line.positionCount = linesteps.Count; for (int i = 0; i < linesteps.Count; i++) { line.SetPosition(i, linesteps[i] + offset); } } validpath = true; } else { srend.color = Color.red; line.enabled = false; //oldpos = Vector3Int.zero; } } else { srend.color = Color.clear; line.enabled = false; //oldpos = Vector3Int.zero; } } else { srend.color = Color.clear; line.enabled = false; //oldpos = Vector3Int.zero; } }/* * if (Input.GetButtonDown("Cancel")) { * unit = null; * currentUnit = null; * srend.color = Color.red; * line.enabled = false; * oldpos = Vector3Int.zero; * }*/ if (Input.GetButtonDown("Fire1")) { if (unit != null && currentAction != null && validpath) { Vector3 worldPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition) - offset; if (currentAction.GetActType() == Unit.ActType.Movement || currentAction.GetActType() == Unit.ActType.Melee) { gridController.getPath(Vector3Int.RoundToInt(transform.position - offset), Vector3Int.RoundToInt(worldPoint), linesteps); if (currentAction.GetActType() == Unit.ActType.Melee) { // do damage after moving StartCoroutine(currentUnit.QueueAction(currentAction, linesteps[linesteps.Count - 1])); int i = 0; while (i < linesteps.Count) { if (linesteps[i] == linesteps[linesteps.Count - 1]) { linesteps.RemoveAt(i); } else { i++; } } //linesteps.RemoveAll(linesteps[linesteps.Count - 1]); } if (linesteps.Count > 0) { gridController.FillPathCache(linesteps[linesteps.Count - 1], currentUnit.MoveDistance); } currentUnit.GiveMoveOrder(linesteps); /*foreach (Vector3Int thisone in linesteps) * { * Debug.Log("After: " + linesteps); * }*/ } else { //currentUnit.PerformAction(currentAction, Vector3Int.RoundToInt(worldPoint)); StartCoroutine(currentUnit.AttackAnimation(currentAction, Vector3Int.RoundToInt(worldPoint))); } srend.color = Color.red; line.enabled = false; oldpos = Vector3Int.zero; //currentAction = null; if (!currentUnit.MovesLeft()) { actionMenu.ClearOptions(); unit = null; currentAction = null; recalcresist = true; //currentUnit = null; CheckForEnemyTurn(); } } else { RaycastHit2D hit = Physics2D.Raycast(new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y), Vector2.zero, 0); Debug.Log("do raycast"); if (hit) { Debug.Log("hit something " + hit.transform.name); if (hit.transform.tag == "Unit") { if (hit.transform.gameObject.GetComponent <Unit>().MovesLeft()) { unit = hit.transform.gameObject; currentUnit = unit.GetComponent <Unit>(); actionMenu.DefineOptions(unit); gridController.FillPathCache(Vector3Int.FloorToInt(unit.transform.position), currentUnit.MoveDistance); } } } } } if (Input.GetButtonDown("Fire2")) { oldpos = Vector3Int.zero; } // Switch between units if (playerturn && (Input.GetButtonDown("Fire3") || (unit == null && (currentUnit == null || currentUnit.readyToMove())))) { oldpos = Vector3Int.zero; if (currentUnit == null && PlayerUnits[0].MovesLeft()) { currentUnit = PlayerUnits[0]; } else { int stepstaken = 0; int i = PlayerUnits.IndexOf(currentUnit); do { i++; stepstaken++; if (i >= PlayerUnits.Count) { i = 0; } if (stepstaken > PlayerUnits.Count) { playerturn = false; actionMenu.ClearOptions(); unit = null; currentAction = null; return; } } while (!PlayerUnits[i].MovesLeft()); currentUnit = PlayerUnits[i]; } unit = currentUnit.gameObject; actionMenu.DefineOptions(unit); gridController.FillPathCache(Vector3Int.FloorToInt(unit.transform.position), currentUnit.MoveDistance); if (recalcresist) { foreach (Unit unt in PlayerUnits) { if (unt != null) { unt.CalcResistance(); } } foreach (EnemyUnit unt in EnemyUnits) { if (unt != null) { unt.CalcResistance(); } } } } }
/** *@todo [2018.07.19 변경] Unit.Action action을 받아서 action이 이동 중, 공격 중, 맞는 중에 따라 효과를 다르게 할 예정 * 이 함수는 유닛에 턴이 지날 때 마다 받는 효과를 지정합니다. */ public abstract void BuffWorkTo(Unit unit, Unit.Action action);
/** * @todo [2018.07.19 변경] Unit.Action action을 받아서 action이 이동 중, 공격 중, 맞는 중에 따라 효과를 다르게 할 예정 * 이 함수는 데미지에 곱해지는 배율을 반환합니다.(ex. 1.5를 반환할 경우 유닛이 받는 데미지에 1.5배를 곱합니다.) */ public abstract float BuffAction(Unit.Action action);
public void Set(Unit.Action _action) { value = _action.value; immune = _action.immune; }
public override void BuffWorkTo(Unit unit, Unit.Action action) { count--; }
public void Add(Unit.Action _action) { value += _action.value; immune += _action.immune; }
/** * @todo I need to change enemy's attack part. */ public override void BuffWorkTo(Unit unit, Unit.Action action) { unit.ChangeHp(-1); count--; }
public void DoAction(Unit.Action _action) { AddEffect(_action); UpdateTabs(); }
public void SetAction(Unit.Action act) { action = act; }