private void SwapPositions(Position pos1, Position pos2) { if (IsDiffOwnerOfPosition(pos1, pos2)) { Debug.LogError("Can't move to an opponent's position"); return; } Chr chr1 = pos1.chrOnPosition; Chr chr2 = pos2.chrOnPosition; //Update both positions pos1.SetChrOnPosition(chr2); pos2.SetChrOnPosition(chr1); //Update both characters if (chr1 != null) { chr1.SetPosition(pos2); } if (chr2 != null) { chr2.SetPosition(pos1); } }
//Interface for modifying Positions public void MoveChrToPosition(Chr chr, Position pos) { Position posStarting = chr.position; if (posStarting != null && IsDiffOwnerOfPosition(posStarting, pos)) { Debug.LogError("Can't move to an opponent's position"); return; } if (pos.positiontype == Position.POSITIONTYPE.BENCH) { Debug.LogError("Can't standardly move to a bench position"); return; } if (pos.chrOnPosition != null) { Debug.LogError("Can't move " + chr.sName + " to " + pos.ToString() + " since it's occupied by " + pos.chrOnPosition.sName); return; } //Vacate the current space if (posStarting != null) { posStarting.SetChrOnPosition(null); } //Place this character on the target position pos.SetChrOnPosition(chr); chr.SetPosition(pos); //Send updates out for all affected character/positions (in reverse order so they take effect in chronological order) pos.subChrEnteredPosition.NotifyObs(chr); chr.subEnteredPosition.NotifyObs(pos); if (posStarting != null) { posStarting.subChrLeftPosition.NotifyObs(chr); } chr.subLeftPosition.NotifyObs(posStarting); }