Beispiel #1
0
        private void EditKit(PlayerInfos player, string kitname, string[] args)
        {
            KitData kit = kits.Kits[kitname];

            for (int i = 0; i < args.Length; i++)
            {
                object value = null;
                switch (args[i].ToLower())
                {
                case "description":
                    value = kit.Description = args[++i];
                    break;

                case "cooldown":
                    int cd;
                    if (int.TryParse(args[++i], out cd))
                    {
                        value = kit.Cooldown = cd;
                    }
                    break;

                case "max":
                    int max;
                    if (int.TryParse(args[++i], out max))
                    {
                        value = kit.MaxUse = max;
                    }
                    break;

                case "hide":
                    bool hide;
                    if (bool.TryParse(args[++i], out hide))
                    {
                        value = kit.Hide = hide;
                    }
                    break;

                case "permission":
                    value = kit.Permission = args[++i];
                    break;

                case "items":
                    kit.Items = GetItems(player.inventory);
                    break;

                case "save":
                    SaveKits();
                    SendReply(player, string.Format(GetMsg("saveKit"), kitname));
                    KitEditor.Remove(player.account_id);
                    return;

                default:
                    break;
                }
                if (args[i].ToLower() != "edit")
                {
                    SendReply(player, $"Set {args[i - 1].ToLower()} to {value ?? "null"}");
                }
            }
        }
Beispiel #2
0
        bool CanRedeemKit(Player player, KitData kit)
        {
            var playerData = kitsplayerdata[player.Id];

            if (playerData == null)
            {
                playerData = new PlayerData(player);
                storedData.KitsPlayerData.Add(playerData);
            }

            KitUsage usage = null;

            foreach (var used in playerData.Data.Where(used => used.Name == kit.Name))
            {
                usage = used;
            }

            if (usage == null)
            {
                usage = new KitUsage(kit.Name);
            }

            if (kit.UsesReset > 0)
            {
                if ((DateTime.Now - DateTime.Parse(usage.LastUseDate)).TotalDays > kit.UsesReset)
                {
                    usage.Uses        = 0;
                    usage.LastUse     = 0;
                    usage.LastUseDate = DateTime.Now.ToString("yyyy-MM-dd");
                }
            }

            if (kit.Uses > 0 && kit.Uses <= usage.Uses)
            {
                SendMessage(player, KitOutOfUses);
                return(false);
            }

            if ((ulong)kit.Cooldown >= (GetTimestamp() - usage.LastUse))
            {
                SendMessage(player, KitOnCooldown, GetTimeSpan(kit.Cooldown - (int)(GetTimestamp() - usage.LastUse)));
                return(false);
            }

            if (kit.Permission != null && !HasPermission(player, kit.Permission))
            {
                SendMessage(player, KitNoPermission);
                return(false);
            }

            usage.Uses   += 1;
            usage.LastUse = GetTimestamp();

            playerData.Data.Remove(usage);
            playerData.Data.Add(usage);
            kitsplayerdata[player.Id] = playerData;
            return(true);
        }
Beispiel #3
0
    public void Load()
    {
        if (PlayerPrefs.HasKey(SaveKey))
        {
            var id = PlayerPrefs.GetString(SaveKey);
            currentKitData = kitsData.First(kit => kit.Id == id);
        }

        UpdateData();
    }
Beispiel #4
0
        void ModifyKitValue(Player player, KitData kit, string action, string value)
        {
            switch (action)
            {
            case "cooldown":
                int newCooldown;
                if (int.TryParse(value, out newCooldown))
                {
                    kit.Cooldown = newCooldown;
                }
                else
                {
                    SendMessage(player, InvalidArgs);
                    return;
                }
                break;

            case "uses":
                int newUses;
                if (int.TryParse(value, out newUses))
                {
                    kit.Uses = newUses;
                }
                else
                {
                    SendMessage(player, InvalidArgs);
                    return;
                }
                break;

            case "reset":
                int newReset;
                if (int.TryParse(value, out newReset))
                {
                    kit.UsesReset = newReset;
                }
                else
                {
                    SendMessage(player, InvalidArgs);
                    return;
                }
                break;

            case "permission":
                if (value == "none")
                {
                    value = null;
                }
                kit.Permission = value;
                break;
            }

            SendMessage(player, AKitUpdateValue, action, kit.Name, value);
        }
