Skip to content

Commit

Permalink
Linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
k-karuna committed Jul 22, 2024
1 parent 65eed13 commit 262798c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 39 deletions.
6 changes: 2 additions & 4 deletions cardinal/query/all_ships.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ import (
"pkg.world.dev/world-engine/cardinal/search/filter"
)

type AllShipsRequest struct {
Nickname string
}
type AllShipsRequest struct{}

// AllShips -
func AllShips(world cardinal.WorldContext, req *AllShipsRequest) (*map[string]comp.Effect, error) {
func AllShips(world cardinal.WorldContext, _ *AllShipsRequest) (*map[string]comp.Effect, error) {
_, effects, err := system.QueryAllComponents[comp.Effect](
world,
filter.Component[comp.Player](),
Expand Down
10 changes: 7 additions & 3 deletions cardinal/system/sail_ship.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ func SailShip(world cardinal.WorldContext) error {
}

buildingComponent, _ := cardinal.GetComponent[comp.Building](world, id)
RaftTravelDistancePerTick := constants.RaftTravelSpeedPerMinute / time.Minute.Seconds() * constants.TickRate.Seconds()
raftTravelDistancePerTick :=
constants.RaftTravelSpeedPerMinute / time.Minute.Seconds() * constants.TickRate.Seconds()

buildingComponent.Effect.Position = findPointAtDistance(
buildingComponent.Effect.Position,
*buildingComponent.Effect.TargetPosition,
RaftTravelDistancePerTick,
raftTravelDistancePerTick,
)

updateEffect(world, id, buildingComponent.Effect)
err := updateEffect(world, id, buildingComponent.Effect)
if err != nil {
return true
}
return true
})
}
Expand Down
73 changes: 42 additions & 31 deletions cardinal/system/start_sail_shipwreck_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ func StartSailShipwreckSystem(world cardinal.WorldContext) error {
return msg.SailShipWreckResult{Success: false}, err
}

playerBuildingsEntityIDs, playerBuildings, _ := QueryAllPlayerComponents[comp.Building](
world,
request.Tx.PersonaTag,
filter.Component[comp.Player](),
filter.Component[comp.Building](),
)

if playerPosition == nil {
return msg.SailShipWreckResult{Success: false},
fmt.Errorf("failed to sail shipwreck, this player did not have tilemap")
Expand All @@ -51,32 +44,50 @@ func StartSailShipwreckSystem(world cardinal.WorldContext) error {
if player.Nickname != request.Tx.PersonaTag {
return msg.SailShipWreckResult{Success: false}, fmt.Errorf("can't sail another player building")
}

var shipyard *comp.Building
var shipyardEntityID types.EntityID
for playerBuildingID, playerBuilding := range playerBuildings {
if playerBuilding.Type != comp.Shipyard {
continue
}
if playerBuilding.Effect.Amount == 0 {
continue
}
if playerBuilding.Effect.Position != playerPosition.Island {
continue
}
shipyard = playerBuilding
shipyardEntityID = playerBuildingsEntityIDs[playerBuildingID]
}

if shipyard == nil {
return msg.SailShipWreckResult{Success: false}, fmt.Errorf("player didn't have ships on base")
}
shipyardEffect := shipyard.Effect
shipyardEffect.TargetPosition = &targetPlayerPosition.Shipwreck
err = updateEffect(world, shipyardEntityID, shipyard.Effect)
err = createSailData(world, request.Tx.PersonaTag, playerPosition, targetPlayerPosition)
if err != nil {
return msg.SailShipWreckResult{Success: false}, err
}
return msg.SailShipWreckResult{Success: true}, nil
return msg.SailShipWreckResult{Success: true}, err
})
}

func createSailData(
world cardinal.WorldContext,
personaTag string,
playerPosition *comp.Position,
targetPlayerPosition *comp.Position) error {
playerBuildingsEntityIDs, playerBuildings, _ := QueryAllPlayerComponents[comp.Building](
world,
personaTag,
filter.Component[comp.Player](),
filter.Component[comp.Building](),
)

var shipyard *comp.Building
var shipyardEntityID types.EntityID
for playerBuildingID, playerBuilding := range playerBuildings {
if playerBuilding.Type != comp.Shipyard {
continue
}
if playerBuilding.Effect.Amount == 0 {
continue
}
if playerBuilding.Effect.Position != playerPosition.Island {
continue
}
shipyard = playerBuilding
shipyardEntityID = playerBuildingsEntityIDs[playerBuildingID]
}

if shipyard == nil {
return fmt.Errorf("player didn't have ships on base")
}
shipyardEffect := shipyard.Effect
shipyardEffect.TargetPosition = &targetPlayerPosition.Shipwreck
err := updateEffect(world, shipyardEntityID, shipyard.Effect)
if err != nil {
return err
}
return err
}
1 change: 0 additions & 1 deletion cardinal/system/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ func GetTotalPlayersAmount(world cardinal.WorldContext) (int, error) {
}

func updateEffect(world cardinal.WorldContext, buildingEntityID types.EntityID, effect *comp.Effect) error {

building, _ := cardinal.GetComponent[comp.Building](world, buildingEntityID)
player, _ := cardinal.GetComponent[comp.Player](world, buildingEntityID)
mapEntityID, playerMap, _ := QueryPlayerComponent[comp.TileMap](
Expand Down

0 comments on commit 262798c

Please sign in to comment.