脚本功能:MVC模式——Model层,定义物品结构,保存物品数据 添加对象:Bag 背包(Canvas下的空对象) 版权声明:Copyright (c) 2015 duzixi.com All Rights Reserved 创建日期:2015.5.8 知识要点: 1. MVC 2. 自定义类 3. 类的嵌套
Inheritance: MonoBehaviour
Ejemplo n.º 1
0
        public static List<ItemModel> GetItems(string fileName)
        {
            var doc = new XmlDocument();

            doc.Load(fileName);
            var xn = doc.SelectSingleNode("Items");
            // 得到根节点的所有子节点
            var xnl = xn.ChildNodes;
            var items = new List<ItemModel>();
            foreach (XmlNode xn1 in xnl)
            {
                XmlElement xe = (XmlElement)xn1;

                foreach (var xmNode in xn1.ChildNodes)
                {
                    ItemModel item = new ItemModel();
                    item.ElectricBusiness = xe.Attributes["ElectricBusiness"].Value;
                    item.PriceCrawlUrl = xe.Attributes["PriceCrawlUrl"].Value;
                    item.PromotionCrawlUrl = xe.Attributes["PromotionCrawlUrl"].Value;
                    var xee = (XmlElement)xmNode;// 将节点转换为元素,便于得到节点的属性值
                    XmlNodeList xnl0 = xee.ChildNodes;
                    item.Skuid = xnl0.Item(0).InnerText;
                    item.Name = xnl0.Item(1).InnerText;
                    item.PriceQueryString = xnl0.Item(2).InnerText;
                    item.PromotionQueryString = xnl0.Item(3).InnerText;
                    items.Add(item);
                }
            }
            return items.OrderBy(p => p.ElectricBusiness).ToList();
        }
        public JsonResult GetConfiguredShows()
        {
            var showMgr = new Fpp.Domain.Managers.ShowManager();
            var configuredShows = showMgr.GetConfiguredShows();

            var items = new ItemModel
            {
                ItemDetails = new List<ItemDetails>(),
                Type = "Rings"
            };
            if (configuredShows.Any())
            {
                var tmp = Rings.GetRingsForShowDayList(configuredShows.First().ShowDetailsId);
                foreach (var item in tmp)
                {
                    items.ItemDetails.Add(new ItemDetails
                    {
                        Id = item.ID,
                        Name = $"Ring No:{item.RingNo}"
                    });
                }
            }

            return Json(new {
                Status = 0,
                Items = items,
                ConfiguredShows = configuredShows
            });
        }
        /// <summary>
        /// Loads the detail view for the specified item.
        /// </summary>
        /// <param name="item">The item to load.</param>
        /// <returns>The task to await.</returns>
        private async Task LoadImage(ItemModel item)
        {
            // Only load a detail view image for image items. Initialize the bitmap from the image content stream.
            if (item.Bitmap == null && (item.Item.Image != null))
            {
                item.Bitmap = new BitmapImage();
                var client = ((App)Application.Current).OneDriveClient;

                using (var responseStream = await client.Drive.Items[item.Id].Content.Request().GetAsync())
                {
                    var memoryStream = responseStream as MemoryStream;

                    if (memoryStream != null)
                    {
                        await item.Bitmap.SetSourceAsync(memoryStream.AsRandomAccessStream());
                    }
                    else
                    {
                        using (memoryStream = new MemoryStream())
                        {
                            await responseStream.CopyToAsync(memoryStream);
                            memoryStream.Position = 0;

                            await item.Bitmap.SetSourceAsync(memoryStream.AsRandomAccessStream());
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public RecipeModel(ItemModel result, ItemModel i1, ItemModel i2 = null, ItemModel i3 = null)
 {
     Result = result;
     Ingredient1 = i1;
     Ingredient2 = i2;
     Ingredient3 = i3;
 }
Ejemplo n.º 5
0
    //Check if three items correspond with the recipe
    public bool IsCorrect(ItemModel i1, ItemModel i2, ItemModel i3)
    {
        //Put all items into a list
        List<ItemModel> items = new List<ItemModel>{i1, i2, i3};
        List<ItemModel> recipeItems = new List<ItemModel>{Ingredient1, Ingredient2, Ingredient3};

        //Check all items to check with items in the recipe
        foreach(var item in items)
        {
            //Check if this item is in the recipe
            bool found = false;
            foreach(var rItem in recipeItems)
            {
                //If both items are null or the same
                if((item == null && rItem == null) || item >= rItem)
                {
                    found = true;
                    break;
                }
            }
            if(!found)
                return false;
        }
        return true;
    }
		public void ReloadData()
		{
			var list = new ObservableCollection<ItemModel>();

			string[] images = {
				"https://farm9.staticflickr.com/8625/15806486058_7005d77438.jpg",
				"https://farm5.staticflickr.com/4011/4308181244_5ac3f8239b.jpg",
				"https://farm8.staticflickr.com/7423/8729135907_79599de8d8.jpg",
				"https://farm3.staticflickr.com/2475/4058009019_ecf305f546.jpg",
				"https://farm6.staticflickr.com/5117/14045101350_113edbe20b.jpg",
				"https://farm2.staticflickr.com/1227/1116750115_b66dc3830e.jpg",
				"https://farm8.staticflickr.com/7351/16355627795_204bf423e9.jpg",
				"https://farm1.staticflickr.com/44/117598011_250aa8ffb1.jpg",
				"https://farm8.staticflickr.com/7524/15620725287_3357e9db03.jpg",
				"https://farm9.staticflickr.com/8351/8299022203_de0cb894b0.jpg",
			};

			int number = 0;
			for (int n = 0; n < 20; n++)
			{
				for (int i = 0; i < images.Length; i++)
				{
					number++;
					var item = new ItemModel()
					{
						ImageUrl = images[i],
						FileName = string.Format("image_{0}.jpg", number),
					};

					list.Add(item);
				}
			}

			Items = list;
		}
Ejemplo n.º 7
0
    public void SetItem(ItemModel item)
    {
        Debug.Log("Setting Item Slot GUI item: " + item.label);

        this.item = item;

        this.nameLabel.text = this.item.label;
    }
Ejemplo n.º 8
0
 public void SetupTests()
 {
     var inbox_persistence = MockRepository.GenerateStub<IItemPersistence<InBoxItem>>();
     var actions_persistence = MockRepository.GenerateStub<IItemPersistence<ActionItem>>();
     _actions_list_model = new ItemModel<ActionItem>(actions_persistence);
     _model = new ItemModel<InBoxItem>(inbox_persistence);
     _converter = new ItemConverter(_model, _actions_list_model);
     Assert.That(_model.Items, Has.Count.EqualTo(0));
 }
Ejemplo n.º 9
0
    private void CreateItemSlot(ItemInstanceModel itemInstance, ItemModel item, int count)
    {
        float yOffset = (this.itemSlotPadding * (float)count);
        ItemSlotGUI itemSlot = (ItemSlotGUI) Instantiate(this.itemSlotPrefab,
            this.itemSlotPrefab.transform.position - new Vector3(0, yOffset, 1),
            this.itemSlotPrefab.transform.rotation);

        itemSlot.gameObject.transform.parent = this.gameObject.transform;

        itemSlot.type = this.type;
        itemSlot.SetItemInstance(itemInstance);
        itemSlot.SetItem(item);

        this.itemSlots.Add(itemSlot);
    }
Ejemplo n.º 10
0
 //Remove the item from the inventory
 public void RemoveItem(ItemModel item)
 {
     //Find the item in the inventory
     int index = Inventory.FindIndex (i => i.Name == item.Name);
     //If the inventory doesn't contain this item
     if (index == -1)
         return;
     else
     {
         Inventory[index].Quantity -= item.Quantity;
         //If the player ran out of this item, remove from inventory
         if(Inventory[index].Quantity <= 0)
             Inventory.RemoveAt(index);
     }
 }
Ejemplo n.º 11
0
	    /// <summary>
	    /// Initializes a new instance of the <see cref="LineItemModel"/> class.
	    /// </summary>
	    /// <param name="lineItem">The line item.</param>
	    /// <param name="catalogItem">The catalog item.</param>
	    /// <param name="parentCatalogItem">The parent catalog item.</param>
	    /// <param name="currency"></param>
	    /// <exception cref="System.ArgumentNullException">catalogItem</exception>
	    public LineItemModel(LineItem lineItem, Item catalogItem, Item parentCatalogItem, string currency)
		{
			_lineItem = lineItem;
	        _currency = currency;

	        if (catalogItem == null)
			{
				throw new ArgumentNullException("catalogItem");
			}
			
			{
				var propertySet = CatalogHelper.CatalogClient.GetPropertySet(catalogItem.PropertySetId);
				_item = CatalogHelper.CreateItemModel(catalogItem, propertySet);
			}

			if (parentCatalogItem != null)
			{
				var propertySet = CatalogHelper.CatalogClient.GetPropertySet(parentCatalogItem.PropertySetId);
				_parentItem = CatalogHelper.CreateItemModel(parentCatalogItem, propertySet);
				_item.ParentItemId = parentCatalogItem.ItemId;
			}
		}
        public JsonResult GetClasses(int Id)
        {
            var tmp = Rings.GetClassesForRingId(Id);
            var Items = new ItemModel
            {
                ItemDetails = new List<ItemDetails>(),
                Type = "Classes"
            };
            foreach (var item in tmp)
            {
                Items.ItemDetails.Add(new ItemDetails
                {
                    Id = item.ClassId,
                    Name = item.ClassName
                });
            }

            return Json(new
            {
                Status = 0,
                Items
            });
        }
Ejemplo n.º 13
0
 private void CreateModel()
 {
     _model = new ItemModel<GTDItem>(_persistence);
 }
 protected override void AddPlugins(ItemModel source, PipelineStep pipelineStep)
 {
     AddUpdateSitecoreItemSettings(source, pipelineStep);
 }
Ejemplo n.º 15
0
        public ActionResult DeleteItem([DataSourceRequest] DataSourceRequest request, ItemModel itemModel)
        {
            try
            {
                if (itemModel != null && ModelState.IsValid)
                {
                    _entities.DeleteItem(itemModel.Id);
                }

                return(Json(new[] { itemModel }.ToDataSourceResult(new DataSourceRequest(), ModelState)));
            }
            catch (Exception e)
            {
                return(Json(e.Message));
            }
        }
Ejemplo n.º 16
0
        public static void Create(Context context, SiteSettings ss, long id, bool force = false)
        {
            if (force)
            {
                var itemModel = new ItemModel(
                    context: context,
                    referenceId: id);
                switch (itemModel.ReferenceType)
                {
                case "Sites":
                    var siteModel = new SiteModel(context: context, siteId: id);
                    CreateFullText(
                        context: context,
                        id: id,
                        fullText: siteModel.FullText(
                            context: context,
                            ss: ss,
                            backgroundTask: true));
                    break;

                case "Issues":
                    var issueModel = new IssueModel(
                        context: context,
                        ss: ss,
                        issueId: id);
                    ss.Links?
                    .Where(o => ss.GetColumn(
                               context: context,
                               columnName: o.ColumnName).UseSearch == true)
                    .ForEach(link =>
                             ss.SetChoiceHash(
                                 context: context,
                                 columnName: link.ColumnName,
                                 selectedValues: new List <string>
                    {
                        issueModel.PropertyValue(
                            context: context, name: link.ColumnName)
                    }));
                    CreateFullText(
                        context: context,
                        id: id,
                        fullText: issueModel.FullText(
                            context: context,
                            ss: ss,
                            backgroundTask: true));
                    break;

                case "Results":
                    var resultModel = new ResultModel(
                        context: context,
                        ss: ss,
                        resultId: id);
                    ss.Links?
                    .Where(o => ss.GetColumn(
                               context: context,
                               columnName: o.ColumnName).UseSearch == true)
                    .ForEach(link =>
                             ss.SetChoiceHash(
                                 context: context,
                                 columnName: link.ColumnName,
                                 selectedValues: new List <string>
                    {
                        resultModel.PropertyValue(
                            context: context, name: link.ColumnName)
                    }));
                    CreateFullText(
                        context: context,
                        id: id,
                        fullText: resultModel.FullText(
                            context: context,
                            ss: ss,
                            backgroundTask: true));
                    break;

                case "Wikis":
                    var wikiModel = new WikiModel(
                        context: context,
                        ss: ss,
                        wikiId: id);
                    CreateFullText(
                        context: context,
                        id: id,
                        fullText: wikiModel.FullText(
                            context: context,
                            ss: ss,
                            backgroundTask: true));
                    break;
                }
            }
        }
        public JsonResult GetShowsForNow()
        {
            var showMgr = new Fpp.Domain.Managers.ShowManager();
            var configuredShows = showMgr.GetConfiguredShows();
            var showForNow = showMgr.GetShowsForNow();
            var items = new ItemModel
            {
                ItemDetails = new List<ItemDetails>(),
                Type = "Shows"
            };
            foreach (var item in showForNow )
            {
                items.ItemDetails.Add(new ItemDetails {
                    Id = item.ID,
                    Name = item.ShowName
                });
            }

            return Json(new {
                Status = 0,
                Items = items,
                ConfiguredShows = configuredShows
            });
        }
Ejemplo n.º 18
0
 public void UpdateModel(ItemModel item)
 {
     UpdateParams(item);
 }
 protected override void AddPlugins(ItemModel source, PipelineStep pipelineStep)
 {
     AddEndpointSettings(source, pipelineStep);
 }
Ejemplo n.º 20
0
 public static AssociationGroup Association(ItemModel item, string groupName)
 {
     return item.AssociationGroups.FirstOrDefault(ag => ag.Name.Equals(groupName, StringComparison.OrdinalIgnoreCase));
 }
Ejemplo n.º 21
0
 public void Init(ItemModel model)
 {
 }
Ejemplo n.º 22
0
 private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
 {
     Item = null;
 }
Ejemplo n.º 23
0
        public string ChangeItemInDb(ItemModel newItem)
        {
            var query = $"update {tableItems} set Name='{newItem.Name}', Beschreibung='{newItem.Description}' where ItemId={newItem.Id}";

            return(DoManipulateQuery(query));
        }
Ejemplo n.º 24
0
 public bool UpdateItem(ItemModel item)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 25
0
 public int SaveItem(ItemModel item)
 {
     return(_itemRepo.SaveItem(item.GetRepoItem()));
 }
Ejemplo n.º 26
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CatalogItemWithPriceModel"/> class.
		/// </summary>
		/// <param name="item">The item.</param>
		/// <param name="price">The price.</param>
		/// <param name="availability">The availability.</param>
        public CatalogItemWithPriceModel(ItemModel item, PriceModel price, ItemAvailabilityModel availability)
        {
            _item = item;
            _price = price;
            _availability = availability;
		    _itemReviews = new ReviewTotals {ItemId = item.ItemId};
        }
Ejemplo n.º 27
0
 internal Model_655_Graph(ItemModel owner, GraphX item) : base(owner, item)
 {
 }
Ejemplo n.º 28
0
 public ItemModel(ItemModel copy)
 {
     Name = copy.Name;
     Quantity = copy.Quantity;
 }
Ejemplo n.º 29
0
 public ItemViewModelB(ItemModel model)
 {
     this.model = model;
 }
        public JsonResult GetRings(int Id)
        {
            var tmp = Rings.GetRingsForShowDayList(Id);
            var items = new ItemModel
            {
                ItemDetails = new List<ItemDetails>(),
                Type = "Rings"
            };
            foreach (var item in tmp)
            {
                items.ItemDetails.Add(new ItemDetails
                {
                    Id = item.ID,
                    Name = $"Ring No:{item.RingNo}"
                });
            }

            return Json(new
            {
                Status = 0,
                Items = items
            });
        }
Ejemplo n.º 31
0
 public Mask(ItemModel item) : base(item)
 {
 }
Ejemplo n.º 32
0
 public void SetItem(ItemModel itemModel)
 {
     itemModel.Description = Description;
     itemModel.Image       = ContentLink;
 }
Ejemplo n.º 33
0
        public async Task <ItemModel> Set(
            string Id,
            string TypeId,
            string SubTypeId,
            string StatusId,
            string MasterId,
            string DetailId,
            long?Sequence,
            DateTime?StartTime,
            DateTime?EndTime,
            string Text,
            string Data0,
            string Data1,
            string Data2,
            string Data3,
            string Data4,
            string Data5,
            string Data6,
            string Data7,
            long?Amount
            )
        {
            bool changed = false;
            bool added   = false;

            var item = await _Context.Item.SingleOrDefaultAsync(m => m.Database == _DatabaseId && m.ItemId == Id);

            if (item == null)
            {
                item          = new ItemModel();
                item.Database = _DatabaseId;
                item.ItemId   = Id;
                added         = true;
            }

            Let(TypeId, s => { item.TypeId = s; changed = true; });
            Let(SubTypeId, s => { item.SubTypeId = s; changed = true; });
            Let(StatusId, s => { item.StatusId = s; changed = true; });
            Let(MasterId, s => { item.MasterId = s; changed = true; });
            Let(DetailId, s => { item.DetailId = s; changed = true; });
            Let(Sequence, s => { item.Sequence = s; changed = true; });
            Let(StartTime, s => { item.StartTime = s; changed = true; });
            Let(EndTime, s => { item.EndTime = s; changed = true; });
            Let(Text, s => { item.Text = s; changed = true; });
            Let(Data0, s => { item.Data0 = s; changed = true; });
            Let(Data1, s => { item.Data1 = s; changed = true; });
            Let(Data2, s => { item.Data2 = s; changed = true; });
            Let(Data3, s => { item.Data3 = s; changed = true; });
            Let(Data4, s => { item.Data4 = s; changed = true; });
            Let(Data5, s => { item.Data5 = s; changed = true; });
            Let(Data6, s => { item.Data6 = s; changed = true; });
            Let(Data7, s => { item.Data7 = s; changed = true; });
            Let(Amount, s => { item.Amount = s; changed = true; });

            if (added)
            {
                _Context.Add(item);
                await _Context.SaveChangesAsync();
            }
            else if (changed)
            {
                _Context.Update(item);
                await _Context.SaveChangesAsync();
            }
            return(item);
        }
Ejemplo n.º 34
0
        public async Task UpdateItemDetails(string fileId)
        {
            ItemModel m = await Request.DeserializeBody <ItemModel>();

            await sql.UpdateRecord(m, $"select * from ItemDetails where FileId = {fileId}", new string[] { "StoredFile" }, null);
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Load the Default data
        /// </summary>
        /// <returns></returns>
        public static List <ItemModel> LoadData(ItemModel temp)
        {
            var datalist = new List <ItemModel>()
            {
                new ItemModel {
                    Name        = "I1",
                    Description = "I1",
                    ImageURI    = "item.png",
                    Range       = 10,
                    Damage      = 10,
                    Value       = 9,
                    Location    = ItemLocationEnum.PrimaryHand,
                    Attribute   = AttributeEnum.Attack
                },
                new ItemModel {
                    Name        = "I2",
                    Description = "I2",
                    ImageURI    = "item.png",
                    Range       = 10,
                    Damage      = 10,
                    Value       = 9,
                    Location    = ItemLocationEnum.Head,
                    Attribute   = AttributeEnum.Attack
                },
                new ItemModel {
                    Name        = "I3",
                    Description = "I3",
                    ImageURI    = "item.png",
                    Range       = 10,
                    Damage      = 10,
                    Value       = 9,
                    Location    = ItemLocationEnum.Necklass,
                    Attribute   = AttributeEnum.Attack
                },
                new ItemModel {
                    Name        = "I4",
                    Description = "I4",
                    ImageURI    = "item.png",
                    Range       = 10,
                    Damage      = 10,
                    Value       = 9,
                    Location    = ItemLocationEnum.OffHand,
                    Attribute   = AttributeEnum.Attack
                },
                new ItemModel {
                    Name        = "I5",
                    Description = "I5",
                    ImageURI    = "item.png",
                    Range       = 10,
                    Damage      = 10,
                    Value       = 9,
                    Location    = ItemLocationEnum.Finger,
                    Attribute   = AttributeEnum.Attack
                },
                new ItemModel {
                    Name        = "I6",
                    Description = "I6",
                    ImageURI    = "item.png",
                    Range       = 10,
                    Damage      = 10,
                    Value       = 9,
                    Location    = ItemLocationEnum.Feet,
                    Attribute   = AttributeEnum.Attack
                },
            };

            for (int i = 0; i < 20; i++)
            {
                var item = new ItemModel
                {
                    ImageURI  = "item.png",
                    Range     = 2,
                    Damage    = 10,
                    Value     = 9,
                    Location  = ItemLocationEnum.PrimaryHand,
                    Attribute = AttributeEnum.Attack
                };
                item.Name        = "I" + (datalist.Count + 1).ToString();
                item.Description = item.Name;

                datalist.Add(item);
            }

            return(datalist);
        }
Ejemplo n.º 36
0
 public void SetItem(ItemModel itemModel)
 {
     itemModel.Description = Subtext?.ToHtmlString();
     itemModel.Image       = BackgroundImage;
 }
Ejemplo n.º 37
0
        /* Modify item and add new item */

        public void ModifyItem(ItemModel item, int index)
        {
            ShowItemDetailForm(activeListType, item, index, this);
        }
Ejemplo n.º 38
0
		public ActionResult Association(ItemModel item, string templateName, string groupName)
        {
            var currentGroup = item.AssociationGroups
                                   .FirstOrDefault(
									   ag => ag.Name.Equals(groupName, StringComparison.OrdinalIgnoreCase));
			return currentGroup == null ? null : PartialView(templateName, currentGroup);
        }
Ejemplo n.º 39
0
 public string IsExistOrInsert(ItemModel item)
 {
     return(_itemSetupRepository.IsExistOrInsert(item));
 }
Ejemplo n.º 40
0
        public void BusinessPurchaseMadeEvent(Client player, string itemName, int amount)
        {
            int               businessId   = player.GetData(EntityData.PLAYER_BUSINESS_ENTERED);
            BusinessModel     business     = GetBusinessById(businessId);
            BusinessItemModel businessItem = GetBusinessItemFromName(itemName);

            if (business.type == Constants.BUSINESS_TYPE_AMMUNATION && businessItem.type == Constants.ITEM_TYPE_WEAPON && player.GetData(EntityData.PLAYER_WEAPON_LICENSE) < Globals.GetTotalSeconds())
            {
                player.SendChatMessage(Constants.COLOR_ERROR + Messages.ERR_WEAPON_LICENSE_EXPIRED);
            }
            else
            {
                int hash  = 0;
                int price = (int)Math.Round(businessItem.products * business.multiplier) * amount;
                int money = player.GetSharedData(EntityData.PLAYER_MONEY);

                if (money < price)
                {
                    player.SendChatMessage(Constants.COLOR_ERROR + Messages.ERR_PLAYER_NOT_ENOUGH_MONEY);
                }
                else
                {
                    string purchaseMessage = string.Format(Messages.INF_BUSINESS_ITEM_PURCHASED, price);
                    int    playerId        = player.GetData(EntityData.PLAYER_SQL_ID);

                    // We look for the item in the inventory
                    ItemModel itemModel = Globals.GetPlayerItemModelFromHash(playerId, businessItem.hash);
                    if (itemModel == null)
                    {
                        // We create the purchased item
                        itemModel      = new ItemModel();
                        itemModel.hash = businessItem.hash;
                        if (businessItem.type == Constants.ITEM_TYPE_WEAPON)
                        {
                            itemModel.ownerEntity = Constants.ITEM_ENTITY_WHEEL;
                        }
                        else
                        {
                            itemModel.ownerEntity = int.TryParse(itemModel.hash, out hash) ? Constants.ITEM_ENTITY_RIGHT_HAND : Constants.ITEM_ENTITY_PLAYER;
                        }
                        itemModel.ownerIdentifier = player.GetData(EntityData.PLAYER_SQL_ID);
                        itemModel.amount          = businessItem.uses * amount;
                        itemModel.position        = new Vector3(0.0f, 0.0f, 0.0f);
                        itemModel.dimension       = 0;

                        Task.Factory.StartNew(() => {
                            // Adding the item to the list and database
                            itemModel.id = Database.AddNewItem(itemModel);
                            Globals.itemList.Add(itemModel);
                        });
                    }
                    else
                    {
                        if (int.TryParse(itemModel.hash, out hash) == true)
                        {
                            itemModel.ownerEntity = Constants.ITEM_ENTITY_RIGHT_HAND;
                        }
                        itemModel.amount += (businessItem.uses * amount);

                        Task.Factory.StartNew(() => {
                            // Update the item's amount
                            Database.UpdateItem(itemModel);
                        });
                    }

                    // If the item has a valid hash, we give it in hand
                    if (itemModel.ownerEntity == Constants.ITEM_ENTITY_RIGHT_HAND)
                    {
                        itemModel.objectHandle = NAPI.Object.CreateObject(uint.Parse(itemModel.hash), itemModel.position, new Vector3(0.0f, 0.0f, 0.0f), (byte)player.Dimension);
                        itemModel.objectHandle.AttachTo(player, "PH_R_Hand", businessItem.position, businessItem.rotation);
                    }
                    else if (businessItem.type == Constants.ITEM_TYPE_WEAPON)
                    {
                        // We give the weapon to the player
                        player.GiveWeapon(NAPI.Util.WeaponNameToModel(itemModel.hash), itemModel.amount);

                        // Checking if it's been bought in the Ammu-Nation
                        if (business.type == Constants.BUSINESS_TYPE_AMMUNATION)
                        {
                            Task.Factory.StartNew(() => {
                                // Add a registered weapon
                                Database.AddLicensedWeapon(itemModel.id, player.Name);
                            });
                        }
                    }

                    // We set the item into the hand variable
                    player.SetData(EntityData.PLAYER_RIGHT_HAND, itemModel.id);

                    // If it's a phone, we create a new number
                    if (itemModel.hash == Constants.ITEM_HASH_TELEPHONE)
                    {
                        if (player.GetData(EntityData.PLAYER_PHONE) == 0)
                        {
                            Random random = new Random();
                            int    phone  = random.Next(100000, 999999);
                            player.SetData(EntityData.PLAYER_PHONE, phone);

                            // Sending the message with the new number to the player
                            string message = string.Format(Messages.INF_PLAYER_PHONE, phone);
                            player.SendChatMessage(Constants.COLOR_INFO + message);
                        }
                    }

                    // We substract the product and add funds to the business
                    if (business.owner != string.Empty)
                    {
                        business.funds    += price;
                        business.products -= businessItem.products;

                        Task.Factory.StartNew(() => {
                            // Update the business
                            Database.UpdateBusiness(business);
                        });
                    }

                    player.SetSharedData(EntityData.PLAYER_MONEY, money - price);
                    player.SendChatMessage(Constants.COLOR_INFO + purchaseMessage);
                }
            }
        }
Ejemplo n.º 41
0
 public void Route(ItemModel item)
 {
     container.Add(new ItemView(new ItemViewModel(item)));
 }
Ejemplo n.º 42
0
		/// <summary>
		/// Initializes a new instance of the <see cref="AssociatedCatalogItemWithPriceModel"/> class.
		/// </summary>
		/// <param name="item">The item.</param>
		/// <param name="price">The price.</param>
		/// <param name="availability">The availability.</param>
		/// <param name="associationType">Type of the association.</param>
        public AssociatedCatalogItemWithPriceModel(ItemModel item, PriceModel price, ItemAvailabilityModel availability,
                                                   string associationType) :
            base(item, price, availability)
        {
            _associationType = associationType;
        }
Ejemplo n.º 43
0
        public void ConfirmVehicleModificationEvent(Client player)
        {
            int totalProducts = 0;
            int vehicleId     = player.Vehicle.GetData(EntityData.VEHICLE_ID);

            // Get player's product amount
            int       playerId = player.GetData(EntityData.PLAYER_SQL_ID);
            ItemModel item     = Globals.GetPlayerItemModelFromHash(playerId, Constants.ITEM_HASH_BUSINESS_PRODUCTS);

            for (int i = 0; i < 49; i++)
            {
                int vehicleMod = player.Vehicle.GetMod(i);

                if (vehicleMod > 0)
                {
                    TunningModel tunningModel = GetVehicleTunningComponent(vehicleId, i, vehicleMod);
                    if (tunningModel == null)
                    {
                        totalProducts += Constants.TUNNING_PRICE_LIST.Where(x => x.slot == i).First().products;
                    }
                }
            }

            if (item != null && item.amount >= totalProducts)
            {
                for (int i = 0; i < 49; i++)
                {
                    int vehicleMod = player.Vehicle.GetMod(i);

                    if (vehicleMod > 0)
                    {
                        TunningModel tunningModel = GetVehicleTunningComponent(vehicleId, i, vehicleMod);
                        if (tunningModel == null)
                        {
                            // Add component to database
                            tunningModel           = new TunningModel();
                            tunningModel.slot      = i;
                            tunningModel.component = vehicleMod;
                            tunningModel.vehicle   = vehicleId;

                            Task.Factory.StartNew(() =>
                            {
                                tunningModel.id = Database.AddTunning(tunningModel);
                                tunningList.Add(tunningModel);
                            });
                        }
                    }
                }

                // Remove consumed products
                item.amount -= totalProducts;

                Task.Factory.StartNew(() =>
                {
                    // Update the amount into the database
                    Database.UpdateItem(item);
                });

                // Close tunning menu
                player.TriggerEvent("closeTunningMenu");

                // Confirmation message
                player.SendChatMessage(Constants.COLOR_INFO + InfoRes.vehicle_tunning);
            }
            else
            {
                string message = string.Format(ErrRes.not_required_products, totalProducts);
                player.SendChatMessage(Constants.COLOR_ERROR + message);
            }
        }
Ejemplo n.º 44
0
 public void AddInventoryItem(ItemModel item)
 {
     this.inventoryItems.Add(item);
 }
Ejemplo n.º 45
0
        public void RepairCommand(Client player, int vehicleId, string type, int price = 0)
        {
            if (player.GetData(EntityData.PLAYER_JOB) != Constants.JOB_MECHANIC)
            {
                player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_not_mechanic);
            }
            else if (player.GetData(EntityData.PLAYER_ON_DUTY) == 0)
            {
                player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_not_on_duty);
            }
            else if (player.GetData(EntityData.PLAYER_KILLED) != 0)
            {
                player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_is_dead);
            }
            else if (PlayerInValidRepairPlace(player) == false)
            {
                player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.not_valid_repair_place);
            }
            else
            {
                Vehicle vehicle = Vehicles.GetVehicleById(vehicleId);
                if (vehicle == null)
                {
                    player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.vehicle_not_exists);
                }
                else if (vehicle.Position.DistanceTo(player.Position) > 5.0f)
                {
                    player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.wanted_vehicle_far);
                }
                else
                {
                    int spentProducts = 0;

                    switch (type.ToLower())
                    {
                    case Commands.ARG_CHASSIS:
                        spentProducts = Constants.PRICE_VEHICLE_CHASSIS;
                        break;

                    case Commands.ARG_DOORS:
                        for (int i = 0; i < 6; i++)
                        {
                            if (vehicle.IsDoorBroken(i) == true)
                            {
                                spentProducts += Constants.PRICE_VEHICLE_DOORS;
                            }
                        }
                        break;

                    case Commands.ARG_TYRES:
                        for (int i = 0; i < 4; i++)
                        {
                            if (vehicle.IsTyrePopped(i) == true)
                            {
                                spentProducts += Constants.PRICE_VEHICLE_TYRES;
                            }
                        }
                        break;

                    case Commands.ARG_WINDOWS:
                        for (int i = 0; i < 4; i++)
                        {
                            if (vehicle.IsWindowBroken(i) == true)
                            {
                                spentProducts += Constants.PRICE_VEHICLE_WINDOWS;
                            }
                        }
                        break;

                    default:
                        player.SendChatMessage(Constants.COLOR_HELP + Commands.HLP_MECHANIC_REPAIR_COMMAND);
                        return;
                    }

                    if (price > 0)
                    {
                        // Get player's products
                        int       playerId = player.GetData(EntityData.PLAYER_SQL_ID);
                        ItemModel item     = Globals.GetPlayerItemModelFromHash(playerId, Constants.ITEM_HASH_BUSINESS_PRODUCTS);

                        if (item != null && item.amount >= spentProducts)
                        {
                            int vehicleFaction = vehicle.GetData(EntityData.VEHICLE_FACTION);

                            // Check a player with vehicle keys
                            foreach (Client target in NAPI.Pools.GetAllPlayers())
                            {
                                if (Vehicles.HasPlayerVehicleKeys(target, vehicle) || (vehicleFaction > 0 && target.GetData(EntityData.PLAYER_FACTION) == vehicleFaction))
                                {
                                    if (target.Position.DistanceTo(player.Position) < 4.0f)
                                    {
                                        // Fill repair entity data
                                        target.SetData(EntityData.PLAYER_JOB_PARTNER, player);
                                        target.SetData(EntityData.PLAYER_REPAIR_VEHICLE, vehicle);
                                        target.SetData(EntityData.PLAYER_REPAIR_TYPE, type);
                                        target.SetData(EntityData.JOB_OFFER_PRODUCTS, spentProducts);
                                        target.SetData(EntityData.JOB_OFFER_PRICE, price);

                                        string playerMessage = string.Format(InfoRes.mechanic_repair_offer, target.Name, price);
                                        string targetMessage = string.Format(InfoRes.mechanic_repair_accept, player.Name, price);
                                        player.SendChatMessage(Constants.COLOR_INFO + playerMessage);
                                        target.SendChatMessage(Constants.COLOR_INFO + targetMessage);
                                        return;
                                    }
                                }
                            }

                            // There's no player with the vehicle's keys near
                            player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_too_far);
                        }
                        else
                        {
                            string message = string.Format(ErrRes.not_required_products, spentProducts);
                            player.SendChatMessage(Constants.COLOR_ERROR + message);
                        }
                    }
                    else
                    {
                        string message = string.Format(InfoRes.repair_price, spentProducts);
                        player.SendChatMessage(Constants.COLOR_INFO + message);
                    }
                }
            }
        }