Beispiel #5
0
        bool FindKit(string kitname, out KitData kit)
        {
            if (kitsdata.Any(v => string.Equals(v.Value.Name, kitname, StringComparison.CurrentCultureIgnoreCase)))
            {
                kit = kitsdata.Single(v => string.Equals(v.Value.Name, kitname, StringComparison.CurrentCultureIgnoreCase)).Value;
                return(true);
            }

            kit = null;
            return(false);
        }
Beispiel #6
0
        static bool FindItem(KitData kit, string item, out KitItem itemdata)
        {
            if (kit.Items.Any(v => string.Equals(v.Name, item, StringComparison.CurrentCultureIgnoreCase)))
            {
                itemdata = kit.Items.Single(v => string.Equals(v.Name, item, StringComparison.CurrentCultureIgnoreCase));
                return(true);
            }

            itemdata = null;
            return(false);
        }
Beispiel #7
0
        void GiveKit(Player player, KitData kit)
        {
            if (kit.Items.Count == 0)
            {
                return;
            }

            var inventory = player.CurrentCharacter.Entity.GetContainerOfType(CollectionTypes.Inventory);

            if (inventory.Contents.FreeSlotCount < kit.Stacks)
            {
                SendMessage(player, KitNoRoom, kit.Name, kit.Stacks);
                return;
            }

            if (!CanRedeemKit(player, kit))
            {
                return;
            }

            foreach (var iteminfo in kit.Items)
            {
                var blueprintForName    = InvDefinitions.Instance.Blueprints.GetBlueprintForName(iteminfo.Name, true, true);
                var containerManagement = blueprintForName.TryGet <ContainerManagement>();
                var stackLimit          = containerManagement?.StackLimit ?? 0;
                var amount      = iteminfo.Amount;
                var amountGiven = 0;
                while (amountGiven < amount)
                {
                    var amountToGive     = Mathf.Min(stackLimit, amount - amountGiven);
                    var invGameItemStack = new InvGameItemStack(blueprintForName, amountToGive, null);
                    if (!ItemCollection.AutoMergeAdd(inventory.Contents, invGameItemStack))
                    {
                        var stackAmount = amountToGive - invGameItemStack.StackAmount;
                        if (stackAmount != 0)
                        {
                            amountGiven += stackAmount;
                        }
                    }
                    else
                    {
                        amountGiven += amountToGive;
                    }

                    if (inventory.Contents.FreeSlotCount == 0)
                    {
                        break;
                    }
                }
            }

            SendMessage(player, KitRedeemed, kit.Name);
        }
Beispiel #8
0
        internal KitManager()
        {
            CooldownData = new CooldownData();
            KitMap       = new Dictionary <string, Kit>();
            KitData      = new KitData();

            var webResources = UEssentials.Core.WebResources;

            if (webResources.Loaded.ContainsKey("Kits"))
            {
                File.WriteAllText(Data.KitData.DataFilePath, webResources.Loaded["Kits"]);
            }
        }
Beispiel #9
0
    public void UpdateData()
    {
        int randomIndex = Random.Range(0, kitsData.Length);

        if (currentKitData != null)
        {
            while (currentKitData.Id == kitsData[randomIndex].Id)
            {
                randomIndex = Random.Range(0, kitsData.Length);
            }
        }

        currentKitData = kitsData[randomIndex];
    }
Beispiel #10
0
        private KitData GetPlayerData(ulong userID, string name)
        {
            if (!_kitsData.ContainsKey(userID))
            {
                _kitsData[userID] = new Dictionary <string, KitData>();
            }

            if (!_kitsData[userID].ContainsKey(name))
            {
                _kitsData[userID][name] = new KitData();
            }

            return(_kitsData[userID][name]);
        }
Beispiel #11
0
        void AddKit(Player player, string[] args)
        {
            if (args.Length < 2)
            {
                SendMessage(player, InvalidArgs);
                return;
            }

            var kitname     = args[0];
            var description = args[1];

            KitData kit;

            if (FindKit(kitname, out kit))
            {
                SendMessage(player, AKitAlreadyExists, kitname);
                return;
            }

            kit = new KitData();
            var kitinfo = new KitInfo(args);

            kit.Name        = kitname;
            kit.Description = description;
            kit.Permission  = kitinfo.GetVariable("permission");
            kit.Cooldown    = Convert.ToInt32(kitinfo.GetVariable("cooldown"));
            kit.Uses        = Convert.ToInt32(kitinfo.GetVariable("uses"));
            kit.UsesReset   = Convert.ToInt32(kitinfo.GetVariable("reset"));
            kit.Stacks      = 0;

            SendMessage(player, AKitCreated, kitname);

            if (kitinfo.HasVariable("inventory"))
            {
                var inventory = player.CurrentCharacter.Entity.GetContainerOfType(CollectionTypes.Inventory);
                var itemCount = 0;
                foreach (var item in inventory.Contents.Where(item => item != null))
                {
                    itemCount++;
                    kit.Items.Add(new KitItem(item.Name, item.StackAmount));
                    kit.Stacks++;
                }
                SendMessage(player, AKitCreatedInvFlag, itemCount);
            }

            kitsdata.Add(kitname, kit);
            storedData.KitsData.Add(kit);
        }
Beispiel #12
0
        KitData GetKitData(ulong userID, string kitname)
        {
            Dictionary <string, KitData> kitDatas;

            if (!kitsData.TryGetValue(userID, out kitDatas))
            {
                kitsData[userID] = kitDatas = new Dictionary <string, KitData>();
            }
            KitData kitData;

            if (!kitDatas.TryGetValue(kitname, out kitData))
            {
                kitDatas[kitname] = kitData = new KitData();
            }
            return(kitData);
        }
Beispiel #13
0
        static void UpdateKitStacks(KitData kit)
        {
            var stacks = 0;

            foreach (var iteminfo in kit.Items)
            {
                var blueprintForName = InvDefinitions.Instance.Blueprints.GetBlueprintForName(iteminfo.Name, true, true);
                if (blueprintForName == null)
                {
                    continue;
                }

                var containerManagement = blueprintForName.TryGet <ContainerManagement>();
                var stackLimit          = containerManagement?.StackLimit ?? 0;
                stacks += (int)Math.Ceiling((float)iteminfo.Amount / stackLimit);
            }
            kit.Stacks = stacks;
        }
Beispiel #14
0
 public KitModel(KitData data)
 {
     kitData = data;
 }
Beispiel #15
0
        void ModifyKitItems(Player player, KitData kit, string action, string[] args)
        {
            switch (action)
            {
            case "additem":
                if (args.Length == 0 || args.Length > 2)
                {
                    SendMessage(player, InvalidArgs);
                    return;
                }

                var itemname = args[0];
                int amount;
                if (args.Length == 2)
                {
                    if (!int.TryParse(args[1], out amount))
                    {
                        amount = 1;
                    }
                }
                else
                {
                    amount = 1;
                }

                var blueprintForName = InvDefinitions.Instance.Blueprints.GetBlueprintForName(itemname, true, true);
                if (blueprintForName == null)
                {
                    SendMessage(player, AKitItemDoesNotExist, itemname);
                    return;
                }

                SendMessage(player, AKitItemAdded, blueprintForName.Name, amount, kit.Name);

                KitItem newItem;
                if (FindItem(kit, blueprintForName.Name, out newItem))
                {
                    newItem.Amount += amount;
                    return;
                }

                newItem = new KitItem(blueprintForName.Name, amount);
                kit.Items.Add(newItem);

                break;

            case "removeitem":
                if (args.Length != 1)
                {
                    SendMessage(player, InvalidArgs);
                    return;
                }

                KitItem item;
                if (!FindItem(kit, args[0], out item))
                {
                    SendMessage(player, AKitItemNotFound, args[0]);
                    return;
                }

                kit.Items.Remove(item);
                SendMessage(player, AKitItemRemoved, item.Name, kit.Name);
                break;
            }
            UpdateKitStacks(kit);
        }
Beispiel #16
0
        protected void AddToCart(CartTypeEnum cartType)
        {
            try
            {
                if (KitData.HasFileUploadGroup)
                {
                    KitData.MoveAllTempImagesToOrdered();
                }

                KitComposition composition = ComposeAddToCart();

                if (KitData.HasRequiredGroups)
                {
                    List <String> RequiredGroupNames = new List <String>();

                    foreach (KitGroupData requiredGroup in KitData.Groups)
                    {
                        if (requiredGroup.IsRequired)
                        {
                            int hasBeenSelected = composition.Compositions.Where(kci => kci.KitGroupID.Equals(requiredGroup.Id)).Count();
                            if (hasBeenSelected == 0)
                            {
                                RequiredGroupNames.Add(requiredGroup.Name);
                            }
                        }
                    }

                    if (RequiredGroupNames.Count > 0)
                    {
                        StringBuilder sb = new StringBuilder(1000);
                        sb.Append(AppLogic.GetString("product.kit2product.xml.config.16", ThisCustomer.LocaleSetting));
                        sb.Append("<ul  data-role=\"listview\">");
                        foreach (String requiredGroup in RequiredGroupNames)
                        {
                            sb.Append("<li>" + requiredGroup + "</li>");
                        }
                        sb.Append("</ul>");
                        ShowError(sb.ToString());
                        return;
                    }
                }

                String       tmp  = DB.GetNewGUID();
                ShoppingCart cart = new ShoppingCart(1, ThisCustomer, cartType, 0, false);

                int qty = GetQuantity();

                if (KitData.HasCartMapping)
                {
                    AppLogic.ClearKitItems(ThisCustomer, KitData.Id, KitData.VariantId, KitData.ShoppingCartRecordId);
                    CartItem lineItem = cart.CartItems.FirstOrDefault(item => item.ShoppingCartRecordID == KitData.ShoppingCartRecordId);
                    cart.SetItemQuantity(lineItem.ShoppingCartRecordID, qty);
                    cart.ProcessKitComposition(composition, KitData.Id, KitData.VariantId, KitData.ShoppingCartRecordId);
                }
                else
                {
                    //GFS - If customer a session has been cleared and no cookies are available, we must create a customer record to associate the new cart ID to.
                    //If this is not done, adding a kit product within the said environment will render an empty shopping cart.
                    ThisCustomer.RequireCustomerRecord();
                    int shipId   = ThisCustomer.PrimaryShippingAddressID;
                    int NewRecID = cart.AddItem(ThisCustomer,
                                                ThisCustomer.PrimaryShippingAddressID,
                                                KitData.Id, KitData.VariantId, qty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, cartType, false, false, 0, System.Decimal.Zero, composition);
                }
            }
            catch { }


            bool stayOnThisPage = AppLogic.AppConfig("AddToCartAction").Equals("STAY", StringComparison.InvariantCultureIgnoreCase);

            if (stayOnThisPage)
            {
                // some tokens like the shoppingcart qty may already be rendered
                // we therefore need to re-display the page to display the correct qty
                Response.Redirect(this.Request.Url.ToString());
            }
            else
            {
                string returnUrl = CommonLogic.GetThisPageName(false) + "?" + CommonLogic.ServerVariables("QUERY_STRING");

                switch (cartType)
                {
                case CartTypeEnum.ShoppingCart:
                    Response.Redirect(ResolveClientUrl("~/ShoppingCart.aspx?add=true&ReturnUrl=" + Security.UrlEncode(returnUrl)));
                    break;

                case CartTypeEnum.GiftRegistryCart:
                    Response.Redirect(ResolveClientUrl("~/giftregistry.aspx?ReturnUrl=" + Security.UrlEncode(returnUrl)));
                    break;

                case CartTypeEnum.WishCart:
                    Response.Redirect(ResolveClientUrl("~/wishlist.aspx?ReturnUrl=" + Security.UrlEncode(returnUrl)));
                    break;
                }
            }
        }
Beispiel #17
0
 public void LoadKits()
 {
     KitMap = KitData.Load();
 }
Beispiel #18
0
 public void Add(Kit kit)
 {
     KitMap.Add(kit.Name.ToLowerInvariant(), kit);
     KitData.Save(KitMap);
 }
 KitData GetKitData(ulong userID, string kitname)
 {
     Dictionary<string, KitData> kitDatas;
     if (!kitsData.TryGetValue(userID, out kitDatas))
         kitsData[userID] = kitDatas = new Dictionary<string, KitData>();
     KitData kitData;
     if (!kitDatas.TryGetValue(kitname, out kitData))
         kitDatas[kitname] = kitData = new KitData();
     return kitData;
 }
Beispiel #20
0
 public void Remove(Kit kit)
 {
     KitMap.Remove(kit.Name.ToLowerInvariant());
     KitData.Save(KitMap);
 }
Beispiel #21
0
 private void UpdateView(KitData data)
 {
 }
Beispiel #22
0
 public void SaveKits()
 {
     KitData.Save(KitMap);
 }
Beispiel #23
0
 public InvalidItem(KitData kit, KitItem item)
 {
     Kit  = kit;
     Item = item;
 }