Ejemplo n.º 1
0
        public bool HandleTransaction(PUTInventoryItemTransactionStart transactionStart, PUTInventoryItemTransactionEnd transactionEnd)
        {
            if (transactionEnd.success)
            {
                PlayerStore store;
                if (!mPlayerStoreCache.TryGetValue(transactionEnd.characterID, out store))
                {
                    return(false);
                }

                switch ((PostTransactionAction)transactionStart.postTransactionAction)
                {
                case PostTransactionAction.BuyStoreItem:
                {
                    int price = (int)transactionStart.tag;
                    if (store.RemoveCredits(price))
                    {
                        SendConsumablePurchaseStatus(transactionStart.gameRefID, true);
                        return(true);
                    }
                    SendConsumablePurchaseStatus(transactionStart.gameRefID, false);
                    return(false);
                }

                default:
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Start transaction of moving item from bank to player station
 /// itemid - id of inventory item in bank
 /// count - count of items to move
 /// server id - id of server where transaction handler placed
 /// </summary>
 public bool MoveItemToStation(string itemid, int count, string serverId)
 {
     if (isUserRegisterd)
     {
         if (bank != null)
         {
             var item = bank.GetItem(itemid);
             if (item.Count >= count)
             {
                 PUTInventoryItemTransactionStart start = new PUTInventoryItemTransactionStart {
                     characterID           = characterId,
                     count                 = count,
                     gameRefID             = id,
                     itemID                = itemid,
                     postTransactionAction = (byte)PostTransactionAction.WithdrawFromBank,
                     inventoryType         = (byte)InventoryType.station,
                     tag                    = 0,
                     targetObject           = item.GetInfo(),
                     transactionID          = Guid.NewGuid().ToString(),
                     transactionSource      = (byte)TransactionSource.Bank,
                     transactionStartServer = SelectCharacterApplication.ServerId.ToString(),
                     transactionEndServer   = serverId
                 };
                 EventData eventData = new EventData((byte)S2SEventCode.PUTInventoryItemStart, start);
                 mPutPool.StartTransaction(start);
                 application.MasterPeer.SendEvent(eventData, new SendParameters());
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Place item to player mail and send back transaction end
        /// </summary>
        /// <param name="eventData">Input event data</param>
        /// <param name="sendParameters">Input send parameters</param>
        private void HandlePutMailTransactionStart(IEventData eventData, SendParameters sendParameters)
        {
            var       startTransaction = new PUTInventoryItemTransactionStart(eventData);
            var       endTransaction   = application.Mail.HandlePutMailTransactionStart(startTransaction);
            EventData evt = new EventData((byte)S2SEventCode.PUTMaiTransactionEnd, endTransaction);

            SendEvent(evt, sendParameters);
            log.InfoFormat("Put Mail Transaction End Returned to Source :red");
        }
Ejemplo n.º 4
0
 public bool HandleTransaction(PUTInventoryItemTransactionStart transactionStart, PUTInventoryItemTransactionEnd transactionEnd)
 {
     if (transactionEnd.success)
     {
         //after putting item to station remove item from bank
         if (transactionStart.postTransactionAction == (byte)PostTransactionAction.WithdrawFromBank)
         {
             if (bank != null)
             {
                 bank.RemoveItem(transactionStart.itemID, transactionStart.count);
                 SendBankUpdate();
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Send event to put item to inventory
        /// </summary>
        /// <param name="login">Login os player</param>
        /// <param name="gameRefID">Game ref ID of player</param>
        /// <param name="characterID">Character of player</param>
        /// <param name="count">Count of item will be putted</param>
        /// <param name="inventoryType">Inventory type of where to put item</param>
        /// <param name="itemID">ID item of will be putted</param>
        /// <param name="action">Action after success complete transaction</param>
        /// <param name="tag">Some tag information with transaction</param>
        /// <param name="objectData">Object Data of item will be putted</param>
        private void PutItemToInventory(string login,
                                        string gameRefID,
                                        string characterID,
                                        int count,
                                        InventoryType inventoryType,
                                        string itemID,
                                        PostTransactionAction action,
                                        object tag,
                                        object objectData,
                                        string targetServer)
        {
            var playerStore = GetOrCreatePlayerStore(login, gameRefID, characterID);

            if (playerStore == null)
            {
                log.Info("PutItemToInventory: player store is null");
                return;
            }

            PUTInventoryItemTransactionStart start = new PUTInventoryItemTransactionStart {
                characterID           = characterID,
                count                 = count,
                gameRefID             = gameRefID,
                inventoryType         = (byte)inventoryType,
                itemID                = itemID,
                postTransactionAction = (byte)action,
                tag                    = tag,
                targetObject           = objectData,
                transactionSource      = (byte)TransactionSource.Store,
                transactionID          = Guid.NewGuid().ToString(),
                transactionEndServer   = targetServer,
                transactionStartServer = SelectCharacterApplication.ServerId.ToString()
            };
            EventData evt = new EventData((byte)S2SEventCode.PUTInventoryItemStart, start);

            mPutTransactionPool.StartTransaction(start);
            mApplication.MasterPeer.SendEvent(evt, new SendParameters());
            log.Info("store PUT transaction started...");
        }
Ejemplo n.º 6
0
    private void HandlePUTInventoryItemStart(IEventData eventData, SendParameters sendParameters)
    {
        //log.Info("HandlePUTInventoryItemStart: PUT inventory item event received");
        PUTInventoryItemTransactionStart start = new PUTInventoryItemTransactionStart(eventData);

        try {
            MmoActor player;
            if (!m_App.serverActors.TryGetValue(start.gameRefID, out player))
            {
                log.InfoFormat("HandlePUTInventoryItemStart: player = {0} not founded on server", start.gameRefID);
                return;
            }

            PUTInventoryItemTransactionEnd end = new PUTInventoryItemTransactionEnd {
                characterID            = start.characterID,
                gameRefID              = start.gameRefID,
                inventoryType          = start.inventoryType,
                itemID                 = start.itemID,
                count                  = start.count,
                transactionID          = start.transactionID,
                transactionSource      = start.transactionSource,
                transactionStartServer = start.transactionStartServer,
                transactionEndServer   = start.transactionEndServer
            };

            InventoryType invType = (InventoryType)start.inventoryType;
            if (invType == InventoryType.ship || invType == InventoryType.station)
            {
                var inventory  = (invType == InventoryType.ship) ? player.Inventory : player.Station.StationInventory;
                int count      = 0;
                var itemObject = InventoryUtils.Create(start.targetObject as Hashtable, out count);
                count = start.count;

                if (!inventory.EnoughSpace(new Dictionary <string, InventoryObjectType> {
                    { itemObject.Id, itemObject.Type }
                }))
                {
                    end.success = false; end.result = 1; end.returnCode = (short)ReturnCode.NotEnoughInventorySpace;
                }
                else
                {
                    if (!inventory.Add(itemObject, count))
                    {
                        end.success = false; end.result = 1; end.returnCode = (short)ReturnCode.ErrorAddingToInventory;
                    }
                    else
                    {
                        end.success = true; end.result = 0; end.returnCode = (short)ReturnCode.Ok;
                    }
                    player.EventOnInventoryUpdated();
                    player.EventOnStationHoldUpdated();
                }
            }

            EventData evt = new EventData((byte)S2SEventCode.PUTInventoryItemEnd, end);
            SendEvent(evt, sendParameters);
            log.InfoFormat("HandlePUTInventoryItemStart: transaction end sended with success = {0}", end.success);
        } catch (Exception exception) {
            log.Info("exception");
            log.Info(exception.Message);
            log.Info(exception.StackTrace);
        }
    }