Ejemplo n.º 46
0
        private void AddToContainer(string category, string[] values)
        {
            IList<ItemModel> itemModels;

            bool founded = _container.TryGetValue(category, out itemModels);

            if (!founded)
            {
                _container.Add(category, new List<ItemModel>());
            }

            List<string> columns = GetColumnsByCategory(category);

            // TODO : Last minute change. Adding support for Supreme Ruler 2020 file. Ugly code will be removed
            if (columns.Count == 134 && values.Length == 133) // Supreme Ruler 2020
            {
                columns.RemoveAt(columns.Count - 1);
            }

            var model = new ItemModel();

            for (int i = 0; i < columns.Count; i++)
            {
                string header = columns[i].Trim();
                string value = values[i].Trim();

                model[header] = value;
            }

            _container[category].Add(model);
        }
Ejemplo n.º 47
0
        public void RepaintVehicleEvent(Client player, int colorType, string firstColor, string secondColor, int pearlescentColor, int vehiclePaid)
        {
            // Get player's vehicle
            Vehicle vehicle = player.GetData(EntityData.PLAYER_VEHICLE);

            switch (colorType)
            {
            case 0:
                // Predefined color
                vehicle.PrimaryColor   = int.Parse(firstColor);
                vehicle.SecondaryColor = int.Parse(secondColor);

                if (pearlescentColor >= 0)
                {
                    vehicle.PearlescentColor = pearlescentColor;
                }
                break;

            case 1:
                // Custom color
                string[] firstColorArray  = firstColor.Split(',');
                string[] secondColorArray = secondColor.Split(',');
                vehicle.CustomPrimaryColor   = new Color(int.Parse(firstColorArray[0]), int.Parse(firstColorArray[1]), int.Parse(firstColorArray[2]));
                vehicle.CustomSecondaryColor = new Color(int.Parse(secondColorArray[0]), int.Parse(secondColorArray[1]), int.Parse(secondColorArray[2]));
                break;
            }

            if (vehiclePaid > 0)
            {
                // Check for the product amount
                int       playerId = player.GetData(EntityData.PLAYER_SQL_ID);
                ItemModel item     = Globals.GetPlayerItemModelFromHash(playerId, Constants.ITEM_HASH_BUSINESS_PRODUCTS);

                if (item != null && item.amount >= 250)
                {
                    int vehicleFaction = vehicle.GetData(EntityData.VEHICLE_FACTION);

                    // Search for a player with vehicle keys
                    foreach (Client target in NAPI.Pools.GetAllPlayers())
                    {
                        if (Vehicles.HasPlayerVehicleKeys(target, vehicle) || (vehicleFaction > 0 && target.GetData(EntityData.PLAYER_FACTION) == vehicleFaction))
                        {
                            if (target.Position.DistanceTo(player.Position) < 4.0f)
                            {
                                // Vehicle repaint data
                                target.SetData(EntityData.PLAYER_JOB_PARTNER, player);
                                target.SetData(EntityData.PLAYER_REPAINT_VEHICLE, vehicle);
                                target.SetData(EntityData.PLAYER_REPAINT_COLOR_TYPE, colorType);
                                target.SetData(EntityData.PLAYER_REPAINT_FIRST_COLOR, firstColor);
                                target.SetData(EntityData.PLAYER_REPAINT_SECOND_COLOR, secondColor);
                                target.SetData(EntityData.PLAYER_REPAINT_PEARLESCENT, pearlescentColor);
                                target.SetData(EntityData.JOB_OFFER_PRICE, vehiclePaid);
                                target.SetData(EntityData.JOB_OFFER_PRODUCTS, 250);

                                string playerMessage = string.Format(InfoRes.mechanic_repaint_offer, target.Name, vehiclePaid);
                                string targetMessage = string.Format(InfoRes.mechanic_repaint_accept, player.Name, vehiclePaid);
                                player.SendChatMessage(Constants.COLOR_INFO + playerMessage);
                                target.SendChatMessage(Constants.COLOR_INFO + targetMessage);
                                return;
                            }
                        }
                    }

                    // There's no player with vehicle's keys near
                    player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_too_far);
                }
                else
                {
                    string message = string.Format(ErrRes.not_required_products, 250);
                    player.SendChatMessage(Constants.COLOR_ERROR + message);
                }
            }
        }
