public int idx = 0;// // Start is called before the first frame update void Start() { MoveObj mb = (MoveObj)GetComponent(typeof(MoveObj)); this.idx = mb.idx; // transform.localRotation = Quaternion.Euler(this.rota[0],this.rota[1],this.rota[2]); }
////////////// DAMAGE AND STAT FUNCTIONS //////////////// /// <summary> /// Calculate how much damage is taken. /// </summary> /// <param name="move">Move the monster is hit with.</param> /// <param name="attacker">Monster who attacked.</param> /// <returns>Updated currentHP after damage and <see cref="DamageDetails"/>.</returns> public DamageDetails TakeDamage(MoveObj move, MonsterObj attacker) { // Critical hit chance is 6.25%. var critical = 1f; if (UnityEngine.Random.value * 100f <= 6.25f) { critical = 2f; } // Type effectiveness defined in TypeChart. float type = TypeChart.GetEffectiveness(move.Base.Type, Base.PrimaryType) * TypeChart.GetEffectiveness(move.Base.Type, Base.SecondaryType); var damageDetails = new DamageDetails() { Critical = critical, TypeEffectiveness = type, Downed = false }; float attack = (move.Base.Category == MoveCategory.Special) ? attacker.SpAttack : attacker.Attack; float defense = (move.Base.Category == MoveCategory.Special) ? SpDefense : Defense; // Damage calculation based on the original game's formula. float modifiers = UnityEngine.Random.Range(0.85f, 1f) * type * critical; float a = (2 * attacker.Level + 10) / 250f; float d = a * move.Base.Power * (attack / defense) + 2; int damage = Mathf.FloorToInt(d * modifiers); UpdateHp(damage); return(damageDetails); }
/// <summary> /// Handle move selection. /// </summary> /// <param name="selectedMove">Index of move selected.</param> /// <param name="move">Move selected.</param> public void UpdateMoveSelection(int selectedMove, MoveObj move) { for (var i = 0; i < _moveTexts.Count; ++i) { _moveTexts[i].color = i == selectedMove ? _highlightColor : _standardColor; } _energyText.text = $"Energy: {move.Energy.ToString()}/{move.Base.Energy.ToString()}"; _typeText.text = "Type: " + move.Base.Type; _energyText.color = move.Energy == 0 ? Color.red : _standardColor; }
// void OnTriggerEnter(Collider other){ // // if(other.tag == ("coll_xianka")) // // Debug.Log("OnTriggerEnter"); // // for(int i=0;i<4;i++) { // // if(other.name == this.collobjs[i].name) // // Debug.Log("OnTriggerEnter"); // // } // } void OnTriggerStay(Collider other) { if (this.finish) { return; } // if(other.tag == ("coll_xianka")) { for (int i = 0; i < 4; i++) { if (other.name == this.collobjs[i].name) { this.colnums[i] = 1; } } this.c**t = 0; for (int i = 0; i < 4; i++) { if (this.colnums[i] == 1) { this.c**t++; } } if (this.c**t >= 4 && !this.found) { Debug.Log("found"); GameObject txt_success = GameObject.Find("txt_success"); Text t = txt_success.GetComponent <Text>(); if (!comManager.getInstance().getState(2) && this.idx != 2) //CPU 未安装 { t.text = "请先安装CPU"; return; } this.c**t = 0; this.finish = true; this.lasttime = Time.time; this.found = true; //找到后设置指定位置 // GameObject.Destroy(gameObject); MoveObj mb = (MoveObj)GetComponent(typeof(MoveObj)); GameObject.Destroy(mb); //不能移动 BoxCollider box = GetComponent <BoxCollider>(); box.enabled = false; // box.isTrigger = false; // Debug.Log("mb "+mb.enabled); // transform.localPosition = this.tarpos; } // } Debug.Log("OnTriggerStay " + other.name); for (int i = 0; i < 4; i++) { // if(other.name == this.collobjs[i].name) // this.colnums[i] = 1; Debug.Log("collnums idx " + this.colnums[i] + this.collobjs[i].name); } }
private void HandleMoveSelection() { if (Keyboard.current.rightArrowKey.wasPressedThisFrame) { ++_currentMove; } else if (Keyboard.current.leftArrowKey.wasPressedThisFrame) { --_currentMove; } else if (Keyboard.current.downArrowKey.wasPressedThisFrame) { _currentMove += 2; } else if (Keyboard.current.upArrowKey.wasPressedThisFrame) { _currentMove -= 2; } _currentMove = Mathf.Clamp(_currentMove, 0, _playerMonster.Monster.Moves.Count - 1); _dialogBox.UpdateMoveSelection(_currentMove, _playerMonster.Monster.Moves[_currentMove]); if (Keyboard.current.zKey.wasPressedThisFrame) { MoveObj move = _playerMonster.Monster.Moves[_currentMove]; _dialogBox.EnableMoveSelector(false); _dialogBox.EnableDialogText(true); if (_state == BattleState.ForgetSelection) { _prevState = null; StartCoroutine(ForgetMove(_playerMonster.Monster, move)); } else { if (move.Energy == 0) { return; } StartCoroutine(ExecuteTurn(BattleAction.Move)); } } else if (Keyboard.current.xKey.wasPressedThisFrame) { _dialogBox.EnableMoveSelector(false); _dialogBox.EnableDialogText(true); ActionSelection(); } }
private IEnumerator ForgetMove(MonsterObj monster, MoveObj oldMove) { //TODO - fix bug where new move is lost if monster gains more than one level LearnableMove newMove = _playerMonster.Monster.GetLearnableMove(); monster.ForgetMove(oldMove); monster.LearnMove(newMove); _dialogBox.SetMoveList(monster.Moves); yield return(_dialogBox.TypeDialog($"{_playerMonster.Monster.Base.Name} has forgotten {oldMove.Base.Name}!")); yield return(_dialogBox.TypeDialog($"{_playerMonster.Monster.Base.Name} has learned {newMove.Base.Name}!")); _state = BattleState.ExecutingTurn; }
/// <summary> /// Constructor used for loading monsters from saved <see cref="MonsterData"/>. /// </summary> /// <param name="monsterData">Saved data of the monster to be loaded.</param> public MonsterObj(MonsterData monsterData) { _base = Resources.Load <MonsterBase>($"Monsters/{monsterData.monsterName}"); _level = monsterData.currentLevel; Exp = monsterData.currentExp; CurrentHp = monsterData.currentHp; Moves = new List <MoveObj>(); for (var i = 0; i < monsterData.currentMoves.Length; i++) { var moveBase = Resources.Load <MoveBase>($"Moves/{monsterData.currentMoves[i]}"); int moveEnergy = monsterData.currentEnergy[i]; var move = new MoveObj(moveBase, moveEnergy); Moves.Add(move); } StatusChanges = new Queue <string>(); CalculateStats(); ResetStatsChanged(); RemoveStatus(); RemoveVolatileStatus(); }
private void Books_Load(object sender, EventArgs e) { DataSet dataalll = new DataSet(); dataalll.ReadXml("BD.xml"); try { int i = 0; int n = 0; foreach (DataRow row in dataalll.Tables["Books"].Rows) { DataBooks.Rows[n].Cells[2].Value = row["Genre"]; // то же самое с третьим столбцом DataBooks.Rows[n++].Cells[3].Value = row["YearPublication"]; // то же самое с четвертым столбцом string[] indexes = row["IndexesOfCurrentUsers"].ToString().Split('.'); foreach (string index in indexes) { Users.Add(new List <DataGridViewRow>()); try { Users[i].Add(friend.DataUserGrid.Rows[Convert.ToInt32(index)]); } catch (Exception) { continue; } } i++; } DataBooks.ClearSelection(); MoveObj.Focus(); } catch (NullReferenceException) { return; } this.DataBooks.SelectionChanged += new System.EventHandler(this.DataBooks_SelectionChanged); CountOfBooksTotal.Text = DataBooks.RowCount.ToString(); }
private bool CheckIfMoveHits(MoveObj move, MonsterObj attackingMonster, MonsterObj defendingMonster) { if (move.Base.AlwaysHits) { return(true); } // Stat changes based on original game's formula. float moveAccuracy = move.Base.Accuracy; int accuracy = attackingMonster.StatsChanged[MonsterStat.Accuracy]; int evasion = defendingMonster.StatsChanged[MonsterStat.Evasion]; float[] changeVals = { 1f, 4f / 3f, 5f / 3f, 2f, 7f / 3f, 8f / 3f, 3f }; if (accuracy > 0) { moveAccuracy *= changeVals[accuracy]; } else if (accuracy < 0) { moveAccuracy /= changeVals[-accuracy]; } if (evasion > 0) { moveAccuracy /= changeVals[evasion]; } else if (evasion < 0) { moveAccuracy *= changeVals[evasion]; } int rng = UnityEngine.Random.Range(1, 101); return(rng <= moveAccuracy); }
} // И ЭТО private void MainForm_Deactivate(object sender, EventArgs e) => MoveObj.Focus();
private MoveObj movePiece(Game current, Game previous) { GameField a = new GameField(2); GameField b = new GameField(2); MoveObj coord = new MoveObj(); coord.color = 10; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (current.board[i, j].color != previous.board[i, j].color) { if (current.board[i, j].color == 2) { coord.prev_i = i; coord.prev_j = j; coord.color = previous.board[i, j].color; } if (previous.board[i, j].color == 2) { coord.curr_i = i; coord.curr_j = j; } } } } return coord; }
private void Button_Click_5(object sender, RoutedEventArgs e) { timer.Tick -= new EventHandler(runCamera); System.Windows.Forms.MessageBox.Show("wykonaj ruch"); MoveObj asd = new MoveObj(); pictureBox1.Image = piecesCheck2(capture.QueryFrame()).ToBitmap(); asd = movePiece(currentGame, previousGame); timer.Tick += new EventHandler(runCamera); timer.Interval = new TimeSpan(0, 0, 0, 0, 1); timer.Start(); }
private MoveObj State; //当前的状态 void Start() { State = GetComponentInParent <MoveObj>(); }
private void Search_form_Deactivate(object sender, EventArgs e) => MoveObj.Focus();
/// <summary> /// Forget a move to make space for a new one. /// </summary> /// <param name="oldMove">Move to forget.</param> public void ForgetMove(MoveObj oldMove) { Debug.Log($"Forgetting {oldMove.Base.Name}"); Moves.Remove(oldMove); }
private void Books_Deactivate(object sender, EventArgs e) { MoveObj.Focus(); }
private IEnumerator UseMove(BattleMonster attackingMonster, BattleMonster defendingMonster, MoveObj move) { // Check for statuses like paralyze or sleep before trying to attack. bool canAttack = attackingMonster.Monster.CheckIfCanAttack(); if (!canAttack) { yield return(ShowStatusChanges(attackingMonster.Monster)); yield return(attackingMonster.Hud.UpdateHp()); yield break; } // Clear the StatusChanges queue and decrease the move energy. yield return(ShowStatusChanges(attackingMonster.Monster)); move.Energy--; if (attackingMonster.IsPlayerMonster) { yield return(_dialogBox.TypeDialog($"{attackingMonster.Monster.Base.Name} used {move.Base.Name}!")); } else { yield return(_dialogBox.TypeDialog($"Enemy {attackingMonster.Monster.Base.Name} used {move.Base.Name}!")); } if (CheckIfMoveHits(move, attackingMonster.Monster, defendingMonster.Monster)) { attackingMonster.PlayAttackAnimation(); yield return(YieldHelper.HalfSecond); defendingMonster.PlayHitAnimation(); // If status move then don't deal damage, switch to UseMoveEffects coroutine. if (move.Base.Category == MoveCategory.Status) { yield return(UseMoveEffects(move.Base.Effects, attackingMonster.Monster, defendingMonster.Monster, move.Base.Target)); } else { DamageDetails damageDetails = defendingMonster.Monster.TakeDamage(move, attackingMonster.Monster); yield return(defendingMonster.Hud.UpdateHp()); yield return(ShowDamageDetails(damageDetails)); } // Check for secondary move effects. if (move.Base.MoveSecondaryEffects != null && move.Base.MoveSecondaryEffects.Count > 0 && attackingMonster.Monster.CurrentHp > 0) { foreach (MoveSecondaryEffects effect in move.Base.MoveSecondaryEffects) { int rng = UnityEngine.Random.Range(1, 101); if (rng <= effect.Chance) { yield return(UseMoveEffects(effect, attackingMonster.Monster, defendingMonster.Monster, effect.Target)); } } } // Handle downed monster and check if we should continue. if (defendingMonster.Monster.CurrentHp <= 0) { yield return(HandleDownedMonster(defendingMonster)); } } else { // Handle a missed attack. if (attackingMonster.IsPlayerMonster) { yield return(_dialogBox.TypeDialog($"{attackingMonster.Monster.Base.Name} missed their attack!")); } else { yield return(_dialogBox.TypeDialog($"Enemy {attackingMonster.Monster.Base.Name} missed their attack!")); } } }
private IEnumerator ExecuteTurn(BattleAction playerAction) { _state = BattleState.ExecutingTurn; if (playerAction == BattleAction.Move) { // Get the monster moves. _playerMonster.Monster.CurrentMove = _playerMonster.Monster.Moves[_currentMove]; _enemyMonster.Monster.CurrentMove = _enemyMonster.Monster.GetRandomMove(); if (_playerMonster.Monster.CurrentMove == null || _enemyMonster.Monster.CurrentMove == null) { BattleOver(BattleResult.Error); yield break; } int playerPriority = _playerMonster.Monster.CurrentMove.Base.Priority; int enemyPriority = _enemyMonster.Monster.CurrentMove.Base.Priority; // Check who goes first. var isPlayerFirst = true; if (enemyPriority > playerPriority) { isPlayerFirst = false; } else if (playerPriority == enemyPriority) { isPlayerFirst = _playerMonster.Monster.Speed >= _enemyMonster.Monster.Speed; } BattleMonster firstMonster = (isPlayerFirst) ? _playerMonster : _enemyMonster; BattleMonster secondMonster = (isPlayerFirst) ? _enemyMonster : _playerMonster; // Store in case it gets downed and switched out before its move. MonsterObj lastMonster = secondMonster.Monster; // Execute the first move. yield return(UseMove(firstMonster, secondMonster, firstMonster.Monster.CurrentMove)); yield return(CleanUpTurn(firstMonster)); if (_state == BattleState.BattleOver) { yield break; } // Execute the second move. if (lastMonster.CurrentHp > 0) { yield return(UseMove(secondMonster, firstMonster, secondMonster.Monster.CurrentMove)); yield return(CleanUpTurn(secondMonster)); if (_state == BattleState.BattleOver) { yield break; } } } else if (playerAction == BattleAction.SwitchMonster) { // Switch the monster. MonsterObj selectedMember = _playerParty.Monsters[_currentMember]; _state = BattleState.Busy; yield return(SwitchMonster(selectedMember)); // Now it's the enemy's turn. MoveObj enemyMove = _enemyMonster.Monster.GetRandomMove(); if (enemyMove == null) { BattleOver(BattleResult.Error); yield break; } yield return(UseMove(_enemyMonster, _playerMonster, enemyMove)); yield return(CleanUpTurn(_enemyMonster)); if (_state == BattleState.BattleOver) { yield break; } } else if (playerAction == BattleAction.UseItem) { //TODO - refactor this when item system is implemented. // Use the item. _dialogBox.EnableActionSelector(false); yield return(ActivateCrystal()); } else if (playerAction == BattleAction.Run) { // Run from the battle. yield return(AttemptRun()); } // Return to ActionSelection. if (_state != BattleState.BattleOver) { ActionSelection(); } }
private void main_Closing(object sender, System.ComponentModel.CancelEventArgs e) //Closing Stop Thread { //Closing Stop Thread MoveObj.Stop(); //Closing Stop Thread }