Skip to content
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,704 changes: 1,335 additions & 369 deletions api/structs/structs/events.pulsar.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions proto/structs/structs/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ option go_package = "structs/x/structs/types";
message EventOreMigrate { EventOreMigrateDetail eventOreMigrateDetail = 1;}
message EventOreMigrateDetail { string playerId = 1; string primaryAddress = 2; string oldPrimaryAddress = 3; uint64 amount = 4;}

message EventStructDefenderClear { EventStructDefenderClearDetail structDefenderClearDetail = 1; }
message EventStructDefenderClearDetail { string defendingStructId = 1; }

message EventAttack { EventAttackDetail eventAttackDetail = 1; }

message EventAttackDetail {
Expand Down
101 changes: 100 additions & 1 deletion x/structs/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
abci "github.com/cometbft/cometbft/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"structs/x/structs/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)

// BeginBlocker will persist the current header and validator set as a historical entry
Expand Down Expand Up @@ -96,7 +97,105 @@ func (k *Keeper) EventAllGenesis(ctx context.Context) {
_ = ctxSDK.EventManager().EmitTypedEvent(&types.EventStructType{StructType: &structType})
}

// Banking
// Allocation
allocations := k.GetAllAllocation(ctx)
for _, allocation := range allocations {
_ = ctxSDK.EventManager().EmitTypedEvent(&types.EventAllocation{Allocation: &allocation})
}

// Agreement
agreements := k.GetAllAgreement(ctx)
for _, agreement := range agreements {
_ = ctxSDK.EventManager().EmitTypedEvent(&types.EventAgreement{Agreement: &agreement})
}

// Fleet
fleets := k.GetAllFleet(ctx)
for _, fleet := range fleets {
_ = ctxSDK.EventManager().EmitTypedEvent(&types.EventFleet{Fleet: &fleet})
}

// Guild (+ bank addresses)
guilds := k.GetAllGuild(ctx)
for _, guild := range guilds {
_ = ctxSDK.EventManager().EmitTypedEvent(&types.EventGuild{Guild: &guild})
_ = ctxSDK.EventManager().EmitTypedEvent(&types.EventGuildBankAddress{
&types.EventGuildBankAddressDetail{
GuildId: guild.Id,
BankCollateralPool: authtypes.NewModuleAddress(types.GuildBankCollateralPool + guild.Id).String(),
BankTokenPool: types.ModuleName,
},
})
}


// Planet
planets := k.GetAllPlanet(ctx)
for _, planet := range planets {
_ = ctxSDK.EventManager().EmitTypedEvent(&types.EventPlanet{Planet: &planet})
}

// Planet attributes
planetAttrs := k.GetAllPlanetAttributeExport(ctx)
for _, attr := range planetAttrs {
_ = ctxSDK.EventManager().EmitTypedEvent(&types.EventPlanetAttribute{attr})
}

// Provider (+ addresses)
providers := k.GetAllProvider(ctx)
for _, provider := range providers {
_ = ctxSDK.EventManager().EmitTypedEvent(&types.EventProvider{Provider: &provider})
_ = ctxSDK.EventManager().EmitTypedEvent(&types.EventProviderAddress{
&types.EventProviderAddressDetail{
ProviderId: provider.Id,
CollateralPool: authtypes.NewModuleAddress(types.ProviderCollateralPool + provider.Id).String(),
EarningPool: authtypes.NewModuleAddress(types.ProviderEarningsPool + provider.Id).String(),
},
})
}

// Provider guild access
providerAccess := k.GetAllProviderGuildAccessExport(ctx)
for _, entry := range providerAccess {
_ = ctxSDK.EventManager().EmitTypedEvent(&types.EventProviderGrantGuild{
&types.EventProviderGrantGuildDetail{ProviderId: entry.ProviderId, GuildId: entry.GuildId},
})
}

// Struct
structs := k.GetAllStruct(ctx)
for _, s := range structs {
_ = ctxSDK.EventManager().EmitTypedEvent(&types.EventStruct{Structure: &s})
}

// Struct attributes
structAttrs := k.GetAllStructAttributeExport(ctx)
for _, attr := range structAttrs {
_ = ctxSDK.EventManager().EmitTypedEvent(&types.EventStructAttribute{attr})
}

// Struct defenders
defenders := k.GetAllStructDefenderExport(ctx)
for _, d := range defenders {
_ = ctxSDK.EventManager().EmitTypedEvent(&types.EventStructDefender{StructDefender: d})
}

// Substation
substations := k.GetAllSubstation(ctx)
for _, s := range substations {
_ = ctxSDK.EventManager().EmitTypedEvent(&types.EventSubstation{Substation: &s})
}

// Guild membership applications
apps := k.GetAllGuildMembershipApplicationExport(ctx)
for _, app := range apps {
_ = ctxSDK.EventManager().EmitTypedEvent(&types.EventGuildMembershipApplication{GuildMembershipApplication: &app})
}

