Пример #1
0
        public bool BuyStoreItem(string login, string gameRef, string character, int race, int inworkshop, int level, string productType, string server, out RPCErrorCode errorCode)
        {
            errorCode = RPCErrorCode.Ok;

            if (level < application.serverSettings.pvpStoreMinLevel)
            {
                log.InfoFormat("player level very low for pvp store {0}:{1} [red]", level, application.serverSettings.pvpStoreMinLevel);
                errorCode = RPCErrorCode.LevelNotEnough;
                return(false);
            }

            var storeItem = application.pvpStoreItems.GetItem(productType.ToLower());

            if (storeItem == null)
            {
                log.InfoFormat("pvp store item {0} not founded [red]", productType.ToLower());
                errorCode = RPCErrorCode.ObjectNotFound;
                return(false);
            }

            var store = application.Stores.GetOnlyPlayerStore(character);

            if (store == null)
            {
                log.InfoFormat("player store not founded [red]");
                errorCode = RPCErrorCode.ObjectNotFound;
                return(false);
            }

            if (store.pvpPoints < storeItem.price)
            {
                log.InfoFormat("player don't enough pvp points for purchase {0}:{1}", store.pvpPoints, storeItem.price);
                errorCode = RPCErrorCode.DontEnoughPvpPoints;
                return(false);
            }

            int workshop = inworkshop;

            if (Rand.Float01() >= 0.9f)
            {
                workshop = (byte)CommonUtils.RandomWorkshop((Race)(byte)race);
            }

            IInfo result = null;

            if (storeItem.isWeapon)
            {
                WeaponDropper dropper = new WeaponDropper(new WeaponDropper.WeaponDropParams(application.resource, level, (Workshop)(byte)workshop, WeaponDamageType.damage, Difficulty.none), 1f);
                result = (dropper.DropWeapon() as IInfo);
            }
            else
            {
                switch (productType.ToLower())
                {
                case "es":
                {
                    result = CreateModule(workshop, level, ShipModelSlotType.ES);
                }
                break;

                case "cb":
                {
                    result = CreateModule(workshop, level, ShipModelSlotType.CB);
                }
                break;

                case "cm":
                {
                    result = CreateModule(workshop, level, ShipModelSlotType.CM);
                }
                break;

                case "dm":
                {
                    result = CreateModule(workshop, level, ShipModelSlotType.DM);
                }
                break;

                case "df":
                {
                    result = CreateModule(workshop, level, ShipModelSlotType.DF);
                }
                break;
                }
            }

            if (result == null)
            {
                log.InfoFormat("creating item error [red]");
                errorCode = RPCErrorCode.UnknownError;
                return(false);
            }

            var itemHash = result.GetInfo();

            PUTInventoryItemTransactionStart start = new PUTInventoryItemTransactionStart {
                characterID           = character,
                count                 = 1,
                gameRefID             = gameRef,
                itemID                = itemHash.GetValue <string>((int)SPC.Id, string.Empty),
                postTransactionAction = (byte)PostTransactionAction.RemovePvpPoints,
                inventoryType         = (byte)InventoryType.ship,
                tag                    = storeItem.price,
                targetObject           = itemHash,
                transactionID          = Guid.NewGuid().ToString(),
                transactionSource      = (byte)TransactionSource.PvpStore,
                transactionEndServer   = server,
                transactionStartServer = SelectCharacterApplication.ServerId.ToString()
            };
            EventData eventData = new EventData((byte)S2SEventCode.PUTInventoryItemStart, start);

            mPutTransactionPool.StartTransaction(start);
            application.MasterPeer.SendEvent(eventData, new SendParameters());
            log.InfoFormat("pass put transaction started [red]...");
            return(true);
        }