Add character levels and permanent player titles

This commit is contained in:
dingo
2026-09-07 07:58:34 -04:00
parent 5a48a3c739
commit bc0ffbbbe5
30 changed files with 1594 additions and 62 deletions
+27 -15
View File
@@ -135,6 +135,8 @@ func (l *Lease) Save(ctx context.Context, w *game.World, claimID string) error {
return l.SaveCommand(ctx, w, claimID, nil, "")
}
func (l *Lease) SaveCommand(ctx context.Context, w *game.World, claimID string, command *Command, outcome string) error {
live := w
w = stageTitleWorld(w)
data, err := json.Marshal(w)
if err != nil {
return err
@@ -167,20 +169,26 @@ func (l *Lease) SaveCommand(ctx context.Context, w *game.World, claimID string,
return errors.New("passage already redeemed or unavailable")
}
}
if w.Phase == "won" {
for _, c := range w.Characters {
if c.View.Entity.State != "eligible" {
continue
}
encoded, err := json.Marshal(c)
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, d.q(`INSERT INTO passages(character_id,account_id,source_world,character) VALUES(?,?,?,?) ON CONFLICT(character_id) DO UPDATE SET source_world=excluded.source_world,character=excluded.character,claimed_world=NULL WHERE passages.claimed_world=excluded.source_world`), c.View.Entity.ID, c.Account, w.ID, string(encoded))
if err != nil {
return err
}
}
if err = d.syncPassages(ctx, tx, w); err != nil {
return err
}
if err = d.syncCharacters(ctx, tx, w, claimID); err != nil {
return err
}
if err = d.syncTitles(ctx, tx, w); err != nil {
return err
}
// Rewrite the final payloads after the immutable award claims have resolved.
// The transaction already holds the owner, passage and character row locks.
data, err = json.Marshal(w)
if err != nil {
return err
}
if _, err = tx.ExecContext(ctx, d.q(`UPDATE worlds SET snapshot=? WHERE id=? AND owner=?`), string(data), l.WorldID, l.Owner); err != nil {
return err
}
if err = d.syncPassages(ctx, tx, w); err != nil {
return err
}
if err = d.syncCharacters(ctx, tx, w, claimID); err != nil {
return err
@@ -208,7 +216,11 @@ func (l *Lease) SaveCommand(ctx context.Context, w *game.World, claimID string,
return err
}
l.Revision++
w.Saved()
for id, c := range w.Characters {
live.Characters[id].View.Titles = c.View.Titles
}
live.PendingTitles = nil
live.Saved()
return nil
}
func (l *Lease) Release(ctx context.Context) error {