allows to use existing tx
@@ -23,6 +23,7 @@ func (f FleetBuilderFactory) NewFleet() *FleetBuilder {
// FleetBuilder ...
type FleetBuilder struct {
b Wrapper
+ tx *Prioritize
origin Celestial
destination Coordinate
speed Speed
@@ -49,6 +50,12 @@ func NewFleetBuilder(b Wrapper) *FleetBuilder {
return fb
}
+// SetTx ...
+func (f *FleetBuilder) SetTx(tx *Prioritize) *FleetBuilder {
+ f.tx = tx
+ return f
+}
+
// SetOrigin ...
func (f *FleetBuilder) SetOrigin(v interface{}) *FleetBuilder {
f.origin = f.b.GetCachedCelestial(v)
@@ -169,17 +176,19 @@ func (f *FleetBuilder) SetRecallIn(secs int64) *FleetBuilder {
func (f *FleetBuilder) FlightTime() (secs, fuel int64) {
ships := f.ships
if f.allShips {
+ if f.tx != nil {
+ ships, _ = f.tx.GetShips(f.origin.GetID())
+ } else {
ships, _ = f.b.GetShips(f.origin.GetID())
}
+ }
return f.b.FlightTime(f.origin.GetCoordinate(), f.destination, f.speed, ships)
}
-// SendNow send the fleet with defined configurations
-func (f *FleetBuilder) SendNow() (Fleet, error) {
- err := f.b.Tx(func(tx *Prioritize) error {
-
+func (f *FleetBuilder) sendNow(tx *Prioritize) error {
if f.origin == nil {
- return errors.New("invalid origin")
+ f.err = errors.New("invalid origin")
+ return f.err
}
// Set all ships
@@ -228,7 +237,18 @@ func (f *FleetBuilder) SendNow() (Fleet, error) {
f.fleet, f.err = tx.EnsureFleet(f.origin.GetID(), f.ships.ToQuantifiables(), f.speed, f.destination, f.mission, payload, f.expeditiontime, f.unionID)
return f.err
+}
+
+// SendNow send the fleet with defined configurations
+func (f *FleetBuilder) SendNow() (Fleet, error) {
+ var err error
+ if f.tx != nil {
+ err = f.sendNow(f.tx)
+ } else {
+ err = f.b.Tx(func(tx *Prioritize) error {
+ return f.sendNow(tx)
})
+ }
if err != nil {
// On error, call error callbacks
for _, clb := range f.errorCallbacks {