Ejemplo n.º 48
0
        /// <summary>
        /// Creates the item model.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="propertySet">The property set.</param>
        /// <returns>ItemModel.</returns>
        /// <exception cref="System.ArgumentNullException">item</exception>
        public static ItemModel CreateItemModel(Item item, PropertySet propertySet = null)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            var model = new ItemModel { Item = item };
            model.InjectFrom(item);

            model.ItemAssets = new List<ItemAsset>(item.ItemAssets).ToArray();
            model.EditorialReviews = new List<EditorialReview>(item.EditorialReviews).ToArray();
            model.AssociationGroups = new List<AssociationGroup>(item.AssociationGroups).ToArray();

            if (propertySet != null && item.ItemPropertyValues != null)
            {
                var values = item.ItemPropertyValues;
                var properties = propertySet.PropertySetProperties.SelectMany(x => values.Where(v => v.Name == x.Property.Name
                    && !x.Property.PropertyAttributes.Any(pa => pa.PropertyAttributeName.Equals("Hidden", StringComparison.OrdinalIgnoreCase)) //skip hidden
                    && (!x.Property.IsLocaleDependant // if not localized ok
                    || string.Equals(v.Locale, CultureInfo.CurrentUICulture.Name, StringComparison.InvariantCultureIgnoreCase) //if current locale match value locale ok
                    || (string.Equals(v.Locale, StoreHelper.GetDefaultLanguageCode(), StringComparison.InvariantCultureIgnoreCase) //if default locale match value locale and values does not contain locale for current property ok
                    && !values.Any(val => val.Name == x.Property.Name && string.Equals(val.Locale, CultureInfo.CurrentUICulture.Name, StringComparison.InvariantCultureIgnoreCase))))),
                    (r, v) => CreatePropertyModel(r.Priority, r.Property, v, item)).ToArray();

                model.Properties = new PropertiesModel(properties);
            }

            //Find item category
            if (item.CategoryItemRelations != null)
            {
                string categoryId = null;
                foreach (var rel in item.CategoryItemRelations)
                {
                    if (rel.CatalogId == UserHelper.CustomerSession.CatalogId)
                    {
                        categoryId = rel.CategoryId;
                        break;
                    }

                    var category = CatalogClient.GetCategoryById(rel.CategoryId);

                    if (category == null)
                        continue;

                    var linkedCategory = category.LinkedCategories.FirstOrDefault(
                        link => link.CatalogId == UserHelper.CustomerSession.CatalogId);

                    if (linkedCategory == null)
                        continue;

                    categoryId = linkedCategory.CategoryId;
                    break;
                }

                if (!string.IsNullOrEmpty(categoryId))
                {
                    var category = CatalogClient.GetCategoryById(categoryId);
                    var cat = category as Category;
                    if (cat != null)
                    {
                        model.CategoryName = cat.Name.Localize();
                    }
                }
            }

            return model;
        }
