Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Sending position field to ship; Fixed bug with unloading nil re… #21

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading