public void ReleaseUnit(CaptureRecord captureRecord) { RaidSceneManager.BattleGround.Captures.Remove(captureRecord); if (captureRecord.RemoveFromParty) { HeroFormation.SpawnUnit(captureRecord.PrisonerUnit, 1); captureRecord.PrisonerUnit.gameObject.SetActive(true); captureRecord.PrisonerUnit.InstantRelocation(); captureRecord.PrisonerUnit.SetCombatAnimation(true); captureRecord.PrisonerUnit.OverlaySlot.UpdateOverlay(); } else { if (captureRecord.Component.ReleaseEffects.Count > 0) { foreach (var captorEffectString in captureRecord.Component.ReleaseEffects) { var captorEffect = DarkestDungeonManager.Data.Effects[captorEffectString]; foreach (var subEffect in captorEffect.SubEffects) { subEffect.ApplyInstant(captureRecord.CaptorUnit, captureRecord.PrisonerUnit, captorEffect); } } captureRecord.PrisonerUnit.RemoveCaptureEffect(); FMODUnity.RuntimeManager.PlayOneShot("event:/char/enemy/" + captureRecord.CaptorUnit.Character.Class + "_capture_fade_out"); } } }
//TODO: Note that this method has no way of filling in the fields of the turn record of // type Piece. This means that the consumer of TurnRecords must be able to infer the // pieces involved in the turn from the positional information included in the record. // Furthermore, either the consumers of TurnRecord need to robust against null Piece // refs, or the Piece refs should be removed altogether from the TurnRecord. internal static TurnRecord DeserializeTurnRecord(string turnStr, Side side) { uint startRow = 0; MoveRecord primaryMove = null; MoveRecord secondaryMove = null; CaptureRecord capture = null; startRow = 0; if (side == Side.Black) { startRow = 7; } if (KingsideCastleStr.Equals(turnStr)) { primaryMove = new MoveRecord( null, new BoardPosition(4, startRow), new BoardPosition(6, startRow)); secondaryMove = new MoveRecord( null, new BoardPosition(7, startRow), new BoardPosition(5, startRow)); return(new TurnRecord(primaryMove, secondaryMove)); } else if (QueensideCastleStr.Equals(turnStr)) { primaryMove = new MoveRecord( null, new BoardPosition(4, startRow), new BoardPosition(2, startRow)); secondaryMove = new MoveRecord( null, new BoardPosition(0, startRow), new BoardPosition(3, startRow)); return(new TurnRecord(primaryMove, secondaryMove)); } char delimeter = '\0'; if (turnStr.Contains("-")) { delimeter = '-'; } else if (turnStr.Contains("x")) { delimeter = 'x'; capture = new CaptureRecord(null); } else { throw new InvalidOperationException("The given string is not a valid representation of a move."); } string[] fromAndTo = turnStr.Split(delimeter); if (fromAndTo.Length != 2) { throw new InvalidOperationException("The given string is not a valid representation of a move."); } BoardPosition from = SerializationHelper.DeserializeBoardPosition(fromAndTo[0]); BoardPosition to = SerializationHelper.DeserializeBoardPosition(fromAndTo[1].Substring(0, 2)); if (fromAndTo[1].Length > 2) { // promotion var pieceStrLen = fromAndTo[1].Length - 4; System.Diagnostics.Debug.Assert(pieceStrLen > 0); var pieceCapabilities = DeserializePieceCapabilities(fromAndTo[1].Substring(3, pieceStrLen)); return(new TurnRecord(new MoveRecord(null, from, to), new PromotionRecord(null, pieceCapabilities))); } else { return(new TurnRecord(new MoveRecord(null, from, to), capture)); } }
private async Task <TurnRecord> TurnFromPiecePositionChange(Piece pieceMoved, BoardPosition from, BoardPosition to, bool doGetPromotionSelectionIfNeeded) { TurnRecord turn = null; CaptureRecord capture = null; PromotionRecord promotion = null; var move = new MoveRecord(pieceMoved, from, to); Piece pieceCaptured = null; if ((pieceCaptured = _model.GetPieceAt(to)) != null) { capture = new CaptureRecord(pieceCaptured); } if (pieceMoved.Capabilities is PawnCapabilities) { // TODO: handle en passant if needed // promotion if (doGetPromotionSelectionIfNeeded && ((pieceMoved.Side == Side.White && to.Row == 7) || (pieceMoved.Side == Side.Black && to.Row == 0))) { var newCapability = await _board.GetPromotionSelectionAsync(); promotion = new PromotionRecord(pieceMoved, newCapability); } } if (capture != null || promotion != null) { turn = new TurnRecord(move, capture, promotion); } else if (IsMoveCastle(move)) { var kingMovedBy = move.To.Column - move.From.Column; var moveDirection = kingMovedBy / Math.Abs(kingMovedBy); var newCastlePosition = new BoardPosition((uint)(move.From.Column + moveDirection), move.From.Row); if (kingMovedBy < 0) { var castlePosition = new BoardPosition(0, move.From.Row); var castleToMove = _model.GetPieceAt(castlePosition); var secondaryMove = new MoveRecord(castleToMove, castlePosition, newCastlePosition); turn = new TurnRecord(move, secondaryMove); } else { var castlePosition = new BoardPosition(7, move.From.Row); var castleToMove = _model.GetPieceAt(castlePosition); var secondaryMove = new MoveRecord(castleToMove, castlePosition, newCastlePosition); turn = new TurnRecord(move, secondaryMove); } } else { turn = new TurnRecord(move); } return(turn); }
public void LoadEffects(BattleGroundSaveData battleSaveData) { #region Load Statuses and Immobilize for (int i = 0; i < HeroParty.Units.Count; i++) { if (HeroParty.Units[i].Character[StatusType.Stun].IsApplied) { HeroParty.Units[i].SetHalo("stunned"); } else if (HeroParty.Units[i].CombatInfo.IsSurprised) { HeroParty.Units[i].SetHalo("surprised"); } if (HeroParty.Units[i].CombatInfo.IsImmobilized) { HeroParty.Units[i].SetDefendAnimation(true); } if (HeroParty.Units[i].Character.IsMonster == false) { var hero = HeroParty.Units[i].Character as Hero; if (hero[StatusType.DeathsDoor].IsApplied) { hero.ApplyDeathDoor(); } else if (hero[StatusType.DeathRecovery].IsApplied) { hero.ApplyMortality(); } } } for (int i = 0; i < MonsterParty.Units.Count; i++) { if (MonsterParty.Units[i].Character[StatusType.Stun].IsApplied) { MonsterParty.Units[i].SetHalo("stunned"); } else if (MonsterParty.Units[i].CombatInfo.IsSurprised) { MonsterParty.Units[i].SetHalo("surprised"); } if (MonsterParty.Units[i].CombatInfo.IsImmobilized) { MonsterParty.Units[i].SetDefendAnimation(true); } if (MonsterParty.Units[i].Character.IsMonster == false) { MonsterParty.Units[i].SetCombatAnimation(true); var hero = MonsterParty.Units[i].Character as Hero; if (hero[StatusType.DeathsDoor].IsApplied) { hero.ApplyDeathDoor(); } else if (hero[StatusType.DeathRecovery].IsApplied) { hero.ApplyMortality(); } } } #endregion #region Load Captures for (int i = 0; i < battleSaveData.Captures.Count; i++) { CaptureRecord newCaptureRecord = new CaptureRecord(); int prisonerId = newCaptureRecord.GetHashPrisonerId(battleSaveData.Captures[i]); int captorId = newCaptureRecord.GetHashCaptorId(battleSaveData.Captures[i]); newCaptureRecord.RemoveFromParty = newCaptureRecord.GetHashRemoveFromParty(battleSaveData.Captures[i]); if (newCaptureRecord.RemoveFromParty == false) { FormationUnit prisoner = FindById(prisonerId); FormationUnit captor = FindById(captorId); newCaptureRecord.PrisonerUnit = prisoner; newCaptureRecord.CaptorUnit = captor; prisoner.SetCaptureEffect(captor); Captures.Add(newCaptureRecord); } else { FormationUnit prisoner = loadedRemovedPrisoners.Find(removedUnit => removedUnit.CombatInfo.CombatId == prisonerId); FormationUnit captor = FindById(captorId); prisoner.RectTransform.position = captor.RectTransform.position; newCaptureRecord.PrisonerUnit = prisoner; newCaptureRecord.CaptorUnit = captor; Captures.Add(newCaptureRecord); } } #endregion #region Load Companions for (int i = 0; i < battleSaveData.Companions.Count; i++) { CompanionRecord newCompanionRecord = new CompanionRecord(); int companionId = newCompanionRecord.GetHashCompanionId(battleSaveData.Companions[i]); int targetId = newCompanionRecord.GetHashTargetId(battleSaveData.Companions[i]); FormationUnit companion = FindById(companionId); FormationUnit target = FindById(targetId); newCompanionRecord.CompanionUnit = companion; newCompanionRecord.TargetUnit = target; Companions.Add(newCompanionRecord); } #endregion #region Load Controls for (int i = 0; i < battleSaveData.Controls.Count; i++) { ControlRecord newControlRecord = new ControlRecord(); int prisonerId = newControlRecord.GetHashPrisonerId(battleSaveData.Controls[i]); int controllerId = newControlRecord.GetHashControlId(battleSaveData.Controls[i]); newControlRecord.DurationLeft = newControlRecord.GetHashDurationLeft(battleSaveData.Controls[i]); FormationUnit prisoner = FindById(prisonerId); FormationUnit controller = FindById(controllerId); newControlRecord.PrisonerUnit = prisoner; newControlRecord.ControllUnit = controller; Controls.Add(newControlRecord); } #endregion loadedRemovedPrisoners.Clear(); RaidSceneManager.Formations.HeroOverlay.UpdateOverlay(); RaidSceneManager.Formations.monsters.overlay.UpdateOverlay(); }