Exemplo n.º 1
0
    def CreateCommandPin(self, charID, typeID, latitude, longitude):
        if charID in self.colonies:
            colony = self.GetColony(charID)
            if colony is not None and colony.colonyData is not None and colony.colonyData.commandPin is not None:
                raise UserError('CannotBuildMultipleCommandPins')
        if session.shipid is None:
            raise UserError('CannotBuildCommandPinWithoutShip')
        shipInv = sm.GetService('invCache').GetInventoryFromId(session.shipid)
        commandCenterID = None
        invList = shipInv.List(const.flagSpecializedCommandCenterHold)
        invList.extend(shipInv.List(const.flagCargo))
        for item in invList:
            if item.typeID == typeID:
                commandCenterID = item.itemID
                break

        if commandCenterID is None:
            raise UserError('CannotBuildCommandPin')
        colony = self.GetNewColony(charID)
        self.colonies[charID] = colony
        self.colony = colony
        colony.SetColonyData(ColonyData(charID, None))
        colony.ValidateCreatePin(charID, typeID, latitude, longitude)
        wasInEditMode = self.IsInEditMode()
        self._EnterEditMode()
        colony.colonyData.PrimePin(commandCenterID, typeID, charID, latitude, longitude)
        self.changes.AddCommand(commandStream.COMMAND_CREATEPIN, pinID=commandCenterID, typeID=typeID, latitude=latitude, longitude=longitude)
        self.commandPinChange = CP_COMMANDPINADDED
        sm.ScatterEvent('OnPlanetPinPlaced', commandCenterID)
        sm.ScatterEvent('OnEditModeBuiltOrDestroyed')
        pin = colony.GetPin(commandCenterID)
        pin.inEditMode = True
        level = sm.GetService('godma').GetTypeAttribute(typeID, const.attributeMetaLevel)
        colony.colonyData.SetLevel(level)
        return pin
Exemplo n.º 2
0
 def _EnterEditMode(self):
     """
         This is an internal use method. If a snapshot has not yet been taken,
         this method takes one and stores it as self.backupData.
         
         It also sets up the Edit Mode Pause Timestamp, which is used to
         perform fun time-freezing logic on the client.
         
         RevertChanges will attempt to restore this data into the user's
         colony, while SubmitChanges will wipe it out if the submission
         was successful.
     """
     if not self.colony:
         colony = self.GetColony(session.charid)
         if colony is None:
             self.LogInfo('No colony found, creating a blank one')
             colony = self.GetNewColony(session.charid)
             colony.SetColonyData(ColonyData(session.charid, None))
             self.colonies[session.charid] = colony
             self.colony = colony
         else:
             self.colony = colony
     if not self.isInEditMode:
         self.backupData = self.colony.colonyData.GetCopy()
         self.backupData.SetEventHandler(self)
         self.enteredEditModeTime = blue.os.GetWallclockTime()
         self.StopTicking()
         self.isInEditMode = True
         sm.GetService('planetUI').EnteredEditMode(self.planetID)
Exemplo n.º 3
0
 def _EnterEditMode(self):
     if not self.colony:
         colony = self.GetColony(session.charid)
         if colony is None:
             self.LogInfo('No colony found, creating a blank one')
             colony = self.GetNewColony(session.charid)
             colony.SetColonyData(ColonyData(session.charid, None))
             self.colonies[session.charid] = colony
             self.colony = colony
         else:
             self.colony = colony
     if not self.isInEditMode:
         self.backupData = self.colony.colonyData.GetCopy()
         self.backupData.SetEventHandler(self)
         self.enteredEditModeTime = blue.os.GetWallclockTime()
         self.StopTicking()
         self.isInEditMode = True
         sm.GetService('planetUI').EnteredEditMode(self.planetID)
Exemplo n.º 4
0
    def SubmitChanges(self):
        simulationEndTime = None
        if self.commandPinChange == CP_COMMANDPINREMOVED:
            self.remoteHandler.UserAbandonPlanet()
            newColonyData = ColonyData(session.charid, None)
            self.colonies[session.charid].SetColonyData(newColonyData)
        else:
            serializedChanges = self.changes.Serialize()
            try:
                updatedColony = self.remoteHandler.UserUpdateNetwork(serializedChanges)
            except Exception:
                self.changes.LogCommandStream(self)
                raise

            self._PrimeColony(session.charid, updatedColony)
        if self.commandPinChange != CP_NOCHANGE:
            sm.GetService('neocom').Blink('factories')
            sm.GetService('planetSvc').ScatterOnPlanetCommandCenterDeployedOrRemoved(self.planetID)
        self._ExitEditMode()
        sm.ScatterEvent('OnPlanetChangesSubmitted', self.planetID)
Exemplo n.º 5
0
    def _PrimeColony(self, ownerID, serializedColony):
        if ownerID not in self.colonies:
            self.colonies[ownerID] = colony = self.GetNewColony(ownerID)
        else:
            colony = self.GetColony(ownerID)
        freshColonyData = ColonyData(session.charid, None)
        colony.SetColonyData(freshColonyData)
        freshColonyData.SetLevel(serializedColony.level)
        for pin in serializedColony.pins:
            freshColonyData.RestorePinFromRow(pin)

        for linkData in serializedColony.links:
            freshColonyData.RestoreLinkFromRow(linkData)

        for route in serializedColony.routes:
            freshColonyData.RestoreRouteFromRow(route)

        colony.currentSimTime = serializedColony.currentSimTime
        colony.PrimeSimulation(serializedColony.currentSimTime)
        self.colonies[ownerID] = colony
        self.colony = colony
        return colony