// Halted players
halted := k.GetAllHaltedPlayerId(ctx)
for _, playerId := range halted {
_ = ctxSDK.EventManager().EmitTypedEvent(&types.EventPlayerHalted{PlayerId: playerId})
}

}
8 changes: 8 additions & 0 deletions x/structs/keeper/fleet_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,14 @@ func (cache *FleetCache) MigrateToNewPlanet(destination *PlanetCache) {
newFleet := cache.K.AppendFleet(cache.Ctx, cache.GetOwner())
cache.Fleet = newFleet
cache.FleetLoaded = true

// Build an Initial Command Ship
structure := cache.K.InitialCommandShipStruct(cache.Ctx, cache.GetOwner())
// TODO Not a huge fan that this is committed separately
// Could change cache.commit() to comment the command struct too
// but that would need SetCommandStruct to accept the StructCache instead of Struct.
structure.Commit()
cache.SetCommandStruct(structure.GetStruct())
}
}

Expand Down
13 changes: 0 additions & 13 deletions x/structs/keeper/msg_server_struct_build_cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,6 @@ func (k msgServer) StructBuildCancel(goCtx context.Context, msg *types.MsgStruct
return &types.MsgStructStatusResponse{}, sdkerrors.Wrapf(types.ErrGridMalfunction, "Struct (%s) already built", msg.StructId)
}

// Check Player Charge
if (structure.GetOwner().GetCharge() < structure.GetStructType().BuildCharge) {
err := sdkerrors.Wrapf(types.ErrInsufficientCharge, "Struct Type (%d) required a charge of %d to build, but player (%s) only had %d", structure.GetStructType().Id, structure.GetStructType().BuildCharge, structure.GetOwnerId(), structure.GetOwner().GetCharge() )
structure.GetOwner().Discharge()
structure.GetOwner().Commit()
return &types.MsgStructStatusResponse{}, err
}

if structure.GetOwner().IsOffline(){
return &types.MsgStructStatusResponse{}, sdkerrors.Wrapf(types.ErrGridMalfunction, "The player (%s) is offline ",structure.GetOwnerId())
}


structure.DestroyAndCommit()

return &types.MsgStructStatusResponse{Struct: structure.GetStruct()}, nil
Expand Down
53 changes: 53 additions & 0 deletions x/structs/keeper/struct_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,59 @@ func (k *Keeper) GetStructCacheFromId(ctx context.Context, structId string) (Str
}
}


func (k *Keeper) InitialCommandShipStruct(ctx context.Context, owner *PlayerCache) (StructCache) {

structType, _ := k.GetStructType(ctx, types.CommandStructTypeId)

structure := types.CreateBaseStruct(&structType, owner.GetPrimaryAddress(), owner.GetPlayerId(), structType.Category, types.Ambit_space)
structure = k.AppendStruct(ctx, structure)

owner.BuildQuantityIncrement(structType.GetId())

var structStatus types.StructState
if owner.CanSupportLoadAddition(structType.GetPassiveDraw()) {
owner.StructsLoadIncrement(structType.GetPassiveDraw())
structStatus = types.StructState(types.StructStateMaterialized | types.StructStateBuilt | types.StructStateOnline)
} else {
structStatus = types.StructState(types.StructStateMaterialized | types.StructStateBuilt )
}

// Start to put the pieces together
structCache := StructCache{
StructId: structure.Id,
K: k,
Ctx: ctx,

AnyChange: true,

Structure: structure,
StructureChanged: false,
StructureLoaded: true,

Owner: owner,
OwnerLoaded: true,

Fleet: owner.GetFleet(),
FleetLoaded: true,

// Include the health value
HealthAttributeId: GetStructAttributeIDByObjectId(types.StructAttributeType_health, structure.Id),
HealthChanged: true,
HealthLoaded: true,
Health: structType.GetMaxHealth(),

// Include the initial status value
StatusAttributeId: GetStructAttributeIDByObjectId(types.StructAttributeType_status, structure.Id),
StatusChanged: true,
StatusLoaded: true,
Status: structStatus,
}

return structCache
}


// Build this initial Struct Cache object
// This does no validation on the provided structId
func (k *Keeper) InitiateStruct(ctx context.Context, creatorAddress string, owner *PlayerCache, structType *types.StructType, ambit types.Ambit, slot uint64) (StructCache, error) {
Expand Down
3 changes: 3 additions & 0 deletions x/structs/keeper/struct_defender.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ func (k Keeper) DestroyStructDefender(ctx context.Context, structDefenderId stri
func (k Keeper) RemoveStructDefender(ctx context.Context, protectedStructId string, structDefenderId string) {
store := prefix.NewStore(runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)), DefenderKeyPrefix(protectedStructId))
store.Delete([]byte(structDefenderId))

ctxSDK := sdk.UnwrapSDKContext(ctx)
_ = ctxSDK.EventManager().EmitTypedEvent(&types.EventStructDefenderClear{&types.EventStructDefenderClearDetail{DefendingStructId: structDefenderId}})
}

// GetAllStructDefender returns all struct defenders for a specific struct
Expand Down
4 changes: 2 additions & 2 deletions x/structs/module/autocli.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
{
RpcMethod: "Guild",
Use: "guild [guild id]",
Short: "Show the details of a specific Allocation",
Short: "Show the details of a specific Guild",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "id"}},
},
{
Expand Down Expand Up @@ -559,7 +559,7 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
{
RpcMethod: "PlayerUpdatePrimaryAddress",
Use: "player-update-primary-address [address]",
Short: "Revoke a set of permissions on from an address",
Short: "Update the primary address for a player",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "primaryAddress"}},
},
{
Expand Down
Loading
Loading