fix: improve endgame clock and gameplay stability
This commit is contained in:
1 parent
ce6aabfc55
commit
658298ee86
46 files changed
+1915
-99
No files matched your search
@@ -6,9 +6,6 @@ import (
|
||||
)
|
||||
|
||||
func (s *Session) applyCurrencyWarsCommands() error {
|
||||
if !s.currencyWarsOpen {
|
||||
return nil
|
||||
}
|
||||
if _, active := CURRENT_BATTLE.Load(s.Token); active {
|
||||
return nil
|
||||
}
|
||||
@@ -23,10 +20,20 @@ func (s *Session) applyCurrencyWarsCommands() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// A pending grant can be blocked by a stuck page. Give the explicit quit
|
||||
// request priority so it can recover that run without applying the grant.
|
||||
for _, command := range commands {
|
||||
if command.UID == cfg.PlayerUID && command.Field == common.CurrencyWarsCommandEnd {
|
||||
return s.applyCurrencyWarsEnd(command)
|
||||
}
|
||||
}
|
||||
for _, command := range commands {
|
||||
if command.UID != cfg.PlayerUID {
|
||||
continue
|
||||
}
|
||||
if !s.currencyWarsOpen {
|
||||
continue
|
||||
}
|
||||
catalog, data, err := cwPreparingData(s)
|
||||
if err != nil {
|
||||
return nil
|
||||
@@ -62,3 +69,52 @@ func (s *Session) applyCurrencyWarsCommands() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// End is allowed even with a pending choice so it can recover a stuck CW UI.
|
||||
// Do not end a battle or replace a newer session's saved data. Queue removal,
|
||||
// archive and quit settlement share the same persistent CAS transaction.
|
||||
func (s *Session) applyCurrencyWarsEnd(command common.CurrencyWarsCommand) error {
|
||||
catalog, err := common.LoadCurrencyWarsCatalog()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data, revision, err := readCurrencyWarsData(catalog)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if data == nil || data.DHFOFLFCLAH == nil || data.DHFOFLFCLAH.UniqueId != command.RunID {
|
||||
if err := common.AcknowledgeCurrencyWarsCommand(command.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
PacketLog(fmt.Sprintf("CW_GM discarded end request=%s: run already ended or changed", command.ID))
|
||||
return nil
|
||||
}
|
||||
if revision != s.currencyWarsRevision {
|
||||
// If this session has not opened CW, it holds no CW UI state. Adopt the
|
||||
// freshly read revision; the CAS still rejects any concurrent changes.
|
||||
if s.currencyWarsOpen {
|
||||
return common.ErrCurrencyWarsSaveConflict
|
||||
}
|
||||
s.currencyWarsRevision = revision
|
||||
}
|
||||
keep, settle, err := currencyWarsQuitSettlement(catalog, data, data.DHFOFLFCLAH)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data.DHFOFLFCLAH = nil
|
||||
if err := s.saveCurrencyWarsTerminal(data, catalog, settle.BFLLJJBHLDF, command.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
wasOpen := s.currencyWarsOpen
|
||||
s.currencyWarsOpen = false
|
||||
if wasOpen {
|
||||
if err := cwSend(s, keep); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cwSend(s, settle); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
PacketLog(fmt.Sprintf("CW_GM applied end request=%s run=%d revision=%d result=quit", command.ID, command.RunID, s.currencyWarsRevision))
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user