Ejemplo n.º 49
0
        private void OnPlayerRob(object playerObject)
        {
            Client  player             = (Client)playerObject;
            int     playerSqlId        = player.GetData(EntityData.PLAYER_SQL_ID);
            int     timeElapsed        = Globals.GetTotalSeconds() - player.GetData(EntityData.PLAYER_ROBBERY_START);
            decimal stolenItemsDecimal = timeElapsed / Constants.ITEMS_ROBBED_PER_TIME;
            int     totalStolenItems   = (int)Math.Round(stolenItemsDecimal);

            // Check if the player has stolen items
            ItemModel stolenItemModel = Globals.GetPlayerItemModelFromHash(playerSqlId, Constants.ITEM_HASH_STOLEN_OBJECTS);

            if (stolenItemModel == null)
            {
                stolenItemModel = new ItemModel();
                {
                    stolenItemModel.amount          = totalStolenItems;
                    stolenItemModel.hash            = Constants.ITEM_HASH_STOLEN_OBJECTS;
                    stolenItemModel.ownerEntity     = Constants.ITEM_ENTITY_PLAYER;
                    stolenItemModel.ownerIdentifier = playerSqlId;
                    stolenItemModel.dimension       = 0;
                    stolenItemModel.position        = new Vector3(0.0f, 0.0f, 0.0f);
                }

                Task.Factory.StartNew(() =>
                {
                    stolenItemModel.id = Database.AddNewItem(stolenItemModel);
                    Globals.itemList.Add(stolenItemModel);
                });
            }
            else
            {
                stolenItemModel.amount += totalStolenItems;

                Task.Factory.StartNew(() =>
                {
                    // Update the amount into the database
                    Database.UpdateItem(stolenItemModel);
                });
            }

            // Allow player movement
            player.Freeze(false);
            player.StopAnimation();
            player.ResetData(EntityData.PLAYER_ANIMATION);
            player.ResetData(EntityData.PLAYER_ROBBERY_START);

            if (robberyTimerList.TryGetValue(player.Value, out Timer robberyTimer) == true)
            {
                robberyTimer.Dispose();
                robberyTimerList.Remove(player.Value);
            }

            // Avisamos de los objetos robados
            string message = string.Format(InfoRes.player_robbed, totalStolenItems);

            player.SendChatMessage(Constants.COLOR_INFO + message);

            // Check if the player commited the maximum thefts allowed
            int totalThefts = player.GetData(EntityData.PLAYER_JOB_DELIVER);

            if (Constants.MAX_THEFTS_IN_ROW == totalThefts)
            {
                // Apply a cooldown to the player
                player.SetData(EntityData.PLAYER_JOB_DELIVER, 0);
                player.SetData(EntityData.PLAYER_JOB_COOLDOWN, 60);
                player.SendChatMessage(Constants.COLOR_INFO + InfoRes.player_rob_pressure);
            }
            else
            {
                player.SetData(EntityData.PLAYER_JOB_DELIVER, totalThefts + 1);
            }
        }
        public JsonResult GetShowDays(int Id)
        {
            var tmp = Fpp.Business.ShowDetails.GetShowDetails(Id);
            var Items = new ItemModel
            {
                ItemDetails = new List<ItemDetails>(),
                Type = "Days"
            };
            foreach (var item in tmp)
            {
                Items.ItemDetails.Add(new ItemDetails
                {
                    Id = item.ID,
                    Name = string.Format("{0:dddd, dd MMM yyyy}", item.ShowDate)
                });
            }

            return Json(new
            {
                Status = 0,
                Items
            });
        }
