Example #1
0
        public Hashtable AddPetSkin()
        {
            string skin = player.resource.petParameters.typeTable.GetRandomType((Race)player.GetComponent <RaceableObject>().race);

            if (false == string.IsNullOrEmpty(skin))
            {
                PetSkinObject skinObject = new PetSkinObject(Guid.NewGuid().ToString(), skin, false);
                var           inventory  = player.Inventory;
                if (inventory.HasSlotsForItems(new List <string> {
                    skinObject.Id
                }))
                {
                    if (inventory.Add(skinObject, 1))
                    {
                        player.EventOnInventoryUpdated();
                        return(new Hashtable {
                            { (int)SPC.ReturnCode, (int)RPCErrorCode.Ok },
                            { (int)SPC.Status, true }
                        });
                    }
                }
            }
            return(new Hashtable {
                { (int)SPC.ReturnCode, (int)RPCErrorCode.UnknownError }
            });
        }
Example #2
0
        public bool RequestPurchaseInap(string gameRef, string character, string inapId, string targetServer, out ReturnCode code)
        {
            var databaseUser = m_Application.GetUser(new GameRefId(gameRef));

            if (databaseUser == null)
            {
                code = ReturnCode.UserNotFound;
                return(false);
            }

            InapItem inapItem = m_Application.inapResource.GetInap(inapId);

            if (inapItem == null)
            {
                code = ReturnCode.ResourceNotFound;
                return(false);
            }

            if (databaseUser.nebulaCredits < inapItem.price)
            {
                code = ReturnCode.NotEnoughCredits;
                return(false);
            }

            s_Log.InfoFormat("request purchase inap = {0} with interval = {1}", inapId, inapItem.data.GetValue <int>("interval", 0));

            Hashtable objInfo = null;

            switch (inapItem.type)
            {
            case InapObjectType.exp_boost: {
                objInfo = new ExpBoostObject(
                    inapId + inapItem.tag.ToString(),
                    inapItem.data.GetValue <float>("value", 0f),
                    inapItem.data.GetValue <int>("interval", 0),
                    inapItem.tag
                    ).GetInfo();
            }
            break;

            case InapObjectType.loot_box: {
                objInfo = new LootBoxObject(
                    inapId,
                    inapItem.data.GetValue <string>("drop_list", string.Empty)
                    ).GetInfo();
            }
            break;

            case InapObjectType.pet_skin: {
                string skin = inapItem.data.GetValue <string>("model", string.Empty);
                if (string.IsNullOrEmpty(skin))
                {
                    code = ReturnCode.InvalidInapType;
                    return(false);
                }
                objInfo = new PetSkinObject(skin, skin).GetInfo();
            }
            break;

            case InapObjectType.founder_cube: {
                objInfo = new FounderCubeInventoryObject().GetInfo();
            }
            break;

            case InapObjectType.credits_bag: {
                objInfo = new CreditsBagObject("creditsbag", inapItem.data.GetValue <int>("count", 10000), false).GetInfo();
            }
            break;
            }

            if (objInfo == null)
            {
                code = ReturnCode.InvalidInapType;
                return(false);
            }

            Hashtable tagHash = new Hashtable {
                { (int)SPC.InapId, inapId },
                { (int)SPC.Price, inapItem.price },
                { (int)SPC.Title, "ginp_title" },
                { (int)SPC.Body, "ginp_body" }
            };

            string itemID = string.Empty;

            if (inapItem.type == InapObjectType.pet_skin)
            {
                itemID = objInfo.GetValue <string>((int)SPC.Id, string.Empty);
            }
            else if (inapItem.type == InapObjectType.founder_cube)
            {
                itemID = objInfo.GetValue <string>((int)SPC.Id, string.Empty);
            }
            else if (inapItem.type == InapObjectType.credits_bag)
            {
                itemID = "creditsbag";
            }
            else
            {
                itemID = inapId + inapItem.tag.ToString();
            }

            PUTInventoryItemTransactionStart startTransaction = new PUTInventoryItemTransactionStart {
                characterID           = character,
                gameRefID             = gameRef,
                count                 = 1,
                inventoryType         = (int)InventoryType.ship,
                itemID                = itemID,
                postTransactionAction = (byte)PostTransactionAction.RemoveNebulaCredits,
                tag                    = tagHash,
                targetObject           = objInfo,
                transactionEndServer   = targetServer,
                transactionStartServer = LoginApplication.ServerId.ToString(),
                transactionID          = Guid.NewGuid().ToString(),
                transactionSource      = (byte)TransactionSource.Inaps
            };

            EventData eventData = new EventData((byte)S2SEventCode.PUTMailTransactionStart, startTransaction);

            m_PutTransactionPool.StartTransaction(startTransaction);
            m_Application.MasterPeer.SendEvent(eventData, new SendParameters());
            s_Log.InfoFormat("inap transaction successfully started...");

            code = ReturnCode.Ok;
            return(true);
        }