Skip to content

Commit

Permalink
moved responsibility for determing the type of un/mounting entity to …
Browse files Browse the repository at this point in the history
…specific subclass rather than generic parent class (#1184)
  • Loading branch information
Fate-JH authored Mar 29, 2024
1 parent b7dc2b6 commit 9319f7e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2021 PSForever
package net.psforever.objects.serverobject.mount

import net.psforever.objects.Player
import net.psforever.types.BailType

trait MountableSpace[A <: MountableEntity] {
Expand Down Expand Up @@ -93,10 +92,6 @@ trait MountableSpace[A <: MountableEntity] {
case Some(p) if testToUnmount(p) =>
_occupant = None
p.BailProtection = bailable && (bailType == BailType.Bailed || bailType == BailType.Kicked)
p match {
case player: Player =>
player.VehicleSeated = None
}
None
case _ =>
occupant
Expand Down
10 changes: 10 additions & 0 deletions src/main/scala/net/psforever/objects/serverobject/mount/Seat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@
package net.psforever.objects.serverobject.mount

import net.psforever.objects.Player
import net.psforever.types.BailType

class Seat(private val sdef: SeatDefinition) extends MountableSpace[Player] {
override protected def testToMount(target: Player): Boolean = target.VehicleSeated.isEmpty && super.testToMount(target)

override def unmount(target: Option[Player], bailType: BailType.Value): Option[Player] = {
val outcome = super.unmount(target, bailType)
target.collect {
case p if outcome.isEmpty && !isOccupiedBy(p) =>
p.VehicleSeated = None
}
outcome
}

def definition: SeatDefinition = sdef
}
10 changes: 10 additions & 0 deletions src/main/scala/net/psforever/objects/vehicles/Cargo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@ package net.psforever.objects.vehicles

import net.psforever.objects.Vehicle
import net.psforever.objects.serverobject.mount.{MountableSpace, MountableSpaceDefinition}
import net.psforever.types.BailType

class Cargo(private val cdef: MountableSpaceDefinition[Vehicle]) extends MountableSpace[Vehicle] {
override def unmount(target: Option[Vehicle], bailType: BailType.Value): Option[Vehicle] = {
val outcome = super.unmount(target, bailType)
target.collect {
case v if outcome.isEmpty && !isOccupiedBy(v) =>
v.MountedIn = None
}
outcome
}

def definition: MountableSpaceDefinition[Vehicle] = cdef
}
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,6 @@ object CarrierBehavior {
hold: Cargo,
bailType: BailType.Value
): Unit = {
cargo.MountedIn = None
hold.unmount(cargo, bailType)
val event = VehicleCargoMountActivity(VehicleSource(carrier), VehicleSource(cargo), carrier.Zone.Number)
cargo.LogActivity(event)
Expand Down

0 comments on commit 9319f7e

Please sign in to comment.