Ejemplo n.º 51
0
 public Item(ItemModel item)
 {
     UpdateParams(item);
 }
Ejemplo n.º 52
0
        private IList <ItemModel> GetItemList(JArray events)
        {
            IList <ItemModel> itemList = new List <ItemModel>();
            ItemModel         item     = new ItemModel();

            try
            {
                foreach (JObject e in events)
                {
                    item.Id          = GetStringFieldOrNull(e, "id");
                    item.Name        = GetStringFieldOrNull(e, "name");
                    item.Url         = GetStringFieldOrNull(e, "url");
                    item.Description = GetDescription(e);
                    item.Categories  = GetCategories(e);
                    item.ImageUrl    = GetImageUrl(e);
                    JObject venue = GetVenue(e);

                    if (venue != null)
                    {
                        if (venue["address"] != null)
                        {
                            JObject       address = (JObject)venue["address"];
                            StringBuilder sb      = new StringBuilder();
                            if (address["line1"] != null)
                            {
                                sb.Append(address["line1"]);
                            }
                            if (address["line2"] != null)
                            {
                                sb.Append(address["line2"]);
                            }
                            if (address["line3"] != null)
                            {
                                sb.Append(address["line3"]);
                            }
                            item.Address = sb.ToString();
                        }
                        if (venue["city"] != null)
                        {
                            JObject city = (JObject)venue["city"];
                            item.City = GetStringFieldOrNull(city, "name");
                        }
                        if (venue["country"] != null)
                        {
                            JObject country = (JObject)venue["country"];
                            item.Country = GetStringFieldOrNull(country, "name");
                        }
                        if (venue["state"] != null)
                        {
                            JObject state = (JObject)venue["state"];
                            item.State = GetStringFieldOrNull(state, "name");
                        }
                        item.Zipcode = GetStringFieldOrNull(venue, "postalCode");
                        if (venue["location"] != null)
                        {
                            JObject location = (JObject)venue["location"];
                            item.Latitude  = GetNumericFieldOrNull(location, "latitude");
                            item.Longitude = GetNumericFieldOrNull(location, "longitude");
                        }
                    }
                    itemList.Add(item);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(itemList);
        }
        public async Task RemoveItem(ItemModel item)
        {
            string sql = "delete from Items where Id=@Id";

            await _dataAccess.ExecuteRawSQL <dynamic>(sql, item);
        }
Ejemplo n.º 54
0
        public void FrequencyCommand(Client player, string args)
        {
            if (player.GetSharedData(EntityData.PLAYER_RIGHT_HAND) != null)
            {
                // Get the item identifier
                string    rightHand = player.GetSharedData(EntityData.PLAYER_RIGHT_HAND).ToString();
                int       itemId    = NAPI.Util.FromJson <AttachmentModel>(rightHand).itemId;
                ItemModel item      = Globals.GetItemModelFromId(itemId);

                if (item != null && item.hash == Constants.ITEM_HASH_WALKIE)
                {
                    int          playerId     = player.GetData(EntityData.PLAYER_SQL_ID);
                    ChannelModel ownedChannel = GetPlayerOwnedChannel(playerId);
                    string[]     arguments    = args.Trim().Split(' ');
                    switch (arguments[0].ToLower())
                    {
                    case Commands.ARG_CREATE:
                        if (arguments.Length == 2)
                        {
                            if (ownedChannel == null)
                            {
                                // We create the new frequency
                                MD5          md5Hash = MD5.Create();
                                ChannelModel channel = new ChannelModel();
                                {
                                    channel.owner    = playerId;
                                    channel.password = GetMd5Hash(md5Hash, arguments[1]);
                                }

                                Task.Factory.StartNew(() =>
                                {
                                    // Create the new channel
                                    channel.id = Database.AddChannel(channel);
                                    channelList.Add(channel);

                                    // Sending the message with created channel
                                    string message = string.Format(InfoRes.channel_created, channel.id);
                                    player.SendChatMessage(Constants.COLOR_INFO + message);
                                });
                            }
                            else
                            {
                                player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.already_owned_channel);
                            }
                        }
                        else
                        {
                            player.SendChatMessage(Constants.COLOR_HELP + Commands.HLP_FREQUENCY_CREATE_COMMAND);
                        }
                        break;

                    case Commands.ARG_MODIFY:
                        if (arguments.Length == 2)
                        {
                            if (ownedChannel != null)
                            {
                                MD5 md5Hash = MD5.Create();
                                ownedChannel.password = GetMd5Hash(md5Hash, arguments[1]);

                                // We kick all the players from the channel
                                foreach (Client target in NAPI.Pools.GetAllPlayers())
                                {
                                    int targetId = player.GetData(EntityData.PLAYER_SQL_ID);
                                    if (target.GetData(EntityData.PLAYER_RADIO) == ownedChannel.id && targetId != ownedChannel.owner)
                                    {
                                        target.SetData(EntityData.PLAYER_RADIO, 0);
                                        target.SendChatMessage(Constants.COLOR_INFO + InfoRes.channel_disconnected);
                                    }
                                }


                                Task.Factory.StartNew(() =>
                                {
                                    // Update the channel and disconnect the leader
                                    Database.UpdateChannel(ownedChannel);
                                    Database.DisconnectFromChannel(ownedChannel.id);

                                    // Message sent with the confirmation
                                    player.SendChatMessage(Constants.COLOR_INFO + InfoRes.channel_updated);
                                });
                            }
                            else
                            {
                                player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.not_owned_channel);
                            }
                        }
                        else
                        {
                            player.SendChatMessage(Constants.COLOR_HELP + Commands.HLP_FREQUENCY_MODIFY_COMMAND);
                        }
                        break;

                    case Commands.ARG_REMOVE:
                        if (ownedChannel != null)
                        {
                            // We kick all the players from the channel
                            foreach (Client target in NAPI.Pools.GetAllPlayers())
                            {
                                int targetId = player.GetData(EntityData.PLAYER_SQL_ID);
                                if (target.GetData(EntityData.PLAYER_RADIO) == ownedChannel.id)
                                {
                                    target.SetData(EntityData.PLAYER_RADIO, 0);
                                    if (ownedChannel.owner != targetId)
                                    {
                                        target.SendChatMessage(Constants.COLOR_INFO + InfoRes.channel_disconnected);
                                    }
                                }
                            }

                            Task.Factory.StartNew(() =>
                            {
                                // Disconnect the leader from the channel
                                Database.DisconnectFromChannel(ownedChannel.id);

                                // We destroy the channel
                                Database.RemoveChannel(ownedChannel.id);
                                channelList.Remove(ownedChannel);

                                // Message sent with the confirmation
                                player.SendChatMessage(Constants.COLOR_INFO + InfoRes.channel_deleted);
                            });
                        }
                        else
                        {
                            player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.not_owned_channel);
                        }
                        break;

                    case Commands.ARG_CONNECT:
                        if (arguments.Length == 3)
                        {
                            if (int.TryParse(arguments[1], out int frequency) == true)
                            {
                                // We encrypt the password
                                MD5    md5Hash  = MD5.Create();
                                string password = GetMd5Hash(md5Hash, arguments[2]);

                                foreach (ChannelModel channel in channelList)
                                {
                                    if (channel.id == frequency && channel.password == password)
                                    {
                                        string message = string.Format(InfoRes.channel_connected, channel.id);
                                        player.SetData(EntityData.PLAYER_RADIO, channel.id);
                                        player.SendChatMessage(Constants.COLOR_INFO + message);
                                        return;
                                    }
                                }

                                // Couldn't find any channel with that id
                                player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.channel_not_found);
                            }
                            else
                            {
                                player.SendChatMessage(Constants.COLOR_HELP + Commands.HLP_FREQUENCY_CONNECT_COMMAND);
                            }
                        }
                        else
                        {
                            player.SendChatMessage(Constants.COLOR_HELP + Commands.HLP_FREQUENCY_CONNECT_COMMAND);
                        }
                        break;

                    case Commands.ARG_DISCONNECT:
                        player.SetData(EntityData.PLAYER_RADIO, 0);
                        player.SendChatMessage(Constants.COLOR_INFO + InfoRes.channel_disconnected);
                        break;

                    default:
                        player.SendChatMessage(Constants.COLOR_HELP + Commands.HLP_FREQUENCY_COMMAND);
                        break;
                    }
                }
                else
                {
                    player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.no_walkie_in_hand);
                }
            }
            else
            {
                player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.right_hand_empty);
            }
        }
Ejemplo n.º 55
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CatalogItemWithPriceModel"/> class.
		/// </summary>
		/// <param name="item">The item.</param>
		/// <param name="price">The price.</param>
		/// <param name="availability">The availability.</param>
        public CatalogItemWithPriceModel(ItemModel item, PriceModel price, ItemAvailabilityModel availability)
        {
            _item = item;
            _price = price;
            _availability = availability;
        }