Skip to content

Commit

Permalink
Added Sending position field to ship; Fixed bug with unloading nil re…
Browse files Browse the repository at this point in the history
…sources from ship; (#21)
  • Loading branch information
k-karuna authored Jul 26, 2024
1 parent 9499e81 commit 6ab14f3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions cardinal/component/effect.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Effect struct {
Speed float64 `json:"speed"`
Position [2]float64 `json:"position,omitempty"`
TargetPosition *[2]float64 `json:"targetPosition,omitempty"`
SendingPosition *[2]float64 `json:"sendingPosition,omitempty"`
BuildingTimeSeconds int `json:"buildingTimeSeconds,omitempty"`
BuildingTimeStartedAt uint64 `json:"buildingTimeStartedAt,omitempty"`
}
Expand Down
6 changes: 6 additions & 0 deletions cardinal/system/sail_ship.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ func SailShip(world cardinal.WorldContext) error {

if buildingComponent.Effect.Position == playerPosition.Island {
buildingComponent.Effect.TargetPosition = nil
buildingComponent.Effect.SendingPosition = nil
_ = unloadShip(world, buildingComponent.Effect)
} else if buildingComponent.Effect.Position == *buildingComponent.Effect.TargetPosition {
previousTargetPosition := buildingComponent.Effect.TargetPosition
buildingComponent.Effect.TargetPosition = &playerPosition.Island
buildingComponent.Effect.SendingPosition = previousTargetPosition
_ = lootShipwreck(world, buildingComponent.Effect)
}

Expand Down Expand Up @@ -106,6 +109,9 @@ func lootShipwreck(world cardinal.WorldContext, effect *comp.Effect) error {
}

func unloadShip(world cardinal.WorldContext, effect *comp.Effect) error {
if effect.LootResources == nil {
return nil
}
playerResourcesID, playerResources, _ := QueryPlayerComponent[comp.PlayerResources](
world,
effect.Player,
Expand Down
1 change: 1 addition & 0 deletions cardinal/system/start_sail_shipwreck_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func createSailData(
}
shipyardEffect := shipyard.Effect
shipyardEffect.TargetPosition = &targetPlayerPosition.Shipwreck
shipyardEffect.SendingPosition = &playerPosition.Island
err := updateEffect(world, shipyardEntityID, shipyard.Effect)
if err != nil {
return err
Expand Down

0 comments on commit 6ab14f3

Please sign in to comment.