Esempio n. 1
0
    private GiveItem GiveAndTakeAction()
    {
        GiveItem ret = new GiveItem(GiverInDrop);

        (ret.ActionOptions [0] as ItemsOnPersonOption).chosenChoice =
            new InventoryItemChoice(ItemSlot.currentlyDraggingSlot.CurrentItem) as IActionOptionChoice;
        ret.actionTargetParameters [0].chosenTile = TakerInDrop.TileMovement.occupying;
        return(ret);
    }
Esempio n. 2
0
    public void TakeItem(OptButton btn)
    {
        if (character == InventoryView.instance.currentCharacter)
        {
            return;
        }

        if (ItemSlot.currentlyDraggingSlot != null)
        {
            NoTakeItemReason reason = GetNoTakeItemReason();
            switch (reason)
            {
            case NoTakeItemReason.GIVER_NO_INTERACTION:
                Debug.LogError("Giver needs interaction!");
                break;

            case NoTakeItemReason.TAKER_NO_INTERACTION:
                Debug.LogError("TAKER needs interaction!");
                break;

            case NoTakeItemReason.TAKER_NO_ROOM:
                Debug.LogError("TAKER has no room left!");
                break;

            case NoTakeItemReason.GIVER_OR_TAKER_NOT_ACTING:
                Debug.LogError("Giver or taker must be acting.");
                break;

            case NoTakeItemReason.OUT_OF_RANGE:
                Debug.LogError("Giver and taker must be within " + GiveItem.GIVE_DISTANCE + " squares of each other.");
                break;

            case NoTakeItemReason.NO_REASON__CAN_TAKE:
                Debug.Log("You may add, my son!");

                //do action
                if (InventoryView.instance.IsBattleMode)
                {
                    GiveItem act = GiveAndTakeAction();
                    act.Perform();
                }
                else
                {
                    character.inventory.AddItem(ItemSlot.currentlyDraggingSlot.GiveUpItem());
                }


                InventoryView.instance.RefreshUi();
                break;

            default:
                break;
            }
        }
    }
Esempio n. 3
0
    void PickItem(Room r)
    {
        if (canHaveComponents || canHaveHealth || canHaveCharges)
        {
            bool haveItem = false;
            while (!haveItem)
            {
                int itemType = Random.Range(0, 3);
                switch (itemType)
                {
                case 0:
                    if (!canHaveComponents)
                    {
                        continue;
                    }
                    price          = componentPrice;
                    giveItem       = GiveSpellComponent;
                    spellComponent = PlayerInventory.instance.AddComponentToStore();
                    ISpellComponent component = ComponentLoader.GetInstance().LoadComponent(new ComponentLoader.UnLoadedSpellComponent(spellComponent, PlayerInventory.instance.componentsInStore[spellComponent]));
                    itemText.text = component.GetTitle() + "\n" + component.GetToolTip();
                    haveItem      = true;
                    break;

                case 1:
                    if (!canHaveHealth)
                    {
                        continue;
                    }
                    price         = fullHealPrice;
                    giveItem      = Heal;
                    itemText.text = "Full Healh";
                    haveItem      = true;
                    break;

                case 2:
                    if (!canHaveCharges)
                    {
                        continue;
                    }
                    price         = fullChargePrice;
                    giveItem      = RechargeSpells;
                    itemText.text = "Recharge Spells";
                    haveItem      = true;
                    break;

                default:
                    break;
                }
            }
            priceText.text = price.ToString();
        }
    }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="script"></param>
        public GiveItemControl(GiveItem script)
        {
            InitializeComponent();


            if (script != null)
            {
                Action = script;
            }
            else
            {
                Action = new GiveItem();
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Loads actions
        /// </summary>
        /// <param name="filename">Xml node</param>
        public void LoadActions(XmlNode xml)
        {
            if (xml == null || xml.Name.ToLower() != "actions")
            {
                return;
            }

            foreach (XmlNode node in xml)
            {
                if (node.NodeType == XmlNodeType.Comment)
                {
                    continue;
                }


                switch (node.Name.ToLower())
                {
                case "teleport":
                {
                    Teleport teleport = new Teleport();
                    teleport.Load(node);
                    Actions.Add(teleport);
                }
                break;

                case "giveexperience":
                {
                    GiveExperience script = new GiveExperience();
                    script.Load(node);
                    Actions.Add(script);
                }
                break;

                case "activate":
                {
                    ActivateTarget script = new ActivateTarget();
                    script.Load(node);
                    Actions.Add(script);
                }
                break;

                case "changepicture":
                {
                    ChangePicture script = new ChangePicture();
                    script.Load(node);
                    Actions.Add(script);
                }
                break;

                case "changetext":
                {
                    ChangeText script = new ChangeText();
                    script.Load(node);
                    Actions.Add(script);
                }
                break;

                case "deactivate":
                {
                    DeactivateTarget script = new DeactivateTarget();
                    script.Load(node);
                    Actions.Add(script);
                }
                break;

                case "disablechoice":
                {
                    DisableChoice script = new DisableChoice();
                    script.Load(node);
                    Actions.Add(script);
                }
                break;

                case "disable":
                {
                    DisableTarget script = new DisableTarget();
                    script.Load(node);
                    Actions.Add(script);
                }
                break;

                case "enablechoice":
                {
                    EnableChoice script = new EnableChoice();
                    script.Load(node);
                    Actions.Add(script);
                }
                break;

                case "endchoice":
                {
                    EndChoice script = new EndChoice();
                    script.Load(node);
                    Actions.Add(script);
                }
                break;

                case "enddialog":
                {
                    EndDialog script = new EndDialog();
                    script.Load(node);
                    Actions.Add(script);
                }
                break;

                case "giveitem":
                {
                    GiveItem script = new GiveItem();
                    script.Load(node);
                    Actions.Add(script);
                }
                break;

                case "healing":
                {
                    Healing script = new Healing();
                    script.Load(node);
                    Actions.Add(script);
                }
                break;

                case "joincharacter":
                {
                    JoinCharacter script = new JoinCharacter();
                    script.Load(node);
                    Actions.Add(script);
                }
                break;

                case "playsound":
                {
                    PlaySound script = new PlaySound();
                    script.Load(node);
                    Actions.Add(script);
                }
                break;

                case "toggle":
                {
                    ToggleTarget script = new ToggleTarget();
                    script.Load(node);
                    Actions.Add(script);
                }
                break;

                default:
                {
                    Trace.WriteLine("[ScriptChoice] LoadActions() : Unknown node \"{0}\"", node.Name);
                }
                break;
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Loads a party
        /// </summary>
        /// <param name="filename">Xml data</param>
        /// <returns>True if team successfuly loaded, otherwise false</returns>
        public virtual bool Load(XmlNode xml)
        {
            if (xml == null)
            {
                return(false);
            }


            Action = null;

            switch (xml.Name)
            {
            case SpawnMonster.Tag:
            {
                Action = new SpawnMonster();
            }
            break;

            case EnableTarget.Tag:
            {
                Action = new EnableTarget();
            }
            break;

            case DisableTarget.Tag:
            {
                Action = new DisableTarget();
            }
            break;

            case ActivateTarget.Tag:
            {
                Action = new ActivateTarget();
            }
            break;

            case DeactivateTarget.Tag:
            {
                Action = new DeactivateTarget();
            }
            break;

            case ChangePicture.Tag:
            {
                Action = new ChangePicture();
            }
            break;

            case ChangeText.Tag:
            {
                Action = new ChangeText();
            }
            break;

            case DisableChoice.Tag:
            {
                Action = new DisableChoice();
            }
            break;

            case EnableChoice.Tag:
            {
                Action = new EnableChoice();
            }
            break;

            case EndChoice.Tag:
            {
                Action = new EndChoice();
            }
            break;

            case EndDialog.Tag:
            {
                Action = new EndDialog();
            }
            break;

            case GiveExperience.Tag:
            {
                Action = new GiveExperience();
            }
            break;

            case GiveItem.Tag:
            {
                Action = new GiveItem();
            }
            break;

            case Healing.Tag:
            {
                Action = new Healing();
            }
            break;

            case JoinCharacter.Tag:
            {
                Action = new JoinCharacter();
            }
            break;

            case PlaySound.Tag:
            {
                Action = new PlaySound();
            }
            break;

            case SetTo.Tag:
            {
                Action = new SetTo();
            }
            break;

            case Teleport.Tag:
            {
                Action = new Teleport();
            }
            break;

            case ToggleTarget.Tag:
            {
                Action = new ToggleTarget();
            }
            break;

            case DisplayMessage.Tag:
            {
                Action = new DisplayMessage();
            }
            break;

            default:
            {
                Trace.WriteLine("[ScriptBase] Load() : Unknown node \"" + xml.Name + "\" found.");
                return(false);
            }
            }

            if (Action == null)
            {
                return(false);
            }


            Action.Load(xml);

            return(true);
        }
        public override IEnumerable <object> Run()
        {
            if (this.service.IsCashShopStopped)
            {
                base.Finished = true;
                base.Entity.SendErrorDialog("CashShop_EmergencyStop");
                yield return(new FailMessage("[QueryCashShopItemPickUpProcessor] service.IsCashShopStopped")
                {
                    Reason = FailMessage.ReasonCode.LogicalFail
                });
            }
            else if (base.Entity.CID == -1L)
            {
                base.Finished = true;
                base.Entity.SendErrorDialog("CashShop_NotReady");
                yield return(new FailMessage("[QueryCashShopItemPickUpProcessor] Entity.CID")
                {
                    Reason = FailMessage.ReasonCode.LogicalFail
                });
            }
            else
            {
                AsyncResultSync sync = new AsyncResultSync(this.service.Thread);
                IAsyncResult    ar   = base.Entity.BeginInventoryPickup(base.Operation.OrderNo, base.Operation.ProductNo, base.Operation.Quantity, new AsyncCallback(sync.AsyncCallback), "DirectPurchase");
                if (ar != null)
                {
                    yield return(sync);
                }
                if (ar == null && !sync.Result)
                {
                    base.Finished = true;
                    yield return(new FailMessage("[QueryCashShopItemPickUpProcessor] !sync.Result")
                    {
                        Reason = FailMessage.ReasonCode.LogicalFail
                    });
                }
                else
                {
                    InventoryPickupOnceResponse asyncResult = base.Entity.EndInventoryPickUp(ar);
                    if (asyncResult == null)
                    {
                        base.Finished = true;
                        yield return(new FailMessage("[QueryCashShopItemPickUpProcessor] asyncResult")
                        {
                            Reason = FailMessage.ReasonCode.LogicalFail
                        });
                    }
                    else
                    {
                        bool     isGift     = base.Entity.GiftSenderCIDDict.ContainsKey(base.Operation.OrderNo);
                        GiveItem giveItemOp = asyncResult.ToGiveItem(this.service, isGift);
                        if (giveItemOp != null && giveItemOp.ItemRequestInfo.Count > 0)
                        {
                            foreach (ItemRequestInfo.Element element in giveItemOp.ItemRequestInfo.Elements)
                            {
                                Log <QueryCashShopItemPickUpProcessor> .Logger.InfoFormat("{0} x {1}", element.ItemClassEx, element.Num);
                            }
                            OperationSync giveItemSync = new OperationSync
                            {
                                Connection = base.Entity.ItemConnection,
                                Operation  = giveItemOp
                            };
                            yield return(giveItemSync);

                            base.Entity.CashShopProcessLog(base.Operation.OrderNo, giveItemOp, giveItemSync.Result);
                            if (!giveItemSync.Result || giveItemOp.ErrorCode != GiveItem.ResultEnum.Success)
                            {
                                Log <QueryCashShopItemPickUpProcessor> .Logger.ErrorFormat("GiveItemSync is failed. NexonID: {0}, CID: {1}", base.Entity.NexonID, base.Entity.CID);

                                base.Entity.EndInventoryPickUp_OnFail(asyncResult);
                                base.Finished = true;
                                yield return(new FailMessage("[QueryCashShopItemPickUpProcessor] giveItemOp.ErrorCode")
                                {
                                    Reason = FailMessage.ReasonCode.LogicalFail
                                });
                            }
                            OperationSync giveMileageSync  = new OperationSync();
                            bool          useMileageSystem = FeatureMatrix.IsEnable("CashShop_MileageSystem");
                            if (useMileageSystem)
                            {
                                double mileageRatio = (double)((float)FeatureMatrix.GetInteger("CashShop_MileageRatio") / 100f);
                                int    totalPrice   = this.service.ProductByProductID.TryGetValue(base.Operation.ProductNo).SalePrice *(int)asyncResult.ProductPieces;
                                int    mileagePoint = Convert.ToInt32(Math.Floor((double)totalPrice * mileageRatio));
                                mileagePoint = ((mileagePoint == 0) ? 1 : mileagePoint);
                                CashshopMileage mileageOp = null;
                                if (isGift)
                                {
                                    long cid = base.Entity.GiftSenderCIDDict.TryGetValue(base.Operation.OrderNo);
                                    mileageOp = new CashshopMileage(cid, mileagePoint, CashshopMileage.ProcessEnum.ADD_GIFT_USER);
                                }
                                else
                                {
                                    mileageOp = new CashshopMileage(0L, mileagePoint, CashshopMileage.ProcessEnum.ADD);
                                }
                                giveMileageSync.Connection = base.Entity.ItemConnection;
                                giveMileageSync.Operation  = mileageOp;
                                yield return(giveMileageSync);

                                if (!giveMileageSync.Result)
                                {
                                    Log <QueryCashShopItemPickUpProcessor> .Logger.ErrorFormat("GiveItemSync is failed. NexonID: {0}, CID: {1}", base.Entity.NexonID, base.Entity.CID);

                                    base.Entity.CashShopProcessLog("", base.Operation.OrderNo.ToString(), base.Operation.OrderNo, mileagePoint, base.Entity.CID, base.Entity.NexonSN, "Mileage", "GiveFail");
                                }
                            }
                            base.Entity.EndInventoryPickUp_OnComplete(asyncResult);
                            int tircoinCount = 0;
                            foreach (ItemRequestInfo.Element element2 in giveItemOp.ItemRequestInfo.Elements)
                            {
                                if (element2.ItemClassEx.StartsWith("tir_coin"))
                                {
                                    tircoinCount += element2.Num;
                                }
                            }
                            if (tircoinCount > 0)
                            {
                                SendPacket op = SendPacket.Create <OpenCustomDialogUIMessage>(new OpenCustomDialogUIMessage
                                {
                                    DialogType = 3,
                                    Arg        = new List <string>
                                    {
                                        tircoinCount.ToString()
                                    }
                                });
                                base.Entity.FrontendConnection.RequestOperation(op);
                                SystemMessage serializeObject = new SystemMessage(SystemMessageCategory.System, "GameUI_Heroes_SystemMessage_TirCoin_BuyOK", new object[]
                                {
                                    tircoinCount
                                });
                                SendPacket op2 = SendPacket.Create <SystemMessage>(serializeObject);
                                base.Entity.FrontendConnection.RequestOperation(op2);
                            }
                            base.Finished = true;
                            yield return(new OkMessage());
                        }
                        else
                        {
                            Log <QueryCashShopItemPickUpProcessor> .Logger.ErrorFormat("ToGiveItem is failed or there's no given item. NexonID: {0}, CID: {1}", base.Entity.NexonID, base.Entity.CID);

                            base.Entity.EndInventoryPickUp_OnFail(asyncResult);
                            base.Finished = true;
                            yield return(new FailMessage("[QueryCashShopItemPickUpProcessor] giveItemOp.ItemRequestInfo.Count")
                            {
                                Reason = FailMessage.ReasonCode.LogicalFail
                            });
                        }
                    }
                }
            }
            yield break;
        }
Esempio n. 8
0
 private void Awake()
 {
     giveItem        = GetComponent <GiveItem>();
     dialogueManager = FindObjectOfType <DialogueManager>();
 }
Esempio n. 9
0
 private IResponse TryGiveItem(GiveItem giveItem)
 {
     return(NotImplemented(giveItem));
 }